Merge branch '2'
# Conflicts: # src/main/java/com/topdraw/business/module/member/profile/service/impl/MemberProfileServiceImpl.java # src/main/java/com/topdraw/business/module/member/service/impl/MemberServiceImpl.java # src/main/java/com/topdraw/business/module/user/iptv/domain/UserTv.java # src/main/java/com/topdraw/business/module/user/iptv/service/dto/UserTvDTO.java # src/main/java/com/topdraw/business/module/user/weixin/service/impl/UserWeixinServiceImpl.java # src/main/java/com/topdraw/mq/consumer/WeiXinEventConsumer.java # src/main/resources/config/application-dev.yml
Showing
221 changed files
with
8029 additions
and
4894 deletions
| ... | @@ -23,12 +23,12 @@ | ... | @@ -23,12 +23,12 @@ |
| 23 | 23 | ||
| 24 | <dependencies> | 24 | <dependencies> |
| 25 | 25 | ||
| 26 | <!--redisson--> | 26 | <!--wechat-util--> |
| 27 | <dependency> | 27 | <!--<dependency> |
| 28 | <groupId>org.redisson</groupId> | 28 | <groupId>com.topdraw</groupId> |
| 29 | <artifactId>redisson</artifactId> | 29 | <artifactId>wechat-util</artifactId> |
| 30 | <version>3.16.3</version> | 30 | <version>0.0.1-SNAPSHOT</version> |
| 31 | </dependency> | 31 | </dependency>--> |
| 32 | 32 | ||
| 33 | <!--代码生成器--> | 33 | <!--代码生成器--> |
| 34 | <dependency> | 34 | <dependency> | ... | ... |
| 1 | package com.topdraw.business.module.common.domain; | 1 | package com.topdraw.business.module.common.domain; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 3 | import lombok.Data; | 4 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
| 5 | 6 | ||
| 6 | import javax.persistence.Transient; | 7 | import javax.persistence.Transient; |
| 8 | import javax.validation.constraints.NotNull; | ||
| 7 | 9 | ||
| 8 | /** | 10 | /** |
| 9 | * @author : | 11 | * @author : |
| ... | @@ -16,9 +18,13 @@ import javax.persistence.Transient; | ... | @@ -16,9 +18,13 @@ import javax.persistence.Transient; |
| 16 | */ | 18 | */ |
| 17 | @Data | 19 | @Data |
| 18 | @Accessors(chain = true) | 20 | @Accessors(chain = true) |
| 19 | public class DefaultAsyncMqModule { | 21 | public class AsyncMqModule { |
| 20 | 22 | ||
| 21 | @Transient | 23 | @Transient |
| 24 | @NotNull(message = "memberCode can't be null" , groups = {UpdateGroup.class}) | ||
| 22 | private String memberCode; | 25 | private String memberCode; |
| 23 | 26 | ||
| 27 | /** 运营商平台账号 */ | ||
| 28 | @Transient | ||
| 29 | private String platformAccount; | ||
| 24 | } | 30 | } | ... | ... |
| ... | @@ -12,6 +12,7 @@ import javax.persistence.*; | ... | @@ -12,6 +12,7 @@ import javax.persistence.*; |
| 12 | import java.io.Serializable; | 12 | import java.io.Serializable; |
| 13 | import java.math.BigDecimal; | 13 | import java.math.BigDecimal; |
| 14 | import java.sql.Timestamp; | 14 | import java.sql.Timestamp; |
| 15 | import java.time.LocalDateTime; | ||
| 15 | 16 | ||
| 16 | /** | 17 | /** |
| 17 | * @author XiangHan | 18 | * @author XiangHan |
| ... | @@ -24,94 +25,94 @@ import java.sql.Timestamp; | ... | @@ -24,94 +25,94 @@ import java.sql.Timestamp; |
| 24 | @Table(name="m_coupon") | 25 | @Table(name="m_coupon") |
| 25 | public class Coupon implements Serializable { | 26 | public class Coupon implements Serializable { |
| 26 | 27 | ||
| 27 | // id | 28 | /** id */ |
| 28 | @Id | 29 | @Id |
| 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 30 | @Column(name = "id") | 31 | @Column(name = "id") |
| 31 | private Long id; | 32 | private Long id; |
| 32 | 33 | ||
| 33 | // 标识 | 34 | /** 标识 */ |
| 34 | @Column(name = "code", nullable = false) | 35 | @Column(name = "code", nullable = false) |
| 35 | private String code; | 36 | private String code; |
| 36 | 37 | ||
| 37 | // 名称 | 38 | /** 名称 */ |
| 38 | @Column(name = "title", nullable = false) | 39 | @Column(name = "title", nullable = false) |
| 39 | private String title; | 40 | private String title; |
| 40 | 41 | ||
| 41 | // 图片 | 42 | /** 图片 */ |
| 42 | @Column(name = "images") | 43 | @Column(name = "images") |
| 43 | private String images; | 44 | private String images; |
| 44 | 45 | ||
| 45 | // 发行量,-1代表不限量 | 46 | /** 发行量,-1代表不限量 */ |
| 46 | @Column(name = "stock") | 47 | @Column(name = "stock") |
| 47 | private Integer stock; | 48 | private Integer stock; |
| 48 | 49 | ||
| 49 | // 剩余量,-1代表不限量 | 50 | /** 剩余量,-1代表不限量 */ |
| 50 | @Column(name = "remain_stock") | 51 | @Column(name = "remain_stock") |
| 51 | private Integer remainStock; | 52 | private Integer remainStock; |
| 52 | 53 | ||
| 53 | // 优惠形式:1:现金;2:折扣 | 54 | /** 优惠形式:1:现金;2:折扣 */ |
| 54 | @Column(name = "use_type") | 55 | @Column(name = "use_type") |
| 55 | private Integer useType; | 56 | private Integer useType; |
| 56 | 57 | ||
| 57 | // 面额 | 58 | /** 面额 */ |
| 58 | @Column(name = "denomination") | 59 | @Column(name = "denomination") |
| 59 | private BigDecimal denomination; | 60 | private BigDecimal denomination; |
| 60 | 61 | ||
| 61 | // 折扣 | 62 | /** 折扣 */ |
| 62 | @Column(name = "discount") | 63 | @Column(name = "discount") |
| 63 | private BigDecimal discount; | 64 | private BigDecimal discount; |
| 64 | 65 | ||
| 65 | // 适用用户范围:1:新用户;2:全体用户 | 66 | /** 适用用户范围:1:新用户;2:全体用户 */ |
| 66 | @Column(name = "user_range") | 67 | @Column(name = "user_range") |
| 67 | private Integer userRange; | 68 | private Integer userRange; |
| 68 | 69 | ||
| 69 | // 限领次数 -1:无限次; >0:具体次数 | 70 | /** 限领次数 -1:无限次; >0:具体次数 */ |
| 70 | @Column(name = "collect_limit") | 71 | @Column(name = "collect_limit") |
| 71 | private Integer collectLimit; | 72 | private Integer collectLimit; |
| 72 | 73 | ||
| 73 | // 适用门槛:1:无门槛;2:满减形式 | 74 | /** 适用门槛:1:无门槛;2:满减形式 */ |
| 74 | @Column(name = "threshold_type") | 75 | @Column(name = "threshold_type") |
| 75 | private Integer thresholdType; | 76 | private Integer thresholdType; |
| 76 | 77 | ||
| 77 | // 满减门槛 | 78 | /** 满减门槛 */ |
| 78 | @Column(name = "amount_threshold") | 79 | @Column(name = "amount_threshold") |
| 79 | private BigDecimal amountThreshold; | 80 | private BigDecimal amountThreshold; |
| 80 | 81 | ||
| 81 | // 产品范围:1:全部商品;2:指定商品 | 82 | /** 产品范围:1:全部商品;2:指定商品 */ |
| 82 | @Column(name = "item_range") | 83 | @Column(name = "item_range") |
| 83 | private Integer itemRange; | 84 | private Integer itemRange; |
| 84 | 85 | ||
| 85 | // 生效形式:1:固定日期;2:相对日期 | 86 | /** 生效形式:1:固定日期;2:相对日期 */ |
| 86 | @Column(name = "effect_type") | 87 | @Column(name = "effect_type") |
| 87 | private Integer effectType; | 88 | private Integer effectType; |
| 88 | 89 | ||
| 89 | // 生效时间 | 90 | /** 生效时间 */ |
| 90 | @Column(name = "start_time") | 91 | @Column(name = "start_time") |
| 91 | private Timestamp startTime; | 92 | private Timestamp startTime; |
| 92 | 93 | ||
| 93 | // 过期时间 | 94 | /** 过期时间 */ |
| 94 | @Column(name = "expire_time") | 95 | @Column(name = "expire_time") |
| 95 | private Timestamp expireTime; | 96 | private LocalDateTime expireTime; |
| 96 | 97 | ||
| 97 | // 自领取当日,几天内有效 | 98 | /** 自领取当日,几天内有效 */ |
| 98 | @Column(name = "valid_days") | 99 | @Column(name = "valid_days") |
| 99 | private Integer validDays; | 100 | private Integer validDays; |
| 100 | 101 | ||
| 101 | // 使用说明 | 102 | /** 使用说明 */ |
| 102 | @Column(name = "description") | 103 | @Column(name = "description") |
| 103 | private String description; | 104 | private String description; |
| 104 | 105 | ||
| 105 | // 状态0:未开始,1:启用;2:停用 | 106 | /** 状态0:未开始,1:启用;2:停用 */ |
| 106 | @Column(name = "status") | 107 | @Column(name = "status") |
| 107 | private Integer status; | 108 | private Integer status; |
| 108 | 109 | ||
| 109 | // 创建时间 | 110 | /** 创建时间 */ |
| 110 | @CreatedDate | 111 | @CreatedDate |
| 111 | @Column(name = "create_time") | 112 | @Column(name = "create_time") |
| 112 | private Timestamp createTime; | 113 | private Timestamp createTime; |
| 113 | 114 | ||
| 114 | // 更新时间 | 115 | /** 更新时间 */ |
| 115 | @LastModifiedDate | 116 | @LastModifiedDate |
| 116 | @Column(name = "update_time") | 117 | @Column(name = "update_time") |
| 117 | private Timestamp updateTime; | 118 | private Timestamp updateTime; | ... | ... |
| 1 | package com.topdraw.business.module.coupon.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | ||
| 4 | import com.topdraw.util.IdWorker; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.beans.BeanUtils; | ||
| 7 | |||
| 8 | import java.math.BigDecimal; | ||
| 9 | import java.sql.Timestamp; | ||
| 10 | import java.time.LocalDateTime; | ||
| 11 | import java.util.Objects; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * 优惠券 | ||
| 15 | */ | ||
| 16 | public class CouponBuilder { | ||
| 17 | |||
| 18 | public static Coupon build(CouponDTO couponDTO){ | ||
| 19 | Coupon coupon = new Coupon(); | ||
| 20 | BeanUtils.copyProperties(couponDTO,coupon); | ||
| 21 | return build(coupon.getId(), | ||
| 22 | coupon.getCode(), | ||
| 23 | coupon.getTitle(),coupon.getImages(),coupon.getStock(),coupon.getRemainStock(),coupon.getUseType(), | ||
| 24 | coupon.getDenomination(),coupon.getDiscount(),coupon.getUserRange(),coupon.getCollectLimit(), | ||
| 25 | coupon.getThresholdType(),coupon.getAmountThreshold(),coupon.getItemRange(),coupon.getEffectType(), | ||
| 26 | coupon.getStartTime(),coupon.getExpireTime(),coupon.getValidDays(),coupon.getDescription(),coupon.getStatus()); | ||
| 27 | } | ||
| 28 | |||
| 29 | public static Coupon build(Coupon coupon){ | ||
| 30 | return build(coupon.getId(), | ||
| 31 | coupon.getCode(), | ||
| 32 | coupon.getTitle(),coupon.getImages(),coupon.getStock(),coupon.getRemainStock(),coupon.getUseType(), | ||
| 33 | coupon.getDenomination(),coupon.getDiscount(),coupon.getUserRange(),coupon.getCollectLimit(), | ||
| 34 | coupon.getThresholdType(),coupon.getAmountThreshold(),coupon.getItemRange(),coupon.getEffectType(), | ||
| 35 | coupon.getStartTime(),coupon.getExpireTime(),coupon.getValidDays(),coupon.getDescription(),coupon.getStatus()); | ||
| 36 | } | ||
| 37 | |||
| 38 | public static Coupon build(Long id , String code , String title, | ||
| 39 | String images, | ||
| 40 | Integer stock, | ||
| 41 | Integer remainStock, | ||
| 42 | Integer useType, | ||
| 43 | BigDecimal denomination, | ||
| 44 | BigDecimal discount, | ||
| 45 | Integer userRange, | ||
| 46 | Integer collectLimit, | ||
| 47 | Integer thresholdType, | ||
| 48 | BigDecimal amountThreshold, | ||
| 49 | Integer itemRange, | ||
| 50 | Integer effectType, | ||
| 51 | Timestamp startTime, | ||
| 52 | LocalDateTime expireTime, | ||
| 53 | Integer validDays,String description , Integer status){ | ||
| 54 | |||
| 55 | Coupon coupon = new Coupon(); | ||
| 56 | coupon.setId(id); | ||
| 57 | coupon.setCode(StringUtils.isBlank(code)? IdWorker.generatorCode("coupon"):code); | ||
| 58 | coupon.setTitle(StringUtils.isBlank(title)?null:title); | ||
| 59 | coupon.setImages(StringUtils.isBlank(images)?null:images); | ||
| 60 | coupon.setStock(Objects.isNull(stock)?null:stock); | ||
| 61 | coupon.setRemainStock(Objects.isNull(remainStock)?null:remainStock); | ||
| 62 | coupon.setUseType(Objects.isNull(useType)?null:useType); | ||
| 63 | coupon.setDenomination(Objects.isNull(denomination)?null:denomination); | ||
| 64 | coupon.setDiscount(Objects.isNull(discount)?null:discount); | ||
| 65 | coupon.setUserRange(Objects.isNull(userRange)?null:userRange); | ||
| 66 | coupon.setCollectLimit(collectLimit); | ||
| 67 | coupon.setThresholdType(Objects.isNull(thresholdType)?null:thresholdType); | ||
| 68 | coupon.setAmountThreshold(Objects.isNull(amountThreshold)?null:amountThreshold); | ||
| 69 | coupon.setItemRange(Objects.isNull(itemRange)?null:itemRange); | ||
| 70 | coupon.setEffectType(Objects.isNull(effectType)?null:effectType); | ||
| 71 | coupon.setStartTime(Objects.isNull(startTime)?null: startTime); | ||
| 72 | coupon.setExpireTime(Objects.isNull(expireTime)?null:expireTime); | ||
| 73 | coupon.setValidDays(validDays); | ||
| 74 | coupon.setDescription(StringUtils.isBlank(description)?"":description); | ||
| 75 | coupon.setStatus(Objects.nonNull(status)?status:0); | ||
| 76 | return coupon; | ||
| 77 | } | ||
| 78 | |||
| 79 | } |
| ... | @@ -10,7 +10,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ... | @@ -10,7 +10,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 10 | ||
| 11 | import javax.persistence.*; | 11 | import javax.persistence.*; |
| 12 | import java.io.Serializable; | 12 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | ||
| 14 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| ... | @@ -24,54 +23,57 @@ import java.time.LocalDateTime; | ... | @@ -24,54 +23,57 @@ import java.time.LocalDateTime; |
| 24 | @Table(name="m_coupon_history") | 23 | @Table(name="m_coupon_history") |
| 25 | public class CouponHistory implements Serializable { | 24 | public class CouponHistory implements Serializable { |
| 26 | 25 | ||
| 27 | // 主键 | 26 | @Transient |
| 27 | private String memberCode; | ||
| 28 | |||
| 29 | /** 主键 */ | ||
| 28 | @Id | 30 | @Id |
| 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 30 | @Column(name = "id") | 32 | @Column(name = "id") |
| 31 | private Long id; | 33 | private Long id; |
| 32 | 34 | ||
| 33 | // 优惠券id | 35 | /** 优惠券id */ |
| 34 | @Column(name = "coupon_id") | 36 | @Column(name = "coupon_id") |
| 35 | private Long couponId; | 37 | private Long couponId; |
| 36 | 38 | ||
| 37 | // 领券用户id(对应账号) | 39 | /** 领券用户id(对应账号) */ |
| 38 | @Column(name = "user_id") | 40 | @Column(name = "user_id") |
| 39 | private Long userId; | 41 | private Long userId; |
| 40 | 42 | ||
| 41 | // 优惠券code | 43 | /** 优惠券code */ |
| 42 | @Column(name = "coupon_code") | 44 | @Column(name = "coupon_code") |
| 43 | private String couponCode; | 45 | private String couponCode; |
| 44 | 46 | ||
| 45 | // 领取人昵称 | 47 | /** 领取人昵称 */ |
| 46 | @Column(name = "user_nickname") | 48 | @Column(name = "user_nickname") |
| 47 | private String userNickname; | 49 | private String userNickname; |
| 48 | 50 | ||
| 49 | // 领取时间 | 51 | /** 领取时间 */ |
| 50 | @Column(name = "receive_time") | 52 | @Column(name = "receive_time") |
| 51 | private LocalDateTime receiveTime; | 53 | private LocalDateTime receiveTime; |
| 52 | 54 | ||
| 53 | // 失效时间 | 55 | /** 失效时间 */ |
| 54 | @Column(name = "expire_time") | 56 | @Column(name = "expire_time") |
| 55 | private LocalDateTime expireTime; | 57 | private LocalDateTime expireTime; |
| 56 | 58 | ||
| 57 | // 使用状态 0:未使用;1:已使用;-1:已过期 | 59 | /** 使用状态 0:未使用;1:已使用;-1:已过期 */ |
| 58 | @Column(name = "use_status") | 60 | @Column(name = "use_status") |
| 59 | private Integer useStatus; | 61 | private Integer useStatus; |
| 60 | 62 | ||
| 61 | // 使用时间 | 63 | /** 使用时间 */ |
| 62 | @Column(name = "use_time") | 64 | @Column(name = "use_time") |
| 63 | private LocalDateTime useTime; | 65 | private LocalDateTime useTime; |
| 64 | 66 | ||
| 65 | // 订单详情id | 67 | /** 订单详情id */ |
| 66 | @Column(name = "order_detail_id") | 68 | @Column(name = "order_detail_id") |
| 67 | private Long orderDetailId; | 69 | private Long orderDetailId; |
| 68 | 70 | ||
| 69 | // 创建时间 | 71 | /** 创建时间 */ |
| 70 | @CreatedDate | 72 | @CreatedDate |
| 71 | @Column(name = "create_time") | 73 | @Column(name = "create_time") |
| 72 | private LocalDateTime createTime; | 74 | private LocalDateTime createTime; |
| 73 | 75 | ||
| 74 | // 更新时间 | 76 | /** 更新时间 */ |
| 75 | @LastModifiedDate | 77 | @LastModifiedDate |
| 76 | @Column(name = "update_time") | 78 | @Column(name = "update_time") |
| 77 | private LocalDateTime updateTime; | 79 | private LocalDateTime updateTime; | ... | ... |
src/main/java/com/topdraw/business/module/coupon/history/domain/CouponHistoryBuilder.java
0 → 100644
| 1 | package com.topdraw.business.module.coupon.history.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.coupon.domain.Coupon; | ||
| 4 | import org.apache.commons.lang3.StringUtils; | ||
| 5 | |||
| 6 | import java.time.LocalDateTime; | ||
| 7 | import java.util.Objects; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * 优惠券 | ||
| 11 | */ | ||
| 12 | public class CouponHistoryBuilder { | ||
| 13 | |||
| 14 | public static CouponHistory build(CouponHistory couponHistory){ | ||
| 15 | return build(couponHistory.getId(), | ||
| 16 | couponHistory.getCouponId(), | ||
| 17 | couponHistory.getUserId(), | ||
| 18 | couponHistory.getCouponCode(), | ||
| 19 | couponHistory.getUserNickname(), | ||
| 20 | couponHistory.getReceiveTime(), | ||
| 21 | couponHistory.getExpireTime(), | ||
| 22 | couponHistory.getUseStatus(), | ||
| 23 | couponHistory.getUseTime(), | ||
| 24 | couponHistory.getOrderDetailId()); | ||
| 25 | } | ||
| 26 | |||
| 27 | public static CouponHistory build(Coupon coupon, Long userId, String userNickname){ | ||
| 28 | return build(coupon,userId,userNickname,null); | ||
| 29 | } | ||
| 30 | |||
| 31 | public static CouponHistory build(Coupon coupon, Long userId, String userNickname, Long orderDetailId){ | ||
| 32 | return build(null, | ||
| 33 | coupon.getId(),userId,coupon.getCode(),userNickname,LocalDateTime.now(), | ||
| 34 | coupon.getExpireTime(),coupon.getStatus(),null,orderDetailId); | ||
| 35 | } | ||
| 36 | |||
| 37 | public static CouponHistory build(Long id , Long couponId , Long userId, String couponCode, String userNickname, LocalDateTime receiveTime, | ||
| 38 | LocalDateTime expireTime, Integer useStatus, LocalDateTime useTime, | ||
| 39 | Long orderDetailId) { | ||
| 40 | CouponHistory couponHistory = new CouponHistory(); | ||
| 41 | couponHistory.setId(id); | ||
| 42 | couponHistory.setCouponId(Objects.isNull(couponId)?null:couponId); | ||
| 43 | couponHistory.setUserId(Objects.isNull(userId)?null:userId); | ||
| 44 | couponHistory.setCouponCode(StringUtils.isBlank(couponCode)?null:couponCode); | ||
| 45 | couponHistory.setUserNickname(StringUtils.isBlank(userNickname)?null:userNickname); | ||
| 46 | couponHistory.setReceiveTime(Objects.isNull(receiveTime)?null:receiveTime); | ||
| 47 | couponHistory.setExpireTime(Objects.isNull(expireTime)?null:expireTime); | ||
| 48 | couponHistory.setUseStatus(Objects.isNull(useStatus)?0:useStatus); | ||
| 49 | couponHistory.setUseTime(Objects.isNull(useTime)?null:useTime); | ||
| 50 | couponHistory.setOrderDetailId(Objects.isNull(orderDetailId)?null:orderDetailId); | ||
| 51 | return couponHistory; | ||
| 52 | } | ||
| 53 | |||
| 54 | } |
| ... | @@ -4,7 +4,6 @@ import com.topdraw.business.module.coupon.history.domain.CouponHistory; | ... | @@ -4,7 +4,6 @@ import com.topdraw.business.module.coupon.history.domain.CouponHistory; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | 6 | ||
| 7 | import java.sql.Timestamp; | ||
| 8 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 9 | 8 | ||
| 10 | /** | 9 | /** | ... | ... |
| ... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.coupon.history.service; | ... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.coupon.history.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.coupon.history.domain.CouponHistory; | 3 | import com.topdraw.business.module.coupon.history.domain.CouponHistory; |
| 4 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO; | 4 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO; |
| 5 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.sql.Timestamp; | ||
| 9 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 10 | import java.util.List; | ||
| 11 | import java.util.Map; | ||
| 12 | 7 | ||
| 13 | /** | 8 | /** |
| 14 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -16,20 +11,6 @@ import java.util.Map; | ... | @@ -16,20 +11,6 @@ import java.util.Map; |
| 16 | */ | 11 | */ |
| 17 | public interface CouponHistoryService { | 12 | public interface CouponHistoryService { |
| 18 | 13 | ||
| 19 | /** | ||
| 20 | * 查询数据分页 | ||
| 21 | * @param criteria 条件参数 | ||
| 22 | * @param pageable 分页参数 | ||
| 23 | * @return Map<String,Object> | ||
| 24 | */ | ||
| 25 | Map<String,Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable); | ||
| 26 | |||
| 27 | /** | ||
| 28 | * 查询所有数据不分页 | ||
| 29 | * @param criteria 条件参数 | ||
| 30 | * @return List<CouponHistoryDTO> | ||
| 31 | */ | ||
| 32 | List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria); | ||
| 33 | 14 | ||
| 34 | /** | 15 | /** |
| 35 | * 根据ID查询 | 16 | * 根据ID查询 |
| ... | @@ -38,15 +19,33 @@ public interface CouponHistoryService { | ... | @@ -38,15 +19,33 @@ public interface CouponHistoryService { |
| 38 | */ | 19 | */ |
| 39 | CouponHistoryDTO findById(Long id); | 20 | CouponHistoryDTO findById(Long id); |
| 40 | 21 | ||
| 22 | /** | ||
| 23 | * | ||
| 24 | * @param resources | ||
| 25 | */ | ||
| 41 | void create(CouponHistory resources); | 26 | void create(CouponHistory resources); |
| 42 | 27 | ||
| 43 | void update(CouponHistory resources); | 28 | /** |
| 44 | 29 | * | |
| 45 | void delete(Long id); | 30 | * @param userId |
| 46 | 31 | * @return | |
| 32 | */ | ||
| 47 | Long countByUserId(Long userId); | 33 | Long countByUserId(Long userId); |
| 48 | 34 | ||
| 35 | /** | ||
| 36 | * | ||
| 37 | * @param userId | ||
| 38 | * @param now | ||
| 39 | * @return | ||
| 40 | */ | ||
| 49 | Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now); | 41 | Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now); |
| 50 | 42 | ||
| 43 | /** | ||
| 44 | * | ||
| 45 | * @param userId | ||
| 46 | * @param now | ||
| 47 | * @param expireTime | ||
| 48 | * @return | ||
| 49 | */ | ||
| 51 | Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime); | 50 | Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime); |
| 52 | } | 51 | } | ... | ... |
| ... | @@ -3,7 +3,6 @@ package com.topdraw.business.module.coupon.history.service.dto; | ... | @@ -3,7 +3,6 @@ package com.topdraw.business.module.coupon.history.service.dto; |
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | ||
| 7 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 8 | 7 | ||
| 9 | 8 | ||
| ... | @@ -14,39 +13,39 @@ import java.time.LocalDateTime; | ... | @@ -14,39 +13,39 @@ import java.time.LocalDateTime; |
| 14 | @Data | 13 | @Data |
| 15 | public class CouponHistoryDTO implements Serializable { | 14 | public class CouponHistoryDTO implements Serializable { |
| 16 | 15 | ||
| 17 | // 主键 | 16 | /** 主键 */ |
| 18 | private Long id; | 17 | private Long id; |
| 19 | 18 | ||
| 20 | // 优惠券id | 19 | /** 优惠券id */ |
| 21 | private Long couponId; | 20 | private Long couponId; |
| 22 | 21 | ||
| 23 | // 领券用户id(对应账号) | 22 | /** 领券用户id(对应账号) */ |
| 24 | private Long userId; | 23 | private Long userId; |
| 25 | 24 | ||
| 26 | // 优惠券code | 25 | /** 优惠券code */ |
| 27 | private String couponCode; | 26 | private String couponCode; |
| 28 | 27 | ||
| 29 | // 领取人昵称 | 28 | /** 领取人昵称 */ |
| 30 | private String userNickname; | 29 | private String userNickname; |
| 31 | 30 | ||
| 32 | // 领取时间 | 31 | /** 领取时间 */ |
| 33 | private LocalDateTime receiveTime; | 32 | private LocalDateTime receiveTime; |
| 34 | 33 | ||
| 35 | // 失效时间 | 34 | /** 失效时间 */ |
| 36 | private LocalDateTime expireTime; | 35 | private LocalDateTime expireTime; |
| 37 | 36 | ||
| 38 | // 使用状态 0:未使用;1:已使用;-1:已过期 | 37 | /** 使用状态 0:未使用;1:已使用;-1:已过期 */ |
| 39 | private Integer useStatus; | 38 | private Integer useStatus; |
| 40 | 39 | ||
| 41 | // 使用时间 | 40 | /** 使用时间 */ |
| 42 | private LocalDateTime useTime; | 41 | private LocalDateTime useTime; |
| 43 | 42 | ||
| 44 | // 订单详情id | 43 | /** 订单详情id */ |
| 45 | private Long orderDetailId; | 44 | private Long orderDetailId; |
| 46 | 45 | ||
| 47 | // 创建时间 | 46 | /** 创建时间 */ |
| 48 | private LocalDateTime createTime; | 47 | private LocalDateTime createTime; |
| 49 | 48 | ||
| 50 | // 更新时间 | 49 | /** 更新时间 */ |
| 51 | private LocalDateTime updateTime; | 50 | private LocalDateTime updateTime; |
| 52 | } | 51 | } | ... | ... |
| 1 | package com.topdraw.business.module.coupon.history.service.impl; | 1 | package com.topdraw.business.module.coupon.history.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.coupon.history.domain.CouponHistory; | 3 | import com.topdraw.business.module.coupon.history.domain.CouponHistory; |
| 4 | import com.topdraw.business.module.coupon.history.domain.CouponHistoryBuilder; | ||
| 4 | import com.topdraw.business.module.coupon.history.repository.CouponHistoryRepository; | 5 | import com.topdraw.business.module.coupon.history.repository.CouponHistoryRepository; |
| 5 | import com.topdraw.business.module.coupon.history.service.CouponHistoryService; | 6 | import com.topdraw.business.module.coupon.history.service.CouponHistoryService; |
| 6 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO; | 7 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryDTO; |
| 7 | import com.topdraw.business.module.coupon.history.service.dto.CouponHistoryQueryCriteria; | ||
| 8 | import com.topdraw.business.module.coupon.history.service.mapper.CouponHistoryMapper; | 8 | import com.topdraw.business.module.coupon.history.service.mapper.CouponHistoryMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 14 | import org.springframework.data.domain.Page; | ||
| 15 | import org.springframework.data.domain.Pageable; | ||
| 16 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 19 | import org.springframework.util.Assert; | ||
| 20 | 14 | ||
| 21 | import java.sql.Timestamp; | ||
| 22 | import java.time.LocalDateTime; | 15 | import java.time.LocalDateTime; |
| 23 | import java.util.List; | ||
| 24 | import java.util.Map; | ||
| 25 | 16 | ||
| 26 | /** | 17 | /** |
| 27 | * @author XiangHan | 18 | * @author XiangHan |
| ... | @@ -32,67 +23,38 @@ import java.util.Map; | ... | @@ -32,67 +23,38 @@ import java.util.Map; |
| 32 | public class CouponHistoryServiceImpl implements CouponHistoryService { | 23 | public class CouponHistoryServiceImpl implements CouponHistoryService { |
| 33 | 24 | ||
| 34 | @Autowired | 25 | @Autowired |
| 35 | private CouponHistoryRepository CouponHistoryRepository; | 26 | private CouponHistoryMapper couponHistoryMapper; |
| 36 | |||
| 37 | @Autowired | 27 | @Autowired |
| 38 | private CouponHistoryMapper CouponHistoryMapper; | 28 | private CouponHistoryRepository couponHistoryRepository; |
| 39 | |||
| 40 | @Override | ||
| 41 | public Map<String, Object> queryAll(CouponHistoryQueryCriteria criteria, Pageable pageable) { | ||
| 42 | Page<CouponHistory> page = CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 43 | return PageUtil.toPage(page.map(CouponHistoryMapper::toDto)); | ||
| 44 | } | ||
| 45 | 29 | ||
| 46 | @Override | ||
| 47 | public List<CouponHistoryDTO> queryAll(CouponHistoryQueryCriteria criteria) { | ||
| 48 | return CouponHistoryMapper.toDto(CouponHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 49 | } | ||
| 50 | 30 | ||
| 51 | @Override | 31 | @Override |
| 52 | public CouponHistoryDTO findById(Long id) { | 32 | public CouponHistoryDTO findById(Long id) { |
| 53 | CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseGet(CouponHistory::new); | 33 | CouponHistory couponHistory = this.couponHistoryRepository.findById(id).orElseGet(CouponHistory::new); |
| 54 | ValidationUtil.isNull(CouponHistory.getId(),"CouponHistory","id",id); | 34 | ValidationUtil.isNull(couponHistory.getId(),"CouponHistory","id",id); |
| 55 | return CouponHistoryMapper.toDto(CouponHistory); | 35 | return this.couponHistoryMapper.toDto(couponHistory); |
| 56 | } | 36 | } |
| 57 | 37 | ||
| 58 | @Override | 38 | @Override |
| 59 | @Transactional(rollbackFor = Exception.class) | 39 | @Transactional(rollbackFor = Exception.class) |
| 60 | public void create(CouponHistory resources) { | 40 | public void create(CouponHistory resources) { |
| 61 | CouponHistoryRepository.save(resources); | 41 | CouponHistory couponHistory = CouponHistoryBuilder.build(resources); |
| 62 | } | 42 | this.couponHistoryRepository.save(couponHistory); |
| 63 | |||
| 64 | @Override | ||
| 65 | @Transactional(rollbackFor = Exception.class) | ||
| 66 | public void update(CouponHistory resources) { | ||
| 67 | CouponHistory CouponHistory = CouponHistoryRepository.findById(resources.getId()).orElseGet(CouponHistory::new); | ||
| 68 | ValidationUtil.isNull( CouponHistory.getId(),"CouponHistory","id",resources.getId()); | ||
| 69 | CouponHistory.copy(resources); | ||
| 70 | CouponHistoryRepository.save(CouponHistory); | ||
| 71 | } | ||
| 72 | |||
| 73 | @Override | ||
| 74 | @Transactional(rollbackFor = Exception.class) | ||
| 75 | public void delete(Long id) { | ||
| 76 | Assert.notNull(id, "The given id must not be null!"); | ||
| 77 | CouponHistory CouponHistory = CouponHistoryRepository.findById(id).orElseThrow( | ||
| 78 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", CouponHistory.class, id), 1)); | ||
| 79 | CouponHistoryRepository.delete(CouponHistory); | ||
| 80 | } | 43 | } |
| 81 | 44 | ||
| 82 | @Override | 45 | @Override |
| 83 | public Long countByUserId(Long userId) { | 46 | public Long countByUserId(Long userId) { |
| 84 | return this.CouponHistoryRepository.countByUserId(userId); | 47 | return this.couponHistoryRepository.countByUserId(userId); |
| 85 | } | 48 | } |
| 86 | 49 | ||
| 87 | @Override | 50 | @Override |
| 88 | public Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now) { | 51 | public Long countByUserIdAndExpireTimeBefore(Long userId, LocalDateTime now) { |
| 89 | return this.CouponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now); | 52 | return this.couponHistoryRepository.countByUserIdAndExpireTimeBefore(userId,now); |
| 90 | } | 53 | } |
| 91 | 54 | ||
| 92 | @Override | 55 | @Override |
| 93 | public Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime) { | 56 | public Long countByUserIdAndExpireTimeBetween(Long userId, LocalDateTime now, LocalDateTime expireTime) { |
| 94 | return this.CouponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime); | 57 | return this.couponHistoryRepository.countByUserIdAndExpireTimeBetween(userId,now,expireTime); |
| 95 | } | 58 | } |
| 96 | 59 | ||
| 97 | |||
| 98 | } | 60 | } | ... | ... |
| ... | @@ -13,4 +13,5 @@ import java.util.Optional; | ... | @@ -13,4 +13,5 @@ import java.util.Optional; |
| 13 | public interface CouponRepository extends JpaRepository<Coupon, Long>, JpaSpecificationExecutor<Coupon> { | 13 | public interface CouponRepository extends JpaRepository<Coupon, Long>, JpaSpecificationExecutor<Coupon> { |
| 14 | 14 | ||
| 15 | Optional<Coupon> findFirstByCode(String code); | 15 | Optional<Coupon> findFirstByCode(String code); |
| 16 | |||
| 16 | } | 17 | } | ... | ... |
| 1 | package com.topdraw.business.module.coupon.service; | 1 | package com.topdraw.business.module.coupon.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.coupon.domain.Coupon; | ||
| 4 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 3 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
| 5 | import com.topdraw.business.module.coupon.service.dto.CouponQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 4 | ||
| 11 | /** | 5 | /** |
| 12 | * @author XiangHan | 6 | * @author XiangHan |
| ... | @@ -15,37 +9,18 @@ import java.util.Map; | ... | @@ -15,37 +9,18 @@ import java.util.Map; |
| 15 | public interface CouponService { | 9 | public interface CouponService { |
| 16 | 10 | ||
| 17 | /** | 11 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(CouponQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<CouponDTO> | ||
| 29 | */ | ||
| 30 | List<CouponDTO> queryAll(CouponQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 12 | * 根据ID查询 |
| 34 | * @param id ID | 13 | * @param id ID |
| 35 | * @return CouponDTO | 14 | * @return CouponDTO |
| 36 | */ | 15 | */ |
| 37 | CouponDTO findById(Long id); | 16 | CouponDTO findById(Long id); |
| 38 | 17 | ||
| 39 | void create(Coupon resources); | ||
| 40 | |||
| 41 | void update(Coupon resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | /** | 18 | /** |
| 46 | * Code校验 | 19 | * Code校验 |
| 47 | * @param code | 20 | * @param code |
| 48 | * @return CouponDTO | 21 | * @return CouponDTO |
| 49 | */ | 22 | */ |
| 50 | CouponDTO getByCode(String code); | 23 | CouponDTO getByCode(String code); |
| 24 | |||
| 25 | |||
| 51 | } | 26 | } | ... | ... |
| ... | @@ -5,6 +5,7 @@ import lombok.Data; | ... | @@ -5,6 +5,7 @@ import lombok.Data; |
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
| 7 | import java.sql.Timestamp; | 7 | import java.sql.Timestamp; |
| 8 | import java.time.LocalDateTime; | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| ... | @@ -14,69 +15,69 @@ import java.sql.Timestamp; | ... | @@ -14,69 +15,69 @@ import java.sql.Timestamp; |
| 14 | @Data | 15 | @Data |
| 15 | public class CouponDTO implements Serializable { | 16 | public class CouponDTO implements Serializable { |
| 16 | 17 | ||
| 17 | // id | 18 | /** id */ |
| 18 | private Long id; | 19 | private Long id; |
| 19 | 20 | ||
| 20 | // 标识 | 21 | /** 标识 */ |
| 21 | private String code; | 22 | private String code; |
| 22 | 23 | ||
| 23 | // 名称 | 24 | /** 名称 */ |
| 24 | private String title; | 25 | private String title; |
| 25 | 26 | ||
| 26 | // 图片 | 27 | /** 图片 */ |
| 27 | private String images; | 28 | private String images; |
| 28 | 29 | ||
| 29 | // 发行量,-1代表不限量 | 30 | /** 发行量,-1代表不限量 */ |
| 30 | private Integer stock; | 31 | private Integer stock; |
| 31 | 32 | ||
| 32 | // 剩余量,-1代表不限量 | 33 | /** 剩余量,-1代表不限量 */ |
| 33 | private Integer remainStock; | 34 | private Integer remainStock; |
| 34 | 35 | ||
| 35 | // 优惠形式:1:现金;2:折扣 | 36 | /** 优惠形式:1:现金;2:折扣 */ |
| 36 | private Integer useType; | 37 | private Integer useType; |
| 37 | 38 | ||
| 38 | // 面额 | 39 | /** 面额 */ |
| 39 | private BigDecimal denomination; | 40 | private BigDecimal denomination; |
| 40 | 41 | ||
| 41 | // 折扣 | 42 | /** 折扣 */ |
| 42 | private BigDecimal discount; | 43 | private BigDecimal discount; |
| 43 | 44 | ||
| 44 | // 适用用户范围:1:新用户;2:全体用户 | 45 | /** 适用用户范围:1:新用户;2:全体用户 */ |
| 45 | private Integer userRange; | 46 | private Integer userRange; |
| 46 | 47 | ||
| 47 | // 限领次数 -1:无限次; >0:具体次数 | 48 | /** 限领次数 -1:无限次; >0:具体次数 */ |
| 48 | private Integer collectLimit; | 49 | private Integer collectLimit; |
| 49 | 50 | ||
| 50 | // 适用门槛:1:无门槛;2:满减形式 | 51 | /** 适用门槛:1:无门槛;2:满减形式 */ |
| 51 | private Integer thresholdType; | 52 | private Integer thresholdType; |
| 52 | 53 | ||
| 53 | // 满减门槛 | 54 | /** 满减门槛 */ |
| 54 | private BigDecimal amountThreshold; | 55 | private BigDecimal amountThreshold; |
| 55 | 56 | ||
| 56 | // 产品范围:1:全部商品;2:指定商品 | 57 | /** 产品范围:1:全部商品;2:指定商品 */ |
| 57 | private Integer itemRange; | 58 | private Integer itemRange; |
| 58 | 59 | ||
| 59 | // 生效形式:1:固定日期;2:相对日期 | 60 | /** 生效形式:1:固定日期;2:相对日期 */ |
| 60 | private Integer effectType; | 61 | private Integer effectType; |
| 61 | 62 | ||
| 62 | // 生效时间 | 63 | /** 生效时间 */ |
| 63 | private Timestamp startTime; | 64 | private Timestamp startTime; |
| 64 | 65 | ||
| 65 | // 过期时间 | 66 | /** 过期时间 */ |
| 66 | private Timestamp expireTime; | 67 | private LocalDateTime expireTime; |
| 67 | 68 | ||
| 68 | // 自领取当日,几天内有效 | 69 | /** 自领取当日,几天内有效 */ |
| 69 | private Integer validDays; | 70 | private Integer validDays; |
| 70 | 71 | ||
| 71 | // 使用说明 | 72 | /** 使用说明 */ |
| 72 | private String description; | 73 | private String description; |
| 73 | 74 | ||
| 74 | // 状态0:未开始,1:启用;2:停用 | 75 | /** 状态0:未开始,1:启用;2:停用 */ |
| 75 | private Integer status; | 76 | private Integer status; |
| 76 | 77 | ||
| 77 | // 创建时间 | 78 | /** 创建时间 */ |
| 78 | private Timestamp createTime; | 79 | private Timestamp createTime; |
| 79 | 80 | ||
| 80 | // 更新时间 | 81 | /** 更新时间 */ |
| 81 | private Timestamp updateTime; | 82 | private Timestamp updateTime; |
| 82 | } | 83 | } | ... | ... |
| ... | @@ -4,23 +4,16 @@ import com.topdraw.business.module.coupon.domain.Coupon; | ... | @@ -4,23 +4,16 @@ import com.topdraw.business.module.coupon.domain.Coupon; |
| 4 | import com.topdraw.business.module.coupon.repository.CouponRepository; | 4 | import com.topdraw.business.module.coupon.repository.CouponRepository; |
| 5 | import com.topdraw.business.module.coupon.service.CouponService; | 5 | import com.topdraw.business.module.coupon.service.CouponService; |
| 6 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 6 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
| 7 | import com.topdraw.business.module.coupon.service.dto.CouponQueryCriteria; | ||
| 8 | import com.topdraw.business.module.coupon.service.mapper.CouponMapper; | 7 | import com.topdraw.business.module.coupon.service.mapper.CouponMapper; |
| 9 | import com.topdraw.utils.PageUtil; | 8 | import com.topdraw.exception.GlobeExceptionMsg; |
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 9 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 10 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 21 | 16 | ||
| 22 | import java.util.List; | ||
| 23 | import java.util.Map; | ||
| 24 | 17 | ||
| 25 | /** | 18 | /** |
| 26 | * @author XiangHan | 19 | * @author XiangHan |
| ... | @@ -30,58 +23,24 @@ import java.util.Map; | ... | @@ -30,58 +23,24 @@ import java.util.Map; |
| 30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 23 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 31 | public class CouponServiceImpl implements CouponService { | 24 | public class CouponServiceImpl implements CouponService { |
| 32 | 25 | ||
| 33 | @Autowired | ||
| 34 | private CouponRepository CouponRepository; | ||
| 35 | 26 | ||
| 36 | @Autowired | 27 | @Autowired |
| 37 | private CouponMapper CouponMapper; | 28 | private CouponMapper couponMapper; |
| 38 | 29 | @Autowired | |
| 39 | @Override | 30 | private CouponRepository couponRepository; |
| 40 | public Map<String, Object> queryAll(CouponQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<Coupon> page = CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(CouponMapper::toDto)); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public List<CouponDTO> queryAll(CouponQueryCriteria criteria) { | ||
| 47 | return CouponMapper.toDto(CouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 31 | ||
| 50 | @Override | 32 | @Override |
| 51 | public CouponDTO findById(Long id) { | 33 | public CouponDTO findById(Long id) { |
| 52 | Coupon Coupon = CouponRepository.findById(id).orElseGet(Coupon::new); | 34 | Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL); |
| 53 | ValidationUtil.isNull(Coupon.getId(),"Coupon","id",id); | ||
| 54 | return CouponMapper.toDto(Coupon); | ||
| 55 | } | ||
| 56 | 35 | ||
| 57 | @Override | 36 | Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new); |
| 58 | @Transactional(rollbackFor = Exception.class) | 37 | ValidationUtil.isNull(coupon.getId(),"Coupon","id",id); |
| 59 | public void create(Coupon resources) { | 38 | return this.couponMapper.toDto(coupon); |
| 60 | CouponRepository.save(resources); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | @Transactional(rollbackFor = Exception.class) | ||
| 65 | public void update(Coupon resources) { | ||
| 66 | Coupon Coupon = CouponRepository.findById(resources.getId()).orElseGet(Coupon::new); | ||
| 67 | ValidationUtil.isNull( Coupon.getId(),"Coupon","id",resources.getId()); | ||
| 68 | Coupon.copy(resources); | ||
| 69 | CouponRepository.save(Coupon); | ||
| 70 | } | 39 | } |
| 71 | 40 | ||
| 72 | @Override | 41 | @Override |
| 73 | @Transactional(rollbackFor = Exception.class) | ||
| 74 | public void delete(Long id) { | ||
| 75 | Assert.notNull(id, "The given id must not be null!"); | ||
| 76 | Coupon Coupon = CouponRepository.findById(id).orElseThrow( | ||
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Coupon.class, id), 1)); | ||
| 78 | CouponRepository.delete(Coupon); | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | @Override | ||
| 83 | public CouponDTO getByCode(String code) { | 42 | public CouponDTO getByCode(String code) { |
| 84 | return StringUtils.isNotEmpty(code) ? CouponMapper.toDto(CouponRepository.findFirstByCode(code).orElseGet(Coupon::new)) | 43 | return StringUtils.isNotEmpty(code) ? this.couponMapper.toDto(this.couponRepository.findFirstByCode(code).orElseGet(Coupon::new)) |
| 85 | : new CouponDTO(); | 44 | : new CouponDTO(); |
| 86 | } | 45 | } |
| 87 | } | 46 | } | ... | ... |
| ... | @@ -23,70 +23,73 @@ import java.sql.Timestamp; | ... | @@ -23,70 +23,73 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_exp_detail") | 23 | @Table(name="uc_exp_detail") |
| 24 | public class ExpDetail implements Serializable { | 24 | public class ExpDetail implements Serializable { |
| 25 | 25 | ||
| 26 | // 主键 | 26 | @Transient |
| 27 | private String memberCode; | ||
| 28 | |||
| 29 | /** 主键 */ | ||
| 27 | @Id | 30 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 32 | @Column(name = "id") |
| 30 | private Long id; | 33 | private Long id; |
| 31 | 34 | ||
| 32 | // 标识 | 35 | /** 标识 */ |
| 33 | @Column(name = "code", nullable = false) | 36 | @Column(name = "code", nullable = false) |
| 34 | private String code; | 37 | private String code; |
| 35 | 38 | ||
| 36 | // 应用code | 39 | /** 应用code */ |
| 37 | @Column(name = "app_code") | 40 | @Column(name = "app_code") |
| 38 | private String appCode; | 41 | private String appCode; |
| 39 | 42 | ||
| 40 | // 会员id | 43 | /** 会员id */ |
| 41 | @Column(name = "member_id", nullable = false) | 44 | @Column(name = "member_id", nullable = false) |
| 42 | private Long memberId; | 45 | private Long memberId; |
| 43 | 46 | ||
| 44 | // 账号id | 47 | /** 账号id */ |
| 45 | @Column(name = "account_id") | 48 | @Column(name = "account_id") |
| 46 | private Long accountId; | 49 | private Long accountId; |
| 47 | 50 | ||
| 48 | // 原始成长值 | 51 | /** 原始成长值 */ |
| 49 | @Column(name = "original_exp", nullable = false) | 52 | @Column(name = "original_exp", nullable = false) |
| 50 | private Long originalExp; | 53 | private Long originalExp; |
| 51 | 54 | ||
| 52 | // 结果成长值 | 55 | /** 结果成长值 */ |
| 53 | @Column(name = "result_exp", nullable = false) | 56 | @Column(name = "result_exp", nullable = false) |
| 54 | private Long resultExp; | 57 | private Long resultExp; |
| 55 | 58 | ||
| 56 | // 成长值变化,一般为正数 | 59 | /** 成长值变化,一般为正数 */ |
| 57 | @Column(name = "exp", nullable = false) | 60 | @Column(name = "exp", nullable = false) |
| 58 | private Long exp; | 61 | private Long exp; |
| 59 | 62 | ||
| 60 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | 63 | /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ |
| 61 | @Column(name = "device_type", nullable = false) | 64 | @Column(name = "device_type", nullable = false) |
| 62 | private Integer deviceType; | 65 | private Integer deviceType; |
| 63 | 66 | ||
| 64 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | 67 | /** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 */ |
| 65 | @Column(name = "evt_type", nullable = false) | 68 | @Column(name = "evt_type", nullable = false) |
| 66 | private Integer evtType; | 69 | private Integer evtType; |
| 67 | 70 | ||
| 68 | // 订单id(针对订购操作) | 71 | /** 订单id(针对订购操作) */ |
| 69 | @Column(name = "order_id") | 72 | @Column(name = "order_id") |
| 70 | private Long orderId; | 73 | private Long orderId; |
| 71 | 74 | ||
| 72 | // 节目id(针对观影操作) | 75 | /** 节目id(针对观影操作) */ |
| 73 | @Column(name = "media_id") | 76 | @Column(name = "media_id") |
| 74 | private Long mediaId; | 77 | private Long mediaId; |
| 75 | 78 | ||
| 76 | // 活动id(针对参与活动) | 79 | /** 活动id(针对参与活动) */ |
| 77 | @Column(name = "activity_id") | 80 | @Column(name = "activity_id") |
| 78 | private Long activityId; | 81 | private Long activityId; |
| 79 | 82 | ||
| 80 | // 成长值变化描述,用于管理侧显示 | 83 | /** 成长值变化描述,用于管理侧显示 */ |
| 81 | @Column(name = "description", nullable = false) | 84 | @Column(name = "description", nullable = false) |
| 82 | private String description; | 85 | private String description; |
| 83 | 86 | ||
| 84 | // 创建时间 | 87 | /** 创建时间 */ |
| 85 | @CreatedDate | 88 | @CreatedDate |
| 86 | @Column(name = "create_time") | 89 | @Column(name = "create_time") |
| 87 | private Timestamp createTime; | 90 | private Timestamp createTime; |
| 88 | 91 | ||
| 89 | // 更新时间 | 92 | /** 更新时间 */ |
| 90 | @LastModifiedDate | 93 | @LastModifiedDate |
| 91 | @Column(name = "update_time") | 94 | @Column(name = "update_time") |
| 92 | private Timestamp updateTime; | 95 | private Timestamp updateTime; | ... | ... |
| 1 | package com.topdraw.business.module.exp.detail.domain; | ||
| 2 | |||
| 3 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 4 | import org.apache.commons.lang3.StringUtils; | ||
| 5 | import org.springframework.util.Assert; | ||
| 6 | |||
| 7 | import java.util.Objects; | ||
| 8 | |||
| 9 | public class ExpDetailBuilder { | ||
| 10 | |||
| 11 | public static ExpDetail build(Long memberId, Long originalExp, Long resultExp, | ||
| 12 | Integer deviceType, Integer evtType){ | ||
| 13 | ExpDetail expDetail = new ExpDetail(); | ||
| 14 | expDetail.setMemberId(memberId); | ||
| 15 | expDetail.setOriginalExp(originalExp); | ||
| 16 | expDetail.setResultExp(resultExp); | ||
| 17 | expDetail.setDeviceType(deviceType); | ||
| 18 | expDetail.setEvtType(evtType); | ||
| 19 | return build(expDetail); | ||
| 20 | } | ||
| 21 | |||
| 22 | public static ExpDetail build(ExpDetail expDetail){ | ||
| 23 | return build(expDetail.getId(), | ||
| 24 | expDetail.getCode(), | ||
| 25 | expDetail.getAppCode(), | ||
| 26 | expDetail.getMemberId(), | ||
| 27 | expDetail.getAccountId(), | ||
| 28 | expDetail.getOriginalExp(),expDetail.getResultExp(), | ||
| 29 | expDetail.getExp(),expDetail.getDeviceType(), | ||
| 30 | expDetail.getEvtType(), expDetail.getOrderId(), expDetail.getMediaId(), | ||
| 31 | expDetail.getActivityId(),expDetail.getDescription()); | ||
| 32 | } | ||
| 33 | |||
| 34 | public static ExpDetail build(Long id, String code, | ||
| 35 | String appCode, Long memberId, Long accountId, | ||
| 36 | Long originalExp, Long resultExp, Long exp, | ||
| 37 | Integer deviceType, Integer evtType, Long orderId, | ||
| 38 | Long mediaId, Long activityId, String description){ | ||
| 39 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 40 | |||
| 41 | ExpDetail expDetail = new ExpDetail(); | ||
| 42 | expDetail.setId(Objects.isNull(id)?null:id); | ||
| 43 | expDetail.setCode(StringUtils.isBlank(code)?null:code); | ||
| 44 | expDetail.setAppCode(StringUtils.isBlank(appCode)?null:appCode); | ||
| 45 | expDetail.setMemberId(Objects.isNull(memberId)?null:memberId); | ||
| 46 | expDetail.setAccountId(Objects.isNull(accountId)?null:accountId); | ||
| 47 | expDetail.setOriginalExp(Objects.isNull(originalExp)?0:originalExp); | ||
| 48 | expDetail.setResultExp(Objects.isNull(resultExp)?0:resultExp); | ||
| 49 | expDetail.setExp(Objects.isNull(exp)?0:exp); | ||
| 50 | expDetail.setDeviceType(Objects.isNull(deviceType)?null:deviceType); | ||
| 51 | expDetail.setEvtType(Objects.isNull(evtType)?null:evtType); | ||
| 52 | expDetail.setOrderId(Objects.isNull(orderId)?null:orderId); | ||
| 53 | expDetail.setMediaId(Objects.isNull(mediaId)?null:mediaId); | ||
| 54 | expDetail.setActivityId(Objects.isNull(activityId)?null:activityId); | ||
| 55 | expDetail.setDescription(StringUtils.isBlank(description)?null:description); | ||
| 56 | return expDetail; | ||
| 57 | } | ||
| 58 | |||
| 59 | } |
| ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.detail.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.detail.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; | 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; |
| 4 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO; | 4 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO; |
| 5 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 5 | ||
| 11 | /** | 6 | /** |
| 12 | * @author XiangHan | 7 | * @author XiangHan |
| ... | @@ -15,31 +10,28 @@ import java.util.Map; | ... | @@ -15,31 +10,28 @@ import java.util.Map; |
| 15 | public interface ExpDetailService { | 10 | public interface ExpDetailService { |
| 16 | 11 | ||
| 17 | /** | 12 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<ExpDetailDTO> | ||
| 29 | */ | ||
| 30 | List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 13 | * 根据ID查询 |
| 34 | * @param id ID | 14 | * @param id ID |
| 35 | * @return ExpDetailDTO | 15 | * @return ExpDetailDTO |
| 36 | */ | 16 | */ |
| 37 | ExpDetailDTO findById(Long id); | 17 | ExpDetailDTO findById(Long id); |
| 38 | 18 | ||
| 19 | /** | ||
| 20 | * | ||
| 21 | * @param resources | ||
| 22 | */ | ||
| 39 | void create(ExpDetail resources); | 23 | void create(ExpDetail resources); |
| 40 | 24 | ||
| 25 | /** | ||
| 26 | * | ||
| 27 | * @param resources | ||
| 28 | */ | ||
| 41 | void update(ExpDetail resources); | 29 | void update(ExpDetail resources); |
| 42 | 30 | ||
| 31 | /** | ||
| 32 | * | ||
| 33 | * @param id | ||
| 34 | */ | ||
| 43 | void delete(Long id); | 35 | void delete(Long id); |
| 44 | 36 | ||
| 45 | /** | 37 | /** | ... | ... |
| ... | @@ -13,51 +13,51 @@ import java.sql.Timestamp; | ... | @@ -13,51 +13,51 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class ExpDetailDTO implements Serializable { | 14 | public class ExpDetailDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // 主键 | 16 | /** 主键 */ |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | // 标识 | 19 | /** 标识 */ |
| 20 | private String code; | 20 | private String code; |
| 21 | 21 | ||
| 22 | // 应用code | 22 | /** 应用code */ |
| 23 | private String appCode; | 23 | private String appCode; |
| 24 | 24 | ||
| 25 | // 会员id | 25 | /** 会员id */ |
| 26 | private Long memberId; | 26 | private Long memberId; |
| 27 | 27 | ||
| 28 | // 账号id | 28 | /** 账号id */ |
| 29 | private Long accountId; | 29 | private Long accountId; |
| 30 | 30 | ||
| 31 | // 原始成长值 | 31 | /** 原始成长值 */ |
| 32 | private Long originalExp; | 32 | private Long originalExp; |
| 33 | 33 | ||
| 34 | // 结果成长值 | 34 | /** 结果成长值 */ |
| 35 | private Long resultExp; | 35 | private Long resultExp; |
| 36 | 36 | ||
| 37 | // 成长值变化,一般为正数 | 37 | /** 成长值变化,一般为正数 */ |
| 38 | private Long exp; | 38 | private Long exp; |
| 39 | 39 | ||
| 40 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | 40 | /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ |
| 41 | private Integer deviceType; | 41 | private Integer deviceType; |
| 42 | 42 | ||
| 43 | // 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 | 43 | /** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;98:系统操作;99:其他 */ |
| 44 | private Integer evtType; | 44 | private Integer evtType; |
| 45 | 45 | ||
| 46 | // 订单id(针对订购操作) | 46 | /** 订单id(针对订购操作) */ |
| 47 | private Long orderId; | 47 | private Long orderId; |
| 48 | 48 | ||
| 49 | // 节目id(针对观影操作) | 49 | /** 节目id(针对观影操作) */ |
| 50 | private Long mediaId; | 50 | private Long mediaId; |
| 51 | 51 | ||
| 52 | // 活动id(针对参与活动) | 52 | /** 活动id(针对参与活动) */ |
| 53 | private Long activityId; | 53 | private Long activityId; |
| 54 | 54 | ||
| 55 | // 成长值变化描述,用于管理侧显示 | 55 | /** 成长值变化描述,用于管理侧显示 */ |
| 56 | private String description; | 56 | private String description; |
| 57 | 57 | ||
| 58 | // 创建时间 | 58 | /** 创建时间 */ |
| 59 | private Timestamp createTime; | 59 | private Timestamp createTime; |
| 60 | 60 | ||
| 61 | // 更新时间 | 61 | /** 更新时间 */ |
| 62 | private Timestamp updateTime; | 62 | private Timestamp updateTime; |
| 63 | } | 63 | } | ... | ... |
| 1 | package com.topdraw.business.module.exp.detail.service.impl; | 1 | package com.topdraw.business.module.exp.detail.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; | 3 | import com.topdraw.business.module.exp.detail.domain.ExpDetail; |
| 4 | import com.topdraw.business.module.exp.detail.domain.ExpDetailBuilder; | ||
| 4 | import com.topdraw.business.module.exp.detail.repository.ExpDetailRepository; | 5 | import com.topdraw.business.module.exp.detail.repository.ExpDetailRepository; |
| 5 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; | 6 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; |
| 6 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO; | 7 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailDTO; |
| 7 | import com.topdraw.business.module.exp.detail.service.dto.ExpDetailQueryCriteria; | ||
| 8 | import com.topdraw.business.module.exp.detail.service.mapper.ExpDetailMapper; | 8 | import com.topdraw.business.module.exp.detail.service.mapper.ExpDetailMapper; |
| 9 | import com.topdraw.utils.PageUtil; | 9 | import com.topdraw.utils.RedisUtils; |
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 10 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 11 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | 13 | import org.springframework.dao.EmptyResultDataAccessException; |
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 15 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | 17 | import org.springframework.util.Assert; |
| 21 | 18 | ||
| 22 | import java.util.List; | ||
| 23 | import java.util.Map; | ||
| 24 | 19 | ||
| 25 | /** | 20 | /** |
| 26 | * @author XiangHan | 21 | * @author XiangHan |
| ... | @@ -31,57 +26,56 @@ import java.util.Map; | ... | @@ -31,57 +26,56 @@ import java.util.Map; |
| 31 | public class ExpDetailServiceImpl implements ExpDetailService { | 26 | public class ExpDetailServiceImpl implements ExpDetailService { |
| 32 | 27 | ||
| 33 | @Autowired | 28 | @Autowired |
| 34 | private ExpDetailRepository ExpDetailRepository; | 29 | private ExpDetailRepository expDetailRepository; |
| 35 | |||
| 36 | @Autowired | 30 | @Autowired |
| 37 | private ExpDetailMapper ExpDetailMapper; | 31 | private ExpDetailMapper expDetailMapper; |
| 38 | |||
| 39 | @Override | ||
| 40 | public Map<String, Object> queryAll(ExpDetailQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<ExpDetail> page = ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(ExpDetailMapper::toDto)); | ||
| 43 | } | ||
| 44 | 32 | ||
| 45 | @Override | 33 | @Autowired |
| 46 | public List<ExpDetailDTO> queryAll(ExpDetailQueryCriteria criteria) { | 34 | private RedisUtils redisUtils; |
| 47 | return ExpDetailMapper.toDto(ExpDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 35 | ||
| 50 | @Override | 36 | @Override |
| 51 | public ExpDetailDTO findById(Long id) { | 37 | public ExpDetailDTO findById(Long id) { |
| 52 | ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseGet(ExpDetail::new); | 38 | ExpDetail ExpDetail = this.expDetailRepository.findById(id).orElseGet(com.topdraw.business.module.exp.detail.domain.ExpDetail::new); |
| 53 | ValidationUtil.isNull(ExpDetail.getId(),"ExpDetail","id",id); | 39 | ValidationUtil.isNull(ExpDetail.getId(),"ExpDetail","id",id); |
| 54 | return ExpDetailMapper.toDto(ExpDetail); | 40 | return this.expDetailMapper.toDto(ExpDetail); |
| 55 | } | 41 | } |
| 56 | 42 | ||
| 57 | @Override | 43 | @Override |
| 58 | @Transactional(rollbackFor = Exception.class) | 44 | @Transactional(rollbackFor = Exception.class) |
| 59 | public void create(ExpDetail resources) { | 45 | public void create(ExpDetail resources) { |
| 60 | ExpDetailRepository.save(resources); | 46 | ExpDetail expDetail = ExpDetailBuilder.build(resources); |
| 47 | this.expDetailRepository.save(expDetail); | ||
| 61 | } | 48 | } |
| 62 | 49 | ||
| 63 | @Override | 50 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 51 | @Transactional(rollbackFor = Exception.class) |
| 65 | public void update(ExpDetail resources) { | 52 | public void update(ExpDetail resources) { |
| 66 | ExpDetail ExpDetail = ExpDetailRepository.findById(resources.getId()).orElseGet(ExpDetail::new); | 53 | this.redisUtils.doLock("expDetail::memberId::" + resources.getMemberId()); |
| 67 | ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId()); | 54 | try { |
| 68 | ExpDetail.copy(resources); | 55 | ExpDetail ExpDetail = this.expDetailRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.exp.detail.domain.ExpDetail::new); |
| 69 | ExpDetailRepository.save(ExpDetail); | 56 | ValidationUtil.isNull( ExpDetail.getId(),"ExpDetail","id",resources.getId()); |
| 57 | ExpDetail.copy(resources); | ||
| 58 | this.expDetailRepository.save(ExpDetail); | ||
| 59 | } catch (Exception e) { | ||
| 60 | e.printStackTrace(); | ||
| 61 | throw e; | ||
| 62 | } finally { | ||
| 63 | this.redisUtils.doUnLock("expDetail::memberId::" + resources.getMemberId()); | ||
| 64 | } | ||
| 70 | } | 65 | } |
| 71 | 66 | ||
| 72 | @Override | 67 | @Override |
| 73 | @Transactional(rollbackFor = Exception.class) | 68 | @Transactional(rollbackFor = Exception.class) |
| 74 | public void delete(Long id) { | 69 | public void delete(Long id) { |
| 75 | Assert.notNull(id, "The given id must not be null!"); | 70 | Assert.notNull(id, "The given id must not be null!"); |
| 76 | ExpDetail ExpDetail = ExpDetailRepository.findById(id).orElseThrow( | 71 | ExpDetail ExpDetail = this.expDetailRepository.findById(id).orElseThrow( |
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpDetail.class, id), 1)); | 72 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.exp.detail.domain.ExpDetail.class, id), 1)); |
| 78 | ExpDetailRepository.delete(ExpDetail); | 73 | this.expDetailRepository.delete(ExpDetail); |
| 79 | } | 74 | } |
| 80 | 75 | ||
| 81 | |||
| 82 | @Override | 76 | @Override |
| 83 | public ExpDetailDTO getByCode(String code) { | 77 | public ExpDetailDTO getByCode(String code) { |
| 84 | return StringUtils.isNotEmpty(code) ? ExpDetailMapper.toDto(ExpDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new)) | 78 | return StringUtils.isNotEmpty(code) ? this.expDetailMapper.toDto(this.expDetailRepository.findFirstByCode(code).orElseGet(ExpDetail::new)) |
| 85 | : new ExpDetailDTO(); | 79 | : new ExpDetailDTO(); |
| 86 | } | 80 | } |
| 87 | } | 81 | } | ... | ... |
| 1 | package com.topdraw.business.module.exp.history.domain; | ||
| 2 | |||
| 3 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 4 | import com.topdraw.util.IdWorker; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.util.Assert; | ||
| 7 | |||
| 8 | import java.util.Objects; | ||
| 9 | |||
| 10 | public class ExpHistoryBuilder { | ||
| 11 | |||
| 12 | public ExpHistory build(Long memberId, Long originalExp, Long resultExp, Long exp,Integer deviceType , Integer evtType) { | ||
| 13 | ExpHistory expHistory = new ExpHistory(); | ||
| 14 | expHistory.setMemberId(memberId); | ||
| 15 | expHistory.setOriginalExp(originalExp); | ||
| 16 | expHistory.setResultExp(resultExp); | ||
| 17 | expHistory.setDeviceType(deviceType); | ||
| 18 | expHistory.setEvtType(evtType); | ||
| 19 | expHistory.setExp(exp); | ||
| 20 | return build(expHistory); | ||
| 21 | } | ||
| 22 | |||
| 23 | public ExpHistory build(ExpHistory expHistory) { | ||
| 24 | return build(expHistory.getId(),expHistory.getCode(), | ||
| 25 | expHistory.getMemberId(),expHistory.getAccountId(), | ||
| 26 | expHistory.getOriginalExp(),expHistory.getResultExp(),expHistory.getExp(), | ||
| 27 | expHistory.getDeviceType(),expHistory.getEvtType(),expHistory.getOrderId(), | ||
| 28 | expHistory.getMediaId(),expHistory.getActivityId(),expHistory.getDescription()); | ||
| 29 | } | ||
| 30 | |||
| 31 | public ExpHistory build(Long id,String code,Long memberId,Long accountId, | ||
| 32 | Long originalExp,Long resultExp,Long exp, | ||
| 33 | Integer deviceType,Integer evtType,Long orderId, | ||
| 34 | Long mediaId,Long activityId,String description) { | ||
| 35 | |||
| 36 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 37 | |||
| 38 | ExpHistory expHistory = new ExpHistory(); | ||
| 39 | expHistory.setId(Objects.isNull(id)?null:id); | ||
| 40 | expHistory.setCode(StringUtils.isBlank(code)? IdWorker.generatorCode("exp") :code); | ||
| 41 | expHistory.setMemberId(memberId); | ||
| 42 | expHistory.setAccountId(Objects.isNull(accountId)?null:accountId); | ||
| 43 | expHistory.setOriginalExp(Objects.isNull(originalExp)?0L:originalExp); | ||
| 44 | expHistory.setResultExp(Objects.isNull(resultExp)?0L:resultExp); | ||
| 45 | expHistory.setExp(Objects.isNull(exp)?0L:exp); | ||
| 46 | expHistory.setDeviceType(Objects.isNull(deviceType)?4:deviceType); | ||
| 47 | expHistory.setEvtType(Objects.isNull(evtType)?98:evtType); | ||
| 48 | expHistory.setOrderId(Objects.isNull(orderId)?null:orderId); | ||
| 49 | expHistory.setMediaId(Objects.isNull(mediaId)?null:mediaId); | ||
| 50 | expHistory.setActivityId(Objects.isNull(activityId)?null:activityId); | ||
| 51 | expHistory.setDescription(StringUtils.isBlank(description)?null:description); | ||
| 52 | return expHistory; | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | } |
| ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.history.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.exp.history.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.exp.history.domain.ExpHistory; | 3 | import com.topdraw.business.module.exp.history.domain.ExpHistory; |
| 4 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO; | 4 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO; |
| 5 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 5 | ||
| 11 | /** | 6 | /** |
| 12 | * @author XiangHan | 7 | * @author XiangHan |
| ... | @@ -15,33 +10,18 @@ import java.util.Map; | ... | @@ -15,33 +10,18 @@ import java.util.Map; |
| 15 | public interface ExpHistoryService { | 10 | public interface ExpHistoryService { |
| 16 | 11 | ||
| 17 | /** | 12 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<ExpHistoryDTO> | ||
| 29 | */ | ||
| 30 | List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 13 | * 根据ID查询 |
| 34 | * @param id ID | 14 | * @param id ID |
| 35 | * @return ExpHistoryDTO | 15 | * @return ExpHistoryDTO |
| 36 | */ | 16 | */ |
| 37 | ExpHistoryDTO findById(Long id); | 17 | ExpHistoryDTO findById(Long id); |
| 38 | 18 | ||
| 19 | /** | ||
| 20 | * | ||
| 21 | * @param resources | ||
| 22 | */ | ||
| 39 | void create(ExpHistory resources); | 23 | void create(ExpHistory resources); |
| 40 | 24 | ||
| 41 | void update(ExpHistory resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | /** | 25 | /** |
| 46 | * Code校验 | 26 | * Code校验 |
| 47 | * @param code | 27 | * @param code | ... | ... |
| ... | @@ -4,23 +4,14 @@ import com.topdraw.business.module.exp.history.domain.ExpHistory; | ... | @@ -4,23 +4,14 @@ import com.topdraw.business.module.exp.history.domain.ExpHistory; |
| 4 | import com.topdraw.business.module.exp.history.repository.ExpHistoryRepository; | 4 | import com.topdraw.business.module.exp.history.repository.ExpHistoryRepository; |
| 5 | import com.topdraw.business.module.exp.history.service.ExpHistoryService; | 5 | import com.topdraw.business.module.exp.history.service.ExpHistoryService; |
| 6 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO; | 6 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryDTO; |
| 7 | import com.topdraw.business.module.exp.history.service.dto.ExpHistoryQueryCriteria; | ||
| 8 | import com.topdraw.business.module.exp.history.service.mapper.ExpHistoryMapper; | 7 | import com.topdraw.business.module.exp.history.service.mapper.ExpHistoryMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | ||
| 21 | 14 | ||
| 22 | import java.util.List; | ||
| 23 | import java.util.Map; | ||
| 24 | 15 | ||
| 25 | /** | 16 | /** |
| 26 | * @author XiangHan | 17 | * @author XiangHan |
| ... | @@ -31,57 +22,28 @@ import java.util.Map; | ... | @@ -31,57 +22,28 @@ import java.util.Map; |
| 31 | public class ExpHistoryServiceImpl implements ExpHistoryService { | 22 | public class ExpHistoryServiceImpl implements ExpHistoryService { |
| 32 | 23 | ||
| 33 | @Autowired | 24 | @Autowired |
| 34 | private ExpHistoryRepository ExpHistoryRepository; | 25 | private ExpHistoryMapper expHistoryMapper; |
| 35 | |||
| 36 | @Autowired | 26 | @Autowired |
| 37 | private ExpHistoryMapper ExpHistoryMapper; | 27 | private ExpHistoryRepository expHistoryRepository; |
| 38 | 28 | ||
| 39 | @Override | ||
| 40 | public Map<String, Object> queryAll(ExpHistoryQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<ExpHistory> page = ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(ExpHistoryMapper::toDto)); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public List<ExpHistoryDTO> queryAll(ExpHistoryQueryCriteria criteria) { | ||
| 47 | return ExpHistoryMapper.toDto(ExpHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 29 | ||
| 50 | @Override | 30 | @Override |
| 51 | public ExpHistoryDTO findById(Long id) { | 31 | public ExpHistoryDTO findById(Long id) { |
| 52 | ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseGet(ExpHistory::new); | 32 | ExpHistory ExpHistory = this.expHistoryRepository.findById(id).orElseGet(ExpHistory::new); |
| 53 | ValidationUtil.isNull(ExpHistory.getId(),"ExpHistory","id",id); | 33 | ValidationUtil.isNull(ExpHistory.getId(),"ExpHistory","id",id); |
| 54 | return ExpHistoryMapper.toDto(ExpHistory); | 34 | return this.expHistoryMapper.toDto(ExpHistory); |
| 55 | } | 35 | } |
| 56 | 36 | ||
| 57 | @Override | 37 | @Override |
| 58 | @Transactional(rollbackFor = Exception.class) | 38 | @Transactional(rollbackFor = Exception.class) |
| 59 | public void create(ExpHistory resources) { | 39 | public void create(ExpHistory resources) { |
| 60 | ExpHistoryRepository.save(resources); | 40 | this.expHistoryRepository.save(resources); |
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | @Transactional(rollbackFor = Exception.class) | ||
| 65 | public void update(ExpHistory resources) { | ||
| 66 | ExpHistory ExpHistory = ExpHistoryRepository.findById(resources.getId()).orElseGet(ExpHistory::new); | ||
| 67 | ValidationUtil.isNull( ExpHistory.getId(),"ExpHistory","id",resources.getId()); | ||
| 68 | ExpHistory.copy(resources); | ||
| 69 | ExpHistoryRepository.save(ExpHistory); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Override | ||
| 73 | @Transactional(rollbackFor = Exception.class) | ||
| 74 | public void delete(Long id) { | ||
| 75 | Assert.notNull(id, "The given id must not be null!"); | ||
| 76 | ExpHistory ExpHistory = ExpHistoryRepository.findById(id).orElseThrow( | ||
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", ExpHistory.class, id), 1)); | ||
| 78 | ExpHistoryRepository.delete(ExpHistory); | ||
| 79 | } | 41 | } |
| 80 | 42 | ||
| 81 | 43 | ||
| 82 | @Override | 44 | @Override |
| 83 | public ExpHistoryDTO getByCode(String code) { | 45 | public ExpHistoryDTO getByCode(String code) { |
| 84 | return StringUtils.isNotEmpty(code) ? ExpHistoryMapper.toDto(ExpHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new)) | 46 | return StringUtils.isNotEmpty(code) ? this.expHistoryMapper.toDto(this.expHistoryRepository.findFirstByCode(code).orElseGet(ExpHistory::new)) |
| 85 | : new ExpHistoryDTO(); | 47 | : new ExpHistoryDTO(); |
| 86 | } | 48 | } |
| 87 | } | 49 | } | ... | ... |
| ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.address.domain; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.address.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -10,7 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ... | @@ -10,7 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 11 | ||
| 11 | import javax.persistence.*; | 12 | import javax.persistence.*; |
| 12 | import java.io.Serializable; | 13 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 14 | import java.time.LocalDateTime; |
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * @author XiangHan | 17 | * @author XiangHan |
| ... | @@ -21,78 +22,75 @@ import java.sql.Timestamp; | ... | @@ -21,78 +22,75 @@ import java.sql.Timestamp; |
| 21 | @EntityListeners(AuditingEntityListener.class) | 22 | @EntityListeners(AuditingEntityListener.class) |
| 22 | @Accessors(chain = true) | 23 | @Accessors(chain = true) |
| 23 | @Table(name="uc_member_address") | 24 | @Table(name="uc_member_address") |
| 24 | public class MemberAddress implements Serializable { | 25 | public class MemberAddress extends AsyncMqModule implements Serializable { |
| 25 | 26 | ||
| 26 | // 主键 | 27 | /** 主键 */ |
| 27 | @Id | 28 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 30 | @Column(name = "id") |
| 30 | private Long id; | 31 | private Long id; |
| 31 | 32 | ||
| 32 | // 会员id | 33 | /** 会员id */ |
| 33 | @Column(name = "member_id", nullable = false) | 34 | @Column(name = "member_id", nullable = false) |
| 34 | private Long memberId; | 35 | private Long memberId; |
| 35 | 36 | ||
| 36 | @Transient | 37 | /** 类型 1:家;2:公司;3:学校 */ |
| 37 | private String memberCode; | ||
| 38 | |||
| 39 | // 类型 1:家;2:公司;3:学校 | ||
| 40 | @Column(name = "type", nullable = false) | 38 | @Column(name = "type", nullable = false) |
| 41 | private Integer type; | 39 | private Integer type; |
| 42 | 40 | ||
| 43 | // 是否默认地址 | 41 | /** 是否默认地址 */ |
| 44 | @Column(name = "is_default", nullable = false) | 42 | @Column(name = "is_default", nullable = false) |
| 45 | private Integer isDefault; | 43 | private Integer isDefault; |
| 46 | 44 | ||
| 47 | // 显示顺序 | 45 | /** 显示顺序 */ |
| 48 | @Column(name = "sequence") | 46 | @Column(name = "sequence") |
| 49 | private Integer sequence; | 47 | private Integer sequence; |
| 50 | 48 | ||
| 51 | // 状态 0:不可用;1-可用 | 49 | /** 状态 0:不可用;1-可用 */ |
| 52 | @Column(name = "status", nullable = false) | 50 | @Column(name = "status", nullable = false) |
| 53 | private Integer status; | 51 | private Integer status; |
| 54 | 52 | ||
| 55 | // 联系人姓名 | 53 | /** 联系人姓名 */ |
| 56 | @Column(name = "contactor", nullable = false) | 54 | @Column(name = "contactor", nullable = false) |
| 57 | private String contactor; | 55 | private String contactor; |
| 58 | 56 | ||
| 59 | // 联系人电话 | 57 | /** 联系人电话 */ |
| 60 | @Column(name = "cellphone", nullable = false) | 58 | @Column(name = "cellphone", nullable = false) |
| 61 | private String cellphone; | 59 | private String cellphone; |
| 62 | 60 | ||
| 63 | // 国家 | 61 | /** 国家 */ |
| 64 | @Column(name = "country", nullable = false) | 62 | @Column(name = "country", nullable = false) |
| 65 | private String country; | 63 | private String country; |
| 66 | 64 | ||
| 67 | // 省份 | 65 | /** 省份 */ |
| 68 | @Column(name = "province", nullable = false) | 66 | @Column(name = "province", nullable = false) |
| 69 | private String province; | 67 | private String province; |
| 70 | 68 | ||
| 71 | // 城市 | 69 | /** 城市 */ |
| 72 | @Column(name = "city", nullable = false) | 70 | @Column(name = "city", nullable = false) |
| 73 | private String city; | 71 | private String city; |
| 74 | 72 | ||
| 75 | // 区县 | 73 | /** 区县 */ |
| 76 | @Column(name = "district", nullable = false) | 74 | @Column(name = "district", nullable = false) |
| 77 | private String district; | 75 | private String district; |
| 78 | 76 | ||
| 79 | // 地址 | 77 | /** 地址 */ |
| 80 | @Column(name = "address", nullable = false) | 78 | @Column(name = "address", nullable = false) |
| 81 | private String address; | 79 | private String address; |
| 82 | 80 | ||
| 83 | // 邮编 | 81 | /** 邮编 */ |
| 84 | @Column(name = "zip_code") | 82 | @Column(name = "zip_code") |
| 85 | private String zipCode; | 83 | private String zipCode; |
| 86 | 84 | ||
| 87 | // 创建时间 | 85 | /** 创建时间 */ |
| 88 | @CreatedDate | 86 | @CreatedDate |
| 89 | @Column(name = "create_time") | 87 | @Column(name = "create_time") |
| 90 | private Timestamp createTime; | 88 | private LocalDateTime createTime; |
| 91 | 89 | ||
| 92 | // 更新时间 | 90 | /** 更新时间 */ |
| 93 | @LastModifiedDate | 91 | @LastModifiedDate |
| 94 | @Column(name = "update_time") | 92 | @Column(name = "update_time") |
| 95 | private Timestamp updateTime; | 93 | private LocalDateTime updateTime; |
| 96 | 94 | ||
| 97 | public void copy(MemberAddress source){ | 95 | public void copy(MemberAddress source){ |
| 98 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 96 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ... | ... |
src/main/java/com/topdraw/business/module/member/address/domain/MemberAddressBuilder.java
0 → 100644
| 1 | package com.topdraw.business.module.member.address.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.util.Assert; | ||
| 7 | |||
| 8 | import java.util.Objects; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author : | ||
| 12 | * @description: | ||
| 13 | * @function : | ||
| 14 | * @date :Created in 2022/3/11 11:08 | ||
| 15 | * @version: : | ||
| 16 | * @modified By: | ||
| 17 | * @since : modified in 2022/3/11 11:08 | ||
| 18 | */ | ||
| 19 | public class MemberAddressBuilder { | ||
| 20 | |||
| 21 | private static final Integer DEFAULT_VALUE_0 = 0; | ||
| 22 | private static final Integer DEFAULT_VALUE_1 = 1; | ||
| 23 | |||
| 24 | public static MemberAddress build(MemberAddress memberAddress, Long memberId, String memberCode){ | ||
| 25 | Long id = memberAddress.getId(); | ||
| 26 | Integer type = memberAddress.getType(); | ||
| 27 | Integer isDefault = memberAddress.getIsDefault(); | ||
| 28 | Integer sequence = memberAddress.getSequence(); | ||
| 29 | Integer status= memberAddress.getStatus(); | ||
| 30 | String contactor = memberAddress.getContactor(); | ||
| 31 | String cellphone = memberAddress.getCellphone(); | ||
| 32 | String country = memberAddress.getCountry(); | ||
| 33 | String province = memberAddress.getProvince(); | ||
| 34 | String city = memberAddress.getCity(); | ||
| 35 | String district = memberAddress.getDistrict(); | ||
| 36 | String address = memberAddress.getAddress(); | ||
| 37 | String zipCode = memberAddress.getZipCode(); | ||
| 38 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
| 39 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
| 40 | } | ||
| 41 | |||
| 42 | public static MemberAddress build(MemberAddress memberAddress, Member member){ | ||
| 43 | Long id = memberAddress.getId(); | ||
| 44 | Long memberId = member.getId(); | ||
| 45 | String memberCode = member.getCode(); | ||
| 46 | Integer type = memberAddress.getType(); | ||
| 47 | Integer isDefault = memberAddress.getIsDefault(); | ||
| 48 | Integer sequence = memberAddress.getSequence(); | ||
| 49 | Integer status= memberAddress.getStatus(); | ||
| 50 | String contactor = memberAddress.getContactor(); | ||
| 51 | String cellphone = memberAddress.getCellphone(); | ||
| 52 | String country = memberAddress.getCountry(); | ||
| 53 | String province = memberAddress.getProvince(); | ||
| 54 | String city = memberAddress.getCity(); | ||
| 55 | String district = memberAddress.getDistrict(); | ||
| 56 | String address = memberAddress.getAddress(); | ||
| 57 | String zipCode = memberAddress.getZipCode(); | ||
| 58 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
| 59 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
| 60 | } | ||
| 61 | |||
| 62 | public static MemberAddress build(MemberAddress memberAddress){ | ||
| 63 | Long id = memberAddress.getId(); | ||
| 64 | Long memberId = memberAddress.getMemberId(); | ||
| 65 | String memberCode = memberAddress.getMemberCode(); | ||
| 66 | Integer type = memberAddress.getType(); | ||
| 67 | Integer isDefault = memberAddress.getIsDefault(); | ||
| 68 | Integer sequence = memberAddress.getSequence(); | ||
| 69 | Integer status= memberAddress.getStatus(); | ||
| 70 | String contactor = memberAddress.getContactor(); | ||
| 71 | String cellphone = memberAddress.getCellphone(); | ||
| 72 | String country = memberAddress.getCountry(); | ||
| 73 | String province = memberAddress.getProvince(); | ||
| 74 | String city = memberAddress.getCity(); | ||
| 75 | String district = memberAddress.getDistrict(); | ||
| 76 | String address = memberAddress.getAddress(); | ||
| 77 | String zipCode = memberAddress.getZipCode(); | ||
| 78 | return build(id,memberId,memberCode,type,isDefault,sequence,status, | ||
| 79 | contactor,cellphone,country,province,city,district,address,zipCode); | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | public static MemberAddress build(Long id , Long memberId, String memberCode, | ||
| 84 | Integer sequence, Integer type , Integer isDefault , Integer status, | ||
| 85 | String contactor, String cellphone, | ||
| 86 | String country, String province, String city, | ||
| 87 | String district, String address, String zipCode){ | ||
| 88 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 89 | |||
| 90 | MemberAddress memberAddress = new MemberAddress(); | ||
| 91 | memberAddress.setId(Objects.nonNull(id)?null:id); | ||
| 92 | memberAddress.setMemberId(Objects.isNull(memberId)?null:memberId); | ||
| 93 | memberAddress.setMemberCode(stringIsNull(memberCode)); | ||
| 94 | |||
| 95 | memberAddress.setSequence(Objects.nonNull(sequence)?null:DEFAULT_VALUE_1); | ||
| 96 | memberAddress.setType(Objects.isNull(type)?null:DEFAULT_VALUE_0); | ||
| 97 | memberAddress.setIsDefault(Objects.nonNull(isDefault)?null:DEFAULT_VALUE_0); | ||
| 98 | memberAddress.setStatus(Objects.isNull(status)?null:DEFAULT_VALUE_1); | ||
| 99 | |||
| 100 | memberAddress.setContactor(stringIsNull(contactor)); | ||
| 101 | memberAddress.setCellphone(stringIsNull(cellphone)); | ||
| 102 | |||
| 103 | memberAddress.setCountry(stringIsNull(country)); | ||
| 104 | memberAddress.setProvince(stringIsNull(province)); | ||
| 105 | memberAddress.setCity(stringIsNull(city)); | ||
| 106 | memberAddress.setDistrict(stringIsNull(district)); | ||
| 107 | memberAddress.setAddress(stringIsNull(address)); | ||
| 108 | memberAddress.setZipCode(stringIsNull(zipCode)); | ||
| 109 | |||
| 110 | return memberAddress; | ||
| 111 | |||
| 112 | } | ||
| 113 | |||
| 114 | private static String stringIsNull(String s){ | ||
| 115 | return StringUtils.isBlank(s)?"":s; | ||
| 116 | } | ||
| 117 | |||
| 118 | } |
| ... | @@ -4,13 +4,12 @@ import com.topdraw.business.module.member.address.domain.MemberAddress; | ... | @@ -4,13 +4,12 @@ import com.topdraw.business.module.member.address.domain.MemberAddress; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | 6 | ||
| 7 | import java.util.Optional; | ||
| 8 | |||
| 9 | /** | 7 | /** |
| 10 | * @author XiangHan | 8 | * @author XiangHan |
| 11 | * @date 2021-10-22 | 9 | * @date 2021-10-22 |
| 12 | */ | 10 | */ |
| 13 | public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> { | 11 | public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> { |
| 14 | 12 | ||
| 15 | Optional<MemberAddress> findByMemberIdAndSequence(Long memberId, Integer sequence); | 13 | |
| 14 | MemberAddress findByMemberIdAndSequence(Long memberId, Integer sequence); | ||
| 16 | } | 15 | } | ... | ... |
| ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.member.address.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.member.address.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
| 4 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; | 4 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; |
| 5 | import com.topdraw.business.module.member.address.service.dto.MemberAddressQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 5 | ||
| 11 | /** | 6 | /** |
| 12 | * @author XiangHan | 7 | * @author XiangHan |
| ... | @@ -15,31 +10,35 @@ import java.util.Map; | ... | @@ -15,31 +10,35 @@ import java.util.Map; |
| 15 | public interface MemberAddressService { | 10 | public interface MemberAddressService { |
| 16 | 11 | ||
| 17 | /** | 12 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<MemberAddressDTO> | ||
| 29 | */ | ||
| 30 | List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 13 | * 根据ID查询 |
| 34 | * @param id ID | 14 | * @param resources ID |
| 35 | * @return MemberAddressDTO | 15 | * @return MemberAddressDTO |
| 36 | */ | 16 | */ |
| 37 | MemberAddressDTO findById(Long id); | 17 | MemberAddressDTO findById(Long resources); |
| 38 | 18 | ||
| 39 | void create(MemberAddress resources); | 19 | /** |
| 20 | * 保存会员地址 | ||
| 21 | * @param resources | ||
| 22 | */ | ||
| 23 | MemberAddressDTO create(MemberAddress resources); | ||
| 40 | 24 | ||
| 41 | void update(MemberAddress resources); | 25 | /** |
| 26 | * 修改会员地址 | ||
| 27 | * @param resources | ||
| 28 | */ | ||
| 29 | MemberAddressDTO update(MemberAddress resources); | ||
| 42 | 30 | ||
| 43 | void delete(Long id); | 31 | /** |
| 32 | * 通过id删除 | ||
| 33 | * @param resources | ||
| 34 | */ | ||
| 35 | void delete(Long resources); | ||
| 44 | 36 | ||
| 37 | /** | ||
| 38 | * | ||
| 39 | * @param memberId | ||
| 40 | * @param sequence | ||
| 41 | * @return | ||
| 42 | */ | ||
| 43 | MemberAddressDTO findByMemberIdAndSequence(Long memberId, Integer sequence); | ||
| 45 | } | 44 | } | ... | ... |
| ... | @@ -3,7 +3,7 @@ package com.topdraw.business.module.member.address.service.dto; | ... | @@ -3,7 +3,7 @@ package com.topdraw.business.module.member.address.service.dto; |
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 6 | import java.time.LocalDateTime; |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| ... | @@ -13,51 +13,54 @@ import java.sql.Timestamp; | ... | @@ -13,51 +13,54 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class MemberAddressDTO implements Serializable { | 14 | public class MemberAddressDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // 主键 | 16 | /** 会员code */ |
| 17 | private String memberCode; | ||
| 18 | |||
| 19 | /** 主键 */ | ||
| 17 | private Long id; | 20 | private Long id; |
| 18 | 21 | ||
| 19 | // 会员id | 22 | /** 会员id */ |
| 20 | private Long memberId; | 23 | private Long memberId; |
| 21 | 24 | ||
| 22 | // 类型 1:家;2:公司;3:学校 | 25 | /** 类型 1:家;2:公司;3:学校 */ |
| 23 | private Integer type; | 26 | private Integer type; |
| 24 | 27 | ||
| 25 | // 是否默认地址 | 28 | /** 是否默认地址 */ |
| 26 | private Integer isDefault; | 29 | private Integer isDefault; |
| 27 | 30 | ||
| 28 | // 显示顺序 | 31 | /** 显示顺序 */ |
| 29 | private Integer sequence; | 32 | private Integer sequence; |
| 30 | 33 | ||
| 31 | // 状态 0:不可用;1-可用 | 34 | /** 状态 0:不可用;1-可用 */ |
| 32 | private Integer status; | 35 | private Integer status; |
| 33 | 36 | ||
| 34 | // 联系人姓名 | 37 | /** 联系人姓名 */ |
| 35 | private String contactor; | 38 | private String contactor; |
| 36 | 39 | ||
| 37 | // 联系人电话 | 40 | /** 联系人电话 */ |
| 38 | private String cellphone; | 41 | private String cellphone; |
| 39 | 42 | ||
| 40 | // 国家 | 43 | /** 国家 */ |
| 41 | private String country; | 44 | private String country; |
| 42 | 45 | ||
| 43 | // 省份 | 46 | /** 省份 */ |
| 44 | private String province; | 47 | private String province; |
| 45 | 48 | ||
| 46 | // 城市 | 49 | /** 城市 */ |
| 47 | private String city; | 50 | private String city; |
| 48 | 51 | ||
| 49 | // 区县 | 52 | /** 区县 */ |
| 50 | private String district; | 53 | private String district; |
| 51 | 54 | ||
| 52 | // 地址 | 55 | /** 地址 */ |
| 53 | private String address; | 56 | private String address; |
| 54 | 57 | ||
| 55 | // 邮编 | 58 | /** 邮编 */ |
| 56 | private String zipCode; | 59 | private String zipCode; |
| 57 | 60 | ||
| 58 | // 创建时间 | 61 | /** 创建时间 */ |
| 59 | private Timestamp createTime; | 62 | private LocalDateTime createTime; |
| 60 | 63 | ||
| 61 | // 更新时间 | 64 | /** 更新时间 */ |
| 62 | private Timestamp updateTime; | 65 | private LocalDateTime updateTime; |
| 63 | } | 66 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.address.service.impl; | 1 | package com.topdraw.business.module.member.address.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; | 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; |
| 4 | import com.topdraw.business.module.member.address.domain.MemberAddressBuilder; | ||
| 4 | import com.topdraw.business.module.member.address.repository.MemberAddressRepository; | 5 | import com.topdraw.business.module.member.address.repository.MemberAddressRepository; |
| 5 | import com.topdraw.business.module.member.address.service.MemberAddressService; | 6 | import com.topdraw.business.module.member.address.service.MemberAddressService; |
| 6 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; | 7 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; |
| 7 | import com.topdraw.business.module.member.address.service.dto.MemberAddressQueryCriteria; | ||
| 8 | import com.topdraw.business.module.member.address.service.mapper.MemberAddressMapper; | 8 | import com.topdraw.business.module.member.address.service.mapper.MemberAddressMapper; |
| 9 | import com.topdraw.business.module.member.service.MemberService; | 9 | import com.topdraw.business.module.member.service.MemberService; |
| 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 11 | import com.topdraw.utils.PageUtil; | ||
| 12 | import com.topdraw.utils.QueryHelp; | ||
| 13 | import com.topdraw.utils.ValidationUtil; | 11 | import com.topdraw.utils.ValidationUtil; |
| 12 | import lombok.extern.slf4j.Slf4j; | ||
| 13 | import org.springframework.beans.BeanUtils; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.dao.EmptyResultDataAccessException; | 15 | import org.springframework.dao.EmptyResultDataAccessException; |
| 16 | import org.springframework.data.domain.Page; | ||
| 17 | import org.springframework.data.domain.Pageable; | ||
| 18 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 19 | import org.springframework.transaction.annotation.Propagation; | 17 | import org.springframework.transaction.annotation.Propagation; |
| 20 | import org.springframework.transaction.annotation.Transactional; | 18 | import org.springframework.transaction.annotation.Transactional; |
| 21 | import org.springframework.util.Assert; | 19 | import org.springframework.util.Assert; |
| 22 | 20 | ||
| 23 | import java.util.List; | ||
| 24 | import java.util.Map; | ||
| 25 | import java.util.Objects; | ||
| 26 | import java.util.Optional; | ||
| 27 | |||
| 28 | /** | 21 | /** |
| 29 | * @author XiangHan | 22 | * @author XiangHan |
| 30 | * @date 2021-10-22 | 23 | * @date 2021-10-22 |
| 31 | */ | 24 | */ |
| 32 | @Service | 25 | @Service |
| 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 26 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 27 | @Slf4j | ||
| 34 | public class MemberAddressServiceImpl implements MemberAddressService { | 28 | public class MemberAddressServiceImpl implements MemberAddressService { |
| 35 | 29 | ||
| 36 | @Autowired | 30 | @Autowired |
| 37 | private MemberAddressRepository MemberAddressRepository; | 31 | private MemberService memberService; |
| 38 | |||
| 39 | @Autowired | 32 | @Autowired |
| 40 | private MemberAddressMapper MemberAddressMapper; | 33 | private MemberAddressMapper memberAddressMapper; |
| 41 | @Autowired | 34 | @Autowired |
| 42 | private MemberService memberService; | 35 | private MemberAddressRepository memberAddressRepository; |
| 43 | 36 | ||
| 44 | @Override | ||
| 45 | public Map<String, Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable) { | ||
| 46 | Page<MemberAddress> page = MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 47 | return PageUtil.toPage(page.map(MemberAddressMapper::toDto)); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public List<MemberAddressDTO> queryAll(MemberAddressQueryCriteria criteria) { | ||
| 52 | return MemberAddressMapper.toDto(MemberAddressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Override | 37 | @Override |
| 56 | public MemberAddressDTO findById(Long id) { | 38 | public MemberAddressDTO findById(Long id) { |
| 57 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseGet(MemberAddress::new); | 39 | Assert.notNull(id,"id can't be null"); |
| 40 | MemberAddress MemberAddress = this.memberAddressRepository.findById(id).orElseGet(MemberAddress::new); | ||
| 58 | ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id); | 41 | ValidationUtil.isNull(MemberAddress.getId(),"MemberAddress","id",id); |
| 59 | return MemberAddressMapper.toDto(MemberAddress); | 42 | return this.memberAddressMapper.toDto(MemberAddress); |
| 60 | } | 43 | } |
| 61 | 44 | ||
| 62 | @Override | 45 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 46 | @Transactional(rollbackFor = Exception.class) |
| 64 | public void create(MemberAddress resources) { | 47 | public MemberAddressDTO create(MemberAddress resources) { |
| 65 | String memberCode = resources.getMemberCode(); | 48 | log.info("MemberAddressServiceImpl ==>> create ==>> param ==>> [{}]",resources); |
| 66 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 49 | MemberAddress memberAddress = this.memberAddressRepository.save(resources); |
| 67 | Long id = memberDTO.getId(); | 50 | |
| 68 | resources.setMemberId(id); | 51 | log.info("MemberAddressServiceImpl ==>> create ==>> result ==>> [{}]",resources); |
| 69 | MemberAddressRepository.save(resources); | 52 | MemberAddressDTO memberAddressDTO = new MemberAddressDTO(); |
| 53 | BeanUtils.copyProperties(memberAddress, memberAddressDTO); | ||
| 54 | return memberAddressDTO; | ||
| 55 | |||
| 70 | } | 56 | } |
| 71 | 57 | ||
| 72 | @Override | 58 | @Override |
| 73 | @Transactional(rollbackFor = Exception.class) | 59 | @Transactional(rollbackFor = Exception.class) |
| 74 | public void update(MemberAddress resources) { | 60 | public MemberAddressDTO update(MemberAddress resources) { |
| 75 | String memberCode = resources.getMemberCode(); | 61 | log.info("MemberAddressServiceImpl ==>> update ==>> param ==>> [{}]",resources); |
| 76 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 62 | Assert.notNull(resources.getId(),"id can't be null"); |
| 77 | if (Objects.nonNull(memberDTO)) { | 63 | try { |
| 78 | Long memberId = memberDTO.getId(); | 64 | MemberAddress _memberAddress = this.memberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new); |
| 79 | Integer sequence = resources.getSequence(); | 65 | ValidationUtil.isNull( _memberAddress.getId(),"MemberAddress","id",resources.getId()); |
| 80 | Assert.notNull(sequence,"sequence can't be null!"); | 66 | _memberAddress.copy(resources); |
| 81 | Optional<MemberAddress> memberAddressOptional = MemberAddressRepository.findByMemberIdAndSequence(memberId,sequence); | 67 | MemberAddress memberAddress = this.memberAddressRepository.save(_memberAddress); |
| 82 | if (memberAddressOptional.isPresent()) { | 68 | |
| 83 | MemberAddress memberAddress = memberAddressOptional.get(); | 69 | MemberAddressDTO memberAddressDTO = new MemberAddressDTO(); |
| 84 | ValidationUtil.isNull(memberAddress.getId(),"MemberAddress","id",resources.getId()); | 70 | BeanUtils.copyProperties(memberAddress, memberAddressDTO); |
| 85 | resources.setId(memberAddress.getId()); | 71 | |
| 86 | memberAddress.copy(resources); | 72 | return memberAddressDTO; |
| 87 | MemberAddressRepository.save(memberAddress); | 73 | |
| 88 | } | 74 | } catch (Exception e) { |
| 75 | e.printStackTrace(); | ||
| 76 | throw e; | ||
| 89 | } | 77 | } |
| 78 | |||
| 90 | } | 79 | } |
| 91 | 80 | ||
| 92 | @Override | 81 | @Override |
| 93 | @Transactional(rollbackFor = Exception.class) | 82 | @Transactional(rollbackFor = Exception.class) |
| 94 | public void delete(Long id) { | 83 | public void delete(Long id) { |
| 95 | Assert.notNull(id, "The given id must not be null!"); | 84 | Assert.notNull(id, "The given id must not be null!"); |
| 96 | MemberAddress MemberAddress = MemberAddressRepository.findById(id).orElseThrow( | 85 | MemberAddress MemberAddress = this.memberAddressRepository.findById(id).orElseThrow( |
| 97 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1)); | 86 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberAddress.class, id), 1)); |
| 98 | MemberAddressRepository.delete(MemberAddress); | 87 | this.memberAddressRepository.delete(MemberAddress); |
| 99 | } | 88 | } |
| 100 | 89 | ||
| 90 | @Override | ||
| 91 | public MemberAddressDTO findByMemberIdAndSequence(Long memberId, Integer sequence) { | ||
| 92 | MemberAddress memberAddress = this.memberAddressRepository.findByMemberIdAndSequence(memberId, sequence); | ||
| 93 | return this.memberAddressMapper.toDto(memberAddress); | ||
| 94 | } | ||
| 95 | |||
| 96 | /** | ||
| 97 | * 检查会员 | ||
| 98 | * @param memberAddress | ||
| 99 | * @return | ||
| 100 | */ | ||
| 101 | private MemberDTO checkMember(MemberAddress memberAddress){ | ||
| 102 | Long memberId = memberAddress.getMemberId(); | ||
| 103 | String memberCode = memberAddress.getMemberCode(); | ||
| 104 | return this.checkMember(memberId,memberCode); | ||
| 105 | } | ||
| 106 | |||
| 107 | /** | ||
| 108 | * 检查会员 | ||
| 109 | * @param memberId 会员id | ||
| 110 | * @param memberCode 会员code | ||
| 111 | * @return | ||
| 112 | */ | ||
| 113 | private MemberDTO checkMember(Long memberId, String memberCode) { | ||
| 114 | return this.memberService.checkMember(memberId, memberCode); | ||
| 115 | } | ||
| 101 | 116 | ||
| 102 | } | 117 | } | ... | ... |
| ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.domain; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -9,8 +10,8 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -9,8 +10,8 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 11 | ||
| 11 | import javax.persistence.*; | 12 | import javax.persistence.*; |
| 13 | import javax.validation.constraints.NotNull; | ||
| 12 | import java.io.Serializable; | 14 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | ||
| 14 | import java.time.LocalDateTime; | 15 | import java.time.LocalDateTime; |
| 15 | 16 | ||
| 16 | /** | 17 | /** |
| ... | @@ -24,115 +25,116 @@ import java.time.LocalDateTime; | ... | @@ -24,115 +25,116 @@ import java.time.LocalDateTime; |
| 24 | @Table(name="uc_member") | 25 | @Table(name="uc_member") |
| 25 | public class Member implements Serializable { | 26 | public class Member implements Serializable { |
| 26 | 27 | ||
| 27 | // 运营商平台账号 | 28 | /** 运营商平台账号 */ |
| 28 | @Transient | 29 | @Transient |
| 29 | private String platformAccount; | 30 | private String platformAccount; |
| 30 | 31 | ||
| 31 | // 会员过期时间 | 32 | /** 会员过期时间 */ |
| 32 | @Column(name = "vip_expire_time", nullable = false) | 33 | @Column(name = "vip_expire_time", nullable = false) |
| 33 | private LocalDateTime vipExpireTime; | 34 | private LocalDateTime vipExpireTime; |
| 34 | 35 | ||
| 35 | // 主键 | 36 | /** 主键 */ |
| 36 | @Id | 37 | @Id |
| 37 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 38 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 38 | @Column(name = "id") | 39 | @Column(name = "id") |
| 40 | @NotNull(message = "id can't be null!!",groups = {UpdateGroup.class}) | ||
| 39 | private Long id; | 41 | private Long id; |
| 40 | 42 | ||
| 41 | // 标识 | 43 | /** 标识 */ |
| 42 | @Column(name = "code", nullable = false) | 44 | @Column(name = "code", nullable = false) |
| 43 | private String code; | 45 | private String code; |
| 44 | 46 | ||
| 45 | // 类型 1:大屏;2:小屏 | 47 | /** 类型 1:大屏;2:小屏 */ |
| 46 | @Column(name = "`type`", nullable = false) | 48 | @Column(name = "`type`", nullable = false) |
| 47 | private Integer type; | 49 | private Integer type; |
| 48 | 50 | ||
| 49 | // 状态 0:不可用;1:可用 | 51 | /** 状态 0:不可用;1:可用 */ |
| 50 | @Column(name = "`status`", nullable = false) | 52 | @Column(name = "`status`", nullable = false) |
| 51 | private Integer status; | 53 | private Integer status; |
| 52 | 54 | ||
| 53 | // 昵称 base64 | 55 | /** 昵称 base64 */ |
| 54 | @Column(name = "nickname") | 56 | @Column(name = "nickname") |
| 55 | private String nickname; | 57 | private String nickname; |
| 56 | 58 | ||
| 57 | // 描述 | 59 | /** 描述 */ |
| 58 | @Column(name = "description") | 60 | @Column(name = "description") |
| 59 | private String description; | 61 | private String description; |
| 60 | 62 | ||
| 61 | // 性别 0:女;1:男;-1:未知 | 63 | /** 性别 0:女;1:男;-1:未知 */ |
| 62 | @Column(name = "gender", nullable = false) | 64 | @Column(name = "gender", nullable = false) |
| 63 | private Integer gender; | 65 | private Integer gender; |
| 64 | 66 | ||
| 65 | // 生日 | 67 | /** 生日 */ |
| 66 | @Column(name = "birthday") | 68 | @Column(name = "birthday") |
| 67 | private String birthday; | 69 | private String birthday; |
| 68 | 70 | ||
| 69 | // 头像 | 71 | /** 头像 */ |
| 70 | @Column(name = "avatar_url") | 72 | @Column(name = "avatar_url") |
| 71 | private String avatarUrl; | 73 | private String avatarUrl; |
| 72 | 74 | ||
| 73 | // 分组信息 | 75 | /** 分组信息 */ |
| 74 | @Column(name = "`groups`") | 76 | @Column(name = "`groups`") |
| 75 | private String groups; | 77 | private String groups; |
| 76 | 78 | ||
| 77 | // 标签 | 79 | /** 标签 */ |
| 78 | @Column(name = "tags") | 80 | @Column(name = "tags") |
| 79 | private String tags; | 81 | private String tags; |
| 80 | 82 | ||
| 81 | // 是否会员 0:非会员;1:会员 | 83 | /** 是否会员 0:非会员;1:会员 */ |
| 82 | @Column(name = "vip", nullable = false) | 84 | @Column(name = "vip", nullable = false) |
| 83 | private Integer vip; | 85 | private Integer vip; |
| 84 | 86 | ||
| 85 | // 会员等级(对应level表的level字段,非id) | 87 | /** 会员等级(对应level表的level字段,非id) */ |
| 86 | @Column(name = "`level`", nullable = false) | 88 | @Column(name = "`level`", nullable = false) |
| 87 | private Integer level; | 89 | private Integer level; |
| 88 | 90 | ||
| 89 | // 成长值 | 91 | /** 成长值 */ |
| 90 | @Column(name = "`exp`") | 92 | @Column(name = "`exp`") |
| 91 | private Long exp; | 93 | private Long exp; |
| 92 | 94 | ||
| 93 | // 当前积分 | 95 | /** 当前积分 */ |
| 94 | @Column(name = "`points`") | 96 | @Column(name = "`points`") |
| 95 | private Long points; | 97 | private Long points; |
| 96 | 98 | ||
| 97 | // 即将到期积分(一个月内) | 99 | /** 即将到期积分(一个月内) */ |
| 98 | @Column(name = "due_points") | 100 | @Column(name = "due_points") |
| 99 | private Long duePoints; | 101 | private Long duePoints; |
| 100 | 102 | ||
| 101 | // 优惠券数量 | 103 | /** 优惠券数量 */ |
| 102 | @Column(name = "coupon_amount") | 104 | @Column(name = "coupon_amount") |
| 103 | private Long couponAmount; | 105 | private Long couponAmount; |
| 104 | 106 | ||
| 105 | // 即将过期优惠券数量 | 107 | /** 即将过期优惠券数量 */ |
| 106 | @Column(name = "due_coupon_amount") | 108 | @Column(name = "due_coupon_amount") |
| 107 | private Long dueCouponAmount; | 109 | private Long dueCouponAmount; |
| 108 | 110 | ||
| 109 | // iptv账号id | 111 | /** iptv账号id */ |
| 110 | @Column(name = "user_iptv_id") | 112 | @Column(name = "user_iptv_id") |
| 111 | private Long userIptvId; | 113 | private Long userIptvId; |
| 112 | 114 | ||
| 113 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | 115 | /** 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 */ |
| 114 | @Column(name = "bind_iptv_platform_type") | 116 | @Column(name = "bind_iptv_platform_type") |
| 115 | private Integer bindIptvPlatformType; | 117 | private Integer bindIptvPlatformType; |
| 116 | 118 | ||
| 117 | // iptv账号绑定时间 | 119 | /** iptv账号绑定时间 */ |
| 118 | @Column(name = "bind_iptv_time") | 120 | @Column(name = "bind_iptv_time") |
| 119 | private LocalDateTime bindIptvTime; | 121 | private LocalDateTime bindIptvTime; |
| 120 | 122 | ||
| 121 | // 创建时间 | 123 | /** 创建时间 */ |
| 122 | @CreatedDate | 124 | @CreatedDate |
| 123 | @Column(name = "create_time") | 125 | @Column(name = "create_time") |
| 124 | private LocalDateTime createTime; | 126 | private LocalDateTime createTime; |
| 125 | 127 | ||
| 126 | // 更新时间 | 128 | /** 更新时间 */ |
| 127 | @LastModifiedDate | 129 | @LastModifiedDate |
| 128 | @Column(name = "update_time") | 130 | @Column(name = "update_time") |
| 129 | private LocalDateTime updateTime; | 131 | private LocalDateTime updateTime; |
| 130 | 132 | ||
| 131 | // 是否在黑名单 1:是;0否 | 133 | /** 是否在黑名单 1:是;0否 */ |
| 132 | @Column(name = "black_status") | 134 | @Column(name = "black_status") |
| 133 | private Long blackStatus; | 135 | private Long blackStatus; |
| 134 | 136 | ||
| 135 | public void copy(Member source){ | 137 | public void copy(Member source){ |
| 136 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 138 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); |
| 137 | } | 139 | } |
| 138 | } | 140 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.domain; | ||
| 2 | |||
| 3 | |||
| 4 | import com.topdraw.util.IdWorker; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | |||
| 7 | import java.nio.charset.StandardCharsets; | ||
| 8 | import java.util.Base64; | ||
| 9 | import java.util.Objects; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author XiangHan | ||
| 13 | * @date 2021-10-22 | ||
| 14 | */ | ||
| 15 | public class MemberBuilder { | ||
| 16 | |||
| 17 | private static final Long DEFAULT_VALUE = 0L; | ||
| 18 | private static final Integer DEFAULT_VALUE_1 = 1; | ||
| 19 | private static final Integer DEFAULT_VALUE_ = -1; | ||
| 20 | |||
| 21 | public static Member build(Member member){ | ||
| 22 | Member _member = checkMemberData(member); | ||
| 23 | return _member; | ||
| 24 | } | ||
| 25 | |||
| 26 | private static Member checkMemberData(Member member) { | ||
| 27 | String code = member.getCode(); | ||
| 28 | member.setCode(StringUtils.isEmpty(code)?String.valueOf(IdWorker.generator()):code); | ||
| 29 | Integer gender = member.getGender(); | ||
| 30 | member.setGender(Objects.nonNull(gender) ? gender : DEFAULT_VALUE_); | ||
| 31 | Integer type = member.getType(); | ||
| 32 | member.setType(Objects.nonNull(type) ? type:DEFAULT_VALUE_); | ||
| 33 | Integer status = member.getStatus(); | ||
| 34 | member.setStatus(Objects.nonNull(status) ? status:DEFAULT_VALUE_1); | ||
| 35 | Integer vip = member.getVip(); | ||
| 36 | member.setVip(Objects.nonNull(vip) ? vip:0); | ||
| 37 | Integer level = member.getLevel(); | ||
| 38 | member.setLevel(Objects.nonNull(level) ? level:DEFAULT_VALUE_1); | ||
| 39 | member.setExp(DEFAULT_VALUE); | ||
| 40 | member.setPoints(DEFAULT_VALUE); | ||
| 41 | member.setDuePoints(DEFAULT_VALUE); | ||
| 42 | member.setCouponAmount(DEFAULT_VALUE); | ||
| 43 | member.setDueCouponAmount(DEFAULT_VALUE); | ||
| 44 | member.setBlackStatus(DEFAULT_VALUE); | ||
| 45 | member.setBirthday(StringUtils.isBlank(member.getBirthday())?"1900-01-01":member.getBirthday()); | ||
| 46 | String nickname = member.getNickname(); | ||
| 47 | if (StringUtils.isNotEmpty(nickname)) { | ||
| 48 | // String base64Nickname = new String(Base64.getEncoder().encode(nickname.getBytes(StandardCharsets.UTF_8))); | ||
| 49 | member.setNickname(nickname); | ||
| 50 | } | ||
| 51 | return member; | ||
| 52 | } | ||
| 53 | |||
| 54 | public static Member build(Integer type, String avatarUrl, String nickname, int vip){ | ||
| 55 | // todo 原型模式 | ||
| 56 | Member member = new Member(); | ||
| 57 | member.setType(type); | ||
| 58 | member.setAvatarUrl(avatarUrl); | ||
| 59 | member.setNickname(nickname); | ||
| 60 | member.setVip(vip); | ||
| 61 | Member _member = checkMemberData(member); | ||
| 62 | return _member; | ||
| 63 | } | ||
| 64 | } |
| 1 | package com.topdraw.business.module.member.group.domain; | ||
| 2 | |||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import lombok.Data; | ||
| 6 | import lombok.experimental.Accessors; | ||
| 7 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| 8 | |||
| 9 | import javax.persistence.*; | ||
| 10 | import java.io.Serializable; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author luerlong | ||
| 14 | * @date 2021-09-27 | ||
| 15 | */ | ||
| 16 | @Entity | ||
| 17 | @Data | ||
| 18 | @EntityListeners(AuditingEntityListener.class) | ||
| 19 | @Accessors(chain = true) | ||
| 20 | @Table(name="uc_group") | ||
| 21 | public class Group implements Serializable { | ||
| 22 | |||
| 23 | /** ID */ | ||
| 24 | @Id | ||
| 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 26 | @Column(name = "id") | ||
| 27 | private Long id; | ||
| 28 | |||
| 29 | /** CODE */ | ||
| 30 | @Column(name = "code") | ||
| 31 | private String code; | ||
| 32 | |||
| 33 | /** 名称 */ | ||
| 34 | @Column(name = "name") | ||
| 35 | private String name; | ||
| 36 | |||
| 37 | /** 状态 0-下线 1-上线 */ | ||
| 38 | @Column(name = "status") | ||
| 39 | private Integer status; | ||
| 40 | |||
| 41 | /** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */ | ||
| 42 | @Column(name = "permission_type") | ||
| 43 | private Integer permissionType; | ||
| 44 | |||
| 45 | public void copy(Group source){ | ||
| 46 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 47 | } | ||
| 48 | } |
| 1 | package com.topdraw.business.module.member.group.domain; | ||
| 2 | |||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import lombok.Data; | ||
| 6 | import lombok.experimental.Accessors; | ||
| 7 | import org.springframework.data.annotation.CreatedDate; | ||
| 8 | import org.springframework.data.annotation.LastModifiedDate; | ||
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| 10 | |||
| 11 | import javax.persistence.*; | ||
| 12 | import java.io.Serializable; | ||
| 13 | import java.sql.Timestamp; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author XiangHan | ||
| 17 | * @date 2021-11-17 | ||
| 18 | */ | ||
| 19 | @Entity | ||
| 20 | @Data | ||
| 21 | @EntityListeners(AuditingEntityListener.class) | ||
| 22 | @Accessors(chain = true) | ||
| 23 | @Table(name="uc_member_group") | ||
| 24 | public class MemberGroup implements Serializable { | ||
| 25 | |||
| 26 | /** ID */ | ||
| 27 | @Id | ||
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 29 | @Column(name = "id") | ||
| 30 | private Long id; | ||
| 31 | |||
| 32 | /** 分组ID */ | ||
| 33 | @Column(name = "group_id") | ||
| 34 | private Long groupId; | ||
| 35 | |||
| 36 | /** 会员ID */ | ||
| 37 | @Column(name = "member_id") | ||
| 38 | private Long memberId; | ||
| 39 | |||
| 40 | /** 运营商平台账号 */ | ||
| 41 | @Column(name = "platform_account") | ||
| 42 | private String platformAccount; | ||
| 43 | |||
| 44 | /** 手机号 */ | ||
| 45 | @Column(name = "cellphone") | ||
| 46 | private String cellphone; | ||
| 47 | |||
| 48 | /** 设备 */ | ||
| 49 | @Column(name = "stb_id") | ||
| 50 | private String stbId; | ||
| 51 | |||
| 52 | /** 有线MAC地址 */ | ||
| 53 | @Column(name = "eth_mac") | ||
| 54 | private String ethMac; | ||
| 55 | |||
| 56 | /** 无线MAC地址 */ | ||
| 57 | @Column(name = "wifi_mac") | ||
| 58 | private String wifiMac; | ||
| 59 | |||
| 60 | /** 描述 */ | ||
| 61 | @Column(name = "description") | ||
| 62 | private String description; | ||
| 63 | |||
| 64 | /** 创建者 */ | ||
| 65 | @Column(name = "create_by") | ||
| 66 | private String createBy; | ||
| 67 | |||
| 68 | /** 创建时间 */ | ||
| 69 | @CreatedDate | ||
| 70 | @Column(name = "create_time") | ||
| 71 | private Timestamp createTime; | ||
| 72 | |||
| 73 | /** 更新者 */ | ||
| 74 | @Column(name = "update_by") | ||
| 75 | private String updateBy; | ||
| 76 | |||
| 77 | /** 更新时间 */ | ||
| 78 | @LastModifiedDate | ||
| 79 | @Column(name = "update_time") | ||
| 80 | private Timestamp updateTime; | ||
| 81 | |||
| 82 | public void copy(MemberGroup source){ | ||
| 83 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 84 | } | ||
| 85 | } |
| 1 | package com.topdraw.business.module.member.group.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.domain.Group; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | import org.springframework.data.jpa.repository.Query; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | import java.util.Optional; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author luerlong | ||
| 14 | * @date 2021-09-27 | ||
| 15 | */ | ||
| 16 | public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecificationExecutor<Group> { | ||
| 17 | |||
| 18 | Optional<Group> findFirstByCode(String code); | ||
| 19 | |||
| 20 | List<Group> findByName(String name); | ||
| 21 | |||
| 22 | @Query(value = "select t1.id from uc_group t1 left join uc_user__group t2 on t1.id = t2.group_id where t2.user_id = ?1 and t1.permission_type = ?2 ", nativeQuery = true) | ||
| 23 | List<Map<String, Object>> findByUserIdAndPermissionType(Long userId, Integer type); | ||
| 24 | } |
src/main/java/com/topdraw/business/module/member/group/repository/MemberGroupRepository.java
0 → 100644
| 1 | package com.topdraw.business.module.member.group.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.domain.MemberGroup; | ||
| 4 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | ||
| 5 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author XiangHan | ||
| 12 | * @date 2021-11-17 | ||
| 13 | */ | ||
| 14 | public interface MemberGroupRepository extends JpaRepository<MemberGroup, Long>, JpaSpecificationExecutor<MemberGroup> { | ||
| 15 | |||
| 16 | List<MemberGroupDTO> findByMemberId(Long memberId); | ||
| 17 | } |
| 1 | package com.topdraw.business.module.member.group.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; | ||
| 4 | |||
| 5 | |||
| 6 | /** | ||
| 7 | * @author luerlong | ||
| 8 | * @date 2021-09-27 | ||
| 9 | */ | ||
| 10 | public interface GroupService { | ||
| 11 | |||
| 12 | |||
| 13 | /** | ||
| 14 | * 根据ID查询 | ||
| 15 | * @param id ID | ||
| 16 | * @return GroupDTO | ||
| 17 | */ | ||
| 18 | GroupDTO findById(Long id); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Code校验 | ||
| 22 | * @param code | ||
| 23 | * @return GroupDTO | ||
| 24 | */ | ||
| 25 | GroupDTO getByCode(String code); | ||
| 26 | } |
| 1 | package com.topdraw.business.module.member.group.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | ||
| 4 | |||
| 5 | import java.util.List; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author XiangHan | ||
| 9 | * @date 2021-11-17 | ||
| 10 | */ | ||
| 11 | public interface MemberGroupService { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * 通过会员id获取会员分组列表 | ||
| 15 | * @param memberId | ||
| 16 | * @return | ||
| 17 | */ | ||
| 18 | List<MemberGroupDTO> findByMemberId(Long memberId); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * 根据ID查询 | ||
| 22 | * @param id ID | ||
| 23 | * @return MemberGroupDTO | ||
| 24 | */ | ||
| 25 | MemberGroupDTO findById(Long id); | ||
| 26 | |||
| 27 | } |
| 1 | package com.topdraw.business.module.member.group.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | |||
| 7 | |||
| 8 | /** | ||
| 9 | * @author luerlong | ||
| 10 | * @date 2021-09-27 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | public class GroupDTO implements Serializable { | ||
| 14 | |||
| 15 | /** ID */ | ||
| 16 | private Long id; | ||
| 17 | |||
| 18 | /** CODE */ | ||
| 19 | private String code; | ||
| 20 | |||
| 21 | /** 名称 */ | ||
| 22 | private String name; | ||
| 23 | |||
| 24 | /** 状态 0-下线 1-上线 */ | ||
| 25 | private Integer status; | ||
| 26 | |||
| 27 | /** 权限 0-测试分组 1-鉴权通过(白名单) 2-不允许精准(黑名单)3-可以精准(金名单) */ | ||
| 28 | private Integer permissionType; | ||
| 29 | |||
| 30 | } |
| 1 | package com.topdraw.business.module.member.group.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | import java.sql.Timestamp; | ||
| 7 | |||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-11-17 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class MemberGroupDTO implements Serializable { | ||
| 15 | |||
| 16 | /** ID */ | ||
| 17 | private Long id; | ||
| 18 | |||
| 19 | /** 分组ID */ | ||
| 20 | private Long groupId; | ||
| 21 | |||
| 22 | /** 会员ID */ | ||
| 23 | private Long memberId; | ||
| 24 | |||
| 25 | /** 运营商平台账号 */ | ||
| 26 | private String platformAccount; | ||
| 27 | |||
| 28 | /** 手机号 */ | ||
| 29 | private String cellphone; | ||
| 30 | |||
| 31 | /** 设备 */ | ||
| 32 | private String stbId; | ||
| 33 | |||
| 34 | /** 有线MAC地址 */ | ||
| 35 | private String ethMac; | ||
| 36 | |||
| 37 | /** 无线MAC地址 */ | ||
| 38 | private String wifiMac; | ||
| 39 | |||
| 40 | /** 描述 */ | ||
| 41 | private String description; | ||
| 42 | |||
| 43 | /** 创建者 */ | ||
| 44 | private String createBy; | ||
| 45 | |||
| 46 | /** 创建时间 */ | ||
| 47 | private Timestamp createTime; | ||
| 48 | |||
| 49 | /** 更新者 */ | ||
| 50 | private String updateBy; | ||
| 51 | |||
| 52 | /** 更新时间 */ | ||
| 53 | private Timestamp updateTime; | ||
| 54 | |||
| 55 | } |
src/main/java/com/topdraw/business/module/member/group/service/impl/GroupServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.module.member.group.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.domain.Group; | ||
| 4 | import com.topdraw.business.module.member.group.repository.GroupRepository; | ||
| 5 | import com.topdraw.business.module.member.group.service.GroupService; | ||
| 6 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; | ||
| 7 | import com.topdraw.business.module.member.group.service.mapper.GroupMapper; | ||
| 8 | import com.topdraw.utils.StringUtils; | ||
| 9 | import com.topdraw.utils.ValidationUtil; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | import org.springframework.stereotype.Service; | ||
| 12 | import org.springframework.transaction.annotation.Propagation; | ||
| 13 | import org.springframework.transaction.annotation.Transactional; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author luerlong | ||
| 17 | * @date 2021-09-27 | ||
| 18 | */ | ||
| 19 | @Service | ||
| 20 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 21 | public class GroupServiceImpl implements GroupService { | ||
| 22 | |||
| 23 | @Autowired | ||
| 24 | private GroupRepository groupRepository; | ||
| 25 | |||
| 26 | @Autowired | ||
| 27 | private GroupMapper groupMapper; | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public GroupDTO findById(Long id) { | ||
| 31 | Group group = groupRepository.findById(id).orElseGet(Group::new); | ||
| 32 | ValidationUtil.isNull(group.getId(),"Group","id",id); | ||
| 33 | return groupMapper.toDto(group); | ||
| 34 | } | ||
| 35 | |||
| 36 | @Override | ||
| 37 | public GroupDTO getByCode(String code) { | ||
| 38 | return StringUtils.isNotEmpty(code) ? groupMapper.toDto(groupRepository.findFirstByCode(code).orElseGet(Group::new)) | ||
| 39 | : new GroupDTO(); | ||
| 40 | } | ||
| 41 | } |
src/main/java/com/topdraw/business/module/member/group/service/impl/MemberGroupServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.module.member.group.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.group.domain.MemberGroup; | ||
| 4 | import com.topdraw.business.module.member.group.repository.MemberGroupRepository; | ||
| 5 | import com.topdraw.business.module.member.group.service.MemberGroupService; | ||
| 6 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | ||
| 7 | import com.topdraw.business.module.member.group.service.mapper.MemberGroupMapper; | ||
| 8 | import com.topdraw.utils.ValidationUtil; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | import org.springframework.stereotype.Service; | ||
| 11 | import org.springframework.transaction.annotation.Propagation; | ||
| 12 | import org.springframework.transaction.annotation.Transactional; | ||
| 13 | |||
| 14 | import java.util.List; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @author XiangHan | ||
| 18 | * @date 2021-11-17 | ||
| 19 | */ | ||
| 20 | @Service | ||
| 21 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 22 | public class MemberGroupServiceImpl implements MemberGroupService { | ||
| 23 | |||
| 24 | @Autowired | ||
| 25 | private MemberGroupRepository memberGroupRepository; | ||
| 26 | @Autowired | ||
| 27 | private MemberGroupMapper memberGroupMapper; | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public List<MemberGroupDTO> findByMemberId(Long memberId) { | ||
| 31 | return this.memberGroupRepository.findByMemberId(memberId); | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public MemberGroupDTO findById(Long id) { | ||
| 36 | MemberGroup memberGroup = this.memberGroupRepository.findById(id).orElseGet(MemberGroup::new); | ||
| 37 | ValidationUtil.isNull(memberGroup.getId(),"MemberGroup","id",id); | ||
| 38 | return this.memberGroupMapper.toDto(memberGroup); | ||
| 39 | } | ||
| 40 | |||
| 41 | } |
| 1 | package com.topdraw.business.module.member.group.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.module.member.group.domain.Group; | ||
| 5 | import com.topdraw.business.module.member.group.service.dto.GroupDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author luerlong | ||
| 11 | * @date 2021-09-27 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface GroupMapper extends BaseMapper<GroupDTO, Group> { | ||
| 15 | |||
| 16 | } |
src/main/java/com/topdraw/business/module/member/group/service/mapper/MemberGroupMapper.java
0 → 100644
| 1 | package com.topdraw.business.module.member.group.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.module.member.group.domain.MemberGroup; | ||
| 5 | import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-11-17 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface MemberGroupMapper extends BaseMapper<MemberGroupDTO, MemberGroup> { | ||
| 15 | |||
| 16 | } |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.level.domain; | ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.level.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
| 6 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 9 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -9,6 +11,8 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -9,6 +11,8 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 11 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 12 | ||
| 11 | import javax.persistence.*; | 13 | import javax.persistence.*; |
| 14 | import javax.validation.constraints.Min; | ||
| 15 | import javax.validation.constraints.NotNull; | ||
| 12 | import java.io.Serializable; | 16 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 17 | import java.sql.Timestamp; |
| 14 | 18 | ||
| ... | @@ -23,50 +27,53 @@ import java.sql.Timestamp; | ... | @@ -23,50 +27,53 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_member_level") | 27 | @Table(name="uc_member_level") |
| 24 | public class MemberLevel implements Serializable { | 28 | public class MemberLevel implements Serializable { |
| 25 | 29 | ||
| 26 | // 主键 | 30 | /** 主键 */ |
| 27 | @Id | 31 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 33 | @Column(name = "id") |
| 34 | @NotNull(message = "id can't be null !!" , groups = {UpdateGroup.class}) | ||
| 30 | private Long id; | 35 | private Long id; |
| 31 | 36 | ||
| 32 | // 标识 | 37 | /** 标识 */ |
| 33 | @Column(name = "code", nullable = false) | 38 | @Column(name = "code", nullable = false) |
| 34 | private String code; | 39 | private String code; |
| 35 | 40 | ||
| 36 | // 名称 | 41 | /** 名称 */ |
| 37 | @Column(name = "name", nullable = false) | 42 | @Column(name = "name", nullable = false) |
| 38 | private String name; | 43 | private String name; |
| 39 | 44 | ||
| 40 | // 状态 0:未启用;1:启用 | 45 | /** 状态 0:未启用;1:启用 */ |
| 41 | @Column(name = "status", nullable = false) | 46 | @Column(name = "status", nullable = false) |
| 42 | private Integer status; | 47 | private Integer status; |
| 43 | 48 | ||
| 44 | // 对应成长值 | 49 | /** 对应成长值 */ |
| 45 | @Column(name = "exp_value", nullable = false) | 50 | @Column(name = "exp_value", nullable = false) |
| 46 | private Long expValue; | 51 | private Long expValue; |
| 47 | 52 | ||
| 48 | // 等级(不可重复,数字越大等级越高) | 53 | /** 等级(不可重复,数字越大等级越高) */ |
| 49 | @Column(name = "level", nullable = false) | 54 | @Column(name = "level", nullable = false) |
| 55 | @Min(message = "level can't less then 1" , value = 1) | ||
| 56 | @NotNull(message = "level can't be null" , groups = {CreateGroup.class,UpdateGroup.class}) | ||
| 50 | private Integer level; | 57 | private Integer level; |
| 51 | 58 | ||
| 52 | // 会员徽标 | 59 | /** 会员徽标 */ |
| 53 | @Column(name = "icon_url") | 60 | @Column(name = "icon_url") |
| 54 | private String iconUrl; | 61 | private String iconUrl; |
| 55 | 62 | ||
| 56 | // 描述 | 63 | /** 描述 */ |
| 57 | @Column(name = "description") | 64 | @Column(name = "description") |
| 58 | private String description; | 65 | private String description; |
| 59 | 66 | ||
| 60 | // 对应任务id,通过此字段可获得该等级所对应的权益 | 67 | /** 对应任务id,通过此字段可获得该等级所对应的权益 */ |
| 61 | @Column(name = "task_id") | 68 | @Column(name = "task_id") |
| 62 | private Long taskId; | 69 | private Long taskId; |
| 63 | 70 | ||
| 64 | // 创建时间 | 71 | /** 创建时间 */ |
| 65 | @CreatedDate | 72 | @CreatedDate |
| 66 | @Column(name = "create_time") | 73 | @Column(name = "create_time") |
| 67 | private Timestamp createTime; | 74 | private Timestamp createTime; |
| 68 | 75 | ||
| 69 | // 更新时间 | 76 | /** 更新时间 */ |
| 70 | @LastModifiedDate | 77 | @LastModifiedDate |
| 71 | @Column(name = "update_time") | 78 | @Column(name = "update_time") |
| 72 | private Timestamp updateTime; | 79 | private Timestamp updateTime; | ... | ... |
| 1 | package com.topdraw.business.module.member.level.service; | 1 | package com.topdraw.business.module.member.level.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.level.domain.MemberLevel; | ||
| 4 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 3 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
| 5 | import com.topdraw.business.module.member.level.service.dto.MemberLevelQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 4 | ||
| 8 | import java.util.List; | 5 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 6 | ||
| 11 | /** | 7 | /** |
| 12 | * @author XiangHan | 8 | * @author XiangHan |
| ... | @@ -15,33 +11,12 @@ import java.util.Map; | ... | @@ -15,33 +11,12 @@ import java.util.Map; |
| 15 | public interface MemberLevelService { | 11 | public interface MemberLevelService { |
| 16 | 12 | ||
| 17 | /** | 13 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<MemberLevelDTO> | ||
| 29 | */ | ||
| 30 | List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 14 | * 根据ID查询 |
| 34 | * @param id ID | 15 | * @param id ID |
| 35 | * @return MemberLevelDTO | 16 | * @return MemberLevelDTO |
| 36 | */ | 17 | */ |
| 37 | MemberLevelDTO findById(Long id); | 18 | MemberLevelDTO findById(Long id); |
| 38 | 19 | ||
| 39 | void create(MemberLevel resources); | ||
| 40 | |||
| 41 | void update(MemberLevel resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | /** | 20 | /** |
| 46 | * Code校验 | 21 | * Code校验 |
| 47 | * @param code | 22 | * @param code |
| ... | @@ -49,5 +24,13 @@ public interface MemberLevelService { | ... | @@ -49,5 +24,13 @@ public interface MemberLevelService { |
| 49 | */ | 24 | */ |
| 50 | MemberLevelDTO getByCode(String code); | 25 | MemberLevelDTO getByCode(String code); |
| 51 | 26 | ||
| 27 | /** | ||
| 28 | * 通过等级和状态检索 | ||
| 29 | * @param i | ||
| 30 | * @param status | ||
| 31 | * @return | ||
| 32 | */ | ||
| 52 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); | 33 | List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); |
| 34 | |||
| 35 | |||
| 53 | } | 36 | } | ... | ... |
| ... | @@ -13,36 +13,36 @@ import java.sql.Timestamp; | ... | @@ -13,36 +13,36 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class MemberLevelDTO implements Serializable { | 14 | public class MemberLevelDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // 主键 | 16 | /** 主键 */ |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | // 标识 | 19 | /** 标识 */ |
| 20 | private String code; | 20 | private String code; |
| 21 | 21 | ||
| 22 | // 名称 | 22 | /** 名称 */ |
| 23 | private String name; | 23 | private String name; |
| 24 | 24 | ||
| 25 | // 状态 0:未启用;1:启用 | 25 | /** 状态 0:未启用;1:启用 */ |
| 26 | private Integer status; | 26 | private Integer status; |
| 27 | 27 | ||
| 28 | // 对应成长值 | 28 | /** 对应成长值 */ |
| 29 | private Long expValue; | 29 | private Long expValue; |
| 30 | 30 | ||
| 31 | // 等级(不可重复,数字越大等级越高) | 31 | /** 等级(不可重复,数字越大等级越高) */ |
| 32 | private Integer level; | 32 | private Integer level; |
| 33 | 33 | ||
| 34 | // 会员徽标 | 34 | /** 会员徽标 */ |
| 35 | private String iconUrl; | 35 | private String iconUrl; |
| 36 | 36 | ||
| 37 | // 描述 | 37 | /** 描述 */ |
| 38 | private String description; | 38 | private String description; |
| 39 | 39 | ||
| 40 | // 对应任务id,通过此字段可获得该等级所对应的权益 | 40 | /** 对应任务id,通过此字段可获得该等级所对应的权益 */ |
| 41 | private Long taskId; | 41 | private Long taskId; |
| 42 | 42 | ||
| 43 | // 创建时间 | 43 | /** 创建时间 */ |
| 44 | private Timestamp createTime; | 44 | private Timestamp createTime; |
| 45 | 45 | ||
| 46 | // 更新时间 | 46 | /** 更新时间 */ |
| 47 | private Timestamp updateTime; | 47 | private Timestamp updateTime; |
| 48 | } | 48 | } | ... | ... |
| ... | @@ -4,23 +4,15 @@ import com.topdraw.business.module.member.level.domain.MemberLevel; | ... | @@ -4,23 +4,15 @@ import com.topdraw.business.module.member.level.domain.MemberLevel; |
| 4 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; | 4 | import com.topdraw.business.module.member.level.repository.MemberLevelRepository; |
| 5 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 5 | import com.topdraw.business.module.member.level.service.MemberLevelService; |
| 6 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | 6 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; |
| 7 | import com.topdraw.business.module.member.level.service.dto.MemberLevelQueryCriteria; | ||
| 8 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; | 7 | import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | ||
| 21 | 14 | ||
| 22 | import java.util.List; | 15 | import java.util.List; |
| 23 | import java.util.Map; | ||
| 24 | 16 | ||
| 25 | /** | 17 | /** |
| 26 | * @author XiangHan | 18 | * @author XiangHan |
| ... | @@ -31,62 +23,27 @@ import java.util.Map; | ... | @@ -31,62 +23,27 @@ import java.util.Map; |
| 31 | public class MemberLevelServiceImpl implements MemberLevelService { | 23 | public class MemberLevelServiceImpl implements MemberLevelService { |
| 32 | 24 | ||
| 33 | @Autowired | 25 | @Autowired |
| 34 | private MemberLevelRepository MemberLevelRepository; | 26 | private MemberLevelRepository memberLevelRepository; |
| 35 | 27 | ||
| 36 | @Autowired | 28 | @Autowired |
| 37 | private MemberLevelMapper MemberLevelMapper; | 29 | private MemberLevelMapper memberLevelMapper; |
| 38 | |||
| 39 | @Override | ||
| 40 | public Map<String, Object> queryAll(MemberLevelQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<MemberLevel> page = MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(MemberLevelMapper::toDto)); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public List<MemberLevelDTO> queryAll(MemberLevelQueryCriteria criteria) { | ||
| 47 | return MemberLevelMapper.toDto(MemberLevelRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 30 | ||
| 50 | @Override | 31 | @Override |
| 51 | public MemberLevelDTO findById(Long id) { | 32 | public MemberLevelDTO findById(Long id) { |
| 52 | MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseGet(MemberLevel::new); | 33 | MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new); |
| 53 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); | 34 | ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); |
| 54 | return MemberLevelMapper.toDto(MemberLevel); | 35 | return this.memberLevelMapper.toDto(MemberLevel); |
| 55 | } | ||
| 56 | |||
| 57 | @Override | ||
| 58 | @Transactional(rollbackFor = Exception.class) | ||
| 59 | public void create(MemberLevel resources) { | ||
| 60 | MemberLevelRepository.save(resources); | ||
| 61 | } | 36 | } |
| 62 | 37 | ||
| 63 | @Override | 38 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | ||
| 65 | public void update(MemberLevel resources) { | ||
| 66 | MemberLevel MemberLevel = MemberLevelRepository.findById(resources.getId()).orElseGet(MemberLevel::new); | ||
| 67 | ValidationUtil.isNull( MemberLevel.getId(),"MemberLevel","id",resources.getId()); | ||
| 68 | MemberLevel.copy(resources); | ||
| 69 | MemberLevelRepository.save(MemberLevel); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Override | ||
| 73 | @Transactional(rollbackFor = Exception.class) | ||
| 74 | public void delete(Long id) { | ||
| 75 | Assert.notNull(id, "The given id must not be null!"); | ||
| 76 | MemberLevel MemberLevel = MemberLevelRepository.findById(id).orElseThrow( | ||
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberLevel.class, id), 1)); | ||
| 78 | MemberLevelRepository.delete(MemberLevel); | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | @Override | ||
| 83 | public MemberLevelDTO getByCode(String code) { | 39 | public MemberLevelDTO getByCode(String code) { |
| 84 | return StringUtils.isNotEmpty(code) ? MemberLevelMapper.toDto(MemberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) | 40 | return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) |
| 85 | : new MemberLevelDTO(); | 41 | : new MemberLevelDTO(); |
| 86 | } | 42 | } |
| 87 | 43 | ||
| 88 | @Override | 44 | @Override |
| 89 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 45 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
| 90 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | 46 | return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level,status)); |
| 91 | } | 47 | } |
| 48 | |||
| 92 | } | 49 | } | ... | ... |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.profile.domain; | ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.profile.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
| 6 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 9 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -9,6 +11,7 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -9,6 +11,7 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 11 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 12 | ||
| 11 | import javax.persistence.*; | 13 | import javax.persistence.*; |
| 14 | import javax.validation.constraints.NotNull; | ||
| 12 | import java.io.Serializable; | 15 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 16 | import java.sql.Timestamp; |
| 14 | 17 | ||
| ... | @@ -23,73 +26,80 @@ import java.sql.Timestamp; | ... | @@ -23,73 +26,80 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_member_profile") | 26 | @Table(name="uc_member_profile") |
| 24 | public class MemberProfile implements Serializable { | 27 | public class MemberProfile implements Serializable { |
| 25 | 28 | ||
| 26 | // 主键 | 29 | /** 会员code */ |
| 30 | @Transient | ||
| 31 | @NotNull(message = "memberCode not be null!!" , groups = {CreateGroup.class, UpdateGroup.class}) | ||
| 32 | private String memberCode; | ||
| 33 | |||
| 34 | /** 头像 */ | ||
| 35 | @Transient | ||
| 36 | private String avatarUrl; | ||
| 37 | |||
| 38 | /** 主键 */ | ||
| 27 | @Id | 39 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 40 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 41 | @Column(name = "id") |
| 42 | @NotNull(message = "id not be null!!" , groups = UpdateGroup.class) | ||
| 30 | private Long id; | 43 | private Long id; |
| 31 | 44 | ||
| 32 | // 手机号 | 45 | /** 会员id */ |
| 33 | @Column(name = "phone") | ||
| 34 | private String phone; | ||
| 35 | |||
| 36 | // 会员id | ||
| 37 | @Column(name = "member_id", nullable = false) | 46 | @Column(name = "member_id", nullable = false) |
| 38 | private Long memberId; | 47 | private Long memberId; |
| 39 | 48 | ||
| 40 | @Transient | 49 | /** 姓名 */ |
| 41 | private String memberCode; | ||
| 42 | |||
| 43 | // 姓名 | ||
| 44 | @Column(name = "realname") | 50 | @Column(name = "realname") |
| 45 | private String realname; | 51 | private String realname; |
| 46 | 52 | ||
| 47 | // 性别 0:女; 1:男 -1:未知 | 53 | /** 性别 0:女; 1:男 -1:未知 */ |
| 48 | @Column(name = "gender", nullable = false) | 54 | @Column(name = "gender", nullable = false) |
| 49 | private Integer gender; | 55 | private Integer gender; |
| 50 | 56 | ||
| 51 | // 生日 | 57 | /** 生日 */ |
| 52 | @Column(name = "birthday", nullable = false) | 58 | @Column(name = "birthday", nullable = false) |
| 53 | private Timestamp birthday; | 59 | private String birthday; |
| 60 | |||
| 61 | /** 手机号 */ | ||
| 62 | @Column(name = "phone") | ||
| 63 | private String phone; | ||
| 54 | 64 | ||
| 55 | // 星座 | 65 | /** 星座 */ |
| 56 | @Column(name = "constellation") | 66 | @Column(name = "constellation") |
| 57 | private String constellation; | 67 | private String constellation; |
| 58 | 68 | ||
| 59 | // 身份证 | 69 | /** 身份证 */ |
| 60 | @Column(name = "id_card", nullable = false) | 70 | @Column(name = "id_card", nullable = false) |
| 61 | private String idCard; | 71 | private String idCard; |
| 62 | 72 | ||
| 63 | // 电子邮件 | 73 | /** 电子邮件 */ |
| 64 | @Column(name = "email") | 74 | @Column(name = "email") |
| 65 | private String email; | 75 | private String email; |
| 66 | 76 | ||
| 67 | // 国家 | 77 | /** 国家 */ |
| 68 | @Column(name = "country") | 78 | @Column(name = "country") |
| 69 | private String country; | 79 | private String country; |
| 70 | 80 | ||
| 71 | // 省份 | 81 | /** 省份 */ |
| 72 | @Column(name = "province") | 82 | @Column(name = "province") |
| 73 | private String province; | 83 | private String province; |
| 74 | 84 | ||
| 75 | // 城市 | 85 | /** 城市 */ |
| 76 | @Column(name = "city") | 86 | @Column(name = "city") |
| 77 | private String city; | 87 | private String city; |
| 78 | 88 | ||
| 79 | // 区县 | 89 | /** 区县 */ |
| 80 | @Column(name = "district") | 90 | @Column(name = "district") |
| 81 | private String district; | 91 | private String district; |
| 82 | 92 | ||
| 83 | // 描述 | 93 | /** 描述 */ |
| 84 | @Column(name = "description") | 94 | @Column(name = "description") |
| 85 | private String description; | 95 | private String description; |
| 86 | 96 | ||
| 87 | // 创建时间 | 97 | /** 创建时间 */ |
| 88 | @CreatedDate | 98 | @CreatedDate |
| 89 | @Column(name = "create_time") | 99 | @Column(name = "create_time") |
| 90 | private Timestamp createTime; | 100 | private Timestamp createTime; |
| 91 | 101 | ||
| 92 | // 更新时间 | 102 | /** 更新时间 */ |
| 93 | @LastModifiedDate | 103 | @LastModifiedDate |
| 94 | @Column(name = "update_time") | 104 | @Column(name = "update_time") |
| 95 | private Timestamp updateTime; | 105 | private Timestamp updateTime; | ... | ... |
src/main/java/com/topdraw/business/module/member/profile/domain/MemberProfileBuilder.java
0 → 100644
| 1 | package com.topdraw.business.module.member.profile.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.util.Assert; | ||
| 7 | |||
| 8 | public class MemberProfileBuilder { | ||
| 9 | |||
| 10 | public static MemberProfile build(Member member){ | ||
| 11 | MemberProfile memberProfile = build(member.getId(),member.getCode(),member.getNickname(),member.getGender(),"","","","","","", | ||
| 12 | "","","",member.getBirthday()); | ||
| 13 | return memberProfile; | ||
| 14 | } | ||
| 15 | |||
| 16 | public static MemberProfile build(Long memberId){ | ||
| 17 | MemberProfile memberProfile = build(memberId,"","",-1,"","","","","","", | ||
| 18 | "","","",""); | ||
| 19 | return memberProfile; | ||
| 20 | } | ||
| 21 | |||
| 22 | public static MemberProfile build(Long memberId ,String memberCode, String realname , Integer gender, String birthday){ | ||
| 23 | MemberProfile memberProfile = build(memberId,memberCode,realname,gender,"","","","","","", | ||
| 24 | "","","",birthday); | ||
| 25 | return memberProfile; | ||
| 26 | } | ||
| 27 | |||
| 28 | public static MemberProfile build(Long memberId,String memberCode, String realName, Integer sex, | ||
| 29 | String country, String district, String city, String idCard, String province, | ||
| 30 | String email, String description, String phone, String constellation, | ||
| 31 | String birthday) { | ||
| 32 | |||
| 33 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 34 | |||
| 35 | MemberProfile memberProfile = new MemberProfile(); | ||
| 36 | memberProfile.setMemberId(memberId); | ||
| 37 | memberProfile.setMemberCode(memberCode); | ||
| 38 | memberProfile.setRealname(stringIsNull(realName)); | ||
| 39 | memberProfile.setGender(sex == null ? 0 : sex); | ||
| 40 | memberProfile.setCountry(StringUtils.isBlank(country)?"中国":birthday); | ||
| 41 | memberProfile.setDistrict(stringIsNull(district)); | ||
| 42 | memberProfile.setCity(stringIsNull(city)); | ||
| 43 | memberProfile.setIdCard(StringUtils.isBlank(idCard)?"000000000000000000":idCard); | ||
| 44 | memberProfile.setProvince(stringIsNull(province)); | ||
| 45 | memberProfile.setEmail(stringIsNull(email)); | ||
| 46 | memberProfile.setDescription(stringIsNull(description)); | ||
| 47 | memberProfile.setPhone(stringIsNull(phone)); | ||
| 48 | memberProfile.setConstellation(stringIsNull(constellation)); | ||
| 49 | memberProfile.setBirthday(StringUtils.isBlank(birthday)?"1900-01-01":birthday); | ||
| 50 | |||
| 51 | return memberProfile; | ||
| 52 | } | ||
| 53 | |||
| 54 | private static String stringIsNull(String s){ | ||
| 55 | return StringUtils.isBlank(s)?"":s; | ||
| 56 | } | ||
| 57 | |||
| 58 | public static MemberProfile build(MemberProfile resources) { | ||
| 59 | if (resources.getMemberId() == null) | ||
| 60 | throw new NullPointerException("memberId is null"); | ||
| 61 | |||
| 62 | MemberProfile memberProfile = new MemberProfile(); | ||
| 63 | memberProfile.setId(resources.getId()); | ||
| 64 | memberProfile.setMemberId(resources.getMemberId()); | ||
| 65 | memberProfile.setRealname(stringIsNull(resources.getRealname())); | ||
| 66 | memberProfile.setGender(resources.getGender() == null ? -1 : resources.getGender()); | ||
| 67 | memberProfile.setCountry(stringIsNull(resources.getCountry())); | ||
| 68 | memberProfile.setDistrict(stringIsNull(resources.getDistrict())); | ||
| 69 | memberProfile.setCity(stringIsNull(resources.getCity())); | ||
| 70 | memberProfile.setIdCard(StringUtils.isBlank(resources.getIdCard())?"000000000000000000":resources.getIdCard()); | ||
| 71 | memberProfile.setProvince(stringIsNull(resources.getProvince())); | ||
| 72 | memberProfile.setEmail(stringIsNull(resources.getEmail())); | ||
| 73 | memberProfile.setDescription(stringIsNull(resources.getDescription())); | ||
| 74 | memberProfile.setPhone(stringIsNull(resources.getPhone())); | ||
| 75 | memberProfile.setConstellation(stringIsNull(resources.getConstellation())); | ||
| 76 | memberProfile.setBirthday(stringIsNull(resources.getBirthday())); | ||
| 77 | return memberProfile; | ||
| 78 | } | ||
| 79 | } |
| ... | @@ -12,5 +12,7 @@ import java.util.Optional; | ... | @@ -12,5 +12,7 @@ import java.util.Optional; |
| 12 | */ | 12 | */ |
| 13 | public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> { | 13 | public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> { |
| 14 | 14 | ||
| 15 | MemberProfile findByMemberId(Long memberId); | 15 | Optional<MemberProfile> findByMemberId(Long memberId); |
| 16 | |||
| 17 | Optional<MemberProfile> findFirstByMemberId(Long memberId); | ||
| 16 | } | 18 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.profile.service; | 1 | package com.topdraw.business.module.member.profile.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 3 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 4 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 4 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | 5 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; |
| 5 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileQueryCriteria; | 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -15,31 +12,69 @@ import java.util.Map; | ... | @@ -15,31 +12,69 @@ import java.util.Map; |
| 15 | public interface MemberProfileService { | 12 | public interface MemberProfileService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<MemberProfileDTO> | ||
| 29 | */ | ||
| 30 | List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 15 | * 根据ID查询 |
| 34 | * @param id ID | 16 | * @param id ID |
| 35 | * @return MemberProfileDTO | 17 | * @return MemberProfileDTO |
| 36 | */ | 18 | */ |
| 37 | MemberProfileDTO findById(Long id); | 19 | MemberProfileDTO findById(Long id); |
| 38 | 20 | ||
| 21 | /** | ||
| 22 | * 保存 | ||
| 23 | * @param resources 会员基本信息 | ||
| 24 | * @return | ||
| 25 | */ | ||
| 39 | MemberProfile create(MemberProfile resources); | 26 | MemberProfile create(MemberProfile resources); |
| 40 | 27 | ||
| 41 | void update(MemberProfile resources); | 28 | /** |
| 29 | * 默认属性 | ||
| 30 | * @param resources | ||
| 31 | * @return | ||
| 32 | */ | ||
| 33 | MemberProfile createDefault(MemberProfile resources); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * 通过会员创建默认属性 | ||
| 37 | * @param resources | ||
| 38 | * @return | ||
| 39 | */ | ||
| 40 | MemberProfile createDefault(Member resources); | ||
| 41 | |||
| 42 | /** | ||
| 43 | * 通过会员id创建默认属性 | ||
| 44 | * @param resources | ||
| 45 | * @return | ||
| 46 | */ | ||
| 47 | MemberProfile createDefaultByMemberId(Long resources); | ||
| 48 | |||
| 49 | /** | ||
| 50 | * 修改 | ||
| 51 | * @param resources | ||
| 52 | */ | ||
| 53 | MemberProfileDTO update(MemberProfile resources); | ||
| 42 | 54 | ||
| 55 | /** | ||
| 56 | * 删除 | ||
| 57 | * @param id | ||
| 58 | */ | ||
| 43 | void delete(Long id); | 59 | void delete(Long id); |
| 44 | 60 | ||
| 61 | /** | ||
| 62 | * 通过会员id查询 | ||
| 63 | * @param memberId | ||
| 64 | * @return | ||
| 65 | */ | ||
| 66 | MemberProfileDTO findByMemberId(Long memberId); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * 通过会员code查询 | ||
| 70 | * @param memberCode | ||
| 71 | * @return | ||
| 72 | */ | ||
| 73 | MemberProfileDTO findByMemberCode(String memberCode); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * 修改会员属性并同步会员信息 | ||
| 77 | * @param resources | ||
| 78 | */ | ||
| 79 | MemberProfileDTO updateMemberProfileAndMember(MemberProfile resources, MemberDTO memberDTO); | ||
| 45 | } | 80 | } | ... | ... |
| ... | @@ -13,51 +13,64 @@ import java.sql.Timestamp; | ... | @@ -13,51 +13,64 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class MemberProfileDTO implements Serializable { | 14 | public class MemberProfileDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // 主键 | 16 | /** 会员code */ |
| 17 | private String memberCode; | ||
| 18 | |||
| 19 | /** 主键 */ | ||
| 17 | private Long id; | 20 | private Long id; |
| 18 | 21 | ||
| 19 | // 会员id | 22 | /** 会员id */ |
| 20 | private Long memberId; | 23 | private Long memberId; |
| 21 | 24 | ||
| 22 | // 手机号 | 25 | /** 姓名 */ |
| 23 | private String phone; | ||
| 24 | |||
| 25 | // 姓名 | ||
| 26 | private String realname; | 26 | private String realname; |
| 27 | 27 | ||
| 28 | // 性别 0:女; 1:男 -1:未知 | 28 | /** 性别 0:女; 1:男 -1:未知 */ |
| 29 | private Integer gender; | 29 | private Integer gender; |
| 30 | 30 | ||
| 31 | // 生日 | 31 | /** 生日 */ |
| 32 | private Timestamp birthday; | 32 | private String birthday; |
| 33 | |||
| 34 | /** 电话 */ | ||
| 35 | private String phone; | ||
| 33 | 36 | ||
| 34 | // 星座 | 37 | /** 星座 */ |
| 35 | private String constellation; | 38 | private String constellation; |
| 36 | 39 | ||
| 37 | // 身份证 | 40 | /** 身份证 */ |
| 38 | private String idCard; | 41 | private String idCard; |
| 39 | 42 | ||
| 40 | // 电子邮件 | 43 | /** 电子邮件 */ |
| 41 | private String email; | 44 | private String email; |
| 42 | 45 | ||
| 43 | // 国家 | 46 | /** 国家 */ |
| 44 | private String country; | 47 | private String country; |
| 45 | 48 | ||
| 46 | // 省份 | 49 | /** 省份 */ |
| 47 | private String province; | 50 | private String province; |
| 48 | 51 | ||
| 49 | // 城市 | 52 | /** 城市 */ |
| 50 | private String city; | 53 | private String city; |
| 51 | 54 | ||
| 52 | // 区县 | 55 | /** 区县 */ |
| 53 | private String district; | 56 | private String district; |
| 54 | 57 | ||
| 55 | // 描述 | 58 | /** 描述 */ |
| 56 | private String description; | 59 | private String description; |
| 57 | 60 | ||
| 58 | // 创建时间 | 61 | /** 创建时间 */ |
| 59 | private Timestamp createTime; | 62 | private Timestamp createTime; |
| 60 | 63 | ||
| 61 | // 更新时间 | 64 | /** 更新时间 */ |
| 62 | private Timestamp updateTime; | 65 | private Timestamp updateTime; |
| 66 | |||
| 67 | |||
| 68 | /** vip */ | ||
| 69 | private Integer vip; | ||
| 70 | |||
| 71 | /** vip过期时间 */ | ||
| 72 | private Long vipExpireTime; | ||
| 73 | |||
| 74 | /** 头像 */ | ||
| 75 | private String avatarUrl; | ||
| 63 | } | 76 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.profile.service.impl; | 1 | package com.topdraw.business.module.member.profile.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 3 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | 4 | import com.topdraw.business.module.member.profile.domain.MemberProfile; |
| 5 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; | ||
| 4 | import com.topdraw.business.module.member.profile.repository.MemberProfileRepository; | 6 | import com.topdraw.business.module.member.profile.repository.MemberProfileRepository; |
| 5 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | 7 | import com.topdraw.business.module.member.profile.service.MemberProfileService; |
| 6 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | 8 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; |
| 7 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileQueryCriteria; | ||
| 8 | import com.topdraw.business.module.member.profile.service.mapper.MemberProfileMapper; | 9 | import com.topdraw.business.module.member.profile.service.mapper.MemberProfileMapper; |
| 9 | import com.topdraw.business.module.member.service.MemberService; | 10 | import com.topdraw.business.module.member.service.MemberService; |
| 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 11 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 11 | import com.topdraw.utils.PageUtil; | 12 | import com.topdraw.util.Base64Util; |
| 12 | import com.topdraw.utils.QueryHelp; | 13 | import com.topdraw.utils.RedisUtils; |
| 13 | import com.topdraw.utils.StringUtils; | 14 | import com.topdraw.utils.StringUtils; |
| 14 | import com.topdraw.utils.ValidationUtil; | 15 | import com.topdraw.utils.ValidationUtil; |
| 16 | import lombok.extern.slf4j.Slf4j; | ||
| 17 | import org.springframework.beans.BeanUtils; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.dao.EmptyResultDataAccessException; | 19 | import org.springframework.dao.EmptyResultDataAccessException; |
| 17 | import org.springframework.data.domain.Page; | ||
| 18 | import org.springframework.data.domain.Pageable; | ||
| 19 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.annotation.Propagation; | 21 | import org.springframework.transaction.annotation.Propagation; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.util.Assert; | 23 | import org.springframework.util.Assert; |
| 23 | 24 | ||
| 24 | import java.util.List; | ||
| 25 | import java.util.Map; | ||
| 26 | import java.util.Objects; | 25 | import java.util.Objects; |
| 27 | 26 | ||
| 27 | |||
| 28 | /** | 28 | /** |
| 29 | * @author XiangHan | 29 | * @author XiangHan |
| 30 | * @date 2021-10-22 | 30 | * @date 2021-10-22 |
| 31 | */ | 31 | */ |
| 32 | @Service | 32 | @Service |
| 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 34 | @Slf4j | ||
| 34 | public class MemberProfileServiceImpl implements MemberProfileService { | 35 | public class MemberProfileServiceImpl implements MemberProfileService { |
| 35 | 36 | ||
| 36 | @Autowired | 37 | @Autowired |
| 37 | private MemberProfileRepository MemberProfileRepository; | 38 | private MemberService memberService; |
| 38 | |||
| 39 | @Autowired | 39 | @Autowired |
| 40 | private MemberProfileMapper MemberProfileMapper; | 40 | private MemberProfileMapper memberProfileMapper; |
| 41 | @Autowired | 41 | @Autowired |
| 42 | private MemberService memberService; | 42 | private MemberProfileRepository memberProfileRepository; |
| 43 | 43 | ||
| 44 | @Override | 44 | @Override |
| 45 | public Map<String, Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable) { | 45 | public MemberProfileDTO findById(Long id) { |
| 46 | Page<MemberProfile> page = MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 46 | MemberProfile MemberProfile = this.memberProfileRepository.findById(id).orElseGet(MemberProfile::new); |
| 47 | return PageUtil.toPage(page.map(MemberProfileMapper::toDto)); | 47 | ValidationUtil.isNull(MemberProfile.getId(),"MemberProfile","id",id); |
| 48 | return this.memberProfileMapper.toDto(MemberProfile); | ||
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | @Override | 51 | @Override |
| 51 | public List<MemberProfileDTO> queryAll(MemberProfileQueryCriteria criteria) { | 52 | public MemberProfileDTO findByMemberId(Long memberId) { |
| 52 | return MemberProfileMapper.toDto(MemberProfileRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 53 | log.info("MemberProfileDTO ==>> findByMemberId ==>> resources ===>> [{}]",memberId); |
| 54 | MemberProfile memberProfile = this.memberProfileRepository.findByMemberId(memberId).orElseGet(MemberProfile::new); | ||
| 55 | return this.memberProfileMapper.toDto(memberProfile); | ||
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | @Override | 58 | @Override |
| 56 | public MemberProfileDTO findById(Long id) { | 59 | public MemberProfileDTO findByMemberCode(String memberCode) { |
| 57 | MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseGet(MemberProfile::new); | 60 | log.info("MemberProfileDTO ==>> findByMemberCode ==>> resources ===>> [{}]",memberCode); |
| 58 | ValidationUtil.isNull(MemberProfile.getId(),"MemberProfile","id",id); | 61 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
| 59 | return MemberProfileMapper.toDto(MemberProfile); | 62 | log.info("MemberProfileDTO ==>> findByMemberCode ==>> result ===>> [{}]",memberDTO); |
| 63 | return this.findByMemberId(memberDTO.getId()); | ||
| 60 | } | 64 | } |
| 61 | 65 | ||
| 62 | @Override | 66 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 67 | @Transactional(rollbackFor = Exception.class) |
| 64 | public MemberProfile create(MemberProfile resources) { | 68 | public MemberProfile create(MemberProfile resources) { |
| 65 | String memberCode = resources.getMemberCode(); | 69 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); |
| 66 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 70 | |
| 67 | if (Objects.nonNull(memberDTO)) { | 71 | // 检查会员 |
| 68 | String code = memberDTO.getCode(); | 72 | this.checkMember(resources); |
| 69 | if (StringUtils.isNotEmpty(code)) { | 73 | |
| 70 | resources.setMemberCode(code); | 74 | this.memberProfileRepository.save(resources); |
| 71 | resources.setMemberId(memberDTO.getId()); | ||
| 72 | resources.setId(null); | ||
| 73 | MemberProfileRepository.save(resources); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | 75 | ||
| 77 | return resources; | 76 | return resources; |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | @Override | 79 | @Override |
| 81 | @Transactional(rollbackFor = Exception.class) | 80 | @Transactional(rollbackFor = Exception.class) |
| 82 | public void update(MemberProfile resources) { | 81 | public MemberProfile createDefault(MemberProfile resources) { |
| 82 | MemberProfile memberProfile = MemberProfileBuilder.build(resources); | ||
| 83 | return this.create(memberProfile); | ||
| 84 | } | ||
| 85 | |||
| 86 | @Override | ||
| 87 | @Transactional(rollbackFor = Exception.class) | ||
| 88 | public MemberProfile createDefault(Member resources) { | ||
| 89 | MemberProfile memberProfile = MemberProfileBuilder.build(resources); | ||
| 90 | return this.create(memberProfile); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Override | ||
| 94 | public MemberProfile createDefaultByMemberId(Long resources) { | ||
| 95 | MemberProfile memberProfile = MemberProfileBuilder.build(resources); | ||
| 96 | return this.create(memberProfile); | ||
| 97 | } | ||
| 83 | 98 | ||
| 99 | private MemberDTO checkMember(MemberProfile resources){ | ||
| 100 | Long memberId = resources.getMemberId(); | ||
| 84 | String memberCode = resources.getMemberCode(); | 101 | String memberCode = resources.getMemberCode(); |
| 85 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 102 | log.info("checkMember ==>> memberId ==>> {} || memberCode ==>> {}", memberId, memberCode); |
| 86 | if (Objects.nonNull(memberDTO)) { | 103 | return this.memberService.checkMember(memberId,memberCode); |
| 87 | Long memberId = memberDTO.getId(); | 104 | } |
| 88 | 105 | ||
| 89 | MemberProfile memberProfile = MemberProfileRepository.findByMemberId(memberId); | 106 | @Override |
| 90 | if (Objects.nonNull(memberProfile)) { | 107 | @Transactional(rollbackFor = Exception.class) |
| 91 | ValidationUtil.isNull( memberProfile.getId(),"MemberProfile","id",memberProfile.getId()); | 108 | public MemberProfileDTO update(MemberProfile resources) { |
| 92 | resources.setId(memberProfile.getId()); | 109 | |
| 93 | } else { | 110 | log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); |
| 94 | resources.setId(null); | 111 | // 检查会员是否存在 |
| 95 | } | 112 | MemberDTO memberDTO = this.checkMember(resources); |
| 96 | 113 | ||
| 97 | resources.setMemberId(memberId); | 114 | MemberProfileDTO _memberProfileDTO = this.findByMemberId(memberDTO.getId()); |
| 98 | memberProfile.copy(resources); | 115 | |
| 99 | MemberProfileRepository.save(memberProfile); | 116 | if (Objects.nonNull(_memberProfileDTO.getId())) { |
| 117 | resources.setId(_memberProfileDTO.getId()); | ||
| 118 | resources.setCreateTime(_memberProfileDTO.getCreateTime()); | ||
| 100 | } | 119 | } |
| 120 | |||
| 121 | resources.setMemberId(memberDTO.getId()); | ||
| 122 | |||
| 123 | log.info("memberProfileServiceImpl ==>> update ==>> memberId ==>> {} || resources =>> {}", memberDTO.getId(), resources); | ||
| 124 | MemberProfile _memberProfile = this.memberProfileRepository.save(resources); | ||
| 125 | |||
| 126 | MemberProfileDTO memberProfileDTO = new MemberProfileDTO(); | ||
| 127 | BeanUtils.copyProperties(_memberProfile, memberProfileDTO); | ||
| 128 | return memberProfileDTO; | ||
| 129 | |||
| 101 | } | 130 | } |
| 102 | 131 | ||
| 103 | @Override | 132 | @Override |
| 104 | @Transactional(rollbackFor = Exception.class) | 133 | @Transactional(rollbackFor = Exception.class) |
| 105 | public void delete(Long id) { | 134 | public void delete(Long id) { |
| 106 | Assert.notNull(id, "The given id must not be null!"); | 135 | Assert.notNull(id, "The given id must not be null!"); |
| 107 | MemberProfile MemberProfile = MemberProfileRepository.findById(id).orElseThrow( | 136 | MemberProfile MemberProfile = this.memberProfileRepository.findById(id).orElseThrow( |
| 108 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberProfile.class, id), 1)); | 137 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberProfile.class, id), 1)); |
| 109 | MemberProfileRepository.delete(MemberProfile); | 138 | this.memberProfileRepository.delete(MemberProfile); |
| 139 | } | ||
| 140 | |||
| 141 | @Override | ||
| 142 | @Transactional(rollbackFor = Exception.class) | ||
| 143 | public MemberProfileDTO updateMemberProfileAndMember(MemberProfile resources, MemberDTO memberDTO) { | ||
| 144 | log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources); | ||
| 145 | MemberProfileDTO memberProfileDTO = this.update(resources); | ||
| 146 | // 同步会员信息 | ||
| 147 | this.synchronizedMemberData(resources, memberDTO); | ||
| 148 | return memberProfileDTO; | ||
| 110 | } | 149 | } |
| 111 | 150 | ||
| 151 | private void synchronizedMemberData(MemberProfile resources, MemberDTO memberDTO) { | ||
| 112 | 152 | ||
| 153 | log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",resources); | ||
| 154 | |||
| 155 | memberDTO.setId(resources.getMemberId()); | ||
| 156 | memberDTO.setCode(resources.getMemberCode()); | ||
| 157 | memberDTO.setNickname(resources.getRealname()); | ||
| 158 | memberDTO.setGender(resources.getGender()); | ||
| 159 | memberDTO.setBirthday(resources.getBirthday()); | ||
| 160 | memberDTO.setAvatarUrl(resources.getAvatarUrl()); | ||
| 161 | |||
| 162 | Member member = new Member(); | ||
| 163 | BeanUtils.copyProperties(memberDTO,member); | ||
| 164 | |||
| 165 | this.memberService.update(member); | ||
| 166 | } | ||
| 113 | } | 167 | } | ... | ... |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.relatedinfo.domain; | ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.member.relatedinfo.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 6 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 9 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -9,8 +11,10 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -9,8 +11,10 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 11 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 12 | ||
| 11 | import javax.persistence.*; | 13 | import javax.persistence.*; |
| 14 | import javax.validation.constraints.NotNull; | ||
| 12 | import java.io.Serializable; | 15 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 16 | import java.sql.Timestamp; |
| 17 | import java.time.LocalDate; | ||
| 14 | 18 | ||
| 15 | /** | 19 | /** |
| 16 | * @author XiangHan | 20 | * @author XiangHan |
| ... | @@ -21,47 +25,53 @@ import java.sql.Timestamp; | ... | @@ -21,47 +25,53 @@ import java.sql.Timestamp; |
| 21 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
| 22 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
| 23 | @Table(name="uc_member_related_info") | 27 | @Table(name="uc_member_related_info") |
| 24 | public class MemberRelatedInfo implements Serializable { | 28 | public class MemberRelatedInfo extends AsyncMqModule implements Serializable { |
| 25 | 29 | ||
| 26 | // ID | 30 | /** ID */ |
| 27 | @Id | 31 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 33 | @Column(name = "id") |
| 34 | @NotNull(message = "id can't be null" , groups = {UpdateGroup.class}) | ||
| 30 | private Long id; | 35 | private Long id; |
| 31 | 36 | ||
| 32 | // 会员id | 37 | /** 会员id */ |
| 33 | @Column(name = "member_id", nullable = false) | 38 | @Column(name = "member_id", nullable = false) |
| 34 | private Long memberId; | 39 | private Long memberId; |
| 35 | 40 | ||
| 36 | @Transient | 41 | /** 人物关系 0:子女;1:父母 */ |
| 37 | private String memberCode; | ||
| 38 | |||
| 39 | // 人物关系 0:子女;1:父母 | ||
| 40 | @Column(name = "type") | 42 | @Column(name = "type") |
| 41 | private Integer type; | 43 | private Integer type; |
| 42 | 44 | ||
| 43 | // 手机号 | 45 | /** 手机号 */ |
| 44 | @Column(name = "cellphone") | 46 | @Column(name = "cellphone") |
| 45 | private String cellphone; | 47 | private String cellphone; |
| 46 | 48 | ||
| 47 | // 身份证号 | 49 | /** 身份证号 */ |
| 48 | @Column(name = "id_card") | 50 | @Column(name = "id_card") |
| 49 | private String idCard; | 51 | private String idCard; |
| 50 | 52 | ||
| 51 | // 姓名 | 53 | /** 姓名 */ |
| 52 | @Column(name = "name") | 54 | @Column(name = "name") |
| 53 | private String name; | 55 | private String name; |
| 54 | 56 | ||
| 55 | // 性别 0:女;1:男;-1:未知 | 57 | /** 性别 0:女;1:男;-1:未知 */ |
| 56 | @Column(name = "sex") | 58 | @Column(name = "sex") |
| 57 | private Integer sex; | 59 | private Integer sex; |
| 58 | 60 | ||
| 59 | // 创建时间 | 61 | /** 生日 */ |
| 62 | @Column(name = "birthday") | ||
| 63 | private LocalDate birthday; | ||
| 64 | |||
| 65 | /** 头像地址 */ | ||
| 66 | @Column(name = "avatar_url") | ||
| 67 | private String avatarUrl; | ||
| 68 | |||
| 69 | /** 创建时间 */ | ||
| 60 | @CreatedDate | 70 | @CreatedDate |
| 61 | @Column(name = "create_time") | 71 | @Column(name = "create_time") |
| 62 | private Timestamp createTime; | 72 | private Timestamp createTime; |
| 63 | 73 | ||
| 64 | // 更新时间 | 74 | /** 更新时间 */ |
| 65 | @LastModifiedDate | 75 | @LastModifiedDate |
| 66 | @Column(name = "update_time") | 76 | @Column(name = "update_time") |
| 67 | private Timestamp updateTime; | 77 | private Timestamp updateTime; | ... | ... |
src/main/java/com/topdraw/business/module/member/relatedinfo/domain/MemberRelatedInfoBuilder.java
0 → 100644
| 1 | package com.topdraw.business.module.member.relatedinfo.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.util.Assert; | ||
| 7 | |||
| 8 | import java.time.LocalDate; | ||
| 9 | import java.util.Objects; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/11 13:56 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/11 13:56 | ||
| 19 | */ | ||
| 20 | public class MemberRelatedInfoBuilder { | ||
| 21 | |||
| 22 | private static final Integer DEFAULT_VALUE_ = -1; | ||
| 23 | private static final Integer DEFAULT_VALUE_0 = 0; | ||
| 24 | |||
| 25 | public static MemberRelatedInfo build(MemberRelatedInfo memberRelatedInfo){ | ||
| 26 | return build(memberRelatedInfo.getMemberId(),memberRelatedInfo.getMemberCode(),memberRelatedInfo.getId(),memberRelatedInfo.getName(),memberRelatedInfo.getSex(), | ||
| 27 | memberRelatedInfo.getCellphone(),memberRelatedInfo.getIdCard(),memberRelatedInfo.getBirthday(),memberRelatedInfo.getAvatarUrl(),memberRelatedInfo.getType()); | ||
| 28 | } | ||
| 29 | |||
| 30 | public static MemberRelatedInfo build(Member member , MemberRelatedInfo memberRelatedInfo){ | ||
| 31 | return build(member.getId(),member.getCode(),memberRelatedInfo.getId(),memberRelatedInfo.getName(),memberRelatedInfo.getSex(), | ||
| 32 | memberRelatedInfo.getCellphone(),memberRelatedInfo.getIdCard(),memberRelatedInfo.getBirthday(),memberRelatedInfo.getAvatarUrl(),memberRelatedInfo.getType()); | ||
| 33 | } | ||
| 34 | |||
| 35 | public static MemberRelatedInfo build(Long memberId , String memberCode , Long id , String name , Integer sex , | ||
| 36 | String cellphone , String idCard, LocalDate birthday , String avatarUrl , Integer type){ | ||
| 37 | |||
| 38 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 39 | |||
| 40 | MemberRelatedInfo memberRelatedInfo = new MemberRelatedInfo(); | ||
| 41 | memberRelatedInfo.setMemberId(memberId); | ||
| 42 | memberRelatedInfo.setMemberCode(memberCode); | ||
| 43 | |||
| 44 | memberRelatedInfo.setId(id); | ||
| 45 | memberRelatedInfo.setName(stringIsNull(name)); | ||
| 46 | memberRelatedInfo.setSex(Objects.isNull(sex)?DEFAULT_VALUE_:sex); | ||
| 47 | memberRelatedInfo.setCellphone(stringIsNull(cellphone)); | ||
| 48 | memberRelatedInfo.setIdCard(StringUtils.isBlank(idCard)?"000000000000000000":idCard); | ||
| 49 | |||
| 50 | memberRelatedInfo.setBirthday(Objects.isNull(birthday)? LocalDate.of(1990,01,01):birthday); | ||
| 51 | memberRelatedInfo.setAvatarUrl(stringIsNull(avatarUrl)); | ||
| 52 | |||
| 53 | memberRelatedInfo.setType(Objects.isNull(type)?DEFAULT_VALUE_0:type); | ||
| 54 | return memberRelatedInfo; | ||
| 55 | } | ||
| 56 | |||
| 57 | private static String stringIsNull(String s){ | ||
| 58 | return StringUtils.isBlank(s)?"":s; | ||
| 59 | } | ||
| 60 | |||
| 61 | } |
| ... | @@ -4,7 +4,6 @@ import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | ... | @@ -4,7 +4,6 @@ import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | 6 | ||
| 7 | import java.util.List; | ||
| 8 | 7 | ||
| 9 | /** | 8 | /** |
| 10 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -12,5 +11,10 @@ import java.util.List; | ... | @@ -12,5 +11,10 @@ import java.util.List; |
| 12 | */ | 11 | */ |
| 13 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { | 12 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { |
| 14 | 13 | ||
| 15 | List<MemberRelatedInfo> findByMemberIdAndIdCard(Long memberDTOId,String idCard); | 14 | MemberRelatedInfo findByIdCard(String idCard); |
| 15 | |||
| 16 | MemberRelatedInfo findByMemberIdAndIdCard(Long memberId, String idCard); | ||
| 17 | |||
| 18 | MemberRelatedInfo findByIdOrIdCard(Long id, String idCard); | ||
| 19 | |||
| 16 | } | 20 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.relatedinfo.service; | 1 | package com.topdraw.business.module.member.relatedinfo.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 3 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
| 4 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 5 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
| 5 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 6 | ||
| 11 | /** | 7 | /** |
| 12 | * @author XiangHan | 8 | * @author XiangHan |
| ... | @@ -15,31 +11,72 @@ import java.util.Map; | ... | @@ -15,31 +11,72 @@ import java.util.Map; |
| 15 | public interface MemberRelatedInfoService { | 11 | public interface MemberRelatedInfoService { |
| 16 | 12 | ||
| 17 | /** | 13 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<MemberRelatedInfoDTO> | ||
| 29 | */ | ||
| 30 | List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 14 | * 根据ID查询 |
| 34 | * @param id ID | 15 | * @param id ID |
| 35 | * @return MemberRelatedInfoDTO | 16 | * @return MemberRelatedInfoDTO |
| 36 | */ | 17 | */ |
| 37 | MemberRelatedInfoDTO findById(Long id); | 18 | MemberRelatedInfoDTO findById(Long id); |
| 38 | 19 | ||
| 39 | void create(MemberRelatedInfo resources); | 20 | /** |
| 21 | * 新增 | ||
| 22 | * @param resources | ||
| 23 | */ | ||
| 24 | MemberRelatedInfoDTO create(MemberRelatedInfo resources); | ||
| 40 | 25 | ||
| 41 | void update(MemberRelatedInfo resources); | 26 | /** |
| 27 | * 修改 | ||
| 28 | * @param resources | ||
| 29 | */ | ||
| 30 | MemberRelatedInfoDTO update(MemberRelatedInfo resources); | ||
| 42 | 31 | ||
| 32 | /** | ||
| 33 | * 删除 | ||
| 34 | * @param id | ||
| 35 | */ | ||
| 43 | void delete(Long id); | 36 | void delete(Long id); |
| 44 | 37 | ||
| 38 | /** | ||
| 39 | * 通过身份证查询 | ||
| 40 | * @param resources | ||
| 41 | * @return | ||
| 42 | */ | ||
| 43 | MemberRelatedInfoDTO findByIdCard(MemberRelatedInfo resources); | ||
| 44 | |||
| 45 | /** | ||
| 46 | * 通过身份证查询 | ||
| 47 | * @param idCard 身份证 | ||
| 48 | * @return | ||
| 49 | */ | ||
| 50 | MemberRelatedInfoDTO findByIdCard(String idCard); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * | ||
| 54 | * @param memberId | ||
| 55 | * @param idCard | ||
| 56 | * @return | ||
| 57 | */ | ||
| 58 | MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId, String idCard); | ||
| 59 | |||
| 60 | /** | ||
| 61 | * | ||
| 62 | * @param memberCode | ||
| 63 | * @param idCard | ||
| 64 | * @return | ||
| 65 | */ | ||
| 66 | MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode, String idCard); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * | ||
| 70 | * @param resources | ||
| 71 | * @return | ||
| 72 | */ | ||
| 73 | MemberRelatedInfoDTO findByMemberIdAndIdCard(MemberRelatedInfo resources); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * | ||
| 77 | * @param member | ||
| 78 | * @param resources | ||
| 79 | * @return | ||
| 80 | */ | ||
| 81 | MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources); | ||
| 45 | } | 82 | } | ... | ... |
| ... | @@ -4,6 +4,7 @@ import lombok.Data; | ... | @@ -4,6 +4,7 @@ import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 6 | import java.sql.Timestamp; |
| 7 | import java.time.LocalDate; | ||
| 7 | 8 | ||
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| ... | @@ -34,6 +35,12 @@ public class MemberRelatedInfoDTO implements Serializable { | ... | @@ -34,6 +35,12 @@ public class MemberRelatedInfoDTO implements Serializable { |
| 34 | // 性别 0:女;1:男;-1:未知 | 35 | // 性别 0:女;1:男;-1:未知 |
| 35 | private Integer sex; | 36 | private Integer sex; |
| 36 | 37 | ||
| 38 | // 生日 | ||
| 39 | private LocalDate birthday; | ||
| 40 | |||
| 41 | // 头像地址 | ||
| 42 | private String avatarUrl; | ||
| 43 | |||
| 37 | // 创建时间 | 44 | // 创建时间 |
| 38 | private Timestamp createTime; | 45 | private Timestamp createTime; |
| 39 | 46 | ... | ... |
| 1 | package com.topdraw.business.module.member.relatedinfo.service.impl; | 1 | package com.topdraw.business.module.member.relatedinfo.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 3 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; |
| 5 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfoBuilder; | ||
| 4 | import com.topdraw.business.module.member.relatedinfo.repository.MemberRelatedInfoRepository; | 6 | import com.topdraw.business.module.member.relatedinfo.repository.MemberRelatedInfoRepository; |
| 5 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; | 7 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; |
| 6 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 8 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
| 7 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | ||
| 8 | import com.topdraw.business.module.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; | 9 | import com.topdraw.business.module.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; |
| 9 | import com.topdraw.business.module.member.service.MemberService; | 10 | import com.topdraw.business.module.member.service.MemberService; |
| 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 11 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 11 | import com.topdraw.utils.PageUtil; | 12 | import com.topdraw.exception.BadRequestException; |
| 12 | import com.topdraw.utils.QueryHelp; | 13 | import com.topdraw.exception.GlobeExceptionMsg; |
| 14 | import com.topdraw.util.Base64Util; | ||
| 15 | import com.topdraw.utils.RedisUtils; | ||
| 13 | import com.topdraw.utils.ValidationUtil; | 16 | import com.topdraw.utils.ValidationUtil; |
| 17 | import lombok.extern.slf4j.Slf4j; | ||
| 18 | import org.apache.commons.lang3.StringUtils; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.dao.EmptyResultDataAccessException; | 20 | import org.springframework.dao.EmptyResultDataAccessException; |
| 16 | import org.springframework.data.domain.Page; | ||
| 17 | import org.springframework.data.domain.Pageable; | ||
| 18 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 19 | import org.springframework.transaction.annotation.Propagation; | 22 | import org.springframework.transaction.annotation.Propagation; |
| 20 | import org.springframework.transaction.annotation.Transactional; | 23 | import org.springframework.transaction.annotation.Transactional; |
| 21 | import org.springframework.util.Assert; | 24 | import org.springframework.util.Assert; |
| 22 | import org.springframework.util.CollectionUtils; | ||
| 23 | 25 | ||
| 24 | import java.util.List; | ||
| 25 | import java.util.Map; | ||
| 26 | import java.util.Objects; | 26 | import java.util.Objects; |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| ... | @@ -31,60 +31,93 @@ import java.util.Objects; | ... | @@ -31,60 +31,93 @@ import java.util.Objects; |
| 31 | */ | 31 | */ |
| 32 | @Service | 32 | @Service |
| 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 34 | @Slf4j | ||
| 34 | public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | 35 | public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { |
| 35 | 36 | ||
| 36 | @Autowired | 37 | @Autowired |
| 37 | private MemberRelatedInfoRepository MemberRelatedInfoRepository; | 38 | private MemberService memberService; |
| 38 | |||
| 39 | @Autowired | 39 | @Autowired |
| 40 | private MemberRelatedInfoMapper MemberRelatedInfoMapper; | 40 | private MemberRelatedInfoMapper memberRelatedInfoMapper; |
| 41 | @Autowired | 41 | @Autowired |
| 42 | private MemberService memberService; | 42 | private MemberRelatedInfoRepository memberRelatedInfoRepository; |
| 43 | |||
| 44 | private static final String DEFAULT_IDCARD = "000000000000000000"; | ||
| 43 | 45 | ||
| 44 | @Override | 46 | @Override |
| 45 | public Map<String, Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable) { | 47 | public MemberRelatedInfoDTO findById(Long id) { |
| 46 | Page<MemberRelatedInfo> page = MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 48 | log.info("MemberRelatedInfoServiceImpl ==>> findById ==>> param ==>> [{}]",id); |
| 47 | return PageUtil.toPage(page.map(MemberRelatedInfoMapper::toDto)); | 49 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new); |
| 50 | ValidationUtil.isNull(memberRelatedInfo.getId(),"MemberRelatedInfo","id",id); | ||
| 51 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); | ||
| 48 | } | 52 | } |
| 49 | 53 | ||
| 50 | @Override | 54 | @Override |
| 51 | public List<MemberRelatedInfoDTO> queryAll(MemberRelatedInfoQueryCriteria criteria) { | 55 | @Transactional(rollbackFor = Exception.class) |
| 52 | return MemberRelatedInfoMapper.toDto(MemberRelatedInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 56 | public MemberRelatedInfoDTO create(MemberRelatedInfo resources) { |
| 57 | log.info("MemberRelatedInfoServiceImpl ==>> create ==>> param ==>> [{}]",resources); | ||
| 58 | String idCard = resources.getIdCard(); | ||
| 59 | Long memberId = resources.getMemberId(); | ||
| 60 | if (Objects.nonNull(memberId) && StringUtils.isNotBlank(idCard) && !idCard.equalsIgnoreCase(DEFAULT_IDCARD) ) { | ||
| 61 | MemberRelatedInfoDTO memberRelatedInfo = this.findByMemberIdAndIdCard(resources); | ||
| 62 | if (Objects.nonNull(memberRelatedInfo)) | ||
| 63 | // 数据已存在 | ||
| 64 | throw new BadRequestException(GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); | ||
| 65 | } | ||
| 66 | |||
| 67 | this.checkMemberAndEncodeRealname(resources); | ||
| 68 | |||
| 69 | MemberRelatedInfo memberRelatedInfo = MemberRelatedInfoBuilder.build(resources); | ||
| 70 | this.memberRelatedInfoRepository.save(memberRelatedInfo); | ||
| 71 | log.info("MemberRelatedInfoServiceImpl ==>> create ==>> result ==>> [{}]",memberRelatedInfo); | ||
| 72 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); | ||
| 53 | } | 73 | } |
| 54 | 74 | ||
| 55 | @Override | 75 | /** |
| 56 | public MemberRelatedInfoDTO findById(Long id) { | 76 | * 检查会员是否存在,加密真实姓名 |
| 57 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseGet(MemberRelatedInfo::new); | 77 | * @param resources |
| 58 | ValidationUtil.isNull(MemberRelatedInfo.getId(),"MemberRelatedInfo","id",id); | 78 | */ |
| 59 | return MemberRelatedInfoMapper.toDto(MemberRelatedInfo); | 79 | private void checkMemberAndEncodeRealname(MemberRelatedInfo resources) { |
| 80 | |||
| 81 | // 检查会员是否存在 | ||
| 82 | this.checkMember(resources); | ||
| 83 | |||
| 84 | // 加密真实姓名 | ||
| 85 | this.encodeRealname(resources); | ||
| 60 | } | 86 | } |
| 61 | 87 | ||
| 62 | @Override | 88 | /** |
| 63 | @Transactional(rollbackFor = Exception.class) | 89 | * 加密真实姓名 |
| 64 | public void create(MemberRelatedInfo resources) { | 90 | * @param resources |
| 65 | MemberRelatedInfoRepository.save(resources); | 91 | * @return |
| 92 | */ | ||
| 93 | private void encodeRealname(MemberRelatedInfo resources){ | ||
| 94 | String name = resources.getName(); | ||
| 95 | if (StringUtils.isNotBlank(name)) { | ||
| 96 | String nickNameEncode = Base64Util.encode(name); | ||
| 97 | if (!nickNameEncode.equalsIgnoreCase(name)) | ||
| 98 | resources.setName(nickNameEncode); | ||
| 99 | } | ||
| 66 | } | 100 | } |
| 67 | 101 | ||
| 68 | @Override | 102 | @Override |
| 69 | @Transactional(rollbackFor = Exception.class) | 103 | @Transactional(rollbackFor = Exception.class) |
| 70 | public void update(MemberRelatedInfo resources) { | 104 | public MemberRelatedInfoDTO update(MemberRelatedInfo resources) { |
| 71 | 105 | log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]",resources); | |
| 72 | String memberCode = resources.getMemberCode(); | 106 | try { |
| 73 | Assert.notNull(memberCode,"memberCode can't be null!"); | 107 | |
| 74 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 108 | this.checkMemberAndEncodeRealname(resources); |
| 75 | if (Objects.nonNull(memberDTO)) { | 109 | |
| 76 | Long memberDTOId = memberDTO.getId(); | 110 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new); |
| 77 | String idCard = resources.getIdCard(); | 111 | ValidationUtil.isNull(memberRelatedInfo.getId(), "MemberRelatedInfo", "id", resources.getId()); |
| 78 | List<MemberRelatedInfo> memberRelatedInfoDTOS = MemberRelatedInfoRepository.findByMemberIdAndIdCard(memberDTOId,idCard); | 112 | memberRelatedInfo.copy(resources); |
| 79 | if (!CollectionUtils.isEmpty(memberRelatedInfoDTOS)) { | 113 | |
| 80 | for (MemberRelatedInfo memberRelatedInfoDTO : memberRelatedInfoDTOS) { | 114 | this.memberRelatedInfoRepository.save(memberRelatedInfo); |
| 81 | ValidationUtil.isNull( memberRelatedInfoDTO.getId(),"MemberRelatedInfo","id",memberRelatedInfoDTO.getId()); | 115 | |
| 82 | resources.setId(memberRelatedInfoDTO.getId()); | 116 | log.info("MemberRelatedInfoServiceImpl ==>> update ==>> param ==>> [{}]", resources); |
| 83 | resources.setMemberId(memberDTOId); | 117 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); |
| 84 | memberRelatedInfoDTO.copy(resources); | 118 | } catch (Exception e) { |
| 85 | MemberRelatedInfoRepository.save(memberRelatedInfoDTO); | 119 | e.printStackTrace(); |
| 86 | } | 120 | throw e; |
| 87 | } | ||
| 88 | } | 121 | } |
| 89 | } | 122 | } |
| 90 | 123 | ||
| ... | @@ -92,10 +125,74 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | ... | @@ -92,10 +125,74 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { |
| 92 | @Transactional(rollbackFor = Exception.class) | 125 | @Transactional(rollbackFor = Exception.class) |
| 93 | public void delete(Long id) { | 126 | public void delete(Long id) { |
| 94 | Assert.notNull(id, "The given id must not be null!"); | 127 | Assert.notNull(id, "The given id must not be null!"); |
| 95 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(id).orElseThrow( | 128 | MemberRelatedInfo MemberRelatedInfo = this.memberRelatedInfoRepository.findById(id).orElseThrow( |
| 96 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberRelatedInfo.class, id), 1)); | 129 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo.class, id), 1)); |
| 97 | MemberRelatedInfoRepository.delete(MemberRelatedInfo); | 130 | this.memberRelatedInfoRepository.delete(MemberRelatedInfo); |
| 98 | } | 131 | } |
| 99 | 132 | ||
| 133 | @Override | ||
| 134 | public MemberRelatedInfoDTO findByIdCard(MemberRelatedInfo resources){ | ||
| 135 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> param ==>> [{}]",resources); | ||
| 136 | String idCard = resources.getIdCard(); | ||
| 137 | Assert.notNull(idCard,"idCard can't be null"); | ||
| 138 | |||
| 139 | if (!idCard.equalsIgnoreCase(DEFAULT_IDCARD)) { | ||
| 140 | MemberRelatedInfoDTO memberRelatedInfoDTO = this.findByIdCard(idCard); | ||
| 141 | ValidationUtil.isNull(memberRelatedInfoDTO.getId(),"MemberRelatedInfo","id",resources.getId()); | ||
| 142 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfoDTO); | ||
| 143 | return memberRelatedInfoDTO; | ||
| 144 | } | ||
| 145 | |||
| 146 | return null; | ||
| 147 | |||
| 148 | } | ||
| 149 | |||
| 150 | @Override | ||
| 151 | public MemberRelatedInfoDTO findByIdCard(String idCard) { | ||
| 152 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> param ==>> [{}]",idCard); | ||
| 153 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findByIdCard(idCard); | ||
| 154 | log.info("MemberRelatedInfoServiceImpl ==>> findByIdCard ==>> result ==>> [{}]",memberRelatedInfo); | ||
| 155 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); | ||
| 156 | } | ||
| 157 | |||
| 158 | @Override | ||
| 159 | public MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode, String idCard) { | ||
| 160 | Assert.notNull(memberCode,"memberCode can't be null"); | ||
| 161 | Assert.notNull(idCard,"idCard can't be null"); | ||
| 162 | MemberDTO memberDTO = this.checkMember(null, memberCode); | ||
| 163 | return this.findByMemberIdAndIdCard(memberDTO.getId(),idCard); | ||
| 164 | } | ||
| 165 | |||
| 166 | @Override | ||
| 167 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId, String idCard) { | ||
| 168 | log.info("MemberRelatedInfoServiceImpl ==>> findByMemberIdAndIdCard ==>> param ==>> [{}]",memberId+","+idCard); | ||
| 169 | MemberRelatedInfo memberRelatedInfo = this.memberRelatedInfoRepository.findByMemberIdAndIdCard(memberId, idCard); | ||
| 170 | log.info("MemberRelatedInfoServiceImpl ==>> findByMemberIdAndIdCard ==>> result ==>> [{}]",memberRelatedInfo); | ||
| 171 | return this.memberRelatedInfoMapper.toDto(memberRelatedInfo); | ||
| 172 | } | ||
| 173 | |||
| 174 | @Override | ||
| 175 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(MemberRelatedInfo resources) { | ||
| 176 | Long memberId = resources.getMemberId(); | ||
| 177 | String idCard = resources.getIdCard(); | ||
| 178 | return this.findByMemberIdAndIdCard(memberId,idCard); | ||
| 179 | } | ||
| 180 | |||
| 181 | @Override | ||
| 182 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources) { | ||
| 183 | Long memberId = member.getId(); | ||
| 184 | String idCard = resources.getIdCard(); | ||
| 185 | return this.findByMemberIdAndIdCard(memberId,idCard); | ||
| 186 | } | ||
| 187 | |||
| 188 | private MemberDTO checkMember(MemberRelatedInfo resources){ | ||
| 189 | Long memberId = resources.getMemberId(); | ||
| 190 | String code = resources.getMemberCode(); | ||
| 191 | return this.memberService.checkMember(memberId, code); | ||
| 192 | } | ||
| 193 | |||
| 194 | private MemberDTO checkMember(Long memberId , String memberCode){ | ||
| 195 | return this.memberService.checkMember(memberId, memberCode); | ||
| 196 | } | ||
| 100 | 197 | ||
| 101 | } | 198 | } | ... | ... |
| ... | @@ -3,9 +3,8 @@ package com.topdraw.business.module.member.repository; | ... | @@ -3,9 +3,8 @@ package com.topdraw.business.module.member.repository; |
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | 6 | ||
| 7 | import java.util.List; | ||
| 9 | import java.util.Optional; | 8 | import java.util.Optional; |
| 10 | 9 | ||
| 11 | /** | 10 | /** |
| ... | @@ -16,10 +15,7 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif | ... | @@ -16,10 +15,7 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif |
| 16 | 15 | ||
| 17 | Optional<Member> findFirstByCode(String code); | 16 | Optional<Member> findFirstByCode(String code); |
| 18 | 17 | ||
| 19 | Optional<Member> findByCode(String code); | 18 | List<Member> findByUserIptvId(Long id); |
| 20 | 19 | ||
| 21 | 20 | Optional<Member> findByIdOrCode(Long id, String code); | |
| 22 | @Modifying | ||
| 23 | @Query(value = "update uc_member set `points` = ?2 , `due_points` = ?3 where id = ?1 ",nativeQuery = true) | ||
| 24 | void updateMemberPoints(Long id, Long points, Long duePoints); | ||
| 25 | } | 21 | } | ... | ... |
| ... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.member.service; | ... | @@ -2,13 +2,8 @@ package com.topdraw.business.module.member.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.module.member.service.dto.MemberQueryCriteria; | ||
| 6 | import com.topdraw.business.module.user.iptv.domain.UserTv; | ||
| 7 | import org.springframework.data.domain.Pageable; | ||
| 8 | import org.springframework.transaction.annotation.Transactional; | ||
| 9 | 5 | ||
| 10 | import java.util.List; | 6 | import java.util.List; |
| 11 | import java.util.Map; | ||
| 12 | 7 | ||
| 13 | /** | 8 | /** |
| 14 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -16,20 +11,7 @@ import java.util.Map; | ... | @@ -16,20 +11,7 @@ import java.util.Map; |
| 16 | */ | 11 | */ |
| 17 | public interface MemberService { | 12 | public interface MemberService { |
| 18 | 13 | ||
| 19 | /** | ||
| 20 | * 查询数据分页 | ||
| 21 | * @param criteria 条件参数 | ||
| 22 | * @param pageable 分页参数 | ||
| 23 | * @return Map<String,Object> | ||
| 24 | */ | ||
| 25 | Map<String,Object> queryAll(MemberQueryCriteria criteria, Pageable pageable); | ||
| 26 | 14 | ||
| 27 | /** | ||
| 28 | * 查询所有数据不分页 | ||
| 29 | * @param criteria 条件参数 | ||
| 30 | * @return List<MemberDTO> | ||
| 31 | */ | ||
| 32 | List<MemberDTO> queryAll(MemberQueryCriteria criteria); | ||
| 33 | 15 | ||
| 34 | /** | 16 | /** |
| 35 | * 根据ID查询 | 17 | * 根据ID查询 |
| ... | @@ -38,24 +20,67 @@ public interface MemberService { | ... | @@ -38,24 +20,67 @@ public interface MemberService { |
| 38 | */ | 20 | */ |
| 39 | MemberDTO findById(Long id); | 21 | MemberDTO findById(Long id); |
| 40 | 22 | ||
| 41 | Long create(Member resources); | 23 | /** |
| 24 | * 通过code查询会员 | ||
| 25 | * @param code 会员编码 | ||
| 26 | * @return MemberDTO | ||
| 27 | */ | ||
| 28 | MemberDTO findByCode(String code); | ||
| 42 | 29 | ||
| 43 | void unbind(Member resources); | 30 | /** |
| 31 | * 保存 | ||
| 32 | * @param resources | ||
| 33 | * @return Long id | ||
| 34 | */ | ||
| 35 | MemberDTO create(Member resources); | ||
| 36 | |||
| 37 | /** | ||
| 38 | * 创建并返回会员 | ||
| 39 | * @param resources 会员 | ||
| 40 | * @return Member | ||
| 41 | */ | ||
| 42 | MemberDTO createAndReturnMember(Member resources); | ||
| 43 | |||
| 44 | /** | ||
| 45 | * 修改会员 | ||
| 46 | * @param resources | ||
| 47 | */ | ||
| 48 | MemberDTO update(Member resources); | ||
| 44 | 49 | ||
| 45 | void update(Member resources); | 50 | /** |
| 51 | * 修改会员积分 | ||
| 52 | * @param member 会员 | ||
| 53 | */ | ||
| 54 | MemberDTO doUpdateMemberPoints(Member member); | ||
| 46 | 55 | ||
| 47 | void delete(Long id); | 56 | /** |
| 57 | * 查询绑定了大屏会员列表 | ||
| 58 | * @param id 条件参数 | ||
| 59 | * @return Map<String,Object> | ||
| 60 | */ | ||
| 61 | List<MemberDTO> findByUserIptvId(Long id); | ||
| 48 | 62 | ||
| 49 | /** | 63 | /** |
| 50 | * Code校验 | 64 | * 检查会员信息 |
| 51 | * @param code | 65 | * @param id 会员id |
| 52 | * @return MemberDTO | 66 | * @param memberCode 会员编码 |
| 53 | */ | 67 | */ |
| 54 | MemberDTO getByCode(String code); | 68 | MemberDTO checkMember(Long id, String memberCode); |
| 55 | 69 | ||
| 56 | boolean createMemberByUserTv(UserTv resources); | 70 | /** |
| 71 | * 检查会员信息 | ||
| 72 | * @param member 会员 | ||
| 73 | */ | ||
| 74 | MemberDTO checkMember(Member member); | ||
| 75 | |||
| 76 | /** | ||
| 77 | * | ||
| 78 | * @param resources | ||
| 79 | */ | ||
| 80 | MemberDTO doUpdateMemberExpAndLevel(Member resources); | ||
| 81 | |||
| 82 | MemberDTO unbindUserIpTv(Member member); | ||
| 57 | 83 | ||
| 58 | void doUpdateMemberPoints(Member member); | ||
| 59 | 84 | ||
| 60 | Member createAndReturnMember(Member resources); | 85 | void unbind(Member resources); |
| 61 | } | 86 | } | ... | ... |
| ... | @@ -3,7 +3,6 @@ package com.topdraw.business.module.member.service.dto; | ... | @@ -3,7 +3,6 @@ package com.topdraw.business.module.member.service.dto; |
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | ||
| 7 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 8 | 7 | ||
| 9 | 8 | ||
| ... | @@ -14,7 +13,12 @@ import java.time.LocalDateTime; | ... | @@ -14,7 +13,12 @@ import java.time.LocalDateTime; |
| 14 | @Data | 13 | @Data |
| 15 | public class MemberDTO implements Serializable { | 14 | public class MemberDTO implements Serializable { |
| 16 | 15 | ||
| 17 | // 会员过期时间 | 16 | private String platformAccount; |
| 17 | |||
| 18 | // iptv绑定的主会员 0:否 1:是 | ||
| 19 | private Integer iptvMajor; | ||
| 20 | |||
| 21 | // vip过期时间 | ||
| 18 | private LocalDateTime vipExpireTime; | 22 | private LocalDateTime vipExpireTime; |
| 19 | 23 | ||
| 20 | // 主键 | 24 | // 主键 |
| ... | @@ -87,5 +91,5 @@ public class MemberDTO implements Serializable { | ... | @@ -87,5 +91,5 @@ public class MemberDTO implements Serializable { |
| 87 | private LocalDateTime updateTime; | 91 | private LocalDateTime updateTime; |
| 88 | 92 | ||
| 89 | // 是否在黑名单 1:是;0否 | 93 | // 是否在黑名单 1:是;0否 |
| 90 | // private Integer blackStatus; | 94 | private Long blackStatus; |
| 91 | } | 95 | } | ... | ... |
src/main/java/com/topdraw/business/module/member/service/dto/MemberQueryCriteria.java
deleted
100644 → 0
| 1 | package com.topdraw.business.module.member.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Query; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author XiangHan | ||
| 8 | * @date 2021-10-22 | ||
| 9 | */ | ||
| 10 | @Data | ||
| 11 | public class MemberQueryCriteria{ | ||
| 12 | |||
| 13 | @Query(type = Query.Type.LEFT_LIKE) | ||
| 14 | private String code; | ||
| 15 | |||
| 16 | // 类型 1:大屏;2:小屏 | ||
| 17 | @Query(type = Query.Type.EQUAL) | ||
| 18 | private Integer type; | ||
| 19 | |||
| 20 | // 状态 0:不可用;1:可用 | ||
| 21 | @Query(type = Query.Type.EQUAL) | ||
| 22 | private Integer status; | ||
| 23 | |||
| 24 | // 昵称 base64 | ||
| 25 | @Query(type = Query.Type.LEFT_LIKE) | ||
| 26 | private String nickname; | ||
| 27 | |||
| 28 | // 性别 0:女;1:男;-1:未知 | ||
| 29 | @Query(type = Query.Type.EQUAL) | ||
| 30 | private Integer gender; | ||
| 31 | |||
| 32 | // 分组信息 | ||
| 33 | @Query(type = Query.Type.EQUAL) | ||
| 34 | private String groups; | ||
| 35 | |||
| 36 | // 标签 | ||
| 37 | @Query(type = Query.Type.IN) | ||
| 38 | private String tags; | ||
| 39 | |||
| 40 | // 是否会员 0:非会员;1:会员 | ||
| 41 | @Query(type = Query.Type.EQUAL) | ||
| 42 | private Integer vip; | ||
| 43 | |||
| 44 | // 会员等级(对应level表的level字段,非id) | ||
| 45 | @Query(type = Query.Type.EQUAL) | ||
| 46 | private Integer level; | ||
| 47 | |||
| 48 | // iptv账号id | ||
| 49 | @Query(type = Query.Type.EQUAL) | ||
| 50 | private Long userIptvId; | ||
| 51 | |||
| 52 | // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 | ||
| 53 | @Query(type = Query.Type.IN) | ||
| 54 | private Integer bindIptvPlatformType; | ||
| 55 | |||
| 56 | } |
| 1 | package com.topdraw.business.module.member.service.impl; | 1 | package com.topdraw.business.module.member.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | 3 | import com.topdraw.business.module.member.domain.Member; |
| 4 | import com.topdraw.business.module.member.domain.MemberBuilder; | ||
| 5 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | ||
| 6 | import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; | ||
| 7 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | ||
| 4 | import com.topdraw.business.module.member.repository.MemberRepository; | 8 | import com.topdraw.business.module.member.repository.MemberRepository; |
| 5 | import com.topdraw.business.module.member.service.MemberService; | 9 | import com.topdraw.business.module.member.service.MemberService; |
| 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 10 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 7 | import com.topdraw.business.module.member.service.dto.MemberQueryCriteria; | ||
| 8 | import com.topdraw.business.module.member.service.mapper.MemberMapper; | 11 | import com.topdraw.business.module.member.service.mapper.MemberMapper; |
| 9 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 12 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
| 10 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 13 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 11 | import com.topdraw.config.LocalConstants; | 14 | import com.topdraw.exception.BadRequestException; |
| 12 | import com.topdraw.util.IdWorker; | 15 | import com.topdraw.exception.GlobeExceptionMsg; |
| 13 | import com.topdraw.util.RedissonUtil; | ||
| 14 | import com.topdraw.util.TimestampUtil; | ||
| 15 | import com.topdraw.utils.PageUtil; | ||
| 16 | import com.topdraw.utils.QueryHelp; | ||
| 17 | import com.topdraw.utils.StringUtils; | ||
| 18 | import com.topdraw.utils.ValidationUtil; | 16 | import com.topdraw.utils.ValidationUtil; |
| 19 | import lombok.extern.slf4j.Slf4j; | 17 | import lombok.extern.slf4j.Slf4j; |
| 20 | import org.redisson.api.RLock; | 18 | import org.apache.commons.lang3.StringUtils; |
| 21 | import org.redisson.api.RedissonClient; | ||
| 22 | import org.springframework.beans.BeanUtils; | 19 | import org.springframework.beans.BeanUtils; |
| 23 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 24 | import org.springframework.context.annotation.Bean; | ||
| 25 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 26 | import org.springframework.data.domain.Page; | ||
| 27 | import org.springframework.data.domain.Pageable; | ||
| 28 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 29 | import org.springframework.transaction.annotation.Propagation; | 22 | import org.springframework.transaction.annotation.Propagation; |
| 30 | import org.springframework.transaction.annotation.Transactional; | 23 | import org.springframework.transaction.annotation.Transactional; |
| 31 | import org.springframework.util.Assert; | ||
| 32 | 24 | ||
| 33 | import java.time.LocalDateTime; | ||
| 34 | import java.util.List; | 25 | import java.util.List; |
| 35 | import java.util.Map; | ||
| 36 | import java.util.Objects; | 26 | import java.util.Objects; |
| 37 | 27 | ||
| 38 | /** | 28 | /** |
| 39 | * @author XiangHan | 29 | * @author XiangHan |
| 40 | * @date 2021-10-22 | 30 | * @date 2021-10-22 |
| 41 | */ | 31 | */ |
| 42 | @Slf4j | ||
| 43 | @Service | 32 | @Service |
| 44 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 34 | @Slf4j | ||
| 45 | public class MemberServiceImpl implements MemberService { | 35 | public class MemberServiceImpl implements MemberService { |
| 46 | 36 | ||
| 47 | @Autowired | 37 | @Autowired |
| 48 | private MemberRepository memberRepository; | 38 | private UserTvService userTvService; |
| 49 | |||
| 50 | @Autowired | 39 | @Autowired |
| 51 | private MemberMapper memberMapper; | 40 | private MemberMapper memberMapper; |
| 52 | |||
| 53 | @Autowired | 41 | @Autowired |
| 54 | private com.topdraw.business.module.user.iptv.service.UserTvService UserTvService; | 42 | private MemberRepository memberRepository; |
| 43 | @Autowired | ||
| 44 | private MemberProfileService memberProfileService; | ||
| 55 | 45 | ||
| 56 | // @Autowired | ||
| 57 | // private RedissonClient redissonClient; | ||
| 58 | 46 | ||
| 59 | @Override | 47 | @Override |
| 60 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { | 48 | public MemberDTO findById(Long id) { |
| 61 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) | 49 | Member member = this.memberRepository.findById(id).orElseGet(Member::new); |
| 62 | -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 50 | ValidationUtil.isNull(member.getId(),"Member","id",id); |
| 63 | return PageUtil.toPage(page.map(memberMapper::toDto)); | 51 | |
| 52 | return this.memberMapper.toDto(member); | ||
| 53 | |||
| 64 | } | 54 | } |
| 65 | 55 | ||
| 66 | @Override | 56 | @Override |
| 67 | public List<MemberDTO> queryAll(MemberQueryCriteria criteria) { | 57 | public MemberDTO findByCode(String code) { |
| 68 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 58 | |
| 59 | Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); | ||
| 60 | |||
| 61 | return this.memberMapper.toDto(member); | ||
| 62 | } | ||
| 63 | |||
| 64 | private MemberDTO findByIdOrCode(Long id, String code) { | ||
| 65 | |||
| 66 | Member member = this.memberRepository.findByIdOrCode(id,code).orElseGet(Member::new); | ||
| 67 | ValidationUtil.isNull(member.getId(),"Member","param",code); | ||
| 68 | |||
| 69 | return this.memberMapper.toDto(member); | ||
| 70 | |||
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | @Override | 73 | @Override |
| 72 | public MemberDTO findById(Long id) { | 74 | public List<MemberDTO> findByUserIptvId(Long id) { |
| 73 | Member member = memberRepository.findById(id).orElseGet(Member::new); | 75 | |
| 74 | ValidationUtil.isNull(member.getId(),"Member","id",id); | 76 | List<Member> memberList = this.memberRepository.findByUserIptvId(id); |
| 75 | return memberMapper.toDto(member); | 77 | |
| 78 | return this.memberMapper.toDto(memberList); | ||
| 79 | |||
| 80 | } | ||
| 81 | |||
| 82 | @Override | ||
| 83 | public MemberDTO checkMember(Long id, String memberCode) { | ||
| 84 | |||
| 85 | if(Objects.isNull(id) && StringUtils.isBlank(memberCode)) | ||
| 86 | throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_AND_CODE_ARE_NULL); | ||
| 87 | |||
| 88 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 89 | MemberDTO memberDTO = this.findByCode(memberCode); | ||
| 90 | log.info("checkMember ==>> findByCode result memberDTO id ==>> {}", memberDTO.getId()); | ||
| 91 | return memberDTO; | ||
| 92 | } else if (Objects.nonNull(id)) { | ||
| 93 | MemberDTO memberDTO = this.findById(id); | ||
| 94 | log.info("checkMember ==>> findById result memberDTO id ==>> {}", memberDTO.getId()); | ||
| 95 | return memberDTO; | ||
| 96 | } | ||
| 97 | |||
| 98 | log.info("checkMember ==>> result is null ==>> id ==>> {} || memberCode ==>> {}" ,id, memberCode); | ||
| 99 | return null; | ||
| 100 | } | ||
| 101 | |||
| 102 | @Override | ||
| 103 | public MemberDTO checkMember(Member member) { | ||
| 104 | |||
| 105 | String memberCode = member.getCode(); | ||
| 106 | Long memberId = member.getId(); | ||
| 107 | |||
| 108 | return this.checkMember(memberId,memberCode); | ||
| 109 | |||
| 110 | } | ||
| 111 | |||
| 112 | @Override | ||
| 113 | public MemberDTO doUpdateMemberExpAndLevel(Member resources) { | ||
| 114 | MemberDTO memberDTO = this.update(resources); | ||
| 115 | return memberDTO; | ||
| 116 | } | ||
| 117 | |||
| 118 | @Override | ||
| 119 | public MemberDTO unbindUserIpTv(Member member) { | ||
| 120 | Member _member = this.save(member); | ||
| 121 | return this.memberMapper.toDto(_member); | ||
| 76 | } | 122 | } |
| 77 | 123 | ||
| 78 | @Override | 124 | @Override |
| 79 | @Transactional(rollbackFor = Exception.class) | 125 | @Transactional(rollbackFor = Exception.class) |
| 80 | public Long create(Member resources) { | 126 | public MemberDTO create(Member resources) { |
| 81 | Member member = this.checkMemberData(resources); | 127 | |
| 82 | memberRepository.save(member); | 128 | Member member = MemberBuilder.build(resources); |
| 83 | return resources.getId(); | 129 | Member _member = this.save(member); |
| 130 | |||
| 131 | if (Objects.nonNull(_member.getId())) { | ||
| 132 | MemberProfile memberProfile = MemberProfileBuilder.build(_member); | ||
| 133 | // 保存会员属性 | ||
| 134 | this.memberProfileService.create(memberProfile); | ||
| 135 | } | ||
| 136 | |||
| 137 | return this.memberMapper.toDto(_member); | ||
| 138 | |||
| 84 | } | 139 | } |
| 85 | 140 | ||
| 86 | private Member checkMemberData(Member member) { | 141 | @Override |
| 87 | Long defaultValue = 0L; | 142 | @Transactional(rollbackFor = Exception.class) |
| 88 | String code = member.getCode(); | 143 | public MemberDTO createAndReturnMember(Member resources) { |
| 89 | member.setCode(StringUtils.isEmpty(code)?String.valueOf(IdWorker.generator()):code); | 144 | |
| 90 | Integer gender = member.getGender(); | 145 | MemberDTO memberDTO = this.create(MemberBuilder.build(resources)); |
| 91 | member.setGender(Objects.nonNull(gender) ? gender : 0); | 146 | |
| 92 | Integer type = member.getType(); | 147 | return memberDTO; |
| 93 | member.setType(Objects.nonNull(type) ? type:-1); | 148 | |
| 94 | Integer status = member.getStatus(); | ||
| 95 | member.setStatus(Objects.nonNull(status) ? status:1); | ||
| 96 | Integer vip = member.getVip(); | ||
| 97 | member.setVip(Objects.nonNull(vip) ? vip:0); | ||
| 98 | Integer level = member.getLevel(); | ||
| 99 | member.setLevel(Objects.nonNull(level) ? level:0); | ||
| 100 | member.setExp(defaultValue); | ||
| 101 | member.setPoints(defaultValue); | ||
| 102 | member.setDuePoints(defaultValue); | ||
| 103 | member.setCouponAmount(defaultValue); | ||
| 104 | member.setDueCouponAmount(defaultValue); | ||
| 105 | member.setBlackStatus(0L); | ||
| 106 | return member; | ||
| 107 | } | 149 | } |
| 108 | 150 | ||
| 109 | @Override | 151 | @Override |
| ... | @@ -111,7 +153,7 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -111,7 +153,7 @@ public class MemberServiceImpl implements MemberService { |
| 111 | public void unbind(Member resources) { | 153 | public void unbind(Member resources) { |
| 112 | try { | 154 | try { |
| 113 | String code = resources.getCode(); | 155 | String code = resources.getCode(); |
| 114 | MemberDTO memberDTO = this.getByCode(code); | 156 | MemberDTO memberDTO = this.findByCode(code); |
| 115 | // Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); | 157 | // Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); |
| 116 | ValidationUtil.isNull(memberDTO.getId(), "Member", "id", resources.getId()); | 158 | ValidationUtil.isNull(memberDTO.getId(), "Member", "id", resources.getId()); |
| 117 | Member member = new Member(); | 159 | Member member = new Member(); |
| ... | @@ -129,138 +171,60 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -129,138 +171,60 @@ public class MemberServiceImpl implements MemberService { |
| 129 | 171 | ||
| 130 | @Override | 172 | @Override |
| 131 | @Transactional(rollbackFor = Exception.class) | 173 | @Transactional(rollbackFor = Exception.class) |
| 132 | public void update(Member resources) { | 174 | public MemberDTO update(Member resources) { |
| 175 | |||
| 176 | log.info("MemberServiceImpl ==>> update ==>> resources ==>> [{}]" , resources); | ||
| 133 | try { | 177 | try { |
| 134 | Member member = memberRepository.findByCode(resources.getCode()).orElseGet(Member::new); | ||
| 135 | if (Objects.nonNull(member.getId())) { | ||
| 136 | Long id = member.getId(); | ||
| 137 | resources.setId(id); | ||
| 138 | |||
| 139 | String platformAccount = resources.getPlatformAccount(); | ||
| 140 | if (StringUtils.isNotEmpty(platformAccount)) { | ||
| 141 | resources.setUserIptvId(null); | ||
| 142 | |||
| 143 | UserTvDTO userTvDTO = this.UserTvService.findByPlatformAccount(platformAccount); | ||
| 144 | if (Objects.nonNull(userTvDTO)) { | ||
| 145 | Long userIptvId = userTvDTO.getId(); | ||
| 146 | resources.setUserIptvId(userIptvId); | ||
| 147 | resources.setBindIptvPlatformType(1); | ||
| 148 | resources.setBindIptvTime(LocalDateTime.now()); | ||
| 149 | } | ||
| 150 | |||
| 151 | } else { | ||
| 152 | resources.setUserIptvId(member.getUserIptvId()); | ||
| 153 | resources.setBindIptvPlatformType(member.getBindIptvPlatformType()); | ||
| 154 | resources.setBindIptvTime(member.getBindIptvTime()); | ||
| 155 | } | ||
| 156 | 178 | ||
| 179 | MemberDTO memberDTO = this.checkMember(resources); | ||
| 180 | resources.setId(memberDTO.getId()); | ||
| 181 | resources.setCode(memberDTO.getCode()); | ||
| 182 | resources.setCreateTime(memberDTO.getCreateTime()); | ||
| 183 | |||
| 184 | String platformAccount = resources.getPlatformAccount(); | ||
| 185 | if (StringUtils.isNotBlank(platformAccount)) { | ||
| 186 | if (Objects.nonNull(resources.getUserIptvId())){ | ||
| 187 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 188 | resources.setUserIptvId(userTvDTO.getId()); | ||
| 189 | } | ||
| 190 | } else { | ||
| 191 | resources.setUserIptvId(memberDTO.getUserIptvId()); | ||
| 157 | } | 192 | } |
| 158 | 193 | ||
| 159 | member.copy(resources); | 194 | Member _member = this.save(resources); |
| 160 | log.info("memberService ==>> update ==>> [{}]",member); | 195 | return this.memberMapper.toDto(_member); |
| 161 | memberRepository.save(member); | ||
| 162 | } catch (Exception e) { | ||
| 163 | e.printStackTrace(); | ||
| 164 | throw e; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | 196 | ||
| 168 | @Override | ||
| 169 | @Transactional(rollbackFor = Exception.class) | ||
| 170 | public void delete(Long id) { | ||
| 171 | Assert.notNull(id, "The given id must not be null!"); | ||
| 172 | // RLock rLock = this.redissonClient.getLock("Member::delete::code" + id); | ||
| 173 | try { | ||
| 174 | // RedissonUtil.lock(rLock); | ||
| 175 | Member member = memberRepository.findById(id).orElseThrow( | ||
| 176 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Member.class, id), 1)); | ||
| 177 | memberRepository.delete(member); | ||
| 178 | } catch (Exception e) { | 197 | } catch (Exception e) { |
| 179 | e.printStackTrace(); | 198 | e.printStackTrace(); |
| 180 | throw e; | 199 | throw e; |
| 181 | } finally { | ||
| 182 | // RedissonUtil.unlock(rLock); | ||
| 183 | } | 200 | } |
| 184 | } | ||
| 185 | 201 | ||
| 202 | } | ||
| 186 | 203 | ||
| 187 | @Override | 204 | public Member save(Member member){ |
| 188 | public MemberDTO getByCode(String code) { | 205 | return this.memberRepository.save(member); |
| 189 | return StringUtils.isNotEmpty(code) ? memberMapper.toDto(memberRepository.findFirstByCode(code).orElseGet(Member::new)) | ||
| 190 | : new MemberDTO(); | ||
| 191 | } | 206 | } |
| 192 | 207 | ||
| 193 | @Override | 208 | @Override |
| 194 | @Transactional(rollbackFor = Exception.class) | 209 | @Transactional(rollbackFor = Exception.class) |
| 195 | public boolean createMemberByUserTv(UserTv resources) { | 210 | public MemberDTO doUpdateMemberPoints(Member resources) { |
| 196 | String platformAccount = resources.getPlatformAccount(); | 211 | try { |
| 197 | UserTvDTO userTvDTO = this.UserTvService.findByPlatformAccount(platformAccount); | ||
| 198 | if (Objects.isNull(userTvDTO)) { | ||
| 199 | Member member = new Member(); | ||
| 200 | // 大屏 | ||
| 201 | member.setType(LocalConstants.MEMBER_PLATFORM_TYPE_VIS); | ||
| 202 | Member member12 = this.checkMemberData(member); | ||
| 203 | Long memberId = this.create(member12); | ||
| 204 | |||
| 205 | if (Objects.nonNull(memberId)) { | ||
| 206 | UserTv userTv = new UserTv(); | ||
| 207 | BeanUtils.copyProperties(resources,userTv); | ||
| 208 | userTv.setPlatformAccount(platformAccount); | ||
| 209 | userTv.setMemberCode(member12.getCode()); | ||
| 210 | Long userIptvId = UserTvService.create(userTv); | ||
| 211 | |||
| 212 | if (Objects.nonNull(userIptvId)) { | ||
| 213 | member.setId(memberId); | ||
| 214 | member.setUserIptvId(userIptvId); | ||
| 215 | member.setBindIptvTime(LocalDateTime.now()); | ||
| 216 | this.bindIptvId(member); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | 212 | ||
| 220 | } else { | 213 | Member member = this.memberRepository.findById(resources.getId()).orElseGet(Member::new); |
| 221 | return false; | 214 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); |
| 222 | } | 215 | member.copy(resources); |
| 223 | 216 | ||
| 224 | return true; | 217 | Member _member = this.save(member); |
| 225 | } | 218 | |
| 219 | return this.memberMapper.toDto(_member); | ||
| 226 | 220 | ||
| 227 | @Override | ||
| 228 | @Transactional(rollbackFor = Exception.class) | ||
| 229 | public void doUpdateMemberPoints(Member member) { | ||
| 230 | try { | ||
| 231 | Long id = member.getId(); | ||
| 232 | Long points = member.getPoints(); | ||
| 233 | Long duePoints = member.getDuePoints(); | ||
| 234 | memberRepository.updateMemberPoints(id,points,duePoints); | ||
| 235 | } catch (Exception e) { | 221 | } catch (Exception e) { |
| 236 | e.printStackTrace(); | 222 | e.printStackTrace(); |
| 237 | throw e; | 223 | throw e; |
| 238 | } | 224 | } |
| 239 | } | ||
| 240 | 225 | ||
| 241 | @Override | ||
| 242 | @Transactional(rollbackFor = Exception.class) | ||
| 243 | public Member createAndReturnMember(Member resources) { | ||
| 244 | Member member = this.checkMemberData(resources); | ||
| 245 | memberRepository.save(member); | ||
| 246 | return resources; | ||
| 247 | } | 226 | } |
| 248 | 227 | ||
| 249 | private void save(Member member){ | ||
| 250 | memberRepository.save(member); | ||
| 251 | } | ||
| 252 | 228 | ||
| 253 | public void bindIptvId(Member resources) { | 229 | |
| 254 | try { | ||
| 255 | Member member = memberRepository.findFirstByCode(resources.getCode()).orElseGet(Member::new); | ||
| 256 | if (member==null) { | ||
| 257 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); | ||
| 258 | member.copy(resources); | ||
| 259 | } | ||
| 260 | this.save(member); | ||
| 261 | } catch (Exception e) { | ||
| 262 | e.printStackTrace(); | ||
| 263 | throw e; | ||
| 264 | } | ||
| 265 | } | ||
| 266 | } | 230 | } | ... | ... |
| ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.viphistory.domain; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.member.viphistory.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -22,10 +23,7 @@ import java.time.LocalDateTime; | ... | @@ -22,10 +23,7 @@ import java.time.LocalDateTime; |
| 22 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
| 23 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
| 24 | @Table(name="uc_member_vip_history") | 25 | @Table(name="uc_member_vip_history") |
| 25 | public class MemberVipHistory implements Serializable { | 26 | public class MemberVipHistory extends AsyncMqModule implements Serializable { |
| 26 | |||
| 27 | @Transient | ||
| 28 | private String memberCode; | ||
| 29 | 27 | ||
| 30 | // 主键 | 28 | // 主键 |
| 31 | @Id | 29 | @Id | ... | ... |
src/main/java/com/topdraw/business/module/member/viphistory/domain/MemberVipHistoryBuilder.java
0 → 100644
| 1 | package com.topdraw.business.module.member.viphistory.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | |||
| 5 | import java.time.LocalDateTime; | ||
| 6 | import java.util.Objects; | ||
| 7 | |||
| 8 | public class MemberVipHistoryBuilder { | ||
| 9 | |||
| 10 | public static MemberVipHistory build(Member member , Integer beforeVip) { | ||
| 11 | Long id = member.getId(); | ||
| 12 | Integer vip = member.getVip(); | ||
| 13 | LocalDateTime vipExpireTime = member.getVipExpireTime(); | ||
| 14 | |||
| 15 | MemberVipHistory memberVipHistory = new MemberVipHistory(); | ||
| 16 | memberVipHistory.setMemberId(Objects.isNull(id)? null:id); | ||
| 17 | memberVipHistory.setVip(Objects.isNull(vip)? null:vip); | ||
| 18 | memberVipHistory.setBeforeVip(Objects.isNull(beforeVip)? null:beforeVip); | ||
| 19 | memberVipHistory.setVipExpireTime(Objects.isNull(vipExpireTime)? null:vipExpireTime); | ||
| 20 | return build(memberVipHistory); | ||
| 21 | } | ||
| 22 | |||
| 23 | public static MemberVipHistory build(Long memberId, Integer vip, Integer beforeVip, LocalDateTime vipExpireTime ) { | ||
| 24 | MemberVipHistory memberVipHistory = new MemberVipHistory(); | ||
| 25 | memberVipHistory.setMemberId(Objects.isNull(memberId)? null:memberId); | ||
| 26 | memberVipHistory.setVip(Objects.isNull(vip)? null:vip); | ||
| 27 | memberVipHistory.setBeforeVip(Objects.isNull(beforeVip)? null:beforeVip); | ||
| 28 | memberVipHistory.setVipExpireTime(Objects.isNull(vipExpireTime)? null:vipExpireTime); | ||
| 29 | return build(memberVipHistory); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static MemberVipHistory build(MemberVipHistory memberVipHistory) { | ||
| 33 | return build(memberVipHistory.getId(), | ||
| 34 | memberVipHistory.getMemberId(), | ||
| 35 | memberVipHistory.getVip(), | ||
| 36 | memberVipHistory.getBeforeVip(), | ||
| 37 | memberVipHistory.getVipExpireTime(), | ||
| 38 | memberVipHistory.getStatus()); | ||
| 39 | } | ||
| 40 | |||
| 41 | public static MemberVipHistory build(Long id, Long memberId , Integer vip , Integer beforeVip , LocalDateTime vipExpireTime, Integer status){ | ||
| 42 | MemberVipHistory memberVipHistory = new MemberVipHistory(); | ||
| 43 | memberVipHistory.setId(Objects.isNull(id)? null:id); | ||
| 44 | memberVipHistory.setMemberId(Objects.isNull(memberId)? null:memberId) ; | ||
| 45 | memberVipHistory.setVip(Objects.isNull(vip)? null:vip); | ||
| 46 | memberVipHistory.setBeforeVip(Objects.isNull(beforeVip)? null:beforeVip); | ||
| 47 | memberVipHistory.setVipExpireTime(Objects.isNull(vipExpireTime)? null:vipExpireTime); | ||
| 48 | memberVipHistory.setStatus(Objects.isNull(status)? 1:status); | ||
| 49 | return memberVipHistory; | ||
| 50 | } | ||
| 51 | |||
| 52 | } |
| 1 | package com.topdraw.business.module.member.viphistory.service; | 1 | package com.topdraw.business.module.member.viphistory.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 3 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | 4 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
| 4 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; | 5 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; |
| 5 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 6 | ||
| 8 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 9 | import java.util.List; | ||
| 10 | import java.util.Map; | ||
| 11 | 8 | ||
| 12 | /** | 9 | /** |
| 13 | * @author luerlong | 10 | * @author luerlong |
| ... | @@ -16,32 +13,42 @@ import java.util.Map; | ... | @@ -16,32 +13,42 @@ import java.util.Map; |
| 16 | public interface MemberVipHistoryService { | 13 | public interface MemberVipHistoryService { |
| 17 | 14 | ||
| 18 | /** | 15 | /** |
| 19 | * 查询数据分页 | ||
| 20 | * @param criteria 条件参数 | ||
| 21 | * @param pageable 分页参数 | ||
| 22 | * @return Map<String,Object> | ||
| 23 | */ | ||
| 24 | Map<String,Object> queryAll(MemberVipHistoryQueryCriteria criteria, Pageable pageable); | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 查询所有数据不分页 | ||
| 28 | * @param criteria 条件参数 | ||
| 29 | * @return List<MemberVipHistoryDTO> | ||
| 30 | */ | ||
| 31 | List<MemberVipHistoryDTO> queryAll(MemberVipHistoryQueryCriteria criteria); | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 根据ID查询 | 16 | * 根据ID查询 |
| 35 | * @param id ID | 17 | * @param id ID |
| 36 | * @return MemberVipHistoryDTO | 18 | * @return MemberVipHistoryDTO |
| 37 | */ | 19 | */ |
| 38 | MemberVipHistoryDTO findById(Long id); | 20 | MemberVipHistoryDTO findById(Long id); |
| 39 | 21 | ||
| 22 | /** | ||
| 23 | * | ||
| 24 | * @param resources | ||
| 25 | */ | ||
| 40 | void create(MemberVipHistory resources); | 26 | void create(MemberVipHistory resources); |
| 41 | 27 | ||
| 28 | /** | ||
| 29 | * | ||
| 30 | * @param member | ||
| 31 | */ | ||
| 32 | void create(Member member, Integer beforeVip); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * | ||
| 36 | * @param resources | ||
| 37 | */ | ||
| 42 | void update(MemberVipHistory resources); | 38 | void update(MemberVipHistory resources); |
| 43 | 39 | ||
| 40 | /** | ||
| 41 | * | ||
| 42 | * @param id | ||
| 43 | */ | ||
| 44 | void delete(Long id); | 44 | void delete(Long id); |
| 45 | 45 | ||
| 46 | /** | ||
| 47 | * | ||
| 48 | * @param id | ||
| 49 | * @param nowTime | ||
| 50 | * @return | ||
| 51 | */ | ||
| 46 | MemberVipHistory findByTime(Long id, LocalDateTime nowTime); | 52 | MemberVipHistory findByTime(Long id, LocalDateTime nowTime); |
| 53 | |||
| 47 | } | 54 | } | ... | ... |
| 1 | package com.topdraw.business.module.member.viphistory.service.impl; | 1 | package com.topdraw.business.module.member.viphistory.service.impl; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.service.MemberService; | 5 | import com.topdraw.business.module.member.service.MemberService; |
| 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 6 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | 7 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; |
| 8 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistoryBuilder; | ||
| 7 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; | 9 | import com.topdraw.business.module.member.viphistory.repository.MemberVipHistoryRepository; |
| 8 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | 10 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; |
| 9 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; | 11 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO; |
| 10 | import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryQueryCriteria; | ||
| 11 | import com.topdraw.business.module.member.viphistory.service.mapper.MemberVipHistoryMapper; | 12 | import com.topdraw.business.module.member.viphistory.service.mapper.MemberVipHistoryMapper; |
| 12 | import com.topdraw.utils.PageUtil; | ||
| 13 | import com.topdraw.utils.QueryHelp; | ||
| 14 | import com.topdraw.utils.ValidationUtil; | 13 | import com.topdraw.utils.ValidationUtil; |
| 15 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | import org.springframework.dao.EmptyResultDataAccessException; | 16 | import org.springframework.dao.EmptyResultDataAccessException; |
| 18 | import org.springframework.data.domain.Page; | ||
| 19 | import org.springframework.data.domain.Pageable; | ||
| 20 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.transaction.annotation.Propagation; | 18 | import org.springframework.transaction.annotation.Propagation; |
| 22 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
| 23 | import org.springframework.util.Assert; | 20 | import org.springframework.util.Assert; |
| 24 | 21 | ||
| 25 | import java.time.LocalDateTime; | 22 | import java.time.LocalDateTime; |
| 26 | import java.util.List; | ||
| 27 | import java.util.Map; | ||
| 28 | import java.util.Objects; | ||
| 29 | 23 | ||
| 30 | /** | 24 | /** |
| 31 | * @author luerlong | 25 | * @author luerlong |
| ... | @@ -37,61 +31,54 @@ import java.util.Objects; | ... | @@ -37,61 +31,54 @@ import java.util.Objects; |
| 37 | public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { | 31 | public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { |
| 38 | 32 | ||
| 39 | @Autowired | 33 | @Autowired |
| 40 | private MemberVipHistoryRepository memberVipHistoryRepository; | 34 | private MemberService memberService; |
| 41 | 35 | ||
| 42 | @Autowired | 36 | @Autowired |
| 43 | private MemberVipHistoryMapper memberVipHistoryMapper; | 37 | private MemberVipHistoryMapper memberVipHistoryMapper; |
| 44 | @Autowired | 38 | @Autowired |
| 45 | private MemberService memberService; | 39 | private MemberVipHistoryRepository memberVipHistoryRepository; |
| 46 | |||
| 47 | @Override | ||
| 48 | public Map<String, Object> queryAll(MemberVipHistoryQueryCriteria criteria, Pageable pageable) { | ||
| 49 | Page<MemberVipHistory> page = memberVipHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 50 | return PageUtil.toPage(page.map(memberVipHistoryMapper::toDto)); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public List<MemberVipHistoryDTO> queryAll(MemberVipHistoryQueryCriteria criteria) { | ||
| 55 | return memberVipHistoryMapper.toDto(memberVipHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 56 | } | ||
| 57 | 40 | ||
| 58 | @Override | 41 | @Override |
| 59 | public MemberVipHistoryDTO findById(Long id) { | 42 | public MemberVipHistoryDTO findById(Long id) { |
| 60 | MemberVipHistory memberVipHistory = memberVipHistoryRepository.findById(id).orElseGet(MemberVipHistory::new); | 43 | log.info("MemberVipHistoryServiceImpl ==>> findById ==>> param ==>> [{}]",id); |
| 44 | MemberVipHistory memberVipHistory = this.memberVipHistoryRepository.findById(id).orElseGet(MemberVipHistory::new); | ||
| 61 | ValidationUtil.isNull(memberVipHistory.getId(),"MemberVipHistory","id",id); | 45 | ValidationUtil.isNull(memberVipHistory.getId(),"MemberVipHistory","id",id); |
| 62 | return memberVipHistoryMapper.toDto(memberVipHistory); | 46 | log.info("MemberVipHistoryServiceImpl ==>> findById ==>> result ==>> [{}]",memberVipHistory); |
| 47 | return this.memberVipHistoryMapper.toDto(memberVipHistory); | ||
| 63 | } | 48 | } |
| 64 | 49 | ||
| 65 | @Override | 50 | @Override |
| 66 | @Transactional(rollbackFor = Exception.class) | 51 | @Transactional(rollbackFor = Exception.class) |
| 67 | public void create(MemberVipHistory resources) { | 52 | public void create(MemberVipHistory resources) { |
| 68 | log.info("MemberVipHistoryServiceImpl ==>> create ==>> resources ==>> [{}]",resources); | 53 | log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources); |
| 69 | String memberCode = resources.getMemberCode(); | 54 | MemberDTO memberDTO = this.memberService.findByCode(resources.getMemberCode()); |
| 70 | Assert.notNull(resources.getMemberCode(),"memberCode can't be null !!"); | 55 | resources.setMemberId(memberDTO.getId()); |
| 71 | MemberDTO byCode = memberService.getByCode(memberCode); | 56 | this.memberVipHistoryRepository.save(resources); |
| 72 | if (Objects.nonNull(byCode.getCode())) { | 57 | } |
| 73 | Long id = byCode.getId(); | 58 | |
| 74 | resources.setMemberId(id); | 59 | @Override |
| 75 | memberVipHistoryRepository.save(resources); | 60 | public void create(Member member, Integer beforeVip) { |
| 76 | } | 61 | this.checkMember(member); |
| 62 | MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(member, beforeVip); | ||
| 63 | this.memberVipHistoryRepository.save(memberVipHistory); | ||
| 77 | } | 64 | } |
| 78 | 65 | ||
| 79 | @Override | 66 | @Override |
| 80 | @Transactional(rollbackFor = Exception.class) | 67 | @Transactional(rollbackFor = Exception.class) |
| 81 | public void update(MemberVipHistory resources) { | 68 | public void update(MemberVipHistory resources) { |
| 82 | MemberVipHistory memberVipHistory = memberVipHistoryRepository.findById(resources.getId()).orElseGet(MemberVipHistory::new); | 69 | MemberVipHistory memberVipHistory = this.memberVipHistoryRepository.findById(resources.getId()).orElseGet(MemberVipHistory::new); |
| 83 | ValidationUtil.isNull( memberVipHistory.getId(),"MemberVipHistory","id",resources.getId()); | 70 | ValidationUtil.isNull( memberVipHistory.getId(),"MemberVipHistory","id",resources.getId()); |
| 84 | memberVipHistory.copy(resources); | 71 | memberVipHistory.copy(resources); |
| 85 | memberVipHistoryRepository.save(memberVipHistory); | 72 | this.memberVipHistoryRepository.save(memberVipHistory); |
| 86 | } | 73 | } |
| 87 | 74 | ||
| 88 | @Override | 75 | @Override |
| 89 | @Transactional(rollbackFor = Exception.class) | 76 | @Transactional(rollbackFor = Exception.class) |
| 90 | public void delete(Long id) { | 77 | public void delete(Long id) { |
| 91 | Assert.notNull(id, "The given id must not be null!"); | 78 | Assert.notNull(id, "The given id must not be null!"); |
| 92 | MemberVipHistory memberVipHistory = memberVipHistoryRepository.findById(id).orElseThrow( | 79 | MemberVipHistory memberVipHistory = this.memberVipHistoryRepository.findById(id).orElseThrow( |
| 93 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberVipHistory.class, id), 1)); | 80 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberVipHistory.class, id), 1)); |
| 94 | memberVipHistoryRepository.delete(memberVipHistory); | 81 | this.memberVipHistoryRepository.delete(memberVipHistory); |
| 95 | } | 82 | } |
| 96 | 83 | ||
| 97 | @Override | 84 | @Override |
| ... | @@ -100,5 +87,16 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { | ... | @@ -100,5 +87,16 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { |
| 100 | return memberVipHistory; | 87 | return memberVipHistory; |
| 101 | } | 88 | } |
| 102 | 89 | ||
| 90 | private MemberDTO checkMember(MemberVipHistory resources){ | ||
| 91 | Long memberId = resources.getMemberId(); | ||
| 92 | String code = resources.getMemberCode(); | ||
| 93 | return this.memberService.checkMember(memberId, code); | ||
| 94 | } | ||
| 95 | |||
| 96 | private MemberDTO checkMember(Member resources){ | ||
| 97 | Long memberId = resources.getId(); | ||
| 98 | String code = resources.getCode(); | ||
| 99 | return this.memberService.checkMember(memberId, code); | ||
| 100 | } | ||
| 103 | 101 | ||
| 104 | } | 102 | } | ... | ... |
| ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.points.available.domain; | ... | @@ -2,6 +2,8 @@ package com.topdraw.business.module.points.available.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 6 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 9 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -24,53 +26,49 @@ import java.time.LocalDateTime; | ... | @@ -24,53 +26,49 @@ import java.time.LocalDateTime; |
| 24 | @EntityListeners(AuditingEntityListener.class) | 26 | @EntityListeners(AuditingEntityListener.class) |
| 25 | @Accessors(chain = true) | 27 | @Accessors(chain = true) |
| 26 | @Table(name="uc_points_available") | 28 | @Table(name="uc_points_available") |
| 27 | public class PointsAvailable implements Serializable { | 29 | public class PointsAvailable extends AsyncMqModule implements Serializable { |
| 28 | 30 | ||
| 29 | /** 会员编号 */ | 31 | /** 主键 */ |
| 30 | @Transient | ||
| 31 | private String memberCode; | ||
| 32 | |||
| 33 | // 主键 | ||
| 34 | @Id | 32 | @Id |
| 35 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 33 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 36 | @Column(name = "id") | 34 | @Column(name = "id") |
| 37 | private Long id; | 35 | private Long id; |
| 38 | 36 | ||
| 39 | // 标识 | 37 | /** 标识 */ |
| 40 | @Column(name = "code") | 38 | @Column(name = "code") |
| 41 | private String code; | 39 | private String code; |
| 42 | 40 | ||
| 43 | // 积分类型 0:通用型 | 41 | /** 积分类型 0:通用型 */ |
| 44 | @Column(name = "points_type") | 42 | @Column(name = "points_type") |
| 45 | private Integer pointsType; | 43 | private Integer pointsType; |
| 46 | 44 | ||
| 47 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | 45 | /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ |
| 48 | @Column(name = "device_type") | 46 | @Column(name = "device_type") |
| 49 | private Integer deviceType; | 47 | private Integer deviceType; |
| 50 | 48 | ||
| 51 | // 会员id | 49 | /** 会员id */ |
| 52 | @Column(name = "member_id", nullable = false) | 50 | @Column(name = "member_id", nullable = false) |
| 53 | private Long memberId; | 51 | private Long memberId; |
| 54 | 52 | ||
| 55 | // 积分值 | 53 | /** 积分值 */ |
| 56 | @Column(name = "points") | 54 | @Column(name = "points") |
| 57 | private Long points; | 55 | private Long points; |
| 58 | 56 | ||
| 59 | // 过期时间 | 57 | /** 过期时间 */ |
| 60 | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | 58 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",locale = "") |
| 61 | @Column(name = "expire_time") | 59 | @Column(name = "expire_time") |
| 62 | private LocalDateTime expireTime; | 60 | private LocalDateTime expireTime; |
| 63 | 61 | ||
| 64 | // 描述 | 62 | /** 描述 */ |
| 65 | @Column(name = "description") | 63 | @Column(name = "description") |
| 66 | private String description; | 64 | private String description; |
| 67 | 65 | ||
| 68 | // 创建时间 | 66 | /** 创建时间 */ |
| 69 | @CreatedDate | 67 | @CreatedDate |
| 70 | @Column(name = "create_time") | 68 | @Column(name = "create_time") |
| 71 | private Timestamp createTime; | 69 | private Timestamp createTime; |
| 72 | 70 | ||
| 73 | // 更新时间 | 71 | /** 更新时间 */ |
| 74 | @LastModifiedDate | 72 | @LastModifiedDate |
| 75 | @Column(name = "update_time") | 73 | @Column(name = "update_time") |
| 76 | private Timestamp updateTime; | 74 | private Timestamp updateTime; | ... | ... |
src/main/java/com/topdraw/business/module/points/available/repository/PointsAvailableRepository.java
| ... | @@ -25,7 +25,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -25,7 +25,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
| 25 | 25 | ||
| 26 | List<PointsAvailableDTO> findByMemberId(Long memberId); | 26 | List<PointsAvailableDTO> findByMemberId(Long memberId); |
| 27 | 27 | ||
| 28 | List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , LocalDateTime now); | 28 | List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime now); |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * 即将过期的积分 | 31 | * 即将过期的积分 | ... | ... |
| 1 | package com.topdraw.business.module.points.available.rest; | ||
| 2 | |||
| 3 | /** | ||
| 4 | * @author XiangHan | ||
| 5 | * @date 2021-10-23 | ||
| 6 | */ | ||
| 7 | //@Api(tags = "PointsAvailable管理") | ||
| 8 | //@RestController | ||
| 9 | //@RequestMapping("/api/PointsAvailable") | ||
| 10 | public class PointsAvailableController { | ||
| 11 | |||
| 12 | /*@Autowired | ||
| 13 | private PointsAvailableService PointsAvailableService; | ||
| 14 | |||
| 15 | @GetMapping | ||
| 16 | @ApiOperation("查询PointsAvailable") | ||
| 17 | public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria, Pageable pageable) { | ||
| 18 | return ResultInfo.successPage(PointsAvailableService.queryAll(criteria,pageable)); | ||
| 19 | } | ||
| 20 | |||
| 21 | @GetMapping(value = "/all") | ||
| 22 | @ApiOperation("查询所有PointsAvailable") | ||
| 23 | public ResultInfo getPointsAvailables(PointsAvailableQueryCriteria criteria) { | ||
| 24 | return ResultInfo.success(PointsAvailableService.queryAll(criteria)); | ||
| 25 | } | ||
| 26 | |||
| 27 | @Log | ||
| 28 | @PostMapping | ||
| 29 | @ApiOperation("新增PointsAvailable") | ||
| 30 | public ResultInfo create(@Validated @RequestBody PointsAvailable resources) { | ||
| 31 | PointsAvailableService.create(resources); | ||
| 32 | return ResultInfo.success(); | ||
| 33 | } | ||
| 34 | |||
| 35 | @Log | ||
| 36 | @PutMapping | ||
| 37 | @ApiOperation("修改PointsAvailable") | ||
| 38 | public ResultInfo update(@Validated @RequestBody PointsAvailable resources) { | ||
| 39 | PointsAvailableService.update(resources); | ||
| 40 | return ResultInfo.success(); | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | @Log | ||
| 45 | @DeleteMapping(value = "/{id}") | ||
| 46 | @ApiOperation("删除PointsAvailable") | ||
| 47 | public ResultInfo delete(@PathVariable Long id) { | ||
| 48 | PointsAvailableService.delete(id); | ||
| 49 | return ResultInfo.success(); | ||
| 50 | } | ||
| 51 | |||
| 52 | @GetMapping(value = "/getByCode/{code}") | ||
| 53 | @ApiOperation(value = "根据标识查询") | ||
| 54 | public ResultInfo getByCode(@PathVariable String code) { | ||
| 55 | return ResultInfo.success(PointsAvailableService.getByCode(code)); | ||
| 56 | }*/ | ||
| 57 | } |
| ... | @@ -2,12 +2,9 @@ package com.topdraw.business.module.points.available.service; | ... | @@ -2,12 +2,9 @@ package com.topdraw.business.module.points.available.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.points.available.domain.PointsAvailable; | 3 | import com.topdraw.business.module.points.available.domain.PointsAvailable; |
| 4 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; | 4 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; |
| 5 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 9 | import java.util.List; | 7 | import java.util.List; |
| 10 | import java.util.Map; | ||
| 11 | 8 | ||
| 12 | /** | 9 | /** |
| 13 | * @author XiangHan | 10 | * @author XiangHan |
| ... | @@ -16,21 +13,6 @@ import java.util.Map; | ... | @@ -16,21 +13,6 @@ import java.util.Map; |
| 16 | public interface PointsAvailableService { | 13 | public interface PointsAvailableService { |
| 17 | 14 | ||
| 18 | /** | 15 | /** |
| 19 | * 查询数据分页 | ||
| 20 | * @param criteria 条件参数 | ||
| 21 | * @param pageable 分页参数 | ||
| 22 | * @return Map<String,Object> | ||
| 23 | */ | ||
| 24 | Map<String,Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable); | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 查询所有数据不分页 | ||
| 28 | * @param criteria 条件参数 | ||
| 29 | * @return List<PointsAvailableDTO> | ||
| 30 | */ | ||
| 31 | List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria); | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 根据ID查询 | 16 | * 根据ID查询 |
| 35 | * @param id ID | 17 | * @param id ID |
| 36 | * @return PointsAvailableDTO | 18 | * @return PointsAvailableDTO |
| ... | @@ -41,13 +23,13 @@ public interface PointsAvailableService { | ... | @@ -41,13 +23,13 @@ public interface PointsAvailableService { |
| 41 | * | 23 | * |
| 42 | * @param resources | 24 | * @param resources |
| 43 | */ | 25 | */ |
| 44 | void create(PointsAvailable resources); | 26 | PointsAvailableDTO create(PointsAvailable resources); |
| 45 | 27 | ||
| 46 | /** | 28 | /** |
| 47 | * | 29 | * |
| 48 | * @param resources | 30 | * @param resources |
| 49 | */ | 31 | */ |
| 50 | void update(PointsAvailable resources); | 32 | PointsAvailableDTO update(PointsAvailable resources); |
| 51 | 33 | ||
| 52 | /** | 34 | /** |
| 53 | * | 35 | * |
| ... | @@ -55,8 +37,6 @@ public interface PointsAvailableService { | ... | @@ -55,8 +37,6 @@ public interface PointsAvailableService { |
| 55 | */ | 37 | */ |
| 56 | void delete(Long id); | 38 | void delete(Long id); |
| 57 | 39 | ||
| 58 | void delete4Custom(Long id); | ||
| 59 | |||
| 60 | /** | 40 | /** |
| 61 | * | 41 | * |
| 62 | * @param id | 42 | * @param id |
| ... | @@ -84,7 +64,7 @@ public interface PointsAvailableService { | ... | @@ -84,7 +64,7 @@ public interface PointsAvailableService { |
| 84 | * @param factor 阈值 | 64 | * @param factor 阈值 |
| 85 | * @return | 65 | * @return |
| 86 | */ | 66 | */ |
| 87 | Long findSoonExpireTime(Long memberId,Integer factor); | 67 | Long findSoonExpireTime(Long memberId, Integer factor); |
| 88 | 68 | ||
| 89 | /** | 69 | /** |
| 90 | * | 70 | * |
| ... | @@ -107,6 +87,15 @@ public interface PointsAvailableService { | ... | @@ -107,6 +87,15 @@ public interface PointsAvailableService { |
| 107 | */ | 87 | */ |
| 108 | long findTotalPointsByMemberId(Long memberId); | 88 | long findTotalPointsByMemberId(Long memberId); |
| 109 | 89 | ||
| 110 | void create4Custom(PointsAvailable pointsAvailable); | 90 | /** |
| 91 | * | ||
| 92 | * @param id | ||
| 93 | */ | ||
| 94 | void delete4Custom(Long id); | ||
| 111 | 95 | ||
| 96 | /** | ||
| 97 | * | ||
| 98 | * @param pointsAvailable | ||
| 99 | */ | ||
| 100 | PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable); | ||
| 112 | } | 101 | } | ... | ... |
| ... | @@ -14,33 +14,33 @@ import java.time.LocalDateTime; | ... | @@ -14,33 +14,33 @@ import java.time.LocalDateTime; |
| 14 | @Data | 14 | @Data |
| 15 | public class PointsAvailableDTO implements Serializable { | 15 | public class PointsAvailableDTO implements Serializable { |
| 16 | 16 | ||
| 17 | // 主键 | 17 | /** 主键 */ |
| 18 | private Long id; | 18 | private Long id; |
| 19 | 19 | ||
| 20 | // 标识 | 20 | /** 标识 */ |
| 21 | private String code; | 21 | private String code; |
| 22 | 22 | ||
| 23 | // 积分类型 0:通用型 | 23 | /** 积分类型 0:通用型 */ |
| 24 | private Integer pointsType; | 24 | private Integer pointsType; |
| 25 | 25 | ||
| 26 | // 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | 26 | /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ |
| 27 | private Integer deviceType; | 27 | private Integer deviceType; |
| 28 | 28 | ||
| 29 | // 会员id | 29 | /** 会员id */ |
| 30 | private Long memberId; | 30 | private Long memberId; |
| 31 | 31 | ||
| 32 | // 积分值 | 32 | /** 积分值 */ |
| 33 | private Long points; | 33 | private Long points; |
| 34 | 34 | ||
| 35 | // 过期时间 | 35 | /** 过期时间 */ |
| 36 | private LocalDateTime expireTime; | 36 | private LocalDateTime expireTime; |
| 37 | 37 | ||
| 38 | // 描述 | 38 | /** 描述 */ |
| 39 | private String description; | 39 | private String description; |
| 40 | 40 | ||
| 41 | // 创建时间 | 41 | /** 创建时间 */ |
| 42 | private Timestamp createTime; | 42 | private Timestamp createTime; |
| 43 | 43 | ||
| 44 | // 更新时间 | 44 | /** 更新时间 */ |
| 45 | private Timestamp updateTime; | 45 | private Timestamp updateTime; |
| 46 | } | 46 | } | ... | ... |
| 1 | package com.topdraw.business.module.points.available.service.impl; | 1 | package com.topdraw.business.module.points.available.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.service.MemberService; | ||
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 5 | import com.topdraw.business.module.points.available.domain.PointsAvailable; | 3 | import com.topdraw.business.module.points.available.domain.PointsAvailable; |
| 6 | import com.topdraw.business.module.points.available.repository.PointsAvailableRepository; | 4 | import com.topdraw.business.module.points.available.repository.PointsAvailableRepository; |
| 7 | import com.topdraw.business.module.points.available.service.PointsAvailableService; | 5 | import com.topdraw.business.module.points.available.service.PointsAvailableService; |
| 8 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; | 6 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; |
| 9 | import com.topdraw.business.module.points.available.service.dto.PointsAvailableQueryCriteria; | ||
| 10 | import com.topdraw.business.module.points.available.service.mapper.PointsAvailableMapper; | 7 | import com.topdraw.business.module.points.available.service.mapper.PointsAvailableMapper; |
| 11 | import com.topdraw.util.RedissonUtil; | 8 | import com.topdraw.utils.RedisUtils; |
| 12 | import com.topdraw.utils.PageUtil; | ||
| 13 | import com.topdraw.utils.QueryHelp; | ||
| 14 | import com.topdraw.utils.StringUtils; | 9 | import com.topdraw.utils.StringUtils; |
| 15 | import com.topdraw.utils.ValidationUtil; | 10 | import com.topdraw.utils.ValidationUtil; |
| 16 | import org.redisson.api.RLock; | ||
| 17 | import org.redisson.api.RedissonClient; | ||
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.dao.EmptyResultDataAccessException; | 12 | import org.springframework.dao.EmptyResultDataAccessException; |
| 20 | import org.springframework.data.domain.Page; | ||
| 21 | import org.springframework.data.domain.Pageable; | ||
| 22 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 23 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
| 24 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -26,7 +17,6 @@ import org.springframework.util.Assert; | ... | @@ -26,7 +17,6 @@ import org.springframework.util.Assert; |
| 26 | 17 | ||
| 27 | import java.time.LocalDateTime; | 18 | import java.time.LocalDateTime; |
| 28 | import java.util.List; | 19 | import java.util.List; |
| 29 | import java.util.Map; | ||
| 30 | import java.util.Objects; | 20 | import java.util.Objects; |
| 31 | 21 | ||
| 32 | /** | 22 | /** |
| ... | @@ -38,147 +28,149 @@ import java.util.Objects; | ... | @@ -38,147 +28,149 @@ import java.util.Objects; |
| 38 | public class PointsAvailableServiceImpl implements PointsAvailableService { | 28 | public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 39 | 29 | ||
| 40 | @Autowired | 30 | @Autowired |
| 41 | private PointsAvailableRepository PointsAvailableRepository; | 31 | private PointsAvailableRepository pointsAvailableRepository; |
| 42 | |||
| 43 | @Autowired | 32 | @Autowired |
| 44 | private PointsAvailableMapper PointsAvailableMapper; | 33 | private PointsAvailableMapper pointsAvailableMapper; |
| 45 | |||
| 46 | @Autowired | 34 | @Autowired |
| 47 | private MemberService memberService; | 35 | private RedisUtils redisUtils; |
| 48 | |||
| 49 | @Override | ||
| 50 | public Map<String, Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable) { | ||
| 51 | Page<PointsAvailable> page = PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> | ||
| 52 | QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 53 | return PageUtil.toPage(page.map(PointsAvailableMapper::toDto)); | ||
| 54 | } | ||
| 55 | 36 | ||
| 56 | @Override | 37 | @Override |
| 57 | public List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId) { | 38 | public List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId) { |
| 58 | return PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId)); | 39 | return this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId)); |
| 59 | } | ||
| 60 | |||
| 61 | @Override | ||
| 62 | public List<PointsAvailableDTO> queryAll(PointsAvailableQueryCriteria criteria) { | ||
| 63 | return PointsAvailableMapper.toDto(PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 64 | } | 40 | } |
| 65 | 41 | ||
| 66 | @Override | 42 | @Override |
| 67 | public PointsAvailableDTO findById(Long id) { | 43 | public PointsAvailableDTO findById(Long id) { |
| 68 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new); | 44 | PointsAvailable pointsAvailable = this.pointsAvailableRepository.findById(id).orElseGet(PointsAvailable::new); |
| 69 | ValidationUtil.isNull(PointsAvailable.getId(),"PointsAvailable","id",id); | 45 | ValidationUtil.isNull(pointsAvailable.getId(),"PointsAvailable","id",id); |
| 70 | return PointsAvailableMapper.toDto(PointsAvailable); | 46 | return this.pointsAvailableMapper.toDto(pointsAvailable); |
| 71 | } | 47 | } |
| 72 | 48 | ||
| 73 | @Override | 49 | @Override |
| 74 | @Transactional(rollbackFor = Exception.class) | 50 | @Transactional(rollbackFor = Exception.class) |
| 75 | public void create(PointsAvailable resources) { | 51 | public PointsAvailableDTO create(PointsAvailable resources) { |
| 76 | String memberCode = resources.getMemberCode(); | 52 | try { |
| 77 | if (StringUtils.isNotEmpty(memberCode)) { | ||
| 78 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 79 | if (Objects.nonNull(memberDTO)) { | ||
| 80 | Long memberId = memberDTO.getId(); | ||
| 81 | resources.setMemberId(memberId); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | 53 | ||
| 85 | PointsAvailableRepository.save(resources); | 54 | this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString()); |
| 86 | } | 55 | PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources); |
| 87 | 56 | ||
| 88 | @Override | 57 | return this.pointsAvailableMapper.toDto(pointsAvailable); |
| 89 | @Transactional(rollbackFor = Exception.class) | ||
| 90 | public void update(PointsAvailable resources) { | ||
| 91 | try { | ||
| 92 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new); | ||
| 93 | ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId()); | ||
| 94 | PointsAvailable.copy(resources); | ||
| 95 | PointsAvailableRepository.save(PointsAvailable); | ||
| 96 | } catch (Exception e) { | 58 | } catch (Exception e) { |
| 97 | e.printStackTrace(); | 59 | e.printStackTrace(); |
| 98 | throw e; | 60 | throw e; |
| 61 | } finally { | ||
| 62 | this.redisUtils.doUnLock("PointsAvailable::create::id"+resources.getMemberId().toString()); | ||
| 99 | } | 63 | } |
| 100 | } | 64 | } |
| 101 | 65 | ||
| 102 | @Override | 66 | @Override |
| 103 | @Transactional(rollbackFor = Exception.class) | 67 | @Transactional(rollbackFor = Exception.class) |
| 104 | public void delete(Long id) { | 68 | public PointsAvailableDTO update(PointsAvailable resources) { |
| 105 | Assert.notNull(id, "The given id must not be null!"); | ||
| 106 | try { | 69 | try { |
| 107 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | 70 | this.redisUtils.doLock("PointsAvailable::update::id"+resources.getMemberId().toString()); |
| 108 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | 71 | PointsAvailable pointsAvailable = this.pointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new); |
| 109 | PointsAvailableRepository.delete(PointsAvailable); | 72 | ValidationUtil.isNull(pointsAvailable.getId(),"PointsAvailable","id",resources.getId()); |
| 73 | pointsAvailable.copy(resources); | ||
| 74 | PointsAvailable _pointsAvailable = this.pointsAvailableRepository.save(pointsAvailable); | ||
| 75 | |||
| 76 | return this.pointsAvailableMapper.toDto(_pointsAvailable); | ||
| 110 | } catch (Exception e) { | 77 | } catch (Exception e) { |
| 111 | e.printStackTrace(); | 78 | e.printStackTrace(); |
| 112 | throw e; | 79 | throw e; |
| 80 | } finally { | ||
| 81 | this.redisUtils.doUnLock("PointsAvailable::update::id"+resources.getMemberId().toString()); | ||
| 113 | } | 82 | } |
| 114 | } | 83 | } |
| 115 | 84 | ||
| 116 | @Override | 85 | @Override |
| 117 | public void delete4Custom(Long id) { | 86 | @Transactional(rollbackFor = Exception.class) |
| 87 | public void delete(Long id) { | ||
| 118 | Assert.notNull(id, "The given id must not be null!"); | 88 | Assert.notNull(id, "The given id must not be null!"); |
| 89 | this.redisUtils.doLock("PointsAvailable::delete::id"+id); | ||
| 119 | try { | 90 | try { |
| 120 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | 91 | PointsAvailable PointsAvailable = this.pointsAvailableRepository.findById(id).orElseThrow( |
| 121 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | 92 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.points.available.domain.PointsAvailable.class, id), 1)); |
| 122 | PointsAvailableRepository.delete(PointsAvailable); | 93 | this.pointsAvailableRepository.delete(PointsAvailable); |
| 123 | } catch (Exception e) { | 94 | } catch (Exception e) { |
| 124 | e.printStackTrace(); | 95 | e.printStackTrace(); |
| 125 | throw e; | 96 | throw e; |
| 97 | } finally { | ||
| 98 | this.redisUtils.doLock("PointsAvailable::delete::id"+id); | ||
| 126 | } | 99 | } |
| 127 | } | 100 | } |
| 128 | 101 | ||
| 129 | @Override | 102 | @Override |
| 130 | @Transactional(rollbackFor = Exception.class) | 103 | @Transactional(rollbackFor = Exception.class) |
| 131 | public void deleteBatchByIds(List<Long> id) { | 104 | public void deleteBatchByIds(List<Long> id) { |
| 105 | this.redisUtils.doLock("PointsAvailable::create::id"+id); | ||
| 132 | try { | 106 | try { |
| 133 | PointsAvailableRepository.deleteBatchByIds(id); | 107 | this.pointsAvailableRepository.deleteBatchByIds(id); |
| 134 | } catch (Exception e) { | 108 | } catch (Exception e) { |
| 135 | e.printStackTrace(); | 109 | e.printStackTrace(); |
| 136 | throw e; | 110 | throw e; |
| 111 | } finally { | ||
| 112 | this.redisUtils.doUnLock("PointsAvailable::create::id"+id); | ||
| 137 | } | 113 | } |
| 138 | } | 114 | } |
| 139 | 115 | ||
| 140 | 116 | ||
| 141 | @Override | 117 | @Override |
| 142 | public PointsAvailableDTO getByCode(String code) { | 118 | public PointsAvailableDTO getByCode(String code) { |
| 143 | return StringUtils.isNotEmpty(code) ? PointsAvailableMapper.toDto(PointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new)) | 119 | return StringUtils.isNotEmpty(code) ? this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findFirstByCode(code).orElseGet(PointsAvailable::new)) |
| 144 | : new PointsAvailableDTO(); | 120 | : new PointsAvailableDTO(); |
| 145 | } | 121 | } |
| 146 | 122 | ||
| 147 | @Override | 123 | @Override |
| 148 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime timestamp) { | 124 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime timestamp) { |
| 149 | return Objects.nonNull(memberId)? | 125 | return Objects.nonNull(memberId)? |
| 150 | PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp)) | 126 | this.pointsAvailableMapper.toDto(this.pointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp)) |
| 151 | :null; | 127 | :null; |
| 152 | } | 128 | } |
| 153 | 129 | ||
| 154 | @Override | 130 | @Override |
| 155 | public Long findSoonExpireTime(Long memberId, Integer factor) { | 131 | public Long findSoonExpireTime(Long memberId, Integer factor) { |
| 156 | return PointsAvailableRepository.findSoonExpireTime(memberId, factor); | 132 | return this.pointsAvailableRepository.findSoonExpireTime(memberId, factor); |
| 157 | } | 133 | } |
| 158 | 134 | ||
| 159 | @Override | 135 | @Override |
| 160 | public long findAvailablePointsByMemberId(long memberId) { | 136 | public long findAvailablePointsByMemberId(long memberId) { |
| 161 | Long availablePoints = this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId); | 137 | Long availablePoints = this.pointsAvailableRepository.findAvailablePointsByMemberId(memberId); |
| 162 | return availablePoints == null ? 0L : availablePoints; | 138 | return availablePoints == null ? 0L : availablePoints; |
| 163 | } | 139 | } |
| 164 | 140 | ||
| 165 | @Override | 141 | @Override |
| 166 | public long findTotalPointsByMemberId(Long memberId) { | 142 | public long findTotalPointsByMemberId(Long memberId) { |
| 167 | return this.PointsAvailableRepository.findTotalCountByMemberId(memberId); | 143 | return this.pointsAvailableRepository.findTotalCountByMemberId(memberId); |
| 168 | } | 144 | } |
| 169 | 145 | ||
| 170 | @Override | 146 | @Override |
| 171 | public void create4Custom(PointsAvailable resources) { | 147 | public void delete4Custom(Long id) { |
| 172 | String memberCode = resources.getMemberCode(); | 148 | Assert.notNull(id, "The given id must not be null!"); |
| 173 | if (StringUtils.isNotEmpty(memberCode)) { | 149 | this.redisUtils.doLock("PointsAvailable::delete::id"+id); |
| 174 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 150 | try { |
| 175 | if (Objects.nonNull(memberDTO)) { | 151 | PointsAvailable PointsAvailable = this.pointsAvailableRepository.findById(id).orElseThrow( |
| 176 | Long memberId = memberDTO.getId(); | 152 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.points.available.domain.PointsAvailable.class, id), 1)); |
| 177 | resources.setMemberId(memberId); | 153 | this.pointsAvailableRepository.delete(PointsAvailable); |
| 178 | } | 154 | } catch (Exception e) { |
| 155 | e.printStackTrace(); | ||
| 156 | throw e; | ||
| 157 | } finally { | ||
| 158 | this.redisUtils.doUnLock("PointsAvailable::delete::id"+id); | ||
| 179 | } | 159 | } |
| 160 | } | ||
| 180 | 161 | ||
| 181 | PointsAvailableRepository.save(resources); | 162 | @Override |
| 163 | public PointsAvailableDTO create4Custom(PointsAvailable resources) { | ||
| 164 | this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString()); | ||
| 165 | try { | ||
| 166 | PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources); | ||
| 167 | return this.pointsAvailableMapper.toDto(pointsAvailable); | ||
| 168 | } catch (Exception e) { | ||
| 169 | e.printStackTrace(); | ||
| 170 | throw e; | ||
| 171 | } finally { | ||
| 172 | this.redisUtils.doUnLock("PointsAvailable::create::id"+resources.getMemberId().toString()); | ||
| 173 | } | ||
| 182 | } | 174 | } |
| 183 | 175 | ||
| 184 | } | 176 | } | ... | ... |
| 1 | package com.topdraw.business.module.points.detail.detailhistory.service.impl; | 1 | package com.topdraw.business.module.points.detail.detailhistory.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory; | 3 | import com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory; |
| 4 | import com.topdraw.business.module.points.detail.detailhistory.repository.PointsDetailHistoryRepository; | ||
| 5 | import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService; | 4 | import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService; |
| 6 | import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO; | 5 | import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryDTO; |
| 7 | import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria; | 6 | import com.topdraw.business.module.points.detail.detailhistory.service.dto.PointsDetailHistoryQueryCriteria; |
| 8 | import com.topdraw.business.module.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper; | ||
| 9 | import com.topdraw.utils.PageUtil; | 7 | import com.topdraw.utils.PageUtil; |
| 10 | import com.topdraw.utils.QueryHelp; | 8 | import com.topdraw.utils.QueryHelp; |
| 11 | import com.topdraw.utils.StringUtils; | 9 | import com.topdraw.utils.StringUtils; |
| ... | @@ -31,10 +29,10 @@ import java.util.Map; | ... | @@ -31,10 +29,10 @@ import java.util.Map; |
| 31 | public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryService { | 29 | public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryService { |
| 32 | 30 | ||
| 33 | @Autowired | 31 | @Autowired |
| 34 | private PointsDetailHistoryRepository PointsDetailHistoryRepository; | 32 | private com.topdraw.business.module.points.detail.detailhistory.repository.PointsDetailHistoryRepository PointsDetailHistoryRepository; |
| 35 | 33 | ||
| 36 | @Autowired | 34 | @Autowired |
| 37 | private PointsDetailHistoryMapper PointsDetailHistoryMapper; | 35 | private com.topdraw.business.module.points.detail.detailhistory.service.mapper.PointsDetailHistoryMapper PointsDetailHistoryMapper; |
| 38 | 36 | ||
| 39 | @Override | 37 | @Override |
| 40 | public Map<String, Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) { | 38 | public Map<String, Object> queryAll(PointsDetailHistoryQueryCriteria criteria, Pageable pageable) { |
| ... | @@ -49,7 +47,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic | ... | @@ -49,7 +47,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic |
| 49 | 47 | ||
| 50 | @Override | 48 | @Override |
| 51 | public PointsDetailHistoryDTO findById(Long id) { | 49 | public PointsDetailHistoryDTO findById(Long id) { |
| 52 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(PointsDetailHistory::new); | 50 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseGet(com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory::new); |
| 53 | ValidationUtil.isNull(PointsDetailHistory.getId(),"PointsDetailHistory","id",id); | 51 | ValidationUtil.isNull(PointsDetailHistory.getId(),"PointsDetailHistory","id",id); |
| 54 | return PointsDetailHistoryMapper.toDto(PointsDetailHistory); | 52 | return PointsDetailHistoryMapper.toDto(PointsDetailHistory); |
| 55 | } | 53 | } |
| ... | @@ -63,7 +61,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic | ... | @@ -63,7 +61,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic |
| 63 | @Override | 61 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 62 | @Transactional(rollbackFor = Exception.class) |
| 65 | public void update(PointsDetailHistory resources) { | 63 | public void update(PointsDetailHistory resources) { |
| 66 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(PointsDetailHistory::new); | 64 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory::new); |
| 67 | ValidationUtil.isNull( PointsDetailHistory.getId(),"PointsDetailHistory","id",resources.getId()); | 65 | ValidationUtil.isNull( PointsDetailHistory.getId(),"PointsDetailHistory","id",resources.getId()); |
| 68 | PointsDetailHistory.copy(resources); | 66 | PointsDetailHistory.copy(resources); |
| 69 | PointsDetailHistoryRepository.save(PointsDetailHistory); | 67 | PointsDetailHistoryRepository.save(PointsDetailHistory); |
| ... | @@ -74,7 +72,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic | ... | @@ -74,7 +72,7 @@ public class PointsDetailHistoryServiceImpl implements PointsDetailHistoryServic |
| 74 | public void delete(Long id) { | 72 | public void delete(Long id) { |
| 75 | Assert.notNull(id, "The given id must not be null!"); | 73 | Assert.notNull(id, "The given id must not be null!"); |
| 76 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseThrow( | 74 | PointsDetailHistory PointsDetailHistory = PointsDetailHistoryRepository.findById(id).orElseThrow( |
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetailHistory.class, id), 1)); | 75 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.points.detail.detailhistory.domain.PointsDetailHistory.class, id), 1)); |
| 78 | PointsDetailHistoryRepository.delete(PointsDetailHistory); | 76 | PointsDetailHistoryRepository.delete(PointsDetailHistory); |
| 79 | } | 77 | } |
| 80 | 78 | ... | ... |
| ... | @@ -84,6 +84,10 @@ public class PointsDetail implements Serializable { | ... | @@ -84,6 +84,10 @@ public class PointsDetail implements Serializable { |
| 84 | @Column(name = "description", nullable = false) | 84 | @Column(name = "description", nullable = false) |
| 85 | private String description; | 85 | private String description; |
| 86 | 86 | ||
| 87 | // 商品id | ||
| 88 | @Column(name = "item_id") | ||
| 89 | private Long itemId; | ||
| 90 | |||
| 87 | // 创建时间 | 91 | // 创建时间 |
| 88 | @CreatedDate | 92 | @CreatedDate |
| 89 | @Column(name = "create_time") | 93 | @Column(name = "create_time") | ... | ... |
| ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.points.detail.service; | ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.points.detail.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.points.detail.domain.PointsDetail; | 3 | import com.topdraw.business.module.points.detail.domain.PointsDetail; |
| 4 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO; | 4 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO; |
| 5 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.util.List; | 6 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -15,33 +12,30 @@ import java.util.Map; | ... | @@ -15,33 +12,30 @@ import java.util.Map; |
| 15 | public interface PointsDetailService { | 12 | public interface PointsDetailService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<PointsDetailDTO> | ||
| 29 | */ | ||
| 30 | List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 15 | * 根据ID查询 |
| 34 | * @param id ID | 16 | * @param id ID |
| 35 | * @return PointsDetailDTO | 17 | * @return PointsDetailDTO |
| 36 | */ | 18 | */ |
| 37 | PointsDetailDTO findById(Long id); | 19 | PointsDetailDTO findById(Long id); |
| 38 | 20 | ||
| 39 | void create(PointsDetail resources); | 21 | /** |
| 40 | 22 | * | |
| 41 | void create4Custom(PointsDetail resources); | 23 | * @param resources |
| 24 | * @return | ||
| 25 | */ | ||
| 26 | PointsDetailDTO create(PointsDetail resources); | ||
| 42 | 27 | ||
| 43 | void update(PointsDetail resources); | 28 | /** |
| 29 | * | ||
| 30 | * @param resources | ||
| 31 | * @return | ||
| 32 | */ | ||
| 33 | PointsDetailDTO update(PointsDetail resources); | ||
| 44 | 34 | ||
| 35 | /** | ||
| 36 | * | ||
| 37 | * @param id | ||
| 38 | */ | ||
| 45 | void delete(Long id); | 39 | void delete(Long id); |
| 46 | 40 | ||
| 47 | /** | 41 | /** |
| ... | @@ -51,13 +45,23 @@ public interface PointsDetailService { | ... | @@ -51,13 +45,23 @@ public interface PointsDetailService { |
| 51 | */ | 45 | */ |
| 52 | PointsDetailDTO getByCode(String code); | 46 | PointsDetailDTO getByCode(String code); |
| 53 | 47 | ||
| 48 | /** | ||
| 49 | * | ||
| 50 | * @param memberId | ||
| 51 | * @return | ||
| 52 | */ | ||
| 54 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); | 53 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); |
| 55 | 54 | ||
| 56 | |||
| 57 | /** | 55 | /** |
| 58 | * 已过期的积分 | 56 | * 已过期的积分 |
| 59 | * @param memberId | 57 | * @param memberId |
| 60 | * @return | 58 | * @return |
| 61 | */ | 59 | */ |
| 62 | List<PointsDetailDTO> findByMemberId(Long memberId); | 60 | List<PointsDetailDTO> findByMemberId(Long memberId); |
| 61 | |||
| 62 | /** | ||
| 63 | * | ||
| 64 | * @param pointsDetail | ||
| 65 | */ | ||
| 66 | void create4Custom(PointsDetail pointsDetail); | ||
| 63 | } | 67 | } | ... | ... |
| ... | @@ -55,6 +55,9 @@ public class PointsDetailDTO implements Serializable { | ... | @@ -55,6 +55,9 @@ public class PointsDetailDTO implements Serializable { |
| 55 | // 积分变化描述,用于管理侧显示 | 55 | // 积分变化描述,用于管理侧显示 |
| 56 | private String description; | 56 | private String description; |
| 57 | 57 | ||
| 58 | // 商品id | ||
| 59 | private Long itemId; | ||
| 60 | |||
| 58 | // 创建时间 | 61 | // 创建时间 |
| 59 | private Timestamp createTime; | 62 | private Timestamp createTime; |
| 60 | 63 | ... | ... |
| 1 | package com.topdraw.business.module.points.detail.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Query; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author XiangHan | ||
| 8 | * @date 2021-10-22 | ||
| 9 | */ | ||
| 10 | @Data | ||
| 11 | public class PointsDetailQueryCriteria{ | ||
| 12 | |||
| 13 | @Query(type = Query.Type.EQUAL) | ||
| 14 | private Long memberId; | ||
| 15 | |||
| 16 | @Query(type = Query.Type.EQUAL) | ||
| 17 | private Long accountId; | ||
| 18 | |||
| 19 | } |
| 1 | package com.topdraw.business.module.points.detail.service.impl; | 1 | package com.topdraw.business.module.points.detail.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.service.MemberService; | ||
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 5 | import com.topdraw.business.module.points.detail.domain.PointsDetail; | 3 | import com.topdraw.business.module.points.detail.domain.PointsDetail; |
| 6 | import com.topdraw.business.module.points.detail.repository.PointsDetailRepository; | 4 | import com.topdraw.business.module.points.detail.repository.PointsDetailRepository; |
| 7 | import com.topdraw.business.module.points.detail.service.PointsDetailService; | 5 | import com.topdraw.business.module.points.detail.service.PointsDetailService; |
| 8 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO; | 6 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailDTO; |
| 9 | import com.topdraw.business.module.points.detail.service.dto.PointsDetailQueryCriteria; | ||
| 10 | import com.topdraw.business.module.points.detail.service.mapper.PointsDetailMapper; | 7 | import com.topdraw.business.module.points.detail.service.mapper.PointsDetailMapper; |
| 11 | import com.topdraw.utils.PageUtil; | ||
| 12 | import com.topdraw.utils.QueryHelp; | ||
| 13 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 14 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.dao.EmptyResultDataAccessException; | 11 | import org.springframework.dao.EmptyResultDataAccessException; |
| 17 | import org.springframework.data.domain.Page; | ||
| 18 | import org.springframework.data.domain.Pageable; | ||
| 19 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 23 | 16 | ||
| 24 | import java.util.List; | 17 | import java.util.List; |
| 25 | import java.util.Map; | ||
| 26 | import java.util.Objects; | 18 | import java.util.Objects; |
| 27 | 19 | ||
| 28 | /** | 20 | /** |
| ... | @@ -34,81 +26,47 @@ import java.util.Objects; | ... | @@ -34,81 +26,47 @@ import java.util.Objects; |
| 34 | public class PointsDetailServiceImpl implements PointsDetailService { | 26 | public class PointsDetailServiceImpl implements PointsDetailService { |
| 35 | 27 | ||
| 36 | @Autowired | 28 | @Autowired |
| 37 | private PointsDetailRepository PointsDetailRepository; | 29 | private PointsDetailRepository pointsDetailRepository; |
| 38 | |||
| 39 | @Autowired | ||
| 40 | private MemberService memberService; | ||
| 41 | |||
| 42 | @Autowired | 30 | @Autowired |
| 43 | private PointsDetailMapper PointsDetailMapper; | 31 | private PointsDetailMapper pointsDetailMapper; |
| 44 | |||
| 45 | @Override | ||
| 46 | public Map<String, Object> queryAll(PointsDetailQueryCriteria criteria, Pageable pageable) { | ||
| 47 | Page<PointsDetail> page = PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 48 | return PageUtil.toPage(page.map(PointsDetailMapper::toDto)); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public List<PointsDetailDTO> queryAll(PointsDetailQueryCriteria criteria) { | ||
| 53 | return PointsDetailMapper.toDto(PointsDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 54 | } | ||
| 55 | 32 | ||
| 56 | @Override | 33 | @Override |
| 57 | public PointsDetailDTO findById(Long id) { | 34 | public PointsDetailDTO findById(Long id) { |
| 58 | PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseGet(PointsDetail::new); | 35 | PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new); |
| 59 | ValidationUtil.isNull(PointsDetail.getId(),"PointsDetail","id",id); | 36 | ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id); |
| 60 | return PointsDetailMapper.toDto(PointsDetail); | 37 | return this.pointsDetailMapper.toDto(pointsDetail); |
| 61 | } | 38 | } |
| 62 | 39 | ||
| 63 | @Override | 40 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 41 | @Transactional(rollbackFor = Exception.class) |
| 65 | public void create(PointsDetail resources) { | 42 | public PointsDetailDTO create(PointsDetail resources) { |
| 66 | String memberCode = resources.getMemberCode(); | 43 | PointsDetail pointsDetail = this.pointsDetailRepository.save(resources); |
| 67 | if (StringUtils.isNotEmpty(memberCode)) { | 44 | return this.pointsDetailMapper.toDto(pointsDetail); |
| 68 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 69 | if (Objects.nonNull(memberDTO)) { | ||
| 70 | Long memberId = memberDTO.getId(); | ||
| 71 | resources.setMemberId(memberId); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | PointsDetailRepository.save(resources); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Override | ||
| 78 | public void create4Custom(PointsDetail resources) { | ||
| 79 | String memberCode = resources.getMemberCode(); | ||
| 80 | if (StringUtils.isNotEmpty(memberCode)) { | ||
| 81 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 82 | if (Objects.nonNull(memberDTO)) { | ||
| 83 | Long memberId = memberDTO.getId(); | ||
| 84 | resources.setMemberId(memberId); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | PointsDetailRepository.save(resources); | ||
| 88 | } | 45 | } |
| 89 | 46 | ||
| 90 | @Override | 47 | @Override |
| 91 | @Transactional(rollbackFor = Exception.class) | 48 | @Transactional(rollbackFor = Exception.class) |
| 92 | public void update(PointsDetail resources) { | 49 | public PointsDetailDTO update(PointsDetail resources) { |
| 93 | PointsDetail PointsDetail = PointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new); | 50 | PointsDetail pointsDetail = this.pointsDetailRepository.findById(resources.getId()).orElseGet(PointsDetail::new); |
| 94 | ValidationUtil.isNull( PointsDetail.getId(),"PointsDetail","id",resources.getId()); | 51 | ValidationUtil.isNull( pointsDetail.getId(),"PointsDetail","id",resources.getId()); |
| 95 | PointsDetail.copy(resources); | 52 | pointsDetail.copy(resources); |
| 96 | PointsDetailRepository.save(PointsDetail); | 53 | PointsDetail _pointsDetail = this.pointsDetailRepository.save(pointsDetail); |
| 54 | return this.pointsDetailMapper.toDto(_pointsDetail); | ||
| 97 | } | 55 | } |
| 98 | 56 | ||
| 99 | @Override | 57 | @Override |
| 100 | @Transactional(rollbackFor = Exception.class) | 58 | @Transactional(rollbackFor = Exception.class) |
| 101 | public void delete(Long id) { | 59 | public void delete(Long id) { |
| 102 | Assert.notNull(id, "The given id must not be null!"); | 60 | Assert.notNull(id, "The given id must not be null!"); |
| 103 | PointsDetail PointsDetail = PointsDetailRepository.findById(id).orElseThrow( | 61 | PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseThrow( |
| 104 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetail.class, id), 1)); | 62 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsDetail.class, id), 1)); |
| 105 | PointsDetailRepository.delete(PointsDetail); | 63 | this.pointsDetailRepository.delete(pointsDetail); |
| 106 | } | 64 | } |
| 107 | 65 | ||
| 108 | 66 | ||
| 109 | @Override | 67 | @Override |
| 110 | public PointsDetailDTO getByCode(String code) { | 68 | public PointsDetailDTO getByCode(String code) { |
| 111 | return StringUtils.isNotEmpty(code) ? PointsDetailMapper.toDto(PointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) | 69 | return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) |
| 112 | : new PointsDetailDTO(); | 70 | : new PointsDetailDTO(); |
| 113 | } | 71 | } |
| 114 | 72 | ||
| ... | @@ -120,7 +78,12 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -120,7 +78,12 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 120 | @Override | 78 | @Override |
| 121 | public List<PointsDetailDTO> findByMemberId(Long memberId) { | 79 | public List<PointsDetailDTO> findByMemberId(Long memberId) { |
| 122 | return Objects.nonNull(memberId)? | 80 | return Objects.nonNull(memberId)? |
| 123 | PointsDetailMapper.toDto(PointsDetailRepository.findByMemberId(memberId)) | 81 | this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId)) |
| 124 | :null; | 82 | :null; |
| 125 | } | 83 | } |
| 84 | |||
| 85 | @Override | ||
| 86 | public void create4Custom(PointsDetail pointsDetail) { | ||
| 87 | this.pointsDetailRepository.save(pointsDetail); | ||
| 88 | } | ||
| 126 | } | 89 | } | ... | ... |
| ... | @@ -24,38 +24,41 @@ import java.sql.Timestamp; | ... | @@ -24,38 +24,41 @@ import java.sql.Timestamp; |
| 24 | public class Points implements Serializable { | 24 | public class Points implements Serializable { |
| 25 | 25 | ||
| 26 | @Id | 26 | @Id |
| 27 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 27 | @Column(name = "id") | 28 | @Column(name = "id") |
| 28 | private Long id; | 29 | private Long id; |
| 29 | 30 | ||
| 31 | /** 账号id */ | ||
| 30 | @Column(name = "user_id") | 32 | @Column(name = "user_id") |
| 31 | private Long userId; | 33 | private Long userId; |
| 32 | 34 | ||
| 33 | // 积分类型,通用,绑定, 区分大小屏 | 35 | /** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) |
| 36 | 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)*/ | ||
| 34 | @Column(name = "point_type") | 37 | @Column(name = "point_type") |
| 35 | private Integer pointType; | 38 | private Integer pointType; |
| 36 | 39 | ||
| 37 | // 绑定对应的实体, 如何描述? | 40 | /** 绑定对应的实体, 如何描述? */ |
| 38 | @Column(name = "target_no") | 41 | @Column(name = "target_no") |
| 39 | private String targetNo; | 42 | private String targetNo; |
| 40 | 43 | ||
| 41 | // 本月期初积分值 | 44 | /** 本月期初积分值 */ |
| 42 | @Column(name = "begin_points") | 45 | @Column(name = "begin_points") |
| 43 | private Integer beginPoints; | 46 | private Integer beginPoints; |
| 44 | 47 | ||
| 45 | // 当前积分余额 | 48 | /** 当前积分余额 */ |
| 46 | @Column(name = "current_points") | 49 | @Column(name = "current_points") |
| 47 | private Integer currentPoints; | 50 | private Integer currentPoints; |
| 48 | 51 | ||
| 49 | // 本月到期积分 | 52 | /** 本月到期积分 */ |
| 50 | @Column(name = "expire_points") | 53 | @Column(name = "expire_points") |
| 51 | private Integer expirePoints; | 54 | private Integer expirePoints; |
| 52 | 55 | ||
| 53 | // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途) | 56 | /** 创建时间 */ |
| 54 | @CreatedDate | 57 | @CreatedDate |
| 55 | @Column(name = "create_time") | 58 | @Column(name = "create_time") |
| 56 | private Timestamp createTime; | 59 | private Timestamp createTime; |
| 57 | 60 | ||
| 58 | // 最后修改时间 | 61 | /** 最后修改时间 */ |
| 59 | @LastModifiedDate | 62 | @LastModifiedDate |
| 60 | @Column(name = "update_time") | 63 | @Column(name = "update_time") |
| 61 | private Timestamp updateTime; | 64 | private Timestamp updateTime; | ... | ... |
| ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.points.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.points.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.points.domain.Points; | 3 | import com.topdraw.business.module.points.domain.Points; |
| 4 | import com.topdraw.business.module.points.service.dto.PointsDTO; | 4 | import com.topdraw.business.module.points.service.dto.PointsDTO; |
| 5 | import com.topdraw.business.module.points.service.dto.PointsQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 5 | ||
| 11 | /** | 6 | /** |
| 12 | * @author XiangHan | 7 | * @author XiangHan |
| ... | @@ -15,31 +10,28 @@ import java.util.Map; | ... | @@ -15,31 +10,28 @@ import java.util.Map; |
| 15 | public interface PointsService { | 10 | public interface PointsService { |
| 16 | 11 | ||
| 17 | /** | 12 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(PointsQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<PointsDTO> | ||
| 29 | */ | ||
| 30 | List<PointsDTO> queryAll(PointsQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 13 | * 根据ID查询 |
| 34 | * @param id ID | 14 | * @param id ID |
| 35 | * @return PointsDTO | 15 | * @return PointsDTO |
| 36 | */ | 16 | */ |
| 37 | PointsDTO findById(Long id); | 17 | PointsDTO findById(Long id); |
| 38 | 18 | ||
| 39 | void create(Points resources); | 19 | /** |
| 20 | * | ||
| 21 | * @param resources | ||
| 22 | */ | ||
| 23 | PointsDTO create(Points resources); | ||
| 40 | 24 | ||
| 41 | void update(Points resources); | 25 | /** |
| 26 | * | ||
| 27 | * @param resources | ||
| 28 | */ | ||
| 29 | PointsDTO update(Points resources); | ||
| 42 | 30 | ||
| 31 | /** | ||
| 32 | * | ||
| 33 | * @param id | ||
| 34 | */ | ||
| 43 | void delete(Long id); | 35 | void delete(Long id); |
| 44 | 36 | ||
| 45 | } | 37 | } | ... | ... |
| ... | @@ -19,26 +19,30 @@ public class PointsDTO implements Serializable { | ... | @@ -19,26 +19,30 @@ public class PointsDTO implements Serializable { |
| 19 | @JsonSerialize(using= ToStringSerializer.class) | 19 | @JsonSerialize(using= ToStringSerializer.class) |
| 20 | private Long id; | 20 | private Long id; |
| 21 | 21 | ||
| 22 | /** 账号id */ | ||
| 22 | private Long userId; | 23 | private Long userId; |
| 23 | 24 | ||
| 24 | // 积分类型,通用,绑定, 区分大小屏 todo | 25 | /** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) |
| 26 | 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途)*/ | ||
| 25 | private Integer pointType; | 27 | private Integer pointType; |
| 26 | 28 | ||
| 27 | // 绑定对应的实体, 如何描述? | 29 | /** 绑定对应的实体, 如何描述? */ |
| 28 | private String targetNo; | 30 | private String targetNo; |
| 29 | 31 | ||
| 30 | // 本月期初积分值 | 32 | /** 本月期初积分值 */ |
| 31 | private Integer beginPoints; | 33 | private Integer beginPoints; |
| 32 | 34 | ||
| 33 | // 当前积分余额 | 35 | /** 当前积分余额 */ |
| 34 | private Integer currentPoints; | 36 | private Integer currentPoints; |
| 35 | 37 | ||
| 36 | // 本月到期积分 | 38 | /** 本月到期积分 */ |
| 37 | private Integer expirePoints; | 39 | private Integer expirePoints; |
| 38 | 40 | ||
| 39 | // 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途) | 41 | /** 积分类型:10:通用积分(跨屏) 11:定向积分(跨屏,绑定用途)20:通用积分(大屏) |
| 42 | * 21:定向积分(大屏,绑定用途)30:通用积分(小屏) 31:定向积分(小屏,绑定用途) | ||
| 43 | */ | ||
| 40 | private Timestamp createTime; | 44 | private Timestamp createTime; |
| 41 | 45 | ||
| 42 | // 最后修改时间 | 46 | /** 最后修改时间 */ |
| 43 | private Timestamp updateTime; | 47 | private Timestamp updateTime; |
| 44 | } | 48 | } | ... | ... |
| 1 | package com.topdraw.business.module.points.service.impl; | 1 | package com.topdraw.business.module.points.service.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Snowflake; | ||
| 4 | import cn.hutool.core.util.IdUtil; | ||
| 5 | import com.topdraw.business.module.points.domain.Points; | 3 | import com.topdraw.business.module.points.domain.Points; |
| 6 | import com.topdraw.business.module.points.repository.PointsRepository; | 4 | import com.topdraw.business.module.points.repository.PointsRepository; |
| 7 | import com.topdraw.business.module.points.service.PointsService; | 5 | import com.topdraw.business.module.points.service.PointsService; |
| 8 | import com.topdraw.business.module.points.service.dto.PointsDTO; | 6 | import com.topdraw.business.module.points.service.dto.PointsDTO; |
| 9 | import com.topdraw.business.module.points.service.dto.PointsQueryCriteria; | ||
| 10 | import com.topdraw.business.module.points.service.mapper.PointsMapper; | 7 | import com.topdraw.business.module.points.service.mapper.PointsMapper; |
| 11 | import com.topdraw.util.RedissonUtil; | 8 | import com.topdraw.utils.RedisUtils; |
| 12 | import com.topdraw.utils.PageUtil; | ||
| 13 | import com.topdraw.utils.QueryHelp; | ||
| 14 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 15 | import org.redisson.api.RLock; | ||
| 16 | import org.redisson.api.RedissonClient; | ||
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 18 | import org.springframework.dao.EmptyResultDataAccessException; | 11 | import org.springframework.dao.EmptyResultDataAccessException; |
| 19 | import org.springframework.data.domain.Page; | ||
| 20 | import org.springframework.data.domain.Pageable; | ||
| 21 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 22 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 23 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 24 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 25 | 16 | ||
| 26 | import java.util.List; | ||
| 27 | import java.util.Map; | ||
| 28 | 17 | ||
| 29 | /** | 18 | /** |
| 30 | * @author XiangHan | 19 | * @author XiangHan |
| ... | @@ -35,48 +24,44 @@ import java.util.Map; | ... | @@ -35,48 +24,44 @@ import java.util.Map; |
| 35 | public class PointsServiceImpl implements PointsService { | 24 | public class PointsServiceImpl implements PointsService { |
| 36 | 25 | ||
| 37 | @Autowired | 26 | @Autowired |
| 38 | private PointsRepository PointsRepository; | 27 | private PointsRepository pointsRepository; |
| 39 | |||
| 40 | @Autowired | 28 | @Autowired |
| 41 | private PointsMapper PointsMapper; | 29 | private PointsMapper pointsMapper; |
| 42 | 30 | @Autowired | |
| 43 | @Override | 31 | private RedisUtils redisUtils; |
| 44 | public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) { | ||
| 45 | Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 46 | return PageUtil.toPage(page.map(PointsMapper::toDto)); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Override | ||
| 50 | public List<PointsDTO> queryAll(PointsQueryCriteria criteria) { | ||
| 51 | return PointsMapper.toDto(PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 52 | } | ||
| 53 | 32 | ||
| 54 | @Override | 33 | @Override |
| 55 | public PointsDTO findById(Long id) { | 34 | public PointsDTO findById(Long id) { |
| 56 | Points Points = PointsRepository.findById(id).orElseGet(Points::new); | 35 | Points Points = this.pointsRepository.findById(id).orElseGet(Points::new); |
| 57 | ValidationUtil.isNull(Points.getId(),"Points","id",id); | 36 | ValidationUtil.isNull(Points.getId(),"Points","id",id); |
| 58 | return PointsMapper.toDto(Points); | 37 | return this.pointsMapper.toDto(Points); |
| 59 | } | 38 | } |
| 60 | 39 | ||
| 61 | @Override | 40 | @Override |
| 62 | @Transactional(rollbackFor = Exception.class) | 41 | @Transactional(rollbackFor = Exception.class) |
| 63 | public void create(Points resources) { | 42 | public PointsDTO create(Points resources) { |
| 64 | Snowflake snowflake = IdUtil.createSnowflake(1, 1); | 43 | |
| 65 | resources.setId(snowflake.nextId()); | 44 | Points points = this.pointsRepository.save(resources); |
| 66 | PointsRepository.save(resources); | 45 | |
| 46 | return this.pointsMapper.toDto(points); | ||
| 67 | } | 47 | } |
| 68 | 48 | ||
| 69 | @Override | 49 | @Override |
| 70 | @Transactional(rollbackFor = Exception.class) | 50 | @Transactional(rollbackFor = Exception.class) |
| 71 | public void update(Points resources) { | 51 | public PointsDTO update(Points resources) { |
| 52 | this.redisUtils.doLock("Points::update::userId"+resources.getUserId().toString()); | ||
| 72 | try { | 53 | try { |
| 73 | Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new); | 54 | Points points = this.pointsRepository.findById(resources.getId()).orElseGet(Points::new); |
| 74 | ValidationUtil.isNull(Points.getId(), "Points", "id", resources.getId()); | 55 | ValidationUtil.isNull(points.getId(), "Points", "id", resources.getId()); |
| 75 | Points.copy(resources); | 56 | points.copy(resources); |
| 76 | PointsRepository.save(Points); | 57 | this.pointsRepository.save(points); |
| 58 | |||
| 59 | return this.pointsMapper.toDto(points); | ||
| 77 | } catch (Exception e) { | 60 | } catch (Exception e) { |
| 78 | e.printStackTrace(); | 61 | e.printStackTrace(); |
| 79 | throw e; | 62 | throw e; |
| 63 | } finally { | ||
| 64 | this.redisUtils.doUnLock("Points::update::userId"+resources.getUserId().toString()); | ||
| 80 | } | 65 | } |
| 81 | } | 66 | } |
| 82 | 67 | ||
| ... | @@ -84,9 +69,9 @@ public class PointsServiceImpl implements PointsService { | ... | @@ -84,9 +69,9 @@ public class PointsServiceImpl implements PointsService { |
| 84 | @Transactional(rollbackFor = Exception.class) | 69 | @Transactional(rollbackFor = Exception.class) |
| 85 | public void delete(Long id) { | 70 | public void delete(Long id) { |
| 86 | Assert.notNull(id, "The given id must not be null!"); | 71 | Assert.notNull(id, "The given id must not be null!"); |
| 87 | Points Points = PointsRepository.findById(id).orElseThrow( | 72 | Points Points = this.pointsRepository.findById(id).orElseThrow( |
| 88 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Points.class, id), 1)); | 73 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Points.class, id), 1)); |
| 89 | PointsRepository.delete(Points); | 74 | this.pointsRepository.delete(Points); |
| 90 | } | 75 | } |
| 91 | 76 | ||
| 92 | 77 | ... | ... |
| 1 | package com.topdraw.business.module.points.standingbook.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author XiangHan | ||
| 9 | * @date 2021-10-29 | ||
| 10 | */ | ||
| 11 | public interface PointsStandingBookRepository extends JpaRepository<PointsStandingBook, Long>, JpaSpecificationExecutor<PointsStandingBook> { | ||
| 12 | |||
| 13 | } |
| 1 | package com.topdraw.business.module.points.standingbook.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook; | ||
| 4 | import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookDTO; | ||
| 5 | import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author XiangHan | ||
| 13 | * @date 2021-10-29 | ||
| 14 | */ | ||
| 15 | public interface PointsStandingBookService { | ||
| 16 | |||
| 17 | /** | ||
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<PointsStandingBookDTO> | ||
| 29 | */ | ||
| 30 | List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | ||
| 34 | * @param id ID | ||
| 35 | * @return PointsStandingBookDTO | ||
| 36 | */ | ||
| 37 | PointsStandingBookDTO findById(Long id); | ||
| 38 | |||
| 39 | void create(PointsStandingBook resources); | ||
| 40 | |||
| 41 | void update(PointsStandingBook resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | } |
| 1 | package com.topdraw.business.module.points.standingbook.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | import java.sql.Timestamp; | ||
| 7 | |||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-10-29 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class PointsStandingBookDTO implements Serializable { | ||
| 15 | |||
| 16 | // 主键 | ||
| 17 | private Long id; | ||
| 18 | |||
| 19 | // 积分生产 | ||
| 20 | private Long pointsProduce; | ||
| 21 | |||
| 22 | // 积分消耗 | ||
| 23 | private Long pointsConsume; | ||
| 24 | |||
| 25 | // 可用总积分 | ||
| 26 | private Long pointsAvailable; | ||
| 27 | |||
| 28 | // 积分过期 | ||
| 29 | private Long pointsExpire; | ||
| 30 | |||
| 31 | // 日期 | ||
| 32 | private String day; | ||
| 33 | |||
| 34 | // 创建时间 | ||
| 35 | private Timestamp createTime; | ||
| 36 | |||
| 37 | // 创建时间 | ||
| 38 | private Timestamp updateTime; | ||
| 39 | } |
| 1 | package com.topdraw.business.module.points.standingbook.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook; | ||
| 4 | import com.topdraw.business.module.points.standingbook.repository.PointsStandingBookRepository; | ||
| 5 | import com.topdraw.business.module.points.standingbook.service.PointsStandingBookService; | ||
| 6 | import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookDTO; | ||
| 7 | import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookQueryCriteria; | ||
| 8 | import com.topdraw.business.module.points.standingbook.service.mapper.PointsStandingBookMapper; | ||
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | ||
| 12 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 14 | import org.springframework.data.domain.Page; | ||
| 15 | import org.springframework.data.domain.Pageable; | ||
| 16 | import org.springframework.stereotype.Service; | ||
| 17 | import org.springframework.transaction.annotation.Propagation; | ||
| 18 | import org.springframework.transaction.annotation.Transactional; | ||
| 19 | import org.springframework.util.Assert; | ||
| 20 | |||
| 21 | import java.util.List; | ||
| 22 | import java.util.Map; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @author XiangHan | ||
| 26 | * @date 2021-10-29 | ||
| 27 | */ | ||
| 28 | @Service | ||
| 29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 30 | public class PointsStandingBookServiceImpl implements PointsStandingBookService { | ||
| 31 | |||
| 32 | @Autowired | ||
| 33 | private PointsStandingBookRepository PointsStandingBookRepository; | ||
| 34 | |||
| 35 | @Autowired | ||
| 36 | private PointsStandingBookMapper PointsStandingBookMapper; | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public Map<String, Object> queryAll(PointsStandingBookQueryCriteria criteria, Pageable pageable) { | ||
| 40 | Page<PointsStandingBook> page = PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 41 | return PageUtil.toPage(page.map(PointsStandingBookMapper::toDto)); | ||
| 42 | } | ||
| 43 | |||
| 44 | @Override | ||
| 45 | public List<PointsStandingBookDTO> queryAll(PointsStandingBookQueryCriteria criteria) { | ||
| 46 | return PointsStandingBookMapper.toDto(PointsStandingBookRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Override | ||
| 50 | public PointsStandingBookDTO findById(Long id) { | ||
| 51 | PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseGet(PointsStandingBook::new); | ||
| 52 | ValidationUtil.isNull(PointsStandingBook.getId(),"PointsStandingBook","id",id); | ||
| 53 | return PointsStandingBookMapper.toDto(PointsStandingBook); | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | @Transactional(rollbackFor = Exception.class) | ||
| 58 | public void create(PointsStandingBook resources) { | ||
| 59 | PointsStandingBookRepository.save(resources); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | @Transactional(rollbackFor = Exception.class) | ||
| 64 | public void update(PointsStandingBook resources) { | ||
| 65 | PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(resources.getId()).orElseGet(PointsStandingBook::new); | ||
| 66 | ValidationUtil.isNull( PointsStandingBook.getId(),"PointsStandingBook","id",resources.getId()); | ||
| 67 | PointsStandingBook.copy(resources); | ||
| 68 | PointsStandingBookRepository.save(PointsStandingBook); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Override | ||
| 72 | @Transactional(rollbackFor = Exception.class) | ||
| 73 | public void delete(Long id) { | ||
| 74 | Assert.notNull(id, "The given id must not be null!"); | ||
| 75 | PointsStandingBook PointsStandingBook = PointsStandingBookRepository.findById(id).orElseThrow( | ||
| 76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsStandingBook.class, id), 1)); | ||
| 77 | PointsStandingBookRepository.delete(PointsStandingBook); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | } |
| ... | @@ -23,63 +23,63 @@ import java.sql.Timestamp; | ... | @@ -23,63 +23,63 @@ import java.sql.Timestamp; |
| 23 | @Table(name="tr_rights") | 23 | @Table(name="tr_rights") |
| 24 | public class Rights implements Serializable { | 24 | public class Rights implements Serializable { |
| 25 | 25 | ||
| 26 | // 主键 | 26 | /** 主键 */ |
| 27 | @Id | 27 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 29 | @Column(name = "id") |
| 30 | private Long id; | 30 | private Long id; |
| 31 | 31 | ||
| 32 | // 标识 | 32 | /** 标识 */ |
| 33 | @Column(name = "code", nullable = false) | 33 | @Column(name = "code", nullable = false) |
| 34 | private String code; | 34 | private String code; |
| 35 | 35 | ||
| 36 | // 权益名称 | 36 | /** 权益名称 */ |
| 37 | // @Column(name = "name") | 37 | @Column(name = "name") |
| 38 | // private String name; | 38 | private String name; |
| 39 | 39 | ||
| 40 | // 类型 1:实体类 (预留字段) | 40 | /** 类型 1:实体类 (预留字段) */ |
| 41 | @Column(name = "type", nullable = false) | 41 | @Column(name = "type", nullable = false) |
| 42 | private Integer type; | 42 | private Integer type; |
| 43 | 43 | ||
| 44 | // 终端类型 0:大屏;1:微信小程序/公众号;2:App | 44 | /** 终端类型 0:大屏;1:微信小程序/公众号;2:App */ |
| 45 | @Column(name = "device_type", nullable = false) | 45 | @Column(name = "device_type", nullable = false) |
| 46 | private Integer deviceType; | 46 | private Integer deviceType; |
| 47 | 47 | ||
| 48 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 48 | /** 权益的实体类型 1:积分;2成长值;3优惠券 */ |
| 49 | @Column(name = "entity_type", nullable = false) | 49 | @Column(name = "entity_type", nullable = false) |
| 50 | private String entityType; | 50 | private String entityType; |
| 51 | 51 | ||
| 52 | // 实体id | 52 | /** 实体id */ |
| 53 | @Column(name = "entity_id", nullable = false) | 53 | @Column(name = "entity_id", nullable = false) |
| 54 | private Long entityId; | 54 | private Long entityId; |
| 55 | 55 | ||
| 56 | // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 | 56 | /** 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 */ |
| 57 | @Column(name = "valid_time") | 57 | @Column(name = "valid_time") |
| 58 | private Timestamp validTime; | 58 | private Timestamp validTime; |
| 59 | 59 | ||
| 60 | // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 | 60 | /** 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 */ |
| 61 | @Column(name = "expire_time") | 61 | @Column(name = "expire_time") |
| 62 | private Long expireTime; | 62 | private Long expireTime; |
| 63 | 63 | ||
| 64 | // 创建时间 | 64 | /** 创建时间 */ |
| 65 | @CreatedDate | 65 | @CreatedDate |
| 66 | @Column(name = "create_time") | 66 | @Column(name = "create_time") |
| 67 | private Timestamp createTime; | 67 | private Timestamp createTime; |
| 68 | 68 | ||
| 69 | // 更新时间 | 69 | /** 更新时间 */ |
| 70 | @LastModifiedDate | 70 | @LastModifiedDate |
| 71 | @Column(name = "update_time") | 71 | @Column(name = "update_time") |
| 72 | private Timestamp updateTime; | 72 | private Timestamp updateTime; |
| 73 | 73 | ||
| 74 | // 图片 | 74 | /** 图片 */ |
| 75 | @Column(name = "image") | 75 | @Column(name = "image") |
| 76 | private String image; | 76 | private String image; |
| 77 | 77 | ||
| 78 | // 图片 | 78 | /** 图片 */ |
| 79 | @Column(name = "images") | 79 | @Column(name = "images") |
| 80 | private String images; | 80 | private String images; |
| 81 | 81 | ||
| 82 | // 描述 | 82 | /** 描述 */ |
| 83 | @Column(name = "description") | 83 | @Column(name = "description") |
| 84 | private String description; | 84 | private String description; |
| 85 | 85 | ... | ... |
| ... | @@ -2,7 +2,7 @@ package com.topdraw.business.module.rights.history.domain; | ... | @@ -2,7 +2,7 @@ package com.topdraw.business.module.rights.history.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; |
| 6 | import lombok.Data; | 6 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 8 | import org.springframework.data.annotation.CreatedDate; | 8 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; | ... | @@ -23,7 +23,7 @@ import java.time.LocalDateTime; |
| 23 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
| 24 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
| 25 | @Table(name="tr_rights_histroy") | 25 | @Table(name="tr_rights_histroy") |
| 26 | public class RightsHistory extends DefaultAsyncMqModule implements Serializable { | 26 | public class RightsHistory extends AsyncMqModule implements Serializable { |
| 27 | 27 | ||
| 28 | // 主键id | 28 | // 主键id |
| 29 | @Id | 29 | @Id |
| ... | @@ -52,7 +52,7 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable | ... | @@ -52,7 +52,7 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable |
| 52 | 52 | ||
| 53 | // 发放时间 | 53 | // 发放时间 |
| 54 | @Column(name = "send_time") | 54 | @Column(name = "send_time") |
| 55 | private LocalDateTime sendTime; | 55 | private Timestamp sendTime; |
| 56 | 56 | ||
| 57 | // 失效时间 | 57 | // 失效时间 |
| 58 | @Column(name = "expire_time") | 58 | @Column(name = "expire_time") |
| ... | @@ -60,11 +60,11 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable | ... | @@ -60,11 +60,11 @@ public class RightsHistory extends DefaultAsyncMqModule implements Serializable |
| 60 | 60 | ||
| 61 | @CreatedDate | 61 | @CreatedDate |
| 62 | @Column(name = "create_time") | 62 | @Column(name = "create_time") |
| 63 | private LocalDateTime createTime; | 63 | private Timestamp createTime; |
| 64 | 64 | ||
| 65 | @LastModifiedDate | 65 | @LastModifiedDate |
| 66 | @Column(name = "update_time") | 66 | @Column(name = "update_time") |
| 67 | private LocalDateTime updateTime; | 67 | private Timestamp updateTime; |
| 68 | 68 | ||
| 69 | public void copy(RightsHistory source){ | 69 | public void copy(RightsHistory source){ |
| 70 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 70 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ... | ... |
| 1 | package com.topdraw.business.module.rights.history.repository; | 1 | package com.topdraw.business.module.rights.history.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; |
| 4 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 5 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | 7 | ||
| 8 | import java.util.List; | ||
| 9 | |||
| 7 | /** | 10 | /** |
| 8 | * @author XiangHan | 11 | * @author XiangHan |
| 9 | * @date 2021-10-22 | 12 | * @date 2021-10-22 |
| 10 | */ | 13 | */ |
| 11 | public interface RightsHistoryRepository extends JpaRepository<RightsHistory, Long>, JpaSpecificationExecutor<RightsHistory> { | 14 | public interface RightsHistoryRepository extends JpaRepository<RightsHistory, Long>, JpaSpecificationExecutor<RightsHistory> { |
| 12 | 15 | ||
| 16 | List<RightsHistoryDTO> findByMemberId(Long memberId); | ||
| 13 | } | 17 | } | ... | ... |
| ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.rights.history.service; | ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.rights.history.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; |
| 4 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO; | 4 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO; |
| 5 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.util.List; | 6 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -15,19 +12,12 @@ import java.util.Map; | ... | @@ -15,19 +12,12 @@ import java.util.Map; |
| 15 | public interface RightsHistoryService { | 12 | public interface RightsHistoryService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | 15 | * |
| 19 | * @param criteria 条件参数 | 16 | * @param memberId |
| 20 | * @param pageable 分页参数 | 17 | * @param memberCode |
| 21 | * @return Map<String,Object> | 18 | * @return |
| 22 | */ | 19 | */ |
| 23 | Map<String,Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable); | 20 | List<RightsHistoryDTO> findByMemberIdOrMemberCode(Long memberId, String memberCode); |
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<RightsHistoryDTO> | ||
| 29 | */ | ||
| 30 | List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria); | ||
| 31 | 21 | ||
| 32 | /** | 22 | /** |
| 33 | * 根据ID查询 | 23 | * 根据ID查询 | ... | ... |
| ... | @@ -30,12 +30,12 @@ public class RightsHistoryDTO implements Serializable { | ... | @@ -30,12 +30,12 @@ public class RightsHistoryDTO implements Serializable { |
| 30 | private String operatorName; | 30 | private String operatorName; |
| 31 | 31 | ||
| 32 | // 发放时间 | 32 | // 发放时间 |
| 33 | private LocalDateTime sendTime; | 33 | private Timestamp sendTime; |
| 34 | 34 | ||
| 35 | // 失效时间 | 35 | // 失效时间 |
| 36 | private LocalDateTime expireTime; | 36 | private LocalDateTime expireTime; |
| 37 | 37 | ||
| 38 | private LocalDateTime createTime; | 38 | private Timestamp createTime; |
| 39 | 39 | ||
| 40 | private LocalDateTime updateTime; | 40 | private Timestamp updateTime; |
| 41 | } | 41 | } | ... | ... |
| ... | @@ -6,23 +6,16 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory; | ... | @@ -6,23 +6,16 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory; |
| 6 | import com.topdraw.business.module.rights.history.repository.RightsHistoryRepository; | 6 | import com.topdraw.business.module.rights.history.repository.RightsHistoryRepository; |
| 7 | import com.topdraw.business.module.rights.history.service.RightsHistoryService; | 7 | import com.topdraw.business.module.rights.history.service.RightsHistoryService; |
| 8 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO; | 8 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryDTO; |
| 9 | import com.topdraw.business.module.rights.history.service.dto.RightsHistoryQueryCriteria; | ||
| 10 | import com.topdraw.business.module.rights.history.service.mapper.RightsHistoryMapper; | 9 | import com.topdraw.business.module.rights.history.service.mapper.RightsHistoryMapper; |
| 11 | import com.topdraw.utils.PageUtil; | ||
| 12 | import com.topdraw.utils.QueryHelp; | ||
| 13 | import com.topdraw.utils.ValidationUtil; | 10 | import com.topdraw.utils.ValidationUtil; |
| 14 | import org.apache.commons.lang3.StringUtils; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.dao.EmptyResultDataAccessException; | 12 | import org.springframework.dao.EmptyResultDataAccessException; |
| 17 | import org.springframework.data.domain.Page; | ||
| 18 | import org.springframework.data.domain.Pageable; | ||
| 19 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.util.Assert; | 16 | import org.springframework.util.Assert; |
| 23 | 17 | ||
| 24 | import java.util.List; | 18 | import java.util.List; |
| 25 | import java.util.Map; | ||
| 26 | 19 | ||
| 27 | /** | 20 | /** |
| 28 | * @author XiangHan | 21 | * @author XiangHan |
| ... | @@ -33,60 +26,49 @@ import java.util.Map; | ... | @@ -33,60 +26,49 @@ import java.util.Map; |
| 33 | public class RightsHistoryServiceImpl implements RightsHistoryService { | 26 | public class RightsHistoryServiceImpl implements RightsHistoryService { |
| 34 | 27 | ||
| 35 | @Autowired | 28 | @Autowired |
| 36 | private RightsHistoryRepository RightsHistoryRepository; | ||
| 37 | |||
| 38 | @Autowired | ||
| 39 | private MemberService memberService; | 29 | private MemberService memberService; |
| 40 | |||
| 41 | @Autowired | 30 | @Autowired |
| 42 | private RightsHistoryMapper RightsHistoryMapper; | 31 | private RightsHistoryMapper rightsHistoryMapper; |
| 32 | @Autowired | ||
| 33 | private RightsHistoryRepository rightsHistoryRepository; | ||
| 43 | 34 | ||
| 44 | @Override | ||
| 45 | public Map<String, Object> queryAll(RightsHistoryQueryCriteria criteria, Pageable pageable) { | ||
| 46 | Page<RightsHistory> page = RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 47 | return PageUtil.toPage(page.map(RightsHistoryMapper::toDto)); | ||
| 48 | } | ||
| 49 | 35 | ||
| 50 | @Override | 36 | @Override |
| 51 | public List<RightsHistoryDTO> queryAll(RightsHistoryQueryCriteria criteria) { | 37 | public List<RightsHistoryDTO> findByMemberIdOrMemberCode(Long memberId, String memberCode) { |
| 52 | return RightsHistoryMapper.toDto(RightsHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 38 | MemberDTO memberDTO = this.memberService.checkMember(memberId, memberCode); |
| 39 | List<RightsHistoryDTO> rightsHistoryDTOList = this.rightsHistoryRepository.findByMemberId(memberDTO.getId()); | ||
| 40 | return rightsHistoryDTOList; | ||
| 53 | } | 41 | } |
| 54 | 42 | ||
| 55 | @Override | 43 | @Override |
| 56 | public RightsHistoryDTO findById(Long id) { | 44 | public RightsHistoryDTO findById(Long id) { |
| 57 | RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseGet(RightsHistory::new); | 45 | RightsHistory RightsHistory = this.rightsHistoryRepository.findById(id).orElseGet(com.topdraw.business.module.rights.history.domain.RightsHistory::new); |
| 58 | ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",id); | 46 | ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",id); |
| 59 | return RightsHistoryMapper.toDto(RightsHistory); | 47 | return this.rightsHistoryMapper.toDto(RightsHistory); |
| 60 | } | 48 | } |
| 61 | 49 | ||
| 62 | @Override | 50 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 51 | @Transactional(rollbackFor = Exception.class) |
| 64 | public void create(RightsHistory resources) { | 52 | public void create(RightsHistory resources) { |
| 65 | String memberCode = resources.getMemberCode(); | 53 | this.rightsHistoryRepository.save(resources); |
| 66 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 67 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 68 | Long id = memberDTO.getId(); | ||
| 69 | resources.setMemberId(id); | ||
| 70 | } | ||
| 71 | RightsHistoryRepository.save(resources); | ||
| 72 | } | 54 | } |
| 73 | 55 | ||
| 74 | @Override | 56 | @Override |
| 75 | @Transactional(rollbackFor = Exception.class) | 57 | @Transactional(rollbackFor = Exception.class) |
| 76 | public void update(RightsHistory resources) { | 58 | public void update(RightsHistory resources) { |
| 77 | RightsHistory RightsHistory = RightsHistoryRepository.findById(resources.getId()).orElseGet(RightsHistory::new); | 59 | RightsHistory RightsHistory = this.rightsHistoryRepository.findById(resources.getId()).orElseGet(com.topdraw.business.module.rights.history.domain.RightsHistory::new); |
| 78 | ValidationUtil.isNull( RightsHistory.getId(),"RightsHistory","id",resources.getId()); | 60 | ValidationUtil.isNull(RightsHistory.getId(),"RightsHistory","id",resources.getId()); |
| 79 | RightsHistory.copy(resources); | 61 | RightsHistory.copy(resources); |
| 80 | RightsHistoryRepository.save(RightsHistory); | 62 | this.rightsHistoryRepository.save(RightsHistory); |
| 81 | } | 63 | } |
| 82 | 64 | ||
| 83 | @Override | 65 | @Override |
| 84 | @Transactional(rollbackFor = Exception.class) | 66 | @Transactional(rollbackFor = Exception.class) |
| 85 | public void delete(Long id) { | 67 | public void delete(Long id) { |
| 86 | Assert.notNull(id, "The given id must not be null!"); | 68 | Assert.notNull(id, "The given id must not be null!"); |
| 87 | RightsHistory RightsHistory = RightsHistoryRepository.findById(id).orElseThrow( | 69 | RightsHistory RightsHistory = this.rightsHistoryRepository.findById(id).orElseThrow( |
| 88 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", RightsHistory.class, id), 1)); | 70 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.rights.history.domain.RightsHistory.class, id), 1)); |
| 89 | RightsHistoryRepository.delete(RightsHistory); | 71 | this.rightsHistoryRepository.delete(RightsHistory); |
| 90 | } | 72 | } |
| 91 | 73 | ||
| 92 | 74 | ... | ... |
| ... | @@ -24,58 +24,58 @@ import java.sql.Timestamp; | ... | @@ -24,58 +24,58 @@ import java.sql.Timestamp; |
| 24 | @Table(name="uc_permanent_rights") | 24 | @Table(name="uc_permanent_rights") |
| 25 | public class PermanentRights implements Serializable { | 25 | public class PermanentRights implements Serializable { |
| 26 | 26 | ||
| 27 | // ID | 27 | /** ID */ |
| 28 | @Id | 28 | @Id |
| 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 30 | @Column(name = "id") | 30 | @Column(name = "id") |
| 31 | private Long id; | 31 | private Long id; |
| 32 | 32 | ||
| 33 | // 标识 | 33 | /** 标识 */ |
| 34 | @Column(name = "code", nullable = false) | 34 | @Column(name = "code", nullable = false) |
| 35 | private String code; | 35 | private String code; |
| 36 | 36 | ||
| 37 | // 名称 | 37 | /** 名称 */ |
| 38 | @Column(name = "name", nullable = false) | 38 | @Column(name = "name", nullable = false) |
| 39 | private String name; | 39 | private String name; |
| 40 | 40 | ||
| 41 | // 永久权益类型 0:vip;1:会员等级 | 41 | /** 永久权益类型 0:vip;1:会员等级 */ |
| 42 | @Column(name = "type") | 42 | @Column(name = "type") |
| 43 | private Integer type; | 43 | private Integer type; |
| 44 | 44 | ||
| 45 | // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) | 45 | /** 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) */ |
| 46 | @Column(name = "level") | 46 | @Column(name = "level") |
| 47 | private Integer level; | 47 | private Integer level; |
| 48 | 48 | ||
| 49 | // 商品折扣,10代表10% off,范围为0-100 | 49 | /** 商品折扣,10代表10% off,范围为0-100 */ |
| 50 | @Column(name = "item_discount", nullable = false) | 50 | @Column(name = "item_discount", nullable = false) |
| 51 | private BigDecimal itemDiscount; | 51 | private BigDecimal itemDiscount; |
| 52 | 52 | ||
| 53 | // 额外积分比率,范围为0-1000 | 53 | /** 额外积分比率,范围为0-1000 */ |
| 54 | @Column(name = "extra_points", nullable = false) | 54 | @Column(name = "extra_points", nullable = false) |
| 55 | private BigDecimal extraPoints; | 55 | private BigDecimal extraPoints; |
| 56 | 56 | ||
| 57 | // 免广告 | 57 | /** 免广告 */ |
| 58 | @Column(name = "ad_disabled", nullable = false) | 58 | @Column(name = "ad_disabled", nullable = false) |
| 59 | private Integer adDisabled; | 59 | private Integer adDisabled; |
| 60 | 60 | ||
| 61 | // 额外活动参与机会 | 61 | /** 额外活动参与机会 */ |
| 62 | @Column(name = "extra_activity_ticket", nullable = false) | 62 | @Column(name = "extra_activity_ticket", nullable = false) |
| 63 | private Integer extraActivityTicket; | 63 | private Integer extraActivityTicket; |
| 64 | 64 | ||
| 65 | // 免费试看 | 65 | /** 免费试看 */ |
| 66 | @Column(name = "free_trial", nullable = false) | 66 | @Column(name = "free_trial", nullable = false) |
| 67 | private Integer freeTrial; | 67 | private Integer freeTrial; |
| 68 | 68 | ||
| 69 | // 上电视专区权益 | 69 | /** 上电视专区权益 */ |
| 70 | @Column(name = "zone_sds", nullable = false) | 70 | @Column(name = "zone_sds", nullable = false) |
| 71 | private Integer zoneSds; | 71 | private Integer zoneSds; |
| 72 | 72 | ||
| 73 | // 创建时间 | 73 | /** 创建时间 */ |
| 74 | @CreatedDate | 74 | @CreatedDate |
| 75 | @Column(name = "create_time") | 75 | @Column(name = "create_time") |
| 76 | private Timestamp createTime; | 76 | private Timestamp createTime; |
| 77 | 77 | ||
| 78 | // 更新时间 | 78 | /** 更新时间 */ |
| 79 | @LastModifiedDate | 79 | @LastModifiedDate |
| 80 | @Column(name = "update_time") | 80 | @Column(name = "update_time") |
| 81 | private Timestamp updateTime; | 81 | private Timestamp updateTime; | ... | ... |
| ... | @@ -13,4 +13,6 @@ import java.util.Optional; | ... | @@ -13,4 +13,6 @@ import java.util.Optional; |
| 13 | public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> { | 13 | public interface PermanentRightsRepository extends JpaRepository<PermanentRights, Long>, JpaSpecificationExecutor<PermanentRights> { |
| 14 | 14 | ||
| 15 | Optional<PermanentRights> findFirstByCode(String code); | 15 | Optional<PermanentRights> findFirstByCode(String code); |
| 16 | |||
| 17 | PermanentRights findByLevel(Integer level); | ||
| 16 | } | 18 | } | ... | ... |
src/main/java/com/topdraw/business/module/rights/permanentrights/service/PermanentRightsService.java
| 1 | package com.topdraw.business.module.rights.permanentrights.service; | 1 | package com.topdraw.business.module.rights.permanentrights.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.rights.permanentrights.domain.PermanentRights; | ||
| 4 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; | 3 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; |
| 5 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 4 | ||
| 11 | /** | 5 | /** |
| 12 | * @author XiangHan | 6 | * @author XiangHan |
| ... | @@ -15,37 +9,23 @@ import java.util.Map; | ... | @@ -15,37 +9,23 @@ import java.util.Map; |
| 15 | public interface PermanentRightsService { | 9 | public interface PermanentRightsService { |
| 16 | 10 | ||
| 17 | /** | 11 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<PermanentRightsDTO> | ||
| 29 | */ | ||
| 30 | List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 12 | * 根据ID查询 |
| 34 | * @param id ID | 13 | * @param id ID |
| 35 | * @return PermanentRightsDTO | 14 | * @return PermanentRightsDTO |
| 36 | */ | 15 | */ |
| 37 | PermanentRightsDTO findById(Long id); | 16 | PermanentRightsDTO findById(Long id); |
| 38 | 17 | ||
| 39 | void create(PermanentRights resources); | ||
| 40 | |||
| 41 | void update(PermanentRights resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | /** | 18 | /** |
| 46 | * Code校验 | 19 | * Code校验 |
| 47 | * @param code | 20 | * @param code |
| 48 | * @return PermanentRightsDTO | 21 | * @return PermanentRightsDTO |
| 49 | */ | 22 | */ |
| 50 | PermanentRightsDTO getByCode(String code); | 23 | PermanentRightsDTO getByCode(String code); |
| 24 | |||
| 25 | /** | ||
| 26 | * 通过会员等级获取对应的永久权益 | ||
| 27 | * @param level | ||
| 28 | * @return | ||
| 29 | */ | ||
| 30 | PermanentRightsDTO findByLevel(Integer level); | ||
| 51 | } | 31 | } | ... | ... |
src/main/java/com/topdraw/business/module/rights/permanentrights/service/dto/PermanentRightsDTO.java
| ... | @@ -14,42 +14,42 @@ import java.sql.Timestamp; | ... | @@ -14,42 +14,42 @@ import java.sql.Timestamp; |
| 14 | @Data | 14 | @Data |
| 15 | public class PermanentRightsDTO implements Serializable { | 15 | public class PermanentRightsDTO implements Serializable { |
| 16 | 16 | ||
| 17 | // ID | 17 | /** ID */ |
| 18 | private Long id; | 18 | private Long id; |
| 19 | 19 | ||
| 20 | // 标识 | 20 | /** 标识 */ |
| 21 | private String code; | 21 | private String code; |
| 22 | 22 | ||
| 23 | // 名称 | 23 | /** 名称 */ |
| 24 | private String name; | 24 | private String name; |
| 25 | 25 | ||
| 26 | // 永久权益类型 0:vip;1:会员等级 | 26 | /** 永久权益类型 0:vip;1:会员等级 */ |
| 27 | private Integer type; | 27 | private Integer type; |
| 28 | 28 | ||
| 29 | // 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) | 29 | /** 等级(当权益类型为vip时,对应vip值,当权益类型为会员等级时,对应等级index) */ |
| 30 | private Integer level; | 30 | private Integer level; |
| 31 | 31 | ||
| 32 | // 商品折扣,10代表10% off,范围为0-100 | 32 | /** 商品折扣,10代表10% off,范围为0-100 */ |
| 33 | private BigDecimal itemDiscount; | 33 | private BigDecimal itemDiscount; |
| 34 | 34 | ||
| 35 | // 额外积分比率,范围为0-1000 | 35 | /** 额外积分比率,范围为0-1000 */ |
| 36 | private BigDecimal extraPoints; | 36 | private BigDecimal extraPoints; |
| 37 | 37 | ||
| 38 | // 免广告 | 38 | /** 免广告 */ |
| 39 | private Integer adDisabled; | 39 | private Integer adDisabled; |
| 40 | 40 | ||
| 41 | // 额外活动参与机会 | 41 | /** 额外活动参与机会 */ |
| 42 | private Integer extraActivityTicket; | 42 | private Integer extraActivityTicket; |
| 43 | 43 | ||
| 44 | // 免费试看 | 44 | /** 免费试看 */ |
| 45 | private Integer freeTrial; | 45 | private Integer freeTrial; |
| 46 | 46 | ||
| 47 | // 上电视专区权益 | 47 | /** 上电视专区权益 */ |
| 48 | private Integer zoneSds; | 48 | private Integer zoneSds; |
| 49 | 49 | ||
| 50 | // 创建时间 | 50 | /** 创建时间 */ |
| 51 | private Timestamp createTime; | 51 | private Timestamp createTime; |
| 52 | 52 | ||
| 53 | // 更新时间 | 53 | /** 更新时间 */ |
| 54 | private Timestamp updateTime; | 54 | private Timestamp updateTime; |
| 55 | } | 55 | } | ... | ... |
| 1 | package com.topdraw.business.module.rights.permanentrights.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Query; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author XiangHan | ||
| 8 | * @date 2021-10-22 | ||
| 9 | */ | ||
| 10 | @Data | ||
| 11 | public class PermanentRightsQueryCriteria{ | ||
| 12 | |||
| 13 | @Query(type = Query.Type.EQUAL) | ||
| 14 | private Integer level; | ||
| 15 | |||
| 16 | } |
| ... | @@ -4,23 +4,13 @@ import com.topdraw.business.module.rights.permanentrights.domain.PermanentRights | ... | @@ -4,23 +4,13 @@ import com.topdraw.business.module.rights.permanentrights.domain.PermanentRights |
| 4 | import com.topdraw.business.module.rights.permanentrights.repository.PermanentRightsRepository; | 4 | import com.topdraw.business.module.rights.permanentrights.repository.PermanentRightsRepository; |
| 5 | import com.topdraw.business.module.rights.permanentrights.service.PermanentRightsService; | 5 | import com.topdraw.business.module.rights.permanentrights.service.PermanentRightsService; |
| 6 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; | 6 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsDTO; |
| 7 | import com.topdraw.business.module.rights.permanentrights.service.dto.PermanentRightsQueryCriteria; | ||
| 8 | import com.topdraw.business.module.rights.permanentrights.service.mapper.PermanentRightsMapper; | 7 | import com.topdraw.business.module.rights.permanentrights.service.mapper.PermanentRightsMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | ||
| 21 | |||
| 22 | import java.util.List; | ||
| 23 | import java.util.Map; | ||
| 24 | 14 | ||
| 25 | /** | 15 | /** |
| 26 | * @author XiangHan | 16 | * @author XiangHan |
| ... | @@ -31,57 +21,27 @@ import java.util.Map; | ... | @@ -31,57 +21,27 @@ import java.util.Map; |
| 31 | public class PermanentRightsServiceImpl implements PermanentRightsService { | 21 | public class PermanentRightsServiceImpl implements PermanentRightsService { |
| 32 | 22 | ||
| 33 | @Autowired | 23 | @Autowired |
| 34 | private PermanentRightsRepository PermanentRightsRepository; | 24 | private PermanentRightsRepository permanentRightsRepository; |
| 35 | 25 | ||
| 36 | @Autowired | 26 | @Autowired |
| 37 | private PermanentRightsMapper PermanentRightsMapper; | 27 | private PermanentRightsMapper permanentRightsMapper; |
| 38 | |||
| 39 | @Override | ||
| 40 | public Map<String, Object> queryAll(PermanentRightsQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<PermanentRights> page = PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(PermanentRightsMapper::toDto)); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public List<PermanentRightsDTO> queryAll(PermanentRightsQueryCriteria criteria) { | ||
| 47 | return PermanentRightsMapper.toDto(PermanentRightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 28 | ||
| 50 | @Override | 29 | @Override |
| 51 | public PermanentRightsDTO findById(Long id) { | 30 | public PermanentRightsDTO findById(Long id) { |
| 52 | PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseGet(PermanentRights::new); | 31 | PermanentRights PermanentRights = this.permanentRightsRepository.findById(id).orElseGet(com.topdraw.business.module.rights.permanentrights.domain.PermanentRights::new); |
| 53 | ValidationUtil.isNull(PermanentRights.getId(),"PermanentRights","id",id); | 32 | ValidationUtil.isNull(PermanentRights.getId(),"PermanentRights","id",id); |
| 54 | return PermanentRightsMapper.toDto(PermanentRights); | 33 | return this.permanentRightsMapper.toDto(PermanentRights); |
| 55 | } | ||
| 56 | |||
| 57 | @Override | ||
| 58 | @Transactional(rollbackFor = Exception.class) | ||
| 59 | public void create(PermanentRights resources) { | ||
| 60 | PermanentRightsRepository.save(resources); | ||
| 61 | } | 34 | } |
| 62 | 35 | ||
| 63 | @Override | 36 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 37 | public PermanentRightsDTO getByCode(String code) { |
| 65 | public void update(PermanentRights resources) { | 38 | return StringUtils.isNotEmpty(code) ? this.permanentRightsMapper.toDto(this.permanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new)) |
| 66 | PermanentRights PermanentRights = PermanentRightsRepository.findById(resources.getId()).orElseGet(PermanentRights::new); | 39 | : new PermanentRightsDTO(); |
| 67 | ValidationUtil.isNull( PermanentRights.getId(),"PermanentRights","id",resources.getId()); | ||
| 68 | PermanentRights.copy(resources); | ||
| 69 | PermanentRightsRepository.save(PermanentRights); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Override | ||
| 73 | @Transactional(rollbackFor = Exception.class) | ||
| 74 | public void delete(Long id) { | ||
| 75 | Assert.notNull(id, "The given id must not be null!"); | ||
| 76 | PermanentRights PermanentRights = PermanentRightsRepository.findById(id).orElseThrow( | ||
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PermanentRights.class, id), 1)); | ||
| 78 | PermanentRightsRepository.delete(PermanentRights); | ||
| 79 | } | 40 | } |
| 80 | 41 | ||
| 81 | |||
| 82 | @Override | 42 | @Override |
| 83 | public PermanentRightsDTO getByCode(String code) { | 43 | public PermanentRightsDTO findByLevel(Integer level) { |
| 84 | return StringUtils.isNotEmpty(code) ? PermanentRightsMapper.toDto(PermanentRightsRepository.findFirstByCode(code).orElseGet(PermanentRights::new)) | 44 | PermanentRights PermanentRights = this.permanentRightsRepository.findByLevel(level); |
| 85 | : new PermanentRightsDTO(); | 45 | return this.permanentRightsMapper.toDto(PermanentRights); |
| 86 | } | 46 | } |
| 87 | } | 47 | } | ... | ... |
| 1 | package com.topdraw.business.module.rights.service; | 1 | package com.topdraw.business.module.rights.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.rights.domain.Rights; | ||
| 4 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | 3 | import com.topdraw.business.module.rights.service.dto.RightsDTO; |
| 5 | import com.topdraw.business.module.rights.service.dto.RightsQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 4 | ||
| 11 | /** | 5 | /** |
| 12 | * @author XiangHan | 6 | * @author XiangHan |
| ... | @@ -15,21 +9,6 @@ import java.util.Map; | ... | @@ -15,21 +9,6 @@ import java.util.Map; |
| 15 | public interface RightsService { | 9 | public interface RightsService { |
| 16 | 10 | ||
| 17 | /** | 11 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(RightsQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<RightsDTO> | ||
| 29 | */ | ||
| 30 | List<RightsDTO> queryAll(RightsQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 12 | * 根据ID查询 |
| 34 | * @param id ID | 13 | * @param id ID |
| 35 | * @return RightsDTO | 14 | * @return RightsDTO |
| ... | @@ -37,19 +16,6 @@ public interface RightsService { | ... | @@ -37,19 +16,6 @@ public interface RightsService { |
| 37 | RightsDTO findById(Long id); | 16 | RightsDTO findById(Long id); |
| 38 | 17 | ||
| 39 | /** | 18 | /** |
| 40 | * 批量查询 | ||
| 41 | * @param ids | ||
| 42 | * @return | ||
| 43 | */ | ||
| 44 | List<RightsDTO> findBatchByIds(Long... ids); | ||
| 45 | |||
| 46 | void create(Rights resources); | ||
| 47 | |||
| 48 | void update(Rights resources); | ||
| 49 | |||
| 50 | void delete(Long id); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Code校验 | 19 | * Code校验 |
| 54 | * @param code | 20 | * @param code |
| 55 | * @return RightsDTO | 21 | * @return RightsDTO | ... | ... |
| ... | @@ -13,44 +13,45 @@ import java.sql.Timestamp; | ... | @@ -13,44 +13,45 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class RightsDTO implements Serializable { | 14 | public class RightsDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // 主键 | 16 | /** 主键 */ |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | // 标识 | 19 | /** 标识 */ |
| 20 | private String code; | 20 | private String code; |
| 21 | 21 | ||
| 22 | // 权益名称 | 22 | /** 权益名称 */ |
| 23 | // private String name; | 23 | private String name; |
| 24 | // 终端类型 0:大屏;1:微信小程序/公众号;2:App | 24 | |
| 25 | /** 终端类型 0:大屏;1:微信小程序/公众号;2:App */ | ||
| 25 | private Integer deviceType; | 26 | private Integer deviceType; |
| 26 | 27 | ||
| 27 | // 类型 1:实体类 (预留字段) | 28 | /** 类型 1:实体类 (预留字段) */ |
| 28 | private Integer type; | 29 | private Integer type; |
| 29 | 30 | ||
| 30 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 31 | /** 权益的实体类型 1:积分;2成长值;3优惠券 */ |
| 31 | private String entityType; | 32 | private String entityType; |
| 32 | 33 | ||
| 33 | // 实体id | 34 | /** 实体id */ |
| 34 | private Long entityId; | 35 | private Long entityId; |
| 35 | 36 | ||
| 36 | // 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 | 37 | /** 生效时间,为null表示获取后立即生效,不为空时,表示特定的生效时间 */ |
| 37 | private Timestamp validTime; | 38 | private Timestamp validTime; |
| 38 | 39 | ||
| 39 | // 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 | 40 | /** 失效时间,空为不失效,否则为获得权益后直到失效的毫秒数 */ |
| 40 | private Long expireTime; | 41 | private Long expireTime; |
| 41 | 42 | ||
| 42 | // 创建时间 | 43 | /** 创建时间 */ |
| 43 | private Timestamp createTime; | 44 | private Timestamp createTime; |
| 44 | 45 | ||
| 45 | // 更新时间 | 46 | /** 更新时间 */ |
| 46 | private Timestamp updateTime; | 47 | private Timestamp updateTime; |
| 47 | 48 | ||
| 48 | // 图片 | 49 | /** 图片 */ |
| 49 | private String image; | 50 | private String image; |
| 50 | 51 | ||
| 51 | // 图片 | 52 | /** 图片 */ |
| 52 | private String images; | 53 | private String images; |
| 53 | 54 | ||
| 54 | // 描述 | 55 | /** 描述 */ |
| 55 | private String description; | 56 | private String description; |
| 56 | } | 57 | } | ... | ... |
src/main/java/com/topdraw/business/module/rights/service/dto/RightsQueryCriteria.java
deleted
100644 → 0
| 1 | package com.topdraw.business.module.rights.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Query; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author XiangHan | ||
| 8 | * @date 2021-10-22 | ||
| 9 | */ | ||
| 10 | @Data | ||
| 11 | public class RightsQueryCriteria{ | ||
| 12 | |||
| 13 | @Query | ||
| 14 | private Long memberId; | ||
| 15 | |||
| 16 | private RightsQueryType queryType; | ||
| 17 | |||
| 18 | } |
| ... | @@ -4,24 +4,13 @@ import com.topdraw.business.module.rights.domain.Rights; | ... | @@ -4,24 +4,13 @@ import com.topdraw.business.module.rights.domain.Rights; |
| 4 | import com.topdraw.business.module.rights.repository.RightsRepository; | 4 | import com.topdraw.business.module.rights.repository.RightsRepository; |
| 5 | import com.topdraw.business.module.rights.service.RightsService; | 5 | import com.topdraw.business.module.rights.service.RightsService; |
| 6 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | 6 | import com.topdraw.business.module.rights.service.dto.RightsDTO; |
| 7 | import com.topdraw.business.module.rights.service.dto.RightsQueryCriteria; | ||
| 8 | import com.topdraw.business.module.rights.service.mapper.RightsMapper; | 7 | import com.topdraw.business.module.rights.service.mapper.RightsMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | ||
| 21 | import org.springframework.util.CollectionUtils; | ||
| 22 | |||
| 23 | import java.util.List; | ||
| 24 | import java.util.Map; | ||
| 25 | 14 | ||
| 26 | /** | 15 | /** |
| 27 | * @author XiangHan | 16 | * @author XiangHan |
| ... | @@ -32,63 +21,20 @@ import java.util.Map; | ... | @@ -32,63 +21,20 @@ import java.util.Map; |
| 32 | public class RightsServiceImpl implements RightsService { | 21 | public class RightsServiceImpl implements RightsService { |
| 33 | 22 | ||
| 34 | @Autowired | 23 | @Autowired |
| 35 | private RightsRepository RightsRepository; | 24 | private RightsRepository rightsRepository; |
| 36 | |||
| 37 | @Autowired | 25 | @Autowired |
| 38 | private RightsMapper RightsMapper; | 26 | private RightsMapper rightsMapper; |
| 39 | |||
| 40 | @Override | ||
| 41 | public Map<String, Object> queryAll(RightsQueryCriteria criteria, Pageable pageable) { | ||
| 42 | Page<Rights> page = RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 43 | return PageUtil.toPage(page.map(RightsMapper::toDto)); | ||
| 44 | } | ||
| 45 | |||
| 46 | @Override | ||
| 47 | public List<RightsDTO> queryAll(RightsQueryCriteria criteria) { | ||
| 48 | return RightsMapper.toDto(RightsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 49 | } | ||
| 50 | 27 | ||
| 51 | @Override | 28 | @Override |
| 52 | public RightsDTO findById(Long id) { | 29 | public RightsDTO findById(Long id) { |
| 53 | Rights Rights = RightsRepository.findById(id).orElseGet(Rights::new); | 30 | Rights Rights = this.rightsRepository.findById(id).orElseGet(com.topdraw.business.module.rights.domain.Rights::new); |
| 54 | ValidationUtil.isNull(Rights.getId(),"Rights","id",id); | 31 | ValidationUtil.isNull(Rights.getId(),"Rights","id",id); |
| 55 | return RightsMapper.toDto(Rights); | 32 | return this.rightsMapper.toDto(Rights); |
| 56 | } | ||
| 57 | |||
| 58 | @Override | ||
| 59 | public List<RightsDTO> findBatchByIds(Long... ids) { | ||
| 60 | List<Rights> rightsList = this.RightsRepository.findBatchByIds(ids); | ||
| 61 | return !CollectionUtils.isEmpty(rightsList) ? RightsMapper.toDto(rightsList) : null; | ||
| 62 | } | 33 | } |
| 63 | 34 | ||
| 64 | @Override | 35 | @Override |
| 65 | @Transactional(rollbackFor = Exception.class) | ||
| 66 | public void create(Rights resources) { | ||
| 67 | RightsRepository.save(resources); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Override | ||
| 71 | @Transactional(rollbackFor = Exception.class) | ||
| 72 | public void update(Rights resources) { | ||
| 73 | Rights Rights = RightsRepository.findById(resources.getId()).orElseGet(Rights::new); | ||
| 74 | ValidationUtil.isNull( Rights.getId(),"Rights","id",resources.getId()); | ||
| 75 | Rights.copy(resources); | ||
| 76 | RightsRepository.save(Rights); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Override | ||
| 80 | @Transactional(rollbackFor = Exception.class) | ||
| 81 | public void delete(Long id) { | ||
| 82 | Assert.notNull(id, "The given id must not be null!"); | ||
| 83 | Rights Rights = RightsRepository.findById(id).orElseThrow( | ||
| 84 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Rights.class, id), 1)); | ||
| 85 | RightsRepository.delete(Rights); | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | @Override | ||
| 90 | public RightsDTO getByCode(String code) { | 36 | public RightsDTO getByCode(String code) { |
| 91 | return StringUtils.isNotEmpty(code) ? RightsMapper.toDto(RightsRepository.findFirstByCode(code).orElseGet(Rights::new)) | 37 | return StringUtils.isNotEmpty(code) ? this.rightsMapper.toDto(this.rightsRepository.findFirstByCode(code).orElseGet(Rights::new)) |
| 92 | : new RightsDTO(); | 38 | : new RightsDTO(); |
| 93 | } | 39 | } |
| 94 | } | 40 | } | ... | ... |
| 1 | package com.topdraw.business.module.task.attribute.domain; | ||
| 2 | |||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | ||
| 5 | import lombok.Data; | ||
| 6 | import lombok.experimental.Accessors; | ||
| 7 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| 8 | |||
| 9 | import javax.persistence.*; | ||
| 10 | import java.io.Serializable; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author XiangHan | ||
| 14 | * @date 2022-01-13 | ||
| 15 | */ | ||
| 16 | @Entity | ||
| 17 | @Data | ||
| 18 | @EntityListeners(AuditingEntityListener.class) | ||
| 19 | @Accessors(chain = true) | ||
| 20 | @Table(name="tr_task_attr") | ||
| 21 | public class TaskAttr implements Serializable { | ||
| 22 | |||
| 23 | @Id | ||
| 24 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 25 | @Column(name = "id") | ||
| 26 | private Long id; | ||
| 27 | |||
| 28 | /** 任务id(关联task主键) */ | ||
| 29 | @Column(name = "task_id") | ||
| 30 | private Long taskId; | ||
| 31 | |||
| 32 | /** 任务属性字符串 */ | ||
| 33 | @Column(name = "attr_str") | ||
| 34 | private String attrStr; | ||
| 35 | |||
| 36 | public void copy(TaskAttr source){ | ||
| 37 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 38 | } | ||
| 39 | } |
src/main/java/com/topdraw/business/module/task/attribute/repository/TaskAttrRepository.java
0 → 100644
| 1 | package com.topdraw.business.module.task.attribute.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | |||
| 7 | import java.util.Optional; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2022-01-13 | ||
| 12 | */ | ||
| 13 | public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> { | ||
| 14 | |||
| 15 | Optional<TaskAttr> findByTaskId(Long taskId); | ||
| 16 | } |
| 1 | package com.topdraw.business.module.task.attribute.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | ||
| 4 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author XiangHan | ||
| 8 | * @date 2022-01-13 | ||
| 9 | */ | ||
| 10 | public interface TaskAttrService { | ||
| 11 | /** | ||
| 12 | * 根据ID查询 | ||
| 13 | * @param id ID | ||
| 14 | * @return TaskAttrDTO | ||
| 15 | */ | ||
| 16 | TaskAttrDTO findById(Long id); | ||
| 17 | |||
| 18 | /** | ||
| 19 | * | ||
| 20 | * @param resources | ||
| 21 | */ | ||
| 22 | void create(TaskAttr resources); | ||
| 23 | |||
| 24 | /** | ||
| 25 | * | ||
| 26 | * @param resources | ||
| 27 | */ | ||
| 28 | void update(TaskAttr resources); | ||
| 29 | |||
| 30 | /** | ||
| 31 | * | ||
| 32 | * @param id | ||
| 33 | */ | ||
| 34 | void delete(Long id); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * | ||
| 38 | * @param taskId | ||
| 39 | * @return | ||
| 40 | */ | ||
| 41 | TaskAttrDTO findByTaskId(Long taskId); | ||
| 42 | } |
| 1 | package com.topdraw.business.module.coupon.history.service.dto; | 1 | package com.topdraw.business.module.task.attribute.service.dto; |
| 2 | 2 | ||
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | ||
| 6 | |||
| 5 | /** | 7 | /** |
| 6 | * @author XiangHan | 8 | * @author XiangHan |
| 7 | * @date 2021-10-23 | 9 | * @date 2022-01-13 |
| 8 | */ | 10 | */ |
| 9 | @Data | 11 | @Data |
| 10 | public class CouponHistoryQueryCriteria{ | 12 | public class TaskAttrDTO implements Serializable { |
| 13 | |||
| 14 | private Long id; | ||
| 15 | |||
| 16 | /** 任务id(关联task主键) */ | ||
| 17 | private Long taskId; | ||
| 18 | |||
| 19 | /** 任务属性字符串 */ | ||
| 20 | private String attrStr; | ||
| 11 | } | 21 | } | ... | ... |
src/main/java/com/topdraw/business/module/task/attribute/service/impl/TaskAttrServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.module.task.attribute.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | ||
| 4 | import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository; | ||
| 5 | import com.topdraw.business.module.task.attribute.service.TaskAttrService; | ||
| 6 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ||
| 7 | import com.topdraw.business.module.task.attribute.service.mapper.TaskAttrMapper; | ||
| 8 | import com.topdraw.utils.ValidationUtil; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 11 | import org.springframework.stereotype.Service; | ||
| 12 | import org.springframework.transaction.annotation.Propagation; | ||
| 13 | import org.springframework.transaction.annotation.Transactional; | ||
| 14 | import org.springframework.util.Assert; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @author XiangHan | ||
| 18 | * @date 2022-01-13 | ||
| 19 | */ | ||
| 20 | @Service | ||
| 21 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 22 | public class TaskAttrServiceImpl implements TaskAttrService { | ||
| 23 | |||
| 24 | @Autowired | ||
| 25 | private TaskAttrMapper taskAttrMapper; | ||
| 26 | @Autowired | ||
| 27 | private TaskAttrRepository taskAttrRepository; | ||
| 28 | |||
| 29 | |||
| 30 | @Override | ||
| 31 | public TaskAttrDTO findById(Long id) { | ||
| 32 | TaskAttr TaskAttr = this.taskAttrRepository.findById(id).orElseGet(TaskAttr::new); | ||
| 33 | ValidationUtil.isNull(TaskAttr.getId(),"TaskAttr","id",id); | ||
| 34 | return this.taskAttrMapper.toDto(TaskAttr); | ||
| 35 | } | ||
| 36 | |||
| 37 | @Override | ||
| 38 | @Transactional(rollbackFor = Exception.class) | ||
| 39 | public void create(TaskAttr resources) { | ||
| 40 | this.taskAttrRepository.save(resources); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Override | ||
| 44 | @Transactional(rollbackFor = Exception.class) | ||
| 45 | public void update(TaskAttr resources) { | ||
| 46 | TaskAttr TaskAttr = this.taskAttrRepository.findById(resources.getId()).orElseGet(TaskAttr::new); | ||
| 47 | ValidationUtil.isNull( TaskAttr.getId(),"TaskAttr","id",resources.getId()); | ||
| 48 | TaskAttr.copy(resources); | ||
| 49 | this.taskAttrRepository.save(TaskAttr); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Override | ||
| 53 | @Transactional(rollbackFor = Exception.class) | ||
| 54 | public void delete(Long id) { | ||
| 55 | Assert.notNull(id, "The given id must not be null!"); | ||
| 56 | TaskAttr TaskAttr = this.taskAttrRepository.findById(id).orElseThrow( | ||
| 57 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TaskAttr.class, id), 1)); | ||
| 58 | this.taskAttrRepository.delete(TaskAttr); | ||
| 59 | } | ||
| 60 | |||
| 61 | @Override | ||
| 62 | public TaskAttrDTO findByTaskId(Long taskId) { | ||
| 63 | TaskAttr TaskAttr = this.taskAttrRepository.findByTaskId(taskId).orElseGet(TaskAttr::new); | ||
| 64 | return this.taskAttrMapper.toDto(TaskAttr); | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | } |
| 1 | package com.topdraw.business.module.points.standingbook.service.mapper; | 1 | package com.topdraw.business.module.task.attribute.service.mapper; |
| 2 | 2 | ||
| 3 | import com.topdraw.base.BaseMapper; | 3 | import com.topdraw.base.BaseMapper; |
| 4 | import com.topdraw.business.module.points.standingbook.domain.PointsStandingBook; | 4 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; |
| 5 | import com.topdraw.business.module.points.standingbook.service.dto.PointsStandingBookDTO; | 5 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; |
| 6 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
| 7 | import org.mapstruct.ReportingPolicy; | 7 | import org.mapstruct.ReportingPolicy; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | * @author XiangHan | 10 | * @author XiangHan |
| 11 | * @date 2021-10-29 | 11 | * @date 2022-01-13 |
| 12 | */ | 12 | */ |
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) |
| 14 | public interface PointsStandingBookMapper extends BaseMapper<PointsStandingBookDTO, PointsStandingBook> { | 14 | public interface TaskAttrMapper extends BaseMapper<TaskAttrDTO, TaskAttr> { |
| 15 | 15 | ||
| 16 | } | 16 | } | ... | ... |
| ... | @@ -11,6 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ... | @@ -11,6 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 11 | import javax.persistence.*; | 11 | import javax.persistence.*; |
| 12 | import java.io.Serializable; | 12 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 13 | import java.sql.Timestamp; |
| 14 | import java.time.LocalDateTime; | ||
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| 16 | * @author XiangHan | 17 | * @author XiangHan |
| ... | @@ -28,104 +29,126 @@ public class Task implements Serializable { | ... | @@ -28,104 +29,126 @@ public class Task implements Serializable { |
| 28 | @Column(name = "id") | 29 | @Column(name = "id") |
| 29 | private Long id; | 30 | private Long id; |
| 30 | 31 | ||
| 31 | // 任务模板id | 32 | /** 任务模板id */ |
| 32 | @Column(name = "task_template_id", nullable = false) | 33 | @Column(name = "task_template_id", nullable = false) |
| 33 | private Long taskTemplateId; | 34 | private Long taskTemplateId; |
| 34 | 35 | ||
| 35 | // 任务重复类型,-1:不限次;1:单次;>1:多次 | 36 | @Transient |
| 37 | private String taskTemplateCode; | ||
| 38 | |||
| 39 | /** 任务重复类型,-1:不限次;1:单次;>1:多次 */ | ||
| 36 | @Column(name = "task_repeat_type", nullable = false) | 40 | @Column(name = "task_repeat_type", nullable = false) |
| 37 | private Integer taskRepeatType; | 41 | private Integer taskRepeatType; |
| 38 | 42 | ||
| 39 | // 任务每日重置 0:不重置;1:重置 | 43 | /** 任务每日重置 0:不重置;1:重置 */ |
| 40 | @Column(name = "task_daily_reset", nullable = false) | 44 | @Column(name = "task_daily_reset", nullable = false) |
| 41 | private Integer taskDailyReset; | 45 | private Integer taskDailyReset; |
| 42 | 46 | ||
| 43 | // 行为量(完成此任务需要多少次相同行为的触发) | 47 | /** 行为量(完成此任务需要多少次相同行为的触发) */ |
| 44 | @Column(name = "action_amount", nullable = false) | 48 | @Column(name = "action_amount", nullable = false) |
| 45 | private Integer actionAmount; | 49 | private Integer actionAmount; |
| 46 | 50 | ||
| 47 | // 任务生效时间 | 51 | /** 任务生效时间 */ |
| 48 | @Column(name = "valid_time") | 52 | @Column(name = "valid_time") |
| 49 | private Timestamp validTime; | 53 | private Timestamp validTime; |
| 50 | 54 | ||
| 51 | // 任务失效时间 | 55 | /** 任务失效时间 */ |
| 52 | @Column(name = "expire_time") | 56 | @Column(name = "expire_time") |
| 53 | private Timestamp expireTime; | 57 | private LocalDateTime expireTime; |
| 54 | 58 | ||
| 55 | // 显示顺序 | 59 | /** 显示顺序 */ |
| 56 | @Column(name = "sequence") | 60 | @Column(name = "sequence") |
| 57 | private Integer sequence; | 61 | private Integer sequence; |
| 58 | 62 | ||
| 59 | // 获得成长值 | 63 | /** 获得成长值 */ |
| 60 | @Column(name = "reward_exp", nullable = false) | 64 | @Column(name = "reward_exp", nullable = false) |
| 61 | private Long rewardExp; | 65 | private Long rewardExp; |
| 62 | 66 | ||
| 63 | // 获得积分 | 67 | /** 获得积分 */ |
| 64 | @Column(name = "reward_points", nullable = false) | 68 | @Column(name = "reward_points", nullable = false) |
| 65 | private Long rewardPoints; | 69 | private Long rewardPoints; |
| 66 | 70 | ||
| 67 | // 积分过期时间(空为不过期) | 71 | /** 积分过期时间(空为不过期) */ |
| 68 | @Column(name = "reward_points_expire_time") | 72 | @Column(name = "reward_points_expire_time") |
| 69 | private Long rewardPointsExpireTime; | 73 | private Long rewardPointsExpireTime; |
| 70 | 74 | ||
| 71 | // 积分获取类型 0:定值;1:随机 | 75 | /** 积分获取类型 0:定值;1:随机 */ |
| 72 | @Column(name = "points_type") | 76 | @Column(name = "points_type") |
| 73 | private Integer pointsType; | 77 | private Integer pointsType; |
| 74 | 78 | ||
| 75 | // 随机积分最大值 | 79 | /** 随机积分最大值 */ |
| 76 | @Column(name = "reward_max_points") | 80 | @Column(name = "reward_max_points") |
| 77 | private Integer rewardMaxPoints; | 81 | private Integer rewardMaxPoints; |
| 78 | 82 | ||
| 79 | // 能够获取该任务的用户分组,为空则都能获取 | 83 | /** 能够获取该任务的用户分组,为空则都能获取 */ |
| 80 | @Column(name = "groups") | 84 | @Column(name = "groups") |
| 81 | private String groups; | 85 | private String groups; |
| 82 | 86 | ||
| 83 | // 权益发放策略 0:立即发放;1:次日发放;2:次月发放 | 87 | /** 权益发放策略 0:立即发放;1:次日发放;2:次月发放 */ |
| 84 | @Column(name = "rights_send_strategy", nullable = false) | 88 | @Column(name = "rights_send_strategy", nullable = false) |
| 85 | private Integer rightsSendStrategy; | 89 | private Integer rightsSendStrategy; |
| 86 | 90 | ||
| 87 | // 会员等级门槛(0表示无门槛) | 91 | /** 会员等级门槛(0表示无门槛) */ |
| 88 | @Column(name = "member_level", nullable = false) | 92 | @Column(name = "member_level", nullable = false) |
| 89 | private Integer memberLevel; | 93 | private Integer memberLevel; |
| 90 | 94 | ||
| 91 | // 会员vip门槛(0表示没有门槛) | 95 | /** 会员vip门槛(0表示没有门槛) */ |
| 92 | @Column(name = "member_vip") | 96 | @Column(name = "member_vip") |
| 93 | private Integer memberVip; | 97 | private Integer memberVip; |
| 94 | 98 | ||
| 95 | // 权益id | 99 | /** 权益id */ |
| 96 | @Column(name = "rights_id") | 100 | @Column(name = "rights_id") |
| 97 | private Long rightsId; | 101 | private Long rightsId; |
| 98 | 102 | ||
| 99 | // 权益数量(活动机会次数、优惠券数量、奖品数量) | 103 | /** 权益数量(活动机会次数、优惠券数量、奖品数量) */ |
| 100 | @Column(name = "rights_amount") | 104 | @Column(name = "rights_amount") |
| 101 | private Integer rightsAmount; | 105 | private Integer rightsAmount; |
| 102 | 106 | ||
| 103 | // 权益2id | 107 | /** 权益2id */ |
| 104 | @Column(name = "rights2_id") | 108 | @Column(name = "rights2_id") |
| 105 | private Long rights2Id; | 109 | private Long rights2Id; |
| 106 | 110 | ||
| 107 | // 权益2数量 | 111 | /** 权益2数量 */ |
| 108 | @Column(name = "rights2_amount") | 112 | @Column(name = "rights2_amount") |
| 109 | private Integer rights2Amount; | 113 | private Integer rights2Amount; |
| 110 | 114 | ||
| 111 | // 权益3id | 115 | /** 权益3id */ |
| 112 | @Column(name = "rights3_id") | 116 | @Column(name = "rights3_id") |
| 113 | private Long rights3Id; | 117 | private Long rights3Id; |
| 114 | 118 | ||
| 115 | // 权益3数量 | 119 | /** 权益3数量 */ |
| 116 | @Column(name = "rights3_amount") | 120 | @Column(name = "rights3_amount") |
| 117 | private Integer rights3Amount; | 121 | private Integer rights3Amount; |
| 118 | 122 | ||
| 119 | // 状态 0:失效;1:生效 | 123 | /** 会员专享 0:会员专享 1:非会员专享 */ |
| 124 | @Column(name = "member_exclusive") | ||
| 125 | private Integer memberExclusive; | ||
| 126 | |||
| 127 | /** 状态 0:失效;1:生效 */ | ||
| 120 | @Column(name = "status", nullable = false) | 128 | @Column(name = "status", nullable = false) |
| 121 | private Integer status; | 129 | private Integer status; |
| 122 | 130 | ||
| 123 | // 创建时间 | 131 | /** 任务名称 */ |
| 132 | @Column(name = "name", nullable = false) | ||
| 133 | private String name; | ||
| 134 | |||
| 135 | /** 编号 */ | ||
| 136 | @Column(name = "code", nullable = false) | ||
| 137 | private String code; | ||
| 138 | |||
| 139 | /** 任务描述 */ | ||
| 140 | @Column(name = "description", nullable = false) | ||
| 141 | private String description; | ||
| 142 | |||
| 143 | @Transient | ||
| 144 | private String attr; | ||
| 145 | |||
| 146 | /** 创建时间 */ | ||
| 124 | @CreatedDate | 147 | @CreatedDate |
| 125 | @Column(name = "create_time") | 148 | @Column(name = "create_time") |
| 126 | private Timestamp createTime; | 149 | private Timestamp createTime; |
| 127 | 150 | ||
| 128 | // 更新时间 | 151 | /** 更新时间 */ |
| 129 | @LastModifiedDate | 152 | @LastModifiedDate |
| 130 | @Column(name = "update_time") | 153 | @Column(name = "update_time") |
| 131 | private Timestamp updateTime; | 154 | private Timestamp updateTime; | ... | ... |
| 1 | package com.topdraw.business.module.points.standingbook.domain; | 1 | package com.topdraw.business.module.task.progress.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import lombok.AllArgsConstructor; | ||
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 7 | import lombok.NoArgsConstructor; | ||
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 9 | import org.springframework.data.annotation.CreatedDate; |
| 8 | import org.springframework.data.annotation.LastModifiedDate; | 10 | import org.springframework.data.annotation.LastModifiedDate; |
| ... | @@ -14,52 +16,55 @@ import java.sql.Timestamp; | ... | @@ -14,52 +16,55 @@ import java.sql.Timestamp; |
| 14 | 16 | ||
| 15 | /** | 17 | /** |
| 16 | * @author XiangHan | 18 | * @author XiangHan |
| 17 | * @date 2021-10-29 | 19 | * @date 2021-11-02 |
| 18 | */ | 20 | */ |
| 19 | @Entity | 21 | @Entity |
| 20 | @Data | 22 | @Data |
| 21 | @EntityListeners(AuditingEntityListener.class) | 23 | @EntityListeners(AuditingEntityListener.class) |
| 22 | @Accessors(chain = true) | 24 | @Accessors(chain = true) |
| 23 | @Table(name="uc_points_standing_book") | 25 | @Table(name="uc_tr_task_progress") |
| 24 | public class PointsStandingBook implements Serializable { | 26 | @AllArgsConstructor |
| 27 | @NoArgsConstructor | ||
| 28 | public class TrTaskProgress implements Serializable { | ||
| 25 | 29 | ||
| 26 | // 主键 | ||
| 27 | @Id | 30 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 32 | @Column(name = "id") |
| 30 | private Long id; | 33 | private Long id; |
| 31 | 34 | ||
| 32 | // 积分生产 | 35 | /** 用户id */ |
| 33 | @Column(name = "points_produce", nullable = false) | 36 | @Column(name = "member_id", nullable = false) |
| 34 | private Long pointsProduce; | 37 | private Long memberId; |
| 35 | 38 | ||
| 36 | // 积分消耗 | 39 | /** 任务id */ |
| 37 | @Column(name = "points_consume", nullable = false) | 40 | @Column(name = "task_id") |
| 38 | private Long pointsConsume; | 41 | private Long taskId; |
| 39 | 42 | ||
| 40 | // 可用总积分 | 43 | /** 已完成的行为量 */ |
| 41 | @Column(name = "points_available", nullable = false) | 44 | @Column(name = "current_action_amount") |
| 42 | private Long pointsAvailable; | 45 | private Integer currentActionAmount; |
| 43 | 46 | ||
| 44 | // 积分过期 | 47 | /** 目标行为量 */ |
| 45 | @Column(name = "points_expire", nullable = false) | 48 | @Column(name = "target_action_amount") |
| 46 | private Long pointsExpire; | 49 | private Integer targetActionAmount; |
| 47 | 50 | ||
| 48 | // 日期 | 51 | /** 状态 0:未完成;1:已完成 */ |
| 49 | @Column(name = "day") | 52 | @Column(name = "status") |
| 50 | private String day; | 53 | private Integer status; |
| 54 | |||
| 55 | /** 完成时间 */ | ||
| 56 | @Column(name = "completion_time") | ||
| 57 | private Timestamp completionTime; | ||
| 51 | 58 | ||
| 52 | // 创建时间 | ||
| 53 | @CreatedDate | 59 | @CreatedDate |
| 54 | @Column(name = "create_time") | 60 | @Column(name = "create_time") |
| 55 | private Timestamp createTime; | 61 | private Timestamp createTime; |
| 56 | 62 | ||
| 57 | // 创建时间 | ||
| 58 | @LastModifiedDate | 63 | @LastModifiedDate |
| 59 | @Column(name = "update_time") | 64 | @Column(name = "update_time") |
| 60 | private Timestamp updateTime; | 65 | private Timestamp updateTime; |
| 61 | 66 | ||
| 62 | public void copy(PointsStandingBook source){ | 67 | public void copy(TrTaskProgress source){ |
| 63 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 68 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); |
| 64 | } | 69 | } |
| 65 | } | 70 | } | ... | ... |
src/main/java/com/topdraw/business/module/task/progress/repository/TrTaskProgressRepository.java
0 → 100644
| 1 | package com.topdraw.business.module.task.progress.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | import org.springframework.data.jpa.repository.Query; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * @author XiangHan | ||
| 12 | * @date 2021-11-02 | ||
| 13 | */ | ||
| 14 | public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { | ||
| 15 | |||
| 16 | @Query(value = "select id, member_id, task_id , current_action_amount , \n" + | ||
| 17 | " target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" + | ||
| 18 | " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true) | ||
| 19 | List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | ||
| 20 | } |
src/main/java/com/topdraw/business/module/task/progress/service/TrTaskProgressService.java
0 → 100644
| 1 | package com.topdraw.business.module.task.progress.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | ||
| 4 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | ||
| 5 | |||
| 6 | import java.util.List; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author XiangHan | ||
| 10 | * @date 2021-11-02 | ||
| 11 | */ | ||
| 12 | public interface TrTaskProgressService { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * 根据ID查询 | ||
| 16 | * @param id ID | ||
| 17 | * @return TrTaskProgressDTO | ||
| 18 | */ | ||
| 19 | TrTaskProgressDTO findById(Long id); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * | ||
| 23 | * @param resources | ||
| 24 | */ | ||
| 25 | void create(TrTaskProgress resources); | ||
| 26 | |||
| 27 | /** | ||
| 28 | * | ||
| 29 | * @param resources | ||
| 30 | */ | ||
| 31 | void update(TrTaskProgress resources); | ||
| 32 | |||
| 33 | /** | ||
| 34 | * | ||
| 35 | * @param id | ||
| 36 | */ | ||
| 37 | void delete(Long id); | ||
| 38 | |||
| 39 | /** | ||
| 40 | * | ||
| 41 | * @param memberId | ||
| 42 | * @param taskId | ||
| 43 | * @param time1 | ||
| 44 | * @return | ||
| 45 | */ | ||
| 46 | List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); | ||
| 47 | } |
src/main/java/com/topdraw/business/module/task/progress/service/dto/TrTaskProgressDTO.java
0 → 100644
| 1 | package com.topdraw.business.module.task.progress.service.dto; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | |||
| 5 | import java.io.Serializable; | ||
| 6 | import java.sql.Timestamp; | ||
| 7 | |||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-11-02 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class TrTaskProgressDTO implements Serializable { | ||
| 15 | |||
| 16 | private Long id; | ||
| 17 | |||
| 18 | /** 用户id */ | ||
| 19 | private Long memberId; | ||
| 20 | |||
| 21 | /** 任务id */ | ||
| 22 | private Long taskId; | ||
| 23 | |||
| 24 | /** 已完成的行为量 */ | ||
| 25 | private Integer currentActionAmount; | ||
| 26 | |||
| 27 | /** 目标行为量 */ | ||
| 28 | private Integer targetActionAmount; | ||
| 29 | |||
| 30 | /** 状态 0:未完成;1:已完成 */ | ||
| 31 | private Integer status; | ||
| 32 | |||
| 33 | /** 完成时间 */ | ||
| 34 | private Timestamp completionTime; | ||
| 35 | |||
| 36 | private Timestamp createTime; | ||
| 37 | |||
| 38 | private Timestamp updateTime; | ||
| 39 | } |
src/main/java/com/topdraw/business/module/task/progress/service/impl/TrTaskProgressServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.module.task.progress.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | ||
| 4 | import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository; | ||
| 5 | import com.topdraw.business.module.task.progress.service.TrTaskProgressService; | ||
| 6 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | ||
| 7 | import com.topdraw.business.module.task.progress.service.mapper.TrTaskProgressMapper; | ||
| 8 | import com.topdraw.utils.ValidationUtil; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 11 | import org.springframework.stereotype.Service; | ||
| 12 | import org.springframework.transaction.annotation.Propagation; | ||
| 13 | import org.springframework.transaction.annotation.Transactional; | ||
| 14 | import org.springframework.util.Assert; | ||
| 15 | |||
| 16 | import java.util.List; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @author XiangHan | ||
| 20 | * @date 2021-11-02 | ||
| 21 | */ | ||
| 22 | @Service | ||
| 23 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 24 | public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ||
| 25 | |||
| 26 | @Autowired | ||
| 27 | private TrTaskProgressRepository trTaskProgressRepository; | ||
| 28 | |||
| 29 | @Autowired | ||
| 30 | private TrTaskProgressMapper trTaskProgressMapper; | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public TrTaskProgressDTO findById(Long id) { | ||
| 34 | TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new); | ||
| 35 | ValidationUtil.isNull(TrTaskProgress.getId(),"TrTaskProgress","id",id); | ||
| 36 | return this.trTaskProgressMapper.toDto(TrTaskProgress); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Override | ||
| 40 | @Transactional(rollbackFor = Exception.class) | ||
| 41 | public void create(TrTaskProgress resources) { | ||
| 42 | this.trTaskProgressRepository.save(resources); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | @Transactional(rollbackFor = Exception.class) | ||
| 47 | public void update(TrTaskProgress resources) { | ||
| 48 | TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new); | ||
| 49 | ValidationUtil.isNull( TrTaskProgress.getId(),"TrTaskProgress","id",resources.getId()); | ||
| 50 | TrTaskProgress.copy(resources); | ||
| 51 | this.trTaskProgressRepository.save(TrTaskProgress); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Override | ||
| 55 | @Transactional(rollbackFor = Exception.class) | ||
| 56 | public void delete(Long id) { | ||
| 57 | Assert.notNull(id, "The given id must not be null!"); | ||
| 58 | TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseThrow( | ||
| 59 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TrTaskProgress.class, id), 1)); | ||
| 60 | this.trTaskProgressRepository.delete(TrTaskProgress); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) { | ||
| 65 | return this.trTaskProgressMapper.toDto(this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1)); | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | } |
src/main/java/com/topdraw/business/module/task/progress/service/mapper/TrTaskProgressMapper.java
0 → 100644
| 1 | package com.topdraw.business.module.task.progress.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.module.task.progress.domain.TrTaskProgress; | ||
| 5 | import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-11-02 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface TrTaskProgressMapper extends BaseMapper<TrTaskProgressDTO, TrTaskProgress> { | ||
| 15 | |||
| 16 | } |
| ... | @@ -3,8 +3,12 @@ package com.topdraw.business.module.task.repository; | ... | @@ -3,8 +3,12 @@ package com.topdraw.business.module.task.repository; |
| 3 | import com.topdraw.business.module.task.domain.Task; | 3 | import com.topdraw.business.module.task.domain.Task; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | import org.springframework.transaction.annotation.Transactional; | ||
| 6 | 9 | ||
| 7 | import java.util.List; | 10 | import java.util.List; |
| 11 | import java.util.Optional; | ||
| 8 | 12 | ||
| 9 | /** | 13 | /** |
| 10 | * @author XiangHan | 14 | * @author XiangHan |
| ... | @@ -14,5 +18,10 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat | ... | @@ -14,5 +18,10 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat |
| 14 | 18 | ||
| 15 | List<Task> findByTaskTemplateId(Long taskTemplateId); | 19 | List<Task> findByTaskTemplateId(Long taskTemplateId); |
| 16 | 20 | ||
| 17 | // List<Task> findByTemplateId(Long taskTemplateId); | 21 | Optional<Task> findByCode(String code); |
| 22 | |||
| 23 | @Modifying | ||
| 24 | @Transactional | ||
| 25 | @Query(value = "UPDATE `tr_task` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true) | ||
| 26 | void updateDeleteMark(Long id); | ||
| 18 | } | 27 | } | ... | ... |
| ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.task.service; | ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.task.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.task.domain.Task; | 3 | import com.topdraw.business.module.task.domain.Task; |
| 4 | import com.topdraw.business.module.task.service.dto.TaskDTO; | 4 | import com.topdraw.business.module.task.service.dto.TaskDTO; |
| 5 | import com.topdraw.business.module.task.service.dto.TaskQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.util.List; | 6 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -15,32 +12,47 @@ import java.util.Map; | ... | @@ -15,32 +12,47 @@ import java.util.Map; |
| 15 | public interface TaskService { | 12 | public interface TaskService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(TaskQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<TaskDTO> | ||
| 29 | */ | ||
| 30 | List<TaskDTO> queryAll(TaskQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 15 | * 根据ID查询 |
| 34 | * @param id ID | 16 | * @param id ID |
| 35 | * @return TaskDTO | 17 | * @return TaskDTO |
| 36 | */ | 18 | */ |
| 37 | TaskDTO findById(Long id); | 19 | TaskDTO findById(Long id); |
| 38 | 20 | ||
| 39 | void create(Task resources); | 21 | /** |
| 22 | * | ||
| 23 | * @param taskTemplateId | ||
| 24 | * @return | ||
| 25 | */ | ||
| 26 | List<Task> findByTemplateId(Long taskTemplateId); | ||
| 40 | 27 | ||
| 41 | void update(Task resources); | 28 | /** |
| 29 | * | ||
| 30 | * @param code | ||
| 31 | * @return | ||
| 32 | */ | ||
| 33 | TaskDTO findByCode(String code); | ||
| 42 | 34 | ||
| 43 | void delete(Long id); | 35 | /** |
| 36 | * | ||
| 37 | * @param task | ||
| 38 | */ | ||
| 39 | TaskDTO create(Task task); | ||
| 44 | 40 | ||
| 45 | List<Task> findByTemplateId(Long taskTemplateId); | 41 | /** |
| 42 | * | ||
| 43 | * @param task | ||
| 44 | */ | ||
| 45 | TaskDTO update(Task task); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * | ||
| 49 | * @param task | ||
| 50 | */ | ||
| 51 | void delete(Task task); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * | ||
| 55 | * @param id | ||
| 56 | */ | ||
| 57 | void delete(Long id); | ||
| 46 | } | 58 | } | ... | ... |
| ... | @@ -4,6 +4,7 @@ import lombok.Data; | ... | @@ -4,6 +4,7 @@ import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 6 | import java.sql.Timestamp; |
| 7 | import java.time.LocalDateTime; | ||
| 7 | 8 | ||
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| ... | @@ -15,69 +16,84 @@ public class TaskDTO implements Serializable { | ... | @@ -15,69 +16,84 @@ public class TaskDTO implements Serializable { |
| 15 | 16 | ||
| 16 | private Long id; | 17 | private Long id; |
| 17 | 18 | ||
| 18 | // 任务模板id | 19 | /** 任务模板id */ |
| 19 | private Long taskTemplateId; | 20 | private Long taskTemplateId; |
| 20 | 21 | ||
| 21 | // 任务重复类型,-1:不限次;1:单次;>1:多次 | 22 | /** 任务重复类型,-1:不限次;1:单次;>1:多次 */ |
| 22 | private Integer taskRepeatType; | 23 | private Integer taskRepeatType; |
| 23 | 24 | ||
| 24 | // 任务每日重置 0:不重置;1:重置 | 25 | /** 任务每日重置 0:不重置;1:重置 */ |
| 25 | private Integer taskDailyReset; | 26 | private Integer taskDailyReset; |
| 26 | 27 | ||
| 27 | // 行为量(完成此任务需要多少次相同行为的触发) | 28 | /** 行为量(完成此任务需要多少次相同行为的触发) */ |
| 28 | private Integer actionAmount; | 29 | private Integer actionAmount; |
| 29 | 30 | ||
| 30 | // 任务生效时间 | 31 | /** 任务生效时间 */ |
| 31 | private Timestamp validTime; | 32 | private Timestamp validTime; |
| 32 | 33 | ||
| 33 | // 任务失效时间 | 34 | /** 任务失效时间 */ |
| 34 | private Timestamp expireTime; | 35 | private LocalDateTime expireTime; |
| 35 | 36 | ||
| 36 | // 显示顺序 | 37 | /** 显示顺序 */ |
| 37 | private Integer sequence; | 38 | private Integer sequence; |
| 38 | 39 | ||
| 39 | // 获得成长值 | 40 | /** 获得成长值 */ |
| 40 | private Long rewardExp; | 41 | private Long rewardExp; |
| 41 | 42 | ||
| 42 | // 获得积分 | 43 | /** 获得积分 */ |
| 43 | private Long rewardPoints; | 44 | private Long rewardPoints; |
| 44 | 45 | ||
| 45 | // 积分过期时间(空为不过期) | 46 | /** 积分过期时间(空为不过期) */ |
| 46 | private Long rewardPointsExpireTime; | 47 | private Long rewardPointsExpireTime; |
| 47 | 48 | ||
| 48 | // 能够获取该任务的用户分组,为空则都能获取 | 49 | /** 能够获取该任务的用户分组,为空则都能获取 */ |
| 49 | private String groups; | 50 | private String groups; |
| 50 | 51 | ||
| 51 | // 会员等级门槛(0表示无门槛) | 52 | /** 会员等级门槛(0表示无门槛) */ |
| 52 | private Integer memberLevel; | 53 | private Integer memberLevel; |
| 53 | 54 | ||
| 54 | // 会员vip门槛(0表示没有门槛) | 55 | /** 会员vip门槛(0表示没有门槛) */ |
| 55 | private Integer memberVip; | 56 | private Integer memberVip; |
| 56 | 57 | ||
| 57 | // 权益id | 58 | /** 权益id */ |
| 58 | private Long rightsId; | 59 | private Long rightsId; |
| 59 | 60 | ||
| 60 | // 权益数量(活动机会次数、优惠券数量、奖品数量) | 61 | /** 权益数量(活动机会次数、优惠券数量、奖品数量) */ |
| 61 | private Integer rightsAmount; | 62 | private Integer rightsAmount; |
| 62 | 63 | ||
| 63 | // 权益2id | 64 | /** 权益2id */ |
| 64 | private Long rights2Id; | 65 | private Long rights2Id; |
| 65 | 66 | ||
| 66 | // 权益2数量 | 67 | /** 权益2数量 */ |
| 67 | private Integer rights2Amount; | 68 | private Integer rights2Amount; |
| 68 | 69 | ||
| 69 | // 权益3id | 70 | /** 权益3id */ |
| 70 | private Long rights3Id; | 71 | private Long rights3Id; |
| 71 | 72 | ||
| 72 | // 权益3数量 | 73 | /** 权益3数量 */ |
| 73 | private Integer rights3Amount; | 74 | private Integer rights3Amount; |
| 74 | 75 | ||
| 75 | // 状态 0:失效;1:生效 | 76 | /** 会员专享 0:会员专享 1:非会员专享 */ |
| 77 | private Integer memberExclusive; | ||
| 78 | |||
| 79 | /** 状态 0:失效;1:生效 */ | ||
| 76 | private Integer status; | 80 | private Integer status; |
| 77 | 81 | ||
| 78 | // 创建时间 | 82 | /** 任务名称 */ |
| 83 | private String name; | ||
| 84 | |||
| 85 | /** 编号 */ | ||
| 86 | private String code; | ||
| 87 | |||
| 88 | /** 任务描述 */ | ||
| 89 | private String description; | ||
| 90 | |||
| 91 | /** 属性 */ | ||
| 92 | private String attr; | ||
| 93 | |||
| 94 | /** 创建时间 */ | ||
| 79 | private Timestamp createTime; | 95 | private Timestamp createTime; |
| 80 | 96 | ||
| 81 | // 更新时间 | 97 | /** 更新时间 */ |
| 82 | private Timestamp updateTime; | 98 | private Timestamp updateTime; |
| 83 | } | 99 | } | ... | ... |
| ... | @@ -4,22 +4,14 @@ import com.topdraw.business.module.task.domain.Task; | ... | @@ -4,22 +4,14 @@ import com.topdraw.business.module.task.domain.Task; |
| 4 | import com.topdraw.business.module.task.repository.TaskRepository; | 4 | import com.topdraw.business.module.task.repository.TaskRepository; |
| 5 | import com.topdraw.business.module.task.service.TaskService; | 5 | import com.topdraw.business.module.task.service.TaskService; |
| 6 | import com.topdraw.business.module.task.service.dto.TaskDTO; | 6 | import com.topdraw.business.module.task.service.dto.TaskDTO; |
| 7 | import com.topdraw.business.module.task.service.dto.TaskQueryCriteria; | ||
| 8 | import com.topdraw.business.module.task.service.mapper.TaskMapper; | 7 | import com.topdraw.business.module.task.service.mapper.TaskMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | 8 | import com.topdraw.utils.ValidationUtil; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | ||
| 14 | import org.springframework.data.domain.Page; | ||
| 15 | import org.springframework.data.domain.Pageable; | ||
| 16 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.transaction.annotation.Propagation; | 11 | import org.springframework.transaction.annotation.Propagation; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
| 19 | import org.springframework.util.Assert; | ||
| 20 | 13 | ||
| 21 | import java.util.List; | 14 | import java.util.List; |
| 22 | import java.util.Map; | ||
| 23 | import java.util.Objects; | 15 | import java.util.Objects; |
| 24 | 16 | ||
| 25 | /** | 17 | /** |
| ... | @@ -31,57 +23,50 @@ import java.util.Objects; | ... | @@ -31,57 +23,50 @@ import java.util.Objects; |
| 31 | public class TaskServiceImpl implements TaskService { | 23 | public class TaskServiceImpl implements TaskService { |
| 32 | 24 | ||
| 33 | @Autowired | 25 | @Autowired |
| 34 | private TaskRepository TaskRepository; | 26 | private TaskMapper taskMapper; |
| 35 | |||
| 36 | @Autowired | 27 | @Autowired |
| 37 | private TaskMapper TaskMapper; | 28 | private TaskRepository taskRepository; |
| 29 | |||
| 38 | 30 | ||
| 39 | @Override | 31 | @Override |
| 40 | public Map<String, Object> queryAll(TaskQueryCriteria criteria, Pageable pageable) { | 32 | public TaskDTO findById(Long id) { |
| 41 | Page<Task> page = TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 33 | Task Task = this.taskRepository.findById(id).orElseGet(Task::new); |
| 42 | return PageUtil.toPage(page.map(TaskMapper::toDto)); | 34 | ValidationUtil.isNull(Task.getId(),"Task","id",id); |
| 35 | return this.taskMapper.toDto(Task); | ||
| 43 | } | 36 | } |
| 44 | 37 | ||
| 45 | @Override | 38 | @Override |
| 46 | public List<TaskDTO> queryAll(TaskQueryCriteria criteria) { | 39 | public List<Task> findByTemplateId(Long taskTemplateId) { |
| 47 | return TaskMapper.toDto(TaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 40 | return Objects.nonNull(taskTemplateId) ? this.taskRepository.findByTaskTemplateId(taskTemplateId) : null; |
| 48 | } | 41 | } |
| 49 | 42 | ||
| 50 | @Override | 43 | @Override |
| 51 | public TaskDTO findById(Long id) { | 44 | public TaskDTO findByCode(String code) { |
| 52 | Task Task = TaskRepository.findById(id).orElseGet(Task::new); | 45 | Task task = this.taskRepository.findByCode(code).orElseGet(Task::new); |
| 53 | ValidationUtil.isNull(Task.getId(),"Task","id",id); | 46 | return this.taskMapper.toDto(task); |
| 54 | return TaskMapper.toDto(Task); | ||
| 55 | } | 47 | } |
| 56 | 48 | ||
| 57 | @Override | 49 | @Override |
| 58 | @Transactional(rollbackFor = Exception.class) | 50 | public TaskDTO create(Task task) { |
| 59 | public void create(Task resources) { | 51 | Task save = this.taskRepository.save(task); |
| 60 | TaskRepository.save(resources); | 52 | return this.taskMapper.toDto(save); |
| 61 | } | 53 | } |
| 62 | 54 | ||
| 63 | @Override | 55 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 56 | public TaskDTO update(Task task) { |
| 65 | public void update(Task resources) { | 57 | Task save = this.taskRepository.save(task); |
| 66 | Task Task = TaskRepository.findById(resources.getId()).orElseGet(Task::new); | 58 | return this.taskMapper.toDto(save); |
| 67 | ValidationUtil.isNull( Task.getId(),"Task","id",resources.getId()); | ||
| 68 | Task.copy(resources); | ||
| 69 | TaskRepository.save(Task); | ||
| 70 | } | 59 | } |
| 71 | 60 | ||
| 72 | @Override | 61 | @Override |
| 73 | @Transactional(rollbackFor = Exception.class) | 62 | public void delete(Task task) { |
| 74 | public void delete(Long id) { | 63 | Long id = task.getId(); |
| 75 | Assert.notNull(id, "The given id must not be null!"); | 64 | this.delete(id); |
| 76 | Task Task = TaskRepository.findById(id).orElseThrow( | ||
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Task.class, id), 1)); | ||
| 78 | TaskRepository.delete(Task); | ||
| 79 | } | 65 | } |
| 80 | 66 | ||
| 81 | @Override | 67 | @Override |
| 82 | public List<Task> findByTemplateId(Long taskTemplateId) { | 68 | public void delete(Long id) { |
| 83 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | 69 | this.taskRepository.updateDeleteMark(id); |
| 84 | } | 70 | } |
| 85 | 71 | ||
| 86 | |||
| 87 | } | 72 | } | ... | ... |
| ... | @@ -28,34 +28,38 @@ public class TaskTemplate implements Serializable { | ... | @@ -28,34 +28,38 @@ public class TaskTemplate implements Serializable { |
| 28 | @Column(name = "id") | 28 | @Column(name = "id") |
| 29 | private Long id; | 29 | private Long id; |
| 30 | 30 | ||
| 31 | // 标识 | 31 | /** 标识 */ |
| 32 | @Column(name = "code") | 32 | @Column(name = "code") |
| 33 | private String code; | 33 | private String code; |
| 34 | 34 | ||
| 35 | // 名称 | 35 | /** 名称 */ |
| 36 | @Column(name = "name") | 36 | @Column(name = "name") |
| 37 | private String name; | 37 | private String name; |
| 38 | 38 | ||
| 39 | // 关注事件(和MQ topic相关) | 39 | /** 关注事件(和MQ topic相关) */ |
| 40 | @Column(name = "event") | 40 | @Column(name = "event") |
| 41 | private String event; | 41 | private String event; |
| 42 | 42 | ||
| 43 | // 描述 | 43 | /** 描述 */ |
| 44 | @Column(name = "description") | 44 | @Column(name = "description") |
| 45 | private String description; | 45 | private String description; |
| 46 | 46 | ||
| 47 | // 状态 0:失效;1:生效 | 47 | /** 状态 0:失效;1:生效 */ |
| 48 | @Column(name = "status") | 48 | @Column(name = "status") |
| 49 | private Integer status; | 49 | private Integer status; |
| 50 | 50 | ||
| 51 | // 类型 0:活动任务模板 | 51 | /** 类型 0:活动任务模板 */ |
| 52 | @Column(name = "type") | 52 | @Column(name = "type") |
| 53 | private Integer type; | 53 | private Integer type; |
| 54 | 54 | ||
| 55 | // 模板参数,json | 55 | /** 模板参数,json */ |
| 56 | @Column(name = "params") | 56 | @Column(name = "params") |
| 57 | private String params; | 57 | private String params; |
| 58 | 58 | ||
| 59 | /** 删除标识 0:正常;1:已删除; */ | ||
| 60 | @Column(name = "delete_mark") | ||
| 61 | private Integer deleteMark; | ||
| 62 | |||
| 59 | @CreatedDate | 63 | @CreatedDate |
| 60 | @Column(name = "create_time") | 64 | @Column(name = "create_time") |
| 61 | private Timestamp createTime; | 65 | private Timestamp createTime; | ... | ... |
| ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.task.template.repository; | ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.task.template.repository; |
| 3 | import com.topdraw.business.module.task.template.domain.TaskTemplate; | 3 | import com.topdraw.business.module.task.template.domain.TaskTemplate; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | import org.springframework.data.jpa.repository.Query; | ||
| 8 | import org.springframework.transaction.annotation.Transactional; | ||
| 6 | 9 | ||
| 7 | import java.util.Optional; | 10 | import java.util.Optional; |
| 8 | 11 | ||
| ... | @@ -14,5 +17,12 @@ public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long | ... | @@ -14,5 +17,12 @@ public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long |
| 14 | 17 | ||
| 15 | Optional<TaskTemplate> findFirstByCode(String code); | 18 | Optional<TaskTemplate> findFirstByCode(String code); |
| 16 | 19 | ||
| 17 | TaskTemplate findByEvent(String event); | 20 | Optional<TaskTemplate> findByEvent(String event); |
| 21 | |||
| 22 | Optional<TaskTemplate> findByType(Integer event); | ||
| 23 | |||
| 24 | @Modifying | ||
| 25 | @Transactional | ||
| 26 | @Query(value = "UPDATE `tr_task_template` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true) | ||
| 27 | void updateDeleteMark(Long id); | ||
| 18 | } | 28 | } | ... | ... |
| ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.task.template.service; | ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.task.template.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.task.template.domain.TaskTemplate; | 3 | import com.topdraw.business.module.task.template.domain.TaskTemplate; |
| 4 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | 4 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; |
| 5 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.util.List; | 6 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -15,31 +12,28 @@ import java.util.Map; | ... | @@ -15,31 +12,28 @@ import java.util.Map; |
| 15 | public interface TaskTemplateService { | 12 | public interface TaskTemplateService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<TaskTemplateDTO> | ||
| 29 | */ | ||
| 30 | List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 15 | * 根据ID查询 |
| 34 | * @param id ID | 16 | * @param id ID |
| 35 | * @return TaskTemplateDTO | 17 | * @return TaskTemplateDTO |
| 36 | */ | 18 | */ |
| 37 | TaskTemplateDTO findById(Long id); | 19 | TaskTemplateDTO findById(Long id); |
| 38 | 20 | ||
| 39 | void create(TaskTemplate resources); | 21 | /** |
| 22 | * | ||
| 23 | * @param resources | ||
| 24 | */ | ||
| 25 | TaskTemplateDTO create(TaskTemplate resources); | ||
| 40 | 26 | ||
| 41 | void update(TaskTemplate resources); | 27 | /** |
| 28 | * | ||
| 29 | * @param resources | ||
| 30 | */ | ||
| 31 | TaskTemplateDTO update(TaskTemplate resources); | ||
| 42 | 32 | ||
| 33 | /** | ||
| 34 | * | ||
| 35 | * @param id | ||
| 36 | */ | ||
| 43 | void delete(Long id); | 37 | void delete(Long id); |
| 44 | 38 | ||
| 45 | /** | 39 | /** |
| ... | @@ -47,7 +41,19 @@ public interface TaskTemplateService { | ... | @@ -47,7 +41,19 @@ public interface TaskTemplateService { |
| 47 | * @param code | 41 | * @param code |
| 48 | * @return TaskTemplateDTO | 42 | * @return TaskTemplateDTO |
| 49 | */ | 43 | */ |
| 50 | TaskTemplateDTO getByCode(String code); | 44 | TaskTemplateDTO findByCode(String code); |
| 45 | |||
| 46 | /** | ||
| 47 | * | ||
| 48 | * @param event | ||
| 49 | * @return | ||
| 50 | */ | ||
| 51 | TaskTemplateDTO findByEvent(String event); | ||
| 51 | 52 | ||
| 52 | TaskTemplate findByEvent(String event); | 53 | /** |
| 54 | * | ||
| 55 | * @param event | ||
| 56 | * @return | ||
| 57 | */ | ||
| 58 | TaskTemplateDTO findByType(Integer event); | ||
| 53 | } | 59 | } | ... | ... |
| ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.task.template.service.dto; | ... | @@ -2,6 +2,7 @@ package com.topdraw.business.module.task.template.service.dto; |
| 2 | 2 | ||
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | import javax.persistence.Column; | ||
| 5 | import java.io.Serializable; | 6 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 7 | import java.sql.Timestamp; |
| 7 | 8 | ||
| ... | @@ -15,27 +16,30 @@ public class TaskTemplateDTO implements Serializable { | ... | @@ -15,27 +16,30 @@ public class TaskTemplateDTO implements Serializable { |
| 15 | 16 | ||
| 16 | private Long id; | 17 | private Long id; |
| 17 | 18 | ||
| 18 | // 标识 | 19 | /** 标识 */ |
| 19 | private String code; | 20 | private String code; |
| 20 | 21 | ||
| 21 | // 名称 | 22 | /** 名称 */ |
| 22 | private String name; | 23 | private String name; |
| 23 | 24 | ||
| 24 | // 关注事件(和MQ topic相关) | 25 | /** 关注事件(和MQ topic相关) */ |
| 25 | private String event; | 26 | private String event; |
| 26 | 27 | ||
| 27 | // 描述 | 28 | /** 描述 */ |
| 28 | private String description; | 29 | private String description; |
| 29 | 30 | ||
| 30 | // 状态 0:失效;1:生效 | 31 | /** 状态 0:失效;1:生效 */ |
| 31 | private Integer status; | 32 | private Integer status; |
| 32 | 33 | ||
| 33 | // 类型 0:活动任务模板 | 34 | /** 类型 0:活动任务模板 */ |
| 34 | private Integer type; | 35 | private Integer type; |
| 35 | 36 | ||
| 36 | // 模板参数,json | 37 | /** 模板参数,json */ |
| 37 | private String params; | 38 | private String params; |
| 38 | 39 | ||
| 40 | /** 删除标识 0:正常;1:已删除; */ | ||
| 41 | private Integer deleteMark; | ||
| 42 | |||
| 39 | private Timestamp createTime; | 43 | private Timestamp createTime; |
| 40 | 44 | ||
| 41 | private Timestamp updateTime; | 45 | private Timestamp updateTime; | ... | ... |
| ... | @@ -4,23 +4,18 @@ import com.topdraw.business.module.task.template.domain.TaskTemplate; | ... | @@ -4,23 +4,18 @@ import com.topdraw.business.module.task.template.domain.TaskTemplate; |
| 4 | import com.topdraw.business.module.task.template.repository.TaskTemplateRepository; | 4 | import com.topdraw.business.module.task.template.repository.TaskTemplateRepository; |
| 5 | import com.topdraw.business.module.task.template.service.TaskTemplateService; | 5 | import com.topdraw.business.module.task.template.service.TaskTemplateService; |
| 6 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | 6 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; |
| 7 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateQueryCriteria; | ||
| 8 | import com.topdraw.business.module.task.template.service.mapper.TaskTemplateMapper; | 7 | import com.topdraw.business.module.task.template.service.mapper.TaskTemplateMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.StringUtils; | 8 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | 11 | import org.springframework.dao.EmptyResultDataAccessException; |
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 21 | 16 | ||
| 22 | import java.util.List; | 17 | import java.util.List; |
| 23 | import java.util.Map; | 18 | import java.util.Objects; |
| 24 | 19 | ||
| 25 | /** | 20 | /** |
| 26 | * @author XiangHan | 21 | * @author XiangHan |
| ... | @@ -31,62 +26,59 @@ import java.util.Map; | ... | @@ -31,62 +26,59 @@ import java.util.Map; |
| 31 | public class TaskTemplateServiceImpl implements TaskTemplateService { | 26 | public class TaskTemplateServiceImpl implements TaskTemplateService { |
| 32 | 27 | ||
| 33 | @Autowired | 28 | @Autowired |
| 34 | private TaskTemplateRepository TaskTemplateRepository; | 29 | private TaskTemplateRepository taskTemplateRepository; |
| 35 | 30 | ||
| 36 | @Autowired | 31 | @Autowired |
| 37 | private TaskTemplateMapper TaskTemplateMapper; | 32 | private TaskTemplateMapper taskTemplateMapper; |
| 38 | |||
| 39 | @Override | ||
| 40 | public Map<String, Object> queryAll(TaskTemplateQueryCriteria criteria, Pageable pageable) { | ||
| 41 | Page<TaskTemplate> page = TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 42 | return PageUtil.toPage(page.map(TaskTemplateMapper::toDto)); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Override | ||
| 46 | public List<TaskTemplateDTO> queryAll(TaskTemplateQueryCriteria criteria) { | ||
| 47 | return TaskTemplateMapper.toDto(TaskTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 48 | } | ||
| 49 | 33 | ||
| 50 | @Override | 34 | @Override |
| 51 | public TaskTemplateDTO findById(Long id) { | 35 | public TaskTemplateDTO findById(Long id) { |
| 52 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseGet(TaskTemplate::new); | 36 | TaskTemplate taskTemplate = this.taskTemplateRepository.findById(id).orElseGet(TaskTemplate::new); |
| 53 | ValidationUtil.isNull(TaskTemplate.getId(),"TaskTemplate","id",id); | 37 | ValidationUtil.isNull(taskTemplate.getId(),"TaskTemplate","id",id); |
| 54 | return TaskTemplateMapper.toDto(TaskTemplate); | 38 | return this.taskTemplateMapper.toDto(taskTemplate); |
| 55 | } | 39 | } |
| 56 | 40 | ||
| 57 | @Override | 41 | @Override |
| 58 | @Transactional(rollbackFor = Exception.class) | 42 | @Transactional(rollbackFor = Exception.class) |
| 59 | public void create(TaskTemplate resources) { | 43 | public TaskTemplateDTO create(TaskTemplate resources) { |
| 60 | TaskTemplateRepository.save(resources); | 44 | TaskTemplate taskTemplate = this.taskTemplateRepository.save(resources); |
| 45 | return this.taskTemplateMapper.toDto(taskTemplate); | ||
| 61 | } | 46 | } |
| 62 | 47 | ||
| 63 | @Override | 48 | @Override |
| 64 | @Transactional(rollbackFor = Exception.class) | 49 | @Transactional(rollbackFor = Exception.class) |
| 65 | public void update(TaskTemplate resources) { | 50 | public TaskTemplateDTO update(TaskTemplate resources) { |
| 66 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(resources.getId()).orElseGet(TaskTemplate::new); | 51 | TaskTemplate taskTemplate = this.taskTemplateRepository.findById(resources.getId()).orElseGet(TaskTemplate::new); |
| 67 | ValidationUtil.isNull( TaskTemplate.getId(),"TaskTemplate","id",resources.getId()); | 52 | ValidationUtil.isNull(taskTemplate.getId(),"TaskTemplate","id",resources.getId()); |
| 68 | TaskTemplate.copy(resources); | 53 | taskTemplate.copy(resources); |
| 69 | TaskTemplateRepository.save(TaskTemplate); | 54 | TaskTemplate template = this.taskTemplateRepository.save(taskTemplate); |
| 55 | return this.taskTemplateMapper.toDto(template); | ||
| 70 | } | 56 | } |
| 71 | 57 | ||
| 72 | @Override | 58 | @Override |
| 73 | @Transactional(rollbackFor = Exception.class) | 59 | @Transactional(rollbackFor = Exception.class) |
| 74 | public void delete(Long id) { | 60 | public void delete(Long id) { |
| 75 | Assert.notNull(id, "The given id must not be null!"); | 61 | Assert.notNull(id, "The given id must not be null!"); |
| 76 | TaskTemplate TaskTemplate = TaskTemplateRepository.findById(id).orElseThrow( | 62 | this.taskTemplateRepository.updateDeleteMark(id); |
| 77 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", TaskTemplate.class, id), 1)); | ||
| 78 | TaskTemplateRepository.delete(TaskTemplate); | ||
| 79 | } | 63 | } |
| 80 | 64 | ||
| 81 | 65 | ||
| 82 | @Override | 66 | @Override |
| 83 | public TaskTemplateDTO getByCode(String code) { | 67 | public TaskTemplateDTO findByCode(String code) { |
| 84 | return StringUtils.isNotEmpty(code) ? TaskTemplateMapper.toDto(TaskTemplateRepository.findFirstByCode(code).orElseGet(TaskTemplate::new)) | 68 | return StringUtils.isNotEmpty(code) ? this.taskTemplateMapper.toDto(this.taskTemplateRepository.findFirstByCode(code).orElseGet(TaskTemplate::new)) |
| 85 | : new TaskTemplateDTO(); | 69 | : new TaskTemplateDTO(); |
| 86 | } | 70 | } |
| 87 | 71 | ||
| 72 | |||
| 73 | @Override | ||
| 74 | public TaskTemplateDTO findByEvent(String event) { | ||
| 75 | return StringUtils.isNotEmpty(event) ? | ||
| 76 | this.taskTemplateMapper.toDto(this.taskTemplateRepository.findByEvent(event).orElseGet(TaskTemplate::new)) : null; | ||
| 77 | } | ||
| 78 | |||
| 88 | @Override | 79 | @Override |
| 89 | public TaskTemplate findByEvent(String event) { | 80 | public TaskTemplateDTO findByType(Integer event) { |
| 90 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; | 81 | return Objects.nonNull(event) ? |
| 82 | this.taskTemplateMapper.toDto(this.taskTemplateRepository.findByType(event).orElseGet(TaskTemplate::new)) : null; | ||
| 91 | } | 83 | } |
| 92 | } | 84 | } | ... | ... |
| ... | @@ -2,6 +2,9 @@ package com.topdraw.business.module.user.iptv.domain; | ... | @@ -2,6 +2,9 @@ package com.topdraw.business.module.user.iptv.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 6 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
| 7 | import com.topdraw.business.module.common.validated.UpdateGroup; | ||
| 5 | import lombok.Data; | 8 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 9 | import lombok.experimental.Accessors; |
| 7 | import org.springframework.data.annotation.CreatedDate; | 10 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -9,9 +12,9 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -9,9 +12,9 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 9 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 10 | 13 | ||
| 11 | import javax.persistence.*; | 14 | import javax.persistence.*; |
| 15 | import javax.validation.constraints.NotNull; | ||
| 12 | import java.io.Serializable; | 16 | import java.io.Serializable; |
| 13 | import java.sql.Timestamp; | 17 | import java.sql.Timestamp; |
| 14 | import java.time.LocalDateTime; | ||
| 15 | 18 | ||
| 16 | /** | 19 | /** |
| 17 | * @author XiangHan | 20 | * @author XiangHan |
| ... | @@ -22,112 +25,110 @@ import java.time.LocalDateTime; | ... | @@ -22,112 +25,110 @@ import java.time.LocalDateTime; |
| 22 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
| 23 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
| 24 | @Table(name="uc_user_tv") | 27 | @Table(name="uc_user_tv") |
| 25 | public class UserTv implements Serializable { | 28 | public class UserTv extends AsyncMqModule implements Serializable { |
| 29 | |||
| 30 | @NotNull(message = "visUserId can't be null !",groups = {CreateGroup.class}) | ||
| 31 | @Column(name = "vis_user_id") | ||
| 32 | private Long visUserId; | ||
| 26 | 33 | ||
| 27 | /** 绑定的小屏账户会员编码 */ | 34 | /** 绑定的小屏账户会员编码 */ |
| 28 | @Column(name = "priority_member_code") | 35 | @Column(name = "priority_member_code") |
| 29 | private String priorityMemberCode; | 36 | private String priorityMemberCode; |
| 30 | 37 | ||
| 31 | @Transient | 38 | /** ID */ |
| 32 | private String memberCode; | ||
| 33 | |||
| 34 | // vis_user表主键 | ||
| 35 | @Column(name = "vis_user_id") | ||
| 36 | private Long visUserId; | ||
| 37 | |||
| 38 | // ID | ||
| 39 | @Id | 39 | @Id |
| 40 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 40 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 41 | @Column(name = "id") | 41 | @Column(name = "id") |
| 42 | private Long id; | 42 | private Long id; |
| 43 | 43 | ||
| 44 | // 人ID | 44 | /** 人ID */ |
| 45 | @Column(name = "`person_id`") | 45 | @Column(name = "person_id") |
| 46 | private Long personId; | 46 | private Long personId; |
| 47 | 47 | ||
| 48 | // 运营商平台 | 48 | /** 运营商平台 */ |
| 49 | @Column(name = "`platform`") | 49 | @Column(name = "platform") |
| 50 | private String platform; | 50 | private String platform; |
| 51 | 51 | ||
| 52 | // 运营商平台账号 | 52 | /** 运营商平台账号 */ |
| 53 | @Column(name = "`platform_account`") | 53 | @Column(name = "platform_account") |
| 54 | @NotNull(message = "platformAccount can't be null !",groups = {CreateGroup.class, UpdateGroup.class}) | ||
| 54 | private String platformAccount; | 55 | private String platformAccount; |
| 55 | 56 | ||
| 56 | // 手机号 | 57 | /** 手机号 */ |
| 57 | @Column(name = "`cellphone`") | 58 | @Column(name = "cellphone") |
| 58 | private String cellphone; | 59 | private String cellphone; |
| 59 | 60 | ||
| 60 | // 用户名 | 61 | /** 用户名 */ |
| 61 | @Column(name = "`username`") | 62 | @Column(name = "username") |
| 62 | private String username; | 63 | private String username; |
| 63 | 64 | ||
| 64 | // 密码 MD5 | 65 | /** 密码 MD5 */ |
| 65 | @Column(name = "`password`") | 66 | @Column(name = "password") |
| 66 | private String password; | 67 | private String password; |
| 67 | 68 | ||
| 68 | // 昵称 Base64 | 69 | /** 昵称 Base64 */ |
| 69 | @Column(name = "`nickname`") | 70 | @Column(name = "nickname") |
| 70 | private String nickname; | 71 | private String nickname; |
| 71 | 72 | ||
| 72 | // 头像 | 73 | /** 头像 */ |
| 73 | @Column(name = "`image`") | 74 | @Column(name = "image") |
| 74 | private String image; | 75 | private String image; |
| 75 | 76 | ||
| 76 | // 登录天数(总天数) | 77 | /** 登录天数(总天数) */ |
| 77 | @Column(name = "`login_days`") | 78 | @Column(name = "login_days") |
| 78 | private Integer loginDays; | 79 | private Integer loginDays; |
| 79 | 80 | ||
| 80 | // 连续登录天数 | 81 | /** 连续登录天数 */ |
| 81 | @Column(name = "`continue_days`") | 82 | @Column(name = "continue_days") |
| 82 | private Integer continueDays; | 83 | private Integer continueDays; |
| 83 | 84 | ||
| 84 | // 活跃时间 | 85 | /** 活跃时间 */ |
| 85 | @Column(name = "`active_time`") | 86 | @Column(name = "active_time") |
| 86 | private LocalDateTime activeTime; | 87 | private Timestamp activeTime; |
| 87 | 88 | ||
| 88 | // 分组 分组ID用逗号分隔 | 89 | /** 分组 分组ID用逗号分隔 */ |
| 89 | @Column(name = "`groups`") | 90 | @Column(name = "groups") |
| 90 | private String groups; | 91 | private String groups; |
| 91 | 92 | ||
| 92 | // 标签 标签用逗号分隔 | 93 | /** 标签 标签用逗号分隔 */ |
| 93 | @Column(name = "`tags`") | 94 | @Column(name = "tags") |
| 94 | private String tags; | 95 | private String tags; |
| 95 | 96 | ||
| 96 | // 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 | 97 | /** 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 */ |
| 97 | @Column(name = "`login_type`") | 98 | @Column(name = "login_type") |
| 98 | private Integer loginType; | 99 | private Integer loginType; |
| 99 | 100 | ||
| 100 | // 状态 0-下线 1-上线 | 101 | /** 状态 0-下线 1-上线 */ |
| 101 | @Column(name = "`status`") | 102 | @Column(name = "status") |
| 102 | private Integer status; | 103 | private Integer status; |
| 103 | 104 | ||
| 104 | // 描述 | 105 | /** 描述 */ |
| 105 | @Column(name = "`description`") | 106 | @Column(name = "description") |
| 106 | private String description; | 107 | private String description; |
| 107 | 108 | ||
| 108 | // 创建者 | 109 | /** 创建者 */ |
| 109 | @Column(name = "`create_by`") | 110 | @Column(name = "create_by") |
| 110 | private String createBy; | 111 | private String createBy; |
| 111 | 112 | ||
| 112 | // 创建时间 | 113 | /** 创建时间 */ |
| 113 | @CreatedDate | 114 | @CreatedDate |
| 114 | @Column(name = "`create_time`") | 115 | @Column(name = "create_time") |
| 115 | private LocalDateTime createTime; | 116 | private Timestamp createTime; |
| 116 | 117 | ||
| 117 | // 更新者 | 118 | /** 更新者 */ |
| 118 | @Column(name = "`update_by`") | 119 | @Column(name = "update_by") |
| 119 | private String updateBy; | 120 | private String updateBy; |
| 120 | 121 | ||
| 121 | // 更新时间 | 122 | /** 更新时间 */ |
| 122 | @LastModifiedDate | 123 | @LastModifiedDate |
| 123 | @Column(name = "`update_time`") | 124 | @Column(name = "update_time") |
| 124 | private LocalDateTime updateTime; | 125 | private Timestamp updateTime; |
| 125 | 126 | ||
| 126 | // 会员id | 127 | /** 会员id */ |
| 127 | @Column(name = "`member_id`") | 128 | @Column(name = "member_id") |
| 128 | private Long memberId; | 129 | private Long memberId; |
| 129 | 130 | ||
| 130 | public void copy(UserTv source){ | 131 | public void copy(UserTv source){ |
| 131 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 132 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false)); |
| 132 | } | 133 | } |
| 133 | } | 134 | } | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 5 | import com.topdraw.util.TimestampUtil; | ||
| 6 | import org.apache.commons.lang3.StringUtils; | ||
| 7 | import org.springframework.util.Assert; | ||
| 8 | |||
| 9 | import java.util.Objects; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/14 14:36 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/14 14:36 | ||
| 19 | */ | ||
| 20 | public class UserTvBuilder { | ||
| 21 | |||
| 22 | private static final Integer DEFAULT_VALUE = 1; | ||
| 23 | private static final String DEFAULT_CREATE_BY = "system"; | ||
| 24 | private static final String DEFAULT_UPDATE_BY = "system"; | ||
| 25 | |||
| 26 | public static UserTv build(UserTv userTv){ | ||
| 27 | return build(userTv.getMemberId(),userTv.getMemberCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
| 28 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId()); | ||
| 29 | } | ||
| 30 | |||
| 31 | public static UserTv build(Long memberId, String memberCode , UserTv userTv){ | ||
| 32 | return build(memberId,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
| 33 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId()); | ||
| 34 | } | ||
| 35 | |||
| 36 | public static UserTv build(String memberCode, UserTv userTv){ | ||
| 37 | return build(null,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
| 38 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId()); | ||
| 39 | } | ||
| 40 | |||
| 41 | public static UserTv build(Member member, UserTv userTv){ | ||
| 42 | return build(member.getId() , member.getCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), | ||
| 43 | userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId()); | ||
| 44 | } | ||
| 45 | |||
| 46 | public static UserTv build(Long memberId , String memberCode , Long id , String platformAccount , String nickname , String username, | ||
| 47 | Integer loginDays , Integer status ,Integer continueDays , String createBy , String updateBy,Long visUserId){ | ||
| 48 | Assert.notNull(memberId, GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 49 | Assert.notNull(memberCode, GlobeExceptionMsg.MEMBER_CODE_IS_NULL); | ||
| 50 | Assert.notNull(platformAccount, GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL); | ||
| 51 | Assert.notNull(platformAccount, GlobeExceptionMsg.VIS_USER_ID_IS_NULL); | ||
| 52 | |||
| 53 | // todo 原型模式 | ||
| 54 | UserTv userTv = new UserTv(); | ||
| 55 | userTv.setId(id); | ||
| 56 | userTv.setPlatformAccount(platformAccount); | ||
| 57 | userTv.setMemberCode(memberCode); | ||
| 58 | userTv.setMemberId(memberId); | ||
| 59 | userTv.setNickname(StringUtils.isBlank(nickname)?platformAccount:nickname); | ||
| 60 | userTv.setUsername(StringUtils.isBlank(username)?platformAccount:username); | ||
| 61 | userTv.setLoginDays(Objects.nonNull(loginDays)?loginDays:DEFAULT_VALUE); | ||
| 62 | userTv.setLoginType(DEFAULT_VALUE); | ||
| 63 | userTv.setStatus(Objects.nonNull(status)?status:DEFAULT_VALUE); | ||
| 64 | userTv.setActiveTime(TimestampUtil.now()); | ||
| 65 | userTv.setContinueDays(Objects.nonNull(continueDays)?loginDays:DEFAULT_VALUE); | ||
| 66 | userTv.setCreateBy(StringUtils.isBlank(createBy)?DEFAULT_CREATE_BY:createBy); | ||
| 67 | userTv.setUpdateBy(StringUtils.isBlank(updateBy)?DEFAULT_UPDATE_BY:updateBy); | ||
| 68 | userTv.setVisUserId(visUserId); | ||
| 69 | return userTv; | ||
| 70 | } | ||
| 71 | |||
| 72 | } |
| ... | @@ -13,4 +13,9 @@ import java.util.Optional; | ... | @@ -13,4 +13,9 @@ import java.util.Optional; |
| 13 | public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecificationExecutor<UserTv> { | 13 | public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecificationExecutor<UserTv> { |
| 14 | 14 | ||
| 15 | Optional<UserTv> findByPlatformAccount(String platformAccount); | 15 | Optional<UserTv> findByPlatformAccount(String platformAccount); |
| 16 | |||
| 17 | Optional<UserTv> findByPriorityMemberCode(String memberCode); | ||
| 18 | |||
| 19 | Optional<UserTv> findByMemberId(Long memberId); | ||
| 20 | |||
| 16 | } | 21 | } | ... | ... |
| 1 | package com.topdraw.business.module.user.iptv.service; | 1 | package com.topdraw.business.module.user.iptv.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 3 | import com.topdraw.business.module.user.iptv.domain.UserTv; | 4 | import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 4 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 5 | import com.topdraw.business.module.user.iptv.service.dto.UserTvQueryCriteria; | 6 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | import org.springframework.transaction.annotation.Transactional; | ||
| 8 | |||
| 9 | import java.util.List; | ||
| 10 | import java.util.Map; | ||
| 11 | 7 | ||
| 12 | /** | 8 | /** |
| 13 | * @author XiangHan | 9 | * @author XiangHan |
| ... | @@ -16,35 +12,72 @@ import java.util.Map; | ... | @@ -16,35 +12,72 @@ import java.util.Map; |
| 16 | public interface UserTvService { | 12 | public interface UserTvService { |
| 17 | 13 | ||
| 18 | /** | 14 | /** |
| 19 | * 查询数据分页 | ||
| 20 | * @param criteria 条件参数 | ||
| 21 | * @param pageable 分页参数 | ||
| 22 | * @return Map<String,Object> | ||
| 23 | */ | ||
| 24 | Map<String,Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable); | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 查询所有数据不分页 | ||
| 28 | * @param criteria 条件参数 | ||
| 29 | * @return List<UserTvDTO> | ||
| 30 | */ | ||
| 31 | List<UserTvDTO> queryAll(UserTvQueryCriteria criteria); | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 根据ID查询 | 15 | * 根据ID查询 |
| 35 | * @param id ID | 16 | * @param id ID |
| 36 | * @return UserTvDTO | 17 | * @return UserTvDTO |
| 37 | */ | 18 | */ |
| 38 | UserTvDTO findById(Long id); | 19 | UserTvDTO findById(Long id); |
| 39 | 20 | ||
| 40 | Long create(UserTv resources); | 21 | /** |
| 22 | * | ||
| 23 | * @param resources | ||
| 24 | * @return | ||
| 25 | */ | ||
| 26 | UserTvDTO create(UserTv resources); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * | ||
| 30 | * @param resources | ||
| 31 | */ | ||
| 32 | UserTvDTO update(UserTv resources); | ||
| 41 | 33 | ||
| 42 | void update(UserTv resources); | ||
| 43 | 34 | ||
| 44 | @Transactional(rollbackFor = Exception.class) | 35 | /** |
| 36 | * | ||
| 37 | * @param resources | ||
| 38 | */ | ||
| 45 | void unbindPriorityMemberCode(UserTv resources); | 39 | void unbindPriorityMemberCode(UserTv resources); |
| 46 | 40 | ||
| 41 | /** | ||
| 42 | * | ||
| 43 | * @param id | ||
| 44 | */ | ||
| 47 | void delete(Long id); | 45 | void delete(Long id); |
| 48 | 46 | ||
| 47 | /** | ||
| 48 | * | ||
| 49 | * @param platformAccount | ||
| 50 | * @return | ||
| 51 | */ | ||
| 49 | UserTvDTO findByPlatformAccount(String platformAccount); | 52 | UserTvDTO findByPlatformAccount(String platformAccount); |
| 53 | |||
| 54 | /** | ||
| 55 | * | ||
| 56 | * @param memberCode | ||
| 57 | * @return | ||
| 58 | */ | ||
| 59 | UserTvDTO findByPriorityMemberCode(String memberCode); | ||
| 60 | |||
| 61 | /** | ||
| 62 | * 通过会员 | ||
| 63 | * @param memberId | ||
| 64 | * @return | ||
| 65 | */ | ||
| 66 | UserTvDTO findByMemberId(Long memberId); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * 检查会员是否是主账号 | ||
| 70 | * @param memberId | ||
| 71 | * @param memberCode | ||
| 72 | * @return | ||
| 73 | */ | ||
| 74 | boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode); | ||
| 75 | |||
| 76 | /** | ||
| 77 | * | ||
| 78 | * @param platformAccount | ||
| 79 | * @return | ||
| 80 | */ | ||
| 81 | MemberDTO findMemberByPlatformAccount(String platformAccount); | ||
| 82 | |||
| 50 | } | 83 | } | ... | ... |
| ... | @@ -4,7 +4,6 @@ import lombok.Data; | ... | @@ -4,7 +4,6 @@ import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 6 | import java.sql.Timestamp; |
| 7 | import java.time.LocalDateTime; | ||
| 8 | 7 | ||
| 9 | 8 | ||
| 10 | /** | 9 | /** |
| ... | @@ -16,70 +15,75 @@ public class UserTvDTO implements Serializable { | ... | @@ -16,70 +15,75 @@ public class UserTvDTO implements Serializable { |
| 16 | 15 | ||
| 17 | private Long visUserId; | 16 | private Long visUserId; |
| 18 | 17 | ||
| 19 | // ID | 18 | private String memberCode; |
| 19 | |||
| 20 | /** 绑定的小屏账户会员编码 */ | ||
| 21 | private String priorityMemberCode; | ||
| 22 | |||
| 23 | /** ID */ | ||
| 20 | private Long id; | 24 | private Long id; |
| 21 | 25 | ||
| 22 | // 人ID | 26 | /** 人ID */ |
| 23 | private Long personId; | 27 | private Long personId; |
| 24 | 28 | ||
| 25 | // 运营商平台 | 29 | /** 运营商平台 */ |
| 26 | private String platform; | 30 | private String platform; |
| 27 | 31 | ||
| 28 | // 运营商平台账号 | 32 | /** 运营商平台账号 */ |
| 29 | private String platformAccount; | 33 | private String platformAccount; |
| 30 | 34 | ||
| 31 | // 手机号 | 35 | /** 手机号 */ |
| 32 | private String cellphone; | 36 | private String cellphone; |
| 33 | 37 | ||
| 34 | // 用户名 | 38 | /** 用户名 */ |
| 35 | private String username; | 39 | private String username; |
| 36 | 40 | ||
| 37 | // 密码 MD5 | 41 | /** 密码 MD5 */ |
| 38 | private String password; | 42 | private String password; |
| 39 | 43 | ||
| 40 | // 昵称 Base64 | 44 | /** 昵称 Base64 */ |
| 41 | private String nickname; | 45 | private String nickname; |
| 42 | 46 | ||
| 43 | // 头像 | 47 | /** 头像 */ |
| 44 | private String image; | 48 | private String image; |
| 45 | 49 | ||
| 46 | // 登录天数(总天数) | 50 | /** 登录天数(总天数) */ |
| 47 | private Integer loginDays; | 51 | private Integer loginDays; |
| 48 | 52 | ||
| 49 | // 连续登录天数 | 53 | /** 连续登录天数 */ |
| 50 | private Integer continueDays; | 54 | private Integer continueDays; |
| 51 | 55 | ||
| 52 | // 活跃时间 | 56 | /** 活跃时间 */ |
| 53 | private LocalDateTime activeTime; | 57 | private Timestamp activeTime; |
| 54 | 58 | ||
| 55 | // 分组 分组ID用逗号分隔 | 59 | /** 分组 分组ID用逗号分隔 */ |
| 56 | private String groups; | 60 | private String groups; |
| 57 | 61 | ||
| 58 | // 标签 标签用逗号分隔 | 62 | /** 标签 标签用逗号分隔 */ |
| 59 | private String tags; | 63 | private String tags; |
| 60 | 64 | ||
| 61 | // 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 | 65 | /** 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 */ |
| 62 | private Integer loginType; | 66 | private Integer loginType; |
| 63 | 67 | ||
| 64 | // 状态 0-下线 1-上线 | 68 | /** 状态 0-下线 1-上线 */ |
| 65 | private Integer status; | 69 | private Integer status; |
| 66 | 70 | ||
| 67 | // 描述 | 71 | /** 描述 */ |
| 68 | private String description; | 72 | private String description; |
| 69 | 73 | ||
| 70 | // 创建者 | 74 | /** 创建者 */ |
| 71 | private String createBy; | 75 | private String createBy; |
| 72 | 76 | ||
| 73 | // 创建时间 | 77 | /** 创建时间 */ |
| 74 | private LocalDateTime createTime; | 78 | private Timestamp createTime; |
| 75 | 79 | ||
| 76 | // 更新者 | 80 | /** 更新者 */ |
| 77 | private String updateBy; | 81 | private String updateBy; |
| 78 | 82 | ||
| 79 | // 更新时间 | 83 | /** 更新时间 */ |
| 80 | private LocalDateTime updateTime; | 84 | private Timestamp updateTime; |
| 81 | 85 | ||
| 82 | // 会员id | 86 | /** 会员id */ |
| 83 | private Long memberId; | 87 | private Long memberId; |
| 84 | } | 88 | } |
| 85 | 89 | ... | ... |
| ... | @@ -6,24 +6,20 @@ import com.topdraw.business.module.user.iptv.domain.UserTv; | ... | @@ -6,24 +6,20 @@ import com.topdraw.business.module.user.iptv.domain.UserTv; |
| 6 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; | 6 | import com.topdraw.business.module.user.iptv.repository.UserTvRepository; |
| 7 | import com.topdraw.business.module.user.iptv.service.UserTvService; | 7 | import com.topdraw.business.module.user.iptv.service.UserTvService; |
| 8 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | 8 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; |
| 9 | import com.topdraw.business.module.user.iptv.service.dto.UserTvQueryCriteria; | ||
| 10 | import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; | 9 | import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; |
| 11 | import com.topdraw.utils.PageUtil; | 10 | import com.topdraw.exception.EntityNotFoundException; |
| 12 | import com.topdraw.utils.QueryHelp; | 11 | import com.topdraw.exception.GlobeExceptionMsg; |
| 13 | import com.topdraw.utils.ValidationUtil; | 12 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.apache.commons.lang3.StringUtils; | ||
| 14 | import org.springframework.beans.BeanUtils; | 14 | import org.springframework.beans.BeanUtils; |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.dao.EmptyResultDataAccessException; | 16 | import org.springframework.dao.EmptyResultDataAccessException; |
| 17 | import org.springframework.data.domain.Page; | ||
| 18 | import org.springframework.data.domain.Pageable; | ||
| 19 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.annotation.Propagation; | 18 | import org.springframework.transaction.annotation.Propagation; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.util.Assert; | 20 | import org.springframework.util.Assert; |
| 23 | 21 | ||
| 24 | import java.time.LocalDateTime; | 22 | import javax.validation.constraints.NotNull; |
| 25 | import java.util.List; | ||
| 26 | import java.util.Map; | ||
| 27 | import java.util.Objects; | 23 | import java.util.Objects; |
| 28 | import java.util.Optional; | 24 | import java.util.Optional; |
| 29 | 25 | ||
| ... | @@ -35,95 +31,159 @@ import java.util.Optional; | ... | @@ -35,95 +31,159 @@ import java.util.Optional; |
| 35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 31 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 36 | public class UserTvServiceImpl implements UserTvService { | 32 | public class UserTvServiceImpl implements UserTvService { |
| 37 | 33 | ||
| 38 | @Autowired | ||
| 39 | private UserTvRepository UserTvRepository; | ||
| 40 | 34 | ||
| 41 | @Autowired | 35 | @Autowired |
| 42 | private UserTvMapper UserTvMapper; | 36 | private UserTvMapper userTvMapper; |
| 43 | @Autowired | 37 | @Autowired |
| 44 | private MemberService memberService; | 38 | private MemberService memberService; |
| 45 | 39 | @Autowired | |
| 40 | private UserTvRepository userTvRepository; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * 获取大屏账户对应的会员 | ||
| 44 | * <Waring> | ||
| 45 | * 如果绑定了小屏,则获取对应主账号对应的会员信息,如果没有绑定小屏会员则默认获取大屏自己的会员(x_member) | ||
| 46 | * </Waring> | ||
| 47 | * @param platformAccount | ||
| 48 | * @return | ||
| 49 | */ | ||
| 46 | @Override | 50 | @Override |
| 47 | public Map<String, Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable) { | 51 | public MemberDTO findMemberByPlatformAccount(String platformAccount){ |
| 48 | Page<UserTv> page = UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 52 | // 大屏账户 |
| 49 | return PageUtil.toPage(page.map(UserTvMapper::toDto)); | 53 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); |
| 54 | |||
| 55 | if (Objects.nonNull(userTvDTO)) { | ||
| 56 | |||
| 57 | // 主账号会员code | ||
| 58 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
| 59 | if (StringUtils.isNotBlank(priorityMemberCode)) | ||
| 60 | return this.findMemberByMemberCode(priorityMemberCode); | ||
| 61 | else | ||
| 62 | return this.findMemberByMemberId(userTvDTO.getMemberId()); | ||
| 63 | |||
| 64 | } | ||
| 65 | |||
| 66 | throw new EntityNotFoundException(UserTvDTO.class,"platformAccount", GlobeExceptionMsg.IPTV_IS_NULL); | ||
| 50 | } | 67 | } |
| 51 | 68 | ||
| 52 | @Override | 69 | private MemberDTO findMemberByMemberCode(String memberCode) { |
| 53 | public List<UserTvDTO> queryAll(UserTvQueryCriteria criteria) { | 70 | return this.memberService.findByCode(memberCode); |
| 54 | return UserTvMapper.toDto(UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 71 | } |
| 72 | |||
| 73 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
| 74 | return this.memberService.findById(memberId); | ||
| 55 | } | 75 | } |
| 56 | 76 | ||
| 57 | @Override | 77 | @Override |
| 58 | public UserTvDTO findById(Long id) { | 78 | public UserTvDTO findById(Long id) { |
| 59 | UserTv UserTv = UserTvRepository.findById(id).orElseGet(UserTv::new); | 79 | UserTv UserTv = this.userTvRepository.findById(id).orElseGet(com.topdraw.business.module.user.iptv.domain.UserTv::new); |
| 60 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); | 80 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); |
| 61 | return UserTvMapper.toDto(UserTv); | 81 | return this.userTvMapper.toDto(UserTv); |
| 62 | } | 82 | } |
| 63 | 83 | ||
| 64 | @Override | 84 | @Override |
| 65 | @Transactional(rollbackFor = Exception.class) | 85 | @Transactional(rollbackFor = Exception.class) |
| 66 | public Long create(UserTv resources) { | 86 | public UserTvDTO create(UserTv resources) { |
| 67 | MemberDTO memberDTO = memberService.getByCode(resources.getMemberCode()); | 87 | MemberDTO memberDTO = memberService.findByCode(resources.getMemberCode()); |
| 68 | if (Objects.nonNull(memberDTO)) { | 88 | if (Objects.nonNull(memberDTO)) { |
| 69 | Long id = memberDTO.getId(); | 89 | Long id = memberDTO.getId(); |
| 70 | resources.setMemberId(id); | 90 | resources.setMemberId(id); |
| 71 | UserTvRepository.save(resources); | 91 | UserTv userTv = this.userTvRepository.save(resources); |
| 72 | return resources.getId(); | 92 | return this.userTvMapper.toDto(userTv); |
| 73 | } | 93 | } |
| 74 | return null; | 94 | return null; |
| 75 | } | 95 | } |
| 76 | 96 | ||
| 77 | @Override | 97 | @Override |
| 78 | @Transactional(rollbackFor = Exception.class) | 98 | @Transactional(rollbackFor = Exception.class) |
| 79 | public void update(UserTv resources) { | 99 | public UserTvDTO update(UserTv resources) { |
| 80 | |||
| 81 | String platformAccount = resources.getPlatformAccount(); | 100 | String platformAccount = resources.getPlatformAccount(); |
| 82 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); | 101 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); |
| 83 | ValidationUtil.isNull(userTvDTO.getId(),"UserTv","id",resources.getId()); | ||
| 84 | 102 | ||
| 85 | UserTv userTv = new UserTv(); | 103 | UserTv userTv = new UserTv(); |
| 86 | BeanUtils.copyProperties(resources,userTv); | 104 | BeanUtils.copyProperties(userTvDTO, userTv); |
| 87 | 105 | ||
| 88 | userTv.setId(userTvDTO.getId()); | 106 | userTv.setId(userTvDTO.getId()); |
| 107 | userTv.setPlatformAccount(userTvDTO.getPlatformAccount()); | ||
| 89 | userTv.setMemberId(userTvDTO.getMemberId()); | 108 | userTv.setMemberId(userTvDTO.getMemberId()); |
| 90 | userTv.setUpdateTime(LocalDateTime.now()); | ||
| 91 | UserTvRepository.save(userTv); | ||
| 92 | } | ||
| 93 | 109 | ||
| 110 | String priorityMemberCode = resources.getPriorityMemberCode(); | ||
| 111 | if (StringUtils.isNotBlank(priorityMemberCode)){ | ||
| 112 | userTv.setPriorityMemberCode(priorityMemberCode); | ||
| 113 | } else { | ||
| 114 | userTv.setPriorityMemberCode(userTvDTO.getPriorityMemberCode()); | ||
| 115 | } | ||
| 116 | |||
| 117 | UserTv _userTv = this.userTvRepository.save(userTv); | ||
| 118 | return this.userTvMapper.toDto(_userTv); | ||
| 119 | } | ||
| 94 | 120 | ||
| 95 | @Override | 121 | @Override |
| 96 | @Transactional(rollbackFor = Exception.class) | 122 | @Transactional(rollbackFor = Exception.class) |
| 97 | public void unbindPriorityMemberCode(UserTv resources) { | 123 | public void unbindPriorityMemberCode(UserTv resources) { |
| 98 | String platformAccount = resources.getPlatformAccount(); | 124 | String platformAccount = resources.getPlatformAccount(); |
| 99 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); | 125 | if (StringUtils.isNotBlank(platformAccount)) { |
| 100 | // UserTv UserTv = UserTvRepository.findById(resources.getId()).orElseGet(UserTv::new); | 126 | UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); |
| 101 | ValidationUtil.isNull( userTvDTO.getId(),"UserTv","id",resources.getId()); | 127 | Long id = userTvDTO.getId(); |
| 102 | //UserTv.copy(resources); | 128 | resources.setId(id); |
| 103 | UserTv userTv = new UserTv(); | 129 | resources.setMemberId(userTvDTO.getMemberId()); |
| 104 | BeanUtils.copyProperties(userTvDTO,userTv); | 130 | } |
| 105 | userTv.setPriorityMemberCode(null); | 131 | this.userTvRepository.save(resources); |
| 106 | UserTvRepository.save(userTv); | ||
| 107 | } | 132 | } |
| 108 | 133 | ||
| 109 | @Override | 134 | @Override |
| 110 | @Transactional(rollbackFor = Exception.class) | 135 | @Transactional(rollbackFor = Exception.class) |
| 111 | public void delete(Long id) { | 136 | public void delete(Long id) { |
| 112 | Assert.notNull(id, "The given id must not be null!"); | 137 | Assert.notNull(id, "The given id must not be null!"); |
| 113 | UserTv UserTv = UserTvRepository.findById(id).orElseThrow( | 138 | UserTv UserTv = this.userTvRepository.findById(id).orElseThrow( |
| 114 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserTv.class, id), 1)); | 139 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.user.iptv.domain.UserTv.class, id), 1)); |
| 115 | UserTvRepository.delete(UserTv); | 140 | this.userTvRepository.delete(UserTv); |
| 116 | } | 141 | } |
| 117 | 142 | ||
| 118 | @Override | 143 | @Override |
| 119 | public UserTvDTO findByPlatformAccount(String platformAccount) { | 144 | public UserTvDTO findByPlatformAccount(String platformAccount) { |
| 120 | Optional<UserTv> userTv = UserTvRepository.findByPlatformAccount(platformAccount); | 145 | Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount); |
| 121 | if (userTv.isPresent()) { | 146 | if (userTv.isPresent()) { |
| 122 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | 147 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); |
| 123 | return UserTvMapper.toDto(userTv.get()); | 148 | return this.userTvMapper.toDto(userTv.get()); |
| 124 | } | 149 | } |
| 125 | return null; | 150 | return null; |
| 126 | } | 151 | } |
| 127 | 152 | ||
| 153 | @Override | ||
| 154 | public UserTvDTO findByPriorityMemberCode(String memberCode) { | ||
| 155 | Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode); | ||
| 156 | if (userTv.isPresent()) { | ||
| 157 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | ||
| 158 | return this.userTvMapper.toDto(userTv.get()); | ||
| 159 | } | ||
| 160 | return null; | ||
| 161 | } | ||
| 162 | |||
| 163 | @Override | ||
| 164 | public UserTvDTO findByMemberId(Long memberId) { | ||
| 165 | Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId); | ||
| 166 | if (userTv.isPresent()) { | ||
| 167 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | ||
| 168 | return this.userTvMapper.toDto(userTv.get()); | ||
| 169 | } | ||
| 170 | return null; | ||
| 171 | } | ||
| 172 | |||
| 173 | @Override | ||
| 174 | public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) { | ||
| 175 | // 检查会员是否存在 | ||
| 176 | this.checkMember(memberId, memberCode); | ||
| 177 | |||
| 178 | UserTvDTO userTvDTO = this.findByPriorityMemberCode(memberCode); | ||
| 179 | if (Objects.nonNull(userTvDTO)) { | ||
| 180 | return true; | ||
| 181 | } | ||
| 182 | return false; | ||
| 183 | } | ||
| 184 | |||
| 185 | private void checkMember(Long memberId, String memberCode){ | ||
| 186 | this.memberService.checkMember(memberId, memberCode); | ||
| 187 | } | ||
| 128 | 188 | ||
| 129 | } | 189 | } | ... | ... |
| ... | @@ -23,38 +23,38 @@ import java.sql.Timestamp; | ... | @@ -23,38 +23,38 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_user_collection") | 23 | @Table(name="uc_user_collection") |
| 24 | public class UserCollection implements Serializable { | 24 | public class UserCollection implements Serializable { |
| 25 | 25 | ||
| 26 | // ID | 26 | /** ID */ |
| 27 | @Id | 27 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 29 | @Column(name = "id") | 29 | @Column(name = "id") |
| 30 | private Long id; | 30 | private Long id; |
| 31 | 31 | ||
| 32 | // 应用ID | 32 | /** 应用ID */ |
| 33 | @Column(name = "app_id") | 33 | @Column(name = "app_id") |
| 34 | private Long appId; | 34 | private Long appId; |
| 35 | 35 | ||
| 36 | // 用户ID | 36 | /** 用户ID */ |
| 37 | @Column(name = "user_id") | 37 | @Column(name = "user_id") |
| 38 | private Long userId; | 38 | private Long userId; |
| 39 | 39 | ||
| 40 | // 收藏夹类型:1-收藏 2-播放记录 3-播放列表 4-评分 5-点赞/关注/订阅 | 40 | /** 收藏夹类型:1-收藏 2-播放记录 3-播放列表 4-评分 5-点赞/关注/订阅 */ |
| 41 | @Column(name = "type") | 41 | @Column(name = "type") |
| 42 | private Integer type; | 42 | private Integer type; |
| 43 | 43 | ||
| 44 | // 收藏夹名称 | 44 | /** 收藏夹名称 */ |
| 45 | @Column(name = "name") | 45 | @Column(name = "name") |
| 46 | private String name; | 46 | private String name; |
| 47 | 47 | ||
| 48 | // 数量 | 48 | /** 数量 */ |
| 49 | @Column(name = "count") | 49 | @Column(name = "count") |
| 50 | private Integer count; | 50 | private Integer count; |
| 51 | 51 | ||
| 52 | // 创建时间 | 52 | /** 创建时间 */ |
| 53 | @CreatedDate | 53 | @CreatedDate |
| 54 | @Column(name = "create_time") | 54 | @Column(name = "create_time") |
| 55 | private Timestamp createTime; | 55 | private Timestamp createTime; |
| 56 | 56 | ||
| 57 | // 更新时间 | 57 | /** 更新时间 */ |
| 58 | @LastModifiedDate | 58 | @LastModifiedDate |
| 59 | @Column(name = "update_time") | 59 | @Column(name = "update_time") |
| 60 | private Timestamp updateTime; | 60 | private Timestamp updateTime; | ... | ... |
| ... | @@ -25,89 +25,89 @@ public class UserCollectionDetail implements Serializable { | ... | @@ -25,89 +25,89 @@ public class UserCollectionDetail implements Serializable { |
| 25 | @JoinColumn(name = "user_collection_id", insertable = false, updatable = false) | 25 | @JoinColumn(name = "user_collection_id", insertable = false, updatable = false) |
| 26 | private UserCollection userCollection; | 26 | private UserCollection userCollection; |
| 27 | 27 | ||
| 28 | // ID | 28 | /** ID */ |
| 29 | @Id | 29 | @Id |
| 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 31 | @Column(name = "id") | 31 | @Column(name = "id") |
| 32 | private Long id; | 32 | private Long id; |
| 33 | 33 | ||
| 34 | // 收藏夹ID | 34 | /** 收藏夹ID */ |
| 35 | @Column(name = "user_collection_id") | 35 | @Column(name = "user_collection_id") |
| 36 | private Long userCollectionId; | 36 | private Long userCollectionId; |
| 37 | 37 | ||
| 38 | // 自定义收藏内容的类型CODE,默认:DEFAULT | 38 | /** 自定义收藏内容的类型CODE,默认:DEFAULT */ |
| 39 | @Column(name = "detail_folder_code") | 39 | @Column(name = "detail_folder_code") |
| 40 | private String detailFolderCode; | 40 | private String detailFolderCode; |
| 41 | 41 | ||
| 42 | // 收藏内容的类型:MEDIA|EPISODE|CATEGORY|SUBJECT|ARTICLE|ARTIST|SCHOOL | 42 | /** 收藏内容的类型:MEDIA|EPISODE|CATEGORY|SUBJECT|ARTICLE|ARTIST|SCHOOL */ |
| 43 | @Column(name = "detail_type") | 43 | @Column(name = "detail_type") |
| 44 | private String detailType; | 44 | private String detailType; |
| 45 | 45 | ||
| 46 | // 收藏内容的ID | 46 | /** 收藏内容的ID */ |
| 47 | @Column(name = "detail_id") | 47 | @Column(name = "detail_id") |
| 48 | private Long detailId; | 48 | private Long detailId; |
| 49 | 49 | ||
| 50 | // 收藏内容的CODE | 50 | /** 收藏内容的CODE */ |
| 51 | @Column(name = "detail_code") | 51 | @Column(name = "detail_code") |
| 52 | private String detailCode; | 52 | private String detailCode; |
| 53 | 53 | ||
| 54 | // 收藏内容的剧集ID | 54 | /** 收藏内容的剧集ID */ |
| 55 | @Column(name = "detail_episode_id") | 55 | @Column(name = "detail_episode_id") |
| 56 | private Long detailEpisodeId; | 56 | private Long detailEpisodeId; |
| 57 | 57 | ||
| 58 | // 收藏内容的剧集CODE | 58 | /** 收藏内容的剧集CODE */ |
| 59 | @Column(name = "detail_episode_code") | 59 | @Column(name = "detail_episode_code") |
| 60 | private String detailEpisodeCode; | 60 | private String detailEpisodeCode; |
| 61 | 61 | ||
| 62 | // 收藏内容的名称 | 62 | /** 收藏内容的名称 */ |
| 63 | @Column(name = "detail_name") | 63 | @Column(name = "detail_name") |
| 64 | private String detailName; | 64 | private String detailName; |
| 65 | 65 | ||
| 66 | // 收藏内容的标记 | 66 | /** 收藏内容的标记 */ |
| 67 | @Column(name = "detail_mark") | 67 | @Column(name = "detail_mark") |
| 68 | private Integer detailMark; | 68 | private Integer detailMark; |
| 69 | 69 | ||
| 70 | // 收藏内容的图片 | 70 | /** 收藏内容的图片 */ |
| 71 | @Column(name = "detail_img") | 71 | @Column(name = "detail_img") |
| 72 | private String detailImg; | 72 | private String detailImg; |
| 73 | 73 | ||
| 74 | // 收藏内容的剧集序号 | 74 | /** 收藏内容的剧集序号 */ |
| 75 | @Column(name = "detail_index") | 75 | @Column(name = "detail_index") |
| 76 | private Integer detailIndex; | 76 | private Integer detailIndex; |
| 77 | 77 | ||
| 78 | // 收藏内容的剧集总数 | 78 | /** 收藏内容的剧集总数 */ |
| 79 | @Column(name = "detail_total_index") | 79 | @Column(name = "detail_total_index") |
| 80 | private Integer detailTotalIndex; | 80 | private Integer detailTotalIndex; |
| 81 | 81 | ||
| 82 | // 收藏内容的播放时间 | 82 | /** 收藏内容的播放时间 */ |
| 83 | @Column(name = "detail_play_time") | 83 | @Column(name = "detail_play_time") |
| 84 | private Integer detailPlayTime; | 84 | private Integer detailPlayTime; |
| 85 | 85 | ||
| 86 | // 收藏内容的总时间 | 86 | /** 收藏内容的总时间 */ |
| 87 | @Column(name = "detail_total_time") | 87 | @Column(name = "detail_total_time") |
| 88 | private Integer detailTotalTime; | 88 | private Integer detailTotalTime; |
| 89 | 89 | ||
| 90 | // 收藏内容在同一folder中的顺序 | 90 | /** 收藏内容在同一folder中的顺序 */ |
| 91 | @Column(name = "detail_sequence") | 91 | @Column(name = "detail_sequence") |
| 92 | private Integer detailSequence; | 92 | private Integer detailSequence; |
| 93 | 93 | ||
| 94 | // 收藏内容的评分 | 94 | /** 收藏内容的评分 */ |
| 95 | @Column(name = "detail_score") | 95 | @Column(name = "detail_score") |
| 96 | private Float detailScore; | 96 | private Float detailScore; |
| 97 | 97 | ||
| 98 | // 收藏内容(根据文件夹和类型的不同)的点赞/关注/订阅 | 98 | /** 收藏内容(根据文件夹和类型的不同)的点赞/关注/订阅 */ |
| 99 | @Column(name = "detail_like") | 99 | @Column(name = "detail_like") |
| 100 | private Integer detailLike; | 100 | private Integer detailLike; |
| 101 | 101 | ||
| 102 | // 收藏内容的扩展数据 | 102 | /** 收藏内容的扩展数据 */ |
| 103 | @Column(name = "detail_ext_data") | 103 | @Column(name = "detail_ext_data") |
| 104 | private String detailExtData; | 104 | private String detailExtData; |
| 105 | 105 | ||
| 106 | // 创建时间 | 106 | /** 创建时间 */ |
| 107 | @Column(name = "create_time") | 107 | @Column(name = "create_time") |
| 108 | private Timestamp createTime; | 108 | private Timestamp createTime; |
| 109 | 109 | ||
| 110 | // 更新时间 | 110 | /** 更新时间 */ |
| 111 | @Column(name = "update_time") | 111 | @Column(name = "update_time") |
| 112 | private Timestamp updateTime; | 112 | private Timestamp updateTime; |
| 113 | 113 | ... | ... |
| ... | @@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; | ... | @@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; |
| 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 7 | 7 | ||
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | import java.util.Optional; | ||
| 10 | 9 | ||
| 11 | /** | 10 | /** |
| 12 | * @author pengmengqing | 11 | * @author pengmengqing |
| ... | @@ -14,8 +13,6 @@ import java.util.Optional; | ... | @@ -14,8 +13,6 @@ import java.util.Optional; |
| 14 | */ | 13 | */ |
| 15 | public interface UserCollectionRepository extends JpaRepository<UserCollection, Long>, JpaSpecificationExecutor<UserCollection> { | 14 | public interface UserCollectionRepository extends JpaRepository<UserCollection, Long>, JpaSpecificationExecutor<UserCollection> { |
| 16 | 15 | ||
| 17 | Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long userId, Integer type, String name); | ||
| 18 | |||
| 19 | List<UserCollection> findByUserIdAndType(Long userId, Integer type); | 16 | List<UserCollection> findByUserIdAndType(Long userId, Integer type); |
| 20 | 17 | ||
| 21 | } | 18 | } | ... | ... |
| ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.user.weixin.collection.service; | ... | @@ -2,11 +2,8 @@ package com.topdraw.business.module.user.weixin.collection.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail; | 3 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail; |
| 4 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailDTO; | 4 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailDTO; |
| 5 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import java.util.List; | 6 | import java.util.List; |
| 9 | import java.util.Map; | ||
| 10 | 7 | ||
| 11 | /** | 8 | /** |
| 12 | * @author pengmengqing | 9 | * @author pengmengqing |
| ... | @@ -15,27 +12,40 @@ import java.util.Map; | ... | @@ -15,27 +12,40 @@ import java.util.Map; |
| 15 | public interface UserCollectionDetailService { | 12 | public interface UserCollectionDetailService { |
| 16 | 13 | ||
| 17 | /** | 14 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(UserCollectionDetailQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 根据ID查询 | 15 | * 根据ID查询 |
| 27 | * @param id ID | 16 | * @param id ID |
| 28 | * @return UserCollectionDetailDTO | 17 | * @return UserCollectionDetailDTO |
| 29 | */ | 18 | */ |
| 30 | UserCollectionDetailDTO findById(Long id); | 19 | UserCollectionDetailDTO findById(Long id); |
| 31 | 20 | ||
| 21 | /** | ||
| 22 | * | ||
| 23 | * @param resources | ||
| 24 | * @return | ||
| 25 | */ | ||
| 32 | UserCollectionDetailDTO create(UserCollectionDetail resources); | 26 | UserCollectionDetailDTO create(UserCollectionDetail resources); |
| 33 | 27 | ||
| 28 | /** | ||
| 29 | * | ||
| 30 | * @param resources | ||
| 31 | */ | ||
| 34 | void update(UserCollectionDetail resources); | 32 | void update(UserCollectionDetail resources); |
| 35 | 33 | ||
| 34 | /** | ||
| 35 | * | ||
| 36 | * @param id | ||
| 37 | */ | ||
| 36 | void delete(Long id); | 38 | void delete(Long id); |
| 37 | 39 | ||
| 40 | /** | ||
| 41 | * | ||
| 42 | * @param id | ||
| 43 | */ | ||
| 38 | void deleteAllByUserCollectionId(Long id); | 44 | void deleteAllByUserCollectionId(Long id); |
| 39 | 45 | ||
| 46 | /** | ||
| 47 | * | ||
| 48 | * @param userCollectionDetailOptional | ||
| 49 | */ | ||
| 40 | void deleteAll(List<UserCollectionDetail> userCollectionDetailOptional); | 50 | void deleteAll(List<UserCollectionDetail> userCollectionDetailOptional); |
| 41 | } | 51 | } | ... | ... |
| ... | @@ -2,13 +2,10 @@ package com.topdraw.business.module.user.weixin.collection.service; | ... | @@ -2,13 +2,10 @@ package com.topdraw.business.module.user.weixin.collection.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; | 3 | import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; |
| 4 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDTO; | 4 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDTO; |
| 5 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | 5 | ||
| 8 | import javax.servlet.http.HttpServletResponse; | 6 | import javax.servlet.http.HttpServletResponse; |
| 9 | import java.io.IOException; | 7 | import java.io.IOException; |
| 10 | import java.util.List; | 8 | import java.util.List; |
| 11 | import java.util.Map; | ||
| 12 | import java.util.Optional; | 9 | import java.util.Optional; |
| 13 | 10 | ||
| 14 | /** | 11 | /** |
| ... | @@ -18,38 +15,60 @@ import java.util.Optional; | ... | @@ -18,38 +15,60 @@ import java.util.Optional; |
| 18 | public interface UserCollectionService { | 15 | public interface UserCollectionService { |
| 19 | 16 | ||
| 20 | /** | 17 | /** |
| 21 | * 查询数据分页 | ||
| 22 | * @param criteria 条件参数 | ||
| 23 | * @param pageable 分页参数 | ||
| 24 | * @return Map<String,Object> | ||
| 25 | */ | ||
| 26 | Map<String,Object> queryAll(UserCollectionQueryCriteria criteria, Pageable pageable); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * 查询所有数据不分页 | ||
| 30 | * @param criteria 条件参数 | ||
| 31 | * @return List<UserCollectionDTO> | ||
| 32 | */ | ||
| 33 | List<UserCollectionDTO> queryAll(UserCollectionQueryCriteria criteria); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * 根据ID查询 | 18 | * 根据ID查询 |
| 37 | * @param id ID | 19 | * @param id ID |
| 38 | * @return UserCollectionDTO | 20 | * @return UserCollectionDTO |
| 39 | */ | 21 | */ |
| 40 | UserCollectionDTO findById(Long id); | 22 | UserCollectionDTO findById(Long id); |
| 41 | 23 | ||
| 24 | /** | ||
| 25 | * | ||
| 26 | * @param resources | ||
| 27 | * @return | ||
| 28 | */ | ||
| 42 | UserCollectionDTO create(UserCollection resources); | 29 | UserCollectionDTO create(UserCollection resources); |
| 43 | 30 | ||
| 31 | /** | ||
| 32 | * | ||
| 33 | * @param resources | ||
| 34 | */ | ||
| 44 | void update(UserCollection resources); | 35 | void update(UserCollection resources); |
| 45 | 36 | ||
| 37 | /** | ||
| 38 | * | ||
| 39 | * @param id | ||
| 40 | */ | ||
| 46 | void delete(Long id); | 41 | void delete(Long id); |
| 47 | 42 | ||
| 43 | /** | ||
| 44 | * | ||
| 45 | * @param all | ||
| 46 | * @param response | ||
| 47 | * @throws IOException | ||
| 48 | */ | ||
| 48 | void download(List<UserCollectionDTO> all, HttpServletResponse response) throws IOException; | 49 | void download(List<UserCollectionDTO> all, HttpServletResponse response) throws IOException; |
| 49 | 50 | ||
| 51 | /** | ||
| 52 | * | ||
| 53 | * @param id | ||
| 54 | * @param type | ||
| 55 | * @return | ||
| 56 | */ | ||
| 50 | List<UserCollection> findByUserIdAndType(Long id, Integer type); | 57 | List<UserCollection> findByUserIdAndType(Long id, Integer type); |
| 51 | 58 | ||
| 59 | /** | ||
| 60 | * | ||
| 61 | * @param id | ||
| 62 | * @param type | ||
| 63 | * @param name | ||
| 64 | * @return | ||
| 65 | */ | ||
| 52 | Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long id, Integer type, String name); | 66 | Optional<UserCollection> findFirstByUserIdAndTypeAndName(Long id, Integer type, String name); |
| 53 | 67 | ||
| 68 | /** | ||
| 69 | * | ||
| 70 | * @param userCollection | ||
| 71 | * @return | ||
| 72 | */ | ||
| 54 | UserCollection save(UserCollection userCollection); | 73 | UserCollection save(UserCollection userCollection); |
| 55 | } | 74 | } | ... | ... |
| ... | @@ -13,27 +13,27 @@ import java.sql.Timestamp; | ... | @@ -13,27 +13,27 @@ import java.sql.Timestamp; |
| 13 | @Data | 13 | @Data |
| 14 | public class UserCollectionDTO implements Serializable { | 14 | public class UserCollectionDTO implements Serializable { |
| 15 | 15 | ||
| 16 | // ID | 16 | /** ID */ |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | // 应用ID | 19 | /** 应用ID */ |
| 20 | private Long appId; | 20 | private Long appId; |
| 21 | 21 | ||
| 22 | // 用户ID | 22 | /** 用户ID */ |
| 23 | private Long userId; | 23 | private Long userId; |
| 24 | 24 | ||
| 25 | // 收藏夹类型:1-收藏 2-播放记录 3-播放列表 4-评分 5-点赞/关注/订阅 | 25 | /** 收藏夹类型:1-收藏 2-播放记录 3-播放列表 4-评分 5-点赞/关注/订阅 */ |
| 26 | private Integer type; | 26 | private Integer type; |
| 27 | 27 | ||
| 28 | // 收藏夹名称 | 28 | /** 收藏夹名称 */ |
| 29 | private String name; | 29 | private String name; |
| 30 | 30 | ||
| 31 | // 数量 | 31 | /** 数量 */ |
| 32 | private Integer count; | 32 | private Integer count; |
| 33 | 33 | ||
| 34 | // 创建时间 | 34 | /** 创建时间 */ |
| 35 | private Timestamp createTime; | 35 | private Timestamp createTime; |
| 36 | 36 | ||
| 37 | // 更新时间 | 37 | /** 更新时间 */ |
| 38 | private Timestamp updateTime; | 38 | private Timestamp updateTime; |
| 39 | } | 39 | } | ... | ... |
| ... | @@ -14,71 +14,71 @@ import java.sql.Timestamp; | ... | @@ -14,71 +14,71 @@ import java.sql.Timestamp; |
| 14 | @Data | 14 | @Data |
| 15 | public class UserCollectionDetailDTO implements Serializable { | 15 | public class UserCollectionDetailDTO implements Serializable { |
| 16 | 16 | ||
| 17 | // ID | 17 | /** ID */ |
| 18 | private Long id; | 18 | private Long id; |
| 19 | 19 | ||
| 20 | // 收藏夹ID | 20 | /** 收藏夹ID */ |
| 21 | private Long userCollectionId; | 21 | private Long userCollectionId; |
| 22 | 22 | ||
| 23 | // 自定义收藏内容的类型CODE,默认:DEFAULT | 23 | /** 自定义收藏内容的类型CODE,默认:DEFAULT */ |
| 24 | private String detailFolderCode; | 24 | private String detailFolderCode; |
| 25 | 25 | ||
| 26 | // 收藏内容的类型:MEDIA|EPISODE|CATEGORY|SUBJECT|ARTICLE|ARTIST|SCHOOL | 26 | /** 收藏内容的类型:MEDIA|EPISODE|CATEGORY|SUBJECT|ARTICLE|ARTIST|SCHOOL */ |
| 27 | private String detailType; | 27 | private String detailType; |
| 28 | 28 | ||
| 29 | // 收藏内容的ID | 29 | /** 收藏内容的ID */ |
| 30 | private Long detailId; | 30 | private Long detailId; |
| 31 | 31 | ||
| 32 | // 收藏内容的CODE | 32 | /** 收藏内容的CODE */ |
| 33 | private String detailCode; | 33 | private String detailCode; |
| 34 | 34 | ||
| 35 | // 收藏内容的剧集ID | 35 | /** 收藏内容的剧集ID */ |
| 36 | private Long detailEpisodeId; | 36 | private Long detailEpisodeId; |
| 37 | 37 | ||
| 38 | // 收藏内容的剧集CODE | 38 | /** 收藏内容的剧集CODE */ |
| 39 | private String detailEpisodeCode; | 39 | private String detailEpisodeCode; |
| 40 | 40 | ||
| 41 | // 收藏内容的名称 | 41 | /** 收藏内容的名称 */ |
| 42 | private String detailName; | 42 | private String detailName; |
| 43 | 43 | ||
| 44 | // 收藏内容的标记 | 44 | /** 收藏内容的标记 */ |
| 45 | private Integer detailMark; | 45 | private Integer detailMark; |
| 46 | 46 | ||
| 47 | // 收藏内容的图片 | 47 | /** 收藏内容的图片 */ |
| 48 | private String detailImg; | 48 | private String detailImg; |
| 49 | 49 | ||
| 50 | // 收藏内容的剧集序号 | 50 | /** 收藏内容的剧集序号 */ |
| 51 | private Integer detailIndex; | 51 | private Integer detailIndex; |
| 52 | 52 | ||
| 53 | // 收藏内容的剧集总数 | 53 | /** 收藏内容的剧集总数 */ |
| 54 | private Integer detailTotalIndex; | 54 | private Integer detailTotalIndex; |
| 55 | 55 | ||
| 56 | // 收藏内容的播放时间 | 56 | /** 收藏内容的播放时间 */ |
| 57 | private Integer detailPlayTime; | 57 | private Integer detailPlayTime; |
| 58 | 58 | ||
| 59 | // 收藏内容的总时间 | 59 | /** 收藏内容的总时间 */ |
| 60 | private Integer detailTotalTime; | 60 | private Integer detailTotalTime; |
| 61 | 61 | ||
| 62 | // 收藏内容在同一folder中的顺序 | 62 | /** 收藏内容在同一folder中的顺序 */ |
| 63 | private Integer detailSequence; | 63 | private Integer detailSequence; |
| 64 | 64 | ||
| 65 | // 收藏内容的评分 | 65 | /** 收藏内容的评分 */ |
| 66 | private Float detailScore; | 66 | private Float detailScore; |
| 67 | 67 | ||
| 68 | // 收藏内容(根据文件夹和类型的不同)的点赞/关注/订阅 | 68 | /** 收藏内容(根据文件夹和类型的不同)的点赞/关注/订阅 */ |
| 69 | private Integer detailLike; | 69 | private Integer detailLike; |
| 70 | 70 | ||
| 71 | // 收藏内容的扩展数据 | 71 | /** 收藏内容的扩展数据 */ |
| 72 | private String detailExtData; | 72 | private String detailExtData; |
| 73 | 73 | ||
| 74 | // 创建时间 | 74 | /** 创建时间 */ |
| 75 | @JsonFormat( | 75 | @JsonFormat( |
| 76 | pattern = "MM月dd日 HH:mm", | 76 | pattern = "MM月dd日 HH:mm", |
| 77 | timezone = "GMT+8" | 77 | timezone = "GMT+8" |
| 78 | ) | 78 | ) |
| 79 | private Timestamp createTime; | 79 | private Timestamp createTime; |
| 80 | 80 | ||
| 81 | // 更新时间 | 81 | /** 更新时间 */ |
| 82 | @JsonFormat( | 82 | @JsonFormat( |
| 83 | pattern = "MM月dd日 HH:mm", | 83 | pattern = "MM月dd日 HH:mm", |
| 84 | timezone = "GMT+8" | 84 | timezone = "GMT+8" | ... | ... |
| 1 | package com.topdraw.business.module.user.weixin.collection.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Query; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | import javax.persistence.criteria.JoinType; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @author pengmengqing | ||
| 10 | * @date 2021-04-02 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | public class UserCollectionDetailQueryCriteria{ | ||
| 14 | |||
| 15 | private Long userWeixinId; | ||
| 16 | |||
| 17 | |||
| 18 | @Query(joinType = JoinType.INNER, joinName = "userCollection") | ||
| 19 | private Long userId; | ||
| 20 | |||
| 21 | @Query(joinType = JoinType.INNER, joinName = "userCollection") | ||
| 22 | private Integer type; | ||
| 23 | |||
| 24 | private String detailType; | ||
| 25 | |||
| 26 | private String detailFolderCode = "DEFAULT"; | ||
| 27 | |||
| 28 | private Long detailId; | ||
| 29 | } |
| ... | @@ -4,22 +4,16 @@ import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionD | ... | @@ -4,22 +4,16 @@ import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionD |
| 4 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository; | 4 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository; |
| 5 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionDetailService; | 5 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionDetailService; |
| 6 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailDTO; | 6 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailDTO; |
| 7 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDetailQueryCriteria; | ||
| 8 | import com.topdraw.business.module.user.weixin.collection.service.mapper.UserCollectionDetailMapper; | 7 | import com.topdraw.business.module.user.weixin.collection.service.mapper.UserCollectionDetailMapper; |
| 9 | import com.topdraw.utils.PageUtil; | ||
| 10 | import com.topdraw.utils.QueryHelp; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | 8 | import com.topdraw.utils.ValidationUtil; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | 10 | import org.springframework.dao.EmptyResultDataAccessException; |
| 14 | import org.springframework.data.domain.Page; | ||
| 15 | import org.springframework.data.domain.Pageable; | ||
| 16 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 19 | import org.springframework.util.Assert; | 14 | import org.springframework.util.Assert; |
| 20 | 15 | ||
| 21 | import java.util.List; | 16 | import java.util.List; |
| 22 | import java.util.Map; | ||
| 23 | 17 | ||
| 24 | /** | 18 | /** |
| 25 | * @author pengmengqing | 19 | * @author pengmengqing |
| ... | @@ -31,15 +25,9 @@ public class UserCollectionDetailServiceImpl implements UserCollectionDetailServ | ... | @@ -31,15 +25,9 @@ public class UserCollectionDetailServiceImpl implements UserCollectionDetailServ |
| 31 | 25 | ||
| 32 | @Autowired | 26 | @Autowired |
| 33 | private UserCollectionDetailRepository userCollectionDetailRepository; | 27 | private UserCollectionDetailRepository userCollectionDetailRepository; |
| 34 | |||
| 35 | @Autowired | 28 | @Autowired |
| 36 | private UserCollectionDetailMapper userCollectionDetailMapper; | 29 | private UserCollectionDetailMapper userCollectionDetailMapper; |
| 37 | 30 | ||
| 38 | @Override | ||
| 39 | public Map<String, Object> queryAll(UserCollectionDetailQueryCriteria criteria, Pageable pageable) { | ||
| 40 | Page<UserCollectionDetail> page = userCollectionDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 41 | return PageUtil.toPage(page.map(userCollectionDetailMapper::toDto)); | ||
| 42 | } | ||
| 43 | 31 | ||
| 44 | @Override | 32 | @Override |
| 45 | public UserCollectionDetailDTO findById(Long id) { | 33 | public UserCollectionDetailDTO findById(Long id) { | ... | ... |
| ... | @@ -4,16 +4,11 @@ import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; | ... | @@ -4,16 +4,11 @@ import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; |
| 4 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionRepository; | 4 | import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionRepository; |
| 5 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionService; | 5 | import com.topdraw.business.module.user.weixin.collection.service.UserCollectionService; |
| 6 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDTO; | 6 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionDTO; |
| 7 | import com.topdraw.business.module.user.weixin.collection.service.dto.UserCollectionQueryCriteria; | ||
| 8 | import com.topdraw.business.module.user.weixin.collection.service.mapper.UserCollectionMapper; | 7 | import com.topdraw.business.module.user.weixin.collection.service.mapper.UserCollectionMapper; |
| 9 | import com.topdraw.utils.FileUtil; | 8 | import com.topdraw.utils.FileUtil; |
| 10 | import com.topdraw.utils.PageUtil; | ||
| 11 | import com.topdraw.utils.QueryHelp; | ||
| 12 | import com.topdraw.utils.ValidationUtil; | 9 | import com.topdraw.utils.ValidationUtil; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | 11 | import org.springframework.dao.EmptyResultDataAccessException; |
| 15 | import org.springframework.data.domain.Page; | ||
| 16 | import org.springframework.data.domain.Pageable; | ||
| 17 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 18 | import org.springframework.transaction.annotation.Propagation; | 13 | import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -37,19 +32,6 @@ public class UserCollectionServiceImpl implements UserCollectionService { | ... | @@ -37,19 +32,6 @@ public class UserCollectionServiceImpl implements UserCollectionService { |
| 37 | @Autowired | 32 | @Autowired |
| 38 | private UserCollectionMapper userCollectionMapper; | 33 | private UserCollectionMapper userCollectionMapper; |
| 39 | 34 | ||
| 40 | |||
| 41 | |||
| 42 | @Override | ||
| 43 | public Map<String, Object> queryAll(UserCollectionQueryCriteria criteria, Pageable pageable) { | ||
| 44 | Page<UserCollection> page = userCollectionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 45 | return PageUtil.toPage(page.map(userCollectionMapper::toDto)); | ||
| 46 | } | ||
| 47 | |||
| 48 | @Override | ||
| 49 | public List<UserCollectionDTO> queryAll(UserCollectionQueryCriteria criteria) { | ||
| 50 | return userCollectionMapper.toDto(userCollectionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | 35 | @Override |
| 54 | public UserCollectionDTO findById(Long id) { | 36 | public UserCollectionDTO findById(Long id) { |
| 55 | UserCollection userCollection = userCollectionRepository.findById(id).orElseGet(UserCollection::new); | 37 | UserCollection userCollection = userCollectionRepository.findById(id).orElseGet(UserCollection::new); | ... | ... |
| ... | @@ -2,7 +2,9 @@ package com.topdraw.business.module.user.weixin.domain; | ... | @@ -2,7 +2,9 @@ package com.topdraw.business.module.user.weixin.domain; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.bean.copier.CopyOptions; | 4 | import cn.hutool.core.bean.copier.CopyOptions; |
| 5 | import com.topdraw.business.module.common.domain.DefaultAsyncMqModule; | 5 | import com.fasterxml.jackson.annotation.JsonFormat; |
| 6 | import com.topdraw.business.module.common.domain.AsyncMqModule; | ||
| 7 | import com.topdraw.business.module.common.validated.CreateGroup; | ||
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 9 | import lombok.experimental.Accessors; |
| 8 | import org.springframework.data.annotation.CreatedDate; | 10 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -10,9 +12,9 @@ import org.springframework.data.annotation.LastModifiedDate; | ... | @@ -10,9 +12,9 @@ import org.springframework.data.annotation.LastModifiedDate; |
| 10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; | 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 11 | 13 | ||
| 12 | import javax.persistence.*; | 14 | import javax.persistence.*; |
| 15 | import javax.validation.constraints.NotNull; | ||
| 13 | import java.io.Serializable; | 16 | import java.io.Serializable; |
| 14 | import java.sql.Timestamp; | 17 | import java.sql.Timestamp; |
| 15 | import java.time.LocalDateTime; | ||
| 16 | 18 | ||
| 17 | /** | 19 | /** |
| 18 | * @author XiangHan | 20 | * @author XiangHan |
| ... | @@ -23,115 +25,119 @@ import java.time.LocalDateTime; | ... | @@ -23,115 +25,119 @@ import java.time.LocalDateTime; |
| 23 | @EntityListeners(AuditingEntityListener.class) | 25 | @EntityListeners(AuditingEntityListener.class) |
| 24 | @Accessors(chain = true) | 26 | @Accessors(chain = true) |
| 25 | @Table(name="uc_user_weixin") | 27 | @Table(name="uc_user_weixin") |
| 26 | public class UserWeixin extends DefaultAsyncMqModule implements Serializable { | 28 | public class UserWeixin extends AsyncMqModule implements Serializable { |
| 27 | 29 | ||
| 28 | // ID | 30 | /** ID */ |
| 29 | @Id | 31 | @Id |
| 30 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 32 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 31 | @Column(name = "id") | 33 | @Column(name = "id") |
| 32 | private Long id; | 34 | private Long id; |
| 33 | 35 | ||
| 34 | // 用户ID | 36 | /** 用户ID */ |
| 35 | @Column(name = "member_id") | 37 | @Column(name = "member_id") |
| 36 | private Long memberId; | 38 | private Long memberId; |
| 37 | 39 | ||
| 38 | // 微信unionid,针对开发者 | 40 | /** 微信unionid,针对开发者 */ |
| 39 | @Column(name = "unionid") | 41 | @Column(name = "unionid") |
| 42 | @NotNull(message = "unionid can't be null",groups = {CreateGroup.class}) | ||
| 40 | private String unionid; | 43 | private String unionid; |
| 41 | 44 | ||
| 42 | // 微信appid | 45 | /** 微信appid */ |
| 43 | @Column(name = "appid") | 46 | @Column(name = "appid") |
| 47 | @NotNull(message = "appid can't be null",groups = {CreateGroup.class}) | ||
| 44 | private String appid; | 48 | private String appid; |
| 45 | 49 | ||
| 46 | // 微信openid,针对微信app | 50 | /** 微信openid,针对微信app */ |
| 47 | @Column(name = "openid") | 51 | @Column(name = "openid") |
| 52 | @NotNull(message = "openid can't be null",groups = {CreateGroup.class}) | ||
| 48 | private String openid; | 53 | private String openid; |
| 49 | 54 | ||
| 50 | // 关注状态 0 -未关注 1 - 已关注 | 55 | /** 关注状态 0 -未关注 1 - 已关注 */ |
| 51 | @Column(name = "status") | 56 | @Column(name = "status") |
| 52 | private Integer status; | 57 | private Integer status; |
| 53 | 58 | ||
| 54 | // 关注同步状态 0-未同步,1-已同步 | 59 | /** 关注同步状态 0-未同步,1-已同步 */ |
| 55 | @Column(name = "sync_status") | 60 | @Column(name = "sync_status") |
| 56 | private Integer syncStatus; | 61 | private Integer syncStatus; |
| 57 | 62 | ||
| 58 | // 昵称 | 63 | /** 昵称 */ |
| 59 | @Column(name = "nickname") | 64 | @Column(name = "nickname") |
| 60 | private String nickname; | 65 | private String nickname; |
| 61 | 66 | ||
| 62 | // 头像地址 | 67 | /** 头像地址 */ |
| 63 | @Column(name = "headimgurl") | 68 | @Column(name = "headimgurl") |
| 64 | private String headimgurl; | 69 | private String headimgurl; |
| 65 | 70 | ||
| 66 | // 特权信息 | 71 | /** 特权信息 */ |
| 67 | @Column(name = "privilege") | 72 | @Column(name = "privilege") |
| 68 | private String privilege; | 73 | private String privilege; |
| 69 | 74 | ||
| 70 | // 刷新凭据 | 75 | /** 刷新凭据 */ |
| 71 | @Column(name = "refresh_token") | 76 | @Column(name = "refresh_token") |
| 72 | private String refreshToken; | 77 | private String refreshToken; |
| 73 | 78 | ||
| 74 | // 凭据 | 79 | /** 凭据 */ |
| 75 | @Column(name = "access_token") | 80 | @Column(name = "access_token") |
| 76 | private String accessToken; | 81 | private String accessToken; |
| 77 | 82 | ||
| 78 | // 超时(秒) | 83 | /** 超时(秒) */ |
| 79 | @Column(name = "expires_in") | 84 | @Column(name = "expires_in") |
| 80 | private Integer expiresIn; | 85 | private Integer expiresIn; |
| 81 | 86 | ||
| 82 | // 超时时间 | 87 | /** 超时时间 */ |
| 83 | @Column(name = "expires_time") | 88 | @Column(name = "expires_time") |
| 84 | private LocalDateTime expiresTime; | 89 | private Timestamp expiresTime; |
| 85 | 90 | ||
| 86 | // 描述 | 91 | /** 描述 */ |
| 87 | @Column(name = "description") | 92 | @Column(name = "description") |
| 88 | private String description; | 93 | private String description; |
| 89 | 94 | ||
| 90 | // 创建者 | 95 | /** 创建者 */ |
| 91 | @Column(name = "create_by") | 96 | @Column(name = "create_by") |
| 92 | private String createBy; | 97 | private String createBy; |
| 93 | 98 | ||
| 94 | // 创建时间 | 99 | /** 创建时间 */ |
| 95 | @CreatedDate | 100 | @CreatedDate |
| 96 | @Column(name = "create_time") | 101 | @Column(name = "create_time") |
| 97 | private LocalDateTime createTime; | 102 | private Timestamp createTime; |
| 98 | 103 | ||
| 99 | // 更新者 | 104 | /** 更新者 */ |
| 100 | @Column(name = "update_by") | 105 | @Column(name = "update_by") |
| 101 | private String updateBy; | 106 | private String updateBy; |
| 102 | 107 | ||
| 103 | // 更新时间 | 108 | /** 更新时间 */ |
| 104 | @LastModifiedDate | 109 | @LastModifiedDate |
| 105 | @Column(name = "update_time") | 110 | @Column(name = "update_time") |
| 106 | private LocalDateTime updateTime; | 111 | private Timestamp updateTime; |
| 107 | 112 | ||
| 108 | // 来源类型 | 113 | /** 来源类型 */ |
| 109 | @Column(name = "source_type") | 114 | @Column(name = "source_type") |
| 110 | private String sourceType; | 115 | private String sourceType; |
| 111 | 116 | ||
| 112 | // 来源id | 117 | /** 来源id */ |
| 113 | @Column(name = "source_id") | 118 | @Column(name = "source_id") |
| 114 | private String sourceId; | 119 | private String sourceId; |
| 115 | 120 | ||
| 116 | // 来源id | 121 | /** 来源id */ |
| 117 | @Column(name = "source_desc") | 122 | @Column(name = "source_desc") |
| 118 | private String sourceDesc; | 123 | private String sourceDesc; |
| 119 | 124 | ||
| 120 | // 人id | 125 | /** 人id */ |
| 121 | @Column(name = "person_id") | 126 | @Column(name = "person_id") |
| 122 | private Long personId; | 127 | private Long personId; |
| 123 | 128 | ||
| 124 | // 来源用户id | 129 | /** 来源用户id */ |
| 125 | @Column(name = "source_user") | 130 | @Column(name = "source_user") |
| 126 | private Long sourceUser; | 131 | private Long sourceUser; |
| 127 | 132 | ||
| 128 | // 来源实体:活动-activity/商品-item | 133 | /** 来源实体:活动-activity/商品-item */ |
| 129 | @Column(name = "source_entity") | 134 | @Column(name = "source_entity") |
| 130 | private String sourceEntity; | 135 | private String sourceEntity; |
| 131 | 136 | ||
| 132 | // 授权时间 | 137 | /** 授权时间 */ |
| 138 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") | ||
| 133 | @Column(name = "auth_time") | 139 | @Column(name = "auth_time") |
| 134 | private LocalDateTime authTime; | 140 | private Timestamp authTime; |
| 135 | 141 | ||
| 136 | @Column(name = "sex") | 142 | @Column(name = "sex") |
| 137 | private Integer sex; | 143 | private Integer sex; | ... | ... |
| 1 | package com.topdraw.business.module.user.weixin.domain; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.exception.BadRequestException; | ||
| 5 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 6 | import com.topdraw.util.TimestampUtil; | ||
| 7 | import org.apache.commons.lang3.StringUtils; | ||
| 8 | |||
| 9 | import java.sql.Timestamp; | ||
| 10 | import java.util.Objects; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @author : | ||
| 14 | * @description: | ||
| 15 | * @function : | ||
| 16 | * @date :Created in 2022/3/14 17:02 | ||
| 17 | * @version: : | ||
| 18 | * @modified By: | ||
| 19 | * @since : modified in 2022/3/14 17:02 | ||
| 20 | */ | ||
| 21 | public class UserWeixinBuilder { | ||
| 22 | |||
| 23 | public static UserWeixin build(Long memberId,String appId,String openId,String unionId,String nickname,String headimgurl){ | ||
| 24 | UserWeixin userWeixin = new UserWeixin(); | ||
| 25 | userWeixin.setAppid(appId); | ||
| 26 | userWeixin.setOpenid(openId); | ||
| 27 | userWeixin.setUnionid(unionId); | ||
| 28 | userWeixin.setNickname(nickname); | ||
| 29 | userWeixin.setHeadimgurl(headimgurl); | ||
| 30 | return build(memberId,userWeixin); | ||
| 31 | } | ||
| 32 | |||
| 33 | public static UserWeixin build(Long memberId,String appId,String openId,String unionId){ | ||
| 34 | UserWeixin userWeixin = new UserWeixin(); | ||
| 35 | userWeixin.setAppid(appId); | ||
| 36 | userWeixin.setOpenid(openId); | ||
| 37 | userWeixin.setUnionid(unionId); | ||
| 38 | return build(memberId,userWeixin); | ||
| 39 | } | ||
| 40 | |||
| 41 | public static UserWeixin build(UserWeixin userWeixin){ | ||
| 42 | return build(userWeixin.getId(), | ||
| 43 | userWeixin.getMemberId(), | ||
| 44 | userWeixin.getMemberCode(), | ||
| 45 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
| 46 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
| 47 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
| 48 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
| 49 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
| 50 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
| 51 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
| 52 | userWeixin.getCity(),userWeixin.getSex()); | ||
| 53 | } | ||
| 54 | |||
| 55 | public static UserWeixin build(Long memberId , String memberCode, UserWeixin userWeixin){ | ||
| 56 | return build(userWeixin.getId(), | ||
| 57 | memberId, | ||
| 58 | memberCode, | ||
| 59 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
| 60 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
| 61 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
| 62 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
| 63 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
| 64 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
| 65 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
| 66 | userWeixin.getCity(),userWeixin.getSex()); | ||
| 67 | } | ||
| 68 | |||
| 69 | public static UserWeixin build(Long memberId , UserWeixin userWeixin){ | ||
| 70 | return build(userWeixin.getId(), | ||
| 71 | memberId, | ||
| 72 | userWeixin.getMemberCode(), | ||
| 73 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
| 74 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
| 75 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
| 76 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
| 77 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
| 78 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
| 79 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
| 80 | userWeixin.getCity(),userWeixin.getSex()); | ||
| 81 | } | ||
| 82 | |||
| 83 | public static UserWeixin build(Member member , UserWeixin userWeixin) { | ||
| 84 | return build(userWeixin.getId(), | ||
| 85 | member.getId(), | ||
| 86 | member.getCode(), | ||
| 87 | userWeixin.getUnionid(),userWeixin.getAppid(),userWeixin.getOpenid(), | ||
| 88 | userWeixin.getStatus(),userWeixin.getSyncStatus(), | ||
| 89 | userWeixin.getNickname(),userWeixin.getHeadimgurl(), | ||
| 90 | userWeixin.getPrivilege(), userWeixin.getRefreshToken(),userWeixin.getAccessToken(), | ||
| 91 | userWeixin.getExpiresIn(),userWeixin.getExpiresTime(),userWeixin.getDescription(), | ||
| 92 | userWeixin.getCreateBy(),userWeixin.getUpdateBy(),userWeixin.getSourceType(),userWeixin.getSourceId(), | ||
| 93 | userWeixin.getSourceDesc(),userWeixin.getSourceUser(),userWeixin.getSourceEntity(),userWeixin.getCountry(),userWeixin.getProvince(), | ||
| 94 | userWeixin.getCity(),userWeixin.getSex()); | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | public static UserWeixin build(Long id , | ||
| 99 | Long memberId, | ||
| 100 | String memberCode, | ||
| 101 | String unionId, String appId,String openId, | ||
| 102 | Integer status, Integer syncStatus, | ||
| 103 | String nickname,String headimgurl, | ||
| 104 | String privilege,String refreshToken, | ||
| 105 | String accessToken,Integer expiresIn,Timestamp expiresTime,String description, | ||
| 106 | String createBy,String updateBy, | ||
| 107 | String sourceType,String sourceId, | ||
| 108 | String sourceDesc, | ||
| 109 | Long sourceUser,String sourceEntity, | ||
| 110 | String country,String province,String city, | ||
| 111 | Integer sex){ | ||
| 112 | |||
| 113 | if (Objects.isNull(memberId)) { | ||
| 114 | throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 115 | } | ||
| 116 | |||
| 117 | UserWeixin userWeixin = new UserWeixin(); | ||
| 118 | userWeixin.setId(Objects.nonNull(id)?id:null); | ||
| 119 | userWeixin.setMemberId(memberId); | ||
| 120 | userWeixin.setMemberCode(memberCode); | ||
| 121 | userWeixin.setUnionid(StringUtils.isNotBlank(unionId)?unionId:""); | ||
| 122 | userWeixin.setAppid(StringUtils.isNotBlank(appId)?appId:""); | ||
| 123 | userWeixin.setOpenid(StringUtils.isNotBlank(openId)?openId:""); | ||
| 124 | userWeixin.setStatus(Objects.nonNull(status)?status:0); | ||
| 125 | userWeixin.setSyncStatus(Objects.nonNull(syncStatus)?syncStatus:0); | ||
| 126 | userWeixin.setNickname(StringUtils.isNotBlank(nickname)?nickname:""); | ||
| 127 | userWeixin.setHeadimgurl(StringUtils.isNotBlank(headimgurl)?headimgurl:""); | ||
| 128 | userWeixin.setPrivilege(StringUtils.isNotBlank(privilege)?privilege:""); | ||
| 129 | userWeixin.setRefreshToken(StringUtils.isNotBlank(refreshToken)?refreshToken:""); | ||
| 130 | userWeixin.setAccessToken(StringUtils.isNotBlank(accessToken)?accessToken:""); | ||
| 131 | userWeixin.setExpiresIn(expiresIn); | ||
| 132 | userWeixin.setExpiresTime(expiresTime); | ||
| 133 | userWeixin.setDescription(StringUtils.isNotBlank(description)?description:""); | ||
| 134 | userWeixin.setCreateBy(StringUtils.isNotBlank(createBy)?createBy:"system"); | ||
| 135 | userWeixin.setUpdateBy(StringUtils.isNotBlank(updateBy)?updateBy:"system"); | ||
| 136 | userWeixin.setSourceType(StringUtils.isNotBlank(sourceType)?sourceType:""); | ||
| 137 | userWeixin.setSourceId(StringUtils.isNotBlank(sourceId)?sourceId:""); | ||
| 138 | userWeixin.setSourceDesc(StringUtils.isNotBlank(sourceDesc)?sourceId:""); | ||
| 139 | userWeixin.setSourceUser(Objects.nonNull(sourceUser)?sourceUser:0L); | ||
| 140 | userWeixin.setSourceEntity(StringUtils.isNotBlank(sourceEntity)?sourceEntity:""); | ||
| 141 | // userWeixin.setAuthTime(TimestampUtil.now()); | ||
| 142 | userWeixin.setCountry(StringUtils.isNotBlank(country)?country:""); | ||
| 143 | userWeixin.setProvince(StringUtils.isNotBlank(province)?province:""); | ||
| 144 | userWeixin.setCity(StringUtils.isNotBlank(city)?city:""); | ||
| 145 | userWeixin.setSex(Objects.nonNull(sex)?sex:-1); | ||
| 146 | return userWeixin; | ||
| 147 | } | ||
| 148 | |||
| 149 | } |
| ... | @@ -16,10 +16,18 @@ import java.util.Optional; | ... | @@ -16,10 +16,18 @@ import java.util.Optional; |
| 16 | */ | 16 | */ |
| 17 | public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, JpaSpecificationExecutor<UserWeixin> { | 17 | public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, JpaSpecificationExecutor<UserWeixin> { |
| 18 | 18 | ||
| 19 | Optional<UserWeixin> findFirstByMemberIdAndAppid(Long memberId, String appid); | ||
| 20 | |||
| 21 | Optional<UserWeixin> findFirstByUnionidAndAppidAndOpenid(String unionId, String appId, String openId); | ||
| 22 | |||
| 19 | Optional<UserWeixin> findFirstByAppidAndOpenid(String appId, String openId); | 23 | Optional<UserWeixin> findFirstByAppidAndOpenid(String appId, String openId); |
| 20 | 24 | ||
| 25 | Optional<UserWeixin> findFirstByUnionid(String unionid); | ||
| 26 | |||
| 27 | Optional<UserWeixin> findFirstByUnionidAndAppid(String unionid, String appId); | ||
| 28 | |||
| 21 | @Modifying | 29 | @Modifying |
| 22 | @Transactional | 30 | @Transactional |
| 23 | @Query(value = "update uc_user_weixin set update_time = :#{#resources.updateTime} where appid = :#{#resources.appid} and openid = :#{#resources.openid}" , nativeQuery = true) | 31 | @Query(value = "update `uc_user_weixin` set update_time = :#{#resources.updateTime} where appid = :#{#resources.appid} and openid = :#{#resources.openid}" , nativeQuery = true) |
| 24 | void updateTime(@Param("resources") UserWeixin resources); | 32 | void updateTime(@Param("resources") UserWeixin resources); |
| 25 | } | 33 | } | ... | ... |
| ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.user.weixin.service; | ... | @@ -2,11 +2,6 @@ package com.topdraw.business.module.user.weixin.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 3 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
| 4 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 4 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 5 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
| 6 | import org.springframework.data.domain.Pageable; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | 5 | ||
| 11 | /** | 6 | /** |
| 12 | * @author XiangHan | 7 | * @author XiangHan |
| ... | @@ -15,35 +10,74 @@ import java.util.Map; | ... | @@ -15,35 +10,74 @@ import java.util.Map; |
| 15 | public interface UserWeixinService { | 10 | public interface UserWeixinService { |
| 16 | 11 | ||
| 17 | /** | 12 | /** |
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(UserWeixinQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<UserWeixinDTO> | ||
| 29 | */ | ||
| 30 | List<UserWeixinDTO> queryAll(UserWeixinQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | 13 | * 根据ID查询 |
| 34 | * @param id ID | 14 | * @param id ID |
| 35 | * @return UserWeixinDTO | 15 | * @return UserWeixinDTO |
| 36 | */ | 16 | */ |
| 37 | UserWeixinDTO findById(Long id); | 17 | UserWeixinDTO findById(Long id); |
| 38 | 18 | ||
| 39 | void updateTime(UserWeixin resources); | 19 | /** |
| 40 | 20 | * | |
| 41 | void create(UserWeixin resources); | 21 | * @param resources |
| 22 | * @return | ||
| 23 | */ | ||
| 24 | UserWeixin create(UserWeixin resources); | ||
| 42 | 25 | ||
| 26 | /** | ||
| 27 | * | ||
| 28 | * @param resources | ||
| 29 | */ | ||
| 43 | void update(UserWeixin resources); | 30 | void update(UserWeixin resources); |
| 44 | 31 | ||
| 32 | /** | ||
| 33 | * | ||
| 34 | * @param resources | ||
| 35 | */ | ||
| 36 | void updateTime(UserWeixin resources); | ||
| 37 | |||
| 38 | /** | ||
| 39 | * | ||
| 40 | * @param id | ||
| 41 | */ | ||
| 45 | void delete(Long id); | 42 | void delete(Long id); |
| 46 | 43 | ||
| 44 | /** | ||
| 45 | * | ||
| 46 | * @param memberId | ||
| 47 | * @param appid | ||
| 48 | * @return | ||
| 49 | */ | ||
| 50 | UserWeixinDTO findFirstByMemberIdAndAppid(Long memberId, String appid); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * | ||
| 54 | * @param unionId | ||
| 55 | * @param appId | ||
| 56 | * @param openId | ||
| 57 | * @return | ||
| 58 | */ | ||
| 59 | UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId(String unionId, String appId, String openId); | ||
| 60 | |||
| 61 | /** | ||
| 62 | * | ||
| 63 | * @param appId | ||
| 64 | * @param openId | ||
| 65 | * @return | ||
| 66 | */ | ||
| 47 | UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId); | 67 | UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId); |
| 48 | 68 | ||
| 69 | /** | ||
| 70 | * | ||
| 71 | * @param unionid | ||
| 72 | * @return | ||
| 73 | */ | ||
| 74 | UserWeixinDTO findFirstByUnionId(String unionid); | ||
| 75 | |||
| 76 | /** | ||
| 77 | * | ||
| 78 | * @param unionid | ||
| 79 | * @param appId | ||
| 80 | * @return | ||
| 81 | */ | ||
| 82 | UserWeixinDTO findFirstByUnionidAndAppid(String unionid, String appId); | ||
| 49 | } | 83 | } | ... | ... |
| ... | @@ -4,7 +4,6 @@ import lombok.Data; | ... | @@ -4,7 +4,6 @@ import lombok.Data; |
| 4 | 4 | ||
| 5 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 6 | import java.sql.Timestamp; | 6 | import java.sql.Timestamp; |
| 7 | import java.time.LocalDateTime; | ||
| 8 | 7 | ||
| 9 | 8 | ||
| 10 | /** | 9 | /** |
| ... | @@ -14,89 +13,93 @@ import java.time.LocalDateTime; | ... | @@ -14,89 +13,93 @@ import java.time.LocalDateTime; |
| 14 | @Data | 13 | @Data |
| 15 | public class UserWeixinDTO implements Serializable { | 14 | public class UserWeixinDTO implements Serializable { |
| 16 | 15 | ||
| 17 | // ID | 16 | private String memberCode; |
| 17 | |||
| 18 | /** ID */ | ||
| 18 | private Long id; | 19 | private Long id; |
| 19 | 20 | ||
| 20 | // 用户ID | 21 | /** 用户ID */ |
| 21 | private Long memberId; | 22 | private Long memberId; |
| 22 | 23 | ||
| 23 | // 微信unionid,针对开发者 | 24 | /** 微信unionid,针对开发者 */ |
| 24 | private String unionid; | 25 | private String unionid; |
| 25 | 26 | ||
| 26 | // 微信appid | 27 | /** 微信appid */ |
| 27 | private String appid; | 28 | private String appid; |
| 28 | 29 | ||
| 29 | // 微信openid,针对微信app | 30 | /** 微信openid,针对微信app */ |
| 30 | private String openid; | 31 | private String openid; |
| 31 | 32 | ||
| 32 | // 关注状态 0 -未关注 1 - 已关注 | 33 | /** 关注状态 0 -未关注 1 - 已关注 */ |
| 33 | private Integer status; | 34 | private Integer status; |
| 34 | 35 | ||
| 35 | // 关注同步状态 0-未同步,1-已同步 | 36 | /** 关注同步状态 0-未同步,1-已同步 */ |
| 36 | private Integer syncStatus; | 37 | private Integer syncStatus; |
| 37 | 38 | ||
| 38 | // 昵称 | 39 | /** 昵称 */ |
| 39 | private String nickname; | 40 | private String nickname; |
| 40 | 41 | ||
| 41 | // 头像地址 | 42 | /** 头像地址 */ |
| 42 | private String headimgurl; | 43 | private String headimgurl; |
| 43 | 44 | ||
| 44 | // 特权信息 | 45 | /** 特权信息 */ |
| 45 | private String privilege; | 46 | private String privilege; |
| 46 | 47 | ||
| 47 | // 刷新凭据 | 48 | /** 刷新凭据 */ |
| 48 | private String refreshToken; | 49 | private String refreshToken; |
| 49 | 50 | ||
| 50 | // 凭据 | 51 | /** 凭据 */ |
| 51 | private String accessToken; | 52 | private String accessToken; |
| 52 | 53 | ||
| 53 | // 超时(秒) | 54 | /** 超时(秒) */ |
| 54 | private Integer expiresIn; | 55 | private Integer expiresIn; |
| 55 | 56 | ||
| 56 | // 超时时间 | 57 | /** 超时时间 */ |
| 57 | private LocalDateTime expiresTime; | 58 | private Timestamp expiresTime; |
| 58 | 59 | ||
| 59 | // 描述 | 60 | /** 描述 */ |
| 60 | private String description; | 61 | private String description; |
| 61 | 62 | ||
| 62 | // 创建者 | 63 | /** 创建者 */ |
| 63 | private String createBy; | 64 | private String createBy; |
| 64 | 65 | ||
| 65 | // 创建时间 | 66 | /** 创建时间 */ |
| 66 | private LocalDateTime createTime; | 67 | private Timestamp createTime; |
| 67 | 68 | ||
| 68 | // 更新者 | 69 | /** 更新者 */ |
| 69 | private String updateBy; | 70 | private String updateBy; |
| 70 | 71 | ||
| 71 | // 更新时间 | 72 | /** 更新时间 */ |
| 72 | private LocalDateTime updateTime; | 73 | private Timestamp updateTime; |
| 73 | 74 | ||
| 74 | // 来源类型 | 75 | /** 来源类型 */ |
| 75 | private String sourceType; | 76 | private String sourceType; |
| 76 | 77 | ||
| 77 | // 来源id | 78 | /** 来源id */ |
| 78 | private String sourceId; | 79 | private String sourceId; |
| 79 | 80 | ||
| 80 | // 来源id | 81 | /** 来源id */ |
| 81 | private String sourceDesc; | 82 | private String sourceDesc; |
| 82 | 83 | ||
| 83 | // 人id | 84 | /** 人id */ |
| 84 | private Long personId; | 85 | private Long personId; |
| 85 | 86 | ||
| 86 | // 来源用户id | 87 | /** 来源用户id */ |
| 87 | private Long sourceUser; | 88 | private Long sourceUser; |
| 88 | 89 | ||
| 89 | // 来源实体:活动-activity/商品-item | 90 | /** 来源实体:活动-activity/商品-item */ |
| 90 | private String sourceEntity; | 91 | private String sourceEntity; |
| 91 | 92 | ||
| 92 | // 授权时间 | 93 | /** 授权时间 */ |
| 93 | private LocalDateTime authTime; | 94 | private Timestamp authTime; |
| 94 | 95 | ||
| 95 | private Integer sex; | 96 | private Integer gender; |
| 96 | 97 | ||
| 97 | private String country; | 98 | private String country; |
| 98 | 99 | ||
| 99 | private String province; | 100 | private String province; |
| 100 | 101 | ||
| 101 | private String city; | 102 | private String city; |
| 103 | |||
| 104 | private Integer sex; | ||
| 102 | } | 105 | } | ... | ... |
| 1 | package com.topdraw.business.module.user.weixin.service.dto; | 1 | package com.topdraw.business.module.user.weixin.service.dto; |
| 2 | 2 | ||
| 3 | import com.topdraw.annotation.Query; | ||
| 3 | import lombok.Data; | 4 | import lombok.Data; |
| 4 | 5 | ||
| 5 | /** | 6 | /** |
| ... | @@ -8,4 +9,8 @@ import lombok.Data; | ... | @@ -8,4 +9,8 @@ import lombok.Data; |
| 8 | */ | 9 | */ |
| 9 | @Data | 10 | @Data |
| 10 | public class UserWeixinQueryCriteria{ | 11 | public class UserWeixinQueryCriteria{ |
| 12 | |||
| 13 | @Query() | ||
| 14 | private String unionId; | ||
| 15 | |||
| 11 | } | 16 | } | ... | ... |
| ... | @@ -3,30 +3,20 @@ package com.topdraw.business.module.user.weixin.service.impl; | ... | @@ -3,30 +3,20 @@ package com.topdraw.business.module.user.weixin.service.impl; |
| 3 | import com.topdraw.business.module.member.service.MemberService; | 3 | import com.topdraw.business.module.member.service.MemberService; |
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | 5 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; |
| 6 | import com.topdraw.business.module.user.weixin.domain.UserWeixinBuilder; | ||
| 6 | import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; | 7 | import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; |
| 7 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | 8 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; |
| 8 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | 9 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; |
| 9 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
| 10 | import com.topdraw.business.module.user.weixin.service.mapper.UserWeixinMapper; | 10 | import com.topdraw.business.module.user.weixin.service.mapper.UserWeixinMapper; |
| 11 | import com.topdraw.utils.PageUtil; | ||
| 12 | import com.topdraw.utils.QueryHelp; | ||
| 13 | import com.topdraw.utils.ValidationUtil; | 11 | import com.topdraw.utils.ValidationUtil; |
| 14 | import lombok.extern.slf4j.Slf4j; | ||
| 15 | import org.springframework.beans.BeanUtils; | ||
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | import org.springframework.dao.EmptyResultDataAccessException; | 13 | import org.springframework.dao.EmptyResultDataAccessException; |
| 18 | import org.springframework.data.domain.Page; | ||
| 19 | import org.springframework.data.domain.Pageable; | ||
| 20 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.transaction.annotation.Propagation; | 15 | import org.springframework.transaction.annotation.Propagation; |
| 22 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| 23 | import org.springframework.util.Assert; | 17 | import org.springframework.util.Assert; |
| 24 | 18 | ||
| 25 | import java.sql.Time; | 19 | import javax.validation.constraints.NotNull; |
| 26 | import java.sql.Timestamp; | ||
| 27 | import java.time.LocalDateTime; | ||
| 28 | import java.util.List; | ||
| 29 | import java.util.Map; | ||
| 30 | import java.util.Objects; | 20 | import java.util.Objects; |
| 31 | 21 | ||
| 32 | /** | 22 | /** |
| ... | @@ -35,97 +25,94 @@ import java.util.Objects; | ... | @@ -35,97 +25,94 @@ import java.util.Objects; |
| 35 | */ | 25 | */ |
| 36 | @Service | 26 | @Service |
| 37 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 27 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 38 | @Slf4j | ||
| 39 | public class UserWeixinServiceImpl implements UserWeixinService { | 28 | public class UserWeixinServiceImpl implements UserWeixinService { |
| 40 | 29 | ||
| 41 | @Autowired | 30 | @Autowired |
| 42 | private UserWeixinRepository UserWeixinRepository; | 31 | private MemberService memberService; |
| 43 | |||
| 44 | @Autowired | 32 | @Autowired |
| 45 | private UserWeixinMapper UserWeixinMapper; | 33 | private UserWeixinRepository userWeixinRepository; |
| 46 | @Autowired | 34 | @Autowired |
| 47 | private MemberService memberService; | 35 | private UserWeixinMapper userWeixinMapper; |
| 48 | |||
| 49 | @Override | ||
| 50 | public Map<String, Object> queryAll(UserWeixinQueryCriteria criteria, Pageable pageable) { | ||
| 51 | Page<UserWeixin> page = UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 52 | return PageUtil.toPage(page.map(UserWeixinMapper::toDto)); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Override | ||
| 56 | public List<UserWeixinDTO> queryAll(UserWeixinQueryCriteria criteria) { | ||
| 57 | return UserWeixinMapper.toDto(UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 58 | } | ||
| 59 | 36 | ||
| 60 | @Override | 37 | @Override |
| 61 | public UserWeixinDTO findById(Long id) { | 38 | public UserWeixinDTO findById(Long id) { |
| 62 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseGet(UserWeixin::new); | 39 | UserWeixin UserWeixin = this.userWeixinRepository.findById(id).orElseGet(com.topdraw.business.module.user.weixin.domain.UserWeixin::new); |
| 63 | ValidationUtil.isNull(UserWeixin.getId(),"UserWeixin","id",id); | 40 | ValidationUtil.isNull(UserWeixin.getId(),"UserWeixin","id",id); |
| 64 | return UserWeixinMapper.toDto(UserWeixin); | 41 | return this.userWeixinMapper.toDto(UserWeixin); |
| 65 | } | 42 | } |
| 66 | 43 | ||
| 67 | @Override | 44 | @Override |
| 68 | @Transactional(rollbackFor = Exception.class) | 45 | @Transactional(rollbackFor = Exception.class) |
| 69 | public void updateTime(UserWeixin resources) { | 46 | public UserWeixin create(UserWeixin resources) { |
| 70 | log.info("updateTime ==>> resources ==>> [{}]", resources); | 47 | MemberDTO memberDTO = memberService.findByCode(resources.getMemberCode()); |
| 71 | String appid = resources.getAppid(); | 48 | if (Objects.nonNull(memberDTO)) { |
| 72 | String openid = resources.getOpenid(); | 49 | Long id = memberDTO.getId(); |
| 73 | UserWeixin userWeixin = UserWeixinRepository.findFirstByAppidAndOpenid(appid,openid).orElseGet(UserWeixin::new); | 50 | resources.setMemberId(id); |
| 74 | ValidationUtil.isNull( userWeixin.getId(),"UserWeixin","id",resources.getId()); | 51 | } |
| 75 | userWeixin.setUpdateTime(LocalDateTime.now()); | 52 | UserWeixin build = UserWeixinBuilder.build(resources); |
| 76 | log.info("userWeixin ==>> userWeixin ==>> [{}]",userWeixin); | 53 | this.userWeixinRepository.save(build); |
| 77 | UserWeixinRepository.updateTime(userWeixin); | 54 | return resources; |
| 78 | } | ||
| 79 | |||
| 80 | @Override | ||
| 81 | @Transactional(rollbackFor = Exception.class) | ||
| 82 | public void create(UserWeixin resources) { | ||
| 83 | resources.setMemberId(null); | ||
| 84 | String memberCode = resources.getMemberCode(); | ||
| 85 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 86 | resources.setMemberId(memberDTO.getId()); | ||
| 87 | UserWeixinRepository.save(resources); | ||
| 88 | } | 55 | } |
| 89 | 56 | ||
| 90 | @Override | 57 | @Override |
| 91 | @Transactional(rollbackFor = Exception.class) | 58 | @Transactional(rollbackFor = Exception.class) |
| 92 | public void update(UserWeixin resources) { | 59 | public void update(UserWeixin resources) { |
| 93 | log.info("update ==>> resources ==>> [{}]",resources); | 60 | |
| 94 | String appid = resources.getAppid(); | 61 | String appid = resources.getAppid(); |
| 95 | String openid = resources.getOpenid(); | 62 | String openid = resources.getOpenid(); |
| 96 | UserWeixin userWeixin = UserWeixinRepository.findFirstByAppidAndOpenid(appid,openid).orElseGet(UserWeixin::new); | 63 | UserWeixinDTO userWeixinDTO = this.findFirstByAppIdAndOpenId(appid, openid); |
| 97 | if (Objects.isNull(userWeixin.getId())) { | 64 | resources.setId(userWeixinDTO.getId()); |
| 98 | this.create(resources); | 65 | resources.setMemberId(userWeixinDTO.getMemberId()); |
| 99 | } else { | 66 | |
| 100 | if (Objects.isNull(userWeixin.getMemberId())) { | 67 | UserWeixin UserWeixin = this.userWeixinRepository.findById(resources.getId()).orElseGet(UserWeixin::new); |
| 101 | String memberCode = resources.getMemberCode(); | 68 | ValidationUtil.isNull( UserWeixin.getId(),"UserWeixin","id",resources.getId()); |
| 102 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | 69 | UserWeixin.copy(resources); |
| 103 | resources.setMemberId(memberDTO.getId()); | 70 | this.userWeixinRepository.save(UserWeixin); |
| 104 | } else { | 71 | } |
| 105 | resources.setMemberId(userWeixin.getMemberId()); | ||
| 106 | } | ||
| 107 | resources.setId(userWeixin.getId()); | ||
| 108 | BeanUtils.copyProperties(resources,userWeixin); | ||
| 109 | log.info("update ==>>userWeixin ==>> resources ==>> [{}]",resources); | ||
| 110 | UserWeixinRepository.save(resources); | ||
| 111 | } | ||
| 112 | 72 | ||
| 73 | @Override | ||
| 74 | public void updateTime(UserWeixin resources) { | ||
| 75 | this.userWeixinRepository.updateTime(resources); | ||
| 113 | } | 76 | } |
| 114 | 77 | ||
| 115 | @Override | 78 | @Override |
| 116 | @Transactional(rollbackFor = Exception.class) | 79 | @Transactional(rollbackFor = Exception.class) |
| 117 | public void delete(Long id) { | 80 | public void delete(Long id) { |
| 118 | Assert.notNull(id, "The given id must not be null!"); | 81 | Assert.notNull(id, "The given id must not be null!"); |
| 119 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseThrow( | 82 | UserWeixin UserWeixin = this.userWeixinRepository.findById(id).orElseThrow( |
| 120 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserWeixin.class, id), 1)); | 83 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", com.topdraw.business.module.user.weixin.domain.UserWeixin.class, id), 1)); |
| 121 | UserWeixinRepository.delete(UserWeixin); | 84 | this.userWeixinRepository.delete(UserWeixin); |
| 85 | } | ||
| 86 | |||
| 87 | @Override | ||
| 88 | public UserWeixinDTO findFirstByMemberIdAndAppid(Long memberId, String appid) { | ||
| 89 | UserWeixin userWeixin = this.userWeixinRepository.findFirstByMemberIdAndAppid(memberId, appid).orElseGet(UserWeixin::new); | ||
| 90 | ValidationUtil.isNull(userWeixin.getId(),"UserWeixin","id",memberId); | ||
| 91 | return this.userWeixinMapper.toDto(userWeixin); | ||
| 92 | } | ||
| 93 | |||
| 94 | @Override | ||
| 95 | public UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId(String unionId, String appId, String openId) { | ||
| 96 | UserWeixin userWeixin = this.userWeixinRepository.findFirstByUnionidAndAppidAndOpenid(unionId, appId,openId).orElseGet(UserWeixin::new); | ||
| 97 | return this.userWeixinMapper.toDto(userWeixin); | ||
| 122 | } | 98 | } |
| 123 | 99 | ||
| 124 | @Override | 100 | @Override |
| 125 | public UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) { | 101 | public UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) { |
| 126 | UserWeixin userWeixin = this.UserWeixinRepository.findFirstByAppidAndOpenid(appId,openId).orElseGet(UserWeixin::new); | 102 | UserWeixin userWeixin = this.userWeixinRepository.findFirstByAppidAndOpenid(appId,openId).orElseGet(UserWeixin::new); |
| 127 | return UserWeixinMapper.toDto(userWeixin); | 103 | return this.userWeixinMapper.toDto(userWeixin); |
| 104 | } | ||
| 105 | |||
| 106 | @Override | ||
| 107 | public UserWeixinDTO findFirstByUnionId(String unionid) { | ||
| 108 | UserWeixin userWeixin = this.userWeixinRepository.findFirstByUnionid(unionid).orElseGet(UserWeixin::new); | ||
| 109 | return this.userWeixinMapper.toDto(userWeixin); | ||
| 128 | } | 110 | } |
| 129 | 111 | ||
| 112 | @Override | ||
| 113 | public UserWeixinDTO findFirstByUnionidAndAppid(String unionid, String appId) { | ||
| 114 | UserWeixin userWeixin = this.userWeixinRepository.findFirstByUnionidAndAppid(unionid,appId).orElseGet(UserWeixin::new); | ||
| 115 | return this.userWeixinMapper.toDto(userWeixin); | ||
| 116 | } | ||
| 130 | 117 | ||
| 131 | } | 118 | } | ... | ... |
| 1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.process.domian.TempCoupon; | ||
| 4 | |||
| 5 | import java.util.List; | ||
| 6 | |||
| 7 | /** | 3 | /** |
| 8 | * @description 权益操作接口 | 4 | * @description 权益操作接口 |
| 9 | * @author XiangHan | 5 | * @author XiangHan |
| ... | @@ -12,15 +8,4 @@ import java.util.List; | ... | @@ -12,15 +8,4 @@ import java.util.List; |
| 12 | 8 | ||
| 13 | public interface CouponOperationService { | 9 | public interface CouponOperationService { |
| 14 | 10 | ||
| 15 | /** | ||
| 16 | * 基于已完成的任务发放优惠券 | ||
| 17 | * @param tempCouponList | ||
| 18 | */ | ||
| 19 | void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * 系统手动发放优惠券 | ||
| 23 | * @param tempCouponList | ||
| 24 | */ | ||
| 25 | void grantCouponByManual(List<TempCoupon> tempCouponList); | ||
| 26 | } | 11 | } | ... | ... |
| ... | @@ -11,20 +11,5 @@ import java.util.List; | ... | @@ -11,20 +11,5 @@ import java.util.List; |
| 11 | */ | 11 | */ |
| 12 | public interface ExpOperationService { | 12 | public interface ExpOperationService { |
| 13 | 13 | ||
| 14 | /** | ||
| 15 | * 任务完成后自动发放成长值 | ||
| 16 | * @param tempExpList | ||
| 17 | */ | ||
| 18 | void grantPointsThroughTempExp(List<TempExp> tempExpList); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * 系统手动发放优惠券 | ||
| 22 | * @param memberId | ||
| 23 | * @param userId | ||
| 24 | * @param tempExpList | ||
| 25 | */ | ||
| 26 | void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList); | ||
| 27 | |||
| 28 | void grantExpByManual(List<TempExp> tempExpList); | ||
| 29 | 14 | ||
| 30 | } | 15 | } | ... | ... |
| 1 | package com.topdraw.business.process.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 5 | |||
| 6 | public interface MemberOperationService { | ||
| 7 | |||
| 8 | void doUpdateMemberInfo(Member member); | ||
| 9 | |||
| 10 | void doInsertMember(Member member); | ||
| 11 | |||
| 12 | MemberDTO findById(Long memberId); | ||
| 13 | |||
| 14 | void doUpdateMemberExp(Member member); | ||
| 15 | |||
| 16 | void doUpdateMemberPoints(Member member); | ||
| 17 | |||
| 18 | void doUpdateMemberCoupon(Member member); | ||
| 19 | } |
| 1 | package com.topdraw.business.process.service; | 1 | package com.topdraw.business.process.service; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.process.domian.TempPoints; | ||
| 4 | |||
| 5 | import java.util.List; | ||
| 6 | |||
| 7 | /** | 3 | /** |
| 8 | * @description 积分操作接口 | 4 | * @description 积分操作接口 |
| 9 | * @author XiangHan | 5 | * @author XiangHan |
| ... | @@ -11,38 +7,4 @@ import java.util.List; | ... | @@ -11,38 +7,4 @@ import java.util.List; |
| 11 | */ | 7 | */ |
| 12 | public interface PointsOperationService { | 8 | public interface PointsOperationService { |
| 13 | 9 | ||
| 14 | /** | ||
| 15 | * 手动发放积分 | ||
| 16 | * @param memberId 会员id | ||
| 17 | * @param tempPoints 积分详情 | ||
| 18 | */ | ||
| 19 | void grantPointsByManual(Long memberId , TempPoints tempPoints); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * | ||
| 23 | * @param tempPoints | ||
| 24 | */ | ||
| 25 | void grantPointsByManualByTempPoints(TempPoints tempPoints); | ||
| 26 | |||
| 27 | |||
| 28 | /** | ||
| 29 | * 积分扣减 | ||
| 30 | * @param tempPoints 积分对象 | ||
| 31 | */ | ||
| 32 | boolean customPoints(TempPoints tempPoints); | ||
| 33 | |||
| 34 | |||
| 35 | /** | ||
| 36 | * 积分发放,基于已获得的权益 | ||
| 37 | * @param tempPointsList 已获得的权益 | ||
| 38 | */ | ||
| 39 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); | ||
| 40 | |||
| 41 | |||
| 42 | /** | ||
| 43 | * 清理过期并计算可用总积分 | ||
| 44 | * @param memberId | ||
| 45 | * @return | ||
| 46 | */ | ||
| 47 | Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); | ||
| 48 | } | 10 | } | ... | ... |
| 1 | package com.topdraw.business.process.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | ||
| 4 | import com.topdraw.business.process.domian.RightType; | ||
| 5 | |||
| 6 | import java.util.List; | ||
| 7 | import java.util.Map; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @description 权益操作接口 | ||
| 11 | * @author XiangHan | ||
| 12 | * @date 2021.10.22 | ||
| 13 | */ | ||
| 14 | public interface RightsOperationService { | ||
| 15 | |||
| 16 | /** | ||
| 17 | * 系统手动发放权益 | ||
| 18 | * @param rightsHistories | ||
| 19 | */ | ||
| 20 | void grantRightsByManual(List<RightsHistory> rightsHistories); | ||
| 21 | |||
| 22 | /** | ||
| 23 | * 任务完成自动发放权益 | ||
| 24 | * @param tempRightsMap | ||
| 25 | */ | ||
| 26 | void grantRights(Map<RightType, Object> tempRightsMap); | ||
| 27 | } |
| 1 | package com.topdraw.business.process.service; | ||
| 2 | |||
| 3 | |||
| 4 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @description 权益操作接口 | ||
| 8 | * @author XiangHan | ||
| 9 | * @date 2021.10.22 | ||
| 10 | */ | ||
| 11 | public interface TaskTemplateOperationService { | ||
| 12 | |||
| 13 | |||
| 14 | TaskTemplateDTO findByCode(String code); | ||
| 15 | } |
| 1 | package com.topdraw.business.process.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 4 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | import java.io.Serializable; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/23 9:48 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/23 9:48 | ||
| 19 | */ | ||
| 20 | |||
| 21 | @Data | ||
| 22 | @AllArgsConstructor | ||
| 23 | @NoArgsConstructor | ||
| 24 | public class MemberAndUserTvDTO implements Serializable { | ||
| 25 | |||
| 26 | private MemberDTO memberDTO; | ||
| 27 | private UserTvDTO userTvDTO; | ||
| 28 | } |
| 1 | package com.topdraw.business.process.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 4 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | import java.io.Serializable; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/23 9:48 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/23 9:48 | ||
| 19 | */ | ||
| 20 | |||
| 21 | @Data | ||
| 22 | @AllArgsConstructor | ||
| 23 | @NoArgsConstructor | ||
| 24 | public class MemberAndWeixinUserDTO implements Serializable { | ||
| 25 | |||
| 26 | private MemberDTO memberDTO; | ||
| 27 | private UserWeixinDTO userWeixinDTO; | ||
| 28 | |||
| 29 | } |
| 1 | package com.topdraw.business.process.service.dto; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | ||
| 4 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 5 | import lombok.AllArgsConstructor; | ||
| 6 | import lombok.Data; | ||
| 7 | import lombok.NoArgsConstructor; | ||
| 8 | |||
| 9 | import java.io.Serializable; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/23 9:48 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/23 9:48 | ||
| 19 | */ | ||
| 20 | |||
| 21 | @Data | ||
| 22 | @AllArgsConstructor | ||
| 23 | @NoArgsConstructor | ||
| 24 | public class MemberProfileAndMemberDTO implements Serializable { | ||
| 25 | |||
| 26 | private MemberProfileDTO memberProfileDTO; | ||
| 27 | private MemberDTO memberDTO; | ||
| 28 | } |
| ... | @@ -6,196 +6,33 @@ import com.topdraw.business.module.coupon.service.CouponService; | ... | @@ -6,196 +6,33 @@ import com.topdraw.business.module.coupon.service.CouponService; |
| 6 | import com.topdraw.business.module.member.domain.Member; | 6 | import com.topdraw.business.module.member.domain.Member; |
| 7 | import com.topdraw.business.module.member.service.MemberService; | 7 | import com.topdraw.business.module.member.service.MemberService; |
| 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 9 | import com.topdraw.business.process.domian.TempCoupon; | ||
| 10 | import com.topdraw.business.process.service.CouponOperationService; | 9 | import com.topdraw.business.process.service.CouponOperationService; |
| 11 | import com.topdraw.business.process.service.MemberOperationService; | 10 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 12 | import com.topdraw.business.process.service.RightsOperationService; | ||
| 13 | import com.topdraw.util.RedissonUtil; | ||
| 14 | import org.redisson.api.RLock; | ||
| 15 | import org.redisson.api.RedissonClient; | ||
| 16 | import org.slf4j.Logger; | ||
| 17 | import org.slf4j.LoggerFactory; | ||
| 18 | import org.springframework.beans.BeanUtils; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 21 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 22 | 13 | ||
| 23 | import java.time.LocalDateTime; | ||
| 24 | import java.util.List; | ||
| 25 | import java.util.Objects; | ||
| 26 | |||
| 27 | |||
| 28 | @Service | 14 | @Service |
| 29 | public class CouponOperationServiceImpl implements CouponOperationService { | 15 | public class CouponOperationServiceImpl implements CouponOperationService { |
| 30 | 16 | ||
| 31 | private static final Logger LOG = LoggerFactory.getLogger(CouponOperationServiceImpl.class); | ||
| 32 | |||
| 33 | @Autowired | ||
| 34 | CouponService couponService; | ||
| 35 | @Autowired | ||
| 36 | CouponHistoryService couponHistoryService; | ||
| 37 | @Autowired | 17 | @Autowired |
| 38 | MemberOperationService memberOperationService; | 18 | private CouponHistoryService couponHistoryService; |
| 39 | @Autowired | 19 | @Autowired |
| 40 | RightsOperationService rightsOperationService; | 20 | private MemberOperationService memberOperationService; |
| 41 | @Autowired | 21 | @Autowired |
| 42 | MemberService memberService; | 22 | private MemberService memberService; |
| 43 | @Autowired | ||
| 44 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 45 | |||
| 46 | // 过期阀值(默认一个月) | ||
| 47 | private static final Integer EXPIRE_FACTOR_DAY = 30; | ||
| 48 | |||
| 49 | @Override | ||
| 50 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { | ||
| 51 | // 优惠券领取、使用历史记录表 | ||
| 52 | for (TempCoupon tempCoupon : tempCouponList) { | ||
| 53 | this.refresh(tempCoupon); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | /** | ||
| 58 | * 手动发放优惠券 | ||
| 59 | * @param tempCouponList | ||
| 60 | */ | ||
| 61 | @Override | ||
| 62 | public void grantCouponByManual(List<TempCoupon> tempCouponList) { | ||
| 63 | // 优惠券领取、使用历史记录表 | ||
| 64 | for (TempCoupon tempCoupon : tempCouponList) { | ||
| 65 | this.refresh(tempCoupon); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | /** | ||
| 71 | * 优惠券领取历史记录表 | ||
| 72 | * | ||
| 73 | * @param tempCoupon 领取的优惠券 | ||
| 74 | */ | ||
| 75 | private void refresh(TempCoupon tempCoupon) { | ||
| 76 | // 1.更新会员优惠券数量 | ||
| 77 | this.refreshMemberCoupon(tempCoupon); | ||
| 78 | // 2.保存优惠券领取、使用历史记录表 | ||
| 79 | this.doInsertCouponHistory(tempCoupon); | ||
| 80 | } | ||
| 81 | |||
| 82 | 23 | ||
| 83 | /** | 24 | public void asyncMemberCoupon(Member member) { |
| 84 | * 更新会员优惠券信息 | 25 | String memberCode = member.getCode(); |
| 85 | * @param tempCoupon 账号id | 26 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
| 86 | */ | 27 | member.setId(memberDTO.getId()); |
| 87 | private void refreshMemberCoupon(TempCoupon tempCoupon) { | 28 | this.memberOperationService.doUpdateMember(member); |
| 88 | // Long userId = tempCoupon.getUserId(); | ||
| 89 | Long memberId = tempCoupon.getMemberId(); | ||
| 90 | Integer rightsAmount = tempCoupon.getRightsAmount(); | ||
| 91 | try { | ||
| 92 | // 1.历史总优惠券数量 | ||
| 93 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); | ||
| 94 | // 1.当前总优惠券数量 | ||
| 95 | Long totalCouponCount = this.getTotalCoupon(historyCouponCount,rightsAmount); | ||
| 96 | // 2.获取已过期的优惠券数量 | ||
| 97 | Long expireCouponCount = this.getTotalExpireCoupon(memberId); | ||
| 98 | // 3.即将过期的优惠券数量 | ||
| 99 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId,EXPIRE_FACTOR_DAY); | ||
| 100 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 | ||
| 101 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); | ||
| 102 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) | ||
| 103 | this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount); | ||
| 104 | } catch (Exception e) { | ||
| 105 | e.printStackTrace(); | ||
| 106 | throw e; | ||
| 107 | } | ||
| 108 | } | 29 | } |
| 109 | 30 | ||
| 110 | private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) { | 31 | public void asyncCouponHistory(CouponHistory couponHistory) { |
| 111 | return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); | 32 | String memberCode = couponHistory.getMemberCode(); |
| 112 | } | 33 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
| 113 | 34 | couponHistory.setUserId(memberDTO.getId()); | |
| 114 | |||
| 115 | /** | ||
| 116 | * 更新当前用户优惠券信息 | ||
| 117 | * @param memberId | ||
| 118 | * @param currentCoupon | ||
| 119 | * @param expireSoonCouponCount | ||
| 120 | */ | ||
| 121 | private void doUpdateMemberInfo(Long memberId, Long currentCoupon, Long expireSoonCouponCount) { | ||
| 122 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | ||
| 123 | 35 | ||
| 124 | Member member = new Member(); | ||
| 125 | BeanUtils.copyProperties(memberDTO,member); | ||
| 126 | |||
| 127 | member.setCouponAmount(currentCoupon); | ||
| 128 | member.setDueCouponAmount(expireSoonCouponCount); | ||
| 129 | member.setUpdateTime(LocalDateTime.now()); | ||
| 130 | this.memberOperationService.doUpdateMemberInfo(member); | ||
| 131 | } | ||
| 132 | |||
| 133 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
| 134 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 135 | return memberDTO; | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | /** | ||
| 141 | * 当前优惠券数量 = 总优惠券-已过期的优惠券 | ||
| 142 | * @param totalCouponCount 总数 | ||
| 143 | * @param expireCouponCount 已过期总数 | ||
| 144 | * @return | ||
| 145 | */ | ||
| 146 | private Long getCurrentCoupon(Long totalCouponCount, Long expireCouponCount) { | ||
| 147 | return (Objects.nonNull(totalCouponCount)?totalCouponCount:0L)-(Objects.nonNull(expireCouponCount)?expireCouponCount:0L); | ||
| 148 | } | ||
| 149 | |||
| 150 | |||
| 151 | /** | ||
| 152 | * 即将过期的优惠券数量 | ||
| 153 | * @param expireFactor | ||
| 154 | * @return | ||
| 155 | */ | ||
| 156 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | ||
| 157 | LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor); | ||
| 158 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),expireTime); | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | /** | ||
| 163 | * 获取已过期的优惠券数量 | ||
| 164 | * @param userId | ||
| 165 | * @return | ||
| 166 | */ | ||
| 167 | private Long getTotalExpireCoupon(Long userId) { | ||
| 168 | return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId,LocalDateTime.now()); | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | /** | ||
| 173 | * 获取用户领取的总优惠券 | ||
| 174 | * @param userId | ||
| 175 | * @return | ||
| 176 | */ | ||
| 177 | private Long getTotalHistoryCoupon(Long userId) { | ||
| 178 | return this.couponHistoryService.countByUserId(userId); | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | /** | ||
| 183 | * 优惠券领取、使用历史记录表 | ||
| 184 | * @param tempCoupon 优惠券 | ||
| 185 | */ | ||
| 186 | private void doInsertCouponHistory(TempCoupon tempCoupon) { | ||
| 187 | CouponHistory couponHistory = new CouponHistory(); | ||
| 188 | BeanUtils.copyProperties(tempCoupon,couponHistory); | ||
| 189 | couponHistory.setId(null); | ||
| 190 | couponHistory.setCouponId(tempCoupon.getId()); | ||
| 191 | couponHistory.setUserId(tempCoupon.getMemberId()); | ||
| 192 | couponHistory.setCouponCode(tempCoupon.getCode()); | ||
| 193 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); | ||
| 194 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); | ||
| 195 | couponHistory.setReceiveTime(LocalDateTime.now()); | ||
| 196 | couponHistory.setUseStatus(Objects.nonNull(couponHistory.getUseStatus()) ? couponHistory.getUseStatus():0); | ||
| 197 | this.couponHistoryService.create(couponHistory); | 36 | this.couponHistoryService.create(couponHistory); |
| 198 | } | 37 | } |
| 199 | |||
| 200 | |||
| 201 | } | 38 | } | ... | ... |
| ... | @@ -4,28 +4,13 @@ import com.topdraw.business.module.exp.detail.domain.ExpDetail; | ... | @@ -4,28 +4,13 @@ import com.topdraw.business.module.exp.detail.domain.ExpDetail; |
| 4 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; | 4 | import com.topdraw.business.module.exp.detail.service.ExpDetailService; |
| 5 | import com.topdraw.business.module.member.domain.Member; | 5 | import com.topdraw.business.module.member.domain.Member; |
| 6 | import com.topdraw.business.module.member.level.service.MemberLevelService; | 6 | import com.topdraw.business.module.member.level.service.MemberLevelService; |
| 7 | import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; | ||
| 8 | import com.topdraw.business.module.member.service.MemberService; | 7 | import com.topdraw.business.module.member.service.MemberService; |
| 9 | import com.topdraw.business.module.member.service.dto.MemberDTO; | 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; |
| 10 | import com.topdraw.business.process.domian.TempExp; | ||
| 11 | import com.topdraw.business.process.service.ExpOperationService; | 9 | import com.topdraw.business.process.service.ExpOperationService; |
| 12 | import com.topdraw.business.process.service.MemberOperationService; | 10 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 13 | import com.topdraw.util.IdWorker; | ||
| 14 | import com.topdraw.util.RedissonUtil; | ||
| 15 | import com.topdraw.utils.StringUtils; | ||
| 16 | import org.redisson.api.RLock; | ||
| 17 | import org.redisson.api.RedissonClient; | ||
| 18 | import org.slf4j.Logger; | ||
| 19 | import org.slf4j.LoggerFactory; | ||
| 20 | import org.springframework.beans.BeanUtils; | ||
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 12 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 23 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 24 | import org.springframework.util.CollectionUtils; | ||
| 25 | |||
| 26 | import java.time.LocalDateTime; | ||
| 27 | import java.util.List; | ||
| 28 | import java.util.Objects; | ||
| 29 | 14 | ||
| 30 | /** | 15 | /** |
| 31 | * | 16 | * |
| ... | @@ -33,180 +18,30 @@ import java.util.Objects; | ... | @@ -33,180 +18,30 @@ import java.util.Objects; |
| 33 | @Service | 18 | @Service |
| 34 | public class ExpOperationServiceImpl implements ExpOperationService { | 19 | public class ExpOperationServiceImpl implements ExpOperationService { |
| 35 | 20 | ||
| 36 | private static final Logger LOG = LoggerFactory.getLogger(ExpOperationServiceImpl.class); | ||
| 37 | |||
| 38 | @Autowired | 21 | @Autowired |
| 39 | ExpDetailService expDetailService; | 22 | private ExpDetailService expDetailService; |
| 40 | @Autowired | 23 | @Autowired |
| 41 | MemberOperationService memberOperationService; | 24 | private MemberOperationService memberOperationService; |
| 42 | @Autowired | 25 | @Autowired |
| 43 | MemberLevelService memberLevelService; | 26 | private MemberLevelService memberLevelService; |
| 44 | @Autowired | 27 | @Autowired |
| 45 | MemberService memberService; | 28 | private MemberService memberService; |
| 46 | @Autowired | 29 | @Autowired |
| 47 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 30 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 48 | 31 | ||
| 49 | @Override | 32 | public void asyncMemberExpAndLevel(Member member) { |
| 50 | public void grantPointsThroughTempExp(List<TempExp> tempExpList) { | 33 | String code = member.getCode(); |
| 51 | 34 | MemberDTO memberDTO = this.memberService.findByCode(code); | |
| 52 | for (TempExp tempExp : tempExpList) { | 35 | member.setId(memberDTO.getId()); |
| 53 | this.refresh(tempExp); | ||
| 54 | } | ||
| 55 | |||
| 56 | } | ||
| 57 | |||
| 58 | @Override | ||
| 59 | public void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList) { | ||
| 60 | for (TempExp tempExp : tempExpList) { | ||
| 61 | this.refresh(tempExp); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | @Override | ||
| 66 | public void grantExpByManual(List<TempExp> tempExpList) { | ||
| 67 | for (TempExp tempExp : tempExpList) { | ||
| 68 | this.refresh(tempExp); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | /** | ||
| 74 | * | ||
| 75 | * @param tempExp | ||
| 76 | */ | ||
| 77 | private void refresh(TempExp tempExp) { | ||
| 78 | String memberCode = tempExp.getMemberCode(); | ||
| 79 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 80 | Long id = memberDTO.getId(); | ||
| 81 | tempExp.setId(id); | ||
| 82 | try { | ||
| 83 | // 原始积分 | ||
| 84 | long originExp = this.getExpByMemberId(tempExp); | ||
| 85 | // 总积分 | ||
| 86 | long totalExp = this.calculateTotalExp(originExp, tempExp); | ||
| 87 | // 1.添加成长值记录 | ||
| 88 | // this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | ||
| 89 | // 2.更新成长值与等级 | ||
| 90 | this.refreshMemberExpAndLevel(tempExp,totalExp); | ||
| 91 | |||
| 92 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
| 93 | 36 | ||
| 94 | } catch (Exception e) { | 37 | this.memberService.doUpdateMemberExpAndLevel(member); |
| 95 | e.printStackTrace(); | ||
| 96 | throw e; | ||
| 97 | } | ||
| 98 | } | 38 | } |
| 99 | 39 | ||
| 100 | private long calculateTotalExp(long originalExp, TempExp tempExp) { | 40 | public void asyncExpDetail(ExpDetail expDetail) { |
| 101 | Long rewardExp = tempExp.getRewardExp(); | 41 | String code = expDetail.getMemberCode(); |
| 102 | return rewardExp + originalExp; | 42 | MemberDTO memberDTO = this.memberService.findByCode(code); |
| 103 | } | 43 | expDetail.setMemberId(memberDTO.getId()); |
| 104 | 44 | ||
| 105 | private long getExpByMemberId(TempExp tempExp) { | ||
| 106 | Long memberId = tempExp.getMemberId(); | ||
| 107 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | ||
| 108 | if (Objects.nonNull(memberDTO)) { | ||
| 109 | Long exp = memberDTO.getExp(); | ||
| 110 | return Objects.isNull(exp) ? 0L : exp; | ||
| 111 | } | ||
| 112 | return 0L; | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | /** | ||
| 117 | * 更新成长值与等级 | ||
| 118 | * | ||
| 119 | * @param tempExp 成长值列表 | ||
| 120 | */ | ||
| 121 | private void refreshMemberExpAndLevel(TempExp tempExp, long totalExp) { | ||
| 122 | |||
| 123 | Long memberId = tempExp.getMemberId(); | ||
| 124 | // 1.获取当前成长值 | ||
| 125 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | ||
| 126 | // 2.获取下一级需要的成长值 | ||
| 127 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); | ||
| 128 | // 4.成长值比较,判断是否升级 | ||
| 129 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); | ||
| 130 | // 5.更新用户信息 | ||
| 131 | this.updateMemberInfo(level, totalExp, memberId); | ||
| 132 | } | ||
| 133 | |||
| 134 | /** | ||
| 135 | * | ||
| 136 | * @param level | ||
| 137 | * @param totalExp 总积分 | ||
| 138 | * @param memberId 会员id | ||
| 139 | */ | ||
| 140 | private void updateMemberInfo(Integer level,Long totalExp,Long memberId) { | ||
| 141 | MemberDTO memberDTO = this.findMemberByMemberId(memberId); | ||
| 142 | |||
| 143 | Member member = new Member(); | ||
| 144 | BeanUtils.copyProperties(memberDTO,member); | ||
| 145 | |||
| 146 | member.setExp(totalExp); | ||
| 147 | member.setLevel(level); | ||
| 148 | member.setUpdateTime(LocalDateTime.now()); | ||
| 149 | this.memberOperationService.doUpdateMemberInfo(member); | ||
| 150 | } | ||
| 151 | |||
| 152 | private MemberDTO findMemberByMemberId(Long memberId) { | ||
| 153 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 154 | return memberDTO; | ||
| 155 | } | ||
| 156 | |||
| 157 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, MemberDTO memberDTO) { | ||
| 158 | if (Objects.nonNull(memberLevelDTO)) { | ||
| 159 | Long nextLevelExp = memberLevelDTO.getExpValue(); | ||
| 160 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | ||
| 161 | if(newExp - nextLevelExp >= 0){ | ||
| 162 | return memberLevelDTO.getLevel(); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | return memberDTO.getLevel(); | ||
| 166 | } | ||
| 167 | |||
| 168 | private MemberLevelDTO getNextLevelExp(Integer i, Integer status) { | ||
| 169 | List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i,status); | ||
| 170 | if (!CollectionUtils.isEmpty(memberLevelDTOList)) { | ||
| 171 | return memberLevelDTOList.get(0); | ||
| 172 | } | ||
| 173 | return null; | ||
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | /** | ||
| 178 | * 获取当前会员的成长值 | ||
| 179 | * @param memberId 会员id | ||
| 180 | * @return Long 当前会员成长值 | ||
| 181 | */ | ||
| 182 | private MemberDTO getMemberInfoByMemberId(Long memberId) { | ||
| 183 | MemberDTO memberDTO = this.memberOperationService.findById(memberId); | ||
| 184 | return memberDTO; | ||
| 185 | } | ||
| 186 | |||
| 187 | /** | ||
| 188 | * 添加成长值记录 | ||
| 189 | * | ||
| 190 | * @param tempExp 成长值列表 | ||
| 191 | */ | ||
| 192 | private void doInsertExpDetail(TempExp tempExp, long originalExp, long totalExp) { | ||
| 193 | // 获得的积分 | ||
| 194 | Long rewardExp = tempExp.getRewardExp(); | ||
| 195 | |||
| 196 | ExpDetail expDetail = new ExpDetail(); | ||
| 197 | BeanUtils.copyProperties(tempExp,expDetail); | ||
| 198 | |||
| 199 | expDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 200 | // 原始积分 | ||
| 201 | expDetail.setOriginalExp(originalExp); | ||
| 202 | // 总积分 | ||
| 203 | expDetail.setResultExp(totalExp); | ||
| 204 | // 获得的积分 | ||
| 205 | expDetail.setExp(rewardExp); | ||
| 206 | if (StringUtils.isEmpty(expDetail.getDescription())) { | ||
| 207 | expDetail.setDescription("#"); | ||
| 208 | } | ||
| 209 | this.expDetailService.create(expDetail); | 45 | this.expDetailService.create(expDetail); |
| 210 | } | 46 | } |
| 211 | |||
| 212 | } | 47 | } | ... | ... |
src/main/java/com/topdraw/business/process/service/impl/MemberOperationServiceImpl.java
deleted
100644 → 0
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.service.MemberService; | ||
| 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 6 | import com.topdraw.business.process.service.MemberOperationService; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Service; | ||
| 9 | import org.springframework.util.Assert; | ||
| 10 | |||
| 11 | import java.util.Objects; | ||
| 12 | |||
| 13 | @Service | ||
| 14 | public class MemberOperationServiceImpl implements MemberOperationService { | ||
| 15 | |||
| 16 | @Autowired | ||
| 17 | MemberService memberService; | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public void doUpdateMemberInfo(Member member) { | ||
| 21 | Long id = member.getId(); | ||
| 22 | Assert.notNull(id,"ERROR MSG: MemberOperationServiceImpl -> doUpdateMemberInfo -> id not be null!!"); | ||
| 23 | this.memberService.update(member); | ||
| 24 | } | ||
| 25 | |||
| 26 | @Override | ||
| 27 | public void doInsertMember(Member member) { | ||
| 28 | this.memberService.create(member); | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | public MemberDTO findById(Long memberId) { | ||
| 33 | return Objects.nonNull(memberId) ? this.memberService.findById(memberId) : null; | ||
| 34 | } | ||
| 35 | |||
| 36 | @Override | ||
| 37 | public void doUpdateMemberExp(Member member) { | ||
| 38 | this.doUpdateMemberInfo(member); | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public void doUpdateMemberPoints(Member member) { | ||
| 43 | this.memberService.doUpdateMemberPoints(member); | ||
| 44 | } | ||
| 45 | |||
| 46 | @Override | ||
| 47 | public void doUpdateMemberCoupon(Member member) { | ||
| 48 | this.doUpdateMemberInfo(member); | ||
| 49 | } | ||
| 50 | } |
| ... | @@ -12,17 +12,12 @@ import com.topdraw.business.module.points.detail.domain.PointsDetail; | ... | @@ -12,17 +12,12 @@ import com.topdraw.business.module.points.detail.domain.PointsDetail; |
| 12 | import com.topdraw.business.module.points.detail.service.PointsDetailService; | 12 | import com.topdraw.business.module.points.detail.service.PointsDetailService; |
| 13 | import com.topdraw.business.module.points.service.PointsService; | 13 | import com.topdraw.business.module.points.service.PointsService; |
| 14 | import com.topdraw.business.process.domian.TempPoints; | 14 | import com.topdraw.business.process.domian.TempPoints; |
| 15 | import com.topdraw.business.process.service.MemberOperationService; | ||
| 16 | import com.topdraw.business.process.service.PointsOperationService; | 15 | import com.topdraw.business.process.service.PointsOperationService; |
| 16 | import com.topdraw.business.process.service.member.MemberOperationService; | ||
| 17 | import com.topdraw.util.IdWorker; | 17 | import com.topdraw.util.IdWorker; |
| 18 | import com.topdraw.util.RedissonUtil; | ||
| 19 | import com.topdraw.util.TimestampUtil; | 18 | import com.topdraw.util.TimestampUtil; |
| 20 | import com.topdraw.utils.StringUtils; | 19 | import com.topdraw.utils.StringUtils; |
| 21 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
| 22 | import org.redisson.api.RLock; | ||
| 23 | import org.redisson.api.RedissonClient; | ||
| 24 | import org.slf4j.Logger; | ||
| 25 | import org.slf4j.LoggerFactory; | ||
| 26 | import org.springframework.beans.BeanUtils; | 21 | import org.springframework.beans.BeanUtils; |
| 27 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 28 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 23 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| ... | @@ -31,7 +26,7 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -31,7 +26,7 @@ import org.springframework.transaction.annotation.Propagation; |
| 31 | import org.springframework.transaction.annotation.Transactional; | 26 | import org.springframework.transaction.annotation.Transactional; |
| 32 | import org.springframework.util.CollectionUtils; | 27 | import org.springframework.util.CollectionUtils; |
| 33 | 28 | ||
| 34 | import java.sql.Timestamp; | 29 | import javax.validation.constraints.NotNull; |
| 35 | import java.time.LocalDateTime; | 30 | import java.time.LocalDateTime; |
| 36 | import java.util.*; | 31 | import java.util.*; |
| 37 | import java.util.stream.Collectors; | 32 | import java.util.stream.Collectors; |
| ... | @@ -44,535 +39,39 @@ import java.util.stream.Collectors; | ... | @@ -44,535 +39,39 @@ import java.util.stream.Collectors; |
| 44 | @Slf4j | 39 | @Slf4j |
| 45 | public class PointsOperationServiceImpl implements PointsOperationService { | 40 | public class PointsOperationServiceImpl implements PointsOperationService { |
| 46 | 41 | ||
| 47 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); | ||
| 48 | |||
| 49 | @Autowired | ||
| 50 | PointsService pointsService; | ||
| 51 | @Autowired | ||
| 52 | PointsDetailService pointsDetailService; | ||
| 53 | @Autowired | 42 | @Autowired |
| 54 | PointsAvailableService pointsAvailableService; | 43 | private PointsDetailService pointsDetailService; |
| 55 | @Autowired | 44 | @Autowired |
| 56 | PointsDetailHistoryService pointsDetailHistoryService; | 45 | private PointsAvailableService pointsAvailableService; |
| 57 | @Autowired | 46 | @Autowired |
| 58 | MemberOperationService memberOperationService; | 47 | private MemberService memberService; |
| 59 | @Autowired | ||
| 60 | MemberService memberService; | ||
| 61 | |||
| 62 | // 过期阈值 30天 | ||
| 63 | private static final Integer EXPIRE_FACTOR = 30; | ||
| 64 | |||
| 65 | private static final String DELETE_AVAILABLE_POINTS = "delete"; | ||
| 66 | private static final String INSERT_AVAILABLE_POINTS = "insert"; | ||
| 67 | @Autowired | 48 | @Autowired |
| 68 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 69 | 50 | ||
| 70 | @Override | 51 | public void asyncMemberPoint(Member member) { |
| 71 | @Transactional(rollbackFor = Exception.class) | 52 | String code = member.getCode(); |
| 72 | public void grantPointsByManual(Long memberId,TempPoints tempPoints){ | 53 | MemberDTO memberDTO = this.memberService.findByCode(code); |
| 73 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { | 54 | member.setId(memberDTO.getId()); |
| 74 | this.refresh(tempPoints); | 55 | this.memberService.doUpdateMemberPoints(member); |
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | @Transactional(rollbackFor = Exception.class) | ||
| 80 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { | ||
| 81 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { | ||
| 82 | String memberCode = tempPoints.getMemberCode(); | ||
| 83 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 84 | if (Objects.nonNull(memberDTO)) { | ||
| 85 | Long memberId = memberDTO.getId(); | ||
| 86 | tempPoints.setMemberId(memberId); | ||
| 87 | this.refresh(tempPoints); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | /** | ||
| 94 | * 积分消耗 | ||
| 95 | * @param tempPoints 任务对象 | ||
| 96 | * @return true: 满足 false:不满足 | ||
| 97 | */ | ||
| 98 | @Override | ||
| 99 | @Transactional(rollbackFor = Exception.class) | ||
| 100 | public boolean customPoints(TempPoints tempPoints) { | ||
| 101 | |||
| 102 | String memberCode = tempPoints.getMemberCode(); | ||
| 103 | |||
| 104 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 105 | |||
| 106 | if (Objects.nonNull(memberDTO)) { | ||
| 107 | |||
| 108 | Long memberId = memberDTO.getId(); | ||
| 109 | tempPoints.setMemberId(memberId); | ||
| 110 | try { | ||
| 111 | //1.删除过期的积分 | ||
| 112 | this.cleanInvalidAvailablePointsByMemberId(memberId); | ||
| 113 | // 1.判断可用积分是否够用 | ||
| 114 | boolean b = this.checkAvailablePoints(tempPoints); | ||
| 115 | log.info("customPoints-->>> 当前可用总积分大于待兑换的积分--->>" + b); | ||
| 116 | if (b) { | ||
| 117 | // 2.可用积分表,按照过期时间进行升序排列 | ||
| 118 | List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints); | ||
| 119 | // 3.当前可用总积分 | ||
| 120 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 121 | // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 | ||
| 122 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = this.customAvailablePoints(tempPoints, pointsAvailableDTOS); | ||
| 123 | // 3.添加积分明细 | ||
| 124 | this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); | ||
| 125 | // 4.更新可用积分表,超过的删除,剩余的新增 | ||
| 126 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); | ||
| 127 | // 5.即将过期的积分 | ||
| 128 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
| 129 | // 6.更新会员积分信息 | ||
| 130 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints); | ||
| 131 | |||
| 132 | return true; | ||
| 133 | } | ||
| 134 | }catch (Exception e) { | ||
| 135 | e.printStackTrace(); | ||
| 136 | throw e; | ||
| 137 | } | ||
| 138 | |||
| 139 | } | ||
| 140 | |||
| 141 | return false; | ||
| 142 | } | ||
| 143 | |||
| 144 | /** | ||
| 145 | * 更新可用积分表 | ||
| 146 | * @param customAvailablePointsMap | ||
| 147 | */ | ||
| 148 | private long doFreshTrPointsAvailableByAvailablePointsMap( | ||
| 149 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap,long currentPoints) { | ||
| 150 | |||
| 151 | long totalCustomAvailablePoints = 0L; | ||
| 152 | if (customAvailablePointsMap != null) { | ||
| 153 | // 需要删除的 | ||
| 154 | List<PointsAvailableDTO> pointsAvailableDTOS1 = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); | ||
| 155 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS1)) { | ||
| 156 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS1) { | ||
| 157 | totalCustomAvailablePoints = (totalCustomAvailablePoints+pointsAvailableDTO.getPoints()); | ||
| 158 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | // 需要添加的 | ||
| 163 | List<PointsAvailableDTO> pointsAvailableDTOS2 = customAvailablePointsMap.get(INSERT_AVAILABLE_POINTS); | ||
| 164 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS2)) { | ||
| 165 | PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS2.get(0); | ||
| 166 | PointsAvailable pointsAvailable = new PointsAvailable(); | ||
| 167 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailable); | ||
| 168 | pointsAvailable.setId(null); | ||
| 169 | pointsAvailable.setCode(String.valueOf(IdWorker.generator())); | ||
| 170 | this.pointsAvailableService.create4Custom(pointsAvailable); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | return currentPoints - totalCustomAvailablePoints; | ||
| 175 | } | ||
| 176 | |||
| 177 | /** | ||
| 178 | * 优先使用即将过期的积分,注意拆分 | ||
| 179 | * @param customAvailablePointsMap | ||
| 180 | */ | ||
| 181 | private void doInsertTrPointsDetailByAvailablePointsMap(TempPoints tempPoints, | ||
| 182 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap, | ||
| 183 | long currentPoints) { | ||
| 184 | // 兑换的积分 | ||
| 185 | Long points = tempPoints.getPoints(); | ||
| 186 | |||
| 187 | List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); | ||
| 188 | |||
| 189 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | ||
| 190 | PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS.get(0); | ||
| 191 | Long memberId = pointsAvailableDTO.getMemberId(); | ||
| 192 | |||
| 193 | TempPoints tempPoints1 = new TempPoints(); | ||
| 194 | BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); | ||
| 195 | BeanUtils.copyProperties(tempPoints,tempPoints1); | ||
| 196 | tempPoints1.setPoints(-(Math.abs(points))); | ||
| 197 | Long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints); | ||
| 198 | this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | /** | ||
| 203 | * 消耗过期的积分 | ||
| 204 | * @param tempPoints 需要消耗的积分 | ||
| 205 | * @param pointsAvailableDTOS 可用积分列表 | ||
| 206 | * @return List<PointsAvailableDTO> 已消耗的可用积分列表 | ||
| 207 | */ | ||
| 208 | private Map<String,List<PointsAvailableDTO>> customAvailablePoints(TempPoints tempPoints, List<PointsAvailableDTO> pointsAvailableDTOS) { | ||
| 209 | // 兑换的积分 | ||
| 210 | Long points = tempPoints.getPoints(); | ||
| 211 | Long points1_ = 0L; | ||
| 212 | List<PointsAvailableDTO> pointsAvailableDTOS1 = new ArrayList<>(); | ||
| 213 | List<PointsAvailableDTO> pointsAvailableDTOS2 = new ArrayList<>(); | ||
| 214 | Map<String,List<PointsAvailableDTO>> map = new HashMap<>(); | ||
| 215 | |||
| 216 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | ||
| 217 | Long points1 = pointsAvailableDTO.getPoints(); | ||
| 218 | points1_ = (points1_ + points1); | ||
| 219 | |||
| 220 | // 不够 | ||
| 221 | if (points1_ < points) { | ||
| 222 | pointsAvailableDTOS1.add(pointsAvailableDTO); | ||
| 223 | continue; | ||
| 224 | } | ||
| 225 | |||
| 226 | // 刚好 | ||
| 227 | if (points1_ == points) { | ||
| 228 | pointsAvailableDTOS1.add(pointsAvailableDTO); | ||
| 229 | break; | ||
| 230 | } | ||
| 231 | |||
| 232 | // 超了,拆分 | ||
| 233 | if (points1_ > points) { | ||
| 234 | |||
| 235 | // 超过的 | ||
| 236 | long beyond = points1_ - points; | ||
| 237 | // 新增 | ||
| 238 | PointsAvailableDTO pointsAvailableDTO2 = new PointsAvailableDTO(); | ||
| 239 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO2); | ||
| 240 | pointsAvailableDTO2.setPoints(beyond); | ||
| 241 | pointsAvailableDTOS2.add(pointsAvailableDTO2); | ||
| 242 | |||
| 243 | // 剩余的 | ||
| 244 | long suit = points1 - beyond; | ||
| 245 | // 扣除 | ||
| 246 | PointsAvailableDTO pointsAvailableDTO1 = new PointsAvailableDTO(); | ||
| 247 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO1); | ||
| 248 | pointsAvailableDTO1.setPoints(suit); | ||
| 249 | pointsAvailableDTOS1.add(pointsAvailableDTO1); | ||
| 250 | |||
| 251 | break; | ||
| 252 | } | ||
| 253 | |||
| 254 | } | ||
| 255 | |||
| 256 | map.put(DELETE_AVAILABLE_POINTS,pointsAvailableDTOS1); | ||
| 257 | map.put(INSERT_AVAILABLE_POINTS,pointsAvailableDTOS2); | ||
| 258 | |||
| 259 | return map; | ||
| 260 | } | ||
| 261 | |||
| 262 | /** | ||
| 263 | * 可用积分表,按照过期时间进行升序排列 | ||
| 264 | * @param tempPoints | ||
| 265 | * @return | ||
| 266 | */ | ||
| 267 | private List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(TempPoints tempPoints) { | ||
| 268 | return this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId()); | ||
| 269 | } | ||
| 270 | |||
| 271 | /** | ||
| 272 | * 检查当前用户可用积分是否足够 | ||
| 273 | * @param tempPoints | ||
| 274 | * @return true : 满足 false: 不满足 | ||
| 275 | */ | ||
| 276 | private boolean checkAvailablePoints(TempPoints tempPoints) { | ||
| 277 | Long memberId = tempPoints.getMemberId(); | ||
| 278 | // 可用积分 | ||
| 279 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 280 | long points1 = tempPoints.getPoints(); | ||
| 281 | if (currentPoints > 0 && points1 > 0 && (currentPoints - Math.abs(points1) >= 0)) { | ||
| 282 | return true; | ||
| 283 | } | ||
| 284 | return false; | ||
| 285 | } | ||
| 286 | |||
| 287 | /** | ||
| 288 | * 积分发放,基于已获得的权益 | ||
| 289 | * | ||
| 290 | * @param tempPointsList 已获得的权益 | ||
| 291 | */ | ||
| 292 | @Override | ||
| 293 | @Transactional(rollbackFor = Exception.class) | ||
| 294 | public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){ | ||
| 295 | log.info("------->>grantPointsThroughTempRightsList start1"); | ||
| 296 | for (TempPoints tempPoints : tempPointsList){ | ||
| 297 | log.info("------->>grantPointsThroughTempRightsList start"); | ||
| 298 | this.refresh(tempPoints); | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | /** | ||
| 303 | * 清理过期积分 | ||
| 304 | * @param memberId | ||
| 305 | */ | ||
| 306 | private void cleanInvalidAvailablePointsByMemberId(Long memberId) { | ||
| 307 | List<PointsAvailableDTO> pointsAvailableDTOS = | ||
| 308 | pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,LocalDateTime.now()); | ||
| 309 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | ||
| 310 | //1.获取原始积分 | ||
| 311 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | ||
| 312 | // 添加积分明细 uc_points_detail | ||
| 313 | this.doCreatePointsDetail(pointsAvailableDTO); | ||
| 314 | // 删除已过期的积分 | ||
| 315 | this.doDeleteInvalidAvailablePoints(pointsAvailableDTO); | ||
| 316 | } | ||
| 317 | |||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | @Override | ||
| 322 | public Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId) { | ||
| 323 | |||
| 324 | // 清理当前用户的过期积分 | ||
| 325 | this.cleanInvalidAvailablePointsByMemberId(memberId); | ||
| 326 | // 获取当前用户的可用总积分 | ||
| 327 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 328 | // 即将过期的积分 | ||
| 329 | long soonExpirePoints = this.getSoonExpirePoints(memberId, null); | ||
| 330 | // 更新会员信息 | ||
| 331 | this.doUpdateMemberPoints(memberId,currentPoints,soonExpirePoints); | ||
| 332 | |||
| 333 | return currentPoints; | ||
| 334 | } | 56 | } |
| 335 | 57 | ||
| 336 | /** | 58 | public void asyncPointsAvailable(PointsAvailable pointsAvailable) { |
| 337 | * 获取可用总积分 | 59 | String memberCode = pointsAvailable.getMemberCode(); |
| 338 | * @param memberId | 60 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
| 339 | * @return | 61 | pointsAvailable.setMemberId(memberDTO.getId()); |
| 340 | */ | 62 | this.pointsAvailableService.create4Custom(pointsAvailable); |
| 341 | private long findAvailablePointsByMemberId(Long memberId){ | ||
| 342 | return this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
| 343 | } | 63 | } |
| 344 | 64 | ||
| 345 | /** | 65 | public void asyncPointsDetail(PointsDetail pointsDetail) { |
| 346 | * 修改会员信息 | 66 | String memberCode = pointsDetail.getMemberCode(); |
| 347 | * @param memberId | 67 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); |
| 348 | * @param currentPoints | 68 | pointsDetail.setMemberId(memberDTO.getId()); |
| 349 | */ | 69 | this.pointsDetailService.create4Custom(pointsDetail); |
| 350 | private void doUpdateMemberPoints(Long memberId, long currentPoints,long soonExpirePoints) { | ||
| 351 | Member member = new Member(); | ||
| 352 | member.setId(memberId); | ||
| 353 | member.setPoints(currentPoints); | ||
| 354 | member.setDuePoints(soonExpirePoints); | ||
| 355 | this.memberOperationService.doUpdateMemberPoints(member); | ||
| 356 | } | ||
| 357 | |||
| 358 | /** | ||
| 359 | * | ||
| 360 | * @param pointsAvailableDTOS | ||
| 361 | */ | ||
| 362 | private void doDeleteBatchInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) { | ||
| 363 | List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList()); | ||
| 364 | this.pointsAvailableService.deleteBatchByIds(collect); | ||
| 365 | } | 70 | } |
| 366 | 71 | ||
| 367 | /** | 72 | public void asyncDeletePointsAvailable(PointsAvailable pointsAvailable) { |
| 368 | * | 73 | String code = pointsAvailable.getCode(); |
| 369 | * @param pointsAvailableDTO | 74 | PointsAvailableDTO pointsAvailableDTO = this.pointsAvailableService.getByCode(code); |
| 370 | */ | ||
| 371 | private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) { | ||
| 372 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); | 75 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); |
| 373 | } | 76 | } |
| 374 | |||
| 375 | /** | ||
| 376 | * 可用积分 | ||
| 377 | * @param pointsAvailableDTO | ||
| 378 | */ | ||
| 379 | private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) { | ||
| 380 | |||
| 381 | Long memberId = pointsAvailableDTO.getMemberId(); | ||
| 382 | // 原始积分 | ||
| 383 | long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId); | ||
| 384 | // 过期积分 | ||
| 385 | long l = pointsAvailableDTO.getPoints(); | ||
| 386 | // 结果积分 | ||
| 387 | long resultPoints = availablePoints - l; | ||
| 388 | |||
| 389 | PointsDetail pointsDetail = new PointsDetail(); | ||
| 390 | BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail); | ||
| 391 | pointsDetail.setId(null); | ||
| 392 | pointsDetail.setPoints(-Math.abs(l)); | ||
| 393 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 394 | pointsDetail.setOriginalPoints(availablePoints); | ||
| 395 | pointsDetail.setResultPoints(resultPoints); | ||
| 396 | pointsDetail.setDescription("过期积分"); | ||
| 397 | pointsDetail.setEvtType(99); | ||
| 398 | pointsDetail.setCreateTime(TimestampUtil.now()); | ||
| 399 | pointsDetail.setUpdateTime(TimestampUtil.now()); | ||
| 400 | this.doInsertPointsDetail(pointsDetail); | ||
| 401 | } | ||
| 402 | |||
| 403 | /** | ||
| 404 | * 模板方法,提供更新积分的总体流程 | ||
| 405 | * | ||
| 406 | * @param tempPoints 积分 | ||
| 407 | */ | ||
| 408 | private void refresh(TempPoints tempPoints) { | ||
| 409 | Long memberId = tempPoints.getMemberId(); | ||
| 410 | log.info("----------->> points refresh start"); | ||
| 411 | log.info("----------->> rLock --->> start" ); | ||
| 412 | try { | ||
| 413 | log.info("----------->> refresh findAvailablePointsByMemberId start"); | ||
| 414 | // 1.可用总积分 | ||
| 415 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 416 | log.info("----------->> refresh findAvailablePointsByMemberId currentPoints " + currentPoints); | ||
| 417 | |||
| 418 | // 2.计算总积分 | ||
| 419 | Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); | ||
| 420 | log.info("----------->> refresh findAvailablePointsByMemberId totalPoints " + totalPoints); | ||
| 421 | |||
| 422 | // 3.添加积分明细,并计算总积分 | ||
| 423 | this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); | ||
| 424 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail end "); | ||
| 425 | |||
| 426 | // 4.添加可用积分 | ||
| 427 | log.info("----------->> refresh doInsertTrPointsAvailable start "); | ||
| 428 | this.doInsertTrPointsAvailable(tempPoints); | ||
| 429 | log.info("----------->> refresh doInsertTrPointsAvailable end "); | ||
| 430 | |||
| 431 | // 即将过期的积分 | ||
| 432 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
| 433 | |||
| 434 | // 6.更新会员的总积分 | ||
| 435 | log.info("----------->> refresh freshMemberCurrentPoints start "); | ||
| 436 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints); | ||
| 437 | log.info("----------->> refresh freshMemberCurrentPoints end "); | ||
| 438 | |||
| 439 | } catch (Exception e) { | ||
| 440 | e.printStackTrace(); | ||
| 441 | throw e; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | |||
| 445 | /** | ||
| 446 | * 获取总积分 | ||
| 447 | * @param tempPoints | ||
| 448 | * @param currentPoints | ||
| 449 | * @return | ||
| 450 | */ | ||
| 451 | private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) { | ||
| 452 | // 获取的积分 | ||
| 453 | Long rewardPoints = tempPoints.getPoints(); | ||
| 454 | // 总积分 | ||
| 455 | Long totalPoints = currentPoints + rewardPoints; | ||
| 456 | return totalPoints; | ||
| 457 | } | ||
| 458 | |||
| 459 | /** | ||
| 460 | * 获取即将过期的积分 | ||
| 461 | * @param memberId | ||
| 462 | * @return | ||
| 463 | */ | ||
| 464 | private long getSoonExpirePoints(Long memberId,TempPoints tempPoints) { | ||
| 465 | // 计算即将过期的天数 | ||
| 466 | Integer factor = this.calculateExpireFactor(tempPoints); | ||
| 467 | if (Objects.isNull(factor)) { | ||
| 468 | factor = EXPIRE_FACTOR; | ||
| 469 | } | ||
| 470 | |||
| 471 | Long soonExpireTime = this.pointsAvailableService.findSoonExpireTime(memberId, factor); | ||
| 472 | return Objects.nonNull(soonExpireTime) ? soonExpireTime : 0L; | ||
| 473 | } | ||
| 474 | |||
| 475 | /** | ||
| 476 | * 如果过期时间和过期天数同时存在,则以过期时间为准 | ||
| 477 | * @param tempPoints | ||
| 478 | * @return | ||
| 479 | */ | ||
| 480 | private Integer calculateExpireFactor(TempPoints tempPoints) { | ||
| 481 | // TODO 计算过期的相对时间 | ||
| 482 | return null; | ||
| 483 | } | ||
| 484 | |||
| 485 | /** | ||
| 486 | * 更新会员总积分 | ||
| 487 | * @param memberId 会员Id | ||
| 488 | * @param currentPoints 当前总积分 | ||
| 489 | */ | ||
| 490 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints,TempPoints tempPoints) { | ||
| 491 | Member member = new Member(); | ||
| 492 | member.setId(memberId); | ||
| 493 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); | ||
| 494 | member.setDuePoints(duePoints); | ||
| 495 | member.setUpdateTime(LocalDateTime.now()); | ||
| 496 | member.setCode(tempPoints.getMemberCode()); | ||
| 497 | try { | ||
| 498 | this.memberOperationService.doUpdateMemberPoints(member); | ||
| 499 | } catch (Exception e){ | ||
| 500 | throw e; | ||
| 501 | } | ||
| 502 | } | ||
| 503 | |||
| 504 | /** | ||
| 505 | * 计算当前总积分 | ||
| 506 | * @param memberId 会员id | ||
| 507 | * @return | ||
| 508 | */ | ||
| 509 | private Long findAvailablePointsByMemberId(long memberId){ | ||
| 510 | Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
| 511 | return Objects.nonNull(availablePoints) ? availablePoints : 0L; | ||
| 512 | } | ||
| 513 | |||
| 514 | /** | ||
| 515 | * 更新可用积分表 | ||
| 516 | * @param tempPoints | ||
| 517 | */ | ||
| 518 | private void doInsertTrPointsAvailable(TempPoints tempPoints){ | ||
| 519 | |||
| 520 | PointsAvailable pointsAvailable = new PointsAvailable(); | ||
| 521 | BeanUtils.copyProperties(tempPoints,pointsAvailable); | ||
| 522 | String description = pointsAvailable.getDescription(); | ||
| 523 | pointsAvailable.setCode(String.valueOf(IdWorker.generator())); | ||
| 524 | pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description); | ||
| 525 | LocalDateTime timestamp = tempPoints.getExpireTime(); | ||
| 526 | if (Objects.nonNull(timestamp)) { | ||
| 527 | pointsAvailable.setExpireTime(timestamp); | ||
| 528 | } | ||
| 529 | |||
| 530 | // 添加可用积分记录 | ||
| 531 | this.doInsertTrPointsAvailable(pointsAvailable); | ||
| 532 | |||
| 533 | } | ||
| 534 | |||
| 535 | /** | ||
| 536 | * 添加可用积分记录 | ||
| 537 | * @param pointsAvailable 可用积分 | ||
| 538 | */ | ||
| 539 | private void doInsertTrPointsAvailable(PointsAvailable pointsAvailable) { | ||
| 540 | this.pointsAvailableService.create(pointsAvailable); | ||
| 541 | } | ||
| 542 | |||
| 543 | /** | ||
| 544 | * 添加积分明细 | ||
| 545 | * @param memberId 会员Id | ||
| 546 | * @param tempPoints 积分 | ||
| 547 | * @return Integer 总积分 | ||
| 548 | */ | ||
| 549 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){ | ||
| 550 | |||
| 551 | PointsDetail pointsDetail = new PointsDetail(); | ||
| 552 | BeanUtils.copyProperties(tempPoints,pointsDetail); | ||
| 553 | pointsDetail.setId(null); | ||
| 554 | pointsDetail.setMemberId(memberId); | ||
| 555 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 556 | pointsDetail.setPoints(tempPoints.getPoints()); | ||
| 557 | pointsDetail.setOriginalPoints(currentPoints); | ||
| 558 | pointsDetail.setResultPoints(totalPoints); | ||
| 559 | pointsDetail.setCreateTime(null); | ||
| 560 | pointsDetail.setUpdateTime(null); | ||
| 561 | String description = pointsDetail.getDescription(); | ||
| 562 | if (StringUtils.isEmpty(description)) { | ||
| 563 | pointsDetail.setDescription("#"); | ||
| 564 | } | ||
| 565 | |||
| 566 | // 保存积分流水 | ||
| 567 | this.doInsertPointsDetail(pointsDetail); | ||
| 568 | |||
| 569 | } | ||
| 570 | |||
| 571 | /** | ||
| 572 | * | ||
| 573 | * @param pointsDetail | ||
| 574 | */ | ||
| 575 | private void doInsertPointsDetail(PointsDetail pointsDetail){ | ||
| 576 | this.pointsDetailService.create4Custom(pointsDetail); | ||
| 577 | } | ||
| 578 | } | 77 | } | ... | ... |
src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
deleted
100644 → 0
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | import cn.hutool.core.date.LocalDateTimeUtil; | ||
| 4 | import com.topdraw.business.module.coupon.service.CouponService; | ||
| 5 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | ||
| 6 | import com.topdraw.business.module.rights.history.domain.RightsHistory; | ||
| 7 | import com.topdraw.business.module.rights.history.service.RightsHistoryService; | ||
| 8 | import com.topdraw.business.module.rights.service.RightsService; | ||
| 9 | import com.topdraw.business.module.rights.service.dto.RightsDTO; | ||
| 10 | import com.topdraw.business.process.domian.*; | ||
| 11 | import com.topdraw.business.process.service.CouponOperationService; | ||
| 12 | import com.topdraw.business.process.service.ExpOperationService; | ||
| 13 | import com.topdraw.business.process.service.PointsOperationService; | ||
| 14 | import com.topdraw.business.process.service.RightsOperationService; | ||
| 15 | import com.topdraw.util.TimestampUtil; | ||
| 16 | import lombok.extern.slf4j.Slf4j; | ||
| 17 | import org.slf4j.Logger; | ||
| 18 | import org.slf4j.LoggerFactory; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | import org.springframework.stereotype.Service; | ||
| 21 | import org.springframework.util.CollectionUtils; | ||
| 22 | import org.springframework.util.StringUtils; | ||
| 23 | |||
| 24 | import java.time.LocalDateTime; | ||
| 25 | import java.util.*; | ||
| 26 | import java.util.concurrent.ExecutorService; | ||
| 27 | import java.util.concurrent.Executors; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 权益处理 | ||
| 31 | * | ||
| 32 | * @author XiangHan | ||
| 33 | * @date 2021.10.23 | ||
| 34 | */ | ||
| 35 | @Service | ||
| 36 | @Slf4j | ||
| 37 | public class RightsOperationServiceImpl implements RightsOperationService { | ||
| 38 | |||
| 39 | private static final Logger LOG = LoggerFactory.getLogger(RightsOperationServiceImpl.class); | ||
| 40 | |||
| 41 | @Autowired | ||
| 42 | RightsHistoryService rightsHistoryService; | ||
| 43 | @Autowired | ||
| 44 | CouponOperationService couponOperationService; | ||
| 45 | @Autowired | ||
| 46 | RightsService rightsService; | ||
| 47 | @Autowired | ||
| 48 | ExpOperationService expOperationService; | ||
| 49 | @Autowired | ||
| 50 | PointsOperationService pointsOperationService; | ||
| 51 | @Autowired | ||
| 52 | CouponService couponService; | ||
| 53 | |||
| 54 | // @Autowired | ||
| 55 | // ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 56 | |||
| 57 | private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * 系统手动发放 | ||
| 61 | * 实现步骤: | ||
| 62 | * 1.当前权益只有实体券 | ||
| 63 | * @param rightsList | ||
| 64 | */ | ||
| 65 | @Override | ||
| 66 | public void grantRightsByManual(List<RightsHistory> rightsList) { | ||
| 67 | // 1.权益区分 | ||
| 68 | Map<RightType,Object> tempRightsMap = this.distinguishRight(rightsList); | ||
| 69 | // 2.权益下发 | ||
| 70 | this.refresh(tempRightsMap); | ||
| 71 | // 3.保存权益历史 | ||
| 72 | this.doInsertTrRightHistory(rightsList); | ||
| 73 | } | ||
| 74 | |||
| 75 | /** | ||
| 76 | * 权益发放 | ||
| 77 | * @param tempRightsMap 权益类型 | ||
| 78 | */ | ||
| 79 | @Override | ||
| 80 | public void grantRights(Map<RightType, Object> tempRightsMap) { | ||
| 81 | |||
| 82 | // this.threadPoolTaskExecutor.execute(()-> { | ||
| 83 | // 2.创建权益历史对象 | ||
| 84 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | ||
| 85 | // 3.保存权益历史 | ||
| 86 | this.doInsertTrRightHistory(rightsList); | ||
| 87 | // }); | ||
| 88 | |||
| 89 | // 1.权益下发 | ||
| 90 | this.refresh(tempRightsMap); | ||
| 91 | } | ||
| 92 | |||
| 93 | /** | ||
| 94 | * | ||
| 95 | * @param tempRightsMap | ||
| 96 | * @return | ||
| 97 | */ | ||
| 98 | private List<RightsHistory> getRightHistory(Map<RightType, Object> tempRightsMap) { | ||
| 99 | List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS); | ||
| 100 | List<RightsHistory> rightsHistoryList = new ArrayList<>(); | ||
| 101 | |||
| 102 | values.forEach(value -> { | ||
| 103 | RightsHistory rightsHistory = new RightsHistory(); | ||
| 104 | rightsHistory.setSendTime(LocalDateTime.now()); | ||
| 105 | rightsHistory.setRightsId(value.getId()); | ||
| 106 | rightsHistory.setMemberId(value.getMemberId()); | ||
| 107 | rightsHistory.setExpireTime(value.getExpireTime()); | ||
| 108 | String memberCode = value.getMemberCode(); | ||
| 109 | rightsHistory.setMemberCode(memberCode); | ||
| 110 | rightsHistoryList.add(rightsHistory); | ||
| 111 | }); | ||
| 112 | |||
| 113 | return rightsHistoryList; | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * 成长值发放,基于已获得的权益 | ||
| 118 | * @param tempExpList 权益列表 | ||
| 119 | */ | ||
| 120 | private void grantExp(List<TempExp> tempExpList) { | ||
| 121 | if (!CollectionUtils.isEmpty(tempExpList)) | ||
| 122 | this.expOperationService.grantPointsThroughTempExp(tempExpList); | ||
| 123 | } | ||
| 124 | |||
| 125 | /** | ||
| 126 | * 发放积分,基于已获得的权益 | ||
| 127 | * | ||
| 128 | * @param tempPointsList 权益列表 | ||
| 129 | */ | ||
| 130 | private void grantPoint(List<TempPoints> tempPointsList) { | ||
| 131 | if (!CollectionUtils.isEmpty(tempPointsList)) | ||
| 132 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); | ||
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * 发放优惠券,基于已获得的权益 | ||
| 137 | * | ||
| 138 | * @param tempCouponList 优惠券 | ||
| 139 | */ | ||
| 140 | private void grantCoupon(List<TempCoupon> tempCouponList) { | ||
| 141 | // 发放优惠券 | ||
| 142 | if (!CollectionUtils.isEmpty(tempCouponList)) | ||
| 143 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); | ||
| 144 | } | ||
| 145 | |||
| 146 | /** | ||
| 147 | * 权益发放 | ||
| 148 | * @param tempRightsMap | ||
| 149 | */ | ||
| 150 | private void refresh(Map<RightType, Object> tempRightsMap) { | ||
| 151 | /*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{ | ||
| 152 | log.info(Thread.currentThread().getName() + "=========>> start"); | ||
| 153 | // 积分 | ||
| 154 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 155 | log.info(Thread.currentThread().getName() + "=========>>grantPoint end"); | ||
| 156 | // 成长值 | ||
| 157 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 158 | // 优惠券 | ||
| 159 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 160 | return null; | ||
| 161 | }); | ||
| 162 | FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{ | ||
| 163 | // 积分 | ||
| 164 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 165 | // 成长值 | ||
| 166 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 167 | // 优惠券 | ||
| 168 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 169 | return null; | ||
| 170 | }); | ||
| 171 | FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{ | ||
| 172 | // 积分 | ||
| 173 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 174 | // 成长值 | ||
| 175 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 176 | // 优惠券 | ||
| 177 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 178 | return null; | ||
| 179 | }); | ||
| 180 | this.threadPoolTaskExecutor.execute(futureTask1); | ||
| 181 | this.threadPoolTaskExecutor.execute(futureTask2); | ||
| 182 | this.threadPoolTaskExecutor.execute(futureTask3);*/ | ||
| 183 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
| 184 | // 积分 | ||
| 185 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 186 | // 成长值 | ||
| 187 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 188 | // 优惠券 | ||
| 189 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 190 | });*/ | ||
| 191 | |||
| 192 | |||
| 193 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
| 194 | log.info(Thread.currentThread().getName() + "=========>> start"); | ||
| 195 | // 积分 | ||
| 196 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 197 | log.info(Thread.currentThread().getName() + "=========>> end"); | ||
| 198 | });*/ | ||
| 199 | |||
| 200 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); | ||
| 201 | if (!CollectionUtils.isEmpty(tempPointsList)) { | ||
| 202 | // 积分 | ||
| 203 | this.grantPoint(tempPointsList); | ||
| 204 | } | ||
| 205 | |||
| 206 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); | ||
| 207 | if (!CollectionUtils.isEmpty(tempExpList)) { | ||
| 208 | // 成长值 | ||
| 209 | this.grantExp(tempExpList); | ||
| 210 | } | ||
| 211 | |||
| 212 | List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); | ||
| 213 | if (!CollectionUtils.isEmpty(tempCouponList)) { | ||
| 214 | // 优惠券 | ||
| 215 | this.grantCoupon(tempCouponList); | ||
| 216 | } | ||
| 217 | |||
| 218 | } | ||
| 219 | |||
| 220 | /** | ||
| 221 | * 区分权益 | ||
| 222 | * @param rightsList | ||
| 223 | * @return | ||
| 224 | */ | ||
| 225 | private Map<RightType, Object> distinguishRight(List<RightsHistory> rightsList) { | ||
| 226 | |||
| 227 | Map<RightType,Object> map = new HashMap<>(); | ||
| 228 | |||
| 229 | // 优惠券 | ||
| 230 | List<TempCoupon> tempCouponList = new ArrayList<>(); | ||
| 231 | |||
| 232 | for (RightsHistory right : rightsList) { | ||
| 233 | Long rightId = right.getRightsId(); | ||
| 234 | Long memberId = right.getMemberId(); | ||
| 235 | Long userId = right.getUserId(); | ||
| 236 | // 权益类型 | ||
| 237 | RightsDTO rightsDTO = this.getRights(rightId); | ||
| 238 | // 权益的实体类型 1:积分;2成长值;3优惠券 | ||
| 239 | String type = rightsDTO.getEntityType(); | ||
| 240 | Long expireTime = rightsDTO.getExpireTime(); | ||
| 241 | |||
| 242 | switch (type) { | ||
| 243 | // 优惠券 | ||
| 244 | case "1": | ||
| 245 | Long entityId = rightsDTO.getEntityId(); | ||
| 246 | CouponDTO couponDTO = this.findCouponById(entityId); | ||
| 247 | if (Objects.nonNull(couponDTO)) { | ||
| 248 | TempCoupon tempCoupon = new TempCoupon(); | ||
| 249 | tempCoupon.setId(couponDTO.getId()); | ||
| 250 | tempCoupon.setMemberId(memberId); | ||
| 251 | tempCoupon.setUserId(userId); | ||
| 252 | tempCoupon.setRightsAmount(1); | ||
| 253 | tempCoupon.setRightsSendStrategy(0); | ||
| 254 | tempCoupon.setCode(couponDTO.getCode()); | ||
| 255 | if (Objects.nonNull(expireTime)) | ||
| 256 | tempCoupon.setExpireTime(LocalDateTimeUtil.of(expireTime)); | ||
| 257 | tempCouponList.add(tempCoupon); | ||
| 258 | } | ||
| 259 | break; | ||
| 260 | // 观影券 | ||
| 261 | case "2": | ||
| 262 | break; | ||
| 263 | // 活动参与机会 | ||
| 264 | case "3": | ||
| 265 | break; | ||
| 266 | |||
| 267 | default: | ||
| 268 | break; | ||
| 269 | } | ||
| 270 | } | ||
| 271 | |||
| 272 | // 优惠券 | ||
| 273 | if (!CollectionUtils.isEmpty(tempCouponList)) | ||
| 274 | map.put(RightType.COUPON,tempCouponList); | ||
| 275 | return map; | ||
| 276 | } | ||
| 277 | |||
| 278 | /** | ||
| 279 | * 获取优惠券信息 | ||
| 280 | * @param id | ||
| 281 | * @return | ||
| 282 | */ | ||
| 283 | private CouponDTO findCouponById(Long id) { | ||
| 284 | CouponDTO couponDTO = this.couponService.findById(id); | ||
| 285 | return couponDTO; | ||
| 286 | } | ||
| 287 | |||
| 288 | /** | ||
| 289 | * 权益详情 | ||
| 290 | * @param rightsId | ||
| 291 | * @return | ||
| 292 | */ | ||
| 293 | private RightsDTO getRights(Long rightsId) { | ||
| 294 | RightsDTO rightsDTO = this.rightsService.findById(rightsId); | ||
| 295 | return rightsDTO; | ||
| 296 | } | ||
| 297 | |||
| 298 | |||
| 299 | /** | ||
| 300 | * 添加权益领取记录 | ||
| 301 | * @param rightsHistories | ||
| 302 | */ | ||
| 303 | private void doInsertTrRightHistory(List<RightsHistory> rightsHistories) { | ||
| 304 | if (!CollectionUtils.isEmpty(rightsHistories)) { | ||
| 305 | |||
| 306 | for (RightsHistory rightsHistory : rightsHistories) { | ||
| 307 | Long operatorId = rightsHistory.getOperatorId(); | ||
| 308 | String operatorName = rightsHistory.getOperatorName(); | ||
| 309 | rightsHistory.setSendTime(LocalDateTime.now()); | ||
| 310 | rightsHistory.setOperatorId(Objects.nonNull(operatorId)?operatorId:0); | ||
| 311 | rightsHistory.setOperatorName(!StringUtils.isEmpty(operatorName)?operatorName:"系统发放"); | ||
| 312 | this.rightsHistoryService.create(rightsHistory); | ||
| 313 | } | ||
| 314 | |||
| 315 | } | ||
| 316 | |||
| 317 | } | ||
| 318 | |||
| 319 | } |
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | ||
| 4 | import com.topdraw.business.module.task.attribute.service.TaskAttrService; | ||
| 5 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ||
| 6 | import com.topdraw.business.module.task.domain.Task; | ||
| 7 | import com.topdraw.business.module.task.service.TaskService; | ||
| 8 | import com.topdraw.business.module.task.service.dto.TaskDTO; | ||
| 9 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | ||
| 10 | import com.topdraw.business.process.service.TaskOperationService; | ||
| 11 | import com.topdraw.business.process.service.TaskTemplateOperationService; | ||
| 12 | import lombok.extern.slf4j.Slf4j; | ||
| 13 | import org.apache.commons.lang3.StringUtils; | ||
| 14 | import org.springframework.beans.BeanUtils; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 16 | import org.springframework.stereotype.Service; | ||
| 17 | |||
| 18 | import java.util.Objects; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * @author : | ||
| 22 | * @description: | ||
| 23 | * @function : | ||
| 24 | * @date :Created in 2022/4/25 15:48 | ||
| 25 | * @version: : | ||
| 26 | * @modified By: | ||
| 27 | * @since : modified in 2022/4/25 15:48 | ||
| 28 | */ | ||
| 29 | @Service | ||
| 30 | @Slf4j | ||
| 31 | public class TaskOperationServiceImpl implements TaskOperationService { | ||
| 32 | |||
| 33 | @Autowired | ||
| 34 | private TaskService taskService; | ||
| 35 | @Autowired | ||
| 36 | private TaskAttrService taskAttrService; | ||
| 37 | @Autowired | ||
| 38 | private TaskTemplateOperationService taskTemplateOperationService; | ||
| 39 | |||
| 40 | public void asyncCreateTask(Task task) { | ||
| 41 | String taskTemplateCode = task.getTaskTemplateCode(); | ||
| 42 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateOperationService.findByCode(taskTemplateCode); | ||
| 43 | Long id = taskTemplateDTO.getId(); | ||
| 44 | task.setTaskTemplateId(id); | ||
| 45 | this.create(task); | ||
| 46 | } | ||
| 47 | |||
| 48 | private void create(Task task) { | ||
| 49 | String code = task.getCode(); | ||
| 50 | TaskDTO taskDTO = this.findByCode(code); | ||
| 51 | if (Objects.isNull(taskDTO.getId())) { | ||
| 52 | TaskDTO taskDTO_ = this.taskService.create(task); | ||
| 53 | if (Objects.nonNull(taskDTO_.getId())) { | ||
| 54 | task.setId(taskDTO_.getId()); | ||
| 55 | this.createTaskAttr(task); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * | ||
| 62 | * @param task_ | ||
| 63 | */ | ||
| 64 | private void createTaskAttr(Task task_) { | ||
| 65 | TaskAttr taskAttr = new TaskAttr(); | ||
| 66 | taskAttr.setAttrStr(task_.getAttr()); | ||
| 67 | taskAttr.setTaskId(task_.getId()); | ||
| 68 | this.taskAttrService.create(taskAttr); | ||
| 69 | } | ||
| 70 | |||
| 71 | public void asyncUpdateTask(Task task) { | ||
| 72 | String code = task.getCode(); | ||
| 73 | TaskDTO taskDTO = this.findByCode(code); | ||
| 74 | if (Objects.nonNull(taskDTO.getId())) { | ||
| 75 | Long id = taskDTO.getId(); | ||
| 76 | task.setId(id); | ||
| 77 | |||
| 78 | String taskTemplateCode = task.getTaskTemplateCode(); | ||
| 79 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateOperationService.findByCode(taskTemplateCode); | ||
| 80 | Long templateId = taskTemplateDTO.getId(); | ||
| 81 | task.setTaskTemplateId(templateId); | ||
| 82 | TaskDTO update = this.update(task); | ||
| 83 | if (Objects.nonNull(update)) { | ||
| 84 | this.updateTaskAttr(task); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * | ||
| 92 | * @param task_ | ||
| 93 | */ | ||
| 94 | private void updateTaskAttr(Task task_) { | ||
| 95 | |||
| 96 | TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(task_.getId()); | ||
| 97 | if (Objects.nonNull(taskAttrDTO.getId())) { | ||
| 98 | TaskAttr taskAttr = new TaskAttr(); | ||
| 99 | BeanUtils.copyProperties(taskAttrDTO, taskAttr); | ||
| 100 | taskAttr.setAttrStr(task_.getAttr()); | ||
| 101 | this.taskAttrService.update(taskAttr); | ||
| 102 | } | ||
| 103 | |||
| 104 | } | ||
| 105 | |||
| 106 | private TaskAttrDTO findTaskAttrByTaskId(Long taskId) { | ||
| 107 | return this.taskAttrService.findByTaskId(taskId); | ||
| 108 | } | ||
| 109 | |||
| 110 | private TaskDTO update(Task task) { | ||
| 111 | return this.taskService.update(task); | ||
| 112 | } | ||
| 113 | |||
| 114 | public void asyncDeleteTask(Task task) { | ||
| 115 | String code = task.getCode(); | ||
| 116 | TaskDTO taskDTO = this.findByCode(code); | ||
| 117 | if (Objects.nonNull(taskDTO.getId())) { | ||
| 118 | |||
| 119 | Long id = taskDTO.getId(); | ||
| 120 | task.setId(id); | ||
| 121 | this.delete(task); | ||
| 122 | |||
| 123 | } | ||
| 124 | |||
| 125 | } | ||
| 126 | |||
| 127 | private void delete(Task task) { | ||
| 128 | this.taskService.delete(task); | ||
| 129 | } | ||
| 130 | |||
| 131 | private TaskDTO findByCode(String code){ | ||
| 132 | TaskDTO taskDTO = this.taskService.findByCode(code); | ||
| 133 | return taskDTO; | ||
| 134 | } | ||
| 135 | |||
| 136 | } |
src/main/java/com/topdraw/business/process/service/impl/TaskTemplateOperationServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.task.template.domain.TaskTemplate; | ||
| 4 | import com.topdraw.business.module.task.template.service.TaskTemplateService; | ||
| 5 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | ||
| 6 | import com.topdraw.business.process.service.TaskTemplateOperationService; | ||
| 7 | import lombok.extern.slf4j.Slf4j; | ||
| 8 | import org.springframework.beans.BeanUtils; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | import org.springframework.stereotype.Service; | ||
| 11 | |||
| 12 | import java.util.Objects; | ||
| 13 | |||
| 14 | |||
| 15 | /** | ||
| 16 | * @author : | ||
| 17 | * @description: | ||
| 18 | * @function : | ||
| 19 | * @date :Created in 2022/4/25 22:27 | ||
| 20 | * @version: : | ||
| 21 | * @modified By: | ||
| 22 | * @since : modified in 2022/4/25 22:27 | ||
| 23 | */ | ||
| 24 | @Service | ||
| 25 | @Slf4j | ||
| 26 | public class TaskTemplateOperationServiceImpl implements TaskTemplateOperationService { | ||
| 27 | |||
| 28 | @Autowired | ||
| 29 | private TaskTemplateService taskTemplateService; | ||
| 30 | |||
| 31 | public void asyncCreate(TaskTemplate resources) { | ||
| 32 | this.create(resources); | ||
| 33 | } | ||
| 34 | |||
| 35 | public void asyncUpdate(TaskTemplate resources) { | ||
| 36 | this.update(resources); | ||
| 37 | } | ||
| 38 | |||
| 39 | public void asyncDelete(TaskTemplate resources) { | ||
| 40 | this.delete(resources); | ||
| 41 | } | ||
| 42 | |||
| 43 | private void create(TaskTemplate resources) { | ||
| 44 | String code = resources.getCode(); | ||
| 45 | TaskTemplateDTO taskTemplateDTO = this.findByCode(code); | ||
| 46 | if (Objects.isNull(taskTemplateDTO.getId())) { | ||
| 47 | this.taskTemplateService.create(resources); | ||
| 48 | } | ||
| 49 | |||
| 50 | } | ||
| 51 | |||
| 52 | private void update(TaskTemplate resources) { | ||
| 53 | String code = resources.getCode(); | ||
| 54 | TaskTemplateDTO taskTemplateDTO = this.findByCode(code); | ||
| 55 | if (Objects.nonNull(taskTemplateDTO.getId())) { | ||
| 56 | Long id = taskTemplateDTO.getId(); | ||
| 57 | resources.setId(id); | ||
| 58 | this.taskTemplateService.update(resources); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | private void delete(TaskTemplate resources) { | ||
| 63 | String code = resources.getCode(); | ||
| 64 | TaskTemplateDTO taskTemplateDTO = this.findByCode(code); | ||
| 65 | if (Objects.nonNull(taskTemplateDTO.getId())) { | ||
| 66 | Long id = taskTemplateDTO.getId(); | ||
| 67 | this.taskTemplateService.delete(id); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | private void delete(Long id) { | ||
| 72 | TaskTemplateDTO taskTemplateDTO = this.findById(id); | ||
| 73 | this.taskTemplateService.delete(id); | ||
| 74 | |||
| 75 | TaskTemplate taskTemplate = new TaskTemplate(); | ||
| 76 | BeanUtils.copyProperties(taskTemplateDTO, taskTemplate); | ||
| 77 | taskTemplate.setDeleteMark(1); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Override | ||
| 81 | public TaskTemplateDTO findByCode(String code) { | ||
| 82 | return this.taskTemplateService.findByCode(code); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | private TaskTemplateDTO findById(Long id) { | ||
| 87 | return this.taskTemplateService.findById(id); | ||
| 88 | } | ||
| 89 | |||
| 90 | } |
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | |||
| 4 | import com.topdraw.business.module.member.domain.Member; | ||
| 5 | import com.topdraw.business.module.member.service.MemberService; | ||
| 6 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 7 | import com.topdraw.business.module.user.iptv.domain.UserTv; | ||
| 8 | import com.topdraw.business.module.user.iptv.service.UserTvService; | ||
| 9 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | ||
| 10 | import com.topdraw.business.module.user.weixin.domain.UserWeixin; | ||
| 11 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | ||
| 12 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | ||
| 13 | import com.topdraw.business.process.service.UserOperationService; | ||
| 14 | import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; | ||
| 15 | import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; | ||
| 16 | import com.topdraw.exception.EntityNotFoundException; | ||
| 17 | import com.topdraw.exception.GlobeExceptionMsg; | ||
| 18 | import lombok.extern.slf4j.Slf4j; | ||
| 19 | import org.apache.commons.lang3.StringUtils; | ||
| 20 | import org.springframework.beans.BeanUtils; | ||
| 21 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 22 | import org.springframework.stereotype.Service; | ||
| 23 | import org.springframework.transaction.annotation.Propagation; | ||
| 24 | import org.springframework.transaction.annotation.Transactional; | ||
| 25 | |||
| 26 | import java.util.Objects; | ||
| 27 | |||
| 28 | @Service | ||
| 29 | @Slf4j | ||
| 30 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 31 | public class UserOperationServiceImpl implements UserOperationService { | ||
| 32 | |||
| 33 | @Autowired | ||
| 34 | private MemberService memberService; | ||
| 35 | @Autowired | ||
| 36 | private UserTvService userTvService; | ||
| 37 | @Autowired | ||
| 38 | private UserWeixinService userWeixinService; | ||
| 39 | |||
| 40 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 41 | public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { | ||
| 42 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); | ||
| 43 | String openid = userWeixinDTO.getOpenid(); | ||
| 44 | String unionid = userWeixinDTO.getUnionid(); | ||
| 45 | String appid = userWeixinDTO.getAppid(); | ||
| 46 | |||
| 47 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid); | ||
| 48 | // 无账号 | ||
| 49 | if (Objects.isNull(_userWeixinDTO.getId())) { | ||
| 50 | |||
| 51 | // 是否存在会员 | ||
| 52 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | ||
| 53 | |||
| 54 | if (Objects.nonNull(userWeixinDTO1.getId())) { | ||
| 55 | |||
| 56 | Long memberId = userWeixinDTO1.getMemberId(); | ||
| 57 | if (Objects.nonNull(memberId)) { | ||
| 58 | |||
| 59 | userWeixinDTO.setMemberId(memberId); | ||
| 60 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 61 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 62 | this.updateMember(memberDTO, memberDTO1); | ||
| 63 | |||
| 64 | } else { | ||
| 65 | |||
| 66 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 67 | String memberCode = memberDTO1.getCode(); | ||
| 68 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 69 | Member member = new Member(); | ||
| 70 | member.setCode(memberCode); | ||
| 71 | MemberDTO _memberDTO1 = this.memberService.create(member); | ||
| 72 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | ||
| 73 | } | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | // 无会员 | ||
| 78 | } else { | ||
| 79 | |||
| 80 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 81 | Member member = new Member(); | ||
| 82 | BeanUtils.copyProperties(memberDTO, member); | ||
| 83 | member.setId(null); | ||
| 84 | MemberDTO memberDTO1 = this.memberService.create(member); | ||
| 85 | userWeixinDTO.setMemberId(memberDTO1.getId()); | ||
| 86 | } | ||
| 87 | |||
| 88 | userWeixinDTO.setId(null); | ||
| 89 | this.createWeixin(userWeixinDTO); | ||
| 90 | |||
| 91 | } else { | ||
| 92 | |||
| 93 | // 会员存在 | ||
| 94 | if(Objects.nonNull(_userWeixinDTO.getMemberId())) { | ||
| 95 | // 账号存在,修改账号和会员 | ||
| 96 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 97 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | ||
| 98 | |||
| 99 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 100 | this.updateMember(_memberDTO, memberDTO); | ||
| 101 | |||
| 102 | // 有账号无会员 | ||
| 103 | } else { | ||
| 104 | |||
| 105 | // 是否存在会员 | ||
| 106 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | ||
| 107 | |||
| 108 | // 有其他账号 | ||
| 109 | if (Objects.nonNull(userWeixinDTO1.getId())) { | ||
| 110 | |||
| 111 | Long memberId = userWeixinDTO1.getMemberId(); | ||
| 112 | if (Objects.nonNull(memberId)) { | ||
| 113 | |||
| 114 | userWeixinDTO.setMemberId(memberId); | ||
| 115 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 116 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 117 | this.updateMember(memberDTO, memberDTO1); | ||
| 118 | |||
| 119 | } else { | ||
| 120 | |||
| 121 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 122 | Member member = new Member(); | ||
| 123 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 124 | member.setId(null); | ||
| 125 | MemberDTO _memberDTO1 = this.memberService.create(member); | ||
| 126 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | ||
| 127 | |||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 | } | ||
| 136 | |||
| 137 | } | ||
| 138 | |||
| 139 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 140 | public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTvDTO) { | ||
| 141 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | ||
| 142 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 143 | |||
| 144 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 145 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 146 | if (Objects.isNull(_userTvDTO)) { | ||
| 147 | |||
| 148 | memberDTO.setId(null); | ||
| 149 | // 创建大屏会员 | ||
| 150 | MemberDTO _memberDTO = this.createMember(memberDTO); | ||
| 151 | userTvDTO.setMemberId(_memberDTO.getId()); | ||
| 152 | // 创建大屏账号 | ||
| 153 | this.createUserTv(userTvDTO); | ||
| 154 | |||
| 155 | } else { | ||
| 156 | |||
| 157 | String code = memberDTO.getCode(); | ||
| 158 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 159 | if (Objects.nonNull(_memberDTO.getId())) { | ||
| 160 | this.updateMember(_memberDTO, memberDTO); | ||
| 161 | } else { | ||
| 162 | memberDTO.setId(null); | ||
| 163 | MemberDTO _memberDTO0 = this.createMember(memberDTO); | ||
| 164 | userTvDTO.setMemberId(_memberDTO0.getId()); | ||
| 165 | } | ||
| 166 | |||
| 167 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 172 | public void asyncAppletBind(MemberAndUserTvDTO memberAndUserTvDTO) { | ||
| 173 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | ||
| 174 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 175 | |||
| 176 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 177 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 178 | if (Objects.nonNull(_userTvDTO)) { | ||
| 179 | |||
| 180 | // | ||
| 181 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 182 | |||
| 183 | String code = memberDTO.getCode(); | ||
| 184 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 185 | |||
| 186 | memberDTO.setUserIptvId(_userTvDTO.getId()); | ||
| 187 | this.updateMember(_memberDTO, memberDTO); | ||
| 188 | |||
| 189 | } else { | ||
| 190 | |||
| 191 | throw new EntityNotFoundException(UserTvDTO.class, "id", GlobeExceptionMsg.IPTV_IS_NULL); | ||
| 192 | |||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 197 | public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) { | ||
| 198 | UserTvDTO userTvDTO = memberAndUserTvDTO.getUserTvDTO(); | ||
| 199 | MemberDTO memberDTO = memberAndUserTvDTO.getMemberDTO(); | ||
| 200 | |||
| 201 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 202 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 203 | |||
| 204 | _userTvDTO.setPriorityMemberCode(null); | ||
| 205 | // | ||
| 206 | this.unbindPriorityMemberCode(_userTvDTO); | ||
| 207 | |||
| 208 | String code = memberDTO.getCode(); | ||
| 209 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 210 | this.unbindUserIpTv(_memberDTO); | ||
| 211 | |||
| 212 | } | ||
| 213 | |||
| 214 | private void unbindUserIpTv(MemberDTO memberDTO) { | ||
| 215 | memberDTO.setUserIptvId(null); | ||
| 216 | memberDTO.setBindIptvPlatformType(null); | ||
| 217 | memberDTO.setBindIptvTime(null); | ||
| 218 | Member member = new Member(); | ||
| 219 | BeanUtils.copyProperties(memberDTO, member); | ||
| 220 | this.memberService.unbindUserIpTv(member); | ||
| 221 | } | ||
| 222 | |||
| 223 | private void unbindPriorityMemberCode(UserTvDTO userTvDTO) { | ||
| 224 | UserTv userTv = new UserTv(); | ||
| 225 | BeanUtils.copyProperties(userTvDTO, userTv); | ||
| 226 | this.userTvService.unbindPriorityMemberCode(userTv); | ||
| 227 | } | ||
| 228 | |||
| 229 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 230 | public void asyncWeixin(UserWeixinDTO userWeixinDTO) { | ||
| 231 | String openid = userWeixinDTO.getOpenid(); | ||
| 232 | String unionid = userWeixinDTO.getUnionid(); | ||
| 233 | String appid = userWeixinDTO.getAppid(); | ||
| 234 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid); | ||
| 235 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
| 236 | |||
| 237 | if(Objects.nonNull(_userWeixinDTO.getMemberId())) { | ||
| 238 | |||
| 239 | if (StringUtils.isNotBlank(_userWeixinDTO.getUnionid())) { | ||
| 240 | |||
| 241 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(_userWeixinDTO.getUnionid()); | ||
| 242 | if (Objects.nonNull(userWeixinDTO1)) { | ||
| 243 | |||
| 244 | Long memberId = userWeixinDTO1.getMemberId(); | ||
| 245 | if (Objects.nonNull(memberId)) { | ||
| 246 | |||
| 247 | userWeixinDTO.setMemberId(memberId); | ||
| 248 | |||
| 249 | } else { | ||
| 250 | |||
| 251 | String memberCode = userWeixinDTO.getMemberCode(); | ||
| 252 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 253 | Member member = new Member(); | ||
| 254 | member.setCode(memberCode); | ||
| 255 | MemberDTO memberDTO1 = this.memberService.create(member); | ||
| 256 | userWeixinDTO.setMemberId(memberDTO1.getId()); | ||
| 257 | } | ||
| 258 | |||
| 259 | } | ||
| 260 | |||
| 261 | } | ||
| 262 | |||
| 263 | } else { | ||
| 264 | |||
| 265 | String memberCode = userWeixinDTO.getMemberCode(); | ||
| 266 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 267 | Member member = new Member(); | ||
| 268 | member.setCode(memberCode); | ||
| 269 | MemberDTO memberDTO1 = this.memberService.create(member); | ||
| 270 | userWeixinDTO.setMemberId(memberDTO1.getId()); | ||
| 271 | } | ||
| 272 | |||
| 273 | } | ||
| 274 | |||
| 275 | } else { | ||
| 276 | |||
| 277 | String memberCode = userWeixinDTO.getMemberCode(); | ||
| 278 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 279 | Member member = new Member(); | ||
| 280 | member.setCode(memberCode); | ||
| 281 | MemberDTO memberDTO1 = this.memberService.create(member); | ||
| 282 | userWeixinDTO.setMemberId(memberDTO1.getId()); | ||
| 283 | } | ||
| 284 | |||
| 285 | } | ||
| 286 | userWeixinDTO.setId(_userWeixinDTO.getId()); | ||
| 287 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 288 | |||
| 289 | } else { | ||
| 290 | |||
| 291 | userWeixinDTO.setId(null); | ||
| 292 | String memberCode = userWeixinDTO.getMemberCode(); | ||
| 293 | Long memberId = null; | ||
| 294 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 295 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 296 | if (Objects.isNull(memberDTO.getId())) { | ||
| 297 | Member member = new Member(); | ||
| 298 | member.setCode(memberCode); | ||
| 299 | MemberDTO memberDTO1 = this.memberService.create(member); | ||
| 300 | memberId = memberDTO1.getId(); | ||
| 301 | } else { | ||
| 302 | memberId = memberDTO.getId(); | ||
| 303 | } | ||
| 304 | |||
| 305 | userWeixinDTO.setMemberId(memberId); | ||
| 306 | this.createWeixin(userWeixinDTO); | ||
| 307 | } | ||
| 308 | |||
| 309 | } | ||
| 310 | |||
| 311 | } | ||
| 312 | |||
| 313 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 314 | public void asyncUserTv(UserTvDTO userTvDTO) { | ||
| 315 | log.info("asyncUserTv ==>> userTvDTO ==>> {}", userTvDTO); | ||
| 316 | String platformAccount = userTvDTO.getPlatformAccount(); | ||
| 317 | UserTvDTO _userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 318 | log.info("db result ==>> _userTvDTO ==>> {}", _userTvDTO); | ||
| 319 | this.updateUserTv(_userTvDTO, userTvDTO); | ||
| 320 | } | ||
| 321 | |||
| 322 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 323 | public void asyncMember(MemberDTO memberDTO) { | ||
| 324 | String code = memberDTO.getCode(); | ||
| 325 | if (StringUtils.isNotBlank(code)) { | ||
| 326 | MemberDTO _memberDTO = this.memberService.findByCode(code); | ||
| 327 | if (Objects.nonNull(_memberDTO)) { | ||
| 328 | Long id = _memberDTO.getId(); | ||
| 329 | memberDTO.setId(id); | ||
| 330 | this.updateMember(_memberDTO, memberDTO); | ||
| 331 | } | ||
| 332 | } | ||
| 333 | } | ||
| 334 | |||
| 335 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 336 | public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { | ||
| 337 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); | ||
| 338 | String openid = userWeixinDTO.getOpenid(); | ||
| 339 | String unionid = userWeixinDTO.getUnionid(); | ||
| 340 | String appid = userWeixinDTO.getAppid(); | ||
| 341 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 342 | |||
| 343 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); | ||
| 344 | // 有账号 | ||
| 345 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
| 346 | |||
| 347 | UserWeixinDTO _userWeixinDTO0 = this.userWeixinService.findFirstByAppIdAndOpenId(appid, openid); | ||
| 348 | // 会员存在 | ||
| 349 | if(Objects.nonNull(_userWeixinDTO0.getMemberId())) { | ||
| 350 | // 账号存在,修改账号和会员 | ||
| 351 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 352 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | ||
| 353 | |||
| 354 | MemberDTO memberDTO0 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 355 | memberDTO0.setUserIptvId(_memberDTO.getUserIptvId()); | ||
| 356 | this.updateMember(_memberDTO, memberDTO0); | ||
| 357 | |||
| 358 | // 有账号无会员 | ||
| 359 | } else { | ||
| 360 | |||
| 361 | // 是否存在会员 | ||
| 362 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | ||
| 363 | |||
| 364 | // 有其他账号 | ||
| 365 | if (Objects.nonNull(userWeixinDTO1.getId())) { | ||
| 366 | |||
| 367 | Long memberId = userWeixinDTO1.getMemberId(); | ||
| 368 | if (Objects.nonNull(memberId)) { | ||
| 369 | |||
| 370 | userWeixinDTO.setMemberId(memberId); | ||
| 371 | MemberDTO memberDTO0 = this.memberService.findById(memberId); | ||
| 372 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 373 | this.updateMember(memberDTO0, memberDTO1); | ||
| 374 | |||
| 375 | } else { | ||
| 376 | |||
| 377 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 378 | Member member = new Member(); | ||
| 379 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 380 | member.setId(null); | ||
| 381 | MemberDTO _memberDTO1 = this.memberService.create(member); | ||
| 382 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | ||
| 383 | |||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 388 | |||
| 389 | } | ||
| 390 | |||
| 391 | // 无账号 | ||
| 392 | } else { | ||
| 393 | |||
| 394 | // 是否存在会员 | ||
| 395 | UserWeixinDTO userWeixinDTO1 = this.userWeixinService.findFirstByUnionId(unionid); | ||
| 396 | |||
| 397 | // 有其他账号 | ||
| 398 | if (Objects.nonNull(userWeixinDTO1.getId())) { | ||
| 399 | |||
| 400 | Long memberId = userWeixinDTO1.getMemberId(); | ||
| 401 | if (Objects.nonNull(memberId)) { | ||
| 402 | |||
| 403 | userWeixinDTO.setMemberId(memberId); | ||
| 404 | MemberDTO memberDTO0 = this.memberService.findById(memberId); | ||
| 405 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 406 | this.updateMember(memberDTO0, memberDTO1); | ||
| 407 | |||
| 408 | } else { | ||
| 409 | |||
| 410 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 411 | Member member = new Member(); | ||
| 412 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 413 | member.setId(null); | ||
| 414 | MemberDTO _memberDTO1 = this.memberService.create(member); | ||
| 415 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | ||
| 416 | |||
| 417 | } | ||
| 418 | } else { | ||
| 419 | |||
| 420 | MemberDTO memberDTO1 = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 421 | Member member = new Member(); | ||
| 422 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 423 | member.setId(null); | ||
| 424 | MemberDTO _memberDTO1 = this.memberService.create(member); | ||
| 425 | userWeixinDTO.setMemberId(_memberDTO1.getId()); | ||
| 426 | |||
| 427 | } | ||
| 428 | |||
| 429 | this.createWeixin(userWeixinDTO); | ||
| 430 | |||
| 431 | } | ||
| 432 | } | ||
| 433 | |||
| 434 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) | ||
| 435 | public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) { | ||
| 436 | UserWeixinDTO userWeixinDTO = memberAndWeixinUserDTO.getUserWeixinDTO(); | ||
| 437 | String openid = userWeixinDTO.getOpenid(); | ||
| 438 | String unionid = userWeixinDTO.getUnionid(); | ||
| 439 | String appid = userWeixinDTO.getAppid(); | ||
| 440 | MemberDTO memberDTO = memberAndWeixinUserDTO.getMemberDTO(); | ||
| 441 | |||
| 442 | UserWeixinDTO _userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionid, appid, openid); | ||
| 443 | if (Objects.nonNull(_userWeixinDTO)) { | ||
| 444 | |||
| 445 | // 账号存在,修改账号和会员 | ||
| 446 | this.updateWeixin(_userWeixinDTO, userWeixinDTO); | ||
| 447 | |||
| 448 | MemberDTO _memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId()); | ||
| 449 | if (Objects.nonNull(_memberDTO)) { | ||
| 450 | |||
| 451 | memberDTO.setUserIptvId(_memberDTO.getUserIptvId()); | ||
| 452 | this.updateMember(_memberDTO, memberDTO); | ||
| 453 | |||
| 454 | } else { | ||
| 455 | |||
| 456 | throw new EntityNotFoundException(MemberDTO.class, "id", GlobeExceptionMsg.MEMBER_ID_IS_NULL); | ||
| 457 | |||
| 458 | } | ||
| 459 | |||
| 460 | } else { | ||
| 461 | |||
| 462 | throw new EntityNotFoundException(UserWeixinDTO.class, "id", GlobeExceptionMsg.WEIXIN_IS_NULL); | ||
| 463 | |||
| 464 | } | ||
| 465 | |||
| 466 | } | ||
| 467 | |||
| 468 | private MemberDTO createMember(MemberDTO memberDTO){ | ||
| 469 | Member member = new Member(); | ||
| 470 | BeanUtils.copyProperties(memberDTO, member); | ||
| 471 | return this.memberService.create(member); | ||
| 472 | } | ||
| 473 | |||
| 474 | private MemberDTO updateMember(MemberDTO _memberDTO, MemberDTO memberDTO){ | ||
| 475 | |||
| 476 | memberDTO.setId(_memberDTO.getId()); | ||
| 477 | memberDTO.setCode(_memberDTO.getCode()); | ||
| 478 | |||
| 479 | Member member = new Member(); | ||
| 480 | BeanUtils.copyProperties(memberDTO, member); | ||
| 481 | return this.memberService.update(member); | ||
| 482 | } | ||
| 483 | |||
| 484 | private void createWeixin(UserWeixinDTO weixinDTO){ | ||
| 485 | UserWeixin userWeixin = new UserWeixin(); | ||
| 486 | BeanUtils.copyProperties(weixinDTO, userWeixin); | ||
| 487 | this.userWeixinService.create(userWeixin); | ||
| 488 | } | ||
| 489 | |||
| 490 | private void updateWeixin(UserWeixinDTO _userWeixinDTO, UserWeixinDTO weixinDTO){ | ||
| 491 | weixinDTO.setId(_userWeixinDTO.getId()); | ||
| 492 | if (Objects.nonNull(_userWeixinDTO.getMemberId())) { | ||
| 493 | weixinDTO.setMemberId(_userWeixinDTO.getMemberId()); | ||
| 494 | } | ||
| 495 | if (StringUtils.isNotBlank(_userWeixinDTO.getUnionid())){ | ||
| 496 | weixinDTO.setUnionid(_userWeixinDTO.getUnionid()); | ||
| 497 | } | ||
| 498 | if (StringUtils.isNotBlank(_userWeixinDTO.getAppid())) { | ||
| 499 | weixinDTO.setAppid(_userWeixinDTO.getAppid()); | ||
| 500 | } | ||
| 501 | if (StringUtils.isNotBlank(_userWeixinDTO.getOpenid())) { | ||
| 502 | weixinDTO.setOpenid(_userWeixinDTO.getOpenid()); | ||
| 503 | } | ||
| 504 | |||
| 505 | UserWeixin userWeixin = new UserWeixin(); | ||
| 506 | BeanUtils.copyProperties(weixinDTO, userWeixin); | ||
| 507 | this.userWeixinService.update(userWeixin); | ||
| 508 | } | ||
| 509 | |||
| 510 | private void createUserTv(UserTvDTO userTvDTO){ | ||
| 511 | UserTv userTv = new UserTv(); | ||
| 512 | BeanUtils.copyProperties(userTvDTO, userTv); | ||
| 513 | this.userTvService.create(userTv); | ||
| 514 | } | ||
| 515 | |||
| 516 | private void updateUserTv(UserTvDTO _userTvDTO, UserTvDTO userTvDTO){ | ||
| 517 | userTvDTO.setId(_userTvDTO.getId()); | ||
| 518 | |||
| 519 | Long memberId = _userTvDTO.getMemberId(); | ||
| 520 | if (Objects.isNull(memberId)){ | ||
| 521 | String memberCode = userTvDTO.getMemberCode(); | ||
| 522 | if (StringUtils.isNotBlank(memberCode)) { | ||
| 523 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 524 | userTvDTO.setMemberId(memberDTO.getId()); | ||
| 525 | } | ||
| 526 | } else { | ||
| 527 | userTvDTO.setMemberId(memberId); | ||
| 528 | } | ||
| 529 | |||
| 530 | userTvDTO.setPlatformAccount(_userTvDTO.getPlatformAccount()); | ||
| 531 | userTvDTO.setCreateTime(_userTvDTO.getCreateTime()); | ||
| 532 | |||
| 533 | UserTv userTv = new UserTv(); | ||
| 534 | BeanUtils.copyProperties(userTvDTO, userTv); | ||
| 535 | log.info("updateUserTv ==>> userTv ==>> {}" , userTv); | ||
| 536 | this.userTvService.update(userTv); | ||
| 537 | } | ||
| 538 | } |
| 1 | package com.topdraw.business.process.service.impl.member; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.address.domain.MemberAddress; | ||
| 4 | import com.topdraw.business.module.member.address.service.MemberAddressService; | ||
| 5 | import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO; | ||
| 6 | import com.topdraw.business.module.member.service.MemberService; | ||
| 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 8 | import com.topdraw.business.process.service.member.MemberAddressOperationService; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | ||
| 10 | import org.springframework.beans.BeanUtils; | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | import org.springframework.stereotype.Service; | ||
| 13 | import org.springframework.transaction.annotation.Propagation; | ||
| 14 | import org.springframework.transaction.annotation.Transactional; | ||
| 15 | |||
| 16 | import java.util.Objects; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @author XiangHan | ||
| 20 | * @date 2021-10-22 | ||
| 21 | */ | ||
| 22 | @Service | ||
| 23 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 24 | @Slf4j | ||
| 25 | public class MemberAddressOperationServiceImpl implements MemberAddressOperationService { | ||
| 26 | |||
| 27 | @Autowired | ||
| 28 | private MemberAddressService memberAddressService; | ||
| 29 | @Autowired | ||
| 30 | private MemberService memberService; | ||
| 31 | |||
| 32 | public void asyncDeleteMemberAddress(MemberAddressDTO memberAddressDTO){ | ||
| 33 | String memberCode = memberAddressDTO.getMemberCode(); | ||
| 34 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 35 | MemberAddressDTO _memberAddressDTO = | ||
| 36 | this.memberAddressService.findByMemberIdAndSequence(memberDTO.getId(), memberAddressDTO.getSequence()); | ||
| 37 | if (Objects.nonNull(_memberAddressDTO)) { | ||
| 38 | this.memberAddressService.delete(_memberAddressDTO.getId()); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public void asyncMemberAddress(MemberAddressDTO memberAddressDTO){ | ||
| 43 | MemberDTO memberDTO = this.memberService.findByCode(memberAddressDTO.getMemberCode()); | ||
| 44 | |||
| 45 | MemberAddressDTO _memberAddressDTO = this.memberAddressService.findByMemberIdAndSequence(memberDTO.getId(), | ||
| 46 | memberAddressDTO.getSequence()); | ||
| 47 | if (Objects.nonNull(_memberAddressDTO)) { | ||
| 48 | |||
| 49 | memberAddressDTO.setId(_memberAddressDTO.getId()); | ||
| 50 | memberAddressDTO.setMemberId(memberDTO.getId()); | ||
| 51 | this.updateMemberAddress(memberAddressDTO); | ||
| 52 | |||
| 53 | } else { | ||
| 54 | |||
| 55 | memberAddressDTO.setId(null); | ||
| 56 | memberAddressDTO.setMemberId(memberDTO.getId()); | ||
| 57 | this.createMemberAddress(memberAddressDTO); | ||
| 58 | |||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | public void createMemberAddress(MemberAddressDTO memberAddressDTO){ | ||
| 63 | MemberAddress memberAddress = new MemberAddress(); | ||
| 64 | BeanUtils.copyProperties(memberAddressDTO, memberAddress); | ||
| 65 | this.memberAddressService.create(memberAddress); | ||
| 66 | } | ||
| 67 | |||
| 68 | public void updateMemberAddress(MemberAddressDTO memberAddressDTO){ | ||
| 69 | MemberAddress memberAddress = new MemberAddress(); | ||
| 70 | BeanUtils.copyProperties(memberAddressDTO, memberAddress); | ||
| 71 | this.memberAddressService.update(memberAddress); | ||
| 72 | } | ||
| 73 | } |
src/main/java/com/topdraw/business/process/service/impl/member/MemberOperationServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.process.service.impl.member; | ||
| 2 | |||
| 3 | import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import com.topdraw.business.module.member.domain.Member; | ||
| 5 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | ||
| 6 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | ||
| 7 | import com.topdraw.business.module.member.service.MemberService; | ||
| 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 9 | import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; | ||
| 10 | import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; | ||
| 11 | import com.topdraw.business.module.user.weixin.service.UserWeixinService; | ||
| 12 | import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; | ||
| 13 | import com.topdraw.business.process.service.member.MemberOperationService; | ||
| 14 | import org.springframework.beans.BeanUtils; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 16 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 17 | import org.springframework.stereotype.Service; | ||
| 18 | import org.springframework.util.Assert; | ||
| 19 | |||
| 20 | import java.time.LocalDateTime; | ||
| 21 | import java.time.ZoneOffset; | ||
| 22 | import java.util.Objects; | ||
| 23 | |||
| 24 | @Service | ||
| 25 | //@CacheConfig(cacheNames = "member") | ||
| 26 | public class MemberOperationServiceImpl implements MemberOperationService { | ||
| 27 | |||
| 28 | @Autowired | ||
| 29 | private MemberService memberService; | ||
| 30 | @Autowired | ||
| 31 | private MemberProfileService memberProfileService; | ||
| 32 | @Autowired | ||
| 33 | private MemberVipHistoryService memberVipHistoryService; | ||
| 34 | @Autowired | ||
| 35 | private UserWeixinService userWeixinService; | ||
| 36 | @Autowired | ||
| 37 | private ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 38 | |||
| 39 | public void asyncUpdateMemberVip(MemberDTO memberDTO) { | ||
| 40 | String code = memberDTO.getCode(); | ||
| 41 | MemberDTO memberDTO1 = this.findByCode(code); | ||
| 42 | memberDTO1.setVip(memberDTO.getVip()); | ||
| 43 | memberDTO1.setVipExpireTime(memberDTO.getVipExpireTime()); | ||
| 44 | Member member = new Member(); | ||
| 45 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 46 | this.update(member); | ||
| 47 | } | ||
| 48 | |||
| 49 | // @Cacheable(key = "#memberId") | ||
| 50 | @Override | ||
| 51 | public MemberDTO findById(Long memberId) { | ||
| 52 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 53 | return Objects.nonNull(memberId) ? memberDTO : null; | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | public MemberDTO findByCode(String code) { | ||
| 58 | return this.memberService.findByCode(code); | ||
| 59 | } | ||
| 60 | |||
| 61 | public void createVipHistory(MemberVipHistory memberVipHistory){ | ||
| 62 | this.memberVipHistoryService.create(memberVipHistory); | ||
| 63 | } | ||
| 64 | |||
| 65 | // @CachePut(key = "#resources.id") | ||
| 66 | @Override | ||
| 67 | public MemberDTO update(Member resources) { | ||
| 68 | MemberDTO memberDTO = this.memberService.update(resources); | ||
| 69 | return memberDTO; | ||
| 70 | } | ||
| 71 | |||
| 72 | @Override | ||
| 73 | public MemberDTO doUpdateMember(Member resources) { | ||
| 74 | Long id = resources.getId(); | ||
| 75 | Assert.notNull(id,"ERROR MSG: MemberOperationServiceImpl -> doUpdateMemberInfo -> id not be null!!"); | ||
| 76 | return this.update(resources); | ||
| 77 | } | ||
| 78 | |||
| 79 | // @CachePut(key = "#resources.id") | ||
| 80 | @Override | ||
| 81 | public MemberDTO doInsertMember(Member resources) { | ||
| 82 | return this.memberService.create(resources); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | @Override | ||
| 88 | public MemberDTO doUpdateMemberExp(Member member) { | ||
| 89 | |||
| 90 | return this.update(member); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | // @CachePut(key = "#resources.id") | ||
| 95 | @Override | ||
| 96 | public MemberDTO doUpdateMemberPoints(Member resources) { | ||
| 97 | return this.memberService.doUpdateMemberPoints(resources); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Override | ||
| 101 | public MemberDTO doUpdateMemberCoupon(Member member) { | ||
| 102 | return this.update(member); | ||
| 103 | } | ||
| 104 | |||
| 105 | @Override | ||
| 106 | public MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appid) { | ||
| 107 | |||
| 108 | // 会员加密信息 | ||
| 109 | MemberProfileDTO memberProfileDTO_0 = this.findMemberProfileByMemberId(memberId); | ||
| 110 | |||
| 111 | // 会员信息 | ||
| 112 | MemberDTO memberDTO = this.findById(memberId); | ||
| 113 | |||
| 114 | // 初始化会员加密信息 | ||
| 115 | MemberProfileDTO memberProfileDTO_1 = this.configMemberProfile(memberProfileDTO_0,memberDTO,appid); | ||
| 116 | |||
| 117 | return memberProfileDTO_1; | ||
| 118 | } | ||
| 119 | |||
| 120 | /** | ||
| 121 | * 配置会员信息 | ||
| 122 | * @param memberProfileDTO_0 | ||
| 123 | * @param memberDTO | ||
| 124 | * @return | ||
| 125 | */ | ||
| 126 | private MemberProfileDTO configMemberProfile(MemberProfileDTO memberProfileDTO_0, MemberDTO memberDTO, String appid) { | ||
| 127 | |||
| 128 | if (Objects.isNull(memberProfileDTO_0)) return memberProfileDTO_0; | ||
| 129 | |||
| 130 | MemberProfileDTO memberProfileDTO = new MemberProfileDTO(); | ||
| 131 | BeanUtils.copyProperties(memberProfileDTO_0,memberProfileDTO); | ||
| 132 | |||
| 133 | // vip | ||
| 134 | Integer vip = memberDTO.getVip(); | ||
| 135 | // 过期时间 | ||
| 136 | LocalDateTime vipExpireTime = memberDTO.getVipExpireTime(); | ||
| 137 | |||
| 138 | Long timeLong = 0L; | ||
| 139 | if (ObjectUtil.isNotNull(vipExpireTime)) { | ||
| 140 | |||
| 141 | // 检查vip | ||
| 142 | MemberDTO memberDTO1 = this.checkVipStatus(memberDTO,vipExpireTime,appid); | ||
| 143 | |||
| 144 | // 更新会员信息 | ||
| 145 | this.threadPoolTaskExecutor.execute(()->{ | ||
| 146 | Member member = new Member(); | ||
| 147 | BeanUtils.copyProperties(memberDTO1,member); | ||
| 148 | this.memberService.update(member); | ||
| 149 | }); | ||
| 150 | |||
| 151 | vip = memberDTO1.getVip(); | ||
| 152 | LocalDateTime vipExpireTime1 = memberDTO1.getVipExpireTime(); | ||
| 153 | if (Objects.nonNull(vipExpireTime1)) { | ||
| 154 | timeLong = vipExpireTime1.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | // 过期时间 | ||
| 159 | memberProfileDTO.setVipExpireTime(timeLong); | ||
| 160 | // 头像 | ||
| 161 | memberProfileDTO.setAvatarUrl(memberDTO.getAvatarUrl()); | ||
| 162 | // 生日 | ||
| 163 | memberProfileDTO.setBirthday(memberDTO.getBirthday()); | ||
| 164 | // 性别 | ||
| 165 | memberProfileDTO.setGender(memberDTO.getGender()); | ||
| 166 | // 会员id | ||
| 167 | memberProfileDTO.setMemberId(memberDTO.getId()); | ||
| 168 | // vip | ||
| 169 | memberProfileDTO.setVip(vip); | ||
| 170 | |||
| 171 | return memberProfileDTO; | ||
| 172 | } | ||
| 173 | |||
| 174 | /** | ||
| 175 | * 检查vip是否过期 | ||
| 176 | * 1.当前vip如果过期则查看是否有vip历史变动 | ||
| 177 | * 2.如果vip变动历史有记录则获取vip变动记录 | ||
| 178 | * 3.如果vip没有记录则查看是否关注了公众号 | ||
| 179 | * @param vipExpireTime | ||
| 180 | * @return | ||
| 181 | */ | ||
| 182 | private MemberDTO checkVipStatus(MemberDTO memberDTO, LocalDateTime vipExpireTime, String appid) { | ||
| 183 | |||
| 184 | Long memberId = memberDTO.getId(); | ||
| 185 | LocalDateTime nowTime = LocalDateTime.now(); | ||
| 186 | |||
| 187 | //vip过期,回退上个vip状态 同时修改member表vip | ||
| 188 | if (nowTime.compareTo(vipExpireTime) >= 0 ) { | ||
| 189 | |||
| 190 | Integer vip = 0; | ||
| 191 | LocalDateTime vipExpireTime1 = memberDTO.getVipExpireTime(); | ||
| 192 | |||
| 193 | //查询小于失效时间的那条记录 查不到 取微信表里 关注状态 | ||
| 194 | MemberVipHistory memberVipHistory = this.memberVipHistoryService.findByTime(memberId, nowTime); | ||
| 195 | |||
| 196 | if (ObjectUtil.isNull(memberVipHistory.getId())) { | ||
| 197 | |||
| 198 | UserWeixinDTO userWeixin = this.userWeixinService.findFirstByMemberIdAndAppid(memberId, appid); | ||
| 199 | // 微信公众号关注的状态 0:未关注 1:关注 | ||
| 200 | Integer status = userWeixin.getStatus(); | ||
| 201 | |||
| 202 | if (status != 1) vip = 0; else vip = 1; | ||
| 203 | vipExpireTime1 = null; | ||
| 204 | |||
| 205 | } else { | ||
| 206 | |||
| 207 | vip = memberVipHistory.getVip(); | ||
| 208 | vipExpireTime1 = memberVipHistory.getVipExpireTime(); | ||
| 209 | } | ||
| 210 | |||
| 211 | memberDTO.setVipExpireTime(vipExpireTime1); | ||
| 212 | memberDTO.setVip(vip); | ||
| 213 | } | ||
| 214 | |||
| 215 | return memberDTO; | ||
| 216 | } | ||
| 217 | |||
| 218 | /** | ||
| 219 | * 查询会员加密信息 | ||
| 220 | * @param memberId | ||
| 221 | * @return | ||
| 222 | */ | ||
| 223 | private MemberProfileDTO findMemberProfileByMemberId(Long memberId) { | ||
| 224 | return this.memberProfileService.findByMemberId(memberId); | ||
| 225 | } | ||
| 226 | } |
| 1 | package com.topdraw.business.process.service.impl.member; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.profile.domain.MemberProfile; | ||
| 5 | import com.topdraw.business.module.member.profile.service.MemberProfileService; | ||
| 6 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | ||
| 7 | import com.topdraw.business.module.member.service.MemberService; | ||
| 8 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 9 | import com.topdraw.business.process.service.dto.MemberProfileAndMemberDTO; | ||
| 10 | import com.topdraw.business.process.service.member.MemberOperationService; | ||
| 11 | import com.topdraw.business.process.service.member.MemberProfileOperationService; | ||
| 12 | import org.springframework.beans.BeanUtils; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 14 | import org.springframework.stereotype.Service; | ||
| 15 | import org.springframework.util.StringUtils; | ||
| 16 | |||
| 17 | import java.util.Objects; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @author : | ||
| 21 | * @description: | ||
| 22 | * @function : | ||
| 23 | * @date :Created in 2022/3/20 17:34 | ||
| 24 | * @version: : | ||
| 25 | * @modified By: | ||
| 26 | * @since : modified in 2022/3/20 17:34 | ||
| 27 | */ | ||
| 28 | @Service | ||
| 29 | public class MemberProfileOperationServiceImpl implements MemberProfileOperationService { | ||
| 30 | |||
| 31 | @Autowired | ||
| 32 | private MemberProfileService memberProfileService; | ||
| 33 | @Autowired | ||
| 34 | private MemberOperationService memberOperationService; | ||
| 35 | @Autowired | ||
| 36 | private MemberService memberService; | ||
| 37 | |||
| 38 | public void asyncCreateMemberProfile(MemberProfileDTO memberProfileDTO) { | ||
| 39 | String memberCode = memberProfileDTO.getMemberCode(); | ||
| 40 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 41 | Long memberId = memberDTO.getId(); | ||
| 42 | MemberProfileDTO _memberProfileDTO = this.memberProfileService.findByMemberId(memberId); | ||
| 43 | if (Objects.isNull(_memberProfileDTO.getId())) { | ||
| 44 | memberProfileDTO.setMemberId(memberId); | ||
| 45 | this.createMemberProfileAndSyncMember(memberProfileDTO, memberDTO); | ||
| 46 | } | ||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | private void createMemberProfileAndSyncMember(MemberProfileDTO memberProfileDTO, MemberDTO memberDTO) { | ||
| 51 | this.createMemberProfile(memberProfileDTO); | ||
| 52 | this.syncMember(memberProfileDTO, memberDTO); | ||
| 53 | } | ||
| 54 | |||
| 55 | private void syncMember(MemberProfileDTO memberProfileDTO, MemberDTO memberDTO) { | ||
| 56 | memberDTO.setAvatarUrl(memberProfileDTO.getAvatarUrl()); | ||
| 57 | memberDTO.setNickname(memberProfileDTO.getRealname()); | ||
| 58 | memberDTO.setGender(memberProfileDTO.getGender()); | ||
| 59 | Member member = new Member(); | ||
| 60 | BeanUtils.copyProperties(memberDTO, member); | ||
| 61 | this.memberService.update(member); | ||
| 62 | } | ||
| 63 | |||
| 64 | private void createMemberProfile(MemberProfileDTO memberProfileDTO) { | ||
| 65 | MemberProfile memberProfile = new MemberProfile(); | ||
| 66 | BeanUtils.copyProperties(memberProfileDTO, memberProfile); | ||
| 67 | this.memberProfileService.createDefault(memberProfile); | ||
| 68 | } | ||
| 69 | |||
| 70 | public MemberProfileDTO asyncMemberProfile(MemberProfileDTO memberProfileDTO){ | ||
| 71 | String memberCode = memberProfileDTO.getMemberCode(); | ||
| 72 | MemberDTO memberDTO = this.memberService.findByCode(memberCode); | ||
| 73 | Long memberId = memberDTO.getId(); | ||
| 74 | MemberProfileDTO _memberProfileDTO = this.memberProfileService.findByMemberId(memberId); | ||
| 75 | memberProfileDTO.setId(_memberProfileDTO.getId()); | ||
| 76 | memberProfileDTO.setMemberId(memberId); | ||
| 77 | return this.updateMemberProfile(memberProfileDTO); | ||
| 78 | } | ||
| 79 | |||
| 80 | private MemberProfileDTO updateMemberProfile(MemberProfileDTO memberProfileDTO) { | ||
| 81 | MemberProfile memberProfile = new MemberProfile(); | ||
| 82 | BeanUtils.copyProperties(memberProfileDTO, memberProfile); | ||
| 83 | return this.memberProfileService.update(memberProfile); | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | public void asyncMemberProfileAndMember(MemberProfileAndMemberDTO resources) { | ||
| 88 | MemberProfileDTO memberProfileDTO = resources.getMemberProfileDTO(); | ||
| 89 | MemberProfileDTO _memberProfileDTO = this.asyncMemberProfile(memberProfileDTO); | ||
| 90 | |||
| 91 | MemberDTO memberDTO = resources.getMemberDTO(); | ||
| 92 | String code = memberDTO.getCode(); | ||
| 93 | if (!StringUtils.isEmpty(code)) { | ||
| 94 | MemberDTO memberDTO1 = this.memberService.findByCode(code); | ||
| 95 | |||
| 96 | Member member = new Member(); | ||
| 97 | BeanUtils.copyProperties(memberDTO1, member); | ||
| 98 | |||
| 99 | member.setNickname(_memberProfileDTO.getRealname()); | ||
| 100 | member.setBirthday(_memberProfileDTO.getBirthday()); | ||
| 101 | member.setGender(_memberProfileDTO.getGender()); | ||
| 102 | this.memberService.update(member); | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | } | ||
| 107 | |||
| 108 | } |
| 1 | package com.topdraw.business.process.service.impl.member; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | ||
| 5 | import com.topdraw.business.module.member.relatedinfo.service.MemberRelatedInfoService; | ||
| 6 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
| 7 | import com.topdraw.business.process.service.member.MemberRelatedInfoOperationService; | ||
| 8 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.stereotype.Service; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/3/20 18:41 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/3/20 18:41 | ||
| 19 | */ | ||
| 20 | @Service | ||
| 21 | public class MemberRelatedInfoOperationServiceImpl implements MemberRelatedInfoOperationService { | ||
| 22 | |||
| 23 | @Autowired | ||
| 24 | private MemberRelatedInfoService memberRelatedInfoService; | ||
| 25 | |||
| 26 | @Override | ||
| 27 | public MemberRelatedInfoDTO findById(Long id) { | ||
| 28 | return this.memberRelatedInfoService.findById(id); | ||
| 29 | } | ||
| 30 | |||
| 31 | @Override | ||
| 32 | public void create(MemberRelatedInfo resources) { | ||
| 33 | this.memberRelatedInfoService.create(resources); | ||
| 34 | } | ||
| 35 | |||
| 36 | @Override | ||
| 37 | public void update(MemberRelatedInfo resources) { | ||
| 38 | this.memberRelatedInfoService.update(resources); | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public void delete(Long id) { | ||
| 43 | this.memberRelatedInfoService.delete(id); | ||
| 44 | } | ||
| 45 | |||
| 46 | @Override | ||
| 47 | public MemberRelatedInfoDTO findByIdCard(MemberRelatedInfo resources) { | ||
| 48 | return this.memberRelatedInfoService.findByIdCard(resources); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Override | ||
| 52 | public MemberRelatedInfoDTO findByIdCard(String idCard) { | ||
| 53 | return this.memberRelatedInfoService.findByIdCard(idCard); | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId, String idCard) { | ||
| 58 | return this.memberRelatedInfoService.findByMemberIdAndIdCard(memberId, idCard); | ||
| 59 | } | ||
| 60 | |||
| 61 | @Override | ||
| 62 | public MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode, String idCard) { | ||
| 63 | return this.memberRelatedInfoService.findByMemberCodeAndIdCard(memberCode, idCard); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Override | ||
| 67 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(MemberRelatedInfo resources) { | ||
| 68 | return this.memberRelatedInfoService.findByMemberIdAndIdCard(resources); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Override | ||
| 72 | public MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources) { | ||
| 73 | return this.memberRelatedInfoService.findByMemberIdAndIdCard(member, resources); | ||
| 74 | } | ||
| 75 | } |
| 1 | package com.topdraw.business.process.service.member; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; | ||
| 5 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 6 | |||
| 7 | public interface MemberOperationService { | ||
| 8 | |||
| 9 | /** | ||
| 10 | * | ||
| 11 | * @param memberId | ||
| 12 | * @return | ||
| 13 | */ | ||
| 14 | MemberDTO findById(Long memberId); | ||
| 15 | |||
| 16 | /** | ||
| 17 | * | ||
| 18 | * @param code | ||
| 19 | * @return | ||
| 20 | */ | ||
| 21 | MemberDTO findByCode(String code); | ||
| 22 | |||
| 23 | /** | ||
| 24 | * 修改会员 | ||
| 25 | * @param resources | ||
| 26 | */ | ||
| 27 | MemberDTO update(Member resources); | ||
| 28 | |||
| 29 | /** | ||
| 30 | * | ||
| 31 | * @param member | ||
| 32 | */ | ||
| 33 | MemberDTO doUpdateMember(Member member); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * | ||
| 37 | * @param member | ||
| 38 | */ | ||
| 39 | MemberDTO doInsertMember(Member member); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * | ||
| 43 | * @param member | ||
| 44 | */ | ||
| 45 | MemberDTO doUpdateMemberExp(Member member); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * | ||
| 49 | * @param member | ||
| 50 | */ | ||
| 51 | MemberDTO doUpdateMemberPoints(Member member); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * | ||
| 55 | * @param member | ||
| 56 | */ | ||
| 57 | MemberDTO doUpdateMemberCoupon(Member member); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * | ||
| 61 | * @param memberId | ||
| 62 | * @param appid | ||
| 63 | * @return | ||
| 64 | */ | ||
| 65 | MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appid); | ||
| 66 | |||
| 67 | } |
src/main/java/com/topdraw/business/process/service/member/MemberRelatedInfoOperationService.java
0 → 100644
| 1 | package com.topdraw.business.process.service.member; | ||
| 2 | |||
| 3 | import com.topdraw.business.module.member.domain.Member; | ||
| 4 | import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo; | ||
| 5 | import com.topdraw.business.module.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author XiangHan | ||
| 9 | * @date 2021-10-22 | ||
| 10 | */ | ||
| 11 | public interface MemberRelatedInfoOperationService { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * 根据ID查询 | ||
| 15 | * @param id ID | ||
| 16 | * @return MemberRelatedInfoDTO | ||
| 17 | */ | ||
| 18 | MemberRelatedInfoDTO findById(Long id); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * 新增 | ||
| 22 | * @param resources | ||
| 23 | */ | ||
| 24 | void create(MemberRelatedInfo resources); | ||
| 25 | |||
| 26 | /** | ||
| 27 | * 修改 | ||
| 28 | * @param resources | ||
| 29 | */ | ||
| 30 | void update(MemberRelatedInfo resources); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 删除 | ||
| 34 | * @param id | ||
| 35 | */ | ||
| 36 | void delete(Long id); | ||
| 37 | |||
| 38 | /** | ||
| 39 | * 通过身份证查询 | ||
| 40 | * @param resources | ||
| 41 | * @return | ||
| 42 | */ | ||
| 43 | MemberRelatedInfoDTO findByIdCard(MemberRelatedInfo resources); | ||
| 44 | |||
| 45 | /** | ||
| 46 | * 通过身份证查询 | ||
| 47 | * @param idCard 身份证 | ||
| 48 | * @return | ||
| 49 | */ | ||
| 50 | MemberRelatedInfoDTO findByIdCard(String idCard); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * | ||
| 54 | * @param memberId | ||
| 55 | * @param idCard | ||
| 56 | * @return | ||
| 57 | */ | ||
| 58 | MemberRelatedInfoDTO findByMemberIdAndIdCard(Long memberId, String idCard); | ||
| 59 | |||
| 60 | /** | ||
| 61 | * | ||
| 62 | * @param memberCode | ||
| 63 | * @param idCard | ||
| 64 | * @return | ||
| 65 | */ | ||
| 66 | MemberRelatedInfoDTO findByMemberCodeAndIdCard(String memberCode, String idCard); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * | ||
| 70 | * @param resources | ||
| 71 | * @return | ||
| 72 | */ | ||
| 73 | MemberRelatedInfoDTO findByMemberIdAndIdCard(MemberRelatedInfo resources); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * | ||
| 77 | * @param member | ||
| 78 | * @param resources | ||
| 79 | * @return | ||
| 80 | */ | ||
| 81 | MemberRelatedInfoDTO findByMemberIdAndIdCard(Member member, MemberRelatedInfo resources); | ||
| 82 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | public class LocalConstants { | ||
| 4 | |||
| 5 | // 小屏侧 | ||
| 6 | public static final String ENV_MOBILE = "mobile"; | ||
| 7 | |||
| 8 | // 大屏侧 | ||
| 9 | public static final String ENV_VIS = "vis"; | ||
| 10 | |||
| 11 | // 服务侧 | ||
| 12 | public static final String ENV_SERVICE = "service"; | ||
| 13 | |||
| 14 | // 管理侧 | ||
| 15 | public static final String ENV_MANAGEMENT = "management"; | ||
| 16 | |||
| 17 | // 大屏类型 | ||
| 18 | public static final int DEVICE_VIS = 1; | ||
| 19 | |||
| 20 | // 小屏类型 | ||
| 21 | public static final int DEVICE_MOBILE = 2; | ||
| 22 | |||
| 23 | // 平台类型 | ||
| 24 | public static final String PLATFORM_TYPE_SERVICE = "service"; | ||
| 25 | public static final String PLATFORM_TYPE_MANAGEMENT = "management"; | ||
| 26 | |||
| 27 | //会员平台类型 类型 1:大屏;2:小屏 | ||
| 28 | public static final Integer MEMBER_PLATFORM_TYPE_VIS = 1; | ||
| 29 | public static final Integer MEMBER_PLATFORM_TYPE_WEIXIN = 2; | ||
| 30 | |||
| 31 | // 重庆_重数_vis | ||
| 32 | public static final String APP_CODE_CHONGQING_CHONGSHU_VIS = "CHONGQING_chongshu_vis"; | ||
| 33 | |||
| 34 | |||
| 35 | // 事件类型 3:参加活动 | ||
| 36 | public static final Integer EVT_TYPE_ACTIVITY = 3; | ||
| 37 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import org.apache.commons.collections4.CollectionUtils; | ||
| 4 | import org.apache.commons.lang3.StringUtils; | ||
| 5 | import org.springframework.amqp.core.*; | ||
| 6 | import org.springframework.amqp.rabbit.core.RabbitAdmin; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Component; | ||
| 9 | |||
| 10 | import javax.annotation.PostConstruct; | ||
| 11 | import javax.annotation.Resource; | ||
| 12 | import javax.naming.ConfigurationException; | ||
| 13 | import java.util.List; | ||
| 14 | import java.util.Map; | ||
| 15 | |||
| 16 | @Component | ||
| 17 | public class RabbitMqBindingConfig { | ||
| 18 | |||
| 19 | /**************************************************数据源选择*************************************************************/ | ||
| 20 | |||
| 21 | @Autowired | ||
| 22 | private RabbitMqSourceConfig rabbitMqSourceConfig; | ||
| 23 | @Autowired | ||
| 24 | private RabbitMqCustomConfig rabbitMqCustomConfig; | ||
| 25 | |||
| 26 | @Resource(name = "managementRabbitAdmin") | ||
| 27 | private RabbitAdmin managementRabbitAdmin; | ||
| 28 | |||
| 29 | @Resource(name = "serviceRabbitAdmin") | ||
| 30 | private RabbitAdmin serviceRabbitAdmin; | ||
| 31 | |||
| 32 | |||
| 33 | @PostConstruct | ||
| 34 | public void initBinding() throws ConfigurationException { | ||
| 35 | |||
| 36 | // String source = rabbitMqSourceConfig.getActiveSource(); | ||
| 37 | |||
| 38 | List<Map<String, String>> list = rabbitMqCustomConfig.getList(); | ||
| 39 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 40 | |||
| 41 | for (Map<String, String> map : list) { | ||
| 42 | |||
| 43 | String exchange = map.get("exchange"); | ||
| 44 | String exchangeType = map.get("exchange-type"); | ||
| 45 | Exchange exchange_ = null; | ||
| 46 | switch (exchangeType) { | ||
| 47 | case ExchangeTypes.TOPIC: | ||
| 48 | exchange_ = ExchangeBuilder.topicExchange(exchange) | ||
| 49 | .durable(true).build(); | ||
| 50 | break; | ||
| 51 | case ExchangeTypes.FANOUT: | ||
| 52 | exchange_ = ExchangeBuilder.fanoutExchange(exchange) | ||
| 53 | .durable(true).build(); | ||
| 54 | break; | ||
| 55 | case ExchangeTypes.HEADERS: | ||
| 56 | exchange_ = ExchangeBuilder.headersExchange(exchange) | ||
| 57 | .durable(true).build(); | ||
| 58 | break; | ||
| 59 | |||
| 60 | default: | ||
| 61 | exchange_ = ExchangeBuilder.directExchange(exchange) | ||
| 62 | .durable(true).build(); | ||
| 63 | break; | ||
| 64 | } | ||
| 65 | |||
| 66 | String queue = map.get("queue"); | ||
| 67 | Queue queue_ = new Queue(queue); | ||
| 68 | |||
| 69 | String routingKey = map.get("routing-key"); | ||
| 70 | if (StringUtils.isBlank(routingKey)) { | ||
| 71 | routingKey = queue; | ||
| 72 | } | ||
| 73 | |||
| 74 | Binding binding_ = BindingBuilder.bind(queue_).to(exchange_).with(routingKey).and(null); | ||
| 75 | |||
| 76 | |||
| 77 | String active = map.get("active"); | ||
| 78 | switch (active) { | ||
| 79 | case "management": | ||
| 80 | this.managementRabbitAdmin.declareExchange(exchange_); | ||
| 81 | this.managementRabbitAdmin.declareQueue(queue_); | ||
| 82 | this.managementRabbitAdmin.declareBinding(binding_); | ||
| 83 | break; | ||
| 84 | case "service": | ||
| 85 | this.serviceRabbitAdmin.declareExchange(exchange_); | ||
| 86 | this.serviceRabbitAdmin.declareQueue(queue_); | ||
| 87 | this.serviceRabbitAdmin.declareBinding(binding_); | ||
| 88 | break; | ||
| 89 | /* case "service,management": | ||
| 90 | this.serviceRabbitAdmin.declareExchange(exchange_); | ||
| 91 | this.serviceRabbitAdmin.declareQueue(queue_); | ||
| 92 | this.serviceRabbitAdmin.declareBinding(binding_); | ||
| 93 | |||
| 94 | this.managementRabbitAdmin.declareExchange(exchange_); | ||
| 95 | this.managementRabbitAdmin.declareQueue(queue_); | ||
| 96 | this.managementRabbitAdmin.declareBinding(binding_); | ||
| 97 | break;*/ | ||
| 98 | default: | ||
| 99 | |||
| 100 | break; | ||
| 101 | } | ||
| 102 | |||
| 103 | } | ||
| 104 | |||
| 105 | } | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import org.springframework.amqp.core.*; | ||
| 4 | import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | ||
| 5 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; | ||
| 6 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
| 7 | import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| 8 | import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; | ||
| 9 | import org.springframework.beans.factory.annotation.Qualifier; | ||
| 10 | import org.springframework.beans.factory.annotation.Value; | ||
| 11 | import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; | ||
| 12 | import org.springframework.context.annotation.Bean; | ||
| 13 | import org.springframework.context.annotation.Configuration; | ||
| 14 | import org.springframework.context.annotation.Primary; | ||
| 15 | |||
| 16 | @Configuration | ||
| 17 | public class RabbitMqConfig { | ||
| 18 | |||
| 19 | |||
| 20 | //////////////////////////////////////////////////////// OMO 小屏/////////////////////////////////////////////////////////////// | ||
| 21 | |||
| 22 | /** 获取带参二维码(大屏->小屏) */ | ||
| 23 | public static final String GET_QR_CODE_QUEUE = "queue.qrCode.get"; | ||
| 24 | |||
| 25 | /** 删除全部收藏队列(大屏->小屏) */ | ||
| 26 | public static final String COLLECTION_DELETE_ALL_QUEUE = "queue.collection.deleteall"; | ||
| 27 | |||
| 28 | /** 添加收藏队列(大屏->小屏) */ | ||
| 29 | public static final String COLLECTION_ADD_QUEUE = "queue.collection.add"; | ||
| 30 | |||
| 31 | /** 删除收藏队列(大屏->小屏) */ | ||
| 32 | public static final String COLLECTION_DELETE_QUEUE = "queue.collection.delete"; | ||
| 33 | |||
| 34 | /** 微信侧 公众号关注与取消关注 */ | ||
| 35 | public static final String WEIXIN_SUBORUNSUB_QUEUE = "weixin.subOrUnSub.queue"; | ||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | //////////////////////////////////////////////////////// 重数 /////////////////////////////////////////////////////////////// | ||
| 47 | |||
| 48 | /** 路由(事件)--direct route.key*/ | ||
| 49 | // 事件,uc-gateway | ||
| 50 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_AAA = "uc.route.key.direct.event.aaa"; | ||
| 51 | // uc-service 服务侧 | ||
| 52 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_BBB = "uc.route.key.direct.event.bbb"; | ||
| 53 | // uc-service 管理侧 | ||
| 54 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_CCC = "uc.route.key.direct.event.ccc"; | ||
| 55 | |||
| 56 | @Value("${mutil-mq.service.host}") | ||
| 57 | private String serviceHost; | ||
| 58 | @Value("${mutil-mq.service.port}") | ||
| 59 | private Integer servicePort; | ||
| 60 | @Value("${mutil-mq.service.username}") | ||
| 61 | private String serviceUserName; | ||
| 62 | @Value("${mutil-mq.service.password}") | ||
| 63 | private String servicePassword; | ||
| 64 | @Value("${mutil-mq.service.virtual-host}") | ||
| 65 | private String serviceVirtualHost; | ||
| 66 | |||
| 67 | @Bean(name = "serviceConnectionFactory") | ||
| 68 | @Primary | ||
| 69 | public ConnectionFactory serviceConnectionFactory(){ | ||
| 70 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 71 | /*connectionFactory.setHost("139.196.145.150"); | ||
| 72 | connectionFactory.setPort(5672); | ||
| 73 | connectionFactory.setUsername("admin"); | ||
| 74 | connectionFactory.setPassword("Topdraw1qaz"); | ||
| 75 | connectionFactory.setVirtualHost("member_center");*/ | ||
| 76 | |||
| 77 | connectionFactory.setHost(serviceHost); | ||
| 78 | connectionFactory.setPort(servicePort); | ||
| 79 | connectionFactory.setUsername(serviceUserName); | ||
| 80 | connectionFactory.setPassword(servicePassword); | ||
| 81 | connectionFactory.setVirtualHost(serviceVirtualHost); | ||
| 82 | return connectionFactory; | ||
| 83 | } | ||
| 84 | |||
| 85 | @Bean(name = "serviceRabbitListenerContainerFactory") | ||
| 86 | @Primary | ||
| 87 | public RabbitListenerContainerFactory userCenterRabbitListenerContainerFactory( | ||
| 88 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | ||
| 89 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 90 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
| 91 | containerFactoryConfigurer.configure(factory,connectionFactory); | ||
| 92 | return factory; | ||
| 93 | } | ||
| 94 | |||
| 95 | @Bean(name = "serviceRabbitTemplate") | ||
| 96 | public RabbitTemplate userCenterRabbitTemplate(ConnectionFactory ucServiceConnectionFactory){ | ||
| 97 | RabbitTemplate u = new RabbitTemplate(ucServiceConnectionFactory); | ||
| 98 | return u; | ||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | @Value("${mutil-mq.management.host}") | ||
| 104 | private String managementHost; | ||
| 105 | @Value("${mutil-mq.management.port}") | ||
| 106 | private Integer managementPort; | ||
| 107 | @Value("${mutil-mq.management.username}") | ||
| 108 | private String managementUserName; | ||
| 109 | @Value("${mutil-mq.management.password}") | ||
| 110 | private String managementPassword; | ||
| 111 | @Value("${mutil-mq.management.virtual-host}") | ||
| 112 | private String managementVirtualHost; | ||
| 113 | |||
| 114 | @Bean(name = "managementConnectionFactory") | ||
| 115 | public ConnectionFactory managementConnectionFactory(){ | ||
| 116 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 117 | /*connectionFactory.setHost("139.196.192.242"); | ||
| 118 | connectionFactory.setPort(5672); | ||
| 119 | connectionFactory.setUsername("member_center"); | ||
| 120 | connectionFactory.setPassword("Tjlh@2021"); | ||
| 121 | connectionFactory.setVirtualHost("member_center");*/ | ||
| 122 | connectionFactory.setHost(managementHost); | ||
| 123 | connectionFactory.setPort(managementPort); | ||
| 124 | connectionFactory.setUsername(managementUserName); | ||
| 125 | connectionFactory.setPassword(managementPassword); | ||
| 126 | connectionFactory.setVirtualHost(managementVirtualHost); | ||
| 127 | return connectionFactory; | ||
| 128 | } | ||
| 129 | |||
| 130 | @Bean(name = "managementRabbitListenerContainerFactory") | ||
| 131 | public RabbitListenerContainerFactory memberServiceRabbitListenerContainerFactory( | ||
| 132 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | ||
| 133 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 134 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
| 135 | containerFactoryConfigurer.configure(factory,connectionFactory); | ||
| 136 | return factory; | ||
| 137 | } | ||
| 138 | |||
| 139 | @Bean(name = "managementRabbitTemplate") | ||
| 140 | public RabbitTemplate memberServiceRabbitTemplate(ConnectionFactory ucGatewayConnectionFactory){ | ||
| 141 | RabbitTemplate u = new RabbitTemplate(ucGatewayConnectionFactory); | ||
| 142 | return u; | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * 处理事件 | ||
| 147 | * @return org.springframework.amqp.core.Queue | ||
| 148 | * @author XiangHan | ||
| 149 | * @date 2021/9/7 10:19 上午 | ||
| 150 | */ | ||
| 151 | @Bean | ||
| 152 | public Queue eventDirect() { | ||
| 153 | return new Queue(UC_ROUTE_KEY_DIRECT_EVENT_AAA); | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | import org.apache.commons.collections4.CollectionUtils; | ||
| 5 | import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 6 | import org.springframework.context.annotation.Configuration; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | |||
| 11 | @Data | ||
| 12 | @Configuration | ||
| 13 | @ConfigurationProperties(prefix = "service.mq") | ||
| 14 | public class RabbitMqCustomConfig { | ||
| 15 | |||
| 16 | private List<Map<String, String>> list; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * viewRecord | ||
| 20 | * @return | ||
| 21 | */ | ||
| 22 | public Map<String, String> getViewRecordInfo() { | ||
| 23 | |||
| 24 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 25 | |||
| 26 | for (Map<String, String> map : list) { | ||
| 27 | String type = map.get("source"); | ||
| 28 | if (type.equalsIgnoreCase("viewRecord")) { | ||
| 29 | return map; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
| 34 | |||
| 35 | return null; | ||
| 36 | } | ||
| 37 | |||
| 38 | /** | ||
| 39 | * ucg_event | ||
| 40 | * @return | ||
| 41 | */ | ||
| 42 | public Map<String, String> getUcgEventInfo() { | ||
| 43 | |||
| 44 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 45 | |||
| 46 | for (Map<String, String> map : list) { | ||
| 47 | String type = map.get("source"); | ||
| 48 | if (type.equalsIgnoreCase("event")) { | ||
| 49 | return map; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 55 | return null; | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * ucg_collection | ||
| 60 | * @return | ||
| 61 | */ | ||
| 62 | public Map<String, String> getUcgCollectionInfo() { | ||
| 63 | |||
| 64 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 65 | |||
| 66 | for (Map<String, String> map : list) { | ||
| 67 | String type = map.get("source"); | ||
| 68 | if (type.equalsIgnoreCase("collection")) { | ||
| 69 | return map; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | return null; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * uce | ||
| 80 | * @return | ||
| 81 | */ | ||
| 82 | public Map<String, String> getUceInfo() { | ||
| 83 | |||
| 84 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 85 | |||
| 86 | for (Map<String, String> map : list) { | ||
| 87 | String type = map.get("source"); | ||
| 88 | if (type.equalsIgnoreCase("uce")) { | ||
| 89 | return map; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | } | ||
| 94 | |||
| 95 | return null; | ||
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 | * eventBus | ||
| 100 | * @return | ||
| 101 | */ | ||
| 102 | public Map<String, String> getEventBusInfo() { | ||
| 103 | |||
| 104 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 105 | |||
| 106 | for (Map<String, String> map : list) { | ||
| 107 | String type = map.get("source"); | ||
| 108 | if (type.equalsIgnoreCase("eventBus")) { | ||
| 109 | return map; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | } | ||
| 114 | |||
| 115 | return null; | ||
| 116 | } | ||
| 117 | |||
| 118 | /** | ||
| 119 | |||
| 120 | * @return | ||
| 121 | */ | ||
| 122 | public Map<String, String> getWechatInfo() { | ||
| 123 | |||
| 124 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 125 | |||
| 126 | for (Map<String, String> map : list) { | ||
| 127 | String type = map.get("source"); | ||
| 128 | if (type.equalsIgnoreCase("wechat")) { | ||
| 129 | return map; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 | return null; | ||
| 136 | } | ||
| 137 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | import org.apache.commons.collections4.CollectionUtils; | ||
| 5 | import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 6 | import org.springframework.context.annotation.Configuration; | ||
| 7 | |||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @author : | ||
| 13 | * @description: | ||
| 14 | * @function : | ||
| 15 | * @date :Created in 2022/5/12 12:37 | ||
| 16 | * @version: : | ||
| 17 | * @modified By: | ||
| 18 | * @since : modified in 2022/5/12 12:37 | ||
| 19 | */ | ||
| 20 | @Data | ||
| 21 | @Configuration | ||
| 22 | @ConfigurationProperties(prefix = "service.mq.error.logs") | ||
| 23 | public class RabbitMqErrorLogConfig { | ||
| 24 | |||
| 25 | private List<Map<String, String>> list; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * uce | ||
| 29 | * @return | ||
| 30 | */ | ||
| 31 | public Map<String, String> getWechatError() { | ||
| 32 | |||
| 33 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 34 | |||
| 35 | for (Map<String, String> map : list) { | ||
| 36 | String type = map.get("type"); | ||
| 37 | if (type.equalsIgnoreCase("wechat")) { | ||
| 38 | return map; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | } | ||
| 43 | |||
| 44 | return null; | ||
| 45 | } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * uce | ||
| 49 | * @return | ||
| 50 | */ | ||
| 51 | public Map<String, String> getUceError() { | ||
| 52 | |||
| 53 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 54 | |||
| 55 | for (Map<String, String> map : list) { | ||
| 56 | String type = map.get("type"); | ||
| 57 | if (type.equalsIgnoreCase("uce")) { | ||
| 58 | return map; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | } | ||
| 63 | |||
| 64 | return null; | ||
| 65 | } | ||
| 66 | |||
| 67 | /** | ||
| 68 | * ucg | ||
| 69 | * @return | ||
| 70 | */ | ||
| 71 | public Map<String, String> getUcgError() { | ||
| 72 | |||
| 73 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 74 | |||
| 75 | for (Map<String, String> map : list) { | ||
| 76 | String type = map.get("type"); | ||
| 77 | if (type.equalsIgnoreCase("ucg")) { | ||
| 78 | return map; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 | return null; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 88 | * 数据总线 | ||
| 89 | * @return | ||
| 90 | */ | ||
| 91 | public Map<String, String> getEventBusError() { | ||
| 92 | |||
| 93 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 94 | |||
| 95 | for (Map<String, String> map : list) { | ||
| 96 | String type = map.get("type"); | ||
| 97 | if (type.equalsIgnoreCase("eventBus")) { | ||
| 98 | return map; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | } | ||
| 103 | |||
| 104 | return null; | ||
| 105 | } | ||
| 106 | |||
| 107 | /** | ||
| 108 | * 个人信息完善 | ||
| 109 | * @return | ||
| 110 | */ | ||
| 111 | public Map<String, String> getCompleteInfoError() { | ||
| 112 | |||
| 113 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 114 | |||
| 115 | for (Map<String, String> map : list) { | ||
| 116 | String type = map.get("type"); | ||
| 117 | if (type.equalsIgnoreCase("completeInfo")) { | ||
| 118 | return map; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | } | ||
| 123 | |||
| 124 | return null; | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * 订购 | ||
| 129 | * @return | ||
| 130 | */ | ||
| 131 | public Map<String, String> getOrderError() { | ||
| 132 | |||
| 133 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 134 | |||
| 135 | for (Map<String, String> map : list) { | ||
| 136 | String type = map.get("type"); | ||
| 137 | if (type.equalsIgnoreCase("order")) { | ||
| 138 | return map; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | } | ||
| 143 | |||
| 144 | return null; | ||
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * 参加活动 | ||
| 149 | * @return | ||
| 150 | */ | ||
| 151 | public Map<String, String> getActivityError() { | ||
| 152 | |||
| 153 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 154 | |||
| 155 | for (Map<String, String> map : list) { | ||
| 156 | String type = map.get("type"); | ||
| 157 | if (type.equalsIgnoreCase("activity")) { | ||
| 158 | return map; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | } | ||
| 163 | |||
| 164 | return null; | ||
| 165 | } | ||
| 166 | |||
| 167 | /** | ||
| 168 | * 签到 | ||
| 169 | * @return | ||
| 170 | */ | ||
| 171 | public Map<String, String> getSignError() { | ||
| 172 | |||
| 173 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 174 | |||
| 175 | for (Map<String, String> map : list) { | ||
| 176 | String type = map.get("type"); | ||
| 177 | if (type.equalsIgnoreCase("sign")) { | ||
| 178 | return map; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | } | ||
| 183 | |||
| 184 | return null; | ||
| 185 | } | ||
| 186 | |||
| 187 | /** | ||
| 188 | * 观影、播放记录 | ||
| 189 | * @return | ||
| 190 | */ | ||
| 191 | public Map<String, String> getPlayError() { | ||
| 192 | |||
| 193 | if (CollectionUtils.isNotEmpty(list)) { | ||
| 194 | |||
| 195 | for (Map<String, String> map : list) { | ||
| 196 | String type = map.get("type"); | ||
| 197 | if (type.equalsIgnoreCase("play")) { | ||
| 198 | return map; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | } | ||
| 203 | |||
| 204 | return null; | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | import org.apache.commons.collections4.MapUtils; | ||
| 5 | import org.apache.commons.lang3.StringUtils; | ||
| 6 | import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | ||
| 7 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; | ||
| 8 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
| 9 | import org.springframework.amqp.rabbit.core.RabbitAdmin; | ||
| 10 | import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| 11 | import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; | ||
| 12 | import org.springframework.beans.factory.annotation.Qualifier; | ||
| 13 | import org.springframework.beans.factory.annotation.Value; | ||
| 14 | import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; | ||
| 15 | import org.springframework.context.annotation.Bean; | ||
| 16 | import org.springframework.context.annotation.Configuration; | ||
| 17 | import org.springframework.context.annotation.Primary; | ||
| 18 | |||
| 19 | import javax.naming.ConfigurationException; | ||
| 20 | import java.util.Map; | ||
| 21 | import java.util.Objects; | ||
| 22 | |||
| 23 | @Data | ||
| 24 | @Configuration | ||
| 25 | public class RabbitMqSourceConfig { | ||
| 26 | |||
| 27 | @Value("${mutil-mq.service.host}") | ||
| 28 | private String serviceHost; | ||
| 29 | @Value("${mutil-mq.service.port}") | ||
| 30 | private Integer servicePort; | ||
| 31 | @Value("${mutil-mq.service.username}") | ||
| 32 | private String serviceUserName; | ||
| 33 | @Value("${mutil-mq.service.password}") | ||
| 34 | private String servicePassword; | ||
| 35 | @Value("${mutil-mq.service.virtual-host}") | ||
| 36 | private String serviceVirtualHost; | ||
| 37 | |||
| 38 | public static final String SERVICE_ = "serviceRabbitListenerContainerFactory"; | ||
| 39 | |||
| 40 | @Bean(name = "serviceConnectionFactory") | ||
| 41 | @Primary | ||
| 42 | public ConnectionFactory serviceConnectionFactory(){ | ||
| 43 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 44 | connectionFactory.setHost(serviceHost); | ||
| 45 | connectionFactory.setPort(servicePort); | ||
| 46 | connectionFactory.setUsername(serviceUserName); | ||
| 47 | connectionFactory.setPassword(servicePassword); | ||
| 48 | connectionFactory.setVirtualHost(serviceVirtualHost); | ||
| 49 | return connectionFactory; | ||
| 50 | } | ||
| 51 | |||
| 52 | @Bean(name = SERVICE_) | ||
| 53 | @Primary | ||
| 54 | public RabbitListenerContainerFactory serviceRabbitListenerContainerFactory( | ||
| 55 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | ||
| 56 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 57 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
| 58 | containerFactoryConfigurer.configure(factory, connectionFactory); | ||
| 59 | return factory; | ||
| 60 | } | ||
| 61 | |||
| 62 | @Bean(name = "serviceRabbitTemplate") | ||
| 63 | public RabbitTemplate serviceRabbitTemplate(ConnectionFactory serviceConnectionFactory){ | ||
| 64 | RabbitTemplate rabbitTemplate = new RabbitTemplate(serviceConnectionFactory); | ||
| 65 | return rabbitTemplate; | ||
| 66 | } | ||
| 67 | |||
| 68 | @Bean(name = "serviceRabbitAdmin") | ||
| 69 | public RabbitAdmin serviceRabbitAdmin( | ||
| 70 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 71 | RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); | ||
| 72 | rabbitAdmin.setAutoStartup(true); | ||
| 73 | return rabbitAdmin; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | public static final String MANAGEMENT_ = "managementRabbitListenerContainerFactory"; | ||
| 78 | |||
| 79 | @Value("${mutil-mq.management.host}") | ||
| 80 | private String managementHost; | ||
| 81 | @Value("${mutil-mq.management.port}") | ||
| 82 | private Integer managementPort; | ||
| 83 | @Value("${mutil-mq.management.username}") | ||
| 84 | private String managementUserName; | ||
| 85 | @Value("${mutil-mq.management.password}") | ||
| 86 | private String managementPassword; | ||
| 87 | @Value("${mutil-mq.management.virtual-host}") | ||
| 88 | private String managementVirtualHost; | ||
| 89 | |||
| 90 | @Bean(name = "managementConnectionFactory") | ||
| 91 | public ConnectionFactory managementConnectionFactory(){ | ||
| 92 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 93 | connectionFactory.setHost(managementHost); | ||
| 94 | connectionFactory.setPort(managementPort); | ||
| 95 | connectionFactory.setUsername(managementUserName); | ||
| 96 | connectionFactory.setPassword(managementPassword); | ||
| 97 | connectionFactory.setVirtualHost(managementVirtualHost); | ||
| 98 | return connectionFactory; | ||
| 99 | } | ||
| 100 | |||
| 101 | @Bean(name = MANAGEMENT_) | ||
| 102 | public RabbitListenerContainerFactory managementRabbitListenerContainerFactory( | ||
| 103 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | ||
| 104 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 105 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
| 106 | containerFactoryConfigurer.configure(factory, connectionFactory); | ||
| 107 | return factory; | ||
| 108 | } | ||
| 109 | |||
| 110 | @Bean(name = "managementRabbitTemplate") | ||
| 111 | public RabbitTemplate managementRabbitTemplate(ConnectionFactory managementConnectionFactory){ | ||
| 112 | RabbitTemplate rabbitTemplate = new RabbitTemplate(managementConnectionFactory); | ||
| 113 | return rabbitTemplate; | ||
| 114 | } | ||
| 115 | |||
| 116 | @Bean(name = "managementRabbitAdmin") | ||
| 117 | public RabbitAdmin managementRabbitAdmin( | ||
| 118 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { | ||
| 119 | RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); | ||
| 120 | rabbitAdmin.setAutoStartup(true); | ||
| 121 | return rabbitAdmin; | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | /**************************************************数据源*************************************************************/ | ||
| 126 | |||
| 127 | |||
| 128 | /*@Value("${service.platform}") | ||
| 129 | private String platform; | ||
| 130 | @Value("${service.active}") | ||
| 131 | private String active; | ||
| 132 | |||
| 133 | public String getActiveSource() throws ConfigurationException { | ||
| 134 | |||
| 135 | if (StringUtils.isBlank(platform)) | ||
| 136 | throw new ConfigurationException("【error】=> platform is none !! "); | ||
| 137 | |||
| 138 | if (StringUtils.isBlank(active)) | ||
| 139 | throw new ConfigurationException("【error】=> active is none !! "); | ||
| 140 | |||
| 141 | if (active.equalsIgnoreCase("service,management") || active.equalsIgnoreCase("management,service")) { | ||
| 142 | return "service,management"; | ||
| 143 | } | ||
| 144 | |||
| 145 | return active; | ||
| 146 | }*/ | ||
| 147 | |||
| 148 | private String chargeSource(String active) { | ||
| 149 | |||
| 150 | if (active.equalsIgnoreCase("management")) { | ||
| 151 | return MANAGEMENT_; | ||
| 152 | } | ||
| 153 | |||
| 154 | if (active.equalsIgnoreCase("service")) { | ||
| 155 | return SERVICE_; | ||
| 156 | } | ||
| 157 | |||
| 158 | return null; | ||
| 159 | } | ||
| 160 | |||
| 161 | /**************************************************uc-getaway 2 uc-consumer*************************************************************/ | ||
| 162 | |||
| 163 | public static final String EVENT_EXCHANGE = "event.exchange"; | ||
| 164 | public static final String EVENT_QUEUE = "event.queue"; | ||
| 165 | |||
| 166 | @Value("#{rabbitMqCustomConfig.getUcgEventInfo()}") | ||
| 167 | private Map<String, String> ucgEventInfo; | ||
| 168 | |||
| 169 | public String getUcgEventQueue(){ | ||
| 170 | if (Objects.nonNull(ucgEventInfo)) { | ||
| 171 | if (MapUtils.isNotEmpty(ucgEventInfo)) { | ||
| 172 | String queue = ucgEventInfo.get("queue"); | ||
| 173 | return queue; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | return EVENT_QUEUE; | ||
| 178 | } | ||
| 179 | |||
| 180 | public String getUcgEventSource(){ | ||
| 181 | if (Objects.nonNull(ucgEventInfo)) { | ||
| 182 | if (MapUtils.isNotEmpty(ucgEventInfo)) { | ||
| 183 | String source = ucgEventInfo.get("active"); | ||
| 184 | if (StringUtils.isNotBlank(source)) { | ||
| 185 | return this.chargeSource(source); | ||
| 186 | } else { | ||
| 187 | return SERVICE_; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | return SERVICE_; | ||
| 193 | } | ||
| 194 | |||
| 195 | public String getUcgEventStartUp(){ | ||
| 196 | if (Objects.nonNull(ucgEventInfo)) { | ||
| 197 | if (MapUtils.isNotEmpty(ucgEventInfo)) { | ||
| 198 | String source = ucgEventInfo.get("active"); | ||
| 199 | if (StringUtils.isNotBlank(source)) { | ||
| 200 | return "true"; | ||
| 201 | } | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | return "false"; | ||
| 206 | } | ||
| 207 | |||
| 208 | /* public static final String COLLECTION_DELETE_ALL_QUEUE = "queue.collection.deleteall"; | ||
| 209 | public static final String COLLECTION_ADD_QUEUE = "queue.collection.add"; | ||
| 210 | public static final String COLLECTION_DELETE_QUEUE = "queue.collection.delete";*/ | ||
| 211 | |||
| 212 | public static final String COLLECTION_EXCHANGE = "collection.exchange"; | ||
| 213 | public static final String COLLECTION_QUEUE = "collection.queue"; | ||
| 214 | |||
| 215 | @Value("#{rabbitMqCustomConfig.getUcgCollectionInfo()}") | ||
| 216 | private Map<String, String> ucgIptvCollectionInfo; | ||
| 217 | |||
| 218 | public String getUcgCollectionQueue(){ | ||
| 219 | if (Objects.nonNull(ucgIptvCollectionInfo)) { | ||
| 220 | if (MapUtils.isNotEmpty(ucgIptvCollectionInfo)) { | ||
| 221 | String queue = ucgIptvCollectionInfo.get("queue"); | ||
| 222 | return queue; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | return COLLECTION_QUEUE; | ||
| 227 | } | ||
| 228 | |||
| 229 | public String getUcgCollectionQueueAdd(){ | ||
| 230 | return "queue.collection.add"; | ||
| 231 | } | ||
| 232 | |||
| 233 | public String getUcgCollectionQueueDelete(){ | ||
| 234 | return "queue.collection.delete"; | ||
| 235 | } | ||
| 236 | |||
| 237 | public String getUcgCollectionQueueDeleteAll(){ | ||
| 238 | return "queue.collection.deleteall"; | ||
| 239 | } | ||
| 240 | |||
| 241 | public String getUcgCollectionSource(){ | ||
| 242 | if (Objects.nonNull(ucgIptvCollectionInfo)) { | ||
| 243 | if (MapUtils.isNotEmpty(ucgIptvCollectionInfo)) { | ||
| 244 | String source = ucgIptvCollectionInfo.get("active"); | ||
| 245 | if (StringUtils.isNotBlank(source)) { | ||
| 246 | return this.chargeSource(source); | ||
| 247 | } else { | ||
| 248 | return SERVICE_; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | return SERVICE_; | ||
| 254 | } | ||
| 255 | |||
| 256 | public String getUcgCollectionStartUp(){ | ||
| 257 | if (Objects.nonNull(ucgIptvCollectionInfo)) { | ||
| 258 | if (MapUtils.isNotEmpty(ucgIptvCollectionInfo)) { | ||
| 259 | String source = ucgIptvCollectionInfo.get("active"); | ||
| 260 | if (StringUtils.isNotBlank(source)) { | ||
| 261 | return "true"; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | return "false"; | ||
| 267 | } | ||
| 268 | |||
| 269 | public static final String VIEW_RECORD_EXCHANGE = "viewRecord.exchange"; | ||
| 270 | public static final String VIEW_RECORD_QUEUE = "viewRecord.queue"; | ||
| 271 | |||
| 272 | @Value("#{rabbitMqCustomConfig.getViewRecordInfo()}") | ||
| 273 | private Map<String, String> viewRecordInfo; | ||
| 274 | |||
| 275 | public String getViewRecordQueue(){ | ||
| 276 | if (Objects.nonNull(viewRecordInfo)) { | ||
| 277 | if (MapUtils.isNotEmpty(viewRecordInfo)) { | ||
| 278 | String queue = viewRecordInfo.get("queue"); | ||
| 279 | return queue; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | return VIEW_RECORD_QUEUE; | ||
| 284 | } | ||
| 285 | |||
| 286 | public String getViewRecordSource(){ | ||
| 287 | if (Objects.nonNull(viewRecordInfo)) { | ||
| 288 | if (MapUtils.isNotEmpty(viewRecordInfo)) { | ||
| 289 | String source = viewRecordInfo.get("active"); | ||
| 290 | if (StringUtils.isNotBlank(source)) { | ||
| 291 | return this.chargeSource(source); | ||
| 292 | } else { | ||
| 293 | return SERVICE_; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | return SERVICE_; | ||
| 299 | } | ||
| 300 | |||
| 301 | public String getViewRecordStartUp(){ | ||
| 302 | if (Objects.nonNull(viewRecordInfo)) { | ||
| 303 | if (MapUtils.isNotEmpty(viewRecordInfo)) { | ||
| 304 | String source = viewRecordInfo.get("active"); | ||
| 305 | if (StringUtils.isNotBlank(source)) { | ||
| 306 | return "true"; | ||
| 307 | } | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | return "false"; | ||
| 312 | } | ||
| 313 | |||
| 314 | /**************************************************uc-engine 2 uc-consumer*************************************************************/ | ||
| 315 | |||
| 316 | public static final String UCE_EXCHANGE = "uce.exchange"; | ||
| 317 | public static final String UCE_QUEUE = "uce.queue"; | ||
| 318 | |||
| 319 | @Value("#{rabbitMqCustomConfig.getUceInfo()}") | ||
| 320 | private Map<String, String> uceInfo; | ||
| 321 | |||
| 322 | public String getUceQueue(){ | ||
| 323 | if (Objects.nonNull(uceInfo)) { | ||
| 324 | if (MapUtils.isNotEmpty(uceInfo)) { | ||
| 325 | String queue = uceInfo.get("queue"); | ||
| 326 | return queue; | ||
| 327 | } | ||
| 328 | } | ||
| 329 | |||
| 330 | return UCE_QUEUE; | ||
| 331 | } | ||
| 332 | |||
| 333 | public String getUceSource(){ | ||
| 334 | if (Objects.nonNull(uceInfo)) { | ||
| 335 | if (MapUtils.isNotEmpty(uceInfo)) { | ||
| 336 | String source = uceInfo.get("active"); | ||
| 337 | if (StringUtils.isNotBlank(source)) { | ||
| 338 | return this.chargeSource(source); | ||
| 339 | } else { | ||
| 340 | return MANAGEMENT_; | ||
| 341 | } | ||
| 342 | } | ||
| 343 | } | ||
| 344 | |||
| 345 | return MANAGEMENT_; | ||
| 346 | } | ||
| 347 | |||
| 348 | public String getUceStartUp(){ | ||
| 349 | if (Objects.nonNull(uceInfo)) { | ||
| 350 | if (MapUtils.isNotEmpty(uceInfo)) { | ||
| 351 | String source = uceInfo.get("active"); | ||
| 352 | if (StringUtils.isNotBlank(source)) { | ||
| 353 | return "true"; | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | return "false"; | ||
| 359 | } | ||
| 360 | |||
| 361 | |||
| 362 | |||
| 363 | public String getMemberInfoAsyncQueue(){ | ||
| 364 | return "queue.MemberInfoSync"; | ||
| 365 | } | ||
| 366 | |||
| 367 | /**************************************************eventBus*************************************************************/ | ||
| 368 | public static final String UC_EVENTBUS_EXCHANGE = "uc.eventbus"; | ||
| 369 | public static final String UC_EVENTBUS_KEY = "uc.eventbus.*.topic"; | ||
| 370 | public static final String UC_EVENTBUS_QUEUE = "uc.eventbus"; | ||
| 371 | |||
| 372 | @Value("#{rabbitMqCustomConfig.getEventBusInfo()}") | ||
| 373 | private Map<String, String> eventBusInfo; | ||
| 374 | |||
| 375 | public String getEventBusQueue(){ | ||
| 376 | if (Objects.nonNull(eventBusInfo)) { | ||
| 377 | if (MapUtils.isNotEmpty(eventBusInfo)) { | ||
| 378 | String queue = eventBusInfo.get("queue"); | ||
| 379 | return queue; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | return UC_EVENTBUS_QUEUE; | ||
| 383 | } | ||
| 384 | |||
| 385 | public String getEventBusSource(){ | ||
| 386 | if (Objects.nonNull(eventBusInfo)) { | ||
| 387 | if (MapUtils.isNotEmpty(eventBusInfo)) { | ||
| 388 | String source = eventBusInfo.get("active"); | ||
| 389 | if (StringUtils.isNotBlank(source)) { | ||
| 390 | return this.chargeSource(source); | ||
| 391 | } else { | ||
| 392 | return SERVICE_; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | } | ||
| 396 | |||
| 397 | return SERVICE_; | ||
| 398 | } | ||
| 399 | |||
| 400 | public String getEventBusStartUp(){ | ||
| 401 | if (Objects.nonNull(eventBusInfo)) { | ||
| 402 | if (MapUtils.isNotEmpty(eventBusInfo)) { | ||
| 403 | String source = eventBusInfo.get("active"); | ||
| 404 | if (StringUtils.isNotBlank(source)) { | ||
| 405 | return "true"; | ||
| 406 | } | ||
| 407 | } | ||
| 408 | } | ||
| 409 | return "false"; | ||
| 410 | } | ||
| 411 | |||
| 412 | /**************************************************wechat*************************************************************/ | ||
| 413 | |||
| 414 | public static final String WEIXIN_EXCHANGE = "weixin.subOrUnSub.direct"; | ||
| 415 | public static final String WEIXIN_SUBORUNSUB_QUEUE = "weixin.subOrUnSub.queue"; | ||
| 416 | |||
| 417 | @Value("#{rabbitMqCustomConfig.getWechatInfo()}") | ||
| 418 | private Map<String, String> wechatInfo; | ||
| 419 | |||
| 420 | public String getWechatQueue(){ | ||
| 421 | if (Objects.nonNull(wechatInfo)) { | ||
| 422 | if (MapUtils.isNotEmpty(wechatInfo)) { | ||
| 423 | String queue = wechatInfo.get("queue"); | ||
| 424 | return queue; | ||
| 425 | } | ||
| 426 | } | ||
| 427 | return WEIXIN_SUBORUNSUB_QUEUE; | ||
| 428 | } | ||
| 429 | |||
| 430 | public String getWechatSource(){ | ||
| 431 | if (Objects.nonNull(wechatInfo)) { | ||
| 432 | if (MapUtils.isNotEmpty(wechatInfo)) { | ||
| 433 | String source = wechatInfo.get("active"); | ||
| 434 | if (StringUtils.isNotBlank(source)) { | ||
| 435 | return this.chargeSource(source); | ||
| 436 | } else { | ||
| 437 | return SERVICE_; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | return SERVICE_; | ||
| 443 | } | ||
| 444 | |||
| 445 | public String getWechatStartUp(){ | ||
| 446 | if (Objects.nonNull(wechatInfo)) { | ||
| 447 | if (MapUtils.isNotEmpty(wechatInfo)) { | ||
| 448 | String source = wechatInfo.get("active"); | ||
| 449 | if (StringUtils.isNotBlank(source)) { | ||
| 450 | return "true"; | ||
| 451 | } | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | return "false"; | ||
| 456 | } | ||
| 457 | } |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import org.springframework.beans.factory.annotation.Value; | ||
| 5 | import org.springframework.stereotype.Component; | ||
| 6 | |||
| 7 | @Component | ||
| 8 | public class ServiceEnvConfig { | ||
| 9 | |||
| 10 | // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | ||
| 11 | public static String UC_SERVICE_TYPE; | ||
| 12 | |||
| 13 | @Value("${service.area:mobile}") | ||
| 14 | public void setUcServiceType(String ucServiceType) { | ||
| 15 | UC_SERVICE_TYPE = ucServiceType; | ||
| 16 | } | ||
| 17 | |||
| 18 | public static boolean isMobile() { | ||
| 19 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_MOBILE); | ||
| 20 | } | ||
| 21 | |||
| 22 | public static boolean isVis() { | ||
| 23 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS); | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 | // service: 服务侧 management: 管理侧 | ||
| 28 | public static String UC_SERVICE_PLATFORM; | ||
| 29 | |||
| 30 | @Value("${service.platform:management}") | ||
| 31 | public void setUcServicePlatform(String ucServicePlatform) { | ||
| 32 | UC_SERVICE_PLATFORM = ucServicePlatform; | ||
| 33 | } | ||
| 34 | |||
| 35 | public static boolean isService() { | ||
| 36 | return ObjectUtil.equals(UC_SERVICE_PLATFORM, LocalConstants.ENV_SERVICE); | ||
| 37 | } | ||
| 38 | |||
| 39 | public static boolean isManagement() { | ||
| 40 | return ObjectUtil.equals(UC_SERVICE_PLATFORM, LocalConstants.ENV_MANAGEMENT); | ||
| 41 | } | ||
| 42 | |||
| 43 | } |
| 1 | package com.topdraw.exception; | ||
| 2 | |||
| 3 | /** | ||
| 4 | * @author : | ||
| 5 | * @description: | ||
| 6 | * @function : | ||
| 7 | * @date :Created in 2022/3/10 17:16 | ||
| 8 | * @version: : | ||
| 9 | * @modified By: | ||
| 10 | * @since : modified in 2022/3/10 17:16 | ||
| 11 | */ | ||
| 12 | public interface GlobeExceptionCode { | ||
| 13 | |||
| 14 | // 会员信息 | ||
| 15 | Integer MEMBER_CODE_IS_NULL = 000100001; | ||
| 16 | |||
| 17 | } |
| 1 | package com.topdraw.exception; | ||
| 2 | |||
| 3 | /** | ||
| 4 | * @author : | ||
| 5 | * @description: | ||
| 6 | * @function : | ||
| 7 | * @date :Created in 2022/3/10 17:16 | ||
| 8 | * @version: : | ||
| 9 | * @modified By: | ||
| 10 | * @since : modified in 2022/3/10 17:16 | ||
| 11 | */ | ||
| 12 | public interface GlobeExceptionMsg { | ||
| 13 | |||
| 14 | /**************************************************************/ | ||
| 15 | /** 系统 */ | ||
| 16 | String OPERATION_FORBID = "operation forbid"; | ||
| 17 | String ENTITY_ALREADY_EXISTS = "entity already exists"; | ||
| 18 | |||
| 19 | |||
| 20 | /**************************************************************/ | ||
| 21 | /** 优惠券 */ | ||
| 22 | String COUPON_ID_IS_NULL = "coupon id is null"; | ||
| 23 | String COUPON_CODE_IS_NULL = "coupon code is null"; | ||
| 24 | |||
| 25 | |||
| 26 | /**************************************************************/ | ||
| 27 | |||
| 28 | /** 会员管理 */ | ||
| 29 | String MEMBER_CODE_IS_NULL = "memberCode is null"; | ||
| 30 | String MEMBER_ID_IS_NULL = "memberId is null"; | ||
| 31 | String MEMBER_ID_AND_CODE_ARE_NULL = "memberId and memberCode both null"; | ||
| 32 | String MEMBER_INFO_ERROR = "member info is error"; | ||
| 33 | String MEMBER_BLOCK_STATUS = "member status is block"; | ||
| 34 | |||
| 35 | /**************************************************************/ | ||
| 36 | |||
| 37 | /** 账户管理 **/ | ||
| 38 | |||
| 39 | /** iptv */ | ||
| 40 | String IPTV_ID_IS_NULL = "iptvId is null"; | ||
| 41 | String IPTV_PLATFORM_ACCOUNT_IS_NULL = "platformAccount is null"; | ||
| 42 | String IPTV_IS_NULL = "iptv is null"; | ||
| 43 | String VIS_USER_ID_IS_NULL = "visUserId is null"; | ||
| 44 | |||
| 45 | /** 微信 */ | ||
| 46 | String APP_ID_IS_NULL = "appId is null"; | ||
| 47 | String OPEN_ID_IS_NULL = "openId is null"; | ||
| 48 | String UNION_ID_IS_NULL = "unionId is null"; | ||
| 49 | String ALREADY_BIND = "already bind"; | ||
| 50 | String WEIXIN_IS_NULL = "weixin is null"; | ||
| 51 | } |
| 1 | package com.topdraw.mq.consumer; | 1 | package com.topdraw.mq.consumer; |
| 2 | 2 | ||
| 3 | import com.topdraw.config.RabbitMqConfig; | 3 | import com.rabbitmq.client.Channel; |
| 4 | import com.topdraw.mq.domain.DataSyncMsg; | ||
| 5 | import com.topdraw.mq.domain.TableOperationMsg; | 4 | import com.topdraw.mq.domain.TableOperationMsg; |
| 6 | import com.topdraw.resttemplate.RestTemplateClient; | 5 | import com.topdraw.resttemplate.RestTemplateClient; |
| 6 | import com.topdraw.util.FileUtil; | ||
| 7 | import com.topdraw.util.JSONUtil; | 7 | import com.topdraw.util.JSONUtil; |
| 8 | import lombok.extern.slf4j.Slf4j; | 8 | import lombok.extern.slf4j.Slf4j; |
| 9 | import org.slf4j.Logger; | 9 | import org.apache.commons.collections4.MapUtils; |
| 10 | import org.slf4j.LoggerFactory; | 10 | import org.springframework.amqp.core.Message; |
| 11 | import org.springframework.amqp.core.ExchangeTypes; | ||
| 12 | import org.springframework.amqp.rabbit.annotation.*; | 11 | import org.springframework.amqp.rabbit.annotation.*; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.beans.factory.annotation.Value; | ||
| 14 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
| 15 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 16 | 16 | ||
| 17 | import java.io.IOException; | ||
| 18 | import java.time.LocalDate; | ||
| 19 | import java.util.Map; | ||
| 20 | |||
| 17 | @Component | 21 | @Component |
| 18 | @Slf4j | 22 | @Slf4j |
| 19 | public class UcEngineEventConsumer { | 23 | public class UcEngineManagement2IptvConsumer { |
| 20 | |||
| 21 | private static final Logger LOG = LoggerFactory.getLogger(UcEngineEventConsumer.class); | ||
| 22 | 24 | ||
| 23 | @Autowired | 25 | @Autowired |
| 24 | AutoRoute autoUser; | 26 | AutoRoute autoUser; |
| ... | @@ -26,6 +28,46 @@ public class UcEngineEventConsumer { | ... | @@ -26,6 +28,46 @@ public class UcEngineEventConsumer { |
| 26 | @Autowired | 28 | @Autowired |
| 27 | RestTemplateClient restTemplateClient; | 29 | RestTemplateClient restTemplateClient; |
| 28 | 30 | ||
| 31 | @Value("#{rabbitMqErrorLogConfig.getUceError()}") | ||
| 32 | private Map<String, String> error; | ||
| 33 | |||
| 34 | @RabbitHandler | ||
| 35 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getMemberInfoAsyncQueue()}", | ||
| 36 | containerFactory = "#{rabbitMqSourceConfig.getUceSource()}", | ||
| 37 | autoStartup = "#{rabbitMqSourceConfig.getUceStartUp()}", | ||
| 38 | ackMode = "AUTO") | ||
| 39 | public void ucEventConsumer2(Channel channel, Message message, String content) throws IOException { | ||
| 40 | log.info(" receive MemberInfoAsync msg , content is : {} ", content); | ||
| 41 | |||
| 42 | try { | ||
| 43 | TableOperationMsg tableOperationMsg = this.parseContent(content); | ||
| 44 | |||
| 45 | autoUser.route(tableOperationMsg); | ||
| 46 | |||
| 47 | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 48 | |||
| 49 | } catch (Exception e) { | ||
| 50 | |||
| 51 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 52 | |||
| 53 | if (MapUtils.isNotEmpty(error)) { | ||
| 54 | String errorStart = this.error.get("start"); | ||
| 55 | |||
| 56 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 57 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 58 | String filePath = this.error.get("filePath"); | ||
| 59 | String filePath1 = filePath+fileName; | ||
| 60 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 61 | } | ||
| 62 | |||
| 63 | } | ||
| 64 | |||
| 65 | e.printStackTrace(); | ||
| 66 | } | ||
| 67 | |||
| 68 | log.info("ucEventConsumer ====>>>> end"); | ||
| 69 | } | ||
| 70 | |||
| 29 | /** | 71 | /** |
| 30 | * 事件 | 72 | * 事件 |
| 31 | * @param content | 73 | * @param content |
| ... | @@ -34,14 +76,39 @@ public class UcEngineEventConsumer { | ... | @@ -34,14 +76,39 @@ public class UcEngineEventConsumer { |
| 34 | * @date 2021/9/7 11:26 上午 | 76 | * @date 2021/9/7 11:26 上午 |
| 35 | */ | 77 | */ |
| 36 | @RabbitHandler | 78 | @RabbitHandler |
| 37 | @RabbitListener(bindings = { | 79 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUceQueue()}", |
| 38 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_BBB), | 80 | containerFactory = "#{rabbitMqSourceConfig.getUceSource()}", |
| 39 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | 81 | autoStartup = "#{rabbitMqSourceConfig.getUceStartUp()}", |
| 40 | }, containerFactory = "serviceRabbitListenerContainerFactory") | 82 | ackMode = "MANUAL") |
| 41 | public void ucEventConsumer(String content) { | 83 | public void ucEventConsumer(Channel channel, Message message, String content) throws IOException { |
| 42 | log.info(" receive dataSync msg , content is : {} ", content); | 84 | log.info(" receive ucEventConsumer msg , content is : {} ", content); |
| 43 | TableOperationMsg tableOperationMsg = this.parseContent(content); | 85 | |
| 44 | autoUser.route(tableOperationMsg); | 86 | try { |
| 87 | TableOperationMsg tableOperationMsg = this.parseContent(content); | ||
| 88 | |||
| 89 | autoUser.route(tableOperationMsg); | ||
| 90 | |||
| 91 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 92 | |||
| 93 | } catch (Exception e) { | ||
| 94 | |||
| 95 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 96 | |||
| 97 | if (MapUtils.isNotEmpty(error)) { | ||
| 98 | String errorStart = this.error.get("start"); | ||
| 99 | |||
| 100 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 101 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 102 | String filePath = this.error.get("filePath"); | ||
| 103 | String filePath1 = filePath+fileName; | ||
| 104 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 105 | } | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | e.printStackTrace(); | ||
| 110 | } | ||
| 111 | |||
| 45 | log.info("ucEventConsumer ====>>>> end"); | 112 | log.info("ucEventConsumer ====>>>> end"); |
| 46 | } | 113 | } |
| 47 | 114 | ... | ... |
| 1 | package com.topdraw.mq.consumer; | ||
| 2 | |||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | ||
| 5 | import com.rabbitmq.client.Channel; | ||
| 6 | import com.topdraw.business.module.member.service.MemberService; | ||
| 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 8 | import com.topdraw.business.module.task.attribute.service.TaskAttrService; | ||
| 9 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ||
| 10 | import com.topdraw.business.module.task.domain.Task; | ||
| 11 | import com.topdraw.business.module.task.service.TaskService; | ||
| 12 | import com.topdraw.business.module.task.template.service.TaskTemplateService; | ||
| 13 | import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; | ||
| 14 | import com.topdraw.business.module.user.iptv.service.UserTvService; | ||
| 15 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | ||
| 16 | import com.topdraw.exception.EntityNotFoundException; | ||
| 17 | import com.topdraw.mq.domain.DataSyncMsg; | ||
| 18 | import com.topdraw.resttemplate.RestTemplateClient; | ||
| 19 | import com.topdraw.util.DateUtil; | ||
| 20 | import com.topdraw.util.FileUtil; | ||
| 21 | import com.topdraw.util.JSONUtil; | ||
| 22 | import com.topdraw.util.TimestampUtil; | ||
| 23 | import com.topdraw.utils.RedisUtils; | ||
| 24 | import lombok.Data; | ||
| 25 | import lombok.extern.slf4j.Slf4j; | ||
| 26 | import org.apache.commons.collections4.CollectionUtils; | ||
| 27 | import org.apache.commons.collections4.MapUtils; | ||
| 28 | import org.apache.commons.lang3.StringUtils; | ||
| 29 | import org.springframework.amqp.core.Message; | ||
| 30 | import org.springframework.amqp.rabbit.annotation.*; | ||
| 31 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 32 | import org.springframework.beans.factory.annotation.Value; | ||
| 33 | import org.springframework.stereotype.Component; | ||
| 34 | |||
| 35 | import java.io.IOException; | ||
| 36 | import java.text.ParseException; | ||
| 37 | import java.time.LocalDate; | ||
| 38 | import java.time.LocalDateTime; | ||
| 39 | import java.util.*; | ||
| 40 | |||
| 41 | @Component | ||
| 42 | @Slf4j | ||
| 43 | public class UcEventBusIptv2ManagementUcEngine { | ||
| 44 | |||
| 45 | @Autowired | ||
| 46 | private TaskService taskService; | ||
| 47 | @Autowired | ||
| 48 | private UserTvService userTvService; | ||
| 49 | @Autowired | ||
| 50 | private MemberService memberService; | ||
| 51 | @Autowired | ||
| 52 | private TaskAttrService taskAttrService; | ||
| 53 | @Autowired | ||
| 54 | private TaskTemplateService taskTemplateService; | ||
| 55 | @Autowired | ||
| 56 | private RestTemplateClient restTemplateClient; | ||
| 57 | @Autowired | ||
| 58 | private RedisUtils redisUtils; | ||
| 59 | |||
| 60 | |||
| 61 | @Value("#{rabbitMqErrorLogConfig.getEventBusError()}") | ||
| 62 | private Map<String, String> error; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * 事件 | ||
| 66 | * @param content | ||
| 67 | * @description 基础数据同步 | ||
| 68 | * @author Hongyan Wang | ||
| 69 | * @date 2021/9/7 11:26 上午 | ||
| 70 | */ | ||
| 71 | @RabbitHandler | ||
| 72 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getEventBusQueue()}", | ||
| 73 | containerFactory = "#{rabbitMqSourceConfig.getEventBusSource()}", | ||
| 74 | autoStartup = "#{rabbitMqSourceConfig.getEventBusStartUp()}", | ||
| 75 | ackMode = "MANUAL") | ||
| 76 | public void eventBusConsumer(Channel channel, Message message, String content) throws ParseException, IOException { | ||
| 77 | log.info(" receive dataSync msg , content is : {} ", content); | ||
| 78 | try { | ||
| 79 | |||
| 80 | this.parseContent(content); | ||
| 81 | |||
| 82 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 83 | |||
| 84 | } catch (Exception e) { | ||
| 85 | |||
| 86 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 87 | |||
| 88 | if (MapUtils.isNotEmpty(error)) { | ||
| 89 | String errorStart = this.error.get("start"); | ||
| 90 | |||
| 91 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 92 | String fileName = this.error.get("fileName")+"_"+LocalDate.now() +".log"; | ||
| 93 | String filePath = this.error.get("filePath"); | ||
| 94 | String filePath1 = filePath+fileName; | ||
| 95 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 96 | } | ||
| 97 | |||
| 98 | } | ||
| 99 | |||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | log.info("ucEventConsumer ====>>>> end"); | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | /** | ||
| 107 | * 数据解析 | ||
| 108 | * @param content | ||
| 109 | * @return | ||
| 110 | */ | ||
| 111 | private void parseContent(String content) throws ParseException { | ||
| 112 | |||
| 113 | PlayContent commonMsg = JSONUtil.parseMsg2Object(content, PlayContent.class); | ||
| 114 | |||
| 115 | String evt = commonMsg.getEvt(); | ||
| 116 | switch (evt.toUpperCase()) { | ||
| 117 | |||
| 118 | case "PLAY": | ||
| 119 | PlayContent playContent = JSONUtil.parseMsg2Object(content, PlayContent.class); | ||
| 120 | |||
| 121 | PlayContent.MsgData msgData = playContent.getMsgData(); | ||
| 122 | if (Objects.nonNull(msgData)) { | ||
| 123 | String time = playContent.getTime(); | ||
| 124 | String formatDate = DateUtil.formatDate(time); | ||
| 125 | Integer deviceType = playContent.getDeviceType(); | ||
| 126 | String platformAccount = msgData.getPlatformAccount(); | ||
| 127 | |||
| 128 | String mediaCode = msgData.getMediaCode(); | ||
| 129 | Long mediaId = msgData.getMediaId(); | ||
| 130 | String mediaName = msgData.getMediaName(); | ||
| 131 | Integer playDuration = msgData.getPlayDuration(); | ||
| 132 | if (Objects.isNull(playDuration) || playDuration == 0) { | ||
| 133 | return; | ||
| 134 | } | ||
| 135 | log.info("playDuration ==>> {}", playDuration); | ||
| 136 | |||
| 137 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | ||
| 138 | dataSyncMsg.setEvt(evt); | ||
| 139 | DataSyncMsg.MsgData msg = new DataSyncMsg.MsgData(); | ||
| 140 | |||
| 141 | Integer playDurationValueTotal = 0; | ||
| 142 | if (StringUtils.isNotBlank(platformAccount)) { | ||
| 143 | |||
| 144 | UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); | ||
| 145 | |||
| 146 | if(Objects.nonNull(userTvDTO)) { | ||
| 147 | // 用大屏账号+日期做为key,并判断这个key是否存在 ,数据类型为hash eg:<total,1>,<1,playDuration>,<2,playDuration> | ||
| 148 | String key = platformAccount+"|"+formatDate; | ||
| 149 | Map<Object, Object> hmget = | ||
| 150 | this.redisUtils.hmget(key); | ||
| 151 | |||
| 152 | if (MapUtils.isEmpty(hmget)) { | ||
| 153 | |||
| 154 | // 初始化播放总时长<total>和第一个播放时间 | ||
| 155 | playDurationValueTotal = playDuration; | ||
| 156 | Map<String, Object> map = new HashMap<>(); | ||
| 157 | map.put("total", playDurationValueTotal); | ||
| 158 | map.put("1", playDuration); | ||
| 159 | this.redisUtils.hmset(key, map, 129600); | ||
| 160 | |||
| 161 | } else { | ||
| 162 | |||
| 163 | // 计算播放总时长 total = 播放总时长+当前播放时长 | ||
| 164 | Integer total = this.getRedisTotal(hmget); | ||
| 165 | playDurationValueTotal = total + playDuration; | ||
| 166 | |||
| 167 | } | ||
| 168 | |||
| 169 | Integer totalKey = this.getRedisTotalKey(hmget); | ||
| 170 | Integer maxSize = totalKey + 1; | ||
| 171 | |||
| 172 | Map<String, Object> map = new HashMap<>(); | ||
| 173 | map.put(String.valueOf(maxSize), playDuration); | ||
| 174 | map.put("total", playDurationValueTotal); | ||
| 175 | this.redisUtils.hmset(key, map); | ||
| 176 | |||
| 177 | this.checkTask(playDurationValueTotal, time, deviceType, | ||
| 178 | mediaCode, mediaId, mediaName, dataSyncMsg, msg, userTvDTO); | ||
| 179 | |||
| 180 | } | ||
| 181 | |||
| 182 | } | ||
| 183 | |||
| 184 | } | ||
| 185 | |||
| 186 | break; | ||
| 187 | |||
| 188 | } | ||
| 189 | |||
| 190 | //return null; | ||
| 191 | } | ||
| 192 | |||
| 193 | private DataSyncMsg checkTask(Integer playDurationValueTotal, String time, Integer deviceType, String mediaCode, | ||
| 194 | Long mediaId, String mediaName, DataSyncMsg dataSyncMsg, | ||
| 195 | DataSyncMsg.MsgData msgData, UserTvDTO userTvDTO) { | ||
| 196 | |||
| 197 | // 检查播放记录任务 | ||
| 198 | List<TaskAttrDTO> taskAttrDTOList = new ArrayList<>(); | ||
| 199 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(8); | ||
| 200 | if (Objects.nonNull(taskTemplateDTO.getId())) { | ||
| 201 | List<Task> taskList = this.taskService.findByTemplateId(taskTemplateDTO.getId()); | ||
| 202 | if (CollectionUtils.isNotEmpty(taskList)) { | ||
| 203 | |||
| 204 | for (Task task : taskList) { | ||
| 205 | TaskAttrDTO taskAttrDTO = this.taskAttrService.findByTaskId(task.getId()); | ||
| 206 | taskAttrDTOList.add(taskAttrDTO); | ||
| 207 | } | ||
| 208 | |||
| 209 | } else { | ||
| 210 | |||
| 211 | return null; | ||
| 212 | |||
| 213 | } | ||
| 214 | |||
| 215 | } else { | ||
| 216 | |||
| 217 | return null; | ||
| 218 | |||
| 219 | } | ||
| 220 | |||
| 221 | List<List<Integer>> attrList = new ArrayList<>(); | ||
| 222 | if (CollectionUtils.isNotEmpty(taskAttrDTOList)) { | ||
| 223 | |||
| 224 | for (TaskAttrDTO taskAttrDTO : taskAttrDTOList) { | ||
| 225 | |||
| 226 | String attrStr = taskAttrDTO.getAttrStr(); | ||
| 227 | if (StringUtils.isNotBlank(attrStr)) { | ||
| 228 | |||
| 229 | JSONObject parse = JSONObject.parseObject(attrStr, JSONObject.class); | ||
| 230 | List<Integer> value = (List<Integer>) parse.get("value"); | ||
| 231 | attrList.add(value); | ||
| 232 | } | ||
| 233 | |||
| 234 | } | ||
| 235 | |||
| 236 | } else { | ||
| 237 | |||
| 238 | return null; | ||
| 239 | |||
| 240 | } | ||
| 241 | |||
| 242 | int size = attrList.size(); | ||
| 243 | |||
| 244 | DataSyncMsg dataSyncMsg1 = null; | ||
| 245 | |||
| 246 | if (size > 0) { | ||
| 247 | |||
| 248 | for (int i = size-1; i >= 0; i--) { | ||
| 249 | |||
| 250 | Integer integer = attrList.get(i).get(0); | ||
| 251 | |||
| 252 | if (playDurationValueTotal >= integer) { | ||
| 253 | dataSyncMsg1 = getDataSyncMsg(time, mediaCode, mediaId, mediaName, integer, dataSyncMsg, | ||
| 254 | msgData, userTvDTO); | ||
| 255 | dataSyncMsg1.setEvt("PLAY"); | ||
| 256 | dataSyncMsg1.setEvent(8); | ||
| 257 | dataSyncMsg1.setTime(LocalDateTime.now()); | ||
| 258 | dataSyncMsg1.setDeviceType(deviceType); | ||
| 259 | this.taskDeal(dataSyncMsg1); | ||
| 260 | } | ||
| 261 | |||
| 262 | } | ||
| 263 | |||
| 264 | } | ||
| 265 | |||
| 266 | return dataSyncMsg1; | ||
| 267 | } | ||
| 268 | |||
| 269 | private Integer getRedisTotalKey(Map<Object, Object> hmget) { | ||
| 270 | Set<Object> objects = hmget.keySet(); | ||
| 271 | return objects.size(); | ||
| 272 | } | ||
| 273 | |||
| 274 | private Integer getRedisTotal(Map<Object, Object> hmget) { | ||
| 275 | Set<Object> objects = hmget.keySet(); | ||
| 276 | |||
| 277 | Integer playDurationValueTotal_ = 0; | ||
| 278 | |||
| 279 | for (Object key_ : objects) { | ||
| 280 | |||
| 281 | if (key_.toString().equalsIgnoreCase("total")) { | ||
| 282 | playDurationValueTotal_ = Integer.valueOf(hmget.get(key_).toString()); | ||
| 283 | return playDurationValueTotal_; | ||
| 284 | |||
| 285 | } else { | ||
| 286 | |||
| 287 | continue; | ||
| 288 | |||
| 289 | } | ||
| 290 | |||
| 291 | } | ||
| 292 | |||
| 293 | return playDurationValueTotal_; | ||
| 294 | |||
| 295 | } | ||
| 296 | |||
| 297 | private DataSyncMsg getDataSyncMsg(String time, String mediaCode, Long mediaId, String mediaName, | ||
| 298 | Integer playDuration, DataSyncMsg dataSyncMsg, DataSyncMsg.MsgData msgData1, UserTvDTO userTvDTO) { | ||
| 299 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
| 300 | String memberCode = ""; | ||
| 301 | if (StringUtils.isNotBlank(priorityMemberCode)) { | ||
| 302 | memberCode = priorityMemberCode; | ||
| 303 | } else { | ||
| 304 | memberCode = this.memberService.findById(userTvDTO.getMemberId()).getCode(); | ||
| 305 | } | ||
| 306 | |||
| 307 | if (StringUtils.isBlank(memberCode)) | ||
| 308 | throw new EntityNotFoundException(MemberDTO.class, "memberCode", "memberCode is null"); | ||
| 309 | |||
| 310 | msgData1.setMemberCode(memberCode); | ||
| 311 | |||
| 312 | msgData1.setMediaId(mediaId); | ||
| 313 | |||
| 314 | JSONObject param = new JSONObject(); | ||
| 315 | // 增量 | ||
| 316 | param.put("playDuration", playDuration); | ||
| 317 | msgData1.setParam(JSON.toJSONString(param)); | ||
| 318 | JSONObject description = new JSONObject(); | ||
| 319 | description.put("mediaId", mediaId); | ||
| 320 | description.put("mediaName", mediaName); | ||
| 321 | description.put("playDuration", playDuration); | ||
| 322 | description.put("mediaCode", mediaCode); | ||
| 323 | description.put("time", time); | ||
| 324 | msgData1.setDescription(JSON.toJSONString(description)); | ||
| 325 | dataSyncMsg.setMsg(msgData1); | ||
| 326 | return dataSyncMsg; | ||
| 327 | } | ||
| 328 | |||
| 329 | /** | ||
| 330 | * 任务处理 | ||
| 331 | * @param dataSyncMsg | ||
| 332 | */ | ||
| 333 | private void taskDeal(DataSyncMsg dataSyncMsg) { | ||
| 334 | this.restTemplateClient.dealTask(dataSyncMsg); | ||
| 335 | } | ||
| 336 | |||
| 337 | @Data | ||
| 338 | static class PlayContent { | ||
| 339 | private String evt; | ||
| 340 | private Integer event; | ||
| 341 | private Integer deviceType; | ||
| 342 | private String time; | ||
| 343 | private MsgData msgData; | ||
| 344 | |||
| 345 | @Data | ||
| 346 | static class MsgData { | ||
| 347 | private String platformAccount; | ||
| 348 | private Integer playDuration; | ||
| 349 | private Long mediaId; | ||
| 350 | private String mediaCode; | ||
| 351 | private String mediaName; | ||
| 352 | } | ||
| 353 | } | ||
| 354 | } |
| 1 | package com.topdraw.mq.consumer; | ||
| 2 | |||
| 3 | import com.topdraw.config.RabbitMqConfig; | ||
| 4 | import com.topdraw.mq.domain.DataSyncMsg; | ||
| 5 | import com.topdraw.resttemplate.RestTemplateClient; | ||
| 6 | import com.topdraw.util.JSONUtil; | ||
| 7 | import lombok.extern.slf4j.Slf4j; | ||
| 8 | import org.springframework.amqp.core.ExchangeTypes; | ||
| 9 | import org.springframework.amqp.rabbit.annotation.*; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | import org.springframework.stereotype.Component; | ||
| 12 | import org.springframework.util.Assert; | ||
| 13 | |||
| 14 | @Component | ||
| 15 | @Slf4j | ||
| 16 | public class UcGatewayEventConsumer { | ||
| 17 | |||
| 18 | @Autowired | ||
| 19 | RestTemplateClient restTemplateClient; | ||
| 20 | |||
| 21 | @Autowired | ||
| 22 | AutoRoute autoUser; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 事件 | ||
| 26 | * @param content | ||
| 27 | * @description 基础数据同步 | ||
| 28 | * @author Hongyan Wang | ||
| 29 | * @date 2021/9/7 11:26 上午 | ||
| 30 | */ | ||
| 31 | @RabbitHandler | ||
| 32 | @RabbitListener(bindings = { | ||
| 33 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA), | ||
| 34 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | ||
| 35 | }, containerFactory = "managementRabbitListenerContainerFactory") | ||
| 36 | public void ucEventConsumer(String content) { | ||
| 37 | log.info(" receive dataSync msg , content is : {} ", content); | ||
| 38 | DataSyncMsg dataSyncMsg = this.parseContent(content); | ||
| 39 | this.taskDeal(dataSyncMsg); | ||
| 40 | log.info("ucEventConsumer ====>>>> end"); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * 数据解析 | ||
| 45 | * @param content | ||
| 46 | * @return | ||
| 47 | */ | ||
| 48 | private DataSyncMsg parseContent(String content) { | ||
| 49 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content,DataSyncMsg.class); | ||
| 50 | Assert.notNull(dataSyncMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!"); | ||
| 51 | DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); | ||
| 52 | Assert.notNull(msgData,"ERROR -->> operationConsumer -->> parseContent -->> 【msgData】 not be null !!"); | ||
| 53 | return dataSyncMsg; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * 任务处理 | ||
| 58 | * @param dataSyncMsg | ||
| 59 | */ | ||
| 60 | private void taskDeal(DataSyncMsg dataSyncMsg) { | ||
| 61 | this.restTemplateClient.dealTask(dataSyncMsg); | ||
| 62 | } | ||
| 63 | } |
| 1 | package com.topdraw.mq.consumer; | ||
| 2 | |||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | ||
| 5 | import com.rabbitmq.client.Channel; | ||
| 6 | import com.topdraw.business.module.member.service.MemberService; | ||
| 7 | import com.topdraw.business.module.member.service.dto.MemberDTO; | ||
| 8 | import com.topdraw.business.module.user.iptv.service.UserTvService; | ||
| 9 | import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; | ||
| 10 | import com.topdraw.mq.domain.DataSyncMsg; | ||
| 11 | import com.topdraw.resttemplate.RestTemplateClient; | ||
| 12 | import com.topdraw.util.FileUtil; | ||
| 13 | import com.topdraw.util.JSONUtil; | ||
| 14 | import lombok.extern.slf4j.Slf4j; | ||
| 15 | import org.apache.commons.collections4.MapUtils; | ||
| 16 | import org.apache.commons.lang3.StringUtils; | ||
| 17 | import org.springframework.amqp.core.Message; | ||
| 18 | import org.springframework.amqp.rabbit.annotation.*; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | import org.springframework.beans.factory.annotation.Value; | ||
| 21 | import org.springframework.stereotype.Component; | ||
| 22 | import org.springframework.util.Assert; | ||
| 23 | |||
| 24 | import javax.validation.constraints.NotNull; | ||
| 25 | import java.io.IOException; | ||
| 26 | import java.time.LocalDate; | ||
| 27 | import java.util.Map; | ||
| 28 | import java.util.Objects; | ||
| 29 | |||
| 30 | @Component | ||
| 31 | @Slf4j | ||
| 32 | public class UcGatewayIptv2IptvConsumer { | ||
| 33 | |||
| 34 | @Autowired | ||
| 35 | RestTemplateClient restTemplateClient; | ||
| 36 | |||
| 37 | @Autowired | ||
| 38 | AutoRoute autoUser; | ||
| 39 | |||
| 40 | @Autowired | ||
| 41 | private MemberService memberService; | ||
| 42 | @Autowired | ||
| 43 | private UserTvService userTvService; | ||
| 44 | |||
| 45 | @Value("#{rabbitMqErrorLogConfig.getUcgError()}") | ||
| 46 | private Map<String, String> error; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * 事件 | ||
| 50 | * @param content | ||
| 51 | * @description 基础数据同步 | ||
| 52 | * @author Hongyan Wang | ||
| 53 | * @date 2021/9/7 11:26 上午 | ||
| 54 | */ | ||
| 55 | @RabbitHandler | ||
| 56 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgEventQueue()}", | ||
| 57 | containerFactory = "#{rabbitMqSourceConfig.getUcgEventSource()}", | ||
| 58 | autoStartup = "#{rabbitMqSourceConfig.getUcgEventStartUp()}", | ||
| 59 | ackMode = "MANUAL") | ||
| 60 | public void eventConsumer(Channel channel, Message message, String content) throws IOException { | ||
| 61 | log.info(" receive dataSync msg , content is : {} ", content); | ||
| 62 | try { | ||
| 63 | DataSyncMsg dataSyncMsg = this.parseContent(content); | ||
| 64 | |||
| 65 | this.taskDeal(dataSyncMsg); | ||
| 66 | |||
| 67 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 68 | |||
| 69 | } catch (Exception e) { | ||
| 70 | |||
| 71 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 72 | |||
| 73 | if (MapUtils.isNotEmpty(error)) { | ||
| 74 | String errorStart = this.error.get("start"); | ||
| 75 | |||
| 76 | if (StringUtils.isEmpty(errorStart) || errorStart.equalsIgnoreCase("true")) { | ||
| 77 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 78 | String filePath = this.error.get("filePath"); | ||
| 79 | String filePath1 = filePath+fileName; | ||
| 80 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 81 | } | ||
| 82 | |||
| 83 | } | ||
| 84 | |||
| 85 | e.printStackTrace(); | ||
| 86 | } | ||
| 87 | log.info("ucEventConsumer ====>>>> end"); | ||
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * 数据解析 | ||
| 92 | * @param content | ||
| 93 | * @return | ||
| 94 | */ | ||
| 95 | private DataSyncMsg parseContent(String content) { | ||
| 96 | DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content,DataSyncMsg.class); | ||
| 97 | Assert.notNull(dataSyncMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!"); | ||
| 98 | DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); | ||
| 99 | Long memberId = msgData.getMemberId(); | ||
| 100 | String memberCode = msgData.getMemberCode(); | ||
| 101 | if (Objects.nonNull(memberId) && StringUtils.isBlank(memberCode)) { | ||
| 102 | MemberDTO memberDTO = this.memberService.findById(memberId); | ||
| 103 | String code = memberDTO.getCode(); | ||
| 104 | msgData.setMemberCode(code); | ||
| 105 | } | ||
| 106 | |||
| 107 | String platformAccount = msgData.getPlatformAccount(); | ||
| 108 | if (StringUtils.isNotBlank(platformAccount)) { | ||
| 109 | UserTvDTO userTvDTO = userTvService.findByPlatformAccount(platformAccount); | ||
| 110 | if (Objects.nonNull(userTvDTO)) { | ||
| 111 | String priorityMemberCode = userTvDTO.getPriorityMemberCode(); | ||
| 112 | if (StringUtils.isNotBlank(priorityMemberCode)) { | ||
| 113 | msgData.setMemberCode(priorityMemberCode); | ||
| 114 | } else { | ||
| 115 | MemberDTO memberDTO = this.memberService.findById(userTvDTO.getMemberId()); | ||
| 116 | msgData.setMemberCode(memberDTO.getCode()); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | Assert.notNull(msgData,"ERROR -->> operationConsumer -->> parseContent -->> 【msgData】 not be null !!"); | ||
| 121 | return dataSyncMsg; | ||
| 122 | } | ||
| 123 | |||
| 124 | /** | ||
| 125 | * 任务处理 | ||
| 126 | * @param dataSyncMsg | ||
| 127 | */ | ||
| 128 | private void taskDeal(DataSyncMsg dataSyncMsg) { | ||
| 129 | this.restTemplateClient.dealTask(dataSyncMsg); | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | /** | ||
| 134 | * @description 添加收藏记录 | ||
| 135 | * @param content 消息内容 | ||
| 136 | */ | ||
| 137 | @RabbitHandler | ||
| 138 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueue()}", | ||
| 139 | containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", | ||
| 140 | autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", | ||
| 141 | ackMode = "MANUAL") | ||
| 142 | public void collectionConsumer(Channel channel, Message message, String content) throws IOException { | ||
| 143 | log.info("receive UserCollection add message, content {}", content); | ||
| 144 | |||
| 145 | try { | ||
| 146 | |||
| 147 | JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); | ||
| 148 | if (Objects.nonNull(content)) { | ||
| 149 | String evt = jsonObject.get("evt").toString(); | ||
| 150 | String msgData = jsonObject.get("msgData").toString(); | ||
| 151 | switch (evt.toUpperCase()) { | ||
| 152 | // 添加收藏 | ||
| 153 | case "ADDCOLLECTION": | ||
| 154 | this.restTemplateClient.addCollection(msgData); | ||
| 155 | break; | ||
| 156 | // 删除收藏 | ||
| 157 | case "DELETECOLLECTION": | ||
| 158 | this.restTemplateClient.deleteCollection(msgData); | ||
| 159 | break; | ||
| 160 | // 删除全部收藏 | ||
| 161 | case "DELETEALLCOLLECTION": | ||
| 162 | this.restTemplateClient.deleteAllCollection(msgData); | ||
| 163 | break; | ||
| 164 | default: | ||
| 165 | break; | ||
| 166 | |||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 171 | |||
| 172 | } catch (Exception e) { | ||
| 173 | |||
| 174 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 175 | |||
| 176 | if (MapUtils.isNotEmpty(error)) { | ||
| 177 | String errorStart = this.error.get("start"); | ||
| 178 | |||
| 179 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 180 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 181 | String filePath = this.error.get("filePath"); | ||
| 182 | String filePath1 = filePath+fileName; | ||
| 183 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 184 | } | ||
| 185 | |||
| 186 | } | ||
| 187 | |||
| 188 | e.printStackTrace(); | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * @description 处理观影记录 | ||
| 194 | * @param content 消息内容 | ||
| 195 | */ | ||
| 196 | @RabbitHandler | ||
| 197 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getViewRecordQueue()}", | ||
| 198 | containerFactory = "#{rabbitMqSourceConfig.getViewRecordSource()}", | ||
| 199 | autoStartup = "#{rabbitMqSourceConfig.getViewRecordStartUp()}", | ||
| 200 | ackMode = "MANUAL") | ||
| 201 | public void viewRecordConsumer(Channel channel, Message message, String content) throws IOException { | ||
| 202 | log.info("receive ViewRecord add message, content {}", content); | ||
| 203 | |||
| 204 | try { | ||
| 205 | |||
| 206 | JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); | ||
| 207 | if (Objects.nonNull(content)) { | ||
| 208 | String evt = jsonObject.get("evt").toString(); | ||
| 209 | String msgData = jsonObject.get("msgData").toString(); | ||
| 210 | switch (evt.toUpperCase()) { | ||
| 211 | // 添加收藏 | ||
| 212 | case "VIEWRECORD": | ||
| 213 | this.restTemplateClient.dealViewRecord(msgData); | ||
| 214 | break; | ||
| 215 | default: | ||
| 216 | break; | ||
| 217 | |||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 222 | |||
| 223 | } catch (Exception e) { | ||
| 224 | |||
| 225 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 226 | |||
| 227 | if (MapUtils.isNotEmpty(error)) { | ||
| 228 | String errorStart = this.error.get("start"); | ||
| 229 | |||
| 230 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 231 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 232 | String filePath = this.error.get("filePath"); | ||
| 233 | String filePath1 = filePath+fileName; | ||
| 234 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 235 | } | ||
| 236 | |||
| 237 | } | ||
| 238 | |||
| 239 | e.printStackTrace(); | ||
| 240 | } | ||
| 241 | } | ||
| 242 | |||
| 243 | |||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | /** | ||
| 248 | * @description 添加收藏记录 | ||
| 249 | * @param content 消息内容 | ||
| 250 | */ | ||
| 251 | @RabbitHandler | ||
| 252 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueAdd()}", | ||
| 253 | containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", | ||
| 254 | autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", | ||
| 255 | ackMode = "MANUAL") | ||
| 256 | public void collectionConsumerAdd(Channel channel, Message message, String content) throws IOException { | ||
| 257 | log.info("receive collectionConsumerAdd add message, content {}", content); | ||
| 258 | |||
| 259 | try { | ||
| 260 | |||
| 261 | JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); | ||
| 262 | if (Objects.nonNull(content)) { | ||
| 263 | String evt = jsonObject.get("evt").toString(); | ||
| 264 | String msgData = jsonObject.get("msgData").toString(); | ||
| 265 | switch (evt.toUpperCase()) { | ||
| 266 | // 添加收藏 | ||
| 267 | case "ADDCOLLECTION": | ||
| 268 | this.restTemplateClient.addCollection(msgData); | ||
| 269 | break; | ||
| 270 | // 删除收藏 | ||
| 271 | case "DELETECOLLECTION": | ||
| 272 | this.restTemplateClient.deleteCollection(msgData); | ||
| 273 | break; | ||
| 274 | // 删除全部收藏 | ||
| 275 | case "DELETEALLCOLLECTION": | ||
| 276 | this.restTemplateClient.deleteAllCollection(msgData); | ||
| 277 | break; | ||
| 278 | default: | ||
| 279 | break; | ||
| 280 | |||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 285 | |||
| 286 | } catch (Exception e) { | ||
| 287 | |||
| 288 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 289 | |||
| 290 | if (MapUtils.isNotEmpty(error)) { | ||
| 291 | String errorStart = this.error.get("start"); | ||
| 292 | |||
| 293 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 294 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 295 | String filePath = this.error.get("filePath"); | ||
| 296 | String filePath1 = filePath+fileName; | ||
| 297 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 298 | } | ||
| 299 | |||
| 300 | } | ||
| 301 | |||
| 302 | e.printStackTrace(); | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | /** | ||
| 307 | * @description 添加收藏记录 | ||
| 308 | * @param content 消息内容 | ||
| 309 | */ | ||
| 310 | @RabbitHandler | ||
| 311 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueDelete()}", | ||
| 312 | containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", | ||
| 313 | autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", | ||
| 314 | ackMode = "MANUAL") | ||
| 315 | public void collectionConsumerDelete(Channel channel, Message message, String content) throws IOException { | ||
| 316 | log.info("receive collectionConsumerDelete add message, content {}", content); | ||
| 317 | |||
| 318 | try { | ||
| 319 | |||
| 320 | JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); | ||
| 321 | if (Objects.nonNull(content)) { | ||
| 322 | String evt = jsonObject.get("evt").toString(); | ||
| 323 | String msgData = jsonObject.get("msgData").toString(); | ||
| 324 | switch (evt.toUpperCase()) { | ||
| 325 | // 添加收藏 | ||
| 326 | case "ADDCOLLECTION": | ||
| 327 | this.restTemplateClient.addCollection(msgData); | ||
| 328 | break; | ||
| 329 | // 删除收藏 | ||
| 330 | case "DELETECOLLECTION": | ||
| 331 | this.restTemplateClient.deleteCollection(msgData); | ||
| 332 | break; | ||
| 333 | // 删除全部收藏 | ||
| 334 | case "DELETEALLCOLLECTION": | ||
| 335 | this.restTemplateClient.deleteAllCollection(msgData); | ||
| 336 | break; | ||
| 337 | default: | ||
| 338 | break; | ||
| 339 | |||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 344 | |||
| 345 | } catch (Exception e) { | ||
| 346 | |||
| 347 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 348 | |||
| 349 | if (MapUtils.isNotEmpty(error)) { | ||
| 350 | String errorStart = this.error.get("start"); | ||
| 351 | |||
| 352 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 353 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 354 | String filePath = this.error.get("filePath"); | ||
| 355 | String filePath1 = filePath+fileName; | ||
| 356 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 357 | } | ||
| 358 | |||
| 359 | } | ||
| 360 | |||
| 361 | e.printStackTrace(); | ||
| 362 | } | ||
| 363 | } | ||
| 364 | |||
| 365 | /** | ||
| 366 | * @description 添加收藏记录 | ||
| 367 | * @param content 消息内容 | ||
| 368 | */ | ||
| 369 | @RabbitHandler | ||
| 370 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueDeleteAll()}", | ||
| 371 | containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", | ||
| 372 | autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", | ||
| 373 | ackMode = "MANUAL") | ||
| 374 | public void collectionConsumerDeleteAll(Channel channel, Message message, String content) throws IOException { | ||
| 375 | log.info("receive collectionConsumerDeleteAll add message, content {}", content); | ||
| 376 | |||
| 377 | try { | ||
| 378 | |||
| 379 | JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); | ||
| 380 | if (Objects.nonNull(content)) { | ||
| 381 | String evt = jsonObject.get("evt").toString(); | ||
| 382 | String msgData = jsonObject.get("msgData").toString(); | ||
| 383 | switch (evt.toUpperCase()) { | ||
| 384 | // 添加收藏 | ||
| 385 | case "ADDCOLLECTION": | ||
| 386 | this.restTemplateClient.addCollection(msgData); | ||
| 387 | break; | ||
| 388 | // 删除收藏 | ||
| 389 | case "DELETECOLLECTION": | ||
| 390 | this.restTemplateClient.deleteCollection(msgData); | ||
| 391 | break; | ||
| 392 | // 删除全部收藏 | ||
| 393 | case "DELETEALLCOLLECTION": | ||
| 394 | this.restTemplateClient.deleteAllCollection(msgData); | ||
| 395 | break; | ||
| 396 | default: | ||
| 397 | break; | ||
| 398 | |||
| 399 | } | ||
| 400 | } | ||
| 401 | |||
| 402 | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 403 | |||
| 404 | } catch (Exception e) { | ||
| 405 | |||
| 406 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); | ||
| 407 | |||
| 408 | if (MapUtils.isNotEmpty(error)) { | ||
| 409 | String errorStart = this.error.get("start"); | ||
| 410 | |||
| 411 | if (errorStart.equalsIgnoreCase("true")) { | ||
| 412 | String fileName = this.error.get("fileName")+"_"+ LocalDate.now() +".log"; | ||
| 413 | String filePath = this.error.get("filePath"); | ||
| 414 | String filePath1 = filePath+fileName; | ||
| 415 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); | ||
| 416 | } | ||
| 417 | |||
| 418 | } | ||
| 419 | |||
| 420 | e.printStackTrace(); | ||
| 421 | } | ||
| 422 | } | ||
| 423 | } |
| ... | @@ -2,19 +2,23 @@ package com.topdraw.mq.consumer; | ... | @@ -2,19 +2,23 @@ package com.topdraw.mq.consumer; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.topdraw.config.RabbitMqConfig; | 5 | import com.rabbitmq.client.Channel; |
| 6 | import com.topdraw.mq.domain.SubscribeBean; | 6 | import com.topdraw.mq.domain.SubscribeBean; |
| 7 | import com.topdraw.resttemplate.RestTemplateClient; | 7 | import com.topdraw.resttemplate.RestTemplateClient; |
| 8 | import com.topdraw.utils.RedisUtils; | 8 | import com.topdraw.util.FileUtil; |
| 9 | import com.topdraw.utils.StringUtils; | ||
| 10 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
| 11 | import org.springframework.amqp.core.ExchangeTypes; | 10 | import org.apache.commons.collections4.MapUtils; |
| 11 | import org.springframework.amqp.core.Message; | ||
| 12 | import org.springframework.amqp.rabbit.annotation.*; | 12 | import org.springframework.amqp.rabbit.annotation.*; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.beans.factory.annotation.Value; | 14 | import org.springframework.beans.factory.annotation.Value; |
| 15 | import org.springframework.stereotype.Component; | 15 | import org.springframework.stereotype.Component; |
| 16 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| 17 | 17 | ||
| 18 | import java.io.IOException; | ||
| 19 | import java.time.LocalDate; | ||
| 20 | import java.util.Map; | ||
| 21 | |||
| 18 | /** | 22 | /** |
| 19 | * 微信事件 | 23 | * 微信事件 |
| 20 | */ | 24 | */ |
| ... | @@ -22,104 +26,14 @@ import org.springframework.transaction.annotation.Transactional; | ... | @@ -22,104 +26,14 @@ import org.springframework.transaction.annotation.Transactional; |
| 22 | @Slf4j | 26 | @Slf4j |
| 23 | public class WeiXinEventConsumer { | 27 | public class WeiXinEventConsumer { |
| 24 | 28 | ||
| 25 | |||
| 26 | @Autowired | 29 | @Autowired |
| 27 | private RestTemplateClient restTemplateClient; | 30 | private RestTemplateClient restTemplateClient; |
| 28 | 31 | ||
| 29 | private static final String QR_CODE_URL = "QR_CODE_URL_"; | 32 | private static final String QR_CODE_URL = "QR_CODE_URL_"; |
| 30 | 33 | ||
| 31 | /** | 34 | @Value("#{rabbitMqErrorLogConfig.getWechatError()}") |
| 32 | * @description 删除用户收藏记录 | 35 | private Map<String, String> error; |
| 33 | * @param content 消息内容 | ||
| 34 | */ | ||
| 35 | /*@RabbitHandler | ||
| 36 | @RabbitListener(bindings = { | ||
| 37 | @QueueBinding(value = @Queue(value = RabbitMqConfig.COLLECTION_DELETE_QUEUE), | ||
| 38 | exchange = @Exchange(value = ExchangeTypes.DIRECT))}, | ||
| 39 | containerFactory = "managementRabbitListenerContainerFactory")*/ | ||
| 40 | public void deleteCollection(String content) { | ||
| 41 | try { | ||
| 42 | log.info("receive UserCollection delete message, content {}", content); | ||
| 43 | this.restTemplateClient.deleteCollection(content); | ||
| 44 | } catch (Exception e) { | ||
| 45 | log.error("CollectionDeleteConsumer || UserCollection delete error || {}", e.toString(), e); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | 36 | ||
| 49 | /** | ||
| 50 | * @description 删除全部收藏记录 | ||
| 51 | * @param content 消息内容 | ||
| 52 | */ | ||
| 53 | /*@RabbitHandler | ||
| 54 | @RabbitListener(bindings = { | ||
| 55 | @QueueBinding(value = @Queue(value = RabbitMqConfig.COLLECTION_DELETE_ALL_QUEUE), | ||
| 56 | exchange = @Exchange(value = ExchangeTypes.DIRECT))}, | ||
| 57 | containerFactory = "managementRabbitListenerContainerFactory")*/ | ||
| 58 | @Transactional | ||
| 59 | public void deleteAllCollection(String content) { | ||
| 60 | try { | ||
| 61 | log.info("receive UserCollection delete all message, content {}", content); | ||
| 62 | this.restTemplateClient.deleteAllCollection(content); | ||
| 63 | } catch (Exception e) { | ||
| 64 | log.error("CollectionDeleteConsumer || UserCollection delete all error || {}", e.toString(), e); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * 处理带参的二维码事件 | ||
| 70 | * @param content 消息内容 | ||
| 71 | * @description 获取公众号带参二维码 | ||
| 72 | */ | ||
| 73 | /*@RabbitHandler | ||
| 74 | @RabbitListener(bindings = { | ||
| 75 | @QueueBinding(value = @Queue(value = RabbitMqConfig.GET_QR_CODE_QUEUE), | ||
| 76 | exchange = @Exchange(value = ExchangeTypes.DIRECT))}, | ||
| 77 | containerFactory = "managementRabbitListenerContainerFactory")*/ | ||
| 78 | public void getQrCode(String content) { | ||
| 79 | try { | ||
| 80 | log.info("receive get qrCode message, content {}", content); | ||
| 81 | JSONObject jsonObject = JSONObject.parseObject(content); | ||
| 82 | /*String appid = jsonObject.getString("appid"); | ||
| 83 | String IPTVappid = jsonObject.getString("IPTVappid"); | ||
| 84 | String platformAccount = jsonObject.getString("platformAccount"); | ||
| 85 | String sessionId = jsonObject.getString("sessionId"); | ||
| 86 | String key = QR_CODE_URL + appid + "_" + platformAccount + "_" + sessionId; | ||
| 87 | String url = (String) redisUtils.get(key); | ||
| 88 | if (StringUtils.isBlank(url)) { | ||
| 89 | Map<String, String> wxInfo = WeixinUtil.getWeixinInfoByAppid(appid); | ||
| 90 | var appType = wxInfo.get("appType"); | ||
| 91 | // 订阅号不支持带参二维码,直接返回 | ||
| 92 | if (StrUtil.isNotEmpty(appType) && ObjectUtil.equals(appType, WeChatConstants.WX_SUBSCRIPTION)) { | ||
| 93 | log.error("订阅号不支持带参二维码 || {} || {}", appid, content); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | QrCode qrCode = new QrCode(); | ||
| 97 | qrCode.setActionName(WeChatConstants.QR_STR_SCENE); | ||
| 98 | if (StringUtils.isNotBlank(wxInfo.get("qrCodeExpireSeconds"))) { | ||
| 99 | qrCode.setExpireSeconds(Integer.valueOf(wxInfo.get("qrCodeExpireSeconds"))); | ||
| 100 | } | ||
| 101 | ActionInfo actionInfo = new ActionInfo(); | ||
| 102 | Scene scene = new Scene(); | ||
| 103 | scene.setSceneStr(content); | ||
| 104 | actionInfo.setScene(scene); | ||
| 105 | qrCode.setActionInfo(actionInfo); | ||
| 106 | JSONObject jsonQrCode = weixinRequestUtil.getQrCode(wxInfo, qrCode); | ||
| 107 | url = jsonQrCode.getString("url"); | ||
| 108 | Integer expireSeconds = jsonQrCode.getInteger("expire_seconds"); | ||
| 109 | redisUtils.set(key, url, expireSeconds, TimeUnit.SECONDS); | ||
| 110 | } | ||
| 111 | HashMap<String, Object> map = new HashMap<>(); | ||
| 112 | map.put("sessionId", sessionId); | ||
| 113 | map.put("url", url); | ||
| 114 | map.put("appid", appid); | ||
| 115 | map.put("IPTVappid", IPTVappid); | ||
| 116 | map.put("platformAccount", platformAccount); | ||
| 117 | map.put("extraInfo", content);*/ | ||
| 118 | restTemplateClient.sendQrCodeMessage(content); | ||
| 119 | } catch (Exception e) { | ||
| 120 | log.error("GetQrCodeConsumer || get qrCode error || {}", e.toString(), e); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | 37 | ||
| 124 | /** | 38 | /** |
| 125 | * 关注和取关事件 | 39 | * 关注和取关事件 |
| ... | @@ -130,13 +44,12 @@ public class WeiXinEventConsumer { | ... | @@ -130,13 +44,12 @@ public class WeiXinEventConsumer { |
| 130 | * } | 44 | * } |
| 131 | * @param content | 45 | * @param content |
| 132 | */ | 46 | */ |
| 133 | /*@RabbitHandler | 47 | @RabbitHandler |
| 134 | @RabbitListener(bindings = { | 48 | @RabbitListener(queues = "#{rabbitMqSourceConfig.getWechatQueue()}", |
| 135 | @QueueBinding(value = @Queue(value = RabbitMqConfig.WEIXIN_SUBORUNSUB_QUEUE), | 49 | containerFactory = "#{rabbitMqSourceConfig.getWechatSource()}", |
| 136 | exchange = @Exchange(value = ExchangeTypes.DIRECT))}, | 50 | autoStartup = "#{rabbitMqSourceConfig.getWechatStartUp()}", ackMode = "MANUAL") |
| 137 | containerFactory = "managementRabbitListenerContainerFactory")*/ | ||
| 138 | @Transactional | 51 | @Transactional |
| 139 | public void subOrUnSubEvent(String content) { | 52 | public void subOrUnSubEvent(Channel channel, Message message, String content) throws IOException { |
| 140 | try { | 53 | try { |
| 141 | log.info("receive wxu subOrUnSub message, content {}", content); | 54 | log.info("receive wxu subOrUnSub message, content {}", content); |
| 142 | JSONObject jsonObject = JSONObject.parseObject(content); | 55 | JSONObject jsonObject = JSONObject.parseObject(content); |
| ... | @@ -145,18 +58,16 @@ public class WeiXinEventConsumer { | ... | @@ -145,18 +58,16 @@ public class WeiXinEventConsumer { |
| 145 | JSONObject wechatMsg = jsonObject.getJSONObject("allFieldsMap"); | 58 | JSONObject wechatMsg = jsonObject.getJSONObject("allFieldsMap"); |
| 146 | String appid = map.getString("mpId"); | 59 | String appid = map.getString("mpId"); |
| 147 | String unionid = map.getString("unionid"); | 60 | String unionid = map.getString("unionid"); |
| 148 | // Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appid); | ||
| 149 | 61 | ||
| 150 | String openid = wechatMsg.getString("FromUserName"); | 62 | String openid = wechatMsg.getString("FromUserName"); |
| 151 | String msgType = wechatMsg.getString("MsgType"); | 63 | String msgType = wechatMsg.getString("MsgType"); |
| 152 | if ("event".equals(msgType)) { | 64 | if ("event".equals(msgType)) { |
| 153 | String event = wechatMsg.getString("Event"); | 65 | String event = wechatMsg.getString("Event"); |
| 154 | log.info("event ===>> [{}]",event); | ||
| 155 | String eventKey = wechatMsg.getString("EventKey"); | 66 | String eventKey = wechatMsg.getString("EventKey"); |
| 156 | 67 | ||
| 157 | SubscribeBean subscribeBean = new SubscribeBean(); | 68 | SubscribeBean subscribeBean = new SubscribeBean(); |
| 158 | subscribeBean.setAppId(appid); | 69 | subscribeBean.setAppid(appid); |
| 159 | subscribeBean.setOpenId(openid); | 70 | subscribeBean.setOpenid(openid); |
| 160 | subscribeBean.setUnionid(unionid); | 71 | subscribeBean.setUnionid(unionid); |
| 161 | subscribeBean.setEventKey(eventKey); | 72 | subscribeBean.setEventKey(eventKey); |
| 162 | 73 | ||
| ... | @@ -166,76 +77,30 @@ public class WeiXinEventConsumer { | ... | @@ -166,76 +77,30 @@ public class WeiXinEventConsumer { |
| 166 | if (event.equals("unsubscribe")) | 77 | if (event.equals("unsubscribe")) |
| 167 | this.restTemplateClient.unsubscribe(subscribeBean); | 78 | this.restTemplateClient.unsubscribe(subscribeBean); |
| 168 | 79 | ||
| 80 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
| 169 | } | 81 | } |
| 170 | 82 | ||
| 171 | } catch (Exception e) { | 83 | } catch (Exception e) { |
| 172 | log.error("WXSubscribeConsumer || subOrUnSub msg error || {} || {}", content, e.getMessage()); | 84 | log.error("WXSubscribeConsumer || subOrUnSub msg error || {} || {}", content, e.getMessage()); |
| 173 | } | ||
| 174 | } | ||
| 175 | 85 | ||
| 176 | /** | 86 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); |
| 177 | * @description 添加收藏记录 | 87 | |
| 178 | * @param content 消息内容 | 88 | if (MapUtils.isNotEmpty(error)) { |
| 179 | */ | 89 | String errorStart = this.error.get("start"); |
| 180 | /* @RabbitHandler | 90 | |
| 181 | @RabbitListener(bindings = { | 91 | if (errorStart.equalsIgnoreCase("true")) { |
| 182 | @QueueBinding(value = @Queue(value = RabbitMqConfig.COLLECTION_ADD_QUEUE), | 92 | String fileName = this.error.get("fileName")+"_"+LocalDate.now() +".log"; |
| 183 | exchange = @Exchange(value = ExchangeTypes.DIRECT))}, | 93 | String filePath = this.error.get("filePath"); |
| 184 | containerFactory = "managementRabbitListenerContainerFactory")*/ | 94 | String filePath1 = filePath+fileName; |
| 185 | @Transactional | 95 | FileUtil.writeStringToFile2(filePath1, content, e.getMessage()); |
| 186 | public void addCollection(String content) { | ||
| 187 | try { | ||
| 188 | log.info("receive UserCollection add message, content {}", content); | ||
| 189 | JSONObject jsonObject = JSONObject.parseObject(content); | ||
| 190 | String platformAccount = jsonObject.getString("platformAccount"); | ||
| 191 | String data = jsonObject.getString("data"); | ||
| 192 | if (StringUtils.isBlank(data) || !data.startsWith("[")) { | ||
| 193 | // return; | ||
| 194 | } | ||
| 195 | /*Optional<TvUser> userOptional = tvUserRepository.findByPlatformAccount(platformAccount); | ||
| 196 | if (!userOptional.isPresent()) { | ||
| 197 | return; | ||
| 198 | } | ||
| 199 | Long tvUserId = userOptional.get().getId(); | ||
| 200 | List<UserCollectionMq> userCollectionMqList = JSONObject.parseArray(data, UserCollectionMq.class); | ||
| 201 | if (userCollectionMqList == null || userCollectionMqList.isEmpty()) { | ||
| 202 | return; | ||
| 203 | } | ||
| 204 | Map<Long, List<UserCollectionMq>> collect = userCollectionMqList.stream().collect(Collectors.groupingBy(UserCollectionMq::getUserCollectionId)); | ||
| 205 | for (Map.Entry<Long, List<UserCollectionMq>> entry : collect.entrySet()) { | ||
| 206 | List<UserCollectionMq> value = entry.getValue(); | ||
| 207 | UserCollectionMq userCollectionMq = value.get(0); | ||
| 208 | if (StringUtils.isBlank(userCollectionMq.getName())) { | ||
| 209 | userCollectionMq.setName("DEFAULT"); | ||
| 210 | } | ||
| 211 | UserCollection userCollection = userCollectionRepository | ||
| 212 | .findFirstByUserIdAndTypeAndName(tvUserId, userCollectionMq.getType(), userCollectionMq.getName()).orElseGet(UserCollection::new); | ||
| 213 | userCollection.setAppId(userCollectionMq.getAppId()) | ||
| 214 | .setUserId(tvUserId) | ||
| 215 | .setName(userCollectionMq.getName()) | ||
| 216 | .setType(userCollectionMq.getType()) | ||
| 217 | .setCount(userCollection.getCount() == null ? value.size() : userCollection.getCount() + value.size()); | ||
| 218 | UserCollection userCollectionSave = userCollectionRepository.save(userCollection); | ||
| 219 | for (UserCollectionMq collectionMq : value) { | ||
| 220 | UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq); | ||
| 221 | Optional<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository | ||
| 222 | .findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), userCollectionDetail.getDetailType(), userCollectionSave.getId()); | ||
| 223 | //观影记录同一天只存一条记录 | ||
| 224 | if (userCollectionDetailOptional.isPresent() && | ||
| 225 | DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date())) { | ||
| 226 | userCollectionDetail.setId(userCollectionDetailOptional.get().getId()); | ||
| 227 | } else { | ||
| 228 | userCollectionDetail.setId(null) | ||
| 229 | .setUserCollectionId(userCollectionSave.getId()); | ||
| 230 | } | ||
| 231 | userCollectionDetailRepository.save(userCollectionDetail); | ||
| 232 | } | 96 | } |
| 233 | }*/ | ||
| 234 | 97 | ||
| 235 | this.restTemplateClient.addCollection(content); | 98 | } |
| 236 | } catch (Exception e) { | 99 | |
| 237 | log.error("CollectionAddConsumer || UserCollection add error || {}", e.toString(), e); | 100 | e.printStackTrace(); |
| 101 | log.info("ucEventConsumer ====>>>> end"); | ||
| 238 | } | 102 | } |
| 103 | |||
| 239 | } | 104 | } |
| 240 | 105 | ||
| 241 | } | 106 | } | ... | ... |
| ... | @@ -6,6 +6,7 @@ import lombok.NoArgsConstructor; | ... | @@ -6,6 +6,7 @@ import lombok.NoArgsConstructor; |
| 6 | 6 | ||
| 7 | import javax.validation.constraints.NotNull; | 7 | import javax.validation.constraints.NotNull; |
| 8 | import java.io.Serializable; | 8 | import java.io.Serializable; |
| 9 | import java.time.LocalDateTime; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * | 12 | * |
| ... | @@ -15,21 +16,18 @@ import java.io.Serializable; | ... | @@ -15,21 +16,18 @@ import java.io.Serializable; |
| 15 | @NoArgsConstructor | 16 | @NoArgsConstructor |
| 16 | public class DataSyncMsg implements Serializable { | 17 | public class DataSyncMsg implements Serializable { |
| 17 | 18 | ||
| 18 | // 实体类型(表示需要修改的数据模型) | ||
| 19 | // @NotNull | ||
| 20 | // private EntityType entityType; | ||
| 21 | |||
| 22 | // 事件类型(用户的实际操作) | ||
| 23 | @NotNull | 19 | @NotNull |
| 24 | private String eventType; | 20 | private String evt; |
| 25 | 21 | // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 | |
| 22 | private Integer event; | ||
| 23 | //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
| 24 | @NotNull | ||
| 25 | private Integer deviceType; | ||
| 26 | // 发送时间 | ||
| 27 | private LocalDateTime time; | ||
| 26 | // 消息体 | 28 | // 消息体 |
| 27 | private MsgData msg; | 29 | private MsgData msg; |
| 28 | 30 | ||
| 29 | // 其他属性 | ||
| 30 | private String extraData; | ||
| 31 | |||
| 32 | |||
| 33 | /** | 31 | /** |
| 34 | * 消息体 | 32 | * 消息体 |
| 35 | */ | 33 | */ |
| ... | @@ -37,22 +35,16 @@ public class DataSyncMsg implements Serializable { | ... | @@ -37,22 +35,16 @@ public class DataSyncMsg implements Serializable { |
| 37 | @AllArgsConstructor | 35 | @AllArgsConstructor |
| 38 | @NoArgsConstructor | 36 | @NoArgsConstructor |
| 39 | public static class MsgData { | 37 | public static class MsgData { |
| 40 | private String remarks; //备注 | ||
| 41 | @NotNull | ||
| 42 | private Integer event; // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 | ||
| 43 | @NotNull | ||
| 44 | private Long memberId; // 会员id | 38 | private Long memberId; // 会员id |
| 45 | @NotNull | ||
| 46 | private Integer deviceType; //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) | ||
| 47 | @NotNull | ||
| 48 | private String appCode; //用户对应的应用code | ||
| 49 | private String memberCode; | 39 | private String memberCode; |
| 50 | private Long accountId; // 账号id | ||
| 51 | private Long orderId; | 40 | private Long orderId; |
| 52 | private Long activityId; | 41 | private Long activityId; |
| 53 | private Long mediaId; | 42 | private Long mediaId; |
| 54 | private Long itemId; | 43 | private Long itemId; |
| 44 | private String description; | ||
| 45 | |||
| 55 | private String param; | 46 | private String param; |
| 47 | private String platformAccount; | ||
| 56 | } | 48 | } |
| 57 | 49 | ||
| 58 | } | 50 | } | ... | ... |
| ... | @@ -10,10 +10,10 @@ import lombok.NoArgsConstructor; | ... | @@ -10,10 +10,10 @@ import lombok.NoArgsConstructor; |
| 10 | public class SubscribeBean { | 10 | public class SubscribeBean { |
| 11 | 11 | ||
| 12 | /** */ | 12 | /** */ |
| 13 | private String openId; | 13 | private String openid; |
| 14 | 14 | ||
| 15 | /** */ | 15 | /** */ |
| 16 | private String appId; | 16 | private String appid; |
| 17 | 17 | ||
| 18 | private String unionid; | 18 | private String unionid; |
| 19 | 19 | ... | ... |
| ... | @@ -6,6 +6,7 @@ import com.topdraw.business.module.member.address.domain.MemberAddress; | ... | @@ -6,6 +6,7 @@ import com.topdraw.business.module.member.address.domain.MemberAddress; |
| 6 | import com.topdraw.mq.domain.DataSyncMsg; | 6 | import com.topdraw.mq.domain.DataSyncMsg; |
| 7 | import com.topdraw.mq.domain.SubscribeBean; | 7 | import com.topdraw.mq.domain.SubscribeBean; |
| 8 | import lombok.extern.slf4j.Slf4j; | 8 | import lombok.extern.slf4j.Slf4j; |
| 9 | import org.apache.commons.lang3.StringUtils; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.core.env.Environment; | 11 | import org.springframework.core.env.Environment; |
| 11 | import org.springframework.http.ResponseEntity; | 12 | import org.springframework.http.ResponseEntity; |
| ... | @@ -41,13 +42,13 @@ public class RestTemplateClient { | ... | @@ -41,13 +42,13 @@ public class RestTemplateClient { |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | public JSONObject dealTask(DataSyncMsg dataSyncMsg) { | 44 | public JSONObject dealTask(DataSyncMsg dataSyncMsg) { |
| 44 | String url = BASE_URL + "/ucEngine/api/taskOperation/dealTask"; | 45 | String url = BASE_URL + "/uce/taskOperation/dealTask"; |
| 45 | log.info("request uc : url is " + url + ", dataSyncMsg is " + dataSyncMsg); | 46 | log.info("request uc : url is " + url + ", dataSyncMsg is " + dataSyncMsg); |
| 46 | String content = JSON.toJSONString(dataSyncMsg); | 47 | String content = JSON.toJSONString(dataSyncMsg); |
| 47 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); | 48 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); |
| 48 | objectObjectHashMap.put("content", content); | 49 | objectObjectHashMap.put("content", content); |
| 49 | log.info("===>>>" + content); | 50 | log.info("===>>>" + content); |
| 50 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); | 51 | restTemplate.postForEntity(url, objectObjectHashMap, String.class); |
| 51 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class); | 52 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class); |
| 52 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | 53 | if (responseEntity.getStatusCode().is2xxSuccessful()) { |
| 53 | String entityBody = responseEntity.getBody();444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444被44444444444444 444444 44444 44444 44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 | 54 | String entityBody = responseEntity.getBody();444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444被44444444444444 444444 44444 44444 44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 |
| ... | @@ -63,7 +64,7 @@ public class RestTemplateClient { | ... | @@ -63,7 +64,7 @@ public class RestTemplateClient { |
| 63 | 64 | ||
| 64 | public JSONObject getMemberInfo(Long memberId) { | 65 | public JSONObject getMemberInfo(Long memberId) { |
| 65 | JSONObject resultSet = null; | 66 | JSONObject resultSet = null; |
| 66 | String url = BASE_URL + "/api/member/findById/" + memberId; | 67 | String url = BASE_URL + "/uce/member/findById/" + memberId; |
| 67 | log.info("request uc : url is " + url + ", memberId is " + memberId); | 68 | log.info("request uc : url is " + url + ", memberId is " + memberId); |
| 68 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | 69 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); |
| 69 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | 70 | if (responseEntity.getStatusCode().is2xxSuccessful()) { |
| ... | @@ -78,7 +79,7 @@ public class RestTemplateClient { | ... | @@ -78,7 +79,7 @@ public class RestTemplateClient { |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | public String createMemberAddress(MemberAddress member) { | 81 | public String createMemberAddress(MemberAddress member) { |
| 81 | String url = BASE_URL + "/api/MemberAddress/create"; | 82 | String url = BASE_URL + "/uce/memberAddress/create"; |
| 82 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); | 83 | log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member)); |
| 83 | restTemplate.postForEntity(url, member, String.class); | 84 | restTemplate.postForEntity(url, member, String.class); |
| 84 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); | 85 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class); |
| ... | @@ -91,7 +92,7 @@ public class RestTemplateClient { | ... | @@ -91,7 +92,7 @@ public class RestTemplateClient { |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | public String unsubscribe(SubscribeBean subscribeBean) { | 94 | public String unsubscribe(SubscribeBean subscribeBean) { |
| 94 | String url = BASE_URL + "/ucEngine/api/userOperation/unsubscribe"; | 95 | String url = BASE_URL + "/uce/userOperation/unsubscribe"; |
| 95 | String content = JSON.toJSONString(subscribeBean); | 96 | String content = JSON.toJSONString(subscribeBean); |
| 96 | 97 | ||
| 97 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); | 98 | HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); |
| ... | @@ -107,7 +108,7 @@ public class RestTemplateClient { | ... | @@ -107,7 +108,7 @@ public class RestTemplateClient { |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 109 | public String subscribe(SubscribeBean subscribeBean) { | 110 | public String subscribe(SubscribeBean subscribeBean) { |
| 110 | String url = BASE_URL + "/ucEngine/api/userOperation/subscribe"; | 111 | String url = BASE_URL + "/uce/userOperation/subscribe"; |
| 111 | String content = JSON.toJSONString(subscribeBean); | 112 | String content = JSON.toJSONString(subscribeBean); |
| 112 | 113 | ||
| 113 | HashMap<String, String> objectObjectHashMap = new HashMap<>(); | 114 | HashMap<String, String> objectObjectHashMap = new HashMap<>(); |
| ... | @@ -124,7 +125,7 @@ public class RestTemplateClient { | ... | @@ -124,7 +125,7 @@ public class RestTemplateClient { |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | public String sendQrCodeMessage(String content) { | 127 | public String sendQrCodeMessage(String content) { |
| 127 | String url = BASE_URL + "/ucEngine/api/userOperation/sendQrCodeMessage"; | 128 | String url = BASE_URL + "/uce/userOperation/sendQrCodeMessage"; |
| 128 | restTemplate.postForEntity(url, content, String.class); | 129 | restTemplate.postForEntity(url, content, String.class); |
| 129 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); | 130 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); |
| 130 | String entityBody = ""; | 131 | String entityBody = ""; |
| ... | @@ -136,7 +137,7 @@ public class RestTemplateClient { | ... | @@ -136,7 +137,7 @@ public class RestTemplateClient { |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | public String addCollection(String content) { | 139 | public String addCollection(String content) { |
| 139 | String url = BASE_URL + "/ucEngine/api/userOperation/addCollection"; | 140 | String url = BASE_URL + "/uce/userOperation/addCollection"; |
| 140 | //处理接口调用 中文不显示问题 | 141 | //处理接口调用 中文不显示问题 |
| 141 | content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); | 142 | content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); |
| 142 | 143 | ||
| ... | @@ -151,7 +152,10 @@ public class RestTemplateClient { | ... | @@ -151,7 +152,10 @@ public class RestTemplateClient { |
| 151 | } | 152 | } |
| 152 | 153 | ||
| 153 | public String deleteCollection(String content) { | 154 | public String deleteCollection(String content) { |
| 154 | String url = BASE_URL + "/ucEngine/api/userOperation/deleteCollection"; | 155 | String url = BASE_URL + "/uce/userOperation/deleteCollection"; |
| 156 | //处理接口调用 中文不显示问题 | ||
| 157 | content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); | ||
| 158 | |||
| 155 | restTemplate.postForEntity(url, content, String.class); | 159 | restTemplate.postForEntity(url, content, String.class); |
| 156 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); | 160 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); |
| 157 | String entityBody = ""; | 161 | String entityBody = ""; |
| ... | @@ -163,7 +167,7 @@ public class RestTemplateClient { | ... | @@ -163,7 +167,7 @@ public class RestTemplateClient { |
| 163 | } | 167 | } |
| 164 | 168 | ||
| 165 | public String deleteAllCollection(String content) { | 169 | public String deleteAllCollection(String content) { |
| 166 | String url = BASE_URL + "/ucEngine/api/userOperation/deleteAllCollection"; | 170 | String url = BASE_URL + "/uce/userOperation/deleteAllCollection"; |
| 167 | restTemplate.postForEntity(url, content, String.class); | 171 | restTemplate.postForEntity(url, content, String.class); |
| 168 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); | 172 | /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); |
| 169 | String entityBody = ""; | 173 | String entityBody = ""; |
| ... | @@ -173,4 +177,19 @@ public class RestTemplateClient { | ... | @@ -173,4 +177,19 @@ public class RestTemplateClient { |
| 173 | log.info("uc response: " + entityBody);*/ | 177 | log.info("uc response: " + entityBody);*/ |
| 174 | return null; | 178 | return null; |
| 175 | } | 179 | } |
| 180 | |||
| 181 | public String dealViewRecord(String content) { | ||
| 182 | String url = BASE_URL + "/uce/userOperation/addCollection"; | ||
| 183 | //处理接口调用 中文不显示问题 | ||
| 184 | content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); | ||
| 185 | |||
| 186 | restTemplate.postForEntity(url, content, String.class); | ||
| 187 | /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); | ||
| 188 | String entityBody = ""; | ||
| 189 | if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
| 190 | entityBody = responseEntity.getBody(); | ||
| 191 | } | ||
| 192 | log.info("uc response: " + entityBody);*/ | ||
| 193 | return null; | ||
| 194 | } | ||
| 176 | } | 195 | } | ... | ... |
| 1 | package com.topdraw.util; | ||
| 2 | |||
| 3 | import java.nio.charset.StandardCharsets; | ||
| 4 | import java.util.Base64; | ||
| 5 | |||
| 6 | public class Base64Util { | ||
| 7 | |||
| 8 | public static String encode(String name){ | ||
| 9 | String name1 = new String(Base64.getEncoder().encode(name.getBytes(StandardCharsets.UTF_8))); | ||
| 10 | return name1; | ||
| 11 | } | ||
| 12 | |||
| 13 | public static void main(String[] args) { | ||
| 14 | // String name = "test005@itv"; | ||
| 15 | String name = "18580619168a@iptv"; | ||
| 16 | String encode = encode(name); | ||
| 17 | System.out.println(encode); | ||
| 18 | } | ||
| 19 | } |
| 1 | package com.topdraw.util; | 1 | package com.topdraw.util; |
| 2 | 2 | ||
| 3 | import java.text.ParseException; | ||
| 4 | import java.text.SimpleDateFormat; | ||
| 3 | import java.util.Date; | 5 | import java.util.Date; |
| 4 | 6 | ||
| 5 | public class DateUtil { | 7 | public class DateUtil { |
| ... | @@ -12,5 +14,17 @@ public class DateUtil { | ... | @@ -12,5 +14,17 @@ public class DateUtil { |
| 12 | return System.currentTimeMillis(); | 14 | return System.currentTimeMillis(); |
| 13 | } | 15 | } |
| 14 | 16 | ||
| 17 | public static String formatDate(String time){ | ||
| 18 | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 19 | try { | ||
| 20 | //使用SimpleDateFormat的parse()方法生成Date | ||
| 21 | Date date = sf.parse(time); | ||
| 22 | String format = sf.format(date); | ||
| 23 | return format; | ||
| 24 | } catch (ParseException e) { | ||
| 25 | e.printStackTrace(); | ||
| 26 | } | ||
| 15 | 27 | ||
| 28 | return null; | ||
| 29 | } | ||
| 16 | } | 30 | } | ... | ... |
src/main/java/com/topdraw/util/FileUtil.java
0 → 100644
| 1 | package com.topdraw.util; | ||
| 2 | |||
| 3 | import java.io.BufferedWriter; | ||
| 4 | import java.io.File; | ||
| 5 | import java.io.FileWriter; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.time.LocalDateTime; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author : | ||
| 11 | * @description: | ||
| 12 | * @function : | ||
| 13 | * @date :Created in 2022/5/12 11:43 | ||
| 14 | * @version: : | ||
| 15 | * @modified By: | ||
| 16 | * @since : modified in 2022/5/12 11:43 | ||
| 17 | */ | ||
| 18 | public class FileUtil { | ||
| 19 | |||
| 20 | private static void createFile(String filePath){ | ||
| 21 | File testFile = new File(filePath); | ||
| 22 | File fileParent = testFile.getParentFile();//返回的是File类型,可以调用exsit()等方法 | ||
| 23 | //String fileParentPath = testFile.getParent();//返回的是String类型 | ||
| 24 | |||
| 25 | if (!fileParent.exists()) { | ||
| 26 | fileParent.mkdirs();// 能创建多级目录 | ||
| 27 | } | ||
| 28 | |||
| 29 | if (!testFile.exists()) { | ||
| 30 | try { | ||
| 31 | testFile.createNewFile();//有路径才能创建文件 | ||
| 32 | } catch (IOException e) { | ||
| 33 | e.printStackTrace(); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | public static void writeStringToFile2(String filePath, String content, String error) { | ||
| 39 | try { | ||
| 40 | String property = System.getProperty("user.dir"); | ||
| 41 | filePath = property + filePath; | ||
| 42 | createFile(filePath); | ||
| 43 | |||
| 44 | FileWriter fw = new FileWriter(filePath, true); | ||
| 45 | BufferedWriter bw = new BufferedWriter(fw); | ||
| 46 | bw.append(LocalDateTime.now()+"\n"); | ||
| 47 | bw.write("【content】==>> \n"+content+"\n"); | ||
| 48 | bw.write("【error】==>> \n"+error+"\n"); | ||
| 49 | bw.write("----------------------------------------------------------------\n"); | ||
| 50 | bw.close(); | ||
| 51 | fw.close(); | ||
| 52 | } catch (Exception e) { | ||
| 53 | e.printStackTrace(); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | } |
| 1 | package com.topdraw.util; | 1 | package com.topdraw.util; |
| 2 | 2 | ||
| 3 | import org.apache.commons.lang3.StringUtils; | ||
| 3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 5 | 6 | ||
| ... | @@ -149,6 +150,14 @@ public class IdWorker { | ... | @@ -149,6 +150,14 @@ public class IdWorker { |
| 149 | return idWorker.nextId(); | 150 | return idWorker.nextId(); |
| 150 | } | 151 | } |
| 151 | 152 | ||
| 153 | public static String generatorCode(String prefix){ | ||
| 154 | IdWorker idWorker = new IdWorker(); | ||
| 155 | if (StringUtils.isNotBlank(prefix)) { | ||
| 156 | return prefix+"_"+String.valueOf(idWorker.nextId()); | ||
| 157 | } | ||
| 158 | return String.valueOf(idWorker.nextId()); | ||
| 159 | } | ||
| 160 | |||
| 152 | public static void main(String[] args) { | 161 | public static void main(String[] args) { |
| 153 | IdWorker idWorker = new IdWorker(); | 162 | IdWorker idWorker = new IdWorker(); |
| 154 | System.out.println(idWorker.nextId()); | 163 | System.out.println(idWorker.nextId()); | ... | ... |
src/main/java/com/topdraw/util/ListUtil.java
0 → 100644
| 1 | package com.topdraw.util; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.List; | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @author : | ||
| 8 | * @description: | ||
| 9 | * @function : | ||
| 10 | * @date :Created in 2022/5/5 12:57 | ||
| 11 | * @version: : | ||
| 12 | * @modified By: | ||
| 13 | * @since : modified in 2022/5/5 12:57 | ||
| 14 | */ | ||
| 15 | public class ListUtil { | ||
| 16 | |||
| 17 | public static List<List<Integer>> sortList(List<List<Integer>> list, String desc) { | ||
| 18 | |||
| 19 | |||
| 20 | return null; | ||
| 21 | } | ||
| 22 | |||
| 23 | public static boolean containsValue(List<Integer> list, Integer value) { | ||
| 24 | |||
| 25 | |||
| 26 | return false; | ||
| 27 | } | ||
| 28 | |||
| 29 | public static void main(String[] args) { | ||
| 30 | List<List<Integer>> listList = new ArrayList<>(); | ||
| 31 | |||
| 32 | List<Integer> integerList = new ArrayList<>(); | ||
| 33 | integerList.add(1); | ||
| 34 | integerList.add(30); | ||
| 35 | |||
| 36 | List<Integer> integerList1 = new ArrayList<>(); | ||
| 37 | integerList1.add(31); | ||
| 38 | integerList1.add(60); | ||
| 39 | |||
| 40 | listList.add(integerList); | ||
| 41 | listList.add(integerList1); | ||
| 42 | |||
| 43 | // Integer firstMaxInteger = listList.get(0).get; | ||
| 44 | /*Integer firstMaxInteger = 0; | ||
| 45 | for (List<Integer> integers : listList) { | ||
| 46 | |||
| 47 | firstMaxInteger = integers.get(integerList.size() - 1); | ||
| 48 | |||
| 49 | |||
| 50 | }*/ | ||
| 51 | } | ||
| 52 | |||
| 53 | } |
| 1 | package com.topdraw.util; | ||
| 2 | |||
| 3 | |||
| 4 | import org.redisson.api.RLock; | ||
| 5 | |||
| 6 | public class RedissonUtil { | ||
| 7 | |||
| 8 | public static void lock(RLock rLock){ | ||
| 9 | rLock.lock(); | ||
| 10 | } | ||
| 11 | |||
| 12 | |||
| 13 | public static void unlock(RLock rLock){ | ||
| 14 | if (rLock.isLocked() && rLock.isHeldByCurrentThread()) | ||
| 15 | rLock.unlock(); | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | } |
| 1 | spring: | ||
| 2 | # 数据源 | ||
| 3 | datasource: | ||
| 4 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_iptv?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
| 5 | username: root | ||
| 6 | password: root | ||
| 7 | # 驱动程序 | ||
| 8 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ||
| 9 | # Druid | ||
| 10 | type: com.alibaba.druid.pool.DruidDataSource | ||
| 11 | druid: | ||
| 12 | # 初始化配置 | ||
| 13 | initial-size: 3 | ||
| 14 | # 最小连接数 | ||
| 15 | min-idle: 3 | ||
| 16 | # 最大连接数 | ||
| 17 | max-active: 15 | ||
| 18 | # 获取连接超时时间 | ||
| 19 | max-wait: 5000 | ||
| 20 | # 连接有效性检测时间 | ||
| 21 | time-between-eviction-runs-millis: 90000 | ||
| 22 | # 最大空闲时间 | ||
| 23 | min-evictable-idle-time-millis: 1800000 | ||
| 24 | test-while-idle: true | ||
| 25 | test-on-borrow: false | ||
| 26 | test-on-return: false | ||
| 27 | validation-query: select 1 | ||
| 28 | # 配置监控统计拦截的filters | ||
| 29 | filters: stat | ||
| 30 | stat-view-servlet: | ||
| 31 | url-pattern: /druid/* | ||
| 32 | reset-enable: false | ||
| 33 | # 过滤器 | ||
| 34 | web-stat-filter: | ||
| 35 | url-pattern: /* | ||
| 36 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | ||
| 37 | |||
| 38 | # jpa | ||
| 39 | jpa: | ||
| 40 | properties: | ||
| 41 | hibernate: | ||
| 42 | # 数据库类型 | ||
| 43 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect | ||
| 44 | hibernate: | ||
| 45 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | ||
| 46 | ddl-auto: none | ||
| 47 | open-in-view: true | ||
| 48 | |||
| 49 | # redis | ||
| 50 | redis: | ||
| 51 | #数据库索引 | ||
| 52 | database: 0 | ||
| 53 | host: 122.112.214.149 | ||
| 54 | port: 6379 | ||
| 55 | password: redis123 | ||
| 56 | #连接超时时间 | ||
| 57 | timeout: 5000 | ||
| 58 | |||
| 59 | |||
| 60 | ###########################################自定义属性################################################################# | ||
| 61 | # 多mq配置 | ||
| 62 | mutil-mq: | ||
| 63 | # 服务侧 | ||
| 64 | service: | ||
| 65 | # ip | ||
| 66 | host: 122.112.214.149 | ||
| 67 | # host: 139.196.145.150 | ||
| 68 | # 端口 | ||
| 69 | port: 5672 | ||
| 70 | # 用户名 | ||
| 71 | username: guest | ||
| 72 | # username: admin | ||
| 73 | # 密码 | ||
| 74 | password: guest | ||
| 75 | # password: Topdraw1qaz | ||
| 76 | # 虚拟空间 | ||
| 77 | virtual-host: member_center_chongshu | ||
| 78 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
| 79 | |||
| 80 | # 管理侧 | ||
| 81 | management: | ||
| 82 | # host: 122.112.214.149 # rabbitmq的连接地址 | ||
| 83 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
| 84 | port: 5672 # rabbitmq的连接端口号 | ||
| 85 | virtual-host: member_center # rabbitmq的虚拟host | ||
| 86 | username: guest # rabbitmq的用户名 | ||
| 87 | password: guest # rabbitmq的密码 | ||
| 88 | # username: admin # rabbitmq的用户名 | ||
| 89 | # password: Topdraw1qaz # rabbitmq的密码 | ||
| 90 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
| 91 | |||
| 92 | # 服务属性 | ||
| 93 | service: | ||
| 94 | mq: | ||
| 95 | list: | ||
| 96 | - source: event | ||
| 97 | exchange: event.exchange | ||
| 98 | queue: event.queue | ||
| 99 | exchange-type: direct | ||
| 100 | routing-key: | ||
| 101 | active: service | ||
| 102 | - source: collection | ||
| 103 | exchange: collection.exchange | ||
| 104 | queue: collection.queue | ||
| 105 | exchange-type: direct | ||
| 106 | routing-key: | ||
| 107 | active: service | ||
| 108 | - source: viewRecord | ||
| 109 | exchange: viewRecord.exchange | ||
| 110 | queue: viewRecord.queue | ||
| 111 | exchange-type: direct | ||
| 112 | routing-key: | ||
| 113 | active: service | ||
| 114 | - source: eventBus | ||
| 115 | exchange: uc.eventbus | ||
| 116 | queue: uc.eventbus | ||
| 117 | exchange-type: topic | ||
| 118 | routing-key: uc.eventbus.*.topic | ||
| 119 | active: service | ||
| 120 | - source: uce | ||
| 121 | exchange: uce.exchange | ||
| 122 | queue: uce.queue | ||
| 123 | exchange-type: direct | ||
| 124 | routing-key: | ||
| 125 | active: management | ||
| 126 | - source: wechat | ||
| 127 | exchange: weixin.exchange.direct | ||
| 128 | queue: weixin.subOrUnSub.queue | ||
| 129 | exchange-type: direct | ||
| 130 | routing-key: | ||
| 131 | active: | ||
| 132 | error: | ||
| 133 | logs: | ||
| 134 | list: | ||
| 135 | - type: eventBus | ||
| 136 | filePath: /logs/mq/eventBus/ | ||
| 137 | fileName: error | ||
| 138 | start: on | ||
| 139 | - type: ucg | ||
| 140 | filePath: /logs/mq/ucg/ | ||
| 141 | fileName: error | ||
| 142 | start: on | ||
| 143 | - type: uce | ||
| 144 | filePath: /logs/mq/uce/ | ||
| 145 | fileName: error | ||
| 146 | start: on | ||
| 147 | - type: wechat | ||
| 148 | filePath: /logs/mq/wechat/ | ||
| 149 | fileName: error | ||
| 150 | start: on | ||
| 151 | |||
| 152 | api: | ||
| 153 | baseUrl: http://127.0.0.1:8447 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | spring: | 1 | spring: |
| 2 | # 数据源 | 2 | # 数据源 |
| 3 | datasource: | 3 | datasource: |
| 4 | # 数据源地址 | 4 | url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_iptv?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 5 | url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs_iptv_sichuan?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
| 6 | # 用户名 | ||
| 7 | username: root | 5 | username: root |
| 8 | # 密码 | 6 | password: root |
| 9 | password: Tjlh@2021 | 7 | # url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs_iptv_sichuan?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
| 8 | # username: root | ||
| 9 | # password: Tjlh@2021 | ||
| 10 | # 驱动程序 | 10 | # 驱动程序 |
| 11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | 11 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy |
| 12 | # Druid | 12 | # Druid |
| ... | @@ -38,16 +38,6 @@ spring: | ... | @@ -38,16 +38,6 @@ spring: |
| 38 | url-pattern: /* | 38 | url-pattern: /* |
| 39 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" | 39 | exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" |
| 40 | 40 | ||
| 41 | # freemarker | ||
| 42 | freemarker: | ||
| 43 | check-template-location: false | ||
| 44 | jackson: | ||
| 45 | time-zone: GMT+8 | ||
| 46 | data: | ||
| 47 | redis: | ||
| 48 | repositories: | ||
| 49 | enabled: false | ||
| 50 | |||
| 51 | # jpa | 41 | # jpa |
| 52 | jpa: | 42 | jpa: |
| 53 | properties: | 43 | properties: |
| ... | @@ -58,13 +48,7 @@ spring: | ... | @@ -58,13 +48,7 @@ spring: |
| 58 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | 48 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 |
| 59 | ddl-auto: none | 49 | ddl-auto: none |
| 60 | open-in-view: true | 50 | open-in-view: true |
| 61 | 51 | show-sql: false | |
| 62 | # 文件上传 | ||
| 63 | servlet: | ||
| 64 | multipart: | ||
| 65 | file-size-threshold: 2KB | ||
| 66 | max-file-size: 100MB | ||
| 67 | max-request-size: 200MB | ||
| 68 | 52 | ||
| 69 | # redis | 53 | # redis |
| 70 | redis: | 54 | redis: |
| ... | @@ -76,113 +60,125 @@ spring: | ... | @@ -76,113 +60,125 @@ spring: |
| 76 | #连接超时时间 | 60 | #连接超时时间 |
| 77 | timeout: 5000 | 61 | timeout: 5000 |
| 78 | 62 | ||
| 79 | # rabbitmq | ||
| 80 | # rabbitmq: | ||
| 81 | # # ip | ||
| 82 | # host: 139.196.145.150 | ||
| 83 | # # 端口号 | ||
| 84 | # port: 5672 | ||
| 85 | # # 用户名 | ||
| 86 | # username: admin # rabbitmq的用户名 | ||
| 87 | # # 密码 | ||
| 88 | # password: Topdraw1qaz | ||
| 89 | # # 虚拟空间 | ||
| 90 | # virtual-host: member_center | ||
| 91 | # # 如果对异步消息需要回调必须设置为true | ||
| 92 | # publisher-confirms: true | ||
| 93 | |||
| 94 | #是否允许生成代码,生产环境设置为false | ||
| 95 | generator: | ||
| 96 | enabled: false | ||
| 97 | |||
| 98 | #是否开启 swagger-ui | ||
| 99 | swagger: | ||
| 100 | enabled: true | ||
| 101 | |||
| 102 | 63 | ||
| 103 | ###########################################自定义属性################################################################# | 64 | ###########################################自定义属性################################################################# |
| 104 | # 多mq配置 | 65 | # 多mq配置 |
| 105 | mutil-mq: | 66 | mutil-mq: |
| 106 | # 服务侧 | 67 | # 服务侧 |
| 107 | service: | 68 | service: |
| 108 | # # ip | ||
| 109 | # host: 139.196.192.242 | ||
| 110 | # # 端口 | ||
| 111 | # port: 5672 | ||
| 112 | # # 用户名 | ||
| 113 | # username: member_center | ||
| 114 | # # 密码 | ||
| 115 | # password: Tjlh@2021 | ||
| 116 | # # 虚拟空间 | ||
| 117 | # virtual-host: /member_center | ||
| 118 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
| 119 | port: 5672 # rabbitmq的连接端口号 | ||
| 120 | virtual-host: member_center_sichuan # rabbitmq的虚拟hosthhh | ||
| 121 | username: guest # rabbitmq的用户名 | ||
| 122 | password: guest # rabbitmq的密码 | ||
| 123 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
| 124 | |||
| 125 | # 管理侧 | ||
| 126 | management: | ||
| 127 | # ip | ||
| 128 | # host: 139.196.145.150 | ||
| 129 | # # 端口 | ||
| 130 | # port: 5672 | ||
| 131 | # # 用户名 | ||
| 132 | # username: admin | ||
| 133 | # # 密码 | ||
| 134 | # password: Topdraw1qaz | ||
| 135 | # # 虚拟空间 | ||
| 136 | # virtual-host: member_center | ||
| 137 | # ip | 69 | # ip |
| 138 | host: 122.112.214.149 | 70 | host: 122.112.214.149 |
| 71 | # host: 139.196.145.150 | ||
| 139 | # 端口 | 72 | # 端口 |
| 140 | port: 5672 | 73 | port: 5672 |
| 141 | # 用户名 | 74 | # 用户名 |
| 142 | username: guest | 75 | username: guest |
| 76 | # username: admin | ||
| 143 | # 密码 | 77 | # 密码 |
| 144 | password: guest | 78 | password: guest |
| 79 | # password: Topdraw1qaz | ||
| 145 | # 虚拟空间 | 80 | # 虚拟空间 |
| 146 | virtual-host: member_center_sichuan | 81 | # virtual-host: member_center_iptv_sichuan |
| 82 | virtual-host: member_center_small_sichuan | ||
| 83 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
| 147 | 84 | ||
| 148 | #登录图形验证码有效时间/分钟 | 85 | # 管理侧 |
| 149 | loginCode: | 86 | management: |
| 150 | expiration: 2 | 87 | # host: 122.112.214.149 # rabbitmq的连接地址 |
| 88 | host: 122.112.214.149 # rabbitmq的连接地址 | ||
| 89 | port: 5672 # rabbitmq的连接端口号 | ||
| 90 | virtual-host: member_center_small_sichuan # rabbitmq的虚拟host | ||
| 91 | # virtual-host: member_center_small_chongshu # rabbitmq的虚拟host | ||
| 92 | username: guest # rabbitmq的用户名 | ||
| 93 | password: guest # rabbitmq的密码 | ||
| 94 | # username: admin # rabbitmq的用户名 | ||
| 95 | # password: Topdraw1qaz # rabbitmq的密码 | ||
| 96 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | ||
| 151 | 97 | ||
| 152 | # 服务属性 | 98 | # 服务属性 |
| 153 | service: | 99 | service: |
| 154 | # 服务域 mobile:小屏侧 vis:大屏侧 | 100 | mq: |
| 155 | area: vis | 101 | list: |
| 156 | #平台类型 service: 服务侧 management: 管理侧 | 102 | # - source: event |
| 157 | platform: service | 103 | # exchange: event.exchange |
| 158 | 104 | # queue: event.queue | |
| 159 | # uc-engine服务地址 | 105 | # exchange-type: direct |
| 160 | api: | 106 | # routing-key: |
| 161 | baseUrl: http://127.0.0.1:8447 | 107 | # active: service |
| 108 | - source: collection | ||
| 109 | exchange: exchange.collection | ||
| 110 | queue: collection.queue | ||
| 111 | exchange-type: direct | ||
| 112 | routing-key: | ||
| 113 | active: service | ||
| 114 | - source: collection | ||
| 115 | exchange: userCenter_exchange | ||
| 116 | queue: queue.collection.add | ||
| 117 | exchange-type: direct | ||
| 118 | routing-key: route.UserCollection.add | ||
| 119 | active: service | ||
| 120 | - source: collection | ||
| 121 | exchange: userCenter_exchange | ||
| 122 | queue: queue.collection.delete | ||
| 123 | exchange-type: direct | ||
| 124 | routing-key: route.UserCollection.delete | ||
| 125 | active: service | ||
| 126 | - source: collection | ||
| 127 | exchange: userCenter_exchange | ||
| 128 | queue: queue.collection.deleteall | ||
| 129 | exchange-type: direct | ||
| 130 | routing-key: route.UserCollection.deleteall | ||
| 131 | active: service | ||
| 162 | 132 | ||
| 163 | # 线程池设置 | 133 | # - source: viewRecord |
| 164 | task: | 134 | # exchange: viewRecord.exchange |
| 165 | pool: | 135 | # queue: viewRecord.queue |
| 166 | # 核心线程池大小 | 136 | # exchange-type: direct |
| 167 | core-pool-size: 10 | 137 | # routing-key: |
| 168 | # 最大线程数 | 138 | # active: service |
| 169 | max-pool-size: 30 | 139 | # - source: eventBus |
| 170 | # 活跃时间 | 140 | # exchange: uc.eventbus |
| 171 | keep-alive-seconds: 60 | 141 | # queue: uc.eventbus |
| 172 | # 队列容量 | 142 | # exchange-type: topic |
| 173 | queue-capacity: 50 | 143 | # routing-key: uc.eventbus.*.topic |
| 144 | # active: service | ||
| 145 | - source: uce | ||
| 146 | exchange: uc.direct | ||
| 147 | queue: uc.route.key.direct.event.bbb | ||
| 148 | exchange-type: direct | ||
| 149 | routing-key: | ||
| 150 | active: service | ||
| 151 | - source: uce | ||
| 152 | exchange: exchange.MemberInfoSync | ||
| 153 | queue: queue.MemberInfoSync | ||
| 154 | exchange-type: direct | ||
| 155 | routing-key: | ||
| 156 | active: service | ||
| 157 | # - source: wechat | ||
| 158 | # exchange: weixin.subOrUnSub.direct | ||
| 159 | # queue: weixin.subOrUnSub.queue | ||
| 160 | # exchange-type: direct | ||
| 161 | # routing-key: | ||
| 162 | # active: active | ||
| 163 | error: | ||
| 164 | logs: | ||
| 165 | list: | ||
| 166 | - type: eventBus | ||
| 167 | filePath: /logs/mq/eventBus/ | ||
| 168 | fileName: error | ||
| 169 | start: on | ||
| 170 | - type: ucg | ||
| 171 | filePath: /logs/mq/ucg/ | ||
| 172 | fileName: error | ||
| 173 | start: on | ||
| 174 | - type: uce | ||
| 175 | filePath: /logs/mq/uce/ | ||
| 176 | fileName: error | ||
| 177 | start: on | ||
| 178 | - type: wechat | ||
| 179 | filePath: /logs/mq/wechat/ | ||
| 180 | fileName: error | ||
| 181 | start: on | ||
| 174 | 182 | ||
| 175 | #权限 jwt。依赖的common中有需要jwt的部分属性。 | ||
| 176 | jwt: | ||
| 177 | header: Authorization | ||
| 178 | secret: mySecret | ||
| 179 | # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒 | ||
| 180 | expiration: 7200000 | ||
| 181 | # 在线用户key | ||
| 182 | online: online-token | ||
| 183 | # 验证码 | ||
| 184 | codeKey: code-key | ||
| 185 | # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期 | ||
| 186 | detect: 3600000 | ||
| 187 | # 续期时间,2小时,单位毫秒 | ||
| 188 | renew: 7200000 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 183 | api: | ||
| 184 | baseUrl: http://127.0.0.1:8447 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <configuration scan="true" scanPeriod="60 seconds" debug="false"> | 2 | <configuration scan="true" scanPeriod="60 seconds" debug="false"> |
| 3 | 3 | ||
| 4 | <contextName>UserCenter</contextName> | 4 | <contextName>uc-consumer</contextName> |
| 5 | <!--定义参数,后面可以通过${app.name}使用--> | 5 | <!--定义参数,后面可以通过${app.name}使用--> |
| 6 | <property name="app.name" value="member-engine"/> | 6 | <property name="app.name" value="uc-consumer"/> |
| 7 | <property name="log.path" value="./logs"/> | 7 | <property name="log.path" value="./logs"/> |
| 8 | <property name="log.pattern" value="%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n"/> | 8 | <property name="log.pattern" value="%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n"/> |
| 9 | 9 | ... | ... |
| ... | @@ -2,8 +2,16 @@ package com.topdraw.resttemplate; | ... | @@ -2,8 +2,16 @@ package com.topdraw.resttemplate; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.topdraw.BaseTest; | 4 | import com.topdraw.BaseTest; |
| 5 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
| 6 | import org.apache.poi.util.IOUtils; | ||
| 5 | import org.junit.Test; | 7 | import org.junit.Test; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | import org.springframework.context.ApplicationContext; | ||
| 10 | |||
| 11 | import java.io.*; | ||
| 12 | import java.lang.reflect.Field; | ||
| 13 | import java.time.LocalDate; | ||
| 14 | import java.time.LocalDateTime; | ||
| 7 | 15 | ||
| 8 | public class RestTemplateTest extends BaseTest { | 16 | public class RestTemplateTest extends BaseTest { |
| 9 | 17 | ||
| ... | @@ -16,4 +24,92 @@ public class RestTemplateTest extends BaseTest { | ... | @@ -16,4 +24,92 @@ public class RestTemplateTest extends BaseTest { |
| 16 | System.out.println(memberInfo); | 24 | System.out.println(memberInfo); |
| 17 | } | 25 | } |
| 18 | 26 | ||
| 27 | @Test | ||
| 28 | public void error(){ | ||
| 29 | String msg3 = "{\n" + | ||
| 30 | " \"evt\": \"play\", \n" + | ||
| 31 | " \"deviceType\": 1, \n" + | ||
| 32 | // " \"time\": \"2022-04-14 00:10:09\",\n" + | ||
| 33 | " \"time\": \"2022-05-03 23:10:09\",\n" + | ||
| 34 | " \"msgData\": {\n" + | ||
| 35 | " \"platformAccount\": \"topdraw\", \n" + | ||
| 36 | " \"playDuration\": "+23+", \n" + | ||
| 37 | " \"mediaCode\": \"\", \n" + | ||
| 38 | " \"mediaName\": \"\"\n" + | ||
| 39 | " }\n" + | ||
| 40 | " }"; | ||
| 41 | |||
| 42 | String classpathUrlPrefix = ApplicationContext.CLASSPATH_URL_PREFIX; | ||
| 43 | String panfu = ""; | ||
| 44 | // String filePath = classpathUrlPrefix+"/mq/play/error.log"; | ||
| 45 | String property = System.getProperty("user.dir"); | ||
| 46 | String separator = File.separator; | ||
| 47 | System.out.println(property); | ||
| 48 | String fileName = "error_"+ LocalDate.now() +".log"; | ||
| 49 | String filePath = property+separator+"logs"+separator+"mq"+separator+fileName; | ||
| 50 | createFile(filePath); | ||
| 51 | this.writeStringToFile2(filePath, msg3); | ||
| 52 | |||
| 53 | String a = "{\n" + | ||
| 54 | "\"data\": [\n" + | ||
| 55 | "\t{\n" + | ||
| 56 | "\t\"app_id\": 57,\n" + | ||
| 57 | "\t\"user_id\": 1,\n" + | ||
| 58 | "\t\"type\": 1,\n" + | ||
| 59 | "\t\"name\": \"PersonalCollectionRecords\",\n" + | ||
| 60 | "\t\"count\": 22,\n" + | ||
| 61 | "\t\"images\": \"{\\\"map\\\":{\\\"poster\\\":[0]},\\\"list\\\":[{\\\"id\\\":47422,\\\"type\\\":2,\\\"width\\\":222,\\\"height\\\":294,\\\"fileUrl\\\":\\\"upload/image/media/2020-07-30/9a8a02db-9444-4bff-ba54-ea784ae4f88c.jpg\\\",\\\"size\\\":104643}]}\",\n" + | ||
| 62 | "\t\"id\": 756756,\n" + | ||
| 63 | "\t\"user_collection_id\": 1,\n" + | ||
| 64 | "\t\"detail_folder_code\": \"Default\",\n" + | ||
| 65 | "\t\"detail_type\": \"MEDIA\",\n" + | ||
| 66 | "\t\"detail_id\": 46532,\n" + | ||
| 67 | "\t\"detail_code\": \"media_558bc45a-5480-46ec-be9a-c749ffdbdf49\",\n" + | ||
| 68 | "\t\"detail_name\": \"熊出没之探险日记2\",\n" + | ||
| 69 | "\t\"detail_total_index\": 40,\n" + | ||
| 70 | "\t\"detail_sequence\": 1,\n" + | ||
| 71 | "\t\"create_time\": 1644503167000,\n" + | ||
| 72 | "\t\"update_time\": 1644503167000\n" + | ||
| 73 | "\t}\n" + | ||
| 74 | "\t],\n" + | ||
| 75 | "\"platformAccount\": \"topdraw\"\n" + | ||
| 76 | "}"; | ||
| 77 | } | ||
| 78 | |||
| 79 | private void createFile(String filePath){ | ||
| 80 | File testFile = new File(filePath); | ||
| 81 | File fileParent = testFile.getParentFile();//返回的是File类型,可以调用exsit()等方法 | ||
| 82 | String fileParentPath = testFile.getParent();//返回的是String类型 | ||
| 83 | System.out.println("fileParent:" + fileParent); | ||
| 84 | System.out.println("fileParentPath:" + fileParentPath); | ||
| 85 | if (!fileParent.exists()) { | ||
| 86 | fileParent.mkdirs();// 能创建多级目录 | ||
| 87 | } | ||
| 88 | |||
| 89 | if (!testFile.exists()) { | ||
| 90 | try { | ||
| 91 | testFile.createNewFile();//有路径才能创建文件 | ||
| 92 | } catch (IOException e) { | ||
| 93 | e.printStackTrace(); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | System.out.println(testFile); | ||
| 98 | } | ||
| 99 | |||
| 100 | public void writeStringToFile2(String filePath, String error) { | ||
| 101 | try { | ||
| 102 | FileWriter fw = new FileWriter(filePath, true); | ||
| 103 | BufferedWriter bw = new BufferedWriter(fw); | ||
| 104 | bw.append(LocalDateTime.now()+"=>"+error+"\n"); | ||
| 105 | //bw.write("我是");// 往已有的文件上添加字符串 | ||
| 106 | //bw.write("程序猿\n "); | ||
| 107 | bw.close(); | ||
| 108 | fw.close(); | ||
| 109 | } catch (Exception e) { | ||
| 110 | // TODO Auto-generated catch block | ||
| 111 | e.printStackTrace(); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 19 | } | 115 | } | ... | ... |
-
Please register or sign in to post a comment