| | |
| | | import com.java110.core.event.cmd.Cmd; |
| | | import com.java110.core.event.cmd.CmdEvent; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.core.factory.Java110TransactionalFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.core.smo.IComputeFeeSMO; |
| | | import com.java110.dto.fee.FeeAttrDto; |
| | |
| | | import com.java110.dto.parking.ParkingSpaceDto; |
| | | import com.java110.dto.repair.RepairDto; |
| | | import com.java110.dto.repair.RepairUserDto; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.intf.community.*; |
| | | import com.java110.intf.fee.*; |
| | | import com.java110.intf.user.IOwnerCarInnerServiceSMO; |
| | | import com.java110.intf.user.IUserV1InnerServiceSMO; |
| | | import com.java110.po.car.OwnerCarPo; |
| | | import com.java110.po.fee.PayFeeDetailPo; |
| | | import com.java110.po.fee.PayFeePo; |
| | | import com.java110.po.owner.RepairPoolPo; |
| | | import com.java110.po.owner.RepairUserPo; |
| | | import com.java110.utils.constant.FeeFlagTypeConstant; |
| | | import com.java110.utils.constant.FeeStateConstant; |
| | | import com.java110.utils.constant.FeeConfigConstant; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.exception.ListenerExecuteException; |
| | |
| | | @Autowired |
| | | private IPayFeeV1InnerServiceSMO payFeeV1InnerServiceSMOImpl; |
| | | @Autowired |
| | | private IPayFeeDetailNewV1InnerServiceSMO payFeeDetailNewV1InnerServiceSMOImpl; |
| | | private IPayFeeDetailV1InnerServiceSMO payFeeDetailNewV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IFeeAttrInnerServiceSMO feeAttrInnerServiceSMOImpl; |
| | |
| | | @Autowired |
| | | private IRepairPoolV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl; |
| | | @Autowired |
| | | private IRepairUserNewV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl; |
| | | private IRepairUserV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IComputeFeeSMO computeFeeSMOImpl; |
| | | |
| | | @Autowired |
| | | private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl; |
| | | |
| | | |
| | | @Override |
| | |
| | | throw new IllegalArgumentException("费用项不存在"); |
| | | } |
| | | Date maxEndTime = feeDtos.get(0).getDeadlineTime(); |
| | | if (FeeDto.FEE_FLAG_CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())) { |
| | | if (!FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) { |
| | | try { |
| | | maxEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | } catch (ParseException e) { |
| | | logger.error("比较费用日期失败", e); |
| | | } |
| | | Date newDate = DateUtil.stepMonth(endTime, paramInObj.getInteger("cycles") - 1); |
| | | if (newDate.getTime() > maxEndTime.getTime()) { |
| | | throw new IllegalArgumentException("缴费周期超过 缴费结束时间"); |
| | | } |
| | | } |
| | | Date newDate = DateUtil.stepMonth(endTime, paramInObj.getInteger("cycles") - 1); |
| | | if (newDate.getTime() > maxEndTime.getTime()) { |
| | | throw new IllegalArgumentException("缴费周期超过 缴费结束时间"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Java110Transactional |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException { |
| | | |
| | | String userId = cmdDataFlowContext.getReqHeaders().get("user-id"); |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserId(userId); |
| | | List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto); |
| | | Assert.listOnlyOne(userDtos, "用户未登录"); |
| | | |
| | | JSONArray fees = reqJson.getJSONArray("fees"); |
| | | JSONObject paramInObj = null; |
| | | JSONArray datas = new JSONArray(); |
| | | for (int feeIndex = 0; feeIndex < fees.size(); feeIndex++) { |
| | | try { |
| | | paramInObj = fees.getJSONObject(feeIndex); |
| | | doDeal(paramInObj, reqJson.getString("communityId"), cmdDataFlowContext); |
| | | doDeal(paramInObj, reqJson.getString("communityId"), cmdDataFlowContext, userDtos.get(0)); |
| | | } catch (Exception e) { |
| | | logger.error("处理异常", e); |
| | | throw new CmdException(e.getMessage()); |
| | |
| | | cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(datas)); |
| | | } |
| | | |
| | | private void doDeal(JSONObject paramObj, String communityId, ICmdDataFlowContext cmdDataFlowContext) throws Exception { |
| | | private void doDeal(JSONObject paramObj, String communityId, ICmdDataFlowContext cmdDataFlowContext, UserDto userDto) throws Exception { |
| | | paramObj.put("communityId", communityId); |
| | | //添加单元信息 |
| | | //获取订单ID |
| | | String oId = Java110TransactionalFactory.getOId(); |
| | | |
| | | //开始锁代码 |
| | | PayFeePo payFeePo = null; |
| | | String requestId = DistributedLock.getLockUUID(); |
| | |
| | | DistributedLock.waitGetDistributedLock(key, requestId); |
| | | JSONObject feeDetail = addFeeDetail(paramObj); |
| | | PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(feeDetail, PayFeeDetailPo.class); |
| | | if (StringUtil.isEmpty(oId)) { |
| | | oId = payFeeDetailPo.getDetailId(); |
| | | } |
| | | payFeeDetailPo.setPayOrderId(oId); |
| | | payFeeDetailPo.setCashierId(userDto.getUserId()); |
| | | payFeeDetailPo.setCashierName(userDto.getName()); |
| | | int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("缴费失败"); |
| | |
| | | throw new IllegalArgumentException("车位已被使用,不能再缴费!"); |
| | | } |
| | | } |
| | | |
| | | Calendar endTimeCalendar = null; |
| | | //车位费用续租 |
| | | for (OwnerCarDto tmpOwnerCarDto : ownerCarDtos) { |
| | | //后付费 或者信用期车辆 加一个月 |
| | | if (FeeConfigDto.PAYMENT_CD_AFTER.equals(feeInfo.getPaymentCd()) |
| | | || OwnerCarDto.CAR_TYPE_CREDIT.equals(tmpOwnerCarDto.getCarType())) { |
| | | endTimeCalendar = Calendar.getInstance(); |
| | | endTimeCalendar.setTime(feeEndTime); |
| | | endTimeCalendar.add(Calendar.MONTH, 1); |
| | | feeEndTime = endTimeCalendar.getTime(); |
| | | } |
| | | if (tmpOwnerCarDto.getEndTime().getTime() >= feeEndTime.getTime()) { |
| | | continue; |
| | | } |
| | |
| | | cycles = new BigDecimal(Double.parseDouble(paramInJson.getString("cycles"))); |
| | | double tmpReceivableAmount = cycles.multiply(feePrice).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | businessFeeDetail.put("receivableAmount", tmpReceivableAmount); |
| | | businessFeeDetail.put("payableAmount", tmpReceivableAmount); |
| | | |
| | | businessFeeDetail.put("endTime", DateUtil.getFormatTimeString(targetEndTime, DateUtil.DATE_FORMATE_STRING_A)); |
| | | paramInJson.put("feeInfo", feeDto); |
| | |
| | | } |
| | | feeInfo.setEndTime(endCalender.getTime()); |
| | | Date maxEndTime = feeInfo.getDeadlineTime(); |
| | | if(FeeDto.FEE_FLAG_CYCLE.equals(feeInfo.getFeeFlag())){ |
| | | if (FeeDto.FEE_FLAG_CYCLE.equals(feeInfo.getFeeFlag())) { |
| | | maxEndTime = feeInfo.getConfigEndTime(); |
| | | } |
| | | //判断 结束时间 是否大于 费用项 结束时间,这里 容错一下,如果 费用结束时间大于 费用项结束时间 30天 走报错 属于多缴费 |
| | | if(maxEndTime != null) { |
| | | if (maxEndTime != null) { |
| | | if (feeInfo.getEndTime().getTime() - maxEndTime.getTime() > 30 * 24 * 60 * 60 * 1000L) { |
| | | throw new IllegalArgumentException("缴费超过了 费用项结束时间"); |
| | | } |
| | |
| | | calendar.add(Calendar.DAY_OF_MONTH, -5); |
| | | maxEndTime = calendar.getTime(); |
| | | if (feeInfo.getEndTime().after(maxEndTime)) { |
| | | businessFee.put("state", FeeStateConstant.END); |
| | | businessFee.put("state", FeeConfigConstant.END); |
| | | businessFee.put("endTime", maxEndTime); |
| | | } |
| | | } |