| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Transactional; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.fee.FeeAttrDto; |
| | | import com.java110.dto.fee.FeeConfigDto; |
| | | import com.java110.dto.fee.FeeDto; |
| | | import com.java110.dto.fee.*; |
| | | import com.java110.dto.repair.RepairDto; |
| | | import com.java110.fee.bmo.IPayOweFee; |
| | | import com.java110.fee.listener.fee.UpdateFeeInfoListener; |
| | | import com.java110.intf.IFeeReceiptDetailInnerServiceSMO; |
| | | import com.java110.intf.community.IParkingSpaceInnerServiceSMO; |
| | | import com.java110.intf.community.IRepairInnerServiceSMO; |
| | | 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.community.IRoomInnerServiceSMO; |
| | | 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.service.smo.IComputeFeeSMO; |
| | | 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; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | @Autowired |
| | | private IRepairInnerServiceSMO repairInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IRoomInnerServiceSMO roomInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IParkingSpaceInnerServiceSMO parkingSpaceInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IFeeReceiptDetailInnerServiceSMO feeReceiptDetailInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IFeeReceiptInnerServiceSMO feeReceiptInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IOwnerCarInnerServiceSMO ownerCarInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IComputeFeeSMO computeFeeSMOImpl; |
| | | |
| | | /** |
| | | * 欠费缴费 |
| | | * |
| | |
| | | JSONArray fees = reqJson.getJSONArray("fees"); |
| | | |
| | | JSONObject feeObj = null; |
| | | |
| | | FeeReceiptPo feeReceiptPo = new FeeReceiptPo(); |
| | | feeReceiptPo.setReceiptId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_receiptId)); |
| | | feeReceiptPo.setAmount("0.0"); |
| | | 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); |
| | | } |
| | | if (fees.size() > 0) { |
| | | feeReceiptInnerServiceSMOImpl.saveFeeReceipt(feeReceiptPo); |
| | | } |
| | | return ResultVo.success(); |
| | | } |
| | | |
| | | 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); |
| | | |
| | | //将有账单下的 状态改为已经缴费 |
| | | modifyFeeBill(feeObj); |
| | | |
| | | //判断是否有派单属性ID |
| | | FeeAttrDto feeAttrDto = new FeeAttrDto(); |
| | |
| | | /** |
| | | * @param feeObj |
| | | */ |
| | | private void modifyFeeBill(JSONObject feeObj) { |
| | | |
| | | 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); |
| | | billOweFeeDto.setBillId(billDtos.get(0).getBillId()); |
| | | feeInnerServiceSMOImpl.updateBillOweFees(billOweFeeDto); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @param feeObj |
| | | */ |
| | | private void modifyFee(JSONObject feeObj) throws ParseException { |
| | | |
| | | 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)); |
| | | // 一次性收费类型,缴费后,则设置费用状态为收费结束、设置结束日期为费用项终止日期 |
| | | 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("billType", feeConfigDtos.get(0).getBillType()); |
| | | 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); |
| | | if (saveFlag < 1) { |
| | | throw new IllegalArgumentException("缴费失败" + payFeePo.toString()); |
| | |
| | | * |
| | | * @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)); |
| | |
| | | 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"); |
| | | 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(computeFeeSMOImpl.getFeeStateByCycles(feeDto, cycles.doubleValue() + "")); |
| | | payFeeDetailPo.setCommunityId(paramInJson.getString("communityId")); |
| | | payFeeDetailPo.setCycles(cycles.doubleValue() + ""); |
| | | payFeeDetailPo.setReceivableAmount(receivedAmount.doubleValue() + ""); |
| | | payFeeDetailPo.setReceivedAmount(receivedAmount.doubleValue() + ""); |
| | | payFeeDetailPo.setFeeId(feeDto.getFeeId()); |
| | | |
| | | int saveFeeDetail = feeDetailInnerServiceSMOImpl.saveFeeDetail(payFeeDetailPo); |
| | | |
| | | 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()); |
| | | 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)); |
| | | } |
| | | } |
| | | } |