From a0974f04b5a83e3ab152ce79e53f180e7b496165 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期一, 08 六月 2026 15:00:51 +0800
Subject: [PATCH] fix:发票管理模块

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java |  361 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 353 insertions(+), 8 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 029813d..bec5082 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
@@ -36,6 +36,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
@@ -58,7 +59,7 @@
 	private final MeterReadRecordMapper meterReadRecordMapper;
 	private final ContractExecDateMapper contractExecDateMapper;
 	private final RemoteFlowProcessService remoteFlowProcessService;
-	private final ContractTemplateMapper contractTemplateMapper;
+	private final ProductMapper productMapper;
 	private final RemoteDeptService remoteDeptService;
 
 	@Value("${file.local.base-path}")
@@ -179,6 +180,19 @@
 				subjectMatter.setDeliveredQuantity(new BigDecimal("0"));
 				subjectMatter.setDeliveryStatus(0);
 				contractSubjectMatterMapper.insert(subjectMatter);
+				//姘寸數绫诲繀椤绘湁鍒濇琛ㄥ彿
+				if (StrUtil.isNotEmpty(contractSubjectMatterAddDTO.getMeterReadCode()) &&
+						ObjUtil.isNotNull(contractSubjectMatterAddDTO.getMeterReadNum())) {
+					meterReadRecordMapper.delete(Wrappers.<MeterReadRecord>lambdaQuery().eq(MeterReadRecord::getContractId, contract.getId()));
+					MeterReadRecord record = BeanUtil.copyProperties(contractSubjectMatterAddDTO, MeterReadRecord.class,"id");
+					record.setContractId(contract.getId());
+					record.setMatterId(subjectMatter.getId());
+					record.setContractName(contract.getContractName());
+					record.setBusGuestId(contract.getPartyAId());
+					record.setBusGuestName(contract.getPartyA());
+					record.setMeterReadTime(new Date());
+					meterReadRecordMapper.insert(record);
+				}
 			});
 		}
 
@@ -222,6 +236,10 @@
 		detailVo.setContractSubjectMatter(subjectMatterList);
 		List<ContractPaymentSchedule> paymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()));
 		detailVo.setContractPaymentSchedule(paymentScheduleList);
+		BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId());
+		if (ObjUtil.isNotNull(a)){
+			detailVo.setPartyAOrgCode(a.getCreditCode());
+		}
 		return detailVo;
 	}
 
@@ -506,7 +524,6 @@
 				PaymentConfirm oiverdueConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getScheduleId, contractPaymentSchedule.getId())
 						.eq(PaymentConfirm::getBusinessType, "搴旀敹瓒呮湡"));
 				if (ObjUtil.isNull(oiverdueConfirm) && overdueConfirm.getTransationAmount().compareTo(new BigDecimal("0")) > 0) {
-					overdueConfirm.setCompId(contractPaymentSchedule.getCompId());
 					paymentConfirmMapper.insert(overdueConfirm);
 				}
 				//褰撳墠閫炬湡
@@ -525,7 +542,6 @@
 				CurrentOverdue overdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getContractId, currentOverdue.getContractId())
 						.eq(CurrentOverdue::getScheduleId, currentOverdue.getScheduleId()).last("limit 1"));
 				if (ObjUtil.isNull(overdue)) {
-					currentOverdue.setCompId(contractPaymentSchedule.getCompId());
 					if (currentOverdue.getReceivableAmount().compareTo(new BigDecimal("0")) > 0) {
 						currentOverdueMapper.insert(currentOverdue);
 					}
@@ -607,11 +623,11 @@
 			Map<String, Object> item = new HashMap<>();
 			item.put("no", no);
 			item.put("materialName", contractSubjectMatter.getMaterialName());
-			item.put("guige", "");
-			item.put("unit", "");
+			item.put("guige", contractSubjectMatter.getSpecification());
+			item.put("unit", contractSubjectMatter.getUnit());
 			item.put("quantity", contractSubjectMatter.getQuantity());
-			item.put("danzhong", "");
-			item.put("zongzhong", "");
+			item.put("danzhong", contractSubjectMatter.getSingleWight());
+			item.put("zongzhong", contractSubjectMatter.getTotalWight());
 			item.put("unitPrice", contractSubjectMatter.getUnitPrice());
 			item.put("price", contractSubjectMatter.getTotalAmount());
 			items.add(item);
@@ -646,7 +662,7 @@
 		try {
 			// 1. 鍔犺浇妯$増
 			// 鍋囪妯$増鍦� resources/templates/template.docx
-			ClassPathResource resource = new ClassPathResource("template/ymjjgclht.docx");
+			ClassPathResource resource = new ClassPathResource("template/ymj/ymjjgclht.docx");
 			// 閰嶇疆鍒楄〃绛栫暐
 			Configure config = Configure.builder()
 					.bind("items", new LoopRowTableRenderPolicy()) // 灏� items 缁戝畾鍒拌寰幆绛栫暐
@@ -689,6 +705,25 @@
 					record.setBusGuestName(contract.getPartyA());
 					meterReadRecordMapper.insert(record);
 				}else {
+					//鍒涘缓鏀舵鑺傜偣
+					//鏌ヨ涓婃鏀舵鑺傜偣
+					ContractPaymentSchedule lastSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery()
+							.eq(ContractPaymentSchedule::getContractId,contract.getId())
+							.orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
+					ContractPaymentSchedule schedule = new ContractPaymentSchedule();
+					schedule.setStageName("鎴跨绉熻祦缂磋垂");
+					schedule.setContractId(contract.getId());
+					schedule.setContractName(contract.getContractName());
+					schedule.setPlannedAmount(subjectMatter.getUnitPrice().multiply(subjectMatter.getQuantity()));
+					schedule.setEffectiveEndDate(contractExecDate.getExecDate());
+					schedule.setStageOrder(1);
+					if (ObjUtil.isNotNull(lastSchedule)){
+						schedule.setStageOrder(lastSchedule.getStageOrder()+1);
+					}
+					schedule.setPaymentStatus(0);
+					schedule.setActualAmount(new BigDecimal("0"));
+					schedule.setCompId(contract.getCompId());
+					contractPaymentScheduleMapper.insert(schedule);
 					//鎴垮眿绉熻祦鐢熸垚搴旀敹
 					PaymentConfirm confirm = new PaymentConfirm();
 					confirm.setBusinessType("鎴垮眿绉熻祦搴旀敹");
@@ -697,6 +732,8 @@
 					confirm.setContractId(contract.getId());
 					confirm.setContractName(contract.getContractName());
 					confirm.setContractNo(contract.getContractNo());
+					confirm.setScheduleId(schedule.getId());
+					confirm.setScheduleName(schedule.getStageName());
 					confirm.setConfirmTime(contractExecDate.getExecDate());
 					confirm.setTransationAmount(subjectMatter.getUnitPrice().multiply(subjectMatter.getQuantity()));
 					confirm.setTotalAmount(confirm.getTransationAmount().multiply(new BigDecimal("-1")));
@@ -728,4 +765,312 @@
 		}
 		return R.ok();
 	}
+
+	@Override
+	public void exportContractYMJGYPMMWord(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("no", no);
+			item.put("materialName", contractSubjectMatter.getMaterialName());
+			item.put("guige", contractSubjectMatter.getSpecification());
+			item.put("unit", contractSubjectMatter.getUnit());
+			item.put("quantity", contractSubjectMatter.getQuantity());
+			item.put("danzhong", contractSubjectMatter.getSingleWight());
+			item.put("zongzhong", contractSubjectMatter.getTotalWight());
+			item.put("unitPrice", contractSubjectMatter.getUnitPrice());
+			item.put("price", contractSubjectMatter.getTotalAmount());
+			if (no.get().equals(Integer.valueOf(0))){
+				item.put("deliveryCycle",contract.getDeliveryCycle());
+			}
+			items.add(item);
+			no.updateAndGet(v -> v + 1);
+		});
+		map.put("items", items);
+		//瀹氬埗鏂�
+		BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+		map.put("companyName", customer.getCompanyName());
+		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/ymj/ymjgypmmht.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();
+		}
+	}
+
+	@Override
+	public void exportContractYMJGKCPMMWord(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()));
+		map.put("deliveryCycle",contract.getDeliveryCycle());
+		//鏍囩殑鐗�
+		List<Map<String, Object>> items = new ArrayList<>();
+		AtomicReference<Integer> no = new AtomicReference<>(0);
+		subjectMatterList.stream().forEach(contractSubjectMatter -> {
+			Map<String, Object> item = new HashMap<>();
+			item.put("no", no);
+			item.put("materialName", contractSubjectMatter.getMaterialName());
+			item.put("guige", contractSubjectMatter.getSpecification());
+			item.put("unit", contractSubjectMatter.getUnit());
+			item.put("quantity", contractSubjectMatter.getQuantity());
+			item.put("danzhong", contractSubjectMatter.getSingleWight());
+			item.put("zongzhong", contractSubjectMatter.getTotalWight());
+			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.getCompanyName());
+		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/ymj/ymjgkcpmmht.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();
+		}
+	}
+
+	@Override
+	public void exportContractYMJCGWord(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()));
+		map.put("environment",contract.getEnvironment());
+		map.put("standard",contract.getStandard());
+		map.put("useMonth",contract.getUseMonth());
+		map.put("afterShipMonth",contract.getAfterShipMonth());
+		map.put("shipMethod",contract.getShipMethod());
+		map.put("shipAddress",contract.getShipAddress());
+		map.put("packaging",contract.getPackaging());
+		map.put("repairPeriod",contract.getRepairPeriod());
+		map.put("repairBreachAmount",contract.getRepairBreachAmount());
+		map.put("goodsShort",contract.getGoodsShort());
+		map.put("goodsShortBreachAmount",contract.getGoodsShortBreachAmount());
+		map.put("overdueBreachAmount",contract.getOverdueBreachAmount());
+		map.put("terminateContract",contract.getTerminateContract());
+		map.put("court",contract.getCourt());
+		map.put("contractAttchment",contract.getContractAttchment());
+		map.put("invoiceNotice",contract.getInvoiceNotice());
+
+		//鏍囩殑鐗�
+		List<Map<String, Object>> items = new ArrayList<>();
+		AtomicReference<Integer> no = new AtomicReference<>(0);
+		subjectMatterList.stream().forEach(contractSubjectMatter -> {
+			Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode,contractSubjectMatter.getMaterialCode()).last("limit 1"));
+			Map<String, Object> item = new HashMap<>();
+			item.put("no", no);
+			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("priceTax", contractSubjectMatter.getUnitPrice().multiply(contractSubjectMatter.getQuantity()).setScale(2, RoundingMode.HALF_UP));
+			item.put("priceNoTax", contractSubjectMatter.getUnitPrice().multiply(contractSubjectMatter.getQuantity())
+					.subtract(contractSubjectMatter.getUnitPrice().multiply(contractSubjectMatter.getQuantity())
+							.divide(new BigDecimal("100").add(new BigDecimal(product.getTaxRate())),2, RoundingMode.HALF_UP).multiply(new BigDecimal(product.getTaxRate())))
+					.setScale(2, RoundingMode.HALF_UP));
+			item.put("deliveryDate", DateUtil.formatDate(contractSubjectMatter.getPlannedDeliveryDate()));
+			item.put("remarks", contractSubjectMatter.getRemarks());
+			map.put("taxRate",product.getTaxRate());
+			items.add(item);
+			no.updateAndGet(v -> v + 1);
+		});
+
+		//浠樻
+		List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
+				.eq(ContractPaymentSchedule::getContractId, id).orderByAsc(ContractPaymentSchedule::getCreateTime));
+		scheduleList.stream().forEach(contractPaymentSchedule -> {
+			if (contractPaymentSchedule.getStageName().equals("鍚堝悓绛捐")){
+				map.put("htqdbl",contractPaymentSchedule.getPaymentRatio());
+				map.put("htqdje",contractPaymentSchedule.getPlannedAmount());
+				map.put("htqdjr",contractPaymentSchedule.getAgreedDays());
+			}
+			if (contractPaymentSchedule.getStageName().equals("鍙戣揣鍓�")){
+				map.put("fhqbl",contractPaymentSchedule.getPaymentRatio());
+				map.put("fhqje",contractPaymentSchedule.getPlannedAmount());
+			}
+			if (contractPaymentSchedule.getStageName().equals("璋冭瘯瀹屾垚鎴栭獙鏀�")){
+				map.put("ysbl",contractPaymentSchedule.getPaymentRatio());
+				map.put("ysje",contractPaymentSchedule.getPlannedAmount());
+				map.put("ysjr",contractPaymentSchedule.getAgreedDays());
+			}
+			if (contractPaymentSchedule.getStageName().equals("璐ㄤ繚閲�")){
+				map.put("zbjbl",contractPaymentSchedule.getPaymentRatio());
+				map.put("zbjje",contractPaymentSchedule.getPlannedAmount());
+				map.put("zbjjr",contractPaymentSchedule.getAgreedDays());
+			}
+		});
+		map.put("items", items);
+		//瀹氬埗鏂�
+		BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+		map.put("companyName", customer.getCompanyName());
+		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/ymj/ymjcght.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