From 77745360f6eab733b07901846ac299b35c0644fc Mon Sep 17 00:00:00 2001 From: Loki <654612@qq.com> Date: Tue, 6 Dec 2022 12:02:48 +0800 Subject: [PATCH] =?UTF-8?q?:-1:=20=E5=A2=9E=E5=8A=A0=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=92=8C=E8=87=AA=E5=8A=A8=E6=94=B6=E8=B4=A7?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/co/yixiang/job/AutoReceiptJob.java | 34 ++++++ .../java/co/yixiang/job/OrderCancalJob.java | 42 +++++++ .../java/co/yixiang/job/PinkCancalJob.java | 50 ++++++++ .../redis/config/RedisConfigProperties.java | 32 ----- .../redis/config/RedisKeyInitialization.java | 59 ---------- .../redis/config/RedisListenerConfig.java | 49 -------- .../listener/RedisKeyExpirationListener.java | 109 ------------------ .../product/rest/StoreProductController.java | 16 ++- .../serializer/BigDecimalSerializer.java | 2 - 9 files changed, 138 insertions(+), 255 deletions(-) create mode 100644 zsw-bxg/src/main/java/co/yixiang/job/AutoReceiptJob.java create mode 100644 zsw-bxg/src/main/java/co/yixiang/job/OrderCancalJob.java create mode 100644 zsw-bxg/src/main/java/co/yixiang/job/PinkCancalJob.java delete mode 100644 zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisConfigProperties.java delete mode 100644 zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisKeyInitialization.java delete mode 100644 zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisListenerConfig.java delete mode 100644 zsw-bxg/src/main/java/co/yixiang/message/redis/listener/RedisKeyExpirationListener.java diff --git a/zsw-bxg/src/main/java/co/yixiang/job/AutoReceiptJob.java b/zsw-bxg/src/main/java/co/yixiang/job/AutoReceiptJob.java new file mode 100644 index 00000000..00d847ea --- /dev/null +++ b/zsw-bxg/src/main/java/co/yixiang/job/AutoReceiptJob.java @@ -0,0 +1,34 @@ +package co.yixiang.job; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import co.yixiang.enums.OrderInfoEnum; +import co.yixiang.modules.order.domain.YxStoreOrder; +import co.yixiang.modules.order.service.YxStoreOrderService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component("autoReceiptJob") +public class AutoReceiptJob implements JobHandler { + + @Autowired + private YxStoreOrderService storeOrderService; + + @Override + public String execute(String param) throws Exception { + // 每隔30分钟查询7天之前的订单 ,准备自动收获 + List orders = storeOrderService.list(new LambdaQueryWrapper() + .eq(YxStoreOrder::getPaid,OrderInfoEnum.PAY_STATUS_1.getValue()) + .eq(YxStoreOrder::getStatus,OrderInfoEnum.STATUS_1.getValue()) + .apply("TIMESTAMPDIFF(day,create_time,CURRENT_DATE) > 7 ") + ); + orders.forEach(yxStoreOrder -> { + storeOrderService.takeOrder(yxStoreOrder.getOrderId(),null); + }); + + return StrUtil.format("自动收货订单{}条",orders.size()); + } +} diff --git a/zsw-bxg/src/main/java/co/yixiang/job/OrderCancalJob.java b/zsw-bxg/src/main/java/co/yixiang/job/OrderCancalJob.java new file mode 100644 index 00000000..1e34f250 --- /dev/null +++ b/zsw-bxg/src/main/java/co/yixiang/job/OrderCancalJob.java @@ -0,0 +1,42 @@ +package co.yixiang.job; + +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import co.yixiang.enums.OrderInfoEnum; +import co.yixiang.modules.order.domain.YxStoreOrder; +import co.yixiang.modules.order.service.YxStoreOrderService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; + +/** + * 订单自动取消 + */ +@Component("orderCancal") +@Slf4j +public class OrderCancalJob implements JobHandler { + + @Autowired + private YxStoreOrderService storeOrderService; + + @Override + public String execute(String param) throws Exception { + // 每隔30分钟 查找30分钟之前 未支付的订单 + List orders = storeOrderService.list(new LambdaQueryWrapper() + .eq(YxStoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue()) + .lt(YxStoreOrder::getCreateTime, LocalDateTimeUtil.offset(LocalDateTime.now(),-30, ChronoUnit.MINUTES)) + ); + // + orders.forEach(yxStoreOrder -> { + storeOrderService.cancelOrder(yxStoreOrder.getOrderId(),null); + }); + + return StrUtil.format("取消订单{}条",orders.size()); + } +} diff --git a/zsw-bxg/src/main/java/co/yixiang/job/PinkCancalJob.java b/zsw-bxg/src/main/java/co/yixiang/job/PinkCancalJob.java new file mode 100644 index 00000000..70bcc610 --- /dev/null +++ b/zsw-bxg/src/main/java/co/yixiang/job/PinkCancalJob.java @@ -0,0 +1,50 @@ +package co.yixiang.job; + +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import co.yixiang.enums.OrderInfoEnum; +import co.yixiang.modules.activity.domain.YxStorePink; +import co.yixiang.modules.activity.service.YxStorePinkService; +import co.yixiang.modules.order.service.YxStoreOrderService; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class PinkCancalJob implements JobHandler { + + @Autowired + private YxStoreOrderService storeOrderService; + + @Autowired + private YxStorePinkService storePinkService; + + @Override + public String execute(String param) throws Exception { + + + //拼团过期取消 + /** + if(body.contains(ShopConstants.REDIS_PINK_CANCEL_KEY)) { + body = body.replace(ShopConstants.REDIS_PINK_CANCEL_KEY, ""); + log.info("body:{}",body); + String pinkId = body; + YxStorePink storePink = storePinkService.getOne(Wrappers.lambdaQuery() + .eq(YxStorePink::getId,pinkId) + .eq(YxStorePink::getStatus,OrderInfoEnum.PINK_STATUS_1.getValue()) + .eq(YxStorePink::getIsRefund,OrderInfoEnum.PINK_REFUND_STATUS_0.getValue())); + + //取消拼团 + if(storePink != null){ + storePinkService.removePink(storePink.getUid(),storePink.getCid(),storePink.getId()); + log.info("拼团订单id:{},未在规定时间完成取消成功",body); + } + } + */ + + + List pinkOrders = storePinkService.list(Wrappers.lambdaQuery() + .eq(YxStorePink::getStatus, OrderInfoEnum.PINK_STATUS_1.getValue()) + .eq(YxStorePink::getIsRefund, OrderInfoEnum.PINK_REFUND_STATUS_0.getValue())); + return null; + } +} diff --git a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisConfigProperties.java b/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisConfigProperties.java deleted file mode 100644 index 9f3071c7..00000000 --- a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisConfigProperties.java +++ /dev/null @@ -1,32 +0,0 @@ -///** -// * Copyright (C) 2018-2022 -// * All rights reserved, Designed By www.yixiang.co -// * 注意: -// * 本软件为www.yixiang.co开发研制,未经购买不得使用 -// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) -// * 一经发现盗用、分享等行为,将追究法律责任,后果自负 -// */ -//package co.yixiang.message.redis.config; -// -// -//import lombok.Data; -//import org.springframework.boot.context.properties.ConfigurationProperties; -//import org.springframework.context.annotation.Configuration; -// -// -///** -// * reids相关配置 -// * @author hupeng -// * @since 2020-02-27 -// */ -//@Data -//@Configuration(proxyBeanMethods = false) -//@ConfigurationProperties(prefix = "spring.redis") -//public class RedisConfigProperties { -// -// private String host = "host"; -// private String port = "port"; -// private String password = "password"; -// private String database = "database"; -// -//} diff --git a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisKeyInitialization.java b/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisKeyInitialization.java deleted file mode 100644 index a8601098..00000000 --- a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisKeyInitialization.java +++ /dev/null @@ -1,59 +0,0 @@ -///** -// * Copyright (C) 2018-2022 -// * All rights reserved, Designed By www.yixiang.co -// * 注意: -// * 本软件为www.yixiang.co开发研制,未经购买不得使用 -// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) -// * 一经发现盗用、分享等行为,将追究法律责任,后果自负 -// */ -//package co.yixiang.message.redis.config; -// -//import co.yixiang.modules.shop.domain.YxSystemConfig; -//import co.yixiang.modules.shop.service.YxSystemConfigService; -//import co.yixiang.utils.RedisUtils; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.CommandLineRunner; -//import org.springframework.stereotype.Component; -// -//import java.util.List; -// -// -///** -// * api服务启动初始化reids -// */ -//@Slf4j -//@Component -//@RequiredArgsConstructor(onConstructor = @__(@Autowired)) -//public class RedisKeyInitialization implements CommandLineRunner { -// -// -// private final YxSystemConfigService systemConfigService; -// -// -// private final RedisUtils redisUtils; -// -// -// /** -// * 初始化redis -// */ -// private void redisKeyInitialization(){ -// try { -// List systemConfigs = systemConfigService.list(); -// for (YxSystemConfig systemConfig : systemConfigs) { -// redisUtils.set(systemConfig.getMenuName(),systemConfig.getValue()); -// } -// -// log.info("---------------redisKey初始化成功---------------"); -// }catch (Exception e){ -// log.error("redisKey初始化失败: {}",e.getMessage()); -// } -// -// } -// -// @Override -// public void run(String... args) throws Exception { -// this.redisKeyInitialization(); -// } -//} diff --git a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisListenerConfig.java b/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisListenerConfig.java deleted file mode 100644 index 1ea10bdb..00000000 --- a/zsw-bxg/src/main/java/co/yixiang/message/redis/config/RedisListenerConfig.java +++ /dev/null @@ -1,49 +0,0 @@ -///** -// * Copyright (C) 2018-2022 -// * All rights reserved, Designed By www.yixiang.co -// * 注意: -// * 本软件为www.yixiang.co开发研制,未经购买不得使用 -// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) -// * 一经发现盗用、分享等行为,将追究法律责任,后果自负 -// */ -//package co.yixiang.message.redis.config; -// -// -//import cn.hutool.core.util.StrUtil; -//import co.yixiang.message.redis.listener.RedisKeyExpirationListener; -//import co.yixiang.modules.activity.service.YxStorePinkService; -//import co.yixiang.modules.order.service.YxStoreOrderService; -//import lombok.AllArgsConstructor; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.data.redis.connection.RedisConnectionFactory; -//import org.springframework.data.redis.core.RedisTemplate; -//import org.springframework.data.redis.listener.PatternTopic; -//import org.springframework.data.redis.listener.RedisMessageListenerContainer; -// -///** -// * redis监听配置 -// * @author hupeng -// * @since 2020-02-27 -// */ -// -//@Configuration(proxyBeanMethods = false) -//@AllArgsConstructor -//public class RedisListenerConfig { -// -// private final RedisTemplate stringRedisTemplate; -// private final RedisConfigProperties redisConfigProperties; -// private final YxStoreOrderService storeOrderService; -// private final YxStorePinkService storePinkService; -// -// @Bean -// RedisMessageListenerContainer container(RedisConnectionFactory factory) { -// String topic =StrUtil.format("__keyevent@{}__:expired", redisConfigProperties.getDatabase()); -// RedisMessageListenerContainer container = new RedisMessageListenerContainer(); -// container.setConnectionFactory(factory); -// container.addMessageListener(new RedisKeyExpirationListener(stringRedisTemplate,redisConfigProperties -// ,storeOrderService,storePinkService), new PatternTopic(topic)); -// return container; -// } -//} -// diff --git a/zsw-bxg/src/main/java/co/yixiang/message/redis/listener/RedisKeyExpirationListener.java b/zsw-bxg/src/main/java/co/yixiang/message/redis/listener/RedisKeyExpirationListener.java deleted file mode 100644 index 66ceafac..00000000 --- a/zsw-bxg/src/main/java/co/yixiang/message/redis/listener/RedisKeyExpirationListener.java +++ /dev/null @@ -1,109 +0,0 @@ -///** -// * Copyright (C) 2018-2022 -// * All rights reserved, Designed By www.yixiang.co -// * 注意: -// * 本软件为www.yixiang.co开发研制,未经购买不得使用 -// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) -// * 一经发现盗用、分享等行为,将追究法律责任,后果自负 -// */ -//package co.yixiang.message.redis.listener; -// -// -//import cn.hutool.core.util.StrUtil; -//import co.yixiang.constant.ShopConstants; -//import co.yixiang.enums.OrderInfoEnum; -//import co.yixiang.message.redis.config.RedisConfigProperties; -//import co.yixiang.modules.activity.domain.YxStorePink; -//import co.yixiang.modules.activity.service.YxStorePinkService; -//import co.yixiang.modules.order.domain.YxStoreOrder; -//import co.yixiang.modules.order.service.YxStoreOrderService; -//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -//import com.baomidou.mybatisplus.core.toolkit.Wrappers; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.data.redis.connection.Message; -//import org.springframework.data.redis.connection.MessageListener; -//import org.springframework.data.redis.core.RedisTemplate; -//import org.springframework.data.redis.serializer.RedisSerializer; -//import org.springframework.stereotype.Component; -// -///** -// * redis过期监听 -// * @author hupeng -// * @since 2020-02-27 -// */ -//@Component -//@Slf4j -//public class RedisKeyExpirationListener implements MessageListener { -// -// private RedisTemplate redisTemplate; -// private RedisConfigProperties redisConfigProperties; -// private YxStoreOrderService storeOrderService; -// private YxStorePinkService storePinkService; -// -// public RedisKeyExpirationListener(RedisTemplate redisTemplate, -// RedisConfigProperties redisConfigProperties, -// YxStoreOrderService storeOrderService, -// YxStorePinkService storePinkService){ -// this.redisTemplate = redisTemplate; -// this.redisConfigProperties = redisConfigProperties; -// this.storeOrderService = storeOrderService; -// this.storePinkService = storePinkService; -// } -// @Override -// public void onMessage(Message message, byte[] bytes) { -// RedisSerializer serializer = redisTemplate.getValueSerializer(); -// String channel = String.valueOf(serializer.deserialize(message.getChannel())); -// String body = String.valueOf(serializer.deserialize(message.getBody())); -// //key过期监听 -// if(StrUtil.format("__keyevent@{}__:expired", redisConfigProperties.getDatabase()).equals(channel)){ -// //订单自动取消 -// if(body.contains(ShopConstants.REDIS_ORDER_OUTTIME_UNPAY)) { -// body = body.replace(ShopConstants.REDIS_ORDER_OUTTIME_UNPAY, ""); -// log.info("body:{}",body); -// String orderId = body; -// YxStoreOrder order = storeOrderService.getOne(new LambdaQueryWrapper() -// .eq(YxStoreOrder::getId, orderId) -// .eq(YxStoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue())); -// //只有待支付的订单能取消 -// if(order != null){ -// storeOrderService.cancelOrder(order.getOrderId(),null); -// log.info("订单id:{},未在规定时间支付取消成功",body); -// } -// } -// //订单自动收货 -// if(body.contains(ShopConstants.REDIS_ORDER_OUTTIME_UNCONFIRM)) { -// body = body.replace(ShopConstants.REDIS_ORDER_OUTTIME_UNCONFIRM, ""); -// log.info("body:{}",body); -// String orderId = body; -// YxStoreOrder order = storeOrderService.getOne(new LambdaQueryWrapper() -// .eq(YxStoreOrder::getId, orderId) -// .eq(YxStoreOrder::getPaid,OrderInfoEnum.PAY_STATUS_1.getValue()) -// .eq(YxStoreOrder::getStatus,OrderInfoEnum.STATUS_1.getValue())); -// -// //只有待收货的订单能收货 -// if(order != null){ -// storeOrderService.takeOrder(order.getOrderId(),null); -// log.info("订单id:{},自动收货成功",body); -// } -// } -// -// //拼团过期取消 -// if(body.contains(ShopConstants.REDIS_PINK_CANCEL_KEY)) { -// body = body.replace(ShopConstants.REDIS_PINK_CANCEL_KEY, ""); -// log.info("body:{}",body); -// String pinkId = body; -// YxStorePink storePink = storePinkService.getOne(Wrappers.lambdaQuery() -// .eq(YxStorePink::getId,pinkId) -// .eq(YxStorePink::getStatus,OrderInfoEnum.PINK_STATUS_1.getValue()) -// .eq(YxStorePink::getIsRefund,OrderInfoEnum.PINK_REFUND_STATUS_0.getValue())); -// -// //取消拼团 -// if(storePink != null){ -// storePinkService.removePink(storePink.getUid(),storePink.getCid(),storePink.getId()); -// log.info("拼团订单id:{},未在规定时间完成取消成功",body); -// } -// } -// } -// -// } -//} diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java b/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java index 5eb3842a..d63cd66d 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java @@ -249,8 +249,12 @@ public class StoreProductController { productDto.setSliderImage(Arrays.asList(yxStoreProduct.getSliderImage().split(","))); YxStoreProductAttrResult storeProductAttrResult = yxStoreProductAttrResultService .getOne(Wrappers.lambdaQuery() - .eq(YxStoreProductAttrResult::getProductId,id).last("limit 1")); - JSONObject result = JSON.parseObject(storeProductAttrResult.getResult()); + .eq(YxStoreProductAttrResult::getProductId,id).last("limit 1"),false); + JSONObject result = null; + if (ObjectUtil.isNotEmpty(storeProductAttrResult)){ + result = JSON.parseObject(storeProductAttrResult.getResult()); + } + List attrValues = storeProductAttrValueService.list(new LambdaQueryWrapper().eq(YxStoreProductAttrValue::getProductId, yxStoreProduct.getId())); List productFormatDtos =attrValues.stream().map(i ->{ ProductFormatDto productFormatDto = new ProductFormatDto(); @@ -261,9 +265,13 @@ public class StoreProductController { if(SpecTypeEnum.TYPE_1.getValue().equals(yxStoreProduct.getSpecType())){ productDto.setAttr(new ProductFormatDto()); productDto.setAttrs(productFormatDtos); - productDto.setItems(result.getObject("attr",ArrayList.class)); + if (ObjectUtil.isNotEmpty(result)) { + productDto.setItems(result.getObject("attr", ArrayList.class)); + } }else{ - productFromat(productDto, result); + if (ObjectUtil.isNotEmpty(result)) { + productFromat(productDto, result); + } } map.put("productInfo",productDto); diff --git a/zsw-bxg/src/main/java/co/yixiang/serializer/BigDecimalSerializer.java b/zsw-bxg/src/main/java/co/yixiang/serializer/BigDecimalSerializer.java index b774ed21..f978b684 100644 --- a/zsw-bxg/src/main/java/co/yixiang/serializer/BigDecimalSerializer.java +++ b/zsw-bxg/src/main/java/co/yixiang/serializer/BigDecimalSerializer.java @@ -22,7 +22,6 @@ public class BigDecimalSerializer extends JsonSerializer { @Override public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { -// log.info("value1:{}",value); if (value != null) { DecimalFormat df2 =new DecimalFormat("0.00"); gen.writeString(df2.format(value)); @@ -33,7 +32,6 @@ public class BigDecimalSerializer extends JsonSerializer { @Override public void serializeWithType(BigDecimal value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { -// log.info("value2:{}",value); if (value != null) { DecimalFormat df2 =new DecimalFormat("0.00"); gen.writeString(df2.format(value));