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

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.component.constance.ProjectCoreEnterpriseScoringModel;
import com.sunxung.factoring.component.constance.ProjectScoringModel;
import com.sunxung.factoring.component.enums.ProjectAndEnterpriseStatusEnums;
import com.sunxung.factoring.component.enums.SupplierStatusEnums;
import com.sunxung.factoring.component.exception.ValidatorException;
import com.sunxung.factoring.component.util.*;
import com.sunxung.factoring.dict.impl.*;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.entprise.Enterprise;
import com.sunxung.factoring.entity.project.*;
import com.sunxung.factoring.entity.project.vo.*;
import com.sunxung.factoring.entity.supplier.CEnterpriseHistory;
import com.sunxung.factoring.entity.supplier.CRegStock;
import com.sunxung.factoring.entity.supplier.SupplierInfo;
import com.sunxung.factoring.entity.sys.FileStorageDO;
import com.sunxung.factoring.mapper.project.ProjectAuditMapper;
import com.sunxung.factoring.service.creditresolution.ICreditResolutionService;
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.ISupplierInfoService;
import com.sunxung.factoring.service.sys.FileService;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.apache.bcel.classfile.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 项目企业审核 服务实现类
 * </p>
 *
 * @author liutao
 * @since 2023-12-15
 */
@Service("project_approval_addService")
public class ProjectAuditServiceImpl extends ServiceImpl<ProjectAuditMapper, ProjectAudit> implements IProjectAuditService {

    @Value("${sop.getProjectReviewInfoUrl}")
    private String getProjectReviewInfo;

    @Value("${sop.getChangesUrl}")
    private String getChanges;

    @Value("${sop.getProjectCoreEnterpriseScoreUrl}")
    private String getProjectCoreEnterpriseScore;

    @Autowired
    private RestTemplate restTemplate;

    @Resource(name = "projectInformationService")
    private IProjectInformationService projectInformationService;

    @Autowired
    private FileService fileService;

    @Autowired
    private ICEnterpriseHistoryService enterpriseHistoryService;

    @Autowired
    private IEnterpriseCreditRatingService enterpriseCreditRatingService;

    @Autowired
    private IProjectOwnerPrivateLendingService projectOwnerPrivateLendingService;

    @Autowired
    private IProjectOwnerEquityFreezeService projectOwnerEquityFreezeService;

    @Autowired
    private IProjectOwnerMajorAbnormalLitigationService projectOwnerMajorAbnormalLitigationService;

    @Autowired
    private IProjectOwnerSeriousIllegalityService projectOwnerSeriousIllegalityService;

    @Autowired
    private IProjectOwnerTaxOweNoticeService projectOwnerTaxOweNoticeService;

    @Autowired
    private IProjectOwnerTaxIllegalDataService projectOwnerTaxIllegalDataService;

    @Autowired
    private IProjectOwnerBlacklistService projectOwnerBlacklistService;

    @Autowired
    private IProjectOwnerExceptionDataService projectOwnerExceptionDataService;

    @Autowired
    private IProjectOwnerNewsService projectOwnerNewsService;

    @Autowired
    private FlowableService flowableService;

    @Autowired
    private IProjectOwnerComprehensiveEvaluationService projectOwnerComprehensiveEvaluationService;

    @Autowired
    private IProjectOwnerScoreService projectOwnerScoreService;

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

    @Resource(name = "supplierInfoService")
    private ISupplierInfoService supplierInfoService;

    @Resource(name = "creditResolutionService")
    private ICreditResolutionService creditResolutionService;

    @Autowired
    private IEnterpriseService enterpriseService;

    @Override
    public ProjectAudit getProjectAuditInfo(Long id) {
        //填充项目信息
        ProjectAudit projectAuditInfo = lambdaQuery().eq(ProjectAudit::getcProjectInformationId, id).one();
        ProjectInformation projectInformation = projectInformationService.get(id);
        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);
        if(projectAuditInfo == null){
            projectAuditInfo = new ProjectAudit();
            qcc(projectAuditInfo,projectInformation);
        }else {
            CEnterpriseHistory enterprise = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
            projectInformation.setEnterprise(enterprise);
            projectAuditInfo.setProjectInformation(projectInformation);
            String getProjectReviewInfoUrl = getProjectReviewInfo + "?comprehensiveRiskInvestigationId=" + enterprise.getcComprehensiveRiskInvestigationId();
            ResponseJson forObject = restTemplate.getForObject(getProjectReviewInfoUrl, ResponseJson.class);
            if(forObject != null) {
                JSONObject result = new JSONObject(forObject.getData());
                List<CRegStock> regStocks = result.getBeanList("cRegStocks", CRegStock.class);
                projectAuditInfo.setRegStocks(regStocks);
            }
            //民间借贷
            List<ProjectOwnerPrivateLending> projectOwnerPrivateLendings = projectOwnerPrivateLendingService.lambdaQuery().eq(ProjectOwnerPrivateLending::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CJudgmentDocuments> privateLendings = BeanUtilsProxy.copyPropertiesList(projectOwnerPrivateLendings, CJudgmentDocuments.class);
            projectAuditInfo.setPrivateLendings(privateLendings);
            projectAuditInfo.setProjectOwnerPrivateLendings(projectOwnerPrivateLendings);
            //股权冻结
            List<ProjectOwnerEquityFreeze> projectOwnerEquityFreezes = projectOwnerEquityFreezeService.lambdaQuery().eq(ProjectOwnerEquityFreeze::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CEquityFreezeData> cEquityFreezeData = BeanUtilsProxy.copyPropertiesList(projectOwnerEquityFreezes, CEquityFreezeData.class);
            projectAuditInfo.setEquityFreezeDataList(cEquityFreezeData);
            projectAuditInfo.setProjectOwnerEquityFreezes(projectOwnerEquityFreezes);
            //重大异常诉讼
            List<ProjectOwnerMajorAbnormalLitigation> projectOwnerMajorAbnormalLitigations = projectOwnerMajorAbnormalLitigationService.lambdaQuery().eq(ProjectOwnerMajorAbnormalLitigation::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CJudgmentDocuments> cJudgmentDocuments = BeanUtilsProxy.copyPropertiesList(projectOwnerMajorAbnormalLitigations, CJudgmentDocuments.class);
            projectAuditInfo.setMajorAnomalies(cJudgmentDocuments);
            projectAuditInfo.setProjectOwnerMajorAbnormalLitigations(projectOwnerMajorAbnormalLitigations);
            //严重违法
            List<ProjectOwnerSeriousIllegality> projectOwnerSeriousIllegalities = projectOwnerSeriousIllegalityService.lambdaQuery().eq(ProjectOwnerSeriousIllegality::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CSeriousIllegalData> cSeriousIllegalData = BeanUtilsProxy.copyPropertiesList(projectOwnerSeriousIllegalities, CSeriousIllegalData.class);
            projectAuditInfo.setSeriousIllegalData(cSeriousIllegalData);
            projectAuditInfo.setProjectOwnerSeriousIllegalities(projectOwnerSeriousIllegalities);
            //欠税公告
            List<ProjectOwnerTaxOweNotice> projectOwnerTaxOweNotices = projectOwnerTaxOweNoticeService.lambdaQuery().eq(ProjectOwnerTaxOweNotice::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CTaxOweNoticeData> cTaxOweNoticeData = BeanUtilsProxy.copyPropertiesList(projectOwnerTaxOweNotices, CTaxOweNoticeData.class);
            projectAuditInfo.setTaxOweNoticeData(cTaxOweNoticeData);
            projectAuditInfo.setProjectOwnerTaxOweNotices(projectOwnerTaxOweNotices);
            //税收违法
            List<ProjectOwnerTaxIllegalData> projectOwnerTaxIllegalData = projectOwnerTaxIllegalDataService.lambdaQuery().eq(ProjectOwnerTaxIllegalData::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CTaxIllegalData> cTaxIllegalData = BeanUtilsProxy.copyPropertiesList(projectOwnerTaxIllegalData, CTaxIllegalData.class);
            projectAuditInfo.setTaxIllegalData(cTaxIllegalData);
            projectAuditInfo.setProjectOwnerTaxIllegalDataList(projectOwnerTaxIllegalData);
            //黑名单信息
            List<ProjectOwnerBlacklist> projectOwnerBlacklists = projectOwnerBlacklistService.lambdaQuery().eq(ProjectOwnerBlacklist::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CBlacklist> cBlacklists = BeanUtilsProxy.copyPropertiesList(projectOwnerBlacklists, CBlacklist.class);
            projectAuditInfo.setBlacklists(cBlacklists);
            projectAuditInfo.setProjectOwnerBlacklists(projectOwnerBlacklists);
            //其他经营异常
            List<ProjectOwnerExceptionData> projectOwnerExceptionData = projectOwnerExceptionDataService.lambdaQuery().eq(ProjectOwnerExceptionData::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CExceptionData> cExceptionData = BeanUtilsProxy.copyPropertiesList(projectOwnerExceptionData, CExceptionData.class);
            projectAuditInfo.setExceptionData(cExceptionData);
            projectAuditInfo.setProjectOwnerExceptionDataList(projectOwnerExceptionData);
            //重大负面新闻舆情
            List<ProjectOwnerNews> projectOwnerNews = projectOwnerNewsService.lambdaQuery().eq(ProjectOwnerNews::getProjectAuditId, projectAuditInfo.getId()).list();
            List<CNews> cNews = BeanUtilsProxy.copyPropertiesList(projectOwnerNews, CNews.class);
            projectAuditInfo.setNews(cNews);
            projectAuditInfo.setProjectOwnerNewsList(projectOwnerNews);
            //一键测算
            ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = projectOwnerComprehensiveEvaluationService.lambdaQuery().eq(ProjectOwnerComprehensiveEvaluation::getProjectAuditId, projectAuditInfo.getId()).one();
            projectAuditInfo.setProjectOwnerComprehensiveEvaluation(projectOwnerComprehensiveEvaluation);
        }

        return projectAuditInfo;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addProjectAuditInfo(ProjectAudit projectAuditInfo) {
        //修改项目信息
        ProjectInformation projectInformation = projectAuditInfo.getProjectInformation();
        projectAuditInfo.setcProjectInformationId(projectInformation.getId());
        fileService.lambdaUpdate().eq(FileStorageDO::getBusinessId,projectInformation.getId())
                .eq(FileStorageDO::getBusinessType,FileModuleDict.ChildEnum.PROJECT_BIDDING_FILE.getCode())
                        .set(FileStorageDO::getBusinessId,null).update();
        fileService.lambdaUpdate().eq(FileStorageDO::getBusinessId,projectInformation.getId())
                .eq(FileStorageDO::getBusinessType,FileModuleDict.ChildEnum.PROJECT_DEPARTMENT_FILE.getCode())
                .set(FileStorageDO::getBusinessId,null).update();
        List<Long> files = projectInformation.getBiddingFileIds();
        List<Long> departmentFileIds = projectInformation.getDepartmentFileIds();
        fileService.updateBusinessId(files,projectInformation.getId());
        fileService.updateBusinessId(departmentFileIds,projectInformation.getId());
        CEnterpriseHistory cEnterpriseHistory = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
        //信用评级
        List<EnterpriseCreditRating> enterpriseCreditRatings = enterpriseCreditRatingService.lambdaQuery().eq(EnterpriseCreditRating::getName,cEnterpriseHistory.getCorporateName()).list();
        if(projectAuditInfo.getEnterpriseNature().equals("enterpriseNature_1")){
            projectAuditInfo.setCreditRating("事业单位");
        }else {
            if(CollectionUtil.isNotEmpty(enterpriseCreditRatings)){
                projectAuditInfo.setCreditRating(enterpriseCreditRatings.get(0).getLevel());
            }else {
                projectAuditInfo.setCreditRating("暂无外部信用级别");
            }
        }
        saveOrUpdate(projectAuditInfo);
        //民间借贷
        projectOwnerPrivateLendingService.lambdaUpdate().eq(ProjectOwnerPrivateLending::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerPrivateLending> projectOwnerPrivateLendings = projectAuditInfo.getProjectOwnerPrivateLendings();
        if(CollectionUtil.isNotEmpty(projectOwnerPrivateLendings)){
            for (ProjectOwnerPrivateLending projectOwnerPrivateLending : projectOwnerPrivateLendings) {
                projectOwnerPrivateLending.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerPrivateLendingService.save(projectOwnerPrivateLending);
            }
        }
        //股权冻结
        projectOwnerEquityFreezeService.lambdaUpdate().eq(ProjectOwnerEquityFreeze::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerEquityFreeze> projectOwnerEquityFreezes = projectAuditInfo.getProjectOwnerEquityFreezes();
        if(CollectionUtil.isNotEmpty(projectOwnerEquityFreezes)){
            for (ProjectOwnerEquityFreeze projectOwnerEquityFreeze : projectOwnerEquityFreezes) {
                projectOwnerEquityFreeze.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerEquityFreezeService.save(projectOwnerEquityFreeze);
            }
        }
        //重大异常诉讼
        projectOwnerMajorAbnormalLitigationService.lambdaUpdate().eq(ProjectOwnerMajorAbnormalLitigation::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerMajorAbnormalLitigation> projectOwnerMajorAbnormalLitigations = projectAuditInfo.getProjectOwnerMajorAbnormalLitigations();
        if(CollectionUtil.isNotEmpty(projectOwnerMajorAbnormalLitigations)){
            for (ProjectOwnerMajorAbnormalLitigation projectOwnerMajorAbnormalLitigation : projectOwnerMajorAbnormalLitigations) {
                projectOwnerMajorAbnormalLitigation.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerMajorAbnormalLitigationService.save(projectOwnerMajorAbnormalLitigation);
            }
        }
        //严重违法
        projectOwnerSeriousIllegalityService.lambdaUpdate().eq(ProjectOwnerSeriousIllegality::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerSeriousIllegality> projectOwnerSeriousIllegalities = projectAuditInfo.getProjectOwnerSeriousIllegalities();
        if(CollectionUtil.isNotEmpty(projectOwnerSeriousIllegalities)){
            for (ProjectOwnerSeriousIllegality projectOwnerSeriousIllegality : projectOwnerSeriousIllegalities) {
                projectOwnerSeriousIllegality.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerSeriousIllegalityService.save(projectOwnerSeriousIllegality);
            }
        }
        //欠税公告
        projectOwnerTaxOweNoticeService.lambdaUpdate().eq(ProjectOwnerTaxOweNotice::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerTaxOweNotice> projectOwnerTaxOweNotices = projectAuditInfo.getProjectOwnerTaxOweNotices();
        if (CollectionUtil.isNotEmpty(projectOwnerTaxOweNotices)) {
            for (ProjectOwnerTaxOweNotice projectOwnerTaxOweNotice : projectOwnerTaxOweNotices) {
                projectOwnerTaxOweNotice.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerTaxOweNoticeService.save(projectOwnerTaxOweNotice);
            }
        }
        //税收违法
        projectOwnerTaxIllegalDataService.lambdaUpdate().eq(ProjectOwnerTaxIllegalData::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerTaxIllegalData> projectOwnerTaxIllegalDataList = projectAuditInfo.getProjectOwnerTaxIllegalDataList();
        if (CollectionUtil.isNotEmpty(projectOwnerTaxIllegalDataList)) {
            for (ProjectOwnerTaxIllegalData projectOwnerTaxIllegalData : projectOwnerTaxIllegalDataList) {
                projectOwnerTaxIllegalData.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerTaxIllegalDataService.save(projectOwnerTaxIllegalData);
            }
        }
        //黑名单信息
        projectOwnerBlacklistService.lambdaUpdate().eq(ProjectOwnerBlacklist::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerBlacklist> projectOwnerBlacklists = projectAuditInfo.getProjectOwnerBlacklists();
        if (CollectionUtil.isNotEmpty(projectOwnerBlacklists)) {
            for (ProjectOwnerBlacklist projectOwnerBlacklist : projectOwnerBlacklists) {
                projectOwnerBlacklist.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerBlacklistService.save(projectOwnerBlacklist);
            }
        }
        //其他经营异常
        projectOwnerExceptionDataService.lambdaUpdate().eq(ProjectOwnerExceptionData::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerExceptionData> projectOwnerExceptionDataList = projectAuditInfo.getProjectOwnerExceptionDataList();
        if (CollectionUtil.isNotEmpty(projectOwnerExceptionDataList)) {
            for (ProjectOwnerExceptionData projectOwnerExceptionData : projectOwnerExceptionDataList) {
                projectOwnerExceptionData.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerExceptionDataService.save(projectOwnerExceptionData);
            }
        }
        //重大负面新闻舆情
        projectOwnerNewsService.lambdaUpdate().eq(ProjectOwnerNews::getProjectAuditId,projectAuditInfo.getId()).remove();
        List<ProjectOwnerNews> projectOwnerNewsList = projectAuditInfo.getProjectOwnerNewsList();
        if (CollectionUtil.isNotEmpty(projectOwnerNewsList)) {
            for (ProjectOwnerNews projectOwnerNews : projectOwnerNewsList) {
                projectOwnerNews.setProjectAuditId(projectAuditInfo.getId());
                projectOwnerNewsService.save(projectOwnerNews);
            }
        }
        BigDecimal financialFunds = projectInformation.getFinancialFunds() == null? BigDecimal.ZERO : projectInformation.getFinancialFunds();
        BigDecimal bankLoans = projectInformation.getBankLoans() == null? BigDecimal.ZERO : projectInformation.getBankLoans();
        BigDecimal foreignCapital = projectInformation.getForeignCapital() == null? BigDecimal.ZERO : projectInformation.getForeignCapital();
        BigDecimal raiseIndependently = projectInformation.getRaiseIndependently() == null? BigDecimal.ZERO : projectInformation.getRaiseIndependently();
        BigDecimal specialFund = projectInformation.getSpecialFund() == null? BigDecimal.ZERO : projectInformation.getSpecialFund();
        BigDecimal otherFunds = projectInformation.getOtherFunds() == null? BigDecimal.ZERO : projectInformation.getOtherFunds();
        BigDecimal unknown = projectInformation.getUnknown() == null? BigDecimal.ZERO : projectInformation.getUnknown();
        BigDecimal total = financialFunds.add(bankLoans).add(foreignCapital).add(raiseIndependently).add(specialFund).add(otherFunds).add(unknown);
        projectInformationService.updateById(projectInformation);
        if(projectAuditInfo.getVisible() == 1){
            if(total.compareTo(new BigDecimal(100)) != 0){
                throw new ValidatorException(CodeUtil.FAIL,"资金来源及占比加和必须等于100");
            }
            //一键测算
            projectOwnerComprehensiveEvaluationService.lambdaUpdate().eq(ProjectOwnerComprehensiveEvaluation::getProjectAuditId,projectAuditInfo.getId()).remove();
            ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = measurement(projectAuditInfo.getId(),projectAuditInfo);
            List<String> errors = projectOwnerComprehensiveEvaluation.getErrors();
            if (CollectionUtil.isNotEmpty(errors)) {
                Enterprise enterprise = enterpriseService.getById(projectInformation.getcEnterpriseId());
                String errorString = enterprise.getCorporateName() + "的企业不准入原因:" + errors.stream().collect(Collectors.joining(","));
                projectInformation.setErrorsString(errorString);
            }
            projectOwnerComprehensiveEvaluation.setProjectAuditId(projectAuditInfo.getId());
            projectOwnerComprehensiveEvaluationService.save(projectOwnerComprehensiveEvaluation);
            if(projectOwnerComprehensiveEvaluation.getAdmitted().equals(ProjectCoreEnterpriseScoringModel.ADMITTED)){
                projectInformation.setStatusStr(ProjectAndEnterpriseStatusEnums.CREDIT_SUCCESS.getCode());
            }else {
                projectInformation.setStatusStr(ProjectAndEnterpriseStatusEnums.VOTE.getCode());
            }
            projectInformationService.updateById(projectInformation);
            //流程处理
            Map<String, Object> msgVariables = new HashMap<>();
            msgVariables.put(ConstantUtil.FLOWABLE_MSG_TITLE, "项目名称：" + projectInformation.getProjectName());
            msgVariables.put(ConstantUtil.FLOWABLE_MSG_CONTENT,
                    "项目名称“" + projectInformation.getProjectName() + "”的项目已审核完成“"
                            + ConstantUtil.FLOWABLE_MSG_ASSIGNEE);
            flowableService.completeMyTask(projectAuditInfo.getTaskId(), projectInformation, null, null, projectAuditInfo.getId(), msgVariables, ConstantUtil.PROJECT_INFORMATION);
            //判断是否开启授信决议
            if(projectInformation.getStatusStr().equals(ProjectAndEnterpriseStatusEnums.CREDIT_SUCCESS.getCode())){
                ProjectCoreEnterprise projectCoreEnterprise = projectCoreEnterpriseService.lambdaQuery().eq(ProjectCoreEnterprise::getcProjectInformationId, projectInformation.getId()).one();
                if(projectCoreEnterprise.getStatusStr().equals(ProjectAndEnterpriseStatusEnums.CREDIT_SUCCESS.getCode())){
                    ProjectInformation exists = projectInformationService.get(projectInformation.getId());
                    SupplierInfo supplierInfo = supplierInfoService.get(exists.getcSupplierInfoId());
                    if(supplierInfo.getStatusStr().equals(SupplierStatusEnums.CREDIT_SUCCESS.getCode())){
                        //开启流程
                        creditResolutionService.startProcess(projectInformation.getId());
                    }
                }
            }
        }
    }
    @Override
    public ProjectOwnerComprehensiveEvaluation measurement(Long projectAuditId ,ProjectAudit projectAuditInfo) {
        List<String> errors = new ArrayList<>();
        ProjectOwnerScore projectOwnerScore = new ProjectOwnerScore();
        String admitted = ProjectScoringModel.ADMITTED;
        ProjectInformation projectInformation = projectAuditInfo.getProjectInformation();
        BigDecimal cooperationAmount = projectInformation.getCooperationAmount();
        BigDecimal highPeakUsage = projectInformation.getHighPeakUsage();
        BigDecimal totalScore = BigDecimal.ZERO;
        BigDecimal creditLimit = BigDecimal.ZERO;
        //（1）评估分值总分为100分，综合分值低于60分即为不准入客户；
        //（2）各项指标触碰任一红线后分值即为0，即为不准入客户；
        //（3）本次评估授信额度为单一项目底层额度，得分对应的授信额度与拟合作金额、用款高峰值取其低为最终底层项目的授信额度；
        //（4）若为集采项目或无项目，则项目仅填写，不红否不打分，项目额度取  本次该供应商拟合作总额、用款高峰值的低值。
        if(projectInformation.getProjectType().equals("c_project_type_3") || projectInformation.getProjectType().equals("c_project_type_2") ){
            BigDecimal result;
            result = cooperationAmount.compareTo(highPeakUsage) == 1 ? highPeakUsage : cooperationAmount;
            creditLimit = result;
        }else {
            CEnterpriseHistory enterprise = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
            //项目地点得分
            BigDecimal projectAddressScore = BigDecimal.ZERO;
            String projectAddress = projectInformation.getProjectAddress();
            if (projectAddress.contains("黑龙江") || projectAddress.contains("辽宁") || projectAddress.contains("吉林")) {
                errors.add("项目地址不准入！");
                admitted = ProjectScoringModel.NOT_ADMITTED;
            }else {
                projectAddressScore = ProjectScoringModel.PROJECT_ADDRESS_RATIO.multiply(ProjectScoringModel.PROJECT_ADDRESS_STANDARD);
            }
            projectOwnerScore.setProjectAddressScore(projectAddressScore);
            //项目周期得分
            BigDecimal projectCycleScore = BigDecimal.ZERO;
            String projectCycle = projectInformation.getProjectCycle();
            if(projectCycle.equals("c_project_cycle_1")){
                projectCycleScore = ProjectScoringModel.PROJECT_CYCLE_RATIO.multiply(ProjectScoringModel.PROJECT_CYCLE_STANDARD_A);
            }else if(projectCycle.equals("c_project_cycle_2")){
                projectCycleScore = ProjectScoringModel.PROJECT_CYCLE_RATIO.multiply(ProjectScoringModel.PROJECT_CYCLE_STANDARD_B);
            }else if(projectCycle.equals("c_project_cycle_3")){
                projectCycleScore = ProjectScoringModel.PROJECT_CYCLE_RATIO.multiply(ProjectScoringModel.PROJECT_CYCLE_STANDARD_C);
                admitted = ProjectScoringModel.NOT_ADMITTED;
                errors.add("项目周期不准入！");
            }else if(projectCycle.equals("c_project_cycle_4")){
                projectCycleScore = ProjectScoringModel.PROJECT_CYCLE_RATIO.multiply(ProjectScoringModel.PROJECT_CYCLE_STANDARD_D);
            }
            projectOwnerScore.setProjectCycleScore(projectCycleScore);
            //项目性质得分
            BigDecimal projectNatureScore = BigDecimal.ZERO;
            String projectNature = projectInformation.getProjectNature();
            if(projectNature.equals("c_project_nature_1")){
                projectNatureScore = ProjectScoringModel.PROJECT_NATURE_RATIO.multiply(ProjectScoringModel.PROJECT_NATURE_STANDARD_A);
            }else if(projectNature.equals("c_project_nature_2")){
                projectNatureScore = ProjectScoringModel.PROJECT_NATURE_RATIO.multiply(ProjectScoringModel.PROJECT_NATURE_STANDARD_B);
            }else if(projectNature.equals("c_project_nature_3")){
                projectNatureScore = ProjectScoringModel.PROJECT_NATURE_RATIO.multiply(ProjectScoringModel.PROJECT_NATURE_STANDARD_C);
            }else if(projectNature.equals("c_project_nature_4")){
                projectNatureScore = ProjectScoringModel.PROJECT_NATURE_RATIO.multiply(ProjectScoringModel.PROJECT_NATURE_STANDARD_D);
                admitted = ProjectScoringModel.NOT_ADMITTED;
                errors.add("项目性质不准入！");
            }else if(projectNature.equals("c_project_nature_5")){
                projectNatureScore = ProjectScoringModel.PROJECT_NATURE_RATIO.multiply(ProjectScoringModel.PROJECT_NATURE_STANDARD_E);
            }
            projectOwnerScore.setProjectNatureScore(projectNatureScore);
            //资金来源及占比得分
            BigDecimal fundScore ;
            BigDecimal financialFunds = projectInformation.getFinancialFunds() == null ? BigDecimal.ZERO:projectInformation.getFinancialFunds();
            BigDecimal specialFund = projectInformation.getSpecialFund() == null ? BigDecimal.ZERO:projectInformation.getSpecialFund();
            BigDecimal total = financialFunds.add(specialFund);
            if(total.compareTo(new BigDecimal("80")) > -1){
                fundScore = ProjectScoringModel.FUND_RATIO.multiply(ProjectScoringModel.FUND_STANDARD_A);
            }else if(total.compareTo(new BigDecimal("50")) < 1){
                fundScore = ProjectScoringModel.FUND_RATIO.multiply(ProjectScoringModel.FUND_STANDARD_C);
            }else {
                fundScore = ProjectScoringModel.FUND_RATIO.multiply(ProjectScoringModel.FUND_STANDARD_B);
            }
            projectOwnerScore.setFundScore(fundScore);
            //成立年限得分
            BigDecimal establishmentPeriodScore = BigDecimal.ZERO;
            if(projectAuditInfo.getEnterpriseNature().equals("enterpriseNature_1")){
                establishmentPeriodScore = ProjectScoringModel.START_DATE_RATIO.multiply(ProjectScoringModel.START_DATE_STANDARD_A);
            }else {
                if(projectInformation.getCompanyForProject().equals(1)){
                    establishmentPeriodScore = ProjectScoringModel.START_DATE_RATIO.multiply(ProjectScoringModel.START_DATE_STANDARD_B);
                }else {
                    Date date = DateUtil.addYears(enterprise.getStartSate(), 2);
                    if(date.compareTo(new Date()) < 1){
                        establishmentPeriodScore = ProjectScoringModel.START_DATE_RATIO.multiply(ProjectScoringModel.START_DATE_STANDARD_C);
                    }else {
                        admitted = ProjectScoringModel.NOT_ADMITTED;
                        errors.add("成立年限不准入！");
                    }
                }
            }
            projectOwnerScore.setEstablishmentPeriodScore(establishmentPeriodScore);
            //注册地址
            BigDecimal registeredAddressScore = BigDecimal.ZERO;
            String address = enterprise.getAddress();
            if (address.contains("黑龙江") || address.contains("辽宁") || address.contains("吉林") ) {
                admitted = ProjectScoringModel.NOT_ADMITTED;
                errors.add("注册（登记）地址不准入！");
            }else {
                registeredAddressScore = ProjectScoringModel.REGISTERED_ADDRESS_RATIO.multiply(ProjectScoringModel.REGISTERED_ADDRESS_TANDARD);
            }
            projectOwnerScore.setRegisteredAddressScore(registeredAddressScore);
            //经营地址得分
            String businessAddress = enterprise.getBusinessAddress();
            BigDecimal businessAddressScore = BigDecimal.ZERO;
            if (businessAddress.contains("黑龙江") || businessAddress.contains("辽宁") || businessAddress.contains("吉林") || businessAddress.contains("县") || businessAddress.contains("镇") || businessAddress.contains("乡") || businessAddress.contains("村")) {
                admitted = ProjectScoringModel.NOT_ADMITTED;
                errors.add("经营地址不准入！");
            }else {
                businessAddressScore = ProjectScoringModel.BUSINESS_ADDRESS_RATIO.multiply(ProjectScoringModel.BUSINESS_ADDRESS_TANDARD);
            }
            projectOwnerScore.setBusinessAddressScore(businessAddressScore);
            //注册资本得分
            BigDecimal registeredCapitalScore = BigDecimal.ZERO;
            BigDecimal registeredCapital = new BigDecimal(enterprise.getRegisteredCapital().replace("万元人民币",""));
            if(projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.ONE.getCode())){
                registeredCapitalScore = ProjectScoringModel.REGISTERED_CAPITAL_RATIO.multiply(ProjectScoringModel.REGISTERED_CAPITAL_STANDARD_FIVE);
            }else {
                if(registeredCapital.compareTo(new BigDecimal("2000")) == -1){
                    registeredCapitalScore = ProjectScoringModel.REGISTERED_CAPITAL_RATIO.multiply(ProjectScoringModel.REGISTERED_CAPITAL_STANDARD_ONE);
                }else if(registeredCapital.compareTo(new BigDecimal("2000")) == 1 && registeredCapital.compareTo(new BigDecimal("100000")) == -1){
                    registeredCapitalScore = ProjectScoringModel.REGISTERED_CAPITAL_RATIO.multiply(ProjectScoringModel.REGISTERED_CAPITAL_STANDARD_TWO);
                }else if(registeredCapital.compareTo(new BigDecimal("100000")) == 1 && registeredCapital.compareTo(new BigDecimal("500000")) == -1){
                    registeredCapitalScore = ProjectScoringModel.REGISTERED_CAPITAL_RATIO.multiply(ProjectScoringModel.REGISTERED_CAPITAL_STANDARD_THREE);
                }else if(registeredCapital.compareTo(new BigDecimal("500000")) == 1){
                    registeredCapitalScore = ProjectScoringModel.REGISTERED_CAPITAL_RATIO.multiply(ProjectScoringModel.REGISTERED_CAPITAL_STANDARD_FORE);
                }
            }
            projectOwnerScore.setRegisteredCapitalScore(registeredCapitalScore);
            //企业性质得分
            BigDecimal enterpriseNatureScore = BigDecimal.ZERO;
            if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.ONE.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_ONE);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.TWO.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_TWO);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.THREE.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_THREE);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.FORE.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_FORE);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.FIVE.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_FIVE);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.SIX.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_SIX);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.SEVEN.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_SEVEN);
            } else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.NINE.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_EIGHT);
            }else if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.TEN.getCode())) {
                enterpriseNatureScore = ProjectScoringModel.ENTERPRISE_NATURE_RATIO.multiply(ProjectScoringModel.ENTERPRISE_NATURE_STANDARD_NINE);
            }
            projectOwnerScore.setEnterpriseNatureScore(enterpriseNatureScore);
            //控股比例得分
            BigDecimal holdingRatioScore = BigDecimal.ZERO;
            if (projectAuditInfo.getEnterpriseNature().equals(EnterpriseNatureDict.ChildEnum.ONE.getCode())) {
                holdingRatioScore = ProjectScoringModel.HOLDING_RATIO.multiply(ProjectScoringModel.HOLDING_RATIO_STANDARD_FIVE);
            }else if (projectAuditInfo.getEnterpriseNatureDetail() != null && (projectAuditInfo.getEnterpriseNatureDetail().equals("enterpriseNature_9_A") || projectAuditInfo.getEnterpriseNatureDetail().equals("enterpriseNature_9_B"))) {

                holdingRatioScore = ProjectScoringModel.HOLDING_RATIO.multiply(ProjectScoringModel.HOLDING_RATIO_STANDARD_FORE);
            }else {
                if (projectAuditInfo.getHoldingRatio().equals(HoldingRatioDict.ChildEnum.ONE.getCode())) {
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("控股比例不准入！");
                } else if (projectAuditInfo.getHoldingRatio().equals(HoldingRatioDict.ChildEnum.TWO.getCode())) {
                    holdingRatioScore = ProjectScoringModel.HOLDING_RATIO.multiply(ProjectScoringModel.HOLDING_RATIO_STANDARD_TWO);
                }else if (projectAuditInfo.getHoldingRatio().equals(HoldingRatioDict.ChildEnum.THREE.getCode())){
                    holdingRatioScore = ProjectScoringModel.HOLDING_RATIO.multiply(ProjectScoringModel.HOLDING_RATIO_STANDARD_THREE);
                }
            }
            projectOwnerScore.setHoldingRatioScore(holdingRatioScore);
            //股权层级得分
            BigDecimal equityHierarchyScore = BigDecimal.ZERO;
            if(projectAuditInfo.getEquityHierarchy().equals(EquityHierarchyDict.ChildEnum.ONE.getCode())){
                if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailOneDict.ChildEnum.ONE.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_ONE);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailOneDict.ChildEnum.TWO.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_TWO);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailOneDict.ChildEnum.THREE.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_THREE);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailOneDict.ChildEnum.FORE.getCode())){
                    errors.add("股权层级不准入！");
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                }
            }else if(projectAuditInfo.getEquityHierarchy().equals(EquityHierarchyDict.ChildEnum.TWO.getCode())){
                if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.ONE.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_FIVE);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.TWO.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_SIX);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.THREE.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_SEVEN);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.FORE.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_EIGHT);
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.FIVE.getCode())){
                    errors.add("股权层级不准入！");
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                }else if(projectAuditInfo.getEquityHierarchyDetail().equals(EquityHierarchyDetailTwoDict.ChildEnum.SIX.getCode())){
                    equityHierarchyScore = ProjectScoringModel.EQUITY_HIERARCHY_RATIO.multiply(ProjectScoringModel.EQUITY_HIERARCHY_STANDARD_TEN);
                }
            }
            projectOwnerScore.setEquityHierarchyScore(equityHierarchyScore);
            //信用评级得分
            //信用评级
            List<EnterpriseCreditRating> enterpriseCreditRatings = enterpriseCreditRatingService.lambdaQuery().eq(EnterpriseCreditRating::getName,enterprise.getCorporateName()).list();
            if(projectAuditInfo.getEnterpriseNature().equals("enterpriseNature_1")){
                projectAuditInfo.setCreditRating("事业单位");
            }else {
                if(CollectionUtil.isNotEmpty(enterpriseCreditRatings)){
                    projectAuditInfo.setCreditRating(enterpriseCreditRatings.get(0).getLevel());
                }else {
                    projectAuditInfo.setCreditRating("暂无外部信用级别");
                }
            }
            BigDecimal creditRatingScore;
            if(projectAuditInfo.getEnterpriseNature().equals("事业单位")){
                creditRatingScore = ProjectScoringModel.CREDIT_RATING_RATIO.multiply(ProjectScoringModel.CREDIT_RATING_STANDARD_ONE);
            }else if(projectAuditInfo.getCreditRating().equals("AAA-") || projectAuditInfo.getCreditRating().equals("AAA+") || projectAuditInfo.getCreditRating().equals("AAA")){
                creditRatingScore = ProjectScoringModel.CREDIT_RATING_RATIO.multiply(ProjectScoringModel.CREDIT_RATING_STANDARD_TWO);
            }else if(projectAuditInfo.getCreditRating().equals("AA-") || projectAuditInfo.getCreditRating().equals("AA+") || projectAuditInfo.getCreditRating().equals("AA")){
                creditRatingScore = ProjectScoringModel.CREDIT_RATING_RATIO.multiply(ProjectScoringModel.CREDIT_RATING_STANDARD_THREE);
            }else if(projectAuditInfo.getCreditRating().equals("A-") || projectAuditInfo.getCreditRating().equals("A+") || projectAuditInfo.getCreditRating().equals("A")){
                creditRatingScore = ProjectScoringModel.CREDIT_RATING_RATIO.multiply(ProjectScoringModel.CREDIT_RATING_STANDARD_FORE);
            }else {
                creditRatingScore = ProjectScoringModel.CREDIT_RATING_RATIO.multiply(ProjectScoringModel.CREDIT_RATING_STANDARD_FIVE);
            }
            projectOwnerScore.setCreditRatingScore(creditRatingScore);
            //企业基本变动信息
            String getChangesUrl = getChanges + "?comprehensiveRiskInvestigationId=" + enterprise.getcComprehensiveRiskInvestigationId();
            Integer changes = restTemplate.getForObject(getChangesUrl, Integer.class);
            projectOwnerScore.setEnterpriseChange(changes);
            //企业基本变动信息得分
            BigDecimal enterpriseChangeScore = BigDecimal.ZERO;
            if(changes < 2){
                enterpriseChangeScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.CHANGE_COUNT_STANDARD);
            }else {
                admitted = ProjectScoringModel.NOT_ADMITTED;
                errors.add("企业基本变动信息不准入！");
            }
            projectOwnerScore.setEnterpriseChangeScore(enterpriseChangeScore);
            String getProjectCoreEnterpriseScoreUrl = getProjectCoreEnterpriseScore + "?comprehensiveRiskInvestigationId=" + enterprise.getcComprehensiveRiskInvestigationId() + "&dongjiangaoRiskId=" + enterprise.getcDongjiangaoRiskId();
            ResponseJson forObject = restTemplate.getForObject(getProjectCoreEnterpriseScoreUrl, ResponseJson.class);
            if(forObject != null) {
                JSONObject jsonObject = new JSONObject(forObject.getData());
                //失信被执行信息 失信被执行信息得分
                Integer zhixing = jsonObject.getInt("zhixing");
                BigDecimal shiXinScore = BigDecimal.ZERO;
                if (zhixing > 0) {
                    projectOwnerScore.setShiXin(1);
                    errors.add("失信被执行信息不准入！");
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                } else {
                    shiXinScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.SHI_XIN_STANDARD);
                    projectOwnerScore.setShiXin(0);
                }
                projectOwnerScore.setShiXinScore(shiXinScore);
                //限高消费情况（企业） 限高消费情况（企业）得分
                Integer stCount = jsonObject.getInt("stCount");
                BigDecimal stCountScore = BigDecimal.ZERO;
                if(stCount > 0 ){
                    projectOwnerScore.setStCount(1);
                    errors.add("限高消费情况（企业）不准入！");
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                }else {
                    projectOwnerScore.setStCount(0);
                    stCountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ST_COUNT_STANDARD_ONE);
                }
                projectOwnerScore.setStCountScore(stCountScore);
                //限高消费情况（法人）  限高消费情况（法人）得分
                Integer stCountPerson = jsonObject.getInt("stCountPerson");
                BigDecimal stCountPersonScore = BigDecimal.ZERO;
                if(stCountPerson > 0){
                    projectOwnerScore.setStCountPerson(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("限高消费情况（法人）不准入！");
                }else {
                    projectOwnerScore.setStCountPerson(0);
                    stCountPersonScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ST_COUNT_STANDARD_TWO);
                }
                projectOwnerScore.setStCountPersonScore(stCountPersonScore);
                //当前被执行金额  当前被执行金额得分
                BigDecimal zhixingAmount = jsonObject.getBigDecimal("zhixingAmount");
                projectOwnerScore.setZhiXingAmount(zhixingAmount);
                BigDecimal zhiXingAmountScore = BigDecimal.ZERO;
                if(zhixingAmount.compareTo(new BigDecimal(enterprise.getRegisteredCapital().replace("万元人民币","")).multiply(new BigDecimal("10000")).multiply(new BigDecimal("0.02"))) < 1){
                    zhiXingAmountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ZHI_XING_STANDARD_ONE);
                }else if(zhixingAmount.compareTo(new BigDecimal(enterprise.getRegisteredCapital().replace("万元人民币","")).multiply(new BigDecimal("10000")).multiply(new BigDecimal("0.02"))) == 1){
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("当前被执行金额不准入！");
                }
                projectOwnerScore.setZhiXingAmountScore(zhiXingAmountScore);
                //当前被执行频率 当前被执行频率得分
                Long zhixingFrequent = jsonObject.getLong("zhixingFrequent");
                projectOwnerScore.setZhiXingFrequent(zhixingFrequent);
                BigDecimal zhiXingFrequentScore = BigDecimal.ZERO;
                if(zhixingFrequent <= 5){
                    zhiXingFrequentScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ZHI_XING_STANDARD_TWO);
                }
                projectOwnerScore.setZhiXingFrequentScore(zhiXingFrequentScore);
                //历史涉诉金额 历史涉诉金额得分
                BigDecimal historicalLitigationAmount = jsonObject.getBigDecimal("historicalLitigationAmount");
                projectOwnerScore.setHistoricalLitigationAmount(historicalLitigationAmount);
                BigDecimal historicalLitigationAmountScore = BigDecimal.ZERO;
                if(historicalLitigationAmount.compareTo(new BigDecimal(enterprise.getRegisteredCapital().replace("万元人民币","")).multiply(new BigDecimal("10000")).multiply(new BigDecimal("0.1"))) < 1){
                    historicalLitigationAmountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_ONE);
                }
                projectOwnerScore.setHistoricalLitigationAmountScore(historicalLitigationAmountScore);
                //历史涉诉数量（近一年） 历史涉诉数量（近一年）得分
                Long historicalLitigationCount = jsonObject.getLong("historicalLitigationCount");
                projectOwnerScore.setHistoricalLitigationCount(historicalLitigationCount);
                BigDecimal historicalLitigationCountScore = BigDecimal.ZERO;
                if(historicalLitigationCount <= 100 ){
                    historicalLitigationCountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_TWO);
                }
                projectOwnerScore.setHistoricalLitigationCountScore(historicalLitigationCountScore);
                //金融机构被告案件 金融机构被告案件得分
                Long documentFinance = jsonObject.getLong("documentFinance");
                BigDecimal financialInstitutionScore = BigDecimal.ZERO;
                if(documentFinance > 0){
                    projectOwnerScore.setFinancialInstitution(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("金融机构被告案件不准入！");
                }else {
                    projectOwnerScore.setFinancialInstitution(0);
                    financialInstitutionScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_FORE);
                }
                projectOwnerScore.setFinancialInstitutionScore(financialInstitutionScore);
                //行政处罚数量 行政处罚数量得分
                Long administrativePenaltyCount = jsonObject.getLong("administrativePenaltyCount");
                BigDecimal administrativePenaltyCountScore = BigDecimal.ZERO;
                projectOwnerScore.setAdministrativePenaltyCount(administrativePenaltyCount);
                if(administrativePenaltyCount <= 3){
                    administrativePenaltyCountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ADMINISTRATIVE_PENALTY_STANDARD_ONE);
                }
                projectOwnerScore.setAdministrativePenaltyCountScore(administrativePenaltyCountScore);
                //行政处罚金额  行政处罚金额得分
                BigDecimal administrativePenaltyAmount = jsonObject.getBigDecimal("administrativePenaltyAmount");
                BigDecimal administrativePenaltyAmountScore = BigDecimal.ZERO;
                projectOwnerScore.setAdministrativePenaltyAmount(administrativePenaltyAmount);
                if(administrativePenaltyAmount.compareTo(new BigDecimal("50")) < 1){
                    administrativePenaltyAmountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ADMINISTRATIVE_PENALTY_STANDARD_TWO);
                }
                projectOwnerScore.setAdministrativePenaltyAmountScore(administrativePenaltyAmountScore);
                //环保处罚金额 环保处罚金额得分
                BigDecimal envPunishmentAmount = jsonObject.getBigDecimal("envPunishmentAmount");
                projectOwnerScore.setEnvironmentalPenaltiesAmount(envPunishmentAmount);
                BigDecimal environmentalPenaltiesAmountScore = BigDecimal.ZERO;
                if(envPunishmentAmount.compareTo(new BigDecimal("50")) < 1){
                    environmentalPenaltiesAmountScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.ADMINISTRATIVE_PENALTY_STANDARD_THREE);
                }
                projectOwnerScore.setEnvironmentalPenaltiesAmountScore(environmentalPenaltiesAmountScore);
            }
            //民间借贷被告记录  民间借贷被告记录得分
            projectOwnerScore.setPrivateLending(0);
            BigDecimal privateLendingScore = BigDecimal.ZERO;
            List<ProjectOwnerPrivateLending> projectOwnerPrivateLendings = projectAuditInfo.getProjectOwnerPrivateLendings();
            if(CollectionUtil.isNotEmpty(projectOwnerPrivateLendings)){
                long count = projectOwnerPrivateLendings.stream().filter(r -> r.getPrivateLending().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setPrivateLending(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("民间借贷被告记录不准入！");
                }else {
                    privateLendingScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_THREE);
                }
            }else {
                privateLendingScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_THREE);
            }
            projectOwnerScore.setPrivateLendingScore(privateLendingScore);
            //股权冻结 股权冻结得分
            List<ProjectOwnerEquityFreeze> projectOwnerEquityFreezes = projectAuditInfo.getProjectOwnerEquityFreezes();
            projectOwnerScore.setEquityFreeze(0);
            BigDecimal equityFreezeScore = BigDecimal.ZERO;
            if(CollectionUtil.isNotEmpty(projectOwnerEquityFreezes)){
                long count = projectOwnerEquityFreezes.stream().filter(r -> r.getEquityFreeze().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setEquityFreeze(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("股权冻结不准入！");
                }else {
                    equityFreezeScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_FIVE);
                }
            }else {
                equityFreezeScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_FIVE);
            }
            projectOwnerScore.setEquityFreezeScore(equityFreezeScore);
            //重大异常诉讼  重大异常诉讼得分
            List<ProjectOwnerMajorAbnormalLitigation> projectOwnerMajorAbnormalLitigations = projectAuditInfo.getProjectOwnerMajorAbnormalLitigations();
            BigDecimal majorAbnormalLitigationScore = BigDecimal.ZERO;
            projectOwnerScore.setMajorAbnormalLitigation(0);
            if(CollectionUtil.isNotEmpty(projectOwnerMajorAbnormalLitigations)){
                long count = projectOwnerMajorAbnormalLitigations.stream().filter(r -> r.getMajorAbnormalLitigation().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setMajorAbnormalLitigation(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("重大异常诉讼不准入！");
                }else {
                    majorAbnormalLitigationScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_SIX);
                }
            }else {
                majorAbnormalLitigationScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.INVOLVING_STANDARD_SIX);
            }
            projectOwnerScore.setMajorAbnormalLitigationScore(majorAbnormalLitigationScore);
            //严重违法行为  严重违法行为得分
            List<ProjectOwnerSeriousIllegality> projectOwnerSeriousIllegalities = projectAuditInfo.getProjectOwnerSeriousIllegalities();
            BigDecimal seriousIllegalityScore = BigDecimal.ZERO;
            projectOwnerScore.setSeriousIllegality(0);
            if(CollectionUtil.isNotEmpty(projectOwnerSeriousIllegalities)){
                long count = projectOwnerSeriousIllegalities.stream().filter(r -> r.getSeriousIllegality().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setSeriousIllegality(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("严重违法行为不准入！");
                }else {
                    seriousIllegalityScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_ONE);
                }
            }else {
                seriousIllegalityScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_ONE);
            }
            projectOwnerScore.setSeriousIllegalityScore(seriousIllegalityScore);
            //欠税公告  欠税公告得分
            List<ProjectOwnerTaxOweNotice> projectOwnerTaxOweNotices = projectAuditInfo.getProjectOwnerTaxOweNotices();
            BigDecimal taxOweNoticeScore = BigDecimal.ZERO;
            projectOwnerScore.setTaxOweNotice(0);
            if(CollectionUtil.isNotEmpty(projectOwnerTaxOweNotices)){
                long count = projectOwnerTaxOweNotices.stream().filter(r -> r.getTaxOweNotice().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setTaxOweNotice(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("欠税公告不准入！");
                }else {
                    taxOweNoticeScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_TWO);
                }
            }else {
                taxOweNoticeScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_TWO);
            }
            projectOwnerScore.setTaxOweNoticeScore(taxOweNoticeScore);
            //税收违法 税收违法得分
            List<ProjectOwnerTaxIllegalData> projectOwnerTaxIllegalDataList = projectAuditInfo.getProjectOwnerTaxIllegalDataList();
            BigDecimal taxIllegalScore = BigDecimal.ZERO;
            projectOwnerScore.setTaxIllegal(0);
            if(CollectionUtil.isNotEmpty(projectOwnerTaxIllegalDataList)){
                long count = projectOwnerTaxIllegalDataList.stream().filter(r -> r.getTaxIllegal().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setTaxIllegal(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("税收违法不准入！");
                }else {
                    taxIllegalScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_THREE);
                }
            }else {
                taxIllegalScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_THREE);
            }
            projectOwnerScore.setTaxIllegalScore(taxIllegalScore);
            //黑名单信息  黑名单信息得分
            List<ProjectOwnerBlacklist> projectOwnerBlacklists = projectAuditInfo.getProjectOwnerBlacklists();
            BigDecimal blacklistScore = BigDecimal.ZERO;
            projectOwnerScore.setBlacklist(0);
            if(CollectionUtil.isNotEmpty(projectOwnerBlacklists)){
                long count = projectOwnerBlacklists.stream().filter(r -> r.getBlacklist().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setBlacklist(1);
                    errors.add("黑名单信息不准入！");
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                }else {
                    blacklistScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_FORE);
                }
            }else {
                blacklistScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_FORE);
            }
            projectOwnerScore.setBlacklistScore(blacklistScore);
            //其他经营异常 其他经营异常得分
            List<ProjectOwnerExceptionData> projectOwnerExceptionDataList = projectAuditInfo.getProjectOwnerExceptionDataList();
            BigDecimal exceptionScore = BigDecimal.ZERO;
            projectOwnerScore.setException(0);
            if(CollectionUtil.isNotEmpty(projectOwnerExceptionDataList)){
                long count = projectOwnerExceptionDataList.stream().filter(r -> r.getException().equals(1)).count();
                if(count > 0){
                    projectOwnerScore.setException(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("其他经营异常不准入！");
                }else {
                    exceptionScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_FIVE);
                }
            }else {
                exceptionScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.BUSINESS_ABNORMALITIES_STANDARD_FIVE);
            }
            projectOwnerScore.setExceptionScore(exceptionScore);
            //重大负面新闻舆情 重大负面新闻舆情得分
            List<ProjectOwnerNews> projectOwnerNewsList = projectAuditInfo.getProjectOwnerNewsList();
            projectOwnerScore.setNews(0);
            BigDecimal newsScore = BigDecimal.ZERO;
            if(CollectionUtil.isNotEmpty(projectOwnerNewsList)){
                long count = projectOwnerNewsList.stream().filter(r -> r.getNews().equals(1)).count();
                if(count > 0 ){
                    projectOwnerScore.setNews(1);
                    admitted = ProjectScoringModel.NOT_ADMITTED;
                    errors.add("重大负面新闻舆情不准入！");
                }else {
                    newsScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.NEWS_STANDARD_THREE);
                }
            }else {
                newsScore = ProjectScoringModel.ENTERPRISE_RATIO.multiply(ProjectScoringModel.NEWS_STANDARD_THREE);
            }
            projectOwnerScore.setNewsScore(newsScore);
            Long estimatedAccountingPeriod = projectInformation.getEstimatedAccountingPeriod();
            BigDecimal estimatedAccountingPeriodScore;
            if(estimatedAccountingPeriod <= 3){
                estimatedAccountingPeriodScore = ProjectScoringModel.ESTIMATED_ACCOUNTING_RATIO.multiply(ProjectScoringModel.ESTIMATED_ACCOUNTING_STANDARD_A);
            }else if(3 < estimatedAccountingPeriod && estimatedAccountingPeriod < 6){
                estimatedAccountingPeriodScore = ProjectScoringModel.ESTIMATED_ACCOUNTING_RATIO.multiply(ProjectScoringModel.ESTIMATED_ACCOUNTING_STANDARD_B);
            }else if(6 <= estimatedAccountingPeriod && estimatedAccountingPeriod < 10){
                estimatedAccountingPeriodScore = ProjectScoringModel.ESTIMATED_ACCOUNTING_RATIO.multiply(ProjectScoringModel.ESTIMATED_ACCOUNTING_STANDARD_C);
            }else {
                estimatedAccountingPeriodScore = ProjectScoringModel.ESTIMATED_ACCOUNTING_RATIO.multiply(ProjectScoringModel.ESTIMATED_ACCOUNTING_STANDARD_D);
            }
            projectOwnerScore.setEstimatedAccountingPeriodScore(estimatedAccountingPeriodScore);
            if(admitted.equals(ProjectScoringModel.ADMITTED)){
                totalScore = totalScore.add(projectOwnerScore.getProjectAddressScore()).add(projectOwnerScore.getProjectCycleScore())
                        .add(projectOwnerScore.getProjectNatureScore()).add(projectOwnerScore.getFundScore()).add(projectOwnerScore.getEstablishmentPeriodScore())
                        .add(projectOwnerScore.getRegisteredAddressScore()).add(projectOwnerScore.getBusinessAddressScore()).add(projectOwnerScore.getRegisteredCapitalScore())
                        .add(projectOwnerScore.getEnterpriseNatureScore()).add(projectOwnerScore.getHoldingRatioScore()).add(projectOwnerScore.getEquityHierarchyScore())
                        .add(projectOwnerScore.getCreditRatingScore()).add(projectOwnerScore.getEnterpriseChangeScore()).add(projectOwnerScore.getShiXinScore())
                        .add(projectOwnerScore.getStCountScore()).add(projectOwnerScore.getStCountPersonScore()).add(projectOwnerScore.getZhiXingAmountScore())
                        .add(projectOwnerScore.getZhiXingFrequentScore()).add(projectOwnerScore.getHistoricalLitigationAmountScore()).add(projectOwnerScore.getHistoricalLitigationCountScore())
                        .add(projectOwnerScore.getPrivateLendingScore()).add(projectOwnerScore.getFinancialInstitutionScore()).add(projectOwnerScore.getEquityFreezeScore())
                        .add(projectOwnerScore.getMajorAbnormalLitigationScore()).add(projectOwnerScore.getSeriousIllegalityScore()).add(projectOwnerScore.getTaxOweNoticeScore())
                        .add(projectOwnerScore.getTaxIllegalScore()).add(projectOwnerScore.getBlacklistScore()).add(projectOwnerScore.getExceptionScore())
                        .add(projectOwnerScore.getAdministrativePenaltyAmountScore()).add(projectOwnerScore.getAdministrativePenaltyCountScore()).add(projectOwnerScore.getEnvironmentalPenaltiesAmountScore())
                        .add(projectOwnerScore.getNewsScore()).add(projectOwnerScore.getEstimatedAccountingPeriodScore());
                if(totalScore.compareTo(new BigDecimal(60)) >-1 && totalScore.compareTo(new BigDecimal(65)) < 1){
                    creditLimit = new BigDecimal("500");
                }else if(totalScore.compareTo(new BigDecimal(65)) == 1 && totalScore.compareTo(new BigDecimal(70)) < 1){
                    creditLimit = new BigDecimal("1000");
                }else if(totalScore.compareTo(new BigDecimal(70)) == 1 && totalScore.compareTo(new BigDecimal(85)) < 1){
                    creditLimit = new BigDecimal("2000");
                }else if(totalScore.compareTo(new BigDecimal(85)) == 1 && totalScore.compareTo(new BigDecimal(90)) < 1){
                    creditLimit = new BigDecimal("3000");
                }else if(totalScore.compareTo(new BigDecimal(90)) == 1 && totalScore.compareTo(new BigDecimal(95)) < 1){
                    creditLimit = new BigDecimal("4000");
                }else if(totalScore.compareTo(new BigDecimal(95)) == 1 && totalScore.compareTo(new BigDecimal(100)) < 1){
                    creditLimit = new BigDecimal("5000");
                }else {
                    admitted = ProjectCoreEnterpriseScoringModel.NOT_ADMITTED;
                    errors.add("得分为" + totalScore + ",不准入！");
                }
            }
            if(projectAuditId != null){
                projectOwnerScore.setProjectAuditId(projectAuditId);
                projectOwnerScoreService.save(projectOwnerScore);
            }
        }
        if(projectAuditInfo.getInvolvingLitigationAccess() == 0 || projectAuditInfo.getAdministrativePenaltyAccess() == 0
                || projectAuditInfo.getAdministrativePenaltyAmountAccess() == 0 || projectAuditInfo.getEnvironmentalPenaltyAmountAccess() == 0){
            admitted = ProjectCoreEnterpriseScoringModel.NOT_ADMITTED;
            if(projectAuditInfo.getInvolvingLitigationAccess() == 0 ){
                errors.add("历史涉诉数量不准入！");
            }
            if( projectAuditInfo.getAdministrativePenaltyAccess() == 0){
                errors.add("行政处罚数量不准入！");
            }
            if(projectAuditInfo.getAdministrativePenaltyAmountAccess() == 0 ){
                errors.add("行政处罚金额不准入！");
            }
            if(projectAuditInfo.getEnvironmentalPenaltyAmountAccess() == 0){
                errors.add("环保处罚金额不准入！");
            }
        }
        if(projectInformation.getPurposeDetail() != null && "c_project_goods_purpose_2_D".equals(projectInformation.getPurposeDetail())){
            admitted = ProjectCoreEnterpriseScoringModel.NOT_ADMITTED;
            errors.add("用途不准入！");
        }
        if(projectAuditInfo.getHoldingRatio().equals(HoldingRatioDict.ChildEnum.ONE.getCode())){
            admitted = ProjectCoreEnterpriseScoringModel.NOT_ADMITTED;
            errors.add("控股比例不准入！");
        }
        if(admitted.equals(ProjectCoreEnterpriseScoringModel.NOT_ADMITTED)){
            totalScore = BigDecimal.ZERO;
            creditLimit = BigDecimal.ZERO;
        }
        ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = new ProjectOwnerComprehensiveEvaluation();
        projectOwnerComprehensiveEvaluation.setErrors(errors);
        projectOwnerComprehensiveEvaluation.setAdmitted(admitted);
        projectOwnerComprehensiveEvaluation.setProjectScore(totalScore);
        projectOwnerComprehensiveEvaluation.setCreditLimit(creditLimit);
        return projectOwnerComprehensiveEvaluation;
    }

    @Override
    public ProjectAudit getView(Long id) {
        //填充项目信息
        ProjectAudit projectAudit = getById(id);
        ProjectInformation projectInformation = projectInformationService.get(projectAudit.getcProjectInformationId());
        List<FileStorageDO> biddingFiles = fileService.findByBusinessId(projectInformation.getId(), FileModuleDict.ChildEnum.PROJECT_BIDDING_FILE.getCode());
        List<FileStorageDO> departmentFiles = fileService.findByBusinessId(projectInformation.getId(), FileModuleDict.ChildEnum.PROJECT_DEPARTMENT_FILE.getCode());
        projectInformation.setBiddingFiles(biddingFiles);
        projectInformation.setDepartmentFiles(departmentFiles);
        //项目业主 企业信息需要用历史的   因为会变动
        CEnterpriseHistory enterprise = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
        projectInformation.setEnterprise(enterprise);
        projectAudit.setProjectInformation(projectInformation);
        //企查查
        String getProjectReviewInfoUrl = getProjectReviewInfo + "?comprehensiveRiskInvestigationId=" + enterprise.getcComprehensiveRiskInvestigationId();
        ResponseJson forObject = restTemplate.getForObject(getProjectReviewInfoUrl, ResponseJson.class);
        if(forObject != null) {
            JSONObject result = new JSONObject(forObject.getData());
            List<CRegStock> regStocks = result.getBeanList("cRegStocks", CRegStock.class);
            projectAudit.setRegStocks(regStocks);
        }
        //民间借贷
        List<ProjectOwnerPrivateLending> projectOwnerPrivateLendings = projectOwnerPrivateLendingService.lambdaQuery().eq(ProjectOwnerPrivateLending::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerPrivateLendings(projectOwnerPrivateLendings);
        //股权冻结
        List<ProjectOwnerEquityFreeze> projectOwnerEquityFreezes = projectOwnerEquityFreezeService.lambdaQuery().eq(ProjectOwnerEquityFreeze::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerEquityFreezes(projectOwnerEquityFreezes);
        //重大异常诉讼
        List<ProjectOwnerMajorAbnormalLitigation> projectOwnerMajorAbnormalLitigations = projectOwnerMajorAbnormalLitigationService.lambdaQuery().eq(ProjectOwnerMajorAbnormalLitigation::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerMajorAbnormalLitigations(projectOwnerMajorAbnormalLitigations);
        //严重违法
        List<ProjectOwnerSeriousIllegality> projectOwnerSeriousIllegalities = projectOwnerSeriousIllegalityService.lambdaQuery().eq(ProjectOwnerSeriousIllegality::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerSeriousIllegalities(projectOwnerSeriousIllegalities);
        //欠税公告
        List<ProjectOwnerTaxOweNotice> projectOwnerTaxOweNotices = projectOwnerTaxOweNoticeService.lambdaQuery().eq(ProjectOwnerTaxOweNotice::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerTaxOweNotices(projectOwnerTaxOweNotices);
        //税收违法
        List<ProjectOwnerTaxIllegalData> projectOwnerTaxIllegalData = projectOwnerTaxIllegalDataService.lambdaQuery().eq(ProjectOwnerTaxIllegalData::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerTaxIllegalDataList(projectOwnerTaxIllegalData);
        //黑名单信息
        List<ProjectOwnerBlacklist> projectOwnerBlacklists = projectOwnerBlacklistService.lambdaQuery().eq(ProjectOwnerBlacklist::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerBlacklists(projectOwnerBlacklists);
        //其他经营异常
        List<ProjectOwnerExceptionData> projectOwnerExceptionData = projectOwnerExceptionDataService.lambdaQuery().eq(ProjectOwnerExceptionData::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerExceptionDataList(projectOwnerExceptionData);
        //重大负面新闻舆情
        List<ProjectOwnerNews> projectOwnerNews = projectOwnerNewsService.lambdaQuery().eq(ProjectOwnerNews::getProjectAuditId, projectAudit.getId()).list();
        projectAudit.setProjectOwnerNewsList(projectOwnerNews);
        //一键测算
        ProjectOwnerComprehensiveEvaluation projectOwnerComprehensiveEvaluation = projectOwnerComprehensiveEvaluationService.lambdaQuery().eq(ProjectOwnerComprehensiveEvaluation::getProjectAuditId, projectAudit.getId()).one();
        projectAudit.setProjectOwnerComprehensiveEvaluation(projectOwnerComprehensiveEvaluation);
        return projectAudit;
    }

    private void qcc(ProjectAudit projectAudit, ProjectInformation projectInformation){
        //项目业主 企业信息需要用历史的   因为会变动
        CEnterpriseHistory enterprise = enterpriseHistoryService.getById(projectInformation.getcEnterpriseHistoryId());
        projectInformation.setEnterprise(enterprise);
        projectAudit.setProjectInformation(projectInformation);
        //企查查
        String getProjectReviewInfoUrl = getProjectReviewInfo + "?comprehensiveRiskInvestigationId=" + enterprise.getcComprehensiveRiskInvestigationId();
        ResponseJson forObject = restTemplate.getForObject(getProjectReviewInfoUrl, ResponseJson.class);
        if(forObject != null){
            JSONObject result = new JSONObject(forObject.getData());
            String entType = result.getStr("entType");
            if(entType.equals("4")){
                projectAudit.setEnterpriseNature("enterpriseNature_1");
            }
            List<CRegStock> regStocks = result.getBeanList("cRegStocks", CRegStock.class);
            projectAudit.setRegStocks(regStocks);
            Long judgmentCount = result.getLong("judgmentCount");
            projectAudit.setInvolvingLitigationAccessCcount(judgmentCount);
            Long adminPenaltyCount = result.getLong("adminPenaltyCount");
            projectAudit.setAdministrativePenaltyAccessCcount(adminPenaltyCount);
            BigDecimal adminPenaltyAmount = result.getBigDecimal("adminPenaltyAmount");
            projectAudit.setAdministrativePenaltyAmount(adminPenaltyAmount);
            BigDecimal envPunishmentAmount = result.getBigDecimal("envPunishmentAmount");
            projectAudit.setEnvironmentalPenaltyAmount(envPunishmentAmount);
            List<CEquityFreezeData> equityFreezeDataList = result.getBeanList("equityFreezeDataList", CEquityFreezeData.class);
            projectAudit.setEquityFreezeDataList(equityFreezeDataList);
            List<CJudgmentDocuments> privateLendings = result.getBeanList("privateLendings", CJudgmentDocuments.class);
            projectAudit.setPrivateLendings(privateLendings);
            List<CJudgmentDocuments> majorAnomalies = result.getBeanList("majorAnomalies", CJudgmentDocuments.class);
            projectAudit.setMajorAnomalies(majorAnomalies);
            List<CSeriousIllegalData> seriousIllegalData = result.getBeanList("seriousIllegalData", CSeriousIllegalData.class);
            projectAudit.setSeriousIllegalData(seriousIllegalData);
            List<CTaxOweNoticeData> taxOweNoticeData = result.getBeanList("taxOweNoticeData", CTaxOweNoticeData.class);
            projectAudit.setTaxOweNoticeData(taxOweNoticeData);
            List<CTaxIllegalData> taxIllegalData = result.getBeanList("taxIllegalData", CTaxIllegalData.class);
            projectAudit.setTaxIllegalData(taxIllegalData);
            List<CBlacklist> blacklists = result.getBeanList("blacklists", CBlacklist.class);
            projectAudit.setBlacklists(blacklists);
            List<CExceptionData> exceptionData = result.getBeanList("exceptionData", CExceptionData.class);
            projectAudit.setExceptionData(exceptionData);
            List<CNews> news = result.getBeanList("news", CNews.class);
            projectAudit.setNews(news);
        }
    }
}
