package com.jeeplus.test.cw.contractRegistration.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.druid.sql.visitor.functions.If;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.core.domain.BaseEntity;
import com.jeeplus.sys.service.dto.UserDTO;
import com.jeeplus.sys.utils.StringUtils;
import com.jeeplus.sys.utils.UserUtils;
import com.jeeplus.test.cw.contractRegistration.domain.ContractFile;
import com.jeeplus.test.cw.contractRegistration.domain.ContractFilePaper;
import com.jeeplus.test.cw.contractRegistration.domain.ContractInfo;
import com.jeeplus.test.cw.contractRegistration.domain.ContractParticipant;
import com.jeeplus.test.cw.contractRegistration.mapper.ContractFileMapper;
import com.jeeplus.test.cw.contractRegistration.mapper.ContractFilePaperMapper;
import com.jeeplus.test.cw.contractRegistration.mapper.ContractInfoMapper;
import com.jeeplus.test.cw.contractRegistration.mapper.ContractParticipantMapper;
import com.jeeplus.test.cw.workClientInfo.domain.CwWorkClientBase;
import com.jeeplus.test.cw.workClientInfo.service.CwWorkClientService;
import com.jeeplus.test.cw.workClientInfo.service.dto.CwWorkClientBaseDTO;
import com.jeeplus.test.mould.service.SerialnumTplService;
import com.jeeplus.test.oss.domain.WorkAttachment;
import com.jeeplus.test.oss.mapper.OssServiceMapper;
import com.jeeplus.test.reimbursement.reimbursementType.domain.ReimbursementTypeInfo;
import com.jeeplus.test.workContract.domain.WorkContractInfo;
import com.jeeplus.test.workContract.service.dto.WorkAttachmentDto;
import com.jeeplus.test.workContract.service.dto.WorkContractInfoDto;
import org.flowable.editor.language.json.converter.util.CollectionUtils;
import org.flowable.ui.modeler.service.mapper.InfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author: 王强
 * @create: 2022-11-08 10:50
 **/
@Service
public class ContractInfoService {

    @Resource
    private ContractInfoMapper mapper;

    @Resource
    private SerialnumTplService serialnumTplService;

    @Resource
    private OssServiceMapper ossServiceMapper;

    @Resource
    private ContractFileMapper fileMapper;

    @Resource
    private ContractFilePaperMapper paperMapper;

    @Resource
    private ContractParticipantMapper participantMapper;

    @Resource
    private CwWorkClientService cwWorkClientService;

    /**
     * 根据id修改status
     */
    public void updateStatusById(ContractInfo info) {
        mapper.updateStatusById(info.getId(), info.getStatus());
    }
    /**
     * 根据id修改合同实际金额
     */
    public void updateInfo(ContractInfo info) {
        mapper.updateInfo(info.getId(), info.getActualContractAmount(),info.getContractApprovalType(),info.getFiledType());
    }

    /**
     * 根据id修改合同实际金额
     */
    public void updatePaperInfo(ContractInfo info) {
        mapper.updatePaperInfo(info.getId(), info.getActualContractAmount(),info.getContractApprovalType(), info.getFiledPaperType());
    }

    public IPage<ContractInfo> list(Page<ContractInfo> page, ContractInfo info, QueryWrapper<ContractInfo> wrapper) {
//        LambdaQueryWrapper<ContractInfo> wrapper = new LambdaQueryWrapper<>();

        //条件查询list
        //1、合同编号
        if (StringUtils.isNotEmpty(info.getContractNo())) {
            wrapper.like("a.contract_no", info.getContractNo());
        }
        //2、合同名称
        if (StringUtils.isNotEmpty(info.getContractName())) {
            wrapper.like("a.contract_name", info.getContractName());
        }
        //3、合同金额（区间）
        String[] contractAmounts = info.getContractAmounts();
        if (contractAmounts != null) {
            if (StringUtils.isNotEmpty(contractAmounts[0])) {
                wrapper.ge("a.contract_amount",contractAmounts[0]);
            }
            if (StringUtils.isNotEmpty(contractAmounts[1])) {
                wrapper.le("a.contract_amount", contractAmounts[1]);
            }
        }
        //4、签约时间（区间）
        String[] contractDates = info.getContractDates();
        if (contractDates != null) {

            wrapper.between("a.signing_date", contractDates[0], contractDates[1]);
        }
        //5、创建人
        if (StringUtils.isNotEmpty(info.getCreateBy())) {
            wrapper.like("c.`id`", info.getCreateBy());
        }
        //6、所属部门
        if (StringUtils.isNotEmpty(info.getDepartment())) {
            //先根据id查出是否是父节点，是父节点则查出所有的子节点信息
            List<String> childIds = mapper.findChildIds(info.getDepartment());
            if ( null != childIds & childIds.size()>0){
                childIds.add(info.getDepartment());
                wrapper.in("a.department",childIds);
            }else {
                wrapper.eq("a.department", info.getDepartment());
            }
        }
        //7、状态
        if (StringUtils.isNotEmpty(info.getStatus())) {
            wrapper.like("a.status", info.getStatus());
        }
        //8、归档状态
        if (StringUtils.isNotEmpty(info.getFiledType())) {
            wrapper.like("a.filed_type", info.getFiledType());
        }
        //纸质归档
        if (StringUtils.isNotEmpty(info.getFiledPaperType())) {
            wrapper.like("a.filed_paper_type", info.getFiledPaperType());
        }
        wrapper.eq("a.del_flag","0");
        IPage<ContractInfo> pageList = mapper.findPageList(page, wrapper);

        return pageList;
    }

    /**
     * 合同登记查询
     */
    public ContractInfo findByContractId(String id) {

        //根据id判断是file表的id，还是info表的id
//        ContractFile byId = mapper.getById(id);
//        ContractInfo dto = null;
//        if (byId != null){
//            dto = mapper.findByContractId(id);
//        }else {
//            dto = mapper.findById(id);
//        }
        ContractInfo dto = mapper.findById(id);
        if (dto != null){
            dto.setContractStatus("新创建");
            // 查询附件信息
            List<WorkAttachmentDto> dtos = mapper.findDtos(id);
            if (CollectionUtils.isNotEmpty(dtos)) {
                for (WorkAttachmentDto i : dtos) {
                    i.setCreateBy(UserUtils.get(i.getBy()));
                }
            }
            dto.setContractProperList(dtos);
        }

        return dto;
    }

    /**
     * 合同登记查询
     */
    public ContractInfo findById(String id) {

        ContractInfo dto = mapper.findById(id);

        if (dto != null){
            List<ContractParticipant> participant = participantMapper.findByInfoId(dto.getId());
            dto.setContractStatus("新创建");
            // 查询附件信息
            List<WorkAttachmentDto> dtos = mapper.findDtos(id);
            if (CollectionUtils.isNotEmpty(dtos)) {
                for (WorkAttachmentDto i : dtos) {
                    i.setCreateBy(UserUtils.get(i.getBy()));
                }
            }
            List<CwWorkClientBaseDTO> list = new ArrayList<>();
            if (participant.size()>0){
                participant.forEach(cw->{
                    CwWorkClientBaseDTO baseDTO = new CwWorkClientBaseDTO();
                    baseDTO.setName(cw.getCustomerName());
                    baseDTO.setNo(cw.getCustomerNo());
                    list.add(baseDTO);
                });

            }
            //根据合同id去归档表查归档附件信息
//            ContractFile file = fileMapper.getInfoByConId(dto.getId());
//            if (null != file){
//                //查归档附件信息
//                List<WorkAttachmentDto> fileDtos = mapper.findDtos(file.getId());
//                if (CollectionUtils.isNotEmpty(fileDtos)) {
//                    for (WorkAttachmentDto i : fileDtos) {
//                        i.setCreateBy(UserUtils.get(i.getBy()));
//                    }
//                    dto.setContractInfoList(fileDtos);
//                }
//            }
            //根据合同id去纸质归档表查附件信息
            ContractFilePaper filePaper = paperMapper.selectFilePaperByContractInfoId(id);
            if (null != filePaper){
                //查归档附件信息
                List<WorkAttachmentDto> fileDtos = mapper.findDtos(filePaper.getId());
                if (CollectionUtils.isNotEmpty(fileDtos)) {
                    for (WorkAttachmentDto i : fileDtos) {
                        i.setCreateBy(UserUtils.get(i.getBy()));
                    }
                    dto.setContractInfoList(fileDtos);
                }
            }

            dto.setCwWorkClientContactDTOList(list);
            dto.setContractProperList(dtos);
        } else {
            //穿来的是归档的id
            ContractFile infoByConId = fileMapper.getById(id);
            if ( null != infoByConId) {
                dto = mapper.findById(infoByConId.getContractInfoId());
                if (null != dto) {
                    List<ContractParticipant> participant = participantMapper.findByInfoId(dto.getId());
                    dto.setContractStatus("新创建");
                    // 查询附件信息
                    List<WorkAttachmentDto> dtos = mapper.findDtos(dto.getId());
                    if (CollectionUtils.isNotEmpty(dtos)) {
                        for (WorkAttachmentDto i : dtos) {
                            i.setCreateBy(UserUtils.get(i.getBy()));
                        }
                    }
                    List<CwWorkClientBaseDTO> list = new ArrayList<>();
                    if (participant.size()>0){
                        participant.forEach(cw->{
                            CwWorkClientBaseDTO baseDTO = new CwWorkClientBaseDTO();
                            baseDTO.setName(cw.getCustomerName());
                            baseDTO.setNo(cw.getCustomerNo());
                            list.add(baseDTO);
                        });

                    }
                    if (null != infoByConId){
                        //查归档附件信息
                        List<WorkAttachmentDto> fileDtos = mapper.findDtos(id);
                        if (CollectionUtils.isNotEmpty(fileDtos)) {
                            for (WorkAttachmentDto i : fileDtos) {
                                i.setCreateBy(UserUtils.get(i.getBy()));
                            }
                            dto.setContractInfoList(fileDtos);
                        }
                    }

                    dto.setCwWorkClientContactDTOList(list);
                    dto.setContractProperList(dtos);
                }
            } else {
                //传过来的是纸质归档的id
                ContractFilePaper filePaper = paperMapper.getById(id);
                if ( null != filePaper ) {
                    dto = mapper.findById(filePaper.getContractInfoId());
                    if (null != dto) {
                        //参与签约方信息
                        List<ContractParticipant> participant = participantMapper.findByInfoId(dto.getId());
                        dto.setContractStatus("新创建");
                        // 查询合同登记附件信息
                        List<WorkAttachmentDto> dtos = mapper.findDtos(dto.getId());
                        if (CollectionUtils.isNotEmpty(dtos)) {
                            for (WorkAttachmentDto i : dtos) {
                                i.setCreateBy(UserUtils.get(i.getBy()));
                            }
                        }
                        List<CwWorkClientBaseDTO> list = new ArrayList<>();
                        if (participant.size()>0){
                            participant.forEach(cw->{
                                CwWorkClientBaseDTO baseDTO = new CwWorkClientBaseDTO();
                                baseDTO.setName(cw.getCustomerName());
                                baseDTO.setNo(cw.getCustomerNo());
                                list.add(baseDTO);
                            });

                        }
                        //查归档附件信息
                        List<WorkAttachmentDto> fileDtos = mapper.findDtos(filePaper.getId());
                        if (CollectionUtils.isNotEmpty(fileDtos)) {
                            for (WorkAttachmentDto i : fileDtos) {
                                i.setCreateBy(UserUtils.get(i.getBy()));
                            }
                            dto.setContractInfoList(fileDtos);
                        }
//                        //估计合同登记id查出归档信息
//                        ContractFile contractFile = fileMapper.getInfoByConId(dto.getId());
//                        if (null != contractFile){
//                            //查归档附件信息
//                            List<WorkAttachmentDto> fileDtos = mapper.findDtos(contractFile.getId());
//                            if (CollectionUtils.isNotEmpty(fileDtos)) {
//                                for (WorkAttachmentDto i : fileDtos) {
//                                    i.setCreateBy(UserUtils.get(i.getBy()));
//                                }
//                                dto.setContractInfoList(fileDtos);
//                            }
//                        }

                        dto.setCwWorkClientContactDTOList(list);
                        dto.setContractProperList(dtos);
                    }
                }
            }
        }

        return dto;
    }

    /**
     * 合同登记查询附件信息
     */
    public ContractInfo findFileInfoById(String id) {

        ContractInfo dto = mapper.findFileInfoById(id);

        if (dto != null){
            List<ContractParticipant> participant = participantMapper.findByInfoId(dto.getId());
            dto.setContractStatus("新创建");
            // 查询附件信息
            List<WorkAttachmentDto> dtos = mapper.findDtos(id);
            if (CollectionUtils.isNotEmpty(dtos)) {
                for (WorkAttachmentDto i : dtos) {
                    i.setCreateBy(UserUtils.get(i.getBy()));
                }
            }
            List<CwWorkClientBaseDTO> list = new ArrayList<>();
            if (participant.size()>0){
                participant.forEach(cw->{
                    CwWorkClientBaseDTO baseDTO = new CwWorkClientBaseDTO();
                    baseDTO.setName(cw.getCustomerName());
                    baseDTO.setNo(cw.getCustomerNo());
                    list.add(baseDTO);
                });

            }
            //根据合同id去归档表查归档附件信息
            ContractFile file = fileMapper.getInfoByConId(dto.getId());
            if (null != file){
                //查归档附件信息
                List<WorkAttachmentDto> fileDtos = mapper.findDtos(file.getId());
                if (CollectionUtils.isNotEmpty(fileDtos)) {
                    for (WorkAttachmentDto i : fileDtos) {
                        i.setCreateBy(UserUtils.get(i.getBy()));
                    }
                    dto.setContractInfoList(fileDtos);
                }
            }

            dto.setCwWorkClientContactDTOList(list);
            dto.setContractProperList(dtos);
        }

        return dto;
    }

    public String saveInfo(ContractInfo info) throws Exception {
        info.setClientContacts(info.getCustomerId());
        if (StringUtils.isNotEmpty(info.getId())) {
            //对参与签约方进行处理  将参与签约方的客户编号 和 客户名称进行持久化
            ContractInfo contractInfo = mapper.selectById(info.getId());
            if (contractInfo != null) {
                info.setCreateBy(info.getCreateId());
                return update(info);
            }
        }
        return add(info);
    }

    /**
     * 合同登记删除
     */
    public String removeById(String id) {
        mapper.deleteById(id);
        // 附件删除
        return "删除完成!";
    }

    /**
     * 合同登记修改
     */
    @Transactional(rollbackFor = Exception.class)
    public String update(ContractInfo info) throws Exception{
        //获取当前登录人信息
        UserDTO userDTO = UserUtils.getCurrentUserDTO();
        //合同编号生成
        ContractInfo contractInfo = new ContractInfo();
        BeanUtils.copyProperties(info, contractInfo);
        contractInfo.setUpdateBy(userDTO.getId());
        contractInfo.setUpdateDate(new Date());

        if (StringUtils.isNotEmpty(contractInfo.getStatus()) &&!contractInfo.getStatus().equals("5")){
            int num = Integer.parseInt(contractInfo.getChangeNum()) + 1;
            contractInfo.setChangeNum(num + "");
        }else {
            contractInfo.setChangeNum(contractInfo.getChangeNum());
        }
        //对管理员上传归档文件进行相关操作  归档修改
        if (StringUtils.isNotEmpty(contractInfo.getFiledType()) && contractInfo.getFiledType().equals("5")){
            //根据id找到归档表id
            ContractFile contractFile = fileMapper.getInfoByConId(info.getId());
            if ( null != contractFile) {
                contractFile.setContractInfoList(info.getContractInfoList());
                if (CollectionUtils.isNotEmpty(contractFile.getContractInfoList())){
                    updateFiles(contractFile.getContractInfoList(), userDTO, contractFile.getId());
                }
            }
        }

        //纸质归档修改
        ContractFilePaper filePaper = paperMapper.selectFilePaperByContractInfoId(info.getId());
        if (null != filePaper) {
            filePaper.setFiledNo(info.getFiledNo());
            filePaper.setConfirmFiledNo(info.getConfirmFiledNo());
            paperMapper.updateById(filePaper);
        }

        mapper.updateById(contractInfo);
        ContractParticipant participant = new ContractParticipant();
        //对参与签约方进行操作
        participantMapper.deleteFromParticipant(info.getId());
        //在操作前，清空之前的信息
        if (info.getCwWorkClientContactDTOList() != null){
            if (info.getCwWorkClientContactDTOList().size()>0){
                info.getCwWorkClientContactDTOList().forEach(cw->{

                    String parId = UUID.randomUUID().toString().replace("-", "");
                    participant.setId(parId);
                    participant.setContractInfoId(info.getId());
                    participant.setCustomerName(cw.getName());
                    participant.setCustomerNo(cw.getNo());
                    participant.setCreateBy(userDTO.getId());
                    participant.setCreateDate(new Date());
                    participant.setUpdateBy(userDTO.getId());
                    participant.setUpdateDate(new Date());
                    participantMapper.insert(participant);
                });
            }
        }

        List<WorkAttachmentDto> list = info.getContractProperList();
        if (CollectionUtils.isNotEmpty(list)) {
            updateFiles(list, userDTO, info.getId());
        }

        return info.getId();
    }

    /**
     * 合同登记新增
     */
    @Transactional(rollbackFor = Exception.class)
    public String add(ContractInfo contractInfo) throws Exception{
        //获取当前登录人信息
        UserDTO userDTO = UserUtils.getCurrentUserDTO();
        //合同流水号生成
        String serialNumber = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.BIZ_CODE);
        //合同编号生成
        String serialNum = "";
        if (StringUtils.isNotEmpty(contractInfo.getContractType())){
            if (contractInfo.getContractType().equals("1")){
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER1);
            } else if (contractInfo.getContractType().equals("2")) {
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER2);
            } else if (contractInfo.getContractType().equals("3")) {
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER3);
            } else if (contractInfo.getContractType().equals("4")) {
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER4);
            } else if (contractInfo.getContractType().equals("5")) {
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER5);
            } else if (contractInfo.getContractType().equals("6")) {
                serialNum = serialnumTplService.genSerialNum(userDTO.getCompanyDTO().getId(), ContractInfo.SERIAL_NUMBER6);
            }
            contractInfo.setContractSerialNumber(serialNumber);
        }
        String id = UUID.randomUUID().toString().replace("-", "");
        ContractInfo info = new ContractInfo();
        BeanUtils.copyProperties(contractInfo, info);
        info.setId(id);
//        info.setNo(serialNum);
        info.setContractNo(serialNum);
        info.setCreateBy(userDTO.getId());
        info.setCreateDate(new Date());
        info.setUpdateBy(userDTO.getId());
        info.setUpdateDate(new Date());
        mapper.insert(info);
        //对参与签约方进行持久化
        //对参与签约方进行操作
        participantMapper.deleteFromParticipant(info.getId());
        ContractParticipant participant = new ContractParticipant();
        if (info.getCwWorkClientContactDTOList() != null){
            if (info.getCwWorkClientContactDTOList().size()>0){
                info.getCwWorkClientContactDTOList().forEach(cw->{
                    String parId = UUID.randomUUID().toString().replace("-", "");
                    participant.setId(parId);
                    participant.setContractInfoId(id);
                    participant.setCustomerName(cw.getName());
                    participant.setCustomerNo(cw.getNo());
                    participant.setCreateBy(userDTO.getId());
                    participant.setCreateDate(new Date());
                    participant.setUpdateBy(userDTO.getId());
                    participant.setUpdateDate(new Date());
                    participantMapper.insert(participant);
                });
            }
        }

        List<WorkAttachmentDto> list = contractInfo.getContractProperList();
        if (CollectionUtils.isNotEmpty(list)) {
            saveFiles(list, userDTO, id);
        }

        return id;
    }

    /**
     * 保存附件信息
     * @param list 待保存的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveFiles(List<WorkAttachmentDto> list, UserDTO userDTO, String id) {
        int j = 1;
        for (WorkAttachmentDto dto : list) {
            WorkAttachment i = new WorkAttachment();
            //包含了url、size、name
            i.setId(UUID.randomUUID().toString().replace("-", ""));
//            i.getCreateBy().setId(userDTO.getId());
            i.setCreateDate(new Date());
//            i.getUpdateBy().setId(userDTO.getId());
            i.setUpdateDate(new Date());
            i.setDelFlag(0);
            i.setUrl(dto.getUrl());
            //文件类型处理
            List<String> strings = Arrays.asList(dto.getName().split("\\."));
            if (CollectionUtils.isNotEmpty(strings)) {
                i.setType(strings.get(1));
            }
            i.setAttachmentId(id);
            i.setAttachmentName(dto.getName());
            i.setAttachmentFlag("cwWorkContract");
            i.setFileSize(dto.getSize());
            i.setSort(j);
            ossServiceMapper.insertWorkAttachment(i, userDTO);
            j++;
        }
    }

    /**
     * 修改附件信息
     * @param list 待修改的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateFiles(List<WorkAttachmentDto> list, UserDTO userDTO, String id) {
        int j = 1;
        String names = new String();
        //表中存在，但是传过来不存在，说明已删除，表中数据也要删除
        for (WorkAttachmentDto dto : list) {
            names = names + "," +dto.getUrl();
        }
        //查询保存的附件信息
        List<WorkAttachment> infoList = mapper.findList(id);
        if (CollectionUtils.isNotEmpty(infoList)) {
            for (WorkAttachment i : infoList) {
                if (!names.contains(i.getUrl())) {
                    ossServiceMapper.deleteById(i.getId());
                }
            }
        }
        //保存信息
        for (WorkAttachmentDto dto : list) {
            //判断是否存在
            Integer isExit = mapper.findIsExit(id, dto.getName());
            if (isExit == 0) {
                WorkAttachment i = new WorkAttachment();
                //包含了url、size、name
                i.setId(UUID.randomUUID().toString().replace("-", ""));
//                i.getCreateBy().setId(userDTO.getId());
                i.setCreateDate(new Date());
//                i.getUpdateBy().setId(userDTO.getId());
                i.setUpdateDate(new Date());
                i.setDelFlag(0);
                i.setUrl(dto.getUrl());
                //文件类型处理
                List<String> strings = Arrays.asList(dto.getName().split("\\."));
                if (CollectionUtils.isNotEmpty(strings)) {
                    i.setType(strings.get(1));
                }
                i.setAttachmentId(id);
                i.setAttachmentName(dto.getName());
                i.setAttachmentFlag("cwWorkContract");
                i.setFileSize(dto.getSize());
                i.setSort(j);
                ossServiceMapper.insertWorkAttachment(i, userDTO);
                j++;
            }
        }
    }

    public List<ContractInfo> getByClientId(String contractId, ContractInfo contractInfo){
        if (StringUtils.isNotBlank(contractId)) {
            CwWorkClientBase cwWorkClientBase = cwWorkClientService.getById(contractId);
            if (ObjectUtil.isNotEmpty(cwWorkClientBase)) {
                if (StringUtils.isNotBlank(cwWorkClientBase.getNo())) {
                    List<String> ids = mapper.getClientListByClientNo(cwWorkClientBase.getNo());
                    if (CollectionUtil.isNotEmpty(ids)){
                        QueryWrapper<ContractInfo> queryWrapper = new QueryWrapper<>();
                        queryWrapper.in("cw_wci.id",ids);
                        queryWrapper.eq("cw_wci.del_flag","0");
                        queryWrapper.eq("cw_wci.status","5");
                        queryWrapper.orderByDesc("cw_wci.create_date");
                        if(ObjectUtil.isNotEmpty(contractInfo)){
                            if(StringUtils.isNotBlank(contractInfo.getContractName())){
                                queryWrapper.like("cw_wci.contract_name",contractInfo.getContractName());
                            }
                            if(StringUtils.isNotBlank(contractInfo.getContractNo())){
                                queryWrapper.like("cw_wci.contract_no",contractInfo.getContractNo());
                            }
                        }
                        return mapper.getByClientId(queryWrapper);
                    }
                }
            }
            return new ArrayList<>();
        }
        return new ArrayList<>();
    }
}
