ComputePayFeeCouponCmd.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.java110.acct.cmd.coupon;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.java110.core.annotation.Java110Cmd;
  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.doc.annotation.*;
  9. import com.java110.dto.couponRuleCpps.CouponRuleCppsDto;
  10. import com.java110.dto.couponRuleFee.CouponRuleFeeDto;
  11. import com.java110.dto.fee.FeeDto;
  12. import com.java110.intf.acct.ICouponRuleCppsV1InnerServiceSMO;
  13. import com.java110.intf.acct.ICouponRuleFeeV1InnerServiceSMO;
  14. import com.java110.intf.fee.IFeeInnerServiceSMO;
  15. import com.java110.utils.exception.CmdException;
  16. import com.java110.utils.util.Assert;
  17. import com.java110.utils.util.DateUtil;
  18. import com.java110.vo.ResultVo;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import java.text.ParseException;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. @Java110CmdDoc(title = "根据费用计算优惠券",
  24. description = "缴费时计算费用 是否有优惠券",
  25. httpMethod = "get",
  26. url = "http://{ip}:{port}/app/coupon.computePayFeeCoupon",
  27. resource = "acctDoc",
  28. author = "吴学文",
  29. serviceCode = "coupon.computePayFeeCoupon"
  30. )
  31. @Java110ParamsDoc(params = {
  32. @Java110ParamDoc(name = "feeId", length = 30, remark = "费用ID"),
  33. @Java110ParamDoc(name = "cycle", length = 30, remark = "缴费周期"),
  34. @Java110ParamDoc(name = "communityId", length = 30, remark = "小区ID"),
  35. })
  36. @Java110ResponseDoc(
  37. params = {
  38. @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 其他失败"),
  39. @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
  40. @Java110ParamDoc(name = "data", type = "Array", remark = "有效数据"),
  41. @Java110ParamDoc(parentNodeName = "data",name = "userId", type = "String", remark = "用户ID"),
  42. @Java110ParamDoc(parentNodeName = "data",name = "token", type = "String", remark = "临时票据"),
  43. }
  44. )
  45. @Java110ExampleDoc(
  46. reqBody="{'feeId':'123123','cycle':'1','communityId':'123123'}",
  47. resBody="{'code':0,'msg':'成功','data':{'userId':'123123','token':'123213'}}"
  48. )
  49. @Java110Cmd(serviceCode = "coupon.computePayFeeCoupon")
  50. public class ComputePayFeeCouponCmd extends Cmd {
  51. @Autowired
  52. private ICouponRuleFeeV1InnerServiceSMO couponRuleFeeV1InnerServiceSMOImpl;
  53. @Autowired
  54. private ICouponRuleCppsV1InnerServiceSMO couponRuleCppsV1InnerServiceSMOImpl;
  55. @Autowired
  56. private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
  57. @Override
  58. public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
  59. Assert.hasKeyAndValue(reqJson,"feeId","未包含费用");
  60. Assert.hasKeyAndValue(reqJson,"communityId","未包含小区");
  61. Assert.hasKeyAndValue(reqJson,"cycles","未包含缴费周期");
  62. }
  63. @Override
  64. public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  65. FeeDto feeDto = new FeeDto();
  66. feeDto.setFeeId(reqJson.getString("feeId"));
  67. List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
  68. Assert.listOnlyOne(feeDtos,"费用不存在");
  69. CouponRuleFeeDto couponRuleFeeDto = new CouponRuleFeeDto();
  70. couponRuleFeeDto.setFeeConfigId(feeDtos.get(0).getConfigId());
  71. couponRuleFeeDto.setCurTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
  72. couponRuleFeeDto.setCommunityId(reqJson.getString("communityId"));
  73. couponRuleFeeDto.setCycle(reqJson.getString("cycles"));
  74. List<CouponRuleFeeDto> couponRuleFeeDtos = couponRuleFeeV1InnerServiceSMOImpl.queryCouponRuleFees(couponRuleFeeDto);
  75. if(couponRuleFeeDtos == null || couponRuleFeeDtos.size()<1){
  76. context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
  77. return ;
  78. }
  79. List<String> ruleIds = new ArrayList<>();
  80. for(CouponRuleFeeDto tmpCouponRuleFeeDto: couponRuleFeeDtos){
  81. ruleIds.add(tmpCouponRuleFeeDto.getRuleId());
  82. }
  83. CouponRuleCppsDto couponRuleCppsDto = new CouponRuleCppsDto();
  84. couponRuleCppsDto.setRuleIds(ruleIds.toArray(new String[ruleIds.size()]));
  85. List<CouponRuleCppsDto> couponRuleCppsDtos = couponRuleCppsV1InnerServiceSMOImpl.queryCouponRuleCppss(couponRuleCppsDto);
  86. if(couponRuleCppsDtos == null || couponRuleCppsDtos.size() < 1){
  87. context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
  88. return ;
  89. }
  90. context.setResponseEntity(ResultVo.createResponseEntity(couponRuleCppsDtos));
  91. }
  92. }