From bc4f6588b92d207bef56edf3b5b38d8e4e2b8236 Mon Sep 17 00:00:00 2001
From: 6c <420680616@qq.com>
Date: 星期四, 12 六月 2025 16:34:11 +0800
Subject: [PATCH] 合同管理

---
 src/main/java/com/product/contract/service/ContractInfoService.java |  155 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 126 insertions(+), 29 deletions(-)

diff --git a/src/main/java/com/product/contract/service/ContractInfoService.java b/src/main/java/com/product/contract/service/ContractInfoService.java
index a74ed68..5893e8e 100644
--- a/src/main/java/com/product/contract/service/ContractInfoService.java
+++ b/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;
@@ -17,7 +19,11 @@
 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
@@ -46,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());
@@ -126,9 +135,19 @@
      */
     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");
-    	
         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);
     }
 
     /**
@@ -139,30 +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.LX_PROJECT_INFO,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);
-            }
+        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"));
         }
-        fss.setValue("invoiced",invoiced);
-        fss.setValue("payment_received",payment_received);
-        fss.setValue("project_num",fsProject.getString("project_num"));
-        fss.setValue("project_name",fsProject.getString("project_name"));
+        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("collection_amount",0);
         return fss;
     }
 
@@ -188,7 +199,7 @@
         if(fss!=null){
             fsinvo = baseDao.getFieldSetEntityByFilter(CmnConst.LX_PROJECT_CONTRACT_INVOICE,"contract_name=?",new Object[]{fss.getUUID()},true);
             fspaym = baseDao.getFieldSetEntityByFilter(CmnConst.LX_PROJECT_CONTRACT_PAYMENT,"contract_name=?",new Object[]{fss.getUUID()},true);
-            dtproj = baseDao.listTable(CmnConst.LX_PROJECT_INFO," uuid=? ",new Object[]{fss.getString("project_uuid")});
+            dtproj = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BUSINESS," uuid=? ",new Object[]{fss.getString("project_uuid")});
         }
         DataTableEntity dt = fss.getSubDataTable(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB);
         FieldSetEntity fsub = null;
@@ -235,9 +246,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);//瀹屾垚椤圭洰
@@ -268,7 +279,7 @@
      */
     public String isAddContract(FieldSetEntity fs) throws BaseException {
         String uuid = fs.getUUID();
-        DataTableEntity dataTableEntity = baseDao.listTable(" SELECT * FROM product_project_contract_info where flow_flag = 2 AND project_uuid = ? ", new String[]{uuid});
+        DataTableEntity dataTableEntity = baseDao.listTable(" SELECT * FROM product_project_contract_info where   project_uuid = ? ", new String[]{uuid});
         if (BaseUtil.dataTableIsEmpty(dataTableEntity)) {
             return "0";
         } else {
@@ -454,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;
+    }
 }

--
Gitblit v1.9.2