From bc407249cfa63b93f10b78bd0b50da9cd1763285 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Thu, 9 May 2024 10:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bweb/src/main/resources/dev/application.yml | 2 +- cweb/src/main/resources/dev/application.yml | 2 +- .../java/com/order/config/AuthConfig.java | 1 + .../order/consumer/OrderCancelConsumer.java | 25 ++ .../consumer/OrderProfitSharingConsumer.java | 24 ++ .../com/order/controller/OrderController.java | 117 ++++++ .../order/controller/OrderPayController.java | 32 +- .../controller/OrderPayNotifyController.java | 90 +++++ order/src/main/resources/dev/application.yml | 2 +- .../hfkj/common/pay/util/SignatureUtil.java | 379 +++--------------- .../java/com/hfkj/config/CommonSysConfig.java | 5 + .../java/com/hfkj/dao/BsOrderChildMapper.java | 53 +-- .../com/hfkj/dao/BsOrderChildSqlProvider.java | 22 +- .../com/hfkj/dao/BsOrderDeductionMapper.java | 8 +- .../hfkj/dao/BsOrderDeductionSqlProvider.java | 8 +- .../main/java/com/hfkj/dao/BsOrderMapper.java | 8 +- .../java/com/hfkj/dao/BsOrderSqlProvider.java | 8 +- .../main/java/com/hfkj/entity/BsOrder.java | 6 +- .../java/com/hfkj/entity/BsOrderChild.java | 22 +- .../com/hfkj/entity/BsOrderChildExample.java | 80 +++- .../com/hfkj/entity/BsOrderDeduction.java | 8 +- .../hfkj/entity/BsOrderDeductionExample.java | 20 +- .../java/com/hfkj/entity/BsOrderExample.java | 20 +- .../java/com/hfkj/mqtopic/OrderTopic.java | 28 ++ .../service/order/BsOrderChildService.java | 30 ++ .../order/BsOrderDeductionService.java | 7 + .../hfkj/service/order/BsOrderService.java | 22 + .../service/order/OrderCancelService.java | 53 +++ .../service/order/OrderCreateService.java | 46 +++ .../service/order/OrderPayBeforeService.java | 23 ++ .../service/order/OrderPaySuccessService.java | 55 +++ .../order/impl/BsOrderChildServiceImpl.java | 52 +++ .../impl/BsOrderDeductionServiceImpl.java | 13 + .../order/impl/BsOrderServiceImpl.java | 210 +++++++++- .../com/hfkj/service/pay/HuiPayService.java | 93 +++++ .../sysenum/order/OrderChildStatusEnum.java | 53 +++ .../sysenum/order/OrderPayChannelEnum.java | 35 ++ .../hfkj/sysenum/order/OrderPayTypeEnum.java | 35 ++ .../resources/dev/commonConfig.properties | 6 + .../com/user/controller/SmsController.java | 2 +- user/src/main/resources/dev/application.yml | 2 +- user/src/main/resources/dev/config.properties | 5 - 42 files changed, 1275 insertions(+), 437 deletions(-) create mode 100644 order/src/main/java/com/order/consumer/OrderCancelConsumer.java create mode 100644 order/src/main/java/com/order/consumer/OrderProfitSharingConsumer.java create mode 100644 order/src/main/java/com/order/controller/OrderPayNotifyController.java create mode 100644 service/src/main/java/com/hfkj/mqtopic/OrderTopic.java create mode 100644 service/src/main/java/com/hfkj/service/order/BsOrderChildService.java create mode 100644 service/src/main/java/com/hfkj/service/order/OrderCancelService.java create mode 100644 service/src/main/java/com/hfkj/service/order/OrderCreateService.java create mode 100644 service/src/main/java/com/hfkj/service/order/OrderPayBeforeService.java create mode 100644 service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java create mode 100644 service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java create mode 100644 service/src/main/java/com/hfkj/service/pay/HuiPayService.java create mode 100644 service/src/main/java/com/hfkj/sysenum/order/OrderChildStatusEnum.java create mode 100644 service/src/main/java/com/hfkj/sysenum/order/OrderPayChannelEnum.java create mode 100644 service/src/main/java/com/hfkj/sysenum/order/OrderPayTypeEnum.java diff --git a/bweb/src/main/resources/dev/application.yml b/bweb/src/main/resources/dev/application.yml index 07a5b09..846d42f 100644 --- a/bweb/src/main/resources/dev/application.yml +++ b/bweb/src/main/resources/dev/application.yml @@ -1,5 +1,5 @@ server: - port: 9502 + port: 9702 servlet: context-path: /brest diff --git a/cweb/src/main/resources/dev/application.yml b/cweb/src/main/resources/dev/application.yml index 915cda2..b012cab 100644 --- a/cweb/src/main/resources/dev/application.yml +++ b/cweb/src/main/resources/dev/application.yml @@ -1,5 +1,5 @@ server: - port: 9501 + port: 9701 servlet: context-path: /crest diff --git a/order/src/main/java/com/order/config/AuthConfig.java b/order/src/main/java/com/order/config/AuthConfig.java index c591cec..89c52ea 100644 --- a/order/src/main/java/com/order/config/AuthConfig.java +++ b/order/src/main/java/com/order/config/AuthConfig.java @@ -86,6 +86,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/**/api-docs") .excludePathPatterns("/**/springfox-swagger-ui/**") .excludePathPatterns("/**/swagger-ui.html") + .excludePathPatterns("/notify/*") ; } diff --git a/order/src/main/java/com/order/consumer/OrderCancelConsumer.java b/order/src/main/java/com/order/consumer/OrderCancelConsumer.java new file mode 100644 index 0000000..891ccc8 --- /dev/null +++ b/order/src/main/java/com/order/consumer/OrderCancelConsumer.java @@ -0,0 +1,25 @@ +package com.order.consumer; + +import com.hfkj.model.order.OrderModel; +import com.hfkj.service.order.BsOrderService; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@Slf4j +@RocketMQMessageListener(consumerGroup = "order-cancel-group", topic = "order-topic",selectorExpression = "cancel") +public class OrderCancelConsumer implements RocketMQListener { + + @Resource + private BsOrderService orderService; + + @Override + public void onMessage(OrderModel order) { + // 取消订单 + orderService.cancel(order.getOrderNo()); + } +} diff --git a/order/src/main/java/com/order/consumer/OrderProfitSharingConsumer.java b/order/src/main/java/com/order/consumer/OrderProfitSharingConsumer.java new file mode 100644 index 0000000..203a004 --- /dev/null +++ b/order/src/main/java/com/order/consumer/OrderProfitSharingConsumer.java @@ -0,0 +1,24 @@ +package com.order.consumer; + +import com.hfkj.model.order.OrderModel; +import com.hfkj.service.order.BsOrderService; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@Slf4j +@RocketMQMessageListener(consumerGroup = "order-profit-sharing-group", topic = "order-topic",selectorExpression = "profit-sharing") +public class OrderProfitSharingConsumer implements RocketMQListener { + + @Resource + private BsOrderService orderService; + + @Override + public void onMessage(OrderModel order) { + + } +} diff --git a/order/src/main/java/com/order/controller/OrderController.java b/order/src/main/java/com/order/controller/OrderController.java index 73e381e..ce4c79f 100644 --- a/order/src/main/java/com/order/controller/OrderController.java +++ b/order/src/main/java/com/order/controller/OrderController.java @@ -1,5 +1,8 @@ package com.order.controller; +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -10,6 +13,11 @@ import com.hfkj.model.UserSessionObject; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.service.order.BsOrderService; +import com.hfkj.service.pay.HuiPayService; +import com.hfkj.sysenum.UserStatusEnum; +import com.hfkj.sysenum.order.OrderPayChannelEnum; +import com.hfkj.sysenum.order.OrderPayTypeEnum; +import com.hfkj.sysenum.order.OrderStatusEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -19,6 +27,8 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; /** * @className: OrderController @@ -45,9 +55,13 @@ public class OrderController { if (userSession == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); } + if (!userSession.getUser().getStatus().equals(UserStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "该账户已被禁用,无法进行交易"); + } if (body == null || body.getOrderChildList().isEmpty()) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + // 子订单必填项校验 for (OrderChildModel orderChild : body.getOrderChildList()) { if (orderChild.getProductType() == null @@ -57,6 +71,10 @@ public class OrderController { } } + body.setUserId(userSession.getUser().getId()); + body.setUserName(userSession.getUser().getName()); + body.setUserPhone(userSession.getUser().getPhone()); + return ResponseMsgUtil.success(orderService.create(body)); } catch (Exception e) { @@ -65,4 +83,103 @@ public class OrderController { } } + @RequestMapping(value="/cancel",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "取消订单") + public ResponseData cancel(@RequestBody JSONObject body) { + try { + if (body == null|| StringUtils.isBlank(body.getString("orderNo"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + return ResponseMsgUtil.success(orderService.cancel(body.getString("orderNo"))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryOrder",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询订单") + public ResponseData queryOrder(@RequestParam(value = "orderNo" , required = true) String orderNo) { + try { + + return ResponseMsgUtil.success(orderService.getDetail(orderNo)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryUserOrder",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询用户订单") + public ResponseData queryUserOrder(@RequestParam(value = "orderNo" , required = false) String orderNo, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + // 用户session + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (userSession == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); + } + Map param = new HashMap<>(); + param.put("userId", userSession.getUser().getId()); + param.put("orderNo", orderNo); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryOrderList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询交易订单列表") + public ResponseData queryOrderList(@RequestParam(value = "orderNo" , required = false) String orderNo, + @RequestParam(value = "userPhone" , required = false) String userPhone, + @RequestParam(value = "payChannel" , required = false) Integer payChannel, + @RequestParam(value = "payType" , required = false) Integer payType, + @RequestParam(value = "createTimeS" , required = false) Long createTimeS, + @RequestParam(value = "createTimeE" , required = false) Long createTimeE, + @RequestParam(value = "payTimeS" , required = false) Long payTimeS, + @RequestParam(value = "payTimeE" , required = false) Long payTimeE, + @RequestParam(value = "finishTimeS" , required = false) Long finishTimeS, + @RequestParam(value = "finishTimeE" , required = false) Long finishTimeE, + @RequestParam(value = "cancelTimeS" , required = false) Long cancelTimeS, + @RequestParam(value = "cancelTimeE" , required = false) Long cancelTimeE, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + Map param = new HashMap<>(); + param.put("orderNo", orderNo); + param.put("userPhone", userPhone); + param.put("payChannel", payChannel); + param.put("payType", payType); + param.put("createTimeS", createTimeS); + param.put("createTimeE", createTimeE); + param.put("payTimeS", payTimeS); + param.put("payTimeE", payTimeE); + param.put("finishTimeS", finishTimeS); + param.put("finishTimeE", finishTimeE); + param.put("cancelTimeS", cancelTimeS); + param.put("cancelTimeE", cancelTimeE); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(orderService.getOrderList(param))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + } diff --git a/order/src/main/java/com/order/controller/OrderPayController.java b/order/src/main/java/com/order/controller/OrderPayController.java index 1b22aea..ce4bf09 100644 --- a/order/src/main/java/com/order/controller/OrderPayController.java +++ b/order/src/main/java/com/order/controller/OrderPayController.java @@ -9,6 +9,10 @@ import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.model.ResponseData; import com.hfkj.model.order.OrderModel; import com.hfkj.service.order.BsOrderService; +import com.hfkj.service.pay.HuiPayService; +import com.hfkj.sysenum.order.OrderPayChannelEnum; +import com.hfkj.sysenum.order.OrderPayTypeEnum; +import com.hfkj.sysenum.order.OrderStatusEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -21,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.Map; /** * @className: OrderController @@ -34,11 +39,8 @@ public class OrderPayController { Logger log = LoggerFactory.getLogger(OrderPayController.class); @Resource - private UserCenter userCenter; - @Resource private BsOrderService orderService; - @RequestMapping(value="/wechat",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "微信") @@ -56,9 +58,13 @@ public class OrderPayController { if (order == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单号"); } - - - return ResponseMsgUtil.success(null); + if (!order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易订单不处于待支付"); + } + order.setPayType(OrderPayTypeEnum.type1.getCode()); + // 请求支付渠道 + Map preorder = HuiPayService.preorder(body.getString("openId"), order); + return ResponseMsgUtil.success(preorder); } catch (Exception e) { log.error("error!",e); @@ -73,12 +79,24 @@ public class OrderPayController { try { if (body == null || StringUtils.isBlank(body.getString("orderNo")) + || StringUtils.isBlank(body.getString("userId")) ) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + // 查询订单 + OrderModel order = orderService.getDetail(body.getString("orderNo")); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单号"); + } + if (order.getOrderStatus().equals(OrderStatusEnum.status2.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易订单不处于待支付"); + } + order.setPayType(OrderPayTypeEnum.type2.getCode()); + // 请求支付渠道 + Map preorder = HuiPayService.preorder(body.getString("userId"), order); - return ResponseMsgUtil.success(null); + return ResponseMsgUtil.success(preorder); } catch (Exception e) { log.error("error!",e); return ResponseMsgUtil.exception(e); diff --git a/order/src/main/java/com/order/controller/OrderPayNotifyController.java b/order/src/main/java/com/order/controller/OrderPayNotifyController.java new file mode 100644 index 0000000..6d056f4 --- /dev/null +++ b/order/src/main/java/com/order/controller/OrderPayNotifyController.java @@ -0,0 +1,90 @@ +package com.order.controller; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsOrder; +import com.hfkj.model.ResponseData; +import com.hfkj.model.order.OrderModel; +import com.hfkj.service.order.BsOrderService; +import com.hfkj.sysenum.order.OrderPayChannelEnum; +import com.hfkj.sysenum.order.OrderPayTypeEnum; +import com.hfkj.sysenum.order.OrderStatusEnum; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @className: OrderPayNotifyController + * @author: HuRui + * @date: 2024/5/7 + **/ +@Controller +@RequestMapping(value="/notify") +@Api(value="通知业务") +public class OrderPayNotifyController { + Logger log = LoggerFactory.getLogger(OrderPayNotifyController.class); + @Resource + private BsOrderService orderService; + + @RequestMapping(value="/huipay",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "【惠支付】主扫通知") + public void huipay(@RequestBody String body, HttpServletResponse response) { + try { + log.info("===============惠支付回调start=================="); + JSONObject dataObject = JSONObject.parseObject(body); + // 处理业务 + log.info("开始处理业务"); + log.info("惠支付-回调参数: " + dataObject); + + // 查询交易订单 + OrderModel order = orderService.getDetail(dataObject.getString("outTradeNo")); + if (order != null && order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { + // 支付方式 微信:WECHAT 支付宝:ALIPAY 银联:UQRCODEPAY + String payMode = dataObject.getString("payMode"); + if ("WECHAT".equals(payMode)) { + order.setPayType(OrderPayTypeEnum.type1.getCode()); + + } else if ("ALIPAY".equals(payMode)) { + order.setPayType(OrderPayTypeEnum.type2.getCode()); + } + order.setPayChannel(OrderPayChannelEnum.type1.getCode()); + order.setPayTime(new Date(dataObject.getLong("payTime"))); + order.setPaySerialNo(dataObject.getString("accTradeNo")); + orderService.orderPaySuccessHandle(order); + } + log.info("处理业务完成"); + log.info("============回调任务End============="); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer= response.getWriter(); + + JSONObject postJson = new JSONObject(); + postJson.put("code" ,"SUCCESS"); + postJson.put("message" ,"执行成功"); + writer.write(postJson.toJSONString()); + writer.flush(); + writer.close(); + + } catch (Exception e) { + log.error("订单处理异常", e); + } finally { + log.info("===============微信支付回调end=================="); + } + } + +} diff --git a/order/src/main/resources/dev/application.yml b/order/src/main/resources/dev/application.yml index 85623af..85ea5c8 100644 --- a/order/src/main/resources/dev/application.yml +++ b/order/src/main/resources/dev/application.yml @@ -1,5 +1,5 @@ server: - port: 9503 + port: 9703 servlet: context-path: /order diff --git a/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java b/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java index 07758e1..2e9dbde 100644 --- a/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/common/pay/util/SignatureUtil.java @@ -1,358 +1,97 @@ package com.hfkj.common.pay.util; -import com.hfkj.common.pay.entity.WechatPayReturnParam; -import com.hfkj.common.pay.entity.WechatReturn; +import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; -import org.dom4j.DocumentException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xml.sax.SAXException; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; +import javax.xml.bind.annotation.adapters.HexBinaryAdapter; import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Map; -import java.util.SortedMap; +import java.util.Set; /** - * - * @Title: - * @Description: 微信支付签名工具类 - * @author: 魏真峰 - * @param: - * @return: - * @throws + * 签名工具类 */ public class SignatureUtil { - private static Logger logger = LoggerFactory.getLogger(SignatureUtil.class); - - /** - * 将字节数组转换为十六进制字符串 - * @param byteArray - * @return - */ - private static String byteToStr(byte[] byteArray) { - String strDigest = ""; - for (int i = 0; i < byteArray.length; i++) { - strDigest += byteToHexStr(byteArray[i]); - } - return strDigest; - } - /** - * 将字节转换为十六进制字符串 - * - * @param mByte + * 参数签名 + * @param param 参数 + * @param key 秘钥 * @return + * @throws Exception */ - private static String byteToHexStr(byte mByte) { - char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - char[] tempArr = new char[2]; - tempArr[0] = Digit[(mByte >>> 4) & 0X0F]; - tempArr[1] = Digit[mByte & 0X0F]; - return new String(tempArr); + public static String createSign(Object param, String key) throws Exception { + Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); + return md5Encode(paramSort(map, key).getBytes()); } /** - * 获取签名 - * - * @param o - * 待加密的对象 该处仅限于Class + * 验证签名 + * @param checkSign 需验证的签名字符串 + * @param param 参数 + * @param key 秘钥 * @return + * @throws Exception */ - public static String createSign(Object o, String apiKey, String encoding) { - String result = notSignParams(o, apiKey); - result = MD5Util.MD5Encode(result, encoding).toUpperCase(); - return result; - } - - /** - * 签名算法 - * - * @param o - * 要参与签名的数据对象 - * @param apiKey - * API密匙 - * @return 签名 - * @throws IllegalAccessException - */ - public static String notSignParams(Object o, String apiKey) { - ArrayList list = new ArrayList<>(); - String result = ""; - try { - Class cls = o.getClass(); - Field[] fields = cls.getDeclaredFields(); - list = getFieldList(fields, o); - Field[] superFields = cls.getSuperclass().getDeclaredFields(); // 获取父类的私有属性 - list.addAll(getFieldList(superFields, o)); - int size = list.size(); - String[] arrayToSort = list.toArray(new String[size]); - Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); // 严格按字母表顺序排序 - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < size; i++) { - sb.append(arrayToSort[i]); - } - result = sb.toString(); - if (apiKey != null && !"".equals(apiKey)) { - result += "key=" + apiKey; - } else { - result = result.substring(0, result.lastIndexOf("&")); - } - } catch (Exception e) { - e.printStackTrace(); + public static Boolean checkSign(String checkSign,Object param, String key) throws Exception { + Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); + // 去除签名 + map.remove("sign"); + if (checkSign.equals(createSign(map, key))) { + return true; } - return result; + return false; } /** - * 将字段集合方法转换 - * - * @param array - * @param object + * 参数排序 + * @param param * @return - * @throws IllegalArgumentException - * @throws IllegalAccessException */ - private static ArrayList getFieldList(Field[] array, Object object) - throws IllegalArgumentException, IllegalAccessException { - ArrayList list = new ArrayList(); - for (Field f : array) { - f.setAccessible(true); - if (f.get(object) != null && f.get(object) != "" && !f.getName().equals("serialVersionUID") - && !f.getName().equals("sign")) { - if (f.getName().equals("packageStr")) { - list.add("package" + "=" + f.get(object) + "&"); - } else { - list.add(f.getName() + "=" + f.get(object) + "&"); - } + public static String paramSort(final Map param, String key) { + Set keySet = param.keySet(); + String[] keyArray = keySet.toArray(new String[keySet.size()]); + Arrays.sort(keyArray); + StringBuilder sb = new StringBuilder(); + for (String k : keyArray) { + if (StringUtils.isBlank(sb.toString())) { + sb.append(k).append("=").append(param.get(k)); + } else { + sb.append("&").append(k).append("=").append(param.get(k)); } } - return list; - } - - /** - * 通过Map中的所有元素参与签名 - * - * @param map - * 待参与签名的map集合 - * @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 - * @return - */ - public static String createSign(Map map, String apiKey, String characterEncoding) { - String result = notSignParams(map, apiKey); - result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); - logger.debug("sign result {}", result); - return result; + sb.append("&key=").append(key); + return sb.toString(); } /** - * 通过Map中的所有元素参与签名 - * - * @param map - * 待参与签名的map集合 - * @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 + * MD5加密 + * @param data * @return + * @throws Exception */ - public static String createSign(SortedMap map, String apiKey, String characterEncoding) { - String result = notSignParams(map, apiKey); - result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); - logger.debug("sign result {}", result); - return result; - } - - /** - * 通过Map中的所有元素参与签名 - * - * @param map - * 待参与签名的map集合 - * @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 - * @return - */ - public static String createSha1Sign(SortedMap map, String apiKey, String characterEncoding) { - String result = notSignParams(map, apiKey); - MessageDigest md = null; - try { - md = MessageDigest.getInstance("SHA-1"); - byte[] digest = md.digest(result.getBytes(characterEncoding)); - result = byteToStr(digest); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return result; - } - - /** - * 返回未加密的字符串 - * - * @param params - * @param apiKey - * @return 待加密的字符串 - */ - private static String notSignParams(SortedMap params, String apiKey) { - StringBuffer buffer = new StringBuffer(); - for (Map.Entry entry : params.entrySet()) { - if (!org.springframework.util.StringUtils.isEmpty(entry.getValue())) { - buffer.append(entry.getKey() + "=" + entry.getValue() + "&"); - } - } - buffer.append("key=" + apiKey); - return buffer.toString(); + public static String md5Encode(byte[] data) throws Exception { + // 初始化MessageDigest + MessageDigest md = MessageDigest.getInstance("MD5"); + // 执行摘要信息 + byte[] digest = md.digest(data); + // 将摘要信息转换为32位的十六进制字符串 + return new String(new HexBinaryAdapter().marshal(digest)); } - /** - * 返回未加密的字符串 - * - * @param params - * @param apiKey - * @return 待加密的字符串 - */ - public static String notSignParams(Map params, String apiKey) { - ArrayList list = new ArrayList<>(); - for (Map.Entry entry : params.entrySet()) { - if (entry.getValue() != "" && entry.getValue() != null) { - list.add(entry.getKey() + "=" + entry.getValue() + "&"); - } - } - int size = list.size(); - String[] arrayToSort = list.toArray(new String[size]); - Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < size; i++) { - sb.append(arrayToSort[i]); - } - String result = sb.toString(); - if (apiKey != null && !"".equals(apiKey)) { - result += "key=" + apiKey; - } else { - result = result.substring(0, result.lastIndexOf("&")); - } - return result; + public static void main(String[] args) throws Exception { + String paramStr = "{\n" + + " \"merchantNo\": \"2023090816465844909\",\n" + + " \"outTradeNo\": \"ZF1130202305051459532538973458\",\n" + + " \"payMode\": \"WECHAT\",\n" + + " \"totalAmount\": 0.01,\n" + + " \"transType\": \"JSAPI\",\n" + + " \"profitSharing\": 0,\n" + + " \"specialField\": \"测试\"" + + "}"; + String sign = createSign(JSONObject.parseObject(paramStr), "ZatCMLMSZxnkc2rk7dtpTORMLcKetcKt"); + System.out.println(sign); } - /** - * 从API返回的XML数据里面重新计算一次签名 - * - * @param responseString - * API返回的XML数据 - * @param apiKey - * Key - * @return 新的签名 - * @throws ParserConfigurationException - * @throws IOException - * @throws SAXException - */ - public static String reCreateSign(String responseString, String apiKey, String encoding) - throws IOException, SAXException, ParserConfigurationException { - Map map = XmlUtil.parseXmlToMap(responseString, encoding); - // 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名 - map.replace("sign",""); - // 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较 - return createSign(map, apiKey, encoding); - } - - - /** - * 检验API返回的数据里面的签名是否合法,规则是:按参数名称a-z排序,遇到空值的参数不参加签名 - * - * @param resultXml - * API返回的XML数据字符串 - * @param apiKey - * Key - * @return API签名是否合法 - * @throws ParserConfigurationException - * @throws IOException - * @throws SAXException - * @throws DocumentException - */ - public static boolean checkIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) - throws ParserConfigurationException, IOException, SAXException, DocumentException { - SortedMap map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); - String signFromresultXml = (String) map.get("sign"); - WechatReturn wechatReturn = new WechatReturn(); - wechatReturn.setAppid((String) map.get("appid")); - wechatReturn.setMch_id((String) map.get("mch_id")); - wechatReturn.setNonce_str((String) map.get("nonce_str")); - wechatReturn.setPrepay_id((String) map.get("prepay_id")); - wechatReturn.setResult_code((String) map.get("result_code")); - wechatReturn.setReturn_code((String) map.get("return_code")); - wechatReturn.setReturn_msg((String) map.get("return_msg")); - wechatReturn.setTrade_type((String) map.get("trade_type")); - if (StringUtils.isEmpty(signFromresultXml)) { - logger.debug("API返回的数据签名数据不存在"); - return false; - } - if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ - logger.debug("返回代码不成功!"); - return false; - } - logger.debug("服务器回包里面的签名{}", signFromresultXml); - // 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名 - // 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较 -// String signForAPIResponse = createSign(wechatReturn, apiKey, encoding); -// if (!signForAPIResponse.equals(signFromresultXml)) { -// // 签名验不过,表示这个API返回的数据有可能已经被篡改了 -// logger.debug("API返回的数据签名验证不通过"); -// return false; -// } - logger.debug("API返回的数据签名验证通过"); - return true; - } - /** - * - * @Title: reCheckIsSignValidFromWeiXin - * @Description: 微信支付异步回调,检验签名是否正确 - * @author: 魏真峰 - * @param: [checktXml, apiKey, encoding] - * @return: boolean - * @throws - */ - public static boolean reCheckIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) - throws ParserConfigurationException, IOException, SAXException, DocumentException { - SortedMap map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); - String signFromresultXml = (String) map.get("sign"); - WechatPayReturnParam wechatPayReturnParam = new WechatPayReturnParam(); - wechatPayReturnParam.setAppid((String) map.get("appid")); - wechatPayReturnParam.setAttach((String) map.get("attach")); - wechatPayReturnParam.setBank_type((String) map.get("bank_type")); - wechatPayReturnParam.setCash_fee((String) map.get("cash_fee")); - wechatPayReturnParam.setFee_type((String) map.get("fee_type")); - wechatPayReturnParam.setIs_subscribe((String) map.get("is_subscribe")); - wechatPayReturnParam.setMch_id((String) map.get("mch_id")); - wechatPayReturnParam.setNonce_str((String) map.get("nonce_str")); - wechatPayReturnParam.setOpenid((String) map.get("openid")); - wechatPayReturnParam.setOut_trade_no((String) map.get("out_trade_no")); - wechatPayReturnParam.setResult_code((String) map.get("result_code")); - wechatPayReturnParam.setReturn_code((String) map.get("return_code")); - wechatPayReturnParam.setTime_end((String) map.get("time_end")); - wechatPayReturnParam.setTotal_fee((String) map.get("total_fee")); - wechatPayReturnParam.setTrade_type((String) map.get("trade_type")); - wechatPayReturnParam.setTransaction_id((String) map.get("transaction_id")); - if (StringUtils.isEmpty(signFromresultXml)) { - logger.debug("API返回的数据签名数据不存在"); - return false; - } - if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ - logger.debug("返回代码不成功!"); - return false; - } - logger.debug("服务器回包里面的签名{}", signFromresultXml); - // 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名 - // 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较 - String signForAPIResponse = createSign(wechatPayReturnParam, apiKey, encoding); - if (!signForAPIResponse.equals(signFromresultXml)) { - // 签名验不过,表示这个API返回的数据有可能已经被篡改了 - logger.debug("API返回的数据签名验证不通过"); - return false; - } - logger.debug("API返回的数据签名验证通过"); - return true; - } } diff --git a/service/src/main/java/com/hfkj/config/CommonSysConfig.java b/service/src/main/java/com/hfkj/config/CommonSysConfig.java index 0227d5c..a3670a0 100644 --- a/service/src/main/java/com/hfkj/config/CommonSysConfig.java +++ b/service/src/main/java/com/hfkj/config/CommonSysConfig.java @@ -28,4 +28,9 @@ public class CommonSysConfig { */ private String wechatMpSecret; + /** + * 【惠支付】支付渠道回调地址 + */ + private String huiPayPreorderNotifyUrl; + } diff --git a/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java b/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java index 0a94840..4e097ef 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java @@ -42,27 +42,27 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { "insert into bs_order_child (order_no, child_order_no, ", "product_type, product_id, ", "product_name, product_img, ", - "product_spec_name, product_price, ", - "product_count, product_total_price, ", - "total_deduction_price, coupon_discount_price, ", - "integral_discount_price, product_actual_price, ", - "surplus_refund_count, surplus_refund_price, ", - "surplus_refund_integral, `status`, ", - "create_time, update_time, ", - "finish_time, ext_1, ", - "ext_2, ext_3)", + "product_spec_id, product_spec_name, ", + "product_price, product_count, ", + "product_total_price, total_deduction_price, ", + "coupon_discount_price, integral_discount_price, ", + "product_actual_price, surplus_refund_count, ", + "surplus_refund_price, surplus_refund_integral, ", + "`status`, create_time, ", + "update_time, finish_time, ", + "ext_1, ext_2, ext_3)", "values (#{orderNo,jdbcType=VARCHAR}, #{childOrderNo,jdbcType=VARCHAR}, ", "#{productType,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, ", "#{productName,jdbcType=VARCHAR}, #{productImg,jdbcType=VARCHAR}, ", - "#{productSpecName,jdbcType=VARCHAR}, #{productPrice,jdbcType=DECIMAL}, ", - "#{productCount,jdbcType=INTEGER}, #{productTotalPrice,jdbcType=DECIMAL}, ", - "#{totalDeductionPrice,jdbcType=DECIMAL}, #{couponDiscountPrice,jdbcType=DECIMAL}, ", - "#{integralDiscountPrice,jdbcType=DECIMAL}, #{productActualPrice,jdbcType=DECIMAL}, ", - "#{surplusRefundCount,jdbcType=INTEGER}, #{surplusRefundPrice,jdbcType=DECIMAL}, ", - "#{surplusRefundIntegral,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, ", - "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", - "#{finishTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{productSpecId,jdbcType=BIGINT}, #{productSpecName,jdbcType=VARCHAR}, ", + "#{productPrice,jdbcType=DECIMAL}, #{productCount,jdbcType=INTEGER}, ", + "#{productTotalPrice,jdbcType=DECIMAL}, #{totalDeductionPrice,jdbcType=DECIMAL}, ", + "#{couponDiscountPrice,jdbcType=DECIMAL}, #{integralDiscountPrice,jdbcType=DECIMAL}, ", + "#{productActualPrice,jdbcType=DECIMAL}, #{surplusRefundCount,jdbcType=INTEGER}, ", + "#{surplusRefundPrice,jdbcType=DECIMAL}, #{surplusRefundIntegral,jdbcType=BIGINT}, ", + "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", + "#{updateTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(BsOrderChild record); @@ -80,6 +80,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="product_id", property="productId", jdbcType=JdbcType.INTEGER), @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR), @Result(column="product_img", property="productImg", jdbcType=JdbcType.VARCHAR), + @Result(column="product_spec_id", property="productSpecId", jdbcType=JdbcType.BIGINT), @Result(column="product_spec_name", property="productSpecName", jdbcType=JdbcType.VARCHAR), @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL), @Result(column="product_count", property="productCount", jdbcType=JdbcType.INTEGER), @@ -90,7 +91,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="product_actual_price", property="productActualPrice", jdbcType=JdbcType.DECIMAL), @Result(column="surplus_refund_count", property="surplusRefundCount", jdbcType=JdbcType.INTEGER), @Result(column="surplus_refund_price", property="surplusRefundPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="surplus_refund_integral", property="surplusRefundIntegral", jdbcType=JdbcType.DECIMAL), + @Result(column="surplus_refund_integral", property="surplusRefundIntegral", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -104,10 +105,10 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Select({ "select", "id, order_no, child_order_no, product_type, product_id, product_name, product_img, ", - "product_spec_name, product_price, product_count, product_total_price, total_deduction_price, ", - "coupon_discount_price, integral_discount_price, product_actual_price, surplus_refund_count, ", - "surplus_refund_price, surplus_refund_integral, `status`, create_time, update_time, ", - "finish_time, ext_1, ext_2, ext_3", + "product_spec_id, product_spec_name, product_price, product_count, product_total_price, ", + "total_deduction_price, coupon_discount_price, integral_discount_price, product_actual_price, ", + "surplus_refund_count, surplus_refund_price, surplus_refund_integral, `status`, ", + "create_time, update_time, finish_time, ext_1, ext_2, ext_3", "from bs_order_child", "where id = #{id,jdbcType=BIGINT}" }) @@ -119,6 +120,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="product_id", property="productId", jdbcType=JdbcType.INTEGER), @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR), @Result(column="product_img", property="productImg", jdbcType=JdbcType.VARCHAR), + @Result(column="product_spec_id", property="productSpecId", jdbcType=JdbcType.BIGINT), @Result(column="product_spec_name", property="productSpecName", jdbcType=JdbcType.VARCHAR), @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL), @Result(column="product_count", property="productCount", jdbcType=JdbcType.INTEGER), @@ -129,7 +131,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="product_actual_price", property="productActualPrice", jdbcType=JdbcType.DECIMAL), @Result(column="surplus_refund_count", property="surplusRefundCount", jdbcType=JdbcType.INTEGER), @Result(column="surplus_refund_price", property="surplusRefundPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="surplus_refund_integral", property="surplusRefundIntegral", jdbcType=JdbcType.DECIMAL), + @Result(column="surplus_refund_integral", property="surplusRefundIntegral", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -157,6 +159,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { "product_id = #{productId,jdbcType=INTEGER},", "product_name = #{productName,jdbcType=VARCHAR},", "product_img = #{productImg,jdbcType=VARCHAR},", + "product_spec_id = #{productSpecId,jdbcType=BIGINT},", "product_spec_name = #{productSpecName,jdbcType=VARCHAR},", "product_price = #{productPrice,jdbcType=DECIMAL},", "product_count = #{productCount,jdbcType=INTEGER},", @@ -167,7 +170,7 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { "product_actual_price = #{productActualPrice,jdbcType=DECIMAL},", "surplus_refund_count = #{surplusRefundCount,jdbcType=INTEGER},", "surplus_refund_price = #{surplusRefundPrice,jdbcType=DECIMAL},", - "surplus_refund_integral = #{surplusRefundIntegral,jdbcType=DECIMAL},", + "surplus_refund_integral = #{surplusRefundIntegral,jdbcType=BIGINT},", "`status` = #{status,jdbcType=INTEGER},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "update_time = #{updateTime,jdbcType=TIMESTAMP},", diff --git a/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java index 13eb628..e41b811 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java @@ -52,6 +52,10 @@ public class BsOrderChildSqlProvider { sql.VALUES("product_img", "#{productImg,jdbcType=VARCHAR}"); } + if (record.getProductSpecId() != null) { + sql.VALUES("product_spec_id", "#{productSpecId,jdbcType=BIGINT}"); + } + if (record.getProductSpecName() != null) { sql.VALUES("product_spec_name", "#{productSpecName,jdbcType=VARCHAR}"); } @@ -93,7 +97,7 @@ public class BsOrderChildSqlProvider { } if (record.getSurplusRefundIntegral() != null) { - sql.VALUES("surplus_refund_integral", "#{surplusRefundIntegral,jdbcType=DECIMAL}"); + sql.VALUES("surplus_refund_integral", "#{surplusRefundIntegral,jdbcType=BIGINT}"); } if (record.getStatus() != null) { @@ -140,6 +144,7 @@ public class BsOrderChildSqlProvider { sql.SELECT("product_id"); sql.SELECT("product_name"); sql.SELECT("product_img"); + sql.SELECT("product_spec_id"); sql.SELECT("product_spec_name"); sql.SELECT("product_price"); sql.SELECT("product_count"); @@ -203,6 +208,10 @@ public class BsOrderChildSqlProvider { sql.SET("product_img = #{record.productImg,jdbcType=VARCHAR}"); } + if (record.getProductSpecId() != null) { + sql.SET("product_spec_id = #{record.productSpecId,jdbcType=BIGINT}"); + } + if (record.getProductSpecName() != null) { sql.SET("product_spec_name = #{record.productSpecName,jdbcType=VARCHAR}"); } @@ -244,7 +253,7 @@ public class BsOrderChildSqlProvider { } if (record.getSurplusRefundIntegral() != null) { - sql.SET("surplus_refund_integral = #{record.surplusRefundIntegral,jdbcType=DECIMAL}"); + sql.SET("surplus_refund_integral = #{record.surplusRefundIntegral,jdbcType=BIGINT}"); } if (record.getStatus() != null) { @@ -290,6 +299,7 @@ public class BsOrderChildSqlProvider { sql.SET("product_id = #{record.productId,jdbcType=INTEGER}"); sql.SET("product_name = #{record.productName,jdbcType=VARCHAR}"); sql.SET("product_img = #{record.productImg,jdbcType=VARCHAR}"); + sql.SET("product_spec_id = #{record.productSpecId,jdbcType=BIGINT}"); sql.SET("product_spec_name = #{record.productSpecName,jdbcType=VARCHAR}"); sql.SET("product_price = #{record.productPrice,jdbcType=DECIMAL}"); sql.SET("product_count = #{record.productCount,jdbcType=INTEGER}"); @@ -300,7 +310,7 @@ public class BsOrderChildSqlProvider { sql.SET("product_actual_price = #{record.productActualPrice,jdbcType=DECIMAL}"); sql.SET("surplus_refund_count = #{record.surplusRefundCount,jdbcType=INTEGER}"); sql.SET("surplus_refund_price = #{record.surplusRefundPrice,jdbcType=DECIMAL}"); - sql.SET("surplus_refund_integral = #{record.surplusRefundIntegral,jdbcType=DECIMAL}"); + sql.SET("surplus_refund_integral = #{record.surplusRefundIntegral,jdbcType=BIGINT}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); @@ -342,6 +352,10 @@ public class BsOrderChildSqlProvider { sql.SET("product_img = #{productImg,jdbcType=VARCHAR}"); } + if (record.getProductSpecId() != null) { + sql.SET("product_spec_id = #{productSpecId,jdbcType=BIGINT}"); + } + if (record.getProductSpecName() != null) { sql.SET("product_spec_name = #{productSpecName,jdbcType=VARCHAR}"); } @@ -383,7 +397,7 @@ public class BsOrderChildSqlProvider { } if (record.getSurplusRefundIntegral() != null) { - sql.SET("surplus_refund_integral = #{surplusRefundIntegral,jdbcType=DECIMAL}"); + sql.SET("surplus_refund_integral = #{surplusRefundIntegral,jdbcType=BIGINT}"); } if (record.getStatus() != null) { diff --git a/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java b/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java index 179dec6..dfc9d43 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java @@ -49,7 +49,7 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { "#{totalDeductionPrice,jdbcType=DECIMAL}, #{userCouponDiscountId,jdbcType=INTEGER}, ", "#{couponDiscountId,jdbcType=INTEGER}, #{couponDiscountType,jdbcType=INTEGER}, ", "#{couponDiscountPrice,jdbcType=DECIMAL}, #{couponDiscountActualPrice,jdbcType=DECIMAL}, ", - "#{integralDiscountPrice,jdbcType=DECIMAL}, #{ext1,jdbcType=VARCHAR}, ", + "#{integralDiscountPrice,jdbcType=BIGINT}, #{ext1,jdbcType=VARCHAR}, ", "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") @@ -70,7 +70,7 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { @Result(column="coupon_discount_type", property="couponDiscountType", jdbcType=JdbcType.INTEGER), @Result(column="coupon_discount_price", property="couponDiscountPrice", jdbcType=JdbcType.DECIMAL), @Result(column="coupon_discount_actual_price", property="couponDiscountActualPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="integral_discount_price", property="integralDiscountPrice", jdbcType=JdbcType.DECIMAL), + @Result(column="integral_discount_price", property="integralDiscountPrice", jdbcType=JdbcType.BIGINT), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) @@ -95,7 +95,7 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { @Result(column="coupon_discount_type", property="couponDiscountType", jdbcType=JdbcType.INTEGER), @Result(column="coupon_discount_price", property="couponDiscountPrice", jdbcType=JdbcType.DECIMAL), @Result(column="coupon_discount_actual_price", property="couponDiscountActualPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="integral_discount_price", property="integralDiscountPrice", jdbcType=JdbcType.DECIMAL), + @Result(column="integral_discount_price", property="integralDiscountPrice", jdbcType=JdbcType.BIGINT), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) @@ -121,7 +121,7 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { "coupon_discount_type = #{couponDiscountType,jdbcType=INTEGER},", "coupon_discount_price = #{couponDiscountPrice,jdbcType=DECIMAL},", "coupon_discount_actual_price = #{couponDiscountActualPrice,jdbcType=DECIMAL},", - "integral_discount_price = #{integralDiscountPrice,jdbcType=DECIMAL},", + "integral_discount_price = #{integralDiscountPrice,jdbcType=BIGINT},", "ext_1 = #{ext1,jdbcType=VARCHAR},", "ext_2 = #{ext2,jdbcType=VARCHAR},", "ext_3 = #{ext3,jdbcType=VARCHAR}", diff --git a/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java index 2c7a1d5..81da87e 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java @@ -61,7 +61,7 @@ public class BsOrderDeductionSqlProvider { } if (record.getIntegralDiscountPrice() != null) { - sql.VALUES("integral_discount_price", "#{integralDiscountPrice,jdbcType=DECIMAL}"); + sql.VALUES("integral_discount_price", "#{integralDiscountPrice,jdbcType=BIGINT}"); } if (record.getExt1() != null) { @@ -152,7 +152,7 @@ public class BsOrderDeductionSqlProvider { } if (record.getIntegralDiscountPrice() != null) { - sql.SET("integral_discount_price = #{record.integralDiscountPrice,jdbcType=DECIMAL}"); + sql.SET("integral_discount_price = #{record.integralDiscountPrice,jdbcType=BIGINT}"); } if (record.getExt1() != null) { @@ -184,7 +184,7 @@ public class BsOrderDeductionSqlProvider { sql.SET("coupon_discount_type = #{record.couponDiscountType,jdbcType=INTEGER}"); sql.SET("coupon_discount_price = #{record.couponDiscountPrice,jdbcType=DECIMAL}"); sql.SET("coupon_discount_actual_price = #{record.couponDiscountActualPrice,jdbcType=DECIMAL}"); - sql.SET("integral_discount_price = #{record.integralDiscountPrice,jdbcType=DECIMAL}"); + sql.SET("integral_discount_price = #{record.integralDiscountPrice,jdbcType=BIGINT}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); @@ -231,7 +231,7 @@ public class BsOrderDeductionSqlProvider { } if (record.getIntegralDiscountPrice() != null) { - sql.SET("integral_discount_price = #{integralDiscountPrice,jdbcType=DECIMAL}"); + sql.SET("integral_discount_price = #{integralDiscountPrice,jdbcType=BIGINT}"); } if (record.getExt1() != null) { diff --git a/service/src/main/java/com/hfkj/dao/BsOrderMapper.java b/service/src/main/java/com/hfkj/dao/BsOrderMapper.java index be42b03..a782a9a 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderMapper.java @@ -50,7 +50,7 @@ public interface BsOrderMapper extends BsOrderMapperExt { "refund_time, order_status, ", "remarks, ext_1, ext_2, ", "ext_3)", - "values (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, ", + "values (#{userId,jdbcType=BIGINT}, #{userName,jdbcType=VARCHAR}, ", "#{userPhone,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, ", "#{payChannel,jdbcType=INTEGER}, #{payChannelOrderNo,jdbcType=VARCHAR}, ", "#{paySerialNo,jdbcType=VARCHAR}, #{payType,jdbcType=INTEGER}, ", @@ -72,7 +72,7 @@ public interface BsOrderMapper extends BsOrderMapperExt { @SelectProvider(type=BsOrderSqlProvider.class, method="selectByExample") @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), - @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.VARCHAR), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @@ -108,7 +108,7 @@ public interface BsOrderMapper extends BsOrderMapperExt { }) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), - @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.VARCHAR), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @@ -144,7 +144,7 @@ public interface BsOrderMapper extends BsOrderMapperExt { @Update({ "update bs_order", - "set user_id = #{userId,jdbcType=INTEGER},", + "set user_id = #{userId,jdbcType=BIGINT},", "user_name = #{userName,jdbcType=VARCHAR},", "user_phone = #{userPhone,jdbcType=VARCHAR},", "order_no = #{orderNo,jdbcType=VARCHAR},", diff --git a/service/src/main/java/com/hfkj/dao/BsOrderSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsOrderSqlProvider.java index 236a026..003f046 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderSqlProvider.java @@ -29,7 +29,7 @@ public class BsOrderSqlProvider { sql.INSERT_INTO("bs_order"); if (record.getUserId() != null) { - sql.VALUES("user_id", "#{userId,jdbcType=INTEGER}"); + sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}"); } if (record.getUserName() != null) { @@ -170,7 +170,7 @@ public class BsOrderSqlProvider { } if (record.getUserId() != null) { - sql.SET("user_id = #{record.userId,jdbcType=INTEGER}"); + sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); } if (record.getUserName() != null) { @@ -266,7 +266,7 @@ public class BsOrderSqlProvider { sql.UPDATE("bs_order"); sql.SET("id = #{record.id,jdbcType=BIGINT}"); - sql.SET("user_id = #{record.userId,jdbcType=INTEGER}"); + sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); sql.SET("user_name = #{record.userName,jdbcType=VARCHAR}"); sql.SET("user_phone = #{record.userPhone,jdbcType=VARCHAR}"); sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}"); @@ -299,7 +299,7 @@ public class BsOrderSqlProvider { sql.UPDATE("bs_order"); if (record.getUserId() != null) { - sql.SET("user_id = #{userId,jdbcType=INTEGER}"); + sql.SET("user_id = #{userId,jdbcType=BIGINT}"); } if (record.getUserName() != null) { diff --git a/service/src/main/java/com/hfkj/entity/BsOrder.java b/service/src/main/java/com/hfkj/entity/BsOrder.java index 67f7b42..4022ed9 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrder.java +++ b/service/src/main/java/com/hfkj/entity/BsOrder.java @@ -22,7 +22,7 @@ public class BsOrder implements Serializable { /** * 用户id */ - private Integer userId; + private Long userId; /** * 用户名称 @@ -130,11 +130,11 @@ public class BsOrder implements Serializable { this.id = id; } - public Integer getUserId() { + public Long getUserId() { return userId; } - public void setUserId(Integer userId) { + public void setUserId(Long userId) { this.userId = userId; } diff --git a/service/src/main/java/com/hfkj/entity/BsOrderChild.java b/service/src/main/java/com/hfkj/entity/BsOrderChild.java index 4bcc33e..06c63a8 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderChild.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderChild.java @@ -49,6 +49,11 @@ public class BsOrderChild implements Serializable { */ private String productImg; + /** + * 产品规格id + */ + private Long productSpecId; + /** * 产品规格名称 */ @@ -102,7 +107,7 @@ public class BsOrderChild implements Serializable { /** * 可退款积分金额 */ - private BigDecimal surplusRefundIntegral; + private Long surplusRefundIntegral; /** * 订单状态: @@ -194,6 +199,14 @@ public class BsOrderChild implements Serializable { this.productImg = productImg; } + public Long getProductSpecId() { + return productSpecId; + } + + public void setProductSpecId(Long productSpecId) { + this.productSpecId = productSpecId; + } + public String getProductSpecName() { return productSpecName; } @@ -274,11 +287,11 @@ public class BsOrderChild implements Serializable { this.surplusRefundPrice = surplusRefundPrice; } - public BigDecimal getSurplusRefundIntegral() { + public Long getSurplusRefundIntegral() { return surplusRefundIntegral; } - public void setSurplusRefundIntegral(BigDecimal surplusRefundIntegral) { + public void setSurplusRefundIntegral(Long surplusRefundIntegral) { this.surplusRefundIntegral = surplusRefundIntegral; } @@ -357,6 +370,7 @@ public class BsOrderChild implements Serializable { && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId())) && (this.getProductName() == null ? other.getProductName() == null : this.getProductName().equals(other.getProductName())) && (this.getProductImg() == null ? other.getProductImg() == null : this.getProductImg().equals(other.getProductImg())) + && (this.getProductSpecId() == null ? other.getProductSpecId() == null : this.getProductSpecId().equals(other.getProductSpecId())) && (this.getProductSpecName() == null ? other.getProductSpecName() == null : this.getProductSpecName().equals(other.getProductSpecName())) && (this.getProductPrice() == null ? other.getProductPrice() == null : this.getProductPrice().equals(other.getProductPrice())) && (this.getProductCount() == null ? other.getProductCount() == null : this.getProductCount().equals(other.getProductCount())) @@ -388,6 +402,7 @@ public class BsOrderChild implements Serializable { result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode()); result = prime * result + ((getProductName() == null) ? 0 : getProductName().hashCode()); result = prime * result + ((getProductImg() == null) ? 0 : getProductImg().hashCode()); + result = prime * result + ((getProductSpecId() == null) ? 0 : getProductSpecId().hashCode()); result = prime * result + ((getProductSpecName() == null) ? 0 : getProductSpecName().hashCode()); result = prime * result + ((getProductPrice() == null) ? 0 : getProductPrice().hashCode()); result = prime * result + ((getProductCount() == null) ? 0 : getProductCount().hashCode()); @@ -422,6 +437,7 @@ public class BsOrderChild implements Serializable { sb.append(", productId=").append(productId); sb.append(", productName=").append(productName); sb.append(", productImg=").append(productImg); + sb.append(", productSpecId=").append(productSpecId); sb.append(", productSpecName=").append(productSpecName); sb.append(", productPrice=").append(productPrice); sb.append(", productCount=").append(productCount); diff --git a/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java b/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java index 65d6e86..38329c6 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java @@ -586,6 +586,66 @@ public class BsOrderChildExample { return (Criteria) this; } + public Criteria andProductSpecIdIsNull() { + addCriterion("product_spec_id is null"); + return (Criteria) this; + } + + public Criteria andProductSpecIdIsNotNull() { + addCriterion("product_spec_id is not null"); + return (Criteria) this; + } + + public Criteria andProductSpecIdEqualTo(Long value) { + addCriterion("product_spec_id =", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdNotEqualTo(Long value) { + addCriterion("product_spec_id <>", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdGreaterThan(Long value) { + addCriterion("product_spec_id >", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdGreaterThanOrEqualTo(Long value) { + addCriterion("product_spec_id >=", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdLessThan(Long value) { + addCriterion("product_spec_id <", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdLessThanOrEqualTo(Long value) { + addCriterion("product_spec_id <=", value, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdIn(List values) { + addCriterion("product_spec_id in", values, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdNotIn(List values) { + addCriterion("product_spec_id not in", values, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdBetween(Long value1, Long value2) { + addCriterion("product_spec_id between", value1, value2, "productSpecId"); + return (Criteria) this; + } + + public Criteria andProductSpecIdNotBetween(Long value1, Long value2) { + addCriterion("product_spec_id not between", value1, value2, "productSpecId"); + return (Criteria) this; + } + public Criteria andProductSpecNameIsNull() { addCriterion("product_spec_name is null"); return (Criteria) this; @@ -1206,52 +1266,52 @@ public class BsOrderChildExample { return (Criteria) this; } - public Criteria andSurplusRefundIntegralEqualTo(BigDecimal value) { + public Criteria andSurplusRefundIntegralEqualTo(Long value) { addCriterion("surplus_refund_integral =", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralNotEqualTo(BigDecimal value) { + public Criteria andSurplusRefundIntegralNotEqualTo(Long value) { addCriterion("surplus_refund_integral <>", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralGreaterThan(BigDecimal value) { + public Criteria andSurplusRefundIntegralGreaterThan(Long value) { addCriterion("surplus_refund_integral >", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralGreaterThanOrEqualTo(BigDecimal value) { + public Criteria andSurplusRefundIntegralGreaterThanOrEqualTo(Long value) { addCriterion("surplus_refund_integral >=", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralLessThan(BigDecimal value) { + public Criteria andSurplusRefundIntegralLessThan(Long value) { addCriterion("surplus_refund_integral <", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralLessThanOrEqualTo(BigDecimal value) { + public Criteria andSurplusRefundIntegralLessThanOrEqualTo(Long value) { addCriterion("surplus_refund_integral <=", value, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralIn(List values) { + public Criteria andSurplusRefundIntegralIn(List values) { addCriterion("surplus_refund_integral in", values, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralNotIn(List values) { + public Criteria andSurplusRefundIntegralNotIn(List values) { addCriterion("surplus_refund_integral not in", values, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralBetween(BigDecimal value1, BigDecimal value2) { + public Criteria andSurplusRefundIntegralBetween(Long value1, Long value2) { addCriterion("surplus_refund_integral between", value1, value2, "surplusRefundIntegral"); return (Criteria) this; } - public Criteria andSurplusRefundIntegralNotBetween(BigDecimal value1, BigDecimal value2) { + public Criteria andSurplusRefundIntegralNotBetween(Long value1, Long value2) { addCriterion("surplus_refund_integral not between", value1, value2, "surplusRefundIntegral"); return (Criteria) this; } diff --git a/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java b/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java index fd8b120..e61b59a 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java @@ -59,9 +59,9 @@ public class BsOrderDeduction implements Serializable { private BigDecimal couponDiscountActualPrice; /** - * 积分抵扣金额 + * 积分抵扣数量 */ - private BigDecimal integralDiscountPrice; + private Long integralDiscountPrice; private String ext1; @@ -143,11 +143,11 @@ public class BsOrderDeduction implements Serializable { this.couponDiscountActualPrice = couponDiscountActualPrice; } - public BigDecimal getIntegralDiscountPrice() { + public Long getIntegralDiscountPrice() { return integralDiscountPrice; } - public void setIntegralDiscountPrice(BigDecimal integralDiscountPrice) { + public void setIntegralDiscountPrice(Long integralDiscountPrice) { this.integralDiscountPrice = integralDiscountPrice; } diff --git a/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java b/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java index db030b0..0fff5a9 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java @@ -685,52 +685,52 @@ public class BsOrderDeductionExample { return (Criteria) this; } - public Criteria andIntegralDiscountPriceEqualTo(BigDecimal value) { + public Criteria andIntegralDiscountPriceEqualTo(Long value) { addCriterion("integral_discount_price =", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceNotEqualTo(BigDecimal value) { + public Criteria andIntegralDiscountPriceNotEqualTo(Long value) { addCriterion("integral_discount_price <>", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceGreaterThan(BigDecimal value) { + public Criteria andIntegralDiscountPriceGreaterThan(Long value) { addCriterion("integral_discount_price >", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceGreaterThanOrEqualTo(BigDecimal value) { + public Criteria andIntegralDiscountPriceGreaterThanOrEqualTo(Long value) { addCriterion("integral_discount_price >=", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceLessThan(BigDecimal value) { + public Criteria andIntegralDiscountPriceLessThan(Long value) { addCriterion("integral_discount_price <", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceLessThanOrEqualTo(BigDecimal value) { + public Criteria andIntegralDiscountPriceLessThanOrEqualTo(Long value) { addCriterion("integral_discount_price <=", value, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceIn(List values) { + public Criteria andIntegralDiscountPriceIn(List values) { addCriterion("integral_discount_price in", values, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceNotIn(List values) { + public Criteria andIntegralDiscountPriceNotIn(List values) { addCriterion("integral_discount_price not in", values, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceBetween(BigDecimal value1, BigDecimal value2) { + public Criteria andIntegralDiscountPriceBetween(Long value1, Long value2) { addCriterion("integral_discount_price between", value1, value2, "integralDiscountPrice"); return (Criteria) this; } - public Criteria andIntegralDiscountPriceNotBetween(BigDecimal value1, BigDecimal value2) { + public Criteria andIntegralDiscountPriceNotBetween(Long value1, Long value2) { addCriterion("integral_discount_price not between", value1, value2, "integralDiscountPrice"); return (Criteria) this; } diff --git a/service/src/main/java/com/hfkj/entity/BsOrderExample.java b/service/src/main/java/com/hfkj/entity/BsOrderExample.java index 5fdeb3a..045710b 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderExample.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderExample.java @@ -196,52 +196,52 @@ public class BsOrderExample { return (Criteria) this; } - public Criteria andUserIdEqualTo(Integer value) { + public Criteria andUserIdEqualTo(Long value) { addCriterion("user_id =", value, "userId"); return (Criteria) this; } - public Criteria andUserIdNotEqualTo(Integer value) { + public Criteria andUserIdNotEqualTo(Long value) { addCriterion("user_id <>", value, "userId"); return (Criteria) this; } - public Criteria andUserIdGreaterThan(Integer value) { + public Criteria andUserIdGreaterThan(Long value) { addCriterion("user_id >", value, "userId"); return (Criteria) this; } - public Criteria andUserIdGreaterThanOrEqualTo(Integer value) { + public Criteria andUserIdGreaterThanOrEqualTo(Long value) { addCriterion("user_id >=", value, "userId"); return (Criteria) this; } - public Criteria andUserIdLessThan(Integer value) { + public Criteria andUserIdLessThan(Long value) { addCriterion("user_id <", value, "userId"); return (Criteria) this; } - public Criteria andUserIdLessThanOrEqualTo(Integer value) { + public Criteria andUserIdLessThanOrEqualTo(Long value) { addCriterion("user_id <=", value, "userId"); return (Criteria) this; } - public Criteria andUserIdIn(List values) { + public Criteria andUserIdIn(List values) { addCriterion("user_id in", values, "userId"); return (Criteria) this; } - public Criteria andUserIdNotIn(List values) { + public Criteria andUserIdNotIn(List values) { addCriterion("user_id not in", values, "userId"); return (Criteria) this; } - public Criteria andUserIdBetween(Integer value1, Integer value2) { + public Criteria andUserIdBetween(Long value1, Long value2) { addCriterion("user_id between", value1, value2, "userId"); return (Criteria) this; } - public Criteria andUserIdNotBetween(Integer value1, Integer value2) { + public Criteria andUserIdNotBetween(Long value1, Long value2) { addCriterion("user_id not between", value1, value2, "userId"); return (Criteria) this; } diff --git a/service/src/main/java/com/hfkj/mqtopic/OrderTopic.java b/service/src/main/java/com/hfkj/mqtopic/OrderTopic.java new file mode 100644 index 0000000..8e2f60b --- /dev/null +++ b/service/src/main/java/com/hfkj/mqtopic/OrderTopic.java @@ -0,0 +1,28 @@ +package com.hfkj.mqtopic; + +import lombok.Getter; + +/** + * 订单主题 + * @author hurui + */ +@Getter +public enum OrderTopic { + // 订单主题 + ORDER_TOPIC("order-topic", "订单主题"), + // 订单取消 + ORDER_TOPIC_CANCEL(ORDER_TOPIC.getTopic() + ":cancel", "订单取消"), + // 订单退款成功业务 + ORDER_TOPIC_REFUND_SUCCESS(ORDER_TOPIC.getTopic() + ":refund-success", "订单退款成功业务"), + // 订单分账业务 + ORDER_TOPIC_PROFIT_SHARING(ORDER_TOPIC.getTopic() + ":profit-sharing", "订单分账业务"), + ; + + private String topic; + private String name; + + OrderTopic(String topic, String name) { + this.topic = topic; + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderChildService.java b/service/src/main/java/com/hfkj/service/order/BsOrderChildService.java new file mode 100644 index 0000000..a669e68 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/BsOrderChildService.java @@ -0,0 +1,30 @@ +package com.hfkj.service.order; + +import com.hfkj.entity.BsOrderChild; +import com.hfkj.model.order.OrderChildModel; +import com.hfkj.model.order.OrderModel; + +import java.util.List; + +/** + * @className: BsOrderChildService + * @author: HuRui + * @date: 2024/5/6 + **/ +public interface BsOrderChildService { + + /** + * 编辑数据 + * @param data + */ + void editData(BsOrderChild data); + + + /** + * 查询子订单 + * @param orderNo + * @return + */ + List getOrderChildListByOrderNo(String orderNo); + +} diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderDeductionService.java b/service/src/main/java/com/hfkj/service/order/BsOrderDeductionService.java index cfc8a10..0735535 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderDeductionService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderDeductionService.java @@ -14,4 +14,11 @@ public interface BsOrderDeductionService { * @param data */ BsOrderDeduction editData(BsOrderDeduction data); + + /** + * 查询交易优惠 + * @param orderNo + * @return + */ + BsOrderDeduction getOrderDeduction(String orderNo); } diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderService.java b/service/src/main/java/com/hfkj/service/order/BsOrderService.java index ac794ae..fd6486d 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java @@ -3,6 +3,9 @@ package com.hfkj.service.order; import com.hfkj.entity.BsOrder; import com.hfkj.model.order.OrderModel; +import java.util.List; +import java.util.Map; + /** * @className: BsOrderService * @author: HuRui @@ -24,6 +27,19 @@ public interface BsOrderService { */ OrderModel create(OrderModel order); + /** + * 取消订单 + * @param orderNo + * @return + */ + OrderModel cancel(String orderNo); + + /** + * 支付成功业务 + * @param order + */ + void orderPaySuccessHandle(OrderModel order); + /** * 查询订单 * @param orderNo @@ -38,5 +54,11 @@ public interface BsOrderService { */ OrderModel getDetail(String orderNo); + /** + * 查询订单列表 + * @param param + * @return + */ + List getOrderList(Map param); } diff --git a/service/src/main/java/com/hfkj/service/order/OrderCancelService.java b/service/src/main/java/com/hfkj/service/order/OrderCancelService.java new file mode 100644 index 0000000..0c33d21 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/OrderCancelService.java @@ -0,0 +1,53 @@ +package com.hfkj.service.order; + +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.entity.BsOrderChild; +import com.hfkj.model.order.OrderModel; +import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +/** + * 取消订单业务 + * @className: OrderCancelService + * @author: HuRui + * @date: 2024/5/7 + **/ +@Component +public class OrderCancelService { + Logger log = LoggerFactory.getLogger(OrderCancelService.class); + @Autowired + private RedisUtil redisUtil; + @Resource + private BsOrderService orderService; + @Resource + private BsOrderChildService orderChildService; + + /** + * 订单业务处理 + * @param order + * @throws Exception + */ + @Transactional( + propagation= Propagation.REQUIRED, + isolation = Isolation.READ_COMMITTED, + timeout = 20, + rollbackFor = Exception.class) + public void orderBusHandle(OrderModel order) { + for (BsOrderChild childOrder : order.getOrderChildList()) { + if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + + } + } + + } + + +} diff --git a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java new file mode 100644 index 0000000..8fae77f --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java @@ -0,0 +1,46 @@ +package com.hfkj.service.order; + +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.entity.BsOrderChild; +import com.hfkj.model.order.OrderChildModel; +import com.hfkj.model.order.OrderModel; +import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; + +/** + * 创建订单业务 + * @className: OrderCreateService + * @author: HuRui + * @date: 2024/5/7 + **/ +@Component +public class OrderCreateService { + Logger log = LoggerFactory.getLogger(OrderCreateService.class); + @Autowired + private RedisUtil redisUtil; + @Resource + private BsOrderService orderService; + @Resource + private BsOrderChildService orderChildService; + + /** + * 事务产品 + * @param orderChild 子订单 + * @throws Exception + */ + public OrderChildModel materialProduct(OrderChildModel orderChild) { + orderChild.setProductPrice(new BigDecimal("10")); + return orderChild; + } + + +} diff --git a/service/src/main/java/com/hfkj/service/order/OrderPayBeforeService.java b/service/src/main/java/com/hfkj/service/order/OrderPayBeforeService.java new file mode 100644 index 0000000..cffaa7e --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/OrderPayBeforeService.java @@ -0,0 +1,23 @@ +package com.hfkj.service.order; + +import com.hfkj.model.order.OrderModel; +import org.springframework.stereotype.Component; + +/** + * 订单支付前校验 + * @className: OrderPayBeforeService + * @author: HuRui + * @date: 2024/5/8 + **/ +@Component +public class OrderPayBeforeService { + + /** + * 支付订单校验 + * @param order + */ + public void payOrderCheck(OrderModel order) { + + } + +} diff --git a/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java new file mode 100644 index 0000000..d2b183e --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java @@ -0,0 +1,55 @@ +package com.hfkj.service.order; + +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.entity.BsOrderChild; +import com.hfkj.model.order.OrderModel; +import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import com.hfkj.sysenum.order.OrderChildStatusEnum; +import com.hfkj.sysenum.order.OrderStatusEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * @className: OrderPaySuccesService + * @author: HuRui + * @date: 2024/5/7 + **/ +@Component +public class OrderPaySuccessService { + Logger log = LoggerFactory.getLogger(OrderPaySuccessService.class); + @Autowired + private RedisUtil redisUtil; + @Resource + private BsOrderService orderService; + @Resource + private BsOrderChildService orderChildService; + + /** + * 订单业务处理 + * @param order + * @throws Exception + */ + @Transactional( + propagation= Propagation.REQUIRED, + isolation = Isolation.READ_COMMITTED, + timeout = 20, + rollbackFor = Exception.class) + public void orderBusHandle(OrderModel order) { + for (BsOrderChild childOrder : order.getOrderChildList()) { + if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + + } + } + + } + + +} diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java new file mode 100644 index 0000000..afa5f48 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java @@ -0,0 +1,52 @@ +package com.hfkj.service.order.impl; + +import com.hfkj.dao.BsOrderChildMapper; +import com.hfkj.entity.BsOrderChild; +import com.hfkj.entity.BsOrderChildExample; +import com.hfkj.model.order.OrderChildModel; +import com.hfkj.service.order.BsOrderChildService; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @className: BsOrderChildServiceImpl + * @author: HuRui + * @date: 2024/5/6 + **/ +@Service("orderChildService") +public class BsOrderChildServiceImpl implements BsOrderChildService { + @Resource + private BsOrderChildMapper orderChildMapper; + + @Override + public void editData(BsOrderChild data) { + data.setUpdateTime(new Date()); + if (data.getId() == null) { + data.setCreateTime(new Date()); + orderChildMapper.insert(data); + } else { + orderChildMapper.updateByPrimaryKey(data); + } + } + + @Override + public List getOrderChildListByOrderNo(String orderNo) { + BsOrderChildExample example = new BsOrderChildExample(); + example.createCriteria().andOrderNoEqualTo(orderNo); + example.setOrderByClause("id"); + List list = orderChildMapper.selectByExample(example); + + List orderChildModelList = new ArrayList<>(); + for (BsOrderChild orderChild : list) { + OrderChildModel childModel = new OrderChildModel(); + BeanUtils.copyProperties(orderChild, childModel); + orderChildModelList.add(childModel); + } + return orderChildModelList; + } +} diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderDeductionServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderDeductionServiceImpl.java index 4a0a5fd..96a0eeb 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderDeductionServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderDeductionServiceImpl.java @@ -2,10 +2,12 @@ package com.hfkj.service.order.impl; import com.hfkj.dao.BsOrderDeductionMapper; import com.hfkj.entity.BsOrderDeduction; +import com.hfkj.entity.BsOrderDeductionExample; import com.hfkj.service.order.BsOrderDeductionService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; /** * @className: BsOrderDeductionServiceImpl @@ -27,4 +29,15 @@ public class BsOrderDeductionServiceImpl implements BsOrderDeductionService { } return data; } + + @Override + public BsOrderDeduction getOrderDeduction(String orderNo) { + BsOrderDeductionExample example = new BsOrderDeductionExample(); + example.createCriteria().andOrderNoEqualTo(orderNo); + List list = orderDeductionMapper.selectByExample(example); + if (!list.isEmpty()) { + return list.get(0); + } + return null; + } } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index ba7499b..03760e9 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -1,28 +1,41 @@ package com.hfkj.service.order.impl; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.DateUtil; import com.hfkj.common.utils.RandomUtils; import com.hfkj.common.utils.RedisUtil; import com.hfkj.dao.BsOrderMapper; import com.hfkj.entity.BsOrder; +import com.hfkj.entity.BsOrderChild; import com.hfkj.entity.BsOrderDeduction; import com.hfkj.entity.BsOrderExample; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; -import com.hfkj.service.order.BsOrderDeductionService; -import com.hfkj.service.order.BsOrderService; +import com.hfkj.mqtopic.OrderTopic; +import com.hfkj.service.order.*; import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import com.hfkj.sysenum.order.OrderChildStatusEnum; import com.hfkj.sysenum.order.OrderStatusEnum; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor; +import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.DateUtils; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; /** * @className: BsOrderServiceImpl @@ -32,16 +45,28 @@ import java.util.List; @Service("orderService") public class BsOrderServiceImpl implements BsOrderService { // 缓存前缀KEY - private final static String CACHE_KEY = "ORDER:"; + public final static String CACHE_KEY = "ORDER:"; // 订单缓存时间 7天 - private final static Integer CACHE_TIME = 60*60*24*7; + public final static Integer CACHE_TIME = 60*60*24*7; @Autowired private RedisUtil redisUtil; @Resource + private RocketMQTemplate rocketMQTemplate; + @Resource private BsOrderMapper orderMapper; @Resource + private BsOrderChildService orderChildService; + @Resource private BsOrderDeductionService orderDeductionService; + @Resource + private OrderPayBeforeService orderPayBeforeService; + @Resource + private OrderCreateService orderCreateService; + @Resource + private OrderCancelService orderCancelService; + @Resource + private OrderPaySuccessService orderPaySuccessService; @Override public BsOrder editData(BsOrder order) { @@ -55,38 +80,142 @@ public class BsOrderServiceImpl implements BsOrderService { return order; } - public static void main(String[] args) { - System.out.println(DateUtil.date2String(new Date(), "yyMMddHHmmss") + RandomUtils.number(6, false)); - } @Override @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10) public OrderModel create(OrderModel order) { // 生成交易单号,共18位,时间 + 6位随机数 order.setOrderNo(DateUtil.date2String(new Date(), "yyMMddHHmmss") + RandomUtils.number(6, false)); - order.setOrderStatus(OrderStatusEnum.status1.getCode()); editData(order); // 交易优惠 - BsOrderDeduction orderDeduction = order.getDeduction()!=null?order.getDeduction():new BsOrderDeduction(); - orderDeduction.setOrderId(order.getId()); - orderDeduction.setOrderNo(order.getOrderNo()); - orderDeductionService.editData(orderDeduction); + if (order.getDeduction() != null) { + // 计算优惠 + BsOrderDeduction deduction = order.getDeduction(); + deduction.setIntegralDiscountPrice(deduction.getIntegralDiscountPrice()==null?0L: deduction.getIntegralDiscountPrice()); + + } else { + BsOrderDeduction deduction = new BsOrderDeduction(); + deduction.setOrderId(order.getId()); + deduction.setOrderNo(order.getOrderNo()); + deduction.setCouponDiscountPrice(new BigDecimal("0")); + deduction.setCouponDiscountActualPrice(new BigDecimal("0")); + deduction.setIntegralDiscountPrice(0L); + deduction.setTotalDeductionPrice(new BigDecimal("0")); + orderDeductionService.editData(deduction); + order.setDeduction(deduction); + } + + // 订单总金额 + BigDecimal totalPrice = new BigDecimal("0"); + // 商品总金额 + BigDecimal productTotalPrice = new BigDecimal("0"); for (OrderChildModel child : order.getOrderChildList()) { child.setOrderNo(order.getOrderNo()); - // 子订单号 交易id + 8位随机数 - child.setChildOrderNo(order.getId()+RandomUtils.number(8, false)); + // 子订单号 交易id + 4位随机数 + child.setChildOrderNo(order.getId()+RandomUtils.number(4, false)); + // 提交订单前产品处理 if (child.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + // TODO 示例 + child = orderCreateService.materialProduct(child); + } + child.setProductTotalPrice(child.getProductPrice().multiply(new BigDecimal(child.getProductCount().toString()))); + child.setStatus(OrderChildStatusEnum.status1.getCode()); + orderChildService.editData(child); + + productTotalPrice = productTotalPrice.add(child.getProductTotalPrice()); + } + + totalPrice = productTotalPrice; + order.setTotalPrice(totalPrice); + order.setProductTotalPrice(productTotalPrice); + order.setPayRealPrice(totalPrice.subtract(order.getDeduction().getTotalDeductionPrice())); + order.setOrderStatus(order.getPayRealPrice().equals(new BigDecimal("0"))?OrderStatusEnum.status2.getCode():OrderStatusEnum.status1.getCode()); + // 订单入库前处理 + for (OrderChildModel childOrder : order.getOrderChildList()) { + childOrder.setSurplusRefundCount(childOrder.getProductCount()); + + // 计算 子订单 在交易订单金额中的占比 + BigDecimal ratio = childOrder.getProductTotalPrice().divide(order.getTotalPrice(), 2, BigDecimal.ROUND_DOWN).setScale(2); + // 计算子订单退款金额。 + if (order.getPayRealPrice().compareTo(new BigDecimal("0")) == 1) { + childOrder.setSurplusRefundPrice(order.getPayRealPrice().multiply(ratio).setScale(2, BigDecimal.ROUND_DOWN)); + } else { + childOrder.setSurplusRefundPrice(new BigDecimal("0")); + } + + // 计算子订单退款积分 + if (order.getDeduction().getIntegralDiscountPrice() > 0) { + childOrder.setSurplusRefundIntegral(new BigDecimal(order.getDeduction().getIntegralDiscountPrice().toString()).multiply(ratio).setScale(2).longValue()); + } else { + childOrder.setSurplusRefundIntegral(0L); } } + // 订单入库 + editData(order); + + if (order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { + // 10分钟内未支付,自动取消订单 + Message rocketMsg = MessageBuilder.withPayload(order).build(); + rocketMQTemplate.syncSend(OrderTopic.ORDER_TOPIC_CANCEL.getTopic(), rocketMsg,1000,14); + + } else if (order.getOrderStatus().equals(OrderStatusEnum.status2.getCode())) { + // 支付校验 + orderPayBeforeService.payOrderCheck(order); + // 处理业务 + orderPaySuccessHandle(order); + } + // 缓存 redisUtil.set(CACHE_KEY + order.getOrderNo(), order, CACHE_TIME); return order; } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10) + public OrderModel cancel(String orderNo) { + // 查询订单 + OrderModel order = getDetail(orderNo); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单"); + } + if (order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法取消,订单不处于待支付状态"); + } + order.setOrderStatus(OrderStatusEnum.status5.getCode()); + order.setCancelTime(new Date()); + editData(order); + + for (BsOrderChild orderChild : order.getOrderChildList()) { + orderChild.setStatus(OrderChildStatusEnum.status5.getCode()); + orderChildService.editData(orderChild); + + // 取消订单业务 + + } + return order; + } + + @Override + public void orderPaySuccessHandle(OrderModel order) { + order.setPayTime(order.getPayTime()==null?new Date():order.getPayTime()); + order.setOrderStatus(OrderStatusEnum.status2.getCode()); + editData(order); + + for (BsOrderChild childOrder : order.getOrderChildList()) { + childOrder.setStatus(OrderChildStatusEnum.status2.getCode()); + orderChildService.editData(childOrder); + } + // 更新缓存 + redisUtil.set(CACHE_KEY + order.getOrderNo(), order, CACHE_TIME); + + // 处理业务 + orderPaySuccessService.orderBusHandle(order); + } + @Override public BsOrder getOrder(String orderNo) { BsOrderExample example = new BsOrderExample(); @@ -100,15 +229,66 @@ public class BsOrderServiceImpl implements BsOrderService { @Override public OrderModel getDetail(String orderNo) { + // 获取缓存 Object cacheObj = redisUtil.get(CACHE_KEY + orderNo); if (cacheObj != null) { return (OrderModel) cacheObj; } OrderModel orderModel = new OrderModel(); BeanUtils.copyProperties(getOrder(orderNo), orderModel); + // 优惠 + orderModel.setDeduction(orderDeductionService.getOrderDeduction(orderNo)); + // 子订单 + orderModel.setOrderChildList(orderChildService.getOrderChildListByOrderNo(orderNo)); + + // 更新缓存 + redisUtil.set(CACHE_KEY + orderNo, orderModel, CACHE_TIME); + return orderModel; + } + @Override + public List getOrderList(Map param) { + BsOrderExample example = new BsOrderExample(); + BsOrderExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(MapUtils.getString(param, "order"))) { + criteria.andOrderNoLike("%"+MapUtils.getString(param, "order")+"%"); + } + if (StringUtils.isNotBlank(MapUtils.getString(param, "userPhone"))) { + criteria.andUserPhoneLike("%"+MapUtils.getString(param, "userPhone")+"%"); + } + if (MapUtils.getInteger(param, "payChannel") != null) { + criteria.andPayChannelEqualTo(MapUtils.getInteger(param, "payChannel")); + } + if (MapUtils.getInteger(param, "payType") != null) { + criteria.andPayTypeEqualTo(MapUtils.getInteger(param, "payType")); + } + if (MapUtils.getLong(param, "createTimeS") != null) { + criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(param, "createTimeS"))); + } + if (MapUtils.getLong(param, "createTimeE") != null) { + criteria.andCreateTimeLessThanOrEqualTo(new Date(MapUtils.getLong(param, "createTimeE"))); + } + if (MapUtils.getLong(param, "payTimeS") != null) { + criteria.andPayTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(param, "payTimeS"))); + } + if (MapUtils.getLong(param, "payTimeE") != null) { + criteria.andPayTimeLessThanOrEqualTo(new Date(MapUtils.getLong(param, "payTimeE"))); + } + if (MapUtils.getLong(param, "finishTimeS") != null) { + criteria.andFinishTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(param, "finishTimeS"))); + } + if (MapUtils.getLong(param, "finishTimeE") != null) { + criteria.andFinishTimeLessThanOrEqualTo(new Date(MapUtils.getLong(param, "finishTimeE"))); + } + if (MapUtils.getLong(param, "cancelTimeS") != null) { + criteria.andCancelTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(param, "cancelTimeS"))); + } + if (MapUtils.getLong(param, "cancelTimeE") != null) { + criteria.andCancelTimeLessThanOrEqualTo(new Date(MapUtils.getLong(param, "cancelTimeE"))); + } - return null; + example.setOrderByClause("create_time desc"); + return orderMapper.selectByExample(example); } } diff --git a/service/src/main/java/com/hfkj/service/pay/HuiPayService.java b/service/src/main/java/com/hfkj/service/pay/HuiPayService.java new file mode 100644 index 0000000..2b34966 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/pay/HuiPayService.java @@ -0,0 +1,93 @@ +package com.hfkj.service.pay; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.pay.util.SignatureUtil; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.config.CommonSysConst; +import com.hfkj.model.order.OrderModel; +import com.hfkj.sysenum.order.OrderPayTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * @className: HuiPayService + * @author: HuRui + * @date: 2024/5/7 + **/ +public class HuiPayService { + static Logger log = LoggerFactory.getLogger(HuiPayService.class); + // 请求地址 + private final static String REQUEST_URL = "https://pay.dctpay.com/openApi/v1/"; + private final static String DEFAULT_MER_NO = "2023041916292112804"; + private final static String DEFAULT_MER_KEY = "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"; + + public static Map preorder(String openId,OrderModel order) throws Exception { + try { + log.info("=============== start 惠支付 start =================="); + Map param = new HashMap<>(); + param.put("merchantNo", DEFAULT_MER_NO); + param.put("outTradeNo", order.getOrderNo()); + param.put("transType", "JSAPI"); + if (OrderPayTypeEnum.type1.getCode() == order.getPayType()) { + param.put("payMode", "WECHAT"); + } else if (OrderPayTypeEnum.type2.getCode() == order.getPayType()) { + param.put("payMode", "ALIPAY"); + } + param.put("totalAmount", order.getPayRealPrice()); + param.put("profitSharing", "0"); + param.put("subject", "购买产品"); + param.put("userId", openId); + param.put("notifyUrl", CommonSysConst.getSysConfig().getHuiPayPreorderNotifyUrl()); + param.put("sign", SignatureUtil.createSign(param, DEFAULT_MER_KEY)); + + log.info("请求地址:" + (REQUEST_URL + "trade/preorder")); + log.info("请求参数:" + JSONObject.toJSONString(param)); + + JSONObject response = HttpsUtils.doPost(REQUEST_URL + "trade/preorder", param, new HashMap<>()); + log.info("响应参数:" + response.toJSONString()); + + if (response != null && response.getString("return_code").equals("000000")) { + JSONObject payParam = response.getJSONObject("return_data").getJSONObject("payParam"); + SortedMap sortedMap = new TreeMap<>(); + sortedMap.put("appId", payParam.get("app_id")); + sortedMap.put("nonceStr", payParam.get("nonce_str")); + sortedMap.put("timeStamp", payParam.get("time_stamp")); + sortedMap.put("signType", "MD5"); + sortedMap.put("package", payParam.get("package")); + sortedMap.put("prepay_id", payParam.get("prepay_id")); + sortedMap.put("sign", payParam.get("pay_sign")); + return sortedMap; + + } + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("return_msg")); + + } catch (Exception e) { + log.info("出现异常:" + e.getMessage()); + throw e; + } finally { + log.info("=============== end 惠支付 end =================="); + } + } + + + public static JSONObject refund() throws Exception { + Map param = new HashMap<>(); + param.put("merchantNo", ""); + param.put("outTradeNo", ""); + param.put("refundTradeNo", ""); + param.put("refundAmount", ""); + param.put("sign" , SignatureUtil.createSign(param, DEFAULT_MER_KEY)); + return HttpsUtils.doPost(REQUEST_URL + "trade/refund", param, new HashMap<>()); + + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderChildStatusEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderChildStatusEnum.java new file mode 100644 index 0000000..9fa6783 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderChildStatusEnum.java @@ -0,0 +1,53 @@ +package com.hfkj.sysenum.order; + +import lombok.Data; +import lombok.Getter; + +/** + * @className: OrderChildStatusEnum + * @author: HuRui + * @date: 2024/5/6 + **/ +@Getter +public enum OrderChildStatusEnum { + /** + * 待支付 + */ + status1(1, "待支付"), + + /** + * 已支付 + */ + status2(2, "已支付"), + + /** + * 已完成 + */ + status3(3, "已完成"), + + /** + * 已退款 + */ + status4(4, "已退款"), + + /** + * 已取消 + */ + status5(5, "已取消"), + + /** + * 退款中 + */ + status6(6, "退款中"), + ; + + private final int code; + + private final String name; + + + OrderChildStatusEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderPayChannelEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderPayChannelEnum.java new file mode 100644 index 0000000..1b5748d --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderPayChannelEnum.java @@ -0,0 +1,35 @@ +package com.hfkj.sysenum.order; + +import lombok.Getter; + +/** + * 交易支付渠道 + * @className: OrderPayModelEnum + * @author: HuRui + * @date: 2024/5/7 + **/ +@Getter +public enum OrderPayChannelEnum { + /** + * 微信 + */ + type1(1, "惠支付"), + /** + * 支付宝 + */ + type2(2, "微信合作商"), + /** + * 快捷支付 + */ + type3(3, "贵州银行"), + ; + + private final int code; + + private final String name; + + OrderPayChannelEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderPayTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderPayTypeEnum.java new file mode 100644 index 0000000..d6c8b29 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderPayTypeEnum.java @@ -0,0 +1,35 @@ +package com.hfkj.sysenum.order; + +import lombok.Getter; + +/** + * 交易支付类型 + * @className: OrderPayModelEnum + * @author: HuRui + * @date: 2024/5/7 + **/ +@Getter +public enum OrderPayTypeEnum { + /** + * 微信 + */ + type1(1, "微信"), + /** + * 支付宝 + */ + type2(2, "支付宝"), + /** + * 快捷支付 + */ + type3(3, "快捷支付"), + ; + + private final int code; + + private final String name; + + OrderPayTypeEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/resources/dev/commonConfig.properties b/service/src/main/resources/dev/commonConfig.properties index e69de29..e0738fd 100644 --- a/service/src/main/resources/dev/commonConfig.properties +++ b/service/src/main/resources/dev/commonConfig.properties @@ -0,0 +1,6 @@ +wechatMaAppid= +wechatMaSecret= +wechatMpAppid= +wechatMpSecret= + +huiPayPreorderNotifyUrl= diff --git a/user/src/main/java/com/user/controller/SmsController.java b/user/src/main/java/com/user/controller/SmsController.java index 174c47f..96c9b87 100644 --- a/user/src/main/java/com/user/controller/SmsController.java +++ b/user/src/main/java/com/user/controller/SmsController.java @@ -1 +1 @@ -package com.user.controller; import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.MessageConfig; import com.hfkj.model.ResponseData; import com.hfkj.service.user.BsUserService; 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.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.Random; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/sms") @Api(value = "短信服务") public class SmsController { private static Logger log = LoggerFactory.getLogger(SmsController.class); @Resource private RedisUtil redisUtil; @Resource private BsUserService userService; @RequestMapping(value = "/getLoginSMSCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取登录验证码") public ResponseData getLoginSMSCode(@RequestBody JSONObject body) { try { if (body == null || StringUtils.isBlank(body.getString("phone"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } String phone = body.getString("phone"); // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 生成随机6位验证码 String smsCode = String.valueOf(new Random().nextInt(899999) + 100000); // MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5); // 验证码缓存5分钟 redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5); return ResponseMsgUtil.success("短信发送成功"); } catch (Exception e) { log.error("SMSController --> getLoginSMSCode() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.user.controller; import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.MessageConfig; import com.hfkj.model.ResponseData; import com.hfkj.service.user.BsUserService; 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.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.Random; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/sms") @Api(value = "短信服务") public class SmsController { private static Logger log = LoggerFactory.getLogger(SmsController.class); @Resource private RedisUtil redisUtil; @Resource private BsUserService userService; @RequestMapping(value = "/sendLoginSMSCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取登录验证码") public ResponseData sendLoginSMSCode(@RequestBody JSONObject body) { try { if (body == null || StringUtils.isBlank(body.getString("phone"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } String phone = body.getString("phone"); // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 生成随机6位验证码 String smsCode = String.valueOf(new Random().nextInt(899999) + 100000); // MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5); // 验证码缓存5分钟 redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5); return ResponseMsgUtil.success("短信发送成功"); } catch (Exception e) { log.error("SMSController --> getLoginSMSCode() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file diff --git a/user/src/main/resources/dev/application.yml b/user/src/main/resources/dev/application.yml index b312807..3c03ab0 100644 --- a/user/src/main/resources/dev/application.yml +++ b/user/src/main/resources/dev/application.yml @@ -1,5 +1,5 @@ server: - port: 9504 + port: 9704 servlet: context-path: /user diff --git a/user/src/main/resources/dev/config.properties b/user/src/main/resources/dev/config.properties index a048ac9..44ea8fc 100644 --- a/user/src/main/resources/dev/config.properties +++ b/user/src/main/resources/dev/config.properties @@ -1,7 +1,2 @@ fileUrl=/home/project/hsg/filesystem cmsPath=/home/project/hsg/filesystem/cmsPath - -wechatMaAppid= -wechatMaSecret= -wechatMpAppid= -wechatMpSecret=