6c
昨天 bc4f6588b92d207bef56edf3b5b38d8e4e2b8236
合同管理
已修改5个文件
233 ■■■■ 文件已修改
src/main/java/com/product/contract/config/CmnConst.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/contract/config/SystemCode.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/contract/controller/ContractInfoController.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/contract/service/ContractInfoService.java 134 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/contract/service/ContractPaymentService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/contract/config/CmnConst.java
@@ -26,6 +26,7 @@
    public static final String PRODUCT_PROJECT_BUSINESS = "product_project_business";//项目表
    public static final String PRODUCT_PROJECT_BUSINESS_PLAN = "product_project_business_plan";//项目计划表
    public static final String PRODUCT_PROJECT_MANAGER_DATA_LIST = "product_project_manager_data_list";//资料表
    public static final String PRODUCT_PROJECT_CONTRACT_INVOICE_INFO = "product_project_contract_invoice_info";// 开票明细
    //常量定义
    public static final String UUID = "uuid"; // uuid
@@ -39,5 +40,7 @@
    public static final String PROJECT_UUID = "project_uuid";
    public static final String PROJECT_TYPE = "project_type";
    public static final String CONTRACT_STATUS = "contract_status";
}
src/main/java/com/product/contract/config/SystemCode.java
@@ -91,6 +91,10 @@
    SYSTEM_FIND_CONTRACT_PROJECT_TRANSLATE_FAIL("获取项目进度模版详情失败", ModuleEnum.CONTRACT.getValue() + "049"),
    SYSTEM_FIND_CONTRACT_PROJECT_TYPE_FAIL("项目类型错误", ModuleEnum.CONTRACT.getValue() + "050"),
    CHECK_INVOICE_NUMBER_FAIL("验证发票号是否重复失败", ModuleEnum.CONTRACT.getValue() + "051"),
    CHECK_INVOICE_PAYMENT_FAIL("验证发票回款是否超额失败", ModuleEnum.CONTRACT.getValue() + "052"),
    LIST_CONTRACT_INVOICE_AND_COLLECTION_FAIL("查询合同下的开票和回款记录失败", ModuleEnum.CONTRACT.getValue() + "053"),
    ;
    private String text;
src/main/java/com/product/contract/controller/ContractInfoController.java
@@ -1,5 +1,6 @@
package com.product.contract.controller;
import com.alibaba.fastjson.JSONObject;
import com.product.common.lang.StringUtils;
import com.product.contract.config.CmnConst;
import com.product.contract.config.SystemCode;
@@ -13,6 +14,7 @@
import com.product.core.exception.BaseException;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.module.sys.version.ApiVersion;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -206,7 +208,9 @@
                return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText());
            }
            FieldSetEntity fs = contractInfoService.findContractInfo(fse);
            return OK_List(fs);
            JSONObject resultObj = BaseUtil.fieldSetEntityToJson(fs);
            resultObj.put("~showType~", fse.getString("showType"));
            return OK(resultObj);
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
@@ -662,4 +666,85 @@
                    SystemCode.SYSTEM_SAVE_CONTRACT_FILE_FAIL.getText());
        }
    }
    /**
     * 验证发票号,不同次数的开票中不能有相同的发票号(同次的可以)
     * @param request
     * @return
     */
    @RequestMapping(value="/check-invoice-number/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String checkInvoiceNumber(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_PROJECT_CONTRACT_INVOICE_INFO);
            // 判断参数是否为空
            if (fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            return OK(contractInfoService.checkInvoiceNumber(fse));
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.CHECK_INVOICE_NUMBER_FAIL.getValue(), SystemCode.CHECK_INVOICE_NUMBER_FAIL.getText());
        }
    }
    /**
     * 验证发票号,单个发票的回款总额不能超过开票金额
     * @param request
     * @return
     */
    @RequestMapping(value="/check-invoice-payment/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String checkInvoicePayment(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_PROJECT_CONTRACT_INVOICE_INFO);
            // 判断参数是否为空
            if (fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            return OK(contractInfoService.checkInvoicePayment(fse));
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.CHECK_INVOICE_NUMBER_FAIL.getValue(), SystemCode.CHECK_INVOICE_NUMBER_FAIL.getText());
        }
    }
    /**
     * 查询合同下的开票和回款记录
     * @param request
     * @return
     */
    @RequestMapping(value="/list-contract-invoice-and-collection/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String listContractInvoiceAndCollection(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.LX_PROJECT_CONTRACT_INFO);
            // 判断参数是否为空
            if (fse == null) {
                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
                return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
            }
            return OK(contractInfoService.listContractInvoiceAndCollection(fse));
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return this.error(SystemCode.LIST_CONTRACT_INVOICE_AND_COLLECTION_FAIL.getValue(), SystemCode.LIST_CONTRACT_INVOICE_AND_COLLECTION_FAIL.getText());
        }
    }
}
src/main/java/com/product/contract/service/ContractInfoService.java
@@ -1,5 +1,7 @@
package com.product.contract.service;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.common.lang.StringUtils;
import com.product.contract.config.CmnConst;
import com.product.contract.service.ide.IContractInfoService;
@@ -14,13 +16,14 @@
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.Arrays;
import java.util.Date;
import java.util.List;
/**
 * Copyright LX
@@ -49,6 +52,9 @@
    @Override
    @Transactional
    public String saveContractInfo(FieldSetEntity fs) throws BaseException {
        if (StringUtils.isEmpty(fs.getString(CmnConst.CONTRACT_STATUS))) {
            fs.setValue(CmnConst.CONTRACT_STATUS, 0);
        }
        if(StringUtils.isEmpty(fs.getString(CmnConst.UUID))){
            fs.setValue("org_level_uuid", SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
            fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
@@ -129,32 +135,6 @@
     */
    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;
    }
@@ -178,18 +158,22 @@
     */
    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);
        FieldSetEntity fsCustomer = baseDao.getFieldSet("product_project_customer", fsProject.getString("customer_name"), false);
        if (!StringUtils.isEmpty(fss.getString("project_uuid"))) {
            FieldSetEntity fsProject = baseDao.getFieldSetEntity(CmnConst.PRODUCT_PROJECT_BUSINESS,fss.getString("project_uuid"),false);
            FieldSetEntity fsCustomer = baseDao.getFieldSet("product_project_customer", fsProject.getString("customer_name"), false);
            fss.setValue("customer_name", fsCustomer.getString("customer_name"));
            fss.setValue("project_num",fsProject.getString("project_num"));
            fss.setValue("project_name",fsProject.getString("project_name"));
        } else {
            fss.setValue("customer_name", fss.getString("owner"));
        }
        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("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;
    }
@@ -481,4 +465,90 @@
            return baseDao.update(fieldSetEntity);
        }
    }
    /**
     * 验证发票号,不同次数的开票中不能有相同的发票号(同次的可以)
     * @param fse
     * @return
     */
    public Object[] checkInvoiceNumber(FieldSetEntity fse) {
        String uuid = fse.getUUID();
        String[] invoiceNumberArr = fse.getString("invoice_num").split(",");
        StringBuilder filter = new StringBuilder(128);
        List<String> paramList  = Lists.newArrayList();
        if (!StringUtils.isEmpty(uuid)) {
            filter.append("contract_invoice_uuid<>? AND ");
            paramList.add(uuid);
        }
        filter.append(BaseUtil.buildQuestionMarkFilter("invoice_num", invoiceNumberArr.length, true));
        paramList.addAll(Arrays.asList(invoiceNumberArr));
        DataTableEntity dte = baseDao.listTable(CmnConst.PRODUCT_PROJECT_CONTRACT_INVOICE_INFO, filter.toString(), paramList.toArray());
        if (!DataTableEntity.isEmpty(dte)) {
            return dte.getFieldAllValues("invoice_num");
        }
        return new Object[]{};
    }
    /**
     * 验证发票号,单个发票的回款总额不能超过开票金额
     * @param fse
     * @return
     */
    public Object checkInvoicePayment(FieldSetEntity fse) {
        String uuid = fse.getUUID();
        DataTableEntity paramDte = fse.getSubDataTable("product_project_contract_payment_collection");
        StringBuilder partSql = new StringBuilder(256);
        for (int i = 0; i < paramDte.getRows(); i++) {
            if (partSql.length() > 0) {
                partSql.append("\n        UNION ALL");
            }
            FieldSetEntity paramFse = paramDte.getFieldSetEntity(i);
            partSql.append("\n        SELECT '").append(paramFse.getString("invoice_num")).append("' invoice_num,'").append(paramFse.getString("collection_amount")).append("' cur_payment_amount");
        }
        StringBuilder sql = new StringBuilder(256);
        sql.append("\nSELECT DISTINCT i.invoice_num,i.invoice_amount,i.payment_amount,p.cur_payment_amount,IFNULL(i.payment_amount,0) + p.cur_payment_amount - i.invoice_amount diff_amount");
        sql.append("\nFROM product_project_contract_invoice_info i");
        sql.append("\nLEFT JOIN product_project_contract_payment_collection ps ON i.invoice_num=ps.invoice_num");
        List<String> paramList = Lists.newArrayList();
        if (!StringUtils.isEmpty(uuid)) {
            sql.append(" AND ps.contract_payment_uuid<>?");
            paramList.add(uuid);
        }
        sql.append("\nINNER JOIN (");
        sql.append("\n    SELECT invoice_num,SUM(cur_payment_amount) cur_payment_amount");
        sql.append("\n    FROM (");
        sql.append(partSql);
        sql.append("\n    ) t");
        sql.append("\n    GROUP BY 1");
        sql.append("\n) p ON i.invoice_num=p.invoice_num");
        sql.append("\nWHERE i.invoice_amount - IFNULL(i.payment_amount,0) < p.cur_payment_amount");
        DataTableEntity resultDte = baseDao.listTable(sql.toString(), paramList.toArray());
        return BaseUtil.dataTableEntityToJson(resultDte);
    }
    /**
     * 查询合同下的开票和回款记录
     * @param fse
     * @return
     */
    public JSONObject listContractInvoiceAndCollection(FieldSetEntity fse) {
        String contractUUID = fse.getUUID();
        JSONObject resultObj = new JSONObject();
        StringBuilder sql = new StringBuilder(128);
        sql.append("\nSELECT id.*");
        sql.append("\nFROM product_project_contract_invoice_info id");
        sql.append("\nINNER JOIN product_project_contract_invoice i ON id.contract_invoice_uuid=i.uuid");
        sql.append("\nWHERE i.contract_name=?");
        DataTableEntity invoiceDte = baseDao.listTable(sql.toString(), new Object[]{contractUUID});
        resultObj.put("invoice", BaseUtil.dataTableEntityToJson(invoiceDte));
        sql.setLength(0);
        sql.append("\nSELECT c.*");
        sql.append("\nFROM product_project_contract_payment_collection c");
        sql.append("\nINNER JOIN product_project_contract_payment p ON c.contract_payment_uuid=p.uuid");
        sql.append("\nWHERE p.contract_name=?");
        DataTableEntity collectionDte = baseDao.listTable(sql.toString(), new Object[]{contractUUID});
        resultObj.put("collection", BaseUtil.dataTableEntityToJson(collectionDte));
        return resultObj;
    }
}
src/main/java/com/product/contract/service/ContractPaymentService.java
@@ -65,14 +65,15 @@
    private void writeBackPayment(FieldSetEntity fs){
        //回写发票号回款
        DataTableEntity dt = fs.getSubDataTable(CmnConst.LX_PROJECT_CONTRACT_PAYMENT_COLLECTION);
        String contractTermsUUID = fs.getString("contract_terms");
        for (int i = 0; i <dt.getRows() ; i++) {
            FieldSetEntity subFs = dt.getFieldSetEntity(i);
            FieldSetEntity collection_amount_fs = baseDao.getFieldSetBySQL("SELECT sum(collection_amount) collection_amount FROM `product_project_contract_payment_collection` where invoice_num=?", new String[]{subFs.getString("invoice_num")}, false);
            baseDao.executeUpdate("UPDATE product_project_contract_invoice_info set payment_amount=? where invoice_num=?",new String[]{collection_amount_fs.getString("collection_amount"),subFs.getString("invoice_num")});
            baseDao.executeUpdate("UPDATE product_project_contract_invoice_info set payment_amount=? where invoice_num=? AND contract_terms=?",new String[]{collection_amount_fs.getString("collection_amount"), subFs.getString("invoice_num"), contractTermsUUID});
        }
        //回写条款回款
        FieldSetEntity contractTerms = baseDao.getFieldSetBySQL("SELECT sum(collection_amount) collection_amount FROM `product_project_contract_payment_collection` \n" +
                "where contract_payment_uuid in(SELECT uuid FROM product_project_contract_payment where contract_terms=?)", new String[]{fs.getString("contract_terms")}, false);
                "where contract_payment_uuid in(SELECT uuid FROM product_project_contract_payment where contract_terms=?)", new String[]{contractTermsUUID}, false);
        if (contractTerms!=null&&!StringUtils.isEmpty(contractTerms.getString("collection_amount"))) {
            FieldSetEntity contractInfoSub = new FieldSetEntity();
            contractInfoSub.setTableName(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB);