From e02812df9217d3e50a368a8234c07c60c64c0ff4 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 05 八月 2026 08:34:26 +0800
Subject: [PATCH] feat:新增石煤机 机械厂模版合同/客户数据主数据同步接口/合同履约进度新增质保结束操作/合同开票状态 修改为待开 可开 已开/出库逻辑完善

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java |  417 +++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 317 insertions(+), 100 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
index 328c86d..9d07ded 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -20,6 +20,8 @@
 import com.by4cloud.platformx.admin.api.feign.RemoteDeptService;
 import com.by4cloud.platformx.business.api.feign.RemoteFlowProcessService;
 import com.by4cloud.platformx.business.constant.FlowNameEnum;
+import com.by4cloud.platformx.business.dto.ContractInvoiceQueryDTO;
+import com.by4cloud.platformx.business.dto.ContractQueryDTO;
 import com.by4cloud.platformx.business.dto.GenInvoiceInfoDTO;
 import com.by4cloud.platformx.business.entity.*;
 import com.by4cloud.platformx.business.mapper.*;
@@ -27,6 +29,7 @@
 import com.by4cloud.platformx.business.service.PaymentConfirmService;
 import com.by4cloud.platformx.business.vo.*;
 import com.by4cloud.platformx.common.core.util.R;
+import com.by4cloud.platformx.common.data.datascope.DataScope;
 import com.by4cloud.platformx.common.data.mybatis.BaseModel;
 import com.by4cloud.platformx.common.security.util.SecurityUtils;
 import com.by4cloud.platformx.flow.task.dto.ProcessInstanceParamDto;
@@ -54,6 +57,10 @@
 	private final ContractMapper contractMapper;
 	private final BusinessCustomerMapper businessCustomerMapper;
 	private final ContractOutBoundMapper contractOutBoundMapper;
+	private final PaymentConfirmMapper paymentConfirmMapper;
+	private final ContractExecDateMapper contractExecDateMapper;
+	private final ContractPaymentScheduleMapper contractPaymentScheduleMapper;
+	private final MeterReadRecordMapper meterReadRecordMapper;
 	private final ContractSubjectMatterMapper subjectMatterMapper;
 	private final ProductMapper productMapper;
 	private final BwRequestRecordMapper bwRequestRecordMapper;
@@ -85,7 +92,7 @@
 				.selectAll(ContractOutBound.class)
 				.eq(ContractOutBound::getContractId, contractId);
 		List<ContractInvoiceOutBoundVo> invoiceOutBoundVoList = contractOutBoundMapper.selectJoinList(ContractInvoiceOutBoundVo.class, wrapper);
-		if (ArrayUtil.isNotEmpty(invoiceOutBoundVoList.toArray())){
+		if (ArrayUtil.isNotEmpty(invoiceOutBoundVoList.toArray())) {
 			invoiceOutBoundVoList.stream().forEach(contractInvoiceOutBoundVo -> {
 				contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(contractInvoiceOutBoundVo.getInvoiceNum()));
 				contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum());
@@ -95,12 +102,29 @@
 	}
 
 	@Override
+	public R getContractHouseWater(Long contractId) {
+		MPJLambdaWrapper<ContractPaymentSchedule> wrapper = new MPJLambdaWrapper<ContractPaymentSchedule>()
+				.selectAll(ContractPaymentSchedule.class)
+				.eq(ContractPaymentSchedule::getContractId, contractId)
+				.orderByAsc(ContractPaymentSchedule::getCreateTime);
+		List<ContractHouseWaterVo> invoiceOutBoundVoList = contractPaymentScheduleMapper.selectJoinList(ContractHouseWaterVo.class, wrapper);
+		return R.ok(invoiceOutBoundVoList);
+	}
+
+	@Override
 	public R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO) {
 		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
 			return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
 		}
-		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
-		Contract contract = contractMapper.selectById(outBound.getContractId());
+		Long contractId = null;
+		if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) {
+			ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
+			contractId = outBound.getContractId();
+		}else {
+			ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
+			contractId = schedule.getContractId();
+		}
+		Contract contract = contractMapper.selectById(contractId);
 		if (ObjUtil.isNull(contract)) {
 			return R.failed("鍚堝悓淇℃伅寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
 		}
@@ -117,7 +141,7 @@
 	private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) {
 		GenInvoiceInfoVo vo = new GenInvoiceInfoVo();
 		BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId());
-		vo.setPartyA(a.getCompanyName());
+		vo.setPartyA(a.getRegisterName());
 		vo.setPartyAOrgCode(a.getCreditCode());
 		vo.setPartyAOpenBank(a.getBankName());
 		vo.setPartyABankAccount(a.getBankAccount());
@@ -130,57 +154,129 @@
 		List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>();
 //		List<ContractOutBound> outBounds = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
 //				.in(ContractOutBound::getId, genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getContractOutBoundId()).collect(Collectors.toList())));
-		if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
-			genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
-				ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+		if (!StrUtil.equals(contract.getContractCategory(), "water_house")){
+			if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
+				genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+					ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
 
-				if (!ArrayUtil.contains(erpCode.toArray(), contractOutBound.getSubjectMatterCode())) {
-					erpCode.add(contractOutBound.getSubjectMatterCode());
-					ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
-					mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode());
-					mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName());
-					mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum());
-					Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
-							.eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
-					if (ObjUtil.isNotNull(product)) {
-						mergeVo.setTaxClass(product.getTaxClass());
-						mergeVo.setSpecification(product.getProductType());
-						mergeVo.setTaxRate(new BigDecimal(product.getTaxRate()));
-						mergeVo.setTaxCode(product.getTaxCode());
-						Product productClass = productMapper.selectById(product.getParentId());
+					if (!ArrayUtil.contains(erpCode.toArray(), contractOutBound.getSubjectMatterCode())) {
+						erpCode.add(contractOutBound.getSubjectMatterCode());
+						ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
+						mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode());
+						mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName());
+						mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum());
+						Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
+								.eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
 						if (ObjUtil.isNotNull(product)) {
-							mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName());
+							mergeVo.setTaxClass(product.getTaxClass());
+							mergeVo.setSpecification(product.getProductType());
+							mergeVo.setTaxRate(new BigDecimal(product.getTaxRate()));
+							mergeVo.setTaxCode(product.getTaxCode());
+							Product productClass = productMapper.selectById(product.getParentId());
+							if (ObjUtil.isNotNull(product)) {
+								if (StrUtil.equals(product.getErpCode(), "water_bill")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*姘磋垂");
+								} else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
+								} else if (StrUtil.equals(product.getErpCode(), "house_rental")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*鎴垮眿绉熻祦");
+								} else {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName());
+								}
+
+							}
+						}
+						ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+								.eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
+								.eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
+						if (ObjUtil.isNotNull(subjectMatter)) {
+							mergeVo.setUnitPrice(subjectMatter.getUnitPrice());
+							mergeVo.setUnit(subjectMatter.getUnit());
+						}
+						mergeOutBounds.add(mergeVo);
+					} else {
+						List<ContractOutBoundMergeVo> filteredList = mergeOutBounds.stream()
+								.filter(item -> contractOutBound.getSubjectMatterCode().equals(item.getMaterialCode())) // 闃叉绌烘寚閽堬紝寤鸿甯搁噺鍦ㄥ墠
+								.collect(Collectors.toList());
+						if (ArrayUtil.isNotEmpty(filteredList.toArray())) {
+							filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum()));
 						}
 					}
-					ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
-							.eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
-							.eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
-					if (ObjUtil.isNotNull(subjectMatter)) {
-						mergeVo.setUnitPrice(subjectMatter.getUnitPrice());
-						mergeVo.setUnit(subjectMatter.getUnit());
-					}
-					mergeOutBounds.add(mergeVo);
-				} else {
-					List<ContractOutBoundMergeVo> filteredList = mergeOutBounds.stream()
-							.filter(item -> contractOutBound.getSubjectMatterCode().equals(item.getMaterialCode())) // 闃叉绌烘寚閽堬紝寤鸿甯搁噺鍦ㄥ墠
-							.collect(Collectors.toList());
-					if (ArrayUtil.isNotEmpty(filteredList.toArray())) {
-						filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum()));
-					}
-				}
-			});
-			if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) {
-				invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class);
-				invoiceItemVoList.stream().forEach(invoiceItemVo -> {
-//				for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) {
-					BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity());
-					BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate());
-					invoiceItemVo.setPriceTax(itemPriceTax);
-					invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax));
 				});
-				vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add));
-				vo.setInvoiceItemList(invoiceItemVoList);
-				vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice()));
+				if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) {
+					invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class);
+					invoiceItemVoList.stream().forEach(invoiceItemVo -> {
+//				for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) {
+						BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity());
+						BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate());
+						invoiceItemVo.setPriceTax(itemPriceTax);
+						invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax));
+					});
+					vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add));
+					vo.setInvoiceItemList(invoiceItemVoList);
+					vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice()));
+				}
+			}
+		}else {
+			if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
+				genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+					ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+
+					if (!ArrayUtil.contains(erpCode.toArray(), schedule.getSubjectMatterCode())) {
+						erpCode.add(schedule.getSubjectMatterCode());
+						ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
+						mergeVo.setMaterialCode(schedule.getSubjectMatterCode());
+						mergeVo.setMaterialInternalName(schedule.getSubjectMatterName());
+						mergeVo.setPriceAndTax(schedule.getPlannedAmount());
+						Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, schedule.getSubjectMatterCode())
+								.eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
+						if (ObjUtil.isNotNull(product)) {
+							mergeVo.setTaxClass(product.getTaxClass());
+							mergeVo.setSpecification(product.getProductType());
+							mergeVo.setTaxRate(new BigDecimal(product.getTaxRate()));
+							mergeVo.setTaxCode(product.getTaxCode());
+							Product productClass = productMapper.selectById(product.getParentId());
+							if (ObjUtil.isNotNull(product)) {
+								if (StrUtil.equals(product.getErpCode(), "water_bill")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*姘磋垂");
+								} else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
+								} else if (StrUtil.equals(product.getErpCode(), "house_rental")) {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*鎴垮眿绉熻祦");
+								} else {
+									mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName());
+								}
+
+							}
+						}
+						ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+								.eq(ContractSubjectMatter::getMaterialCode, schedule.getSubjectMatterCode())
+								.eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
+						if (ObjUtil.isNotNull(subjectMatter)) {
+							mergeVo.setUnitPrice(subjectMatter.getUnitPrice());
+						}
+						mergeOutBounds.add(mergeVo);
+					}else {
+						List<ContractOutBoundMergeVo> filterMergeVo = mergeOutBounds.stream().filter(item->item.getMaterialCode()
+								.equals(schedule.getSubjectMatterCode())).collect(Collectors.toList());
+						if (ArrayUtil.isNotEmpty(filterMergeVo.toArray())){
+							filterMergeVo.get(0).setPriceAndTax(schedule.getPlannedAmount().add(filterMergeVo.get(0).getPriceAndTax()));
+						}
+					}
+				});
+				if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) {
+					invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class);
+					invoiceItemVoList.stream().forEach(invoiceItemVo -> {
+//				for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) {
+						BigDecimal itemPrice = invoiceItemVo.getPriceAndTax();
+						BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate());
+						invoiceItemVo.setPriceTax(itemPriceTax);
+						invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax));
+					});
+					vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceAndTax()).reduce(BigDecimal.ZERO, BigDecimal::add));
+					vo.setInvoiceItemList(invoiceItemVoList);
+					vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice()));
+				}
 			}
 		}
 		return vo;
@@ -191,8 +287,15 @@
 		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
 			return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
 		}
-		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
-		Contract contract = contractMapper.selectById(outBound.getContractId());
+		Long contractId = null;
+		if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) {
+			ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
+			contractId = outBound.getContractId();
+		}else {
+			ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
+			contractId = schedule.getContractId();
+		}
+		Contract contract = contractMapper.selectById(contractId);
 		if (ObjUtil.isNull(contract)) {
 			return R.failed("鍚堝悓淇℃伅寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
 		}
@@ -207,19 +310,31 @@
 		//鍚姩娴佺▼
 		ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
 		Map<String, Object> map = BeanUtil.beanToMap(invoice);
+		if (StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) {
+			map.put("contractCategory","water_house");
+		}
 		dto.setParamMap(map);
 		dto.setFlowName(FlowNameEnum.閿�鍞寕璐﹀鎵�.name());
 		R r1 = remoteFlowProcessService.startProcessInstance(dto);
 		if (r1.getCode() == 1) {
 			return R.failed("娴佺▼鍚姩澶辫触");
 		}
-		//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
-		genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
-			ContractOutBound bound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
-			bound.setInvoiceStatus("1");
-			bound.setInvoiceNum(bound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
-			contractOutBoundMapper.updateById(bound);
-		});
+		if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+			//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
+			genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+				ContractOutBound bound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+				bound.setInvoiceStatus("1");
+				bound.setInvoiceNum(bound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
+				contractOutBoundMapper.updateById(bound);
+			});
+		}else {
+			//鏇存柊鍚堝悓鎴跨 姘寸數 璐瑰紑绁ㄧ姸鎬�
+			genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+					ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+					schedule.setInvoiceFlag("1");
+					contractPaymentScheduleMapper.updateById(schedule);
+				});
+		}
 		return R.ok();
 	}
 
@@ -257,7 +372,11 @@
 			invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit());
 			invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity());
 			invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice());
-			invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()));
+			if (!StrUtil.equals(vo.getContractCategory(),"water_house")) {
+				invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()));
+			}else {
+				invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceAndTax());
+			}
 			invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax());
 
 			invoiceDetailsList.add(invoiceDetail);
@@ -314,6 +433,7 @@
 		ContractInvoice blueInvoice = baseMapper.selectById(invoiceId);
 		blueInvoice.setRedReversal("2");
 		baseMapper.updateById(blueInvoice);
+		Contract contract = contractMapper.selectById(blueInvoice.getContractId());
 		ContractInvoice invoice = new ContractInvoice();
 		invoice.setContractId(blueInvoice.getContractId());
 		invoice.setTexNo(blueInvoice.getTexNo());
@@ -340,6 +460,10 @@
 		ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
 		Map<String, Object> map = BeanUtil.beanToMap(invoice);
 		dto.setParamMap(map);
+		if (StrUtil.equals(contract.getContractCategory(),"water_house")) {
+			map.put("contractCategory","water_house");
+		}
+		dto.setParamMap(map);
 		dto.setFlowName(FlowNameEnum.閿�鍞寕璐﹀鎵�.name());
 		R r1 = remoteFlowProcessService.startProcessInstance(dto);
 		if (r1.getCode() == 1) {
@@ -349,7 +473,7 @@
 		return R.ok();
 	}
 
-	private JSONObject genRedInvoice(ContractInvoice blueInvoice, String redConfirmSerialNo) {
+	private JSONObject genRedInvoice(Contract contract,ContractInvoice blueInvoice, String redConfirmSerialNo) {
 		JSONObject jsonObject = new JSONObject();
 		jsonObject.put("taxNo", blueInvoice.getTexNo());
 		jsonObject.put("redConfirmSerialNo", redConfirmSerialNo);
@@ -378,7 +502,11 @@
 			invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit());
 			invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity());
 			invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice());
-			invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()));
+			if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+				invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()));
+			}else {
+				invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceAndTax());
+			}
 			invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax());
 
 			invoiceDetailsList.add(invoiceDetail);
@@ -547,7 +675,7 @@
 		ContractInvoice invoice = baseMapper.selectById(id);
 		Contract contract = contractMapper.selectById(invoice.getContractId());
 		GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(invoice.getInvoicePreview()), GenInvoiceInfoVo.class);
-
+		vo.setContractCategory(contract.getContractCategory());
 		//钃濈エ
 		if (invoice.getInvoiceCategory().equals("1")) {
 			// TODO 寮�钃濈エ鎺ュ彛
@@ -570,37 +698,77 @@
 					invoice.setInvoiceNo(model.getString("invoiceNo"));
 				}
 			}
+			if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+				//鍚堝悓鐘舵��
+				if (StrUtil.equals(contract.getBillingStatus(), "2")) {
+					if (ObjUtil.isNull(contract.getBillingAmout())) {
+						contract.setBillingAmout(vo.getTotalPrice());
+						if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
+							contract.setBillingStatus("3");
+						}
+						if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
+							contract.setBillingStatus("1");
+						}
+						contractMapper.updateById(contract);
+					} else {
+						contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
+						if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
+							contract.setBillingStatus("3");
+						}
+						if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
+							contract.setBillingStatus("1");
+						}
+						contractMapper.updateById(contract);
+					}
+				} else {
+					if (ObjUtil.isNull(contract.getBillingAmout())) {
+						contract.setBillingAmout(vo.getTotalPrice());
+						contractMapper.updateById(contract);
+					} else {
+						contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
+						contractMapper.updateById(contract);
+					}
+				}
+			}else {
+				//鍒ゆ柇 寰幆鏄惁瀹屾垚
+				List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId())
+						.eq(ContractExecDate::getGenFlag,"0"));
+				List<MeterReadRecord> recordList = meterReadRecordMapper.selectList(Wrappers.<MeterReadRecord>lambdaQuery()
+						.eq(MeterReadRecord::getContractId,contract.getId())
+						.isNull(MeterReadRecord::getMeterReadNum));
+				if (ArrayUtil.isEmpty(execDateList.toArray())&&ArrayUtil.isEmpty(recordList.toArray())) {
+					//鍒ゆ柇鏄惁鏈夊彲寮�绁ㄨ褰�
+					List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
+							.eq(ContractPaymentSchedule::getContractId,contract.getId()).eq(ContractPaymentSchedule::getInvoiceFlag,"0"));
+					if (ArrayUtil.isEmpty(scheduleList.toArray())){
+						contract.setBillingStatus("3");
+					}else {
+						contract.setBillingStatus("2");
+					}
 
-			//鍚堝悓鐘舵��
-			if (StrUtil.equals(contract.getBillingStatus(), "2")) {
+				}else {
+					//鍒ゆ柇鏄惁鏈夊彲寮�绁ㄨ褰�
+					List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
+							.eq(ContractPaymentSchedule::getContractId,contract.getId()));
+					if (ArrayUtil.isEmpty(scheduleList.toArray())){
+						contract.setBillingStatus("1");
+					}else {
+						contract.setBillingStatus("2");
+					}
+				}
 				if (ObjUtil.isNull(contract.getBillingAmout())) {
 					contract.setBillingAmout(vo.getTotalPrice());
-					if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
-						contract.setBillingStatus("3");
-					}
-					contractMapper.updateById(contract);
 				} else {
 					contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
-					if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
-						contract.setBillingStatus("3");
-					}
-					contractMapper.updateById(contract);
 				}
-			} else {
-				if (ObjUtil.isNull(contract.getBillingAmout())) {
-					contract.setBillingAmout(vo.getTotalPrice());
-					contractMapper.updateById(contract);
-				} else {
-					contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
-					contractMapper.updateById(contract);
-				}
+				contractMapper.updateById(contract);
 			}
 		}
 		//绾㈢エ
 		if (invoice.getInvoiceCategory().equals("2")) {
 			// TODO 寮�绾㈢エ鎺ュ彛
 			ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId());
-			JSONObject request = genRedInvoice(blueInvoice, invoice.getSerialNo());
+			JSONObject request = genRedInvoice(contract,blueInvoice, invoice.getSerialNo());
 			String requestId = IdUtil.fastUUID();
 			if (bwFlag) {
 				log.info("绾㈠瓧纭鍗曡姹傛帴鍙e叆鍙�", request.toJSONString());
@@ -627,19 +795,32 @@
 					}
 				}
 			}
-			//鏇存柊鍚堝悓寮�绁ㄧ姸鎬�
+			contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax()));
+			//鏇存柊鍚堝悓寮�绁ㄧ姸鎬� 鍓嶆彁鍑哄簱瀹屾垚
 			contract.setBillingStatus("2");
-			contract.setBillingAmout(contract.getAmount().subtract(invoice.getInvoiceTotalPriceTax()));
 			contractMapper.updateById(contract);
-
-			//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
-			List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()),ContractOutBoundInvoiceVo.class);
-			if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())){
-				outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
-					ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
-					contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
-					contractOutBoundMapper.updateById(contractOutBound);
-				});
+			blueInvoice.setRedReversal("1");
+			baseMapper.updateById(blueInvoice);
+			if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+				//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
+				List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class);
+				if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
+					outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
+						ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+						contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
+						contractOutBoundMapper.updateById(contractOutBound);
+					});
+				}
+			}else {
+				//鏇存柊鍚堝悓鎴跨 姘寸數 璐瑰紑绁ㄧ姸鎬�
+				List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class);
+				if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
+					outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
+						ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+						schedule.setInvoiceFlag("0");
+						contractPaymentScheduleMapper.updateById(schedule);
+					});
+				}
 			}
 		}
 		invoice.setApprovalStatus("1");
@@ -649,14 +830,50 @@
 	@Override
 	public void refuseApproval(Long id) {
 		ContractInvoice invoice = baseMapper.selectById(id);
-		//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
-		String[] outBoundIds = invoice.getOutBoundId().split(",");
-		Arrays.stream(outBoundIds).forEach(outBoundId -> {
-			ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId);
-			bound.setInvoiceStatus("0");
-			contractOutBoundMapper.updateById(bound);
-		});
 		invoice.setApprovalStatus("2");
 		baseMapper.updateById(invoice);
+		Contract contract = contractMapper.selectById(invoice.getContractId());
+		//钃濈エ
+		if (invoice.getInvoiceCategory().equals("1")) {
+			if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+				//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
+				List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class);
+				if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
+					outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
+						ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+						contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
+						contractOutBoundMapper.updateById(contractOutBound);
+					});
+				}
+			}else {
+				//鏇存柊鍚堝悓鎴跨 姘寸數 璐瑰紑绁ㄧ姸鎬�
+				List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class);
+				if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) {
+					outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
+						ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+						schedule.setInvoiceFlag("0");
+						contractPaymentScheduleMapper.updateById(schedule);
+					});
+				}
+				contract.setBillingStatus("2");
+				contractMapper.updateById(contract);
+			}
+		}
+		//绾㈢エ
+		if (invoice.getInvoiceCategory().equals("2")) {
+			ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId());
+			blueInvoice.setRedReversal("0");
+			baseMapper.updateById(blueInvoice);
+		}
+	}
+
+	@Override
+	public Page pageInvoice(Page page, ContractInvoiceQueryDTO queryDTO) {
+		return baseMapper.pageInvoice(page,queryDTO, DataScope.of("comp_id"));
+	}
+
+	@Override
+	public Page pageScope(Page page, ContractQueryDTO queryDTO) {
+		return baseMapper.pageScope(page,queryDTO, DataScope.of("comp_id"));
 	}
 }

--
Gitblit v1.9.1