package com.cool.store.service.impl;

import com.cool.store.context.LoginUserInfo;
import com.cool.store.dao.*;
import com.cool.store.dto.DeskStageDTO;
import com.cool.store.dto.InvestmentCountDTO;
import com.cool.store.dto.PendingCountDTO;
import com.cool.store.dto.openPreparation.PlanLineDTO;
import com.cool.store.entity.*;
import com.cool.store.enums.*;
import com.cool.store.enums.point.PayBusinessTypeEnum;
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.EnterpriseUserRoleMapper;
import com.cool.store.mapper.IntentAgreementMapper;
import com.cool.store.mapper.TrainingExperienceMapper;
import com.cool.store.request.AssignPendingRequest;
import com.cool.store.request.BusinessRemarkRequest;
import com.cool.store.request.DeskRequest;
import com.cool.store.service.DeskService;
import com.cool.store.service.RegionService;
import com.cool.store.service.SysRoleService;
import com.cool.store.service.UserAuthMappingService;
import com.cool.store.utils.BeanUtil;
import com.cool.store.utils.StringUtil;
import com.cool.store.utils.poi.DateUtils;
import com.cool.store.vo.BaseInfoVO;
import com.cool.store.vo.LabelBaseInfoVO;
import com.cool.store.vo.desk.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

import static com.cool.store.enums.WorkflowSubStageStatusEnum.*;
import static com.cool.store.enums.point.ShopSubStageStatusEnum.*;
import static com.cool.store.utils.poi.DateUtils.SPECIAL_DATE_START;
import static com.cool.store.utils.poi.DateUtils.YYYY_MM_DD_HH_MM_SS;

/**
 * @Author suzhuhong
 * @Date 2024/3/26 15:15
 * @Version 1.0
 */
@Service
public class DeskServiceImpl implements DeskService {

    @Resource
    private SignFranchiseDAO signFranchiseDAO;
    @Resource
    DecorationMeasureDAO decorationMeasureDAO;
    @Resource
    LineInfoDAO lineInfoDAO;
    @Resource
    HyPartnerLabelDAO hyPartnerLabelDAO;
    @Resource
    HyOpenAreaInfoDAO hyOpenAreaInfoDAO;
    @Resource
    LineInterviewDAO lineInterviewDAO;
    @Resource
    LinePayDAO linePayDAO;
    @Resource
    IntentAgreementMapper intentAgreementMapper;
    @Resource
    TrainingExperienceMapper trainingExperienceMapper;
    @Resource
    ShopStageInfoDAO shopStageInfoDAO;
    @Resource
    ShopInfoDAO shopInfoDAO;
    @Resource
    EnterpriseUserDAO enterpriseUserDAO;
    @Resource
    RegionService regionService;
    @Resource
    SysRoleService sysRoleService;
    @Resource
    UserAuthMappingService userAuthMappingService;
    @Autowired
    private EnterpriseUserRoleMapper enterpriseUserRoleMapper;
    @Autowired
    private OperationLogDAO operationLogDAO;
    @Autowired
    private DecorationDesignInfoDAO decorationDesignInfoDAO;
    @Autowired
    private AcceptanceInfoDAO acceptanceInfoDAO;
    @Autowired
    private PointInfoDAO pointInfoDAO;
    @Autowired
    private ShopStageRemarkInfoDAO shopStageRemarkInfoDAO;
    @Resource
    ShopAccountDAO shopAccountDAO;
    @Resource
    OperationsConsultantAssignDAO operationsConsultantAssignDAO;
    @Resource
    private RegionDao regionDao;
    @Resource
    ShopDeliveryPlanDAO shopDeliveryPlanDAO;

    @Override
    public PageInfo<IntendPendingVO> intendPendingList(Integer pageNum, Integer pageSize, String userId, String keyword) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(userId);
        List<LineInfoDO> lineInfoDOS = null;
        if (userRoleIds.contains(UserRoleEnum.REGION_MANAGER.getCode())){
            //大区总 根据管辖查询
            List<String> authRegionIds = userAuthMappingService.getAuthRegionIdByUserId(userId,Boolean.TRUE);
            PageHelper.startPage(pageNum, pageSize);
            lineInfoDOS = lineInfoDAO.listByInvestmentManager(null, Arrays.asList(INTENT_6.getCode()), keyword,authRegionIds);
        }else {
            PageHelper.startPage(pageNum, pageSize);
            lineInfoDOS = lineInfoDAO.listByInvestmentManager(userId, Arrays.asList(INTENT_5.getCode()), keyword,null);
        }

        PageInfo page = new PageInfo(lineInfoDOS);
        Map<Long, HyPartnerLabelDO> userPortraitMap = this.getUserPortraitMap(lineInfoDOS);
        List<Long> wantShopAreaIds = lineInfoDOS.stream().filter(lineInfoDO -> lineInfoDO.getWantShopAreaId() != null).map(LineInfoDO::getWantShopAreaId).collect(Collectors.toList());
        Map<Long, String> wantShopAreaMap = hyOpenAreaInfoDAO.selectNameMapByIds(wantShopAreaIds);
        List<Long> lineIds = lineInfoDOS.stream().map(LineInfoDO::getId).collect(Collectors.toList());
        List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByLineIdsAndStage(lineIds, Arrays.asList(INTENT_5.getCode()));
        Map<Long, ShopStageRemarkInfoDO> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getLineId, Function.identity()));
        List<IntendPendingVO> list = new ArrayList<>();
        lineInfoDOS.forEach(x -> {
            BaseInfoVO baseInfoVO = convertToBaseInfoVO(x, userPortraitMap, wantShopAreaMap);
            IntendPendingVO intendPendingVO = new IntendPendingVO(baseInfoVO);
            intendPendingVO.setJoinTime(new Date());
            intendPendingVO.setJoinMode(x.getJoinMode());
            intendPendingVO.setUpdateTime(x.getUpdateTime());
            intendPendingVO.setBusinessRemark(remarkInfoMap.getOrDefault(x.getId(), new ShopStageRemarkInfoDO()).getRemark());
            list.add(intendPendingVO);
        });

        page.setList(list);
        return page;
    }


    @Override
    public PageInfo<PayStagePendingVO> payStagePendingList(Integer pageNum, Integer pageSize, LoginUserInfo user, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<LineInfoDO> lineInfoDOS = lineInfoDAO.listByInvestmentManager(user.getUserId(), Arrays.asList(WorkflowSubStageStatusEnum.PAY_DEPOSIT_50.getCode()), keyword,null);
        PageInfo page = new PageInfo(lineInfoDOS);
        Map<Long, HyPartnerLabelDO> userPortraitMap = this.getUserPortraitMap(lineInfoDOS);
        List<Long> wantShopAreaIds = lineInfoDOS.stream().filter(lineInfoDO -> lineInfoDO.getWantShopAreaId() != null).map(LineInfoDO::getWantShopAreaId).collect(Collectors.toList());
        Map<Long, String> wantShopAreaMap = hyOpenAreaInfoDAO.selectNameMapByIds(wantShopAreaIds);
        List<Long> lineIds = lineInfoDOS.stream().filter(lineInfoDO -> lineInfoDO.getId() != null).map(LineInfoDO::getId).collect(Collectors.toList());
        Map<Long, LinePayDO> payMap = linePayDAO.getLinePayByLineIds(lineIds, PayBusinessTypeEnum.INTENT_MONEY.getCode());
        List<PayStagePendingVO> list = new ArrayList<>();
        List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByLineIdsAndStage(lineIds, Arrays.asList(WorkflowSubStageStatusEnum.PAY_DEPOSIT_50.getCode()));
        Map<Long, ShopStageRemarkInfoDO> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getLineId, Function.identity()));

        lineInfoDOS.forEach(x -> {
            BaseInfoVO baseInfoVO = convertToBaseInfoVO(x, userPortraitMap, wantShopAreaMap);
            PayStagePendingVO payStagePendingVO = new PayStagePendingVO(baseInfoVO);
            LinePayDO linePayDO = payMap.get(x.getId());
            if (linePayDO != null && linePayDO.getPayTime() != null) {
                payStagePendingVO.setPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, linePayDO.getPayTime()));
            }
            payStagePendingVO.setUpdateTime(x.getUpdateTime());
            payStagePendingVO.setBusinessRemark(remarkInfoMap.getOrDefault(x.getId(), new ShopStageRemarkInfoDO()).getRemark());
            list.add(payStagePendingVO);
        });
        page.setList(list);
        return page;
    }

    @Override
    public PageInfo<SigningPendingVO> signingPendingList(Integer pageNum, Integer pageSize, LoginUserInfo user, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<LineInfoDO> lineInfoDOS = lineInfoDAO.listByInvestmentManager(user.getUserId(),
                Arrays.asList(WorkflowSubStageStatusEnum.SIGN_INTENT_AGREEMENT_70.getCode()), keyword,null);
        PageInfo page = new PageInfo(lineInfoDOS);
        Map<Long, HyPartnerLabelDO> userPortraitMap = this.getUserPortraitMap(lineInfoDOS);
        List<Long> wantShopAreaIds = lineInfoDOS.stream().filter(lineInfoDO -> lineInfoDO.getWantShopAreaId() != null).map(LineInfoDO::getWantShopAreaId).collect(Collectors.toList());
        Map<Long, String> wantShopAreaMap = hyOpenAreaInfoDAO.selectNameMapByIds(wantShopAreaIds);
        List<Long> lineIds = lineInfoDOS.stream().filter(lineInfoDO -> lineInfoDO.getId() != null).map(LineInfoDO::getId).collect(Collectors.toList());
        List<SigningBaseInfoDO> signingBaseInfoDOS = intentAgreementMapper.selectByLineIds(lineIds);
        Map<Long, Date> dateMap = signingBaseInfoDOS.stream().collect(Collectors.toMap(SigningBaseInfoDO::getLineId, SigningBaseInfoDO::getCreateTime));
        List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByLineIdsAndStage(lineIds, Arrays.asList(WorkflowSubStageStatusEnum.SIGN_INTENT_AGREEMENT_70.getCode()));
        Map<Long, ShopStageRemarkInfoDO> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getLineId, Function.identity()));
        List<SigningPendingVO> list = new ArrayList<>();
        lineInfoDOS.forEach(x -> {
            BaseInfoVO baseInfoVO = convertToBaseInfoVO(x, userPortraitMap, wantShopAreaMap);
            SigningPendingVO signingPendingVO = new SigningPendingVO(baseInfoVO);
            Date date = dateMap.get(x.getId());
            if (date != null) {
                signingPendingVO.setSubmitTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, date));
            }
            signingPendingVO.setUpdateTime(x.getUpdateTime());
            signingPendingVO.setBusinessRemark(remarkInfoMap.getOrDefault(x.getId(), new ShopStageRemarkInfoDO()).getRemark());
            list.add(signingPendingVO);
        });
        page.setList(list);
        return page;
    }


    /**
     * convertToBaseInfoVO
     *
     * @param lineInfoDO
     * @param userPortraitMap
     * @param wantShopAreaMap
     * @return
     */
    @Override
    public BaseInfoVO convertToBaseInfoVO(LineInfoDO lineInfoDO, Map<Long, HyPartnerLabelDO> userPortraitMap, Map<Long, String> wantShopAreaMap) {
        BaseInfoVO baseInfoVO = new BaseInfoVO();
        BeanUtil.copyProperties(lineInfoDO, baseInfoVO);
        baseInfoVO.setLineId(lineInfoDO.getId());
        String userPortrait = lineInfoDO.getUserPortrait();
        List<LabelBaseInfoVO> labelBaseInfoList = new ArrayList<>();
        if (StringUtil.isNotEmpty(userPortrait)) {
            Arrays.asList(userPortrait.split(",")).subList(1, userPortrait.split(",").length).forEach(x -> {
                LabelBaseInfoVO labelBaseInfoVO = new LabelBaseInfoVO();
                HyPartnerLabelDO hyPartnerLabelDO = userPortraitMap.get(Long.valueOf(x));
                if (hyPartnerLabelDO != null) {
                    labelBaseInfoVO.setLabelId(userPortraitMap.getOrDefault(Long.valueOf(x), new HyPartnerLabelDO()).getId());
                    labelBaseInfoVO.setLabelName(userPortraitMap.getOrDefault(Long.valueOf(x), new HyPartnerLabelDO()).getLabelName());
                    labelBaseInfoList.add(labelBaseInfoVO);
                }
            });
        }
        baseInfoVO.setUserPortraitList(labelBaseInfoList);
        baseInfoVO.setJoinMode(lineInfoDO.getJoinMode());
        baseInfoVO.setWantShopAreaName(wantShopAreaMap.get(lineInfoDO.getWantShopAreaId()));

        return baseInfoVO;
    }


    /**
     * 用户画像MAP
     *
     * @param lineInfoDOList
     * @return
     */
    @Override
    public Map<Long, HyPartnerLabelDO> getUserPortraitMap(List<LineInfoDO> lineInfoDOList) {
        List<Long> libelIds = new ArrayList<>();
        lineInfoDOList.stream().forEach(x -> {
            if (StringUtil.isNotEmpty(x.getUserPortrait())) {
                List<String> list = Arrays.asList(x.getUserPortrait().split(",")).subList(1, x.getUserPortrait().split(",").length);
                libelIds.addAll(list.stream().map(Long::valueOf).collect(Collectors.toList()));
            }
        });
        List<HyPartnerLabelDO> hyPartnerLabelDOS = hyPartnerLabelDAO.listByIds(libelIds);
        if (CollectionUtils.isEmpty(hyPartnerLabelDOS)) {
            return new HashMap<>();
        }
        return hyPartnerLabelDOS.stream().collect(Collectors.toMap(HyPartnerLabelDO::getId, x -> x));
    }

    @Override
    public PendingCountDTO getPendingCount(LoginUserInfo user) {
        PendingCountDTO pendingCount = lineInfoDAO.pendingCount(user.getUserId());
        return pendingCount;
    }

    @Override
    public InvestmentCountDTO getInvestmentCount(LoginUserInfo user) {
        return lineInfoDAO.investmentData(user.getUserId());
    }


    @Override
    public PageInfo<PreparationCommonPendingVO> payFranchiseFeesPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        PageInfo<PreparationCommonPendingVO> pageInfo = new PageInfo<>();
        List<Integer> subStageStatusList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(userRoleIds)) {
            // 招商经理代填
            if (userRoleIds.contains(UserRoleEnum.INVESTMENT_MANGER.getCode())) {
                pageInfo = commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_7,
                        Arrays.asList(SHOP_SUB_STAGE_STATUS_71.getShopSubStageStatus(), SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus()), Boolean.FALSE);
            } else {
                Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
                if (userRoleIds.contains(UserRoleEnum.JOIN_OFFICE.getCode()) || userRoleIds.contains(UserRoleEnum.REGION_OFFICE.getCode()) || isAdmin) {
                    subStageStatusList.add(SHOP_SUB_STAGE_STATUS_70.getShopSubStageStatus());
                }
                if (userRoleIds.contains(UserRoleEnum.BRANCH_OFFICE.getCode()) || userRoleIds.contains(UserRoleEnum.REGION_OFFICE.getCode()) || isAdmin) {
                    subStageStatusList.add(SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus());
                }
                if (!subStageStatusList.isEmpty()) {
                    pageInfo = commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_7,
                            subStageStatusList, Boolean.TRUE);
                }
            }
        }
        return pageInfo;
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> signingOfFranchiseContractPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Integer> subStageStatusList = new ArrayList<>();
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        if (userRoleIds.contains(UserRoleEnum.JOIN_OFFICE.getCode()) || userRoleIds.contains(UserRoleEnum.REGION_OFFICE.getCode()) || isAdmin) {
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_80.getShopSubStageStatus());
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_85.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.BRANCH_OFFICE.getCode()) || userRoleIds.contains(UserRoleEnum.REGION_OFFICE.getCode()) || isAdmin) {
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_83.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.FINANCE.getCode())) {
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_83_5.getShopSubStageStatus());
        }
        if (CollectionUtils.isEmpty(subStageStatusList)) {
            return new PageInfo<>();
        }
        PageInfo<PreparationCommonPendingVO> pageInfo = commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_8,
                subStageStatusList, Boolean.TRUE);
        return pageInfo;

    }

    @Override
    public PageInfo<PreparationCommonPendingVO> standardStorePendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Integer> subStageStatusList = new ArrayList<>();
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        //两个角色都包含
        if (userRoleIds.contains(UserRoleEnum.AI_STORE_TYPE_APPROVE.getCode())&&userRoleIds.contains(UserRoleEnum.FINANCE.getCode())){
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_281.getShopSubStageStatus());
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_282.getShopSubStageStatus());
        }
        //立规 待确认
        if (userRoleIds.contains(UserRoleEnum.AI_STORE_TYPE_APPROVE.getCode())){
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_281.getShopSubStageStatus());
        }
        //如果是财务 待财务确认
        if (userRoleIds.contains(UserRoleEnum.FINANCE.getCode())){
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_282.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.INVESTMENT_MANGER.getCode())){
            subStageStatusList.add(SHOP_SUB_STAGE_STATUS_281_5.getShopSubStageStatus());
            return commonPendingVOPageInfo(deskRequest, user,
                    ShopSubStageEnum.SHOP_STAGE_28, subStageStatusList, Boolean.FALSE);
        }
        if (CollectionUtils.isEmpty(subStageStatusList)){
            return new PageInfo<>();
        }
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        PageInfo<PreparationCommonPendingVO> pageInfo = commonPendingVOPageInfo(deskRequest, isAdmin ? null : user,
                ShopSubStageEnum.SHOP_STAGE_28, subStageStatusList, isAdmin ? Boolean.FALSE : Boolean.TRUE);
        return pageInfo;
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> invoiceReturnPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, null, ShopSubStageEnum.SHOP_STAGE_8_5,
                Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_85_1.getShopSubStageStatus()), Boolean.FALSE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> openingAndOperationPlanPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_14, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_140.getShopSubStageStatus()), Boolean.FALSE);
    }


    @Override
    public PageInfo<PreparationCommonPendingVO> trainListPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        /// 如果是管理员则查询所有 其他角色查询管
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        return commonPendingVOPageInfo(deskRequest, isAdmin ? null : user, ShopSubStageEnum.SHOP_STAGE_5,
                Collections.singletonList(SHOP_SUB_STAGE_STATUS_50.getShopSubStageStatus()), isAdmin ? Boolean.FALSE : Boolean.TRUE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> xinFaListPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, null, ShopSubStageEnum.SHOP_STAGE_23,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_230.getShopSubStageStatus()), Boolean.FALSE);

    }

    @Override
    public PageInfo<PreparationCommonPendingVO> posListPendingList(DeskRequest deskRequest, LoginUserInfo user) {

        return commonPendingVOPageInfo(deskRequest, null, ShopSubStageEnum.SHOP_STAGE_16,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_160.getShopSubStageStatus()), Boolean.FALSE);

    }

    @Override
    public PageInfo<PreparationCommonPendingVO> tentPassListPendingList(DeskRequest deskRequest, LoginUserInfo user) {

        return commonPendingVOPageInfo(deskRequest, null, ShopSubStageEnum.SHOP_STAGE_24,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_240.getShopSubStageStatus()), Boolean.FALSE);

    }

    @Override
    public PageInfo<PreparationCommonPendingVO> orderSysPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        //订单组 只查询待授权的数据
        if (userRoleIds.contains(UserRoleEnum.ORDER_GROUP.getCode())) {
            //只查管辖的待授权的数据
            return commonPendingVOPageInfo(deskRequest,user , ShopSubStageEnum.SHOP_STAGE_17,
                    Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_172.getShopSubStageStatus()), Boolean.TRUE);
        }
        //其他角色能看到
        return commonPendingVOPageInfo(deskRequest, null, ShopSubStageEnum.SHOP_STAGE_17,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_170.getShopSubStageStatus()), Boolean.FALSE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> designPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        List<Integer> subStageStatusList = new ArrayList<>();
        //报价员和管理员不指定人，看阶段符合的全部数据
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        if (userRoleIds.contains(UserRoleEnum.QUOTATION_OFFICE.getCode()) || isAdmin) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_902.getShopSubStageStatus());
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_903.getShopSubStageStatus());
            if (isAdmin) {
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_90.getShopSubStageStatus());
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_901.getShopSubStageStatus());
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_902.getShopSubStageStatus());
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_903.getShopSubStageStatus());
            }
            return commonPendingVOPageInfo(deskRequest, isAdmin ? null : user, ShopSubStageEnum.SHOP_STAGE_9, subStageStatusList, isAdmin ? Boolean.FALSE : Boolean.TRUE);
        } else {
            List<PreparationCommonPendingVO> list = new ArrayList<>();
            list = getDesignPendingVO(deskRequest, user, userRoleIds);

            if (CollectionUtils.isEmpty(list)) {
                return new PageInfo<>();
            }
            List<Long> shopIds = list.stream().map(PreparationCommonPendingVO::getShopId).collect(Collectors.toList());
            List<Long> lineIds = list.stream().map(PreparationCommonPendingVO::getLineId).collect(Collectors.toList());
            List<LineInfoDO> lineInfoDOS = lineInfoDAO.getByLineIds(lineIds);
            Map<Long, LineInfoDO> lineMap = lineInfoDOS.stream().collect(Collectors.toMap(LineInfoDO::getId, line -> line));
            List<SignFranchiseDO> signType = signFranchiseDAO.getSignType(shopIds);
            Map<Long, SignFranchiseDO> signTypeMap = signType.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, dto -> dto));

            Set<Long> regionIdSet = list.stream().map(PreparationCommonPendingVO::getRegionId).collect(Collectors.toSet());
            Map<Long, String> regionNameMap = regionService.getBelongWarRegionNameMap(new ArrayList<>(regionIdSet));

            Set<String> investmentManagerIds = list.stream().map(PreparationCommonPendingVO::getInvestmentManager).collect(Collectors.toSet());
            Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(investmentManagerIds));

            for (PreparationCommonPendingVO preparationCommonPendingVO : list) {
                LineInfoDO lineInfoDO = lineMap.get(preparationCommonPendingVO.getLineId());
                if (lineInfoDO == null) {
                    continue;
                }
                SignFranchiseDO signFranchiseDO = signTypeMap.getOrDefault(preparationCommonPendingVO.getShopId(), new SignFranchiseDO());
                preparationCommonPendingVO.setSignType(signFranchiseDO.getSignType());
                preparationCommonPendingVO.setPartnerName(lineInfoDO.getUsername());
                preparationCommonPendingVO.setPartnerPhone(lineInfoDO.getMobile());
                preparationCommonPendingVO.setRegionNodeName(regionNameMap.getOrDefault(preparationCommonPendingVO.getRegionId(), ""));
                preparationCommonPendingVO.setInvestmentManager(userNameMap.getOrDefault(preparationCommonPendingVO.getInvestmentManager(), ""));
                preparationCommonPendingVO.setSubmitTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, preparationCommonPendingVO.getUpdateTime()));
            }
            return new PageInfo<>(list);
        }
    }

    private List<PreparationCommonPendingVO> getDesignPendingVO(DeskRequest deskRequest, LoginUserInfo user, List<Long> userRoleIds) {
        //只有设计组长 查询 指定当前用户和阶段为 900 待分配设计师
        if (userRoleIds.contains(UserRoleEnum.HEAD_OF_DESIGN.getCode()) && !userRoleIds.contains(UserRoleEnum.DESIGN_CUSTOMER.getCode())) {
            PageHelper.startPage(deskRequest.getPageNum(), deskRequest.getPageSize());
            List<PreparationCommonPendingVO> resultList = decorationMeasureDAO.getShopIdListByDesignUserIdAndShopStage(user.getUserId(), deskRequest);
            List<Long> shopIds = resultList.stream().map(PreparationCommonPendingVO::getShopId).collect(Collectors.toList());
            List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_90.getShopSubStageStatus()));
            Map<Long, List<ShopStageRemarkInfoDO>> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.groupingBy(ShopStageRemarkInfoDO::getShopId));
            for (PreparationCommonPendingVO preparationCommonPendingVO : resultList) {
                List<ShopStageRemarkInfoDO> remarkInfoList = remarkInfoMap.getOrDefault(preparationCommonPendingVO.getShopId(), new ArrayList<>());
                Map<Integer, String> remarkMapByShopSubStageStatus = remarkInfoList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopSubStageStatus, ShopStageRemarkInfoDO::getRemark));
                preparationCommonPendingVO.setBusinessRemark(remarkMapByShopSubStageStatus.getOrDefault(preparationCommonPendingVO.getSubStageStatus(), ""));
            }
            return resultList;
        }
        //只有设计师 查询 指定当前用户和阶段为 901
        if (userRoleIds.contains(UserRoleEnum.DESIGN_CUSTOMER.getCode()) && !userRoleIds.contains(UserRoleEnum.HEAD_OF_DESIGN.getCode())) {
            PageHelper.startPage(deskRequest.getPageNum(), deskRequest.getPageSize());
            List<PreparationCommonPendingVO> resultList = decorationDesignInfoDAO.getByDesignUserIdAndShopStage(user.getUserId(), deskRequest);
            List<Long> shopIds = resultList.stream().map(PreparationCommonPendingVO::getShopId).collect(Collectors.toList());
            List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_901.getShopSubStageStatus()));
            Map<Long, List<ShopStageRemarkInfoDO>> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.groupingBy(ShopStageRemarkInfoDO::getShopId));
            for (PreparationCommonPendingVO preparationCommonPendingVO : resultList) {
                List<ShopStageRemarkInfoDO> remarkInfoList = remarkInfoMap.getOrDefault(preparationCommonPendingVO.getShopId(), new ArrayList<>());
                Map<Integer, String> remarkMapByShopSubStageStatus = remarkInfoList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopSubStageStatus, ShopStageRemarkInfoDO::getRemark));
                preparationCommonPendingVO.setBusinessRemark(remarkMapByShopSubStageStatus.getOrDefault(preparationCommonPendingVO.getSubStageStatus(), ""));
            }
            return resultList;
        }
        //有 设计组长 和 设计师 查询 指定当前用户和  阶段为 900 待分配设计师 阶段为 901 设计中
        if (userRoleIds.contains(UserRoleEnum.DESIGN_CUSTOMER.getCode()) && userRoleIds.contains(UserRoleEnum.HEAD_OF_DESIGN.getCode())) {
            PageHelper.startPage(deskRequest);
            List<PreparationCommonPendingVO> resultList = decorationMeasureDAO.getShopIdListByDesignUserIdOrQuotationAndShopStage(user.getUserId(), deskRequest);
            List<Long> shopIds = resultList.stream().map(PreparationCommonPendingVO::getShopId).collect(Collectors.toList());
            List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_901.getShopSubStageStatus(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_90.getShopSubStageStatus()));
            Map<Long, List<ShopStageRemarkInfoDO>> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.groupingBy(ShopStageRemarkInfoDO::getShopId));
            for (PreparationCommonPendingVO preparationCommonPendingVO : resultList) {
                List<ShopStageRemarkInfoDO> remarkInfoList = remarkInfoMap.getOrDefault(preparationCommonPendingVO.getShopId(), new ArrayList<>());
                Map<Integer, String> remarkMapByShopSubStageStatus = remarkInfoList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopSubStageStatus, ShopStageRemarkInfoDO::getRemark));
                preparationCommonPendingVO.setBusinessRemark(remarkMapByShopSubStageStatus.getOrDefault(preparationCommonPendingVO.getSubStageStatus(), ""));
            }
            return resultList;
        }
        return null;
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> constructionPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_11,
                Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_110.getShopSubStageStatus(),
                        ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_111.getShopSubStageStatus()), Boolean.TRUE);

    }

    @Override
    public PageInfo<PreparationCommonPendingVO> fitmentPendingList(DeskRequest deskRequest, LoginUserInfo user) {

        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_12,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_122.getShopSubStageStatus()), Boolean.TRUE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> DYPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_181.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> KSPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_221.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> MTPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_191.getShopSubStageStatus(), SHOP_SUB_STAGE_STATUS_193.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> MTBuyPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_201.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> ELMEPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_211.getShopSubStageStatus(), SHOP_SUB_STAGE_STATUS_213.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> buildInformationPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        if (userRoleIds.contains(UserRoleEnum.SUPERVISION.getCode())) {
            return commonPendingVOPageInfoByOperationsConsultant(deskRequest, user.getUserId(), ShopSubStageEnum.SHOP_STAGE_15,
                    Arrays.asList(SHOP_SUB_STAGE_STATUS_150.getShopSubStageStatus(), SHOP_SUB_STAGE_STATUS_150_5.getShopSubStageStatus()), Boolean.FALSE);
        }
        //如果不是财务角色或者即是财务又是自有店财务 则不需要标识
        Boolean ownShopFlag = null;
        if (userRoleIds.contains(UserRoleEnum.FINANCE.getCode()) && userRoleIds.contains(UserRoleEnum.OWN_SHOP_OFFICE.getCode())) {
            ownShopFlag = null;
        } else if (userRoleIds.contains(UserRoleEnum.FINANCE.getCode())) {
            ownShopFlag = Boolean.FALSE;
        } else if (userRoleIds.contains(UserRoleEnum.OWN_SHOP_OFFICE.getCode())) {
            ownShopFlag = Boolean.TRUE;
        }
        List<Integer> subStageStatusList = new ArrayList<>();
        if (userRoleIds.contains(UserRoleEnum.LOGISTICS.getCode())) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.FINANCE.getCode()) || userRoleIds.contains(UserRoleEnum.OWN_SHOP_OFFICE.getCode())) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_152.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.HEAD_OF_DIVISION.getCode()) || userRoleIds.contains(UserRoleEnum.REGIONAL_MANAGER.getCode())) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_153.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.VICE_PRESIDENT_IN_CHARGE.getCode()) || userRoleIds.contains(UserRoleEnum.BRAND_HEAD.getCode())) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_154.getShopSubStageStatus());
        }
        if (userRoleIds.contains(UserRoleEnum.PRESIDENT.getCode())) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_155.getShopSubStageStatus());
        }
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        if (isAdmin) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151.getShopSubStageStatus());
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_152.getShopSubStageStatus());
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_153.getShopSubStageStatus());
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_154.getShopSubStageStatus());
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_155.getShopSubStageStatus());
        }
        return commonPendingVOPage(deskRequest, isAdmin ? null : user, ShopSubStageEnum.SHOP_STAGE_15, subStageStatusList, isAdmin ? Boolean.FALSE : Boolean.TRUE, ownShopFlag, null);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> openingAcceptance(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        //如果运营顾问 查询直接返回
        List<Integer> stageList = new ArrayList<>();
        Boolean flag = Boolean.FALSE;
        if (userRoleIds.contains(UserRoleEnum.QW_SUPERVISION.getCode()) || userRoleIds.contains(UserRoleEnum.SUPERVISION.getCode())) {
            stageList.addAll(Arrays.asList(SHOP_SUB_STAGE_STATUS_270.getShopSubStageStatus(),SHOP_SUB_STAGE_STATUS_274.getShopSubStageStatus()));
            return operationCustomQueryList(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_27, stageList);
        }
        if (userRoleIds.contains(UserRoleEnum.OPERATION_GENERAL_CONSULTANT.getCode()) ) {
            stageList.add(SHOP_SUB_STAGE_STATUS_272.getShopSubStageStatus());
            flag =  Boolean.TRUE;
        }
        if (CollectionUtils.isEmpty(stageList)){
            return new PageInfo<>();
        }
        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_27, stageList, flag);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> openingConfirmPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return operationCustomQueryList(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_30, Arrays.asList(SHOP_SUB_STAGE_STATUS_310.getShopSubStageStatus()));
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> measurePendingList(DeskRequest deskRequest, LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        List<Integer> subStageStatusList = new ArrayList<>();
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        if (userRoleIds.contains(UserRoleEnum.CONSTRUCTION_CUSTOMER.getCode()) || isAdmin) {
            subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_861.getShopSubStageStatus());
            if (isAdmin) {
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_861.getShopSubStageStatus());
                subStageStatusList.add(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_862.getShopSubStageStatus());
            }
            return commonPendingVOPageInfo(deskRequest, isAdmin ? null : user, ShopSubStageEnum.SHOP_STAGE_8_6, subStageStatusList, isAdmin ? Boolean.FALSE : Boolean.TRUE);

        }
        if (userRoleIds.contains(UserRoleEnum.MEASURE_OFFICE.getCode())) {
            PageHelper.startPage(deskRequest);
            List<PreparationCommonPendingVO> list = decorationMeasureDAO.getByMeasureUserIdAndShopStage(user.getUserId(), deskRequest);
            if (CollectionUtils.isEmpty(list)) {
                return new PageInfo<>();
            }
            List<Long> shopIds = list.stream().map(PreparationCommonPendingVO::getShopId).collect(Collectors.toList());
            List<Long> lineIds = list.stream().map(PreparationCommonPendingVO::getLineId).collect(Collectors.toList());
            List<LineInfoDO> lineInfoDOS = lineInfoDAO.getByLineIds(lineIds);
            Map<Long, LineInfoDO> lineMap = lineInfoDOS.stream().collect(Collectors.toMap(LineInfoDO::getId, line -> line));
            List<SignFranchiseDO> signType = signFranchiseDAO.getSignType(shopIds);
            Map<Long, SignFranchiseDO> signTypeMap = signType.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, dto -> dto));

            Set<Long> regionIdSet = list.stream().map(PreparationCommonPendingVO::getRegionId).collect(Collectors.toSet());
            Map<Long, String> regionNameMap = regionService.getBelongWarRegionNameMap(new ArrayList<>(regionIdSet));

            Set<String> investmentManagerIds = list.stream().map(PreparationCommonPendingVO::getInvestmentManager).collect(Collectors.toSet());
            Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(investmentManagerIds));
            List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_862.getShopSubStageStatus()));
            Map<Long, ShopStageRemarkInfoDO> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopId, Function.identity()));

            for (PreparationCommonPendingVO preparationCommonPendingVO : list) {
                LineInfoDO lineInfoDO = lineMap.get(preparationCommonPendingVO.getLineId());
                if (lineInfoDO == null) {
                    continue;
                }
                preparationCommonPendingVO.setBusinessRemark(remarkInfoMap.getOrDefault(preparationCommonPendingVO.getShopId(), new ShopStageRemarkInfoDO()).getRemark());
                preparationCommonPendingVO.setSignType(signTypeMap.getOrDefault(preparationCommonPendingVO.getShopId(), new SignFranchiseDO()).getSignType());
                preparationCommonPendingVO.setPartnerName(lineInfoDO.getUsername());
                preparationCommonPendingVO.setPartnerPhone(lineInfoDO.getMobile());
                preparationCommonPendingVO.setRegionNodeName(regionNameMap.getOrDefault(preparationCommonPendingVO.getRegionId(), ""));
                preparationCommonPendingVO.setInvestmentManager(userNameMap.getOrDefault(preparationCommonPendingVO.getInvestmentManager(), ""));
            }
            return new PageInfo<>(list);
        }
        return new PageInfo<>();
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> businessLicensePendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_3,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_30.getShopSubStageStatus()), Boolean.FALSE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> foodLicensePendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPendingVOPageInfo(deskRequest, user, ShopSubStageEnum.SHOP_STAGE_4,
                Collections.singletonList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_40.getShopSubStageStatus()), Boolean.FALSE);
    }

    @Override
    public PageInfo<PreparationCommonPendingVO> JingDongPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        return commonPlatformBuild(deskRequest, user, Arrays.asList(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_251.getShopSubStageStatus(), SHOP_SUB_STAGE_STATUS_253.getShopSubStageStatus()));

    }

    @Override
    public Integer submitBusinessRemark(BusinessRemarkRequest request, LoginUserInfo user) {
        if (!((request.getShopId() != null && request.getSubStage() != null && request.getSubStageStatus() != null)
                || (request.getLineId() != null && request.getWorkflowSubStage() != null && request.getWorkflowSubStageStatus() != null))) {
            throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
        }
        ShopStageRemarkInfoDO remarkInfoDO = new ShopStageRemarkInfoDO();
        if (request.getShopId() != null) {
            remarkInfoDO = shopStageRemarkInfoDAO.getByShopIdAndStage(request.getShopId(), request.getSubStageStatus());
            remarkInfoDO.setShopId(request.getShopId());
            remarkInfoDO.setShopSubStage(request.getSubStage());
            remarkInfoDO.setShopSubStageStatus(request.getSubStageStatus());
        } else if (request.getLineId() != null) {
            remarkInfoDO = shopStageRemarkInfoDAO.getByLineIdAndStage(request.getLineId(), request.getWorkflowSubStageStatus());
            remarkInfoDO.setLineId(request.getLineId());
            remarkInfoDO.setWorkflowSubStage(request.getWorkflowSubStage());
            remarkInfoDO.setWorkflowSubStageStatus(request.getWorkflowSubStageStatus());
        }
        remarkInfoDO.setRemark(request.getBusinessRemark());
        if (remarkInfoDO.getCreateTime() == null) {
            remarkInfoDO.setCreateTime(new Date());
        }
        if (StringUtil.isBlank(remarkInfoDO.getCreateUserId())) {
            remarkInfoDO.setCreateUserId(user.getUserId());
        }
        remarkInfoDO.setUpdateTime(new Date());
        remarkInfoDO.setUpdateUserId(user.getUserId());
        return shopStageRemarkInfoDAO.insertOrUpdate(remarkInfoDO);
    }


    @Override
    public PageInfo<PreparationCommonPendingVO> posEntryListPendingList(DeskRequest deskRequest, LoginUserInfo user) {
        //user.getJobNumber()
        PageHelper.startPage(deskRequest.getPageNum(), deskRequest.getPageSize());
        List<ShopAccountDO> entryPendingList = shopAccountDAO.getEntryPendingList(deskRequest, ShopAccountEnum.HUOMA.getSystemName());
        PageInfo result = new PageInfo<>(entryPendingList);
        List<Long> shopIds = entryPendingList.stream().map(ShopAccountDO::getShopId).collect(Collectors.toList());
        List<ShopInfoDO> shopInfoList = shopInfoDAO.getShopListByIds(shopIds);
        List<Long> lineIds = shopInfoList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());
        List<PlanLineDTO> lines = lineInfoDAO.getLines(lineIds);

        List<SignFranchiseDO> signType = signFranchiseDAO.getSignType(shopIds);
        Map<Long, SignFranchiseDO> signTypeMap = signType.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, dto -> dto));
        //将shopInfoList 转为map
        Map<Long, ShopInfoDO> shopInfoMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getId, shop -> shop));
        //将lines 转为map
        Map<Long, PlanLineDTO> lineMap = lines.stream().collect(Collectors.toMap(PlanLineDTO::getLineId, line -> line));

        List<Long> pointId = shopInfoList.stream().filter(x -> Objects.nonNull(x.getPointId())).map(ShopInfoDO::getPointId).collect(Collectors.toList());
        Set<String> investmentUserIds = shopInfoList.stream().map(ShopInfoDO::getInvestmentManager).collect(Collectors.toSet());
        List<PointInfoDO> pointListByIds = pointInfoDAO.getPointListByIds(pointId);
        Map<Long, PointInfoDO> pointMap = pointListByIds.stream().collect(Collectors.toMap(PointInfoDO::getId, Function.identity()));
        List<Long> regionIds = shopInfoList.stream().flatMap(v -> Stream.of(v.getRegionId(), v.getInvestRegionId())).distinct().collect(Collectors.toList());
        List<String> developmentManagers = shopInfoList.stream().filter(x -> StringUtil.isNotEmpty(x.getShopManagerUserId())).map(ShopInfoDO::getShopManagerUserId).distinct().collect(Collectors.toList());
        Set< String> userIds=new HashSet<>();
        userIds.addAll(investmentUserIds);
        userIds.addAll(developmentManagers);
        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(userIds));
        Map<Long, String> regionNameMap = regionService.getBelongWarRegionNameMap(regionIds);

        List<PreparationCommonPendingVO> list = new ArrayList<>();
        entryPendingList.forEach(x -> {
            PreparationCommonPendingVO preparationCommonPendingVO = new PreparationCommonPendingVO();
            ShopInfoDO shop = shopInfoMap.get(x.getShopId());
            preparationCommonPendingVO.setLineId(shop.getLineId());
            preparationCommonPendingVO.setShopId(shop.getId());
            ShopInfoDO shopInfoDO = shopInfoMap.getOrDefault(x.getShopId(), new ShopInfoDO());
            preparationCommonPendingVO.setStoreType(shopInfoDO.getStoreType());
            if (StringUtil.isNotEmpty(shopInfoDO.getDetailAddress())) {
                preparationCommonPendingVO.setShopAddress(shopInfoDO.getDetailAddress());
            } else {
                PointInfoDO pointInfoDO = pointMap.get(shopInfoDO.getPointId());
                if (pointInfoDO != null) {
                    preparationCommonPendingVO.setShopAddress(pointInfoDO.getAddress());
                }
            }
            SignFranchiseDO signFranchiseDO = signTypeMap.get(x.getShopId());
            if (signFranchiseDO != null) {
                preparationCommonPendingVO.setSignType(signFranchiseDO.getSignType());
                preparationCommonPendingVO.setPartnershipSignatorySecond(signFranchiseDO.getPartnershipSignatorySecond());
            }
            preparationCommonPendingVO.setShopCode(shopInfoDO.getShopCode());
            preparationCommonPendingVO.setJoinMode(shopInfoDO.getJoinMode());
            preparationCommonPendingVO.setInvestmentManager(userNameMap.getOrDefault(shopInfoDO.getInvestmentManager(),""));
            preparationCommonPendingVO.setStoreName(shopInfoDO.getShopName());
            PlanLineDTO planLineDTO = lineMap.getOrDefault(shop.getLineId(), new PlanLineDTO());
            preparationCommonPendingVO.setPartnerName(planLineDTO.getUsername());
            preparationCommonPendingVO.setPartnerPhone(planLineDTO.getMobile());
            preparationCommonPendingVO.setShopManagerUserName(userNameMap.getOrDefault(shopInfoDO.getShopManagerUserId(), ""));
            preparationCommonPendingVO.setRegionNodeName(regionNameMap.getOrDefault(shopInfoDO.getRegionId(), ""));
            preparationCommonPendingVO.setFranchiseBrand(shopInfoDO.getFranchiseBrand());
            preparationCommonPendingVO.setInvestRegionId(shopInfoDO.getInvestRegionId());
            preparationCommonPendingVO.setInvestRegionName(regionNameMap.get(shopInfoDO.getInvestRegionId()));
            list.add(preparationCommonPendingVO);
        });
        result.setList(list);
        return result;
    }

    @Override
    public PageInfo<OperationsConsultantAssignVO> assignPendingList(AssignPendingRequest request,LoginUserInfo user) {
        //查询管辖范围内的数据
        List<String> authRegionIds = new ArrayList<>();
        if (!sysRoleService.checkIsAdmin(user.getUserId())) {
            authRegionIds = userAuthMappingService.getAuthRegionIdByUserId(user.getUserId(),null);
        }
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<OperationsConsultantAssignDO> noAssignList = operationsConsultantAssignDAO.getNoAssign(request.getKeyword(), authRegionIds);
        if (CollectionUtils.isEmpty(noAssignList)) {
            return new PageInfo<>();
        }
        PageInfo<OperationsConsultantAssignDO> operationsConsultantAssignDOPageInfo = new PageInfo<>(noAssignList);
        PageInfo<OperationsConsultantAssignVO> page = BeanUtil.toPage(operationsConsultantAssignDOPageInfo, OperationsConsultantAssignVO.class);
        List<Long> shopIdList = noAssignList.stream().map(OperationsConsultantAssignDO::getShopId).collect(Collectors.toList());
        List<ShopInfoDO> shopList = shopInfoDAO.getShopListByIds(shopIdList);
        Map<Long, ShopInfoDO> shopInfoDOMap = shopList.stream().collect(Collectors.toMap(ShopInfoDO::getId, data -> data));
        Set<Long> regionIdList = shopList.stream().map(ShopInfoDO::getRegionId).collect(Collectors.toSet());
        regionIdList.addAll(shopList.stream().map(ShopInfoDO::getInvestRegionId).collect(Collectors.toSet()));

        Map<Long, String> regionNameMap = regionDao.getRegionNameMap(new ArrayList<>(regionIdList));

        Set<String> userIds = shopList.stream().map(ShopInfoDO::getInvestmentManager).collect(Collectors.toSet());

        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(userIds));

        List<Long> lineIds = shopList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());
        List<PlanLineDTO> lines = lineInfoDAO.getLines(lineIds);
        Map<Long, PlanLineDTO> lineMap = lines.stream().collect(Collectors.toMap(PlanLineDTO::getLineId, line -> line));

        List<SignFranchiseDO> signTypeList = signFranchiseDAO.getSignType(shopIdList);
        Map<Long, Integer> signTypoMap = signTypeList.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, SignFranchiseDO::getSignType));

        List<OperationsConsultantAssignVO> list = new ArrayList<>();

        noAssignList.forEach(x -> {
            OperationsConsultantAssignVO operationsConsultantAssignVO = new OperationsConsultantAssignVO();
            operationsConsultantAssignVO.setShopId(x.getShopId());
            operationsConsultantAssignVO.setId(x.getId());
            ShopInfoDO shopInfoDO = shopInfoDOMap.get(x.getShopId());
            operationsConsultantAssignVO.setShopId(x.getShopId());
            operationsConsultantAssignVO.setShopName(shopInfoDO.getShopName());
            operationsConsultantAssignVO.setShopCode(shopInfoDO.getShopCode());
            operationsConsultantAssignVO.setJoinMode(shopInfoDO.getJoinMode());
            operationsConsultantAssignVO.setStoreType(shopInfoDO.getStoreType());
            operationsConsultantAssignVO.setSignType(signTypoMap.get(x.getShopId()));
            operationsConsultantAssignVO.setRegionId(shopInfoDO.getRegionId());
            operationsConsultantAssignVO.setRegionName(regionNameMap.get(shopInfoDO.getRegionId()));
            operationsConsultantAssignVO.setInvestmentManager(shopInfoDO.getInvestmentManager());
            operationsConsultantAssignVO.setInvestmentManagerName(userNameMap.get(shopInfoDO.getInvestmentManager()));
            operationsConsultantAssignVO.setInvestRegionId(shopInfoDO.getInvestRegionId());
            operationsConsultantAssignVO.setInvestRegionName(regionNameMap.get(shopInfoDO.getInvestRegionId()));
            PlanLineDTO lineDTO = lineMap.getOrDefault(shopInfoDO.getLineId(), new PlanLineDTO());
            operationsConsultantAssignVO.setPartnerName(lineDTO.getUsername());
            operationsConsultantAssignVO.setPartnerPhone(lineDTO.getMobile());
            operationsConsultantAssignVO.setShopAddress(shopInfoDO.getDetailAddress());
            list.add(operationsConsultantAssignVO);
        });
        page.setList(list);
        return page;
    }

    @Override
    public PageInfo<DeliveryPendingVO> deliveryPendingList(AssignPendingRequest request,LoginUserInfo user) {
        List<Long> userRoleIds = enterpriseUserRoleMapper.getUserRoleIds(user.getUserId());
        List<Integer> subStageStatusList = new ArrayList<>();
        Boolean isAdmin = sysRoleService.checkIsAdmin(user.getUserId());
        Boolean flag = userRoleIds.contains(UserRoleEnum.DEVICE_SHIPMENT_HM.getCode()) && userRoleIds.contains(UserRoleEnum.DEVICE_SHIPMENT_CG.getCode());

        if (isAdmin||flag){
            //返回所有数据
            List<DeliveryPendingVO> pendingList = shopDeliveryPlanDAO.getPendingList(request.getKeyword(), null);
            return convert(pendingList);
        }
        Integer type = null;
        //采购
        if (userRoleIds.contains(UserRoleEnum.DEVICE_SHIPMENT_CG.getCode())){
            type = DeliveryItemTypeEnum.PURCHASE_DEVICE.getCode();
        }
        //火码
        if (userRoleIds.contains(UserRoleEnum.DEVICE_SHIPMENT_HM.getCode())){
            type = DeliveryItemTypeEnum.FIRE_CODE_DEVICE.getCode();
        }
        if(type!=null){
            List<DeliveryPendingVO> pendingList = shopDeliveryPlanDAO.getPendingList(request.getKeyword(), type);
            return convert(pendingList);
        }
        return new PageInfo<>();
    }

    private PageInfo<DeliveryPendingVO> convert(List<DeliveryPendingVO> pendingList){
        if (CollectionUtils.isEmpty(pendingList)){
            return new PageInfo<>();
        }
        PageInfo<DeliveryPendingVO> result = new PageInfo<>(pendingList);
        List<Long> lineIdList = pendingList.stream().map(DeliveryPendingVO::getLineId).collect(Collectors.toList());
        List<LineInfoDO> lineInfoDOList = lineInfoDAO.getByLineIds(lineIdList);
        Map<Long, String> lineMap = lineInfoDOList.stream().collect(Collectors.toMap(LineInfoDO::getId, LineInfoDO::getUsername));

        List<Long> regionIds = pendingList.stream().filter(x->x.getRegionId()!=null).map(DeliveryPendingVO::getRegionId).collect(Collectors.toList());
        List<Long> investRegionIds = pendingList.stream().filter(x->x.getInvestRegionId()!=null).map(DeliveryPendingVO::getRegionId).collect(Collectors.toList());
        regionIds.addAll(investRegionIds);
        Map<Long, String> regionNameMap = regionDao.getRegionNameMap(regionIds);
        List<Long> shopIdList = pendingList.stream().map(DeliveryPendingVO::getShopId).collect(Collectors.toList());
        List<ShopStageInfoDO> stageByShopSubStage = shopStageInfoDAO.getStageByShopSubStage(shopIdList, ShopSubStageEnum.SHOP_STAGE_29.getShopSubStage());
        Map<Long, Integer> stageStatusMap = stageByShopSubStage.stream().collect(Collectors.toMap(ShopStageInfoDO::getShopId, ShopStageInfoDO::getShopSubStageStatus));
        result.getList().stream().forEach(x->{
            x.setPartnerName(lineMap.get(x.getLineId()));
            x.setRegionName(regionNameMap.get(x.getRegionId()));
            x.setInvestRegionName(regionNameMap.get(x.getInvestRegionId()));
            x.setSubStageStatus(stageStatusMap.get(x.getShopId()));
        });
        return result;
    }



    /**
     * 通用查询
     * @param user
     * @param shopSubStageEnum
     * @param subStageStatusList
     * @param filterFlag
     * @return
     */
    private PageInfo<PreparationCommonPendingVO> commonPendingVOPageInfo(DeskRequest deskRequest, LoginUserInfo user, ShopSubStageEnum shopSubStageEnum, List<Integer> subStageStatusList, Boolean filterFlag) {
        return this.commonPendingVOPage(deskRequest, user, shopSubStageEnum, subStageStatusList, filterFlag, null, null);
    }

    private PageInfo<PreparationCommonPendingVO> commonPendingVOPageInfoByOperationsConsultant(DeskRequest deskRequest, String operationsConsultantUserId, ShopSubStageEnum shopSubStageEnum, List<Integer> subStageStatusList, Boolean filterFlag) {
        return this.commonPendingVOPage(deskRequest, null, shopSubStageEnum, subStageStatusList, filterFlag, null, operationsConsultantUserId);
    }


    /**
     * 运营顾问对于的代办
     * @param deskRequest
     * @param user
     * @param shopSubStageEnum
     * @param subStageStatusList
     * @return
     */
    private PageInfo<PreparationCommonPendingVO> operationCustomQueryList(DeskRequest deskRequest, LoginUserInfo user, ShopSubStageEnum shopSubStageEnum, List<Integer> subStageStatusList) {
        PageHelper.startPage(deskRequest.getPageNum(), deskRequest.getPageSize());
        List<ShopStageInfoDO> specialShopStageInfo = shopStageInfoDAO.getOperationsConsultantStageInfo(null, shopSubStageEnum.getShopSubStage(),
                subStageStatusList, user.getUserId(), deskRequest);
        PageInfo result = new PageInfo<>(specialShopStageInfo);
        List<PreparationCommonPendingVO> list = convert(specialShopStageInfo, subStageStatusList);
        result.setList(list);
        return result;
    }


    /**
     * 通用查询
     *
     * @param user
     * @param shopSubStageEnum
     * @param subStageStatusList
     * @return
     */
    private PageInfo<PreparationCommonPendingVO> commonPendingVOPage(DeskRequest deskRequest, LoginUserInfo user, ShopSubStageEnum shopSubStageEnum, List<Integer> subStageStatusList, Boolean filterFlag, Boolean ownShopFlag,
                                                                     String operationsConsultantUserId) {
        //user.getJobNumber()
        List<String> authRegionIds = new ArrayList<>();
        if (filterFlag) {
            if (!sysRoleService.checkIsAdmin(user.getUserId())) {
                authRegionIds = userAuthMappingService.getAuthRegionIdByUserId(user.getUserId(),null);
            }
        }
        PageHelper.startPage(deskRequest.getPageNum(), deskRequest.getPageSize());
        List<ShopStageInfoDO> specialShopStageInfo = shopStageInfoDAO.getSpecialShopStageInfo(null, shopSubStageEnum.getShopSubStage(),
                subStageStatusList, user == null ? null : user.getUserId(), authRegionIds, ownShopFlag, deskRequest, operationsConsultantUserId);
        PageInfo result = new PageInfo<>(specialShopStageInfo);
        List<PreparationCommonPendingVO> list = convert(specialShopStageInfo, subStageStatusList);
        result.setList(list);

        return result;
    }

    private  List<PreparationCommonPendingVO> convert(List<ShopStageInfoDO> specialShopStageInfo,List<Integer> subStageStatusList){
        List<Long> shopIds = specialShopStageInfo.stream().map(ShopStageInfoDO::getShopId).collect(Collectors.toList());
        List<Long> lineIds = specialShopStageInfo.stream().map(ShopStageInfoDO::getLineId).collect(Collectors.toList());
        List<ShopInfoDO> shopInfoList = shopInfoDAO.getShopListByIds(shopIds);
        List<PlanLineDTO> lines = lineInfoDAO.getLines(lineIds);

        List<SignFranchiseDO> signType = signFranchiseDAO.getSignType(shopIds);
        Map<Long, SignFranchiseDO> signTypeMap = signType.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, dto -> dto));
        //将shopInfoList 转为map
        Map<Long, ShopInfoDO> shopInfoMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getId, shop -> shop));
        //将lines 转为map
        Map<Long, PlanLineDTO> lineMap = lines.stream().collect(Collectors.toMap(PlanLineDTO::getLineId, line -> line));

        List<Long> pointId = shopInfoList.stream().filter(x -> Objects.nonNull(x.getPointId())).map(ShopInfoDO::getPointId).collect(Collectors.toList());
        Set<String> investmentUserIds = shopInfoList.stream().map(ShopInfoDO::getInvestmentManager).collect(Collectors.toSet());
        List<PointInfoDO> pointListByIds = pointInfoDAO.getPointListByIds(pointId);
        Map<Long, PointInfoDO> pointMap = pointListByIds.stream().collect(Collectors.toMap(PointInfoDO::getId, Function.identity()));
        List<Long> regionIds = shopInfoList.stream().flatMap(v -> Stream.of(v.getRegionId(), v.getInvestRegionId())).distinct().collect(Collectors.toList());
        List<String> developmentManagers = shopInfoList.stream().filter(x -> StringUtil.isNotEmpty(x.getShopManagerUserId())).map(ShopInfoDO::getShopManagerUserId).distinct().collect(Collectors.toList());
        Set< String> userIds=new HashSet<>();
        userIds.addAll(investmentUserIds);
        userIds.addAll(developmentManagers);
        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(userIds));
        Map<Long, String> regionNameMap = regionService.getBelongWarRegionNameMap(regionIds);
        List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, subStageStatusList);
        Map<Long, List<ShopStageRemarkInfoDO>> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.groupingBy(ShopStageRemarkInfoDO::getShopId));

        List<PreparationCommonPendingVO> list = new ArrayList<>();
        specialShopStageInfo.forEach(x -> {
            PreparationCommonPendingVO preparationCommonPendingVO = new PreparationCommonPendingVO();
            List<ShopStageRemarkInfoDO> remarkInfoMapOrDefault = remarkInfoMap.getOrDefault(x.getShopId(), new ArrayList<>());
            Map<Integer, ShopStageRemarkInfoDO> remarkInfoMapByStageStatus = remarkInfoMapOrDefault.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopSubStageStatus, Function.identity()));
            preparationCommonPendingVO.setBusinessRemark(remarkInfoMapByStageStatus.getOrDefault(x.getShopSubStageStatus(), new ShopStageRemarkInfoDO()).getRemark());
            preparationCommonPendingVO.setLineId(x.getLineId());
            preparationCommonPendingVO.setShopId(x.getShopId());
            ShopInfoDO shopInfoDO = shopInfoMap.getOrDefault(x.getShopId(), new ShopInfoDO());
            preparationCommonPendingVO.setStoreType(shopInfoDO.getStoreType());
            if (StringUtil.isNotEmpty(shopInfoDO.getDetailAddress())) {
                preparationCommonPendingVO.setShopAddress(shopInfoDO.getDetailAddress());
            } else {
                PointInfoDO pointInfoDO = pointMap.get(shopInfoDO.getPointId());
                if (pointInfoDO != null) {
                    preparationCommonPendingVO.setShopAddress(pointInfoDO.getAddress());
                }
            }
            SignFranchiseDO signFranchiseDO = signTypeMap.get(x.getShopId());
            if (signFranchiseDO != null) {
                preparationCommonPendingVO.setSignType(signFranchiseDO.getSignType());
                preparationCommonPendingVO.setPartnershipSignatorySecond(signFranchiseDO.getPartnershipSignatorySecond());
            }
            preparationCommonPendingVO.setShopCode(shopInfoDO.getShopCode());
            preparationCommonPendingVO.setJoinMode(shopInfoDO.getJoinMode());
            preparationCommonPendingVO.setInvestmentManager(userNameMap.getOrDefault(shopInfoDO.getInvestmentManager(),""));
            preparationCommonPendingVO.setStage(x.getShopStage());
            preparationCommonPendingVO.setSubStage(x.getShopSubStage());
            preparationCommonPendingVO.setSubStageStatus(x.getShopSubStageStatus());
            preparationCommonPendingVO.setStoreName(shopInfoDO.getShopName());
            PlanLineDTO planLineDTO = lineMap.getOrDefault(x.getLineId(), new PlanLineDTO());
            preparationCommonPendingVO.setPartnerName(planLineDTO.getUsername());
            preparationCommonPendingVO.setPartnerPhone(planLineDTO.getMobile());
            preparationCommonPendingVO.setShopManagerUserName(userNameMap.getOrDefault(shopInfoDO.getShopManagerUserId(), ""));
            preparationCommonPendingVO.setRegionNodeName(regionNameMap.getOrDefault(shopInfoDO.getRegionId(), ""));
            preparationCommonPendingVO.setUpdateTime(x.getUpdateTime());
            preparationCommonPendingVO.setFranchiseBrand(shopInfoDO.getFranchiseBrand());
            preparationCommonPendingVO.setInvestRegionId(shopInfoDO.getInvestRegionId());
            preparationCommonPendingVO.setInvestRegionName(regionNameMap.get(shopInfoDO.getInvestRegionId()));
            if (shopInfoDO!=null&&shopInfoDO.getPlanOpenDate()!=null){
                preparationCommonPendingVO.setPlanOpenDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,shopInfoDO.getPlanOpenDate()));
            }
            list.add(preparationCommonPendingVO);
        });
        return  list;
    }



    private void doThing(Map<Long, List<DeskStageDTO>> deskStageMap, List<ShopStageInfoDO> subStageList) {
        for (ShopStageInfoDO shopStageInfoDO : subStageList) {
            List<DeskStageDTO> deskStageDTOS = deskStageMap.get(shopStageInfoDO.getShopId());
            if (CollectionUtils.isEmpty(deskStageDTOS)) {
                DeskStageDTO dto = new DeskStageDTO();
                Date date = DateUtils.toDate(YYYY_MM_DD_HH_MM_SS, shopStageInfoDO.getActualCompleteTime());
                dto.setActualCompleteTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, date));
                dto.setShopSubStageStatus(shopStageInfoDO.getShopSubStageStatus());
                deskStageMap.put(shopStageInfoDO.getShopId(), Arrays.asList(dto));
            } else {
                DeskStageDTO dto = new DeskStageDTO();
                Date date = DateUtils.toDate(YYYY_MM_DD_HH_MM_SS, shopStageInfoDO.getActualCompleteTime());
                dto.setActualCompleteTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, date));
                dto.setShopSubStageStatus(shopStageInfoDO.getShopSubStageStatus());
                deskStageDTOS.add(dto);
                deskStageMap.put(shopStageInfoDO.getShopId(), deskStageDTOS);
            }
        }
    }

    //平台建店通用查询
    private PageInfo<PreparationCommonPendingVO> commonPlatformBuild(DeskRequest deskRequest, LoginUserInfo user, List<Integer> subStageStatusList) {
        PageHelper.startPage(deskRequest);
        List<OperationLogDO> operationLogDOList = operationLogDAO.getBySubStageStatusAndUser(user.getUserId(), subStageStatusList, deskRequest);
        if (CollectionUtils.isEmpty(operationLogDOList)) {
            return new PageInfo<>();
        }
        PageInfo result = new PageInfo<>(operationLogDOList);
        List<Long> shopIds = operationLogDOList.stream().map(OperationLogDO::getShopId).collect(Collectors.toList());
        List<ShopInfoDO> shopInfoList = shopInfoDAO.getShopListByIds(shopIds);
        List<Long> lineIds = shopInfoList.stream().map(ShopInfoDO::getLineId).collect(Collectors.toList());
        List<PlanLineDTO> lines = lineInfoDAO.getLines(lineIds);

        List<Long> pointId = shopInfoList.stream().filter(x -> Objects.nonNull(x.getPointId())).map(ShopInfoDO::getPointId).collect(Collectors.toList());
        List<String> investmentUserIds = shopInfoList.stream().map(ShopInfoDO::getInvestmentManager).collect(Collectors.toList());
        List<PointInfoDO> pointListByIds = pointInfoDAO.getPointListByIds(pointId);
        Map<Long, PointInfoDO> pointMap = pointListByIds.stream().collect(Collectors.toMap(PointInfoDO::getId, Function.identity()));
        //将shopInfoList 转为map
        Map<Long, ShopInfoDO> shopInfoMap = shopInfoList.stream().collect(Collectors.toMap(ShopInfoDO::getId, shop -> shop));
        //将lines 转为map
        Map<Long, PlanLineDTO> lineMap = lines.stream().collect(Collectors.toMap(PlanLineDTO::getLineId, line -> line));

        List<SignFranchiseDO> signType = signFranchiseDAO.getSignType(shopIds);
        Map<Long, SignFranchiseDO> signTypeMap = signType.stream().collect(Collectors.toMap(SignFranchiseDO::getShopId, dto -> dto));

        List<Long> regionIds = shopInfoList.stream().map(ShopInfoDO::getRegionId).distinct().collect(Collectors.toList());
        List<String> developmentManagers = shopInfoList.stream().filter(x -> StringUtil.isNotEmpty(x.getShopManagerUserId())).map(ShopInfoDO::getShopManagerUserId).distinct().collect(Collectors.toList());
        Set<String> userIds = new HashSet<>();
        userIds.addAll(investmentUserIds);
        userIds.addAll(developmentManagers);
        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(userIds));
        Map<Long, String> regionNameMap = regionService.getBelongWarRegionNameMap(regionIds);
        List<ShopStageRemarkInfoDO> remarkInfoDOList = shopStageRemarkInfoDAO.getByShopIdsAndStage(shopIds, subStageStatusList);
        Map<Long, ShopStageRemarkInfoDO> remarkInfoMap = remarkInfoDOList.stream().collect(Collectors.toMap(ShopStageRemarkInfoDO::getShopId, Function.identity()));

        List<PreparationCommonPendingVO> list = new ArrayList<>();
        operationLogDOList.forEach(x -> {
            PreparationCommonPendingVO preparationCommonPendingVO = new PreparationCommonPendingVO();
            preparationCommonPendingVO.setBusinessRemark(remarkInfoMap.getOrDefault(x.getShopId(), new ShopStageRemarkInfoDO()).getRemark());
            ShopInfoDO shopInfoDO = shopInfoMap.getOrDefault(x.getShopId(), new ShopInfoDO());
            preparationCommonPendingVO.setStoreType(shopInfoDO.getStoreType());
            preparationCommonPendingVO.setJoinMode(shopInfoDO.getJoinMode());
            preparationCommonPendingVO.setShopAddress(shopInfoDO.getDetailAddress());
            preparationCommonPendingVO.setInvestmentManager(userNameMap.get(shopInfoDO.getInvestmentManager()));
            preparationCommonPendingVO.setSignType(signTypeMap.getOrDefault(x.getShopId(), new SignFranchiseDO()).getSignType());
            preparationCommonPendingVO.setShopCode(shopInfoDO.getShopCode());
            preparationCommonPendingVO.setLineId(shopInfoDO.getLineId());
            preparationCommonPendingVO.setShopId(x.getShopId());
            preparationCommonPendingVO.setSubStage(x.getShopSubStage());
            preparationCommonPendingVO.setSubStageStatus(x.getShopSubStageStatus());
            preparationCommonPendingVO.setSubmitTime(DateUtils.parseDateToStr(SPECIAL_DATE_START, x.getCreateTime()));
            preparationCommonPendingVO.setUpdateTime(x.getUpdateTime());
            preparationCommonPendingVO.setStoreName(shopInfoDO.getShopName());
            PlanLineDTO planLineDTO = lineMap.getOrDefault(shopInfoDO.getLineId(), new PlanLineDTO());
            preparationCommonPendingVO.setPartnerName(planLineDTO.getUsername());
            preparationCommonPendingVO.setPartnerPhone(planLineDTO.getMobile());
            preparationCommonPendingVO.setShopManagerUserName(userNameMap.getOrDefault(shopInfoDO.getShopManagerUserId(), ""));
            preparationCommonPendingVO.setRegionNodeName(regionNameMap.getOrDefault(shopInfoDO.getRegionId(), ""));
            list.add(preparationCommonPendingVO);
        });
        result.setList(list);
        return result;
    }
}
