From bb861d11380875e607aa3c0df65b1f1eff776fb9 Mon Sep 17 00:00:00 2001 From: sj <1304317391@qq.com> Date: Wed, 30 Nov 2022 16:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E5=8F=91=E6=94=BE=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=8E=92=E5=BA=8F=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-local.yaml | 78 +++++++++---------- .../activity/rest/StoreCouponController.java | 54 +++++++++++++ .../impl/YxStoreCouponIssueServiceImpl.java | 12 ++- .../YxStoreCouponIssueUserServiceImpl.java | 2 + .../impl/YxStoreCouponUserServiceImpl.java | 2 +- .../impl/YxStoreSeckillServiceImpl.java | 11 ++- 6 files changed, 109 insertions(+), 50 deletions(-) diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index ecad409f..a721b48d 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -40,63 +40,63 @@ spring: test-while-idle: true test-on-borrow: false test-on-return: false -# datasource: -# master: -# url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: root -# slave: # 模拟从库,可根据自己需要修改 -# url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: root -# bxg: # 农场数据源 -# url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: root -# erp: # 进销存 -# url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: root -# farm: # 农场数据源 -# url: jdbc:p6spy:mysql://192.168.10.250:3306/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 -# driver-class-name: com.p6spy.engine.spy.P6SpyDriver -# username: root -# password: root datasource: master: - url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.p6spy.engine.spy.P6SpyDriver username: root - password: 123456 + password: root slave: # 模拟从库,可根据自己需要修改 - url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.p6spy.engine.spy.P6SpyDriver username: root - password: 123456 + password: root bxg: # 农场数据源 - url: jdbc:p6spy:mysql://localhost:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.p6spy.engine.spy.P6SpyDriver username: root - password: 123456 + password: root erp: # 进销存 - url: jdbc:p6spy:mysql://localhost/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:p6spy:mysql://192.168.10.250:3306/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.p6spy.engine.spy.P6SpyDriver username: root - password: 123456 + password: root farm: # 农场数据源 - url: jdbc:p6spy:mysql://localhost/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:p6spy:mysql://192.168.10.250:3306/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.p6spy.engine.spy.P6SpyDriver username: root - password: 123456 + password: root +# datasource: +# master: +# url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 +# driver-class-name: com.p6spy.engine.spy.P6SpyDriver +# username: root +# password: 123456 +# slave: # 模拟从库,可根据自己需要修改 +# url: jdbc:p6spy:mysql://localhost:3306/vue_pro?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 +# driver-class-name: com.p6spy.engine.spy.P6SpyDriver +# username: root +# password: 123456 +# bxg: # 农场数据源 +# url: jdbc:p6spy:mysql://localhost:3306/vue_pro_bxg?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 +# driver-class-name: com.p6spy.engine.spy.P6SpyDriver +# username: root +# password: 123456 +# erp: # 进销存 +# url: jdbc:p6spy:mysql://localhost/vue_pro_erp?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 +# driver-class-name: com.p6spy.engine.spy.P6SpyDriver +# username: root +# password: 123456 +# farm: # 农场数据源 +# url: jdbc:p6spy:mysql://localhost/zsw-farm?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 +# driver-class-name: com.p6spy.engine.spy.P6SpyDriver +# username: root +# password: 123456 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: -# host: 192.168.10.250 # 地址 - host: 127.0.0.1 # 地址 + host: 192.168.10.250 # 地址 +# host: 127.0.0.1 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 @@ -270,7 +270,7 @@ dubbo: bxg: shop: # API_URL: http://192.168.10.113:48080/bxgApp - API_URL: http://78871492.r2.cpolar.top + API_URL: http://6fa9fbb0.cpolar.top SITE_URL: http://192.168.10.113:48080/bxgApp UNI_SITE_URL: http://192.168.10.113:48080/bxgApp ADMIN_API_URL: http://192.168.10.113:48080/bxg diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/activity/rest/StoreCouponController.java b/zsw-bxg/src/main/java/co/yixiang/modules/activity/rest/StoreCouponController.java index afe4cb3f..532f9c19 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/activity/rest/StoreCouponController.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/activity/rest/StoreCouponController.java @@ -5,16 +5,27 @@ */ package co.yixiang.modules.activity.rest; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.exception.YshopException; import co.yixiang.enums.CouponEnum; +import co.yixiang.event.TemplateBean; +import co.yixiang.event.TemplateEvent; +import co.yixiang.event.TemplateListenEnum; import co.yixiang.logging.aop.log.Log; import co.yixiang.modules.activity.domain.YxStoreCoupon; +import co.yixiang.modules.activity.service.YxStoreCouponIssueService; +import co.yixiang.modules.activity.service.YxStoreCouponIssueUserService; import co.yixiang.modules.activity.service.YxStoreCouponService; +import co.yixiang.modules.activity.service.YxStoreCouponUserService; import co.yixiang.modules.activity.service.dto.YxStoreCouponQueryCriteria; import co.yixiang.modules.aop.ForbidSubmit; +import co.yixiang.modules.user.domain.YxUser; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -29,6 +40,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; +import java.util.List; + /** * @author hupeng * @date 2019-11-09 @@ -39,6 +53,17 @@ import org.springframework.web.bind.annotation.RestController; public class StoreCouponController { private final YxStoreCouponService yxStoreCouponService; + @Autowired + private YxStoreCouponUserService storeCouponUserService; + + @Autowired + private YxStoreCouponIssueService couponIssueService; + + @Autowired + private ApplicationEventPublisher publisher; + + @Autowired + private YxStoreCouponIssueUserService storeCouponIssueUserService; public StoreCouponController(YxStoreCouponService yxStoreCouponService) { this.yxStoreCouponService = yxStoreCouponService; @@ -67,6 +92,35 @@ public class StoreCouponController { return new ResponseEntity<>(yxStoreCouponService.save(resources),HttpStatus.CREATED); } + @Log("发放优惠券") + @ApiOperation(value = "发放优惠券") + @PostMapping(value = "/yxStoreCoupon/give") + @PreAuthorize("@ss.hasAnyPermissions('admin','YXSTORECOUPON_ALL','YXSTORECOUPON_EDIT')") + public ResponseEntity giveOut(@Validated @RequestBody CouponGive couponGive){ + Long couponId = couponGive.getCouponId(); + couponGive.getUserIds().forEach(yxUser -> { + //用户的券记录 + storeCouponUserService.addUserCoupon(yxUser.getUid(),Math.toIntExact(couponId)); +// //领取记录 +// storeCouponIssueUserService.addUserIssue(yxUser.getUid(),Math.toIntExact(couponId)); + //这里调用微信订阅模板发送消息 + TemplateBean templateBean = TemplateBean.builder() + .couponId(Math.toIntExact(couponId)) + .uid(yxUser.getUid()) + .templateType(TemplateListenEnum.TYPE_10.getValue()) + .time(DateUtil.formatTime(new Date())) + .build(); + publisher.publishEvent(new TemplateEvent(this, templateBean)); + }); + return new ResponseEntity(HttpStatus.OK); + } + + //优惠券发放内部类 + @Data + static class CouponGive{ + private Long couponId; + private List userIds; + } @Log("修改") @ApiOperation(value = "修改") diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueServiceImpl.java index 013ef6de..ceb6a945 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueServiceImpl.java @@ -90,6 +90,11 @@ public class YxStoreCouponIssueServiceImpl extends BaseServiceImpl 0){ + yxStoreCouponIssueMapper.decCount(id); + } //这里调用微信订阅模板发送消息 TemplateBean templateBean = TemplateBean.builder() .couponId(couponIssueQueryVo.getCid()) @@ -98,13 +103,6 @@ public class YxStoreCouponIssueServiceImpl extends BaseServiceImpl 0){ - yxStoreCouponIssueMapper.decCount(id); - } - } diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueUserServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueUserServiceImpl.java index b74a0324..72fec88f 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueUserServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponIssueUserServiceImpl.java @@ -19,6 +19,7 @@ import co.yixiang.modules.activity.service.mapper.YxStoreCouponIssueUserMapper; import co.yixiang.utils.FileUtil; import com.github.pagehelper.PageInfo; import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -55,6 +56,7 @@ public class YxStoreCouponIssueUserServiceImpl extends BaseServiceImpl yxStoreSeckillQueryVos = generator.convert (yxStoreSeckillMapper.selectPage(pageModel,wrapper).getRecords(), YxStoreSeckillQueryVo.class); @@ -307,7 +309,8 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl timeIds=new ArrayList<>(); seckillConfigVo.getSeckillTime().forEach(seckillTimeDto -> { if (seckillTimeDto.getStatus()==1){ @@ -357,7 +360,9 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl