package org.jeecg.modules.projectManagement.controller;

import java.util.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
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 org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
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 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.entity.FdContractClass;
import org.jeecg.modules.basedata.entity.FdCustomer;
import org.jeecg.modules.basedata.service.IFdContractClassService;
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;

/**
 * @Title: Controller
 * @Description: 临床项目里程碑
 * @author： jeecg-boot
 * @date： 2019-06-03
 * @version： V1.0
 */
@RestController
@RequestMapping("/projectManagement/fdClinicalProjectMilestones")
@Slf4j
public class FdClinicalProjectMilestonesController {
    @Autowired
    private IFdClinicalProjectMilestonesService fdClinicalProjectMilestonesService;

    @Resource
    private IFdContractService fdContractService;

    @Resource
    private IFdContractDetailService fdContractDetailService;

    @Resource
    private IFdProjectFileService fdProjectFileService;

    @Resource
    private IFdClinicalProjectMilestonesItemsService fdClinicalProjectMilestonesItemsService;

    @Resource
    private IFdContractClassService fdContractClassService;
    @Resource
    private IFdContractClauseService fdContractClauseService;
    // @Resource
    // private IFdContractClauseService fdContractClauseService;
    @Resource
    private IFdProjectFileMembersService fdProjectFileMembersService;

    @Resource
    private IFdBioanalysisTemplateService iFdBioanalysisTemplateService;

    @Resource
    private IFdBioanalysisSampleMilestonesItemsService iFdBioanalysisSampleMilestonesItemsService;

    @Resource
    ISysSerialPatternService iSysSerialPatternService;

    @Resource
    IFdProjectReceivablesService iFdProjectReceivablesService;
    @Resource
    private IFdCustomerService iFdCustomerService;

    @Resource
    private FdColumnManagementController fdColumnManagementController;

    /**
     * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage < org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
     * @Author gurui
     * @Description //TODO 分页列表查询
     * @Date 13:34 2019/6/4
     * @Param [fdClinicalProjectMilestones, pageNo, pageSize, req]
     **/
    @GetMapping(value = "/list")
    @RequiresPermissions("url:pre-experiment:view")
    @PermissionData(pageComponent="projectMilestones/pre-experiment")
    public Result<IPage<FdClinicalProjectMilestones>> queryPageList(FdClinicalProjectMilestones fdClinicalProjectMilestones,
                                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                    HttpServletRequest req) {
        Result<IPage<FdClinicalProjectMilestones>> result = new Result<IPage<FdClinicalProjectMilestones>>();

        String contractCode = fdClinicalProjectMilestones.getContractCode();
        String clinicalCode = fdClinicalProjectMilestones.getClinicalCode();
        //合同号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getContractCode())) {
            fdClinicalProjectMilestones.setContractCode(null);
        }
        //临床方案号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getClinicalCode())) {
            fdClinicalProjectMilestones.setClinicalCode(null);
        }
        QueryWrapper<FdClinicalProjectMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdClinicalProjectMilestones, req.getParameterMap());
        // queryWrapper.lambda().eq(FdClinicalProjectMilestones::getDelFlag,"0");
        //queryWrapper.lambda().orderByDesc(FdClinicalProjectMilestones::getCreateTime);
        // queryWrapper.orderByDesc("create_time");
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.like("cpm.contract_code", contractCode);
        }
        //临床方案号
        if (StringUtils.isNotBlank(clinicalCode)) {
            queryWrapper.like("cpm.clinical_code", clinicalCode);
        }
        queryWrapper.eq("cpm.del_flag", "0");
        // queryWrapper.eq("cc.sort","1");

        queryWrapper.orderByDesc("cpm.create_time");
        Page<FdClinicalProjectMilestones> page = new Page<FdClinicalProjectMilestones>(pageNo, pageSize);
        IPage<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /***
     * @Title:餐后
            * @Description:TODO
            * @param fdClinicalProjectMilestones, pageNo, pageSize, req]
            * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/7/2 15:36
            * @updatehistory:
     *   2019/7/2 15:36 新增
            */
    @GetMapping(value = "/list2")
    @RequiresPermissions("url:postprandial:view")
    @PermissionData(pageComponent = "projectMilestones/postprandial")
    public Result<IPage<FdClinicalProjectMilestones>> queryPageList2(FdClinicalProjectMilestones fdClinicalProjectMilestones,
                                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                    HttpServletRequest req) {
        Result<IPage<FdClinicalProjectMilestones>> result = new Result<IPage<FdClinicalProjectMilestones>>();
        String contractCode = fdClinicalProjectMilestones.getContractCode();
        String clinicalCode = fdClinicalProjectMilestones.getClinicalCode();
        //合同号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getContractCode())) {
            fdClinicalProjectMilestones.setContractCode(null);
        }
        //临床方案号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getClinicalCode())) {
            fdClinicalProjectMilestones.setClinicalCode(null);
        }
        QueryWrapper<FdClinicalProjectMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdClinicalProjectMilestones, req.getParameterMap());
        // queryWrapper.lambda().eq(FdClinicalProjectMilestones::getDelFlag,"0");
        //queryWrapper.lambda().orderByDesc(FdClinicalProjectMilestones::getCreateTime);
        // queryWrapper.orderByDesc("create_time");
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.eq("cpm.contract_code", contractCode);
        }
        //临床方案号
        if (StringUtils.isNotBlank(clinicalCode)) {
            queryWrapper.eq("cpm.clinical_code", clinicalCode);
        }
        queryWrapper.eq("cpm.del_flag", "0");
        // queryWrapper.eq("cc.sort","1");

        queryWrapper.orderByDesc("cpm.create_time");
        Page<FdClinicalProjectMilestones> page = new Page<FdClinicalProjectMilestones>(pageNo, pageSize);
        IPage<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /***
     * @Title:空腹
            * @Description:TODO
            * @param fdClinicalProjectMilestones, pageNo, pageSize, req]
            * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/7/2 15:37
            * @updatehistory:
     *   2019/7/2 15:37 新增
            */
    @GetMapping(value = "/list3")
    @RequiresPermissions("url:empty-stomach:view")
    @PermissionData(pageComponent = "projectMilestones/empty-stomach")
    public Result<IPage<FdClinicalProjectMilestones>> queryPageList3(FdClinicalProjectMilestones fdClinicalProjectMilestones,
                                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                     HttpServletRequest req) {
        Result<IPage<FdClinicalProjectMilestones>> result = new Result<IPage<FdClinicalProjectMilestones>>();
        String contractCode = fdClinicalProjectMilestones.getContractCode();
        String clinicalCode = fdClinicalProjectMilestones.getClinicalCode();
        //合同号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getContractCode())) {
            fdClinicalProjectMilestones.setContractCode(null);
        }
        //临床方案号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getClinicalCode())) {
            fdClinicalProjectMilestones.setClinicalCode(null);
        }
        QueryWrapper<FdClinicalProjectMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdClinicalProjectMilestones, req.getParameterMap());
        // queryWrapper.lambda().eq(FdClinicalProjectMilestones::getDelFlag,"0");
        //queryWrapper.lambda().orderByDesc(FdClinicalProjectMilestones::getCreateTime);
        // queryWrapper.orderByDesc("create_time");
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.eq("cpm.contract_code", contractCode);
        }
        //临床方案号
        if (StringUtils.isNotBlank(clinicalCode)) {
            queryWrapper.eq("cpm.clinical_code", clinicalCode);
        }
        queryWrapper.eq("cpm.del_flag", "0");
        // queryWrapper.eq("cc.sort","1");

        queryWrapper.orderByDesc("cpm.create_time");
        // queryWrapper.eq("cc.sort","1");
        Page<FdClinicalProjectMilestones> page = new Page<FdClinicalProjectMilestones>(pageNo, pageSize);
        IPage<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /***
     * @Title:空腹餐后
            * @Description:TODO
            * @param fdClinicalProjectMilestones, pageNo, pageSize, req]
            * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/7/2 16:17
            * @updatehistory:
     *   2019/7/2 16:17 新增
            */
    @GetMapping(value = "/list4")
    @RequiresPermissions("url:empty-stomach-postprandial:view")
    @PermissionData(pageComponent = "projectMilestones/empty-stomach-postprandial")
    public Result<IPage<FdClinicalProjectMilestones>> queryPageList4(FdClinicalProjectMilestones fdClinicalProjectMilestones,
                                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                     HttpServletRequest req) {
        Result<IPage<FdClinicalProjectMilestones>> result = new Result<IPage<FdClinicalProjectMilestones>>();
        String contractCode = fdClinicalProjectMilestones.getContractCode();
        String clinicalCode = fdClinicalProjectMilestones.getClinicalCode();
        //合同号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getContractCode())) {
            fdClinicalProjectMilestones.setContractCode(null);
        }
        //临床方案号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getClinicalCode())) {
            fdClinicalProjectMilestones.setClinicalCode(null);
        }
        QueryWrapper<FdClinicalProjectMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdClinicalProjectMilestones, req.getParameterMap());
        // queryWrapper.lambda().eq(FdClinicalProjectMilestones::getDelFlag,"0");
        //queryWrapper.lambda().orderByDesc(FdClinicalProjectMilestones::getCreateTime);
        // queryWrapper.orderByDesc("create_time");
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.eq("cpm.contract_code", contractCode);
        }
        //临床方案号
        if (StringUtils.isNotBlank(clinicalCode)) {
            queryWrapper.eq("cpm.clinical_code", clinicalCode);
        }
        queryWrapper.eq("cpm.del_flag", "0");
        // queryWrapper.eq("cc.sort","1");

        queryWrapper.orderByDesc("cpm.create_time");
        Page<FdClinicalProjectMilestones> page = new Page<FdClinicalProjectMilestones>(pageNo, pageSize);
        IPage<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /***
     * @Title:内部
            * @Description:TODO
            * @param fdClinicalProjectMilestones, pageNo, pageSize, req]
            * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/7/2 16:17
            * @updatehistory:
     *   2019/7/2 16:17 新增
            */
    @GetMapping(value = "/list5")
    @RequiresPermissions("url:internal:view")
    @PermissionData(pageComponent = "projectMilestones/internal")
    public Result<IPage<FdClinicalProjectMilestones>> queryPageList5(FdClinicalProjectMilestones fdClinicalProjectMilestones,
                                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                     HttpServletRequest req) {
        Result<IPage<FdClinicalProjectMilestones>> result = new Result<IPage<FdClinicalProjectMilestones>>();
        String contractCode = fdClinicalProjectMilestones.getContractCode();
        String clinicalCode = fdClinicalProjectMilestones.getClinicalCode();
        //合同号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getContractCode())) {
            fdClinicalProjectMilestones.setContractCode(null);
        }
        //临床方案号
        if (StringUtils.isNotBlank(fdClinicalProjectMilestones.getClinicalCode())) {
            fdClinicalProjectMilestones.setClinicalCode(null);
        }
        QueryWrapper<FdClinicalProjectMilestones> queryWrapper = QueryGenerator.initQueryWrapper(fdClinicalProjectMilestones, req.getParameterMap());
        // queryWrapper.lambda().eq(FdClinicalProjectMilestones::getDelFlag,"0");
        //queryWrapper.lambda().orderByDesc(FdClinicalProjectMilestones::getCreateTime);
        // queryWrapper.orderByDesc("create_time");
        //合同号
        if (StringUtils.isNotBlank(contractCode)) {
            queryWrapper.eq("cpm.contract_code", contractCode);
        }
        //临床方案号
        if (StringUtils.isNotBlank(clinicalCode)) {
            queryWrapper.eq("cpm.clinical_code", clinicalCode);
        }
        queryWrapper.eq("cpm.del_flag", "0");
        // queryWrapper.eq("cc.sort","1");

        queryWrapper.orderByDesc("cpm.create_time");
        Page<FdClinicalProjectMilestones> page = new Page<FdClinicalProjectMilestones>(pageNo, pageSize);
        IPage<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.findByPage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }
    

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

    /**
     * 编辑
     *
     * @param fdClinicalProjectMilestones
     * @return
     */
    @PutMapping(value = "/edit")
    @NotDuplicate
    public Result<FdClinicalProjectMilestones> edit(@RequestBody @Valid FdClinicalProjectMilestones fdClinicalProjectMilestones, BindingResult bindingResult) {
        Result<FdClinicalProjectMilestones> result = new Result<FdClinicalProjectMilestones>();
        FdClinicalProjectMilestones fdClinicalProjectMilestonesEntity = fdClinicalProjectMilestonesService.getById(fdClinicalProjectMilestones.getId());
        if (fdClinicalProjectMilestonesEntity == 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;
            }

            //查询项目档案的成员
            LambdaQueryWrapper<FdProjectFileMembers> projectFileMembersLambdaQueryWrapper=new LambdaQueryWrapper<>();
            projectFileMembersLambdaQueryWrapper.eq(FdProjectFileMembers::getProjectId,fdClinicalProjectMilestones.getPkProjectFile());
            List<FdProjectFileMembers> projectFileMembersList=fdProjectFileMembersService.list(projectFileMembersLambdaQueryWrapper);
            //获取成员id
            int i=0;
            String personnelIds="";
            for(FdProjectFileMembers fdProjectFileMembers:projectFileMembersList){
                if(i==0){
                    personnelIds=fdProjectFileMembers.getPersonnelName();
                }else{
                    personnelIds=personnelIds+","+fdProjectFileMembers.getPersonnelName();
                }
                i++;
            }
            fdClinicalProjectMilestones.setPersonnelIds(personnelIds);
            boolean ok = fdClinicalProjectMilestonesService.updateById(fdClinicalProjectMilestones);
            //TODO 返回false说明什么？
            if (ok) {
                result.success("修改成功!");
            }
        }

        return result;
    }

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

        return result;
    }

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

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>
     * @Author gurui
     * @Description //TODO 通过id查询 同时查询默认
     * @Date 10:14 2019/6/4
     * @Param [id]
     **/
    @GetMapping(value = "/queryById")
    public Result<FdClinicalProjectMilestones> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<FdClinicalProjectMilestones> result = new Result<FdClinicalProjectMilestones>();
        FdClinicalProjectMilestones fdClinicalProjectMilestones = fdClinicalProjectMilestonesService.getById(id);
        if (fdClinicalProjectMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            //合同号
            FdContract contract=fdContractService.getById(fdClinicalProjectMilestones.getPkContract());
            fdClinicalProjectMilestones.setContractCode(contract.getCode());

            //临床PMId
            FdProjectFile fdProjectFile=fdProjectFileService.getById(fdClinicalProjectMilestones.getPkProjectFile());
            fdClinicalProjectMilestones.setClinicalIdPM(fdProjectFile.getClinicalPm());

            //合同收款节点
            LambdaQueryWrapper<FdContractClause> contractClauseLambdaQueryWrapper=new LambdaQueryWrapper<>();
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getDelFlag,"0");
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getContractId,fdClinicalProjectMilestones.getPkContract());
            contractClauseLambdaQueryWrapper.orderByAsc(FdContractClause::getSort);
            //根据合同id查出的收款节点集合
            List<FdContractClause> contractClauseList=fdContractClauseService.list(contractClauseLambdaQueryWrapper);
            fdClinicalProjectMilestones.setContractClauseList(contractClauseList);

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

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

        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<FdClinicalProjectMilestones> pageList = fdClinicalProjectMilestonesService.list(queryWrapper);
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "临床项目里程碑列表");
        mv.addObject(NormalExcelConstants.CLASS, FdClinicalProjectMilestones.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<FdClinicalProjectMilestones> listFdClinicalProjectMilestoness = ExcelImportUtil.importExcel(file.getInputStream(), FdClinicalProjectMilestones.class, params);
                for (FdClinicalProjectMilestones fdClinicalProjectMilestonesExcel : listFdClinicalProjectMilestoness) {
                    fdClinicalProjectMilestonesService.save(fdClinicalProjectMilestonesExcel);
                }
                return Result.ok("文件导入成功！数据行数：" + listFdClinicalProjectMilestoness.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.FdClinicalProjectMilestones>
     * @Author gurui
     * @Description //TODO 添加项目里程碑 同时添加 项目里程碑明细 项目档案 合同档案
     * @Date 17:55 2019/6/3
     * @Param [fdClinicalProjectMilestones]
     **/
    @PostMapping(value = "/addAll")
    @NotDuplicate
    //临床的里程碑新增修改权限控制（预实验、空腹、餐后、空腹与餐后、内部）
    @RequiresPermissions(value = {"pre-experiment:add","pre-experiment:update","pm-milestones:add","pm-milestones:update","empty-stomach:add","empty-stomach:update","empty-stomach-postprandial:add","empty-stomach-postprandial:update","internal:add","internal:update"},logical = Logical.OR)
    public Result<FdClinicalProjectMilestones> addAll(@RequestBody @Valid FdClinicalProjectMilestones fdClinicalProjectMilestones, BindingResult bindingResult) {
        Result<FdClinicalProjectMilestones> result = new Result<FdClinicalProjectMilestones>();
        try {
            CallResult<String> resultSerial = iSysSerialPatternService.getNextSerial(fdClinicalProjectMilestones, "fd_clinical_project_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;
            }
            //临床里程碑编码
            fdClinicalProjectMilestones.setMilestoneCode(resultSerial.getContent());
            fdClinicalProjectMilestonesService.addAll(fdClinicalProjectMilestones);
            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.FdClinicalProjectMilestones>>
     * @Author gurui
     * @Description //TODO  根据临床里程碑id查询里程碑模板类型
     * @Date 11:29 2019/6/19
     * @Param [id]
     **/
    @GetMapping(value = "getByMilestonesId")
    public Result<List<FdClinicalProjectMilestones>> getByMilestonesId(@RequestParam("id") String id) {
        Result<List<FdClinicalProjectMilestones>> result = new Result<>();
        result.setResult(fdClinicalProjectMilestonesService.getByMilestonesId(id));
        return result;
    }

    /***
     * @Title:查询里程碑模板项末端数据集合
     * @Description:TODO
     * @param templateId
     * @return org.jeecg.common.api.vo.Result<java.util.List < org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestonesItemsTree>>
     * @exception
     * @author 陈创
     * @date 2019/6/21 18:22
     * @updatehistory:
     *   2019/6/21 18:22 新增
     */
    @GetMapping(value = "endTreeList")
    public Result<List<FdClinicalProjectMilestonesItemsTree>> endTreeList(String templateId) {
        Result<List<FdClinicalProjectMilestonesItemsTree>> result = new Result<>();
        try {
            LambdaQueryWrapper<FdClinicalProjectMilestonesItems> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(FdClinicalProjectMilestonesItems::getPkClinicalProjectMilestones, templateId);
            // lambdaQueryWrapper.orderBy(true, true, FdClinicalProjectMilestonesItems::getCode);
            lambdaQueryWrapper.orderByAsc(FdClinicalProjectMilestonesItems::getCode);
            List<FdClinicalProjectMilestonesItems> list = fdClinicalProjectMilestonesItemsService.list(lambdaQueryWrapper);
            List<FdClinicalProjectMilestonesItemsTree> treeLists = new ArrayList<>();
            getTreeList(treeLists, list, null);
            findLeaf(treeLists);
            List<FdClinicalProjectMilestonesItemsTree> fdClinicalProjectMilestonesItemsTreeList = new ArrayList<>();
            //临床查询末级
            getEndTreeList(fdClinicalProjectMilestonesItemsTreeList, treeLists);
            //临床没有则去生物分析查询末级
            if(fdClinicalProjectMilestonesItemsTreeList.size()<=0){
                getBioEndTreeList(fdClinicalProjectMilestonesItemsTreeList,templateId);
            }

            result.setResult(fdClinicalProjectMilestonesItemsTreeList);
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        return result;
    }

    /***
     * @Title:查询末端tree数据递归方法
     * @Description:TODO
     * @param listEnd, treeList]
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/6/21 18:20
     * @updatehistory:
     *   2019/6/21 18:20 新增
     */
    public void getEndTreeList(List<FdClinicalProjectMilestonesItemsTree> listEnd, List<FdClinicalProjectMilestonesItemsTree> treeList) {
        // int i = 0;
        // for (FdClinicalProjectMilestonesItemsTree tree : treeList) {
        //     if (i < treeList.size() - 1) {
        //         //除集合最后一条数据中有child则继续递归
        //         if (tree.getChildren() != null && !tree.getChildren().isEmpty()) {
        //             getEndTreeList(listEnd, tree.getChildren());
        //         } else {
        //             //最顶级且没子集数据则添加为末端
        //             if (oConvertUtils.isEmpty(tree.getParentId())) {
        //                 listEnd.add(tree);
        //             }
        //         }
        //     } else {
        //         //集合最后一天数据中没有child则添加为末端
        //         if (tree.getChildren() == null || tree.getChildren().isEmpty()) {
        //             listEnd.add(tree);
        //         } else {
        //             getEndTreeList(listEnd, tree.getChildren());
        //         }
        //     }
        //     // }
        //     i++;
        // }
        for(FdClinicalProjectMilestonesItemsTree tree : treeList){
            if(tree.getChildren()==null||tree.getChildren().isEmpty()){
                listEnd.add(tree);
            }else{
                getEndTreeList(listEnd, tree.getChildren());
            }
        }
    }


    public void getBioEndTreeList(List<FdClinicalProjectMilestonesItemsTree> listEnd,String milId){
        //查询基质类型的生物分析模板
        LambdaQueryWrapper<FdBioanalysisTemplate> fdBioanalysisTemplateLambdaQueryWrapper =new LambdaQueryWrapper<>();
        fdBioanalysisTemplateLambdaQueryWrapper.eq(FdBioanalysisTemplate::getLevelType,"3");
        fdBioanalysisTemplateLambdaQueryWrapper.eq(FdBioanalysisTemplate::getProjectId,milId);
        List<FdBioanalysisTemplate> fdBioanalysisTemplateList=iFdBioanalysisTemplateService.list(fdBioanalysisTemplateLambdaQueryWrapper);
        if(!fdBioanalysisTemplateList.isEmpty()&&fdBioanalysisTemplateList.size()>0){
            String templateId=fdBioanalysisTemplateList.get(0).getId();
            //根据模板id查询生物分析的模板项
            LambdaQueryWrapper<FdBioanalysisSampleMilestonesItems> fdBioanalysisSampleMilestonesItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
            fdBioanalysisSampleMilestonesItemsLambdaQueryWrapper.eq(FdBioanalysisSampleMilestonesItems::getTemplateId,templateId);
            fdBioanalysisSampleMilestonesItemsLambdaQueryWrapper.orderByAsc(FdBioanalysisSampleMilestonesItems::getCode);
            List<FdBioanalysisSampleMilestonesItems> list = iFdBioanalysisSampleMilestonesItemsService.list(fdBioanalysisSampleMilestonesItemsLambdaQueryWrapper);
            //获取末级项
            for(FdBioanalysisSampleMilestonesItems fdBioanalysisSampleMilestonesItems:list){
                String id=fdBioanalysisSampleMilestonesItems.getId();
                boolean isEnd=true;
                //循环是否有子集
                for(FdBioanalysisSampleMilestonesItems fdBioanalysisSampleMilestonesItems1:list){
                    if(id.equals(fdBioanalysisSampleMilestonesItems1.getParentId())){
                        isEnd=false;
                    }
                }
                //没有则是末级
                if(isEnd){
                    FdClinicalProjectMilestonesItemsTree fdClinicalProjectMilestonesItemsTree=new FdClinicalProjectMilestonesItemsTree();
                    fdClinicalProjectMilestonesItemsTree.setId(fdBioanalysisSampleMilestonesItems.getId());
                    fdClinicalProjectMilestonesItemsTree.setDescription(fdBioanalysisSampleMilestonesItems.getDescription());
                    listEnd.add(fdClinicalProjectMilestonesItemsTree);
                }
            }
        }
    }

    /**
     * @return org.jeecg.common.api.vo.Result<java.util.List < org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestonesItemsTree>>
     * @Author gurui
     * @Description //TODO 父子集查询
     * @Date 15:56 2019/6/19
     * @Param [parent]
     **/
    @GetMapping(value = "/queryTreeList")
    public Result<List<FdClinicalProjectMilestonesItemsTree>> queryTreeList(String templateId) {
        Result<List<FdClinicalProjectMilestonesItemsTree>> result = new Result<>();
        try {
            LambdaQueryWrapper<FdClinicalProjectMilestonesItems> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(FdClinicalProjectMilestonesItems::getPkClinicalProjectMilestones, templateId);
            // lambdaQueryWrapper.orderBy(true, true, FdClinicalProjectMilestonesItems::getCode);
            lambdaQueryWrapper.orderByAsc(FdClinicalProjectMilestonesItems::getCode);
            List<FdClinicalProjectMilestonesItems> list = fdClinicalProjectMilestonesItemsService.list(lambdaQueryWrapper);
            List<FdClinicalProjectMilestonesItemsTree> treeLists = new ArrayList<>();
            getTreeList(treeLists, list, null);
            findLeaf(treeLists);
            result.setResult(treeLists);
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        return result;
    }

    private void getTreeList(List<FdClinicalProjectMilestonesItemsTree> treeList, List<FdClinicalProjectMilestonesItems> fdlist, FdClinicalProjectMilestonesItemsTree temp) {
        for (FdClinicalProjectMilestonesItems fdClinicalProjectMilestonesItems : fdlist) {
            String tempPid = fdClinicalProjectMilestonesItems.getParentId();
            FdClinicalProjectMilestonesItemsTree tree = new FdClinicalProjectMilestonesItemsTree(fdClinicalProjectMilestonesItems);
            if (temp == null && oConvertUtils.isEmpty(tempPid)) {
                treeList.add(tree);
                if (!tree.getIsLeaf()) {
                    getTreeList(treeList, fdlist, tree);
                }
            } else if (temp != null && tempPid != null && tempPid.equals(temp.getId())) {
                temp.getChildren().add(tree);
                if (!tree.getIsLeaf()) {
                    getTreeList(treeList, fdlist, tree);
                }
            }

        }
    }

    private void findLeaf(List<FdClinicalProjectMilestonesItemsTree> treeList) {
        for (FdClinicalProjectMilestonesItemsTree fdClinicalProjectMilestonesItemsTree : treeList) {
            //用于树形的swith
            //是否里程碑
            if (fdClinicalProjectMilestonesItemsTree.getIsPayMilestones().equals("1")) {
                fdClinicalProjectMilestonesItemsTree.setPayMilestonesBoo(true);
            } else {
                fdClinicalProjectMilestonesItemsTree.setPayMilestonesBoo(false);
            }
            //是否上传文档
            if (fdClinicalProjectMilestonesItemsTree.getIsUploadFile().equals("1")) {
                fdClinicalProjectMilestonesItemsTree.setUploadFileBoo(true);
            } else {
                fdClinicalProjectMilestonesItemsTree.setUploadFileBoo(false);
            }

            if (fdClinicalProjectMilestonesItemsTree.getChildren().isEmpty()) {
                fdClinicalProjectMilestonesItemsTree.setIsLeaf(true);
                fdClinicalProjectMilestonesItemsTree.setChildren(null);
            } else {
                findLeaf(fdClinicalProjectMilestonesItemsTree.getChildren());
            }
        }
    }

    /***
     * @Title:根据合同id查询相关信息
     * @Description:TODO
     * @param projectFileId
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdContract>
     * @exception
     * @author 陈创
     * @date 2019/6/19 18:00
     * @updatehistory:
     *   2019/6/19 18:00 查询
     */
    @GetMapping(value = "/getClinicalByConId")
    public Result<FdClinicalProjectMilestones> getClinicalByConId(String projectFileId) {
        Result<FdClinicalProjectMilestones> result = new Result<>();
        FdClinicalProjectMilestones fdContract = fdClinicalProjectMilestonesService.getClinicalByConId(projectFileId);
        if (fdContract == null) {
            result.error500("未找到对应数据");
        } else {
            //截取合同类型id
            String[] conClassIds = fdContract.getContractType().split(",");
            //根据合同类型id获取相关信息
            List<FdContractClass> fdContractClassList = fdContractClassService.selectBatchIds(conClassIds);
            //合同类型名称
            String conClassName = "";
            //循环获取名称
            for (FdContractClass fdContractClass : fdContractClassList) {
                if (conClassName == "") {
                    conClassName = fdContractClass.getName();
                } else {
                    conClassName += "、" + fdContractClass.getName();
                }
            }
            fdContract.setContractType(conClassName);

            //根据合同id查询相关收款节点
            LambdaQueryWrapper<FdContractClause> contractClauseLambdaQueryWrapper = new LambdaQueryWrapper<>();
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getContractId, fdContract.getPkContract());//合同id
            contractClauseLambdaQueryWrapper.eq(FdContractClause::getDelFlag,"0");
            contractClauseLambdaQueryWrapper.orderByAsc(FdContractClause::getSort);
            List<FdContractClause> fdContractClauseList = fdContractClauseService.list(contractClauseLambdaQueryWrapper);
            fdContract.setContractClauseList(fdContractClauseList);

            //受试例数、周期等。。
            LambdaQueryWrapper<FdContractDetail> contractDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
            contractDetailLambdaQueryWrapper.eq(FdContractDetail::getDelFlag,"0");
            contractDetailLambdaQueryWrapper.eq(FdContractDetail::getContractId, fdContract.getPkContract());//合同id
            //对照明细采样数据
            List<FdContractDetail> contractDetailList = fdContractDetailService.list(contractDetailLambdaQueryWrapper);
            int i = 0;
            for (FdContractDetail fdContractDetail : contractDetailList) {
                if (i == 0) {
                    fdContract.setSubjectsNumber(fdContractDetail.getSubjectNumber());
                    fdContract.setCycle(fdContractDetail.getPeriod());
                    fdContract.setCleanPeriod(fdContractDetail.getCleaningPeriod());
                }
                i++;
            }
            String contractPartyName = fdColumnManagementController.getContractPartyName(fdContract.getPkContractParty());
            fdContract.setContractPartyName(contractPartyName);
            result.setResult(fdContract);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * @Author gurui
     * @Description //TODO  删除项目里程碑 同时删除模板项
     * @Date 17:59 2019/6/26
     * @Param [id]
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>
     **/
    @DeleteMapping(value = "/deleteAll")
    @NotDuplicate
    //临床里程碑删除权限控制（预实验、空腹、餐后、空腹或餐后、内部）
    @RequiresPermissions(value = {"pre-experiment:delete","pm-milestones:delete","empty-stomach:delete","empty-stomach-postprandial:delete","internal:delete"},logical = Logical.OR)
    public Result<FdClinicalProjectMilestones> deleteAll(@RequestParam(name = "id", required = true) String id) {
        Result<FdClinicalProjectMilestones> result = new Result<FdClinicalProjectMilestones>();
        FdClinicalProjectMilestones fdClinicalProjectMilestones = fdClinicalProjectMilestonesService.getById(id);
        if (fdClinicalProjectMilestones == null) {
            result.error500("未找到对应实体");
        } else {
            fdClinicalProjectMilestones.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
            fdClinicalProjectMilestonesService.updateById(fdClinicalProjectMilestones);
            // fdClinicalProjectMilestonesService.deleteAll(id);
            result.success("删除成功!");
        }
        return result;
    }


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

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

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

    /***
     * @Title:详情保存
            * @Description:TODO
            * @param fdClinicalProjectMilestones
            * @return org.jeecg.common.api.vo.Result
            * @exception
            * @author 陈创
            * @date 2019/7/10 13:44
            * @updatehistory:
     *   2019/7/10 13:44 新增
            */
    @PostMapping(value = "/viewUpdateMilestonesItems")
    public Result viewUpdateMilestonesItems(@RequestBody FdClinicalProjectMilestones fdClinicalProjectMilestones){
        Result result=new Result();
        try {
            fdClinicalProjectMilestonesService.viewUpdateMilestonesItems(fdClinicalProjectMilestones);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("保存失败");
        }
        return result;
    }

    /***
     * @Title:查询已审核项目档案的合同号
            * @Description:TODO
            * @return org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.projectManagement.entity.FdContract>>
            * @exception 
            * @author 陈创
            * @date 2019/7/7 15:53
            * @updatehistory:
     *   2019/7/7 15:53 查询
            */
    @GetMapping(value = "/getFileContractList")
    public Result<List<FdContract>> getFileContractList(){
        Result<List<FdContract>> result=new Result<>();
        result.setResult(fdClinicalProjectMilestonesService.getFileContractList());
        result.setSuccess(true);
        return result;
    }

    /***
     * @Title:查询里程碑数目
            * @Description:TODO 根据合同id查询对应合同下是否存在已保存的里程碑项目
            * @param contractId
            * @return org.jeecg.common.api.vo.Result
            * @exception
            * @author 陈创
            * @date 2019/9/9 11:34
            * @updatehistory:
     *   2019/9/9 11:34 新增
            */
    @GetMapping(value = "/getIsExistenceMilestones")
    public Result getIsExistenceMilestones(String contractId,String milestonesType){
        Result result=new Result();
        try {
            LambdaQueryWrapper<FdClinicalProjectMilestones> fdClinicalProjectMilestonesLambdaQueryWrapper=new LambdaQueryWrapper<>();
            fdClinicalProjectMilestonesLambdaQueryWrapper.eq(FdClinicalProjectMilestones::getDelFlag,"0");
            fdClinicalProjectMilestonesLambdaQueryWrapper.eq(FdClinicalProjectMilestones::getPkContract,contractId);
            fdClinicalProjectMilestonesLambdaQueryWrapper.eq(FdClinicalProjectMilestones::getMilestonesType,milestonesType);
            List<FdClinicalProjectMilestones> fdClinicalProjectMilestonesList=fdClinicalProjectMilestonesService.list(fdClinicalProjectMilestonesLambdaQueryWrapper);
            if(!fdClinicalProjectMilestonesList.isEmpty()&&fdClinicalProjectMilestonesList.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 list, fdClinicalProjectMilestonesItems]
            * @return org.jeecg.common.api.vo.Result
            * @exception
            * @author 陈创
            * @date 2019/9/12 14:03
            * @updatehistory:
     *   2019/9/12 14:03 新增
            */
    @PostMapping(value = "/emailNoticePandF")
    public Result emailNoticePandF(@RequestBody List<Object> list){
        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(fdClinicalProjectMilestones.getPkProjectFile());
            //查询收款条
            FdContractClause fdContractClause=fdContractClauseService.getById(fdClinicalProjectMilestonesItems.getPkContractClause());
            //查询客户
            LambdaQueryWrapper<FdCustomer> lambdaQueryWrapper=new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(FdCustomer::getName,fdClinicalProjectMilestones.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=fdClinicalProjectMilestones.getProjectManagerId();
            String personnel=fdProjectFile.getClinicalPm();
            String msg="\n合同号："+fdClinicalProjectMilestones.getContractCode()
                    +"\n项目名称："+fdClinicalProjectMilestones.getProjectName()
                    +"\n任务项："+fdClinicalProjectMilestonesItems.getDescription()
                    +"\n付款节点："+descriptionName
                    +"\n进度已完成";
            //通知项目经理
            iFdProjectReceivablesService.noticeFinance(personnel,"临床里程碑任务项确认通知",msg);
            //财务通知
            //财务通知
            //财务标题
            String titleFinance=fdClinicalProjectMilestones.getContractCode()
                    +"-"+shortName
                    +"-"+typeName+"￥"+money+"-收款通知！";
            //财务内容
            String msgFinance="合同号："+fdClinicalProjectMilestones.getContractCode()
                    +"\n合同方："+fdClinicalProjectMilestones.getContractPartyName()
                    +"\n收款类别："+typeName
                    +"\n条款描述："+descriptionName
                    +"\n收款百分比："+paymentPercent+"%"
                    +"\n金额：￥"+money;
//            iFdProjectReceivablesService.noticeFinance2("1479142272@qq.com",titleFinance,msgFinance);
            iFdProjectReceivablesService.noticeFinance2("ar@frontagelab.com.cn",titleFinance,msgFinance);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败"+e.getMessage());
        }
        return result;
    }
    
    /***
     * @Title:生物分析以及临床进度变化报表
            * @Description:TODO
            * @param startDate, endDate]
            * @return org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
            * @exception 
            * @author 陈创
            * @date 2019/9/24 20:04
            * @updatehistory:
     *   2019/9/24 20:04 新增
            */
    @GetMapping(value = "/clinAndBioProgressReport")
    @RequiresPermissions("url:clinicalAndBiologicalAnalysisProgress:view")
    public Result<List<FdClinicalProjectMilestones>> clinAndBioProgressReport(String startDate,String endDate){
        Result<List<FdClinicalProjectMilestones>> result=new Result<>();
        try {
            List<FdClinicalProjectMilestones> fdClinicalProjectMilestonesList=fdClinicalProjectMilestonesService.clinAndBioProgressReport(startDate,endDate);
            result.setResult(fdClinicalProjectMilestonesList);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败："+e.getMessage());
        }
        return result;
    }

    /**
    * @Author chenchuang
    * @Description //TODO 导出主表数据集合
    * @Date 2020/8/4 16:45
    * @Param [fdClinicalProjectMilestones]
    * @return org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.projectManagement.entity.FdClinicalProjectMilestones>>
    */
    @GetMapping(value = "/getMainExport")
    public Result<List<FdClinicalProjectMilestones>> getMainExport(FdClinicalProjectMilestones fdClinicalProjectMilestones){
        Result<List<FdClinicalProjectMilestones>> result=new Result<>();
        try {
            List<FdClinicalProjectMilestones> fdClinicalProjectMilestonesList=fdClinicalProjectMilestonesService.getMainExport(fdClinicalProjectMilestones);
            result.setResult(fdClinicalProjectMilestonesList);
            result.success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败："+e.getMessage());
        }
        return result;
    }
}
