UpdateFeeConfigCmd.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.java110.fee.cmd.feeConfig;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.java110.core.annotation.Java110Cmd;
  4. import com.java110.core.annotation.Java110Transactional;
  5. import com.java110.core.context.ICmdDataFlowContext;
  6. import com.java110.core.event.cmd.Cmd;
  7. import com.java110.core.event.cmd.CmdEvent;
  8. import com.java110.dto.fee.FeeConfigDto;
  9. import com.java110.dto.fee.FeeDto;
  10. import com.java110.dto.payFeeRule.PayFeeRuleDto;
  11. import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
  12. import com.java110.intf.fee.IPayFeeConfigV1InnerServiceSMO;
  13. import com.java110.intf.fee.IPayFeeRuleV1InnerServiceSMO;
  14. import com.java110.intf.fee.IPayFeeV1InnerServiceSMO;
  15. import com.java110.po.fee.PayFeeConfigPo;
  16. import com.java110.po.fee.PayFeePo;
  17. import com.java110.utils.exception.CmdException;
  18. import com.java110.utils.util.Assert;
  19. import com.java110.utils.util.BeanConvertUtil;
  20. import com.java110.vo.ResultVo;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import java.util.List;
  23. @Java110Cmd(serviceCode = "feeConfig.updateFeeConfig")
  24. public class UpdateFeeConfigCmd extends Cmd {
  25. @Autowired
  26. private IPayFeeConfigV1InnerServiceSMO payFeeConfigV1InnerServiceSMOImpl;
  27. @Autowired
  28. private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
  29. @Autowired
  30. private IPayFeeRuleV1InnerServiceSMO payFeeRuleV1InnerServiceSMOImpl;
  31. @Autowired
  32. private IPayFeeV1InnerServiceSMO payFeeV1InnerServiceSMOImpl;
  33. @Override
  34. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  35. Assert.hasKeyAndValue(reqJson, "configId", "费用项ID不能为空");
  36. Assert.hasKeyAndValue(reqJson, "feeTypeCd", "必填,请选择费用类型");
  37. Assert.hasKeyAndValue(reqJson, "feeName", "必填,请填写收费项目");
  38. Assert.hasKeyAndValue(reqJson, "feeFlag", "必填,请选择费用标识");
  39. Assert.hasKeyAndValue(reqJson, "startTime", "必填,请选择计费起始时间");
  40. Assert.hasKeyAndValue(reqJson, "endTime", "必填,请选择计费终止时间");
  41. Assert.hasKeyAndValue(reqJson, "computingFormula", "必填,请填写附加费用");
  42. Assert.hasKeyAndValue(reqJson, "squarePrice", "必填,请填写计费单价");
  43. Assert.hasKeyAndValue(reqJson, "additionalAmount", "必填,请填写附加费用");
  44. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区ID");
  45. Assert.hasKeyAndValue(reqJson, "billType", "必填,请填写出账类型");
  46. }
  47. @Override
  48. @Java110Transactional
  49. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  50. FeeConfigDto feeConfigDto = new FeeConfigDto();
  51. feeConfigDto.setCommunityId(reqJson.getString("communityId"));
  52. feeConfigDto.setConfigId(reqJson.getString("configId"));
  53. List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
  54. Assert.listOnlyOne(feeConfigDtos, "未找到该费用项");
  55. JSONObject businessFeeConfig = new JSONObject();
  56. businessFeeConfig.putAll(reqJson);
  57. businessFeeConfig.put("isDefault", feeConfigDtos.get(0).getIsDefault());
  58. PayFeeConfigPo payFeeConfigPo = BeanConvertUtil.covertBean(businessFeeConfig, PayFeeConfigPo.class);
  59. if("NA".equals(payFeeConfigPo.getState())){
  60. payFeeConfigPo.setState("N");
  61. }
  62. int flag = payFeeConfigV1InnerServiceSMOImpl.updatePayFeeConfig(payFeeConfigPo);
  63. if (flag < 1) {
  64. throw new CmdException("修改费用项失败");
  65. }
  66. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  67. //todo 结束费用
  68. finishFee(reqJson,feeConfigDtos);
  69. //todo 修改费用标识
  70. if (!reqJson.containsKey("feeFlag")) {
  71. return;
  72. }
  73. String feeFlag = reqJson.getString("feeFlag");
  74. //todo 说明没有修改费用项标识
  75. if (feeFlag.equals(feeConfigDtos.get(0).getFeeFlag())) {
  76. return;
  77. }
  78. // todo 检查是否为账单模式,也就是在 poy_fee_rule 中是否有数据,这里有数据不让修改
  79. PayFeeRuleDto payFeeRuleDto = new PayFeeRuleDto();
  80. payFeeRuleDto.setConfigId(feeConfigDtos.get(0).getConfigId());
  81. payFeeRuleDto.setCommunityId(reqJson.getString("communityId"));
  82. int count = payFeeRuleV1InnerServiceSMOImpl.queryPayFeeRulesCount(payFeeRuleDto);
  83. if (count > 0) {
  84. return;
  85. }
  86. PayFeePo payFeePo = new PayFeePo();
  87. payFeePo.setConfigId(feeConfigDtos.get(0).getConfigId());
  88. payFeePo.setFeeFlag(reqJson.getString("feeFlag"));
  89. payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
  90. }
  91. /**
  92. * 结束费用
  93. * @param reqJson
  94. * @param feeConfigDtos
  95. */
  96. private void finishFee(JSONObject reqJson, List<FeeConfigDto> feeConfigDtos) {
  97. String state = reqJson.getString("state");
  98. if(!"NA".equals(state)){
  99. return;
  100. }
  101. PayFeePo payFeePo = new PayFeePo();
  102. payFeePo.setConfigId(feeConfigDtos.get(0).getConfigId());
  103. payFeePo.setState(FeeDto.STATE_FINISH);
  104. payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
  105. }
  106. }