杜洪波
2025-03-14 38eaaa83c6ba703edfa90e72054b5548dbeb07e0
src/main/java/com/product/contract/service/ContractInfoService.java
@@ -14,9 +14,12 @@
import com.product.core.transfer.Transactional;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import org.apache.bcel.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
@@ -127,8 +130,44 @@
    public FieldSetEntity findContractInfo(FieldSetEntity fs) throws BaseException {
       FieldSetEntity cfs =baseDao.getFieldSetEntity(CmnConst.LX_PROJECT_CONTRACT_INFO,fs.getUUID(),true);
       DataTableEntity sub=cfs.getSubDataTable("product_project_contract_info_sub");
        StringBuilder  filter=new StringBuilder(128);
        filter.append(" uuid='"+cfs.getValues().get("project_uuid")+"'");
        DataTableEntity product_project_business = baseDao.listTable("product_project_business",filter.toString(),new Object[]{});
//        String guarantee_period = product_project_business.getData().get(0).getValues().get("guarantee_period").toString();
        String guarantee_period = product_project_business.getString(0, "guarantee_period");
        StringBuilder  dictFilter=new StringBuilder(128);
        dictFilter.append("dict_name='项目管理项目类型' and dict_value="+product_project_business.getData().get(0).getValues().get("project_type").toString());
        DataTableEntity product_sys_dict = baseDao.listTable("product_sys_dict", dictFilter.toString(), new Object[]{});
       //合同有效期:如果是开发项目、实施项目,从项目信息的质保期带过来
        String dict_label = product_sys_dict.getData().get(0).getValues().get("dict_label").toString();
        if(dict_label.equals("开发项目") ||dict_label.equals("实施项目")){
            cfs.setValue("guarantee_period",guarantee_period);
            cfs.setValue("project_type_now",dict_label);
        }
       //结束日期: 如果是开发项目、实施项目,验收日期+合同有效期,维护合同则是签定日期+合同有效期
        if(dict_label.equals("开发项目") || dict_label.equals("实施项目")){
//            String carefully_check = product_project_business.getData().get(0).getValues().get("carefully_check").toString();
            String carefully_check = product_project_business.getString(0, "carefully_check");
            if (!StringUtils.isEmpty(carefully_check)){
                String[] dateTime = carefully_check.split(" ");
                String time=dateTime[0];
                String date = getDate(time,guarantee_period);
                cfs.setValue("end_time",date);
            }
        }
        return cfs;
    }
    //日期计算方式
    public String  getDate(String dateTime,String carefully_time){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date = LocalDate.parse(dateTime, formatter);
        // 加上指定的月份数,例如加3个月
        LocalDate newDate = date.plusMonths(Integer.parseInt(carefully_time));
         return  newDate.format(formatter);
    }
    /**
@@ -140,27 +179,15 @@
    public FieldSetEntity getContractInfoByName(FieldSetEntity fs) throws BaseException {
        FieldSetEntity fss = baseDao.getFieldSetEntity(CmnConst.LX_PROJECT_CONTRACT_INFO,fs.getUUID(),true);
        FieldSetEntity fsProject = baseDao.getFieldSetEntity(CmnConst.PRODUCT_PROJECT_BUSINESS,fss.getString("project_uuid"),false);
        DataTableEntity dt = fss.getSubDataTable(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB);
        FieldSetEntity fsub = null;
        int invoiced = 0;//已开票金额
        int payment_received = 0;//已回款金额
        if(dt!=null && dt.getRows()>0){
            for (int i = 0; i < dt.getRows(); i++) {
                fsub = dt.getFieldSetEntity(i);
                String invo = fsub.getString("invoiced");
                String paym = fsub.getString("payment_received");
                if(BaseUtil.strIsNull(invo)){
                    invo = "0";
                }
                if(BaseUtil.strIsNull(paym)){
                    paym = "0";
                }
                invoiced += Double.parseDouble(invo);
                payment_received += Double.parseDouble(paym);
            }
        FieldSetEntity fsCustomer = baseDao.getFieldSet("product_project_customer", fsProject.getString("customer_name"), false);
        FieldSetEntity contractName = baseDao.getFieldSetEntityBySQL("SELECT sum(invoice_amount) invoice_amount FROM product_project_contract_invoice_info WHERE contract_invoice_uuid in(SELECT uuid FROM product_project_contract_invoice where contract_name=?)", new String[]{fs.getString("uuid")},false);
        if (contractName==null||StringUtils.isEmpty(contractName.getString("invoice_amount"))){
            fss.setValue("invoice_amount",0);
        }else {
            fss.setValue("invoice_amount",contractName.getString("invoice_amount"));
        }
        fss.setValue("invoiced",invoiced);
        fss.setValue("payment_received",payment_received);
        fss.setValue("customer_name", fsCustomer.getString("customer_name"));
        fss.setValue("collection_amount",0);
        fss.setValue("project_num",fsProject.getString("project_num"));
        fss.setValue("project_name",fsProject.getString("project_name"));
        return fss;
@@ -235,9 +262,9 @@
            }
        }
        fss.setValue("invoiced",invoiced);//已开票金额
        fss.setValue("uinvoiced",fss.getInteger("contract_amount")-invoiced);//未开票金额
        fss.setValue("uinvoiced",fss.getDouble("contract_amount")-invoiced);//未开票金额
        fss.setValue("payment_received",payment_received);//已回款金额
        fss.setValue("upayment_received",fss.getInteger("contract_amount")-payment_received);//未回款金额
        fss.setValue("upayment_received",fss.getDouble("contract_amount")-payment_received);//未回款金额
        fss.setValue("project_total",dtproj.getRows());//项目数
        fss.setValue("projecting",projecting);//在建项目
        fss.setValue("projected",projected);//完成项目