From b1b3da5393c75ced1afa1467be69d60af5403878 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期四, 27 八月 2026 14:25:16 +0800
Subject: [PATCH] feat:合同审核、出库及履约阶段代码优化
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java | 592 ++++++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 441 insertions(+), 151 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 73098ea..f652c00 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
@@ -9,6 +9,7 @@
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -22,6 +23,7 @@
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.dto.InvoiceQueryDTO;
import com.by4cloud.platformx.business.entity.*;
import com.by4cloud.platformx.business.mapper.*;
import com.by4cloud.platformx.business.service.ContractInvoiceService;
@@ -38,6 +40,9 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
@@ -80,6 +85,9 @@
@Value("${bip.appSecret}")
private String appSecret;
+ @Value("${file.path}")
+ private String localPath;
+
@Override
public R getContractOutBound(Long contractId) {
@@ -91,12 +99,15 @@
invoiceOutBoundVoList.stream().forEach(contractInvoiceOutBoundVo -> {
contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(contractInvoiceOutBoundVo.getInvoiceNum()));
- ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,contractId)
- .eq(ContractSubjectMatter::getMaterialCode,contractInvoiceOutBoundVo.getSubjectMatterCode())
- .eq(StrUtil.isNotBlank(contractInvoiceOutBoundVo.getLineNo()),ContractSubjectMatter::getLineNo,contractInvoiceOutBoundVo.getLineNo())
+ ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contractId)
+ .eq(ContractSubjectMatter::getMaterialCode, contractInvoiceOutBoundVo.getSubjectMatterCode())
+ .eq(StrUtil.isNotBlank(contractInvoiceOutBoundVo.getLineNo()), ContractSubjectMatter::getLineNo, contractInvoiceOutBoundVo.getLineNo())
.last("limit 1"));
- if (ObjUtil.isNotNull(subjectMatter)&&subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0"))>0){
- contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(subjectMatter.getAdvanceNum()));
+ if (ObjUtil.isNotNull(subjectMatter)) {
+ contractInvoiceOutBoundVo.setUnitPrice(subjectMatter.getUnitPrice());
+ if (subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0")) > 0) {
+ contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(subjectMatter.getAdvanceNum()));
+ }
}
contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum());
});
@@ -137,11 +148,16 @@
if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
}
+ genInvoiceInfoDTO.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList().stream().filter(item->
+ item.getInvoiceNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList()));
+ if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
+ return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庢垨璋冩暣寮�绁ㄦ暟閲忓啀鎿嶄綔");
+ }
Long contractId = null;
//棰勬敹娆惧紑绁�
if (StrUtil.isNotBlank(genInvoiceInfoDTO.getContractId())) {
ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery()
- .eq(ContractPaymentSchedule::getStageName, "鍚堝悓绛捐").eq(ContractPaymentSchedule::getContractId,genInvoiceInfoDTO.getContractId())
+ .eq(ContractPaymentSchedule::getStageName, "鍚堝悓绛捐").eq(ContractPaymentSchedule::getContractId, genInvoiceInfoDTO.getContractId())
.last("limit 1"));
if (ObjUtil.isNull(schedule)) {
return R.failed("鍚堝悓棰勬敹娆鹃樁娈靛紓甯革紝璇疯仈绯绘妧鏈汉鍛�");
@@ -162,8 +178,8 @@
advanceAmount = advanceAmount.add(contractOutBoundInvoiceVo.getInvoiceNum().multiply(subjectMatter.getUnitPrice()));
}
}
- log.info("advanceAmount:{}",advanceAmount);
- log.info("schedule.getPlannedAmount:{}",schedule.getPlannedAmount());
+ log.info("advanceAmount:{}", advanceAmount);
+ log.info("schedule.getPlannedAmount:{}", schedule.getPlannedAmount());
if (advanceAmount.compareTo(schedule.getPlannedAmount()) > 0) {
return R.failed("寮�绁ㄩ噾棰濊秴鍑哄悎鍚岀璁㈤樁娈靛簲鏀堕噾棰�:" + schedule.getPlannedAmount() + ",璇疯皟鏁村紑绁ㄦ暟閲�");
}
@@ -190,22 +206,22 @@
}
SysDept b = r.getData();
//鏈哄姩杞﹀紑绁�
- if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){
- if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){
+ if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) {
+ if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) {
return R.failed("鏈哄姩杞﹀紑绁ㄨ杈撳叆杞︽灦鍙�");
}
- BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add);
- if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){
+ BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
+ if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) {
return R.failed("鏈哄姩杞﹀紑绁ㄥ彧鑳�1娆″紑1杈�");
}
- JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(),b);
+ JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(), b);
R r1 = requestQueryVehicleNo(request);
- if (!r1.isOk()){
+ if (!r1.isOk()) {
return r1;
}
- JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(),b);
+ JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(), b);
R r2 = requestQueryVehicleDetail(request1);
- if (!r2.isOk()){
+ if (!r2.isOk()) {
return r2;
}
genInvoiceInfoDTO.setVehicleData(r2.getData().toString());
@@ -220,16 +236,16 @@
String requestId = IdUtil.fastUUID();
log.info("鏈哄姩杞﹀悎鏍艰瘉鏌ヨ鎺ュ彛鍏ュ弬锛歿},", request.toJSONString());
- String result = HttpUtil.post(bwUrl+"method=baiwang.output.invoice.queryVinDetail&version=1.0&request_id=" + requestId, request.toJSONString());
+ String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.queryVinDetail&version=1.0&request_id=" + requestId, request.toJSONString());
log.info("鏈哄姩杞﹀悎鏍艰瘉鏌ヨ鎺ュ彛鍥炲弬锛歿},", result);
saveBwRequestRecord("baiwang.output.invoice.queryVinDetail", requestId, request.toJSONString(), result);
JSONObject resultObj = JSONObject.parseObject(result);
if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) &&
!resultObj.getBoolean("success")) {
- return R.failed("鏈哄姩杞﹀悎鏍艰瘉鏌ヨ澶辫触",result);
+ return R.failed("鏈哄姩杞﹀悎鏍艰瘉鏌ヨ澶辫触", result);
}
JSONArray models = resultObj.getJSONArray("model");
- if (CollUtil.isNotEmpty(models)){
+ if (CollUtil.isNotEmpty(models)) {
JSONObject model = (JSONObject) models.get(0);
return R.ok(model);
}
@@ -238,10 +254,10 @@
private JSONObject genQueryVehDetailParam(String vehicleNo, SysDept b) {
JSONObject jsonObject = new JSONObject();
- jsonObject.put("taxNo",b.getOrgCode());
+ jsonObject.put("taxNo", b.getOrgCode());
JSONObject data = new JSONObject();
data.put("vehicleNo", vehicleNo);
- jsonObject.put("data",data);
+ jsonObject.put("data", data);
return jsonObject;
}
@@ -249,30 +265,30 @@
String requestId = IdUtil.fastUUID();
log.info("鏌ヨ绋庡眬杞︽灦鍙风爜鍏ュ弬锛歿},", request.toJSONString());
- String result = HttpUtil.post(bwUrl+"method=baiwang.output.einvoice.queryvinlist&version=1.0&request_id=" + requestId, request.toJSONString());
+ String result = HttpUtil.post(bwUrl + "method=baiwang.output.einvoice.queryvinlist&version=1.0&request_id=" + requestId, request.toJSONString());
log.info("鏌ヨ绋庡眬杞︽灦鍙风爜鍥炲弬锛歿},", result);
saveBwRequestRecord("baiwang.output.einvoice.queryvinlist", requestId, request.toJSONString(), result);
JSONObject resultObj = JSONObject.parseObject(result);
if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) &&
!resultObj.getBoolean("success")) {
- return R.failed("鏌ヨ绋庡眬杞︽灦鍙风爜澶辫触",result);
+ return R.failed("鏌ヨ绋庡眬杞︽灦鍙风爜澶辫触", result);
}
JSONArray models = resultObj.getJSONArray("model");
- if (CollUtil.isNotEmpty(models)){
+ if (CollUtil.isNotEmpty(models)) {
JSONObject model = (JSONObject) models.get(0);
- if (!model.getBoolean("isOpenInvoice")){
+ if (!model.getBoolean("isOpenInvoice")) {
return R.failed(model.getString("isNotOpenInvReason"));
}
}
return R.ok();
}
- private JSONObject genQueryVinParam(String vehicleNo,SysDept b) {
+ private JSONObject genQueryVinParam(String vehicleNo, SysDept b) {
JSONObject jsonObject = new JSONObject();
- jsonObject.put("taxNo",b.getOrgCode());
+ jsonObject.put("taxNo", b.getOrgCode());
JSONObject data = new JSONObject();
data.put("vinList", new ArrayList<String>(Arrays.asList(vehicleNo)));
- jsonObject.put("data",data);
+ jsonObject.put("data", data);
return jsonObject;
}
@@ -309,11 +325,14 @@
if (CollUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
-
- if (!CollUtil.contains(erpCode, contractOutBound.getSubjectMatterCode())) {
- erpCode.add(contractOutBound.getSubjectMatterCode());
+ ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
+ .eq(StrUtil.isNotBlank(contractOutBound.getLineNo()),ContractSubjectMatter::getLineNo,contractOutBound.getLineNo())
+ .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
+ if (!CollUtil.contains(erpCode, contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice())) {
+ erpCode.add(contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice());
ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
- mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode());
+ mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice());
mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName());
mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum());
Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
@@ -324,9 +343,6 @@
mergeVo.setTaxRate(new BigDecimal(product.getTaxRate()));
mergeVo.setTaxCode(product.getTaxCode());
}
- 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());
@@ -343,7 +359,7 @@
mergeOutBounds.add(mergeVo);
} else {
List<ContractOutBoundMergeVo> filteredList = mergeOutBounds.stream()
- .filter(item -> contractOutBound.getSubjectMatterCode().equals(item.getMaterialCode())) // 闃叉绌烘寚閽堬紝寤鸿甯搁噺鍦ㄥ墠
+ .filter(item -> item.getMaterialCode().equals(subjectMatter.getMaterialCode()+subjectMatter.getUnitPrice())) // 闃叉绌烘寚閽堬紝寤鸿甯搁噺鍦ㄥ墠
.collect(Collectors.toList());
if (ArrayUtil.isNotEmpty(filteredList)) {
filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum()));
@@ -385,27 +401,24 @@
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() + "*姘磋垂");
- mergeVo.setUnit("鍚�");
- } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
- mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
- mergeVo.setUnit("搴�");
- } 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());
+ if (StrUtil.equals(product.getErpCode(), "water_bill")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*姘磋垂");
+ mergeVo.setUnit("鍚�");
+ } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
+ mergeVo.setUnit("搴�");
+ } else if (StrUtil.equals(product.getErpCode(), "house_rental")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*鎴垮眿绉熻祦");
+ } else {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*" + subjectMatter.getMaterialName());
+ }
+
}
mergeOutBounds.add(mergeVo);
} else {
@@ -456,7 +469,7 @@
genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
if (ObjUtil.isNotNull(subjectMatter)) {
- if (!CollUtil.contains(erpCode, subjectMatter.getMaterialCode())) {
+ if (!CollUtil.contains(erpCode, subjectMatter.getMaterialCode()+subjectMatter.getUnitPrice())) {
erpCode.add(subjectMatter.getMaterialCode());
ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
mergeVo.setMaterialCode(subjectMatter.getMaterialCode());
@@ -469,21 +482,20 @@
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() + "*姘磋垂");
- mergeVo.setUnit("鍚�");
- } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
- mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
- mergeVo.setUnit("搴�");
- } else if (StrUtil.equals(product.getErpCode(), "house_rental")) {
- mergeVo.setItemName("*" + product.getTaxClass() + "*鎴垮眿绉熻祦");
- } else {
- mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName());
- }
-
+ }
+ if (ObjUtil.isNotNull(product)) {
+ if (StrUtil.equals(product.getErpCode(), "water_bill")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*姘磋垂");
+ mergeVo.setUnit("鍚�");
+ } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*鐢佃垂");
+ mergeVo.setUnit("搴�");
+ } else if (StrUtil.equals(product.getErpCode(), "house_rental")) {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*鎴垮眿绉熻祦");
+ } else {
+ mergeVo.setItemName("*" + product.getTaxClass() + "*" + subjectMatter.getMaterialName());
}
+
}
mergeVo.setUnitPrice(subjectMatter.getUnitPrice());
mergeVo.setUnit(subjectMatter.getUnit());
@@ -514,15 +526,20 @@
@Override
public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) {
- if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
+ if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
}
- if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){
- if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){
+ genInvoiceInfoDTO.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList().stream().filter(item->
+ item.getInvoiceNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList()));
+ if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
+ return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庢垨璋冩暣寮�绁ㄦ暟閲忓啀鎿嶄綔");
+ }
+ if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) {
+ if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) {
return R.failed("鏈哄姩杞﹀紑绁ㄨ杈撳叆杞︽灦鍙�");
}
- BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add);
- if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){
+ BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
+ if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) {
return R.failed("鏈哄姩杞﹀紑绁ㄥ彧鑳�1娆″紑1杈�");
}
}
@@ -530,7 +547,7 @@
if (StrUtil.isNotBlank(genInvoiceInfoDTO.getContractId())) {
ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery()
- .eq(ContractPaymentSchedule::getStageName, "鍚堝悓绛捐").eq(ContractPaymentSchedule::getContractId,genInvoiceInfoDTO.getContractId())
+ .eq(ContractPaymentSchedule::getStageName, "鍚堝悓绛捐").eq(ContractPaymentSchedule::getContractId, genInvoiceInfoDTO.getContractId())
.last("limit 1"));
if (ObjUtil.isNull(schedule)) {
return R.failed("鍚堝悓棰勬敹娆鹃樁娈靛紓甯革紝璇疯仈绯绘妧鏈汉鍛�");
@@ -539,9 +556,9 @@
if (ObjUtil.isNull(contract)) {
return R.failed("鍚堝悓淇℃伅寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
}
- ContractInvoice lastInvoice = baseMapper.selectOne(Wrappers.<ContractInvoice>lambdaQuery().eq(ContractInvoice::getContractId,contract.getId())
+ ContractInvoice lastInvoice = baseMapper.selectOne(Wrappers.<ContractInvoice>lambdaQuery().eq(ContractInvoice::getContractId, contract.getId())
.orderByDesc(ContractInvoice::getCreateTime).last("limit 1"));
- if (ObjUtil.isNotNull(lastInvoice)&&StrUtil.equals(lastInvoice.getApprovalStatus(),"0")){
+ if (ObjUtil.isNotNull(lastInvoice) && StrUtil.equals(lastInvoice.getApprovalStatus(), "0")) {
return R.failed("璇风瓑寰呮渶杩戠殑鍙戠エ瀹℃牳瀹屾垚鍚庡啀杩涜棰勬敹寮�绁�");
}
R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
@@ -562,7 +579,7 @@
}
GenInvoiceInfoVo vo = genAdvanceInvoiceInfoVo(genInvoiceInfoDTO, contract, b);
//鍙戠エ淇濆瓨
- ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "","1");
+ ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "1");
//鍚姩娴佺▼
ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
Map<String, Object> map = BeanUtil.beanToMap(invoice);
@@ -597,29 +614,29 @@
}
SysDept b = r.getData();
//鏈哄姩杞﹀紑绁�
- if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){
- if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){
+ if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) {
+ if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) {
return R.failed("鏈哄姩杞﹀紑绁ㄨ杈撳叆杞︽灦鍙�");
}
- BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add);
- if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){
+ BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
+ if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) {
return R.failed("鏈哄姩杞﹀紑绁ㄥ彧鑳�1娆″紑1杈�");
}
- JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(),b);
+ JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(), b);
R r1 = requestQueryVehicleNo(request);
- if (!r1.isOk()){
+ if (!r1.isOk()) {
return r1;
}
- JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(),b);
+ JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(), b);
R r2 = requestQueryVehicleDetail(request1);
- if (!r2.isOk()){
+ if (!r2.isOk()) {
return r2;
}
genInvoiceInfoDTO.setVehicleData(r2.getData().toString());
}
GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b);
//鍙戠エ淇濆瓨
- ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "","0");
+ ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "0");
//鍚姩娴佺▼
ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
Map<String, Object> map = BeanUtil.beanToMap(invoice);
@@ -637,9 +654,7 @@
genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
contractOutBound.setInvoiceStatus("1");
- if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) {
- contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
- }
+ contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
contractOutBoundMapper.updateById(contractOutBound);
});
} else {
@@ -663,7 +678,7 @@
bwRequestRecordMapper.insert(bwRequestRecord);
}
- private JSONObject genBlueInvoice(GenInvoiceInfoVo vo, String serialNo,SysDept dept) {
+ private JSONObject genBlueInvoice(GenInvoiceInfoVo vo, String serialNo, SysDept dept) {
JSONObject jsonObject = new JSONObject();
//閿�鏂�
jsonObject.put("taxNo", vo.getPartyBOrgCode());//绋庡彿
@@ -688,9 +703,9 @@
invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit());
invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity());
// invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice());
- if (StrUtil.equals(vo.getInvoiceVehicleType(),"3")){
+ if (StrUtil.equals(vo.getInvoiceVehicleType(), "3")) {
invoiceDetail.put("goodsSpecification", vo.getVehicleNo());
- }else {
+ } else {
invoiceDetail.put("goodsSpecification", invoiceItemVo.getSpecification());
}
@@ -718,7 +733,7 @@
}
private ContractInvoice saveContractInvoice(GenInvoiceInfoVo genInvoiceInfoVo, Contract contract,
- List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList, String serialNo,String advanceFlag) {
+ List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList, String serialNo, String advanceFlag) {
ContractInvoice invoice = new ContractInvoice();
invoice.setContractId(contract.getId());
invoice.setInvoiceCategory("1");
@@ -846,7 +861,7 @@
if (bwFlag) {
List<ContractInvoice> contractInvoices = baseMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery()
.eq(ContractInvoice::getApprovalStatus, "1")
- .eq(ContractInvoice::getBwRequestResult,"1")
+ .eq(ContractInvoice::getBwRequestResult, "1")
.isNull(ContractInvoice::getInvoicePath));
if (ArrayUtil.isNotEmpty(contractInvoices)) {
contractInvoices.stream().forEach(contractInvoice -> {
@@ -856,11 +871,11 @@
data.put("serialNo", contractInvoice.getSerialNo());
data.put("returnType", "3");
data.put("invoiceIssueMode", "1");
- request.put("data",data);
+ request.put("data", data);
String requestId = IdUtil.fastUUID();
log.info("serial_no:{},鍙戠エ鏌ヨ鍏ュ弬锛歿},", contractInvoice.getSerialNo(), request.toJSONString());
- String result = HttpUtil.post(bwUrl+"method=baiwang.output.format.query&version=1.0&request_id=" + requestId, request.toJSONString());
+ String result = HttpUtil.post(bwUrl + "method=baiwang.output.format.query&version=1.0&request_id=" + requestId, request.toJSONString());
log.info("serial_no:{},鍙戠エ鏌ヨ鍥炲弬锛歿},", contractInvoice.getSerialNo(), result);
saveBwRequestRecord("baiwang.output.format.query", requestId, request.toJSONString(), result);
JSONObject resultObj = JSONObject.parseObject(result);
@@ -869,11 +884,101 @@
contractInvoice.setInvoicePath(model.getString("queryData"));
contractInvoice.setInvoiceStatus("2");
baseMapper.updateById(contractInvoice);
+ //浼犺緭闄勪欢
+ pushBipInvoicePdf(contractInvoice);
}
});
}
}
return R.ok();
+ }
+
+ private void pushBipInvoicePdf(ContractInvoice contractInvoice) {
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return;
+ }
+ String finalAccessToken = accessToken;
+ String requestId = IdUtil.fastUUID();
+ JSONObject request = new JSONObject();
+ request.put("taxNo", contractInvoice.getTaxNo());
+ JSONObject data = new JSONObject();
+ data.put("serialNo", contractInvoice.getSerialNo());
+ data.put("returnType", "2");
+ data.put("invoiceIssueMode", "1");
+ request.put("data", data);
+ log.info("serial_no:{},鍙戠エ鏌ヨ鍏ュ弬锛歿},", contractInvoice.getSerialNo(), request.toJSONString());
+ String result = HttpUtil.post(bwUrl + "method=baiwang.output.format.query&version=1.0&request_id=" + requestId, request.toJSONString());
+ log.info("serial_no:{},鍙戠エ鏌ヨ鍥炲弬锛歿},", contractInvoice.getSerialNo(), result);
+ JSONObject resultObj = JSONObject.parseObject(result);
+ String filePath = localPath + File.separator + DateUtil.today() + File.separator + IdUtil.fastUUID() + ".pdf";
+ if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && resultObj.getBoolean("success")) {
+ JSONObject model = resultObj.getJSONObject("model");
+ saveBase64ToFile(model.getString("queryData"), filePath);
+
+ }
+ File file = new File(filePath);
+ if (file.exists()) {
+ log.info("搴旀敹鍙戠エ闄勪欢涓婁紶鍏ュ弬:{}", url + "/yonbip/uspace/iuap-apcom-file/rest/v1/file?access_token="
+ + finalAccessToken + "&businessType=yonbip-fi-earapbill&businessId=" + contractInvoice.getBipId());
+ HttpResponse response = HttpUtil.createPost(url + "/yonbip/uspace/iuap-apcom-file/rest/v1/file?access_token="
+ + finalAccessToken + "&businessType=yonbip-fi-earapbill&businessId=" + contractInvoice.getBipId())
+ .header("Content-Type", "multipart/form-data")
+ // 璁剧疆琛ㄥ崟鍙傛暟锛堟枃浠讹級锛岀涓�涓弬鏁颁负鎺ュ彛鎺ユ敹鐨勫弬鏁板悕锛堝"file"锛�
+ .form("files", file)
+ // 鎵ц璇锋眰
+ .execute();
+ log.info("搴旀敹鍙戠エ闄勪欢涓婁紶鍥炲弬:{}", response.body());
+ //淇濆瓨璇锋眰璁板綍
+ paymentConfirmService.saveBipRequestRecord(request, "搴旀敹鍙戠エ闆嗘垚鎺ュ彛", response.body());
+ JSONObject resultJson = JSONObject.parseObject(response.body());
+ if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) {
+ JSONObject datas = resultJson.getJSONObject("data");
+ JSONArray arr = datas.getJSONArray("data");
+ if (CollUtil.isNotEmpty(arr)) {
+ JSONObject data0 = (JSONObject) arr.get(0);
+ contractInvoice.setBipFileId(data0.getString("id"));
+ baseMapper.updateById(contractInvoice);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * 灏� Base64 瀛楃涓茶浆鎹负鏈湴鏂囦欢
+ *
+ * @param base64Str Base64 缂栫爜鐨勫瓧绗︿覆
+ * @param targetPath 鐩爣鏂囦欢璺緞锛堝寘鍚枃浠跺悕鍜屽悗缂�锛屽 "D:/test.pdf"锛�
+ */
+ public static void saveBase64ToFile(String base64Str, String targetPath) {
+ if (base64Str == null || base64Str.isEmpty()) {
+ throw new IllegalArgumentException("Base64 瀛楃涓蹭笉鑳戒负绌�");
+ }
+
+ // 1. 澶勭悊鍙兘瀛樺湪鐨� Data URI 鍓嶇紑 (濡�: "data:application/pdf;base64,JVBERi...")
+ if (base64Str.contains(",")) {
+ base64Str = base64Str.split(",")[1];
+ }
+
+ // 2. 瑙g爜 Base64 涓哄瓧鑺傛暟缁�
+ byte[] fileBytes = Base64.getDecoder().decode(base64Str);
+
+ // 3. 灏嗗瓧鑺傛暟缁勫啓鍏ユ枃浠�
+ try (FileOutputStream fos = new FileOutputStream(new File(targetPath))) {
+ fos.write(fileBytes);
+ fos.flush();
+ System.out.println("鏂囦欢淇濆瓨鎴愬姛: " + targetPath);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException("鏂囦欢淇濆瓨澶辫触", e);
+ }
}
private void pushBipInvoice(ContractInvoice contractInvoice) {
@@ -902,14 +1007,21 @@
log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
return;
}
- SysDept dept = r.getData();
+ SysDept comp = r.getData();
+ R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return;
+ }
+ SysDept dept = rDept.getData();
//钃濈エ
if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "1")) {
- JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, dept);
+
+ JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp, dept);
String finalAccessToken = accessToken;
log.info("搴旀敹鍙戠エ闆嗘垚鍏ュ弬:{}", params.toJSONString());
- String result = HttpUtil.post(url + "/yonbip/EFI/receivable/save?access_token=" + finalAccessToken, params.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/receivable/saveandsubmit?access_token=" + finalAccessToken, params.toJSONString());
log.info("搴旀敹鍙戠エ闆嗘垚鍥炲弬:{}", result);
//淇濆瓨璇锋眰璁板綍
paymentConfirmService.saveBipRequestRecord(params, "搴旀敹鍙戠エ闆嗘垚鎺ュ彛", result);
@@ -935,6 +1047,7 @@
JSONObject resultJson = JSONObject.parseObject(result);
if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) {
contractInvoice.setBipPush("1");
+ contractInvoice.setBipBody(resultJson.getString("data"));
baseMapper.updateById(contractInvoice);
}
}
@@ -949,7 +1062,8 @@
return jsonObject;
}
- private JSONObject genBlueReceiveParams(ContractInvoice contractInvoice, Contract contract, BusinessCustomer customer, SysDept dept) {
+ private JSONObject genBlueReceiveParams(ContractInvoice contractInvoice, Contract contract, BusinessCustomer customer
+ , SysDept comp, SysDept dept) {
JSONObject jsonObject = new JSONObject();
JSONObject data = new JSONObject();
if (contractInvoice.getInvoiceCategory().equals("1")) {
@@ -960,11 +1074,13 @@
data.put("billDate", DateUtil.format(contractInvoice.getInvoiceTime(), DatePattern.NORM_DATETIME_FORMAT));
data.put("exchangeRate", "1");//姹囩巼
data.put("exchangeRateDate", DateUtil.now());//姹囩巼鏃堕棿
- data.put("objectType", "1");
+ data.put("objectType", "1");//寰�鏉ュ璞$被鍨�(鏋氫妇鍊� 1:瀹㈡埛; 2:鍛樺伐;3:璧勯噾涓氬姟瀵硅薄)
+ data.put("deptCode", dept.getOrgCode());//閮ㄩ棬缂栫爜 SS2
+ data.put("staffCode", SecurityUtils.getUser().getNickname());//涓氬姟鍛樼紪鐮�
data.put("customerCode", customer.getBipCode());//瀹㈡埛缂栫爜
- data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
- data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
- data.put("bustypeCode", "");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁JHYXGLXT
+ data.put("financeOrgCode", comp.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", comp.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ZBYXGLXT");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁BYXGLXT
data.put("contractNo", contract.getContractNo());
data.put("oriCurrencyCode", "CNY");//甯佺
data.put("_status", "Insert");
@@ -1034,7 +1150,7 @@
public void takeEffect(Long id) {
ContractInvoice invoice = baseMapper.selectById(id);
R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
- if (!r.isOk()){
+ if (!r.isOk()) {
log.error("鍗曚綅淇℃伅鏌ヨ寮傚父");
return;
}
@@ -1049,8 +1165,8 @@
//钃濈エ
if (invoice.getInvoiceCategory().equals("1")) {
// TODO 寮�钃濈エ鎺ュ彛鏈哄姩杞�
- if (StrUtil.equals(vo.getInvoiceVehicleType(),"3")){
- JSONObject request = genBlueInvoiceVehicle(vo, invoice.getSerialNo(),dept);
+ if (StrUtil.equals(vo.getInvoiceVehicleType(), "3")) {
+ JSONObject request = genBlueInvoiceVehicle(vo, invoice.getSerialNo(), dept);
String requestId = IdUtil.fastUUID();
invoice.setBwRequestId(requestId);
invoice.setBwRequestParam(request.toJSONString());
@@ -1075,7 +1191,7 @@
}
// TODO 寮�钃濈エ鎺ュ彛 闈炴満鍔ㄨ溅
- JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(),dept);
+ JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(), dept);
if (bwFlag) {
String requestId = IdUtil.fastUUID();
invoice.setBwRequestId(requestId);
@@ -1103,34 +1219,37 @@
}
}
}
- if (StrUtil.isNotBlank(vo.getAdvanceInvoice())){
+ if (StrUtil.isNotBlank(vo.getAdvanceInvoice())) {
contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
contractMapper.updateById(contract);
return;
}
if (!StrUtil.equals(contract.getContractCategory(), "water_house")) {
//鍚堝悓鐘舵��
- if (StrUtil.equals(contract.getBillingStatus(), "2")) {
- 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");
- List<ContractOutBound> outBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
- .eq(ContractOutBound::getContractId,contract.getId())
- .apply("invoice_num < out_bound_num"));
- if (CollUtil.isNotEmpty(outBoundList)){
- contract.setBillingStatus("2");
- }
-
- }
- //闃叉閲嶅瀹″紑绁ㄥ鏍搁�氳繃鍚� 寮�绁ㄩ噾棰濊秴鍑哄悎鍚岄噾棰�
- if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) {
- contract.setBillingAmout(contract.getAmount());
- }
- contractMapper.updateById(contract);
+ contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
+ if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
+ contract.setBillingStatus("3");
}
+ if (contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&&
+ contract.getBillingAmout().compareTo(contract.getAmount()) == 0){
+ contract.setContractStatus(3);
+ }
+ if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
+ contract.setBillingStatus("1");
+ List<ContractOutBound> outBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
+ .eq(ContractOutBound::getContractId, contract.getId())
+ .apply("invoice_num < out_bound_num"));
+ if (CollUtil.isNotEmpty(outBoundList)) {
+ contract.setBillingStatus("2");
+ }
+
+ }
+ //闃叉閲嶅瀹″紑绁ㄥ鏍搁�氳繃鍚� 寮�绁ㄩ噾棰濊秴鍑哄悎鍚岄噾棰�
+ if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) {
+ contract.setBillingAmout(contract.getAmount());
+ }
+ contractMapper.updateById(contract);
+
} else {
//鍒ゆ柇 寰幆鏄惁瀹屾垚
List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId, contract.getId())
@@ -1144,7 +1263,19 @@
} else {
contract.setBillingStatus("2");
}
-
+ 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.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) {
+ contract.setBillingStatus("3");
+ contract.setContractStatus(3);
+ }
+ //闃叉閲嶅瀹″紑绁ㄥ鏍搁�氳繃鍚� 寮�绁ㄩ噾棰濊秴鍑哄悎鍚岄噾棰�
+ if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) {
+ contract.setBillingAmout(contract.getAmount());
+ }
} else {
//鍒ゆ柇鏄惁鏈夊彲寮�绁ㄨ褰�
List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
@@ -1155,11 +1286,7 @@
contract.setBillingStatus("2");
}
}
- contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout()));
- //闃叉閲嶅瀹″紑绁ㄥ鏍搁�氳繃鍚� 寮�绁ㄩ噾棰濊秴鍑哄悎鍚岄噾棰�
- if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) {
- contract.setBillingAmout(contract.getAmount());
- }
+
contractMapper.updateById(contract);
}
baseMapper.updateById(invoice);
@@ -1209,15 +1336,15 @@
contractMapper.updateById(contract);
blueInvoice.setRedReversal("1");
baseMapper.updateById(blueInvoice);
- if (StrUtil.isNotBlank(vo.getAdvanceInvoice())){
+ if (StrUtil.isNotBlank(vo.getAdvanceInvoice())) {
//杩樺師棰勫紑鏁伴噺
List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class);
if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) {
outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
- if (ObjUtil.isNotNull(subjectMatter)){
+ if (ObjUtil.isNotNull(subjectMatter)) {
subjectMatter.setAdvanceNum(subjectMatter.getAdvanceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
- if (subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0"))<=0){
+ if (subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0")) <= 0) {
subjectMatter.setAdvanceNum(new BigDecimal("0"));
}
contractSubjectMatterMapper.updateById(subjectMatter);
@@ -1235,10 +1362,8 @@
if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) {
outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
- if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) {
- contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
- contractOutBoundMapper.updateById(contractOutBound);
- }
+ contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
+ contractOutBoundMapper.updateById(contractOutBound);
});
}
} else {
@@ -1256,7 +1381,7 @@
}
- private JSONObject genBlueInvoiceVehicle(GenInvoiceInfoVo vo, String serialNo,SysDept dept) {
+ private JSONObject genBlueInvoiceVehicle(GenInvoiceInfoVo vo, String serialNo, SysDept dept) {
JSONObject vechicleData = JSONObject.parseObject(vo.getVehicleData());
JSONObject jsonObject = new JSONObject();
//閿�鏂�
@@ -1275,13 +1400,13 @@
JSONObject invoiceDetail = new JSONObject();
invoiceDetail.put("vehicleNo", vo.getVehicleNo());
- invoiceDetail.put("manufacturingEnterprise","03");
+ invoiceDetail.put("manufacturingEnterprise", "03");
invoiceDetail.put("originPlace", vechicleData.getString("originPlace"));
- invoiceDetail.put("certificateNo",vo.getCertificateNo());
- invoiceDetail.put("engineNo",vechicleData.getString("engineNo"));
- invoiceDetail.put("tonnage",vechicleData.getString("tonnage"));
- invoiceDetail.put("passengersLimited",vechicleData.getString("passengersLimited"));
- invoiceDetail.put("brandModel",vechicleData.getString("brandModel"));
+ invoiceDetail.put("certificateNo", vo.getCertificateNo());
+ invoiceDetail.put("engineNo", vechicleData.getString("engineNo"));
+ invoiceDetail.put("tonnage", vechicleData.getString("tonnage"));
+ invoiceDetail.put("passengersLimited", vechicleData.getString("passengersLimited"));
+ invoiceDetail.put("brandModel", vechicleData.getString("brandModel"));
invoiceDetail.put("goodsCode", vo.getInvoiceItemList().get(0).getTaxCode());
invoiceDetail.put("goodsTaxRate", vo.getInvoiceItemList().get(0).getTaxRate().divide(new BigDecimal("100")));
@@ -1320,10 +1445,8 @@
if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) {
outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
- if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) {
- contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
- contractOutBoundMapper.updateById(contractOutBound);
- }
+ contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
+ contractOutBoundMapper.updateById(contractOutBound);
});
}
} else {
@@ -1430,4 +1553,171 @@
baseMapper.updateById(invoice);
return R.ok();
}
+
+ @Override
+ public R bipPush(Long invoiceId) {
+ ContractInvoice contractInvoice = baseMapper.selectById(invoiceId);
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
+ }
+ Contract contract = contractMapper.selectById(contractInvoice.getContractId());
+ if (ObjUtil.isNull(contract)) {
+ log.error("鏌ヨ鍚堝悓淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍚堝悓淇℃伅寮傚父");
+ }
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) {
+ log.error("鏌ヨ鍚堝悓淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍚堝悓淇℃伅寮傚父");
+ }
+ R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept comp = r.getData();
+
+ R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ閮ㄩ棬淇℃伅寮傚父");
+ return R.failed("鏌ヨ閮ㄩ棬淇℃伅寮傚父");
+ }
+ SysDept dept = rDept.getData();
+
+ //钃濈エ
+ if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "1")) {
+ JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp, dept);
+ String finalAccessToken = accessToken;
+
+ log.info("搴旀敹鍙戠エ闆嗘垚鍏ュ弬:{}", params.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/receivable/saveandsubmit?access_token=" + finalAccessToken, params.toJSONString());
+ log.info("搴旀敹鍙戠エ闆嗘垚鍥炲弬:{}", result);
+ //淇濆瓨璇锋眰璁板綍
+ paymentConfirmService.saveBipRequestRecord(params, "搴旀敹鍙戠エ闆嗘垚鎺ュ彛", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) {
+ JSONObject data = resultJson.getJSONObject("data");
+ contractInvoice.setBipPush("1");
+ contractInvoice.setBipId(data.getLong("id"));
+ contractInvoice.setBipBody(resultJson.getString("data"));
+ baseMapper.updateById(contractInvoice);
+ return R.ok();
+ }
+ return R.failed(resultJson, "搴旀敹鍙戠エ闆嗘垚澶辫触");
+ }
+ //绾㈢エ
+ if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "2")) {
+ JSONObject params = genRedReceiveParams(contractInvoice);
+ String finalAccessToken = accessToken;
+
+ log.info("搴旀敹鍙戠エ鍒犻櫎鍏ュ弬:{}", params.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/receivable/delete?access_token=" + finalAccessToken, params.toJSONString());
+ log.info("搴旀敹鍙戠エ鍒犻櫎鍥炲弬:{}", result);
+ //淇濆瓨璇锋眰璁板綍
+ paymentConfirmService.saveBipRequestRecord(params, "搴旀敹鍙戠エ鍒犻櫎鎺ュ彛", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) {
+ contractInvoice.setBipPush("1");
+ contractInvoice.setBipBody(resultJson.getString("data"));
+ baseMapper.updateById(contractInvoice);
+ return R.ok();
+ }
+ return R.failed(resultJson, "搴旀敹鍙戠エ鍒犻櫎澶辫触");
+ }
+ return R.ok();
+ }
+
+ @Override
+ public R queryInvoice(Page page, InvoiceQueryDTO queryDTO) {
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept comp = r.getData();
+
+ JSONObject request = genQueryInvoiceParam(page, queryDTO, comp);
+ String requestId = IdUtil.fastUUID();
+
+ log.info("宸插紑鍙戠エ鏌ヨ鎺ュ彛鍏ュ弬锛歿},", request.toJSONString());
+ String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.query&version=1.0&request_id=" + requestId, request.toJSONString());
+ log.info("宸插紑鍙戠エ鏌ヨ鎺ュ彛鍥炲弬锛歿},", result);
+ saveBwRequestRecord("baiwang.output.invoice.query", requestId, request.toJSONString(), result);
+ JSONObject resultObj = JSONObject.parseObject(result);
+ if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) &&
+ !resultObj.getBoolean("success")) {
+ return R.failed("宸插紑鍙戠エ鏌ヨ", result);
+ }
+ JSONArray models = resultObj.getJSONArray("model");
+ if (CollUtil.isNotEmpty(models)) {
+ page.setRecords(models);
+ page.setTotal(resultObj.getInteger("total"));
+ return R.ok(page);
+ }
+ page.setTotal(0);
+ page.setRecords(null);
+ return R.ok(page);
+ }
+
+ private JSONObject genQueryInvoiceParam(Page page, InvoiceQueryDTO queryDTO, SysDept comp) {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("taxNo", comp.getOrgCode());
+ JSONObject data = new JSONObject();
+ data.put("serialNo", StrUtil.isNotBlank(queryDTO.getSerialNo()) ? queryDTO.getSerialNo() : "");
+ data.put("invoiceCode", StrUtil.isNotBlank(queryDTO.getInvoiceCode()) ? queryDTO.getInvoiceCode() : "");
+ data.put("invoiceNo", StrUtil.isNotBlank(queryDTO.getInvoiceNo()) ? queryDTO.getInvoiceNo() : "");
+ data.put("invoiceTypeCode", StrUtil.isNotBlank(queryDTO.getInvoiceTypeCode()) ? queryDTO.getInvoiceTypeCode() : "");
+ data.put("invoiceTerminalCode", StrUtil.isNotBlank(queryDTO.getInvoiceTerminalCode()) ? queryDTO.getInvoiceTerminalCode() : "");
+ data.put("sourceMark", StrUtil.isNotBlank(queryDTO.getSourceMark()) ? queryDTO.getSourceMark() : "");
+ data.put("invoiceSpecialMark", StrUtil.isNotBlank(queryDTO.getInvoiceSpecialMark()) ? queryDTO.getInvoiceSpecialMark() : "");
+ data.put("buyerTaxNo", StrUtil.isNotBlank(queryDTO.getBuyerTaxNo()) ? queryDTO.getBuyerTaxNo() : "");
+ data.put("buyerName", StrUtil.isNotBlank(queryDTO.getBuyerName()) ? queryDTO.getBuyerName() : "");
+ data.put("invoiceStatus", StrUtil.isNotBlank(queryDTO.getInvoiceStatus()) ? queryDTO.getInvoiceStatus() : "");
+ data.put("invoiceType", StrUtil.isNotBlank(queryDTO.getInvoiceType()) ? queryDTO.getInvoiceType() : "");
+ data.put("invoiceStartDate", StrUtil.isNotBlank(queryDTO.getInvoiceStartDate()) ? queryDTO.getInvoiceStartDate() : "");
+ data.put("invoiceEndDate", StrUtil.isNotBlank(queryDTO.getInvoiceEndDate()) ? queryDTO.getInvoiceEndDate() : "");
+ data.put("machineNo", StrUtil.isNotBlank(queryDTO.getMachineNo()) ? queryDTO.getMachineNo() : "");
+ data.put("systemName", StrUtil.isNotBlank(queryDTO.getSystemName()) ? queryDTO.getSystemName() : "");
+ data.put("systemId", StrUtil.isNotBlank(queryDTO.getSystemId()) ? queryDTO.getSystemId() : "");
+ data.put("pageSize", page.getSize());
+ data.put("pageNo", page.getCurrent());
+ jsonObject.put("data", data);
+ return jsonObject;
+ }
+
+ @Override
+ public R add(ContractInvoice contractInvoice) {
+ Contract contract = contractMapper.selectById(contractInvoice.getContractId());
+ if (ObjUtil.isNull(contract)) {
+ return R.failed("鍚堝悓淇℃伅寮傚父");
+ }
+ List<ContractInvoice> invoiceList = baseMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery()
+ .eq(ContractInvoice::getInvoiceNo, contractInvoice.getInvoiceNo()));
+ if (CollUtil.isNotEmpty(invoiceList)) {
+ return R.failed("鍙戠エ宸插瓨鍦紝璇峰嬁閲嶅鎿嶄綔");
+ }
+ contractInvoice.setInvoiceStatus("2");
+ contractInvoice.setInvoiceSource("1");
+ contractInvoice.setRedReversal("0");
+ contractInvoice.setApprovalStatus("1");
+ baseMapper.insert(contractInvoice);
+ contract.setBillingAmout(contract.getBillingAmout().add(contractInvoice.getInvoiceTotalPriceTax()));
+ if (contract.getBillingAmout().compareTo(contract.getAmount()) >= 0) {
+ contract.setBillingStatus("3");
+ }
+ contractMapper.updateById(contract);
+ return R.ok();
+ }
+
+ public static void main(String[] args) {
+ File file = new File("d://tmp//" + IdUtil.fastUUID() + ".pdf");
+ HttpUtil.downloadFile("http://fp.baiwang.com/format/d?d=BB99645F8ED2AE7D2055E7D29330D366B7CAE92C278C6BB84D222610CEC2118D", file);
+ }
}
--
Gitblit v1.9.1