package org.jeecg.modules.projectManagement.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.NotDuplicate;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.basedata.entity.*;;
import org.jeecg.modules.basedata.mapper.FdContractClassMapper;
import org.jeecg.modules.basedata.mapper.FdMatrixTypeMapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.basedata.service.IFdCustomerService;
import org.jeecg.modules.financeManage.service.IFdProjectReceivablesService;
import org.jeecg.modules.projectManagement.entity.*;
import org.jeecg.modules.projectManagement.service.*;
import org.jeecg.modules.sampleAndConsumableManagement.controller.FdColumnManagementController;
import org.jeecg.modules.system.service.ISysSerialPatternService;
import org.jeecg.modules.system.vo.CallResult;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;

import static org.jeecg.common.util.oConvertUtils.isEmpty;

/**
 * @Title: Controller
 * @Description: 生物分析样本里程碑
 * @author： jeecg-boot
 * @date： 2019-06-04
 * @version： V1.0
 */
@RestController
@RequestMapping("/projectManagement/fdBioanalysisSampleMilestones")
@Slf4j
public class FdBioanalysisSampleMilestonesController {
    @Autowired
    private IFdBioanalysisSampleMilestonesService fdBioanalysisSampleMilestonesService;

    @Resource
    private FdContractClassMapper fdContractClassMapper;

    @Resource
    private IFdBioanalysisSampleMilestonesItemsService fdBioanalysisSampleMilestonesItemsService;

    @Resource
    private IFdBioanalysisSampleMilestonesSampleReceivedService fdBioanalysisSampleMilestonesSampleReceivedService;

    @Resource
    private IFdBioanalysisSampleMilestonesCompletedNumberService fdBioanalysisSampleMilestonesCompletedNumberService;

    @Resource
    private IFdProjectFileMethodService fdProjectFileMethodService;

    @Resource
    private IFdProjectFileConfirmService fdProjectFileConfirmService;

    @Resource
    private IFdProjectFileValidationService fdProjectFileValidationService;

    @Resource
    private IFdProjectFileSampleService fdProjectFileSampleService;

    @Resource
    private FdMatrixTypeMapper fdMatrixTypeMapper;

    @Resource
    private IFdContractClauseService fdContractClauseService;

    @Resource
    private IFdContractDetailService fdContractDetailService;

    @Resource
    private IFdProjectFileService fdProjectFileService;

    @Resource
    private IFdBioanalysisSampleMilestonesMethodService fdBioanalysisSampleMilestonesMethodService;

    @Resource
    private IFdBioanalysisSampleMilestonesConfirmService fdBioanalysisSampleMilestonesConfirmService;

    @Resource
    private IFdBioanalysisSampleMilestonesValidationService fdBioanalysisSampleMilestonesValidationService;

    @Resource
    private IFdBioanalysisSampleMilestonesSampleService fdBioanalysisSampleMilestonesSampleService;

    @Resource
    private FdColumnManagementController fdColumnManagementController;


    @Resource
    private IFdProjectReceivablesService iFdProjectReceivablesService;

    @Resource
    ISysSerialPatternService iSysSerialPatternService;

    @Resource
    private IFdCustomerService iFdCustomerService;

    @Resource
    private IFdProjectFileCompoundService iFdProjectFileCompoundService;

    /**
     * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage   <   org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>>
     * @Author gurui
     * @Description //TODO 分页连接查询
     * @Date 17:33 2019/6/4
     * @Param [fdBioanalysisSampleMilestones, pageNo, pageSize, req]
     **/
    @GetMapping(value = "/list")
    @RequiresPermissions("url:bioanalysis:view")
    @PermissionData(pageComponent = "projectMilestones-bioanalysis")
    public Result<IPage<FdBioanalysisSampleMilestones>> queryPageList(FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones,
                                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                      HttpServletRequest req) {
        Result<IPage<FdBioanalysisSampleMilestones>> result = new Result<IPage<FdBioanalysisSampleMilestones>>();
        // 状态
//        if (StringUtils.isNotBlank(fdBioanalysisSampleMilestones.getStatus())) {
//            fdBioanalysisSampleMilestones.setStatus("%" + fdBioanalysisSampleMilestones.getStatus() + "%");
//        }
        String bidPartyName = fdBioanalysisSampleMilestones.getBidPartyName();
        if (StringUtils.isNotBlank(fdBioanalysisSampleMilestones.getBidPartyName())) {
            fdBioanalysisSampleMilestones.setBidPartyName(null);
        }
//        //合同号
//        if (StringUtils.isNotBlank(fdBioanalysisSampleMilestones.getContractCode())){
//            fdBioanalysisSampleMilestones.setContractCode("%" + fdBioanalysisSampleMilestones.getContractCode() + "%");
//        }
        String contractCode = fdBioanalysisSampleMilestones.getContractCode();
        if (StringUtils.isNotBlank(fdBioanalysisSampleMilestones.getContractCode())) {
            fdBioanalysisSampleMilestones.setContractCode(null);
        }
        QueryWrapper<FdBioanalysisSampleMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdBioanalysisSampleMilestones, req.getParameterMap());
        queryWrapper.eq("bsm.del_flag", "0");
        // queryWrapper.eq("cc.sort", "1");
        queryWrapper.orderByDesc("bsm.create_time");
        if (oConvertUtils.isNotEmpty(bidPartyName)) {
            queryWrapper.like(" cus.NAME", bidPartyName);
        }
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.like("con.code", contractCode);
        }
        Page<FdBioanalysisSampleMilestones> page = new Page<FdBioanalysisSampleMilestones>(pageNo, pageSize);
        IPage<FdBioanalysisSampleMilestones> pageList = fdBioanalysisSampleMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 添加
     *
     * @param fdBioanalysisSampleMilestones
     * @return
     */
    @PostMapping(value = "/add")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> add(@RequestBody @Valid FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones, BindingResult bindingResult) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        try {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            fdBioanalysisSampleMilestonesService.save(fdBioanalysisSampleMilestones);
            result.success("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败" + e.getMessage());
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param fdBioanalysisSampleMilestones
     * @return
     */
    @PutMapping(value = "/edit")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> edit(@RequestBody @Valid FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones, BindingResult bindingResult) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestonesEntity = fdBioanalysisSampleMilestonesService.getById(fdBioanalysisSampleMilestones.getId());
        if (fdBioanalysisSampleMilestonesEntity == null) {
            result.error500("未找到对应实体");
        } else {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            boolean ok = fdBioanalysisSampleMilestonesService.updateById(fdBioanalysisSampleMilestones);
            //TODO 返回false说明什么？
            if (ok) {
                result.success("修改成功!");
            }
        }

        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete")
    public Result<FdBioanalysisSampleMilestones> delete(@RequestParam(name = "id", required = true) String id) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones = fdBioanalysisSampleMilestonesService.getById(id);
        if (fdBioanalysisSampleMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            boolean ok = fdBioanalysisSampleMilestonesService.removeById(id);
            if (ok) {
                result.success("删除成功!");
            }
        }

        return result;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    public Result<FdBioanalysisSampleMilestones> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别！");
        } else {
            this.fdBioanalysisSampleMilestonesService.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public Result<FdBioanalysisSampleMilestones> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones = fdBioanalysisSampleMilestonesService.getById(id);
        if (fdBioanalysisSampleMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            //合同收款节点
            LambdaQueryWrapper<FdContractClause> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(FdContractClause::getContractId, fdBioanalysisSampleMilestones.getPkContract());
            queryWrapper.eq(FdContractClause::getDelFlag,"0");
            queryWrapper.orderByAsc(FdContractClause::getSort);
            List<FdContractClause> fdContractClauses = fdContractClauseService.list(queryWrapper);
            fdBioanalysisSampleMilestones.setFdContractClauseList(fdContractClauses);
            // 生物分析样本里程碑明细 生物分析样本里程碑当前完成数量 生物分析样本接收日期
            Map<String, Object> msp1 = Maps.newHashMap();
            msp1.put("del_flag", "0");
            msp1.put("pk_bioanalysis_sample_milestones", fdBioanalysisSampleMilestones.getId());
            List<FdBioanalysisSampleMilestonesItems> fdBioanalysisSampleMilestonesItems = (List<FdBioanalysisSampleMilestonesItems>) fdBioanalysisSampleMilestonesItemsService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesItemsList(fdBioanalysisSampleMilestonesItems);
            List<FdBioanalysisSampleMilestonesSampleReceived> fdBioanalysisSampleMilestonesSampleReceiveds = (List<FdBioanalysisSampleMilestonesSampleReceived>) fdBioanalysisSampleMilestonesSampleReceivedService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesSampleReceivedList(fdBioanalysisSampleMilestonesSampleReceiveds);
            List<FdBioanalysisSampleMilestonesCompletedNumber> fdBioanalysisSampleMilestonesCompletedNumbers = (List<FdBioanalysisSampleMilestonesCompletedNumber>) fdBioanalysisSampleMilestonesCompletedNumberService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesCompletedNumberList(fdBioanalysisSampleMilestonesCompletedNumbers);
            // 生物分析方法号 生物分析方法确认项目号 生物分析方法验证号 生物分析样本分析号
            List<FdBioanalysisSampleMilestonesMethod> fdProjectFileMethods = (List<FdBioanalysisSampleMilestonesMethod>) fdBioanalysisSampleMilestonesMethodService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesMethodList(fdProjectFileMethods);
            List<FdBioanalysisSampleMilestonesConfirm> fdProjectFileConfirms = (List<FdBioanalysisSampleMilestonesConfirm>) fdBioanalysisSampleMilestonesConfirmService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesConfirmList(fdProjectFileConfirms);
            List<FdBioanalysisSampleMilestonesValidation> fdProjectFileValidations = (List<FdBioanalysisSampleMilestonesValidation>) fdBioanalysisSampleMilestonesValidationService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesValidationList(fdProjectFileValidations);
            List<FdBioanalysisSampleMilestonesSample> fdProjectFileSamples = (List<FdBioanalysisSampleMilestonesSample>) fdBioanalysisSampleMilestonesSampleService.listByMap(msp1);
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesSampleList(fdProjectFileSamples);

            result.setResult(fdBioanalysisSampleMilestones);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
        // Step.1 组装查询条件
        QueryWrapper<FdBioanalysisSampleMilestones> queryWrapper = null;
        try {
            String paramsStr = request.getParameter("paramsStr");
            if (oConvertUtils.isNotEmpty(paramsStr)) {
                String deString = URLDecoder.decode(paramsStr, "UTF-8");
                FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones = JSON.parseObject(deString, FdBioanalysisSampleMilestones.class);
                queryWrapper = QueryGenerator.initQueryWrapper(fdBioanalysisSampleMilestones, request.getParameterMap());
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<FdBioanalysisSampleMilestones> pageList = fdBioanalysisSampleMilestonesService.list(queryWrapper);
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "生物分析样本里程碑列表");
        mv.addObject(NormalExcelConstants.CLASS, FdBioanalysisSampleMilestones.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("生物分析样本里程碑列表数据", "导出人:Jeecg", "导出信息"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<FdBioanalysisSampleMilestones> listFdBioanalysisSampleMilestoness = ExcelImportUtil.importExcel(file.getInputStream(), FdBioanalysisSampleMilestones.class, params);
                for (FdBioanalysisSampleMilestones fdBioanalysisSampleMilestonesExcel : listFdBioanalysisSampleMilestoness) {
                    fdBioanalysisSampleMilestonesService.save(fdBioanalysisSampleMilestonesExcel);
                }
                return Result.ok("文件导入成功！数据行数：" + listFdBioanalysisSampleMilestoness.size());
            } catch (Exception e) {
                log.error(e.getMessage());
                return Result.error("文件导入失败！");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.ok("文件导入失败！");
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO  添加生物分析样本里程碑同时添加 生物分析样本里程碑明细 生物分析样本里程碑当前完成数量 生物分析样本接收日期 项目档案 生物分析方法号 生物分析方法确认项目号 生物分析方法验证号 生物分析样本分析号
     * @Date 10:18 2019/6/5
     * @Param [fdBioanalysisSampleMilestones, bindingResult]
     **/
    @PostMapping(value = "/addAll")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> addAll(@RequestBody @Valid FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones, BindingResult bindingResult) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        try {
            //编码规则
            CallResult<String> resultSerial = iSysSerialPatternService.getNextSerial(fdBioanalysisSampleMilestones, "fd_bioanalysis_sample_milestones", "milestone_code", true);
            if(!resultSerial.isSucceed()){
                result.error500("获取编码失败");
                return result;
            }
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            //生物分析编码
            fdBioanalysisSampleMilestones.setMilestoneCode(resultSerial.getContent());
            fdBioanalysisSampleMilestonesService.addAll(fdBioanalysisSampleMilestones);
            result.success("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败" + e.getMessage());
        }
        return result;
    }


    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO 根据合同号查询相关数据
     * @Date 13:41 2019/6/28
     * @Param [id]
     **/
    @GetMapping(value = "/queryBioanalysisByConId")
    public Result<FdBioanalysisSampleMilestones> queryBioanalysisByConId(@RequestParam(name = "contractId", required = true) String projectFileId) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones = fdBioanalysisSampleMilestonesService.queryBioanalysisByConId(projectFileId);
        if (fdBioanalysisSampleMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            //合同类型
            if (oConvertUtils.isNotEmpty(fdBioanalysisSampleMilestones.getContractType())) {
                List<String> list = Arrays.asList(fdBioanalysisSampleMilestones.getContractType().split(","));
                List<FdContractClass> contractClasses = fdContractClassMapper.selectBatchIds(list);
                String contractType = "";
                for (FdContractClass fdContractClass : contractClasses) {
                    if (contractType.equals("")) {
                        contractType = fdContractClass.getName();
                    } else {
                        contractType += "," + fdContractClass.getName();
                    }
                }
                fdBioanalysisSampleMilestones.setContractType(contractType);
            }
            //基质类型
            if (oConvertUtils.isNotEmpty(fdBioanalysisSampleMilestones.getMatrixType())) {
                List<String> list1 = Arrays.asList(fdBioanalysisSampleMilestones.getMatrixType().split(","));
                List<FdMatrixType> matrixTypes = fdMatrixTypeMapper.selectBatchIds(list1);
                String matrixType = "";
                for (FdMatrixType fdMatrixType : matrixTypes) {
                    if (matrixType.equals("")) {
                        matrixType = fdMatrixType.getName();
                    } else {
                        matrixType += "," + fdMatrixType.getName();
                    }
                }
                fdBioanalysisSampleMilestones.setMatrixType(matrixType);
            }
            //根据合同id查询相关收款节点
            LambdaQueryWrapper<FdContractClause> contractClauseLambdaQueryWrapper = new LambdaQueryWrapper<>();
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getContractId, fdBioanalysisSampleMilestones.getPkContract());//合同id
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getDelFlag,"0");
            contractClauseLambdaQueryWrapper.orderByAsc(FdContractClause::getSort);
            List<FdContractClause> fdContractClauseList = fdContractClauseService.list(contractClauseLambdaQueryWrapper);
            fdBioanalysisSampleMilestones.setFdContractClauseList(fdContractClauseList);
            //合同样本数
            LambdaQueryWrapper<FdContractDetail> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(FdContractDetail::getContractId, fdBioanalysisSampleMilestones.getPkContract());
            queryWrapper.eq(FdContractDetail::getDelFlag,"0");
            List<FdContractDetail> list = fdContractDetailService.list(queryWrapper);
            Integer totalNumInteger=0;//获取样本总数
            for (FdContractDetail fdContractDetail : list) {
                if (oConvertUtils.isNotEmpty(fdContractDetail.getTotalNum())) {
                    String totalNum=fdContractDetail.getTotalNum();
                    //判断是否是数字
//                    Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
//                    boolean isInteger=pattern.matcher(totalNum).matches();
                    if(isNumber(totalNum)){
                        totalNumInteger+=Double.valueOf(totalNum).intValue();
                    }
                }
            }
            fdBioanalysisSampleMilestones.setSampleNumber(totalNumInteger);
            //获取树形对应化合物基质得比例和数量
            getProportionAndSamplesTotal(fdBioanalysisSampleMilestones,list);
            //合同方
            LambdaQueryWrapper<FdProjectFile> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.eq(FdProjectFile::getContractId, fdBioanalysisSampleMilestones.getPkContract());
            List<FdProjectFile> list1 = fdProjectFileService.list(queryWrapper1);
            for (FdProjectFile fdProjectFile : list1) {
                fdBioanalysisSampleMilestones.setPkContractParty(fdProjectFile.getContractParty());
            }
            String contractPartyName = fdColumnManagementController.getContractPartyName(fdBioanalysisSampleMilestones.getPkContractParty());
            fdBioanalysisSampleMilestones.setContractPartyName(contractPartyName);

            // 生物分析样本里程碑明细 生物分析样本里程碑当前完成数量 生物分析样本接收日期
            Map<String, Object> msp1 = Maps.newHashMap();
            msp1.put("del_flag", "0");
            msp1.put("project_id", fdBioanalysisSampleMilestones.getPkProjectFile());
            // List<FdBioanalysisSampleMilestonesItems> fdBioanalysisSampleMilestonesItems = (List<FdBioanalysisSampleMilestonesItems>) fdBioanalysisSampleMilestonesItemsService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesItemsList(fdBioanalysisSampleMilestonesItems);
            // List<FdBioanalysisSampleMilestonesSampleReceived> fdBioanalysisSampleMilestonesSampleReceiveds = (List<FdBioanalysisSampleMilestonesSampleReceived>) fdBioanalysisSampleMilestonesSampleReceivedService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesSampleReceivedList(fdBioanalysisSampleMilestonesSampleReceiveds);
            // List<FdBioanalysisSampleMilestonesCompletedNumber> fdBioanalysisSampleMilestonesCompletedNumbers = (List<FdBioanalysisSampleMilestonesCompletedNumber>) fdBioanalysisSampleMilestonesCompletedNumberService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesCompletedNumberList(fdBioanalysisSampleMilestonesCompletedNumbers);
            // 生物分析方法号 生物分析方法确认项目号 生物分析方法验证号 生物分析样本分析号
            // List<FdBioanalysisSampleMilestonesMethod> fdProjectFileMethods = (List<FdBioanalysisSampleMilestonesMethod>) fdBioanalysisSampleMilestonesMethodService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesMethodList(fdProjectFileMethods);
            // List<FdBioanalysisSampleMilestonesConfirm> fdProjectFileConfirms = (List<FdBioanalysisSampleMilestonesConfirm>) fdBioanalysisSampleMilestonesConfirmService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesConfirmList(fdProjectFileConfirms);
            // List<FdBioanalysisSampleMilestonesValidation> fdProjectFileValidations = (List<FdBioanalysisSampleMilestonesValidation>) fdBioanalysisSampleMilestonesValidationService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesValidationList(fdProjectFileValidations);
            // List<FdBioanalysisSampleMilestonesSample> fdProjectFileSamples = (List<FdBioanalysisSampleMilestonesSample>) fdBioanalysisSampleMilestonesSampleService.listByMap(msp1);
            // fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesSampleList(fdProjectFileSamples);

            // 生物分析方法号 生物分析方法确认项目号 生物分析方法验证号 生物分析样本分析号
            //生物分析方法号
            List<FdProjectFileMethod> fdProjectFileMethods = (List<FdProjectFileMethod>) fdProjectFileMethodService.listByMap(msp1);
            List<FdBioanalysisSampleMilestonesMethod> fdBioanalysisSampleMilestonesMethodList=new ArrayList<>();
            for(FdProjectFileMethod fdProjectFileMethod:fdProjectFileMethods){
                FdBioanalysisSampleMilestonesMethod fdBioanalysisSampleMilestonesMethod=new FdBioanalysisSampleMilestonesMethod();
                fdBioanalysisSampleMilestonesMethod.setCode(fdProjectFileMethod.getCode());
                fdBioanalysisSampleMilestonesMethod.setMemo(fdProjectFileMethod.getMemo());
                fdBioanalysisSampleMilestonesMethodList.add(fdBioanalysisSampleMilestonesMethod);
            }
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesMethodList(fdBioanalysisSampleMilestonesMethodList);

            //生物分析方法确认项目号
            List<FdProjectFileConfirm> fdProjectFileConfirms = (List<FdProjectFileConfirm>) fdProjectFileConfirmService.listByMap(msp1);
            List<FdBioanalysisSampleMilestonesConfirm> fdBioanalysisSampleMilestonesConfirmList=new ArrayList<>();
            for(FdProjectFileConfirm fdProjectFileConfirm:fdProjectFileConfirms){
                FdBioanalysisSampleMilestonesConfirm fdBioanalysisSampleMilestonesConfirm=new FdBioanalysisSampleMilestonesConfirm();
                fdBioanalysisSampleMilestonesConfirm.setCode(fdProjectFileConfirm.getCode());
                fdBioanalysisSampleMilestonesConfirm.setMemo(fdProjectFileConfirm.getMemo());
                fdBioanalysisSampleMilestonesConfirmList.add(fdBioanalysisSampleMilestonesConfirm);
            }
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesConfirmList(fdBioanalysisSampleMilestonesConfirmList);

            //生物分析方法验证号
            List<FdProjectFileValidation> fdProjectFileValidations = (List<FdProjectFileValidation>) fdProjectFileValidationService.listByMap(msp1);
            List<FdBioanalysisSampleMilestonesValidation> fdBioanalysisSampleMilestonesValidationList=new ArrayList<>();
            for(FdProjectFileValidation fdProjectFileValidation:fdProjectFileValidations){
                FdBioanalysisSampleMilestonesValidation fdBioanalysisSampleMilestonesValidation=new FdBioanalysisSampleMilestonesValidation();
                fdBioanalysisSampleMilestonesValidation.setCode(fdProjectFileValidation.getCode());
                fdBioanalysisSampleMilestonesValidation.setMemo(fdProjectFileValidation.getMemo());
                fdBioanalysisSampleMilestonesValidationList.add(fdBioanalysisSampleMilestonesValidation);
            }
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesValidationList(fdBioanalysisSampleMilestonesValidationList);

            //生物分析样本分析号
            List<FdProjectFileSample> fdProjectFileSamples = (List<FdProjectFileSample>) fdProjectFileSampleService.listByMap(msp1);
            List<FdBioanalysisSampleMilestonesSample> fdBioanalysisSampleMilestonesSampleList=new ArrayList<>();
            for(FdProjectFileSample fdProjectFileSample:fdProjectFileSamples){
                FdBioanalysisSampleMilestonesSample fdBioanalysisSampleMilestonesSample=new FdBioanalysisSampleMilestonesSample();
                fdBioanalysisSampleMilestonesSample.setCode(fdProjectFileSample.getCode());
                fdBioanalysisSampleMilestonesSample.setMemo(fdProjectFileSample.getMemo());
                fdBioanalysisSampleMilestonesSampleList.add(fdBioanalysisSampleMilestonesSample);
            }
            fdBioanalysisSampleMilestones.setFdBioanalysisSampleMilestonesSampleList(fdBioanalysisSampleMilestonesSampleList);

            result.setResult(fdBioanalysisSampleMilestones);
            result.setSuccess(true);
        }
        return result;
    }

    //获取比例和数量
    public void getProportionAndSamplesTotal(FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones,List<FdContractDetail> fdContractDetailList){

        List<FdBioanalysisTemplate> fdBioanalysisTemplateList=new ArrayList<>();

        //获取项目档案得化合物
        List<FdProjectFileCompound> fdProjectFileCompoundList=fdBioanalysisSampleMilestones.getFdProjectFileCompoundList();
        //判断化合物是否为空
        if(fdProjectFileCompoundList!=null&&fdProjectFileCompoundList.size()>0){
            /////获取化合物累计样本总数
            //循环化合物集合
            for(FdProjectFileCompound fdProjectFileCompound:fdProjectFileCompoundList){
                Double sampleTotal=0.00;
                //判断采样单是否有值
                if(fdContractDetailList!=null&&fdContractDetailList.size()>0){
                    //循环采样单
                    for(FdContractDetail detail:fdContractDetailList){
                        //找到对应化合物
                        if(StringUtils.isNotBlank(detail.getCompoundName())&&detail.getCompoundName().equals(fdProjectFileCompound.getCompound())){
                            if(isNumber(detail.getTotalNum())){//判断是否是数字
                                //获取累计样本总数
                                sampleTotal=(getDecimal(sampleTotal).add(getDecimal(Double.parseDouble(detail.getTotalNum())))).doubleValue();
                            }

                        }
                    }
                }
                //整理基质比例和数量
                //判断基质名称是否为空
                if(StringUtils.isNotBlank(fdBioanalysisSampleMilestones.getMatrixType())){
                    //获取基质数组
                    String[] matrixTypeNames=fdBioanalysisSampleMilestones.getMatrixType().split(",");
                    //判断是否为空
                    if(matrixTypeNames!=null&&matrixTypeNames.length>0){
                        if(matrixTypeNames.length==1){//如果只有一个基质
                            FdBioanalysisTemplate fdBioanalysisTemplate=new FdBioanalysisTemplate();
                            fdBioanalysisTemplate.setCompoundName(fdProjectFileCompound.getCompound());
                            fdBioanalysisTemplate.setMatrixName(matrixTypeNames[0]);
                            fdBioanalysisTemplate.setProportion("100");
                            fdBioanalysisTemplate.setSamplesTotal(sampleTotal.intValue()+"");
                            fdBioanalysisTemplateList.add(fdBioanalysisTemplate);
                        }else{//存在一个以上基质
                            //循环基质数组
                            for(String ma:matrixTypeNames){
                                Double matrixTotal=0.00;
                                //循环
                                for(FdContractDetail detail:fdContractDetailList){
                                    if(StringUtils.isNotBlank(detail.getCompoundName())&&detail.getCompoundName().equals(fdProjectFileCompound.getCompound())&&StringUtils.isNotBlank(detail.getMatrixTypeName())&&detail.getMatrixTypeName().equals(ma)){
                                        if(isNumber(detail.getTotalNum())){//判断是否为数字
                                            matrixTotal=(getDecimal(matrixTotal).add(getDecimal(Double.parseDouble(detail.getTotalNum())))).doubleValue();
                                        }
                                    }
                                }
                                //获取
                                FdBioanalysisTemplate fdBioanalysisTemplate=new FdBioanalysisTemplate();
                                fdBioanalysisTemplate.setCompoundName(fdProjectFileCompound.getCompound());
                                fdBioanalysisTemplate.setMatrixName(ma);
                                if(sampleTotal!=0.00){
                                    Double proportion=(getDecimal(matrixTotal).divide(getDecimal(sampleTotal),2, BigDecimal.ROUND_HALF_UP)).doubleValue();
                                    fdBioanalysisTemplate.setProportion(formatDouble5(proportion*100));
                                    fdBioanalysisTemplate.setSamplesTotal(matrixTotal.intValue()+"");
                                }
                                fdBioanalysisTemplateList.add(fdBioanalysisTemplate);
                            }
                        }
                    }
                }


            }
        }
        fdBioanalysisSampleMilestones.setFdBioanalysisTemplateList(fdBioanalysisTemplateList);

    }


    public BigDecimal getDecimal(Double d){
        BigDecimal decimal= new BigDecimal(d);
        return decimal;
    }


    public static String formatDouble5(double d) {
        return String.format("%.2f", d);
    }

    private boolean isNumber(String str){
        if(isEmpty(str)){
            return false;
        }
        String reg = "\\d+(\\.\\d+)?";
        return str.matches(reg);

    }
    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO 删除生物分析样本里程碑同时删除 生物分析样本里程碑明细 生物分析样本里程碑当前完成数量 生物分析样本接收日期 项目档案 生物分析方法号 生物分析方法确认项目号 生物分析方法验证号 生物分析样本分析号
     * @Date 14:50 2019/6/28
     * @Param [id]
     **/
    @DeleteMapping(value = "/deleteAll")
    public Result<FdBioanalysisSampleMilestones> deleteAll(@RequestParam(name = "id", required = true) String id) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones = fdBioanalysisSampleMilestonesService.getById(id);
        if (fdBioanalysisSampleMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            fdBioanalysisSampleMilestones.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
            boolean ok =fdBioanalysisSampleMilestonesService.updateById(fdBioanalysisSampleMilestones);
            // boolean ok = fdBioanalysisSampleMilestonesService.deleteAll(id);
            if (ok) {
                result.success("删除成功!");
            }
        }

        return result;
    }


    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO 根据id复制一条一样的数据
     * @Date 14:52 2019/6/28
     * @Param [id]
     **/
    @PostMapping(value = "/copy")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> copy(@RequestBody String id) {
        Result<FdBioanalysisSampleMilestones> result = new Result<>();
        try {
            fdBioanalysisSampleMilestonesService.copy(id);
            result.success("复制成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败" + e.getMessage());
        }
        return result;
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdContract>
     * @Author gurui
     * @Description //TODO 弃审核数据,使其状态为0
     * @Date 10:20 2019/6/28
     * @Param [ids]
     **/
    @GetMapping(value = "/auditBatch")
    public Result<FdBioanalysisSampleMilestones> auditBatch(@RequestParam(name = "ids", required = true) List<String> ids) {
        Result<FdBioanalysisSampleMilestones> result = new Result<>();
        String message = "";
        if (ids.isEmpty()) {
            message += "请选择数据</br>";
        }
        Map<String, Object> map = null;
        try {
            //执行service
            map = fdBioanalysisSampleMilestonesService.auditBatch(ids);
            result.setSuccess(true);
            result.setMessage(message + map.get("msg").toString());
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }
        return result;
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdContract>
     * @Author gurui
     * @Description //TODO 审核数据,使其状态为1
     * @Date 10:20 2019/6/28
     * @Param [ids]
     **/
    @GetMapping(value = "/reviewBatch")
    public Result<FdBioanalysisSampleMilestones> reviewBatch(@RequestParam(name = "ids", required = true) List<String> ids) {
        Result<FdBioanalysisSampleMilestones> result = new Result<>();
        String message = "";
        if (ids.isEmpty()) {
            message += "请选择数据</br>";
        }
        Map<String, Object> map = null;
        try {
            //执行service
            map = fdBioanalysisSampleMilestonesService.reviewBatch(ids);
            result.setSuccess(true);
            result.setMessage(message + map.get("msg").toString());
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }
        return result;
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO  详情保存
     * @Date 9:28 2019/7/11
     * @Param [fdBioanalysisSampleMilestones, bindingResult]
     **/
    @PostMapping(value = "/viewUpdateMilestonesItems")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> viewUpdateMilestonesItems(@RequestBody @Valid FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones, BindingResult bindingResult) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        try {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            boolean res=fdBioanalysisSampleMilestonesService.viewUpdateMilestonesItems(fdBioanalysisSampleMilestones);
            if(res==false){
                result.error500("操作失败");
            }
            result.success("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败" + e.getMessage());
        }
        return result;
    }

    /**
     * @return org.jeecg.common.api.vo.Result<java.util.List   <   org.jeecg.modules.projectManagement.entity.FdContract>>
     * @Author gurui
     * @Description //TODO 查询已审核项目档案的合同号
     * @Date 10:03 2019/7/11
     * @Param []
     **/
    @GetMapping(value = "/getFileContractList")
    public Result<List<FdContract>> getFileContractList() {
        Result<List<FdContract>> result = new Result<>();
        result.setResult(fdBioanalysisSampleMilestonesService.getFileContractList());
        result.setSuccess(true);
        return result;
    }


    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>
     * @Author gurui
     * @Description //TODO  修改
     * @Date 17:11 2019/7/11
     * @Param [fdBioanalysisSampleMilestones, bindingResult]
     **/
    @PutMapping(value = "/editAll")
    @NotDuplicate
    public Result<FdBioanalysisSampleMilestones> editAll(@RequestBody @Valid FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones, BindingResult bindingResult) {
        Result<FdBioanalysisSampleMilestones> result = new Result<FdBioanalysisSampleMilestones>();
        FdBioanalysisSampleMilestones fdBioanalysisSampleMilestonesEntity = fdBioanalysisSampleMilestonesService.getById(fdBioanalysisSampleMilestones.getId());
        if (fdBioanalysisSampleMilestonesEntity == null) {
            result.error500("未找到对应实体");
        } else {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            boolean ok = fdBioanalysisSampleMilestonesService.editAll(fdBioanalysisSampleMilestones);
            //TODO 返回false说明什么？
            if (ok) {
                result.success("修改成功!");
            }
        }
        return result;
    }


    /***
     * @Title:查询生物分析里程碑数量
            * @Description:TODO 根据合同id查询所对应的合同下面是否存在里程碑项目
            * @param contractId
            * @return org.jeecg.common.api.vo.Result
            * @exception
            * @author 陈创
            * @date 2019/9/9 12:10
            * @updatehistory:
     *   2019/9/9 12:10 新增
            */
    @GetMapping(value = "/getIsExistenceMilestones")
    public Result getIsExistenceMilestones(String contractId){
        Result result=new Result();
        try {
            LambdaQueryWrapper<FdBioanalysisSampleMilestones> fdBioanalysisSampleMilestonesLambdaQueryWrapper=new LambdaQueryWrapper<>();
            fdBioanalysisSampleMilestonesLambdaQueryWrapper.eq(FdBioanalysisSampleMilestones::getDelFlag,"0");
            fdBioanalysisSampleMilestonesLambdaQueryWrapper.eq(FdBioanalysisSampleMilestones::getPkContract,contractId);
            List<FdBioanalysisSampleMilestones> fdBioanalysisSampleMilestonesList=fdBioanalysisSampleMilestonesService.list(fdBioanalysisSampleMilestonesLambdaQueryWrapper);
            if(!fdBioanalysisSampleMilestonesList.isEmpty()&&fdBioanalysisSampleMilestonesList.size()>0){
                result.setResult(true);
            }else{
                result.setResult(false);
            }
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败"+e.getMessage());
        }
        return result;
    }

    /***
     * @Title:里程碑明细中即是关键点又是付款节点则通知项目管理经理与财务
            * @Description:TODO
            * @param fdBioanalysisSampleMilestones
            * @return org.jeecg.common.api.vo.Result
            * @exception 
            * @author 陈创
            * @date 2019/9/17 18:23
            * @updatehistory:
     *   2019/9/17 18:23 新增
            */
    @PostMapping(value = "/emailNoticePandF")
    public Result emailNoticePandF(@RequestBody FdBioanalysisSampleMilestones fdBioanalysisSampleMilestones){
        Result result=new Result();
        try {

            // //主表对象
            // FdClinicalProjectMilestones fdClinicalProjectMilestones=JSON.parseObject(JSON.toJSONString(list.get(0)),new TypeReference<FdClinicalProjectMilestones>(){});
            // //明细单个对象
            // FdClinicalProjectMilestonesItems fdClinicalProjectMilestonesItems=JSON.parseObject(JSON.toJSONString(list.get(1)),new TypeReference<FdClinicalProjectMilestonesItems>(){});
            //获取最新项目档案中的项目经理
            FdProjectFile fdProjectFile=fdProjectFileService.getById(fdBioanalysisSampleMilestones.getPkProjectFile());
            //查询收款条
            FdContractClause fdContractClause=fdContractClauseService.getById(fdBioanalysisSampleMilestones.getItemPkContractClause());
            //查询客户
            LambdaQueryWrapper<FdCustomer> lambdaQueryWrapper=new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(FdCustomer::getName,fdBioanalysisSampleMilestones.getBidPartyName());
            lambdaQueryWrapper.eq(FdCustomer::getDelFlag,"0");
            FdCustomer fdCustomer=iFdCustomerService.getOne(lambdaQueryWrapper);
            String descriptionName="";//付款描述
            String paymentPercent="";//收款百分比
            String money="";//金额
            String typeName="";//付款类别

            //获取付款节点信息
            if(fdContractClause!=null){
                descriptionName=fdContractClause.getDescriptionName();
                paymentPercent=fdContractClause.getPaymentPercent();
                money=fdContractClause.getMoney();
                typeName=fdContractClause.getTypeName();
            }
            String shortName="";//客户简称
            //获取客户信息
            if(fdCustomer!=null){
                shortName=fdCustomer.getShortName();
            }



//            String personnel=fdBioanalysisSampleMilestones.getProjectManagerId();
            String personnel=fdProjectFile.getProjectManagerId();
            String msg="合同号："+fdBioanalysisSampleMilestones.getContractCode()
                    +"\n项目名称："+fdBioanalysisSampleMilestones.getProjectName()
                    +"\n任务项："+fdBioanalysisSampleMilestones.getItemDescriptionName()
                    +"\n付款节点："+descriptionName
                    +"\n进度已完成";
            //通知项目经理
//            iFdProjectReceivablesService.noticeFinance(personnel,"生物分析里程碑任务项确认通知",msg);

            //财务通知
            //财务标题
            String titleFinance=fdBioanalysisSampleMilestones.getContractCode()
                                +"-"+shortName
                                +"-"+typeName+"￥"+money+"-收款通知！";
            //财务内容
            String msgFinance="合同号："+fdBioanalysisSampleMilestones.getContractCode()
                    +"\n合同方："+fdBioanalysisSampleMilestones.getContractPartyName()
                    +"\n收款类别："+typeName
                    +"\n条款描述："+descriptionName
                    +"\n收款百分比："+paymentPercent+"%"
                    +"\n金额：￥"+money;

//            iFdProjectReceivablesService.noticeFinance2("ar@frontagelab.com.cn",titleFinance,msgFinance);
//            iFdProjectReceivablesService.noticeFinance2("1479142272@qq.com",titleFinance,msgFinance);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败"+e.getMessage());
        }
        return result;
    }

    /***
     * @Title:生物分析进度变化报表
            * @Description:TODO
            * @param
            * @return org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/9/24 20:04
            * @updatehistory:
     *   2019/9/24 20:04 新增
            */
    @GetMapping(value = "/progressReport")
    @RequiresPermissions("url:biologicalAnalysisProgress:view")
    public Result<List<FdBioanalysisSampleMilestones>> progressReport(String startDate,String endDate){
        Result<List<FdBioanalysisSampleMilestones>> result=new Result<>();
        try {
            List<FdBioanalysisSampleMilestones> fdBioanalysisSampleMilestonesList=fdBioanalysisSampleMilestonesService.progressReport(startDate,endDate);
            result.setResult(fdBioanalysisSampleMilestonesList);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败："+e.getMessage());
        }
        return result;
    }

    /**
    * @Author chenchuang
    * @Description //TODO 里程碑导出全部主表信息
    * @Date 2020/8/4 16:25
    * @Param []
    * @return org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.projectManagement.entity.FdBioanalysisSampleMilestones>>
    */
    @GetMapping(value = "/getMainExport")
    public Result<List<FdBioanalysisSampleMilestones>> getMainExport(){
        Result<List<FdBioanalysisSampleMilestones>> result=new Result<>();
        try {
            List<FdBioanalysisSampleMilestones> fdBioanalysisSampleMilestonesList=fdBioanalysisSampleMilestonesService.getMainExport();
            result.setResult(fdBioanalysisSampleMilestonesList);
            result.success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败：");
        }
        return result;
    }

}
