package com.cool.store.service.impl;


import cn.hutool.core.collection.CollStreamUtil;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.CommonConstants;
import com.cool.store.constants.RedisConstant;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dao.*;
import com.cool.store.entity.*;
import com.cool.store.enums.*;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.WarehouseInfoMapper;
import com.cool.store.request.AuditApproveRequest;
import com.cool.store.request.BuildInformationRequest;
import com.cool.store.request.BuildSettlerRequest;
import com.cool.store.response.BuildInformationResponse;
import com.cool.store.service.*;
import com.cool.store.utils.RedisConstantUtil;
import com.cool.store.utils.RedisUtilPool;
import com.cool.store.utils.poi.StringUtils;
import com.cool.store.utils.poi.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

import static com.cool.store.enums.point.ShopSubStageStatusEnum.*;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_150_5;

/**
 * @author EDY
 * @description 针对表【xfsg_build_information(建店资料表)】的数据库操作Service实现
 * @createDate 2024-10-09 14:05:52
 */
@Service
@Slf4j
public class BuildInformationServiceImpl implements BuildInformationService {
    @Resource
    private  PlatformBuildDAO platformBuildDAO;
    @Resource
    private EnumInfoService enumInfoService;
    @Resource
    private RedisConstantUtil redisConstantUtil;
    @Resource
    private RedisUtilPool redisUtilPool;
    @Resource
    private WarehouseInfoMapper warehouseInfoMapper;
    @Resource
    private UserAuthMappingService userAuthMappingService;
    @Resource
    private BuildInformationDAO buildInformationDAO;
    @Autowired
    private ShopStageInfoDAO shopStageInfoDAO;
    @Autowired
    private PointInfoDAO pointInfoDAO;
    @Autowired
    private ShopInfoDAO shopInfoDAO;
    @Resource
    PreparationService preparationService;
    @Autowired
    private QualificationsInfoDAO qualificationsInfoDAO;
    @Resource
    private LineInfoDAO lineInfoDAO;
    @Resource
    private CommonService commonService;
    @Autowired
    private OrderSysInfoDAO orderSysInfoDAO;
    @Autowired
    private BigRegionDAO bigRegionDAO;
    @Resource
    private AcceptanceInfoDAO acceptanceInfoDAO;
    @Resource
    private OperationLogService operationLogService;
    @Resource
    private EnterpriseUserDAO enterpriseUserDAO;
    @Resource
    private ShopAuditInfoDAO shopAuditInfoDAO;
    @Resource
    private OperationLogDAO operationLogDAO;
    @Autowired
    private RegionDao regionDao;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer submitOrUpdate(BuildInformationRequest request, String userId, String userName) {
        log.info("提交/修改建店资料开始,shopId:{}", JSONObject.toJSONString(request));
        String lockKey = redisConstantUtil.submitBuildKey(request.getShopId());
        String lockValue = UUID.randomUUID().toString();
        boolean acquired = false;
        try {
            acquired = redisUtilPool.setNxExpire(lockKey, lockValue, CommonConstants.TEN_SECONDS);
            if (Boolean.TRUE.equals(acquired)) {
                ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId());
//                if (JoinModeEnum.FLAGSHIP_STORE.getCode()!=shopInfoDO.getJoinMode()){
//                    log.info("FLAGSHIP_STORE：{}，{}，{}，{}，{}，{}，{}",request.getSettlerName(),request.getSettlerIdCardFront(),
//                            request.getSettlerInHandFrontPicture(),request.getSettlerBankBackPhotoUrl(),
//                            request.getSettlerBankNumber(),request.getSettlerBankMobile(),request.getSettlerBankName());
//                    //校验结算人非空
//                    if (StringUtils.isAnyBlank(request.getSettlerName(),request.getSettlerIdCardFront(),
//                            request.getSettlerInHandFrontPicture(),request.getSettlerBankBackPhotoUrl(),
//                            request.getSettlerBankNumber(),request.getSettlerBankMobile(),request.getSettlerBankName())) {
//                        throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
//                    }
//                }

                BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(request.getShopId());
                BuildInformationDO buildInformationDO = request.toDO();
                OrderSysInfoDO orderSysInfoDO = getOrderSysInfoDO(request);
                OrderSysInfoDO orderSysInfoDO1 = orderSysInfoDAO.selectByShopId(request.getShopId());
                if (Objects.nonNull(orderSysInfoDO1)) {
                    orderSysInfoDAO.updateByShopId(orderSysInfoDO);
                } else {
                    orderSysInfoDAO.insertSelective(orderSysInfoDO);
                }
                LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
                QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineInfoDO.getId());
                if (request.getJuridicalIsSamePartner()) {
                    buildInformationDO.setJuridicalName(lineInfoDO.getUsername());
                    buildInformationDO.setJuridicalIdCardNo(qualificationsInfoDO.getIdCardNo());
                    buildInformationDO.setJuridicalIdCardFront(qualificationsInfoDO.getFrontOfIdCard());
                    buildInformationDO.setJuridicalIdCardReverse(qualificationsInfoDO.getBackOfIdCard());
                }
                if (request.getSettlerIsSamePartner()!=null&&request.getSettlerIsSamePartner()) {
                    buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo());
                    buildInformationDO.setSettlerName(lineInfoDO.getUsername());
                    buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard());
                    buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard());
                }
                // 存在运营顾问审批不通过重新编辑的情况，所以这里判断一下是否存在未处理的审批记录，不存在则添加审批记录
                insertOperations(shopInfoDO, userId, userName);
                if (Objects.isNull(informationDO)) {
                    buildInformationDO.setCreateTime(new Date());
                    buildInformationDO.setUpdateTime(new Date());
                    shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_150_5);
                    HashMap<String, String> map = new HashMap<>();
                    map.put("partnerUsername", lineInfoDO.getUsername());
                    map.put("partnerMobile", lineInfoDO.getMobile());
                    map.put("storeName", shopInfoDO.getShopName());
                    commonService.sendQWMessage(Collections.singletonList(shopInfoDO.getOperationsConsultant()),
                            MessageEnum.MESSAGE_54,
                            map);
                    return buildInformationDAO.insertSelective(buildInformationDO);
                } else {
                    buildInformationDO.setUpdateTime(new Date());
                    List<PlatformBuildDO> platformBuildDOS = platformBuildDAO.selectByShopId(request.getShopId());
                    if (CollectionUtils.isNotEmpty(platformBuildDOS)){
                        for (PlatformBuildDO platformBuildDO : platformBuildDOS){
                            platformBuildDO.setSettlerName(buildInformationDO.getSettlerName());
                            platformBuildDO.setSettlerIdCardFront(buildInformationDO.getSettlerIdCardFront());
                            platformBuildDO.setSettlerIdCardReverse(buildInformationDO.getSettlerIdCardReverse());
                            platformBuildDO.setSettlerInHandBackPicture(buildInformationDO.getSettlerInHandBackPicture());
                            platformBuildDO.setSettlerInHandFrontPicture(buildInformationDO.getSettlerInHandFrontPicture());
                            platformBuildDO.setSettlerIdCardNo(buildInformationDO.getSettlerIdCardNo());
                            platformBuildDO.setSettlerBankPhotoUrl(buildInformationDO.getSettlerBankPhotoUrl());
                            platformBuildDO.setSettlerBankNumber(buildInformationDO.getSettlerBankNumber());
                            platformBuildDO.setSettlerBankMobile(buildInformationDO.getSettlerBankMobile());
                            platformBuildDO.setSettlerBankName(buildInformationDO.getSettlerBankName());
                        }
                    }
                    platformBuildDAO.batchUpdate(platformBuildDOS);
                    // 运营顾问审批驳回后，走的编辑逻辑，因此判断是否为加盟商驳回后第一次编辑，推进阶段到运营顾问审批
                    ShopStageInfoDO currentStage = shopStageInfoDAO.getByShopIdAndSubStage(shopInfoDO.getId(), ShopSubStageEnum.SHOP_STAGE_15.getShopSubStage());
                    if (SHOP_SUB_STAGE_STATUS_150.getShopSubStageStatus().equals(currentStage.getShopSubStageStatus())) {
                        shopStageInfoDAO.updateShopStageInfo(request.getShopId(), SHOP_SUB_STAGE_STATUS_150_5);
                        shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_150_5);
                        HashMap<String, String> map = new HashMap<>();
                        map.put("partnerUsername", lineInfoDO.getUsername());
                        map.put("partnerMobile", lineInfoDO.getMobile());
                        map.put("storeName", shopInfoDO.getShopName());
                        commonService.sendQWMessage(Collections.singletonList(shopInfoDO.getOperationsConsultant()),
                                MessageEnum.MESSAGE_54,
                                map);
                    }
                    return buildInformationDAO.updateByShopIdSelective(buildInformationDO);
                }
            }else{
                throw  new ServiceException(ErrorCodeEnum.DUPLICATE_SUBMISSION);
            }
        } finally {
            if (Boolean.TRUE.equals(acquired)) {
                String currentValue = redisUtilPool.getString(lockKey);
                if (lockValue.equals(currentValue)) {
                    redisUtilPool.delKey(lockKey);
                }
            }
        }
    }

    private void insertOperations(ShopInfoDO shopInfoDO, String userId, String userName) {
        List<OperationLogDO> operationLogs = operationLogDAO.getBySubStageStatusEnumAndsStatus(shopInfoDO.getId(), SHOP_SUB_STAGE_STATUS_150_5, OperationTypeEnum.OPERATION_TYPE_1.getCode());
        if (CollectionUtils.isEmpty(operationLogs)) {
            EnterpriseUserDO operationsConsultant = enterpriseUserDAO.getUserInfoById(shopInfoDO.getOperationsConsultant());
            // 审批记录
            operationLogService.addOperationLog(shopInfoDO.getId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_150, userId, userName,
                    OperationTypeEnum.OPERATION_TYPE_0, "建店资料提交审批", OperationStatusEnum.PROCESSED);
            operationLogService.addOperationLog(shopInfoDO.getId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_150_5,
                    shopInfoDO.getOperationsConsultant(), Collections.singletonList(operationsConsultant),
                    OperationTypeEnum.OPERATION_TYPE_1, "建店资料运营顾问审核", OperationStatusEnum.NOT_PROCESSED);
        }
    }

    @Override
    public BuildInformationResponse getBuildInformation(Long shopId) {
        BuildInformationResponse response = new BuildInformationResponse();
        ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(shopId);
        if (Objects.isNull(shopInfo)) {
            throw new ServiceException(ErrorCodeEnum.SHOP_NOT_EXIST);
        }
        LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfo.getLineId());
        ShopStageInfoDO shopSubStageInfo = shopStageInfoDAO.getShopSubStageInfo(shopId, ShopSubStageEnum.SHOP_STAGE_15);
        response.setShopSubStageStatus(shopSubStageInfo.getShopSubStageStatus());
        response.setUsername(lineInfoDO.getUsername());
        response.setShopId(shopId);
        response.setShopName(shopInfo.getShopName());
        response.setShopCode(shopInfo.getShopCode());
        response.setProvince(shopInfo.getProvince());
        response.setDistrict(shopInfo.getDistrict());
        response.setCity(shopInfo.getCity());
        response.setTownship(shopInfo.getDetailAddress());
        BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(shopId);
        if (Objects.nonNull(informationDO)) {
            extracted(response, informationDO);
        }
        OrderSysInfoDO orderSysInfoDO = orderSysInfoDAO.selectByShopId(shopId);
        if (Objects.nonNull(orderSysInfoDO)) {
            response.setAddresseeName(orderSysInfoDO.getAddresseeName());
            response.setAddresseeMobile(orderSysInfoDO.getAddresseeMobile());
            response.setXgjVicePresident(orderSysInfoDO.getXgjVicePresident());
            response.setXgjRegionId(orderSysInfoDO.getXgjRegionId());
            response.setXgjRegionName(orderSysInfoDO.getXgjRegionName());
            response.setAddresseeProvince(orderSysInfoDO.getAddresseeProvince());
            response.setAddresseeCity(orderSysInfoDO.getAddresseeCity());
            response.setAddresseeDistrict(orderSysInfoDO.getAddresseeDistrict());
            response.setAddresseeAddress(orderSysInfoDO.getAddresseeAddress());
            response.setDeclareGoodsLogisticsWarehouse(orderSysInfoDO.getDeclareGoodsLogisticsWarehouse());
            response.setDeclareGoodsDate(orderSysInfoDO.getDeclareGoodsDate());
            response.setWarehouseDeliveryDate(orderSysInfoDO.getWarehouseDeliveryDate());
            response.setReceivingFirmName(orderSysInfoDO.getReceivingFirmName());
            response.setReceivingMsBankAccount(orderSysInfoDO.getReceivingMsBankAccount());
            response.setReceivingMsBankBranch(orderSysInfoDO.getReceivingMsBankBranch());
            response.setBankUnionPayAccount(orderSysInfoDO.getBankUnionPayAccount());
            response.setOrderType(orderSysInfoDO.getOrderType());
            response.setOrderRemark(orderSysInfoDO.getOrderRemark());
            WarehouseInfoDO warehouseInfoDO = warehouseInfoMapper.getByCode(orderSysInfoDO.getDeclareGoodsLogisticsWarehouse());
            if (Objects.nonNull(warehouseInfoDO)) {
                response.setDeclareGoodsLogisticsWarehouseName(warehouseInfoDO.getWarehouseName());
            }
            response.setDeclareGoodsType(orderSysInfoDO.getDeclareGoodsType());
        }
        if (StringUtils.isBlank(response.getReceivingFirmName())) {
            String bankInfoStr = redisUtilPool.getString(RedisConstant.BUILD_RECEIVE_BANK_INFO + ":" + shopInfo.getFranchiseBrand());
            if (StringUtils.isBlank(bankInfoStr)) {
                bankInfoStr = redisUtilPool.getString(RedisConstant.BUILD_RECEIVE_BANK_INFO + ":1");
            }
            if (StringUtils.isNotBlank(bankInfoStr)) {
                JSONObject bankInfo = JSONObject.parseObject(bankInfoStr);
                response.setReceivingFirmName(bankInfo.getString("receivingFirmName"));
                response.setReceivingMsBankAccount(bankInfo.getString("receivingMsBankAccount"));
                response.setReceivingMsBankBranch(bankInfo.getString("receivingMsBankBranch"));
                response.setBankUnionPayAccount(bankInfo.getString("bankUnionPayAccount"));
            }
        }
        if (StringUtils.isBlank(response.getXgjVicePresident())) {
            RegionDO region = regionDao.getRegionById(shopInfo.getRegionId());
            if (!Objects.isNull(region)){
                String parentId = region.getParentId();
                RegionDO parentRegion = regionDao.getRegionById(Long.valueOf(parentId));
                if (!Objects.isNull(parentRegion)){
                    String name = parentRegion.getName();
                    if (name != null && name.contains("_")) {
                        String president = name.substring(name.indexOf("_") + 1);
                        response.setXgjVicePresident(president);
                    } else {
                        response.setXgjVicePresident(name);
                    }
                }
            }
        }
        //根据映射关系默认带出新管家组织
        if (StringUtils.isBlank(response.getXgjRegionName())) {
            //2026之后 新管家组织不会根据加盟模式 只有一套
            BigRegionDO bigRegionDO = bigRegionDAO.queryOrgInfoByBigRegionAndJoinMode(shopInfo.getRegionId(), 0);
            if (Objects.nonNull(bigRegionDO)) {
                response.setXgjRegionId(bigRegionDO.getOrgId());
                response.setXgjRegionName(bigRegionDO.getOrgName());
            }
        }
        if (StringUtils.isBlank(response.getAddresseeProvince())) {
            response.setAddresseeProvince(shopInfo.getProvince());
        }
        if (StringUtils.isBlank(response.getAddresseeCity())) {
            response.setAddresseeCity(shopInfo.getCity());
        }
        if (StringUtils.isBlank(response.getAddresseeDistrict())) {
            response.setAddresseeDistrict(shopInfo.getDistrict());
        }
        if (StringUtils.isBlank(response.getAddresseeAddress())) {
            response.setAddresseeAddress(shopInfo.getDetailAddress());
        }
        // 不存在的情况下从装修验收中获取
        if (StringUtils.isBlank(response.getDoorPhoto()) || StringUtils.isBlank(response.getInStorePhoto())) {
            AcceptanceInfoDO acceptanceInfoDO = acceptanceInfoDAO.selectByShopId(shopId);
            if (Objects.nonNull(acceptanceInfoDO)) {
                response.setDoorPhoto(StringUtils.isNotBlank(response.getDoorPhoto()) ? response.getDoorPhoto() : acceptanceInfoDO.getShopDoorwayPhoto());
                response.setInStorePhoto(StringUtils.isNotBlank(response.getInStorePhoto()) ? response.getInStorePhoto() : acceptanceInfoDO.getShopInteriorPhoto());
            }
        }
        return response;

    }

    private static void extracted(BuildInformationResponse response, BuildInformationDO informationDO) {
        response.setShopContactName(informationDO.getShopContactName());
        response.setShopContactMobile(informationDO.getShopContactMobile());
        response.setBusinessHours(informationDO.getBusinessHours());
        response.setBusinessMobile(informationDO.getBusinessMobile());
        response.setDoorPhoto(informationDO.getDoorPhoto());
        response.setInStorePhoto(informationDO.getInStorePhoto());
        response.setJuridicalIdCardFront(informationDO.getJuridicalIdCardFront());
        response.setJuridicalName(informationDO.getJuridicalName());
        response.setJuridicalIdCardNo(informationDO.getJuridicalIdCardNo());
        response.setJuridicalIdCardReverse(informationDO.getJuridicalIdCardReverse());
        response.setJuridicalHandheldIdCardReverse(informationDO.getJuridicalHandheldIdCardReverse());
        response.setJuridicalHandheldIdCardFront(informationDO.getJuridicalHandheldIdCardFront());
        response.setJuridicalHandheldIdCardReverse(informationDO.getJuridicalHandheldIdCardReverse());
        response.setSettlerIdCardNo(informationDO.getSettlerIdCardNo());
        response.setSettlerName(informationDO.getSettlerName());
        response.setSettlerBankPhotoUrl(informationDO.getSettlerBankPhotoUrl());
        response.setSettlerIdCardFront(informationDO.getSettlerIdCardFront());
        response.setSettlerIdCardReverse(informationDO.getSettlerIdCardReverse());
        response.setSettlerBankNumber(informationDO.getSettlerBankNumber());
        response.setSettlerBankMobile(informationDO.getSettlerBankMobile());
        response.setSettlerBankName(informationDO.getSettlerBankName());
        response.setAuthorizationUrl(informationDO.getAuthorizationUrl());
        response.setRelationshipProve(informationDO.getRelationshipProve());
        response.setAccountOpeningPermit(informationDO.getAccountOpeningPermit());
        response.setSettlerInHandFrontPicture(informationDO.getSettlerInHandFrontPicture());
        response.setSettlerInHandBackPicture(informationDO.getSettlerInHandBackPicture());
        response.setMiniProgramsShopName(informationDO.getCShopName());
        response.setSettlerBankBackPhotoUrl(informationDO.getSettlerBankBackPhotoUrl());
        response.setSettlerIsSamePartner(informationDO.getSettlerIsSamePartner());
        response.setJuridicalIsSamePartner(informationDO.getJuridicalIsSamePartner());
    }

    private static @NotNull OrderSysInfoDO getOrderSysInfoDO(BuildInformationRequest request) {
        OrderSysInfoDO orderSysInfoDO = new OrderSysInfoDO();
        orderSysInfoDO.setShopId(request.getShopId());
        orderSysInfoDO.setAddresseeName(request.getAddresseeName());
        orderSysInfoDO.setAddresseeMobile(request.getAddresseeMobile());
        orderSysInfoDO.setAddresseeProvince(request.getAddresseeProvince());
        orderSysInfoDO.setAddresseeCity(request.getAddresseeCity());
        orderSysInfoDO.setAddresseeDistrict(request.getAddresseeDistrict());
        orderSysInfoDO.setAddresseeAddress(request.getAddresseeAddress());
        return orderSysInfoDO;
    }

    @Override
    public Integer getJoinType(Long lineId) {
        QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineId);
        if (Objects.isNull(qualificationsInfoDO)) {
            return null;
        }
        return qualificationsInfoDO.getJoinType();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateBuildSettler(BuildSettlerRequest request,String userId) {
        ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(request.getShopId());
        LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfo.getLineId());
        QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(shopInfo.getLineId());
        BuildInformationDO buildInformationDO = buildInformationDAO.selectOneByShopId(request.getShopId());
        if (request.getSettlerIsSamePartner()) {
            buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo());
            buildInformationDO.setSettlerName(lineInfoDO.getUsername());
            buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard());
            buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard());
        }else{
            buildInformationDO.setSettlerName(request.getSettlerName());
            buildInformationDO.setSettlerIdCardNo(request.getSettlerIdCardNo());
            buildInformationDO.setSettlerIdCardFront(request.getSettlerIdCardFront());
            buildInformationDO.setSettlerIdCardReverse(request.getSettlerIdCardReverse());
        }
        buildInformationDO.setSettlerIsSamePartner(request.getSettlerIsSamePartner());
        buildInformationDO.setSettlerInHandBackPicture(request.getSettlerInHandBackPicture());
        buildInformationDO.setSettlerInHandFrontPicture(request.getSettlerInHandFrontPicture());
        buildInformationDO.setSettlerBankPhotoUrl(request.getSettlerBankPhotoUrl());
        buildInformationDO.setSettlerBankNumber(request.getSettlerBankNumber());
        buildInformationDO.setSettlerBankMobile(request.getSettlerBankMobile());
        buildInformationDO.setSettlerBankName(request.getSettlerBankName());
        buildInformationDO.setSettlerBankBackPhotoUrl(request.getSettlerBankBackPhotoUrl());
        buildInformationDO.setUpdateTime(new Date());
        buildInformationDO.setUpdateUser(userId);
        buildInformationDAO.updateByShopIdSelective(buildInformationDO);
        List<PlatformBuildDO> platformBuildDOS = platformBuildDAO.selectByShopId(request.getShopId());
        if (CollectionUtils.isNotEmpty(platformBuildDOS)){
            for (PlatformBuildDO platformBuildDO : platformBuildDOS){
                platformBuildDO.setSettlerName(buildInformationDO.getSettlerName());
                platformBuildDO.setSettlerIdCardFront(buildInformationDO.getSettlerIdCardFront());
                platformBuildDO.setSettlerIdCardReverse(buildInformationDO.getSettlerIdCardReverse());
                platformBuildDO.setSettlerInHandBackPicture(buildInformationDO.getSettlerInHandBackPicture());
                platformBuildDO.setSettlerInHandFrontPicture(buildInformationDO.getSettlerInHandFrontPicture());
                platformBuildDO.setSettlerIdCardNo(buildInformationDO.getSettlerIdCardNo());
                platformBuildDO.setSettlerBankPhotoUrl(buildInformationDO.getSettlerBankPhotoUrl());
                platformBuildDO.setSettlerBankNumber(buildInformationDO.getSettlerBankNumber());
                platformBuildDO.setSettlerBankMobile(buildInformationDO.getSettlerBankMobile());
                platformBuildDO.setSettlerBankName(buildInformationDO.getSettlerBankName());
            }
        }
        platformBuildDAO.batchUpdate(platformBuildDOS);
        return true;
    }

    @Override
    @Transactional
    public Boolean operationsConsultantAudit(AuditApproveRequest request, LoginUserInfo user) {
        ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(request.getShopId());
        if (shopInfo.getShopDecorationAttributes() == null){
            throw new ServiceException(ErrorCodeEnum.SHOP_DECORATION_ATTRIBUTES_IS_NULL);
        }
        ShopStageInfoDO shopSubStageInfo = shopStageInfoDAO.getShopSubStageInfo(request.getShopId(), ShopSubStageEnum.SHOP_STAGE_15);
        if (!shopSubStageInfo.getShopSubStageStatus().equals(SHOP_SUB_STAGE_STATUS_150_5.getShopSubStageStatus())) {
            throw new ServiceException(ErrorCodeEnum.WORK_FLOW_STAGE_PASS_ERROR);
        }
        if (Constants.ZERO_INTEGER.equals(request.getAuditResult())) {
            shopStageInfoDAO.updateShopStageInfo(request.getShopId(), SHOP_SUB_STAGE_STATUS_150);
        } else {
            shopStageInfoDAO.updateShopStageInfo(request.getShopId(), SHOP_SUB_STAGE_STATUS_151);
            ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId());
            LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
            HashMap<String, String> map = new HashMap<>();
            map.put("partnerUsername", lineInfoDO.getUsername());
            map.put("partnerMobile", lineInfoDO.getMobile());
            map.put("storeName", shopInfoDO.getShopName());
            List<EnterpriseUserDO> logisticsList = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.LOGISTICS, shopInfoDO.getRegionId());
            List<String> logistics = CollStreamUtil.toList(logisticsList, EnterpriseUserDO::getUserId);
            commonService.sendQWMessage(logistics, MessageEnum.MESSAGE_52, map);
        }

        ShopAuditInfoDO shopAuditInfoDO = new ShopAuditInfoDO();
        shopAuditInfoDO.setShopId(request.getShopId());
        shopAuditInfoDO.setAuditType(AuditTypeEnum.BUILDINFORMATION.getCode());
        shopAuditInfoDO.setSubmittedUserId(user.getUserId());
        shopAuditInfoDO.setSubmittedUserName(user.getName());
        shopAuditInfoDO.setResultType(request.getAuditResult() ^ 1);
        if (AuditResultTypeEnum.PASS.getCode().equals(shopAuditInfoDO.getResultType())) {
            shopAuditInfoDO.setPassReason(request.getCause());
        } else {
            shopAuditInfoDO.setRejectReason(request.getCause());
        }
        Long auditId = shopAuditInfoDAO.addAuditInfo(shopAuditInfoDO);
        //更新操作记录
        List<OperationLogDO> operationLogs = operationLogDAO.getBySubStageStatusEnumAndsStatus(request.getShopId(), SHOP_SUB_STAGE_STATUS_150_5, OperationTypeEnum.OPERATION_TYPE_1.getCode());
        operationLogService.batchUpdateProcessed(operationLogs, auditId, user.getUserId(), request.getCause());
        return true;
    }


}




