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 | 134 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 102 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/product/contract/service/ContractInfoService.java b/src/main/java/com/product/contract/service/ContractInfoService.java index 4fccc04..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; @@ -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; + } } -- Gitblit v1.9.2