| | |
| | | package com.java110.fee.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Transactional; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.dto.applyRoomDiscount.ApplyRoomDiscountDto; |
| | | import com.java110.dto.applyRoomDiscountType.ApplyRoomDiscountTypeDto; |
| | | import com.java110.dto.fee.FeeDetailDto; |
| | | import com.java110.dto.feeDiscount.FeeDiscountRuleDto; |
| | | import com.java110.fee.bmo.account.ISaveAccountBMO; |
| | | import com.java110.fee.bmo.account.IUpdateAccountBMO; |
| | | import com.java110.fee.bmo.applyRoomDiscount.IAuditApplyRoomDiscountBMO; |
| | | import com.java110.fee.bmo.applyRoomDiscount.IDeleteApplyRoomDiscountBMO; |
| | | import com.java110.fee.bmo.applyRoomDiscount.IGetApplyRoomDiscountBMO; |
| | |
| | | import com.java110.fee.bmo.applyRoomDiscountType.IGetApplyRoomDiscountTypeBMO; |
| | | import com.java110.fee.bmo.applyRoomDiscountType.ISaveApplyRoomDiscountTypeBMO; |
| | | import com.java110.fee.bmo.applyRoomDiscountType.IUpdateApplyRoomDiscountTypeBMO; |
| | | import com.java110.intf.acct.IAccountInnerServiceSMO; |
| | | import com.java110.intf.fee.IApplyRoomDiscountInnerServiceSMO; |
| | | import com.java110.intf.fee.IFeeDetailInnerServiceSMO; |
| | | import com.java110.intf.fee.IFeeDiscountRuleInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO; |
| | | import com.java110.po.applyRoomDiscount.ApplyRoomDiscountPo; |
| | | import com.java110.po.applyRoomDiscountType.ApplyRoomDiscountTypePo; |
| | | import com.java110.utils.util.Assert; |
| | |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestHeader; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | |
| | | @RestController |
| | | @RequestMapping(value = "/applyRoomDiscount") |
| | | public class ApplyRoomDiscountApi { |
| | | |
| | | private static final String SPEC_RATE = "89002020980013"; // 打折率 |
| | | |
| | | @Autowired |
| | | private ISaveApplyRoomDiscountBMO saveApplyRoomDiscountBMOImpl; |
| | |
| | | @Autowired |
| | | private IApplyRoomDiscountInnerServiceSMO applyRoomDiscountInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IFeeDiscountRuleInnerServiceSMO feeDiscountRuleInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IFeeDetailInnerServiceSMO feeDetailInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IOwnerRoomRelInnerServiceSMO ownerRoomRelInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IAccountInnerServiceSMO accountInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private ISaveAccountBMO saveAccountBMOImpl; |
| | | |
| | | @Autowired |
| | | private IUpdateAccountBMO updateAccountBMOImpl; |
| | | |
| | | /** |
| | | * 优惠申请 |
| | | * |
| | |
| | | Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime"); |
| | | Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime"); |
| | | Assert.hasKeyAndValue(reqJson, "applyType", "请求报文中未包含applyType"); |
| | | if (!StringUtil.isEmpty(reqJson.getString("startTime"))) { |
| | | String startTime = reqJson.getString("startTime") + " 00:00:00"; |
| | | reqJson.put("startTime", startTime); |
| | | } |
| | | if (!StringUtil.isEmpty(reqJson.getString("endTime"))) { |
| | | String endTime = reqJson.getString("endTime") + " 23:59:59"; |
| | | reqJson.put("endTime", endTime); |
| | | } |
| | | ApplyRoomDiscountPo applyRoomDiscountPo = BeanConvertUtil.covertBean(reqJson, ApplyRoomDiscountPo.class); |
| | | ApplyRoomDiscountDto applyRoomDiscountDto = new ApplyRoomDiscountDto(); |
| | | applyRoomDiscountDto.setCommunityId(applyRoomDiscountPo.getCommunityId()); |
| | | applyRoomDiscountDto.setRoomId(applyRoomDiscountPo.getRoomId()); |
| | | applyRoomDiscountDto.setFeeId(applyRoomDiscountPo.getFeeId()); |
| | | //查询折扣申请表中该房屋下符合条件的最新的一条数据 |
| | | List<ApplyRoomDiscountDto> applyRoomDiscountDtos = applyRoomDiscountInnerServiceSMOImpl.queryFirstApplyRoomDiscounts(applyRoomDiscountDto); |
| | | //获取本次填写的开始时间 |
| | | Date startDate = simpleDateFormat.parse(applyRoomDiscountPo.getStartTime()); |
| | | if (applyRoomDiscountDtos.size() == 0) { |
| | | //空置房优惠可用 |
| | | applyRoomDiscountPo.setInUse("0"); |
| | | return saveApplyRoomDiscountBMOImpl.save(applyRoomDiscountPo); |
| | | } else if (applyRoomDiscountDtos.size() > 0) { |
| | | //取出结束时间 |
| | | String endTime = applyRoomDiscountDtos.get(0).getEndTime(); |
| | | Date finishTime = simpleDateFormat.parse(endTime); |
| | | if (startDate.getTime() - finishTime.getTime() >= 0) { |
| | | //空置房优惠可用 |
| | | applyRoomDiscountPo.setInUse("0"); |
| | | return saveApplyRoomDiscountBMOImpl.save(applyRoomDiscountPo); |
| | | } else { |
| | | throw new UnsupportedOperationException("该时间段已经申请过空置房,请重新输入空置房申请开始和结束时间"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改优惠申请 |
| | | * |
| | | * @param reqJson |
| | | * @return |
| | | * @serviceCode /applyRoomDiscount/editApplyRoomDiscount |
| | | * @path /app/applyRoomDiscount/editApplyRoomDiscount |
| | | */ |
| | | @RequestMapping(value = "/editApplyRoomDiscount", method = RequestMethod.POST) |
| | | public ResponseEntity<String> editApplyRoomDiscount(@RequestBody JSONObject reqJson, @RequestHeader(value = "user-id") String userId) { |
| | | Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId"); |
| | | Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含验房状态"); |
| | | Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含开始时间"); |
| | | Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含结束时间"); |
| | | Assert.hasKeyAndValue(reqJson, "ardId", "ardId不能为空"); |
| | | ApplyRoomDiscountPo applyRoomDiscountPo = BeanConvertUtil.covertBean(reqJson, ApplyRoomDiscountPo.class); |
| | | return updateApplyRoomDiscountBMOImpl.update(applyRoomDiscountPo); |
| | | } |
| | | |
| | | /** |
| | | * 审批接口 |
| | | * |
| | | * @param reqJson |
| | |
| | | * @path /app/applyRoomDiscount/updateReviewApplyRoomDiscount |
| | | */ |
| | | @RequestMapping(value = "/updateReviewApplyRoomDiscount", method = RequestMethod.POST) |
| | | public ResponseEntity<String> updateReviewApplyRoomDiscount(@RequestBody JSONObject reqJson, @RequestHeader(value = "user-id") String userId) { |
| | | @Java110Transactional |
| | | public ResponseEntity<String> updateReviewApplyRoomDiscount(@RequestBody JSONObject reqJson, @RequestHeader(value = "user-id") String userId, DataFlowContext dataFlowContext) { |
| | | Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId"); |
| | | Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含验房状态"); |
| | | Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含开始时间"); |
| | | Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含结束时间"); |
| | | Assert.hasKeyAndValue(reqJson, "reviewRemark", "请求报文中未包含验房说明"); |
| | | // Assert.hasKeyAndValue(reqJson, "discountId", "请求报文中未包含折扣"); |
| | | Assert.hasKeyAndValue(reqJson, "ardId", "ardId不能为空"); |
| | | ApplyRoomDiscountDto applyRoomDiscountDto = new ApplyRoomDiscountDto(); |
| | | applyRoomDiscountDto.setArdId(reqJson.getString("ardId")); |
| | |
| | | Assert.listOnlyOne(applyRoomDiscountDtos, "查询房屋优惠信息错误!"); |
| | | //获取房屋优惠审核状态 |
| | | String state = applyRoomDiscountDtos.get(0).getState(); |
| | | if (!StringUtil.isEmpty(state) && !state.equals("2")) { |
| | | String stateNow = reqJson.getString("state"); |
| | | String returnWay = reqJson.getString("returnWay"); |
| | | if (!StringUtil.isEmpty(state) && state.equals("4")) { |
| | | throw new IllegalArgumentException("该房屋已审核过,无法再次进行审核!"); |
| | | } |
| | | if (reqJson.containsKey("selectedFees") && !StringUtil.isEmpty(reqJson.getString("selectedFees")) && stateNow.equals("4") && "1002".equals(returnWay)) { |
| | | //获取前端传来的缴费历史 |
| | | String selectedFees = reqJson.getString("selectedFees"); |
| | | JSONArray feeDetailIds = JSON.parseArray(selectedFees); |
| | | //获取优惠 |
| | | JSONArray discounts = reqJson.getJSONArray("discounts"); |
| | | BigDecimal cashBackAmount = new BigDecimal("0.00");//返现总金额 |
| | | for (int i = 0; i < discounts.size(); i++) { |
| | | JSONObject discountObject = discounts.getJSONObject(i); |
| | | JSONArray feeDiscountSpecs = discountObject.getJSONArray("feeDiscountSpecs"); |
| | | //获取规则id |
| | | String ruleId = discounts.getJSONObject(i).getString("ruleId"); |
| | | FeeDiscountRuleDto feeDiscountRuleDto = new FeeDiscountRuleDto(); |
| | | feeDiscountRuleDto.setRuleId(ruleId); |
| | | List<FeeDiscountRuleDto> feeDiscountRuleDtos = feeDiscountRuleInnerServiceSMOImpl.queryFeeDiscountRules(feeDiscountRuleDto); |
| | | Assert.listOnlyOne(feeDiscountRuleDtos, "查询折扣规则错误!"); |
| | | //获取折扣类型(1: 打折 2:减免 3:滞纳金 4:空置房打折 5:空置房减免) |
| | | String discountSmallType = feeDiscountRuleDtos.get(0).getDiscountSmallType(); |
| | | //获取规则 |
| | | //String specValue = feeDiscountSpecs.getJSONObject(1).getString("specValue"); |
| | | String specValue = getRateSpecValueByFeeDiscountSpecs(feeDiscountSpecs); |
| | | if (!StringUtil.isEmpty(discountSmallType) && (discountSmallType.equals("1") || discountSmallType.equals("4"))) { //打折 |
| | | for (int index = 0; index < feeDetailIds.size(); index++) { |
| | | String feeDetailId = String.valueOf(feeDetailIds.get(index)); |
| | | FeeDetailDto feeDetailDto = new FeeDetailDto(); |
| | | feeDetailDto.setDetailId(feeDetailId); |
| | | List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto); |
| | | Assert.listOnlyOne(feeDetailDtos, "查询费用明细表错误!"); |
| | | |
| | | BigDecimal receivedAmount = new BigDecimal(feeDetailDtos.get(0).getReceivedAmount());//获取实收金额 |
| | | BigDecimal spec = new BigDecimal(specValue);//折扣 |
| | | //计算打折后的实收金额 |
| | | BigDecimal money = receivedAmount.multiply(spec); |
| | | cashBackAmount = cashBackAmount.add(receivedAmount.subtract(money)); //计算优惠的金额 |
| | | } |
| | | } else if (!StringUtil.isEmpty(discountSmallType) && (discountSmallType.equals("2") || discountSmallType.equals("5"))) { //减免 |
| | | for (int index = 0; index < feeDetailIds.size(); index++) { |
| | | String feeDetailId = String.valueOf(feeDetailIds.get(index)); |
| | | FeeDetailDto feeDetailDto = new FeeDetailDto(); |
| | | feeDetailDto.setDetailId(feeDetailId); |
| | | List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto); |
| | | Assert.listOnlyOne(feeDetailDtos, "查询费用明细表错误!"); |
| | | |
| | | BigDecimal spec = new BigDecimal(specValue);//减免金額 |
| | | cashBackAmount = cashBackAmount.add(spec); //计算优惠的金额 |
| | | } |
| | | } |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | | reqJson.put("cashBackAmount", df.format(cashBackAmount)); |
| | | //处理账户返现 |
| | | JSONArray businesses = new JSONArray(); |
| | | updateAccountBMOImpl.cashBackAccount(reqJson, dataFlowContext, businesses); |
| | | reqJson.put("inUse", 1); |
| | | reqJson.put("returnAmount", df.format(cashBackAmount)); |
| | | } |
| | | } else { |
| | | reqJson.put("inUse", 0); |
| | | } |
| | | reqJson.put("reviewUserId", userId); |
| | | ApplyRoomDiscountPo applyRoomDiscountPo = BeanConvertUtil.covertBean(reqJson, ApplyRoomDiscountPo.class); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 89002020980001 102020001 月份 |
| | | * 89002020980002 102020001 打折率 |
| | | * 89002020980003 102020002 月份 |
| | | * 89002020980004 102020002 减免金额 |
| | | * 89002020980005 102020003 滞纳金 |
| | | * 89002020980006 102020004 滞纳金 |
| | | * 89002020980007 102020005 月份 |
| | | * 89002020980008 102020005 打折率 |
| | | * 89002020980009 102020005 欠费时长 |
| | | * 89002020980010 102020006 月份 |
| | | * 89002020980011 102020006 减免金额 |
| | | * 89002020980012 102020007 月份 |
| | | * 89002020980013 102020007 打折率 |
| | | * @param feeDiscountSpecs |
| | | * @return |
| | | */ |
| | | private String getRateSpecValueByFeeDiscountSpecs(JSONArray feeDiscountSpecs) { |
| | | |
| | | for (int specIndex = 0; specIndex < feeDiscountSpecs.size(); specIndex++) { |
| | | if (SPEC_RATE.equals(feeDiscountSpecs.getJSONObject(specIndex).getString("specId"))) { |
| | | return feeDiscountSpecs.getJSONObject(specIndex).getString("specValue"); |
| | | } |
| | | if ("89002020980002".equals(feeDiscountSpecs.getJSONObject(specIndex).getString("specId"))) { |
| | | return feeDiscountSpecs.getJSONObject(specIndex).getString("specValue"); |
| | | } |
| | | if ("89002020980004".equals(feeDiscountSpecs.getJSONObject(specIndex).getString("specId"))) { |
| | | return feeDiscountSpecs.getJSONObject(specIndex).getString("specValue"); |
| | | } |
| | | if ("89002020980008".equals(feeDiscountSpecs.getJSONObject(specIndex).getString("specId"))) { |
| | | return feeDiscountSpecs.getJSONObject(specIndex).getString("specValue"); |
| | | } |
| | | if ("89002020980011".equals(feeDiscountSpecs.getJSONObject(specIndex).getString("specId"))) { |
| | | return feeDiscountSpecs.getJSONObject(specIndex).getString("specValue"); |
| | | } |
| | | } |
| | | |
| | | throw new IllegalArgumentException("未找到 打折系数"); |
| | | } |
| | | |
| | | /** |
| | | * 验房接口 |
| | | * |
| | | * @param reqJson |