package com.jwipc.supplier.logic.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.jwipc.constant.DelFlag;
import com.jwipc.exception.DaoException;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.prop.SysProp;
import com.jwipc.security.LoginUtil;
import com.jwipc.supplier.constant.*;
import com.jwipc.supplier.convert.SupplierInvitaionConvert;
import com.jwipc.supplier.convert.SupplierPurchaseCategoryConvert;
import com.jwipc.supplier.dto.SupplierInvitationListDTO;
import com.jwipc.supplier.dto.SupplierInvitationSaveDTO;
import com.jwipc.supplier.dto.SupplierPurchaseCategoryBaseDTO;
import com.jwipc.supplier.entity.*;
import com.jwipc.supplier.logic.SupplierInvitationLogic;
import com.jwipc.supplier.logic.SupplierPurchaseCategoryLogic;
import com.jwipc.supplier.model.po.SupplierInvitationListPO;
import com.jwipc.supplier.model.po.SupplierTemplateFieldPO;
import com.jwipc.supplier.model.query.SupplierInvitationQuery;
import com.jwipc.supplier.service.*;
import com.jwipc.sys.client.EmailSendClient;
import com.jwipc.sys.client.SequenceClient;
import com.jwipc.sys.client.UserClient;
import com.jwipc.sys.client.UserRoleClient;
import com.jwipc.sys.client.dto.CreateUserCDTO;
import com.jwipc.sys.client.dto.EmailTmpSingleSendDTO;
import com.jwipc.sys.client.dto.UserDTO;
import com.jwipc.util.DateUtils;
import com.jwipc.util.EncryptUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


/**
 * <p> </p>
 *
 * @author BOGON
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@RequiredArgsConstructor
public class SupplierInvitationLogicImpl implements SupplierInvitationLogic {
    private final ISupplierInvitaionService supplierInvitaionService;
    private final SupplierInvitaionConvert supplierInvitaionConvert;
    private final ISupplierService supplierService;
    private final SupplierPurchaseCategoryConvert supplierPurchaseCategoryConvert;
    private final ISupplierPurchaseCategoryService supplierPurchaseCategoryService;
    private final SysProp sysProp;
    private final ISupplierContactsService supplierContactsService;
    private final ISupplierBankService supplierBankService;
    private final ISupplierQualificationService supplierQualificationService;
    private final ISupplierQuestionnaireAnswerService supplierQuestionnaireAnswerService;
    private final ISupplierExtensionService supplierExtensionService;
    private final ISupplierAgreementVersionService supplierAgreementVersionService;
    private final SequenceClient sequenceClient;
    private final UserClient userClient;
    private final UserRoleClient userRoleClient;
    private final EmailSendClient emailSendClient;
    private final ISupplierTemplateFieldRelationService supplierTemplateFieldRelationService;
    private final ISupplierFieldService supplierFieldService;
    private final SupplierPurchaseCategoryLogic supplierPurchaseCategoryLogic;
    private final ISupplierTemplateService supplierTemplateService;


    @Override
    public PageView getList(SupplierInvitationQuery query) {
        final Page<SupplierInvitationListPO> page = PageUtil.toPage(query);
        List<SupplierInvitationListPO> supplierInvitationListPOs = supplierInvitaionService.findList(page, query);
        List<SupplierInvitationListDTO> supplierInvitationListDTOS = supplierInvitaionConvert.pos2Dtos(
                supplierInvitationListPOs);
        return PageUtil.getPV(supplierInvitationListDTOS, page.getTotal());
    }

    @Override
    public SupplierInvitationSaveDTO getDetail(Long id) {
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        if (Objects.nonNull(supplierInvitaion)) {
            final Supplier supplier = supplierService.getById(supplierInvitaion.getSupplierId());
            final SupplierInvitationSaveDTO supplierInvitationSaveDTO = supplierInvitaionConvert.entity2Dto(
                    supplierInvitaion);
            supplierInvitaionConvert.fillToDto(supplier, supplierInvitationSaveDTO);
            return supplierInvitationSaveDTO;
        } else {
            return new SupplierInvitationSaveDTO();
        }
    }
    @Override
    public List<SupplierInvitationSaveDTO> getListSupplierInvitation(Long supplierId) {
        List<SupplierInvitaion> list = supplierInvitaionService.list(new LambdaQueryWrapper<SupplierInvitaion>().eq(SupplierInvitaion::getSupplierId, supplierId).eq(SupplierInvitaion::getDelFlag, DelFlag.NORMAL));
        Supplier supplier = supplierService.getById(supplierId);
        List<SupplierInvitationSaveDTO> dtoList= new ArrayList<>();
        for (SupplierInvitaion supplierInvitaion : list) {
            dtoList.add(supplierInvitaionConvert.entity2Dto(supplierInvitaion));
        }
        dtoList.forEach( f -> f.setSpecialRemark(supplier.getSpecialRemark()));
        return dtoList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdate(SupplierInvitationSaveDTO supplierInvitationSaveDTO) {
        SupplierInvitaion supplierInvitaion = supplierInvitaionConvert.dto2Entity(supplierInvitationSaveDTO);
        //需要校验简称是否存在
        final LambdaQueryWrapper<Supplier> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Supplier::getShortName, supplierInvitationSaveDTO.getShortName())
                .eq(Supplier::getShortName, supplierInvitationSaveDTO.getShortName());
        Supplier supplier;
        supplierInvitaion.setCreateId(LoginUtil.getUserId());
        if (Objects.isNull(supplierInvitaion.getId())) {
            //表示新增
            supplierInvitaion.setCreateTime(LocalDateTime.now());
            supplierInvitaion.setRecommender(LoginUtil.getAccount());
            supplierInvitaion.setInviteCode(UUID.fastUUID().toString());
            supplier = new Supplier();
            supplier.setCreateUser(LoginUtil.getUserId());
            supplier.setCreateTime(LocalDateTime.now());
            supplier.setRegisterType(RegisterType.INVITE.getType());
        } else {
            //表示修改
            supplierInvitaion.setRecommender(LoginUtil.getAccount());
            queryWrapper.ne(Supplier::getId, supplierInvitaion.getSupplierId());
            supplier = supplierService.getById(supplierInvitaion.getSupplierId());
        }
        //

        //如果是自助注册编辑是不需要修改信息的,如果是审批通过的也不允许修改
        if (Objects.nonNull(supplier.getSignUpThrough()) &&
                supplier.getSignUpThrough() == SignUpThrough.REGISTERED.getStatus()) {
            throw new DaoException("已通过数据无法修改");
        }
        if (supplier.getRegisterType() == RegisterType.INVITE.getType()) {
            supplier.setInfoState(InformationStatus.NEW.getValue());
        } else if (supplier.getRegisterType() == RegisterType.SELF.getType()) {
            supplier.setSignUpThrough(SignUpThrough.NEW.getStatus());
            supplier.setInfoState(InformationStatus.NEW.getValue());
        }
        supplier.setEmail(supplierInvitationSaveDTO.getEmail());
        supplier.setAttr(supplierInvitationSaveDTO.getAttr());
        supplier.setCustomer1Code(supplierInvitationSaveDTO.getCustomer1Code());
        supplier.setCustomer1Name(supplierInvitationSaveDTO.getCustomer1Name());
        supplier.setCustomer2Code(supplierInvitationSaveDTO.getCustomer2Code());
        supplier.setCustomer2Name(supplierInvitationSaveDTO.getCustomer2Name());
        supplier.setSpecialRemark(supplierInvitationSaveDTO.getSpecialRemark());
        supplier.setSupplierGroup(supplierInvitationSaveDTO.getSupplierGroup());
        supplier.setAssessType(supplierInvitationSaveDTO.getAssessType());
        supplier.setTemplateId(supplierInvitaion.getTemplateId());
        supplier.setShortName(supplierInvitaion.getShortName());
//        if (StrUtil.isEmpty(supplier.getSupplierName())) {
//            supplier.setSupplierName(supplierInvitaion.getShortName());
//        }
        supplier.setPurchaseGroupCode(supplierInvitaion.getPurchaseGroupCode());
        supplier.setSupplierGenre(supplierInvitaion.getSupplierType());
        supplier.setProcurementStrategy(supplierInvitationSaveDTO.getProcurementStrategy());
        final long count = supplierService.count(queryWrapper);
        if (count > 0) {
            throw new DaoException("供应商简称已存在!");
        }
        List<SupplierPurchaseCategoryBaseDTO> items1 = supplierInvitationSaveDTO.getItems();
        SupplierTemplate supplierTemp = supplierTemplateService.getById(supplierInvitaion.getTemplateId());
        final List<String> purchaseCategoryCodes = items1.stream().map(SupplierPurchaseCategoryBaseDTO::getPurchaseCategoryCode).collect(Collectors.toList());
        if(purchaseCategoryCodes.contains("Z011") && "代收供应商注册模板".equals(supplierTemp.getTemplateName())){
            //Z011-代收款供应商
            supplier.setSupplierAttribution(50);
        }else if(purchaseCategoryCodes.contains("Z012") && "手板供应商注册模板".equals(supplierTemp.getTemplateName())){
            //Z012-手板供应商
            supplier.setSupplierAttribution(60);
        }else{
            supplier.setSupplierAttribution(null);
        }
        supplierService.saveOrUpdate(supplier);
        supplierInvitaion.setSupplierId(supplier.getId());
        supplierInvitaionService.saveOrUpdate(supplierInvitaion);
        final List<SupplierPurchaseCategoryBaseDTO> items = items1;
        List<SupplierPurchaseCategory> supplierPurchaseCategories = supplierPurchaseCategoryConvert.dtos2Entities(
                items);

        for (SupplierPurchaseCategory supplierPurchaseCategory : supplierPurchaseCategories) {
            supplierPurchaseCategory.setSupplierId(supplier.getId());
            supplierPurchaseCategory.setCreateTime(LocalDateTime.now());
            supplierPurchaseCategory.setCreateId(LoginUtil.getUserId());
            supplierPurchaseCategory.setInvitationId(supplierInvitaion.getId());
        }
        if (CollUtil.isNotEmpty(supplierPurchaseCategories)) {
            supplierPurchaseCategoryService.saveOrUpdateBatch(supplierPurchaseCategories);
            //需要根据品类、税率、币种、付款条件、公司、组织、付款方式判断啊采购品类的唯一性
            final List<SupplierPurchaseCategory> dbPurchaseCategory = supplierPurchaseCategoryService.list(
                    new LambdaQueryWrapper<SupplierPurchaseCategory>().eq(SupplierPurchaseCategory::getSupplierId,
                            supplier.getId()));
            final Map<String, String> stringStringMap = dbPurchaseCategory.stream().collect(
                    Collectors.toMap(
                            category -> {
                                final String format = StrUtil.format("{}-{}-{}-{}-{}-{}-{}",
                                        category.getPurchaseCategoryCode(),
                                        category.getTaxCode(),
                                        category.getCurrencyCode(),
                                        category.getPaymentTerms(),
                                        category.getCompanyCode(),
                                        category.getPurchaseOrgCode(),
                                        category.getPaymentMethod()
                                );
                                return format;
                            },
                            SupplierPurchaseCategory::getPurchaseCategoryName,
                            (existing, replacement) -> existing));
            //校验
            Map<String, Long> codeCountMap = dbPurchaseCategory.stream()
                    .collect(Collectors.groupingBy(
                            category -> {
                                final String format = StrUtil.format("{}-{}-{}-{}-{}-{}-{}",
                                        category.getPurchaseCategoryCode(),
                                        category.getTaxCode(),
                                        category.getCurrencyCode(),
                                        category.getPaymentTerms(),
                                        category.getCompanyCode(),
                                        category.getPurchaseOrgCode(),
                                        category.getPaymentMethod()
                                );
                                return format;
                            },
                            Collectors.counting()
                    ));

            boolean hasDuplicates = codeCountMap.values().stream().anyMatch(a -> a > 1);
            if (hasDuplicates) {
                Set<String> tipMsg = Sets.newHashSet();
                codeCountMap.entrySet().stream()
                        .filter(entry -> entry.getValue() > 1)
                        .forEach(entry -> tipMsg.add(stringStringMap.get(entry.getKey())));
                throw new DaoException(String.join(",", tipMsg) + "出现重复");
            }
            supplierPurchaseCategoryLogic.updateFirstForAll(supplier.getId());
        }
    }

    @Override
    public void updateReviewMethod(Long id, String assessType, String specialRemark) {
        SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        Supplier supplier = new Supplier();
        supplier.setId(supplierInvitaion.getSupplierId());
        supplier.setAssessType(assessType);
        supplier.setSpecialRemark(specialRemark);
        supplierService.saveOrUpdate(supplier);
    }

    @Override
    public String generateUrl(Long supplierId, Long templateId) {
        String supplierLink = EncryptUtils.encrypt(supplierId.toString());
        String templateLink = EncryptUtils.encrypt(templateId.toString());
        return sysProp.getWebsiteUrl() + "/pc/supplier/register?supplierId=" + supplierLink + "&templateId=" +
                templateLink +
                "&type=0";
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove(Long id) {
        //删除供应商邀请信息
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        final Long supplierId = supplierInvitaion.getSupplierId();
        final Supplier byId = supplierService.getById(supplierId);
        if (byId.getInfoState() != InformationStatus.NEW.getValue()) {
            throw new DaoException("供应商信息已填写，不可删除!");
        }
        removeRef(id, supplierId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void forceRemove(Long id) {
        //删除供应商邀请信息
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        final Long supplierId = supplierInvitaion.getSupplierId();
        removeRef(id, supplierId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateTemplate(Long id, Long templateId) {
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        if (Objects.nonNull(supplierInvitaion)) {
            final Supplier supplier = supplierService.getById(supplierInvitaion.getSupplierId());
            if (supplier.getTemplateId() == templateId) {
                return;
            } else {
                supplierFieldService.remove(
                        new LambdaQueryWrapper<SupplierField>().eq(SupplierField::getSupplierId, supplier.getId()));
            }
            //注册状态是
//            List<Integer> state = Lists.newArrayList(InformationStatus.NEW.getValue(),
//                    InformationStatus.STEP_ONE.getValue(),
//                    InformationStatus.STEP_TWO.getValue(),
//                    InformationStatus.COMPLETED.getValue()
//            );
//            if (state.contains(supplier.getInfoState())) {
            supplier.setTemplateId(templateId);
            supplier.setUpdateTime(LocalDateTime.now());
            supplier.setUpdateUser(LoginUtil.getUserId());
            supplierService.updateById(supplier);
            supplierInvitaion.setTemplateId(templateId);
            supplierInvitaionService.updateById(supplierInvitaion);
            //需要把模板数据放到供应商字段中
            final List<SupplierTemplateFieldPO> supplierTemplateFieldPOS =
                    supplierTemplateFieldRelationService.selectByTemplate(
                            String.valueOf(templateId), DelFlag.NORMAL.getStatus());
            //需要把模板的字段信息保存一份，要不然后面模板修改了这个地方就出现问题
            List<SupplierField> supplierFields = Lists.newArrayList();
            for (SupplierTemplateFieldPO fieldPO : supplierTemplateFieldPOS) {
                SupplierField supplierField = new SupplierField();
                supplierField.setFieldCode(fieldPO.getFieldName());
                supplierField.setFieldAlias(
                        StrUtil.isNotEmpty(fieldPO.getFieldAlias()) ? fieldPO.getFieldAlias() : fieldPO.getLabelName());
                supplierField.setFieldSort(fieldPO.getFieldSort());
                supplierField.setFieldType(fieldPO.getFieldType());
                supplierField.setSqlSentence(fieldPO.getSqlSentence());
                supplierField.setValidateStr(fieldPO.getValidateStr());
                supplierField.setRequired(fieldPO.getRequired());
                supplierField.setFormControl(fieldPO.getFormControl());
                supplierField.setSupplierId(supplier.getId());
                supplierFields.add(supplierField);
            }
            if (CollUtil.isNotEmpty(supplierFields)) {
                supplierFieldService.saveBatch(supplierFields);
            }
//            } else {
//                throw new DaoException("供应商注册已完成无法修改注册模板");
//            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void agree(Long id, String remark) {
        /**
         *如果通过，需要创建供应商用户和用户角色，并且把供应商品类的状态改成潜在
         * 需要生成供应商临时编码
         */
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        final Long supplierId = supplierInvitaion.getSupplierId();
        final Supplier supplier = supplierService.getById(supplierId);
        String supplierCode=null;
        if(StringUtils.isEmpty(supplier.getSupplierCode())){
            supplierCode = sequenceClient.createSequenceNo(SequenceConst.SUPPLIER_CODE.getCode());
        }else{
            supplierCode=supplier.getSupplierCode();
        }
        supplier.setSupplierCode(supplierCode);
        supplier.setSupplierTempCode(supplierCode);
        if (supplier.getSignUpThrough() != SignUpThrough.NEW.getStatus()) {
            throw new DaoException("供应商已审批!");
        }
        supplier.setSignUpUser(LoginUtil.getUserId());
        supplier.setSignUpThrough(SignUpThrough.REGISTERED.getStatus());
        supplier.setSignUpRemark(remark);
        //查询如果有用户就不建立
        //需要创建用户，需要创建用户角色关联表
        int bySupplierId = userClient.getBySupplierId(supplierId);
        if(bySupplierId==0){
            CreateUserCDTO createUserDTO = new CreateUserCDTO();
            createUserDTO.setAccountName(supplierCode);
            createUserDTO.setUsername(supplier.getSupplierName());
            createUserDTO.setSupplierId(supplier.getId());
            createUserDTO.setEmail(supplier.getEmail());
            final Long userId = userClient.createSupplierUser(createUserDTO);
            //需要创建供应商默认角色
            userRoleClient.createSupplierDefaultRole(userId);
        }else{
            userClient.updateUserCode(supplier.getId(),supplierCode);
        }
        supplier.setInfoState(InformationStatus.REGISTRATION_COMPLETED.getValue());
        final List<SupplierPurchaseCategory> supplierPurchaseCategories = supplierPurchaseCategoryService.list(
                new LambdaQueryWrapper<SupplierPurchaseCategory>().eq(SupplierPurchaseCategory::getSupplierId,
                        supplierId));
        for (SupplierPurchaseCategory supplierPurchaseCategory : supplierPurchaseCategories) {
            supplierPurchaseCategory.setState(AuthenticationState.POTENTIAL.getState());
            //资源整合部供应商初始化状态清空状态
            if(StringUtils.isNotEmpty(supplierPurchaseCategory.getOaId())){
                supplierPurchaseCategory.setReportFlag(null);
                supplierPurchaseCategory.setOaId(null);
                supplierPurchaseCategory.setApprState(0);
            }
        }
        //注册审批完清空资源整合标识
        if(supplier.getSupplierAttribution()!=null && supplier.getSupplierAttribution()==10){
            supplier.setSupplierAttribution(null);
        }
        supplierService.updateById(supplier);
        //更新银行供应商编码
        supplierBankService.update(new LambdaUpdateWrapper<SupplierBank>()
                .set(SupplierBank::getSupplierCode, supplierCode)
                .set(SupplierBank::getSupplierName, supplier.getSupplierName())
                .eq(SupplierBank::getSupplierId, supplierId));
        final EmailTmpSingleSendDTO emailTxtSingleSendDTO = new EmailTmpSingleSendDTO();
        emailTxtSingleSendDTO.setTemplateCode("JW_POST_040");
        Map<String, Object> params = Maps.newHashMap();
        params.put("url", sysProp.getWebsiteUrl());
        params.put("pwd", sysProp.getDefaultPassword());
        params.put("supplierName", supplier.getSupplierName());
        params.put("accountCode", supplierCode);
        emailTxtSingleSendDTO.setParams(params);
        emailTxtSingleSendDTO.setReceiver(supplierInvitaion.getEmail());
        emailTxtSingleSendDTO.setSender(LoginUtil.getUserId());
        emailSendClient.async(emailTxtSingleSendDTO);
        supplierPurchaseCategoryService.updateBatchById(supplierPurchaseCategories);

    }

    @Override
    public void reject(Long id, String remark) {
        /**
         *如果驳回,需要修改供应商
         *
         */
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        final Long supplierId = supplierInvitaion.getSupplierId();
        final Supplier supplier = supplierService.getById(supplierId);
        if (supplier.getSignUpThrough() != SignUpThrough.NEW.getStatus()) {
            throw new DaoException("供应商已审批!");
        }
        supplier.setSignUpUser(LoginUtil.getUserId());
        supplier.setSignUpThrough(SignUpThrough.REJECT.getStatus());
        supplier.setSignUpRemark(remark);
        final String s = generateUrl(supplierId, supplierInvitaion.getTemplateId());
        final EmailTmpSingleSendDTO emailTxtSingleSendDTO = new EmailTmpSingleSendDTO();
        emailTxtSingleSendDTO.setTemplateCode("JW_POST_030");
        Map<String, Object> params = Maps.newHashMap();
        params.put("url", s);
        params.put("date", DateUtils.formatYYYYMMDDHms(LocalDateTime.now()));
        params.put("msg", remark);
        params.put("supplierName", supplier.getSupplierName());
        emailTxtSingleSendDTO.setParams(params);
        emailTxtSingleSendDTO.setReceiver(supplierInvitaion.getEmail());
        emailTxtSingleSendDTO.setSender(LoginUtil.getUserId());
        emailSendClient.async(emailTxtSingleSendDTO);
        supplierService.updateById(supplier);
    }

    @Override
    public void sendEmail(Long id) {
        final SupplierInvitaion supplierInvitaion = supplierInvitaionService.getById(id);
        //取邀请人的数据

        final Long supplierId = supplierInvitaion.getSupplierId();
        final Long templateId = supplierInvitaion.getTemplateId();
        final String s = generateUrl(supplierId, templateId);
        final EmailTmpSingleSendDTO emailTxtSingleSendDTO = new EmailTmpSingleSendDTO();
        emailTxtSingleSendDTO.setTemplateCode("JW_POST_001");
        Map<String, Object> params = Maps.newHashMap();
        params.put("url", s);
        final UserDTO byAccount = userClient.getByUserId(supplierInvitaion.getCreateId());
        params.put("email", byAccount.getEmail());
        params.put("mobile", byAccount.getPhone());
        params.put("recommender", byAccount.getUsername());
        params.put("supplierName", supplierInvitaion.getShortName());
        emailTxtSingleSendDTO.setParams(params);
        emailTxtSingleSendDTO.setReceiver(supplierInvitaion.getEmail());
        emailTxtSingleSendDTO.setSender(LoginUtil.getUserId());
        emailSendClient.async(emailTxtSingleSendDTO);
    }

    @Override
    public void updateState(Long id) {
        Supplier  supplier = supplierService.getById(id);
        if(supplier.getSupplierAttribution()!=null && (supplier.getSupplierAttribution().intValue()==10
                ||supplier.getSupplierAttribution().intValue()==50 ||supplier.getSupplierAttribution().intValue()==60)){
            supplier.setInfoState(InformationStatus.NEW.getValue());
            supplier.setSignUpThrough(0);
            supplierService.updateById(supplier);
        }else{
            throw new DaoException(StrUtil.format("非资源整合部供应商或代收款供应商或手板供应商不可修改状态"));
        }
    }

    private void removeRef(Long id, Long supplierId) {
        //需要删除的表
        supplierInvitaionService.removeById(id);
        supplierService.removeById(supplierId);
        supplierPurchaseCategoryService.remove(
                new LambdaQueryWrapper<SupplierPurchaseCategory>().eq(SupplierPurchaseCategory::getInvitationId, id));
        supplierContactsService.remove(
                new LambdaQueryWrapper<SupplierContacts>().eq(SupplierContacts::getSupplierId, supplierId));
        supplierBankService.remove(new LambdaQueryWrapper<SupplierBank>().eq(SupplierBank::getSupplierId, supplierId));
        supplierQualificationService.remove(
                new LambdaQueryWrapper<SupplierQualification>().eq(SupplierQualification::getSupplierId, supplierId));
        supplierQuestionnaireAnswerService.remove(
                new LambdaQueryWrapper<SupplierQuestionnaireAnswer>().eq(SupplierQuestionnaireAnswer::getSupplierId,
                        supplierId));
        supplierExtensionService.remove(
                new LambdaQueryWrapper<SupplierExtension>().eq(SupplierExtension::getSupplierId, supplierId));
        supplierAgreementVersionService.remove(
                new LambdaQueryWrapper<SupplierAgreementVersion>().eq(SupplierAgreementVersion::getSupplierId,
                        supplierId));
    }
}