package org.jeecg.modules.clinical.budget.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.models.auth.In;
import org.apache.shiro.SecurityUtils;
import org.jeecg.modules.basedata.entity.FdPersonnel;
import org.jeecg.modules.basedata.service.IFdPersonnelService;
import org.jeecg.modules.clinical.budget.controller.FdClinicalBudgetTemplateTypeCostController;
import org.jeecg.modules.clinical.budget.entity.*;
import org.jeecg.modules.clinical.budget.mapper.FdClinicalBudgetMapper;
import org.jeecg.modules.clinical.budget.service.*;
import org.jeecg.modules.projectManagement.entity.FdContractDetail;
import org.jeecg.modules.projectManagement.entity.FdContractProportion;
import org.jeecg.modules.projectManagement.entity.fdProjectQuotationFee;
import org.jeecg.modules.projectManagement.service.IFdContractDetailService;
import org.jeecg.modules.projectManagement.service.IFdContractProportionService;
import org.jeecg.modules.projectManagement.service.IfdProjectQuotationFeeService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysSerialPatternService;
import org.jeecg.modules.system.vo.CallResult;
import org.springframework.stereotype.Service;

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

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 临床预算表
 * @author： jeecg-boot
 * @date： 2019-08-17
 * @version： V1.0
 */
@Transactional
@Service
public class FdClinicalBudgetServiceImpl extends ServiceImpl<FdClinicalBudgetMapper, FdClinicalBudget> implements IFdClinicalBudgetService {

    @Resource
    FdClinicalBudgetMapper fdClinicalBudgetMapper;
    @Resource
    IfdProjectQuotationFeeService ifdProjectQuotationFeeService;
    @Resource
    IFdContractProportionService iFdContractProportionService;
    @Resource
    IFdContractDetailService iFdContractDetailService;
    @Resource
    IFdClinicalBudgetService iFdClinicalBudgetService;
    @Resource
    IFdClinicalBudgetTemplateTypeCostService iFdClinicalBudgetTemplateTypeCostService;
    @Resource
    IFdClinicalBudgetContractorService iFdClinicalBudgetContractorService;
    @Resource
    IFdClinicalBudgetHandoverfeeItemsService iFdClinicalBudgetHandoverfeeItemsService;
    @Resource
    IFdClinicalBudgetProjectCostService iFdClinicalBudgetProjectCostService;
    @Resource
    IFdClinicalBudgetWorkingHoursItemsService iFdClinicalBudgetWorkingHoursItemsService;
    @Resource
    IFdClinicalBudgetWorkingHoursTotalService iFdClinicalBudgetWorkingHoursTotalService;
    @Resource
    IFdPersonnelService fdPersonnelService;

    @Resource
    ISysSerialPatternService sysSerialPatternService;

    @Resource
    IFdClinicalGrossProfitService iFdClinicalGrossProfitService;

    /***
     * @Title:查询已经审核的项目档案中项目报价数据
     * @Description:TODO
     * @return java.util.List<org.jeecg.modules.clinical.budget.entity.FdClinicalBudget>
     * @exception
     * @author 陈创
     * @date 2019/8/26 16:18
     * @updatehistory:
     *   2019/8/26 16:18 新增
     */
    @Override
    public List<FdClinicalBudget> getQuotationList() {
        return fdClinicalBudgetMapper.getQuotationList();
    }

    /***
     * @Title:根据报价id查询项目档案中已审核的数据
     * @Description:TODO
     * @param quotationId
     * @return org.jeecg.modules.clinical.budget.entity.FdClinicalBudget
     * @exception
     * @author 陈创
     * @date 2019/8/26 17:48
     * @updatehistory:
     *   2019/8/26 17:48 新增
     */
    @Override
    public FdClinicalBudget getByQuotationId(String quotationId) {

        FdClinicalBudget fdClinicalBudget = fdClinicalBudgetMapper.getByQuotationId(quotationId);

        //报价中的费用单
        LambdaQueryWrapper<fdProjectQuotationFee> fdProjectQuotationFeeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        fdProjectQuotationFeeLambdaQueryWrapper.eq(fdProjectQuotationFee::getProjectQuotationId, fdClinicalBudget.getProjectQuotationId());
        fdProjectQuotationFeeLambdaQueryWrapper.eq(fdProjectQuotationFee::getDelFlag,"0");
        fdProjectQuotationFeeLambdaQueryWrapper.orderByAsc(fdProjectQuotationFee::getSort);
        //报价中费用单集合
        List<fdProjectQuotationFee> fdProjectQuotationFeeList = ifdProjectQuotationFeeService.list(fdProjectQuotationFeeLambdaQueryWrapper);
        //成本预算费用集合
        List<FdClinicalBudgetTemplateTypeCost> fdClinicalBudgetTemplateTypeCostArrayList = new ArrayList<>();
        //空腹总金额-餐后总金额-空腹餐后总金额
        Double fee1Total = 0.00;
        Double fee2Total = 0.00;
        //循环报价费用单表
        for (fdProjectQuotationFee fee : fdProjectQuotationFeeList) {
            FdClinicalBudgetTemplateTypeCost fdClinicalBudgetTemplateTypeCost = new FdClinicalBudgetTemplateTypeCost();
            fdClinicalBudgetTemplateTypeCost.setTemplateTypeId(fee.getFeeType());
            fdClinicalBudgetTemplateTypeCost.setTemplateTypeName(fee.getProjectFeeName());
            fdClinicalBudgetTemplateTypeCost.setFastingCost(fee.getFeeCategory1Subtotal());
            fdClinicalBudgetTemplateTypeCost.setFedCost(fee.getFeeCategory2Subtotal());
            //计算总和
            Double fee1 = 0.00;
            Double fee2 = 0.00;
            //判断小计费用是否为空
            if (fdClinicalBudgetTemplateTypeCost.getFastingCost() != null && !fdClinicalBudgetTemplateTypeCost.getFastingCost().equals("")) {
                fee1 = Double.parseDouble(fdClinicalBudgetTemplateTypeCost.getFastingCost());
            }
            if (fdClinicalBudgetTemplateTypeCost.getFedCost() != null && !fdClinicalBudgetTemplateTypeCost.getFedCost().equals("")) {
                fee2 = Double.parseDouble(fdClinicalBudgetTemplateTypeCost.getFedCost());
            }
            //总和
            fdClinicalBudgetTemplateTypeCost.setTotal(String.format("%.2f", (fee1 + fee2)));
            //保存到集合
            fdClinicalBudgetTemplateTypeCostArrayList.add(fdClinicalBudgetTemplateTypeCost);

            fee1Total = fee1Total + fee1;
            fee2Total = fee2Total + fee2;
        }
        fdClinicalBudget.setFastingTotal(String.format("%.2f", (fee1Total)));
        fdClinicalBudget.setFedTotal(String.format("%.2f", (fee2Total)));
        fdClinicalBudget.setContractTotal(String.format("%.2f", (fee1Total + fee2Total)));

        //获取临床、生物分析、总金额
        getProportion(fdClinicalBudget);
        //获取研究类型
        getResearchType(fdClinicalBudget);

        fdClinicalBudget.setFdClinicalBudgetTemplateTypeCostList(fdClinicalBudgetTemplateTypeCostArrayList);
        return fdClinicalBudget;
    }

    /***
     * @Title:根据合同的比例表获取临床含税金额，生物分析含税金额
     * @Description:TODO
     * @param fdClinicalBudget
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/8/27 15:49
     * @updatehistory:
     *   2019/8/27 15:49 新增
     */
    public void getProportion(FdClinicalBudget fdClinicalBudget) {
        LambdaQueryWrapper<FdContractProportion> fdContractProportionLambdaQueryWrapper = new LambdaQueryWrapper<>();
        fdContractProportionLambdaQueryWrapper.eq(FdContractProportion::getContractId, fdClinicalBudget.getContractId());
        List<FdContractProportion> fdContractProportionList = iFdContractProportionService.list(fdContractProportionLambdaQueryWrapper);
        //循环合同比例集合
        for (FdContractProportion fdContractProportion : fdContractProportionList) {
            if (fdContractProportion.getProportionItem().equals("临床项目")) {
                fdClinicalBudget.setClinicalMoneyTax(fdContractProportion.getTotalMoney());
            }
            if (fdContractProportion.getProportionItem().equals("生物分析")) {
                fdClinicalBudget.setBioanalysisMoneyTax(fdContractProportion.getTotalMoney());
            }
        }
    }

    /***
     * @Title:获取研究类型id和名称
     * @Description:TODO
     * @param fdClinicalBudget
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/8/27 16:02
     * @updatehistory:
     *   2019/8/27 16:02 新增
     */
    public void getResearchType(FdClinicalBudget fdClinicalBudget) {
        LambdaQueryWrapper<FdContractDetail> fdContractDetailLambdaQueryWrapper = new LambdaQueryWrapper<>();
        fdContractDetailLambdaQueryWrapper.eq(FdContractDetail::getContractId, fdClinicalBudget.getContractId());
        List<FdContractDetail> fdContractDetailList = iFdContractDetailService.list(fdContractDetailLambdaQueryWrapper);
        //存取研究类型id
        String researchTypeId = "";
        //存取研究类型名称
        String researchTypeName = "";
        //循环合同研究类型
        for (FdContractDetail fdContractDetail : fdContractDetailList) {
            if (researchTypeName.equals("")) {
                researchTypeName = fdContractDetail.getStudyType();
                researchTypeId = fdContractDetail.getId();
            } else {
                researchTypeName += "、" + fdContractDetail.getStudyType();
                researchTypeId += "、" + fdContractDetail.getId();
            }
        }
        fdClinicalBudget.setResearchTypeId(researchTypeId);
        fdClinicalBudget.setResearchTypeName(researchTypeName);
    }


    /***
     * @Title:保存主表和子表信息
     * @Description:TODO
     * @param fdClinicalBudget
     * @return void
     * @exception
     * @author 陈创
     * @date 2019/8/27 20:03
     * @updatehistory:
     *   2019/8/27 20:03 新增
     */
    @Override
    public void addFdClinicalBudgetAdd(FdClinicalBudget fdClinicalBudget) {
        //主表保存
        iFdClinicalBudgetService.save(fdClinicalBudget);
        //保存子表
        addChild(fdClinicalBudget);
    }

    /***
     * @Title:保存所有子表数据
            * @Description:TODO
            * @param fdClinicalBudget
            * @return void
            * @exception
            * @author 陈创
            * @date 2019/9/12 11:54
            * @updatehistory:
     *   2019/9/12 11:54 新增
            */
    public void addChild(FdClinicalBudget fdClinicalBudget){
        //临床预算id
        String fdClinicalBudgetId = fdClinicalBudget.getId();

        //成本预算集合
        List<FdClinicalBudgetTemplateTypeCost> fdClinicalBudgetTemplateTypeCostList = fdClinicalBudget.getFdClinicalBudgetTemplateTypeCostList();
        if (fdClinicalBudgetTemplateTypeCostList.size() > 0) {
            for (FdClinicalBudgetTemplateTypeCost fdClinicalBudgetTemplateTypeCost : fdClinicalBudgetTemplateTypeCostList) {
                fdClinicalBudgetTemplateTypeCost.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存成本预算
            iFdClinicalBudgetTemplateTypeCostService.saveBatch(fdClinicalBudgetTemplateTypeCostList);
        }

        //公司成本预算集合
        List<FdClinicalBudgetContractor> fdClinicalBudgetContractorList = fdClinicalBudget.getFdClinicalBudgetContractorList();
        if (fdClinicalBudgetContractorList.size() > 0) {
            for (FdClinicalBudgetContractor fdClinicalBudgetContractor : fdClinicalBudgetContractorList) {
                fdClinicalBudgetContractor.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存成本预算集合
            iFdClinicalBudgetContractorService.saveBatch(fdClinicalBudgetContractorList);
        }

        //临床过手费明细集合
        List<FdClinicalBudgetHandoverfeeItems> fdClinicalBudgetHandoverfeeItemsList = fdClinicalBudget.getFdClinicalBudgetHandoverfeeItemsList();
        if (fdClinicalBudgetHandoverfeeItemsList.size() > 0) {
            for (FdClinicalBudgetHandoverfeeItems fdClinicalBudgetHandoverfeeItems : fdClinicalBudgetHandoverfeeItemsList) {
                fdClinicalBudgetHandoverfeeItems.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存临床过手费明细集合
            iFdClinicalBudgetHandoverfeeItemsService.saveBatch(fdClinicalBudgetHandoverfeeItemsList);
        }

        //临床管理项目明细
        List<FdClinicalBudgetProjectCost> fdClinicalBudgetProjectCostList = fdClinicalBudget.getFdClinicalBudgetProjectCostList();
        if (fdClinicalBudgetProjectCostList.size() > 0) {
            for (FdClinicalBudgetProjectCost fdClinicalBudgetProjectCost : fdClinicalBudgetProjectCostList) {
                fdClinicalBudgetProjectCost.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存临床管理项目明细
            iFdClinicalBudgetProjectCostService.saveBatch(fdClinicalBudgetProjectCostList);
        }

        //临床工时统计表
        List<FdClinicalBudgetWorkingHoursItems> fdClinicalBudgetWorkingHoursItemsList = fdClinicalBudget.getFdClinicalBudgetWorkingHoursItemsList();
        if (fdClinicalBudgetWorkingHoursItemsList.size() > 0) {
            for (FdClinicalBudgetWorkingHoursItems fdClinicalBudgetWorkingHoursItems : fdClinicalBudgetWorkingHoursItemsList) {
                fdClinicalBudgetWorkingHoursItems.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存临床工时统计表
            iFdClinicalBudgetWorkingHoursItemsService.saveBatch(fdClinicalBudgetWorkingHoursItemsList);
        }

        //临床工时总统计表
        List<FdClinicalBudgetWorkingHoursTotal> fdClinicalBudgetWorkingHoursTotalList = fdClinicalBudget.getFdClinicalBudgetWorkingHoursTotalList();
        if (fdClinicalBudgetWorkingHoursTotalList.size() > 0) {
            for (FdClinicalBudgetWorkingHoursTotal fdClinicalBudgetWorkingHoursTotal : fdClinicalBudgetWorkingHoursTotalList) {
                fdClinicalBudgetWorkingHoursTotal.setClinicalBudgetId(fdClinicalBudgetId);//获取临床预算id
            }
            //批量保存临床工时总统计表
            iFdClinicalBudgetWorkingHoursTotalService.saveBatch(fdClinicalBudgetWorkingHoursTotalList);
        }

        //毛利分析表
        List<FdClinicalGrossProfit> fdClinicalGrossProfitList=fdClinicalBudget.getFdClinicalGrossProfitList();
        if(fdClinicalGrossProfitList!=null&&fdClinicalGrossProfitList.size()>0){
            Integer sort=1;
            for(FdClinicalGrossProfit fdClinicalGrossProfit:fdClinicalGrossProfitList){
                fdClinicalGrossProfit.setClinicalBudgetId(fdClinicalBudgetId);
                fdClinicalGrossProfit.setSort(sort);
                sort++;
            }
            //批量新增毛利分析统计表
            iFdClinicalGrossProfitService.saveBatch(fdClinicalGrossProfitList);
        }
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Author gurui
     * @Description //TODO  弃审核数据 ,使其 状态为0
     * @Date 17:09 2019/9/11
     * @Param [list]
     **/
    @Override
    public Map<String, Object> auditBatch(List<String> list) {
        Map<String, Object> map = new HashMap<>();
        String unAudit = " ";//可审计
        String audit = " ";//已审计
        //根据多个id查询报价对象集合
        List<FdClinicalBudget> fdProjectFileList = fdClinicalBudgetMapper.selectBatchIds(list);
        //修改
        if (fdProjectFileList == null || fdProjectFileList.isEmpty()) {
            audit += "未找到修改数据</br>";
        } else {
            //判断哪些可关闭哪些不可关闭
            for (FdClinicalBudget fdClinicalBudget : fdProjectFileList) {
                if (fdClinicalBudget.getStatus().equals("0")) {
                    audit += fdClinicalBudget.getProjectName() + "，";
                } else {
                    unAudit += fdClinicalBudget.getProjectName() + "，";
                }
            }
            //可关闭存在则操作数据库修改
            if (!unAudit.equals("")) {
                fdClinicalBudgetMapper.auditBatch(list);
            }
        }
        //去掉最后一个"，"号
        audit = audit.substring(0, audit.length() - 1);
        unAudit = unAudit.substring(0, unAudit.length() - 1);
        //加关键词
        if (!unAudit.equals("")) {
            unAudit = unAudit + "弃审核成功";
        }
        if (!audit.equals("")) {
            audit = "其中:" + audit + "已处于未审核状态。<br> ";
        }
        map.put("msg", unAudit + audit);
        return map;
    }

    /**
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Author gurui
     * @Description //TODO  审核数据 ,使其 状态为1
     * @Date 17:10 2019/9/11
     * @Param [list]
     **/
    @Override
    public Map<String, Object> reviewBatch(List<String> list) {
        Map<String, Object> map = new HashMap<>();
        String unReview = " "; //未审核
        String review = " "; //已审核
        //根据多个id查询报价对象集合
        List<FdClinicalBudget> fdProjectFileList = fdClinicalBudgetMapper.selectBatchIds(list);
        //修改
        if (fdProjectFileList == null || fdProjectFileList.isEmpty()) {
            review += "未找到修改数据</br>";
        } else {
            //判断哪些已审核哪些未审核
            for (FdClinicalBudget fdClinicalBudget : fdProjectFileList) {
                if (fdClinicalBudget.getStatus().equals("0")) {
                    unReview += fdClinicalBudget.getProjectName() + ",";
                }
                if (fdClinicalBudget.getStatus().equals("1")) {
                    review += fdClinicalBudget.getProjectName() + ",";
                }
            }
            //去掉最后一个","号
            unReview = unReview.substring(0, unReview.length() - 1);
            review = review.substring(0, review.length() - 1);
            //操作数据库将未审核的修改成已审核
            if (!unReview.equals("")) {
                fdClinicalBudgetMapper.reviewBatch(list);
            }
        }
        //加关键词
        if (!unReview.equals("")) {
            unReview = unReview + "审核成功";
        }
        if (!review.equals("")) {
            review = "其中：" + review + "已审核。<br>";
        }
        map.put("msg", unReview + review);
        return map;
    }

    /***
     * @Title:删除全部临床预算
            * @Description:TODO 主表子表数据删除
            * @param fdClinicalBudgetId
            * @return void
            * @exception
            * @author 陈创
            * @date 2019/9/12 11:52
            * @updatehistory:
     *   2019/9/12 11:52 删除
            */
    @Override
    public void deleteFdClinicalBudgetAll(String fdClinicalBudgetId) {
        //删除主表
        iFdClinicalBudgetService.removeById(fdClinicalBudgetId);

        //删除子表数据
        deleteChild(fdClinicalBudgetId);
    }

    /***
     * @Title:删除全部子表数据
            * @Description:TODO
            * @param fdClinicalBudgetId
            * @return void
            * @exception
            * @author 陈创
            * @date 2019/9/12 11:56
            * @updatehistory:
     *   2019/9/12 11:56 新增
            */
    public void deleteChild(String fdClinicalBudgetId){
        //删除公司统计表
        LambdaQueryWrapper<FdClinicalBudgetContractor> fdClinicalBudgetContractorLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetContractorLambdaQueryWrapper.eq(FdClinicalBudgetContractor::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetContractorService.remove(fdClinicalBudgetContractorLambdaQueryWrapper);

        //删除临床过手费明细表
        LambdaQueryWrapper<FdClinicalBudgetHandoverfeeItems> fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper.eq(FdClinicalBudgetHandoverfeeItems::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetHandoverfeeItemsService.remove(fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper);

        //删除临床项目管理明细表
        LambdaQueryWrapper<FdClinicalBudgetProjectCost> fdClinicalBudgetProjectCostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetProjectCostLambdaQueryWrapper.eq(FdClinicalBudgetProjectCost::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetProjectCostService.remove(fdClinicalBudgetProjectCostLambdaQueryWrapper);

        //删除模板类型费用统计表
        LambdaQueryWrapper<FdClinicalBudgetTemplateTypeCost> fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper.eq(FdClinicalBudgetTemplateTypeCost::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetTemplateTypeCostService.remove(fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper);

        //删除临床工时统计表
        LambdaQueryWrapper<FdClinicalBudgetWorkingHoursItems> fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursItems::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetWorkingHoursItemsService.remove(fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper);

        //删除临床工时总计表
        LambdaQueryWrapper<FdClinicalBudgetWorkingHoursTotal> fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursTotal::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalBudgetWorkingHoursTotalService.remove(fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper);

        //删除毛利分析总计表
        LambdaQueryWrapper<FdClinicalGrossProfit> fdClinicalGrossProfitLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalGrossProfitLambdaQueryWrapper.eq(FdClinicalGrossProfit::getClinicalBudgetId,fdClinicalBudgetId);
        iFdClinicalGrossProfitService.remove(fdClinicalGrossProfitLambdaQueryWrapper);
    }

    /***
     * @Title:修改临床预算
            * @Description:TODO 先删除子表数据  然后修改主表新增子表数据
            * @param fdClinicalBudget
            * @return void
            * @exception
            * @author 陈创
            * @date 2019/9/12 11:59
            * @updatehistory:
     *   2019/9/12 11:59 修改
            */
    @Override
    public void updateFdClinicalBudgetAll(FdClinicalBudget fdClinicalBudget) {
        //删除子表数据
        deleteChild(fdClinicalBudget.getId());

        //修改主表数据
        iFdClinicalBudgetService.updateById(fdClinicalBudget);

        //新增子表数据
        addChild(fdClinicalBudget);
    }

    @Override
    public FdClinicalBudget exportById(FdClinicalBudget fdClinicalBudget) {
        //主表
        FdClinicalBudget fdClinicalBudgetResult=fdClinicalBudgetMapper.selectById(fdClinicalBudget.getId());

        //合同收入
        LambdaQueryWrapper<FdClinicalBudgetTemplateTypeCost> fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper.eq(FdClinicalBudgetTemplateTypeCost::getDelFlag,"0");
        fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper.eq(FdClinicalBudgetTemplateTypeCost::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper.orderByAsc(FdClinicalBudgetTemplateTypeCost::getSort);
        List<FdClinicalBudgetTemplateTypeCost> fdClinicalBudgetTemplateTypeCostList=iFdClinicalBudgetTemplateTypeCostService.list(fdClinicalBudgetTemplateTypeCostLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetTemplateTypeCostList(fdClinicalBudgetTemplateTypeCostList);

        //毛利分析
        LambdaQueryWrapper<FdClinicalGrossProfit> fdClinicalGrossProfitLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalGrossProfitLambdaQueryWrapper.eq(FdClinicalGrossProfit::getDelFlag,"0");
        fdClinicalGrossProfitLambdaQueryWrapper.eq(FdClinicalGrossProfit::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalGrossProfitLambdaQueryWrapper.orderByAsc(FdClinicalGrossProfit::getSort);
        List<FdClinicalGrossProfit> fdClinicalGrossProfitList=iFdClinicalGrossProfitService.list(fdClinicalGrossProfitLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalGrossProfitList(fdClinicalGrossProfitList);

        //公司统计
        LambdaQueryWrapper<FdClinicalBudgetContractor> fdClinicalBudgetContractorLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetContractorLambdaQueryWrapper.eq(FdClinicalBudgetContractor::getDelFlag,"0");
        fdClinicalBudgetContractorLambdaQueryWrapper.eq(FdClinicalBudgetContractor::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetContractorLambdaQueryWrapper.orderByAsc(FdClinicalBudgetContractor::getSort);
        List<FdClinicalBudgetContractor> fdClinicalBudgetContractorList=iFdClinicalBudgetContractorService.list(fdClinicalBudgetContractorLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetContractorList(fdClinicalBudgetContractorList);

        //工时统计表
        LambdaQueryWrapper<FdClinicalBudgetWorkingHoursItems> fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursItems::getDelFlag,"0");
        fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursItems::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper.orderByAsc(FdClinicalBudgetWorkingHoursItems::getSort);
        List<FdClinicalBudgetWorkingHoursItems> fdClinicalBudgetWorkingHoursItemsList=iFdClinicalBudgetWorkingHoursItemsService.list(fdClinicalBudgetWorkingHoursItemsLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetWorkingHoursItemsList(fdClinicalBudgetWorkingHoursItemsList);

        //工时总计
        LambdaQueryWrapper<FdClinicalBudgetWorkingHoursTotal> fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursTotal::getDelFlag,"0");
        fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper.eq(FdClinicalBudgetWorkingHoursTotal::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper.orderByAsc(FdClinicalBudgetWorkingHoursTotal::getSort);
        List<FdClinicalBudgetWorkingHoursTotal> fdClinicalBudgetWorkingHoursTotalList=iFdClinicalBudgetWorkingHoursTotalService.list(fdClinicalBudgetWorkingHoursTotalLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetWorkingHoursTotalList(fdClinicalBudgetWorkingHoursTotalList);

        //过手费明细
        LambdaQueryWrapper<FdClinicalBudgetHandoverfeeItems> fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper.eq(FdClinicalBudgetHandoverfeeItems::getDelFlag,"0");
        fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper.eq(FdClinicalBudgetHandoverfeeItems::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper.orderByAsc(FdClinicalBudgetHandoverfeeItems::getSort);
        List<FdClinicalBudgetHandoverfeeItems> fdClinicalBudgetHandoverfeeItemsList=iFdClinicalBudgetHandoverfeeItemsService.list(fdClinicalBudgetHandoverfeeItemsLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetHandoverfeeItemsList(fdClinicalBudgetHandoverfeeItemsList);

        //项目管理费
        LambdaQueryWrapper<FdClinicalBudgetProjectCost> fdClinicalBudgetProjectCostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        fdClinicalBudgetProjectCostLambdaQueryWrapper.eq(FdClinicalBudgetProjectCost::getDelFlag,"0");
        fdClinicalBudgetProjectCostLambdaQueryWrapper.eq(FdClinicalBudgetProjectCost::getClinicalBudgetId,fdClinicalBudget.getId());
        fdClinicalBudgetProjectCostLambdaQueryWrapper.orderByAsc(FdClinicalBudgetProjectCost::getSort);
        List<FdClinicalBudgetProjectCost> fdClinicalBudgetProjectCostList=iFdClinicalBudgetProjectCostService.list(fdClinicalBudgetProjectCostLambdaQueryWrapper);
        fdClinicalBudgetResult.setFdClinicalBudgetProjectCostList(fdClinicalBudgetProjectCostList);

        return fdClinicalBudgetResult;
    }

}
