From 3835848b28f3cf605aa1fbda443024ee11740493 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 10 五月 2021 11:54:14 +0800
Subject: [PATCH] 优化代码
---
service-fee/src/main/java/com/java110/fee/bmo/impl/PayOweFeeImpl.java | 179 ++++++++++++++++++++++++++---------------------------------
1 files changed, 79 insertions(+), 100 deletions(-)
diff --git a/service-fee/src/main/java/com/java110/fee/bmo/impl/PayOweFeeImpl.java b/service-fee/src/main/java/com/java110/fee/bmo/impl/PayOweFeeImpl.java
old mode 100644
new mode 100755
index e158ed8..8ed1b6d
--- a/service-fee/src/main/java/com/java110/fee/bmo/impl/PayOweFeeImpl.java
+++ b/service-fee/src/main/java/com/java110/fee/bmo/impl/PayOweFeeImpl.java
@@ -4,32 +4,29 @@
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.dto.RoomDto;
-import com.java110.dto.fee.BillOweFeeDto;
-import com.java110.dto.fee.FeeAttrDto;
-import com.java110.dto.fee.FeeConfigDto;
-import com.java110.dto.fee.FeeDto;
-import com.java110.dto.parking.ParkingSpaceDto;
+import com.java110.core.smo.IComputeFeeSMO;
+import com.java110.dto.fee.*;
+import com.java110.dto.owner.OwnerDto;
import com.java110.dto.repair.RepairDto;
import com.java110.fee.bmo.IPayOweFee;
import com.java110.fee.listener.fee.UpdateFeeInfoListener;
+import com.java110.intf.fee.IFeeReceiptDetailInnerServiceSMO;
import com.java110.intf.community.IParkingSpaceInnerServiceSMO;
import com.java110.intf.community.IRepairInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
-import com.java110.intf.fee.IFeeAttrInnerServiceSMO;
-import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
-import com.java110.intf.fee.IFeeDetailInnerServiceSMO;
-import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.intf.fee.*;
+import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.po.fee.PayFeeDetailPo;
import com.java110.po.fee.PayFeePo;
+import com.java110.po.feeReceipt.FeeReceiptPo;
+import com.java110.po.feeReceiptDetail.FeeReceiptDetailPo;
import com.java110.po.owner.RepairPoolPo;
-import com.java110.utils.constant.FeeFlagTypeConstant;
-import com.java110.utils.constant.FeeStateConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.ListenerExecuteException;
import com.java110.utils.lock.DistributedLock;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +36,6 @@
import java.math.BigDecimal;
import java.text.ParseException;
-import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -73,6 +69,18 @@
@Autowired
private IParkingSpaceInnerServiceSMO parkingSpaceInnerServiceSMOImpl;
+ @Autowired
+ private IFeeReceiptDetailInnerServiceSMO feeReceiptDetailInnerServiceSMOImpl;
+
+ @Autowired
+ private IFeeReceiptInnerServiceSMO feeReceiptInnerServiceSMOImpl;
+
+ @Autowired
+ private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl;
+
+ @Autowired
+ private IComputeFeeSMO computeFeeSMOImpl;
+
/**
* 娆犺垂缂磋垂
*
@@ -89,26 +97,35 @@
JSONArray fees = reqJson.getJSONArray("fees");
JSONObject feeObj = null;
+ FeeReceiptPo feeReceiptPo = new FeeReceiptPo();
+ feeReceiptPo.setReceiptId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_receiptId));
+ feeReceiptPo.setAmount("0.0");
+
+ feeReceiptPo.setPayObjId("-1");
+ feeReceiptPo.setPayObjName("鏈煡");
for (int feeIndex = 0; feeIndex < fees.size(); feeIndex++) {
feeObj = fees.getJSONObject(feeIndex);
Assert.hasKeyAndValue(feeObj, "feeId", "鏈寘鍚垂鐢ㄩ」ID");
- Assert.hasKeyAndValue(feeObj, "feeId", "鏈寘鍚垂鐢ㄩ」ID");
+ Assert.hasKeyAndValue(feeObj, "feePrice", "鏈寘鍚即璐归噾棰�");
feeObj.put("communityId", communityId);
- doPayOweFee(feeObj);
+ doPayOweFee(feeObj, feeReceiptPo);
}
- return ResultVo.success();
+ if (fees.size() > 0) {
+ feeReceiptInnerServiceSMOImpl.saveFeeReceipt(feeReceiptPo);
+ }
+ return ResultVo.createResponseEntity(feeReceiptPo);
}
- private void doPayOweFee(JSONObject feeObj) {
+ private void doPayOweFee(JSONObject feeObj, FeeReceiptPo feeReceiptPo) {
//寮�鍚叏灞�閿�
String requestId = DistributedLock.getLockUUID();
String key = this.getClass().getSimpleName() + feeObj.get("feeId");
try {
DistributedLock.waitGetDistributedLock(key, requestId);
- addFeeDetail(feeObj);
+ addFeeDetail(feeObj, feeReceiptPo);
modifyFee(feeObj);
@@ -148,16 +165,21 @@
if (FeeConfigDto.BILL_TYPE_EVERY.equals(feeObj.getString("billType"))) {
return;
}
-
+ BillDto billDto = new BillDto();
+ billDto.setCommunityId(feeObj.getString("communityId"));
+ billDto.setConfigId(feeObj.getString("configId"));
+ billDto.setCurBill("T");
+ List<BillDto> billDtos = feeInnerServiceSMOImpl.queryBills(billDto);
+ if (billDtos == null || billDtos.size() < 1) {
+ return;
+ }
BillOweFeeDto billOweFeeDto = new BillOweFeeDto();
billOweFeeDto.setCommunityId(feeObj.getString("communityId"));
billOweFeeDto.setFeeId(feeObj.getString("feeId"));
billOweFeeDto.setState(BillOweFeeDto.STATE_FINISH_FEE);
- int updateFlag = feeInnerServiceSMOImpl.updateBillOweFees(billOweFeeDto);
+ billOweFeeDto.setBillId(billDtos.get(0).getBillId());
+ feeInnerServiceSMOImpl.updateBillOweFees(billOweFeeDto);
- if (updateFlag < 1) {
- throw new IllegalArgumentException("淇敼璐﹀崟澶辫触");
- }
}
/**
@@ -167,34 +189,18 @@
PayFeePo payFeePo = new PayFeePo();
FeeDto feeInfo = (FeeDto) feeObj.get("feeInfo");
- Date endTime = feeInfo.getEndTime();
- Calendar endCalender = Calendar.getInstance();
- endCalender.setTime(endTime);
- int hours = 0;
- hours = new Double(Double.parseDouble(feeObj.getString("tmpCycles")) * DateUtil.getCurrentMonthDay() * 24).intValue();
- endCalender.add(Calendar.HOUR, hours);
FeeConfigDto feeConfigDto = new FeeConfigDto();
feeConfigDto.setConfigId(feeInfo.getConfigId());
feeConfigDto.setCommunityId(feeInfo.getCommunityId());
List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
-
Assert.listOnlyOne(feeConfigDtos, "鏈壘鍒拌垂鐢ㄩ厤缃�");
- payFeePo.setEndTime(DateUtil.getFormatTimeString(endCalender.getTime(), DateUtil.DATE_FORMATE_STRING_A));
feeObj.put("billType", feeConfigDtos.get(0).getBillType());
- // 涓�娆℃�ф敹璐圭被鍨嬶紝缂磋垂鍚庯紝鍒欒缃垂鐢ㄧ姸鎬佷负鏀惰垂缁撴潫銆佽缃粨鏉熸棩鏈熶负璐圭敤椤圭粓姝㈡棩鏈�
- if (FeeFlagTypeConstant.ONETIME.equals(feeConfigDtos.get(0).getFeeFlag())) {
- payFeePo.setState(FeeStateConstant.END);
- payFeePo.setEndTime(feeConfigDtos.get(0).getEndTime());
- }
- // 鍛ㄦ湡鎬ф敹璐广�佺即璐瑰悗锛屽埌鏈熸棩鏈熷湪璐圭敤椤圭粓姝㈡棩鏈熷悗锛屽垯璁剧疆缂磋垂鐘舵�佺粨鏉燂紝璁剧疆缁撴潫鏃ユ湡涓鸿垂鐢ㄩ」缁堟鏃ユ湡
- if (FeeFlagTypeConstant.CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())) {
- if ((feeInfo.getEndTime()).after(DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A))) {
- payFeePo.setState(FeeStateConstant.END);
- payFeePo.setEndTime(feeConfigDtos.get(0).getEndTime());
- }
- }
+ feeObj.put("configId", feeConfigDtos.get(0).getConfigId());
+ Date targetEndTime = computeFeeSMOImpl.getFeeEndTimeByCycles(feeInfo, feeObj.getString("tmpCycles"));
+ String state = computeFeeSMOImpl.getFeeStateByCycles(feeInfo, feeObj.getString("tmpCycles"));
payFeePo.setFeeId(feeObj.getString("feeId"));
- payFeePo.setEndTime(DateUtil.getFormatTimeString(feeInfo.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
+ payFeePo.setEndTime(DateUtil.getFormatTimeString(targetEndTime, DateUtil.DATE_FORMATE_STRING_A));
+ payFeePo.setState(state);
payFeePo.setCommunityId(feeObj.getString("communityId"));
payFeePo.setStatusCd("0");
int saveFlag = feeInnerServiceSMOImpl.updateFee(payFeePo);
@@ -208,7 +214,7 @@
*
* @param paramInJson
*/
- private void addFeeDetail(JSONObject paramInJson) {
+ private void addFeeDetail(JSONObject paramInJson, FeeReceiptPo feeReceiptPo) {
PayFeeDetailPo payFeeDetailPo = new PayFeeDetailPo();
payFeeDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
@@ -218,70 +224,18 @@
feeDto.setFeeId(paramInJson.getString("feeId"));
feeDto.setCommunityId(paramInJson.getString("communityId"));
List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
-
if (feeDtos == null || feeDtos.size() != 1) {
throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏌ヨ璐圭敤淇℃伅澶辫触锛屾湭鏌ュ埌鏁版嵁鎴栨煡鍒板鏉℃暟鎹�");
}
-
feeDto = feeDtos.get(0);
paramInJson.put("feeInfo", feeDto);
-
- BigDecimal feePrice = new BigDecimal("0.00");
-
- if ("3333".equals(feeDto.getPayerObjType())) { //鎴垮眿鐩稿叧
- String computingFormula = feeDto.getComputingFormula();
- if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
- RoomDto roomDto = new RoomDto();
- roomDto.setRoomId(feeDto.getPayerObjId());
- roomDto.setCommunityId(feeDto.getCommunityId());
- List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
- if (roomDtos == null || roomDtos.size() != 1) {
- throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏈煡鍒版埧灞嬩俊鎭紝鏌ヨ澶氭潯鏁版嵁");
- }
- //feePrice = Double.parseDouble(feeDto.getSquarePrice()) * Double.parseDouble(roomDtos.get(0).getBuiltUpArea()) + Double.parseDouble(feeDto.getAdditionalAmount());
- BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
- BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(roomDtos.get(0).getBuiltUpArea()));
- BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
- feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN);
- } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
- //feePrice = Double.parseDouble(feeDto.getAdditionalAmount());
- BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
- feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN);
- } else if ("4004".equals(computingFormula)) {
- feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
- } else {
- throw new IllegalArgumentException("鏆備笉鏀寔璇ョ被鍏紡");
- }
- } else if ("6666".equals(feeDto.getPayerObjType())) {//杞︿綅鐩稿叧
- String computingFormula = feeDto.getComputingFormula();
- if ("1001".equals(computingFormula)) { //闈㈢Н*鍗曚环+闄勫姞璐�
- ParkingSpaceDto parkingSpaceDto = new ParkingSpaceDto();
- parkingSpaceDto.setCommunityId(feeDto.getCommunityId());
- parkingSpaceDto.setPsId(feeDto.getPayerObjId());
- List<ParkingSpaceDto> parkingSpaceDtos = parkingSpaceInnerServiceSMOImpl.queryParkingSpaces(parkingSpaceDto);
-
- if (parkingSpaceDtos == null || parkingSpaceDtos.size() < 1) { //鏁版嵁鏈夐棶棰�
- throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "鏈煡鍒板仠杞︿綅淇℃伅锛屾煡璇㈠鏉℃暟鎹�");
- }
- //feePrice = Double.parseDouble(feeDto.getSquarePrice()) * Double.parseDouble(parkingSpaceDtos.get(0).getArea()) + Double.parseDouble(feeDto.getAdditionalAmount());
- BigDecimal squarePrice = new BigDecimal(Double.parseDouble(feeDto.getSquarePrice()));
- BigDecimal builtUpArea = new BigDecimal(Double.parseDouble(parkingSpaceDtos.get(0).getArea()));
- BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
- feePrice = squarePrice.multiply(builtUpArea).add(additionalAmount).setScale(2, BigDecimal.ROUND_HALF_EVEN);
- } else if ("2002".equals(computingFormula)) { // 鍥哄畾璐圭敤
- //feePrice = Double.parseDouble(feeDto.getAdditionalAmount());
- BigDecimal additionalAmount = new BigDecimal(Double.parseDouble(feeDto.getAdditionalAmount()));
- feePrice = additionalAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN);
- } else if ("4004".equals(computingFormula)) {
- feePrice = new BigDecimal(Double.parseDouble(feeDto.getAmount()));
- } else {
- throw new IllegalArgumentException("鏆備笉鏀寔璇ョ被鍏紡");
- }
- }
+ payFeeDetailPo.setStartTime(DateUtil.getFormatTimeString(feeDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
+ BigDecimal feePrice = new BigDecimal(computeFeeSMOImpl.getFeePrice(feeDto));
BigDecimal receivedAmount = new BigDecimal(Double.parseDouble(paramInJson.getString("feePrice")));
BigDecimal cycles = receivedAmount.divide(feePrice, 2, BigDecimal.ROUND_HALF_EVEN);
paramInJson.put("tmpCycles", cycles);
+ payFeeDetailPo.setEndTime(DateUtil.getFormatTimeString(computeFeeSMOImpl.getFeeEndTimeByCycles(feeDto, cycles.doubleValue() + ""), DateUtil.DATE_FORMATE_STRING_A));
payFeeDetailPo.setCommunityId(paramInJson.getString("communityId"));
payFeeDetailPo.setCycles(cycles.doubleValue() + "");
payFeeDetailPo.setReceivableAmount(receivedAmount.doubleValue() + "");
@@ -293,5 +247,30 @@
if (saveFeeDetail < 1) {
throw new IllegalArgumentException("淇濆瓨璐圭敤璇︽儏澶辫触" + payFeeDetailPo.toString());
}
+ FeeReceiptDetailPo feeReceiptDetailPo = new FeeReceiptDetailPo();
+ feeReceiptDetailPo.setAmount(payFeeDetailPo.getReceivableAmount());
+ feeReceiptDetailPo.setCommunityId(feeDto.getCommunityId());
+ feeReceiptDetailPo.setCycle(payFeeDetailPo.getCycles());
+ feeReceiptDetailPo.setDetailId(payFeeDetailPo.getDetailId());
+ feeReceiptDetailPo.setEndTime(payFeeDetailPo.getEndTime());
+ feeReceiptDetailPo.setFeeId(feeDto.getFeeId());
+ feeReceiptDetailPo.setFeeName(StringUtil.isEmpty(feeDto.getImportFeeName()) ? feeDto.getFeeName() : feeDto.getImportFeeName());
+ feeReceiptDetailPo.setStartTime(payFeeDetailPo.getStartTime());
+ feeReceiptDetailPo.setReceiptId(feeReceiptPo.getReceiptId());
+ computeFeeSMOImpl.freshFeeReceiptDetail(feeDto, feeReceiptDetailPo);
+ feeReceiptDetailInnerServiceSMOImpl.saveFeeReceiptDetail(feeReceiptDetailPo);
+
+ BigDecimal amount = new BigDecimal(Double.parseDouble(feeReceiptPo.getAmount()));
+ amount = amount.add(receivedAmount);
+ feeReceiptPo.setAmount(amount.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue() + "");
+ feeReceiptPo.setCommunityId(feeReceiptDetailPo.getCommunityId());
+ feeReceiptPo.setObjType(feeDto.getPayerObjType());
+ feeReceiptPo.setObjId(feeDto.getPayerObjId());
+ if (StringUtil.isEmpty(feeReceiptPo.getObjName())) {
+ feeReceiptPo.setObjName(computeFeeSMOImpl.getFeeObjName(feeDto));
+ }
+ OwnerDto ownerDto = computeFeeSMOImpl.getFeeOwnerDto(feeDto);
+ feeReceiptPo.setPayObjId(ownerDto.getOwnerId());
+ feeReceiptPo.setPayObjName(ownerDto.getName());
}
}
--
Gitblit v1.8.0