From c1275e416cad00bf3eb014a62f1d06404cccb3c4 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Fri, 22 Apr 2022 10:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=B5=E5=B7=9E=E4=B8=AD=E7=9F=B3=E5=8C=96?= =?UTF-8?q?=E5=88=86=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighCouponAgentController.java | 55 ++++++----- .../hai/service/HighCouponAgentService.java | 8 ++ .../service/HighCouponCodeOtherService.java | 7 ++ .../impl/HighCouponAgentServiceImpl.java | 94 ++++++++++++++++++- .../impl/HighCouponCodeOtherServiceImpl.java | 11 +++ 5 files changed, 152 insertions(+), 23 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java index 8265d525..a785a0b2 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -9,6 +9,7 @@ import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; +import com.hai.common.utils.MemberValidateUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.*; import com.hai.model.ResponseData; @@ -16,6 +17,7 @@ import com.hai.model.UserInfoModel; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -57,6 +59,8 @@ public class HighCouponAgentController { @Resource private HighCouponService highCouponService; + @Resource + private HighCouponCodeOtherService couponCodeOtherService; @RequestMapping(value = "/getAgentCount", method = RequestMethod.GET) @ResponseBody @@ -404,6 +408,7 @@ public class HighCouponAgentController { Map map = new HashMap<>(); map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); map.put("couponCode", highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId())); + map.put("couponCodeOther", couponCodeOtherService.getDetailByCouponAgentCodeId(couponAgentCode.getId())); map.put("couponAgentCode", couponAgentCode); return ResponseMsgUtil.success(map); @@ -413,7 +418,6 @@ public class HighCouponAgentController { } } - @RequestMapping(value = "/remark", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "填写备注") @@ -444,44 +448,51 @@ public class HighCouponAgentController { } } - @RequestMapping(value = "/getRecordByCouponAgentId", method = RequestMethod.GET) + @RequestMapping(value = "/pushGzSinopec", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "根据卡券与代理商关系 查询分发记录") - public ResponseData getRecordByCouponAgentId(@RequestParam(name = "couponAgentId", required = true) Long couponAgentId, - @RequestParam(name = "pageNum", required = true) Integer pageNum, - @RequestParam(name = "pageSize", required = true) Integer pageSize, - HttpServletRequest request) { + @ApiOperation(value = "推送贵州中石化") + public ResponseData pushGzSinopec(@RequestBody String reqBody) { try { - Map map = new HashMap<>(); - map.put("couponAgentId", couponAgentId); - PageHelper.startPage(pageNum,pageSize); - return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getRecordList(map))); + JSONObject jsonObject = JSONObject.parseObject(reqBody); + Long couponAgentCodeId = jsonObject.getLong("couponAgentCodeId"); + String phone = jsonObject.getString("phone"); + String remark = jsonObject.getString("remark"); + if (couponAgentCodeId == null || StringUtils.isBlank(phone) || StringUtils.isBlank(remark)) { + log.error("HighMerchantStoreController -> useCouponCode() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + if (!MemberValidateUtil.validatePhone(phone)) { + log.error("HighMerchantStoreController -> useCouponCode() error!","手机号格式错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号格式错误"); + } + + highCouponAgentService.pushGzSinopec(couponAgentCodeId, phone, remark); + + return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { - log.error("HighCouponAgentController --> getRecordByCouponAgentId() error!", e); + log.error("HighCouponAgentController --> pushGzSinopec() error!", e); return ResponseMsgUtil.exception(e); } } - - @RequestMapping(value = "/getCouponByRecord", method = RequestMethod.GET) + @RequestMapping(value = "/getRecordByCouponAgentId", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "根据分发记录 查询卡券") - public ResponseData getCouponByRecord(@RequestParam(name = "recordId", required = true) Long recordId, + @ApiOperation(value = "根据卡券与代理商关系 查询分发记录") + public ResponseData getRecordByCouponAgentId(@RequestParam(name = "couponAgentId", required = true) Long couponAgentId, @RequestParam(name = "pageNum", required = true) Integer pageNum, - @RequestParam(name = "pageSize", required = true) Integer pageSize) { + @RequestParam(name = "pageSize", required = true) Integer pageSize, + HttpServletRequest request) { try { Map map = new HashMap<>(); - map.put("recordId", recordId); - + map.put("couponAgentId", couponAgentId); PageHelper.startPage(pageNum,pageSize); - return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getCouponAgentCodeList(map))); + return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getRecordList(map))); } catch (Exception e) { - log.error("HighCouponAgentController --> getCouponByRecord() error!", e); + log.error("HighCouponAgentController --> getRecordByCouponAgentId() error!", e); return ResponseMsgUtil.exception(e); } } - } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index 78cd9f89..a8dda49e 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -127,4 +127,12 @@ public interface HighCouponAgentService { */ Map useConvertCode(String phone, String code) throws Exception; + /** + * 推送贵州中石化 + * @param phone 手机号 + * @param remark 备注 + * @return + */ + Map pushGzSinopec(Long couponAgentRelId, String phone, String remark) throws Exception; + } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java index 97d377f4..1be265e5 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java @@ -14,4 +14,11 @@ public interface HighCouponCodeOtherService { */ List getList(Map map); + /** + * 查询详情 + * @param couponAgentCodeId + * @return + */ + HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 0997f502..986f173d 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -66,6 +66,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { @Resource private HighCouponCodeOtherMapper highCouponCodeOtherMapper; + @Resource + private HighCouponCodeOtherService couponCodeOtherService; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) { @@ -454,7 +457,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { Map push = new HashMap<>(); push.put("token", token); - push.put("orderNo", coupon.getCouponKey()); + push.put("orderNo", convertCode.getConvertCode()); push.put("couTypeCode", coupon.getCouponKey()); push.put("distCouCount", 1); push.put("userPhone", phone); @@ -524,4 +527,93 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { return map; } + + @Override + public Map pushGzSinopec(Long couponAgentRelId, String phone, String remark) throws Exception { + // 查询兑换码 + HighCouponAgentCode convertCode = getCodeById(couponAgentRelId); + if (convertCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的数据"); + } + if (convertCode.getStatus() == 3) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已被使用"); + } + // 查询卡券 + HighCoupon coupon = highCouponService.getCouponById(convertCode.getCouponId()); + if (coupon == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的卡券"); + } + // 卡券来源:1.中石化 2.消费券 3.其他 4:贵州中石化 + if (!coupon.getCouponSource().equals(4)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "不是中石化卡券"); + } + if (StringUtils.isBlank(phone)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "需要填写手机手机号"); + } + convertCode.setConvertUserPhone(phone); + convertCode.setRemark(remark); + convertCode.setCouponCode(System.currentTimeMillis()+""); + convertCode.setStatus(2); + highCouponAgentCodeMapper.updateByPrimaryKey(convertCode); + + HighCouponAgentRel couponAgent = highCouponAgentRelMapper.selectByPrimaryKey(convertCode.getCouponAgentId()); + couponAgent.setStockCount(couponAgent.getStockCount() - 1); + couponAgent.setSalesCount(couponAgent.getSalesCount() + 1); + highCouponAgentRelMapper.updateByPrimaryKey(couponAgent); + + // 获取token + String token = huiLianTongConfig.getToken(); + + Map push = new HashMap<>(); + push.put("token", token); + push.put("orderNo", convertCode.getConvertCode()); + push.put("couTypeCode", coupon.getCouponKey()); + push.put("distCouCount", 1); + push.put("userPhone", phone); + push.put("thirdUserId", phone); + + // 推送给高速 + JSONObject returnParam = HuiLianTongConfig.couJointDist(token, + MapUtils.getString(push, "orderNo"), + MapUtils.getString(push, "couTypeCode"), + MapUtils.getInteger(push, "distCouCount"), + MapUtils.getString(push, "userPhone"), + MapUtils.getString(push, "userPhone") + ); + + if (returnParam != null && returnParam.getString("result").equals("success")) { + JSONArray dataArray = returnParam.getJSONArray("data"); + for (Object data : dataArray) { + JSONObject dataObject = (JSONObject) data; + HighCouponCodeOther couponCodeOther = new HighCouponCodeOther(); + couponCodeOther.setType(1); + couponCodeOther.setCouponAgentCodeId(convertCode.getId()); + couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode")); + couponCodeOther.setCouNo(dataObject.getString("couNo")); + couponCodeOther.setActiveTime(dataObject.getDate("activeTime")); + couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate")); + couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate")); + couponCodeOther.setStatus(20); + couponCodeOther.setCreateTime(new Date()); + highCouponCodeOtherMapper.insert(couponCodeOther); + } + } + // 推送记录 + HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); + highGasOrderPush.setType(OrderPushType.type6.getType()); + highGasOrderPush.setOrderNo(convertCode.getCouponCode()); + highGasOrderPush.setCreateTime(new Date()); + highGasOrderPush.setCode(returnParam.getString("result")); + highGasOrderPush.setRequestContent(JSONObject.toJSONString(push)); + highGasOrderPush.setReturnContent(returnParam.toJSONString()); + highGasOrderPushMapper.insert(highGasOrderPush); + + // 查询卡券销售码 + Map map = new HashMap<>(); + map.put("couponInfo", highCouponService.getCouponById(convertCode.getCouponId())); + map.put("couponCode", highCouponCodeService.getCouponCodeById(convertCode.getCouponCodeId())); + map.put("couponCodeOther", couponCodeOtherService.getDetailByCouponAgentCodeId(couponAgentRelId)); + map.put("couponAgentCode", convertCode); + return map; + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java index d96fb8bb..22090a80 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java @@ -35,4 +35,15 @@ public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherServic } return highCouponCodeOtherMapper.selectByExample(example); } + + @Override + public HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId) { + HighCouponCodeOtherExample example = new HighCouponCodeOtherExample(); + example.createCriteria().andCouponAgentCodeIdEqualTo(couponAgentCodeId); + List list = highCouponCodeOtherMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } }