package com.sunxung.factoring.service.project.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sunxung.factoring.component.exception.BusinessException;
import com.sunxung.factoring.component.exception.ValidatorException;
import com.sunxung.factoring.component.util.*;
import com.sunxung.factoring.component.util.onlineConverter.OfficeConverterUtil;
import com.sunxung.factoring.dict.impl.FileModuleDict;
import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.entprise.Enterprise;
import com.sunxung.factoring.entity.project.*;
import com.sunxung.factoring.entity.project.vo.ProjectInformationVo;
import com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask;
import com.sunxung.factoring.entity.supplier.CEnterpriseHistory;
import com.sunxung.factoring.entity.sys.*;
import com.sunxung.factoring.mapper.project.ProjectInformationMapper;
import com.sunxung.factoring.mapper.supplier.SupplierInfoMapper;
import com.sunxung.factoring.service.entprise.IEnterpriseService;
import com.sunxung.factoring.service.project.*;
import com.sunxung.factoring.service.supplier.ICEnterpriseHistoryService;
import com.sunxung.factoring.service.supplier.IDueDiligenceAllocationService;
import com.sunxung.factoring.service.sys.*;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.apache.commons.io.FileUtils;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.Period;
import java.util.*;

/**
 * <p>
 * 项目信息 服务实现类
 * </p>
 *
 * @author liutao
 * @since 2023-11-25
 */
@Service
public class ProjectInformationServiceImpl extends ServiceImpl<ProjectInformationMapper, ProjectInformation> implements IProjectInformationService {

    @Autowired
    private IDueDiligenceAllocationService dueDiligenceAllocationService;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    @Resource(name = "projectCoreEnterpriseService")
    private IProjectCoreEnterpriseService projectCoreEnterpriseService;

    @Autowired
    private IEnterpriseService enterpriseService;

    @Autowired
    private FlowableService flowableService;

    @Autowired
    private UserService userService;

    @Autowired
    private ICProjectInformationHistoryService projectInformationHistoryService;

    @Autowired
    private FileService fileService;

    @Autowired
    private ICEnterpriseHistoryService enterpriseHistoryService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private IProjectAuditService projectAuditService;

    @Autowired
    private IProjectOwnerScoreService projectOwnerScoreService;

    @Autowired
    private IProjectOwnerComprehensiveEvaluationService projectOwnerComprehensiveEvaluationService;

    @Autowired
    private DictionaryService dictionaryService;

    @Override
    public ProjectInformationVo getByBusinessNo(String businessNumber) {

        return baseMapper.getByBusinessNo(businessNumber);
    }

    @Override
    public void startProjectProcess(ProjectInformation projectInformation) {
        Long historyId = projectInformation.getHistoryId();
        User admin = userService.getByLoginName("admin");
        ThreadLocalUtil.setUser(admin);
        ProjectCoreEnterprise projectCoreEnterprise = projectInformation.getProjectCoreEnterprise();
        CEnterpriseHistory coreEnterprise = null;
        if (projectCoreEnterprise != null) {
            coreEnterprise = projectCoreEnterprise.getEnterprise();
        }
        CEnterpriseHistory enterprise = projectInformation.getEnterprise();
        //开启流程
        Map<String, Object> procVariables = new HashMap<>();
        procVariables.put(ConstantUtil.PROJECT_ADD_ASSIGNEE, admin.getId());
        //查询条件：业务编号 项目名称 主企业名称 核心企业名称
        String queryBusiness = projectInformation.getBusinessNumber() + FlowableUtil.splitChar + projectInformation.getProjectName();
        if (enterprise != null) {
            queryBusiness = queryBusiness + FlowableUtil.splitChar + enterprise.getCorporateName();
        }
        if (coreEnterprise != null) {
            queryBusiness = queryBusiness + FlowableUtil.splitChar + coreEnterprise.getCorporateName();
        }
        ProcessInstance processInst = flowableService.startProcessInstance(projectInformation, procVariables,
                FlowableUtil.generateBusinessKey(projectInformation, ConstantUtil.PROJECT_INFORMATION, queryBusiness), null, ConstantUtil.PROJECT_INFORMATION);
        if (processInst == null) {
            throw new BusinessException(CodeUtil.FAIL, "流程启动失败");
        }
        //完成第一步流程
        //获取风控负责人
        Long riskManagerId = projectInformation.getRiskManagerId();
        procVariables.put(ConstantUtil.PROJECT_APPROVAL_ADD_ASSIGNEE, riskManagerId);
        String processInstId = processInst.getId();
        Task task = flowableService.findRuntimeTaskByProcessInstId(processInstId).get(0);
        Map<String, Object> msgVariables = new HashMap<>();
        msgVariables.put(ConstantUtil.FLOWABLE_MSG_TITLE, "项目名称：" + projectInformation.getProjectName());
        msgVariables.put(ConstantUtil.FLOWABLE_MSG_CONTENT,
                "项目名称“" + projectInformation.getProjectName() + "”的项目已进入“"
                        + ConstantConversionUtil.flowBusinessKeyNames.get(ConstantUtil.PROJECT_INFORMATION) + "—项目审核，"
                        + ConstantUtil.FLOWABLE_MSG_ASSIGNEE);
        flowableService.completeMyTask(task.getId(), projectInformation, procVariables, null, historyId, msgVariables, ConstantUtil.PROJECT_INFORMATION);
    }

    @Override
    public GridPage<ProjectInformation> findAll(SearchBusinessProcessingTask search) {
        Long currentUserId = ThreadLocalUtil.getUserId();
        List<UserOrgRel> userOrgRelList = userService.findOrgRelByUserId(currentUserId);
        List<Long> userIdList;
        List<UserRoleRel> userRoleRels = roleService.getUserRoleByUserId(ThreadLocalUtil.getUserId());
        List<Long> pers = permissionService.getPermissionIdByUserId(ThreadLocalUtil.getUserId());
        Permission per = permissionService.getByEname(ConstantConversionUtil.VIEW_ALL_PROJECT);
        if (per == null) {
            throw new ValidatorException(CodeUtil.FAIL, "数据可见-查看全员权限不能为空");
        }
        if (pers.contains(per.getId())
                || ThreadLocalUtil.getUser().getLoginName().equals(ConstantConversionUtil.ADMINISTORIES)) {
            userIdList = null;
        } else {
            userIdList = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(userRoleRels)) {
                for (UserOrgRel userOrgRel : userOrgRelList) {
                    if (userOrgRel.isUserIdentity()) {
                        // 如果是部门负责人，获取部门下所有人员Id
                        List<Long> userIds = userService.findUserIdByOrgId(userOrgRel.getOrgId());
                        userIdList.addAll(userIds);
                    } else {
                        userIdList.add(currentUserId);
                    }
                }
            }
        }
        search.setUserIds(userIdList);
        Page page = PageHelper.startPage(search.getPage(), search.getRows());
        List<ProjectInformation> list = baseMapper.findBySearch(search);
        return new GridPage<>(page.getPageSize(), page.getPageNum(), page.getTotal(), list);
    }

    @Override
    public ProjectOwnerScore getProjectReport(Long id) {
        ProjectInformation projectInformation = get(id);
        projectInformation.setProjectType(dictionaryService.getByCode(projectInformation.getProjectType()).getName());
        projectInformation.setProjectCycle(dictionaryService.getByCode(projectInformation.getProjectCycle()).getName());
        projectInformation.setProjectNature(dictionaryService.getByCode(projectInformation.getProjectNature()).getName());
        projectInformation.setProjectNatureDetail(StringUtil.isEmpty(projectInformation.getProjectNatureDetail()) ? "" : dictionaryService.getByCode(projectInformation.getProjectNatureDetail()).getName());
        projectInformation.setProjectNatureDetailDes(StringUtil.isEmpty(projectInformation.getProjectNatureDetailDes()) ? "" : projectInformation.getProjectNatureDetailDes());
        projectInformation.setGoodsCategory(dictionaryService.getByCode(projectInformation.getGoodsCategory()).getName());
        projectInformation.setGoodsCategoryDetail(StringUtil.isEmpty(projectInformation.getGoodsCategoryDetail()) ? "" : dictionaryService.getByCode(projectInformation.getGoodsCategoryDetail()).getName());
        projectInformation.setGoodsCategoryDetailDes(StringUtil.isEmpty(projectInformation.getGoodsCategoryDetailDes()) ? "" : projectInformation.getGoodsCategoryDetailDes());
        projectInformation.setPurpose(dictionaryService.getByCode(projectInformation.getPurpose()).getName());
        projectInformation.setPurposeDetail(dictionaryService.getByCode(projectInformation.getPurposeDetail()).getName());
        List<FileStorageDO> biddingFiles = fileService.findByBusinessId(id, FileModuleDict.ChildEnum.PROJECT_BIDDING_FILE.getCode());
        List<FileStorageDO> departmentFiles = fileService.findByBusinessId(id, FileModuleDict.ChildEnum.PROJECT_DEPARTMENT_FILE.getCode());
        projectInformation.setBiddingFiles(biddingFiles);
        projectInformation.setDepartmentFiles(departmentFiles);
        Enterprise projectOwnerEnterprise = enterpriseService.getById(projectInformation.getcEnterpriseId());
        ProjectAudit projectAuditInfo = projectAuditService.lambdaQuery().eq(ProjectAudit::getcProjectInformationId, id).one();
        projectAuditInfo.setEnterpriseNature(dictionaryService.getByCode(projectAuditInfo.getEnterpriseNature()).getName());
        projectAuditInfo.setHoldingRatio(dictionaryService.getByCode(projectAuditInfo.getHoldingRatio()).getName());
        projectAuditInfo.setEquityHierarchy(dictionaryService.getByCode(projectAuditInfo.getEquityHierarchy()).getName());
        projectAuditInfo.setEquityHierarchyDetail(StringUtil.isEmpty(projectAuditInfo.getEquityHierarchyDetail()) ? "" : dictionaryService.getByCode(projectAuditInfo.getEquityHierarchyDetail()).getName());
        ProjectOwnerScore projectOwnerScore = projectOwnerScoreService.lambdaQuery().eq(ProjectOwnerScore::getProjectAuditId, projectAuditInfo.getId()).one();
        ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = projectOwnerComprehensiveEvaluationService.lambdaQuery().eq(ProjectOwnerComprehensiveEvaluation::getProjectAuditId, projectAuditInfo.getId()).one();
        projectOwnerScore.setProjectInformation(projectInformation);
        projectOwnerScore.setProjectOwnerEnterprise(projectOwnerEnterprise);
        projectOwnerScore.setProjectAuditInfo(projectAuditInfo);
        projectOwnerScore.setProjectOwnerComprehensiveEvaluation(projectOwnerComprehensiveEvaluation);

        LocalDate date1 = LocalDate.of(Integer.valueOf(DateUtil.getYear(projectOwnerEnterprise.getStartSate())), Integer.valueOf(DateUtil.getMonth(projectOwnerEnterprise.getStartSate())), Integer.valueOf(DateUtil.getDay(projectOwnerEnterprise.getStartSate()))); // 第一个日期
        LocalDate date2 = LocalDate.of(Integer.valueOf(DateUtil.getYear(projectOwnerScore.getGmtCreate())), Integer.valueOf(DateUtil.getMonth(projectOwnerScore.getGmtCreate())), Integer.valueOf(DateUtil.getDay(projectOwnerScore.getGmtCreate()))); // 当前日期（或者其他指定日期）
        Period period = Period.between(date1, date2); // 获取两个日期之间的时间段
        int yearsDiff = period.getYears(); // 获取年份差
        projectOwnerEnterprise.setYearsDiff(yearsDiff);
        return projectOwnerScore;
    }

    @Override
    public void download(Long id, HttpServletResponse res) throws IOException {
        ProjectOwnerScore projectReport = getProjectReport(id);
        ProjectInformation projectInformation = projectReport.getProjectInformation();
        Enterprise projectOwnerEnterprise = projectReport.getProjectOwnerEnterprise();
        ProjectAudit projectAuditInfo = projectReport.getProjectAuditInfo();
        ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = projectReport.getProjectOwnerComprehensiveEvaluation();
        DecimalFormat b = new DecimalFormat("0.00");
        Map params = new HashMap();
        params.put("projectType", projectInformation.getProjectType());
        params.put("projectName", projectInformation.getProjectName());
        params.put("projectAddress", projectInformation.getProjectAddress());
        params.put("projectAddressScore", b.format(projectReport.getProjectAddressScore()));
        params.put("projectCycle", projectInformation.getProjectCycle());
        params.put("projectCycleScore", b.format(projectReport.getProjectCycleScore()));
        String projectNature = projectInformation.getProjectNature() + " " + projectInformation.getProjectNatureDetail() + " " + projectInformation.getProjectNatureDetailDes();
        params.put("projectNature", projectNature);
        params.put("projectNatureScore", b.format(projectReport.getProjectNatureScore()));
        String goodsCategory = projectInformation.getGoodsCategory() + " " + projectInformation.getGoodsCategoryDetail() + " " + projectInformation.getGoodsCategoryDetailDes();
        params.put("goodsCategory", goodsCategory);
        String purpose = projectInformation.getPurpose() + " " + projectInformation.getPurposeDetail();
        params.put("purpose", purpose);
        String financialFunds = "财政资金" + (projectInformation.getFinancialFunds() == null ? "" : b.format(projectInformation.getFinancialFunds())) + "% ";
        String bankLoans = "银行贷款" + (projectInformation.getBankLoans() == null ? "" : b.format(projectInformation.getBankLoans())) + "% ";
        String foreignCapital = "利用外资" + (projectInformation.getForeignCapital() == null ? "" : b.format(projectInformation.getForeignCapital())) + "% ";
        String raiseIndependently = "企事业单位自筹自己" + (projectInformation.getRaiseIndependently() == null ? "" : b.format(projectInformation.getRaiseIndependently())) + "% ";
        String specialFund = "专项资金" + (projectInformation.getSpecialFund() == null ? "" : b.format(projectInformation.getSpecialFund())) + "% ";
        String otherFunds = "其他资金" + (projectInformation.getOtherFunds() == null ? "" : b.format(projectInformation.getOtherFunds())) + "% ";
        String unknown = "未知" + (projectInformation.getUnknown() == null ? "" : b.format(projectInformation.getUnknown())) + "% ";
        String funds = "";
        if (projectInformation.getFinancialFunds() != null && projectInformation.getFinancialFunds().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + financialFunds;
        }
        if (projectInformation.getBankLoans() != null && projectInformation.getBankLoans().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + bankLoans;
        }
        if (projectInformation.getForeignCapital() != null && projectInformation.getForeignCapital().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + foreignCapital;
        }
        if (projectInformation.getRaiseIndependently() != null && projectInformation.getRaiseIndependently().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + raiseIndependently;
        }
        if (projectInformation.getSpecialFund() != null && projectInformation.getSpecialFund().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + specialFund;
        }
        if (projectInformation.getOtherFunds() != null && projectInformation.getOtherFunds().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + otherFunds;
        }
        if (projectInformation.getUnknown() != null && projectInformation.getUnknown().compareTo(BigDecimal.ZERO) > 0) {
            funds = funds + unknown;
        }
        params.put("funds", funds);
        params.put("fundScore", b.format(projectReport.getFundScore()));
        params.put("projectOwnerEnterprise", projectOwnerEnterprise.getCorporateName());
        params.put("socialCreditCode", projectOwnerEnterprise.getSocialCreditCode());
        params.put("yearsDiff", projectOwnerEnterprise.getYearsDiff());
        params.put("establishmentPeriodScore", b.format(projectReport.getEstablishmentPeriodScore()));
        params.put("companyForProject", projectInformation.getCompanyForProject() == 0 ? "否" : "是");
        params.put("registeredCapital", projectOwnerEnterprise.getRegisteredCapital());
        params.put("registeredCapitalScore", b.format(projectReport.getRegisteredCapitalScore()));
        params.put("address", projectOwnerEnterprise.getAddress());
        params.put("registeredAddressScore", b.format(projectReport.getRegisteredAddressScore()));
        params.put("businessAddress", projectOwnerEnterprise.getBusinessAddress());
        params.put("businessAddressScore", b.format(projectReport.getBusinessAddressScore()));
        params.put("enterpriseNature", projectAuditInfo.getEnterpriseNature());
        params.put("enterpriseNatureScore", b.format(projectReport.getEnterpriseNatureScore()));
        params.put("holdingRatio", projectAuditInfo.getHoldingRatio());
        params.put("holdingRatioScore", b.format(projectReport.getHoldingRatioScore()));
        String equityHierarchy = projectAuditInfo.getEquityHierarchy() + " " + projectAuditInfo.getEquityHierarchyDetail();
        params.put("equityHierarchy", equityHierarchy);
        params.put("equityHierarchyScore", b.format(projectReport.getEquityHierarchyScore()));
        params.put("creditRating", projectAuditInfo.getCreditRating());
        params.put("creditRatingScore", b.format(projectReport.getCreditRatingScore()));
        params.put("enterpriseChange", projectReport.getEnterpriseChange() == 0 ? "不存在" : "存在");
        params.put("enterpriseChangeScore", b.format(projectReport.getEnterpriseChangeScore()));
        params.put("shiXin", projectReport.getShiXin() == 0 ? "不存在" : "存在");
        params.put("shiXinScore", b.format(projectReport.getShiXinScore()));
        params.put("stCount", projectReport.getStCount() == 0 ? "不存在" : "存在");
        params.put("stCountScore", b.format(projectReport.getStCountScore()));
        params.put("stCountPerson", projectReport.getStCountPerson() == 0 ? "不存在" : "存在");
        params.put("stCountPersonScore", b.format(projectReport.getStCountPersonScore()));
        params.put("zhiXingAmount", projectReport.getZhiXingAmount().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("zhiXingAmountScore", b.format(projectReport.getZhiXingAmountScore()));
        params.put("zhiXingFrequent", projectReport.getZhiXingFrequent());
        params.put("zhiXingFrequentScore", b.format(projectReport.getZhiXingFrequentScore()));
        params.put("historicalLitigationAmount", projectReport.getHistoricalLitigationAmount().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("historicalLitigationAmountScore", b.format(projectReport.getHistoricalLitigationAmountScore()));
        params.put("historicalLitigationCount", projectReport.getHistoricalLitigationCount());
        params.put("historicalLitigationCountScore", b.format(projectReport.getHistoricalLitigationCountScore()));
        params.put("privateLending", projectReport.getPrivateLending() == 0 ? "不存在" : "存在");
        params.put("privateLendingScore", b.format(projectReport.getPrivateLendingScore()));
        params.put("financialInstitution", projectReport.getFinancialInstitution() == 0 ? "不存在" : "存在");
        params.put("financialInstitutionScore", b.format(projectReport.getFinancialInstitutionScore()));
        params.put("equityFreeze", projectReport.getEquityFreeze() == 0 ? "不存在" : "存在");
        params.put("equityFreezeScore", b.format(projectReport.getEquityFreezeScore()));
        params.put("majorAbnormalLitigation", projectReport.getMajorAbnormalLitigation() == 0 ? "不存在" : "存在");
        params.put("majorAbnormalLitigationScore", b.format(projectReport.getMajorAbnormalLitigationScore()));
        params.put("seriousIllegality", projectReport.getSeriousIllegality() == 0 ? "不存在" : "存在");
        params.put("seriousIllegalityScore", b.format(projectReport.getSeriousIllegalityScore()));
        params.put("taxOweNotice", projectReport.getTaxOweNotice() == 0 ? "不存在" : "存在");
        params.put("taxOweNoticeScore", b.format(projectReport.getTaxOweNoticeScore()));
        params.put("taxIllegal", projectReport.getTaxIllegal() == 0 ? "不存在" : "存在");
        params.put("taxIllegalScore", b.format(projectReport.getTaxIllegalScore()));
        params.put("blacklist", projectReport.getBlacklist() == 0 ? "不存在" : "存在");
        params.put("blacklistScore", b.format(projectReport.getBlacklistScore()));
        params.put("exception", projectReport.getException() == 0 ? "不存在" : "存在");
        params.put("exceptionScore", b.format(projectReport.getExceptionScore()));
        params.put("administrativePenaltyCount", projectReport.getAdministrativePenaltyCount());
        params.put("administrativePenaltyCountScore", b.format(projectReport.getAdministrativePenaltyCountScore()));
        params.put("administrativePenaltyAmount", projectReport.getAdministrativePenaltyAmount().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("administrativePenaltyAmountScore", b.format(projectReport.getAdministrativePenaltyAmountScore()));
        params.put("environmentalPenaltiesAmount", projectReport.getEnvironmentalPenaltiesAmount().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("environmentalPenaltiesAmountScore", b.format(projectReport.getEnvironmentalPenaltiesAmountScore()));
        params.put("news", projectReport.getNews() == 0 ? "不存在" : "存在");
        params.put("newsScore", b.format(projectReport.getNewsScore()));
        params.put("cooperationAmount", projectInformation.getCooperationAmount().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("peakValue", projectInformation.getPeakValue().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("highPeakUsage", projectInformation.getHighPeakUsage().setScale(2, RoundingMode.HALF_UP) + "元人民币");
        params.put("estimatedAccountingPeriod", projectInformation.getEstimatedAccountingPeriod());
        params.put("estimatedAccountingPeriodScore", b.format(projectReport.getEstimatedAccountingPeriodScore()));
        params.put("evaluationOpinions", projectAuditInfo.getEvaluationOpinions());
        params.put("admitted", projectOwnerComprehensiveEvaluation.getAdmitted());
        params.put("projectScore", b.format(projectOwnerComprehensiveEvaluation.getProjectScore()));
        params.put("creditLimit", projectOwnerComprehensiveEvaluation.getCreditLimit().setScale(2, RoundingMode.HALF_UP) + "万元人民币");
        //模板地址
        ClassPathResource classPathResource = new ClassPathResource("ftl/project/projectReport.docx");
        XWPFTemplate template = XWPFTemplate.compile(classPathResource.getInputStream()).render(params);
        String path = FileUtil.getAbsolutePath(UUID.randomUUID().toString(), ".docx", FileModuleDict.ChildEnum.PROJECT_CREDIT_REPORT);
        File docxFile = new File(path);
        if (!docxFile.exists()) {
            FileUtils.createParentDirectories(docxFile);
        }
        template.writeToFile(path);
        //将docx转为pdf
        String suffix = FileUtil.getSuffix(docxFile.getName());
        String newPath = docxFile.getAbsolutePath().replace(suffix, ".pdf");
        File pdfFile = OfficeConverterUtil.office2Pdf(docxFile.getAbsolutePath(), newPath);
        docxFile.deleteOnExit();
        FileUtil.downloadPdfFile(res, pdfFile);
    }

    @Override
    public ProjectInformation get(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public CProjectInformationHistory getView(Long id) {
        CProjectInformationHistory projectInformationHistory = projectInformationHistoryService.getById(id);
        ProjectInformation projectInformation = lambdaQuery().eq(ProjectInformation::getBusinessNumber, projectInformationHistory.getBusinessNumber()).one();
        CEnterpriseHistory enterpriseHistory = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
        projectInformationHistory.setEnterpriseHistory(enterpriseHistory);
        List<FileStorageDO> biddingFiles = fileService.findByBusinessId(projectInformationHistory.getId(), FileModuleDict.ChildEnum.PROJECT_BIDDING_FILE_HISTORY.getCode());
        List<FileStorageDO> departmentFiles = fileService.findByBusinessId(projectInformationHistory.getId(), FileModuleDict.ChildEnum.PROJECT_DEPARTMENT_FILE_HISTORY.getCode());
        projectInformationHistory.setBiddingFiles(biddingFiles);
        projectInformationHistory.setDepartmentFiles(departmentFiles);
        projectInformationHistory.setGoodsCategory(StringUtil.isNotEmpty(projectInformationHistory.getGoodsCategory()) ? dictionaryService.getByCode(projectInformationHistory.getGoodsCategory()).getName() : "");
        projectInformationHistory.setGoodsCategoryDetail(StringUtil.isNotEmpty(projectInformationHistory.getGoodsCategoryDetail()) ? dictionaryService.getByCode(projectInformationHistory.getGoodsCategoryDetail()).getName() : "");
        projectInformationHistory.setProjectCycle(StringUtil.isNotEmpty(projectInformationHistory.getProjectCycle()) ? dictionaryService.getByCode(projectInformationHistory.getProjectCycle()).getName() : "");
        projectInformationHistory.setProjectNature(StringUtil.isNotEmpty(projectInformationHistory.getProjectNature()) ? dictionaryService.getByCode(projectInformationHistory.getProjectNature()).getName() : "");
        projectInformationHistory.setProjectNatureDetail(StringUtil.isNotEmpty(projectInformationHistory.getProjectNatureDetail()) ? dictionaryService.getByCode(projectInformationHistory.getProjectNatureDetail()).getName() : "");
        projectInformationHistory.setProjectType(StringUtil.isNotEmpty(projectInformationHistory.getProjectType()) ? dictionaryService.getByCode(projectInformationHistory.getProjectType()).getName() : "");
        projectInformationHistory.setPurpose(StringUtil.isNotEmpty(projectInformationHistory.getPurpose()) ? dictionaryService.getByCode(projectInformationHistory.getPurpose()).getName() : "");
        projectInformationHistory.setStatus(StringUtil.isNotEmpty(projectInformationHistory.getStatus()) ? dictionaryService.getByCode(projectInformationHistory.getStatus()).getName() : "");
        projectInformationHistory.setPurposeDetail(StringUtil.isNotEmpty(projectInformationHistory.getPurposeDetail()) ? dictionaryService.getByCode(projectInformationHistory.getPurposeDetail()).getName() : "");
        return projectInformationHistory;
    }
}
