MerchantServiceCenterController.java 38.8 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
package cn.com.glsx.busassistant.controller;

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

import cn.com.glsx.dj.smartcarlife.dto.ShopSettingDTO;
import cn.com.glsx.dj.smartcarlife.model.ServiceMerchantStaffAllocation;
import cn.com.glsx.dj.smartcarlife.remote.ServiceMerchantRemote;
import cn.com.glsx.dj.smartcarlife.util.DateUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.oreframework.boot.autoconfigure.rop.util.RopThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;

import cn.com.glsx.busassistant.converter.MerchantServiceCenterPageResponseConvert;
import cn.com.glsx.busassistant.request.DefaultRequest;
import cn.com.glsx.busassistant.request.ListByServiceMerchantIdRequest;
import cn.com.glsx.busassistant.request.MerchantsServiceCenterSaveRequest;
import cn.com.glsx.busassistant.request.MerchantsServiceCenterUpdateRequest;
import cn.com.glsx.busassistant.request.common.SearchPageRequest;
import cn.com.glsx.busassistant.request.merchant.MerchantIdRequest;
import cn.com.glsx.busassistant.request.serviceCenter.CreateMerchantReviewPageRequest;
import cn.com.glsx.busassistant.request.serviceCenter.MerchantBrandIdAndNameRequest;
import cn.com.glsx.busassistant.request.serviceCenter.MerchantBrandRequest;
import cn.com.glsx.busassistant.response.CarbrandResponse;
import cn.com.glsx.busassistant.response.CreateMerchantReviewResponse;
import cn.com.glsx.busassistant.response.MerchantServiceCenterPageResponse;
import cn.com.glsx.busassistant.response.ServiceMerchantRopResponse;
import cn.com.glsx.busassistant.response.YqPartnerMerchantResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantInfoRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantRopResponse;
import cn.com.glsx.busassistant.util.CommonUtil;
import cn.com.glsx.dj.smartcarlife.dto.businessassistant.MerchantServiceCenterDTO;
import cn.com.glsx.dj.smartcarlife.model.MerchantSubRef;
import cn.com.glsx.dj.smartcarlife.remote.MerchantServiceCenterRemote;
import cn.com.glsx.dj.smartcarlife.remote.MerchantSubRefRemote;
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.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.proxy.remote.merchant.MerchantRemote;
import cn.com.glsx.scrm.system.model.wechatapplets.LoginUserInfoResponse;
import cn.hutool.extra.pinyin.PinyinUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("生意助手-服务中心管理")
public class MerchantServiceCenterController {
    @Autowired
    private CommonProxyRemote commonProxyRemote;
    @Autowired
    private MerchantRemote merchantRemote;
    @Autowired
    private MerchantServiceCenterRemote merchantServiceCenterRemote;
    @Autowired
    private MerchantSubRefRemote merchantSubRefRemote;
    @Autowired
    private ServiceMerchantRemote serviceMerchantRemote;

    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.page", needInSession= NeedInSessionType.YES)
    @ApiOperation("分页查询服务中心列表")
    public RopResponse<RpcPagination<MerchantServiceCenterPageResponse>> page(SearchPageRequest request) {
        try {
            final String requestMethod = "dj.api.businessAssistant.serviceCenter.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(request.getQuerySubRef() != null) {
                params.add("querySubRef", request.getQuerySubRef().toString());
            }
            if (Objects.equals(loginUser.getIsSuper(), true)) {
                params.remove("partnerMerchantId");
            }
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!response.isSuccess()) {
                log.error("分页查询服务中心列表失败:{}", response.getMessage());
                return RopResponse.error("分页查询服务中心列表失败");
            }
            RpcPagination<YqPartnerMerchantResponse> yqPartnerMerchantResponseList = RpcPagination.copyPage(response.getResult().getPageFromRpcPagination(YqPartnerMerchantResponse.class));
            if (Objects.isNull(yqPartnerMerchantResponseList) || CollectionUtils.isEmpty(yqPartnerMerchantResponseList.getList())) {
                log.info("分页查询智享车生活服务中心结果为空");
                return RopResponse.success(new RpcPagination<>());
            }
            List<YqPartnerMerchantResponse> list = yqPartnerMerchantResponseList.getList();
            List<Integer> merchantNoList = list.stream().map(YqPartnerMerchantResponse::getYqMerchantId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(list)) {
                log.info("分页查询智享车生活服务中心数据,商户列表为空");
                return RopResponse.success(new RpcPagination<>());
            }
            final String requestMethodMerchant = "merchants.api.open.serviceCenter.merchantPage";
            CommonProxyRequest proxyRequestMerchant = new CommonProxyRequest();
            proxyRequestMerchant.setRequestMethod(requestMethodMerchant);
            proxyRequestMerchant.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
            MultiValueMap<String, String> paramsMerchant = new LinkedMultiValueMap<>();

            for (int i = 0; i < merchantNoList.size(); i++) {
                String param = "merchantNoList" + "[" + i + "]";
                paramsMerchant.add(param, merchantNoList.get(i).toString());
            }
            paramsMerchant.add("pageNum", "1");
            paramsMerchant.add("pageSize", "1000");
            proxyRequestMerchant.setParams(paramsMerchant);
            RpcResponse<ProxyBaseResponse> responseMerchant = commonProxyRemote.proxyRequest2(proxyRequestMerchant);
            if (!responseMerchant.hasResult()) {
                log.error("分页查询服务中心列表失败:{}",responseMerchant.getMessage());
                return RopResponse.error("分页查询服务中心列表失败");
            }
            List<ServiceMerchantRopResponse> serviceMerchantRopList = responseMerchant.getResult().getPage(ServiceMerchantRopResponse.class);
            RpcPagination<MerchantServiceCenterPageResponse> responseRpcPagination = new RpcPagination<>();
            responseRpcPagination.setPageSize(yqPartnerMerchantResponseList.getPageSize());
            responseRpcPagination.setTotal(yqPartnerMerchantResponseList.getTotal());
            responseRpcPagination.setPageNum(yqPartnerMerchantResponseList.getPageNum());
            responseRpcPagination.setPages(yqPartnerMerchantResponseList.getPages());
            responseRpcPagination.setEndRow(yqPartnerMerchantResponseList.getEndRow());
            responseRpcPagination.setStartRow(yqPartnerMerchantResponseList.getStartRow());
            List<MerchantServiceCenterPageResponse> responseList = Lists.newArrayList();

            for (YqPartnerMerchantResponse yqPartnerMerchantResponse : list) {
                for (ServiceMerchantRopResponse serviceMerchantRopResponse : serviceMerchantRopList) {
                    if (Objects.equals(yqPartnerMerchantResponse.getYqMerchantId(), serviceMerchantRopResponse.getMerchantNo())) {
                        MerchantServiceCenterPageResponse merchantServiceCenterPageResponse = MerchantServiceCenterPageResponseConvert.INSTANCE
                                .toMerchantServiceCenterPageResponse(serviceMerchantRopResponse);
                        merchantServiceCenterPageResponse.setCreatedDate(yqPartnerMerchantResponse.getCreatedDate());
                        responseList.add(merchantServiceCenterPageResponse);
                    }
                }
            }
            responseRpcPagination.setList(responseList);
            return RopResponse.success(responseRpcPagination);
        } catch (Exception e) {
            log.error("=====分页查询服务中心列表 exception:{}", e.getMessage(), e);
            return RopResponse.error("分页查询服务中心列表失败");
        }
    }

    private List<Integer> getSubPartnerMerchant(Integer merchantId){
		List<Integer> list = new ArrayList<>();
		list.add(merchantId);

		List<MerchantSubRef> subMerchantList = merchantSubRefRemote.getListByMerchantId(merchantId).getResult();
		if(CollectionUtils.isNotEmpty(subMerchantList)) {
			list.addAll(subMerchantList.stream().map(item->item.getSubMerchantId()).collect(Collectors.toList()));
		}
		return list;
	}

    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.listByServiceMerchantId", needInSession= NeedInSessionType.YES)
    @ApiOperation("查询服务中心列表")
    public RopResponse<List<MerchantServiceCenterDTO>> listByServiceMerchantId(ListByServiceMerchantIdRequest request) {
        LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
        MerchantServiceCenterDTO condition = new MerchantServiceCenterDTO();
        if (!Objects.equals(loginUser.getIsSuper(), true)) {
        	if(Objects.equals(request.getQuerySubPartner(), true)) {
        		condition.setPartnerMerchantIds(this.getSubPartnerMerchant(loginUser.getMerchantId()));
        	}else {
        		condition.setPartnerMerchantId(loginUser.getMerchantId());
        	}
        }
        RpcResponse<List<MerchantServiceCenterDTO>> res = merchantServiceCenterRemote.listByServiceMerchantId(condition);
        return CommonUtil.convertRopResponse(res);
    }

    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.save", needInSession= NeedInSessionType.YES)
    @ApiOperation("保存服务中心信息")
    public RopResponse<Boolean> save(MerchantsServiceCenterSaveRequest request) {
        try {
            final String requestMethod = "dj.api.businessAssistant.serviceCenter.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("yqMerchantName", 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> responseDiJia = createMerchantReview(request, loginUser);
            if (!responseDiJia.hasResult()) {
                log.error("提交服务中心开店申请失败,调用智享车生活接口失败,param:{}", request.toString());
                return RopResponse.error("提交服务中心开店申请失败");
            }
            return CommonUtil.convertRopResponseBean(responseDiJia, Boolean.class);
        } catch (Exception e) {
            log.error("=====保存服务中心信息 exception:{}", e.getMessage(), e);
            return RopResponse.error("保存服务中心信息失败");
        }
    }

    private RpcResponse<ProxyBaseResponse> createMerchantReview(MerchantsServiceCenterSaveRequest 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", request.getPassword());
        //园区店类型商户
        paramsDiJia.add("merchantType", "1");
        //创建来源 1:账户中心 2:SCRM 3:生意助手 4:门店助手 5:服务商saas
        paramsDiJia.add("createdSource", "3");
        paramsDiJia.add("partnerMerchantId", loginUser.getMerchantId().toString());
        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());
            }
        }
        paramsDiJia.add("createdBy", loginUser.getUuid());
        proxyRequestDiJia.setParams(paramsDiJia);
        return commonProxyRemote.proxyRequest2(proxyRequestDiJia);
    }

    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.update", needInSession= NeedInSessionType.YES)
    @ApiOperation("修改服务中心信息")
    public RopResponse<Boolean> update(MerchantsServiceCenterUpdateRequest request) {
        try {
            LoginUserInfoResponse loginUser = RopThreadLocal.getLoginUser(LoginUserInfoResponse.class);
            if (!Objects.equals(request.getMerchantName(), request.getOldMerchantName())) {
                final String requestMethod = "dj.api.businessAssistant.serviceCenter.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("yqMerchantName", 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.serviceCenter.update";
            proxyRequestDiJia.setRequestMethod(requestMethodDiJia);
            proxyRequestDiJia.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());

            MultiValueMap<String, String> paramsDiJia = new LinkedMultiValueMap<>();
            paramsDiJia.add("yqMerchantId", request.getMerchantId().toString());
            paramsDiJia.add("updatedBy", loginUser.getUuid());
            proxyRequestDiJia.setParams(paramsDiJia);
            RpcResponse<ProxyBaseResponse> responseDiJia = commonProxyRemote.proxyRequest2(proxyRequestDiJia);
            if (!responseDiJia.hasResult()) {
                log.error("修改服务中心信息,智享车生活更新商户失败:{}", responseDiJia.getMessage());
                return RopResponse.error("修改服务中心信息失败");
            }
            return CommonUtil.convertRopResponseBean(responseDiJia, Boolean.class);
        } catch (Exception e) {
            log.error("=====修改服务中心信息 exception:{}", e.getMessage(), e);
            return RopResponse.error("修改服务中心信息失败");
        }
    }

    public  RpcResponse<ProxyBaseResponse> updateMerchant(MerchantsServiceCenterUpdateRequest 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<MerchantBrandRequest> merchantBrandList;
        try {
            merchantBrandList = JSONArray.parseArray(request.getMerchantBrandJson(), MerchantBrandRequest.class);
        } catch (Exception e) {
            log.error("创建客户失败,解析品牌json异常:{}", e.getMessage(), e);
            return RpcResponse.error(e);
        }
        List<cn.com.glsx.merchants.model.request.MerchantBrandRequest> merchantBrandRequestList = Lists.newArrayList();
        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.serviceCenter.init", needInSession= NeedInSessionType.YES)
    @ApiOperation("自动创建服务中心")
    public RopResponse<Boolean> initServiceCenter(AbstractRopRequest request) {
        //查询当前服务商下是否有服务中心,如果没有,默认创建一个
        try {
            final String requestMethod = "dj.api.businessAssistant.serviceCenter.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);
            if (Objects.equals(loginUser.getIsSuper(), true)) {
                log.info("超管无需自动创建服务中心");
                return RopResponse.success(true);
            }
            String partnerMerchantId = loginUser.getMerchantId().toString();
            params.add("partnerMerchantId", partnerMerchantId);
            params.add("querySubRef", "true");
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!response.isSuccess()) {
                log.error("分页查询服务中心列表失败:{}", response.getMessage());
                return RopResponse.error("分页查询服务中心列表失败");
            }
            RpcPagination<YqPartnerMerchantResponse> yqPartnerMerchantResponseList = RpcPagination.copyPage(response.getResult().getPageFromRpcPagination(YqPartnerMerchantResponse.class));
            if (Objects.nonNull(yqPartnerMerchantResponseList) && CollectionUtils.isNotEmpty(yqPartnerMerchantResponseList.getList())) {
                log.info("自动创建服务中心,查询智享车生活服务中心存在数据, partnerMerchantId={}", partnerMerchantId);
                return RopResponse.success(true);
            }
            //查询服务商中心信息
            final String requestMethodMerchant = "merchants.api.open.findMerchantDetailByMerchantNo";
            proxyRequest.setRequestMethod(requestMethodMerchant);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
            MultiValueMap<String, String> paramsMerchant = new LinkedMultiValueMap<>();
            paramsMerchant.add("merchantId", loginUser.getMerchantId().toString());
            proxyRequest.setParams(paramsMerchant);
            RpcResponse<ProxyBaseResponse> responseMerchant = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!responseMerchant.hasResult()) {
                log.error("查询客户销售顾问列表,账户中心查询销售顾问列表失败:{}", responseMerchant.getMessage());
                return RopResponse.error("自动创建服务中心失败");
            }
            MerchantRopResponse ropMerchantResponse = responseMerchant.getResult().getBean(MerchantRopResponse.class);
            if (ropMerchantResponse == null) {
                log.error("查询账户中心服务商信息不存在,partnerMerchantId={}", partnerMerchantId);
                return RopResponse.error("自动创建服务中心失败");
            }
            if (Objects.isNull(ropMerchantResponse.getMerchantLoginPassword()) || Objects.isNull(ropMerchantResponse.getMerchantLegalPerson()) ||
                    Objects.isNull(ropMerchantResponse.getMerchantLegalPersonPhone())
            ) {
                log.error("查询账户中心服务商信息为空,password={}, merchantLegalPerson={}, merchantLegalPersonPhone={}", ropMerchantResponse.getMerchantLoginPassword(),
                        ropMerchantResponse.getMerchantLegalPerson(), ropMerchantResponse.getMerchantLegalPersonPhone());
                return RopResponse.error("自动创建服务中心失败");
            }
            //去账户中心创建默认的服务中心
            final String requestMethodCreateMerchant = "merchants.api.open.serviceCenter.createMerchant";
            proxyRequest.setRequestMethod(requestMethodCreateMerchant);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
            MultiValueMap<String, String> paramsCreateMerchant = new LinkedMultiValueMap<>();
            paramsCreateMerchant.add("merchantName", "总部服务中心");
            paramsCreateMerchant.add("password", ropMerchantResponse.getMerchantLoginPassword());
            if (StringUtils.isEmpty(ropMerchantResponse.getMerchantLegalPerson())) {
                paramsCreateMerchant.add("merchantLegalPerson", "总部员工");
            } else {
                paramsCreateMerchant.add("merchantLegalPerson", ropMerchantResponse.getMerchantLegalPerson());
            }
            paramsCreateMerchant.add("merchantLegalPersonPhone", ropMerchantResponse.getMerchantLegalPersonPhone());
            paramsCreateMerchant.add("createType", "1");
            paramsCreateMerchant.add("createdSource", "3");
            paramsCreateMerchant.add("createdAccount", loginUser.getAccountName());
            //商户地址
            paramsCreateMerchant.add("lng", ropMerchantResponse.getLng().toString());
            paramsCreateMerchant.add("lat", ropMerchantResponse.getLat().toString());
            paramsCreateMerchant.add("provinceCode", ropMerchantResponse.getProvinceCode());
            paramsCreateMerchant.add("provinceName", ropMerchantResponse.getProvinceName());
            paramsCreateMerchant.add("cityCode", ropMerchantResponse.getCityCode());
            paramsCreateMerchant.add("cityName", ropMerchantResponse.getCityName());
            paramsCreateMerchant.add("merchantAddress", ropMerchantResponse.getMerchantAddress());
            //一级品牌
            String merchantBrandCars = ropMerchantResponse.getMerchantBrandCars();
            //二级品牌
            String merchantBrandMain = ropMerchantResponse.getMerchantBrandMain();
            if (!StringUtils.isEmpty(merchantBrandCars)) {
                List<cn.com.glsx.merchants.model.request.MerchantBrandRequest> merchantBrandRequestList = Lists.newArrayList();
                String[] carArray = merchantBrandCars.split(";");
                String[] merchantBrandMainArray = merchantBrandMain.split(";");
                for (int i = 0; i < carArray.length; i++) {
                    cn.com.glsx.merchants.model.request.MerchantBrandRequest merchantBrandRequest = new cn.com.glsx.merchants.model.request.MerchantBrandRequest();
                    merchantBrandRequest.setCars(Integer.valueOf(carArray[i]));
                    String secondBrand = merchantBrandMainArray[i];
                    List<Integer> secondBrandList = Arrays.stream(secondBrand.split(",")).map(Integer::valueOf).collect(Collectors.toList());
                    merchantBrandRequest.setMerchantBrandId(secondBrandList);
                    merchantBrandRequestList.add(merchantBrandRequest);
                }
                paramsCreateMerchant.add("merchantBrandListJson", JSONArray.toJSONString(merchantBrandRequestList));
            }
            proxyRequest.setParams(paramsCreateMerchant);
            RpcResponse<ProxyBaseResponse> createMerchantResponse = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!createMerchantResponse.hasResult()) {
                log.error("自动创建服务中心,账户中心创建商户失败:{}", createMerchantResponse.getMessage());
                return RopResponse.error("自动创建服务中心失败");
            }
            RopResponse<MerchantInfoRopResponse> merchantInfoRopResponse = CommonUtil.convertRopResponseBean(createMerchantResponse, MerchantInfoRopResponse.class);
            Integer yqMerchantId = merchantInfoRopResponse.getData().getMerchantNo();
            if (Objects.isNull(yqMerchantId)) {
                log.error("自动创建服务中心,账户中心创建商户失败,商户号为空");
                return RopResponse.error("自动创建服务中心失败");
            }

            //去嘀加创建服务中心商户,并绑定服务中心与服务商得关联关系
            final String requestMethodDiJia = "dj.api.businessAssistant.serviceCenter.save";
            proxyRequest.setRequestMethod(requestMethodDiJia);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.DJ_SMARTCARLIFE.getSource());
            MultiValueMap<String, String> paramsDiJia = new LinkedMultiValueMap<>();
            paramsDiJia.add("partnerMerchantId", partnerMerchantId);
            paramsDiJia.add("yqMerchantId", yqMerchantId.toString());
            paramsDiJia.add("updatedBy", loginUser.getUuid());
            proxyRequest.setParams(paramsDiJia);
            RpcResponse<ProxyBaseResponse> responseDiJia = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!responseDiJia.hasResult()) {
                log.error("保存服务中心信息,智享车生活创建商户失败:{}", responseDiJia.getMessage());
                return RopResponse.error("保存服务中心信息失败");
            }
            return CommonUtil.convertRopResponseBean(responseDiJia, Boolean.class);
        } catch (Exception e) {
            log.error("=====自动创建服务中心 exception:{}", e.getMessage(), e);
            return RopResponse.error("自动创建服务中心失败");
        }
    }

    @ServiceMethod(method="scrm.api.busassistant.merchant.review.list", needInSession= NeedInSessionType.YES)
    @ApiOperation("查询开店申请列表")
    public RopResponse<RpcPagination<CreateMerchantReviewResponse>> merchantReviewList(CreateMerchantReviewPageRequest request) {
        try {
            final String requestMethod = "dj.api.smartcarlife.createMerchant.review.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);
        /*if (Objects.equals(loginUser.getIsSuper(), false)) {
            params.add("partnerMerchantId", loginUser.getMerchantId().toString());
        }*/
            params.add("partnerMerchantId", loginUser.getMerchantId().toString());
            if (Objects.equals(loginUser.getIsSuper(), true)) {
                params.remove("partnerMerchantId");
            }
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (response.isFailed()) {
                log.error("分页查询开店申请列表:{}", response.getMessage());
                return RopResponse.error("分页查询开店申请列表失败");
            }
            RpcPagination<CreateMerchantReviewResponse> merchantReviewResponseRpcPagination = RpcPagination.copyPage(response.getResult().getPageFromRpcPagination(CreateMerchantReviewResponse.class));
            if (Objects.isNull(merchantReviewResponseRpcPagination) || CollectionUtils.isEmpty(merchantReviewResponseRpcPagination.getList())) {
                log.info("分页查询开店申请列表结果为空");
                return RopResponse.success(new RpcPagination<>());
            }
            return RopResponse.success(merchantReviewResponseRpcPagination);
        } catch (Exception e) {
            log.error("=====查询开店申请列表 exception:{}", e.getMessage(), e);
            return RopResponse.error("查询开店申请列表失败");
        }
    }

    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.merchantInfo", needInSession= NeedInSessionType.YES)
    @ApiOperation("查询商户详情")
    public RopResponse<MerchantRopResponse> merchantInfo(MerchantIdRequest request){
        try {
            final String requestMethod = "merchants.api.open.serviceCenter.merchantInfo";
            CommonProxyRequest proxyRequest = new CommonProxyRequest();
            proxyRequest.setRequestMethod(requestMethod);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.add("merchantNo",request.getMerchantId()+"");
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (response.isFailed()) {
                log.error("查询商户详情:{}", response.getMessage());
                return RopResponse.error("查询商户详情失败");
            }

            RopResponse<MerchantRopResponse> merchantRopResponseRopResponse = CommonUtil.convertRopResponseBean(response, MerchantRopResponse.class);

            //查询4s店店铺负责人
            RpcResponse<ShopSettingDTO> shopSettingResponse = serviceMerchantRemote.getShopSetting(request.getMerchantId(), DateUtils.getMonth(0));
            if (shopSettingResponse.hasResult()) {
                ServiceMerchantStaffAllocation residentManager = shopSettingResponse.getResult().getResidentManager();
                if (Objects.nonNull(residentManager)) {
                    merchantRopResponseRopResponse.getData().setResidentManager(residentManager);
                }
            }
            return merchantRopResponseRopResponse;
        } catch (RpcServiceException e) {
            log.info("=======BusinessAssistantActivityControllerr__invoke__merchantInfo__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    /**
     * 获取车型品牌
     */
    @ServiceMethod(method="scrm.api.busassistant.serviceCenter.getCarbrandTree", needInSession= NeedInSessionType.NO)
    @ApiOperation("获取车型品牌")
    public RopResponse<List<CarbrandResponse>> getCarbrandTree(DefaultRequest defaultRequest) {
        try {
            final String requestMethod = "merchants.api.merchantCommon.getCarbrandTree";
            CommonProxyRequest proxyRequest = new CommonProxyRequest();
            proxyRequest.setRequestMethod(requestMethod);
            proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            proxyRequest.setParams(params);
            RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
            if (!response.hasResult()) {
                log.error("获取车型品牌:{}", response.getMessage());
                return RopResponse.error("获取车型品牌失败");
            }
            RopResponse<List<CarbrandResponse>> ropResponse = CommonUtil.convertRopResponseList(response, CarbrandResponse.class);
            ropResponse.getData().forEach(v->{
                if (!StringUtils.isEmpty(v.getLabel())){
                    String firstLetter = PinyinUtil.getFirstLetter(v.getLabel().charAt(0)) + "";
                    v.setLetter(firstLetter.toUpperCase());
                }
            });
            Collections.sort(ropResponse.getData(), new Comparator<CarbrandResponse>() {
                @Override
                public int compare(CarbrandResponse o1, CarbrandResponse o2) {
                    return o1.getLetter().compareTo(o2.getLetter());
                }
            });
            return ropResponse;
        } catch (RpcServiceException e) {
            log.info("=======MerchantCommonController__invoke__getCarbrandTree__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(),e.getMessage());
        }
    }
}