package com.cool.store.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.CommonConstants;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dao.*;
import com.cool.store.dto.*;
import com.cool.store.dto.region.BigRegionDTO;
import com.cool.store.entity.*;
import com.cool.store.enums.*;
import com.cool.store.enums.point.PayBusinessTypeEnum;
import com.cool.store.enums.point.ShopStageEnum;
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.*;
import com.cool.store.request.HqtBuildRequest;
import com.cool.store.request.QueryBigRegionRequest;
import com.cool.store.service.*;
import com.cool.store.utils.StringUtil;
import com.cool.store.utils.easyExcel.EasyExcelUtil;
import com.cool.store.utils.poi.DateUtils;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.cool.store.utils.poi.DateUtils.SPECIAL_DATE_START_1;
import static com.cool.store.utils.poi.DateUtils.YYYY_MM_DD;

/**
 * @Author: WangShuo
 * @Date: 2025/05/09/10:12
 * @Version 1.0
 * @注释:
 */
@Service
@Slf4j
public class DataHandlerServerImpl implements DataHandlerServer {
    @Resource
    private HqtAPIService hqtAPIService;
    @Resource
    private RegionMapper regionMapper;
    @Resource
    private BigRegionDAO bigRegionDAO;
    @Resource
    private RegionDao regionDao;
    @Resource
    private LinePayService linePayService;
    @Resource
    private OpenApiService openApiService;
    @Resource
    private LinePayDAO linePayDAO;
    @Resource
    private AcceptanceInfoDAO acceptanceInfoDAO;
    @Resource
    private ImportTaskMapper importTaskMapper;
    @Resource
    private EasyExcelUtil easyExcelUtil;
    @Resource
    private ShopInfoDAO shopInfoDAO;
    @Resource
    private PointInfoDAO pointInfoDAO;
    @Resource
    private SignFranchiseMapper signFranchiseMapper;
    @Resource
    private BuildInformationDAO buildInformationDAO;
    @Resource
    private OrderSysInfoDAO orderSysInfoDAO;
    @Resource
    private ShopStageInfoDAO shopStageInfoDAO;
    @Resource
    private FranchiseFeeMapper franchiseFeeMapper;
    @Resource
    private FranchiseFeeDAO franchiseFeeDAO;
    @Resource
    private WarehouseInfoMapper warehouseInfoMapper;
    @Resource
    private PreparationService preparationService;
    @Resource
    private PosAndOrderInfoDAO posAndOrderInfoDAO;
    @Resource
    private PointDetailInfoDAO pointDetailInfoDAO;
    @Resource
    private LineInfoDAO lineInfoDAO;
    @Resource
    private ShopAccountDAO shopAccountDAO;
    @Resource
    private SignFranchiseDAO signFranchiseDAO;
    @Resource
    private EnterpriseUserDAO enterpriseUserDAO;
    @Value("${mybatis.configuration.variables.enterpriseId}")
    private String eid;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean importOaOldShopData(List<Map<String, Object>> dataMapList, String originalFilename, LoginUserInfo user, ImportTaskDO task) {
        List<ImportOaOldShopDataDTO> list = new ArrayList<>();
        List<ImportOaOldShopDataErrorDTO> errorList = new ArrayList<>();
        ListUtils.emptyIfNull(dataMapList)
                .forEach(data -> {
                    try {
                        ImportOaOldShopDataDTO dto = buildColumn(data);
                        list.add(dto);
                    } catch (Exception e) {
                        log.info("importOaOldShopData 转化dto error:{}", JSONObject.toJSONString(data));
                    }
                });
        log.info("导入数据条数:{}", list.size());
        if (CollectionUtils.isEmpty(list)) {
            log.info("导入数据转化为空");
            return false;
        }
        List<String> shopCodeList = list.stream().map(ImportOaOldShopDataDTO::getShopCode).collect(Collectors.toList());
        Map<String, ImportOaOldShopDataDTO> dotMap = list.stream().collect(Collectors.toMap(ImportOaOldShopDataDTO::getShopCode, item -> item));
        List<ShopInfoDO> shopInfoList = shopInfoDAO.selectByShopCodeList(shopCodeList);
        if (CollectionUtils.isEmpty(shopInfoList)) {
            log.info("导入数据根据shopCode 未找到数据");
        }
        Map<String, ShopInfoDO> shopInfoByCodeMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getShopCode, item -> item));
        List<Long> shopIds = shopInfoList.stream().map(ShopInfoDO::getId).collect(Collectors.toList());
        List<Long> lineIdList = shopInfoList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());
        //装修验收数据
        List<AcceptanceInfoDO> acceptanceInfoDOList = acceptanceInfoDAO.selectByShopIds(shopIds);
        Map<Long, AcceptanceInfoDO> acceptanceInfoMap = acceptanceInfoDOList.stream().collect(Collectors.toMap(AcceptanceInfoDO::getShopId, item -> item));

        //手机号
        Map<Long, String> lineMobileMap = lineInfoDAO.getLineMobileMap(lineIdList);
        //铺位列表
        List<Long> pointIds = shopInfoList.stream().map(ShopInfoDO::getPointId).filter(Objects::nonNull).collect(Collectors.toList());
        List<PointInfoDO> pointListByIds = pointInfoDAO.getPointListByIds(pointIds);
        Map<Long, PointInfoDO> pointMap = pointListByIds.stream().collect(Collectors.toMap(PointInfoDO::getId, Function.identity()));
        //铺位详情
        List<PointDetailInfoDO> pointDetailInfoDOList = pointDetailInfoDAO.getByPointIdList(pointIds);
        Map<Long, PointDetailInfoDO> pointDetailMap = pointDetailInfoDOList.stream().collect(Collectors.toMap(PointDetailInfoDO::getPointId, Function.identity()));
        //合同列表
        List<SignFranchiseDO> signFranchiseDOS = signFranchiseMapper.selectAllByShopIds(shopIds);
        Map<Long, SignFranchiseDO> signFranchiseMap = signFranchiseDOS.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, Function.identity()));
        //订货信息和总部订货收款账户表
        List<OrderSysInfoDO> orderSysInfoDOS = orderSysInfoDAO.selectByShopIdList(shopIds);
        Map<Long, OrderSysInfoDO> orderSysInfoMap = orderSysInfoDOS.stream().collect(Collectors.toMap(OrderSysInfoDO::getShopId, Function.identity()));
        //合同阶段
        List<ShopStageInfoDO> signFranchiseStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_8.getShopSubStage());
        Map<Long, ShopStageInfoDO> signFranchiseStageMap = signFranchiseStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //建店资料收集阶段
        List<ShopStageInfoDO> bulidStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_15.getShopSubStage());
        Map<Long, ShopStageInfoDO> bulidStageMap = bulidStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //加盟费阶段
        List<ShopStageInfoDO> franchiseFeeStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_7.getShopSubStage());
        Map<Long, ShopStageInfoDO> franchiseFeeStageMap = franchiseFeeStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //加盟费账单
        List<FranchiseFeeDO> franchiseFeeByShopIds = franchiseFeeMapper.getFranchiseFeeByShopIds(shopIds);
        Map<Long, FranchiseFeeDO> franchiseFeeMap = franchiseFeeByShopIds.stream().collect(Collectors.toMap(FranchiseFeeDO::getShopId, Function.identity()));
        //建店资料
        List<BuildInformationDO> buildInformationDOList = buildInformationDAO.getSpecificByShopIdList(shopIds);
        Map<Long, BuildInformationDO> buildInformationMap = buildInformationDOList.stream().collect(Collectors.toMap(BuildInformationDO::getShopId, Function.identity()));
        //初始化建店资料
        List<Long> addBuildList = new ArrayList<>();
        //初始化订货信息和总部订货收款账户表
        List<OrderSysInfoDO> addOrderSysInfoList = new ArrayList<>();
        //报货仓库
        List<WarehouseInfoDO> warehouseInfoMapperAll = warehouseInfoMapper.getAll();
        Map<String, String> warehouseInfoMap = warehouseInfoMapperAll.stream().collect(Collectors.toMap(WarehouseInfoDO::getWarehouseName, WarehouseInfoDO::getWarehouseCode));
        //订货系统
        List<PosAndOrderInfoDO> orderSysInfoDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.ORDER.getCode());
        Map<Long, PosAndOrderInfoDO> orderSysInfoDOMap = orderSysInfoDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        List<PosAndOrderInfoDO> addPosAndOrderInfoList = new ArrayList<>();
        //pos系统
        List<PosAndOrderInfoDO> posSysInfoDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.POS.getCode());
        Map<Long, PosAndOrderInfoDO> posSysInfoDOMap = posSysInfoDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        //装修阶段需要变更的shopId
        List<Long> fitmentFhopIdList = new ArrayList<>();
        //建店阶段完成时间
        List<BuildStageDTO> updateBuildStageList = new ArrayList<>();
        //装修验收表需要初始化的门店
        List<Long> initFitmentShopIdList = new ArrayList<>();
        for (ImportOaOldShopDataDTO dto : list) {
            if (!check(dto, errorList)) {
                continue;
            }
            ShopInfoDO shopInfoDO = shopInfoByCodeMap.get(dto.getShopCode().trim());
            if (Objects.isNull(shopInfoDO)) {
                log.info("门店不存在，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店编码不存在");
                errorList.add(errorDTO);
                continue;
            }
            Long shopId = shopInfoDO.getId();
            ShopStageInfoDO franchiseFeeStage = franchiseFeeStageMap.get(shopId);
            if (!franchiseFeeStage.getIsTerminated()) {
                log.info("门店未完成加盟费阶段，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店未完成加盟费阶段");
                errorList.add(errorDTO);
                continue;
            }
            ShopStageInfoDO signStage = signFranchiseStageMap.get(shopId);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_84.getShopSubStageStatus().equals(signStage.getShopSubStageStatus())) {
                log.info("门店未完成合同签约，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店未完成合同签约");
                errorList.add(errorDTO);
                continue;
            }
            Date buildEndTime = DateUtils.toDate(YYYY_MM_DD, dto.getBuildEndTime());
            if (Objects.isNull(buildEndTime)) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("建店资料时间转化失败");
                errorList.add(errorDTO);
                continue;
            }
            //合同
            SignFranchiseDO signFranchiseDO = signFranchiseMap.get(shopId);
            if (signFranchiseDO == null) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("合同DO不存在");
                errorList.add(errorDTO);
                continue;
            }
            FranchiseFeeDO franchiseFeeDO = franchiseFeeMap.get(shopId);
            if (franchiseFeeDO == null) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("加盟费DO不存在");
                errorList.add(errorDTO);
                continue;
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecond())) {
                signFranchiseDO.setPartnershipSignatorySecond(dto.getPartnershipSignatorySecond().trim());
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecondMobile())) {
                signFranchiseDO.setPartnershipSignatorySecondMobile(dto.getPartnershipSignatorySecondMobile().trim());
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecondIdNumber())) {
                signFranchiseDO.setPartnershipSignatorySecondIdNumber(dto.getPartnershipSignatorySecondIdNumber());
            }
            if (StringUtil.isNotBlank(dto.getContractStartDate())) {
                signFranchiseDO.setContractStartTime(DateUtils.toDate(YYYY_MM_DD, dto.getContractStartDate().trim()));
            }
            if (StringUtil.isNotBlank(dto.getContractEndDate())) {
                signFranchiseDO.setContractEndTime(DateUtils.toDate(YYYY_MM_DD, dto.getContractEndDate().trim()));
            }
            if ((StringUtil.isNotBlank(dto.getIntroducer()) && !"0".equals(dto.getIntroducer()))) {
                signFranchiseDO.setIntroducer(dto.getIntroducer());
            }
            if (StringUtil.isNotBlank(dto.getIntroduceStore()) && !"0".equals(dto.getIntroduceStore())) {
                signFranchiseDO.setIntroduceStore(dto.getIntroduceStore());
            }
            if (StringUtil.isNotBlank(dto.getIntroductionAward())) {
                signFranchiseDO.setIntroductionAward(dto.getIntroductionAward());
            }
            if (StringUtil.isNotBlank(dto.getContractCode()) && dto.getContractCode().trim().startsWith("ZX") && dto.getContractCode().trim() != "0") {
                signFranchiseDO.setContractCode(dto.getContractCode().trim());
            }
            if (StringUtil.isNotBlank(dto.getProtectionDistance())) {
                signFranchiseDO.setProtectiveDistance((int) Double.parseDouble(dto.getProtectionDistance().trim()));
            }
            ShopStageInfoDO buildStage = bulidStageMap.get(shopId);
            //建店资料完成时间
            BuildStageDTO buildStageDTO = new BuildStageDTO();
            buildStageDTO.setShopId(shopId);
            buildStageDTO.setEndTime(dto.getBuildEndTime() + " 00:00:00");
            updateBuildStageList.add(buildStageDTO);
            //建店资料阶段处理
            shopStageInfoDAO.dataUpdateShopStageInfo(Collections.singletonList(buildStageDTO), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_156);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_156.getShopSubStageStatus().equals(buildStage.getShopSubStageStatus())) {
                //初始化数据
                preparationService.licenseCompleted(shopId);
                preparationService.sysStoreCompleted(shopId);
                preparationService.buildStoreAndDecorationComplete(shopId);
                preparationService.selectSiteAndBuildStoreComplete(shopId);
                preparationService.buildStoreComplete(shopId);
            }
            if (buildEndTime.before(new Date(1745164800000L))) {
                fitmentFhopIdList.add(shopId);
            }
            BuildInformationDO buildInformationDO = buildInformationMap.get(shopId);
            if (Objects.isNull(buildInformationDO)) {
                addBuildList.add(shopId);
            }
            OrderSysInfoDO orderSysInfoDO = orderSysInfoMap.get(shopId);
            //报货物流仓库
            String warehouseCode = warehouseInfoMap.get(dto.getDeclareGoodsLogisticsWarehouseName().trim());
            if (Objects.isNull(orderSysInfoDO)) {
                orderSysInfoDO = new OrderSysInfoDO();
                orderSysInfoDO.setShopId(shopId);
                orderSysInfoDO.setOrderCreateTime(new Date());
                orderSysInfoDO.setReceivingCreateTime(new Date());
                setOrderInfo(dto, orderSysInfoDO, warehouseCode);
                addOrderSysInfoList.add(orderSysInfoDO);
            } else {
                setOrderInfo(dto, orderSysInfoDO, warehouseCode);
            }
            //shopInfo
            shopInfoDO.setShopName(dto.getShopName().trim());
            shopInfoDO.setProvince(dto.getProvince().trim());
            shopInfoDO.setCity(dto.getCity().trim());
            shopInfoDO.setDistrict(dto.getDistrict().trim());
            shopInfoDO.setDetailAddress(dto.getShopAddress().trim());
            //point
            PointInfoDO pointInfoDO = pointMap.get(shopInfoDO.getPointId());
            if (pointInfoDO != null) {
                pointInfoDO.setProvince(dto.getProvince().trim());
                pointInfoDO.setCity(dto.getCity().trim());
                pointInfoDO.setDistrict(dto.getDistrict().trim());
                pointInfoDO.setAddress(dto.getShopAddress().trim());
                pointInfoDO.setPointArea(dto.getPointArea().trim());
            }
            PointDetailInfoDO pointDetailInfoDO = pointDetailMap.get(shopInfoDO.getPointId());
            if (pointDetailInfoDO != null) {
                if (StringUtil.isNotBlank(dto.getMonthRent())) {
                    pointDetailInfoDO.setMonthRent(dto.getMonthRent().trim());
                }
            }
            //  更新加盟费账单
            franchiseFeeDO.setYearFranchiseFee(dto.getYearFranchiseFee().trim());
            franchiseFeeDO.setLoanMargin(dto.getLoanMargin().trim());
            franchiseFeeDO.setFirstYearFee(dto.getFirstYearFee().trim());
            franchiseFeeDO.setFirstYearManageFee(dto.getFirstYearManageFee().trim());
            franchiseFeeDO.setPerformanceBond(dto.getPerformanceBond().trim());
            franchiseFeeDO.setDiscountReason(dto.getDiscountReason().trim());
            //订货系统
            PosAndOrderInfoDO order = orderSysInfoDOMap.get(shopId);
            if (StringUtil.isNotBlank(dto.getYlsAccount())) {
                if (Objects.isNull(order)) {
                    order = new PosAndOrderInfoDO();
                    order.setShopId(shopId);
                    order.setType(PosAndOrderEnum.ORDER.getCode());
                    order.setRemark("已为您开通订货系统账号和密码，密码已加密，初始密码为888888，可通过加盟小程序修改密码！");
                    order.setAccount(dto.getYlsAccount().trim());
                    order.setPassword("888888");
                    order.setCreateTime(new Date());
                    addPosAndOrderInfoList.add(order);
                }
            }
            //pos
            PosAndOrderInfoDO posDO = posSysInfoDOMap.get(shopId);
            if (Objects.isNull(posDO)) {
                posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setType(PosAndOrderEnum.POS.getCode());
                posDO.setAccount(lineMobileMap.getOrDefault(shopInfoDO.getLineId(), ""));
                posDO.setRemark("已为您开通POS系统账号和密码");
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
            AcceptanceInfoDO acceptanceInfoDO = acceptanceInfoMap.get(shopId);
            if (Objects.isNull(acceptanceInfoDO)) {
                initFitmentShopIdList.add(shopId);
            }
        }
        shopInfoDAO.updateShopCity(shopInfoList);
        pointInfoDAO.updateAddress(pointListByIds);
        pointDetailInfoDAO.updateMonthRent(pointDetailInfoDOList);
        signFranchiseDAO.updateSpecific(signFranchiseDOS);
        posAndOrderInfoDAO.batchInsert(addPosAndOrderInfoList);
        orderSysInfoDAO.batchUpdateSpecific(orderSysInfoDOS);
        orderSysInfoDAO.batchInsertSpecific(addOrderSysInfoList);
        franchiseFeeDAO.updateBill(franchiseFeeByShopIds);
        buildInformationDAO.batchInsertSpecific(addBuildList);
        //装修表初始化
        acceptanceInfoDAO.initAcceptanceInfo(initFitmentShopIdList);
        List<Long> updateStageShopIds = updateBuildStageList.stream().map(BuildStageDTO::getShopId).collect(Collectors.toList());
        //pos阶段完成
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_163);
        // 订货阶段 完成
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_173);
        //数据处理用平台账号 火马，云流水，新掌柜状态改为已完成
        shopAccountDAO.updateStatusDataHandle(updateStageShopIds);

        //表中4月20号后的数据，数据录入系统，新店装修阶段状态不变更  其他时间的数据状态改为已完成 不包括装修验收
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_863);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_91);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_112);
        //装修验收初始化
        shopStageInfoDAO.dataUpdateAcceptanceStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_121);
        if (!errorList.isEmpty()) {
            task.setStatus(ImportTaskStatusEnum.ERROR.getCode());
            String url = null;
            try {
                url = easyExcelUtil.exportExcel(ImportOaOldShopDataErrorDTO.class, errorList, null,
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()),
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()));
            } catch (Exception e) {
                log.info("导出失败列表失败 errorList:{}", JSONObject.toJSONString(errorList));
            }
            task.setFileUrl(url);
        } else {
            task.setStatus(ImportTaskStatusEnum.SUCCESS.getCode());
        }
        task.setTotalNum(dataMapList.size());
        task.setSuccessNum(dataMapList.size() - errorList.size());
        importTaskMapper.update(eid, task);
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean dataStageHandler(List<Map<String, Object>> dataMapList, String originalFilename, LoginUserInfo user, ImportTaskDO task, Boolean flag) {
        List<String> shopCodeList = new ArrayList<>();
        ListUtils.emptyIfNull(dataMapList)
                .forEach(data -> {
                    try {
                        shopCodeList.add(String.valueOf(data.get("门店编码")).trim());
                    } catch (Exception e) {
                        log.info("importOaOldShopData 转化dto error:{}", JSONObject.toJSONString(data));
                    }
                });
        if (CollectionUtils.isEmpty(shopCodeList)) {
            log.info("数据处理 门店编码为空");
            return null;
        }
        List<ShopInfoDO> shopInfoList = shopInfoDAO.selectByShopCodeList(shopCodeList);
        if (CollectionUtils.isEmpty(shopInfoList)) {
            log.info("数据处理 门店未找到对应数据");
            return null;
        }
        List<ImportOaOldShopDataErrorDTO> errorList = new ArrayList<>();
        List<Long> shopIds = shopInfoList.stream().map(ShopInfoDO::getId).collect(Collectors.toList());
        Map<String, ShopInfoDO> shopInfoMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getShopCode, x -> x));
        List<Long> lineIdList = shopInfoList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());

        //手机号
        Map<Long, String> lineMobileMap = lineInfoDAO.getLineMobileMap(lineIdList);
        List<ShopStageInfoDO> stageByShopStage = shopStageInfoDAO.getStageByShopStage(shopIds, ShopStageEnum.SHOP_STAGE_2.getShopStage());
        Map<Long, List<ShopStageInfoDO>> shopStageInfoMap = stageByShopStage.stream().collect(Collectors.groupingBy(ShopStageInfoDO::getShopId));
        //培训和开业完成
        List<Long> trainShopIdList = new ArrayList<>();
        //建店大阶段完成
        List<Long> buildShopIdList = new ArrayList<>();
        List<OpeningOperationPlanDO> addOpeningOperationPlanDO = new ArrayList<>();
        List<PosAndOrderInfoDO> addPosAndOrderInfoList = new ArrayList<>();
        for (String shopCode : shopCodeList) {
            ShopInfoDO shop = shopInfoMap.get(shopCode);
            if (shop == null) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(shopCode);
                errorDTO.setErrorReason("code未找到对应门店数据");
                errorList.add(errorDTO);
                continue;
            }
            Long shopId = shop.getId();
            List<ShopStageInfoDO> shopStageInfoList = shopStageInfoMap.get(shopId);
            if (CollectionUtils.isEmpty(shopStageInfoList)) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(shop.getShopCode());
                errorDTO.setErrorReason("门店未找到对应阶段数据");
                errorList.add(errorDTO);
                continue;
            }
            Map<Integer, ShopStageInfoDO> stageMap = shopStageInfoList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopSubStage, Function.identity()));
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_84.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_8.getShopSubStage()).getShopSubStageStatus())) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(shop.getShopCode());
                errorDTO.setErrorReason("合同未完成");
                errorList.add(errorDTO);
                continue;
            }
            trainShopIdList.add(shopId);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_143.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_14.getShopSubStage()).getShopSubStageStatus())) {
                OpeningOperationPlanDO openingOperationPlanDO = new OpeningOperationPlanDO();
                openingOperationPlanDO.setShopId(shopId);
                openingOperationPlanDO.setCreateTime(new Date());
                addOpeningOperationPlanDO.add(openingOperationPlanDO);
            }
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_156.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_15.getShopSubStage()).getShopSubStageStatus())) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(shop.getShopCode());
                errorDTO.setErrorReason("建店资料未完成");
                errorList.add(errorDTO);
                continue;
            }
            buildShopIdList.add(shopId);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_173.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_17.getShopSubStage()).getShopSubStageStatus())) {
                PosAndOrderInfoDO posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setAccount("ZXA8_" + shop.getShopCode());
                posDO.setPassword("888888");
                posDO.setType(PosAndOrderEnum.ORDER.getCode());
                posDO.setRemark("已为您开通订货系统账号和密码，密码已加密，初始密码为888888，可通过加盟小程序修改密码！");
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_163.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_16.getShopSubStage()).getShopSubStageStatus())) {
                PosAndOrderInfoDO posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setAccount(lineMobileMap.get(shop.getLineId()));
                posDO.setType(PosAndOrderEnum.POS.getCode());
                posDO.setRemark("已为您开通POS系统账号和密码");
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_235.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_23.getShopSubStage()).getShopSubStageStatus())) {
                PosAndOrderInfoDO posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setAccount(shop.getShopCode());
                posDO.setType(PosAndOrderEnum.XIN_FA_SYS.getCode());
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_245.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_24.getShopSubStage()).getShopSubStageStatus())
                    && !ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_244.getShopSubStageStatus()
                    .equals(stageMap.get(ShopSubStageEnum.SHOP_STAGE_24.getShopSubStage()).getShopSubStageStatus())) {
                PosAndOrderInfoDO posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setType(PosAndOrderEnum.TENT_PASS.getCode());
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
        }
        if (flag) {
            //装修大阶段
            shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_863);
            shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_91);
            shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_112);
            shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_123);
        }
        //培训
        shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_51);
        //开业方案
        shopStageInfoDAO.dataUpdateStatus(trainShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_143);
        //营帐通
        shopStageInfoDAO.dataUpdateStatus(buildShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_245);
        //新发
        shopStageInfoDAO.dataUpdateStatus(buildShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_235);
        //pos
        shopStageInfoDAO.dataUpdateStatus(buildShopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_163);
        if (!errorList.isEmpty()) {
            task.setStatus(ImportTaskStatusEnum.ERROR.getCode());
            String url = null;
            try {
                url = easyExcelUtil.exportExcel(ImportOaOldShopDataErrorDTO.class, errorList, null,
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_STAGE_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()),
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_STAGE_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()));
            } catch (Exception e) {
                log.info("导出失败列表失败 errorList:{}", JSONObject.toJSONString(errorList));
            }
            task.setFileUrl(url);
        } else {
            task.setStatus(ImportTaskStatusEnum.SUCCESS.getCode());
        }
        task.setTotalNum(dataMapList.size());
        task.setSuccessNum(dataMapList.size() - errorList.size());
        importTaskMapper.update(eid, task);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean decorationDataInit() {

        //施工阶段
        List<ShopStageInfoDO> subStages = shopStageInfoDAO.getSubStages(ShopSubStageEnum.SHOP_STAGE_11.getShopSubStage());
        List<Long> allShopIds = acceptanceInfoDAO.getAllShopIds();
        //需要处理的门店
        List<Long> addShopIds = new ArrayList<>();
        for (ShopStageInfoDO subStage : subStages) {
            if (ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_112.getShopSubStageStatus().equals(subStage.getShopSubStageStatus())) {
                if (!allShopIds.contains(subStage.getShopId())) {
                    addShopIds.add(subStage.getShopId());
                }
            }
        }
        if (CollectionUtils.isEmpty(addShopIds)) {
            throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
        }
        acceptanceInfoDAO.initAcceptanceInfo(addShopIds);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean dataHandlerV20241012(List<Map<String, Object>> dataMapList, String originalFilename, LoginUserInfo user, ImportTaskDO task) {

        List<ImportOaOldShopDataDTO> list = new ArrayList<>();
        List<ImportOaOldShopDataErrorDTO> errorList = new ArrayList<>();
        ListUtils.emptyIfNull(dataMapList)
                .forEach(data -> {
                    try {
                        ImportOaOldShopDataDTO dto = buildColumn(data);
                        list.add(dto);
                    } catch (Exception e) {
                        log.info("dataHandlerV20241012 转化dto error:{}", JSONObject.toJSONString(data));
                    }
                });
        log.info("导入数据条数:{}", list.size());
        if (CollectionUtils.isEmpty(list)) {
            log.info("导入数据转化为空");
            return false;
        }
        List<String> shopCodeList = list.stream().map(ImportOaOldShopDataDTO::getShopCode).collect(Collectors.toList());
        Map<String, ImportOaOldShopDataDTO> dotMap = list.stream().collect(Collectors.toMap(ImportOaOldShopDataDTO::getShopCode, item -> item));
        List<ShopInfoDO> shopInfoList = shopInfoDAO.selectByShopCodeList(shopCodeList);
        if (CollectionUtils.isEmpty(shopInfoList)) {
            log.info("导入数据根据shopCode 未找到数据");
        }
        Map<String, ShopInfoDO> shopInfoByCodeMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getShopCode, item -> item));
        List<Long> shopIds = shopInfoList.stream().map(ShopInfoDO::getId).collect(Collectors.toList());
        List<Long> lineIdList = shopInfoList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());
        //装修验收数据
        List<AcceptanceInfoDO> acceptanceInfoDOList = acceptanceInfoDAO.selectByShopIds(shopIds);
        Map<Long, AcceptanceInfoDO> acceptanceInfoMap = acceptanceInfoDOList.stream().collect(Collectors.toMap(AcceptanceInfoDO::getShopId, item -> item));
        //手机号
        Map<Long, String> lineMobileMap = lineInfoDAO.getLineMobileMap(lineIdList);
        //铺位列表
        List<Long> pointIds = shopInfoList.stream().map(ShopInfoDO::getPointId).filter(Objects::nonNull).collect(Collectors.toList());
        List<PointInfoDO> pointListByIds = pointInfoDAO.getPointListByIds(pointIds);
        Map<Long, PointInfoDO> pointMap = pointListByIds.stream().collect(Collectors.toMap(PointInfoDO::getId, Function.identity()));
        //铺位详情
        List<PointDetailInfoDO> pointDetailInfoDOList = pointDetailInfoDAO.getByPointIdList(pointIds);
        Map<Long, PointDetailInfoDO> pointDetailMap = pointDetailInfoDOList.stream().collect(Collectors.toMap(PointDetailInfoDO::getPointId, Function.identity()));
        //合同列表
        List<SignFranchiseDO> signFranchiseDOS = signFranchiseMapper.selectAllByShopIds(shopIds);
        Map<Long, SignFranchiseDO> signFranchiseMap = signFranchiseDOS.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, Function.identity()));
        //订货信息和总部订货收款账户表
        List<OrderSysInfoDO> orderSysInfoDOS = orderSysInfoDAO.selectByShopIdList(shopIds);
        Map<Long, OrderSysInfoDO> orderSysInfoMap = orderSysInfoDOS.stream().collect(Collectors.toMap(OrderSysInfoDO::getShopId, Function.identity()));
        //合同阶段
        List<ShopStageInfoDO> signFranchiseStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_8.getShopSubStage());
        Map<Long, ShopStageInfoDO> signFranchiseStageMap = signFranchiseStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //建店资料收集阶段
        List<ShopStageInfoDO> bulidStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_15.getShopSubStage());
        Map<Long, ShopStageInfoDO> bulidStageMap = bulidStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //加盟费阶段
        List<ShopStageInfoDO> franchiseFeeStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_7.getShopSubStage());
        Map<Long, ShopStageInfoDO> franchiseFeeStageMap = franchiseFeeStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //加盟费账单
        List<FranchiseFeeDO> franchiseFeeByShopIds = franchiseFeeMapper.getFranchiseFeeByShopIds(shopIds);
        Map<Long, FranchiseFeeDO> franchiseFeeMap = franchiseFeeByShopIds.stream().collect(Collectors.toMap(FranchiseFeeDO::getShopId, Function.identity()));
        //建店资料
        List<BuildInformationDO> buildInformationDOList = buildInformationDAO.getSpecificByShopIdList(shopIds);
        Map<Long, BuildInformationDO> buildInformationMap = buildInformationDOList.stream().collect(Collectors.toMap(BuildInformationDO::getShopId, Function.identity()));
        //初始化建店资料
        List<Long> addBuildList = new ArrayList<>();
        //初始化订货信息和总部订货收款账户表
        List<OrderSysInfoDO> addOrderSysInfoList = new ArrayList<>();
        //报货仓库
        List<WarehouseInfoDO> warehouseInfoMapperAll = warehouseInfoMapper.getAll();
        Map<String, String> warehouseInfoMap = warehouseInfoMapperAll.stream().collect(Collectors.toMap(WarehouseInfoDO::getWarehouseName, WarehouseInfoDO::getWarehouseCode));
        //订货系统
        List<PosAndOrderInfoDO> orderSysInfoDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.ORDER.getCode());
        Map<Long, PosAndOrderInfoDO> orderSysInfoDOMap = orderSysInfoDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        List<PosAndOrderInfoDO> addPosAndOrderInfoList = new ArrayList<>();
        //pos系统
        List<PosAndOrderInfoDO> posSysInfoDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.POS.getCode());
        Map<Long, PosAndOrderInfoDO> posSysInfoDOMap = posSysInfoDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        //新发系统
        List<PosAndOrderInfoDO> xfSysDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.XIN_FA_SYS.getCode());
        Map<Long, PosAndOrderInfoDO> xfSysInfoDOMap = xfSysDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        //营帐通系统
        List<PosAndOrderInfoDO> tentPassInfoDOList = posAndOrderInfoDAO.selectListByShopIdAndType(shopIds, PosAndOrderEnum.TENT_PASS.getCode());
        Map<Long, PosAndOrderInfoDO> tentPassInfoDOMap = tentPassInfoDOList.stream().collect(Collectors.toMap(PosAndOrderInfoDO::getShopId, Function.identity()));
        //装修阶段需要变更的shopId
        List<Long> fitmentFhopIdList = new ArrayList<>();
        //建店阶段完成时间
        List<BuildStageDTO> updateBuildStageList = new ArrayList<>();
        //装修验收表需要初始化的门店
        List<Long> initFitmentShopIdList = new ArrayList<>();
        for (ImportOaOldShopDataDTO dto : list) {
            if (!check(dto, errorList)) {
                continue;
            }
            ShopInfoDO shopInfoDO = shopInfoByCodeMap.get(dto.getShopCode().trim());
            if (Objects.isNull(shopInfoDO)) {
                log.info("门店不存在，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店编码不存在");
                errorList.add(errorDTO);
                continue;
            }
            Long shopId = shopInfoDO.getId();
            ShopStageInfoDO franchiseFeeStage = franchiseFeeStageMap.get(shopId);
            if (!franchiseFeeStage.getIsTerminated()) {
                log.info("门店未完成加盟费阶段，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店未完成加盟费阶段");
                errorList.add(errorDTO);
                continue;
            }
            ShopStageInfoDO signStage = signFranchiseStageMap.get(shopId);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_84.getShopSubStageStatus().equals(signStage.getShopSubStageStatus())) {
                log.info("门店未完成合同签约，门店编码：{}", dto.getShopCode());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("门店未完成合同签约");
                errorList.add(errorDTO);
                continue;
            }
            Date buildEndTime = DateUtils.toDate(YYYY_MM_DD, dto.getBuildEndTime());
            if (Objects.isNull(buildEndTime)) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("建店资料时间转化失败");
                errorList.add(errorDTO);
                continue;
            }
            //合同
            SignFranchiseDO signFranchiseDO = signFranchiseMap.get(shopId);
            if (signFranchiseDO == null) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("合同DO不存在");
                errorList.add(errorDTO);
                continue;
            }
            FranchiseFeeDO franchiseFeeDO = franchiseFeeMap.get(shopId);
            if (franchiseFeeDO == null) {
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
                errorDTO.setShopCode(dto.getShopCode());
                errorDTO.setErrorReason("加盟费DO不存在");
                errorList.add(errorDTO);
                continue;
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecond())) {
                signFranchiseDO.setPartnershipSignatorySecond(dto.getPartnershipSignatorySecond().trim());
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecondMobile())) {
                signFranchiseDO.setPartnershipSignatorySecondMobile(dto.getPartnershipSignatorySecondMobile().trim());
            }
            if (StringUtil.isNotBlank(dto.getPartnershipSignatorySecondIdNumber())) {
                signFranchiseDO.setPartnershipSignatorySecondIdNumber(dto.getPartnershipSignatorySecondIdNumber());
            }
            if (StringUtil.isNotBlank(dto.getContractStartDate())) {
                signFranchiseDO.setContractStartTime(DateUtils.toDate(YYYY_MM_DD, dto.getContractStartDate().trim()));
            }
            if (StringUtil.isNotBlank(dto.getContractEndDate())) {
                signFranchiseDO.setContractEndTime(DateUtils.toDate(YYYY_MM_DD, dto.getContractEndDate().trim()));
            }
            if ((StringUtil.isNotBlank(dto.getIntroducer()) && !"0".equals(dto.getIntroducer()))) {
                signFranchiseDO.setIntroducer(dto.getIntroducer());
            }
            if (StringUtil.isNotBlank(dto.getIntroduceStore()) && !"0".equals(dto.getIntroduceStore())) {
                signFranchiseDO.setIntroduceStore(dto.getIntroduceStore());
            }
            if (StringUtil.isNotBlank(dto.getIntroductionAward())) {
                signFranchiseDO.setIntroductionAward(dto.getIntroductionAward());
            }
            if (StringUtil.isNotBlank(dto.getContractCode()) && dto.getContractCode().trim().startsWith("ZX") && !"0".equals(dto.getContractCode().trim())) {
                signFranchiseDO.setContractCode(dto.getContractCode().trim());
            }
            if (StringUtil.isNotBlank(dto.getProtectionDistance())) {
                signFranchiseDO.setProtectiveDistance((int) Double.parseDouble(dto.getProtectionDistance().trim()));
            }
            ShopStageInfoDO buildStage = bulidStageMap.get(shopId);
            //建店资料未完成
            BuildStageDTO buildStageDTO = new BuildStageDTO();
            buildStageDTO.setShopId(shopId);
            buildStageDTO.setEndTime(dto.getBuildEndTime() + " 00:00:00");
            updateBuildStageList.add(buildStageDTO);
            //建店资料阶段处理
            shopStageInfoDAO.dataUpdateShopStageInfo(Collections.singletonList(buildStageDTO), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_156);
            if (!ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_156.getShopSubStageStatus().equals(buildStage.getShopSubStageStatus())) {
                //初始化数据
                preparationService.licenseCompleted(shopId);
                preparationService.sysStoreCompleted(shopId);
                preparationService.buildStoreAndDecorationComplete(shopId);
                preparationService.selectSiteAndBuildStoreComplete(shopId);
                preparationService.buildStoreComplete(shopId);
            }
            fitmentFhopIdList.add(shopId);
            BuildInformationDO buildInformationDO = buildInformationMap.get(shopId);
            if (Objects.isNull(buildInformationDO)) {
                addBuildList.add(shopId);
            }
            OrderSysInfoDO orderSysInfoDO = orderSysInfoMap.get(shopId);
            //报货物流仓库
            String warehouseCode = warehouseInfoMap.get(dto.getDeclareGoodsLogisticsWarehouseName().trim());
            if (Objects.isNull(orderSysInfoDO)) {
                orderSysInfoDO = new OrderSysInfoDO();
                orderSysInfoDO.setShopId(shopId);
                orderSysInfoDO.setOrderCreateTime(new Date());
                orderSysInfoDO.setReceivingCreateTime(new Date());
                setOrderInfo(dto, orderSysInfoDO, warehouseCode);
                addOrderSysInfoList.add(orderSysInfoDO);
            } else {
                setOrderInfo(dto, orderSysInfoDO, warehouseCode);
            }
            //shopInfo
            shopInfoDO.setShopName(dto.getShopName().trim());
            shopInfoDO.setProvince(dto.getProvince().trim());
            shopInfoDO.setCity(dto.getCity().trim());
            shopInfoDO.setDistrict(dto.getDistrict().trim());
            shopInfoDO.setDetailAddress(dto.getShopAddress().trim());
            //point
            PointInfoDO pointInfoDO = pointMap.get(shopInfoDO.getPointId());
            if (pointInfoDO != null) {
                pointInfoDO.setProvince(dto.getProvince().trim());
                pointInfoDO.setCity(dto.getCity().trim());
                pointInfoDO.setDistrict(dto.getDistrict().trim());
                pointInfoDO.setAddress(dto.getShopAddress().trim());
                pointInfoDO.setPointArea(dto.getPointArea().trim());
            }
            PointDetailInfoDO pointDetailInfoDO = pointDetailMap.get(shopInfoDO.getPointId());
            if (pointDetailInfoDO != null) {
                if (StringUtil.isNotBlank(dto.getMonthRent())) {
                    pointDetailInfoDO.setMonthRent(dto.getMonthRent().trim());
                }
            }
            //  更新加盟费账单
            franchiseFeeDO.setYearFranchiseFee(dto.getYearFranchiseFee().trim());
            franchiseFeeDO.setLoanMargin(dto.getLoanMargin().trim());
            franchiseFeeDO.setFirstYearFee(dto.getFirstYearFee().trim());
            franchiseFeeDO.setFirstYearManageFee(dto.getFirstYearManageFee().trim());
            franchiseFeeDO.setPerformanceBond(dto.getPerformanceBond().trim());
            franchiseFeeDO.setDiscountReason(dto.getDiscountReason().trim());
            //订货系统
            PosAndOrderInfoDO order = orderSysInfoDOMap.get(shopId);
            if (StringUtil.isNotBlank(dto.getYlsAccount())) {
                if (Objects.isNull(order)) {
                    order = new PosAndOrderInfoDO();
                    order.setShopId(shopId);
                    order.setType(PosAndOrderEnum.ORDER.getCode());
                    order.setRemark("已为您开通订货系统账号和密码，密码已加密，初始密码为888888，可通过加盟小程序修改密码！");
                    order.setAccount(dto.getYlsAccount().trim());
                    order.setPassword("888888");
                    order.setCreateTime(new Date());
                    addPosAndOrderInfoList.add(order);
                }
            }
            //pos
            PosAndOrderInfoDO posDO = posSysInfoDOMap.get(shopId);
            if (Objects.isNull(posDO)) {
                posDO = new PosAndOrderInfoDO();
                posDO.setShopId(shopId);
                posDO.setType(PosAndOrderEnum.POS.getCode());
                posDO.setAccount(lineMobileMap.getOrDefault(shopInfoDO.getLineId(), ""));
                posDO.setRemark("已为您开通POS系统账号和密码");
                posDO.setCreateTime(new Date());
                addPosAndOrderInfoList.add(posDO);
            }
            //xf
            PosAndOrderInfoDO xf = xfSysInfoDOMap.get(shopId);
            if (Objects.isNull(xf)) {
                order = new PosAndOrderInfoDO();
                order.setShopId(shopId);
                order.setType(PosAndOrderEnum.XIN_FA_SYS.getCode());
                order.setRemark("已为您开通信发系统账号和授权码请妥善保管");
                order.setAccount(dto.getShopCode().trim());
                order.setCreateTime(new Date());
                addPosAndOrderInfoList.add(order);
            }
            //营帐通
            PosAndOrderInfoDO yzt = tentPassInfoDOMap.get(shopId);
            if (Objects.isNull(yzt)) {
                order = new PosAndOrderInfoDO();
                order.setShopId(shopId);
                order.setType(PosAndOrderEnum.TENT_PASS.getCode());
                order.setRemark("已为您开通营帐通");
                order.setCreateTime(new Date());
                addPosAndOrderInfoList.add(order);
            }
            AcceptanceInfoDO acceptanceInfoDO = acceptanceInfoMap.get(shopId);
            if (Objects.isNull(acceptanceInfoDO)) {
                initFitmentShopIdList.add(shopId);
            }
        }
        shopInfoDAO.updateShopCity(shopInfoList);
        pointInfoDAO.updateAddress(pointListByIds);
        pointDetailInfoDAO.updateMonthRent(pointDetailInfoDOList);
        signFranchiseDAO.updateSpecific(signFranchiseDOS);
        posAndOrderInfoDAO.batchInsert(addPosAndOrderInfoList);
        orderSysInfoDAO.batchUpdateSpecific(orderSysInfoDOS);
        orderSysInfoDAO.batchInsertSpecific(addOrderSysInfoList);
        franchiseFeeDAO.updateBill(franchiseFeeByShopIds);
        buildInformationDAO.batchInsertSpecific(addBuildList);
        List<Long> updateStageShopIds = updateBuildStageList.stream().map(BuildStageDTO::getShopId).collect(Collectors.toList());
        //pos阶段完成
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_163);
        //xf
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_235);
        //yzt
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_245);
        // 订货阶段 完成
        shopStageInfoDAO.dataUpdateStatus(updateStageShopIds, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_173);
        //数据处理用平台账号 火马，云流水，新掌柜状态改为已完成
        shopAccountDAO.updateStatusDataHandle(updateStageShopIds);
        //装修stage
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_863);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_91);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_112);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_123);
        //train
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_51);
        //openPlan
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_143);
        //装修表初始化
        acceptanceInfoDAO.initAcceptanceInfo(initFitmentShopIdList);
        if (!errorList.isEmpty()) {
            task.setStatus(ImportTaskStatusEnum.ERROR.getCode());
            String url = null;
            try {
                url = easyExcelUtil.exportExcel(ImportOaOldShopDataErrorDTO.class, errorList, null,
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()),
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_DATA_ERROR.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()));
            } catch (Exception e) {
                log.info("导出失败列表失败 errorList:{}", JSONObject.toJSONString(errorList));
            }
            task.setFileUrl(url);
        } else {
            task.setStatus(ImportTaskStatusEnum.SUCCESS.getCode());
        }
        task.setTotalNum(dataMapList.size());
        task.setSuccessNum(dataMapList.size() - errorList.size());
        importTaskMapper.update(eid, task);
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer JingDongStageHandler() {
        List<ShopStageInfoDO> subStages = shopStageInfoDAO.getSubStages(ShopSubStageEnum.SHOP_STAGE_19.getShopSubStage());
        List<ShopStageInfoDO> jdSubStages = shopStageInfoDAO.getSubStages(ShopSubStageEnum.SHOP_STAGE_25.getShopSubStage());
        List<Long> jdStageShopIds = jdSubStages.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        Set<Long> lineIds = subStages.stream().map(ShopStageInfoDO::getLineId).collect(Collectors.toSet());
        List<LineInfoDO> lineInfoDOS = lineInfoDAO.getByLineIds(new ArrayList<>(lineIds));
        Map<Long, LineInfoDO> lineMap = lineInfoDOS.stream().collect(Collectors.toMap(LineInfoDO::getId, line -> line));
        List<ShopStageInfoDO> initList = new ArrayList<>();
        List<ShopAccountDO> initAccountList = new ArrayList<>();
        ShopSubStageEnum shopSubStageEnum = ShopSubStageEnum.SHOP_STAGE_25;
        List<Long> shopIds = shopAccountDAO.getShopId();
        for (ShopStageInfoDO shopStageInfoDO : subStages) {
            if (jdStageShopIds.contains(shopStageInfoDO.getShopId())) {
                continue;
            }
            LineInfoDO lineInfoDO = lineMap.get(shopStageInfoDO.getLineId());
            if (Objects.isNull(lineInfoDO)) {
                log.info("线索不存在：{}", shopStageInfoDO.getShopId());
                continue;
            }
            if (shopStageInfoDO.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_00.getShopSubStageStatus())) {
                ShopStageInfoDO shopStageInfo = getShopStageInfoDO(shopSubStageEnum, shopStageInfoDO, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_00);
                initList.add(shopStageInfo);
            }
            if (!shopStageInfoDO.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_00.getShopSubStageStatus())) {
                ShopStageInfoDO shopStageInfo = getShopStageInfoDO(shopSubStageEnum, shopStageInfoDO, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_250);
                initList.add(shopStageInfo);
            }
            if (shopIds.contains(shopStageInfoDO.getShopId())) {
                ShopAccountDO shopAccountDO = new ShopAccountDO();
                shopAccountDO.setShopId(shopStageInfoDO.getShopId());
                shopAccountDO.setSystemName(ShopAccountEnum.JINGDONG.getSystemName());
                shopAccountDO.setBoundPhone(lineInfoDO.getMobile());
                shopAccountDO.setStatus(ShopAccountEnum.JINGDONG.getInitStatus().getCode());
                initAccountList.add(shopAccountDO);
            }
        }
        shopAccountDAO.batchInsert(initAccountList);
        return shopStageInfoDAO.batchInsert(initList);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean dataHandlerV2025029(List<Map<String, Object>> dataMapList, String originalFilename, LoginUserInfo user, ImportTaskDO task) {

        List<ImportOaOldShopDataDTO> list = new ArrayList<>();
        List<ImportOaOldShopDataErrorDTO> errorList = new ArrayList<>();
        ListUtils.emptyIfNull(dataMapList)
                .forEach(data -> {
                    try {
                        ImportOaOldShopDataDTO importOaOldShopDataDTO = new ImportOaOldShopDataDTO();
                        importOaOldShopDataDTO.setShopCode(String.valueOf(data.get("门店编码")));
                        list.add(importOaOldShopDataDTO);
                    } catch (Exception e) {
                        log.info("dataHandlerV2025029 转化dto error:{}", JSONObject.toJSONString(data));
                    }
                });
        log.info("导入数据条数:{}", list.size());
        if (CollectionUtils.isEmpty(list)) {
            log.info("导入数据转化为空");
            return false;
        }
        List<String> shopCodeList = list.stream().map(ImportOaOldShopDataDTO::getShopCode).collect(Collectors.toList());
        List<ShopInfoDO> shopInfoList = shopInfoDAO.selectByShopCodeList(shopCodeList);
        if (CollectionUtils.isEmpty(shopInfoList)) {
            log.info("导入数据根据shopCode 未找到数据");
        }
        List<Long> shopIds = shopInfoList.stream().map(ShopInfoDO::getId).collect(Collectors.toList());
        Map<String, List<ShopInfoDO>> shopMapByCode = shopInfoList.stream().collect(Collectors.groupingBy(ShopInfoDO::getShopCode));
        //装修验收数据
        List<AcceptanceInfoDO> acceptanceInfoDOList = acceptanceInfoDAO.selectByShopIds(shopIds);
        Map<Long, AcceptanceInfoDO> acceptanceInfoMap = acceptanceInfoDOList.stream().collect(Collectors.toMap(AcceptanceInfoDO::getShopId, item -> item));
        //合同阶段
        List<ShopStageInfoDO> signFranchiseStageList = shopStageInfoDAO.getSubStageList(shopIds, ShopSubStageEnum.SHOP_STAGE_8.getShopSubStage());
        Map<Long, ShopStageInfoDO> signFranchiseStageMap = signFranchiseStageList.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, Function.identity()));
        //装修阶段需要变更的shopId
        List<Long> fitmentFhopIdList = new ArrayList<>();
        //装修验收表需要初始化的门店
        List<Long> initFitmentShopIdList = new ArrayList<>();
        for (ImportOaOldShopDataDTO dto : list) {
            String shopCode = dto.getShopCode();
            List<ShopInfoDO> shopInfoDOS = shopMapByCode.get(shopCode);
            if (CollectionUtils.isEmpty(shopInfoDOS)) {
                errorList.add(new ImportOaOldShopDataErrorDTO(dto.getShopCode(), "门店编码未找到"));
                continue;
            }
            if (shopInfoDOS.size() > 1) {
                errorList.add(new ImportOaOldShopDataErrorDTO(dto.getShopCode(), "门店编码重复"));
                continue;
            }
            ShopInfoDO shopInfoDO = shopInfoDOS.get(0);
            Long shopId = shopInfoDO.getId();
            ShopStageInfoDO signFranchiseStage = signFranchiseStageMap.get(shopId);
            if (!signFranchiseStage.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_84.getShopSubStageStatus())) {
                errorList.add(new ImportOaOldShopDataErrorDTO(dto.getShopCode(), "合同阶段未完成"));
                continue;
            }
            AcceptanceInfoDO acceptanceInfoDO = acceptanceInfoMap.get(shopId);
            if (Objects.isNull(acceptanceInfoDO)) {
                initFitmentShopIdList.add(shopId);
            }
            fitmentFhopIdList.add(shopId);
        }
        //装修stage
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_863);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_91);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_112);
        shopStageInfoDAO.dataUpdateStatus(fitmentFhopIdList, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_123);
        //装修表初始化
        acceptanceInfoDAO.initAcceptanceInfo(initFitmentShopIdList);
        if (!errorList.isEmpty()) {
            task.setStatus(ImportTaskStatusEnum.ERROR.getCode());
            String url = null;
            try {
                url = easyExcelUtil.exportExcel(ImportOaOldShopDataErrorDTO.class, errorList, null,
                        FileTypeEnum.IMPORT_FITMENT_SHOP_STAGE_DATA_ERROR_LIST.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()),
                        FileTypeEnum.IMPORT_FITMENT_SHOP_STAGE_DATA_ERROR_LIST.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()));
            } catch (Exception e) {
                log.info("导出失败列表失败 errorList:{}", JSONObject.toJSONString(errorList));
            }
            task.setFileUrl(url);
        } else {
            task.setStatus(ImportTaskStatusEnum.SUCCESS.getCode());
        }
        task.setTotalNum(dataMapList.size());
        task.setSuccessNum(dataMapList.size() - errorList.size());
        importTaskMapper.update(eid, task);
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean franchiseFeeStageDateHandler() {
        //处理加盟费阶段待审核（对账中）
        List<ShopStageInfoDO> waitAuditStageList = shopStageInfoDAO.getShopStageInfoByShopSubStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus());
        log.info("waitAuditStageList:{}", JSONObject.toJSONString(waitAuditStageList));
        List<Long> waitAuditShopIdList = waitAuditStageList.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
//        shopStageInfoDAO.dataUpdateStatus(waitAuditShopIdList,ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_73);
        franchiseFeeDAO.batchUpdateXgjCollectionStatus(waitAuditShopIdList, XGJCollectionStatusEnum.WAIT_PAY.getCode());
       // linePayDAO.updateXgjClaimStatus(waitAuditShopIdList, ClaimStatusEnum.TO_BE_CLAIMED.getCode(), PayBusinessTypeEnum.FRANCHISE_FEE.getCode());
        //已缴费 修改新管家回调状态
        List<ShopStageInfoDO> isPaidStageList = shopStageInfoDAO.getShopStageInfoByShopSubStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_73.getShopSubStageStatus());
        List<Long> isPaidShopId = isPaidStageList.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        List<FranchiseFeeDO> franchiseFeeByShopIds = franchiseFeeMapper.getFranchiseFeeByShopIds(isPaidShopId);
        List<FranchiseFeeStageDateDTO> franchiseFeeStageDateDTOList = new ArrayList<>();
        for (FranchiseFeeDO franchiseFeeDO : franchiseFeeByShopIds){
            FranchiseFeeStageDateDTO dto = new FranchiseFeeStageDateDTO();
            dto.setShopId(franchiseFeeDO.getShopId());
            dto.setXgjCollectionStatus(XGJCollectionStatusEnum.COMPLETED.getCode());
            dto.setXgjFeesPaid(dto.getXgjFeesPaid()
                    .add(new BigDecimal(franchiseFeeDO.getYearFranchiseFee()))
                    .add(new BigDecimal(franchiseFeeDO.getLoanMargin()))
                    .add(new BigDecimal(franchiseFeeDO.getFirstYearManageFee()))
                    .add(new BigDecimal(franchiseFeeDO.getPerformanceBond()))
                    .add(new BigDecimal(franchiseFeeDO.getFirstYearFee()))
            );
            franchiseFeeStageDateDTOList.add(dto);
        }
        franchiseFeeDAO.batchUpdateXgjCollectionStatusAndXgjFeesPaid(franchiseFeeStageDateDTOList);
       // linePayDAO.updateXgjClaimStatus(isPaidShopId, ClaimStatusEnum.CLAIMED.getCode(), PayBusinessTypeEnum.FRANCHISE_FEE.getCode());
        //待加盟商缴费阶段
        List<ShopStageInfoDO> waitPayStageList = shopStageInfoDAO.getShopStageInfoByShopSubStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_71.getShopSubStageStatus());
        List<Long> waitPayShopIds = waitPayStageList.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        franchiseFeeDAO.batchUpdateXgjCollectionStatus(waitPayShopIds, XGJCollectionStatusEnum.WAIT_PAY.getCode());
        //审批拒绝阶段
        List<ShopStageInfoDO> refuseStageList = shopStageInfoDAO.getShopStageInfoByShopSubStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_74.getShopSubStageStatus());
        List<Long> refuseShopIds = refuseStageList.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        franchiseFeeDAO.batchUpdateXgjCollectionStatus(refuseShopIds, XGJCollectionStatusEnum.WAIT_PAY.getCode());
        linePayDAO.deleteByShopId(refuseShopIds);
        shopStageInfoDAO.dataUpdateStatus(refuseShopIds,ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_71);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean franchiseFeeDateHandler(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<LinePayDO> dateHandler = linePayDAO.getDateHandler();
        List<ShopStageInfoDO> waitAuditStageList = shopStageInfoDAO.getShopStageInfoByShopSubStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus());
        log.info("waitAuditStageList:{}", JSONObject.toJSONString(waitAuditStageList));
        List<Long> waitAuditShopIdList = waitAuditStageList.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        for (LinePayDO linePayDO : dateHandler) {
            JSONArray jsonArray = JSONObject.parseArray(linePayDO.getCombinedField());
            JSONObject jsonObject = jsonArray.getJSONObject(0);
            linePayDO.setPayTime(jsonObject.getDate("payTime"));
            linePayDO.setPayPic(jsonObject.getString("payPic"));
            if (waitAuditShopIdList.contains(linePayDO.getShopId())) {
                linePayDO.setXgjClaimStatus(ClaimStatusEnum.TO_BE_CLAIMED.getCode());
                if (StringUtils.isBlank(linePayDO.getPaymentReceiptCode())) {
                    linePayDO.setPaymentReceiptCode(linePayService.getPaymentReceiptCode());
                }
            } else {
                linePayDO.setXgjClaimStatus(ClaimStatusEnum.CLAIMED.getCode());
            }
        }
        linePayDAO.dataUpdateLinePay(dateHandler);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchStatusRefreshYls(BatchStatusRefreshDTO batchStatusRefreshDTO) {
        if (CollectionUtils.isEmpty(batchStatusRefreshDTO.getShopCode())) {
            log.info("数据处理 门店编码为空");
            return null;
        }
        for (String shopCode : batchStatusRefreshDTO.getShopCode()) {
            StatusRefreshDTO statusRefreshDTO = new StatusRefreshDTO();
            statusRefreshDTO.setShopCode(shopCode);
            statusRefreshDTO.setSystemSource(batchStatusRefreshDTO.getSystemSource());
            statusRefreshDTO.setOpenStatus(batchStatusRefreshDTO.getOpenStatus());
            openApiService.statusRefresh(statusRefreshDTO);
        }
        List<String> shopCodeList = new ArrayList<>();
        for (String shopCode : batchStatusRefreshDTO.getShopCode()) {
            shopCodeList.add(StringUtils.substringAfter(shopCode, "_"));
        }
        posAndOrderInfoDAO.batchUpdateYlsRemarkByShopCode(shopCodeList, batchStatusRefreshDTO.getRemark());
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void dataHandlerCreateStore() {
        //已经创建了的门店
        List<IsCreateStoreDTO> isCreateStore = shopInfoDAO.selectIsCreateStore( );
        List<ShopInfoDO> updateList = new ArrayList<>();
        for (IsCreateStoreDTO isCreateStoreDTO:isCreateStore){
            ShopInfoDO shopInfoDO = new ShopInfoDO();
            shopInfoDO.setId(isCreateStoreDTO.getShopId());
            shopInfoDO.setManagerRegionId(isCreateStoreDTO.getPid());
            updateList.add(shopInfoDO);
        }
        List<BigRegionDTO> bigRegionDTOS = bigRegionDAO.queryAllBigRegion(null, null,null);
        Map<Long, BigRegionDTO> bigRegionDTOMap = bigRegionDTOS.stream().collect(Collectors.toMap(BigRegionDTO::getRegionId, x -> x));
        //XX大区  正烧鸡
        List<Long> storeManageIds = bigRegionDTOS.stream().filter(x -> x.getStoreManageRegionId() != null).map(BigRegionDTO::getStoreManageRegionId).collect(Collectors.toList());
        //加盟分部
        List<Long> branchStoreManageIds = bigRegionDTOS.stream().filter(x -> x.getStoreManageRegionId() == null).map(BigRegionDTO::getRegionId).collect(Collectors.toList());

        //查询门店-XX大区下面的管理督导
        List<RegionDO> manageRegionList = regionDao.getSubRegionByParentIdsAndRegionType(storeManageIds, "path");
        Map<String, List<RegionDO>> manageRegionMap = manageRegionList.stream().collect(Collectors.groupingBy(RegionDO::getName));
        //查询加盟分部下的管理督导
        List<RegionDO> branchStoreManageList = regionDao.getSubRegionByParentIdsAndRegionType(branchStoreManageIds, "path");
        Map<String, List<RegionDO>> branchStoreManageMap = branchStoreManageList.stream().collect(Collectors.groupingBy(RegionDO::getName));

        List<Long> isShopIds = isCreateStore.stream().map(IsCreateStoreDTO::getShopId).collect(Collectors.toList());
        //未建店
        List<ShopInfoDO> shopInfoDOS = shopInfoDAO.selectByNotCreateStore(isShopIds);
        //List<ShopInfoDO> shopInfoDOS = Collections.singletonList(shopInfoDAO.getShopInfo(414L));
        Set<String> investUserIds = shopInfoDOS.stream().map(ShopInfoDO::getInvestmentManager).collect(Collectors.toSet());
        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(investUserIds));
        List<ImportOaOldShopDataErrorDTO> errorList = new ArrayList<>();

        for (ShopInfoDO shopInfoDO : shopInfoDOS){
            String name = userNameMap.getOrDefault(shopInfoDO.getInvestmentManager(),"");
            if (StringUtils.isBlank(name)){
                log.info("门店招商经理未找到 shopId：{}",shopInfoDO.getId());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO(shopInfoDO.getShopCode(), "门店招商经理未找到");
                errorDTO.setShopName(shopInfoDO.getShopName());
                errorList.add(errorDTO);
                continue;
            }
            BigRegionDTO bigRegionDTO = bigRegionDTOMap.get(shopInfoDO.getRegionId());
            List<RegionDO> regions = new ArrayList<>();
            if (bigRegionDTO==null){
                log.info("门店所属大区未找到 shopId：{}",shopInfoDO.getId());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO(shopInfoDO.getShopCode(), "门店所属大区未找到");
                errorDTO.setShopName(shopInfoDO.getShopName());
                errorList.add(errorDTO);
                continue;
            }
            if (bigRegionDTO.getStoreManageRegionId()!=null){
                regions = manageRegionMap.get(name);
            }else{
                regions= branchStoreManageMap.get(name);
            }
            if (CollectionUtils.isEmpty(regions)){
                log.info("门店所属管理区域未找到 shopId：{}",shopInfoDO.getId());
                ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO(shopInfoDO.getShopCode(), "门店所属管理区域未找到");
                errorDTO.setShopName(shopInfoDO.getShopName());
                errorList.add(errorDTO);
                continue;
            }
            for(RegionDO regionDO:regions){
                if ((Long.valueOf(regionDO.getParentId()).equals(bigRegionDTO.getStoreManageRegionId())&&bigRegionDTO.getStoreManageRegionId()!=null)
                        ||(Long.valueOf(regionDO.getParentId()).equals(bigRegionDTO.getRegionId())&&bigRegionDTO.getStoreManageRegionId()==null)){
                    shopInfoDO.setManagerRegionId(regionDO.getId());
                    break;
                }
            }
          if (shopInfoDO.getManagerRegionId()==null){
              log.info("门店所属管理区域未找到 shopId：{}",shopInfoDO.getId());
              ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO(shopInfoDO.getShopCode(), "门店所属管理区域未找到");
              errorDTO.setShopName(shopInfoDO.getShopName());
              errorList.add(errorDTO);
              continue;
          }
            updateList.add(shopInfoDO);
        }
        shopInfoDAO.updateManagerRegionId(updateList);
        if (CollectionUtils.isNotEmpty(errorList)) {
            String url = null;
            try {
                url = easyExcelUtil.exportExcel(ImportOaOldShopDataErrorDTO.class, errorList, null,
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_STAGE_DATA.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()),
                        FileTypeEnum.IMPORT_OA_OLD_SHOP_STAGE_DATA.getDesc() + DateUtils.parseDateToStr(SPECIAL_DATE_START_1, new Date()));
            } catch (Exception e) {
                log.info("导出同步门店数据错误列表失败 errorList:{}", JSONObject.toJSONString(errorList));
            }
            ImportTaskDO importTaskDO = new ImportTaskDO();
            importTaskDO.setFileName("同步门店数据错误列表");
            importTaskDO.setFileType(FileTypeEnum.IMPORT_FITMENT_SHOP_STAGE.getFileType());
            importTaskDO.setIsImport(true);
            importTaskDO.setFileUrl(url);
            importTaskDO.setStatus(ImportTaskStatusEnum.ERROR.getCode());
            importTaskDO.setCreateUserId(CurrentUserHolder.getUserId());
            importTaskDO.setCreateName(CurrentUserHolder.getUser().getName());
            importTaskDO.setCreateTime(System.currentTimeMillis());
            importTaskMapper.insert(eid, importTaskDO);
        }

    }

    @Override
    public void dataHandlerPushHqt() {
        List<ShopInfoDO> pushHqtShopList = shopInfoDAO.getPushHqtShopList();
        List<Long> shopIds = pushHqtShopList.stream().map(ShopInfoDO::getId).collect(Collectors.toList());
        log.info("推送HQT的店铺shopIds：{}", JSONObject.toJSONString(shopIds));
        for (ShopInfoDO shopInfoDO : pushHqtShopList) {
            try{
                hqtAPIService.pushHqtBuild(getHqtBuildRequest(shopInfoDO.getId()));
            }catch (Exception e){
                log.info("推送HQT失败:shopId:{},mes:{}",shopInfoDO.getId(),e.getMessage());
            }
        }
    }

    @Override
    public Boolean openingAcceptanceDataHandle() {
        Integer pageSize = 100;
        Integer pageNum = 1;

        // 方式1：使用while循环获取所有页数据
        boolean hasNextPage = true;

        while (hasNextPage) {
            // 开启分页
            PageHelper.startPage(pageNum, pageSize);

            // 执行查询
            List<ShopInfoDO> shopInfoDOS = shopInfoDAO.selectByIdOrSelectAll(null);

            // 处理当前页数据
            if (CollectionUtils.isNotEmpty(shopInfoDOS)) {
                for (ShopInfoDO shopInfoDO : shopInfoDOS) {
                   //查询装修阶段 是否完成 完成=开业阶段完成 未完成=开业阶段未开始
                    ShopStageInfoDO stage = shopStageInfoDAO.getByShopIdAndSubStage(shopInfoDO.getId(), ShopSubStageEnum.SHOP_STAGE_12.getShopSubStage());
                    if (stage == null) {
                        log.info("装修阶段数据不存在 shopId:{}",shopInfoDO.getId());
                        continue;
                    }
                    ShopStageInfoDO stage27 = shopStageInfoDAO.getByShopIdAndSubStage(shopInfoDO.getId(), ShopSubStageEnum.SHOP_STAGE_27.getShopSubStage());
                    if (stage27 == null) {
                        ShopStageInfoDO shopStageInfo = null;
                        if (stage.getIsTerminated()){
                             shopStageInfo = getShopStageInfoDO(ShopSubStageEnum.SHOP_STAGE_27, stage, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_276);
                        }else {
                             shopStageInfo = getShopStageInfoDO(ShopSubStageEnum.SHOP_STAGE_27, stage, ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_00);
                        }
                        shopStageInfoDAO.batchInsert(Arrays.asList(shopStageInfo));
                    }

                }
                // 判断是否还有下一页
                if (shopInfoDOS.size() < pageSize) {
                    hasNextPage = false; // 当前页数据不足一页，说明是最后一页
                } else {
                    pageNum++; // 继续查询下一页
                }
            } else {
                hasNextPage = false; // 没有数据，结束循环
            }

            // 清除分页参数（重要！防止影响其他查询）
            PageHelper.clearPage();
        }
        return Boolean.TRUE;
    }

    public HqtBuildRequest getHqtBuildRequest(Long shopId) {
        ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(shopId);
        LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfo.getLineId());
        EnterpriseUserDO userInfoById = enterpriseUserDAO.getUserInfoById(shopInfo.getInvestmentManager());
        BigRegionDO bigRegionDO = bigRegionDAO.getByRegionId(shopInfo.getRegionId());
        if (com.cool.store.utils.poi.StringUtils.isBlank(bigRegionDO.getHqtRegionCode())){
            bigRegionDO = hqtAPIService.pushHqtRegion(bigRegionDO);
        }
        HqtBuildRequest request = new HqtBuildRequest();
        request.setShopId(shopId);
        request.setShopCode(shopInfo.getShopCode());
        request.setShopName(shopInfo.getShopName());
        request.setShopDecorationAttributes(shopInfo.getShopDecorationAttributes());
        request.setHqtRegionCode(bigRegionDO.getHqtRegionCode());
        request.setHqtRegionName(bigRegionDO.getHqtRegionName());
        request.setSupervisorName(userInfoById.getName());
        request.setSupervisorMobile(userInfoById.getMobile());
        request.setPartnershipSignatoryFirst(lineInfoDO.getUsername());
        request.setPartnershipSignatoryFirstMobile(lineInfoDO.getMobile());
        request.setShopAddress(shopInfo.getDetailAddress());
        request.setIsPayDesignFee(CommonConstants.ONE);
        if (com.cool.store.utils.poi.StringUtils.isNotBlank(shopInfo.getFranchiseBrand())) {
            request.setFranchiseBrand(Integer.valueOf(shopInfo.getFranchiseBrand()));
        }
        return request;
    }

    private static @NotNull ShopStageInfoDO getShopStageInfoDO(ShopSubStageEnum shopSubStageEnum, ShopStageInfoDO shopStageInfoDO, ShopSubStageStatusEnum shopSubStageStatus) {
        ShopStageEnum shopStageEnum = shopSubStageEnum.getShopStageEnum();
        ShopStageInfoDO shopStageInfo = new ShopStageInfoDO();
        shopStageInfo.setLineId(shopStageInfoDO.getLineId());
        shopStageInfo.setShopId(shopStageInfoDO.getShopId());
        shopStageInfo.setShopStage(shopStageEnum.getShopStage());
        shopStageInfo.setShopSubStage(shopSubStageEnum.getShopSubStage());
        shopStageInfo.setShopSubStageStatus(shopSubStageStatus.getShopSubStageStatus());
        shopStageInfo.setRemark(shopSubStageEnum.getShopSubStageName() + CommonConstants.PATH_BAR + shopSubStageStatus.getShopSubStageStatusName());
        shopStageInfo.setIsTerminated(Boolean.FALSE);
        shopStageInfo.setPlanCompleteTime(null);
        return shopStageInfo;
    }

    private static boolean check(ImportOaOldShopDataDTO dto, List<ImportOaOldShopDataErrorDTO> errorList) {
        if (StringUtil.isBlank(dto.getShopCode())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("门店编码不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getShopName())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("门店名称不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getProvince())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("省不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getCity())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("市不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getDistrict())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("区不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getShopAddress())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("门店地址不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getBuildEndTime())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("建店资料完成时间不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getContractStartDate())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("合同开始时间不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getContractEndDate())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("合同结束时间不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getYearFranchiseFee())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("加盟费不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getFirstYearManageFee())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("管理费 不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getFirstYearFee())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("品牌使用管理费不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getPerformanceBond())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("设计费不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getLoanMargin())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("保证金不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getDeclareGoodsLogisticsWarehouseName())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("报货物流仓库不能为空");
            errorList.add(errorDTO);
            return false;
        }
        if (StringUtil.isBlank(dto.getContractCode())) {
            ImportOaOldShopDataErrorDTO errorDTO = new ImportOaOldShopDataErrorDTO();
            errorDTO.setShopCode(dto.getShopCode());
            errorDTO.setErrorReason("合同编号不能为空");
            errorList.add(errorDTO);
            return false;
        }
        return true;
    }

    private static void setOrderInfo(ImportOaOldShopDataDTO dto, OrderSysInfoDO orderSysInfoDO, String warehouseCode) {
        orderSysInfoDO.setAddresseeProvince(dto.getProvince().trim());
        orderSysInfoDO.setAddresseeCity(dto.getCity().trim());
        orderSysInfoDO.setAddresseeDistrict(dto.getDistrict().trim());
        orderSysInfoDO.setAddresseeAddress(dto.getShopAddress().trim());
        if (StringUtil.isNotBlank(warehouseCode)) {
            orderSysInfoDO.setDeclareGoodsLogisticsWarehouse(warehouseCode);
        }
        orderSysInfoDO.setReceivingMsBankAccount(dto.getReceivingMsBankAccount().trim());
    }

    private ImportOaOldShopDataDTO buildColumn(Map<String, Object> data) {
        ImportOaOldShopDataDTO importOaOldShopDataDTO = new ImportOaOldShopDataDTO();
        importOaOldShopDataDTO.setShopCode(String.valueOf(data.get("门店编码")));
        importOaOldShopDataDTO.setShopName(String.valueOf(data.get("签约门店名称")));
        importOaOldShopDataDTO.setProvince(String.valueOf(data.get("省")));
        importOaOldShopDataDTO.setCity(String.valueOf(data.get("市")));
        importOaOldShopDataDTO.setDistrict(String.valueOf(data.get("区")));
        importOaOldShopDataDTO.setShopAddress(String.valueOf(data.get("门店地址")));
        importOaOldShopDataDTO.setBuildEndTime(String.valueOf(data.get("建店资料完成时间")));
        if (Objects.nonNull(data.get("店面租金"))) {
            importOaOldShopDataDTO.setMonthRent(String.valueOf(data.get("店面租金")));
        }
        if (Objects.nonNull(data.get("场地实际面积"))) {
            importOaOldShopDataDTO.setPointArea(String.valueOf(data.get("场地实际面积")));
        }
        if (Objects.nonNull(data.get("签约人2姓名"))) {
            importOaOldShopDataDTO.setPartnershipSignatorySecond(String.valueOf(data.get("签约人2姓名")));
        }
        if (Objects.nonNull(data.get("签约人2电话"))) {
            importOaOldShopDataDTO.setPartnershipSignatorySecondMobile(String.valueOf(data.get("签约人2电话")));
        }
        if (Objects.nonNull(data.get("签约人2身份证号码"))) {
            importOaOldShopDataDTO.setPartnershipSignatorySecondIdNumber(String.valueOf(data.get("签约人2身份证号码")));
        }
        if (Objects.nonNull(data.get("合同开始日期"))) {
            importOaOldShopDataDTO.setContractStartDate(String.valueOf(data.get("合同开始日期")));
        }
        if (Objects.nonNull(data.get("合同结束日期"))) {
            importOaOldShopDataDTO.setContractEndDate(String.valueOf(data.get("合同结束日期")));
        }
        if (Objects.nonNull(data.get("合同编号"))) {
            importOaOldShopDataDTO.setContractCode(String.valueOf(data.get("合同编号")));
        }
        if (Objects.nonNull(data.get("保护距离(米)"))) {
            importOaOldShopDataDTO.setProtectionDistance(String.valueOf(data.get("保护距离(米)")));
        }
        if (Objects.nonNull(data.get("介绍人"))) {
            importOaOldShopDataDTO.setIntroducer(String.valueOf(data.get("介绍人")));
        }
        if (Objects.nonNull(data.get("介绍门店"))) {
            importOaOldShopDataDTO.setIntroduceStore(String.valueOf(data.get("介绍门店")));
        }
        if (Objects.nonNull(data.get("介绍奖"))) {
            importOaOldShopDataDTO.setIntroductionAward(String.valueOf(data.get("介绍奖")));
        }
        if (Objects.nonNull(data.get("报货物流仓库"))) {
            importOaOldShopDataDTO.setDeclareGoodsLogisticsWarehouseName(String.valueOf(data.get("报货物流仓库")));
        }
        if (Objects.nonNull(data.get("收款公司民生银行账号"))) {
            importOaOldShopDataDTO.setReceivingMsBankAccount(String.valueOf(data.get("收款公司民生银行账号")));
        }
        if (Objects.nonNull(data.get("云流水账号"))) {
            importOaOldShopDataDTO.setYlsAccount(String.valueOf(data.get("云流水账号")));
        }
        if (Objects.nonNull(data.get("加盟费"))) {
            importOaOldShopDataDTO.setYearFranchiseFee(String.valueOf(data.get("加盟费")));
        }
        if (Objects.nonNull(data.get("加盟费优惠原因"))) {
            importOaOldShopDataDTO.setDiscountReason(String.valueOf(data.get("加盟费优惠原因")));
        }
        if (Objects.nonNull(data.get("管理费"))) {
            importOaOldShopDataDTO.setFirstYearManageFee(String.valueOf(data.get("管理费")));
        }
        if (Objects.nonNull(data.get("设计费"))) {
            importOaOldShopDataDTO.setPerformanceBond(String.valueOf(data.get("设计费")));
        }
        if (Objects.nonNull(data.get("保证金"))) {
            importOaOldShopDataDTO.setLoanMargin(String.valueOf(data.get("保证金")));
        }
        if (Objects.nonNull(data.get("品牌使用管理费"))) {
            importOaOldShopDataDTO.setFirstYearFee(String.valueOf(data.get("品牌使用管理费")));
        }
        return importOaOldShopDataDTO;
    }
}
