From 659ad7ea5feebf0deb7de45223dbaacaebe4415d Mon Sep 17 00:00:00 2001 From: 199901012 Date: Tue, 20 Apr 2021 19:27:28 +0800 Subject: [PATCH] =?UTF-8?q?'=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cweb/controller/HighCouponController.java | 16 ++-- .../cweb/controller/HighOrderController.java | 1 + .../com/hai/schedule/SynchronizeCNPC.java | 92 +++++++++++++------ .../hai/service/HighCouponCodeService.java | 7 ++ .../hai/service/HighUserCouponService.java | 8 ++ .../hai/service/SecSinopecConfigService.java | 2 +- .../impl/HighCouponCodeServiceImpl.java | 32 ++++++- .../impl/HighUserCouponServiceImpl.java | 9 ++ .../impl/SecSinopecConfigServiceImpl.java | 2 +- 9 files changed, 128 insertions(+), 41 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index 40de384a..51aeecd7 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -149,24 +149,20 @@ public class HighCouponController { @RequestMapping(value = "/getUserCouponDetail", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取用户卡卷详细") - public ResponseData getUserCouponDetail(@RequestParam(name = "couponId", required = true) Long couponId, + public ResponseData getUserCouponDetail(@RequestParam(name = "userCouponId", required = true) Long userCouponId, HttpServletRequest request) { try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - - HighUserCoupon coupon = highUserCouponService.getUserCoupon(userInfoModel.getHighUser().getId(), couponId); + HighUserCoupon coupon = highUserCouponService.getDetailById(userCouponId); if (coupon == null) { - log.error("HighCouponController --> getUserCouponDetail() error!", "卡卷库存数量不足"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + log.error("HighCouponController --> getUserCouponDetail() error!", "未找到卡券"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到卡券"); } Map map = new HashMap<>(); map.put("highUserCoupon", coupon); map.put("couponInfo", highCouponService.getCouponById(coupon.getCouponId())); - map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(coupon.getCouponCodeId())); + //map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(coupon.getCouponCodeId())); return ResponseMsgUtil.success(map); @@ -194,7 +190,7 @@ public class HighCouponController { Map map = new HashMap<>(); map.put("highUserCoupon", userCoupon); map.put("couponInfo", highCouponService.getCouponById(userCoupon.getCouponId())); - map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(userCoupon.getCouponCodeId())); + //map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(userCoupon.getCouponCodeId())); return ResponseMsgUtil.success(map); } catch (Exception e) { diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index 5d8bf049..32c704c1 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -159,6 +159,7 @@ public class HighOrderController { childOrder.setGoodsSpecName("默认"); } + childOrder.setMemId(userInfoModel.getHighUser().getId()); childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); childOrder.setGiveawayType(false); // 是否是赠品 0:否 1:是 childOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 diff --git a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java index 98c5fdd1..3ce728ed 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java +++ b/hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java @@ -1,21 +1,25 @@ package com.hai.schedule; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.hai.common.utils.DateUtil; import com.hai.common.utils.HttpsUtils; import com.hai.entity.HighOrder; +import com.hai.entity.SecSinopecConfig; +import com.hai.service.HighCouponCodeService; +import com.hai.service.SecSinopecConfigService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Scheduled; +import springfox.documentation.spring.web.json.Json; +import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @Auther: 胡锐 @@ -29,31 +33,63 @@ public class SynchronizeCNPC { private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; - //@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + @Resource + private HighCouponCodeService highCouponCodeService; + + @Resource + private SecSinopecConfigService secSinopecConfigService; + + @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 public void certification() { - Map tokenMap = new HashMap<>(); - tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); - tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4"); - JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); - log.error(jsonObject.toJSONString()); - if (jsonObject != null && jsonObject.getBoolean("success") == true) { - JSONObject data = jsonObject.getJSONObject("data"); - String token = data.getString("token"); - - Map bodyMap = new HashMap<>(); - bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA"); - bodyMap.put("pageNo", 1); - bodyMap.put("pageSize", 10); - bodyMap.put("startTime", new Date()); - bodyMap.put("endTime", new Date()); - bodyMap.put("customerCode", "48464274"); - - String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK"; - - Long date = new Date().getTime(); - String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date); - JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); - log.error(object.toJSONString()); + + List sinopecConfig = secSinopecConfigService.getListSinopecConfig(new HashMap<>()); + for (SecSinopecConfig config : sinopecConfig) { + Map tokenMap = new HashMap<>(); + tokenMap.put("appId", config.getAppId()); + tokenMap.put("appSecret", config.getAppSecret()); + JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap)); + log.error(jsonObject.toJSONString()); + + if (jsonObject != null && jsonObject.getBoolean("success") == true) { + JSONObject data = jsonObject.getJSONObject("data"); + String token = data.getString("token"); + + Calendar instance = Calendar.getInstance(); + instance.add(Calendar.MINUTE, -10); + + Map bodyMap = new HashMap<>(); + bodyMap.put("appId", config.getAppId()); + bodyMap.put("pageNo", 1); + bodyMap.put("pageSize", 100); + bodyMap.put("startTime", instance.getTime()); + bodyMap.put("endTime", new Date()); + bodyMap.put("customerCode", config.getCode()); + + Long date = new Date().getTime(); + String sha256 = encodeBySHA256(config.getSignkey() + JSON.toJSONString(bodyMap) + date); + JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date); + + //JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}"); + + if(Objects.equals(object.get("success"), true)) { + log.error(JSONObject.toJSONString(object.get("data"))); + + Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data"))); + JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson)); + JSONArray list = dataObject.getJSONArray("list"); + for (Object dataJsonObject : list) { + try { + JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject)); + String codeId = parseObject.getString("codeId"); + Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss"); + highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime); + } catch (Exception e) { + log.error("HighCouponSchedule --> expiredCoupon() error!", e); + } + } + } + log.error(object.toJSONString()); + } } } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java index 3d6ddd86..afd91cdc 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java @@ -43,6 +43,13 @@ public interface HighCouponCodeService { **/ void useCouponCode(String code, UserInfoModel userInfoModel); + /** + * @Author 胡锐 + * @Description 中石化回调已使用的消核码 + * @Date 2021/4/19 21:53 + **/ + void cnpcCallbackCouponCode(String salesCode,Date useTime); + /** * @Author 胡锐 * @Description 根据订单id查询 diff --git a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java index ff924ea2..cff57a88 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java @@ -1,5 +1,6 @@ package com.hai.service; +import com.hai.entity.HighUser; import com.hai.entity.HighUserCoupon; import com.hai.model.HighUserCouponModel; @@ -41,6 +42,13 @@ public interface HighUserCouponService { **/ HighUserCoupon getDetailByCodeId(Long couponCodeId); + /** + * @Author 胡锐 + * @Description 根据关系id查询 + * @Date 2021/4/20 19:23 + **/ + HighUserCoupon getDetailById(Long userCouponId); + /** * @Author 胡锐 * @Description 查询用户列表 diff --git a/hai-service/src/main/java/com/hai/service/SecSinopecConfigService.java b/hai-service/src/main/java/com/hai/service/SecSinopecConfigService.java index dec271b6..4fb30986 100644 --- a/hai-service/src/main/java/com/hai/service/SecSinopecConfigService.java +++ b/hai-service/src/main/java/com/hai/service/SecSinopecConfigService.java @@ -26,7 +26,7 @@ public interface SecSinopecConfigService { * @throws Exception 抛出异常 */ - List getListSinopecConfig(Map map) throws Exception; + List getListSinopecConfig(Map map); /** * diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java index 9e3d186e..0a4acb38 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java @@ -111,7 +111,7 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡卷状态异常"); } - HighChildOrder order = highOrderService.getChildOrderByUserGoods(userCoupon.getUserId(), 1, userCoupon.getCouponCodeId()); + HighChildOrder order = highOrderService.getChildOrderByUserGoods(userCoupon.getUserId(), 1, userCoupon.getCouponId()); if (order == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); } @@ -122,6 +122,36 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { highOrderService.childOrderComplete(order.getId()); } + @Override + @Transactional + public void cnpcCallbackCouponCode(String salesCode, Date useTime) { + HighCouponCode code = getCouponCodeBySalesCode(salesCode); + if (code != null && code.getStatus() != 3) { + code.setStatus(3); + code.setConsumeTime(useTime); + updateCouponCode(code); + + Map map = new HashMap<>(); + map.put("status", "1"); + map.put("couponCodeId", code.getId()); + List list = highUserCouponService.getUserCouponList(map); + for (HighUserCoupon userCoupon : list) { + userCoupon.setStatus(2); + userCoupon.setConsumeTime(useTime); + + HighChildOrder order = highOrderService.getChildOrderByUserGoods(userCoupon.getUserId(), 1, userCoupon.getCouponId()); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); + } + userCoupon.setConsumeTime(new Date()); + userCoupon.setStatus(2); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponService.updateUserCoupon(userCoupon); + + highOrderService.childOrderComplete(order.getId()); + } + } + } + @Override public HighCouponCode getCouponCodeByOrderId(Long childOrderId) { HighCouponCodeExample example = new HighCouponCodeExample(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java index 2823ad72..1d31fe51 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java @@ -71,6 +71,11 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { return null; } + @Override + public HighUserCoupon getDetailById(Long userCouponId) { + return highUserCouponMapper.selectByPrimaryKey(userCouponId); + } + @Override public List getUserCouponList(Map map) { HighUserCouponExample example = new HighUserCouponExample(); @@ -88,6 +93,10 @@ public class HighUserCouponServiceImpl implements HighUserCouponService { criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); } + if (MapUtils.getLong(map, "couponCodeId") != null) { + criteria.andCouponCodeIdEqualTo(MapUtils.getLong(map, "couponCodeId")); + } + criteria.andStatusNotEqualTo(100); example.setOrderByClause("create_time desc"); List highUserCoupons = highUserCouponMapper.selectByExample(example); diff --git a/hai-service/src/main/java/com/hai/service/impl/SecSinopecConfigServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/SecSinopecConfigServiceImpl.java index 1310d0d8..4a04d561 100644 --- a/hai-service/src/main/java/com/hai/service/impl/SecSinopecConfigServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/SecSinopecConfigServiceImpl.java @@ -18,7 +18,7 @@ public class SecSinopecConfigServiceImpl implements SecSinopecConfigService { private SecSinopecConfigMapper secSinopecConfigMapper; @Override - public List getListSinopecConfig(Map map) throws Exception { + public List getListSinopecConfig(Map map) { SecSinopecConfigExample example = new SecSinopecConfigExample(); SecSinopecConfigExample.Criteria criteria = example.createCriteria();