package org.jeecg.modules.projectManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.basedata.entity.*;
import org.jeecg.modules.basedata.mapper.FdCustomerMapper;
import org.jeecg.modules.basedata.mapper.FdPersonnelMapper;
import org.jeecg.modules.projectManagement.mapper.*;
import org.jeecg.modules.basedata.service.*;
import org.jeecg.modules.projectManagement.entity.*;
import org.jeecg.modules.projectManagement.service.*;
import org.jeecg.modules.system.entity.SysAnnouncement;
import org.jeecg.modules.system.entity.SysAnnouncementSend;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.mapper.SysUserMapper;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.jeecg.modules.system.service.ISysSerialPatternService;
import org.jeecg.modules.system.service.impl.SysAnnouncementServiceImpl;
import org.jeecg.modules.system.vo.CallResult;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @Description: 项目报价表
 * @author： jeecg-boot
 * @date： 2019-05-20
 * @version： V1.0
 */
@Service
@Transactional
public class FdProjectQuotationServiceImpl extends ServiceImpl<FdProjectQuotationMapper, FdProjectQuotation> implements IFdProjectQuotationService {

    @Resource
    FdProjectQuotationMapper fdProjectQuotationMapper;
    @Resource
    IFdProjectQuotationService fdProjectQuotationService;
    @Resource
    IFdProjectQuotationCommentsService fdProjectQuotationCommentsService;
    @Resource
    IFdProjectQuotationTemplateService fdProjectQuotationTemplateService;
    @Resource
    IFdProjectQuotationCompoundService fdProjectQuotationCompoundService;
    @Resource
    IFdProjectQuotationDetailService fdProjectQuotationDetailService;
    @Resource
    IFdProjectQuotationContactsService fdProjectQuotationContactsService;
    @Resource
    IfdProjectQuotationFeeService ifdProjectQuotationFeeService;
    @Resource
    IFdProjectQuotationTemplateItemService fdProjectQuotationTemplateItemService;
    @Resource
    IFdContractDetailService fdContractDetailService;
    @Resource
    IFdContractCompoundService fdContractCompoundService;
    @Resource
    IFdContractContactsService fdContractContactsService;
    @Resource
    IFdContractService fdContractService;
    @Resource
    IFdContractProportionService fdContractProportionService;
    @Resource
    IFdCustomerService fdCustomerService;
    @Resource
    FdCustomerMapper fdCustomerMapper;
    @Resource
    IFdPersonnelService fdPersonnelService;
    @Resource
    IFdContractClassService fdContractClassService;
    @Resource
    IFdMatrixTypeService fdMatrixTypeService;
    @Resource
    FdPersonnelMapper fdPersonnelMapper;
    @Resource
    SysDepartMapper sysDepartMapper;
    @Resource
    FdProjectQuotationTemplateItemMapper fdProjectQuotationTemplateItemMapper;
    @Resource
    FdProjectQuotationTemplateMapper fdProjectQuotationTemplateMapper;
    @Resource
    private ISysSerialPatternService sysSerialPatternService;

    @Resource
    IFdQuotationTemplateItemService fdQuotationTemplateItemService;

    @Resource
    IFdProjectQuotationTemplateAddService iFdProjectQuotationTemplateAddService;

    @Resource
    FdProjectQuotationDetailMapper fdProjectQuotationDetailMapper;

    @Resource
    FdProjectQuotationCommentsMapper fdProjectQuotationCommentsMapper;

    @Resource
    FdProjectQuotationCompoundMapper fdProjectQuotationCompoundMapper;
    @Resource
    FdProjectQuotationContactsMapper fdProjectQuotationContactsMapper;
    @Resource
    fdProjectQuotationFeeMapper fdProjectQuotationFeeMapper;
    @Resource
    FdProjectQuotationUploadMapper fdProjectQuotationUploadMapper;

    @Resource
    FdProjectQuotationTemplateAddMapper fdProjectQuotationTemplateAddMapper;
    @Resource
    IFdCustomerContactsService iFdCustomerContactsService;

    @Resource
    ISysAnnouncementService iSysAnnouncementService;

    @Resource
    SysUserMapper sysUserMapper;

    @Resource
    SysAnnouncementServiceImpl sysAnnouncementService;

    /***
     * @Title:
     * @Description:TODO 判断是否是数字
     * @param src 判断字符
     * @return boolean 是返回true 则返回false
     * @exception
     * @author 陈创
     * @date 2020/1/8 13:56
     * @updatehistory:
     *   2020/1/8 13:56 新增
     */
    public boolean isInteger(String src){
        // Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        // return pattern.matcher(src).matches();
        String reg = "^[0-9]+(.[0-9]+)?$";
        return src.matches(reg);
    }

    /***
     * @Title:
     * @Description:TODO 保留两位小数
     * @param d
     * @return java.lang.Double
     * @exception
     * @author 陈创
     * @date 2020/1/8 15:19
     * @updatehistory:
     *   2020/1/8 15:19 新增
     */
    public static String twoDouble(Double d){
        // BigDecimal bd = new BigDecimal(d);
        // Double tem = bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        DecimalFormat df = new DecimalFormat("0.00");

        return df.format(d);
    }

    public static Double format(double data,int scope){
        //10的位数次方 如保留2位则 tempDouble=100
                double tempDouble=Math.pow(10, scope);
        //原始数据先乘tempDouble再转成整型，作用是去小数点
                data=data*tempDouble;
                int tempInt=(int) data;
        //返回去小数之后再除tempDouble的结果
                return tempInt/tempDouble;
    }

    @Override
    public IPage<FdProjectQuotation> findByPage(Page<FdProjectQuotation> page, QueryWrapper<FdProjectQuotation> queryWrapper) {
        return fdProjectQuotationMapper.findByPage(page, queryWrapper);
    }

    /**
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotation>
     * @Author tanj
     * @Description //TODO  报价总数及员工占比
     * @Date 15:26 2019/7/25
     * @Param []
     **/
    @Override
    public List<FdProjectQuotation> totalProportion(Date quotationDate, Date endDate,FdProjectQuotation fdProjectQuotationD) {
        //获取制单人用户登录名
        if(StringUtils.isNotBlank(fdProjectQuotationD.getCreateBy())){
            SysUser sysUser=sysUserMapper.getUserByPerId(fdProjectQuotationD.getCreateBy());
            fdProjectQuotationD.setCreateBy(sysUser.getUsername());
        }

        System.out.println(endDate + "结束时间");
        List<FdProjectQuotation> quotationList = fdProjectQuotationMapper.totalProportion(quotationDate, endDate,fdProjectQuotationD);
        double sum = 0.00;
        //  计算出总报表数
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            sum += Double.parseDouble(fdProjectQuotation.getTranslate());
        }
        double percentage = 0.00;
        //  设置占比保留两位小数
        DecimalFormat df = new DecimalFormat("0.00");
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            percentage = Double.parseDouble(fdProjectQuotation.getTranslate()) / sum * 100;
            fdProjectQuotation.setProportion(df.format(percentage));
        }
        return quotationList;
    }

    /**
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotation>
     * @Author tanj
     * @Description //TODO 员工签约及报价占比
     * @Date 20:57 2019/7/25
     * @Param [queryWrapper]
     **/
    @Override
    public List<FdProjectQuotation> signed(Date quotationDate, Date endDate,FdProjectQuotation fdProjectQuotationD) {
        //获取制单人用户登录名
        if(StringUtils.isNotBlank(fdProjectQuotationD.getCreateBy())){
            SysUser sysUser=sysUserMapper.getUserByPerId(fdProjectQuotationD.getCreateBy());
            fdProjectQuotationD.setCreateBy(sysUser.getUsername());
        }
        List<FdProjectQuotation> quotationList = fdProjectQuotationMapper.signed(quotationDate, endDate,fdProjectQuotationD);
        double sum = 0.00;
        //  计算出总报表数
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            sum += Double.parseDouble(fdProjectQuotation.getTranslate());
        }
        double percentage = 0.00;
        //  设置占比保留两位小数
        DecimalFormat df = new DecimalFormat("0.00");
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            percentage = Double.parseDouble(fdProjectQuotation.getTranslate()) / sum * 100;
            fdProjectQuotation.setProportion(df.format(percentage));
        }
        return quotationList;
    }

    /**
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotation>
     * @Author tanj
     * @Description //TODO 按月合计报价数、签约数及占比
     * @Date 19:49 2019/7/25
     * @Param [smallMonth, largeMonth]
     **/
    @Override
    public List<FdProjectQuotation> monthlyGrouping(String smallMonth, String largeMonth,FdProjectQuotation fdProjectQuotationD) {
        //获取制单人用户登录名
        if(StringUtils.isNotBlank(fdProjectQuotationD.getCreateBy())){
            SysUser sysUser=sysUserMapper.getUserByPerId(fdProjectQuotationD.getCreateBy());
            fdProjectQuotationD.setCreateBy(sysUser.getUsername());
        }
        List<FdProjectQuotation> quotationList = fdProjectQuotationMapper.monthlyGrouping(smallMonth, largeMonth,fdProjectQuotationD);
        double sum = 0.00;
        //  计算出总报表数
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            sum += Double.parseDouble(fdProjectQuotation.getTranslate());
        }
        double percentage = 0.00;
        //  设置占比保留两位小数
        DecimalFormat df = new DecimalFormat("0.00");
        for (FdProjectQuotation fdProjectQuotation : quotationList) {
            percentage = Double.parseDouble(fdProjectQuotation.getTranslate()) / sum * 100;
            fdProjectQuotation.setProportion(df.format(percentage));
        }
        return quotationList;
    }

    /***
     * @Title:保存
     * @Description:TODO 保存，客户档案，报价明细，对照明细，化合物，联系人，模板，模板数据
     * @param fdProjectQuotation
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/6/5 11:48
     * @updatehistory:
     *   2019/6/5 11:48 新增/修改
     */
    public void saveProjectQuotation(FdProjectQuotation fdProjectQuotation) {
        //生成客户档案
        if (fdProjectQuotation.getCustomerName() != null && fdProjectQuotation.getCustomerName() != "") {
            if (fdProjectQuotation.getPkCustomerId().equals("") || fdProjectQuotation.getPkCustomerId() == null) {
                customer(fdProjectQuotation);
            }
        }
        //获取化合物名称
        if (fdProjectQuotation.getQuotationCompoundList().size() > 0) {
            int i = 0;
            String compoundName = "";
            for (FdProjectQuotationCompound fdProjectQuotationCompound : fdProjectQuotation.getQuotationCompoundList()) {
                if (i == 0) {
                    compoundName = fdProjectQuotationCompound.getCompound();
                } else {
                    compoundName = compoundName + "、" + fdProjectQuotationCompound.getCompound();
                }
                i++;
            }
            fdProjectQuotation.setCompoundName(compoundName);
        }

        //判断币别 获取币别类型英文名称
        //币别类型id
        String currencyType = fdProjectQuotation.getCurrencyType();
        if (currencyType != null) {
            //美元
            if (currencyType.equals("0")) {
                fdProjectQuotation.setCurrencyTypeEgName("Dollar");
                fdProjectQuotation.setCurrencyTypeChName("美元");
            }
            //人名币
            if (currencyType.equals("1")) {
                fdProjectQuotation.setCurrencyTypeEgName("RMB");
                fdProjectQuotation.setCurrencyTypeChName("人民币");
            }
            //欧元
            if (currencyType.equals("2")) {
                fdProjectQuotation.setCurrencyTypeEgName("Euro");
                fdProjectQuotation.setCurrencyTypeChName("欧元");
            }
        }

        //设置审核人员的状态
        toExamineStatus(fdProjectQuotation);
        //合同费用单总金额
        /** 保存报价单*/
        if ( fdProjectQuotation.getId() == null || fdProjectQuotation.getId().equals("")) {
            //获取编码
            // if (fdProjectQuotation.getId() == null || fdProjectQuotation.getId().equals("")) {
                //获取Q300001 SHFL YY
                CallResult<String> resultSerial = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_one", "code", true);
                //获取 客户缩写 001
                CallResult<String> resultSerial2 = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_two", "code", true);
                if (!resultSerial.isSucceed() || !resultSerial2.isSucceed()) {
                    // result.error500("获取编码失败");
                    // return result;
                    throw new RuntimeException("获取编码失败");
                }
                fdProjectQuotation.setCode(resultSerial.getContent() + resultSerial2.getContent());
//                fdProjectQuotation.setCode(resultSerial.getContent() + resultSerial2.getContent().substring(2));
            // }
            //新增操作
            projectSave(fdProjectQuotation);
        } else {
            //修改操作
            projectUpdate(fdProjectQuotation);
        }
        //审核描述添加报表id
        // for (FdProjectQuotationComments fdProjectQuotationComments : fdProjectQuotation.getQuotationCommentsList()) {
        //     fdProjectQuotationComments.setQuotationId(fdProjectQuotation.getId());
        // }
        //对照明细对象添加报表id
        if (fdProjectQuotation.getQuotationDetailList().size() > 0) {
            for (FdProjectQuotationDetail fdProjectQuotationDetail : fdProjectQuotation.getQuotationDetailList()) {
                fdProjectQuotationDetail.setId(null);
                fdProjectQuotationDetail.setQuotationId(fdProjectQuotation.getId());
            }
            //批量新增对照明细
            fdProjectQuotationDetailService.saveBatch(fdProjectQuotation.getQuotationDetailList());
        }

        //化合物对象添加报表id
        if (fdProjectQuotation.getQuotationCompoundList().size() > 0) {
            int i = 1;
            for (FdProjectQuotationCompound fdProjectQuotationCompound : fdProjectQuotation.getQuotationCompoundList()) {
                fdProjectQuotationCompound.setId(null);
                fdProjectQuotationCompound.setSort(i + "");
                fdProjectQuotationCompound.setQuotationId(fdProjectQuotation.getId());
                i++;
            }
            //批量新增化合物
            fdProjectQuotationCompoundService.saveBatch(fdProjectQuotation.getQuotationCompoundList());
        }

        //联系人对象添加报表id
        if (fdProjectQuotation.getQuotationContactsList().size() > 0) {
            for (FdProjectQuotationContacts fdProjectQuotationContacts : fdProjectQuotation.getQuotationContactsList()) {
                fdProjectQuotationContacts.setId("");
                fdProjectQuotationContacts.setQuotationId(fdProjectQuotation.getId());
            }
            //联系人批量邢增
            fdProjectQuotationContactsService.saveBatch(fdProjectQuotation.getQuotationContactsList());
        }

        //费用单对象添加报表id
        if (fdProjectQuotation.getFdProjectQuotationFeeList().size() > 0) {
            for (fdProjectQuotationFee projectQuotationFee : fdProjectQuotation.getFdProjectQuotationFeeList()) {
                projectQuotationFee.setId("");
                projectQuotationFee.setProjectQuotationId(fdProjectQuotation.getId());
                projectQuotationFee.setFeeCategory1SubtotalC(projectQuotationFee.getFeeCategory1Subtotal());
                projectQuotationFee.setFeeCategory2SubtotalC(projectQuotationFee.getFeeCategory2Subtotal());
                //如果只有一列的情况 第二列的费用清空
                if(projectQuotationFee.getFeeColspan()==1){
                    projectQuotationFee.setFeeCategory2Subtotal(null);
                    projectQuotationFee.setFeeCategory2SubtotalC(null);
                }
            }
            //联系人批量邢增
            ifdProjectQuotationFeeService.saveBatch(fdProjectQuotation.getFdProjectQuotationFeeList());
        }

        //新增时添加的模板
        if (fdProjectQuotation.getQuotationTemplateListAdd().size() > 0) {
            int sort = 1;
            for (FdProjectQuotationTemplateAdd fdProjectQuotationTemplateAdd : fdProjectQuotation.getQuotationTemplateListAdd()) {
                fdProjectQuotationTemplateAdd.setId("");
                fdProjectQuotationTemplateAdd.setQuotationId(fdProjectQuotation.getId());
                fdProjectQuotationTemplateAdd.setSort(sort);
                sort++;
            }
            //批量保存
            iFdProjectQuotationTemplateAddService.saveBatch(fdProjectQuotation.getQuotationTemplateListAdd());
        }

        //项目报价单对照明细添加报表id
        // if(fdProjectQuotation.getQuotationTemplateItemList().size()>0) {
        //     for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotation.getQuotationTemplateItemList()) {
        //         fdProjectQuotationTemplateItem.setQuotationId(fdProjectQuotation.getId());
        //     }
        //     //项目报价单对照明细批量新增
        //     fdProjectQuotationTemplateItemService.saveBatch(fdProjectQuotation.getQuotationTemplateItemList());
        // }
        // /**项目报价单模板集合*/
        // List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList = new ArrayList<>();
        // String quotationTemplateId = "";//用于判断相等
        // //从对照明细取模板id
        // for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotation.getQuotationTemplateItemList()) {
        //     String quotationTemplateId2 = fdProjectQuotationTemplateItem.getProjectQuotationTemplateId();
        //     if (!quotationTemplateId.equals(quotationTemplateId2)) {//存对照对象
        //         //项目报价单对照对象
        //         FdProjectQuotationTemplate temp = new FdProjectQuotationTemplate();
        //         temp.setQuotationTemplateId(quotationTemplateId2);//模板id
        //         temp.setQuotationId(fdProjectQuotation.getId());
        //         fdProjectQuotationTemplateList.add(temp);
        //         quotationTemplateId = quotationTemplateId2;
        //     }
        // }
        // if(fdProjectQuotation.getQuotationTemplateList().size()>0) {
        //     //项目报价单对照明细添加报表id
        //     for (FdProjectQuotationTemplate fdProjectQuotationTemplateList : fdProjectQuotation.getQuotationTemplateList()) {
        //         fdProjectQuotationTemplateList.setQuotationId(fdProjectQuotation.getId());
        //     }
        //     //项目对照
        //     fdProjectQuotationTemplateService.saveBatch(fdProjectQuotation.getQuotationTemplateList());
        // }

        //批量新增审核描述
        // fdProjectQuotationCommentsService.saveBatch(fdProjectQuotation.getQuotationCommentsList());
        if (fdProjectQuotation.getQuotationTemplateList().size() > 0) {
            //添加模板与模板项
            templateOrItemSave(fdProjectQuotation);
        }
    }

    //添加模板与模板项
    public void templateOrItemSave(FdProjectQuotation fdProjectQuotation) {
        //添加报价id
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotation.getQuotationTemplateList()) {
            clearTempFee2(fdProjectQuotationTemplate);//如果改模板只有一列费用则清空第二列的费用
            fdProjectQuotationTemplate.setId(null);
            fdProjectQuotationTemplate.setQuotationId(fdProjectQuotation.getId());
            fdProjectQuotationTemplate.setOriginalsubtotal1C(fdProjectQuotationTemplate.getOriginalsubtotal1());
            fdProjectQuotationTemplate.setOriginalsubtotal2C(fdProjectQuotationTemplate.getOriginalsubtotal2());
            fdProjectQuotationTemplate.setSubtotalFeeCategory1C(fdProjectQuotationTemplate.getSubtotalFeeCategory1());
            fdProjectQuotationTemplate.setSubtotalFeeCategory2C(fdProjectQuotationTemplate.getSubtotalFeeCategory2());
            fdProjectQuotationTemplate.setTaxationFeeCategory1C(fdProjectQuotationTemplate.getTaxationFeeCategory1());
            fdProjectQuotationTemplate.setTaxationFeeCategory2C(fdProjectQuotationTemplate.getTaxationFeeCategory2());
            fdProjectQuotationTemplate.setTotleFeeCategory1C(fdProjectQuotationTemplate.getTotleFeeCategory1());
            fdProjectQuotationTemplate.setTotleFeeCategory2C(fdProjectQuotationTemplate.getTotleFeeCategory2());
            fdProjectQuotationTemplate.setFinalPrice1C(fdProjectQuotationTemplate.getFinalPrice1());
            fdProjectQuotationTemplate.setFinalPrice2C(fdProjectQuotationTemplate.getFinalPrice2());
            fdProjectQuotationTemplateService.save(fdProjectQuotationTemplate);
            //获取保存后的模板id
            String templId = fdProjectQuotationTemplate.getId();
            //给对应模板项赋值模板id
            for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotationTemplate.getTemplateItemList()) {
                //存取模板项id
                fdProjectQuotationTemplateItem.setPid(fdProjectQuotationTemplateItem.getProjectQuotationTemplateItemId());
                fdProjectQuotationTemplateItem.setId("");
                fdProjectQuotationTemplateItem.setCreateTime(null);
                fdProjectQuotationTemplateItem.setQuotationId(fdProjectQuotation.getId());
                fdProjectQuotationTemplateItem.setProjectQuotationTemplateId(templId);
                //清空费用的空格以及保留两位小数
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getFeeCategory1())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getFeeCategory1());
                    fdProjectQuotationTemplateItem.setFeeCategory1(feeCategory);

                }
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getFeeCategory2())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getFeeCategory2());
                    fdProjectQuotationTemplateItem.setFeeCategory2(feeCategory);
                }
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getOriginalFeeCategory1())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getOriginalFeeCategory1());
                    fdProjectQuotationTemplateItem.setOriginalFeeCategory1(feeCategory);
                }
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getOriginalFeeCategory2())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getOriginalFeeCategory2());
                    fdProjectQuotationTemplateItem.setOriginalFeeCategory2(feeCategory);
                }
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getFeeCategory1Contract())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getFeeCategory1Contract());
                    fdProjectQuotationTemplateItem.setFeeCategory1Contract(feeCategory);
                }
                if(StringUtils.isNotBlank(fdProjectQuotationTemplateItem.getFeeCategory2Contract())){
                    //调用fee()方法
                    String feeCategory=fee(fdProjectQuotationTemplateItem.getFeeCategory2Contract());
                    fdProjectQuotationTemplateItem.setFeeCategory2Contract(feeCategory);
                }
            }
            //保存模板项
            fdProjectQuotationTemplateItemService.saveBatch(fdProjectQuotationTemplate.getTemplateItemList());
            //修改父极id
            getIdUpdatePid(fdProjectQuotationTemplate.getTemplateItemList());
            //修改数据库模板项
            fdProjectQuotationTemplateItemMapper.parentIdBatch(fdProjectQuotationTemplate.getTemplateItemList());
        }
    }

    //如果改模板只有一列费用则清空第二列的费用
    public void clearTempFee2(FdProjectQuotationTemplate fdProjectQuotationTemplate){
        if(fdProjectQuotationTemplate!=null&&fdProjectQuotationTemplate.getCostColumnNumber()!=null&&fdProjectQuotationTemplate.getCostColumnNumber()==1){
            //主表第二类费用清空
            fdProjectQuotationTemplate.setOriginalsubtotal2("0.00");
            fdProjectQuotationTemplate.setSubtotalFeeCategory2("0.00");
            fdProjectQuotationTemplate.setTaxationFeeCategory2("0.00");
            fdProjectQuotationTemplate.setTotleFeeCategory2("0.00");
            fdProjectQuotationTemplate.setFinalPrice2("0.00");
            fdProjectQuotationTemplate.setOriginalsubtotal2C("0.00");
            fdProjectQuotationTemplate.setSubtotalFeeCategory2C("0.00");
            fdProjectQuotationTemplate.setTaxationFeeCategory2C("0.00");
            fdProjectQuotationTemplate.setTotleFeeCategory2C("0.00");
            fdProjectQuotationTemplate.setFinalPrice2C("0.00");
            //子表第二列费用清空
            if(fdProjectQuotationTemplate.getTemplateItemList()!=null){
                for(FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem:fdProjectQuotationTemplate.getTemplateItemList()){
                    fdProjectQuotationTemplateItem.setFeeCategory2("0.00");
                    fdProjectQuotationTemplateItem.setOriginalFeeCategory2("0.00");
                    fdProjectQuotationTemplateItem.setFeeCategory2Contract("0.00");
                }
            }
        }
    }


    //修改父极id
    public void getIdUpdatePid(List<FdProjectQuotationTemplateItem> list) {
        for (FdProjectQuotationTemplateItem fdQuotationTemplateIte : list) {
            for (FdProjectQuotationTemplateItem fdQuotationTemplateItem2 : list) {
                if (fdQuotationTemplateIte.getPid().equals(fdQuotationTemplateItem2.getParentId())) {
                    fdQuotationTemplateItem2.setParentId(fdQuotationTemplateIte.getId());
                }
            }

        }
    }

    //新增
    public void projectSave(FdProjectQuotation fdProjectQuotation) {
        //新增报表
        fdProjectQuotation.setDelFlag("0");
        fdProjectQuotation.setRelationCode(fdProjectQuotation.getCode());//关联报价号默认本身号
        if (fdProjectQuotation.getStatus() == null || fdProjectQuotation.getStatus() == "") {
            fdProjectQuotation.setStatus("0");
        }
        //修改最终申办方
        fdProjectQuotation.setSponsorName(fdProjectQuotation.getCustomerName());
        fdProjectQuotationService.save(fdProjectQuotation);
    }

    //修改
    public void projectUpdate(FdProjectQuotation fdProjectQuotation) {
        // //根据申办方名称查询是否在客户档案存在
        // FdProjectQuotation projectQuotationS = fdProjectQuotationMapper.selectById(fdProjectQuotation.getId());
        // //不存在则认为修改申办方
        // if (!projectQuotationS.getCustomerName().equals(fdProjectQuotation.getCustomerName())) {
        //     //根据客户档案id删除客户信息
        //     fdCustomerService.cusAndContactsDelete(fdProjectQuotation.getPkCustomerId());
        //     //生成客户档案
        //     customer(fdProjectQuotation);
        // }

        //报价单id
        String quotationId = fdProjectQuotation.getId();
        //批量删除对照明细
        LambdaQueryWrapper<FdProjectQuotationDetail> queryDetail = new LambdaQueryWrapper<>();
        queryDetail.eq(FdProjectQuotationDetail::getQuotationId, quotationId);
        queryDetail.eq(FdProjectQuotationDetail::getDelFlag, "0");
        // fdProjectQuotationDetailService.remove(queryDetail);
        //需修改值
        FdProjectQuotationDetail fdProjectQuotationDetail = new FdProjectQuotationDetail();
        fdProjectQuotationDetail.setDelFlag("1");
        fdProjectQuotationDetailService.update(fdProjectQuotationDetail, queryDetail);

        //批量新增化合物
        LambdaQueryWrapper<FdProjectQuotationCompound> queryCompound = new LambdaQueryWrapper<>();
        queryCompound.eq(FdProjectQuotationCompound::getQuotationId, quotationId);
        queryCompound.eq(FdProjectQuotationCompound::getDelFlag, "0");
        // fdProjectQuotationCompoundService.remove(queryCompound);
        //需修改化合物的值
        FdProjectQuotationCompound fdProjectQuotationCompound = new FdProjectQuotationCompound();
        fdProjectQuotationCompound.setDelFlag("1");
        fdProjectQuotationCompoundService.update(fdProjectQuotationCompound, queryCompound);

        //联系人批量邢增
        LambdaQueryWrapper<FdProjectQuotationContacts> queryContacts = new LambdaQueryWrapper<>();
        queryContacts.eq(FdProjectQuotationContacts::getQuotationId, quotationId);
        queryContacts.eq(FdProjectQuotationContacts::getDelFlag, "0");
        // fdProjectQuotationContactsService.remove(queryContacts);
        //需修改的联系人的值
        FdProjectQuotationContacts fdProjectQuotationContacts = new FdProjectQuotationContacts();
        fdProjectQuotationContacts.setDelFlag("1");
        fdProjectQuotationContactsService.update(fdProjectQuotationContacts, queryContacts);

        //项目报价单对照明细批量新增
        LambdaQueryWrapper<FdProjectQuotationTemplateItem> queryTemplateItem = new LambdaQueryWrapper<>();
        queryTemplateItem.eq(FdProjectQuotationTemplateItem::getQuotationId, quotationId);
        queryTemplateItem.eq(FdProjectQuotationTemplateItem::getDelFlag, "0");
        // fdProjectQuotationTemplateItemService.remove(queryTemplateItem);
        //需修改对照明细的值
        FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem = new FdProjectQuotationTemplateItem();
        fdProjectQuotationTemplateItem.setDelFlag("1");
        fdProjectQuotationTemplateItemService.update(fdProjectQuotationTemplateItem, queryTemplateItem);


        //项目对照
        LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemolate = new LambdaQueryWrapper<>();
        queryTemolate.eq(FdProjectQuotationTemplate::getQuotationId, quotationId);
        fdProjectQuotationTemplateService.remove(queryTemolate);
        //批量删除费用单明细
        LambdaQueryWrapper<fdProjectQuotationFee> quotationFeeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        quotationFeeLambdaQueryWrapper.eq(fdProjectQuotationFee::getProjectQuotationId, quotationId);
        quotationFeeLambdaQueryWrapper.eq(fdProjectQuotationFee::getDelFlag, "0");
        // ifdProjectQuotationFeeService.remove(quotationFeeLambdaQueryWrapper);
        //需修改费用单的值
        fdProjectQuotationFee fdProjectQuotationFee = new fdProjectQuotationFee();
        fdProjectQuotationFee.setDelFlag("1");
        ifdProjectQuotationFeeService.update(fdProjectQuotationFee, quotationFeeLambdaQueryWrapper);

        //批量删除初始选择的模板
        LambdaQueryWrapper<FdProjectQuotationTemplateAdd> quotationTemplateAddLambdaQueryWrapper = new LambdaQueryWrapper<>();
        quotationTemplateAddLambdaQueryWrapper.eq(FdProjectQuotationTemplateAdd::getQuotationId, quotationId);
        iFdProjectQuotationTemplateAddService.remove(quotationTemplateAddLambdaQueryWrapper);

        //修改最终申办方
        fdProjectQuotation.setSponsorName(fdProjectQuotation.getCustomerName());
        //修改报表
        fdProjectQuotationService.updateById(fdProjectQuotation);
    }

    //根据申办方生成客户档案
    public void customer(FdProjectQuotation fdProjectQuotation) {
        /**根据申办方生成客户档案*/
        //创建客户档案联系人集合
        List<FdCustomerContacts> customerContactsList = new ArrayList<>();
        //循环报价客户联系人
        for (FdProjectQuotationContacts contacts : fdProjectQuotation.getQuotationContactsList()) {
            //创建客户档案联系人
            FdCustomerContacts customerContacts = new FdCustomerContacts();
            customerContacts.setContactPsn(contacts.getContactPsn());
            customerContacts.setContectTel(contacts.getContactTel());
            customerContacts.setEmail(contacts.getEmail());
            customerContacts.setIsDefault(contacts.getIsDefault());
            //添加到客户档案联系人
            customerContactsList.add(customerContacts);
        }
        //创建客户档案
        FdCustomer customer = new FdCustomer();
        //默认编码为当前时间
        String code = "KH" + new SimpleDateFormat("yyyyMMddhhmmss").format(new Date().getTime());
        customer.setCode(code);
        customer.setName(fdProjectQuotation.getCustomerName());
        customer.setEnable("0");
        customer.setFdCustomerContactsList(customerContactsList);
        customer.setAddress(fdProjectQuotation.getCustomerAddress());
        customer.setAbbreviation(fdProjectQuotation.getAbbreviation());
        //调用客户档案新增
        fdCustomerService.saveCustomer(customer);
        //添加到报价外键
        fdProjectQuotation.setPkCustomerId(customer.getId());
    }

    /***
     * @Title:
            * @Description:TODO 清除费用的空格以及保留两位小数
            * @param src
            * @return java.lang.String
            * @exception
            * @author 陈创
            * @date 2020/1/8 15:18
            * @updatehistory:
     *   2020/1/8 15:18 新增
            */
    public String fee(String src){
        String feeCategory=src.trim();//清除空格
        //是否为数字
        if(isInteger(feeCategory)){
            //保留两位小数
            Double feeDouble=Double.parseDouble(feeCategory);
            // feeCategory=twoDouble(feeDouble);
            // feeCategory=format(feeDouble,2).toString();
            feeCategory=String.format("%.2f",feeDouble);
        }
        return feeCategory;
    }


    /***
     * @Title:保存时审核状态控制
     * @Description:TODO
     * @param fdProjectQuotation
     * @return voidF
     * @exception
     * @author 陈创
     * @date 2019/9/18 11:07
     * @updatehistory:
     *   2019/9/18 11:07 新增
     */
    public void toExamineStatus(FdProjectQuotation fdProjectQuotation) {
        //临床审核
        if (!StringUtils.isNotBlank(fdProjectQuotation.getClinicalSectionId())) {
            fdProjectQuotation.setIsClinicalSectionExamine("1");
        } else if (!StringUtils.isNotBlank(fdProjectQuotation.getClinicalSectionMemo())) {//只允许修改新加的审核人状态
            fdProjectQuotation.setIsClinicalSectionExamine("0");
        }
        //中心价格审核
        if (!StringUtils.isNotBlank(fdProjectQuotation.getCentralPriceId())) {
            fdProjectQuotation.setIsCentralPriceExamine("1");
        } else if (!StringUtils.isNotBlank(fdProjectQuotation.getCentralPriceMemo())) {//只允许修改新加的审核人状态
            fdProjectQuotation.setIsCentralPriceExamine("0");
        }
        //数据统计审核
        if (!StringUtils.isNotBlank(fdProjectQuotation.getDataStatisticsId())) {
            fdProjectQuotation.setIsDataStatisticsExamine("1");
        } else if (!StringUtils.isNotBlank(fdProjectQuotation.getDataStatisticsMemo())) {//只允许修改新加的审核人状态
            fdProjectQuotation.setIsDataStatisticsExamine("0");
        }
        //PK计算审核
        if (!StringUtils.isNotBlank(fdProjectQuotation.getPkComputingId())) {
            fdProjectQuotation.setIsPkComputingExamine("1");
        } else if (!StringUtils.isNotBlank(fdProjectQuotation.getPkComputingMemo())) {//只允许修改新加的审核人状态
            fdProjectQuotation.setIsPkComputingExamine("0");
        }
        //生物分析计算审核
        if (!StringUtils.isNotBlank(fdProjectQuotation.getBioanalysisId())) {
            fdProjectQuotation.setIsBioanalysisExamine("1");
        } else if (!StringUtils.isNotBlank(fdProjectQuotation.getBioanalysisMemo())) {
            fdProjectQuotation.setIsBioanalysisExamine("0");
        }
    }

    /***
     * @Title:复制时审核状态控制
     * @Description:TODO
     * @param fdProjectQuotation
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/9/18 11:08
     * @updatehistory:
     *   2019/9/18 11:08 新增
     */
    public void copyToExamineStatus(FdProjectQuotation fdProjectQuotation) {
        //临床审核
        if (StringUtils.isNotBlank(fdProjectQuotation.getClinicalSectionId())) {
            fdProjectQuotation.setIsClinicalSectionExamine("0");
            fdProjectQuotation.setClinicalSectionMemo("");
        }
        //中心价格审核
        if (StringUtils.isNotBlank(fdProjectQuotation.getCentralPriceId())) {
            fdProjectQuotation.setIsCentralPriceExamine("0");
            fdProjectQuotation.setCentralPriceMemo("");
        }
        //数据统计审核
        if (StringUtils.isNotBlank(fdProjectQuotation.getDataStatisticsId())) {
            fdProjectQuotation.setIsDataStatisticsExamine("0");
            fdProjectQuotation.setDataStatisticsMemo("");
        }
        //PK计算审核
        if (StringUtils.isNotBlank(fdProjectQuotation.getPkComputingId())) {
            fdProjectQuotation.setIsPkComputingExamine("0");
            fdProjectQuotation.setPkComputingMemo("");
        }
        //生物分析计算审核
        if (StringUtils.isNotBlank(fdProjectQuotation.getBioanalysisId())) {
            fdProjectQuotation.setIsBioanalysisExamine("0");
            fdProjectQuotation.setBioanalysisMemo("");
        }
        //总经理
        if (StringUtils.isNotBlank(fdProjectQuotation.getGeneralManager())) {
            fdProjectQuotation.setIsGeneralExamine("0");
            fdProjectQuotation.setGeneralManagerMemo("");
        }
    }

//    //合同档案的 添加
//    public void  saveProjectQuotation1(FdProjectQuotation fdProjectQuotation,FdContract fdContract){
//        if(fdProjectQuotation.getId()==""||fdProjectQuotation.getId()==null) {
//            //新增报表
//            fdProjectQuotation.setDelFlag("0");
//            fdProjectQuotationService.save(fdProjectQuotation);
//        }else {
//            //修改报表
//            fdProjectQuotationService.updateById(fdProjectQuotation);
//            //合同id
//            String contractId = fdContract.getId();
//            //报价单id
//            String quotationId=fdProjectQuotation.getId();
//            //批量删除对照明细
//            LambdaQueryWrapper<FdContractDetail> queryDetail=new LambdaQueryWrapper<>();
//            queryDetail.eq(FdContractDetail::getContractId,contractId);
//            fdContractDetailService.remove(queryDetail);
//            //批量删除化合物
//            LambdaQueryWrapper<FdContractCompound> queryCompound=new LambdaQueryWrapper<>();
//            queryCompound.eq(FdContractCompound::getContractId,contractId);
//            fdContractCompoundService.remove(queryCompound);
//            //批量删除联系人
//            LambdaQueryWrapper<FdContractContacts> queryContacts=new LambdaQueryWrapper<>();
//            queryContacts.eq(FdContractContacts::getContractId,contractId);
//            fdContractContactsService.remove(queryContacts);
//            //项目报价单对照明细
//            LambdaQueryWrapper<FdProjectQuotationTemplateItem> queryTemplateItem=new LambdaQueryWrapper<>();
//            queryTemplateItem.eq(FdProjectQuotationTemplateItem::getQuotationId,quotationId);
//            fdProjectQuotationTemplateItemService.remove(queryTemplateItem);
//            //项目对照
//            LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemolate=new LambdaQueryWrapper<>();
//            queryTemolate.eq(FdProjectQuotationTemplate::getQuotationId,quotationId);
//            fdProjectQuotationTemplateService.remove(queryTemolate);
//            //比例设置
//            LambdaQueryWrapper<FdContractProportion> queryProportion = new LambdaQueryWrapper<>();
//            queryProportion.eq(FdContractProportion::getContractId,contractId);
//            fdContractProportionService.remove(queryProportion);
//        }
//        //对照明细对象添加合同id
//        for(FdContractDetail fdContractDetail:fdContract.getContractDetailList()){
//            fdContractDetail.setContractId(fdContract.getId());
//        }
//        //化合物对象添加合同id
//        int i=1;
//        for(FdContractCompound fdContractCompound:fdContract.getContractCompoundList()){
//            fdContractCompound.setSort(i);
//            fdContractCompound.setContractId(fdContract.getId());
//            i++;
//        }
//        //联系人对象添加合同id
//        for(FdContractContacts fdContractContacts:fdContract.getContractContactsList()){
//            fdContractContacts.setContractId(fdContract.getId());
//        }
//        //项目报价单对照明细添加报表id
//        for(FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem:fdProjectQuotation.getQuotationTemplateItemList()){
//            //判断利润中心 和 负责人 是否为空
//            if (fdProjectQuotationTemplateItem.getProfitCenter()!=null && fdProjectQuotationTemplateItem.getMaster()!=null){
//                //不为空则添加数据
//                fdProjectQuotationTemplateItem.setQuotationId(fdProjectQuotation.getId());
//            }
//        }
//        //项目报价单对照集合
//        List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList=new ArrayList<>();
//        String quotationTemplateId="";//用于判断相等
//        //从对照明细取模板id
//        for(FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem:fdProjectQuotation.getQuotationTemplateItemList()){
//            String quotationTemplateId2=fdProjectQuotationTemplateItem.getProjectQuotationTemplateId();
//            if(!quotationTemplateId.equals(quotationTemplateId2)){//存对照对象
//                //项目报价单对照对象
//                FdProjectQuotationTemplate temp=new FdProjectQuotationTemplate();
//                temp.setQuotationTemplateId(quotationTemplateId2);//模板id
//                temp.setQuotationId(fdProjectQuotation.getId());
//                fdProjectQuotationTemplateList.add(temp);
//                quotationTemplateId=quotationTemplateId2;
//            }
//        }
//        for (FdContractProportion fdContractProportion : fdContract.getContractProportionList()) {
//            if (fdContractProportion.getContractId().equals(fdContract.getId())) {
//                    fdContractProportion.setProportion(proportionSet11(fdContract.getQuotationId()));
//                    fdContractProportion.setProportion(proportionSet22(fdContract.getQuotationId()));
//            }
//        }
//        fdContractProportionService.saveBatch(fdContract.getContractProportionList());
//        //批量新增对照明细
//        fdContractDetailService.saveBatch(fdContract.getContractDetailList());
//        //批量新增化合物
//        fdContractCompoundService.saveBatch(fdContract.getContractCompoundList());
//        //批量新增联系人
//        fdContractContactsService.saveBatch(fdContract.getContractContactsList());
//        //项目报价单对照明细批量新增
//        fdProjectQuotationTemplateItemService.saveBatch(fdProjectQuotation.getQuotationTemplateItemList());
//        //项目对照
//        fdProjectQuotationTemplateService.saveBatch(fdProjectQuotationTemplateList);
//    }


    /**
     * @return void
     * @Author gurui
     * @Description //TODO 修改 项目报价表 同时修改 项目报价选择的模板对照表,项目报价评论明细表
     * @Date 18:30 2019/5/20
     * @Param [fdProjectQuotation]
     **/
    @Override
    public void updateQuotation(FdProjectQuotation fdProjectQuotation) {
        fdProjectQuotationService.updateById(fdProjectQuotation);
        //根据项目报价单id查询项目报价选择的模板对照表
        LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemplate = new LambdaQueryWrapper<>();
        queryTemplate.eq(FdProjectQuotationTemplate::getQuotationId, fdProjectQuotation.getId()).eq(FdProjectQuotationTemplate::getDelFlag, "0");
        List<FdProjectQuotationTemplate> templateList = fdProjectQuotationTemplateService.list(queryTemplate);
        if (fdProjectQuotation.getQuotationTemplateList() != null) {
            for (FdProjectQuotationTemplate templates : templateList) {
                for (FdProjectQuotationTemplate template : fdProjectQuotation.getQuotationTemplateList()) {
                    //将查询出来的ID赋给传入值,根据ID修改
                    template.setId(templates.getId());
                    fdProjectQuotationTemplateService.updateById(template);
                }
            }
        }

        //根据项目报价单id查询项目报价评论明细表
        LambdaQueryWrapper<FdProjectQuotationComments> queryComments = new LambdaQueryWrapper<>();
        queryComments.eq(FdProjectQuotationComments::getQuotationId, fdProjectQuotation.getId()).eq(FdProjectQuotationComments::getDelFlag, "0");
        List<FdProjectQuotationComments> commentsList = fdProjectQuotationCommentsService.list(queryComments);
        if (fdProjectQuotation.getQuotationCommentsList() != null) {
            for (FdProjectQuotationComments comments : commentsList) {
                for (FdProjectQuotationComments comment : fdProjectQuotation.getQuotationCommentsList()) {
                    //将查询出来的ID赋给传入值,根据ID修改
                    comment.setId(comments.getId());
                    fdProjectQuotationCommentsService.updateById(comment);
                }
            }
        }
    }

    /**
     * @return void
     * @Author gurui
     * @Description //TODO 删除 项目报价表 同时删除 项目报价选择的模板对照表,项目报价评论明细表
     * @Date 9:23 2019/5/21
     * @Param [ids]
     **/
    // @Override
    // public void deleteProjectQuotation(String ids) {
    //     //获得要删除的ids
    //     List list = Arrays.asList(ids.split(","));
    //     FdProjectQuotation fdProjectQuotation = null;
    //     for (int i = 0; i < list.size(); i++) {
    //         fdProjectQuotation = new FdProjectQuotation();
    //         fdProjectQuotation.setId(list.get(i).toString());
    //         // 删除项目报价选择的模板对照表
    //         LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemplate = new LambdaQueryWrapper<>();
    //         queryTemplate.eq(FdProjectQuotationTemplate::getQuotationId, fdProjectQuotation.getId());
    //         List<FdProjectQuotationTemplate> templateList = fdProjectQuotationTemplateService.list(queryTemplate);
    //         for (FdProjectQuotationTemplate template : templateList) {
    //             template.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
    //             fdProjectQuotationTemplateService.updateById(template);
    //         }
    //         //删除项目报价评论明细表
    //         LambdaQueryWrapper<FdProjectQuotationComments> queryComments = new LambdaQueryWrapper<>();
    //         queryComments.eq(FdProjectQuotationComments::getQuotationId, fdProjectQuotation.getId());
    //         List<FdProjectQuotationComments> commentsList = fdProjectQuotationCommentsService.list(queryComments);
    //         for (FdProjectQuotationComments comments : commentsList) {
    //             comments.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
    //             fdProjectQuotationCommentsService.updateById(comments);
    //         }
    //         fdProjectQuotation.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
    //         fdProjectQuotationService.updateById(fdProjectQuotation);
    //     }
    // }


    /*
     *
     * 生成合同
     * @author 陈创
     * @date 2019/5/28
     * @param
     * @return void
     */
    public void contractOfFormation(String id) {

        //报价单明细
        FdProjectQuotation fdProjectQuotation = fdProjectQuotationService.getById(id);
        //修改状态
        fdProjectQuotation.setStatus("3");
        fdProjectQuotationService.updateById(fdProjectQuotation);
        //联系人
        LambdaQueryWrapper<FdProjectQuotationContacts> query = new LambdaQueryWrapper<>();
        query.eq(FdProjectQuotationContacts::getDelFlag, "0");
        query.eq(FdProjectQuotationContacts::getQuotationId, id);
        query.eq(FdProjectQuotationContacts::getIsDefault, "1");
        List<FdProjectQuotationContacts> fdCustomerContactsList = fdProjectQuotationContactsService.list(query);
        //化合物查询条件
        LambdaQueryWrapper<FdProjectQuotationCompound> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FdProjectQuotationCompound::getDelFlag, "0");
        queryWrapper.eq(FdProjectQuotationCompound::getQuotationId, id);
        //查询第一个化合物
        List<FdProjectQuotationCompound> compoundList = fdProjectQuotationCompoundService.list(queryWrapper);
        //添加到合同明细
        FdContract contract = new FdContract();
        contract.setCode(fdProjectQuotation.getCode());
        contract.setBidParty(fdProjectQuotation.getContactPsn());
        // contract.setSignDate("");
        contract.setContractType(fdProjectQuotation.getContractType());
        contract.setNatrixType(fdProjectQuotation.getMatrixType());
        contract.setSourceQuotationCode(fdProjectQuotation.getCode());
        contract.setQuotationId(fdProjectQuotation.getId());
        contract.setQuotationDate(fdProjectQuotation.getQuotationDate());
        contract.setQuotationValidDate(fdProjectQuotation.getValidDate());
        contract.setCustomerAddress(fdProjectQuotation.getCustomerAddress());
        contract.setMemo(fdProjectQuotation.getMemo());
        contract.setPkCustomerId(fdProjectQuotation.getPkCustomerId());
        contract.setCustomerName(fdProjectQuotation.getCustomerName());
        contract.setTaxRate(fdProjectQuotation.getTaxRate());
        contract.setType(fdProjectQuotation.getType());
        contract.setDetectionIndicators(fdProjectQuotation.getDetectionIndicators());
        contract.setBusinessManager(fdProjectQuotation.getBusinessManager());
        contract.setProjectManagerId(fdProjectQuotation.getProjectManager());
        contract.setTotalAmount(fdProjectQuotation.getTotalAmount());
        contract.setFinalTotalAmount(fdProjectQuotation.getTotalAmount());
        contract.setHospitalList(fdProjectQuotation.getHospitalList());
        contract.setHospitalListName(fdProjectQuotation.getHospitalListName());
        contract.setBiologicalAnalysisLaboratory(fdProjectQuotation.getBiologicalAnalysisLaboratory());
        contract.setBiologicalAnalysisLaboratoryName(fdProjectQuotation.getBiologicalAnalysisLaboratoryName());
        contract.setFastingSubtotal(fdProjectQuotation.getFastingSubtotal());
        contract.setPostMealSubtotals(fdProjectQuotation.getPostMealSubtotals());
        contract.setCostTotal(fdProjectQuotation.getCostTotal());
        contract.setMaCostTotal(fdProjectQuotation.getMaCostTotal());
        contract.setCurrencyType(fdProjectQuotation.getCurrencyType());
        contract.setCurrencyTypeName(fdProjectQuotation.getCurrencyTypeName());
        contract.setCurrencyTypeEgName(fdProjectQuotation.getCurrencyTypeEgName());
        contract.setCurrencyTypeChName(fdProjectQuotation.getCurrencyTypeChName());
        contract.setItemColspanSub(fdProjectQuotation.getItemColspanSub());
        contract.setFeeCategory1Title(fdProjectQuotation.getFeeCategory1Title());
        contract.setFeeCategory2Title(fdProjectQuotation.getFeeCategory2Title());
        contract.setFirstParty(fdProjectQuotation.getCustomerName());
        contract.setFirstPartyId(fdProjectQuotation.getPkCustomerId());
        contract.setContractTypeName(fdProjectQuotation.getContractTypeName());
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        contract.setBusinessManager(user.getPersonnelId());
        for (FdProjectQuotationContacts contacts : fdCustomerContactsList) {
            contract.setContactPsn(contacts.getContactPsn());
            contract.setContactTel(contacts.getContactTel());
            contract.setContactEmail(contacts.getEmail());
        }
        contract.setProjectName(fdProjectQuotation.getName());
        contract.setProjectDescription(fdProjectQuotation.getDescription());
        for (FdProjectQuotationCompound compounds : compoundList) {
            contract.setCompound(compounds.getCompound());
        }
        contract.setSubmission(fdProjectQuotation.getSubmission());
        contract.setFastingSubtotalC(fdProjectQuotation.getFastingSubtotal());
        contract.setPostMealSubtotalsC(fdProjectQuotation.getPostMealSubtotals());
        contract.setCostTotalC(fdProjectQuotation.getCostTotal());
        contract.setMaCostTotalC(fdProjectQuotation.getMaCostTotal());
        contract.setSponsorName(fdProjectQuotation.getCustomerName());
        //保存合同明细
        fdContractService.save(contract);
        /** 生成对照明细*/
        contractDetail(id, contract.getId());
        /** 生成合同化合物*/
        contractCompound(id, contract.getId());
        /** 生成客户联系人*/
        contractContact(id, contract.getId());
    }


    /*
     *
     *合同生成化合物
     * @author 陈创
     * @date 2019/5/28
     * @param
     * @return
     */
    public void contractCompound(String quotationId, String contractId) {
        //根据报价单查询化合物
        LambdaQueryWrapper<FdProjectQuotationCompound> queryCompound = new LambdaQueryWrapper<>();
        queryCompound.eq(FdProjectQuotationCompound::getQuotationId, quotationId);
        queryCompound.eq(FdProjectQuotationCompound::getDelFlag, "0");
        //查询第一个化合物
        List<FdProjectQuotationCompound> compounds = fdProjectQuotationCompoundService.list(queryCompound);
        //合同化合物对象
        List<FdContractCompound> contractCompounds = new ArrayList<>();
        //把报价中的化合物带入合同
        for (FdProjectQuotationCompound co : compounds) {
            FdContractCompound contractCompound = new FdContractCompound();
            contractCompound.setContractId(contractId);
            contractCompound.setCompound(co.getCompound());
            contractCompound.setSourceId(quotationId);
            contractCompound.setSort(Integer.parseInt(co.getSort()));
            contractCompound.setDelFlag("0");
            contractCompounds.add(contractCompound);
        }
        //批量存入合同化合物中
        fdContractCompoundService.saveBatch(contractCompounds);
    }

    /*
     *
     * 生成合同联系人
     * @author 陈创
     * @date 2019/5/28
     * @param
     * @return void
     */
    public void contractContact(String quotationId, String contractId) {
        //联系人查询条件
        LambdaQueryWrapper<FdProjectQuotationContacts> query = new LambdaQueryWrapper<>();
        query.eq(FdProjectQuotationContacts::getQuotationId, quotationId);
        query.eq(FdProjectQuotationContacts::getDelFlag, "0");
        //报价单客户联系人
        List<FdProjectQuotationContacts> fdCustomerContactsList = fdProjectQuotationContactsService.list(query);
        //合同联系人集合
        List<FdContractContacts> contractContactsList = new ArrayList<>();
        //报价单客户联系人生成到合同
        for (FdProjectQuotationContacts fdProjectQuotationContacts : fdCustomerContactsList) {
            FdContractContacts contractContacts = new FdContractContacts();
            contractContacts.setContractId(contractId);
            contractContacts.setContactPsn(fdProjectQuotationContacts.getContactPsn());
            contractContacts.setContactTel(fdProjectQuotationContacts.getContactTel());
            contractContacts.setEmail(fdProjectQuotationContacts.getEmail());
            contractContacts.setIsDefault(fdProjectQuotationContacts.getIsDefault());
            contractContacts.setMemo(fdProjectQuotationContacts.getMemo());
            contractContacts.setSourceId(quotationId);
            contractContacts.setEnable(fdProjectQuotationContacts.getEnable());
            contractContactsList.add(contractContacts);
        }
        //批量生成客户联系人
        fdContractContactsService.saveBatch(contractContactsList);
    }

    /*
     *
     * 生成对照明细合同
     * @author 陈创
     * @date 2019/5/28
     * @param
     * @return void
     */
    public void contractDetail(String quotationId, String contractId) {
        //对照明细查询条件
        LambdaQueryWrapper<FdProjectQuotationDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FdProjectQuotationDetail::getQuotationId, quotationId);
        queryWrapper.eq(FdProjectQuotationDetail::getDelFlag, "0");
        //报价对照明细集合
        List<FdProjectQuotationDetail> quotationDetailList = fdProjectQuotationDetailService.list(queryWrapper);
        //合同对照明细集合
        List<FdContractDetail> contractDetailList = new ArrayList<>();
        //把报价单中的对照明细生成到合同
        for (FdProjectQuotationDetail fdProjectQuotationDetail : quotationDetailList) {
            FdContractDetail fdContractDetail = new FdContractDetail();
            fdContractDetail.setContractId(contractId);
            fdContractDetail.setStudyType(fdProjectQuotationDetail.getStudyType());
            fdContractDetail.setSubjectNumber(fdProjectQuotationDetail.getSubjectNumber());
            fdContractDetail.setPeriod(fdProjectQuotationDetail.getPeriod());
            fdContractDetail.setSamplesPeriod(fdProjectQuotationDetail.getSamplesPeriod());
            fdContractDetail.setTotalSamples(fdProjectQuotationDetail.getTotalSamples());
            fdContractDetail.setSamplesTime(fdProjectQuotationDetail.getSamplesTime());
            fdContractDetail.setOpvPeriod(fdProjectQuotationDetail.getOpvPeriod());
            fdContractDetail.setTotalNum(fdProjectQuotationDetail.getTotalSample());
            fdContractDetail.setCleaningPeriod(fdProjectQuotationDetail.getCleaningPeriod());
            fdContractDetail.setHospitalization(fdProjectQuotationDetail.getHospitalization());
            fdContractDetail.setSourceId(quotationId);
            fdContractDetail.setEnable(fdProjectQuotationDetail.getEnable());
            fdContractDetail.setAnalysisSample(fdProjectQuotationDetail.getAnalysisSample());
            fdContractDetail.setLongTimePoint(fdProjectQuotationDetail.getLongTimePoint());
            fdContractDetail.setIsr(fdProjectQuotationDetail.getIsr());
            fdContractDetail.setMonthlyExpenses(fdProjectQuotationDetail.getMonthlyExpenses());
            fdContractDetail.setStorageMonth(fdProjectQuotationDetail.getStorageMonth());
            fdContractDetail.setLabelFee(fdProjectQuotationDetail.getLabelFee());
            fdContractDetail.setTransportationExpenses(fdProjectQuotationDetail.getTransportationExpenses());
            fdContractDetail.setTransportationFrequency(fdProjectQuotationDetail.getTransportationFrequency());
            fdContractDetail.setTagName(fdProjectQuotationDetail.getTagName());
            fdContractDetail.setSort(fdProjectQuotationDetail.getSort());
            fdContractDetail.setSamplesTimeHour(fdProjectQuotationDetail.getSamplesTimeHour());
            fdContractDetail.setMatrixTypeId(fdProjectQuotationDetail.getMatrixTypeId());
            fdContractDetail.setMatrixTypeName(fdProjectQuotationDetail.getMatrixTypeName());
            fdContractDetail.setCompoundName(fdProjectQuotationDetail.getCompoundName());
            contractDetailList.add(fdContractDetail);
        }
        //批量保存合同对照明细
        fdContractDetailService.saveBatch(contractDetailList);
    }

    /*
     *
     * 状态关闭
     * @author 陈创
     * @date 2019/6/3
     * @param
     * @return void
     */
    @Override
    public Map<String, Object> close(List<String> ids) {
        Map<String, Object> map = new HashMap<>();
        String succ = " ";//可关闭
        String closed = " ";//已关闭
        //根据多个id查询报价对象集合
        List<FdProjectQuotation> projectQuotationList = fdProjectQuotationMapper.selectBatchIds(ids);
        //修改
        if (projectQuotationList == null || projectQuotationList.isEmpty()) {
            closed += "未找到修改数据</br>";
        } else {
            //判断哪些可关闭哪些不可关闭
            for (FdProjectQuotation projectQuotation : projectQuotationList) {
                if (projectQuotation.getStatus().equals("2")) {
                    closed += projectQuotation.getName() + "，";
                } else {
                    succ += projectQuotation.getName() + "，";
                }
            }
            //可关闭存在则操作数据库修改
            if (!succ.equals("")) {
                fdProjectQuotationMapper.updateStatusBatch(ids);
            }
        }
        //去掉最后一个"，"号
        closed = closed.substring(0, closed.length() - 1);
        succ = succ.substring(0, succ.length() - 1);
        //加关键词
        if (!succ.equals("")) {
            succ = succ + "关闭成功";
        }
        if (!closed.equals("")) {
            closed = "其中：" + closed + "已处关闭状态。<br>";
        }
        map.put("msg", succ + closed);
        return map;
    }

    /**
     * @return void
     * @Author gurui
     * @Description //TODO  根据id删除化合物
     * @Date 14:14 2019/6/13
     * @Param [id]
     **/
    @Override
    public void deleteCompound(String id) {
        //获得要删除的id
        List list = Arrays.asList(id.split(","));
        FdProjectQuotation fdProjectQuotation = new FdProjectQuotation();
        for (int i = 0; i < list.size(); i++) {
            fdProjectQuotation.setId(list.get(i).toString());
            //获得根据id查询到的化合物信息删除
            FdProjectQuotationCompound compound = new FdProjectQuotationCompound();
            compound.setDelFlag("1");
            UpdateWrapper<FdProjectQuotationCompound> updateWrapper = new UpdateWrapper<>();
            System.out.println(fdProjectQuotation.getId());
            updateWrapper.eq("quotation_id", fdProjectQuotation.getId());
            fdProjectQuotationCompoundService.update(compound, updateWrapper);

        }

    }

    /**
     * @return void
     * @Author gurui
     * @Description //TODO 根据id删除联系人
     * @Date 15:04 2019/6/13
     * @Param [id]
     **/
    @Override
    public void deleteContracts(String id) {
        //获得要删除的id
        List list = Arrays.asList(id.split(","));
        FdProjectQuotation fdProjectQuotation = new FdProjectQuotation();
        for (int i = 0; i < list.size(); i++) {
            fdProjectQuotation.setId(list.get(i).toString());
            //获得根据id查询到的化合物信息删除
            FdProjectQuotationContacts contacts = new FdProjectQuotationContacts();
            contacts.setDelFlag("1");
            UpdateWrapper<FdProjectQuotationContacts> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("quotation_id", fdProjectQuotation.getId());
            fdProjectQuotationContactsService.update(contacts, updateWrapper);

        }
    }

    /**
     * @return java.util.Map<java.lang.String   ,       java.lang.Object>
     * @Author gurui
     * @Description //TODO 根据多个报价id修改状态为1(已审核)
     * @Date 18:14 2019/6/17
     * @Param [ids]
     **/
    @Override
    public Map<String, Object> reviewBatch(List<String> ids) {
        Map<String, Object> map = new HashMap<>();
        String unReview = " "; //未审核
        String review = " "; //已审核
        String isExamine = " ";//三位负责人是否都已经审核
        //根据多个id查询报价对象集合
        List<FdProjectQuotation> fdProjectQuotationList = fdProjectQuotationMapper.selectBatchIds(ids);

        //修改
        if (fdProjectQuotationList == null || fdProjectQuotationList.isEmpty()) {
            review += "未找到修改数据</br>";
        } else {
            //判断哪些已审核哪些未审核
            for (FdProjectQuotation fdProjectQuotation : fdProjectQuotationList) {
                if (fdProjectQuotation.getIsGeneralExamine().equals("1")) {
                    if (fdProjectQuotation.getStatus().equals("0")) {
                        unReview += fdProjectQuotation.getName() + "，";
                    }
                    if (fdProjectQuotation.getStatus().equals("1")) {
                        review += fdProjectQuotation.getName() + "，";
                    }
                    if (fdProjectQuotation.getStatus().equals("2")) {
                        throw new RuntimeException("已关闭！无法审核");
                    }
                    if (fdProjectQuotation.getStatus().equals("3")) {
                        throw new RuntimeException("已转合同！无法审核");
                    }
                } else {
                    isExamine = "经理还未审核";
                }

            }
            //去掉最后一个","号
            unReview = unReview.substring(0, unReview.length() - 1);
            review = review.substring(0, review.length() - 1);
            //操作数据库将未审核的修改成已审核
            if (!unReview.equals("")) {
                fdProjectQuotationMapper.updateReviewBatch(ids);
            }
        }
        //加关键词
        if (!unReview.equals("")) {
            unReview = unReview + "审核成功";
        }
        if (!review.equals("")) {
            review = "其中：" + review + "已审核。<br>";
        }
        map.put("msg", isExamine + unReview + review);
        return map;
    }


    /**
     * @return void
     * @Author gurui
     * @Description //TODO 根据项目报价单id复制一条一样的数据
     * @Date 13:53 2019/6/26
     * @Param [id]
     **/
    public void copy(String id, String status, String curId) {
        //根据id获得模板
        FdProjectQuotation fdProjectQuotation = fdProjectQuotationMapper.selectById(id);
        //根据选择的客户获取客户信息
        FdCustomer fdCustomer = fdCustomerService.getById(curId);
        //用于编码规则
        FdProjectQuotation fdProjectQuotationCall = new FdProjectQuotation();
        fdProjectQuotationCall.setAbbreviation(fdCustomer.getAbbreviation());//获取选择的客户缩写
        //获取Q300001 SHFL YY
        CallResult<String> resultSerial = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_one", "code", true);
        //获取 客户缩写 001
        CallResult<String> resultSerial2 = sysSerialPatternService.getNextSerial(fdProjectQuotationCall, "fd_project_quotation_two", "code", true);
        if (!resultSerial.isSucceed() || !resultSerial2.isSucceed()) {
            throw new RuntimeException("获取编码失败");
        }
        //根据模板保存
        fdProjectQuotation.setCode(resultSerial.getContent() +resultSerial2.getContent());
//        fdProjectQuotation.setCode(resultSerial.getContent() +resultSerial2.getContent().substring(2));
        fdProjectQuotation.setId("");
        fdProjectQuotation.setCreateTime(null);
        fdProjectQuotation.setCreateBy("");
        fdProjectQuotation.setPkCustomerId(fdCustomer.getId());//客户id
        fdProjectQuotation.setCustomerName(fdCustomer.getName());//客户名称
        fdProjectQuotation.setCustomerAddress(fdCustomer.getAddress());//客户地址
        fdProjectQuotation.setAbbreviation(fdCustomer.getAbbreviation());//客户缩写
        fdProjectQuotation.setFinalAuditorId(null);//最后审核人id
        fdProjectQuotation.setFinalAuditorName(null);//最后审核人名称
        fdProjectQuotation.setStatus(status);//状态
        //审核人状态控制
        copyToExamineStatus(fdProjectQuotation);
        fdProjectQuotationService.save(fdProjectQuotation);

        //联系人
        LambdaQueryWrapper<FdCustomerContacts> fdCustomerContactsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        fdCustomerContactsLambdaQueryWrapper.eq(FdCustomerContacts::getPkCustomerId, curId);
        fdCustomerContactsLambdaQueryWrapper.eq(FdCustomerContacts::getDelFlag, "0");
        List<FdCustomerContacts> fdCustomerContactsList = iFdCustomerContactsService.list(fdCustomerContactsLambdaQueryWrapper);
        //客户联系人不为空则获取到报价联系人中
        if (!fdCustomerContactsList.isEmpty() && fdCustomerContactsList.size() > 0) {
            List<FdProjectQuotationContacts> fdProjectQuotationContactsList = new ArrayList<>();
            for (FdCustomerContacts fdCustomerContacts : fdCustomerContactsList) {
                //把客户联系人赋到报价联系人
                FdProjectQuotationContacts fdProjectQuotationContacts = new FdProjectQuotationContacts();
                fdProjectQuotationContacts.setContactPsn(fdCustomerContacts.getContactPsn());
                fdProjectQuotationContacts.setContactTel(fdCustomerContacts.getContectTel());
                fdProjectQuotationContacts.setEmail(fdCustomerContacts.getEmail());
                fdProjectQuotationContacts.setIsDefault(fdCustomerContacts.getIsDefault());
                fdProjectQuotationContacts.setMemo(fdCustomerContacts.getMemo());
                fdProjectQuotationContactsList.add(fdProjectQuotationContacts);
            }
            fdProjectQuotation.setQuotationContactsList(fdProjectQuotationContactsList);
        }
        //子表数据复制
        childCopy(fdProjectQuotation, id);

        //模板以及模板项复制
        quotationTempItemsCopy(fdProjectQuotation, id);

        // //化合物
        // LambdaQueryWrapper<FdProjectQuotationCompound> queryCompound = new LambdaQueryWrapper<>();
        // queryCompound.eq(FdProjectQuotationCompound::getQuotationId, id);
        // List<FdProjectQuotationCompound> fdProjectQuotationCompoundList = fdProjectQuotationCompoundService.list(queryCompound);
        // fdProjectQuotation.setQuotationCompoundList(fdProjectQuotationCompoundList);
        // //对照明细
        // LambdaQueryWrapper<FdProjectQuotationDetail> queryDetail = new LambdaQueryWrapper<>();
        // queryDetail.eq(FdProjectQuotationDetail::getQuotationId, id);
        // List<FdProjectQuotationDetail> fdProjectQuotationDetailList = fdProjectQuotationDetailService.list(queryDetail);
        // fdProjectQuotation.setQuotationDetailList(fdProjectQuotationDetailList);
        // //联系人
        // LambdaQueryWrapper<FdProjectQuotationContacts> queryContacts = new LambdaQueryWrapper<>();
        // queryContacts.eq(FdProjectQuotationContacts::getQuotationId, id);
        // List<FdProjectQuotationContacts> fdProjectQuotationContactsList = fdProjectQuotationContactsService.list(queryContacts);
        // fdProjectQuotation.setQuotationContactsList(fdProjectQuotationContactsList);

        //模板以及模板项
        // //项目报价单对照明细
        // LambdaQueryWrapper<FdProjectQuotationTemplateItem> queryTemplateItem = new LambdaQueryWrapper<>();
        // queryTemplateItem.eq(FdProjectQuotationTemplateItem::getQuotationId, id);
        // List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList = fdProjectQuotationTemplateItemService.list(queryTemplateItem);
        // fdProjectQuotation.setQuotationTemplateItemList(fdProjectQuotationTemplateItemList);
        // //项目对照
        // LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemolate = new LambdaQueryWrapper<>();
        // queryTemolate.eq(FdProjectQuotationTemplate::getQuotationId, id);
        // List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList = fdProjectQuotationTemplateService.list(queryTemolate);
        // fdProjectQuotation.setQuotationTemplateList(fdProjectQuotationTemplateList);

        //审核描述
        // LambdaQueryWrapper<FdProjectQuotationComments> queryComments = new LambdaQueryWrapper<>();
        // queryComments.eq(FdProjectQuotationComments::getQuotationId, id);
        // List<FdProjectQuotationComments> fdProjectQuotationCommentsList = fdProjectQuotationCommentsService.list(queryComments);
        // fdProjectQuotation.setQuotationCommentsList(fdProjectQuotationCommentsList);

        //审核描述添加报表id
        // for (FdProjectQuotationComments fdProjectQuotationComments : fdProjectQuotation.getQuotationCommentsList()) {
        //     fdProjectQuotationComments.setId("");
        //     fdProjectQuotationComments.setCreateTime(null);
        //     fdProjectQuotationComments.setQuotationId(fdProjectQuotation.getId());
        // }
        // //对照明细对象添加报表id
        // for (FdProjectQuotationDetail fdProjectQuotationDetail : fdProjectQuotation.getQuotationDetailList()) {
        //     fdProjectQuotationDetail.setId("");
        //     fdProjectQuotationDetail.setCreateTime(null);
        //     fdProjectQuotationDetail.setQuotationId(fdProjectQuotation.getId());
        // }
        // //化合物对象添加报表id
        // int i = 1;
        // for (FdProjectQuotationCompound fdProjectQuotationCompound : fdProjectQuotation.getQuotationCompoundList()) {
        //     fdProjectQuotationCompound.setSort(i + "");
        //     fdProjectQuotationCompound.setId("");
        //     fdProjectQuotationCompound.setCreateTime(null);
        //     fdProjectQuotationCompound.setQuotationId(fdProjectQuotation.getId());
        //     i++;
        // }
        // //联系人对象添加报表id
        // for (FdProjectQuotationContacts fdProjectQuotationContacts : fdProjectQuotation.getQuotationContactsList()) {
        //     fdProjectQuotationContacts.setId("");
        //     fdProjectQuotationContacts.setCreateTime(null);
        //     fdProjectQuotationContacts.setQuotationId(fdProjectQuotation.getId());
        // }

        //模板以及模板项
        //项目报价单对照明细添加报表id
        // for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotation.getQuotationTemplateList()) {
        //     fdProjectQuotationTemplate.setPid(fdProjectQuotationTemplate.getId());
        //     fdProjectQuotationTemplate.setId("");
        //     fdProjectQuotationTemplate.setCreateTime(null);
        //     fdProjectQuotationTemplate.setQuotationId(fdProjectQuotation.getId());
        // }
        //
        // //项目报价单对照明细添加报表id
        // for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotation.getQuotationTemplateItemList()) {
        //     fdProjectQuotationTemplateItem.setPid(fdProjectQuotationTemplateItem.getId());
        //     fdProjectQuotationTemplateItem.setId("");
        //     fdProjectQuotationTemplateItem.setCreateTime(null);
        //     fdProjectQuotationTemplateItem.setQuotationId(fdProjectQuotation.getId());
        // }

        //审核描述
        // fdProjectQuotationCommentsService.saveBatch(fdProjectQuotation.getQuotationCommentsList());
        // //对照明细
        // fdProjectQuotationDetailService.saveBatch(fdProjectQuotation.getQuotationDetailList());
        // //化合物
        // fdProjectQuotationCompoundService.saveBatch(fdProjectQuotation.getQuotationCompoundList());
        // //联系人
        // fdProjectQuotationContactsService.saveBatch(fdProjectQuotation.getQuotationContactsList());

        //模板以及模板相
        //项目对照模板
        // fdProjectQuotationTemplateService.saveBatch(fdProjectQuotation.getQuotationTemplateList());
        // //为模板项获取复制后的模板id
        // getItemAssignmentQuotationTemplateId(fdProjectQuotation.getQuotationTemplateList(),fdProjectQuotation.getQuotationTemplateItemList());
        //
        // //项目报价单对照明细
        // fdProjectQuotationTemplateItemService.saveBatch(fdProjectQuotation.getQuotationTemplateItemList());
        // //修改父极id
        // getIdUpdatePid(fdProjectQuotation.getQuotationTemplateItemList());
        // //修改数据库模板项
        // fdProjectQuotationMapper.parentIdBatch(fdProjectQuotation.getQuotationTemplateItemList());


    }

    /***
     * @Title:报价相关子表复制
     * @Description:TODO
     * @param fdProjectQuotation, id]
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/10/31 17:29
     * @updatehistory:
     *   2019/10/31 17:29 新增
     */
    public void childCopy(FdProjectQuotation fdProjectQuotation, String id) {
        //化合物
        LambdaQueryWrapper<FdProjectQuotationCompound> queryCompound = new LambdaQueryWrapper<>();
        queryCompound.eq(FdProjectQuotationCompound::getDelFlag, "0");
        queryCompound.eq(FdProjectQuotationCompound::getQuotationId, id);
        List<FdProjectQuotationCompound> fdProjectQuotationCompoundList = fdProjectQuotationCompoundService.list(queryCompound);
        fdProjectQuotation.setQuotationCompoundList(fdProjectQuotationCompoundList);
        //对照明细
        LambdaQueryWrapper<FdProjectQuotationDetail> queryDetail = new LambdaQueryWrapper<>();
        queryDetail.eq(FdProjectQuotationDetail::getDelFlag, "0");
        queryDetail.eq(FdProjectQuotationDetail::getQuotationId, id);
        List<FdProjectQuotationDetail> fdProjectQuotationDetailList = fdProjectQuotationDetailService.list(queryDetail);
        fdProjectQuotation.setQuotationDetailList(fdProjectQuotationDetailList);
        //联系人
        // LambdaQueryWrapper<FdProjectQuotationContacts> queryContacts = new LambdaQueryWrapper<>();
        // queryContacts.eq(FdProjectQuotationContacts::getDelFlag, "0");
        // queryContacts.eq(FdProjectQuotationContacts::getQuotationId, id);
        // List<FdProjectQuotationContacts> fdProjectQuotationContactsList = fdProjectQuotationContactsService.list(queryContacts);
        // fdProjectQuotation.setQuotationContactsList(fdProjectQuotationContactsList);

        //初始模板
        LambdaQueryWrapper<FdProjectQuotationTemplateAdd> queryTemplateAdd = new LambdaQueryWrapper<>();
        queryTemplateAdd.eq(FdProjectQuotationTemplateAdd::getDelFlag, "0");
        queryTemplateAdd.eq(FdProjectQuotationTemplateAdd::getQuotationId, id);
        List<FdProjectQuotationTemplateAdd> fdProjectQuotationTemplateAddList = iFdProjectQuotationTemplateAddService.list(queryTemplateAdd);
        //费用单
        LambdaQueryWrapper<fdProjectQuotationFee> queryFee = new LambdaQueryWrapper<>();
        queryFee.eq(fdProjectQuotationFee::getDelFlag, "0");
        queryFee.eq(fdProjectQuotationFee::getProjectQuotationId, id);
        List<fdProjectQuotationFee> fdProjectQuotationFeeList = ifdProjectQuotationFeeService.list(queryFee);

        //对照明细对象添加报表id
        for (FdProjectQuotationDetail fdProjectQuotationDetail : fdProjectQuotation.getQuotationDetailList()) {
            fdProjectQuotationDetail.setId("");
            fdProjectQuotationDetail.setCreateTime(null);
            fdProjectQuotationDetail.setQuotationId(fdProjectQuotation.getId());
        }
        //化合物对象添加报表id
        int i = 1;
        for (FdProjectQuotationCompound fdProjectQuotationCompound : fdProjectQuotation.getQuotationCompoundList()) {
            fdProjectQuotationCompound.setSort(i + "");
            fdProjectQuotationCompound.setId("");
            fdProjectQuotationCompound.setCreateTime(null);
            fdProjectQuotationCompound.setQuotationId(fdProjectQuotation.getId());
            i++;
        }
        //联系人对象添加报表id
        for (FdProjectQuotationContacts fdProjectQuotationContacts : fdProjectQuotation.getQuotationContactsList()) {
            fdProjectQuotationContacts.setId("");
            fdProjectQuotationContacts.setCreateTime(null);
            fdProjectQuotationContacts.setQuotationId(fdProjectQuotation.getId());
        }

        //初始模板修改报价id等
        if (!fdProjectQuotationTemplateAddList.isEmpty()) {
            //换成复制后的信息
            for (FdProjectQuotationTemplateAdd fdProjectQuotationTemplateAdd : fdProjectQuotationTemplateAddList) {
                fdProjectQuotationTemplateAdd.setId("");
                fdProjectQuotationTemplateAdd.setCreateBy("");
                fdProjectQuotationTemplateAdd.setCreateTime(null);
                fdProjectQuotationTemplateAdd.setQuotationId(fdProjectQuotation.getId());
            }
            // fdProjectQuotation.setQuotationTemplateListAdd(fdProjectQuotationTemplateAddList);
            iFdProjectQuotationTemplateAddService.saveBatch(fdProjectQuotationTemplateAddList);
        }

        //费用单修改报价id
        if (!fdProjectQuotationFeeList.isEmpty()) {
            for (fdProjectQuotationFee fee : fdProjectQuotationFeeList) {
                fee.setId("");
                fee.setProjectQuotationId(fdProjectQuotation.getId());
            }
            ifdProjectQuotationFeeService.saveBatch(fdProjectQuotationFeeList);
        }

        //对照明细
        fdProjectQuotationDetailService.saveBatch(fdProjectQuotation.getQuotationDetailList());
        //化合物
        fdProjectQuotationCompoundService.saveBatch(fdProjectQuotation.getQuotationCompoundList());
        //联系人
        fdProjectQuotationContactsService.saveBatch(fdProjectQuotation.getQuotationContactsList());
    }

    /***
     * @Title:报价模板以及模板项复制
     * @Description:TODO
     * @param fdProjectQuotation, id]
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/10/31 17:33
     * @updatehistory:
     *   2019/10/31 17:33 新增
     */
    public void quotationTempItemsCopy(FdProjectQuotation fdProjectQuotation, String id) {
        //项目报价单对照明细
        LambdaQueryWrapper<FdProjectQuotationTemplateItem> queryTemplateItem = new LambdaQueryWrapper<>();
        queryTemplateItem.eq(FdProjectQuotationTemplateItem::getDelFlag, "0");
        queryTemplateItem.eq(FdProjectQuotationTemplateItem::getQuotationId, id);
        List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList = fdProjectQuotationTemplateItemService.list(queryTemplateItem);
        fdProjectQuotation.setQuotationTemplateItemList(fdProjectQuotationTemplateItemList);
        //项目对照
        LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemolate = new LambdaQueryWrapper<>();
        queryTemolate.eq(FdProjectQuotationTemplate::getDelFlag, "0");
        queryTemolate.eq(FdProjectQuotationTemplate::getQuotationId, id);
        List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList = fdProjectQuotationTemplateService.list(queryTemolate);
        fdProjectQuotation.setQuotationTemplateList(fdProjectQuotationTemplateList);

        //项目报价单对照明细添加报表id
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotation.getQuotationTemplateList()) {
            fdProjectQuotationTemplate.setPid(fdProjectQuotationTemplate.getId());
            fdProjectQuotationTemplate.setId("");
            fdProjectQuotationTemplate.setCreateTime(null);
            fdProjectQuotationTemplate.setQuotationId(fdProjectQuotation.getId());
        }

        //项目报价单对照明细添加报表id
        for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotation.getQuotationTemplateItemList()) {
            fdProjectQuotationTemplateItem.setPid(fdProjectQuotationTemplateItem.getId());
            fdProjectQuotationTemplateItem.setId("");
            fdProjectQuotationTemplateItem.setCreateTime(null);
            fdProjectQuotationTemplateItem.setQuotationId(fdProjectQuotation.getId());
        }

        //项目对照模板
        fdProjectQuotationTemplateService.saveBatch(fdProjectQuotation.getQuotationTemplateList());
        //为模板项获取复制后的模板id
        getItemAssignmentQuotationTemplateId(fdProjectQuotation.getQuotationTemplateList(), fdProjectQuotation.getQuotationTemplateItemList());

        //项目报价单对照明细
        fdProjectQuotationTemplateItemService.saveBatch(fdProjectQuotation.getQuotationTemplateItemList());
        //修改父极id
        getIdUpdatePid(fdProjectQuotation.getQuotationTemplateItemList());
        //修改数据库模板项
        fdProjectQuotationMapper.parentIdBatch(fdProjectQuotation.getQuotationTemplateItemList());
    }

    //为模板项获取复制后的模板id
    public void getItemAssignmentQuotationTemplateId(List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList, List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList) {
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotationTemplateList) {
            //复制前模板id
            String tempId = fdProjectQuotationTemplate.getPid();
            //复制后模板id
            String tempIdCopy = fdProjectQuotationTemplate.getId();
            for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotationTemplateItemList) {
                //复制前模板项存储的id
                String tempItemId = fdProjectQuotationTemplateItem.getProjectQuotationTemplateId();
                if (tempId.equals(tempItemId)) {
                    //获取复制后的模板id
                    fdProjectQuotationTemplateItem.setProjectQuotationTemplateId(tempIdCopy);
                }
            }
        }
    }

    /***
     * @Title:补充合同复制
     * @Description:TODO
     * @param fdProjectQuotations
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/10/31 17:34
     * @updatehistory:
     *   2019/10/31 17:34 新增
     */
    @Override
    public void supplementaryCopy(FdProjectQuotation fdProjectQuotations) {
        //根据id获得模板
        FdProjectQuotation fdProjectQuotation = fdProjectQuotationMapper.selectById(fdProjectQuotations.getId());
        //获取Q300001 SHFL YY
        // CallResult<String> resultSerial = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_one", "code", true);
        // //获取 客户缩写 001
        // CallResult<String> resultSerial2 = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_two", "code", true);
        //获取 {_AMD#} 00001
        CallResult<String> resultSerial3 = sysSerialPatternService.getNextSerial(fdProjectQuotation, "fd_project_quotation_three", "code", true);

        if (!resultSerial3.isSucceed()) {
            throw new RuntimeException("获取编码失败");
        }
        //根据模板保存
        fdProjectQuotation.setCode(resultSerial3.getContent());
        fdProjectQuotation.setId("");
        fdProjectQuotation.setCreateTime(null);
        fdProjectQuotation.setCreateBy("");
        fdProjectQuotation.setStatus(fdProjectQuotations.getStatus());
        //审核人状态控制
        copyToExamineStatus(fdProjectQuotation);
        fdProjectQuotationService.save(fdProjectQuotation);

        //联系人
        LambdaQueryWrapper<FdProjectQuotationContacts> queryContacts = new LambdaQueryWrapper<>();
        queryContacts.eq(FdProjectQuotationContacts::getDelFlag, "0");
        queryContacts.eq(FdProjectQuotationContacts::getQuotationId, fdProjectQuotations.getId());
        List<FdProjectQuotationContacts> fdProjectQuotationContactsList = fdProjectQuotationContactsService.list(queryContacts);
        fdProjectQuotation.setQuotationContactsList(fdProjectQuotationContactsList);
        //子表数据复制
        childCopy(fdProjectQuotation, fdProjectQuotations.getId());
        //模板以及模板项复制
        quotationTempItemsCopy(fdProjectQuotation, fdProjectQuotations.getId());


        // //获取模板
        // fdProjectQuotation.setQuotationTemplateList(fdProjectQuotations.getQuotationTemplateList());
        // for(FdProjectQuotationTemplate fdProjectQuotationTemplate:fdProjectQuotation.getQuotationTemplateList()){
        //     fdProjectQuotationTemplate.setTemplateItemList(templateItemByTemplate(fdProjectQuotationTemplate.getQuotationTemplateId()));
        // }
        // templateOrItemSave(fdProjectQuotation);
    }

    /***
     * @Title:根据模板id获取预支模板项复制到报价模板项中
     * @Description:TODO
     * @param pkTemplateId
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotationTemplateItem>
     * @exception
     * @author 陈创
     * @date 2019/9/18 17:06
     * @updatehistory:
     *   2019/9/18 17:06 新增
     */
    public List<FdProjectQuotationTemplateItem> templateItemByTemplate(String pkTemplateId) {
        //储存报价管理的模板项
        List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList = new ArrayList<>();
        //获取模板对应的预支模板项
        LambdaQueryWrapper<FdQuotationTemplateItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FdQuotationTemplateItem::getDelFlag, "0");
        lambdaQueryWrapper.eq(FdQuotationTemplateItem::getPkQuotationTemplate, pkTemplateId);
        lambdaQueryWrapper.orderBy(true, true, FdQuotationTemplateItem::getCode);
        List<FdQuotationTemplateItem> list1 = fdQuotationTemplateItemService.findOrderByCode(pkTemplateId);
        //把预支的模板项预支到报价模板项中
        for (FdQuotationTemplateItem fdQuotationTemplateItem : list1) {
            FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem = new FdProjectQuotationTemplateItem();
            fdProjectQuotationTemplateItem.setProjectQuotationTemplateId(pkTemplateId);
            fdProjectQuotationTemplateItem.setProjectQuotationTemplateItemId(fdQuotationTemplateItem.getId());
            fdProjectQuotationTemplateItem.setParentId(fdQuotationTemplateItem.getParentId());
            fdProjectQuotationTemplateItem.setText(fdQuotationTemplateItem.getDescription());
            fdProjectQuotationTemplateItem.setName(fdQuotationTemplateItem.getName());
            fdProjectQuotationTemplateItem.setDeliverables(fdQuotationTemplateItem.getDeliverables());
            fdProjectQuotationTemplateItem.setTimeline(fdQuotationTemplateItem.getTimeline());
            fdProjectQuotationTemplateItem.setUnitPrice(fdQuotationTemplateItem.getUnitPrice());
            fdProjectQuotationTemplateItem.setDetailField(fdQuotationTemplateItem.getDetailField());
            fdProjectQuotationTemplateItem.setCode(fdQuotationTemplateItem.getCode());
            fdProjectQuotationTemplateItem.setPostprandialUnitPrice(fdQuotationTemplateItem.getPostprandialUnitPrice());
            fdProjectQuotationTemplateItemList.add(fdProjectQuotationTemplateItem);
        }
        return fdProjectQuotationTemplateItemList;
    }

    /***
     * @Title:导出json
     * @Description:TODO
     * @param id
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/6/29 16:10
     * @updatehistory:
     *   2019/6/29 16:10 查询
     */
    public FdProjectQuotation export(String id) {
        //主表详情
        FdProjectQuotation fdProjectQuotation = fdProjectQuotationMapper.getQuotationById(id);
        //导出文件名称 日期+Q号+申办方简称+化合物+报价类型
        fdProjectQuotation.setExportName(getExportName(fdProjectQuotation));

        /** 合同类型名称*/
        //截取合同类型id
        if(StringUtils.isNotBlank(fdProjectQuotation.getContractType())){
            String[] conClassIds = fdProjectQuotation.getContractType().split(",");
            //根据合同类型id获取相关信息
            List<FdContractClass> fdContractClassList = fdContractClassService.selectBatchIds(conClassIds);
            //合同类型名称
            String conClassName = "";
            //循环获取名称
            for (FdContractClass fdContractClass : fdContractClassList) {
                if (conClassName == "") {
                    conClassName = fdContractClass.getName();
                } else {
                    conClassName += "、" + fdContractClass.getName();
                }
            }
            fdProjectQuotation.setContractTypeName(conClassName);
        }


        /**基质类型名称*/
        //截取合同类型id
        if(StringUtils.isNotBlank(fdProjectQuotation.getMatrixType())){
            String[] matrxClassIds = fdProjectQuotation.getMatrixType().split(",");
            //根据合同类型id获取相关信息
            List<FdMatrixType> fdMatrixTypeList = fdMatrixTypeService.selectBatchIds(matrxClassIds);
            //合同类型名称
            String matrxClassName = "";
            //循环获取名称
            for (FdMatrixType fdMatrixType : fdMatrixTypeList) {
                if (matrxClassName == "") {
                    matrxClassName = fdMatrixType.getName();
                } else {
                    matrxClassName += "、" + fdMatrixType.getName();
                }
            }
            fdProjectQuotation.setMatrixTypeName(matrxClassName);
        }


        //化合物
        LambdaQueryWrapper<FdProjectQuotationCompound> queryCompound = new LambdaQueryWrapper<>();
        queryCompound.eq(FdProjectQuotationCompound::getDelFlag, "0");
        queryCompound.eq(FdProjectQuotationCompound::getQuotationId, id);
        queryCompound.orderByAsc(FdProjectQuotationCompound::getSort);
        List<FdProjectQuotationCompound> fdProjectQuotationCompoundList = fdProjectQuotationCompoundService.list(queryCompound);
        fdProjectQuotation.setQuotationCompoundList(fdProjectQuotationCompoundList);
        //对照明细
        LambdaQueryWrapper<FdProjectQuotationDetail> queryDetail = new LambdaQueryWrapper<>();
        queryDetail.eq(FdProjectQuotationDetail::getDelFlag, "0");
        queryDetail.eq(FdProjectQuotationDetail::getQuotationId, id);
        queryDetail.orderByAsc(FdProjectQuotationDetail::getSort);
        List<FdProjectQuotationDetail> fdProjectQuotationDetailList = fdProjectQuotationDetailService.list(queryDetail);
        fdProjectQuotation.setQuotationDetailList(fdProjectQuotationDetailList);
        //联系人
        LambdaQueryWrapper<FdProjectQuotationContacts> queryContacts = new LambdaQueryWrapper<>();
        queryContacts.eq(FdProjectQuotationContacts::getDelFlag, "0");
        queryContacts.eq(FdProjectQuotationContacts::getQuotationId, id);
        queryContacts.orderByAsc(FdProjectQuotationContacts::getSort);
        List<FdProjectQuotationContacts> fdProjectQuotationContactsList = fdProjectQuotationContactsService.list(queryContacts);
        fdProjectQuotation.setQuotationContactsList(fdProjectQuotationContactsList);
        //费用总计
        LambdaQueryWrapper<fdProjectQuotationFee> feeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        feeLambdaQueryWrapper.eq(fdProjectQuotationFee::getDelFlag, "0");
        feeLambdaQueryWrapper.eq(fdProjectQuotationFee::getProjectQuotationId, id);
        feeLambdaQueryWrapper.orderByAsc(fdProjectQuotationFee::getSort);
        List<fdProjectQuotationFee> fdProjectQuotationFeeList = ifdProjectQuotationFeeService.list(feeLambdaQueryWrapper);
        fdProjectQuotation.setFdProjectQuotationFeeList(fdProjectQuotationFeeList);
        //项目报价单对照明细
        // List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList = fdProjectQuotationTemplateItemMapper.listOrderByCode(id,null);
        // fdProjectQuotation.setQuotationTemplateItemList(fdProjectQuotationTemplateItemList);
        // //项目对照
        // LambdaQueryWrapper<FdProjectQuotationTemplate> queryTemolate = new LambdaQueryWrapper<>();
        // queryTemolate.eq(FdProjectQuotationTemplate::getQuotationId, id);
        // List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList = fdProjectQuotationTemplateService.list(queryTemolate);
        // fdProjectQuotation.setQuotationTemplateList(fdProjectQuotationTemplateList);
        // //审核描述
        // LambdaQueryWrapper<FdProjectQuotationComments> queryComments = new LambdaQueryWrapper<>();
        // queryComments.eq(FdProjectQuotationComments::getQuotationId, id);
        // List<FdProjectQuotationComments> fdProjectQuotationCommentsList = fdProjectQuotationCommentsService.list(queryComments);
        // fdProjectQuotation.setQuotationCommentsList(fdProjectQuotationCommentsList);

        //选择得模板
        List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList = fdProjectQuotationTemplateService.getByQuotationId(id);

        //模板明细
        List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList = fdProjectQuotationTemplateItemMapper.listOrderByCode(id, null);
        //循环选择的模板
        // List<FdProjectQuotationTemplateItem> storageItems=new ArrayList<>();
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotationTemplateList) {
            //模板id
            String tempId = fdProjectQuotationTemplate.getId();
            //用处储存对应模板明细
            List<FdProjectQuotationTemplateItem> storageItems = new ArrayList<>();
            //计算小计变量
            Integer subtotal1 = 0;
            Integer subtotal2 = 0;
            //判断是否数字对象
            Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
            //循环模板明细
            for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotationTemplateItemList) {
                //是否顶级数据
                boolean isChild = false;
                for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem2 : fdProjectQuotationTemplateItemList) {
                    //判断是否存在子集数据
                    if (fdProjectQuotationTemplateItem.getId().equals(fdProjectQuotationTemplateItem2.getParentId())) {
                        isChild = true;
                    }
                }
                //找到对应模板明细
                if (tempId.equals(fdProjectQuotationTemplateItem.getProjectQuotationTemplateId()) && isChild == false) {
                    //判断空腹费用是否为数字
                    // String feeCategory1=fdProjectQuotationTemplateItem.getFeeCategory1();
                    // if(feeCategory1!=null&&!feeCategory1.equals("")&&pattern.matcher(feeCategory1).matches()){
                    //     Integer sub1=Integer.parseInt(feeCategory1);
                    //     subtotal1=subtotal1+sub1;
                    // }
                    // //判断空腹费用是否为数字
                    // String feeCategory2=fdProjectQuotationTemplateItem.getFeeCategory2();
                    // if(feeCategory2!=null&&!feeCategory2.equals("")&&pattern.matcher(feeCategory2).matches()){
                    //     Integer sub2=Integer.parseInt(feeCategory2);
                    //     subtotal2=subtotal2+sub2;
                    // }
                    storageItems.add(fdProjectQuotationTemplateItem);
                }
            }
            //赋给模板下的明细数据
            fdProjectQuotationTemplate.setTemplateItemList(storageItems);
            //小计
            // fdProjectQuotationTemplate.setSubtotal(subtotal1+subtotal2+"");
            //税费
            //保留小数
            // String tax=((subtotal1+subtotal2)*stringToDouble(fdProjectQuotation.getTaxRate()))/100+"";
            // fdProjectQuotationTemplate.setTaxation(stringToDouble(tax)+"");
            //总计
            // fdProjectQuotationTemplate.setTotal(subtotal1+subtotal2+stringToDouble(tax)+"");
        }
        // fdProjectQuotation.setQuotationTemplateItemList(storageItems);
        //改变type
        // updateTempTypeJson(fdProjectQuotationTemplateList);
        fdProjectQuotation.setQuotationTemplateList(fdProjectQuotationTemplateList);
        //合并两种费用
        // fee1AndFee2Group(storageItems);
        //cro模板与明细
        // List<FdProjectQuotationTemplate> cro=templateJson(fdProjectQuotationTemplateList,"1");
        // List<FdProjectQuotationTemplateItem> croItem=templateItemJson(storageItems,"1");
        // //cro相关模板与明细
        // List<FdProjectQuotationTemplate> croRelevant=templateJson(fdProjectQuotationTemplateList,"3");
        // List<FdProjectQuotationTemplateItem> croItemRelevant=templateItemJson(storageItems,"3");
        // //合并cro与cro相关
        // cro.addAll(croRelevant);
        // croItem.addAll(croItemRelevant);

        // fdProjectQuotation.setCroTemplateList(cro);
        // fdProjectQuotation.setCroTemplateItemList(croItem);
        // //临床
        // fdProjectQuotation.setClinTemplateList(templateJson(fdProjectQuotationTemplateList,"4"));
        // fdProjectQuotation.setClinTemplateItemList(templateItemJson(storageItems,"4"));
        // //生物分析
        // fdProjectQuotation.setBioTemplateList(templateJson(fdProjectQuotationTemplateList,"2"));
        // fdProjectQuotation.setBioTemplateItemList(templateItemJson(storageItems,"2"));
        // //生物分析耗材
        // fdProjectQuotation.setBioConsumablesTemplateList(templateJson(fdProjectQuotationTemplateList,"5"));
        // fdProjectQuotation.setBioConsumablesTemplateItemList(templateItemJson(storageItems,"5"));
        // //大分子
        // fdProjectQuotation.setMacromoleculeTemplateList(templateJson(fdProjectQuotationTemplateList,"6"));
        // fdProjectQuotation.setMacromoleculeTemplateItemList(templateItemJson(storageItems,"6"));


        return fdProjectQuotation;
    }



    /***
     * @Title:获取导出文件名称
     * @Description:TODO
     * @param fdProjectQuotation
     * @return java.lang.String
     * @exception
     * @author 陈创
     * @date 2019/10/28 16:28
     * @updatehistory:
     *   2019/10/28 16:28 新增
     */
    public String getExportName(FdProjectQuotation fdProjectQuotation) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date()) + " ";//时间
        String code = fdProjectQuotation.getCode() + " ";//编码
        String shortName = fdProjectQuotation.getShortName() + " ";//客户简称
        if (StringUtils.isEmpty(shortName)) {
            shortName = "";
        }
        String compoundName = fdProjectQuotation.getCompoundName() + " ";//化合物名称
        if (StringUtils.isEmpty(compoundName)) {
            compoundName = "";
        }
        String quotationTypeName = fdProjectQuotation.getQuotationTypeName();//报价类型名称
        if (StringUtils.isEmpty(quotationTypeName)) {
            quotationTypeName = "";
        }
        return date + code + shortName + compoundName + quotationTypeName;
    }

    /***
     * @Title:全部模板按类型分json
     * @Description:TODO
     * @param fdProjectQuotationTemplateList, tempType]
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotationTemplate>
     * @exception
     * @author 陈创
     * @date 2019/9/25 15:00
     * @updatehistory:
     *   2019/9/25 15:00 新增
     */
    public List<FdProjectQuotationTemplate> templateJson(List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList, String tempType) {
        List<FdProjectQuotationTemplate> fdProjectQuotationTemplateListResult = new ArrayList<>();
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotationTemplateList) {
            String tempTypeNow = fdProjectQuotationTemplate.getType();
            //cro、cro相关
            if (tempType.equals(tempTypeNow)) {
                fdProjectQuotationTemplateListResult.add(fdProjectQuotationTemplate);
            }
        }
        return fdProjectQuotationTemplateListResult;
    }

    /***
     * @Title:全部 模板项按类型分json
     * @Description:TODO
     * @param fdProjectQuotationTemplateItemList, tempType]
     * @return java.util.List<org.jeecg.modules.projectManagement.entity.FdProjectQuotationTemplateItem>
     * @exception
     * @author 陈创
     * @date 2019/9/25 15:00
     * @updatehistory:
     *   2019/9/25 15:00 新增
     */
    public List<FdProjectQuotationTemplateItem> templateItemJson(List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList, String tempType) {
        List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemListResult = new ArrayList<>();
        for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotationTemplateItemList) {
            String tempTypeNow = fdProjectQuotationTemplateItem.getType();
            if (tempTypeNow.equals(tempType)) {
                fdProjectQuotationTemplateItemListResult.add(fdProjectQuotationTemplateItem);
            }
        }
        return fdProjectQuotationTemplateItemListResult;
    }

    public void fee1AndFee2Group(List<FdProjectQuotationTemplateItem> fdProjectQuotationTemplateItemList) {
        for (FdProjectQuotationTemplateItem fdProjectQuotationTemplateItem : fdProjectQuotationTemplateItemList) {
            String fee1 = fdProjectQuotationTemplateItem.getFeeCategory1();
            String fee2 = fdProjectQuotationTemplateItem.getFeeCategory2();
            if (!StringUtils.isNotBlank(fee1)) {
                fdProjectQuotationTemplateItem.setFeeCategory1(fee2);
            } else if (StringUtils.isNotBlank(fee1) && StringUtils.isNotBlank(fee2)) {
                fdProjectQuotationTemplateItem.setFeeCategory1(fee1 + "--" + fee2);
            }
        }
    }

    /***
     * @Title:修改模板类型用于导出模板判断
     * @Description:TODO
     * @param fdProjectQuotationTemplateList
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/9/25 10:04
     * @updatehistory:
     *   2019/9/25 10:04 新增
     */
    public void updateTempTypeJson(List<FdProjectQuotationTemplate> fdProjectQuotationTemplateList) {
        for (FdProjectQuotationTemplate fdProjectQuotationTemplate : fdProjectQuotationTemplateList) {
            String tempType = fdProjectQuotationTemplate.getType();
            //CRO服务
            if (tempType.equals("1") || tempType.equals("3")) {
                fdProjectQuotationTemplate.setType("1");
            }
        }
    }

    /***
     * @Title:强转double，保留两位小数，小数四舍五入
     * @Description:TODO
     * @param a
     * @return double
     * @exception
     * @author 陈创
     * @date 2019/8/26 15:18
     * @updatehistory:
     *   2019/8/26 15:18 新增
     */
    public double stringToDouble(String a) {
        if (StringUtils.isNotBlank(a)) {
            double b = Double.valueOf(a);
            DecimalFormat df = new DecimalFormat("#.00");//此为保留1位小数，若想保留2位小数，则填写#.00  ，以此类推
            String temp = df.format(b);
            b = Double.valueOf(temp);
            return b;
        } else {
            return 0.00;
        }
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdContract>
     * @Author gurui
     * @Description //TODO 批量弃审核数据 是其状态变为0
     * @Date 9:35 2019/6/28
     * @Param [ids]
     **/
    @Override
    public Map<String, Object> auditBatch(List<String> ids) {
        Map<String, Object> map = new HashMap<>();
        String unAudit = " ";//可审计
        String audit = " ";//已审计
        //根据多个id查询报价对象集合
        List<FdProjectQuotation> projectQuotationList = fdProjectQuotationMapper.selectBatchIds(ids);
        //修改
        if (projectQuotationList == null || projectQuotationList.isEmpty()) {
            audit += "未找到修改数据</br>";
        } else {
            //判断哪些可审计哪些不可审计
            for (FdProjectQuotation projectQuotation : projectQuotationList) {
                if (projectQuotation.getStatus().equals("0")) {
                    audit += projectQuotation.getName() + "，";
                } else {
                    unAudit += projectQuotation.getName() + "，";
                }
            }
            //可审计存在则操作数据库修改
            if (!unAudit.equals("")) {
                fdProjectQuotationMapper.updateAuditBatch(ids);
            }
        }
        //去掉最后一个","
        audit = audit.substring(0, audit.length() - 1);
        unAudit = unAudit.substring(0, unAudit.length() - 1);
        //加关键词
        if (!unAudit.equals("")) {
            unAudit = unAudit + "弃审核成功";
        }
        if (!audit.equals("")) {
            audit = "其中:" + audit + "已处于未审核状态。<br> ";
        }
        map.put("msg", unAudit + audit);
        return map;
    }


    /***
     * @Title:项目经理人员数据
     * @Description:TODO
     * @param
     * @return java.util.List<org.jeecg.modules.basedata.entity.FdPersonnel>
     * @exception
     * @author 陈创
     * @date 2019/7/2 19:54
     * @updatehistory:
     *   2019/7/2 19:54 查询
     */
    @Override
    public List<FdPersonnel> getProjectManagerList() {
        return fdProjectQuotationMapper.getProjectManagerList();
    }

    /***
     * @Title:根据角色id查询部门一级下面的人员（树形下拉）
     * @Description:TODO
     * @param roleId
     * @return java.util.List<java.util.Map < java.lang.Object , java.lang.Object>>
     * @exception
     * @author 陈创
     * @date 2019/7/4 14:48
     * @updatehistory:
     *   2019/7/4 14:48 查询
     */
    @Override
    public List<Map<Object, Object>> getPersonnelByRole(String roleId) {
        List<Map<Object, Object>> mapList = new ArrayList<>();
        //人员id
        List<FdPersonnel> fdPersonnelList = fdPersonnelMapper.getPersonnelByRole(roleId);
        //部门人员
        presonnelOrDeparJson(fdPersonnelList, mapList,"");
        return mapList;
    }

    /***
     * @Title:根据多个角色获取人员
     * @Description:TODO
     * @param roleIds
     * @return java.util.List<java.util.Map < java.lang.Object , java.lang.Object>>
     * @exception
     * @author 陈创
     * @date 2019/9/20 15:47
     * @updatehistory:
     *   2019/9/20 15:47 新增
     */
    @Override
    public List<Map<Object, Object>> getPersonnelByRoleList(List<String> roleIds,String typeName) {
        List<Map<Object, Object>> mapList = new ArrayList<>();
        //人员id
        List<FdPersonnel> fdPersonnelList = fdPersonnelMapper.getPersonnelByRoleLists(roleIds);
        //人员去重
        personnelDuplicateRemoval(fdPersonnelList);
        //部门人员
        presonnelOrDeparJson(fdPersonnelList, mapList,typeName);
        return mapList;
    }

    /***
     * @Title:获取部门下的人员Json
     * @Description:TODO
     * @param fdPersonnelList, mapList]
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/9/20 15:44
     * @updatehistory:
     *   2019/9/20 15:44 新增
     */
    public void presonnelOrDeparJson(List<FdPersonnel> fdPersonnelList, List<Map<Object, Object>> mapList,String typeName) {
        //部门数据
        List<SysDepart> sysDepartList = new ArrayList<>();
        if (!fdPersonnelList.isEmpty()) {
            if(typeName.equals("生物分析")){
                //上海公司部门数据
                sysDepartList = sysDepartMapper.getBatchByPerIdAndOrgId(fdPersonnelList);
            }else if(typeName.equals("苏州")){
                //苏州公司部门数据
                sysDepartList = sysDepartMapper.getBatchByPerIdSuZhou(fdPersonnelList);
            }else if(typeName.equals("郑州临床")){
                //上海临床部门数据
                sysDepartList = sysDepartMapper.getBatchByPerIdZhengZhou(fdPersonnelList);
            }else{
                //所有公司部门数据
                sysDepartList = sysDepartMapper.getBatchByPerId(fdPersonnelList);
            }
        }
        if (!sysDepartList.isEmpty()) {
            //循环部门
            for (SysDepart sysDepart : sysDepartList) {
                Map<Object, Object> map = new HashMap<>();
                //部门名称
                map.put("title", sysDepart.getDepartName());
                //部门id
                map.put("key", sysDepart.getId());
                //子级
                List<Map<Object, Object>> listChildMap = new ArrayList<>();
                //根据部门获取对应人员
                for (FdPersonnel fdPersonnel : fdPersonnelList) {
                    Map<Object, Object> childMap = new HashMap<>();
                    if (fdPersonnel.getPkDepart().equals(sysDepart.getId())) {
                        childMap.put("title", fdPersonnel.getName());
                        childMap.put("key", fdPersonnel.getId());
                        childMap.put("isLeaf", true);
                        childMap.put("reloId", fdPersonnel.getRoleId());
                        childMap.put("reloName", fdPersonnel.getRoleName());
                        childMap.put("departName", sysDepart.getDepartName());
                        childMap.put("departId", sysDepart.getId());
                        listChildMap.add(childMap);
                    }
                }
                //部门下面的人员
                map.put("children", listChildMap);
                mapList.add(map);
            }
        }
    }


    /***
     * @Title:
            * @Description:TODO 人员去重
            * @param fdPersonnelList
            * @return void
            * @exception
            * @author 陈创
            * @date 2020/4/22 17:54
            * @updatehistory:
     *   2020/4/22 17:54 新增
            */
    public void personnelDuplicateRemoval(List<FdPersonnel> fdPersonnelList){
        if(!fdPersonnelList.isEmpty()&&fdPersonnelList.size()>0) {
            List<FdPersonnel> fdPersonnelListStart = new ArrayList<>();
            fdPersonnelListStart.addAll(fdPersonnelList);
            for (int s1 = 0; s1 < fdPersonnelListStart.size() - 1; s1++) {
                int i = 0;
                for (int s2 = 0; s2 < fdPersonnelList.size() - 1; s2++) {
                    //找到对应人员
                    if (fdPersonnelListStart.get(s1).getId().equals(fdPersonnelList.get(s2).getId())) {
                        if (i != 0) {//大于0则出现了多次
                            fdPersonnelList.remove(s2);
                        }
                        i++;
                    }
                }
            }
        }
    }
    /***
     * @Title:经理审核（修改状态、保存审核内容）
     * @Description:TODO
     * @param fdProjectQuotation
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/7/10 11:04
     * @updatehistory:
     *   2019/7/10 11:04 修改
     */
    @Override
    public void managerAudit(FdProjectQuotation fdProjectQuotation) {
        // String isBusinessExamine=fdProjectQuotation.getIsBusinessExamine();
        // String isDirectorExamine=fdProjectQuotation.getIsDirectorExamine();
        // String isGeneralExamine=fdProjectQuotation.getIsGeneralExamine();
        //修改经理审核状态
        // if(isBusinessExamine!=null&&!isBusinessExamine.equals("")
        //         ||isDirectorExamine!=null&&!isDirectorExamine.equals("")
        //         ||isGeneralExamine!=null&&!isGeneralExamine.equals("")){
        //     fdProjectQuotationService.updateById(fdProjectQuotation);
        // }

        // fdProjectQuotationService.updateById(fdProjectQuotation);
        //修改审核状态
        fdProjectQuotationMapper.updateExamineStatusByQuotationId(fdProjectQuotation);
        //批量删除审核描述
        if (fdProjectQuotation.getQuotationCommentsList() != null && !fdProjectQuotation.getQuotationCommentsList().isEmpty()) {
            String perId = "";//人员id
            String auditType = "";//审核类型
            for (FdProjectQuotationComments comme : fdProjectQuotation.getQuotationCommentsList()) {
                perId = comme.getPersonnelId();
                auditType = comme.getAuditType();
                break;
            }
            LambdaQueryWrapper<FdProjectQuotationComments> queryCommen = new LambdaQueryWrapper<>();
            queryCommen.eq(FdProjectQuotationComments::getQuotationId, fdProjectQuotation.getId());
            queryCommen.eq(FdProjectQuotationComments::getPersonnelId, perId);
            queryCommen.eq(FdProjectQuotationComments::getAuditType, auditType);
            fdProjectQuotationCommentsService.remove(queryCommen);
            //批量新增审核描述
            fdProjectQuotationCommentsService.saveBatch(fdProjectQuotation.getQuotationCommentsList());
        }

        //根据id查询报价对象
        FdProjectQuotation projectQuotation = fdProjectQuotationMapper.getQuotationById(fdProjectQuotation.getId());
        if (projectQuotation != null) {
            //临床
            String isClinicalSectionExamine = projectQuotation.getIsClinicalSectionExamine();
            String clinicalSectionMemo = projectQuotation.getClinicalSectionMemo();
            //中心
            String isCentralPriceExamine = projectQuotation.getIsCentralPriceExamine();
            String centralPriceMemo = projectQuotation.getCentralPriceMemo();
            //数据
            String isDataStatisticsExamine = projectQuotation.getIsDataStatisticsExamine();
            String dataStatisticsMemo = projectQuotation.getDataStatisticsMemo();
            //PK
            String isPkComputingExamine = projectQuotation.getIsPkComputingExamine();
            String pkComputingMemo = projectQuotation.getPkComputingMemo();
            //生物分析
            String isBioanalysisExamine = projectQuotation.getIsBioanalysisExamine();
            String bioanalysisMemo = projectQuotation.getBioanalysisMemo();
            //总经理
            String isGeneralExamine = projectQuotation.getIsGeneralExamine();
            String generalManagerMemo = projectQuotation.getGeneralManagerMemo();
            String status = "6";
            if (!StringUtils.isNotBlank(fdProjectQuotation.getGeneralManagerMemo())) {
                //总经理以上人员审核 填写意见没审核通过则报价状态为待修改
                if (StringUtils.isNotBlank(clinicalSectionMemo) && isClinicalSectionExamine.equals("0")) {
                    status = "7";
                } else if (StringUtils.isNotBlank(centralPriceMemo) && isCentralPriceExamine.equals("0")) {
                    status = "7";
                } else if (StringUtils.isNotBlank(dataStatisticsMemo) && isDataStatisticsExamine.equals("0")) {
                    status = "7";
                } else if (StringUtils.isNotBlank(pkComputingMemo) && isPkComputingExamine.equals("0")) {
                    status = "7";
                } else if (StringUtils.isNotBlank(bioanalysisMemo) && isBioanalysisExamine.equals("0")) {
                    status = "7";
                }
            } else {
                //总经理审核
                if (StringUtils.isNotBlank(generalManagerMemo) && isGeneralExamine.equals("0")) {
                    status = "7";
                } else {//审核通过
                    status = "1";
                }
            }
            //修改报价状态
            List<String> list=new ArrayList<>();
            list.add(fdProjectQuotation.getId());
            fdProjectQuotationMapper.updataStatusShared(list,status);
        } else {
            throw new RuntimeException("操作失败");
        }

    }

    /**
     * @return boolean
     * @Author tanj
     * @Description //TODO 判断是否有比列为100%
     * @Date 18:00 2019/8/7
     * @Param [id]
     **/
    @Override
    public boolean judge(String id) {
        FdContract contract = fdContractService.getById(id);
        QueryWrapper<FdContractProportion> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("contract_id", contract.getId());
        List<FdContractProportion> list = fdContractProportionService.list(queryWrapper);
        Integer totalProportion = 0;
        // Integer project = 0;
        for (FdContractProportion fdContractProportion : list) {
            if (fdContractProportion.getProportionItem().equals("生物分析") || fdContractProportion.getProportionItem().equals("临床项目")) {
                String proportion = StringUtils.substringBefore(fdContractProportion.getProportion(), "%");
                System.out.println(proportion + "合计比列");

                totalProportion = Double.valueOf(proportion).intValue();
            }
            // else {
            //     String proportion = StringUtils.substringBefore(fdContractProportion.getProportion(), "%");
            //     System.out.println(proportion + "临床项目比列");
            //     project = Integer.parseInt(proportion);
            // }
        }
        if (totalProportion == 100 || totalProportion == 0) {
            return true;
        } else {
            return false;
        }
    }


    /***
     * @Title:删除报价以及子表
     * @Description:TODO
     * @param fdProjectQuotation
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/11/1 13:16
     * @updatehistory:
     *   2019/11/1 13:16 新增
     */
    @Override
    public void deleteProjectQuotation(FdProjectQuotation fdProjectQuotation) {

        //修改主表状态
        fdProjectQuotation.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
        fdProjectQuotationMapper.updateById(fdProjectQuotation);
        //主表id
        String quotationId = fdProjectQuotation.getId();

        //删除研究类型明细
        fdProjectQuotationDetailMapper.updateDelFlagByQuotationId(quotationId);

        //删除审核意见
        fdProjectQuotationCommentsMapper.updateDelFlagByQuotationId(quotationId);

        //删除化合物
        fdProjectQuotationCompoundMapper.updateDelFlagByQuotationId(quotationId);

        //删除联系人
        fdProjectQuotationContactsMapper.updateDelFlagByQuotationId(quotationId);

        //删除费用单
        fdProjectQuotationFeeMapper.updateDelFlagByQuotationId(quotationId);

        //删除模板明细
        fdProjectQuotationTemplateItemMapper.updateDelFlagByQuotationId(quotationId);

        //删除模板
        fdProjectQuotationTemplateMapper.updateDelFlagByQuotationId(quotationId);

        //删除初始模板
        fdProjectQuotationTemplateAddMapper.updateDelFlagByQuotationId(quotationId);

        //删除附件
        fdProjectQuotationUploadMapper.updateDelFlagByQuotationId(quotationId);
    }

    @Override
    public int updataStatusShared(List<String> list, String status) {
        fdProjectQuotationMapper.updataStatusShared(list, status);
        return 0;
    }

    /***
     * @Title:修改审核状态以及修改分布的审核人状态
     * @Description:TODO
     * @param list, status]
     * @return int
     * @exception
     * @author 陈创
     * @date 2019/11/28 17:18
     * @updatehistory:
     *   2019/11/28 17:18 新增
     */
    @Override
    public int updateStatusAndPersonnelStatus(List<String> list, String status) {
        //修改审核状态
        fdProjectQuotationMapper.updataStatusShared(list, status);
        //获取修改报价对象
        FdProjectQuotation fdProjectQuotation = fdProjectQuotationService.getById(list.get(0));
        //修改分配的审核人状态
        fdProjectQuotationMapper.updatePersonnelStatus(list, fdProjectQuotation);
        return 0;
    }

    /***
     * @Title:
            * @Description:TODO 根据报价id查询相关信息
            * @param id
            * @return org.jeecg.modules.projectManagement.entity.FdProjectQuotation
            * @exception
            * @author 陈创
            * @date 2019/12/19 16:36
            * @updatehistory:
     *   2019/12/19 16:36 新增
            */
    @Override
    public FdProjectQuotation getQuotationById(String id) {
        return fdProjectQuotationMapper.getQuotationById(id);
    }

    /***
     * @Title:再次审核提醒
            * @Description:TODO 待修改状态的报价选择提出意见人员确定是否需要再次审核操作 以及更新报价信息
            * @param fdProjectQuotation
            * @return void
            * @exception
            * @author 陈创
            * @date 2019/12/20 15:13
            * @updatehistory:
     *   2019/12/20 15:13 新增
            */
    @Override
    public void reAuditSave(FdProjectQuotation fdProjectQuotation) {

        //修改不需要再审核的人员状态
        fdProjectQuotationMapper.updateExamineStatusByQuotationId(fdProjectQuotation);
        //是否存在需要通知审核部分的人员
        if(!fdProjectQuotation.getSysAnnouncementSendList().isEmpty()&&fdProjectQuotation.getSysAnnouncementSendList().size()>0){
            SysAnnouncement sysAnnouncement=new SysAnnouncement();
            sysAnnouncement.setTitile("审核提醒");
            sysAnnouncement.setMsgContent(fdProjectQuotation.getCode()+"已修改，请再次审核");
            sysAnnouncement.setSysAnnouncementSendList(fdProjectQuotation.getSysAnnouncementSendList());
            iSysAnnouncementService.addAll(sysAnnouncement);
        }else{//不需要再审核的则需要更新报价状态
            //根据报价id查询报价对象数据
            FdProjectQuotation projectQuotation= fdProjectQuotationMapper.getQuotationById(fdProjectQuotation.getId());
            String status="6";
            if(projectQuotation.getIsGeneralExamine().equals("1")){
                status="1";
            }
            //修改报价状态
            List<String> list=new ArrayList<>();
            list.add(fdProjectQuotation.getId());
            fdProjectQuotationMapper.updataStatusShared(list,status);
        }
    }

    @Override
    public boolean updateRelationCode(FdProjectQuotation fdProjectQuotation) {
        boolean result=true;
        String relationCode=fdProjectQuotation.getRelationCode();//关联报价号
        //查询需要修改关联号的报价对象
        FdProjectQuotation projectQuotationSelet=fdProjectQuotationMapper.selectById(fdProjectQuotation.getId());
        //修改
        projectQuotationSelet.setRelationCode(relationCode);//关联报价号
        projectQuotationSelet.setRelationStart(3);//关联状态
        fdProjectQuotationMapper.updateById(projectQuotationSelet);

        //查询关联的主报价
        LambdaQueryWrapper<FdProjectQuotation> fdProjectQuotationLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdProjectQuotationLambdaQueryWrapper.eq(FdProjectQuotation::getDelFlag,"0");
        fdProjectQuotationLambdaQueryWrapper.eq(FdProjectQuotation::getCode,relationCode);
        List<FdProjectQuotation> projectQuotationMainList =fdProjectQuotationService.list(fdProjectQuotationLambdaQueryWrapper);
        //主报价对象
        FdProjectQuotation fdProjectQuotationMain=new FdProjectQuotation();
        //是否查询到一个主报价
        if(!projectQuotationMainList.isEmpty()&&projectQuotationMainList.size()==1){
            fdProjectQuotationMain=projectQuotationMainList.get(0);
        }else{//没查询或者大于一个或者其他则修改失败
            result=false;
        }
        fdProjectQuotationMain.setRelationStart(2);//修改为主报价
        fdProjectQuotationMapper.updateById(fdProjectQuotationMain);
        return result;
    }

    @Override
    public List<String> getQuotationIdsByfileIds(List<String> list) {
        return fdProjectQuotationMapper.getQuotationIdsByfileIds(list);
    }

    @Override
    public void reviewedByMessage(FdProjectQuotation fdProjectQuotation) {
        List<SysAnnouncementSend> sysAnnouncementSendList=new ArrayList<>();
        //获取通知人
        //临床部分
        if(StringUtils.isNotBlank(fdProjectQuotation.getClinicalSectionId())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getClinicalSectionId(),fdProjectQuotation.getClinicalSectionName());
        }
        //中心价格
        if(StringUtils.isNotBlank(fdProjectQuotation.getCentralPriceId())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getCentralPriceId(),fdProjectQuotation.getCentralPriceName());
        }
        //数据统计
        if(StringUtils.isNotBlank(fdProjectQuotation.getDataStatisticsId())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getDataStatisticsId(),fdProjectQuotation.getDataStatisticsName());
        }
        //PK计算
        if(StringUtils.isNotBlank(fdProjectQuotation.getPkComputingId())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getPkComputingId(),fdProjectQuotation.getPkComputingMemo());
        }
        //生物分析
        if(StringUtils.isNotBlank(fdProjectQuotation.getBioanalysisId())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getBioanalysisId(),fdProjectQuotation.getBioanalysisName());
        }
        //总经理
        if(StringUtils.isNotBlank(fdProjectQuotation.getGeneralManager())){
            addSysAnnouncementSend(sysAnnouncementSendList,fdProjectQuotation.getGeneralManager(),fdProjectQuotation.getGeneralManagerName());
        }

        //获取消息相关信息
        SysAnnouncement sysAnnouncement=new SysAnnouncement();
        sysAnnouncement.setTitile("报价审核");
        sysAnnouncement.setMsgContent(fdProjectQuotation.getCode()+"待审核！");
        sysAnnouncement.setSysAnnouncementSendList(sysAnnouncementSendList);
        sysAnnouncementService.addAll(sysAnnouncement);
    }



    /***
     * @Title:
            * @Description:TODO 获取审核人对象
            * @param sysAnnouncementSendList, userId, userName]
            * @return void
            * @exception
            * @author 陈创
            * @date 2020/4/20 17:40
            * @updatehistory:
     *   2020/4/20 17:40 新增
            */
    public void addSysAnnouncementSend(List<SysAnnouncementSend> sysAnnouncementSendList,String userId,String userName){
        SysAnnouncementSend sysAnnouncementSend=new SysAnnouncementSend();
        sysAnnouncementSend.setUserId(userId);
        sysAnnouncementSend.setUserName(userName);
        sysAnnouncementSendList.add(sysAnnouncementSend);
    }


    @Override
    public IPage<FdProjectQuotation> getReportPage(Page<FdProjectQuotation> page, QueryWrapper<FdProjectQuotation> queryWrapper) {
        return fdProjectQuotationMapper.getReportPage(page,queryWrapper);
    }

    @Override
    public void updateSponsorName(FdProjectQuotation fdProjectQuotation) {
        fdProjectQuotationMapper.updateSponsorName(fdProjectQuotation);
    }
}



