MerchantCustomerInfoController.java 30.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
package cn.com.glsx.busassistant.controller;

import cn.com.glsx.busassistant.constant.CommonConstant;
import cn.com.glsx.busassistant.model.request.activity.ActivityMerchantRpcRequest;
import cn.com.glsx.busassistant.model.response.activity.ActivityOpenedByMerchantRpcResponse;
import cn.com.glsx.busassistant.request.*;
import cn.com.glsx.busassistant.request.merchant.InviteQRCodeRopRequest;
import cn.com.glsx.busassistant.request.merchant.MerchantProductsRopRequest;
import cn.com.glsx.busassistant.request.serviceCenter.MerchantBrandIdAndNameRequest;
import cn.com.glsx.busassistant.request.serviceCenter.MerchantBrandRequest;
import cn.com.glsx.busassistant.request.staff.BusiMerchantStaffRequest;
import cn.com.glsx.busassistant.response.*;
import cn.com.glsx.busassistant.response.serviceCenter.InviteStaffUrlRopResponse;
import cn.com.glsx.busassistant.service.BusiAssistantActivityService;
import cn.com.glsx.busassistant.service.BusiAssistantMerchantService;
import cn.com.glsx.busassistant.service.BusinessStaffService;
import cn.com.glsx.busassistant.util.CommonUtil;
import cn.com.glsx.dj.smartcarlife.model.ServiceMerchantStaffAllocation;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.merchants.enums.StaffBusinessTypeEnum;
import cn.com.glsx.merchants.model.request.serviceCenter.SearchMerchantRpcRequest;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.model.response.staff.StaffCountRpcResponse;
import cn.com.glsx.scrm.proxy.enums.ProxyRequestSourceEnum;
import cn.com.glsx.scrm.proxy.model.CommonProxyRequest;
import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse;
import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote;
import cn.com.glsx.scrm.system.model.wechatapplets.LoginUserInfoResponse;
import com.alibaba.fastjson.JSONArray;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.oreframework.boot.autoconfigure.rop.util.RopThreadLocal;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("生意助手-客户管理")
public class MerchantCustomerInfoController {
    @Autowired
    private CommonProxyRemote commonProxyRemote;

    @Autowired
    private BusiAssistantActivityService activityService;

    @Autowired
    private BusinessStaffService staffService;

    @Autowired
    private BusiAssistantMerchantService merchantService;

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;


    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.page", needInSession= NeedInSessionType.YES)
    @ApiOperation("分页查询客户列表")
    public RopResponse<RpcPagination<MerchantCustomerPageResponse>> page(MerchantCustomPageRequest request) {
        try {
            final String requestMethod = "dj.api.businessAssistant.merchantCustomer.page";
            CommonProxyRequest proxyRequest = new CommonProxyRequest();
            proxyRequest.setRequestMethod(requestMethod);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
            LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
            MultiValueMap<String, String> params = CommonUtil.convertToMap(request);
            params.add("partnerMerchantId", loginUser.getMerchantId().toString());
            if (Objects.equals(loginUser.getIsSuper(), true)) {
                params.remove("partnerMerchantId");
            }
            if (Objects.nonNull(request.getServiceCenterMerchantId())) {
                params.add("yqMerchantId", request.getServiceCenterMerchantId().toString());
            }
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (response.isFailed()) {
                log.error("分页查询客户列表失败,查询智享车生活客户列表失败:{}", response.getMessage());
                return RopResponse.error("分页查询客户列表失败");
            }
            if (Objects.isNull(response.getResult())) {
                log.info("分页查询客户列表,查询智享车生活客户列表为空");
                return RopResponse.success(new RpcPagination<>());
            }
            RpcPagination<MerchantCustomerResponse> merchantCustomerResponsePagination = RpcPagination.copyPage(response.getResult().getPageFromRpcPagination(MerchantCustomerResponse.class));
            if (Objects.isNull(merchantCustomerResponsePagination) || CollectionUtils.isEmpty(merchantCustomerResponsePagination.getList())) {
                log.info("分页查询客户列表,查询智享车生活客户列表为空2");
                return RopResponse.success(new RpcPagination<>());
            }
            List<Integer> merchantNoList = merchantCustomerResponsePagination.getList().stream().map(MerchantCustomerResponse::getShopMerchantId).collect(Collectors.toList());
            SearchMerchantRpcRequest rpcRequest = new SearchMerchantRpcRequest();
            BeanUtils.copyProperties(request,rpcRequest);
            rpcRequest.setPageNum(1);
            rpcRequest.setMerchantNoList(merchantNoList);
            rpcRequest.setStaffBusinessType(StaffBusinessTypeEnum.TECHNICIAN.getCode());
            List<ServiceMerchantRopResponse> serviceMerchantRopList = merchantService.selectMerchantPage(rpcRequest);
            if (CollectionUtils.isEmpty(serviceMerchantRopList)){
                log.error("查询商户列表分页失败");
                return RopResponse.success(new RpcPagination<>());
            }
            List<Integer> yqMerchantNoList = merchantCustomerResponsePagination.getList().stream().map(MerchantCustomerResponse::getYqMerchantId).collect(Collectors.toList());
            rpcRequest.setMerchantNoList(yqMerchantNoList);
            List<StaffCountRpcResponse> staffCountList = staffService.selectStaffCount(rpcRequest);
            return buildPageResponse(serviceMerchantRopList, merchantCustomerResponsePagination,staffCountList);
        } catch (Exception e) {
            log.error("=====分页查询客户列表 exception:{}", e.getMessage(), e);
            return RopResponse.error("分页查询客户列表失败");
        }
    }


    private RopResponse<RpcPagination<MerchantCustomerPageResponse>> buildPageResponse(List<ServiceMerchantRopResponse> serviceMerchantRopList,
                                                                                       RpcPagination<MerchantCustomerResponse> merchantCustomerResponse,
                                                                                       List<StaffCountRpcResponse> staffCountList) {
        RpcPagination<MerchantCustomerPageResponse> responseRpcPagination = new RpcPagination<>();
        responseRpcPagination.setPageSize(merchantCustomerResponse.getPageSize());
        responseRpcPagination.setTotal(merchantCustomerResponse.getTotal());
        responseRpcPagination.setPageNum(merchantCustomerResponse.getPageNum());
        responseRpcPagination.setPages(merchantCustomerResponse.getPages());
        responseRpcPagination.setEndRow(merchantCustomerResponse.getEndRow());
        responseRpcPagination.setStartRow(merchantCustomerResponse.getStartRow());
        List<MerchantCustomerPageResponse> responseList = Lists.newArrayList();

        Map<Integer, List<StaffCountRpcResponse>> staffCountByMerNo = staffCountList.stream().collect(Collectors.groupingBy(StaffCountRpcResponse::getMerchantNo));

        List<MerchantCustomerResponse> list = merchantCustomerResponse.getList();
        for (MerchantCustomerResponse customerResponse : list) {
            for (ServiceMerchantRopResponse merchantRopResponse : serviceMerchantRopList) {
                if (Objects.equals(customerResponse.getShopMerchantId(), merchantRopResponse.getMerchantNo())) {
                    MerchantCustomerPageResponse merchantCustomerPageResponse = buildMerchantCustomerPageResponse(merchantRopResponse, customerResponse,staffCountByMerNo);
                    responseList.add(merchantCustomerPageResponse);
                }
            }
        }
        responseRpcPagination.setList(responseList);
        // 封装商户开通的业务场景
        List<Integer> merchantIds = responseList.stream().map(MerchantCustomerPageResponse::getMerchantId).collect(Collectors.toList());
        ActivityMerchantRpcRequest request = new ActivityMerchantRpcRequest();
        request.setMerchantId(merchantIds);
        List<ActivityOpenedByMerchantRpcResponse> sceneList= activityService.findOpenedActivityByMerchantIds(request);
        sceneList.forEach(v-> responseList.forEach(x->{
            if (v.getMerchantId().equals(x.getMerchantId())){
                x.setSceneList(v.getSceneCodeList());
            }
        }));
        return RopResponse.success(responseRpcPagination);
    }

    private MerchantCustomerPageResponse buildMerchantCustomerPageResponse(ServiceMerchantRopResponse serviceMerchantRopResponse,
                                                                           MerchantCustomerResponse merchantCustomerResponse,
                                                                           Map<Integer, List<StaffCountRpcResponse>> staffCountByMerNo) {
        MerchantCustomerPageResponse merchantCustomerPageResponse = new MerchantCustomerPageResponse();
        merchantCustomerPageResponse.setMerchantName(serviceMerchantRopResponse.getMerchantName());
        merchantCustomerPageResponse.setMerchantId(serviceMerchantRopResponse.getMerchantNo());
        merchantCustomerPageResponse.setContactName(serviceMerchantRopResponse.getMerchantLegalPerson());
        merchantCustomerPageResponse.setPhone(serviceMerchantRopResponse.getMerchantLegalPersonPhone());
        merchantCustomerPageResponse.setServiceCenterMerchantId(merchantCustomerResponse.getYqMerchantId());
        merchantCustomerPageResponse.setServiceCenterMerchantName(merchantCustomerResponse.getYqMerchantName());
        merchantCustomerPageResponse.setCreatedDate(merchantCustomerResponse.getCreatedDate());
        merchantCustomerPageResponse.setSceneList(serviceMerchantRopResponse.getSceneIdList());
        merchantCustomerPageResponse.setEmployeeNum(serviceMerchantRopResponse.getStaffCount());
        List<StaffCountRpcResponse> list = staffCountByMerNo.get(merchantCustomerResponse.getYqMerchantId());
        merchantCustomerPageResponse.setTechnicianCount(CollectionUtils.isEmpty(list) ? 0 :list.get(0).getStaffCount());
        return merchantCustomerPageResponse;
    }


    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.save", needInSession= NeedInSessionType.YES)
    @ApiOperation("保存客户信息")
    public RopResponse<Boolean> save(MerchantCustomInfoSaveRequest request) {
        try {
            final String requestMethod = "dj.api.businessAssistant.merchantCustomer.duplicate";
            CommonProxyRequest proxyRequest = new CommonProxyRequest();
            proxyRequest.setRequestMethod(requestMethod);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
            LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
            MultiValueMap<String, String> queryDuplicateParams = new LinkedMultiValueMap<>();
            queryDuplicateParams.add("partnerMerchantId", loginUser.getMerchantId().toString());
            queryDuplicateParams.add("shopMerchantName", request.getMerchantName());
            proxyRequest.setParams(queryDuplicateParams);
            RpcResponse<ProxyBaseResponse> queryDuplicate = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!queryDuplicate.hasResult()) {
                log.error("提交客户开店申请失败,查询客户是否重复失败:{}", queryDuplicate.getMessage());
                return RopResponse.error("提交客户开店申请失败,查询同名商户失败");
            }
            RopResponse<Boolean> queryDuplicateRopResponse = CommonUtil.convertRopResponseBean(queryDuplicate, Boolean.class);
            if (Objects.equals(true, queryDuplicateRopResponse.getData())) {
                log.error("提交客户开店申请失败,存在重复的客户,partnerMerchantId:{}, shopMerchantName:{}",
                        loginUser.getMerchantId().toString(), request.getMerchantName());
                return RopResponse.error("存在同名商户,请确认后重新输入");
            }
            //提交开店申请
            RpcResponse<ProxyBaseResponse> responseDiJia = createMerchantReview(request, loginUser);
            if (!responseDiJia.hasResult()) {
                log.error("提交客户开店申请失败,调用智享车生活接口失败,param:{}", request.toString());
                return RopResponse.error("提交客户开店申请失败");
            }
            return RopResponse.success(true);
        } catch (Exception e) {
            log.error("=====保存客户信息 exception:{}", e.getMessage(), e);
            return RopResponse.error("保存客户信息失败");
        }
    }


    public RpcResponse<ProxyBaseResponse> createMerchantReview(MerchantCustomInfoSaveRequest request, LoginUserInfoResponse loginUser) {
        CommonProxyRequest proxyRequestDiJia = new CommonProxyRequest();
        final String requestMethodDiJia = "dj.api.smartcarlife.createMerchant.review";
        proxyRequestDiJia.setRequestMethod(requestMethodDiJia);
        proxyRequestDiJia.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
        MultiValueMap<String, String> paramsDiJia = new LinkedMultiValueMap<>();
        paramsDiJia.add("merchantName", request.getMerchantName());
        paramsDiJia.add("contactName", request.getContactName());
        paramsDiJia.add("phone", request.getPhone());
        paramsDiJia.add("password", "gl" + request.getPhone());
        //4s店类型商户
        paramsDiJia.add("merchantType", "2");
        //创建来源 1:账户中心 2:SCRM 3:生意助手 4:门店助手 5:服务商saas
        paramsDiJia.add("createdSource", "3");
        paramsDiJia.add("yqMerchantId", request.getServiceCenterMerchantId().toString());
        paramsDiJia.add("partnerMerchantId", loginUser.getMerchantId().toString());
        paramsDiJia.add("createdBy", loginUser.getUuid());
        List<String> sceneList = request.getSceneList();
        for (int i = 0; i < sceneList.size(); i++) {
            byte scene = CommonConstant.sceneCodeMap.get(sceneList.get(i));
            String param = "sceneList" + "[" + i + "]";
            paramsDiJia.add(param, String.valueOf(scene));
        }
        int productCodeSize = request.getProductCodeList().size();
        for (int i = 0; i < productCodeSize; i++) {
            String param = "productCodeList" + "[" + i + "]";
            paramsDiJia.add(param, String.valueOf(request.getProductCodeList().get(i)));
        }
        paramsDiJia.add("longitude", request.getLongitude().toString());
        paramsDiJia.add("latitude", request.getLatitude().toString());
        paramsDiJia.add("provinceCode", request.getProvinceCode());
        paramsDiJia.add("provinceName", request.getProvinceName());
        paramsDiJia.add("cityCode", request.getCityCode());
        paramsDiJia.add("cityName", request.getCityName());
        paramsDiJia.add("merchantAddress", request.getMerchantAddress());
        List<MerchantBrandRequest> merchantBrandList;
        try {
            merchantBrandList = JSONArray.parseArray(request.getMerchantBrandJson(), MerchantBrandRequest.class);
        } catch (Exception e) {
            log.error("创建客户失败,解析品牌json异常:{}", e.getMessage(), e);
            return RpcResponse.error(e);
        }

        for (int i = 0; i < merchantBrandList.size(); i++) {
            MerchantBrandRequest merchantBrandRequest = merchantBrandList.get(i);
            MerchantBrandIdAndNameRequest firstBrandDetail = merchantBrandRequest.getMerchantFirstBrandDetail();
            List<MerchantBrandIdAndNameRequest> merchantBrandDetailList = merchantBrandRequest.getMerchantSecondBrandDetailList();
            String param = "merchantBrandList" + "[" + i + "]";
            paramsDiJia.add(param + ".merchantFirstBrandDetail.id", firstBrandDetail.getId().toString());
            paramsDiJia.add(param + ".merchantFirstBrandDetail.name", firstBrandDetail.getName());
            for (int j = 0; j < merchantBrandDetailList.size(); j++) {
                String brandIdParam = param + ".merchantSecondBrandDetailList" + "[" + j + "]" + ".id";
                String brandNameParam = param + ".merchantSecondBrandDetailList" + "[" + j + "]" + ".name";
                paramsDiJia.add(brandIdParam, merchantBrandDetailList.get(j).getId().toString());
                paramsDiJia.add(brandNameParam, merchantBrandDetailList.get(j).getName());
            }
        }
        //驻店负责人
        addResidentManagerParam(paramsDiJia, request.getResidentManager());

        proxyRequestDiJia.setParams(paramsDiJia);
        return commonProxyRemote.proxyRequest2(proxyRequestDiJia);
    }

    private void addResidentManagerParam(MultiValueMap<String, String> paramsDiJia, ServiceMerchantStaffAllocation residentManager) {
        if (Objects.nonNull(residentManager)) {
            String userId = residentManager.getUserId();
            Byte userType = residentManager.getUserType();
            String userName = residentManager.getUserName();
            String userNum = residentManager.getUserNum();
            if (Objects.nonNull(userId)) {
                paramsDiJia.add("residentManager.userId", userId);
            }
            if (Objects.nonNull(userType)) {
                paramsDiJia.add("residentManager.userType", userType.toString());
            }
            if (Objects.nonNull(userName)) {
                paramsDiJia.add("residentManager.userName", userName);
            }
            if (Objects.nonNull(userNum)) {
                paramsDiJia.add("residentManager.userNum", userNum);
            }
        }
    }

    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.update", needInSession= NeedInSessionType.YES)
    @ApiOperation("更新客户信息")
    public RopResponse<Boolean> update(MerchantCustomInfoUpdateRequest request) {
        try {
            LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
            if (!Objects.equals(request.getOldMerchantName(), request.getMerchantName())) {
                final String requestMethod = "dj.api.businessAssistant.merchantCustomer.duplicate";
                CommonProxyRequest proxyRequest = new CommonProxyRequest();
                proxyRequest.setRequestMethod(requestMethod);
                proxyRequest.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
                MultiValueMap<String, String> queryDuplicateParams = new LinkedMultiValueMap<>();
                queryDuplicateParams.add("partnerMerchantId", loginUser.getMerchantId().toString());
                queryDuplicateParams.add("shopMerchantName", request.getMerchantName());
                proxyRequest.setParams(queryDuplicateParams);
                RpcResponse<ProxyBaseResponse> queryDuplicate = commonProxyRemote.proxyRequest2(proxyRequest);
                if (!queryDuplicate.hasResult()) {
                    log.error("更新客户信息,查询客户是否重复失败:{}", queryDuplicate.getMessage());
                    return RopResponse.error("更新客户信息失败");
                }
                RopResponse<Boolean> queryDuplicateRopResponse = CommonUtil.convertRopResponseBean(queryDuplicate, Boolean.class);
                if (Objects.equals(true, queryDuplicateRopResponse.getData())) {
                    log.error("更新客户信息失败,存在重复的客户,partnerMerchantId:{}, merchantName:{}",
                            loginUser.getMerchantId().toString(), request.getMerchantName());
                    return RopResponse.error("存在同名商户,请确认后重新输入");
                }
            }

            RpcResponse<ProxyBaseResponse> response = updateMerchant(request, loginUser);
            if (!response.hasResult()) {
                log.error("更新客户信息,账户中心修改服务中心商户信息失败:{}", response.getMessage());
                return RopResponse.error("更新客户信息失败");
            }
            RopResponse<Boolean> responseString = CommonUtil.convertRopResponseBean(response, Boolean.class);
            if (Objects.equals(responseString.getData(), false)) {
                log.error("更新客户信息,账户中心修改商户信息失败,返回结果错误");
                return RopResponse.error("更新客户信息失败");
            }
            CommonProxyRequest proxyRequestDiJia = new CommonProxyRequest();
            final String requestMethodDiJia = "dj.api.businessAssistant.merchantCustomer.update";
            proxyRequestDiJia.setRequestMethod(requestMethodDiJia);
            proxyRequestDiJia.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
            MultiValueMap<String, String> paramsDiJia = new LinkedMultiValueMap<>();
            paramsDiJia.add("shopMerchantId", request.getMerchantId().toString());
            paramsDiJia.add("yqMerchantId", request.getServiceCenterMerchantId().toString());
            paramsDiJia.add("partnerMerchantId", loginUser.getMerchantId().toString());
            paramsDiJia.add("updatedBy", loginUser.getUuid());
            List<String> sceneList = request.getSceneList();
            for (int i = 0; i < sceneList.size(); i++) {
                byte scene = CommonConstant.sceneCodeMap.get(sceneList.get(i));
                String param = "sceneList" + "[" + i + "]";
                paramsDiJia.add(param, String.valueOf(scene));
            }
            //驻店负责人
            addResidentManagerParam(paramsDiJia, request.getResidentManager());
            proxyRequestDiJia.setParams(paramsDiJia);
            RpcResponse<ProxyBaseResponse> responseDiJia = commonProxyRemote.proxyRequest2(proxyRequestDiJia);
            if (!responseDiJia.hasResult()) {
                log.error("更新客户信息,修改智享车生活商户信息失败:{}", response.getMessage());
                return RopResponse.error("更新客户信息失败");
            }

            // 开通业务产品
            MerchantProductsRopRequest rpcRequest = new MerchantProductsRopRequest();
            rpcRequest.setMerchantId(request.getMerchantId());
            rpcRequest.setProductCodeList(request.getProductCodeList());
            rpcRequest.setMerchantName(request.getMerchantName());
            activityService.openProductList(rpcRequest);
            return CommonUtil.convertRopResponseBean(responseDiJia, Boolean.class);
        } catch (Exception e) {
            log.error("=====更新客户信息 exception:{}", e.getMessage(), e);
            return RopResponse.error("更新客户信息失败");
        }
    }

    public RpcResponse<ProxyBaseResponse> updateMerchant(MerchantCustomInfoUpdateRequest request, LoginUserInfoResponse loginUser) {
        final String updateMerchantRequestMethod = "merchants.api.open.serviceCenter.updateMerchant";
        CommonProxyRequest proxyRequest = new CommonProxyRequest();
        proxyRequest.setRequestMethod(updateMerchantRequestMethod);
        proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        //账户类型、账户等级
        params.add("merchantNo", request.getMerchantId().toString());
        params.add("merchantName", request.getMerchantName());
        params.add("merchantLegalPerson", request.getContactName());
        params.add("merchantLegalPersonPhone", request.getPhone());
        params.add("updatedAccount", loginUser.getAccountName());
        //商户地址
        params.add("lng", request.getLongitude().toString());
        params.add("lat", request.getLatitude().toString());
        params.add("provinceCode", request.getProvinceCode());
        params.add("provinceName", request.getProvinceName());
        params.add("cityCode", request.getCityCode());
        params.add("cityName", request.getCityName());
        params.add("merchantAddress", request.getMerchantAddress());
        //主营品牌
        List<cn.com.glsx.merchants.model.request.MerchantBrandRequest> merchantBrandRequestList = Lists.newArrayList();
        List<MerchantBrandRequest> merchantBrandList;
        try {
            merchantBrandList = JSONArray.parseArray(request.getMerchantBrandJson(), MerchantBrandRequest.class);
        } catch (Exception e) {
            log.error("创建客户失败,解析品牌json异常:{}", e.getMessage(), e);
            return RpcResponse.error(e);
        }
        for (MerchantBrandRequest merchantBrandRequestDTO : merchantBrandList) {
            cn.com.glsx.merchants.model.request.MerchantBrandRequest merchantBrandRequest = new cn.com.glsx.merchants.model.request.MerchantBrandRequest();
            //一级品牌
            merchantBrandRequest.setCars(merchantBrandRequestDTO.getMerchantFirstBrandDetail().getId());
            //二级品牌
            List<Integer> secondBrandIdList = merchantBrandRequestDTO.getMerchantSecondBrandDetailList().stream()
                    .map(MerchantBrandIdAndNameRequest::getId).collect(Collectors.toList());
            merchantBrandRequest.setMerchantBrandId(secondBrandIdList);
            merchantBrandRequestList.add(merchantBrandRequest);
        }
        params.add("merchantBrandListJson", JSONArray.toJSONString(merchantBrandRequestList));
        proxyRequest.setParams(params);
        return commonProxyRemote.proxyRequest2(proxyRequest);
    }

    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.employee.list", needInSession= NeedInSessionType.YES)
    @ApiOperation("查询客户销售顾问列表")
    public RopResponse<List<MerchantCustomerEmployeePageResponse>> employeeList(MerchantCustomEmployeePageRequest request) {
        try {
            List<MerchantCustomerEmployeePageResponse> resultList = new ArrayList<>();
            BusiMerchantStaffRequest staffRequest = new BusiMerchantStaffRequest();
            staffRequest.setMerchantNoList(Arrays.asList(request.getMerchantId()));
            List<MerchantStaffResponse> staffList = staffService.getMerchantStaff(staffRequest);
            if (!CollectionUtils.isEmpty(staffList)){
                staffList.forEach(v->{
                    MerchantCustomerEmployeePageResponse response = new MerchantCustomerEmployeePageResponse();
                    BeanUtils.copyProperties(v,response);
                    response.setEmployeeName(v.getStaffName());
                    response.setPhone(v.getStaffPhone());
                    response.setCreatedDate(v.getCreatedTime());
                    response.setMerchantCustomerName(v.getMerchantName());
                    response.setStaffUuid(v.getUuid());
                    response.setWeChatAvatarUrl(v.getWeChatAvatarUrl());
                    resultList.add(response);
                });
            }
            return RopResponse.success(resultList);
        } catch (Exception e) {
            log.error("=====查询客户销售顾问列表 exception:{}", e.getMessage(), e);
            return RopResponse.error("查询客户销售顾问列表失败");
        }
    }


    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.listByServiceCenterMerchantId", needInSession= NeedInSessionType.YES)
    @ApiOperation("查询服务中心中下的所有客户")
    public RopResponse<List<MerchantCustomerPageResponse>> listByServiceCenterMerchantId(MerchantCustomListRequest request) {
        try {
            final String requestMethodMerchant = "dj.api.scenemerchantref.query4SRefByYqShop";
            CommonProxyRequest proxyRequestMerchant = new CommonProxyRequest();
            proxyRequestMerchant.setRequestMethod(requestMethodMerchant);
            proxyRequestMerchant.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
            MultiValueMap<String, String> paramsMerchant = new LinkedMultiValueMap<>();
            paramsMerchant.add("merchantId", request.getServiceCenterMerchantId().toString());
            proxyRequestMerchant.setParams(paramsMerchant);
            RpcResponse<ProxyBaseResponse> responseMerchant = commonProxyRemote.proxyRequest2(proxyRequestMerchant);
            if (responseMerchant.isFailed()) {
                log.error("查询服务中心中下的所有客户,查询失败:{}", responseMerchant.getMessage());
                return RopResponse.error("查询服务中心中下的所有客户失败");
            }
            if (Objects.isNull(responseMerchant.getResult())) {
                log.info("查询服务中心中下的所有客户,查询结果为空");
                return RopResponse.success(Lists.newArrayList());
            }
            List<MerchantCustomerPageResponse> serviceMerchantRopList = null;
            try {
                serviceMerchantRopList = responseMerchant.getResult().getList(MerchantCustomerPageResponse.class);
            } catch (Exception e) {
                log.error("查询服务中心中下的所有客户,解析查询结果异常:{}", e.getMessage());
                return RopResponse.error("查询服务中心中下的所有客户失败");
            }
            return RopResponse.success(serviceMerchantRopList);
        } catch (Exception e) {
            log.error("=====查询服务中心中下的所有客户 exception:{}", e.getMessage(), e);
            return RopResponse.error("查询服务中心中下的所有客户失败");
        }
    }

    @ServiceMethod(method="scrm.api.busassistant.merchantCustomer.inviteCode", needInSession= NeedInSessionType.YES)
    @ApiOperation("创建邀请销售顾问二维码")
    public RopResponse<InviteStaffUrlRopResponse> getInviteStaffQRCode(InviteQRCodeRopRequest request){
        try {
            return RopResponse.success(staffService.getInviteStaffQRCode(request));
        } catch (RpcServiceException e) {
            log.info("=======BusinessAssistantActivityControllerr__invoke__inviteCode__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }


}