From 838618d0d4a7dd3b585a3a7390fa389e555c9bb0 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期一, 22 六月 2026 15:44:40 +0800
Subject: [PATCH] feat:新增通方公司工业品买卖合同新增
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 101 insertions(+), 16 deletions(-)
diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
index bf5f56e..7a97217 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
@@ -33,7 +33,6 @@
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
@@ -278,10 +277,10 @@
.eq(ContractSubjectMatter::getContractId,id));
if (ArrayUtil.isNotEmpty(subjectMatterList.toArray())) {
- subjectMatterList.stream().forEach(contractSubjectMatter -> {
+ for (ContractSubjectMatter contractSubjectMatter: subjectMatterList) {
if (StrUtil.equals(contract.getExecFrequency(), "1")) {
Long weeksTrue = DateUtil.betweenWeek(DateUtil.beginOfWeek(contract.getEffectiveDate()),
- DateUtil.endOfWeek(contract.getExpirationDate()), true);
+ DateUtil.endOfWeek(contract.getExpirationDate()), true)+1;
//寰幆鏃ユ湡
Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfWeek(contract.getEffectiveDate()), contract.getExecDay());
for (int i = 0; i < weeksTrue.intValue(); i++) {
@@ -298,7 +297,7 @@
}
if (StrUtil.equals(contract.getExecFrequency(), "2")) {
Long weeksTrue = DateUtil.betweenMonth(DateUtil.beginOfMonth(contract.getEffectiveDate()),
- DateUtil.endOfMonth(contract.getExpirationDate()), true);
+ DateUtil.endOfMonth(contract.getExpirationDate()), true)+1;
//寰幆鏃ユ湡
Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfMonth(contract.getEffectiveDate()), contract.getExecDay());
for (int i = 0; i < weeksTrue.intValue(); i++) {
@@ -314,11 +313,11 @@
}
}
if (StrUtil.equals(contract.getExecFrequency(), "3")) {
- Long weeksTrue = DateUtil.betweenMonth(DateUtil.beginOfQuarter(contract.getEffectiveDate()),
- DateUtil.endOfQuarter(contract.getExpirationDate()), true)/3;
+ Long weeksTrue = (DateUtil.betweenMonth(DateUtil.beginOfQuarter(contract.getEffectiveDate()),
+ DateUtil.endOfQuarter(contract.getExpirationDate()), true)+1)/3;
//寰幆鏃ユ湡
- Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfWeek(contract.getExpirationDate()), contract.getExecDay());
+ Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfQuarter(contract.getEffectiveDate()), contract.getExecDay());
for (int i = 0; i < weeksTrue.intValue(); i++) {
Date execDatei = DateUtil.offsetMonth(execDate0, i*3);
ContractExecDate execDate = new ContractExecDate();
@@ -348,9 +347,9 @@
if (7<=endMonth&&endMonth<=12){
endDate = DateUtil.endOfYear(endDate);
}
- Long weeksTrue = DateUtil.betweenMonth(startDate,endDate, true)/6;
+ Long weeksTrue = (DateUtil.betweenMonth(startDate,endDate, true)+1)/6;
//寰幆鏃ユ湡
- Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfWeek(contract.getExpirationDate()), contract.getExecDay());
+ Date execDate0 = DateUtil.offsetDay(startDate, contract.getExecDay());
for (int i = 0; i < weeksTrue.intValue(); i++) {
Date execDatei = DateUtil.offsetMonth(execDate0, i*6);
ContractExecDate execDate = new ContractExecDate();
@@ -365,7 +364,7 @@
}
if (StrUtil.equals(contract.getExecFrequency(), "5")) {
Long weeksTrue = DateUtil.betweenWeek(DateUtil.beginOfYear(contract.getEffectiveDate()),
- DateUtil.endOfYear(contract.getExpirationDate()), true);
+ DateUtil.endOfYear(contract.getExpirationDate()), true)+1;
//寰幆鏃ユ湡
Date execDate0 = DateUtil.offsetDay(DateUtil.beginOfYear(contract.getEffectiveDate()), contract.getExecDay());
for (int i = 0; i < weeksTrue.intValue(); i++) {
@@ -381,7 +380,7 @@
}
}
- });
+ }
}
} else {
ContractPaymentSchedule fitstSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
@@ -698,7 +697,7 @@
map.put("items", items);
//瀹氬埗鏂�
BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
- map.put("companyName", customer.getCompanyName());
+ map.put("companyName", customer.getRegisterName());
map.put("legalPerson", customer.getLegalPerson());
map.put("contactPhone", customer.getContactPhone());
map.put("bankName", customer.getBankName());
@@ -867,7 +866,7 @@
map.put("items", items);
//瀹氬埗鏂�
BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
- map.put("companyName", customer.getCompanyName());
+ map.put("companyName", customer.getRegisterName());
map.put("legalPerson", customer.getLegalPerson());
map.put("contactPhone", customer.getContactPhone());
map.put("bankName", customer.getBankName());
@@ -953,7 +952,7 @@
map.put("items", items);
//瀹氬埗鏂�
BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
- map.put("companyName", customer.getCompanyName());
+ map.put("companyName", customer.getRegisterName());
map.put("legalPerson", customer.getLegalPerson());
map.put("contactPhone", customer.getContactPhone());
map.put("bankName", customer.getBankName());
@@ -1088,7 +1087,7 @@
map.put("items", items);
//瀹氬埗鏂�
BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
- map.put("companyName", customer.getCompanyName());
+ map.put("companyName", customer.getRegisterName());
map.put("legalPerson", customer.getLegalPerson());
map.put("contactPhone", customer.getContactPhone());
map.put("bankName", customer.getBankName());
@@ -1148,6 +1147,8 @@
Map<String,Object> map = new HashMap<>();
map.put("contractId",contract.getId());
map.put("contractName",contract.getContractName());
+ map.put("partyA",contract.getPartyA());
+ map.put("partyB",contract.getPartyB());
map.put("delayDay",dto.getDelayDay());
map.put("applyName",SecurityUtils.getUser().getUsername());
map.put("applyTime",DateUtil.format(delayOut.getApplyTime(),DatePattern.NORM_DATETIME_FORMAT));
@@ -1165,7 +1166,91 @@
@Override
public Page pageScope(Page page, ContracQueryDTO queryDTO) {
-
return baseMapper.pageScope(page,queryDTO, DataScope.of("comp_id"));
}
+
+ @Override
+ public void exportContractTFGSGYPMMWord(Long id, HttpServletResponse response) {
+ Contract contract = baseMapper.selectById(id);
+ List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId, id).orderByAsc(ContractSubjectMatter::getCreateTime));
+ Map<String, Object> map = new HashMap<>();
+ //鍚堝悓鍩烘湰淇℃伅
+ map.put("partyA", contract.getPartyA());
+ map.put("partyB", contract.getPartyB());
+ map.put("contractNo", contract.getContractNo());
+ map.put("signPlace", contract.getSignPlace());
+ map.put("signDate", DateUtil.formatDate(contract.getSignDate()));
+ map.put("signDateYMD", DateUtil.format(contract.getSignDate(), DatePattern.CHINESE_DATE_PATTERN));
+ map.put("total", contract.getAmount());
+ map.put("amountWords", Convert.digitToChinese(contract.getAmount()));
+ //鏍囩殑鐗�
+ List<Map<String, Object>> items = new ArrayList<>();
+ List<RowRenderData> dataList = new ArrayList<>();
+ AtomicReference<Integer> no = new AtomicReference<>(0);
+ subjectMatterList.stream().forEach(contractSubjectMatter -> {
+ Map<String, Object> item = new HashMap<>();
+ item.put("materialName", contractSubjectMatter.getMaterialName());
+ item.put("guige", contractSubjectMatter.getSpecification());
+ item.put("unit", contractSubjectMatter.getUnit());
+ item.put("quantity", contractSubjectMatter.getQuantity());
+ item.put("unitPrice", contractSubjectMatter.getUnitPrice());
+ item.put("price", contractSubjectMatter.getTotalAmount());
+
+ items.add(item);
+ no.updateAndGet(v -> v + 1);
+ });
+ map.put("items", items);
+ //瀹氬埗鏂�
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ map.put("companyName", customer.getRegisterName());
+ map.put("legalPerson", customer.getLegalPerson());
+ map.put("contactPhone", customer.getContactPhone());
+ map.put("bankName", customer.getBankName());
+ map.put("bankAccount", customer.getBankAccount());
+
+ //鎵挎徑鏂�
+ R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
+ SysDept dept = r.getData();
+ map.put("orgName", dept.getOrgName());
+ map.put("legalPerson1", StrUtil.isNotEmpty(dept.getLegalPerson()) ? dept.getLegalPerson() : "");
+ map.put("entrustedAgent", StrUtil.isNotEmpty(dept.getLegalPerson()) ? "" : dept.getEntrustedAgent());
+ map.put("orgContact", dept.getOrgContact());
+ map.put("orgBank", dept.getOrgBank());
+ map.put("orgBankAccount", dept.getOrgBankAccount());
+
+ //鐢熸垚鏂囦欢鍚�
+ Long time = new Date().getTime();
+ // 鐢熸垚鐨剋ord鏍煎紡
+ String formatSuffix = ".docx";
+ // 鎷兼帴鍚庣殑鏂囦欢鍚�
+ String fileName = time + formatSuffix;//鏂囦欢鍚� 甯﹀悗缂�
+ //瀵煎嚭word
+ try {
+ // 1. 鍔犺浇妯$増
+ // 鍋囪妯$増鍦� resources/templates/template.docx
+ ClassPathResource resource = new ClassPathResource("template/tfgs/tfgsgypmmht.docx");
+ // 閰嶇疆鍒楄〃绛栫暐
+ Configure config = Configure.builder()
+ .bind("items", new LoopRowTableRenderPolicy()) // 灏� items 缁戝畾鍒拌寰幆绛栫暐
+ .build();
+ // 2. 缂栬瘧骞舵覆鏌撴暟鎹�
+ XWPFTemplate xwpfTemplate = XWPFTemplate.compile(resource.getInputStream(), config).render(map);
+
+ // 3. 璁剧疆鍝嶅簲澶�
+ response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+ response.setCharacterEncoding("utf-8");
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".docx");
+
+ // 4. 鍐欏叆杈撳嚭娴�
+ OutputStream out = response.getOutputStream();
+ xwpfTemplate.write(out);
+ out.flush();
+ out.close();
+ xwpfTemplate.close(); // 閲嶈锛氬叧闂ā鐗堥噴鏀捐祫婧�
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
}
--
Gitblit v1.9.1