From 309f6910d53b9d2bdc73e52790e792ffdd82dd8c Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 21 May 2024 09:34:31 +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/config.properties | 4 +- .../cweb/controller/FileUploadController.java | 166 ++++++++ cweb/src/main/resources/dev/config.properties | 4 +- .../order/consumer/OrderCancelConsumer.java | 2 +- .../com/order/controller/OrderController.java | 2 +- .../controller/OrderRefundController.java | 32 ++ .../hfkj/common/utils/PetroEncryptUtil.java | 189 +++++++++ .../java/com/hfkj/config/CommonSysConfig.java | 14 + .../java/com/hfkj/config/MessageConfig.java | 2 +- .../com/hfkj/dao/BsOrderDeductionMapper.java | 16 +- .../hfkj/dao/BsOrderDeductionSqlProvider.java | 16 +- .../com/hfkj/entity/BsOrderDeduction.java | 12 +- .../hfkj/entity/BsOrderDeductionExample.java | 40 +- .../com/hfkj/model/UserSessionObject.java | 15 +- .../hfkj/service/card/BsUserCardService.java | 2 +- .../card/impl/BsUserCardServiceImpl.java | 27 +- .../service/coupon/channel/PetroConfig.java | 380 ++++++++++++++++++ .../hfkj/service/order/BsOrderService.java | 3 +- .../service/order/OrderPaySuccessService.java | 11 +- .../order/impl/BsOrderRefundServiceImpl.java | 12 + .../order/impl/BsOrderServiceImpl.java | 110 ++++- .../user/BsUserIntegralRecordService.java | 17 + .../com/hfkj/service/user/BsUserService.java | 11 +- .../service/user/UserIntegralService.java | 40 ++ .../impl/BsUserIntegralRecordServiceImpl.java | 26 ++ .../service/user/impl/BsUserServiceImpl.java | 63 ++- .../user/impl/UserIntegralServiceImpl.java | 157 ++++++++ .../UserIntegralRecordOpUserTypeEnum.java | 37 ++ .../UserIntegralRecordSourceTypeEnum.java | 28 ++ .../sysenum/UserIntegralRecordStatusEnum.java | 33 ++ .../resources/dev/commonConfig.properties | 18 + .../user/controller/UserCardController.java | 4 +- .../controller/UserIntegralController.java | 7 +- 33 files changed, 1381 insertions(+), 119 deletions(-) create mode 100644 cweb/src/main/java/com/cweb/controller/FileUploadController.java create mode 100644 service/src/main/java/com/hfkj/common/utils/PetroEncryptUtil.java create mode 100644 service/src/main/java/com/hfkj/service/coupon/channel/PetroConfig.java create mode 100644 service/src/main/java/com/hfkj/service/user/BsUserIntegralRecordService.java create mode 100644 service/src/main/java/com/hfkj/service/user/UserIntegralService.java create mode 100644 service/src/main/java/com/hfkj/service/user/impl/BsUserIntegralRecordServiceImpl.java create mode 100644 service/src/main/java/com/hfkj/service/user/impl/UserIntegralServiceImpl.java create mode 100644 service/src/main/java/com/hfkj/sysenum/UserIntegralRecordOpUserTypeEnum.java create mode 100644 service/src/main/java/com/hfkj/sysenum/UserIntegralRecordSourceTypeEnum.java create mode 100644 service/src/main/java/com/hfkj/sysenum/UserIntegralRecordStatusEnum.java diff --git a/bweb/src/main/resources/dev/config.properties b/bweb/src/main/resources/dev/config.properties index 44ea8fc..9176532 100644 --- a/bweb/src/main/resources/dev/config.properties +++ b/bweb/src/main/resources/dev/config.properties @@ -1,2 +1,2 @@ -fileUrl=/home/project/hsg/filesystem -cmsPath=/home/project/hsg/filesystem/cmsPath +fileUrl=/home/project/phg/filesystem +cmsPath=/home/project/phg/filesystem/cmsPath diff --git a/cweb/src/main/java/com/cweb/controller/FileUploadController.java b/cweb/src/main/java/com/cweb/controller/FileUploadController.java new file mode 100644 index 0000000..5beb98c --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/FileUploadController.java @@ -0,0 +1,166 @@ +package com.cweb.controller; + +import com.cweb.config.SysConfig; +import com.hfkj.common.obs.HuaWeiYunObs; +import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.config.CommonSysConst; +import com.hfkj.model.ResponseData; +import com.hfkj.service.FileUploadService; +import com.obs.services.model.PutObjectResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import net.coobird.thumbnailator.Thumbnails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +@RestController +@RequestMapping(value="/fileUpload") +@Api(value="文件上传") +public class FileUploadController { + + private static Logger log = LoggerFactory.getLogger(FileUploadController.class); + + @Resource + private SysConfig sysConfig; + + @Resource + private FileUploadService fileUploadService; + + @RequestMapping(value="/uploadfile",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "文件上传") + public ResponseData uploadFile(@RequestParam(value = "files" , required = false) MultipartFile files, + HttpServletRequest request, + HttpServletResponse response) throws Exception { + try { + response.setHeader("Access-Control-Allow-Origin", "*"); + CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( + request.getSession().getServletContext()); + // 判断 request 是否有文件上传,即多部分请求 + List fileNames = new ArrayList(); + if (multipartResolver.isMultipart(request)) { + // 转换成多部分request + MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; + Iterator iterator = multiRequest.getFileNames(); + + while (iterator.hasNext()) { + MultipartFile file = multiRequest.getFile(iterator.next()); + if (file != null) { + FileOutputStream out = null; + try { + String fileType = file.getOriginalFilename() + .substring(file.getOriginalFilename().lastIndexOf(".") + 1); + String fileName = System.currentTimeMillis() + "." + fileType; + String childPath = DateUtil.date2String(new Date(), "yyyyMM"); + String destDirName = sysConfig.getFileUrl() + File.separator + childPath; + File dir = new File(destDirName); + if (!dir.exists()) { + dir.mkdirs(); + } + out = new FileOutputStream(destDirName + File.separator + fileName); + out.write(file.getBytes()); + out.flush(); + fileNames.add(childPath + "/" + fileName); + + PutObjectResult putObjectResult = HuaWeiYunObs.putObject(CommonSysConst.getSysConfig().getObsBucketName(), + childPath + "/" + fileName, new File(destDirName + "/" + fileName)); + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + if (out != null) { + out.close(); + } + } + } + } + } + return ResponseMsgUtil.success(fileNames); + + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResponseMsgUtil.exception(e); + } + + } + + @RequestMapping(value = "/fileUpload", method = RequestMethod.POST) + @ApiOperation(value = "上传文件(超过500KB压缩)") + @ResponseBody + public ResponseData fileUpload(@RequestParam(value = "files" , required = false) MultipartFile files, + HttpServletRequest request, + HttpServletResponse response + ) { + try { + response.setHeader("Access-Control-Allow-Origin", "*"); + CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( + request.getSession().getServletContext()); + // 判断 request 是否有文件上传,即多部分请求 + List fileNames = new ArrayList(); + if (multipartResolver.isMultipart(request)) { + // 转换成多部分request + MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; + Iterator iterator = multiRequest.getFileNames(); + + while (iterator.hasNext()) { + MultipartFile file = multiRequest.getFile(iterator.next()); + if (file != null) { + FileOutputStream out = null; + try { + String fileType = file.getOriginalFilename() + .substring(file.getOriginalFilename().lastIndexOf(".") + 1); + String fileName = System.currentTimeMillis() + "." + fileType; + String childPath = DateUtil.date2String(new Date(), "yyyyMM"); + String destDirName = sysConfig.getFileUrl() + File.separator + childPath; + File dir = new File(destDirName); + if (!dir.exists()) { + dir.mkdirs(); + } + out = new FileOutputStream(destDirName + File.separator + fileName); + out.write(file.getBytes()); + out.flush(); + fileNames.add(childPath + "/" + fileName); + // 图片压缩 + InputStream fis = new FileInputStream(destDirName + File.separator + fileName); + if (fis.available() > 500000) { + Thumbnails.of(new FileInputStream(destDirName + File.separator + fileName)).scale(0.5).toFile(new File(destDirName + File.separator + fileName)); + } + PutObjectResult putObjectResult = HuaWeiYunObs.putObject(CommonSysConst.getSysConfig().getObsBucketName(), + childPath + "/" + fileName, new File(destDirName + "/" + fileName)); + + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + if (out != null) { + out.close(); + } + } + } + } + } + return ResponseMsgUtil.success(fileNames); + + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResponseMsgUtil.exception(e); + } + } + + +} diff --git a/cweb/src/main/resources/dev/config.properties b/cweb/src/main/resources/dev/config.properties index 44ea8fc..9176532 100644 --- a/cweb/src/main/resources/dev/config.properties +++ b/cweb/src/main/resources/dev/config.properties @@ -1,2 +1,2 @@ -fileUrl=/home/project/hsg/filesystem -cmsPath=/home/project/hsg/filesystem/cmsPath +fileUrl=/home/project/phg/filesystem +cmsPath=/home/project/phg/filesystem/cmsPath diff --git a/order/src/main/java/com/order/consumer/OrderCancelConsumer.java b/order/src/main/java/com/order/consumer/OrderCancelConsumer.java index 891ccc8..13e0661 100644 --- a/order/src/main/java/com/order/consumer/OrderCancelConsumer.java +++ b/order/src/main/java/com/order/consumer/OrderCancelConsumer.java @@ -20,6 +20,6 @@ public class OrderCancelConsumer implements RocketMQListener { @Override public void onMessage(OrderModel order) { // 取消订单 - orderService.cancel(order.getOrderNo()); + orderService.cancel(order.getOrderNo(),true); } } diff --git a/order/src/main/java/com/order/controller/OrderController.java b/order/src/main/java/com/order/controller/OrderController.java index d1402f7..1b84c3e 100644 --- a/order/src/main/java/com/order/controller/OrderController.java +++ b/order/src/main/java/com/order/controller/OrderController.java @@ -101,7 +101,7 @@ public class OrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - return ResponseMsgUtil.success(orderService.cancel(body.getString("orderNo"))); + return ResponseMsgUtil.success(orderService.cancel(body.getString("orderNo"), false)); } catch (Exception e) { log.error("error!",e); diff --git a/order/src/main/java/com/order/controller/OrderRefundController.java b/order/src/main/java/com/order/controller/OrderRefundController.java index 68b10da..5d20a99 100644 --- a/order/src/main/java/com/order/controller/OrderRefundController.java +++ b/order/src/main/java/com/order/controller/OrderRefundController.java @@ -123,5 +123,37 @@ public class OrderRefundController { } } + @RequestMapping(value="/queryList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询退款订单列表") + public ResponseData queryList(@RequestParam(value = "userPhone" , required = false) String userPhone, + @RequestParam(value = "orderNo" , required = false) String orderNo, + @RequestParam(value = "orderChildNo" , required = false) String orderChildNo, + @RequestParam(value = "refundOrderNo" , required = false) String refundOrderNo, + @RequestParam(value = "refundStatus" , required = false) Integer refundStatus, + @RequestParam(value = "createTimeS" , required = false) Long createTimeS, + @RequestParam(value = "createTimeE" , required = false) Long createTimeE, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + + Map param = new HashMap<>(); + param.put("userPhone", userPhone); + param.put("orderNo", orderNo); + param.put("orderChildNo", orderChildNo); + param.put("refundOrderNo", refundOrderNo); + param.put("refundStatus", refundStatus); + param.put("createTimeS", createTimeS); + param.put("createTimeE", createTimeE); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(orderRefundService.getRefundList(param))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/service/src/main/java/com/hfkj/common/utils/PetroEncryptUtil.java b/service/src/main/java/com/hfkj/common/utils/PetroEncryptUtil.java new file mode 100644 index 0000000..82ad969 --- /dev/null +++ b/service/src/main/java/com/hfkj/common/utils/PetroEncryptUtil.java @@ -0,0 +1,189 @@ +package com.hfkj.common.utils; + +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.Map; +import java.util.TreeMap; + +public class PetroEncryptUtil { + + + /** + * 生成签名 + * + * @param signMaps + * @return + * @throws Exception + */ + public static String generateSign(Map signMaps) { + StringBuilder sb = new StringBuilder(); + TreeMap sortedMap = new TreeMap<>(signMaps); + // 字典序 + for (Map.Entry entry : sortedMap.entrySet()) { + String key = entry.getKey(); + String value = (String) entry.getValue(); + + // 为空不参与签名、参数名区分大小写 + if (!"sign".equals(key)) { + sb.append(key).append("=").append(value).append("&"); + } + + } + sb = new StringBuilder(sb.substring(0, sb.length() - 1)); + // MD5加密 + return md532(sb.toString()); + } + + /*** + * MD5加码 生成32位md5码 + */ + public static String md532(String inStr) { + MessageDigest md5; + try { + md5 = MessageDigest.getInstance("MD5"); + + } catch (Exception e) { + System.out.println(e); + e.printStackTrace(); + return ""; + } + char[] charArray = inStr.toCharArray(); + byte[] byteArray = new byte[charArray.length]; + + for (int i = 0; i < charArray.length; i++) + byteArray[i] = (byte) charArray[i]; + byte[] md5Bytes = md5.digest(byteArray); + StringBuilder hexValue = new StringBuilder(); + for (byte md5Byte : md5Bytes) { + int val = ((int) md5Byte) & 0xff; + if (val < 16) + hexValue.append("0"); + hexValue.append(Integer.toHexString(val)); + } + return hexValue.toString(); + } + + + /** + * 加密解密算法 + * + * @param inStr 加密字符串 + * @param secretKey 秘钥 + * 算法: + * 1:加密字符串和秘钥转换成字符数组; + * 2:秘钥去重复 + * 3:循环一(秘钥字符串数组){ 循环二(加密字符串数组){ + * 秘钥字符的ASC码 与 加密字符的ASC码 进行二进制异或运算 + * } + * } + * 4:把字符串转为16进制 + */ + private static String convert(String inStr, String secretKey) { + char[] a = inStr.toCharArray(); + char[] s = rmRepeated(secretKey).toCharArray(); + for (int i = 0; i < s.length; i++) { + for (int j = 0; j < a.length; j++) { + a[j] = (char) (a[j] ^ s[i]); + } + } + return new String(a); + } + + /** + * 清除字符串中重复字母算法 + * + * @param s + * @return + */ + private static String rmRepeated(String s) { + int len = s.length(); + int k = 0; + int count = 0; + String str = ""; + char[] c = new char[len]; + for (int i = 0; i < len; i++) { + c[i] = s.charAt(i); + } + for (int i = 0; i < len; i++) { + k = i + 1; + while (k < len - count) { + if (c[i] == c[k]) { + for (int j = k; j < len - 1; j++) { + c[j] = c[j + 1];// 出现重复字母,从k位置开始将数组往前挪位 + } + count++;// 重复字母出现的次数 + k--; + } + k++; + } + } + for (int i = 0; i < len - count; i++) { + str += String.valueOf(c[i]); + } + return str; + } + + /* + * 将字符串编码成16进制数字,适用于所有字符(包括中文) + */ + private static String hexString = "0123456789ABCDEF"; + + public static String encode(String str) { + // 根据默认编码获取字节数组 + String r; + byte[] bytes = str.getBytes(StandardCharsets.UTF_8); + StringBuilder sb = new StringBuilder(bytes.length * 2); + // 将字节数组中每个字节拆解成2位16进制整数 + for (byte aByte : bytes) { + sb.append(hexString.charAt((aByte & 0xf0) >> 4)); + sb.append(hexString.charAt((aByte & 0x0f))); + } + r = sb.toString(); + return r; + } + + /* + * 将16进制数字解码成字符串,适用于所有字符(包括中文) + */ + public static String decode(String bytes) { + String r = ""; + try { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(bytes.length() / 2); + // 将每2位16进制整数组装成一个字节 + for (int i = 0; i < bytes.length(); i += 2) { + byteArrayOutputStream.write((hexString.indexOf(bytes.charAt(i)) << 4 | hexString.indexOf(bytes.charAt(i + 1)))); + } + r = byteArrayOutputStream.toString("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return r; + } + + /** + * 加密 + * + * @param inStr 原字符串 + * @param secretKey 秘钥 + * @return + */ + public static String encrypt(String inStr, String secretKey) { + String hexStr = convert(inStr, secretKey); + return encode(hexStr); + } + + /** + * 解密 + * + * @param inStr 原字符串 + * @param secretKey 秘钥 + * @return + */ + public static String decrypt(String inStr, String secretKey) { + String hexStr = decode(inStr); + return convert(hexStr, secretKey); + } + +} diff --git a/service/src/main/java/com/hfkj/config/CommonSysConfig.java b/service/src/main/java/com/hfkj/config/CommonSysConfig.java index 2d791f1..80ea550 100644 --- a/service/src/main/java/com/hfkj/config/CommonSysConfig.java +++ b/service/src/main/java/com/hfkj/config/CommonSysConfig.java @@ -84,4 +84,18 @@ public class CommonSysConfig { private String huiliantongDistributorId; private String huiliantongSinopecUrl; + private String scPetroUrl; + private String scPetroAppid; + private String scPetroAppKey; + private String scPetroAesKey; + + private String gzPetroUrl; + private String gzPetroAppid; + private String gzPetroAppKey; + private String gzPetroAesKey; + + private String etcPostUrl; + private String etcChannelCode; + private String etcPublicKey; + private String etcPrivateKey; } diff --git a/service/src/main/java/com/hfkj/config/MessageConfig.java b/service/src/main/java/com/hfkj/config/MessageConfig.java index c83195c..1529953 100644 --- a/service/src/main/java/com/hfkj/config/MessageConfig.java +++ b/service/src/main/java/com/hfkj/config/MessageConfig.java @@ -210,7 +210,7 @@ public class MessageConfig { mtSmsMessage.setMobiles(mobiles); mtSmsMessage.setTemplateId(smsTemplateId); mtSmsMessage.setTemplateParas(paramValues); - mtSmsMessage.setSignature("【嗨森逛】"); + mtSmsMessage.setSignature("【普惠GO】"); requestLists.add(mtSmsMessage); map.put("account", accout); map.put("password", passward); diff --git a/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java b/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java index dfc9d43..7d54165 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderDeductionMapper.java @@ -46,8 +46,8 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { "integral_discount_price, ext_1, ", "ext_2, ext_3)", "values (#{orderId,jdbcType=BIGINT}, #{orderNo,jdbcType=VARCHAR}, ", - "#{totalDeductionPrice,jdbcType=DECIMAL}, #{userCouponDiscountId,jdbcType=INTEGER}, ", - "#{couponDiscountId,jdbcType=INTEGER}, #{couponDiscountType,jdbcType=INTEGER}, ", + "#{totalDeductionPrice,jdbcType=DECIMAL}, #{userCouponDiscountId,jdbcType=BIGINT}, ", + "#{couponDiscountId,jdbcType=BIGINT}, #{couponDiscountType,jdbcType=INTEGER}, ", "#{couponDiscountPrice,jdbcType=DECIMAL}, #{couponDiscountActualPrice,jdbcType=DECIMAL}, ", "#{integralDiscountPrice,jdbcType=BIGINT}, #{ext1,jdbcType=VARCHAR}, ", "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" @@ -65,8 +65,8 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @Result(column="total_deduction_price", property="totalDeductionPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="user_coupon_discount_id", property="userCouponDiscountId", jdbcType=JdbcType.INTEGER), - @Result(column="coupon_discount_id", property="couponDiscountId", jdbcType=JdbcType.INTEGER), + @Result(column="user_coupon_discount_id", property="userCouponDiscountId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_discount_id", property="couponDiscountId", jdbcType=JdbcType.BIGINT), @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), @@ -90,8 +90,8 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @Result(column="total_deduction_price", property="totalDeductionPrice", jdbcType=JdbcType.DECIMAL), - @Result(column="user_coupon_discount_id", property="userCouponDiscountId", jdbcType=JdbcType.INTEGER), - @Result(column="coupon_discount_id", property="couponDiscountId", jdbcType=JdbcType.INTEGER), + @Result(column="user_coupon_discount_id", property="userCouponDiscountId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_discount_id", property="couponDiscountId", jdbcType=JdbcType.BIGINT), @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), @@ -116,8 +116,8 @@ public interface BsOrderDeductionMapper extends BsOrderDeductionMapperExt { "set order_id = #{orderId,jdbcType=BIGINT},", "order_no = #{orderNo,jdbcType=VARCHAR},", "total_deduction_price = #{totalDeductionPrice,jdbcType=DECIMAL},", - "user_coupon_discount_id = #{userCouponDiscountId,jdbcType=INTEGER},", - "coupon_discount_id = #{couponDiscountId,jdbcType=INTEGER},", + "user_coupon_discount_id = #{userCouponDiscountId,jdbcType=BIGINT},", + "coupon_discount_id = #{couponDiscountId,jdbcType=BIGINT},", "coupon_discount_type = #{couponDiscountType,jdbcType=INTEGER},", "coupon_discount_price = #{couponDiscountPrice,jdbcType=DECIMAL},", "coupon_discount_actual_price = #{couponDiscountActualPrice,jdbcType=DECIMAL},", diff --git a/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java index 81da87e..f82105d 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderDeductionSqlProvider.java @@ -41,11 +41,11 @@ public class BsOrderDeductionSqlProvider { } if (record.getUserCouponDiscountId() != null) { - sql.VALUES("user_coupon_discount_id", "#{userCouponDiscountId,jdbcType=INTEGER}"); + sql.VALUES("user_coupon_discount_id", "#{userCouponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountId() != null) { - sql.VALUES("coupon_discount_id", "#{couponDiscountId,jdbcType=INTEGER}"); + sql.VALUES("coupon_discount_id", "#{couponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountType() != null) { @@ -132,11 +132,11 @@ public class BsOrderDeductionSqlProvider { } if (record.getUserCouponDiscountId() != null) { - sql.SET("user_coupon_discount_id = #{record.userCouponDiscountId,jdbcType=INTEGER}"); + sql.SET("user_coupon_discount_id = #{record.userCouponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountId() != null) { - sql.SET("coupon_discount_id = #{record.couponDiscountId,jdbcType=INTEGER}"); + sql.SET("coupon_discount_id = #{record.couponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountType() != null) { @@ -179,8 +179,8 @@ public class BsOrderDeductionSqlProvider { sql.SET("order_id = #{record.orderId,jdbcType=BIGINT}"); sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}"); sql.SET("total_deduction_price = #{record.totalDeductionPrice,jdbcType=DECIMAL}"); - sql.SET("user_coupon_discount_id = #{record.userCouponDiscountId,jdbcType=INTEGER}"); - sql.SET("coupon_discount_id = #{record.couponDiscountId,jdbcType=INTEGER}"); + sql.SET("user_coupon_discount_id = #{record.userCouponDiscountId,jdbcType=BIGINT}"); + sql.SET("coupon_discount_id = #{record.couponDiscountId,jdbcType=BIGINT}"); 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}"); @@ -211,11 +211,11 @@ public class BsOrderDeductionSqlProvider { } if (record.getUserCouponDiscountId() != null) { - sql.SET("user_coupon_discount_id = #{userCouponDiscountId,jdbcType=INTEGER}"); + sql.SET("user_coupon_discount_id = #{userCouponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountId() != null) { - sql.SET("coupon_discount_id = #{couponDiscountId,jdbcType=INTEGER}"); + sql.SET("coupon_discount_id = #{couponDiscountId,jdbcType=BIGINT}"); } if (record.getCouponDiscountType() != null) { diff --git a/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java b/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java index e61b59a..ca848eb 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderDeduction.java @@ -36,12 +36,12 @@ public class BsOrderDeduction implements Serializable { /** * 用户优惠券id */ - private Integer userCouponDiscountId; + private Long userCouponDiscountId; /** * 优惠券id */ - private Integer couponDiscountId; + private Long couponDiscountId; /** * 优惠券类型 @@ -103,19 +103,19 @@ public class BsOrderDeduction implements Serializable { this.totalDeductionPrice = totalDeductionPrice; } - public Integer getUserCouponDiscountId() { + public Long getUserCouponDiscountId() { return userCouponDiscountId; } - public void setUserCouponDiscountId(Integer userCouponDiscountId) { + public void setUserCouponDiscountId(Long userCouponDiscountId) { this.userCouponDiscountId = userCouponDiscountId; } - public Integer getCouponDiscountId() { + public Long getCouponDiscountId() { return couponDiscountId; } - public void setCouponDiscountId(Integer couponDiscountId) { + public void setCouponDiscountId(Long couponDiscountId) { this.couponDiscountId = couponDiscountId; } diff --git a/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java b/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java index 0fff5a9..52743f4 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderDeductionExample.java @@ -385,52 +385,52 @@ public class BsOrderDeductionExample { return (Criteria) this; } - public Criteria andUserCouponDiscountIdEqualTo(Integer value) { + public Criteria andUserCouponDiscountIdEqualTo(Long value) { addCriterion("user_coupon_discount_id =", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdNotEqualTo(Integer value) { + public Criteria andUserCouponDiscountIdNotEqualTo(Long value) { addCriterion("user_coupon_discount_id <>", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdGreaterThan(Integer value) { + public Criteria andUserCouponDiscountIdGreaterThan(Long value) { addCriterion("user_coupon_discount_id >", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdGreaterThanOrEqualTo(Integer value) { + public Criteria andUserCouponDiscountIdGreaterThanOrEqualTo(Long value) { addCriterion("user_coupon_discount_id >=", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdLessThan(Integer value) { + public Criteria andUserCouponDiscountIdLessThan(Long value) { addCriterion("user_coupon_discount_id <", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdLessThanOrEqualTo(Integer value) { + public Criteria andUserCouponDiscountIdLessThanOrEqualTo(Long value) { addCriterion("user_coupon_discount_id <=", value, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdIn(List values) { + public Criteria andUserCouponDiscountIdIn(List values) { addCriterion("user_coupon_discount_id in", values, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdNotIn(List values) { + public Criteria andUserCouponDiscountIdNotIn(List values) { addCriterion("user_coupon_discount_id not in", values, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdBetween(Integer value1, Integer value2) { + public Criteria andUserCouponDiscountIdBetween(Long value1, Long value2) { addCriterion("user_coupon_discount_id between", value1, value2, "userCouponDiscountId"); return (Criteria) this; } - public Criteria andUserCouponDiscountIdNotBetween(Integer value1, Integer value2) { + public Criteria andUserCouponDiscountIdNotBetween(Long value1, Long value2) { addCriterion("user_coupon_discount_id not between", value1, value2, "userCouponDiscountId"); return (Criteria) this; } @@ -445,52 +445,52 @@ public class BsOrderDeductionExample { return (Criteria) this; } - public Criteria andCouponDiscountIdEqualTo(Integer value) { + public Criteria andCouponDiscountIdEqualTo(Long value) { addCriterion("coupon_discount_id =", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdNotEqualTo(Integer value) { + public Criteria andCouponDiscountIdNotEqualTo(Long value) { addCriterion("coupon_discount_id <>", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdGreaterThan(Integer value) { + public Criteria andCouponDiscountIdGreaterThan(Long value) { addCriterion("coupon_discount_id >", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdGreaterThanOrEqualTo(Integer value) { + public Criteria andCouponDiscountIdGreaterThanOrEqualTo(Long value) { addCriterion("coupon_discount_id >=", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdLessThan(Integer value) { + public Criteria andCouponDiscountIdLessThan(Long value) { addCriterion("coupon_discount_id <", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdLessThanOrEqualTo(Integer value) { + public Criteria andCouponDiscountIdLessThanOrEqualTo(Long value) { addCriterion("coupon_discount_id <=", value, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdIn(List values) { + public Criteria andCouponDiscountIdIn(List values) { addCriterion("coupon_discount_id in", values, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdNotIn(List values) { + public Criteria andCouponDiscountIdNotIn(List values) { addCriterion("coupon_discount_id not in", values, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdBetween(Integer value1, Integer value2) { + public Criteria andCouponDiscountIdBetween(Long value1, Long value2) { addCriterion("coupon_discount_id between", value1, value2, "couponDiscountId"); return (Criteria) this; } - public Criteria andCouponDiscountIdNotBetween(Integer value1, Integer value2) { + public Criteria andCouponDiscountIdNotBetween(Long value1, Long value2) { addCriterion("coupon_discount_id not between", value1, value2, "couponDiscountId"); return (Criteria) this; } diff --git a/service/src/main/java/com/hfkj/model/UserSessionObject.java b/service/src/main/java/com/hfkj/model/UserSessionObject.java index b68e4d8..b7c20ae 100644 --- a/service/src/main/java/com/hfkj/model/UserSessionObject.java +++ b/service/src/main/java/com/hfkj/model/UserSessionObject.java @@ -1,9 +1,6 @@ package com.hfkj.model; -import com.hfkj.entity.BsUser; -import com.hfkj.entity.SecMenu; -import com.hfkj.entity.SecRole; -import com.hfkj.entity.SecUser; +import com.hfkj.entity.*; import lombok.Data; import java.util.List; @@ -18,7 +15,17 @@ public class UserSessionObject { * 登录账户 */ private BsUser user; + /** + * 汇联通卡绑定状态 + */ + private Boolean hltCardBind; + /** + * 汇联通卡信息 + */ + private BsUserCard hltCard; + public UserSessionObject(){ + } public UserSessionObject(BsUser user){ this.user = user; diff --git a/service/src/main/java/com/hfkj/service/card/BsUserCardService.java b/service/src/main/java/com/hfkj/service/card/BsUserCardService.java index c50fdcc..6387806 100644 --- a/service/src/main/java/com/hfkj/service/card/BsUserCardService.java +++ b/service/src/main/java/com/hfkj/service/card/BsUserCardService.java @@ -47,7 +47,7 @@ public interface BsUserCardService { * @param userId * @param cardNo */ - void bindCard(UserCardTypeEnum type,Long userId,String cardNo); + void bindCard(UserCardTypeEnum type,Long userId,String cardNo) throws Exception; /** * 解绑 diff --git a/service/src/main/java/com/hfkj/service/card/impl/BsUserCardServiceImpl.java b/service/src/main/java/com/hfkj/service/card/impl/BsUserCardServiceImpl.java index 505e6d1..1b20b4b 100644 --- a/service/src/main/java/com/hfkj/service/card/impl/BsUserCardServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/card/impl/BsUserCardServiceImpl.java @@ -1,5 +1,6 @@ package com.hfkj.service.card.impl; +import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -7,8 +8,11 @@ import com.hfkj.dao.BsUserCardMapper; import com.hfkj.entity.BsUserCard; import com.hfkj.entity.BsUserCardExample; import com.hfkj.service.card.BsUserCardService; +import com.hfkj.service.hlt.HuiLianTongUnionCardService; +import com.hfkj.service.user.BsUserService; import com.hfkj.sysenum.UserCardStatusEnum; import com.hfkj.sysenum.UserCardTypeEnum; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -24,7 +28,8 @@ import java.util.List; public class BsUserCardServiceImpl implements BsUserCardService { @Resource private BsUserCardMapper userCardMapper; - + @Resource + private BsUserService userService; @Override public void editData(BsUserCard data) { data.setUpdateTime(new Date()); @@ -75,12 +80,22 @@ public class BsUserCardServiceImpl implements BsUserCardService { } @Override - public void bindCard(UserCardTypeEnum type, Long userId, String cardNo) { + public void bindCard(UserCardTypeEnum type, Long userId, String cardNo) throws Exception { if (UserCardTypeEnum.type1.getCode() == type.getCode()) { if (!getCardList(userId, type).isEmpty()) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户已绑定工会卡,请勿重复绑定!"); } + // 查询工会卡信息 + JSONObject cardInfo = HuiLianTongUnionCardService.queryCardInfo(cardNo); + if (!cardInfo.getString("respCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到工会卡信息"); + } + JSONObject cardInfoObject = HuiLianTongUnionCardService.resolveResponse(cardInfo.getString("data")); + if (!cardInfoObject.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, cardInfoObject.getString("message")); + } } + if (getCard(cardNo) != null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前卡号已被账户绑定,请勿重复绑定!"); } @@ -90,6 +105,9 @@ public class BsUserCardServiceImpl implements BsUserCardService { card.setCardNo(cardNo); card.setStatus(UserCardStatusEnum.status1.getCode()); editData(card); + + // 更新登录信息 + userService.updateSession(userId); } @Override @@ -99,11 +117,14 @@ public class BsUserCardServiceImpl implements BsUserCardService { if (card == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前卡号已被账户绑定,请勿重复绑定!"); } - if (card.getUserId().equals(userId)) { + if (!card.getUserId().equals(userId)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户不一致"); } card.setStatus(UserCardStatusEnum.status0.getCode()); editData(card); + + // 更新登录信息 + userService.updateSession(userId); } diff --git a/service/src/main/java/com/hfkj/service/coupon/channel/PetroConfig.java b/service/src/main/java/com/hfkj/service/coupon/channel/PetroConfig.java new file mode 100644 index 0000000..bb7f213 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/channel/PetroConfig.java @@ -0,0 +1,380 @@ +package com.hfkj.service.coupon.channel; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.PetroEncryptUtil; +import com.hfkj.config.CommonSysConst; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @serviceName .java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 四川中石油 + * @createTime 18:33 2023/11/13 + **/ +public class PetroConfig { + + private static String reqUrl; + private static String petroAppKey; + private static String petroAppid; + private static String petroAesKey; + + private static final String version = "1.0"; + + private final static String charset = "UTF-8"; + + private static Logger log = LoggerFactory.getLogger(PetroConfig.class); + + + public static void init(Integer type) { + if (type == 1) { + reqUrl = CommonSysConst.getSysConfig().getScPetroUrl(); + petroAppKey = CommonSysConst.getSysConfig().getScPetroAppKey(); + petroAppid = CommonSysConst.getSysConfig().getScPetroAppid(); + petroAesKey = CommonSysConst.getSysConfig().getScPetroAesKey(); + } else { + reqUrl = CommonSysConst.getSysConfig().getGzPetroUrl(); + petroAppKey = CommonSysConst.getSysConfig().getGzPetroAppKey(); + petroAppid = CommonSysConst.getSysConfig().getGzPetroAppid(); + petroAesKey = CommonSysConst.getSysConfig().getGzPetroAesKey(); + } + } + + /** + * @Author Sum1Dream + * @Name synCouponRule + * @Description // 获取券列表 + * @Date 11:17 2023/11/17 + + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject synCouponRule() { + log.info("========================请求任务Start========================="); + Map req = new HashMap<>(); + req.put("appId", petroAppid); + req.put("appKey", petroAppKey); + req.put("jsonData" , ""); + req.put("timestamp", System.currentTimeMillis() + ""); + req.put("nonce" , generateRandomString(16)); + + //生成签名 + String sign = PetroEncryptUtil.generateSign(req); + + Map postData = new HashMap<>(); + postData.put("sign" , sign); + postData.put("timestamp" , req.get("timestamp")); + postData.put("jsonData" , ""); + postData.put("nonce" , req.get("nonce")); + postData.put("appId", petroAppid); + //签名放到参数中 + + log.info("获取券列表-请求参数: " + JSON.toJSONString(req)); + JSONObject object = HttpsUtils.doPost(reqUrl + "/outapi/getCouTypesYt", postData); + log.info("购买加油券充值订单-回调参数: " + JSON.toJSONString(object)); + log.info("========================请求任务End========================="); + // 请求接口 + return object; + } + + + /** + * @Author Sum1Dream + * @Name getCoupon + * @Description // 获取券code + * @Date 11:19 2023/11/17 + * @Param code + * @Param phone + * @Param orderNo + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject getCoupon(String code , String phone) { + log.info("========================请求任务Start========================="); + Map req = new HashMap<>(); + req.put("appId", petroAppid); + req.put("appKey", petroAppKey); + req.put("timestamp", System.currentTimeMillis()+ ""); + req.put("nonce" , generateRandomString(16)); + + // 业务数据 + JSONObject jsonData = new JSONObject(); + jsonData.put("alias" , code); + jsonData.put("businessId" , phone); + + //业务内容加密 + String bizContent = JSONObject.toJSONString(jsonData); + bizContent = encrypt(bizContent); + + //加密的内容放到参数中 + req.put("jsonData", bizContent); + //生成签名 + String sign = PetroEncryptUtil.generateSign(req); + + + Map postData = new HashMap<>(); + postData.put("sign" , sign); + postData.put("timestamp" , req.get("timestamp")); + postData.put("jsonData" , bizContent); + postData.put("nonce" , req.get("nonce")); + postData.put("appId", petroAppid); + log.info("获取电子券-请求参数: " + JSON.toJSONString(req)); + JSONObject object = HttpsUtils.doPost(reqUrl + "/outapi/getCouponYt", postData); + log.info("获取电子券-回调参数: " + JSON.toJSONString(object)); + log.info("========================请求任务End========================="); + // 请求接口 + return object; + } + + /** + * @Author Sum1Dream + * @Name couponDetail + * @Description // 查询电子券状态 + * @Date 11:20 2023/11/17 + * @Param ticketNum + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject couponDetail(String ticketNum , String phone) throws Exception{ + log.info("========================请求任务Start========================="); + Map req = new HashMap<>(); + req.put("appId", petroAppid); + req.put("appKey", petroAppKey); + req.put("timestamp", System.currentTimeMillis() + ""); + req.put("nonce" , generateRandomString(16)); + + // 业务数据 + JSONObject jsonData = new JSONObject(); + jsonData.put("voucher" , ticketNum); + jsonData.put("businessId" , phone); + + + //业务内容加密 + String bizContent = JSONObject.toJSONString(jsonData); + bizContent = encrypt(bizContent); + + //加密的内容放到参数中 + req.put("jsonData", bizContent); + //生成签名 + String sign = PetroEncryptUtil.generateSign(req); + //签名放到参数中 + req.put("sign", sign); + Map postData = new HashMap<>(); + postData.put("sign" , sign); + postData.put("timestamp" , req.get("timestamp")); + postData.put("jsonData" , bizContent); + postData.put("nonce" , req.get("nonce")); + postData.put("appId", petroAppid); + log.info("查询电子券状态-请求参数: " + JSON.toJSONString(req)); + // 请求接口 + JSONObject object = HttpsUtils.doPost(reqUrl + "/outapi/getStateYt", postData); + + log.info("查询电子券状态-回调参数: " + JSON.toJSONString(object)); + return object; + } + + /** + * @Author Sum1Dream + * @Name unusedCoupons + * @Description // 获取核销码 + * @Date 14:32 2024/1/31 + * @Param ticketNum + * @Param phone + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject getCheckCode(String ticketNum , String phone) throws Exception{ + log.info("========================请求任务Start========================="); + Map req = new HashMap<>(); + req.put("appId", petroAppid); + req.put("appKey", petroAppKey); + req.put("timestamp", System.currentTimeMillis() + ""); + req.put("nonce" , generateRandomString(16)); + + // 业务数据 + JSONObject jsonData = new JSONObject(); + jsonData.put("voucher" , ticketNum); + jsonData.put("businessId" , phone); + + + //业务内容加密 + String bizContent = JSONObject.toJSONString(jsonData); + bizContent = encrypt(bizContent); + + //加密的内容放到参数中 + req.put("jsonData", bizContent); + //生成签名 + String sign = PetroEncryptUtil.generateSign(req); + //签名放到参数中 + req.put("sign", sign); + Map postData = new HashMap<>(); + postData.put("sign" , sign); + postData.put("timestamp" , req.get("timestamp")); + postData.put("jsonData" , bizContent); + postData.put("nonce" , req.get("nonce")); + postData.put("appId", petroAppid); + log.info("查询电子券状态-请求参数: " + JSON.toJSONString(req)); + // 请求接口 + JSONObject object = HttpsUtils.doPost(reqUrl + "/outapi/getCheckCode", postData); + + log.info("查询电子券状态-回调参数: " + JSON.toJSONString(object)); + return object; + } + + + /** + * @Author Sum1Dream + * @Name cancelCouponsYt + * @Description // 注销电子券 + * @Date 15:19 2024/1/31 + * @Param ticketNum + * @Param phone + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject cancelCouponsYt(String ticketNum , String phone) throws Exception{ + log.info("========================请求任务Start========================="); + Map req = new HashMap<>(); + req.put("appId", petroAppid); + req.put("appKey", petroAppKey); + req.put("timestamp", System.currentTimeMillis() + ""); + req.put("nonce" , generateRandomString(16)); + + String [] vouchers = {ticketNum}; + + // 业务数据 + JSONObject jsonData = new JSONObject(); + jsonData.put("vouchers" , vouchers); + jsonData.put("businessId" , phone); + + //业务内容加密 + String bizContent = JSONObject.toJSONString(jsonData); + bizContent = encrypt(bizContent); + + //加密的内容放到参数中 + req.put("jsonData", bizContent); + //生成签名 + String sign = PetroEncryptUtil.generateSign(req); + //签名放到参数中 + req.put("sign", sign); + Map postData = new HashMap<>(); + postData.put("sign" , sign); + postData.put("timestamp" , req.get("timestamp")); + postData.put("jsonData" , bizContent); + postData.put("nonce" , req.get("nonce")); + postData.put("appId", petroAppid); + log.info("查询电子券状态-请求参数: " + JSON.toJSONString(req)); + // 请求接口 + JSONObject object = HttpsUtils.doPost(reqUrl + "/outapi/cancelCouponsYt", postData); + + log.info("查询电子券状态-回调参数: " + JSON.toJSONString(object)); + return object; + } + + /** + * @Author Sum1Dream + * @Name memberCards + * @Description // ETC卡券下发接口 + * @Date 14:17 2024/2/28 + * @Param object + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject etcOrder(Map object) { + log.info("========================请求任务Start========================="); + log.info("卡券下发接口-请求参数: " + JSON.toJSONString(object)); + // 请求接口 + JSONObject jsonObject = HttpsUtils.doPost(CommonSysConst.getSysConfig().getEtcPostUrl() + "channel/order" , object); + log.info("卡券下发接口-回调参数: " + JSON.toJSONString(jsonObject)); + return jsonObject; + } + + /** + * @Author Sum1Dream + * @Name etcCardStatus + * @Description // etc卡券状态查询接口 + * @Date 14:22 2024/2/28 + * @Param object + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject etcCardStatus(Map object) { + log.info("========================请求任务Start========================="); + log.info("卡券状态查询接口-请求参数: " + JSON.toJSONString(object)); + // 请求接口 + JSONObject jsonObject = HttpsUtils.doPost(CommonSysConst.getSysConfig().getEtcPostUrl() + "/channel/cardStatus" , object); + log.info("卡券状态查询接口-回调参数: " + JSON.toJSONString(jsonObject)); + return jsonObject; + } + + /** + * @Author Sum1Dream + * @Name etcDestroy + * @Description // 卡券退款接口 + * @Date 14:23 2024/2/28 + * @Param object + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject etcDestroy(Map object) { + log.info("========================请求任务Start========================="); + log.info(" 卡券退款接口-请求参数: " + JSON.toJSONString(object)); + // 请求接口 + JSONObject jsonObject = HttpsUtils.doPost(CommonSysConst.getSysConfig().getEtcPostUrl() + "/channel/order/destroy" , object); + log.info(" 卡券退款接口-回调参数: " + JSON.toJSONString(jsonObject)); + return jsonObject; + } + + /** + * @Author Sum1Dream + * @Name etcQueryStock + * @Description // 查询卡券库存接口 + * @Date 14:23 2024/2/28 + * @Param object + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject etcQueryStock(Map object) { + log.info("========================请求任务Start========================="); + log.info(" 查询卡券库存接口-请求参数: " + JSON.toJSONString(object)); + // 请求接口 + JSONObject jsonObject = HttpsUtils.doPost(CommonSysConst.getSysConfig().getEtcPostUrl() + "/channel/queryStock" , object); + log.info(" 查询卡券库存接口-回调参数: " + JSON.toJSONString(jsonObject)); + return jsonObject; + } + + /** + * @Author Sum1Dream + * @Name generateRandomString + * @Description // 生成16位随机字符串 + * @Date 16:24 2024/1/15 + * @Param length 长度 + * @return java.lang.String + */ + private static String generateRandomString(Integer length) { + UUID uuid = UUID.randomUUID(); + return uuid.toString().replaceAll("-", "").substring(0, length); + } + + + /** + * @param content AES加密前的明文 + * @return AES加密后的内容 + */ + public static String encrypt(final String content) { + return PetroEncryptUtil.encrypt(content , petroAesKey); + } + + /** + * @Author Sum1Dream + * @Name decrypt + * @Description // 解密 + * @Date 16:19 2023/11/15 + * @Param content + * @Param key + * @return java.lang.String + */ + public static String decrypt(final String content) { + return PetroEncryptUtil.decrypt(content , petroAesKey); + } + +} 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 8e84e24..5e15a8a 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java @@ -37,9 +37,10 @@ public interface BsOrderService { /** * 取消订单 * @param orderNo + * @param system 系统取消 false:不是 true:是 * @return */ - OrderModel cancel(String orderNo); + OrderModel cancel(String orderNo, boolean system); /** * 支付成功业务 diff --git a/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java index 8ad234c..e211669 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java @@ -14,6 +14,7 @@ import com.hfkj.service.coupon.BsOrderCouponService; import com.hfkj.service.coupon.channel.ChongQingCNPCCouponService; import com.hfkj.service.coupon.channel.HuiLianTongCouponService; import com.hfkj.service.coupon.channel.PcytCNPCCouponService; +import com.hfkj.service.coupon.channel.PetroConfig; import com.hfkj.service.goods.GoodsMsgService; import com.hfkj.service.goods.GoodsVpdService; import com.hfkj.service.hlt.HuiLianTongUnionCardService; @@ -156,16 +157,16 @@ public class OrderPaySuccessService { }*/ } else if (vpd.getSource() == GoodsVpdSourceEnum.type7.getCode()) { - /* // 发放卡券 - JSONObject jsonObject = petroConfig.getCoupon(orderCoupon.getGoodsVpdKey(), orderCoupon.getUserPhone()); + // 发放卡券 + JSONObject jsonObject = PetroConfig.getCoupon(orderCoupon.getGoodsVpdKey(), orderCoupon.getUserPhone()); if (!jsonObject.getString("resultCode").equals("0000")) { throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , jsonObject.getString("errMsg")); } String data = PetroConfig.decrypt(jsonObject.getString("jsonResult")); JSONObject object = JSONObject.parseObject(data); - orderCoupon.setExpireTime(vpd.getSalesEndTime()); - orderCoupon.setGoodsVpdSourceCouNo(object.getString("voucher")); - orderCouponService.editData(orderCoupon);*/ + couponNo.setExpireTime(vpd.getSalesEndTime()); + couponNo.setGoodsVpdSourceCouNo(object.getString("voucher")); + orderCouponService.editData(orderCoupon); } else if (vpd.getSource() == GoodsVpdSourceEnum.type10.getCode()) { // 发放卡券 diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java index 3ae2f32..0362152 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java @@ -194,6 +194,10 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { BsOrderRefundExample example = new BsOrderRefundExample(); BsOrderRefundExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(MapUtils.getString(param, "userPhone"))) { + criteria.andUserPhoneEqualTo(MapUtils.getString(param, "userPhone")); + } + if (StringUtils.isNotBlank(MapUtils.getString(param, "orderNo"))) { criteria.andOrderNoEqualTo(MapUtils.getString(param, "orderNo")); } @@ -206,6 +210,14 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { criteria.andOrderNoEqualTo(MapUtils.getString(param, "refundOrderNo")); } + 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"))); + } + example.setOrderByClause("create_time desc"); return orderRefundMapper.selectByExample(example); } 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 841228f..4ad3f91 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 @@ -7,20 +7,19 @@ 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.entity.*; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.mqtopic.OrderTopic; import com.hfkj.service.order.*; +import com.hfkj.service.user.UserIntegralService; +import com.hfkj.sysenum.UserIntegralRecordOpUserTypeEnum; +import com.hfkj.sysenum.UserIntegralRecordSourceTypeEnum; 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; @@ -34,10 +33,7 @@ import org.thymeleaf.util.DateUtils; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @className: BsOrderServiceImpl @@ -69,7 +65,8 @@ public class BsOrderServiceImpl implements BsOrderService { private OrderCancelService orderCancelService; @Resource private OrderPaySuccessService orderPaySuccessService; - + @Resource + private UserIntegralService userIntegralService; @Override public BsOrder editData(BsOrder order) { order.setUpdateTime(new Date()); @@ -101,21 +98,63 @@ public class BsOrderServiceImpl implements BsOrderService { editData(order); // 交易优惠 - if (order.getDeduction() != null) { + BsOrderDeduction deduction = order.getDeduction()==null?new BsOrderDeduction():order.getDeduction(); + deduction.setOrderId(order.getId()); + deduction.setOrderNo(order.getOrderNo()); + deduction.setIntegralDiscountPrice(deduction.getIntegralDiscountPrice()==null?0L: deduction.getIntegralDiscountPrice()); + if (order.getDeduction().getUserCouponDiscountId() != null) { // 计算优惠 - BsOrderDeduction deduction = order.getDeduction(); - deduction.setIntegralDiscountPrice(deduction.getIntegralDiscountPrice()==null?0L: deduction.getIntegralDiscountPrice()); - + CouponDiscount discount = new CouponDiscount(); + deduction.setCouponDiscountId(discount.getId()); + deduction.setCouponDiscountType(discount.getType()); + deduction.setCouponDiscountPrice(discount.getPrice()); + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (1 == discount.getType()) { + deduction.setCouponDiscountActualPrice(discount.getPrice()); + } else if (2 == discount.getType()) { + if (discount.getCondition().compareTo(order.getProductTotalPrice()) < 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未满足优惠券满减条件"); + } + deduction.setCouponDiscountActualPrice(discount.getPrice()); + } else if (3 == discount.getType()) { + deduction.setCouponDiscountActualPrice( + order.getTotalPrice() + .multiply(discount.getPrice().divide(new BigDecimal("100"))) + .setScale(2, BigDecimal.ROUND_DOWN) + ); + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券优惠类型"); + } } 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); + } + // 优惠券优惠金额 + 积分抵扣实际金额 + deduction.setTotalDeductionPrice(deduction.getCouponDiscountActualPrice() + .add(new BigDecimal(deduction.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100")))); + orderDeductionService.editData(deduction); + order.setDeduction(deduction); + + if (order.getDeduction().getIntegralDiscountPrice() > 0) { + Map opUser = new HashMap<>(); + opUser.put("opUserType", UserIntegralRecordOpUserTypeEnum.type3.getCode()); + opUser.put("opUserId", order.getUserId()); + opUser.put("opUserName", order.getUserName()); + opUser.put("opUserPhone", order.getUserPhone()); + + Map source = new HashMap<>(); + source.put("sourceType", UserIntegralRecordSourceTypeEnum.type1.getCode()); + source.put("sourceId", order.getId()); + source.put("sourceOrderNo", order.getOrderNo()); + source.put("sourceContent", "交易积分抵扣"); + + // 扣除用户积分 + userIntegralService.consume( + order.getUserId(), + order.getDeduction().getIntegralDiscountPrice(), + opUser, + source + ); } // 订单总金额 @@ -187,7 +226,7 @@ public class BsOrderServiceImpl implements BsOrderService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10) - public OrderModel cancel(String orderNo) { + public OrderModel cancel(String orderNo, boolean system) { // 查询订单 OrderModel order = getDetail(orderNo); if (order == null) { @@ -204,6 +243,33 @@ public class BsOrderServiceImpl implements BsOrderService { orderChild.setStatus(OrderChildStatusEnum.status5.getCode()); orderChildService.editData(orderChild); } + + if (order.getDeduction().getIntegralDiscountPrice() > 0) { + Map opUser = new HashMap<>(); + if (system) { + opUser.put("opUserType", UserIntegralRecordOpUserTypeEnum.type1.getCode()); + opUser.put("opUserId", 0); + opUser.put("opUserName", UserIntegralRecordOpUserTypeEnum.type1.getName()); + } else { + opUser.put("opUserType", UserIntegralRecordOpUserTypeEnum.type3.getCode()); + opUser.put("opUserId", order.getUserId()); + opUser.put("opUserName", order.getUserName()); + opUser.put("opUserPhone", order.getUserPhone()); + } + Map source = new HashMap<>(); + source.put("sourceType", UserIntegralRecordSourceTypeEnum.type1.getCode()); + source.put("sourceId", order.getId()); + source.put("sourceOrderNo", order.getOrderNo()); + source.put("sourceContent", "交易取消!退回积分"); + + // 扣除用户积分 + userIntegralService.entry( + order.getUserId(), + order.getDeduction().getIntegralDiscountPrice(), + opUser, + source + ); + } // 取消订单业务 orderCancelService.orderBusHandle(order); // 更新缓存 diff --git a/service/src/main/java/com/hfkj/service/user/BsUserIntegralRecordService.java b/service/src/main/java/com/hfkj/service/user/BsUserIntegralRecordService.java new file mode 100644 index 0000000..cf33c2f --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/BsUserIntegralRecordService.java @@ -0,0 +1,17 @@ +package com.hfkj.service.user; + +import com.hfkj.entity.BsUserIntegralRecord; + +/** + * @className: BsUserIntegralRecordService + * @author: HuRui + * @date: 2024/5/20 + **/ +public interface BsUserIntegralRecordService { + + /** + * 编辑数据 + * @param record + */ + void create(BsUserIntegralRecord record); +} diff --git a/service/src/main/java/com/hfkj/service/user/BsUserService.java b/service/src/main/java/com/hfkj/service/user/BsUserService.java index d8b4a9c..4a66e0f 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserService.java @@ -73,16 +73,9 @@ public interface BsUserService { /** * 更新登录Session - * @param token - * @return - */ - SessionObject updateSession(String token); - - /** - * 获取积分数量 - * @param userId + * @param userId 用户id * @return */ - Long getIntegral(Long userId); + SessionObject updateSession(Long userId); } diff --git a/service/src/main/java/com/hfkj/service/user/UserIntegralService.java b/service/src/main/java/com/hfkj/service/user/UserIntegralService.java new file mode 100644 index 0000000..f7ceca7 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/UserIntegralService.java @@ -0,0 +1,40 @@ +package com.hfkj.service.user; + +import java.util.Map; + +/** + * 用户积分业务 + * @className: UserIntegral + * @author: HuRui + * @date: 2024/5/20 + **/ +public interface UserIntegralService { + + /** + * 获取积分数量 + * @param userId + * @return + */ + Long getIntegral(Long userId); + + /** + * 进账 + * @param userId 用户id + * @param integralNum + * @param opUser + * @param source + * @return + */ + void entry(Long userId, Long integralNum, Map opUser, Map source); + + /** + * 消费 + * @param userId 用户id + * @param integralNum + * @param opUser + * @param source + * @return + */ + void consume(Long userId, Long integralNum,Map opUser, Map source); + +} diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserIntegralRecordServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserIntegralRecordServiceImpl.java new file mode 100644 index 0000000..d61ca7c --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserIntegralRecordServiceImpl.java @@ -0,0 +1,26 @@ +package com.hfkj.service.user.impl; + +import com.hfkj.dao.BsUserIntegralRecordMapper; +import com.hfkj.entity.BsUserIntegralRecord; +import com.hfkj.service.user.BsUserIntegralRecordService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * @className: BsUserIntegralRecordServiceImpl + * @author: HuRui + * @date: 2024/5/20 + **/ +@Service("userIntegralRecordService") +public class BsUserIntegralRecordServiceImpl implements BsUserIntegralRecordService { + @Resource + private BsUserIntegralRecordMapper userIntegralRecordMapper; + @Override + public void create(BsUserIntegralRecord record) { + record.setStatus(1); + record.setCreateTime(new Date()); + userIntegralRecordMapper.insert(record); + } +} diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index bcf6103..12177c0 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -8,11 +8,14 @@ import com.hfkj.common.security.SessionObject; import com.hfkj.common.security.UserCenter; import com.hfkj.dao.BsUserMapper; import com.hfkj.entity.BsUser; +import com.hfkj.entity.BsUserCard; import com.hfkj.entity.BsUserExample; import com.hfkj.model.SecUserSessionObject; import com.hfkj.model.UserSessionObject; +import com.hfkj.service.card.BsUserCardService; import com.hfkj.service.user.BsUserLoginLogService; import com.hfkj.service.user.BsUserService; +import com.hfkj.sysenum.UserCardTypeEnum; import com.hfkj.sysenum.UserLoginPlatform; import com.hfkj.sysenum.UserLoginType; import com.hfkj.sysenum.UserStatusEnum; @@ -43,6 +46,8 @@ public class BsUserServiceImpl implements BsUserService { @Resource private UserCenter userCenter; @Resource + private BsUserCardService userCardService; + @Resource private BsUserLoginLogService userLoginLogService; @Override public void editData(BsUser data) { @@ -99,7 +104,7 @@ public class BsUserServiceImpl implements BsUserService { * @throws Exception */ public String token(BsUser user) throws Exception { - // token 生成格式:账户id + 时间戳 + // token 生成格式:账户id return AESEncodeUtil.aesEncrypt(user.getId().toString(), "ydQcF894xdcKQKfc8SEZdZrnSxzMckjZ"); } @@ -132,7 +137,18 @@ public class BsUserServiceImpl implements BsUserService { } // 缓存 - SessionObject sessionObject = new SessionObject(token(user), new UserSessionObject(user)); + UserSessionObject session = new UserSessionObject(); + session.setUser(user); + + // 查询汇联通工会卡 + List hltCardList = userCardService.getCardList(user.getId(), UserCardTypeEnum.type1); + if (hltCardList.isEmpty()) { + session.setHltCardBind(false); + } else { + session.setHltCardBind(true); + session.setHltCard(hltCardList.get(0)); + } + SessionObject sessionObject = new SessionObject(token(user), session); userCenter.save(sessionObject); // 异步记录登录信息 userLoginLogService.asyncCreateLog(platform, loginType, user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); @@ -145,25 +161,32 @@ public class BsUserServiceImpl implements BsUserService { } @Override - public SessionObject updateSession(String token) { - SessionObject sessionObject = userCenter.getSessionObject(token); - UserSessionObject user = (UserSessionObject) sessionObject.getObject(); - - // 重新缓存 - SessionObject newSession = new SessionObject(token, new UserSessionObject(getUser(user.getUser().getId()))); - userCenter.save(newSession); - return newSession; - } - - @Override - public Long getIntegral(Long userId) { - BsUserExample example = new BsUserExample(); - example.createCriteria().andIdEqualTo(userId).andStatusNotEqualTo(UserStatusEnum.status0.getCode()); - List list = userMapper.selectByExample(example); - if (!list.isEmpty()) { - return list.get(0).getIntegral(); + public SessionObject updateSession(Long userId) { + // 查询用户 + BsUser user = getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户"); + } + // 缓存 + UserSessionObject session = new UserSessionObject(); + session.setUser(user); + // 查询汇联通工会卡 + List hltCardList = userCardService.getCardList(user.getId(), UserCardTypeEnum.type1); + if (hltCardList.isEmpty()) { + session.setHltCardBind(false); + } else { + session.setHltCardBind(true); + session.setHltCard(hltCardList.get(0)); + } + try { + // 重新缓存 + SessionObject newSession = new SessionObject(token(user), session); + userCenter.save(newSession); + return newSession; + } catch (Exception e) { + return null; } - return null; } + } diff --git a/service/src/main/java/com/hfkj/service/user/impl/UserIntegralServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/UserIntegralServiceImpl.java new file mode 100644 index 0000000..c718cfb --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/impl/UserIntegralServiceImpl.java @@ -0,0 +1,157 @@ +package com.hfkj.service.user.impl; + +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.entity.BsUser; +import com.hfkj.entity.BsUserIntegralRecord; +import com.hfkj.service.user.BsUserIntegralRecordService; +import com.hfkj.service.user.BsUserService; +import com.hfkj.service.user.UserIntegralService; +import com.hfkj.sysenum.UserIntegralRecordStatusEnum; +import org.apache.commons.collections4.MapUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Map; + +/** + * @className: UserIntegralServiceImpl + * @author: HuRui + * @date: 2024/5/20 + **/ +@Service("userIntegralService") +public class UserIntegralServiceImpl implements UserIntegralService { + @Autowired + private RedisTemplate redisTemplate; + @Resource + private BsUserService userService; + @Resource + private BsUserIntegralRecordService userIntegralRecordService; + @Override + public Long getIntegral(Long userId) { + BsUser user = userService.getUser(userId); + if (user != null) { + return user.getIntegral(); + } + return 0L; + } + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void entry(Long userId, Long integralNum, Map opUser, Map source) { + String key = "USER_INTEGRAL_" + userId; + // 获取锁 + Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, integralNum); + if (Boolean.FALSE.equals(lock)) { + try { + Thread.sleep(100); + } catch (Exception e) { + e.printStackTrace(); + } + entry(userId,integralNum, opUser, source); + } + + try { + // 获取锁成功 + // 查询用户 + BsUser user = userService.getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的账户"); + } + // 变更前积分数 + Long beforeAmount = user.getIntegral(); + + // 计算金额 + user.setIntegral(user.getIntegral() + integralNum); + userService.editData(user); + + // 变更后积分数 + Long afterAmount = user.getIntegral(); + + BsUserIntegralRecord record = new BsUserIntegralRecord(); + record.setUserId(userId); + record.setType(UserIntegralRecordStatusEnum.type1.getCode()); + record.setTransactionAmount(integralNum); + record.setBeforeAmount(beforeAmount); + record.setAfterAmount(afterAmount); + record.setSourceType(MapUtils.getInteger(source, "sourceType")); + record.setSourceId(MapUtils.getLong(source, "sourceId")); + record.setSourceOrderNo(MapUtils.getString(source, "sourceOrderNo")); + record.setSourceContent(MapUtils.getString(source, "sourceContent")); + record.setOpUserType(MapUtils.getInteger(source, "opUserType")); + record.setOpUserId(MapUtils.getLong(source, "opUserId")); + record.setOpUserName(MapUtils.getString(source, "opUserName")); + record.setOpUserPhone(MapUtils.getString(source, "opUserPhone")); + userIntegralRecordService.create(record); + + } catch (Exception e) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分交易异常"); + } finally { + redisTemplate.delete(key); + } + } + + @Override + public void consume(Long userId, Long integralNum, Map opUser, Map source) { + String key = "USER_INTEGRAL_" + userId; + // 获取锁 + Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, integralNum); + if (Boolean.FALSE.equals(lock)) { + try { + Thread.sleep(100); + } catch (Exception e) { + e.printStackTrace(); + } + entry(userId,integralNum, opUser, source); + } + + try { + // 获取锁成功 + // 查询用户 + BsUser user = userService.getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的账户"); + } + if (user.getIntegral() > integralNum) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分数量不足"); + } + // 变更前积分数 + Long beforeAmount = user.getIntegral(); + + // 计算金额 + user.setIntegral(user.getIntegral() - integralNum); + userService.editData(user); + + // 变更后积分数 + Long afterAmount = user.getIntegral(); + + BsUserIntegralRecord record = new BsUserIntegralRecord(); + record.setUserId(userId); + record.setType(UserIntegralRecordStatusEnum.type2.getCode()); + record.setTransactionAmount(integralNum); + record.setBeforeAmount(beforeAmount); + record.setAfterAmount(afterAmount); + record.setSourceType(MapUtils.getInteger(source, "sourceType")); + record.setSourceId(MapUtils.getLong(source, "sourceId")); + record.setSourceOrderNo(MapUtils.getString(source, "sourceOrderNo")); + record.setSourceContent(MapUtils.getString(source, "sourceContent")); + record.setOpUserType(MapUtils.getInteger(source, "opUserType")); + record.setOpUserId(MapUtils.getLong(source, "opUserId")); + record.setOpUserName(MapUtils.getString(source, "opUserName")); + record.setOpUserPhone(MapUtils.getString(source, "opUserPhone")); + userIntegralRecordService.create(record); + + } catch (Exception e) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分交易异常"); + } finally { + redisTemplate.delete(key); + } + } + +} diff --git a/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordOpUserTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordOpUserTypeEnum.java new file mode 100644 index 0000000..659afa4 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordOpUserTypeEnum.java @@ -0,0 +1,37 @@ +package com.hfkj.sysenum; + +import lombok.Getter; + +/** + * @className: UserIntegralRecordOpUserTypeEnum + * @author: HuRui + * @date: 2024/5/20 + **/ +@Getter +public enum UserIntegralRecordOpUserTypeEnum { + + /** + * 系统 + */ + type1(1, "系统"), + + /** + * 支出 + */ + type2(2, "管理员"), + /** + * 用户 + */ + type3(3, "用户"), + ; + + private int code; + + private String name; + + + UserIntegralRecordOpUserTypeEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordSourceTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordSourceTypeEnum.java new file mode 100644 index 0000000..2b1299c --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordSourceTypeEnum.java @@ -0,0 +1,28 @@ +package com.hfkj.sysenum; + +import lombok.Getter; + +/** + * @className: UserIntegralRecordSourceTypeEnum + * @author: HuRui + * @date: 2024/5/20 + **/ +@Getter +public enum UserIntegralRecordSourceTypeEnum { + + /** + * 交易订单 + */ + type1(1, "交易订单"), + ; + + private int code; + + private String name; + + + UserIntegralRecordSourceTypeEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordStatusEnum.java b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordStatusEnum.java new file mode 100644 index 0000000..391ec90 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/UserIntegralRecordStatusEnum.java @@ -0,0 +1,33 @@ +package com.hfkj.sysenum; + +import lombok.Getter; + +/** + * @className: UserIntegralRecordStatusEnum + * @author: HuRui + * @date: 2024/5/20 + **/ +@Getter +public enum UserIntegralRecordStatusEnum { + + /** + * 收入 + */ + type1(1, "收入"), + + /** + * 支出 + */ + type2(2, "支出"), + ; + + private int code; + + private String name; + + + UserIntegralRecordStatusEnum(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 2ff9cc0..a2c58d9 100644 --- a/service/src/main/resources/dev/commonConfig.properties +++ b/service/src/main/resources/dev/commonConfig.properties @@ -30,3 +30,21 @@ huiliantongAppsecret=52662415DDCE55C7BA34223BCF53877A huiliantongSinopecDistributorId=aNId4A3X huiliantongDistributorId=1JnL8YMV huiliantongSinopecUrl=fuelCoupons + + + +scPetroUrl = http://43.136.176.177:8081/hd-api/out/ +scPetroAppid = 510000313181602615 +scPetroAppKey = 510000kA5kxtaDnx3V6HE +scPetroAesKey = AptFsUgpgAij3evH7rm4ubTKu5viSx9U + +gzPetroUrl = http://140.143.82.223:1588/gz +gzPetroAppid = F0bdoJRwt +gzPetroAppKey = pIyhCbA61wwyyU371QUSnBKqbWvO8Q98 +gzPetroAesKey = pIyhCbA61wwyyU371QUSnBKqbWvO8Q98 + +#ETC +etcPostUrl = https://test.djien-qr.com/ +etcChannelCode = GZETCFXQD +etcPublicKey = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMyQb5gR1rweB5oHKqRPJtJjLQKsn5PXOVfaNdGt/2kPkHvRdN3L9zOaAvFEXcEl2V0sg3D8a+2Sfy1YANAZvjscTQYOaoFl+LVyQZvgyyX8RQw+26Jmbqh8DwenUbNf7DFYVSDxIMBLOiWPkGsYGFONjsUVmfykSeVTcEgQB3VwIDAQAB +etcPrivateKey = MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBAO8+KWh/OmBahFk7TWOEjPl13BT5NdlbGvQ/311Yua6CQqul9w1DIR2TwFUUh/Bko/eVoLROfF2XVjHbw2bImTdJ7y9C3511HI59YPNzqyql0DHjLxbH0VW92eUgk8mG09wtrUMu1ImN0b7aFE3uqAgz6pwh3TUiQWsDWz+l/MG7AgMBAAECgYEA7nYsOd8OpbmzT2m/omEdTwz9993KocKgZDJCBj4InftyTrrXO93cZSm/PE6BjMgTcxUuIGpWpcbRgFLHOmzZ4Qd+k/6Yb1ErMTfdGlgrxv2B+vztWYfjmFzEiXpecFH47ED6iYrrqm14X3InpnBv4rUkGdqqNbyPGgTO2ncs/3kCQQD+xqRAQSb/TROlqJdO91y6z9v0PO2GLmokqYg444rKYZKhDE0tdJeLU/sfK8SMg5+SlwdQm4nlo8EDJ/w2CEn3AkEA8GRqVkKgIuH413/a6+luYDjlf30WY7Mi1sm3QPSZ6+eH35UwsL6mdX6mjRpUN9Hez6FMfE7s3XOldoPVMzR1XQJBAOa2VTkGhtz8HEWQZOySXfuhjSogHmu7Dk2C5CO4Eg/wycpjDGSUR0NZWnfAt60S6GbjszEQmJBGeNt10xPO78MCQQCWXwnRaZ3IFDhXfQfRWFSN5ilQ5UszFGQvnUB/ZkI+ObdZmXY6qRdxGcdPLnAN9r78fDZe7/Pk1qljCDY98IuVAkEAnSeO/221gDhL1wnbUhGuX1yo8f5Eo/wDTW5cBxXFGZeexhB8I4jnEV4E/xmikkb3jDFvmrnFk+XUtDqkrvicRQ== diff --git a/user/src/main/java/com/user/controller/UserCardController.java b/user/src/main/java/com/user/controller/UserCardController.java index c83c85a..bcd45a6 100644 --- a/user/src/main/java/com/user/controller/UserCardController.java +++ b/user/src/main/java/com/user/controller/UserCardController.java @@ -112,7 +112,7 @@ public class UserCardController { if (phoneCodeObject == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } - if (smsCode.equals(phoneCodeObject.toString())) { + if (!smsCode.equals(phoneCodeObject.toString())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } @@ -138,7 +138,7 @@ public class UserCardController { @RequestMapping(value = "/queryHltBalance", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询汇联通工会卡余额") - public ResponseData queryHltBalance() { + public ResponseData queryHltBalance(HttpServletRequest request) { try { // 用户 UserSessionObject sessionObject = userCenter.getSessionModel(UserSessionObject.class); diff --git a/user/src/main/java/com/user/controller/UserIntegralController.java b/user/src/main/java/com/user/controller/UserIntegralController.java index dc5cabd..4795a78 100644 --- a/user/src/main/java/com/user/controller/UserIntegralController.java +++ b/user/src/main/java/com/user/controller/UserIntegralController.java @@ -8,6 +8,7 @@ import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.model.ResponseData; import com.hfkj.model.UserSessionObject; import com.hfkj.service.user.BsUserService; +import com.hfkj.service.user.UserIntegralService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -28,11 +29,11 @@ import javax.annotation.Resource; public class UserIntegralController { Logger log = LoggerFactory.getLogger(UserIntegralController.class); @Resource - private BsUserService userService; + private UserIntegralService userIntegralService; @Resource private UserCenter userCenter; - @RequestMapping(value="/queryIntegral",method = RequestMethod.POST) + @RequestMapping(value="/queryIntegral",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取积分数量") public ResponseData queryIntegral() { @@ -43,7 +44,7 @@ public class UserIntegralController { throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); } - return ResponseMsgUtil.success(userService.getIntegral(userSessionObject.getUser().getId())); + return ResponseMsgUtil.success(userIntegralService.getIntegral(userSessionObject.getUser().getId())); } catch (Exception e) { log.error("error!",e);