diff --git a/mallinkCApi/src/main/java/com/iformall/aop/RedisCacheAspect.java b/mallinkCApi/src/main/java/com/iformall/aop/RedisCacheAspect.java index 8657cce81..9a491cd30 100644 --- a/mallinkCApi/src/main/java/com/iformall/aop/RedisCacheAspect.java +++ b/mallinkCApi/src/main/java/com/iformall/aop/RedisCacheAspect.java @@ -56,90 +56,91 @@ public class RedisCacheAspect { @Around("cacheAspect()") public Object round(ProceedingJoinPoint jp) throws Throwable { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - // 查询token信息 - //从header中获取token - String token = request.getHeader("token"); - //如果header中不存在token,则从参数中获取token - if (StringUtils.isBlank(token)) { - token = request.getParameter("token"); - } - log.info("token>>>>>>>>>>>>>>>"+token); - String tenantId; - WxCUser wxCUser = null ; - if(StringUtils.isNotBlank(token)) { - wxCUser = userTokenService.getByToken(token); - } - if (Objects.isNull(wxCUser) || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()) { - tenantId = "0"; - } else { - tenantId = wxCUser.getTenantId(); - } - - // 请求参数 - Object[] args = jp.getArgs(); - // 接口 返回结果 - Object result; - String redisKey; - - //得到注释的名称 - MethodSignature signature = (MethodSignature) jp.getSignature(); - //判断tag是否在用户权限中 如果存在加入参数查询 - Method method = signature.getMethod(); - RedisCache cache = method.getAnnotation(RedisCache.class) ; - if (cache.autoKey()) { - // 构建 redisKey => reqPath:tenantId:md5(param1_param2_param3) - String requestUrl = request.getRequestURI(); - // 接口路径 reqPath => /api/xxx - String reqPath = requestUrl.substring(requestUrl.indexOf("/api/")); - if (cache.md5()) { - String md5Before = StringUtils.join(args, DELIMITER_PARAMS); - redisKey = StringUtils.join(reqPath, DELIMITER_KEY, tenantId, DELIMITER_KEY, HashUtil.md5(StringUtils.join(token, md5Before, DELIMITER_PARAMS))); - } else { - redisKey = StringUtils.join(reqPath, DELIMITER_KEY, tenantId, DELIMITER_KEY, StringUtils.join(token,args, DELIMITER_PARAMS)); - } - } else { - redisKey = cache.key(); - } - - // redisKey 不存在,获取接口数据并返回 - if (StringUtils.isBlank(redisKey)) { - result = jp.proceed(args); - } else { - ValueOperations valueOperations = stringRedisTemplate.opsForValue(); - String value = valueOperations.get(redisKey); - if (value == null) { - String lockKey = StringUtils.join(redisKey, ":", "lock"); - long time = System.currentTimeMillis() + 2000; - String timeStr = String.valueOf(time); - try { - //分布式锁,保证一个线程读DB,其它线程排队 - if (redisLock.lock2(lockKey, timeStr)) { - log.debug("CacheAspect 读库中, key:{}: " + lockKey); - result = jp.proceed(args); - String json_data = JSONObject.toJSONString(result); - valueOperations.set(redisKey, json_data, cache.expireTime(), cache.dateUnit()); - log.debug("CacheAspect 缓存不存在,获取接口数据并放入缓存,key:{}, expire:{}", redisKey, cache.expireTime()); - } else { - log.debug("CacheAspect 读库等待中, key:{}: " + lockKey); - Thread.sleep(2000); - value = valueOperations.get(redisKey); - result = parseCache(jp, redisKey, value); - } - } catch (Throwable throwable) { - log.error("CacheAspect proceed error , Illegal argument: {} in {}.{}()", Arrays.toString(jp.getArgs()), - jp.getSignature().getDeclaringTypeName(), jp.getSignature().getName(), throwable); - throw throwable; - } finally { - redisLock.unlock(lockKey, timeStr); - } - } else { - result = parseCache(jp, redisKey, value); - } - // 计数器 - stringRedisTemplate.opsForHash().increment("hotapi", redisKey, 1); - } - return result; +// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); +// // 查询token信息 +// //从header中获取token +// String token = request.getHeader("token"); +// //如果header中不存在token,则从参数中获取token +// if (StringUtils.isBlank(token)) { +// token = request.getParameter("token"); +// } +// log.info("token>>>>>>>>>>>>>>>"+token); +// String tenantId; +// WxCUser wxCUser = null ; +// if(StringUtils.isNotBlank(token)) { +// wxCUser = userTokenService.getByToken(token); +// } +// if (Objects.isNull(wxCUser) || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()) { +// tenantId = "0"; +// } else { +// tenantId = wxCUser.getTenantId(); +// } +// +// // 请求参数 +// Object[] args = jp.getArgs(); +// // 接口 返回结果 +// Object result; +// String redisKey; +// +// //得到注释的名称 +// MethodSignature signature = (MethodSignature) jp.getSignature(); +// //判断tag是否在用户权限中 如果存在加入参数查询 +// Method method = signature.getMethod(); +// RedisCache cache = method.getAnnotation(RedisCache.class) ; +// if (cache.autoKey()) { +// // 构建 redisKey => reqPath:tenantId:md5(param1_param2_param3) +// String requestUrl = request.getRequestURI(); +// // 接口路径 reqPath => /api/xxx +// String reqPath = requestUrl.substring(requestUrl.indexOf("/api/")); +// if (cache.md5()) { +// String md5Before = StringUtils.join(args, DELIMITER_PARAMS); +// redisKey = StringUtils.join(reqPath, DELIMITER_KEY, tenantId, DELIMITER_KEY, HashUtil.md5(StringUtils.join(token, md5Before, DELIMITER_PARAMS))); +// } else { +// redisKey = StringUtils.join(reqPath, DELIMITER_KEY, tenantId, DELIMITER_KEY, StringUtils.join(token,args, DELIMITER_PARAMS)); +// } +// } else { +// redisKey = cache.key(); +// } +// +// // redisKey 不存在,获取接口数据并返回 +// if (StringUtils.isBlank(redisKey)) { +// result = jp.proceed(args); +// } else { +// ValueOperations valueOperations = stringRedisTemplate.opsForValue(); +// String value = valueOperations.get(redisKey); +// if (value == null) { +// String lockKey = StringUtils.join(redisKey, ":", "lock"); +// long time = System.currentTimeMillis() + 2000; +// String timeStr = String.valueOf(time); +// try { +// //分布式锁,保证一个线程读DB,其它线程排队 +// if (redisLock.lock2(lockKey, timeStr)) { +// log.debug("CacheAspect 读库中, key:{}: " + lockKey); +// result = jp.proceed(args); +// String json_data = JSONObject.toJSONString(result); +// valueOperations.set(redisKey, json_data, cache.expireTime(), cache.dateUnit()); +// log.debug("CacheAspect 缓存不存在,获取接口数据并放入缓存,key:{}, expire:{}", redisKey, cache.expireTime()); +// } else { +// log.debug("CacheAspect 读库等待中, key:{}: " + lockKey); +// Thread.sleep(2000); +// value = valueOperations.get(redisKey); +// result = parseCache(jp, redisKey, value); +// } +// } catch (Throwable throwable) { +// log.error("CacheAspect proceed error , Illegal argument: {} in {}.{}()", Arrays.toString(jp.getArgs()), +// jp.getSignature().getDeclaringTypeName(), jp.getSignature().getName(), throwable); +// throw throwable; +// } finally { +// redisLock.unlock(lockKey, timeStr); +// } +// } else { +// result = parseCache(jp, redisKey, value); +// } +// // 计数器 +// stringRedisTemplate.opsForHash().increment("hotapi", redisKey, 1); +// } +// return result; + return null; } private Object parseCache(ProceedingJoinPoint jp, String redisKey, String value) { diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java index 9f5299b7c..9f3cc051b 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java @@ -41,7 +41,7 @@ public class WxPayOrderController extends BaseController { @Autowired private WxCUserBasicInfoService wxCUserBasicInfoService; - @ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}") + //@ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}") @RequestMapping(value = "/create", method = RequestMethod.POST) public ResultData _create(@RequestBody Map paramMap, HttpServletRequest request) throws Exception { logger.info("/api/pay/create" + paramMap.toString()); diff --git a/mallinkCApi/src/main/resources/application-dev.yml b/mallinkCApi/src/main/resources/application-dev.yml index 58dd6618e..bad683935 100644 --- a/mallinkCApi/src/main/resources/application-dev.yml +++ b/mallinkCApi/src/main/resources/application-dev.yml @@ -4,7 +4,7 @@ spring: #include: rabbitMQ # JDBC datasource: - url: jdbc:mysql://zc349w82qvn56ftl5e64-rw4rm.rwlb.rds.aliyuncs.com:3306/mallink?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false&useAffectedRows=true + url: jdbc:mysql://rm-2zel9i9t555zy7lftmo.mysql.rds.aliyuncs.com:3306/mallink?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false&useAffectedRows=true username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) password: ENC(IKH7HxMZwIqMttMc9+QsqWa1KMsJvTs4) type: com.alibaba.druid.pool.DruidDataSource diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 5ae6bca6b..12437508d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -256,9 +256,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已撤销,无法支付!"); }else if (EnumPayStatus.PAY_STATUS_WAIT.getCode()==wxpaystatus) { throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单支付中,请勿重复支付!"); - }else if (EnumPayStatus.PAY_STATUS_FAIL.getCode()==wxpaystatus) { + }else if (EnumPayStatus.PAY_STATUS_NOTPAY.getCode()==wxpaystatus || EnumPayStatus.PAY_STATUS_FAIL.getCode()==wxpaystatus) { oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); - oldRecord.setPayOrderNo(String.valueOf(idworker.nextId())); + Long payno = idworker.nextId(); + if (null == payno || payno.intValue() <=0) { + throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!"); + } + oldRecord.setPayOrderNo(String.valueOf(payno)); + int sqlRow0 =wxPayOrderMapper.updateById(oldRecord); if (sqlRow0 != 1) { logger.error("pay order update error: " + record.toString()); @@ -270,7 +275,11 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { }else if(oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_FAIL.getCode()) { oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); //重新设置支付no - oldRecord.setPayOrderNo(String.valueOf(idworker.nextId())); + Long payno = idworker.nextId(); + if (null == payno || payno.intValue() <=0) { + throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!"); + } + oldRecord.setPayOrderNo(String.valueOf(payno)); int sqlRow0 = wxPayOrderMapper.updateById(oldRecord); if (sqlRow0 != 1) { logger.error("pay order update error: " + record.toString()); @@ -284,6 +293,10 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { { // 3.1 创建支付订单 Long id = idworker.nextId(); + if (null == id || id.intValue() <=0) { + throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!"); + } + payOrderNo = String.valueOf(id); record.setId(id); record.updateTenantInfo(order); @@ -318,6 +331,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { } } } + if (payAccount.getType() == EnumPayMode.MCH.getCode()) { // 统一下单 普通商户模式 String noncestr = Utility.generate32UUID();