1.添加同步管理侧积分计算,包括获取和消耗
Showing
71 changed files
with
3044 additions
and
152 deletions
| ... | @@ -23,6 +23,13 @@ | ... | @@ -23,6 +23,13 @@ |
| 23 | 23 | ||
| 24 | <dependencies> | 24 | <dependencies> |
| 25 | 25 | ||
| 26 | <!--redisson--> | ||
| 27 | <dependency> | ||
| 28 | <groupId>org.redisson</groupId> | ||
| 29 | <artifactId>redisson</artifactId> | ||
| 30 | <version>3.16.3</version> | ||
| 31 | </dependency> | ||
| 32 | |||
| 26 | <!--代码生成器--> | 33 | <!--代码生成器--> |
| 27 | <dependency> | 34 | <dependency> |
| 28 | <groupId>com.topdraw</groupId> | 35 | <groupId>com.topdraw</groupId> |
| ... | @@ -113,7 +120,7 @@ | ... | @@ -113,7 +120,7 @@ |
| 113 | </profiles> | 120 | </profiles> |
| 114 | 121 | ||
| 115 | <build> | 122 | <build> |
| 116 | <finalName>member-engine</finalName> | 123 | <finalName>uc-consumer</finalName> |
| 117 | <plugins> | 124 | <plugins> |
| 118 | <plugin> | 125 | <plugin> |
| 119 | <groupId>org.springframework.boot</groupId> | 126 | <groupId>org.springframework.boot</groupId> | ... | ... |
| ... | @@ -33,6 +33,9 @@ public class MemberAddress implements Serializable { | ... | @@ -33,6 +33,9 @@ public class MemberAddress implements Serializable { |
| 33 | @Column(name = "member_id", nullable = false) | 33 | @Column(name = "member_id", nullable = false) |
| 34 | private Long memberId; | 34 | private Long memberId; |
| 35 | 35 | ||
| 36 | @Transient | ||
| 37 | private String memberCode; | ||
| 38 | |||
| 36 | // 类型 1:家;2:公司;3:学校 | 39 | // 类型 1:家;2:公司;3:学校 |
| 37 | @Column(name = "type", nullable = false) | 40 | @Column(name = "type", nullable = false) |
| 38 | private Integer type; | 41 | private Integer type; | ... | ... |
| ... | @@ -4,10 +4,13 @@ import com.topdraw.business.basicdata.member.address.domain.MemberAddress; | ... | @@ -4,10 +4,13 @@ import com.topdraw.business.basicdata.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 | |||
| 7 | /** | 9 | /** |
| 8 | * @author XiangHan | 10 | * @author XiangHan |
| 9 | * @date 2021-10-22 | 11 | * @date 2021-10-22 |
| 10 | */ | 12 | */ |
| 11 | public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> { | 13 | public interface MemberAddressRepository extends JpaRepository<MemberAddress, Long>, JpaSpecificationExecutor<MemberAddress> { |
| 12 | 14 | ||
| 15 | Optional<MemberAddress> findByMemberIdAndSequence(Long memberId, Integer sequence); | ||
| 13 | } | 16 | } | ... | ... |
| ... | @@ -6,6 +6,8 @@ import com.topdraw.business.basicdata.member.address.service.MemberAddressServic | ... | @@ -6,6 +6,8 @@ import com.topdraw.business.basicdata.member.address.service.MemberAddressServic |
| 6 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO; | 6 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressDTO; |
| 7 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria; | 7 | import com.topdraw.business.basicdata.member.address.service.dto.MemberAddressQueryCriteria; |
| 8 | import com.topdraw.business.basicdata.member.address.service.mapper.MemberAddressMapper; | 8 | import com.topdraw.business.basicdata.member.address.service.mapper.MemberAddressMapper; |
| 9 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 10 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 9 | import com.topdraw.utils.PageUtil; | 11 | import com.topdraw.utils.PageUtil; |
| 10 | import com.topdraw.utils.QueryHelp; | 12 | import com.topdraw.utils.QueryHelp; |
| 11 | import com.topdraw.utils.ValidationUtil; | 13 | import com.topdraw.utils.ValidationUtil; |
| ... | @@ -20,6 +22,8 @@ import org.springframework.util.Assert; | ... | @@ -20,6 +22,8 @@ import org.springframework.util.Assert; |
| 20 | 22 | ||
| 21 | import java.util.List; | 23 | import java.util.List; |
| 22 | import java.util.Map; | 24 | import java.util.Map; |
| 25 | import java.util.Objects; | ||
| 26 | import java.util.Optional; | ||
| 23 | 27 | ||
| 24 | /** | 28 | /** |
| 25 | * @author XiangHan | 29 | * @author XiangHan |
| ... | @@ -34,6 +38,8 @@ public class MemberAddressServiceImpl implements MemberAddressService { | ... | @@ -34,6 +38,8 @@ public class MemberAddressServiceImpl implements MemberAddressService { |
| 34 | 38 | ||
| 35 | @Autowired | 39 | @Autowired |
| 36 | private MemberAddressMapper MemberAddressMapper; | 40 | private MemberAddressMapper MemberAddressMapper; |
| 41 | @Autowired | ||
| 42 | private MemberService memberService; | ||
| 37 | 43 | ||
| 38 | @Override | 44 | @Override |
| 39 | public Map<String, Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable) { | 45 | public Map<String, Object> queryAll(MemberAddressQueryCriteria criteria, Pageable pageable) { |
| ... | @@ -56,16 +62,28 @@ public class MemberAddressServiceImpl implements MemberAddressService { | ... | @@ -56,16 +62,28 @@ public class MemberAddressServiceImpl implements MemberAddressService { |
| 56 | @Override | 62 | @Override |
| 57 | @Transactional(rollbackFor = Exception.class) | 63 | @Transactional(rollbackFor = Exception.class) |
| 58 | public void create(MemberAddress resources) { | 64 | public void create(MemberAddress resources) { |
| 65 | String memberCode = resources.getMemberCode(); | ||
| 59 | MemberAddressRepository.save(resources); | 66 | MemberAddressRepository.save(resources); |
| 60 | } | 67 | } |
| 61 | 68 | ||
| 62 | @Override | 69 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 70 | @Transactional(rollbackFor = Exception.class) |
| 64 | public void update(MemberAddress resources) { | 71 | public void update(MemberAddress resources) { |
| 65 | MemberAddress MemberAddress = MemberAddressRepository.findById(resources.getId()).orElseGet(MemberAddress::new); | 72 | String memberCode = resources.getMemberCode(); |
| 66 | ValidationUtil.isNull( MemberAddress.getId(),"MemberAddress","id",resources.getId()); | 73 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); |
| 67 | MemberAddress.copy(resources); | 74 | if (Objects.nonNull(memberDTO)) { |
| 68 | MemberAddressRepository.save(MemberAddress); | 75 | Long memberId = memberDTO.getId(); |
| 76 | Integer sequence = resources.getSequence(); | ||
| 77 | Assert.notNull(sequence,"sequence can't be null!"); | ||
| 78 | Optional<MemberAddress> memberAddressOptional = MemberAddressRepository.findByMemberIdAndSequence(memberId,sequence); | ||
| 79 | if (memberAddressOptional.isPresent()) { | ||
| 80 | MemberAddress memberAddress = memberAddressOptional.get(); | ||
| 81 | ValidationUtil.isNull(memberAddress.getId(),"MemberAddress","id",resources.getId()); | ||
| 82 | resources.setId(memberAddress.getId()); | ||
| 83 | memberAddress.copy(resources); | ||
| 84 | MemberAddressRepository.save(memberAddress); | ||
| 85 | } | ||
| 86 | } | ||
| 69 | } | 87 | } |
| 70 | 88 | ||
| 71 | @Override | 89 | @Override | ... | ... |
| ... | @@ -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 |
| ... | @@ -23,6 +24,14 @@ import java.sql.Timestamp; | ... | @@ -23,6 +24,14 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_member") | 24 | @Table(name="uc_member") |
| 24 | public class Member implements Serializable { | 25 | public class Member implements Serializable { |
| 25 | 26 | ||
| 27 | // 运营商平台账号 | ||
| 28 | @Transient | ||
| 29 | private String platformAccount; | ||
| 30 | |||
| 31 | // 会员过期时间 | ||
| 32 | @Column(name = "vip_expire_time", nullable = false) | ||
| 33 | private LocalDateTime vipExpireTime; | ||
| 34 | |||
| 26 | // 主键 | 35 | // 主键 |
| 27 | @Id | 36 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 37 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| ... | @@ -83,7 +92,7 @@ public class Member implements Serializable { | ... | @@ -83,7 +92,7 @@ public class Member implements Serializable { |
| 83 | 92 | ||
| 84 | // 当前积分 | 93 | // 当前积分 |
| 85 | @Column(name = "`points`") | 94 | @Column(name = "`points`") |
| 86 | private Integer points; | 95 | private Long points; |
| 87 | 96 | ||
| 88 | // 即将到期积分(一个月内) | 97 | // 即将到期积分(一个月内) |
| 89 | @Column(name = "due_points") | 98 | @Column(name = "due_points") |
| ... | @@ -91,11 +100,11 @@ public class Member implements Serializable { | ... | @@ -91,11 +100,11 @@ public class Member implements Serializable { |
| 91 | 100 | ||
| 92 | // 优惠券数量 | 101 | // 优惠券数量 |
| 93 | @Column(name = "coupon_amount") | 102 | @Column(name = "coupon_amount") |
| 94 | private Integer couponAmount; | 103 | private Long couponAmount; |
| 95 | 104 | ||
| 96 | // 即将过期优惠券数量 | 105 | // 即将过期优惠券数量 |
| 97 | @Column(name = "due_coupon_amount") | 106 | @Column(name = "due_coupon_amount") |
| 98 | private Integer dueCouponAmount; | 107 | private Long dueCouponAmount; |
| 99 | 108 | ||
| 100 | // iptv账号id | 109 | // iptv账号id |
| 101 | @Column(name = "user_iptv_id") | 110 | @Column(name = "user_iptv_id") |
| ... | @@ -120,8 +129,8 @@ public class Member implements Serializable { | ... | @@ -120,8 +129,8 @@ public class Member implements Serializable { |
| 120 | private Timestamp updateTime; | 129 | private Timestamp updateTime; |
| 121 | 130 | ||
| 122 | // 是否在黑名单 1:是;0否 | 131 | // 是否在黑名单 1:是;0否 |
| 123 | // @Column(name = "black_status") | 132 | @Column(name = "black_status") |
| 124 | // private Integer blackStatus; | 133 | private Long blackStatus; |
| 125 | 134 | ||
| 126 | public void copy(Member source){ | 135 | public void copy(Member source){ |
| 127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 136 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ... | ... |
| ... | @@ -37,6 +37,9 @@ public class MemberProfile implements Serializable { | ... | @@ -37,6 +37,9 @@ public class MemberProfile implements Serializable { |
| 37 | @Column(name = "member_id", nullable = false) | 37 | @Column(name = "member_id", nullable = false) |
| 38 | private Long memberId; | 38 | private Long memberId; |
| 39 | 39 | ||
| 40 | @Transient | ||
| 41 | private String memberCode; | ||
| 42 | |||
| 40 | // 姓名 | 43 | // 姓名 |
| 41 | @Column(name = "realname") | 44 | @Column(name = "realname") |
| 42 | private String realname; | 45 | private String realname; | ... | ... |
| ... | @@ -10,4 +10,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ... | @@ -10,4 +10,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 10 | */ | 10 | */ |
| 11 | public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> { | 11 | public interface MemberProfileRepository extends JpaRepository<MemberProfile, Long>, JpaSpecificationExecutor<MemberProfile> { |
| 12 | 12 | ||
| 13 | MemberProfile findByMemberId(Long memberId); | ||
| 13 | } | 14 | } | ... | ... |
| ... | @@ -6,8 +6,11 @@ import com.topdraw.business.basicdata.member.profile.service.MemberProfileServic | ... | @@ -6,8 +6,11 @@ import com.topdraw.business.basicdata.member.profile.service.MemberProfileServic |
| 6 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO; | 6 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileDTO; |
| 7 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria; | 7 | import com.topdraw.business.basicdata.member.profile.service.dto.MemberProfileQueryCriteria; |
| 8 | import com.topdraw.business.basicdata.member.profile.service.mapper.MemberProfileMapper; | 8 | import com.topdraw.business.basicdata.member.profile.service.mapper.MemberProfileMapper; |
| 9 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 10 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 9 | import com.topdraw.utils.PageUtil; | 11 | import com.topdraw.utils.PageUtil; |
| 10 | import com.topdraw.utils.QueryHelp; | 12 | import com.topdraw.utils.QueryHelp; |
| 13 | import com.topdraw.utils.StringUtils; | ||
| 11 | import com.topdraw.utils.ValidationUtil; | 14 | import com.topdraw.utils.ValidationUtil; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | 16 | import org.springframework.dao.EmptyResultDataAccessException; |
| ... | @@ -20,6 +23,7 @@ import org.springframework.util.Assert; | ... | @@ -20,6 +23,7 @@ import org.springframework.util.Assert; |
| 20 | 23 | ||
| 21 | import java.util.List; | 24 | import java.util.List; |
| 22 | import java.util.Map; | 25 | import java.util.Map; |
| 26 | import java.util.Objects; | ||
| 23 | 27 | ||
| 24 | /** | 28 | /** |
| 25 | * @author XiangHan | 29 | * @author XiangHan |
| ... | @@ -34,6 +38,8 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -34,6 +38,8 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
| 34 | 38 | ||
| 35 | @Autowired | 39 | @Autowired |
| 36 | private MemberProfileMapper MemberProfileMapper; | 40 | private MemberProfileMapper MemberProfileMapper; |
| 41 | @Autowired | ||
| 42 | private MemberService memberService; | ||
| 37 | 43 | ||
| 38 | @Override | 44 | @Override |
| 39 | public Map<String, Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable) { | 45 | public Map<String, Object> queryAll(MemberProfileQueryCriteria criteria, Pageable pageable) { |
| ... | @@ -56,16 +62,38 @@ public class MemberProfileServiceImpl implements MemberProfileService { | ... | @@ -56,16 +62,38 @@ public class MemberProfileServiceImpl implements MemberProfileService { |
| 56 | @Override | 62 | @Override |
| 57 | @Transactional(rollbackFor = Exception.class) | 63 | @Transactional(rollbackFor = Exception.class) |
| 58 | public void create(MemberProfile resources) { | 64 | public void create(MemberProfile resources) { |
| 59 | MemberProfileRepository.save(resources); | 65 | String memberCode = resources.getMemberCode(); |
| 66 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 67 | if (Objects.nonNull(memberDTO)) { | ||
| 68 | String code = memberDTO.getCode(); | ||
| 69 | if (StringUtils.isNotEmpty(code)) { | ||
| 70 | resources.setMemberCode(code); | ||
| 71 | resources.setMemberId(memberDTO.getId()); | ||
| 72 | resources.setId(null); | ||
| 73 | MemberProfileRepository.save(resources); | ||
| 74 | } | ||
| 75 | } | ||
| 60 | } | 76 | } |
| 61 | 77 | ||
| 62 | @Override | 78 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 79 | @Transactional(rollbackFor = Exception.class) |
| 64 | public void update(MemberProfile resources) { | 80 | public void update(MemberProfile resources) { |
| 65 | MemberProfile MemberProfile = MemberProfileRepository.findById(resources.getId()).orElseGet(MemberProfile::new); | 81 | |
| 66 | ValidationUtil.isNull( MemberProfile.getId(),"MemberProfile","id",resources.getId()); | 82 | String memberCode = resources.getMemberCode(); |
| 67 | MemberProfile.copy(resources); | 83 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); |
| 68 | MemberProfileRepository.save(MemberProfile); | 84 | if (Objects.nonNull(memberDTO)) { |
| 85 | Long memberId = memberDTO.getId(); | ||
| 86 | |||
| 87 | MemberProfile memberProfile = MemberProfileRepository.findByMemberId(memberId); | ||
| 88 | if (Objects.nonNull(memberProfile)) { | ||
| 89 | ValidationUtil.isNull( memberProfile.getId(),"MemberProfile","id",memberProfile.getId()); | ||
| 90 | resources.setId(memberProfile.getId()); | ||
| 91 | } else { | ||
| 92 | resources.setId(null); | ||
| 93 | } | ||
| 94 | memberProfile.copy(resources); | ||
| 95 | MemberProfileRepository.save(memberProfile); | ||
| 96 | } | ||
| 69 | } | 97 | } |
| 70 | 98 | ||
| 71 | @Override | 99 | @Override | ... | ... |
| ... | @@ -33,6 +33,9 @@ public class MemberRelatedInfo implements Serializable { | ... | @@ -33,6 +33,9 @@ public class MemberRelatedInfo implements Serializable { |
| 33 | @Column(name = "member_id", nullable = false) | 33 | @Column(name = "member_id", nullable = false) |
| 34 | private Long memberId; | 34 | private Long memberId; |
| 35 | 35 | ||
| 36 | @Transient | ||
| 37 | private String memberCode; | ||
| 38 | |||
| 36 | // 人物关系 0:子女;1:父母 | 39 | // 人物关系 0:子女;1:父母 |
| 37 | @Column(name = "type") | 40 | @Column(name = "type") |
| 38 | private Integer type; | 41 | private Integer type; | ... | ... |
| 1 | package com.topdraw.business.basicdata.member.relatedinfo.repository; | 1 | package com.topdraw.business.basicdata.member.relatedinfo.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; | 3 | import com.topdraw.business.basicdata.member.relatedinfo.domain.MemberRelatedInfo; |
| 4 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | ||
| 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 | import java.util.Optional; | ||
| 10 | |||
| 7 | /** | 11 | /** |
| 8 | * @author XiangHan | 12 | * @author XiangHan |
| 9 | * @date 2021-10-22 | 13 | * @date 2021-10-22 |
| 10 | */ | 14 | */ |
| 11 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { | 15 | public interface MemberRelatedInfoRepository extends JpaRepository<MemberRelatedInfo, Long>, JpaSpecificationExecutor<MemberRelatedInfo> { |
| 12 | 16 | ||
| 17 | List<MemberRelatedInfo> findByMemberIdAndIdCard(Long memberDTOId,String idCard); | ||
| 13 | } | 18 | } | ... | ... |
| ... | @@ -6,6 +6,8 @@ import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedIn | ... | @@ -6,6 +6,8 @@ import com.topdraw.business.basicdata.member.relatedinfo.service.MemberRelatedIn |
| 6 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; | 6 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoDTO; |
| 7 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; | 7 | import com.topdraw.business.basicdata.member.relatedinfo.service.dto.MemberRelatedInfoQueryCriteria; |
| 8 | import com.topdraw.business.basicdata.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; | 8 | import com.topdraw.business.basicdata.member.relatedinfo.service.mapper.MemberRelatedInfoMapper; |
| 9 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 10 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 9 | import com.topdraw.utils.PageUtil; | 11 | import com.topdraw.utils.PageUtil; |
| 10 | import com.topdraw.utils.QueryHelp; | 12 | import com.topdraw.utils.QueryHelp; |
| 11 | import com.topdraw.utils.ValidationUtil; | 13 | import com.topdraw.utils.ValidationUtil; |
| ... | @@ -17,9 +19,12 @@ import org.springframework.stereotype.Service; | ... | @@ -17,9 +19,12 @@ import org.springframework.stereotype.Service; |
| 17 | import org.springframework.transaction.annotation.Propagation; | 19 | import org.springframework.transaction.annotation.Propagation; |
| 18 | import org.springframework.transaction.annotation.Transactional; | 20 | import org.springframework.transaction.annotation.Transactional; |
| 19 | import org.springframework.util.Assert; | 21 | import org.springframework.util.Assert; |
| 22 | import org.springframework.util.CollectionUtils; | ||
| 20 | 23 | ||
| 21 | import java.util.List; | 24 | import java.util.List; |
| 22 | import java.util.Map; | 25 | import java.util.Map; |
| 26 | import java.util.Objects; | ||
| 27 | import java.util.Optional; | ||
| 23 | 28 | ||
| 24 | /** | 29 | /** |
| 25 | * @author XiangHan | 30 | * @author XiangHan |
| ... | @@ -34,6 +39,8 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | ... | @@ -34,6 +39,8 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { |
| 34 | 39 | ||
| 35 | @Autowired | 40 | @Autowired |
| 36 | private MemberRelatedInfoMapper MemberRelatedInfoMapper; | 41 | private MemberRelatedInfoMapper MemberRelatedInfoMapper; |
| 42 | @Autowired | ||
| 43 | private MemberService memberService; | ||
| 37 | 44 | ||
| 38 | @Override | 45 | @Override |
| 39 | public Map<String, Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable) { | 46 | public Map<String, Object> queryAll(MemberRelatedInfoQueryCriteria criteria, Pageable pageable) { |
| ... | @@ -62,10 +69,24 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { | ... | @@ -62,10 +69,24 @@ public class MemberRelatedInfoServiceImpl implements MemberRelatedInfoService { |
| 62 | @Override | 69 | @Override |
| 63 | @Transactional(rollbackFor = Exception.class) | 70 | @Transactional(rollbackFor = Exception.class) |
| 64 | public void update(MemberRelatedInfo resources) { | 71 | public void update(MemberRelatedInfo resources) { |
| 65 | MemberRelatedInfo MemberRelatedInfo = MemberRelatedInfoRepository.findById(resources.getId()).orElseGet(MemberRelatedInfo::new); | 72 | |
| 66 | ValidationUtil.isNull( MemberRelatedInfo.getId(),"MemberRelatedInfo","id",resources.getId()); | 73 | String memberCode = resources.getMemberCode(); |
| 67 | MemberRelatedInfo.copy(resources); | 74 | Assert.notNull(memberCode,"memberCode can't be null!"); |
| 68 | MemberRelatedInfoRepository.save(MemberRelatedInfo); | 75 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); |
| 76 | if (Objects.nonNull(memberDTO)) { | ||
| 77 | Long memberDTOId = memberDTO.getId(); | ||
| 78 | String idCard = resources.getIdCard(); | ||
| 79 | List<MemberRelatedInfo> memberRelatedInfoDTOS = MemberRelatedInfoRepository.findByMemberIdAndIdCard(memberDTOId,idCard); | ||
| 80 | if (!CollectionUtils.isEmpty(memberRelatedInfoDTOS)) { | ||
| 81 | for (MemberRelatedInfo memberRelatedInfoDTO : memberRelatedInfoDTOS) { | ||
| 82 | ValidationUtil.isNull( memberRelatedInfoDTO.getId(),"MemberRelatedInfo","id",memberRelatedInfoDTO.getId()); | ||
| 83 | resources.setId(memberRelatedInfoDTO.getId()); | ||
| 84 | resources.setMemberId(memberDTOId); | ||
| 85 | memberRelatedInfoDTO.copy(resources); | ||
| 86 | MemberRelatedInfoRepository.save(memberRelatedInfoDTO); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 69 | } | 90 | } |
| 70 | 91 | ||
| 71 | @Override | 92 | @Override | ... | ... |
| ... | @@ -3,6 +3,8 @@ package com.topdraw.business.basicdata.member.repository; | ... | @@ -3,6 +3,8 @@ package com.topdraw.business.basicdata.member.repository; |
| 3 | import com.topdraw.business.basicdata.member.domain.Member; | 3 | import com.topdraw.business.basicdata.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; | ||
| 6 | 8 | ||
| 7 | import java.util.Optional; | 9 | import java.util.Optional; |
| 8 | 10 | ||
| ... | @@ -13,4 +15,11 @@ import java.util.Optional; | ... | @@ -13,4 +15,11 @@ import java.util.Optional; |
| 13 | public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecificationExecutor<Member> { | 15 | public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecificationExecutor<Member> { |
| 14 | 16 | ||
| 15 | Optional<Member> findFirstByCode(String code); | 17 | Optional<Member> findFirstByCode(String code); |
| 18 | |||
| 19 | Optional<Member> findByCode(String code); | ||
| 20 | |||
| 21 | |||
| 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); | ||
| 16 | } | 25 | } | ... | ... |
| ... | @@ -3,6 +3,7 @@ package com.topdraw.business.basicdata.member.service; | ... | @@ -3,6 +3,7 @@ package com.topdraw.business.basicdata.member.service; |
| 3 | import com.topdraw.business.basicdata.member.domain.Member; | 3 | import com.topdraw.business.basicdata.member.domain.Member; |
| 4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | 4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; |
| 5 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; | 5 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; |
| 6 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 6 | import org.springframework.data.domain.Pageable; | 7 | import org.springframework.data.domain.Pageable; |
| 7 | 8 | ||
| 8 | import java.util.List; | 9 | import java.util.List; |
| ... | @@ -36,7 +37,7 @@ public interface MemberService { | ... | @@ -36,7 +37,7 @@ public interface MemberService { |
| 36 | */ | 37 | */ |
| 37 | MemberDTO findById(Long id); | 38 | MemberDTO findById(Long id); |
| 38 | 39 | ||
| 39 | void create(Member resources); | 40 | Long create(Member resources); |
| 40 | 41 | ||
| 41 | void update(Member resources); | 42 | void update(Member resources); |
| 42 | 43 | ||
| ... | @@ -48,4 +49,8 @@ public interface MemberService { | ... | @@ -48,4 +49,8 @@ public interface MemberService { |
| 48 | * @return MemberDTO | 49 | * @return MemberDTO |
| 49 | */ | 50 | */ |
| 50 | MemberDTO getByCode(String code); | 51 | MemberDTO getByCode(String code); |
| 52 | |||
| 53 | boolean createMemberByUserTv(UserTv resources); | ||
| 54 | |||
| 55 | void doUpdateMemberPoints(Member member); | ||
| 51 | } | 56 | } | ... | ... |
| ... | @@ -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 | /** |
| ... | @@ -13,6 +14,9 @@ import java.sql.Timestamp; | ... | @@ -13,6 +14,9 @@ import java.sql.Timestamp; |
| 13 | @Data | 14 | @Data |
| 14 | public class MemberDTO implements Serializable { | 15 | public class MemberDTO implements Serializable { |
| 15 | 16 | ||
| 17 | // 会员过期时间 | ||
| 18 | private LocalDateTime vipExpireTime; | ||
| 19 | |||
| 16 | // 主键 | 20 | // 主键 |
| 17 | private Long id; | 21 | private Long id; |
| 18 | 22 | ||
| ... | @@ -62,10 +66,10 @@ public class MemberDTO implements Serializable { | ... | @@ -62,10 +66,10 @@ public class MemberDTO implements Serializable { |
| 62 | private Long duePoints; | 66 | private Long duePoints; |
| 63 | 67 | ||
| 64 | // 优惠券数量 | 68 | // 优惠券数量 |
| 65 | private Integer couponAmount; | 69 | private Long couponAmount; |
| 66 | 70 | ||
| 67 | // 即将过期优惠券数量 | 71 | // 即将过期优惠券数量 |
| 68 | private Integer dueCouponAmount; | 72 | private Long dueCouponAmount; |
| 69 | 73 | ||
| 70 | // iptv账号id | 74 | // iptv账号id |
| 71 | private Long userIptvId; | 75 | private Long userIptvId; | ... | ... |
| ... | @@ -6,11 +6,21 @@ import com.topdraw.business.basicdata.member.service.MemberService; | ... | @@ -6,11 +6,21 @@ import com.topdraw.business.basicdata.member.service.MemberService; |
| 6 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | 6 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; |
| 7 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; | 7 | import com.topdraw.business.basicdata.member.service.dto.MemberQueryCriteria; |
| 8 | import com.topdraw.business.basicdata.member.service.mapper.MemberMapper; | 8 | import com.topdraw.business.basicdata.member.service.mapper.MemberMapper; |
| 9 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 10 | import com.topdraw.business.basicdata.user.iptv.service.UserTvService; | ||
| 11 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvDTO; | ||
| 12 | import com.topdraw.config.LocalConstants; | ||
| 9 | import com.topdraw.util.IdWorker; | 13 | import com.topdraw.util.IdWorker; |
| 14 | import com.topdraw.util.RedissonUtil; | ||
| 15 | import com.topdraw.util.TimestampUtil; | ||
| 10 | import com.topdraw.utils.PageUtil; | 16 | import com.topdraw.utils.PageUtil; |
| 11 | import com.topdraw.utils.QueryHelp; | 17 | import com.topdraw.utils.QueryHelp; |
| 12 | import com.topdraw.utils.StringUtils; | 18 | import com.topdraw.utils.StringUtils; |
| 13 | import com.topdraw.utils.ValidationUtil; | 19 | import com.topdraw.utils.ValidationUtil; |
| 20 | import lombok.extern.slf4j.Slf4j; | ||
| 21 | import org.redisson.api.RLock; | ||
| 22 | import org.redisson.api.RedissonClient; | ||
| 23 | import org.springframework.beans.BeanUtils; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.dao.EmptyResultDataAccessException; | 25 | import org.springframework.dao.EmptyResultDataAccessException; |
| 16 | import org.springframework.data.domain.Page; | 26 | import org.springframework.data.domain.Page; |
| ... | @@ -22,11 +32,13 @@ import org.springframework.util.Assert; | ... | @@ -22,11 +32,13 @@ import org.springframework.util.Assert; |
| 22 | 32 | ||
| 23 | import java.util.List; | 33 | import java.util.List; |
| 24 | import java.util.Map; | 34 | import java.util.Map; |
| 35 | import java.util.Objects; | ||
| 25 | 36 | ||
| 26 | /** | 37 | /** |
| 27 | * @author XiangHan | 38 | * @author XiangHan |
| 28 | * @date 2021-10-22 | 39 | * @date 2021-10-22 |
| 29 | */ | 40 | */ |
| 41 | @Slf4j | ||
| 30 | @Service | 42 | @Service |
| 31 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 43 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 32 | public class MemberServiceImpl implements MemberService { | 44 | public class MemberServiceImpl implements MemberService { |
| ... | @@ -37,6 +49,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -37,6 +49,12 @@ public class MemberServiceImpl implements MemberService { |
| 37 | @Autowired | 49 | @Autowired |
| 38 | private MemberMapper memberMapper; | 50 | private MemberMapper memberMapper; |
| 39 | 51 | ||
| 52 | @Autowired | ||
| 53 | private com.topdraw.business.basicdata.user.iptv.service.UserTvService UserTvService; | ||
| 54 | |||
| 55 | @Autowired | ||
| 56 | private RedissonClient redissonClient; | ||
| 57 | |||
| 40 | @Override | 58 | @Override |
| 41 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { | 59 | public Map<String, Object> queryAll(MemberQueryCriteria criteria, Pageable pageable) { |
| 42 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) | 60 | Page<Member> page = memberRepository.findAll((root, criteriaQuery, criteriaBuilder) |
| ... | @@ -58,42 +76,85 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -58,42 +76,85 @@ public class MemberServiceImpl implements MemberService { |
| 58 | 76 | ||
| 59 | @Override | 77 | @Override |
| 60 | @Transactional(rollbackFor = Exception.class) | 78 | @Transactional(rollbackFor = Exception.class) |
| 61 | public void create(Member resources) { | 79 | public Long create(Member resources) { |
| 62 | Member member = this.checkMemberData(resources); | 80 | Member member = this.checkMemberData(resources); |
| 63 | memberRepository.save(member); | 81 | memberRepository.save(member); |
| 82 | return resources.getId(); | ||
| 64 | } | 83 | } |
| 65 | 84 | ||
| 66 | private Member checkMemberData(Member member) { | 85 | private Member checkMemberData(Member member) { |
| 67 | member.setCode(String.valueOf(IdWorker.generator())); | 86 | Long defaultValue = 0L; |
| 68 | member.setGender(0); | 87 | String code = member.getCode(); |
| 69 | member.setType(-1); | 88 | member.setCode(StringUtils.isEmpty(code)?String.valueOf(IdWorker.generator()):code); |
| 70 | member.setStatus(1); | 89 | Integer gender = member.getGender(); |
| 71 | member.setVip(0); | 90 | member.setGender(Objects.nonNull(gender) ? gender : 0); |
| 72 | member.setLevel(0); | 91 | Integer type = member.getType(); |
| 73 | member.setExp(0L); | 92 | member.setType(Objects.nonNull(type) ? type:-1); |
| 74 | member.setPoints(0); | 93 | Integer status = member.getStatus(); |
| 75 | member.setDuePoints(0L); | 94 | member.setStatus(Objects.nonNull(status) ? status:1); |
| 76 | member.setCouponAmount(0); | 95 | Integer vip = member.getVip(); |
| 77 | member.setDueCouponAmount(0); | 96 | member.setVip(Objects.nonNull(vip) ? vip:0); |
| 97 | Integer level = member.getLevel(); | ||
| 98 | member.setLevel(Objects.nonNull(level) ? level:0); | ||
| 99 | member.setExp(defaultValue); | ||
| 100 | member.setPoints(defaultValue); | ||
| 101 | member.setDuePoints(defaultValue); | ||
| 102 | member.setCouponAmount(defaultValue); | ||
| 103 | member.setDueCouponAmount(defaultValue); | ||
| 104 | member.setBlackStatus(0L); | ||
| 78 | return member; | 105 | return member; |
| 79 | } | 106 | } |
| 80 | 107 | ||
| 108 | |||
| 109 | |||
| 81 | @Override | 110 | @Override |
| 82 | @Transactional(rollbackFor = Exception.class) | 111 | @Transactional(rollbackFor = Exception.class) |
| 83 | public void update(Member resources) { | 112 | public void update(Member resources) { |
| 84 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); | 113 | RLock rLock = this.redissonClient.getLock("Member::update::code" + resources.getCode()); |
| 85 | ValidationUtil.isNull( member.getId(),"Member","id",resources.getId()); | 114 | try { |
| 86 | member.copy(resources); | 115 | RedissonUtil.lock(rLock); |
| 87 | memberRepository.save(member); | 116 | Member member = memberRepository.findByCode(resources.getCode()).orElseGet(Member::new); |
| 117 | ValidationUtil.isNull( member.getId(),"Member","id",member.getId()); | ||
| 118 | if (Objects.nonNull(member)) { | ||
| 119 | Long id = member.getId(); | ||
| 120 | resources.setId(id); | ||
| 121 | |||
| 122 | String platformAccount = resources.getPlatformAccount(); | ||
| 123 | if (StringUtils.isNotEmpty(platformAccount)) { | ||
| 124 | UserTvDTO userTvDTO = this.UserTvService.findByPlatformAccount(platformAccount); | ||
| 125 | if (Objects.nonNull(userTvDTO)) { | ||
| 126 | Long userIptvId = userTvDTO.getId(); | ||
| 127 | resources.setUserIptvId(userIptvId); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | member.copy(resources); | ||
| 133 | memberRepository.save(member); | ||
| 134 | } catch (Exception e) { | ||
| 135 | e.printStackTrace(); | ||
| 136 | throw e; | ||
| 137 | } finally { | ||
| 138 | RedissonUtil.unlock(rLock); | ||
| 139 | } | ||
| 88 | } | 140 | } |
| 89 | 141 | ||
| 90 | @Override | 142 | @Override |
| 91 | @Transactional(rollbackFor = Exception.class) | 143 | @Transactional(rollbackFor = Exception.class) |
| 92 | public void delete(Long id) { | 144 | public void delete(Long id) { |
| 93 | Assert.notNull(id, "The given id must not be null!"); | 145 | Assert.notNull(id, "The given id must not be null!"); |
| 94 | Member member = memberRepository.findById(id).orElseThrow( | 146 | RLock rLock = this.redissonClient.getLock("Member::delete::code" + id); |
| 95 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Member.class, id), 1)); | 147 | try { |
| 96 | memberRepository.delete(member); | 148 | RedissonUtil.lock(rLock); |
| 149 | Member member = memberRepository.findById(id).orElseThrow( | ||
| 150 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", Member.class, id), 1)); | ||
| 151 | memberRepository.delete(member); | ||
| 152 | } catch (Exception e) { | ||
| 153 | e.printStackTrace(); | ||
| 154 | throw e; | ||
| 155 | } finally { | ||
| 156 | RedissonUtil.unlock(rLock); | ||
| 157 | } | ||
| 97 | } | 158 | } |
| 98 | 159 | ||
| 99 | 160 | ||
| ... | @@ -102,4 +163,79 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -102,4 +163,79 @@ public class MemberServiceImpl implements MemberService { |
| 102 | return StringUtils.isNotEmpty(code) ? memberMapper.toDto(memberRepository.findFirstByCode(code).orElseGet(Member::new)) | 163 | return StringUtils.isNotEmpty(code) ? memberMapper.toDto(memberRepository.findFirstByCode(code).orElseGet(Member::new)) |
| 103 | : new MemberDTO(); | 164 | : new MemberDTO(); |
| 104 | } | 165 | } |
| 166 | |||
| 167 | @Override | ||
| 168 | @Transactional(rollbackFor = Exception.class) | ||
| 169 | public boolean createMemberByUserTv(UserTv resources) { | ||
| 170 | String platformAccount = resources.getPlatformAccount(); | ||
| 171 | UserTvDTO userTvDTO = this.UserTvService.findByPlatformAccount(platformAccount); | ||
| 172 | if (Objects.isNull(userTvDTO)) { | ||
| 173 | Member member = new Member(); | ||
| 174 | // 大屏 | ||
| 175 | member.setType(LocalConstants.MEMBER_PLATFORM_TYPE_VIS); | ||
| 176 | Member member12 = this.checkMemberData(member); | ||
| 177 | Long memberId = this.create(member12); | ||
| 178 | |||
| 179 | if (Objects.nonNull(memberId)) { | ||
| 180 | UserTv userTv = new UserTv(); | ||
| 181 | BeanUtils.copyProperties(resources,userTv); | ||
| 182 | userTv.setPlatformAccount(platformAccount); | ||
| 183 | userTv.setMemberCode(member12.getCode()); | ||
| 184 | Long userIptvId = UserTvService.create(userTv); | ||
| 185 | |||
| 186 | if (Objects.nonNull(userIptvId)) { | ||
| 187 | member.setId(memberId); | ||
| 188 | member.setUserIptvId(userIptvId); | ||
| 189 | member.setBindIptvTime(TimestampUtil.now()); | ||
| 190 | this.bindIptvId(member); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | } else { | ||
| 195 | return false; | ||
| 196 | } | ||
| 197 | |||
| 198 | return true; | ||
| 199 | } | ||
| 200 | |||
| 201 | @Override | ||
| 202 | @Transactional(rollbackFor = Exception.class) | ||
| 203 | public void doUpdateMemberPoints(Member member) { | ||
| 204 | RLock rLock = this.redissonClient.getLock("Member::update::code::" + member.getCode()); | ||
| 205 | try { | ||
| 206 | RedissonUtil.lock(rLock); | ||
| 207 | Long id = member.getId(); | ||
| 208 | Long points = member.getPoints(); | ||
| 209 | Long duePoints = member.getDuePoints(); | ||
| 210 | memberRepository.updateMemberPoints(id,points,duePoints); | ||
| 211 | } catch (Exception e) { | ||
| 212 | e.printStackTrace(); | ||
| 213 | throw e; | ||
| 214 | } finally { | ||
| 215 | RedissonUtil.unlock(rLock); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | private void save(Member member){ | ||
| 220 | memberRepository.save(member); | ||
| 221 | } | ||
| 222 | |||
| 223 | |||
| 224 | public void bindIptvId(Member resources) { | ||
| 225 | RLock rLock = this.redissonClient.getLock("Member::update::code::" + resources.getCode()); | ||
| 226 | try { | ||
| 227 | RedissonUtil.lock(rLock); | ||
| 228 | Member member = memberRepository.findFirstByCode(resources.getCode()).orElseGet(Member::new); | ||
| 229 | if (member==null) { | ||
| 230 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); | ||
| 231 | member.copy(resources); | ||
| 232 | } | ||
| 233 | this.save(member); | ||
| 234 | } catch (Exception e) { | ||
| 235 | e.printStackTrace(); | ||
| 236 | throw e; | ||
| 237 | } finally { | ||
| 238 | RedissonUtil.unlock(rLock); | ||
| 239 | } | ||
| 240 | } | ||
| 105 | } | 241 | } | ... | ... |
| ... | @@ -2,7 +2,6 @@ package com.topdraw.business.basicdata.points.available.domain; | ... | @@ -2,7 +2,6 @@ package com.topdraw.business.basicdata.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 lombok.Data; | 5 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
| 8 | import org.springframework.data.annotation.CreatedDate; | 7 | import org.springframework.data.annotation.CreatedDate; |
| ... | @@ -12,8 +11,11 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ... | @@ -12,8 +11,11 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 12 | import javax.persistence.*; | 11 | import javax.persistence.*; |
| 13 | import java.io.Serializable; | 12 | import java.io.Serializable; |
| 14 | import java.sql.Timestamp; | 13 | import java.sql.Timestamp; |
| 14 | import java.time.LocalDateTime; | ||
| 15 | 15 | ||
| 16 | /** | 16 | /** |
| 17 | * 每天定时扫描可用积分表,将过期积分删除,并及时更新积分明细表和积分总额表 | ||
| 18 | * | ||
| 17 | * @author XiangHan | 19 | * @author XiangHan |
| 18 | * @date 2021-10-23 | 20 | * @date 2021-10-23 |
| 19 | */ | 21 | */ |
| ... | @@ -24,6 +26,10 @@ import java.sql.Timestamp; | ... | @@ -24,6 +26,10 @@ import java.sql.Timestamp; |
| 24 | @Table(name="uc_points_available") | 26 | @Table(name="uc_points_available") |
| 25 | public class PointsAvailable implements Serializable { | 27 | public class PointsAvailable implements Serializable { |
| 26 | 28 | ||
| 29 | /** 会员编号 */ | ||
| 30 | @Transient | ||
| 31 | private String memberCode; | ||
| 32 | |||
| 27 | // 主键 | 33 | // 主键 |
| 28 | @Id | 34 | @Id |
| 29 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 35 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| ... | @@ -51,9 +57,9 @@ public class PointsAvailable implements Serializable { | ... | @@ -51,9 +57,9 @@ public class PointsAvailable implements Serializable { |
| 51 | private Long points; | 57 | private Long points; |
| 52 | 58 | ||
| 53 | // 过期时间 | 59 | // 过期时间 |
| 54 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | 60 | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| 55 | @Column(name = "expire_time") | 61 | @Column(name = "expire_time") |
| 56 | private Timestamp expireTime; | 62 | private LocalDateTime expireTime; |
| 57 | 63 | ||
| 58 | // 描述 | 64 | // 描述 |
| 59 | @Column(name = "description") | 65 | @Column(name = "description") | ... | ... |
| ... | @@ -2,9 +2,15 @@ package com.topdraw.business.basicdata.points.available.repository; | ... | @@ -2,9 +2,15 @@ package com.topdraw.business.basicdata.points.available.repository; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | 3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; |
| 4 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | 4 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; |
| 5 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; | ||
| 5 | import org.springframework.data.jpa.repository.JpaRepository; | 6 | import org.springframework.data.jpa.repository.JpaRepository; |
| 6 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 7 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 8 | import org.springframework.data.jpa.repository.Modifying; | ||
| 9 | import org.springframework.data.jpa.repository.Query; | ||
| 10 | import org.springframework.transaction.annotation.Transactional; | ||
| 7 | 11 | ||
| 12 | import java.sql.Timestamp; | ||
| 13 | import java.time.LocalDateTime; | ||
| 8 | import java.util.Date; | 14 | import java.util.Date; |
| 9 | import java.util.List; | 15 | import java.util.List; |
| 10 | import java.util.Optional; | 16 | import java.util.Optional; |
| ... | @@ -19,5 +25,73 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -19,5 +25,73 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
| 19 | 25 | ||
| 20 | List<PointsAvailableDTO> findByMemberId(Long memberId); | 26 | List<PointsAvailableDTO> findByMemberId(Long memberId); |
| 21 | 27 | ||
| 22 | List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , Date now); | 28 | List<PointsAvailable> findByMemberIdAndExpireTimeBefore(Long memberId , LocalDateTime now); |
| 29 | |||
| 30 | /** | ||
| 31 | * 即将过期的积分 | ||
| 32 | * @param memberId | ||
| 33 | * @param factor | ||
| 34 | * @return | ||
| 35 | */ | ||
| 36 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 " + | ||
| 37 | " and (TO_DAYS(expire_time) - TO_DAYS(NOW())) <= ?2 " | ||
| 38 | ,nativeQuery = true) | ||
| 39 | Long findSoonExpireTime(Long memberId, Integer factor); | ||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | /** | ||
| 44 | * 总积分 | ||
| 45 | * @param criteria | ||
| 46 | * @return | ||
| 47 | */ | ||
| 48 | @Deprecated | ||
| 49 | @Query(value = "SELECT sum(upa.points) AS pointsProduce FROM uc_points_available upa WHERE (TO_DAYS(create_time)+1) = TO_DAYS(NOW())" | ||
| 50 | ,nativeQuery = true) | ||
| 51 | Long findEveryDayPointsProduce(PointsAvailableQueryCriteria criteria); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * 可用总积分 | ||
| 55 | * @param criteria | ||
| 56 | * @return | ||
| 57 | */ | ||
| 58 | @Deprecated | ||
| 59 | @Query(value = "SELECT sum(upa.points) AS pointsAvailable FROM uc_points_available upa WHERE (TO_DAYS(create_time)+1) = TO_DAYS(NOW())" | ||
| 60 | ,nativeQuery = true) | ||
| 61 | Long findEveryDayPointsAvailable(PointsAvailableQueryCriteria criteria); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * 过期总积分 | ||
| 65 | * @param criteria | ||
| 66 | * @return | ||
| 67 | */ | ||
| 68 | @Deprecated | ||
| 69 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where (TO_DAYS(create_time)+1) = TO_DAYS(NOW()) " + | ||
| 70 | " and TO_DAYS(expire_time) < TO_DAYS(NOW())" | ||
| 71 | ,nativeQuery = true) | ||
| 72 | Long findEveryDayPointsExpire(PointsAvailableQueryCriteria criteria); | ||
| 73 | |||
| 74 | /** | ||
| 75 | * 获取可用积分 | ||
| 76 | * @param memberId | ||
| 77 | * @return | ||
| 78 | */ | ||
| 79 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and (upa.expire_time > now() or upa.expire_time is null)" | ||
| 80 | ,nativeQuery = true) | ||
| 81 | Long findAvailablePointsByMemberId(long memberId); | ||
| 82 | |||
| 83 | List<PointsAvailable> findByMemberIdOrderByExpireTime(Long memberId); | ||
| 84 | |||
| 85 | @Transactional | ||
| 86 | @Modifying | ||
| 87 | @Query(value = "delete from uc_points_available where id in ?1" ,nativeQuery = true) | ||
| 88 | void deleteBatchByIds(List<Long> id); | ||
| 89 | |||
| 90 | List<PointsAvailable> findByExpireTimeBefore(Timestamp now); | ||
| 91 | |||
| 92 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1" | ||
| 93 | ,nativeQuery = true) | ||
| 94 | long findTotalCountByMemberId(Long memberId); | ||
| 95 | |||
| 96 | List<PointsAvailable> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp); | ||
| 23 | } | 97 | } | ... | ... |
| ... | @@ -5,7 +5,7 @@ import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailab | ... | @@ -5,7 +5,7 @@ import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailab |
| 5 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; | 5 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; |
| 6 | import org.springframework.data.domain.Pageable; | 6 | import org.springframework.data.domain.Pageable; |
| 7 | 7 | ||
| 8 | import java.util.Date; | 8 | import java.time.LocalDateTime; |
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | import java.util.Map; | 10 | import java.util.Map; |
| 11 | 11 | ||
| ... | @@ -55,6 +55,14 @@ public interface PointsAvailableService { | ... | @@ -55,6 +55,14 @@ public interface PointsAvailableService { |
| 55 | */ | 55 | */ |
| 56 | void delete(Long id); | 56 | void delete(Long id); |
| 57 | 57 | ||
| 58 | void delete4Custom(Long id); | ||
| 59 | |||
| 60 | /** | ||
| 61 | * | ||
| 62 | * @param id | ||
| 63 | */ | ||
| 64 | void deleteBatchByIds(List<Long> id); | ||
| 65 | |||
| 58 | /** | 66 | /** |
| 59 | * Code校验 | 67 | * Code校验 |
| 60 | * @param code | 68 | * @param code |
| ... | @@ -63,18 +71,42 @@ public interface PointsAvailableService { | ... | @@ -63,18 +71,42 @@ public interface PointsAvailableService { |
| 63 | PointsAvailableDTO getByCode(String code); | 71 | PointsAvailableDTO getByCode(String code); |
| 64 | 72 | ||
| 65 | /** | 73 | /** |
| 66 | * | 74 | * 已过期的积分 |
| 67 | * @param memberId | 75 | * @param memberId |
| 68 | * @param timestamp | 76 | * @param timestamp |
| 69 | * @return | 77 | * @return |
| 70 | */ | 78 | */ |
| 71 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp); | 79 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime timestamp); |
| 80 | |||
| 81 | /** | ||
| 82 | * 即将过期的积分 | ||
| 83 | * @param memberId 会员id | ||
| 84 | * @param factor 阈值 | ||
| 85 | * @return | ||
| 86 | */ | ||
| 87 | Long findSoonExpireTime(Long memberId,Integer factor); | ||
| 88 | |||
| 89 | /** | ||
| 90 | * | ||
| 91 | * @param memberId | ||
| 92 | * @return | ||
| 93 | */ | ||
| 94 | List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId); | ||
| 95 | |||
| 96 | /** | ||
| 97 | * | ||
| 98 | * @param memberId | ||
| 99 | * @return | ||
| 100 | */ | ||
| 101 | long findAvailablePointsByMemberId(long memberId); | ||
| 72 | 102 | ||
| 73 | /** | 103 | /** |
| 74 | * 查询数据分页 | 104 | * |
| 75 | * @param criteria 条件参数 | 105 | * @param memberId |
| 76 | * @param pageable 分页参数 | 106 | * @return |
| 77 | * @return Map<String,Object> | ||
| 78 | */ | 107 | */ |
| 79 | Map<String,Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable); | 108 | long findTotalPointsByMemberId(Long memberId); |
| 109 | |||
| 110 | void create4Custom(PointsAvailable pointsAvailable); | ||
| 111 | |||
| 80 | } | 112 | } | ... | ... |
| ... | @@ -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 | /** |
| ... | @@ -32,7 +33,7 @@ public class PointsAvailableDTO implements Serializable { | ... | @@ -32,7 +33,7 @@ public class PointsAvailableDTO implements Serializable { |
| 32 | private Long points; | 33 | private Long points; |
| 33 | 34 | ||
| 34 | // 过期时间 | 35 | // 过期时间 |
| 35 | private Timestamp expireTime; | 36 | private LocalDateTime expireTime; |
| 36 | 37 | ||
| 37 | // 描述 | 38 | // 描述 |
| 38 | private String description; | 39 | private String description; | ... | ... |
| 1 | package com.topdraw.business.basicdata.points.available.service.impl; | 1 | package com.topdraw.business.basicdata.points.available.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 3 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | 5 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; |
| 4 | import com.topdraw.business.basicdata.points.available.repository.PointsAvailableRepository; | 6 | import com.topdraw.business.basicdata.points.available.repository.PointsAvailableRepository; |
| 5 | import com.topdraw.business.basicdata.points.available.service.PointsAvailableService; | 7 | import com.topdraw.business.basicdata.points.available.service.PointsAvailableService; |
| 6 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | 8 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; |
| 7 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; | 9 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableQueryCriteria; |
| 8 | import com.topdraw.business.basicdata.points.available.service.mapper.PointsAvailableMapper; | 10 | import com.topdraw.business.basicdata.points.available.service.mapper.PointsAvailableMapper; |
| 11 | import com.topdraw.util.RedissonUtil; | ||
| 9 | import com.topdraw.utils.PageUtil; | 12 | import com.topdraw.utils.PageUtil; |
| 10 | import com.topdraw.utils.QueryHelp; | 13 | import com.topdraw.utils.QueryHelp; |
| 11 | import com.topdraw.utils.StringUtils; | 14 | import com.topdraw.utils.StringUtils; |
| 12 | import com.topdraw.utils.ValidationUtil; | 15 | import com.topdraw.utils.ValidationUtil; |
| 16 | import org.redisson.api.RLock; | ||
| 17 | import org.redisson.api.RedissonClient; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.dao.EmptyResultDataAccessException; | 19 | import org.springframework.dao.EmptyResultDataAccessException; |
| 15 | import org.springframework.data.domain.Page; | 20 | import org.springframework.data.domain.Page; |
| ... | @@ -19,7 +24,7 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -19,7 +24,7 @@ import org.springframework.transaction.annotation.Propagation; |
| 19 | import org.springframework.transaction.annotation.Transactional; | 24 | import org.springframework.transaction.annotation.Transactional; |
| 20 | import org.springframework.util.Assert; | 25 | import org.springframework.util.Assert; |
| 21 | 26 | ||
| 22 | import java.util.Date; | 27 | import java.time.LocalDateTime; |
| 23 | import java.util.List; | 28 | import java.util.List; |
| 24 | import java.util.Map; | 29 | import java.util.Map; |
| 25 | import java.util.Objects; | 30 | import java.util.Objects; |
| ... | @@ -38,6 +43,12 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -38,6 +43,12 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 38 | @Autowired | 43 | @Autowired |
| 39 | private PointsAvailableMapper PointsAvailableMapper; | 44 | private PointsAvailableMapper PointsAvailableMapper; |
| 40 | 45 | ||
| 46 | @Autowired | ||
| 47 | private RedissonClient redissonClient; | ||
| 48 | |||
| 49 | @Autowired | ||
| 50 | private MemberService memberService; | ||
| 51 | |||
| 41 | @Override | 52 | @Override |
| 42 | public Map<String, Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable) { | 53 | public Map<String, Object> queryAll(PointsAvailableQueryCriteria criteria, Pageable pageable) { |
| 43 | Page<PointsAvailable> page = PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> | 54 | Page<PointsAvailable> page = PointsAvailableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> |
| ... | @@ -46,8 +57,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -46,8 +57,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 46 | } | 57 | } |
| 47 | 58 | ||
| 48 | @Override | 59 | @Override |
| 49 | public Map<String, Object> findByMemberIdAndExpireTimeBefore(PointsAvailableQueryCriteria criteria, Pageable pageable) { | 60 | public List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(Long memberId) { |
| 50 | return this.queryAll(criteria,pageable); | 61 | return PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdOrderByExpireTime(memberId)); |
| 51 | } | 62 | } |
| 52 | 63 | ||
| 53 | @Override | 64 | @Override |
| ... | @@ -65,25 +76,84 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -65,25 +76,84 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 65 | @Override | 76 | @Override |
| 66 | @Transactional(rollbackFor = Exception.class) | 77 | @Transactional(rollbackFor = Exception.class) |
| 67 | public void create(PointsAvailable resources) { | 78 | public void create(PointsAvailable 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 | |||
| 68 | PointsAvailableRepository.save(resources); | 88 | PointsAvailableRepository.save(resources); |
| 69 | } | 89 | } |
| 70 | 90 | ||
| 71 | @Override | 91 | @Override |
| 72 | @Transactional(rollbackFor = Exception.class) | 92 | @Transactional(rollbackFor = Exception.class) |
| 73 | public void update(PointsAvailable resources) { | 93 | public void update(PointsAvailable resources) { |
| 74 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new); | 94 | RLock rLock = this.redissonClient.getLock("PointsAvailable::update::id"+resources.getMemberId().toString()); |
| 75 | ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId()); | 95 | try { |
| 76 | PointsAvailable.copy(resources); | 96 | RedissonUtil.lock(rLock); |
| 77 | PointsAvailableRepository.save(PointsAvailable); | 97 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(resources.getId()).orElseGet(PointsAvailable::new); |
| 98 | ValidationUtil.isNull( PointsAvailable.getId(),"PointsAvailable","id",resources.getId()); | ||
| 99 | PointsAvailable.copy(resources); | ||
| 100 | PointsAvailableRepository.save(PointsAvailable); | ||
| 101 | } catch (Exception e) { | ||
| 102 | e.printStackTrace(); | ||
| 103 | throw e; | ||
| 104 | } finally { | ||
| 105 | RedissonUtil.unlock(rLock); | ||
| 106 | } | ||
| 78 | } | 107 | } |
| 79 | 108 | ||
| 80 | @Override | 109 | @Override |
| 81 | @Transactional(rollbackFor = Exception.class) | 110 | @Transactional(rollbackFor = Exception.class) |
| 82 | public void delete(Long id) { | 111 | public void delete(Long id) { |
| 83 | Assert.notNull(id, "The given id must not be null!"); | 112 | Assert.notNull(id, "The given id must not be null!"); |
| 84 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | 113 | RLock rLock = this.redissonClient.getLock("PointsAvailable::delete::id"+id); |
| 85 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | 114 | try { |
| 86 | PointsAvailableRepository.delete(PointsAvailable); | 115 | RedissonUtil.lock(rLock); |
| 116 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | ||
| 117 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | ||
| 118 | PointsAvailableRepository.delete(PointsAvailable); | ||
| 119 | } catch (Exception e) { | ||
| 120 | e.printStackTrace(); | ||
| 121 | throw e; | ||
| 122 | } finally { | ||
| 123 | RedissonUtil.unlock(rLock); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | @Override | ||
| 128 | public void delete4Custom(Long id) { | ||
| 129 | Assert.notNull(id, "The given id must not be null!"); | ||
| 130 | RLock rLock = this.redissonClient.getLock("PointsAvailable::delete::id"+id); | ||
| 131 | try { | ||
| 132 | RedissonUtil.lock(rLock); | ||
| 133 | PointsAvailable PointsAvailable = PointsAvailableRepository.findById(id).orElseThrow( | ||
| 134 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", PointsAvailable.class, id), 1)); | ||
| 135 | PointsAvailableRepository.delete(PointsAvailable); | ||
| 136 | } catch (Exception e) { | ||
| 137 | e.printStackTrace(); | ||
| 138 | throw e; | ||
| 139 | } finally { | ||
| 140 | RedissonUtil.unlock(rLock); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | @Override | ||
| 145 | @Transactional(rollbackFor = Exception.class) | ||
| 146 | public void deleteBatchByIds(List<Long> id) { | ||
| 147 | RLock rLock = this.redissonClient.getLock("PointsAvailable::create::id"+id.get(0)); | ||
| 148 | try { | ||
| 149 | RedissonUtil.lock(rLock); | ||
| 150 | PointsAvailableRepository.deleteBatchByIds(id); | ||
| 151 | } catch (Exception e) { | ||
| 152 | e.printStackTrace(); | ||
| 153 | throw e; | ||
| 154 | } finally { | ||
| 155 | RedissonUtil.unlock(rLock); | ||
| 156 | } | ||
| 87 | } | 157 | } |
| 88 | 158 | ||
| 89 | 159 | ||
| ... | @@ -94,11 +164,40 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -94,11 +164,40 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
| 94 | } | 164 | } |
| 95 | 165 | ||
| 96 | @Override | 166 | @Override |
| 97 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp) { | 167 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, LocalDateTime timestamp) { |
| 98 | return Objects.nonNull(memberId)? | 168 | return Objects.nonNull(memberId)? |
| 99 | PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp)) | 169 | PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeBefore(memberId, timestamp)) |
| 100 | :null; | 170 | :null; |
| 101 | } | 171 | } |
| 102 | 172 | ||
| 173 | @Override | ||
| 174 | public Long findSoonExpireTime(Long memberId, Integer factor) { | ||
| 175 | return PointsAvailableRepository.findSoonExpireTime(memberId, factor); | ||
| 176 | } | ||
| 177 | |||
| 178 | @Override | ||
| 179 | public long findAvailablePointsByMemberId(long memberId) { | ||
| 180 | Long availablePoints = this.PointsAvailableRepository.findAvailablePointsByMemberId(memberId); | ||
| 181 | return availablePoints == null ? 0L : availablePoints; | ||
| 182 | } | ||
| 183 | |||
| 184 | @Override | ||
| 185 | public long findTotalPointsByMemberId(Long memberId) { | ||
| 186 | return this.PointsAvailableRepository.findTotalCountByMemberId(memberId); | ||
| 187 | } | ||
| 188 | |||
| 189 | @Override | ||
| 190 | public void create4Custom(PointsAvailable resources) { | ||
| 191 | String memberCode = resources.getMemberCode(); | ||
| 192 | if (StringUtils.isNotEmpty(memberCode)) { | ||
| 193 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 194 | if (Objects.nonNull(memberDTO)) { | ||
| 195 | Long memberId = memberDTO.getId(); | ||
| 196 | resources.setMemberId(memberId); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | PointsAvailableRepository.save(resources); | ||
| 201 | } | ||
| 103 | 202 | ||
| 104 | } | 203 | } | ... | ... |
| ... | @@ -23,6 +23,9 @@ import java.sql.Timestamp; | ... | @@ -23,6 +23,9 @@ import java.sql.Timestamp; |
| 23 | @Table(name="uc_points_detail") | 23 | @Table(name="uc_points_detail") |
| 24 | public class PointsDetail implements Serializable { | 24 | public class PointsDetail implements Serializable { |
| 25 | 25 | ||
| 26 | @Transient | ||
| 27 | private String memberCode; | ||
| 28 | |||
| 26 | // 主键 | 29 | // 主键 |
| 27 | @Id | 30 | @Id |
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ... | ... |
| ... | @@ -4,6 +4,7 @@ import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ... | @@ -4,6 +4,7 @@ import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; |
| 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; | ||
| 7 | import java.util.Optional; | 8 | import java.util.Optional; |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| ... | @@ -13,4 +14,6 @@ import java.util.Optional; | ... | @@ -13,4 +14,6 @@ import java.util.Optional; |
| 13 | public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long>, JpaSpecificationExecutor<PointsDetail> { | 14 | public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long>, JpaSpecificationExecutor<PointsDetail> { |
| 14 | 15 | ||
| 15 | Optional<PointsDetail> findFirstByCode(String code); | 16 | Optional<PointsDetail> findFirstByCode(String code); |
| 17 | |||
| 18 | List<PointsDetail> findByMemberId(Long memberId); | ||
| 16 | } | 19 | } | ... | ... |
| ... | @@ -38,6 +38,8 @@ public interface PointsDetailService { | ... | @@ -38,6 +38,8 @@ public interface PointsDetailService { |
| 38 | 38 | ||
| 39 | void create(PointsDetail resources); | 39 | void create(PointsDetail resources); |
| 40 | 40 | ||
| 41 | void create4Custom(PointsDetail resources); | ||
| 42 | |||
| 41 | void update(PointsDetail resources); | 43 | void update(PointsDetail resources); |
| 42 | 44 | ||
| 43 | void delete(Long id); | 45 | void delete(Long id); |
| ... | @@ -50,4 +52,12 @@ public interface PointsDetailService { | ... | @@ -50,4 +52,12 @@ public interface PointsDetailService { |
| 50 | PointsDetailDTO getByCode(String code); | 52 | PointsDetailDTO getByCode(String code); |
| 51 | 53 | ||
| 52 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); | 54 | List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId); |
| 55 | |||
| 56 | |||
| 57 | /** | ||
| 58 | * 已过期的积分 | ||
| 59 | * @param memberId | ||
| 60 | * @return | ||
| 61 | */ | ||
| 62 | List<PointsDetailDTO> findByMemberId(Long memberId); | ||
| 53 | } | 63 | } | ... | ... |
src/main/java/com/topdraw/business/basicdata/points/detail/service/impl/PointsDetailServiceImpl.java
| 1 | package com.topdraw.business.basicdata.points.detail.service.impl; | 1 | package com.topdraw.business.basicdata.points.detail.service.impl; |
| 2 | 2 | ||
| 3 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 3 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | 5 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; |
| 4 | import com.topdraw.business.basicdata.points.detail.repository.PointsDetailRepository; | 6 | import com.topdraw.business.basicdata.points.detail.repository.PointsDetailRepository; |
| 5 | import com.topdraw.business.basicdata.points.detail.service.PointsDetailService; | 7 | import com.topdraw.business.basicdata.points.detail.service.PointsDetailService; |
| ... | @@ -21,6 +23,7 @@ import org.springframework.util.Assert; | ... | @@ -21,6 +23,7 @@ import org.springframework.util.Assert; |
| 21 | 23 | ||
| 22 | import java.util.List; | 24 | import java.util.List; |
| 23 | import java.util.Map; | 25 | import java.util.Map; |
| 26 | import java.util.Objects; | ||
| 24 | 27 | ||
| 25 | /** | 28 | /** |
| 26 | * @author XiangHan | 29 | * @author XiangHan |
| ... | @@ -34,6 +37,9 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -34,6 +37,9 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 34 | private PointsDetailRepository PointsDetailRepository; | 37 | private PointsDetailRepository PointsDetailRepository; |
| 35 | 38 | ||
| 36 | @Autowired | 39 | @Autowired |
| 40 | private MemberService memberService; | ||
| 41 | |||
| 42 | @Autowired | ||
| 37 | private PointsDetailMapper PointsDetailMapper; | 43 | private PointsDetailMapper PointsDetailMapper; |
| 38 | 44 | ||
| 39 | @Override | 45 | @Override |
| ... | @@ -57,6 +63,27 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -57,6 +63,27 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 57 | @Override | 63 | @Override |
| 58 | @Transactional(rollbackFor = Exception.class) | 64 | @Transactional(rollbackFor = Exception.class) |
| 59 | public void create(PointsDetail resources) { | 65 | public void create(PointsDetail resources) { |
| 66 | String memberCode = resources.getMemberCode(); | ||
| 67 | if (StringUtils.isNotEmpty(memberCode)) { | ||
| 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 | } | ||
| 60 | PointsDetailRepository.save(resources); | 87 | PointsDetailRepository.save(resources); |
| 61 | } | 88 | } |
| 62 | 89 | ||
| ... | @@ -89,4 +116,11 @@ public class PointsDetailServiceImpl implements PointsDetailService { | ... | @@ -89,4 +116,11 @@ public class PointsDetailServiceImpl implements PointsDetailService { |
| 89 | public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) { | 116 | public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) { |
| 90 | return null; | 117 | return null; |
| 91 | } | 118 | } |
| 119 | |||
| 120 | @Override | ||
| 121 | public List<PointsDetailDTO> findByMemberId(Long memberId) { | ||
| 122 | return Objects.nonNull(memberId)? | ||
| 123 | PointsDetailMapper.toDto(PointsDetailRepository.findByMemberId(memberId)) | ||
| 124 | :null; | ||
| 125 | } | ||
| 92 | } | 126 | } | ... | ... |
| ... | @@ -30,7 +30,7 @@ public class Points implements Serializable { | ... | @@ -30,7 +30,7 @@ public class Points implements Serializable { |
| 30 | @Column(name = "user_id") | 30 | @Column(name = "user_id") |
| 31 | private Long userId; | 31 | private Long userId; |
| 32 | 32 | ||
| 33 | // 积分类型,通用,绑定, 区分大小屏 todo | 33 | // 积分类型,通用,绑定, 区分大小屏 |
| 34 | @Column(name = "point_type") | 34 | @Column(name = "point_type") |
| 35 | private Integer pointType; | 35 | private Integer pointType; |
| 36 | 36 | ... | ... |
| ... | @@ -11,7 +11,7 @@ import io.swagger.annotations.Api; | ... | @@ -11,7 +11,7 @@ import io.swagger.annotations.Api; |
| 11 | //@RequestMapping("/api/Points") | 11 | //@RequestMapping("/api/Points") |
| 12 | public class PointsController { | 12 | public class PointsController { |
| 13 | 13 | ||
| 14 | /* @Autowired | 14 | /*@Autowired |
| 15 | private PointsService PointsService; | 15 | private PointsService PointsService; |
| 16 | 16 | ||
| 17 | @GetMapping | 17 | @GetMapping |
| ... | @@ -24,9 +24,9 @@ public class PointsController { | ... | @@ -24,9 +24,9 @@ public class PointsController { |
| 24 | @ApiOperation("查询所有Points") | 24 | @ApiOperation("查询所有Points") |
| 25 | public ResultInfo getPointss(PointsQueryCriteria criteria) { | 25 | public ResultInfo getPointss(PointsQueryCriteria criteria) { |
| 26 | return ResultInfo.success(PointsService.queryAll(criteria)); | 26 | return ResultInfo.success(PointsService.queryAll(criteria)); |
| 27 | } | 27 | }*/ |
| 28 | 28 | ||
| 29 | @Log | 29 | /*@Log |
| 30 | @PostMapping | 30 | @PostMapping |
| 31 | @ApiOperation("新增Points") | 31 | @ApiOperation("新增Points") |
| 32 | public ResultInfo create(@Validated @RequestBody Points resources) { | 32 | public ResultInfo create(@Validated @RequestBody Points resources) { | ... | ... |
| ... | @@ -2,10 +2,12 @@ package com.topdraw.business.basicdata.points.service.dto; | ... | @@ -2,10 +2,12 @@ package com.topdraw.business.basicdata.points.service.dto; |
| 2 | 2 | ||
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | 4 | ||
| 5 | |||
| 5 | /** | 6 | /** |
| 6 | * @author XiangHan | 7 | * @author XiangHan |
| 7 | * @date 2021-10-22 | 8 | * @date 2021-10-22 |
| 8 | */ | 9 | */ |
| 9 | @Data | 10 | @Data |
| 10 | public class PointsQueryCriteria{ | 11 | public class PointsQueryCriteria{ |
| 12 | |||
| 11 | } | 13 | } | ... | ... |
| ... | @@ -8,9 +8,12 @@ import com.topdraw.business.basicdata.points.service.PointsService; | ... | @@ -8,9 +8,12 @@ import com.topdraw.business.basicdata.points.service.PointsService; |
| 8 | import com.topdraw.business.basicdata.points.service.dto.PointsDTO; | 8 | import com.topdraw.business.basicdata.points.service.dto.PointsDTO; |
| 9 | import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria; | 9 | import com.topdraw.business.basicdata.points.service.dto.PointsQueryCriteria; |
| 10 | import com.topdraw.business.basicdata.points.service.mapper.PointsMapper; | 10 | import com.topdraw.business.basicdata.points.service.mapper.PointsMapper; |
| 11 | import com.topdraw.util.RedissonUtil; | ||
| 11 | import com.topdraw.utils.PageUtil; | 12 | import com.topdraw.utils.PageUtil; |
| 12 | import com.topdraw.utils.QueryHelp; | 13 | import com.topdraw.utils.QueryHelp; |
| 13 | import com.topdraw.utils.ValidationUtil; | 14 | import com.topdraw.utils.ValidationUtil; |
| 15 | import org.redisson.api.RLock; | ||
| 16 | import org.redisson.api.RedissonClient; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.dao.EmptyResultDataAccessException; | 18 | import org.springframework.dao.EmptyResultDataAccessException; |
| 16 | import org.springframework.data.domain.Page; | 19 | import org.springframework.data.domain.Page; |
| ... | @@ -37,6 +40,9 @@ public class PointsServiceImpl implements PointsService { | ... | @@ -37,6 +40,9 @@ public class PointsServiceImpl implements PointsService { |
| 37 | @Autowired | 40 | @Autowired |
| 38 | private PointsMapper PointsMapper; | 41 | private PointsMapper PointsMapper; |
| 39 | 42 | ||
| 43 | @Autowired | ||
| 44 | private RedissonClient redissonClient; | ||
| 45 | |||
| 40 | @Override | 46 | @Override |
| 41 | public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) { | 47 | public Map<String, Object> queryAll(PointsQueryCriteria criteria, Pageable pageable) { |
| 42 | Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | 48 | Page<Points> page = PointsRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| ... | @@ -66,10 +72,19 @@ public class PointsServiceImpl implements PointsService { | ... | @@ -66,10 +72,19 @@ public class PointsServiceImpl implements PointsService { |
| 66 | @Override | 72 | @Override |
| 67 | @Transactional(rollbackFor = Exception.class) | 73 | @Transactional(rollbackFor = Exception.class) |
| 68 | public void update(Points resources) { | 74 | public void update(Points resources) { |
| 69 | Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new); | 75 | RLock rLock = this.redissonClient.getLock(resources.getId().toString()); |
| 70 | ValidationUtil.isNull( Points.getId(),"Points","id",resources.getId()); | 76 | try { |
| 71 | Points.copy(resources); | 77 | RedissonUtil.lock(rLock); |
| 72 | PointsRepository.save(Points); | 78 | Points Points = PointsRepository.findById(resources.getId()).orElseGet(Points::new); |
| 79 | ValidationUtil.isNull(Points.getId(), "Points", "id", resources.getId()); | ||
| 80 | Points.copy(resources); | ||
| 81 | PointsRepository.save(Points); | ||
| 82 | } catch (Exception e) { | ||
| 83 | e.printStackTrace(); | ||
| 84 | throw e; | ||
| 85 | } finally { | ||
| 86 | RedissonUtil.unlock(rLock); | ||
| 87 | } | ||
| 73 | } | 88 | } |
| 74 | 89 | ||
| 75 | @Override | 90 | @Override | ... | ... |
src/main/java/com/topdraw/business/basicdata/points/standingbook/domain/PointsStandingBook.java
0 → 100644
| 1 | package com.topdraw.business.basicdata.points.standingbook.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-10-29 | ||
| 18 | */ | ||
| 19 | @Entity | ||
| 20 | @Data | ||
| 21 | @EntityListeners(AuditingEntityListener.class) | ||
| 22 | @Accessors(chain = true) | ||
| 23 | @Table(name="uc_points_standing_book") | ||
| 24 | public class PointsStandingBook implements Serializable { | ||
| 25 | |||
| 26 | // 主键 | ||
| 27 | @Id | ||
| 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 29 | @Column(name = "id") | ||
| 30 | private Long id; | ||
| 31 | |||
| 32 | // 积分生产 | ||
| 33 | @Column(name = "points_produce", nullable = false) | ||
| 34 | private Long pointsProduce; | ||
| 35 | |||
| 36 | // 积分消耗 | ||
| 37 | @Column(name = "points_consume", nullable = false) | ||
| 38 | private Long pointsConsume; | ||
| 39 | |||
| 40 | // 可用总积分 | ||
| 41 | @Column(name = "points_available", nullable = false) | ||
| 42 | private Long pointsAvailable; | ||
| 43 | |||
| 44 | // 积分过期 | ||
| 45 | @Column(name = "points_expire", nullable = false) | ||
| 46 | private Long pointsExpire; | ||
| 47 | |||
| 48 | // 日期 | ||
| 49 | @Column(name = "day") | ||
| 50 | private String day; | ||
| 51 | |||
| 52 | // 创建时间 | ||
| 53 | @CreatedDate | ||
| 54 | @Column(name = "create_time") | ||
| 55 | private Timestamp createTime; | ||
| 56 | |||
| 57 | // 创建时间 | ||
| 58 | @LastModifiedDate | ||
| 59 | @Column(name = "update_time") | ||
| 60 | private Timestamp updateTime; | ||
| 61 | |||
| 62 | public void copy(PointsStandingBook source){ | ||
| 63 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 64 | } | ||
| 65 | } |
| 1 | package com.topdraw.business.basicdata.points.standingbook.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.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.basicdata.points.standingbook.rest; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Log; | ||
| 4 | import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook; | ||
| 5 | import com.topdraw.business.basicdata.points.standingbook.service.PointsStandingBookService; | ||
| 6 | import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookQueryCriteria; | ||
| 7 | import com.topdraw.common.ResultInfo; | ||
| 8 | import io.swagger.annotations.Api; | ||
| 9 | import io.swagger.annotations.ApiOperation; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | import org.springframework.data.domain.Pageable; | ||
| 12 | import org.springframework.validation.annotation.Validated; | ||
| 13 | import org.springframework.web.bind.annotation.*; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author XiangHan | ||
| 17 | * @date 2021-10-29 | ||
| 18 | */ | ||
| 19 | @Api(tags = "PointsStandingBook管理") | ||
| 20 | @RestController | ||
| 21 | @RequestMapping("/api/PointsStandingBook") | ||
| 22 | public class PointsStandingBookController { | ||
| 23 | |||
| 24 | @Autowired | ||
| 25 | private PointsStandingBookService PointsStandingBookService; | ||
| 26 | |||
| 27 | @GetMapping | ||
| 28 | @ApiOperation("查询PointsStandingBook") | ||
| 29 | public ResultInfo getPointsStandingBooks(PointsStandingBookQueryCriteria criteria, Pageable pageable) { | ||
| 30 | return ResultInfo.successPage(PointsStandingBookService.queryAll(criteria,pageable)); | ||
| 31 | } | ||
| 32 | |||
| 33 | @GetMapping(value = "/all") | ||
| 34 | @ApiOperation("查询所有PointsStandingBook") | ||
| 35 | public ResultInfo getPointsStandingBooks(PointsStandingBookQueryCriteria criteria) { | ||
| 36 | return ResultInfo.success(PointsStandingBookService.queryAll(criteria)); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Log | ||
| 40 | @PostMapping | ||
| 41 | @ApiOperation("新增PointsStandingBook") | ||
| 42 | public ResultInfo create(@Validated @RequestBody PointsStandingBook resources) { | ||
| 43 | PointsStandingBookService.create(resources); | ||
| 44 | return ResultInfo.success(); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Log | ||
| 48 | @PutMapping | ||
| 49 | @ApiOperation("修改PointsStandingBook") | ||
| 50 | public ResultInfo update(@Validated @RequestBody PointsStandingBook resources) { | ||
| 51 | PointsStandingBookService.update(resources); | ||
| 52 | return ResultInfo.success(); | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | @Log | ||
| 57 | @DeleteMapping(value = "/{id}") | ||
| 58 | @ApiOperation("删除PointsStandingBook") | ||
| 59 | public ResultInfo delete(@PathVariable Long id) { | ||
| 60 | PointsStandingBookService.delete(id); | ||
| 61 | return ResultInfo.success(); | ||
| 62 | } | ||
| 63 | |||
| 64 | } |
| 1 | package com.topdraw.business.basicdata.points.standingbook.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook; | ||
| 4 | import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO; | ||
| 5 | import com.topdraw.business.basicdata.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.basicdata.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.basicdata.points.standingbook.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook; | ||
| 4 | import com.topdraw.business.basicdata.points.standingbook.repository.PointsStandingBookRepository; | ||
| 5 | import com.topdraw.business.basicdata.points.standingbook.service.PointsStandingBookService; | ||
| 6 | import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO; | ||
| 7 | import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookQueryCriteria; | ||
| 8 | import com.topdraw.business.basicdata.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 | } |
| 1 | package com.topdraw.business.basicdata.points.standingbook.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.basicdata.points.standingbook.domain.PointsStandingBook; | ||
| 5 | import com.topdraw.business.basicdata.points.standingbook.service.dto.PointsStandingBookDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-10-29 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface PointsStandingBookMapper extends BaseMapper<PointsStandingBookDTO, PointsStandingBook> { | ||
| 15 | |||
| 16 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.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-12-16 | ||
| 18 | */ | ||
| 19 | @Entity | ||
| 20 | @Data | ||
| 21 | @EntityListeners(AuditingEntityListener.class) | ||
| 22 | @Accessors(chain = true) | ||
| 23 | @Table(name="uc_user_tv") | ||
| 24 | public class UserTv implements Serializable { | ||
| 25 | |||
| 26 | @Transient | ||
| 27 | private String memberCode; | ||
| 28 | |||
| 29 | // ID | ||
| 30 | @Id | ||
| 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 32 | @Column(name = "id") | ||
| 33 | private Long id; | ||
| 34 | |||
| 35 | // 人ID | ||
| 36 | @Column(name = "`person_id`") | ||
| 37 | private Long personId; | ||
| 38 | |||
| 39 | // 运营商平台 | ||
| 40 | @Column(name = "`platform`") | ||
| 41 | private String platform; | ||
| 42 | |||
| 43 | // 运营商平台账号 | ||
| 44 | @Column(name = "`platform_account`") | ||
| 45 | private String platformAccount; | ||
| 46 | |||
| 47 | // 手机号 | ||
| 48 | @Column(name = "`cellphone`") | ||
| 49 | private String cellphone; | ||
| 50 | |||
| 51 | // 用户名 | ||
| 52 | @Column(name = "`username`") | ||
| 53 | private String username; | ||
| 54 | |||
| 55 | // 密码 MD5 | ||
| 56 | @Column(name = "`password`") | ||
| 57 | private String password; | ||
| 58 | |||
| 59 | // 昵称 Base64 | ||
| 60 | @Column(name = "`nickname`") | ||
| 61 | private String nickname; | ||
| 62 | |||
| 63 | // 头像 | ||
| 64 | @Column(name = "`image`") | ||
| 65 | private String image; | ||
| 66 | |||
| 67 | // 登录天数(总天数) | ||
| 68 | @Column(name = "`login_days`") | ||
| 69 | private Integer loginDays; | ||
| 70 | |||
| 71 | // 连续登录天数 | ||
| 72 | @Column(name = "`continue_days`") | ||
| 73 | private Integer continueDays; | ||
| 74 | |||
| 75 | // 活跃时间 | ||
| 76 | @Column(name = "`active_time`") | ||
| 77 | private Timestamp activeTime; | ||
| 78 | |||
| 79 | // 分组 分组ID用逗号分隔 | ||
| 80 | @Column(name = "`groups`") | ||
| 81 | private String groups; | ||
| 82 | |||
| 83 | // 标签 标签用逗号分隔 | ||
| 84 | @Column(name = "`tags`") | ||
| 85 | private String tags; | ||
| 86 | |||
| 87 | // 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 | ||
| 88 | @Column(name = "`login_type`") | ||
| 89 | private Integer loginType; | ||
| 90 | |||
| 91 | // 状态 0-下线 1-上线 | ||
| 92 | @Column(name = "`status`") | ||
| 93 | private Integer status; | ||
| 94 | |||
| 95 | // 描述 | ||
| 96 | @Column(name = "`description`") | ||
| 97 | private String description; | ||
| 98 | |||
| 99 | // 创建者 | ||
| 100 | @Column(name = "`create_by`") | ||
| 101 | private String createBy; | ||
| 102 | |||
| 103 | // 创建时间 | ||
| 104 | @CreatedDate | ||
| 105 | @Column(name = "`create_time`") | ||
| 106 | private Timestamp createTime; | ||
| 107 | |||
| 108 | // 更新者 | ||
| 109 | @Column(name = "`update_by`") | ||
| 110 | private String updateBy; | ||
| 111 | |||
| 112 | // 更新时间 | ||
| 113 | @LastModifiedDate | ||
| 114 | @Column(name = "`update_time`") | ||
| 115 | private Timestamp updateTime; | ||
| 116 | |||
| 117 | // 会员id | ||
| 118 | @Column(name = "`member_id`") | ||
| 119 | private Long memberId; | ||
| 120 | |||
| 121 | public void copy(UserTv source){ | ||
| 122 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 123 | } | ||
| 124 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 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 2021-12-16 | ||
| 12 | */ | ||
| 13 | public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecificationExecutor<UserTv> { | ||
| 14 | |||
| 15 | Optional<UserTv> findByPlatformAccount(String platformAccount); | ||
| 16 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.rest; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Log; | ||
| 4 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 5 | import com.topdraw.business.basicdata.user.iptv.service.UserTvService; | ||
| 6 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvQueryCriteria; | ||
| 7 | import com.topdraw.common.ResultInfo; | ||
| 8 | import io.swagger.annotations.Api; | ||
| 9 | import io.swagger.annotations.ApiOperation; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | import org.springframework.data.domain.Pageable; | ||
| 12 | import org.springframework.validation.annotation.Validated; | ||
| 13 | import org.springframework.web.bind.annotation.*; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author XiangHan | ||
| 17 | * @date 2021-12-16 | ||
| 18 | */ | ||
| 19 | @Api(tags = "UserTv管理") | ||
| 20 | @RestController | ||
| 21 | @RequestMapping("/api/UserTv") | ||
| 22 | public class UserTvController { | ||
| 23 | |||
| 24 | @Autowired | ||
| 25 | private UserTvService UserTvService; | ||
| 26 | |||
| 27 | @GetMapping | ||
| 28 | @ApiOperation("查询UserTv") | ||
| 29 | public ResultInfo getUserTvs(UserTvQueryCriteria criteria, Pageable pageable) { | ||
| 30 | return ResultInfo.successPage(UserTvService.queryAll(criteria,pageable)); | ||
| 31 | } | ||
| 32 | |||
| 33 | @GetMapping(value = "/all") | ||
| 34 | @ApiOperation("查询所有UserTv") | ||
| 35 | public ResultInfo getUserTvs(UserTvQueryCriteria criteria) { | ||
| 36 | return ResultInfo.success(UserTvService.queryAll(criteria)); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Log | ||
| 40 | @PostMapping | ||
| 41 | @ApiOperation("新增UserTv") | ||
| 42 | public ResultInfo create(@Validated @RequestBody UserTv resources) { | ||
| 43 | UserTvService.create(resources); | ||
| 44 | return ResultInfo.success(); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Log | ||
| 48 | @PutMapping | ||
| 49 | @ApiOperation("修改UserTv") | ||
| 50 | public ResultInfo update(@Validated @RequestBody UserTv resources) { | ||
| 51 | UserTvService.update(resources); | ||
| 52 | return ResultInfo.success(); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Log | ||
| 56 | @DeleteMapping(value = "/{id}") | ||
| 57 | @ApiOperation("删除UserTv") | ||
| 58 | public ResultInfo delete(@PathVariable Long id) { | ||
| 59 | UserTvService.delete(id); | ||
| 60 | return ResultInfo.success(); | ||
| 61 | } | ||
| 62 | |||
| 63 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 4 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvDTO; | ||
| 5 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvQueryCriteria; | ||
| 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-12-16 | ||
| 14 | */ | ||
| 15 | public interface UserTvService { | ||
| 16 | |||
| 17 | /** | ||
| 18 | * 查询数据分页 | ||
| 19 | * @param criteria 条件参数 | ||
| 20 | * @param pageable 分页参数 | ||
| 21 | * @return Map<String,Object> | ||
| 22 | */ | ||
| 23 | Map<String,Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * 查询所有数据不分页 | ||
| 27 | * @param criteria 条件参数 | ||
| 28 | * @return List<UserTvDTO> | ||
| 29 | */ | ||
| 30 | List<UserTvDTO> queryAll(UserTvQueryCriteria criteria); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * 根据ID查询 | ||
| 34 | * @param id ID | ||
| 35 | * @return UserTvDTO | ||
| 36 | */ | ||
| 37 | UserTvDTO findById(Long id); | ||
| 38 | |||
| 39 | Long create(UserTv resources); | ||
| 40 | |||
| 41 | void update(UserTv resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | UserTvDTO findByPlatformAccount(String platformAccount); | ||
| 46 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.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-12-16 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class UserTvDTO implements Serializable { | ||
| 15 | |||
| 16 | // ID | ||
| 17 | private Long id; | ||
| 18 | |||
| 19 | // 人ID | ||
| 20 | private Long personId; | ||
| 21 | |||
| 22 | // 运营商平台 | ||
| 23 | private String platform; | ||
| 24 | |||
| 25 | // 运营商平台账号 | ||
| 26 | private String platformAccount; | ||
| 27 | |||
| 28 | // 手机号 | ||
| 29 | private String cellphone; | ||
| 30 | |||
| 31 | // 用户名 | ||
| 32 | private String username; | ||
| 33 | |||
| 34 | // 密码 MD5 | ||
| 35 | private String password; | ||
| 36 | |||
| 37 | // 昵称 Base64 | ||
| 38 | private String nickname; | ||
| 39 | |||
| 40 | // 头像 | ||
| 41 | private String image; | ||
| 42 | |||
| 43 | // 登录天数(总天数) | ||
| 44 | private Integer loginDays; | ||
| 45 | |||
| 46 | // 连续登录天数 | ||
| 47 | private Integer continueDays; | ||
| 48 | |||
| 49 | // 活跃时间 | ||
| 50 | private Timestamp activeTime; | ||
| 51 | |||
| 52 | // 分组 分组ID用逗号分隔 | ||
| 53 | private String groups; | ||
| 54 | |||
| 55 | // 标签 标签用逗号分隔 | ||
| 56 | private String tags; | ||
| 57 | |||
| 58 | // 登录类型 1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录 | ||
| 59 | private Integer loginType; | ||
| 60 | |||
| 61 | // 状态 0-下线 1-上线 | ||
| 62 | private Integer status; | ||
| 63 | |||
| 64 | // 描述 | ||
| 65 | private String description; | ||
| 66 | |||
| 67 | // 创建者 | ||
| 68 | private String createBy; | ||
| 69 | |||
| 70 | // 创建时间 | ||
| 71 | private Timestamp createTime; | ||
| 72 | |||
| 73 | // 更新者 | ||
| 74 | private String updateBy; | ||
| 75 | |||
| 76 | // 更新时间 | ||
| 77 | private Timestamp updateTime; | ||
| 78 | |||
| 79 | // 会员id | ||
| 80 | private Long memberId; | ||
| 81 | } | ||
| 82 | |||
| 83 |
src/main/java/com/topdraw/business/basicdata/user/iptv/service/impl/UserTvServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.basicdata.user.iptv.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 5 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 6 | import com.topdraw.business.basicdata.user.iptv.repository.UserTvRepository; | ||
| 7 | import com.topdraw.business.basicdata.user.iptv.service.UserTvService; | ||
| 8 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvDTO; | ||
| 9 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvQueryCriteria; | ||
| 10 | import com.topdraw.business.basicdata.user.iptv.service.mapper.UserTvMapper; | ||
| 11 | import com.topdraw.utils.PageUtil; | ||
| 12 | import com.topdraw.utils.QueryHelp; | ||
| 13 | import com.topdraw.utils.ValidationUtil; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 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; | ||
| 19 | import org.springframework.transaction.annotation.Propagation; | ||
| 20 | import org.springframework.transaction.annotation.Transactional; | ||
| 21 | import org.springframework.util.Assert; | ||
| 22 | |||
| 23 | import java.util.List; | ||
| 24 | import java.util.Map; | ||
| 25 | import java.util.Objects; | ||
| 26 | import java.util.Optional; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * @author XiangHan | ||
| 30 | * @date 2021-12-16 | ||
| 31 | */ | ||
| 32 | @Service | ||
| 33 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 34 | public class UserTvServiceImpl implements UserTvService { | ||
| 35 | |||
| 36 | @Autowired | ||
| 37 | private UserTvRepository UserTvRepository; | ||
| 38 | |||
| 39 | @Autowired | ||
| 40 | private UserTvMapper UserTvMapper; | ||
| 41 | @Autowired | ||
| 42 | private MemberService memberService; | ||
| 43 | |||
| 44 | @Override | ||
| 45 | public Map<String, Object> queryAll(UserTvQueryCriteria criteria, Pageable pageable) { | ||
| 46 | Page<UserTv> page = UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 47 | return PageUtil.toPage(page.map(UserTvMapper::toDto)); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public List<UserTvDTO> queryAll(UserTvQueryCriteria criteria) { | ||
| 52 | return UserTvMapper.toDto(UserTvRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Override | ||
| 56 | public UserTvDTO findById(Long id) { | ||
| 57 | UserTv UserTv = UserTvRepository.findById(id).orElseGet(UserTv::new); | ||
| 58 | ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); | ||
| 59 | return UserTvMapper.toDto(UserTv); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | @Transactional(rollbackFor = Exception.class) | ||
| 64 | public Long create(UserTv resources) { | ||
| 65 | MemberDTO memberDTO = memberService.getByCode(resources.getMemberCode()); | ||
| 66 | if (Objects.nonNull(memberDTO)) { | ||
| 67 | Long id = memberDTO.getId(); | ||
| 68 | resources.setMemberId(id); | ||
| 69 | UserTvRepository.save(resources); | ||
| 70 | return resources.getId(); | ||
| 71 | } | ||
| 72 | return null; | ||
| 73 | } | ||
| 74 | |||
| 75 | @Override | ||
| 76 | @Transactional(rollbackFor = Exception.class) | ||
| 77 | public void update(UserTv resources) { | ||
| 78 | UserTv UserTv = UserTvRepository.findById(resources.getId()).orElseGet(UserTv::new); | ||
| 79 | ValidationUtil.isNull( UserTv.getId(),"UserTv","id",resources.getId()); | ||
| 80 | UserTv.copy(resources); | ||
| 81 | UserTvRepository.save(UserTv); | ||
| 82 | } | ||
| 83 | |||
| 84 | @Override | ||
| 85 | @Transactional(rollbackFor = Exception.class) | ||
| 86 | public void delete(Long id) { | ||
| 87 | Assert.notNull(id, "The given id must not be null!"); | ||
| 88 | UserTv UserTv = UserTvRepository.findById(id).orElseThrow( | ||
| 89 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserTv.class, id), 1)); | ||
| 90 | UserTvRepository.delete(UserTv); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Override | ||
| 94 | public UserTvDTO findByPlatformAccount(String platformAccount) { | ||
| 95 | Optional<UserTv> userTv = UserTvRepository.findByPlatformAccount(platformAccount); | ||
| 96 | if (userTv.isPresent()) { | ||
| 97 | ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId()); | ||
| 98 | return UserTvMapper.toDto(userTv.get()); | ||
| 99 | } | ||
| 100 | return null; | ||
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | } |
| 1 | package com.topdraw.business.basicdata.user.iptv.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.basicdata.user.iptv.domain.UserTv; | ||
| 5 | import com.topdraw.business.basicdata.user.iptv.service.dto.UserTvDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-12-16 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface UserTvMapper extends BaseMapper<UserTvDTO, UserTv> { | ||
| 15 | |||
| 16 | } |
| 1 | package com.topdraw.business.basicdata.user.weixin.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-12-16 | ||
| 18 | */ | ||
| 19 | @Entity | ||
| 20 | @Data | ||
| 21 | @EntityListeners(AuditingEntityListener.class) | ||
| 22 | @Accessors(chain = true) | ||
| 23 | @Table(name="uc_user_weixin") | ||
| 24 | public class UserWeixin 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 = "member_id") | ||
| 34 | private Long memberId; | ||
| 35 | |||
| 36 | // 微信unionid,针对开发者 | ||
| 37 | @Column(name = "unionid") | ||
| 38 | private String unionid; | ||
| 39 | |||
| 40 | // 微信appid | ||
| 41 | @Column(name = "appid") | ||
| 42 | private String appid; | ||
| 43 | |||
| 44 | // 微信openid,针对微信app | ||
| 45 | @Column(name = "openid") | ||
| 46 | private String openid; | ||
| 47 | |||
| 48 | // 关注状态 0 -未关注 1 - 已关注 | ||
| 49 | @Column(name = "status") | ||
| 50 | private Integer status; | ||
| 51 | |||
| 52 | // 关注同步状态 0-未同步,1-已同步 | ||
| 53 | @Column(name = "sync_status") | ||
| 54 | private Integer syncStatus; | ||
| 55 | |||
| 56 | // 昵称 | ||
| 57 | @Column(name = "nickname") | ||
| 58 | private String nickname; | ||
| 59 | |||
| 60 | // 头像地址 | ||
| 61 | @Column(name = "headimgurl") | ||
| 62 | private String headimgurl; | ||
| 63 | |||
| 64 | // 特权信息 | ||
| 65 | @Column(name = "privilege") | ||
| 66 | private String privilege; | ||
| 67 | |||
| 68 | // 刷新凭据 | ||
| 69 | @Column(name = "refresh_token") | ||
| 70 | private String refreshToken; | ||
| 71 | |||
| 72 | // 凭据 | ||
| 73 | @Column(name = "access_token") | ||
| 74 | private String accessToken; | ||
| 75 | |||
| 76 | // 超时(秒) | ||
| 77 | @Column(name = "expires_in") | ||
| 78 | private Integer expiresIn; | ||
| 79 | |||
| 80 | // 超时时间 | ||
| 81 | @Column(name = "expires_time") | ||
| 82 | private Timestamp expiresTime; | ||
| 83 | |||
| 84 | // 描述 | ||
| 85 | @Column(name = "description") | ||
| 86 | private String description; | ||
| 87 | |||
| 88 | // 创建者 | ||
| 89 | @Column(name = "create_by") | ||
| 90 | private String createBy; | ||
| 91 | |||
| 92 | // 创建时间 | ||
| 93 | @CreatedDate | ||
| 94 | @Column(name = "create_time") | ||
| 95 | private Timestamp createTime; | ||
| 96 | |||
| 97 | // 更新者 | ||
| 98 | @Column(name = "update_by") | ||
| 99 | private String updateBy; | ||
| 100 | |||
| 101 | // 更新时间 | ||
| 102 | @LastModifiedDate | ||
| 103 | @Column(name = "update_time") | ||
| 104 | private Timestamp updateTime; | ||
| 105 | |||
| 106 | // 来源类型 | ||
| 107 | @Column(name = "source_type") | ||
| 108 | private String sourceType; | ||
| 109 | |||
| 110 | // 来源id | ||
| 111 | @Column(name = "source_id") | ||
| 112 | private String sourceId; | ||
| 113 | |||
| 114 | // 来源id | ||
| 115 | @Column(name = "source_desc") | ||
| 116 | private String sourceDesc; | ||
| 117 | |||
| 118 | // 人id | ||
| 119 | @Column(name = "person_id") | ||
| 120 | private Long personId; | ||
| 121 | |||
| 122 | // 来源用户id | ||
| 123 | @Column(name = "source_user") | ||
| 124 | private Long sourceUser; | ||
| 125 | |||
| 126 | // 来源实体:活动-activity/商品-item | ||
| 127 | @Column(name = "source_entity") | ||
| 128 | private String sourceEntity; | ||
| 129 | |||
| 130 | // 授权时间 | ||
| 131 | @Column(name = "auth_time") | ||
| 132 | private Timestamp authTime; | ||
| 133 | |||
| 134 | @Column(name = "sex") | ||
| 135 | private Integer sex; | ||
| 136 | |||
| 137 | @Column(name = "country") | ||
| 138 | private String country; | ||
| 139 | |||
| 140 | @Column(name = "province") | ||
| 141 | private String province; | ||
| 142 | |||
| 143 | @Column(name = "city") | ||
| 144 | private String city; | ||
| 145 | |||
| 146 | public void copy(UserWeixin source){ | ||
| 147 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
| 148 | } | ||
| 149 | } |
src/main/java/com/topdraw/business/basicdata/user/weixin/repository/UserWeixinRepository.java
0 → 100644
| 1 | package com.topdraw.business.basicdata.user.weixin.repository; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.user.weixin.domain.UserWeixin; | ||
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @author XiangHan | ||
| 9 | * @date 2021-12-16 | ||
| 10 | */ | ||
| 11 | public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, JpaSpecificationExecutor<UserWeixin> { | ||
| 12 | |||
| 13 | } |
| 1 | package com.topdraw.business.basicdata.user.weixin.rest; | ||
| 2 | |||
| 3 | import com.topdraw.annotation.Log; | ||
| 4 | import com.topdraw.business.basicdata.user.weixin.domain.UserWeixin; | ||
| 5 | import com.topdraw.business.basicdata.user.weixin.service.UserWeixinService; | ||
| 6 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
| 7 | import com.topdraw.common.ResultInfo; | ||
| 8 | import io.swagger.annotations.Api; | ||
| 9 | import io.swagger.annotations.ApiOperation; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | import org.springframework.data.domain.Pageable; | ||
| 12 | import org.springframework.validation.annotation.Validated; | ||
| 13 | import org.springframework.web.bind.annotation.*; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * @author XiangHan | ||
| 17 | * @date 2021-12-16 | ||
| 18 | */ | ||
| 19 | @Api(tags = "UserWeixin管理") | ||
| 20 | @RestController | ||
| 21 | @RequestMapping("/api/UserWeixin") | ||
| 22 | public class UserWeixinController { | ||
| 23 | |||
| 24 | @Autowired | ||
| 25 | private UserWeixinService UserWeixinService; | ||
| 26 | |||
| 27 | @GetMapping | ||
| 28 | @ApiOperation("查询UserWeixin") | ||
| 29 | public ResultInfo getUserWeixins(UserWeixinQueryCriteria criteria, Pageable pageable) { | ||
| 30 | return ResultInfo.successPage(UserWeixinService.queryAll(criteria,pageable)); | ||
| 31 | } | ||
| 32 | |||
| 33 | @GetMapping(value = "/all") | ||
| 34 | @ApiOperation("查询所有UserWeixin") | ||
| 35 | public ResultInfo getUserWeixins(UserWeixinQueryCriteria criteria) { | ||
| 36 | return ResultInfo.success(UserWeixinService.queryAll(criteria)); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Log | ||
| 40 | @PostMapping | ||
| 41 | @ApiOperation("新增UserWeixin") | ||
| 42 | public ResultInfo create(@Validated @RequestBody UserWeixin resources) { | ||
| 43 | UserWeixinService.create(resources); | ||
| 44 | return ResultInfo.success(); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Log | ||
| 48 | @PutMapping | ||
| 49 | @ApiOperation("修改UserWeixin") | ||
| 50 | public ResultInfo update(@Validated @RequestBody UserWeixin resources) { | ||
| 51 | UserWeixinService.update(resources); | ||
| 52 | return ResultInfo.success(); | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | @Log | ||
| 57 | @DeleteMapping(value = "/{id}") | ||
| 58 | @ApiOperation("删除UserWeixin") | ||
| 59 | public ResultInfo delete(@PathVariable Long id) { | ||
| 60 | UserWeixinService.delete(id); | ||
| 61 | return ResultInfo.success(); | ||
| 62 | } | ||
| 63 | |||
| 64 | } |
| 1 | package com.topdraw.business.basicdata.user.weixin.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.user.weixin.domain.UserWeixin; | ||
| 4 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinDTO; | ||
| 5 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
| 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-12-16 | ||
| 14 | */ | ||
| 15 | public interface UserWeixinService { | ||
| 16 | |||
| 17 | /** | ||
| 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查询 | ||
| 34 | * @param id ID | ||
| 35 | * @return UserWeixinDTO | ||
| 36 | */ | ||
| 37 | UserWeixinDTO findById(Long id); | ||
| 38 | |||
| 39 | void create(UserWeixin resources); | ||
| 40 | |||
| 41 | void update(UserWeixin resources); | ||
| 42 | |||
| 43 | void delete(Long id); | ||
| 44 | |||
| 45 | } |
| 1 | package com.topdraw.business.basicdata.user.weixin.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-12-16 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | public class UserWeixinDTO implements Serializable { | ||
| 15 | |||
| 16 | // ID | ||
| 17 | private Long id; | ||
| 18 | |||
| 19 | // 用户ID | ||
| 20 | private Long memberId; | ||
| 21 | |||
| 22 | // 微信unionid,针对开发者 | ||
| 23 | private String unionid; | ||
| 24 | |||
| 25 | // 微信appid | ||
| 26 | private String appid; | ||
| 27 | |||
| 28 | // 微信openid,针对微信app | ||
| 29 | private String openid; | ||
| 30 | |||
| 31 | // 关注状态 0 -未关注 1 - 已关注 | ||
| 32 | private Integer status; | ||
| 33 | |||
| 34 | // 关注同步状态 0-未同步,1-已同步 | ||
| 35 | private Integer syncStatus; | ||
| 36 | |||
| 37 | // 昵称 | ||
| 38 | private String nickname; | ||
| 39 | |||
| 40 | // 头像地址 | ||
| 41 | private String headimgurl; | ||
| 42 | |||
| 43 | // 特权信息 | ||
| 44 | private String privilege; | ||
| 45 | |||
| 46 | // 刷新凭据 | ||
| 47 | private String refreshToken; | ||
| 48 | |||
| 49 | // 凭据 | ||
| 50 | private String accessToken; | ||
| 51 | |||
| 52 | // 超时(秒) | ||
| 53 | private Integer expiresIn; | ||
| 54 | |||
| 55 | // 超时时间 | ||
| 56 | private Timestamp expiresTime; | ||
| 57 | |||
| 58 | // 描述 | ||
| 59 | private String description; | ||
| 60 | |||
| 61 | // 创建者 | ||
| 62 | private String createBy; | ||
| 63 | |||
| 64 | // 创建时间 | ||
| 65 | private Timestamp createTime; | ||
| 66 | |||
| 67 | // 更新者 | ||
| 68 | private String updateBy; | ||
| 69 | |||
| 70 | // 更新时间 | ||
| 71 | private Timestamp updateTime; | ||
| 72 | |||
| 73 | // 来源类型 | ||
| 74 | private String sourceType; | ||
| 75 | |||
| 76 | // 来源id | ||
| 77 | private String sourceId; | ||
| 78 | |||
| 79 | // 来源id | ||
| 80 | private String sourceDesc; | ||
| 81 | |||
| 82 | // 人id | ||
| 83 | private Long personId; | ||
| 84 | |||
| 85 | // 来源用户id | ||
| 86 | private Long sourceUser; | ||
| 87 | |||
| 88 | // 来源实体:活动-activity/商品-item | ||
| 89 | private String sourceEntity; | ||
| 90 | |||
| 91 | // 授权时间 | ||
| 92 | private Timestamp authTime; | ||
| 93 | |||
| 94 | private Integer sex; | ||
| 95 | |||
| 96 | private String country; | ||
| 97 | |||
| 98 | private String province; | ||
| 99 | |||
| 100 | private String city; | ||
| 101 | } |
src/main/java/com/topdraw/business/basicdata/user/weixin/service/impl/UserWeixinServiceImpl.java
0 → 100644
| 1 | package com.topdraw.business.basicdata.user.weixin.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.user.weixin.domain.UserWeixin; | ||
| 4 | import com.topdraw.business.basicdata.user.weixin.repository.UserWeixinRepository; | ||
| 5 | import com.topdraw.business.basicdata.user.weixin.service.UserWeixinService; | ||
| 6 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinDTO; | ||
| 7 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinQueryCriteria; | ||
| 8 | import com.topdraw.business.basicdata.user.weixin.service.mapper.UserWeixinMapper; | ||
| 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-12-16 | ||
| 27 | */ | ||
| 28 | @Service | ||
| 29 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 30 | public class UserWeixinServiceImpl implements UserWeixinService { | ||
| 31 | |||
| 32 | @Autowired | ||
| 33 | private UserWeixinRepository UserWeixinRepository; | ||
| 34 | |||
| 35 | @Autowired | ||
| 36 | private UserWeixinMapper UserWeixinMapper; | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public Map<String, Object> queryAll(UserWeixinQueryCriteria criteria, Pageable pageable) { | ||
| 40 | Page<UserWeixin> page = UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
| 41 | return PageUtil.toPage(page.map(UserWeixinMapper::toDto)); | ||
| 42 | } | ||
| 43 | |||
| 44 | @Override | ||
| 45 | public List<UserWeixinDTO> queryAll(UserWeixinQueryCriteria criteria) { | ||
| 46 | return UserWeixinMapper.toDto(UserWeixinRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Override | ||
| 50 | public UserWeixinDTO findById(Long id) { | ||
| 51 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseGet(UserWeixin::new); | ||
| 52 | ValidationUtil.isNull(UserWeixin.getId(),"UserWeixin","id",id); | ||
| 53 | return UserWeixinMapper.toDto(UserWeixin); | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 57 | @Transactional(rollbackFor = Exception.class) | ||
| 58 | public void create(UserWeixin resources) { | ||
| 59 | UserWeixinRepository.save(resources); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | @Transactional(rollbackFor = Exception.class) | ||
| 64 | public void update(UserWeixin resources) { | ||
| 65 | UserWeixin UserWeixin = UserWeixinRepository.findById(resources.getId()).orElseGet(UserWeixin::new); | ||
| 66 | ValidationUtil.isNull( UserWeixin.getId(),"UserWeixin","id",resources.getId()); | ||
| 67 | UserWeixin.copy(resources); | ||
| 68 | UserWeixinRepository.save(UserWeixin); | ||
| 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 | UserWeixin UserWeixin = UserWeixinRepository.findById(id).orElseThrow( | ||
| 76 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserWeixin.class, id), 1)); | ||
| 77 | UserWeixinRepository.delete(UserWeixin); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | } |
src/main/java/com/topdraw/business/basicdata/user/weixin/service/mapper/UserWeixinMapper.java
0 → 100644
| 1 | package com.topdraw.business.basicdata.user.weixin.service.mapper; | ||
| 2 | |||
| 3 | import com.topdraw.base.BaseMapper; | ||
| 4 | import com.topdraw.business.basicdata.user.weixin.domain.UserWeixin; | ||
| 5 | import com.topdraw.business.basicdata.user.weixin.service.dto.UserWeixinDTO; | ||
| 6 | import org.mapstruct.Mapper; | ||
| 7 | import org.mapstruct.ReportingPolicy; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @author XiangHan | ||
| 11 | * @date 2021-12-16 | ||
| 12 | */ | ||
| 13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
| 14 | public interface UserWeixinMapper extends BaseMapper<UserWeixinDTO, UserWeixin> { | ||
| 15 | |||
| 16 | } |
| 1 | package com.topdraw.business.process.domian; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Data; | ||
| 5 | import lombok.NoArgsConstructor; | ||
| 6 | |||
| 7 | import javax.persistence.Transient; | ||
| 8 | import java.sql.Timestamp; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * 权益-非持久化数据 | ||
| 12 | */ | ||
| 13 | @Data | ||
| 14 | @AllArgsConstructor | ||
| 15 | @NoArgsConstructor | ||
| 16 | public class TempCoupon extends TempRights { | ||
| 17 | |||
| 18 | @Transient | ||
| 19 | protected String code; | ||
| 20 | |||
| 21 | @Transient | ||
| 22 | protected Integer useStatus; | ||
| 23 | |||
| 24 | @Transient | ||
| 25 | protected Timestamp useTime; | ||
| 26 | |||
| 27 | /**领取时间*/ | ||
| 28 | @Transient | ||
| 29 | protected Timestamp receiveTime; | ||
| 30 | |||
| 31 | @Transient | ||
| 32 | protected String userNickname; | ||
| 33 | |||
| 34 | } |
| 1 | package com.topdraw.business.process.domian; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Data; | ||
| 5 | import lombok.NoArgsConstructor; | ||
| 6 | |||
| 7 | import javax.persistence.Transient; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * 权益-非持久化数据 | ||
| 11 | */ | ||
| 12 | @Data | ||
| 13 | @AllArgsConstructor | ||
| 14 | @NoArgsConstructor | ||
| 15 | public class TempExp extends TempRights { | ||
| 16 | |||
| 17 | // 获得成长值 | ||
| 18 | @Transient | ||
| 19 | protected Long rewardExp; | ||
| 20 | |||
| 21 | |||
| 22 | } |
| 1 | package com.topdraw.business.process.domian; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Data; | ||
| 5 | import lombok.NoArgsConstructor; | ||
| 6 | |||
| 7 | import javax.persistence.Transient; | ||
| 8 | |||
| 9 | @Data | ||
| 10 | @AllArgsConstructor | ||
| 11 | @NoArgsConstructor | ||
| 12 | public class TempIptvUser { | ||
| 13 | |||
| 14 | // 账户 | ||
| 15 | @Transient | ||
| 16 | private String platformAccount; | ||
| 17 | |||
| 18 | // 分数 | ||
| 19 | @Transient | ||
| 20 | private Long points; | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | } |
| 1 | package com.topdraw.business.process.domian; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Data; | ||
| 5 | import lombok.NoArgsConstructor; | ||
| 6 | import lombok.ToString; | ||
| 7 | |||
| 8 | import javax.persistence.Transient; | ||
| 9 | import javax.validation.constraints.NotNull; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * 权益-非持久化数据 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @AllArgsConstructor | ||
| 16 | @NoArgsConstructor | ||
| 17 | @ToString | ||
| 18 | public class TempPoints extends TempRights { | ||
| 19 | |||
| 20 | // 获得积分 | ||
| 21 | @Transient | ||
| 22 | @NotNull(message = "【points】积分数值不得为空!!") | ||
| 23 | protected Long points; | ||
| 24 | |||
| 25 | // 积分类型 0:通用 | ||
| 26 | @Transient | ||
| 27 | protected Integer pointsType; | ||
| 28 | |||
| 29 | @Transient | ||
| 30 | protected Long rewardPointsExpireTime; | ||
| 31 | |||
| 32 | } |
| 1 | package com.topdraw.business.process.domian; | ||
| 2 | |||
| 3 | import lombok.AllArgsConstructor; | ||
| 4 | import lombok.Data; | ||
| 5 | import lombok.NoArgsConstructor; | ||
| 6 | |||
| 7 | import javax.persistence.Transient; | ||
| 8 | import javax.validation.constraints.NotNull; | ||
| 9 | import java.time.LocalDateTime; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * 权益-非持久化数据 | ||
| 13 | */ | ||
| 14 | @Data | ||
| 15 | @AllArgsConstructor | ||
| 16 | @NoArgsConstructor | ||
| 17 | public class TempRights { | ||
| 18 | |||
| 19 | /** 主键 */ | ||
| 20 | @Transient | ||
| 21 | protected Long id; | ||
| 22 | |||
| 23 | /** 编号 */ | ||
| 24 | @Transient | ||
| 25 | protected String code; | ||
| 26 | |||
| 27 | /** 权益名称 */ | ||
| 28 | @Transient | ||
| 29 | protected String name; | ||
| 30 | |||
| 31 | /** 会员ID */ | ||
| 32 | @Transient | ||
| 33 | protected Long memberId; | ||
| 34 | |||
| 35 | /** 会员编号 */ | ||
| 36 | @Transient | ||
| 37 | protected String memberCode; | ||
| 38 | |||
| 39 | /** 账号id */ | ||
| 40 | @Transient | ||
| 41 | protected Long userId; | ||
| 42 | |||
| 43 | /** 发放策略 */ | ||
| 44 | @Transient | ||
| 45 | protected Integer rightsSendStrategy; | ||
| 46 | |||
| 47 | /** 账号id */ | ||
| 48 | @Transient | ||
| 49 | private Long accountId; | ||
| 50 | |||
| 51 | /** 过期时间 */ | ||
| 52 | @Transient | ||
| 53 | protected LocalDateTime expireTime; | ||
| 54 | |||
| 55 | |||
| 56 | /** 设备类型 1:大屏;2:小屏(微信)3.小屏(xx) */ | ||
| 57 | @Transient | ||
| 58 | @NotNull(message = "设备类型不得为空") | ||
| 59 | protected Integer deviceType; | ||
| 60 | |||
| 61 | /** 应用code(表示当前用户对应应用的标识) */ | ||
| 62 | @Transient | ||
| 63 | protected String appCode; | ||
| 64 | |||
| 65 | /** 订单id */ | ||
| 66 | @Transient | ||
| 67 | protected Long orderId; | ||
| 68 | |||
| 69 | /** 节目id(针对观影操作) */ | ||
| 70 | @Transient | ||
| 71 | protected Long mediaId; | ||
| 72 | |||
| 73 | /** 活动id(针对参与活动) */ | ||
| 74 | @Transient | ||
| 75 | protected Long activityId; | ||
| 76 | |||
| 77 | /** 商品id */ | ||
| 78 | @Transient | ||
| 79 | protected Long itemId; | ||
| 80 | |||
| 81 | /** 积分变化描述,用于管理侧显示 */ | ||
| 82 | @Transient | ||
| 83 | protected String description; | ||
| 84 | |||
| 85 | /** 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;98:系统操作;99:其他 */ | ||
| 86 | @Transient | ||
| 87 | protected Integer evtType; | ||
| 88 | |||
| 89 | /** 数量 */ | ||
| 90 | @Transient | ||
| 91 | protected Integer rightsAmount; | ||
| 92 | |||
| 93 | } |
| 1 | package com.topdraw.business.process.service; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
| 4 | import com.topdraw.business.basicdata.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; | ||
| 2 | |||
| 3 | import com.topdraw.business.process.domian.TempPoints; | ||
| 4 | |||
| 5 | import java.util.List; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @description 积分操作接口 | ||
| 9 | * @author XiangHan | ||
| 10 | * @date 2021.10.22 | ||
| 11 | */ | ||
| 12 | public interface PointsOperationService { | ||
| 13 | |||
| 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 | } |
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
| 4 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 5 | import com.topdraw.business.basicdata.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 | } |
| 1 | package com.topdraw.business.process.service.impl; | ||
| 2 | |||
| 3 | |||
| 4 | import com.topdraw.business.basicdata.member.domain.Member; | ||
| 5 | import com.topdraw.business.basicdata.member.service.MemberService; | ||
| 6 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
| 7 | import com.topdraw.business.basicdata.points.available.domain.PointsAvailable; | ||
| 8 | import com.topdraw.business.basicdata.points.available.service.PointsAvailableService; | ||
| 9 | import com.topdraw.business.basicdata.points.available.service.dto.PointsAvailableDTO; | ||
| 10 | import com.topdraw.business.basicdata.points.detail.detailhistory.service.PointsDetailHistoryService; | ||
| 11 | import com.topdraw.business.basicdata.points.detail.domain.PointsDetail; | ||
| 12 | import com.topdraw.business.basicdata.points.detail.service.PointsDetailService; | ||
| 13 | import com.topdraw.business.basicdata.points.service.PointsService; | ||
| 14 | import com.topdraw.business.process.domian.TempPoints; | ||
| 15 | import com.topdraw.business.process.service.MemberOperationService; | ||
| 16 | import com.topdraw.business.process.service.PointsOperationService; | ||
| 17 | import com.topdraw.util.IdWorker; | ||
| 18 | import com.topdraw.util.RedissonUtil; | ||
| 19 | import com.topdraw.util.TimestampUtil; | ||
| 20 | import com.topdraw.utils.StringUtils; | ||
| 21 | 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; | ||
| 27 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 28 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 29 | import org.springframework.stereotype.Service; | ||
| 30 | import org.springframework.transaction.annotation.Propagation; | ||
| 31 | import org.springframework.transaction.annotation.Transactional; | ||
| 32 | import org.springframework.util.CollectionUtils; | ||
| 33 | |||
| 34 | import java.sql.Timestamp; | ||
| 35 | import java.time.LocalDateTime; | ||
| 36 | import java.util.*; | ||
| 37 | import java.util.stream.Collectors; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * | ||
| 41 | */ | ||
| 42 | @Service | ||
| 43 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
| 44 | @Slf4j | ||
| 45 | public class PointsOperationServiceImpl implements PointsOperationService { | ||
| 46 | |||
| 47 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); | ||
| 48 | |||
| 49 | @Autowired | ||
| 50 | PointsService pointsService; | ||
| 51 | @Autowired | ||
| 52 | PointsDetailService pointsDetailService; | ||
| 53 | @Autowired | ||
| 54 | PointsAvailableService pointsAvailableService; | ||
| 55 | @Autowired | ||
| 56 | PointsDetailHistoryService pointsDetailHistoryService; | ||
| 57 | @Autowired | ||
| 58 | MemberOperationService memberOperationService; | ||
| 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 | |||
| 68 | @Autowired | ||
| 69 | RedissonClient redissonClient; | ||
| 70 | @Autowired | ||
| 71 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 72 | |||
| 73 | @Override | ||
| 74 | @Transactional(rollbackFor = Exception.class) | ||
| 75 | public void grantPointsByManual(Long memberId,TempPoints tempPoints){ | ||
| 76 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { | ||
| 77 | this.refresh(tempPoints); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | @Override | ||
| 82 | @Transactional(rollbackFor = Exception.class) | ||
| 83 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { | ||
| 84 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { | ||
| 85 | String memberCode = tempPoints.getMemberCode(); | ||
| 86 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 87 | if (Objects.nonNull(memberDTO)) { | ||
| 88 | Long memberId = memberDTO.getId(); | ||
| 89 | tempPoints.setMemberId(memberId); | ||
| 90 | this.refresh(tempPoints); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | /** | ||
| 97 | * 积分消耗 | ||
| 98 | * @param tempPoints 任务对象 | ||
| 99 | * @return true: 满足 false:不满足 | ||
| 100 | */ | ||
| 101 | @Override | ||
| 102 | @Transactional(rollbackFor = Exception.class) | ||
| 103 | public boolean customPoints(TempPoints tempPoints) { | ||
| 104 | |||
| 105 | String memberCode = tempPoints.getMemberCode(); | ||
| 106 | |||
| 107 | MemberDTO memberDTO = this.memberService.getByCode(memberCode); | ||
| 108 | |||
| 109 | if (Objects.nonNull(memberDTO)) { | ||
| 110 | |||
| 111 | Long memberId = memberDTO.getId(); | ||
| 112 | tempPoints.setMemberId(memberId); | ||
| 113 | RLock rLock = this.redissonClient.getLock("member::id::" + memberId.toString()); | ||
| 114 | try { | ||
| 115 | RedissonUtil.lock(rLock); | ||
| 116 | //1.删除过期的积分 | ||
| 117 | this.cleanInvalidAvailablePointsByMemberId(memberId); | ||
| 118 | // 1.判断可用积分是否够用 | ||
| 119 | boolean b = this.checkAvailablePoints(tempPoints); | ||
| 120 | log.info("customPoints-->>> 当前可用总积分大于待兑换的积分--->>" + b); | ||
| 121 | if (b) { | ||
| 122 | // 2.可用积分表,按照过期时间进行升序排列 | ||
| 123 | List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints); | ||
| 124 | // 3.当前可用总积分 | ||
| 125 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 126 | // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 | ||
| 127 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = this.customAvailablePoints(tempPoints, pointsAvailableDTOS); | ||
| 128 | // 3.添加积分明细 | ||
| 129 | this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); | ||
| 130 | // 4.更新可用积分表,超过的删除,剩余的新增 | ||
| 131 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); | ||
| 132 | // 5.即将过期的积分 | ||
| 133 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
| 134 | // 6.更新会员积分信息 | ||
| 135 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints); | ||
| 136 | |||
| 137 | return true; | ||
| 138 | } | ||
| 139 | }catch (Exception e) { | ||
| 140 | e.printStackTrace(); | ||
| 141 | throw e; | ||
| 142 | } finally { | ||
| 143 | RedissonUtil.unlock(rLock); | ||
| 144 | } | ||
| 145 | |||
| 146 | } | ||
| 147 | |||
| 148 | return false; | ||
| 149 | } | ||
| 150 | |||
| 151 | /** | ||
| 152 | * 更新可用积分表 | ||
| 153 | * @param customAvailablePointsMap | ||
| 154 | */ | ||
| 155 | private long doFreshTrPointsAvailableByAvailablePointsMap( | ||
| 156 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap,long currentPoints) { | ||
| 157 | |||
| 158 | long totalCustomAvailablePoints = 0L; | ||
| 159 | if (customAvailablePointsMap != null) { | ||
| 160 | // 需要删除的 | ||
| 161 | List<PointsAvailableDTO> pointsAvailableDTOS1 = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); | ||
| 162 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS1)) { | ||
| 163 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS1) { | ||
| 164 | totalCustomAvailablePoints = (totalCustomAvailablePoints+pointsAvailableDTO.getPoints()); | ||
| 165 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | // 需要添加的 | ||
| 170 | List<PointsAvailableDTO> pointsAvailableDTOS2 = customAvailablePointsMap.get(INSERT_AVAILABLE_POINTS); | ||
| 171 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS2)) { | ||
| 172 | PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS2.get(0); | ||
| 173 | PointsAvailable pointsAvailable = new PointsAvailable(); | ||
| 174 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailable); | ||
| 175 | pointsAvailable.setId(null); | ||
| 176 | pointsAvailable.setCode(String.valueOf(IdWorker.generator())); | ||
| 177 | this.pointsAvailableService.create4Custom(pointsAvailable); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | return currentPoints - totalCustomAvailablePoints; | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * 优先使用即将过期的积分,注意拆分 | ||
| 186 | * @param customAvailablePointsMap | ||
| 187 | */ | ||
| 188 | private void doInsertTrPointsDetailByAvailablePointsMap(TempPoints tempPoints, | ||
| 189 | Map<String, List<PointsAvailableDTO>> customAvailablePointsMap, | ||
| 190 | long currentPoints) { | ||
| 191 | // 兑换的积分 | ||
| 192 | Long points = tempPoints.getPoints(); | ||
| 193 | |||
| 194 | List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); | ||
| 195 | |||
| 196 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | ||
| 197 | PointsAvailableDTO pointsAvailableDTO = pointsAvailableDTOS.get(0); | ||
| 198 | Long memberId = pointsAvailableDTO.getMemberId(); | ||
| 199 | |||
| 200 | TempPoints tempPoints1 = new TempPoints(); | ||
| 201 | BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); | ||
| 202 | BeanUtils.copyProperties(tempPoints,tempPoints1); | ||
| 203 | tempPoints1.setPoints(-(Math.abs(points))); | ||
| 204 | Long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints); | ||
| 205 | this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * 消耗过期的积分 | ||
| 211 | * @param tempPoints 需要消耗的积分 | ||
| 212 | * @param pointsAvailableDTOS 可用积分列表 | ||
| 213 | * @return List<PointsAvailableDTO> 已消耗的可用积分列表 | ||
| 214 | */ | ||
| 215 | private Map<String,List<PointsAvailableDTO>> customAvailablePoints(TempPoints tempPoints, List<PointsAvailableDTO> pointsAvailableDTOS) { | ||
| 216 | // 兑换的积分 | ||
| 217 | Long points = tempPoints.getPoints(); | ||
| 218 | Long points1_ = 0L; | ||
| 219 | List<PointsAvailableDTO> pointsAvailableDTOS1 = new ArrayList<>(); | ||
| 220 | List<PointsAvailableDTO> pointsAvailableDTOS2 = new ArrayList<>(); | ||
| 221 | Map<String,List<PointsAvailableDTO>> map = new HashMap<>(); | ||
| 222 | |||
| 223 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | ||
| 224 | Long points1 = pointsAvailableDTO.getPoints(); | ||
| 225 | points1_ = (points1_ + points1); | ||
| 226 | |||
| 227 | // 不够 | ||
| 228 | if (points1_ < points) { | ||
| 229 | pointsAvailableDTOS1.add(pointsAvailableDTO); | ||
| 230 | continue; | ||
| 231 | } | ||
| 232 | |||
| 233 | // 刚好 | ||
| 234 | if (points1_ == points) { | ||
| 235 | pointsAvailableDTOS1.add(pointsAvailableDTO); | ||
| 236 | break; | ||
| 237 | } | ||
| 238 | |||
| 239 | // 超了,拆分 | ||
| 240 | if (points1_ > points) { | ||
| 241 | |||
| 242 | // 超过的 | ||
| 243 | long beyond = points1_ - points; | ||
| 244 | // 新增 | ||
| 245 | PointsAvailableDTO pointsAvailableDTO2 = new PointsAvailableDTO(); | ||
| 246 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO2); | ||
| 247 | pointsAvailableDTO2.setPoints(beyond); | ||
| 248 | pointsAvailableDTOS2.add(pointsAvailableDTO2); | ||
| 249 | |||
| 250 | // 剩余的 | ||
| 251 | long suit = points1 - beyond; | ||
| 252 | // 扣除 | ||
| 253 | PointsAvailableDTO pointsAvailableDTO1 = new PointsAvailableDTO(); | ||
| 254 | BeanUtils.copyProperties(pointsAvailableDTO,pointsAvailableDTO1); | ||
| 255 | pointsAvailableDTO1.setPoints(suit); | ||
| 256 | pointsAvailableDTOS1.add(pointsAvailableDTO1); | ||
| 257 | |||
| 258 | break; | ||
| 259 | } | ||
| 260 | |||
| 261 | } | ||
| 262 | |||
| 263 | map.put(DELETE_AVAILABLE_POINTS,pointsAvailableDTOS1); | ||
| 264 | map.put(INSERT_AVAILABLE_POINTS,pointsAvailableDTOS2); | ||
| 265 | |||
| 266 | return map; | ||
| 267 | } | ||
| 268 | |||
| 269 | /** | ||
| 270 | * 可用积分表,按照过期时间进行升序排列 | ||
| 271 | * @param tempPoints | ||
| 272 | * @return | ||
| 273 | */ | ||
| 274 | private List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(TempPoints tempPoints) { | ||
| 275 | return this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId()); | ||
| 276 | } | ||
| 277 | |||
| 278 | /** | ||
| 279 | * 检查当前用户可用积分是否足够 | ||
| 280 | * @param tempPoints | ||
| 281 | * @return true : 满足 false: 不满足 | ||
| 282 | */ | ||
| 283 | private boolean checkAvailablePoints(TempPoints tempPoints) { | ||
| 284 | Long memberId = tempPoints.getMemberId(); | ||
| 285 | // 可用积分 | ||
| 286 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 287 | long points1 = tempPoints.getPoints(); | ||
| 288 | if (currentPoints > 0 && points1 > 0 && (currentPoints - Math.abs(points1) >= 0)) { | ||
| 289 | return true; | ||
| 290 | } | ||
| 291 | return false; | ||
| 292 | } | ||
| 293 | |||
| 294 | /** | ||
| 295 | * 积分发放,基于已获得的权益 | ||
| 296 | * | ||
| 297 | * @param tempPointsList 已获得的权益 | ||
| 298 | */ | ||
| 299 | @Override | ||
| 300 | @Transactional(rollbackFor = Exception.class) | ||
| 301 | public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){ | ||
| 302 | log.info("------->>grantPointsThroughTempRightsList start1"); | ||
| 303 | for (TempPoints tempPoints : tempPointsList){ | ||
| 304 | log.info("------->>grantPointsThroughTempRightsList start"); | ||
| 305 | this.refresh(tempPoints); | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * 清理过期积分 | ||
| 311 | * @param memberId | ||
| 312 | */ | ||
| 313 | private void cleanInvalidAvailablePointsByMemberId(Long memberId) { | ||
| 314 | List<PointsAvailableDTO> pointsAvailableDTOS = | ||
| 315 | pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,LocalDateTime.now()); | ||
| 316 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | ||
| 317 | //1.获取原始积分 | ||
| 318 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | ||
| 319 | // 添加积分明细 uc_points_detail | ||
| 320 | this.doCreatePointsDetail(pointsAvailableDTO); | ||
| 321 | // 删除已过期的积分 | ||
| 322 | this.doDeleteInvalidAvailablePoints(pointsAvailableDTO); | ||
| 323 | } | ||
| 324 | |||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | @Override | ||
| 329 | public Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId) { | ||
| 330 | |||
| 331 | // 清理当前用户的过期积分 | ||
| 332 | this.cleanInvalidAvailablePointsByMemberId(memberId); | ||
| 333 | // 获取当前用户的可用总积分 | ||
| 334 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 335 | // 即将过期的积分 | ||
| 336 | long soonExpirePoints = this.getSoonExpirePoints(memberId, null); | ||
| 337 | // 更新会员信息 | ||
| 338 | this.doUpdateMemberPoints(memberId,currentPoints,soonExpirePoints); | ||
| 339 | |||
| 340 | return currentPoints; | ||
| 341 | } | ||
| 342 | |||
| 343 | /** | ||
| 344 | * 获取可用总积分 | ||
| 345 | * @param memberId | ||
| 346 | * @return | ||
| 347 | */ | ||
| 348 | private long findAvailablePointsByMemberId(Long memberId){ | ||
| 349 | return this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
| 350 | } | ||
| 351 | |||
| 352 | /** | ||
| 353 | * 修改会员信息 | ||
| 354 | * @param memberId | ||
| 355 | * @param currentPoints | ||
| 356 | */ | ||
| 357 | private void doUpdateMemberPoints(Long memberId, long currentPoints,long soonExpirePoints) { | ||
| 358 | Member member = new Member(); | ||
| 359 | member.setId(memberId); | ||
| 360 | member.setPoints(currentPoints); | ||
| 361 | member.setDuePoints(soonExpirePoints); | ||
| 362 | this.memberOperationService.doUpdateMemberPoints(member); | ||
| 363 | } | ||
| 364 | |||
| 365 | /** | ||
| 366 | * | ||
| 367 | * @param pointsAvailableDTOS | ||
| 368 | */ | ||
| 369 | private void doDeleteBatchInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) { | ||
| 370 | List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList()); | ||
| 371 | this.pointsAvailableService.deleteBatchByIds(collect); | ||
| 372 | } | ||
| 373 | |||
| 374 | /** | ||
| 375 | * | ||
| 376 | * @param pointsAvailableDTO | ||
| 377 | */ | ||
| 378 | private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) { | ||
| 379 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); | ||
| 380 | } | ||
| 381 | |||
| 382 | /** | ||
| 383 | * 可用积分 | ||
| 384 | * @param pointsAvailableDTO | ||
| 385 | */ | ||
| 386 | private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) { | ||
| 387 | |||
| 388 | Long memberId = pointsAvailableDTO.getMemberId(); | ||
| 389 | // 原始积分 | ||
| 390 | long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId); | ||
| 391 | // 过期积分 | ||
| 392 | long l = pointsAvailableDTO.getPoints(); | ||
| 393 | // 结果积分 | ||
| 394 | long resultPoints = availablePoints - l; | ||
| 395 | |||
| 396 | PointsDetail pointsDetail = new PointsDetail(); | ||
| 397 | BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail); | ||
| 398 | pointsDetail.setId(null); | ||
| 399 | pointsDetail.setPoints(-Math.abs(l)); | ||
| 400 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 401 | pointsDetail.setOriginalPoints(availablePoints); | ||
| 402 | pointsDetail.setResultPoints(resultPoints); | ||
| 403 | pointsDetail.setDescription("过期积分"); | ||
| 404 | pointsDetail.setEvtType(99); | ||
| 405 | pointsDetail.setCreateTime(TimestampUtil.now()); | ||
| 406 | pointsDetail.setUpdateTime(TimestampUtil.now()); | ||
| 407 | this.doInsertPointsDetail(pointsDetail); | ||
| 408 | } | ||
| 409 | |||
| 410 | /** | ||
| 411 | * 模板方法,提供更新积分的总体流程 | ||
| 412 | * | ||
| 413 | * @param tempPoints 积分 | ||
| 414 | */ | ||
| 415 | private void refresh(TempPoints tempPoints) { | ||
| 416 | Long memberId = tempPoints.getMemberId(); | ||
| 417 | log.info("----------->> points refresh start"); | ||
| 418 | RLock rLock = this.redissonClient.getLock("member::id::" + memberId.toString()); | ||
| 419 | log.info("----------->> rLock --->> start" ); | ||
| 420 | try { | ||
| 421 | RedissonUtil.lock(rLock); | ||
| 422 | log.info("----------->> refresh findAvailablePointsByMemberId start"); | ||
| 423 | // 1.可用总积分 | ||
| 424 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); | ||
| 425 | log.info("----------->> refresh findAvailablePointsByMemberId currentPoints " + currentPoints); | ||
| 426 | |||
| 427 | // 2.计算总积分 | ||
| 428 | Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); | ||
| 429 | log.info("----------->> refresh findAvailablePointsByMemberId totalPoints " + totalPoints); | ||
| 430 | |||
| 431 | // 3.添加积分明细,并计算总积分 | ||
| 432 | this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); | ||
| 433 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail end "); | ||
| 434 | |||
| 435 | // 4.添加可用积分 | ||
| 436 | log.info("----------->> refresh doInsertTrPointsAvailable start "); | ||
| 437 | this.doInsertTrPointsAvailable(tempPoints); | ||
| 438 | log.info("----------->> refresh doInsertTrPointsAvailable end "); | ||
| 439 | |||
| 440 | // 即将过期的积分 | ||
| 441 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
| 442 | |||
| 443 | // 6.更新会员的总积分 | ||
| 444 | log.info("----------->> refresh freshMemberCurrentPoints start "); | ||
| 445 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints,tempPoints); | ||
| 446 | log.info("----------->> refresh freshMemberCurrentPoints end "); | ||
| 447 | |||
| 448 | } catch (Exception e) { | ||
| 449 | e.printStackTrace(); | ||
| 450 | throw e; | ||
| 451 | } finally { | ||
| 452 | RedissonUtil.unlock(rLock); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | /** | ||
| 457 | * 获取总积分 | ||
| 458 | * @param tempPoints | ||
| 459 | * @param currentPoints | ||
| 460 | * @return | ||
| 461 | */ | ||
| 462 | private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) { | ||
| 463 | // 获取的积分 | ||
| 464 | Long rewardPoints = tempPoints.getPoints(); | ||
| 465 | // 总积分 | ||
| 466 | Long totalPoints = currentPoints + rewardPoints; | ||
| 467 | return totalPoints; | ||
| 468 | } | ||
| 469 | |||
| 470 | /** | ||
| 471 | * 获取即将过期的积分 | ||
| 472 | * @param memberId | ||
| 473 | * @return | ||
| 474 | */ | ||
| 475 | private long getSoonExpirePoints(Long memberId,TempPoints tempPoints) { | ||
| 476 | // 计算即将过期的天数 | ||
| 477 | Integer factor = this.calculateExpireFactor(tempPoints); | ||
| 478 | if (Objects.isNull(factor)) { | ||
| 479 | factor = EXPIRE_FACTOR; | ||
| 480 | } | ||
| 481 | |||
| 482 | Long soonExpireTime = this.pointsAvailableService.findSoonExpireTime(memberId, factor); | ||
| 483 | return Objects.nonNull(soonExpireTime) ? soonExpireTime : 0L; | ||
| 484 | } | ||
| 485 | |||
| 486 | /** | ||
| 487 | * 如果过期时间和过期天数同时存在,则以过期时间为准 | ||
| 488 | * @param tempPoints | ||
| 489 | * @return | ||
| 490 | */ | ||
| 491 | private Integer calculateExpireFactor(TempPoints tempPoints) { | ||
| 492 | // TODO 计算过期的相对时间 | ||
| 493 | return null; | ||
| 494 | } | ||
| 495 | |||
| 496 | /** | ||
| 497 | * 更新会员总积分 | ||
| 498 | * @param memberId 会员Id | ||
| 499 | * @param currentPoints 当前总积分 | ||
| 500 | */ | ||
| 501 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints,TempPoints tempPoints) { | ||
| 502 | Member member = new Member(); | ||
| 503 | member.setId(memberId); | ||
| 504 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); | ||
| 505 | member.setDuePoints(duePoints); | ||
| 506 | member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); | ||
| 507 | member.setCode(tempPoints.getMemberCode()); | ||
| 508 | try { | ||
| 509 | this.memberOperationService.doUpdateMemberPoints(member); | ||
| 510 | } catch (Exception e){ | ||
| 511 | throw e; | ||
| 512 | } | ||
| 513 | } | ||
| 514 | |||
| 515 | /** | ||
| 516 | * 计算当前总积分 | ||
| 517 | * @param memberId 会员id | ||
| 518 | * @return | ||
| 519 | */ | ||
| 520 | private Long findAvailablePointsByMemberId(long memberId){ | ||
| 521 | Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
| 522 | return Objects.nonNull(availablePoints) ? availablePoints : 0L; | ||
| 523 | } | ||
| 524 | |||
| 525 | /** | ||
| 526 | * 更新可用积分表 | ||
| 527 | * @param tempPoints | ||
| 528 | */ | ||
| 529 | private void doInsertTrPointsAvailable(TempPoints tempPoints){ | ||
| 530 | |||
| 531 | PointsAvailable pointsAvailable = new PointsAvailable(); | ||
| 532 | BeanUtils.copyProperties(tempPoints,pointsAvailable); | ||
| 533 | String description = pointsAvailable.getDescription(); | ||
| 534 | pointsAvailable.setCode(String.valueOf(IdWorker.generator())); | ||
| 535 | pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description); | ||
| 536 | LocalDateTime timestamp = tempPoints.getExpireTime(); | ||
| 537 | if (Objects.nonNull(timestamp)) { | ||
| 538 | pointsAvailable.setExpireTime(timestamp); | ||
| 539 | } | ||
| 540 | |||
| 541 | // 添加可用积分记录 | ||
| 542 | this.doInsertTrPointsAvailable(pointsAvailable); | ||
| 543 | |||
| 544 | } | ||
| 545 | |||
| 546 | /** | ||
| 547 | * 添加可用积分记录 | ||
| 548 | * @param pointsAvailable 可用积分 | ||
| 549 | */ | ||
| 550 | private void doInsertTrPointsAvailable(PointsAvailable pointsAvailable) { | ||
| 551 | this.pointsAvailableService.create(pointsAvailable); | ||
| 552 | } | ||
| 553 | |||
| 554 | /** | ||
| 555 | * 添加积分明细 | ||
| 556 | * @param memberId 会员Id | ||
| 557 | * @param tempPoints 积分 | ||
| 558 | * @return Integer 总积分 | ||
| 559 | */ | ||
| 560 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){ | ||
| 561 | |||
| 562 | PointsDetail pointsDetail = new PointsDetail(); | ||
| 563 | BeanUtils.copyProperties(tempPoints,pointsDetail); | ||
| 564 | pointsDetail.setId(null); | ||
| 565 | pointsDetail.setMemberId(memberId); | ||
| 566 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | ||
| 567 | pointsDetail.setPoints(tempPoints.getPoints()); | ||
| 568 | pointsDetail.setOriginalPoints(currentPoints); | ||
| 569 | pointsDetail.setResultPoints(totalPoints); | ||
| 570 | pointsDetail.setCreateTime(null); | ||
| 571 | pointsDetail.setUpdateTime(null); | ||
| 572 | String description = pointsDetail.getDescription(); | ||
| 573 | if (StringUtils.isEmpty(description)) { | ||
| 574 | pointsDetail.setDescription("#"); | ||
| 575 | } | ||
| 576 | |||
| 577 | // 保存积分流水 | ||
| 578 | this.doInsertPointsDetail(pointsDetail); | ||
| 579 | |||
| 580 | } | ||
| 581 | |||
| 582 | /** | ||
| 583 | * | ||
| 584 | * @param pointsDetail | ||
| 585 | */ | ||
| 586 | private void doInsertPointsDetail(PointsDetail pointsDetail){ | ||
| 587 | this.pointsDetailService.create4Custom(pointsDetail); | ||
| 588 | } | ||
| 589 | } |
| ... | @@ -8,9 +8,30 @@ public class LocalConstants { | ... | @@ -8,9 +8,30 @@ public class LocalConstants { |
| 8 | // 大屏侧 | 8 | // 大屏侧 |
| 9 | public static final String ENV_VIS = "vis"; | 9 | public static final String ENV_VIS = "vis"; |
| 10 | 10 | ||
| 11 | // 服务侧 | ||
| 12 | public static final String ENV_SERVICE = "service"; | ||
| 13 | |||
| 14 | // 管理侧 | ||
| 15 | public static final String ENV_MANAGEMENT = "management"; | ||
| 16 | |||
| 11 | // 大屏类型 | 17 | // 大屏类型 |
| 12 | public static final int DEVICE_VIS = 1; | 18 | public static final int DEVICE_VIS = 1; |
| 13 | 19 | ||
| 14 | // 小屏类型 | 20 | // 小屏类型 |
| 15 | public static final int DEVICE_MOBILE = 2; | 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; | ||
| 16 | } | 37 | } | ... | ... |
| ... | @@ -17,84 +17,102 @@ import org.springframework.context.annotation.Primary; | ... | @@ -17,84 +17,102 @@ import org.springframework.context.annotation.Primary; |
| 17 | public class RabbitMqConfig { | 17 | public class RabbitMqConfig { |
| 18 | 18 | ||
| 19 | /** 路由(事件)--direct route.key*/ | 19 | /** 路由(事件)--direct route.key*/ |
| 20 | // 事件,uc-gateway | ||
| 20 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_AAA = "uc.route.key.direct.event.aaa"; | 21 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_AAA = "uc.route.key.direct.event.aaa"; |
| 22 | // uc-service 服务侧 | ||
| 23 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_BBB = "uc.route.key.direct.event.bbb"; | ||
| 24 | // uc-service 管理侧 | ||
| 25 | public static final String UC_ROUTE_KEY_DIRECT_EVENT_CCC = "uc.route.key.direct.event.ccc"; | ||
| 21 | 26 | ||
| 22 | /** 队列-- */ | 27 | @Value("${mutil-mq.service.host}") |
| 23 | public static final String UC_QUEUE_FANOUT_IPTV = "uc.fanout.iptv"; | 28 | private String serviceHost; |
| 24 | public static final String UC_QUEUE_FANOUT_WEIXIN = "uc.fanout.weixin"; | 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; | ||
| 25 | 37 | ||
| 26 | public static final String UC_EXCHANGE_FANOUT = "uc.fanout"; | 38 | @Bean(name = "serviceConnectionFactory") |
| 27 | |||
| 28 | |||
| 29 | @Bean(name = "userCenterConnectionFactory") | ||
| 30 | @Primary | 39 | @Primary |
| 31 | public ConnectionFactory userCenterConnectionFactory(){ | 40 | public ConnectionFactory serviceConnectionFactory(){ |
| 32 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 33 | /*connectionFactory.setHost("47.100.212.170"); | ||
| 34 | connectionFactory.setPort(5672); | ||
| 35 | connectionFactory.setUsername("test"); | ||
| 36 | connectionFactory.setPassword("test"); | ||
| 37 | connectionFactory.setVirtualHost("/");*/ | ||
| 38 | connectionFactory.setHost("172.23.51.109"); | ||
| 39 | connectionFactory.setPort(5672); | ||
| 40 | connectionFactory.setUsername("admin"); | ||
| 41 | connectionFactory.setPassword("Tjlh@2021"); | ||
| 42 | // connectionFactory.setVirtualHost("member_center"); | ||
| 43 | connectionFactory.setVirtualHost("/"); | ||
| 44 | return connectionFactory; | ||
| 45 | } | ||
| 46 | |||
| 47 | @Bean(name = "memberServiceConnectionFactory") | ||
| 48 | public ConnectionFactory memberServiceConnectionFactory(){ | ||
| 49 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | 41 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); |
| 50 | /*connectionFactory.setHost("139.196.145.150"); | 42 | /*connectionFactory.setHost("139.196.145.150"); |
| 51 | connectionFactory.setPort(5672); | 43 | connectionFactory.setPort(5672); |
| 52 | connectionFactory.setUsername("admin"); | 44 | connectionFactory.setUsername("admin"); |
| 53 | connectionFactory.setPassword("Topdraw1qaz"); | 45 | connectionFactory.setPassword("Topdraw1qaz"); |
| 54 | connectionFactory.setVirtualHost("member_center");*/ | 46 | connectionFactory.setVirtualHost("member_center");*/ |
| 55 | connectionFactory.setHost("172.0.31.108"); | 47 | |
| 56 | connectionFactory.setPort(5672); | 48 | connectionFactory.setHost(serviceHost); |
| 57 | connectionFactory.setUsername("admin"); | 49 | connectionFactory.setPort(servicePort); |
| 58 | connectionFactory.setPassword("Tjlh@2021"); | 50 | connectionFactory.setUsername(serviceUserName); |
| 59 | connectionFactory.setVirtualHost("member_center"); | 51 | connectionFactory.setPassword(servicePassword); |
| 52 | connectionFactory.setVirtualHost(serviceVirtualHost); | ||
| 60 | return connectionFactory; | 53 | return connectionFactory; |
| 61 | } | 54 | } |
| 62 | 55 | ||
| 63 | @Bean(name = "userCenterRabbitListenerContainerFactory") | 56 | @Bean(name = "serviceRabbitListenerContainerFactory") |
| 64 | @Primary | 57 | @Primary |
| 65 | public RabbitListenerContainerFactory userCenterRabbitListenerContainerFactory( | 58 | public RabbitListenerContainerFactory userCenterRabbitListenerContainerFactory( |
| 66 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | 59 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, |
| 67 | @Qualifier("userCenterConnectionFactory") ConnectionFactory connectionFactory) { | 60 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { |
| 68 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | 61 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); |
| 69 | containerFactoryConfigurer.configure(factory,connectionFactory); | 62 | containerFactoryConfigurer.configure(factory,connectionFactory); |
| 70 | return factory; | 63 | return factory; |
| 71 | } | 64 | } |
| 72 | 65 | ||
| 66 | @Bean(name = "serviceRabbitTemplate") | ||
| 67 | public RabbitTemplate userCenterRabbitTemplate(ConnectionFactory ucServiceConnectionFactory){ | ||
| 68 | RabbitTemplate u = new RabbitTemplate(ucServiceConnectionFactory); | ||
| 69 | return u; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | @Value("${mutil-mq.management.host}") | ||
| 75 | private String managementHost; | ||
| 76 | @Value("${mutil-mq.management.port}") | ||
| 77 | private Integer managementPort; | ||
| 78 | @Value("${mutil-mq.management.username}") | ||
| 79 | private String managementUserName; | ||
| 80 | @Value("${mutil-mq.management.password}") | ||
| 81 | private String managementPassword; | ||
| 82 | @Value("${mutil-mq.management.virtual-host}") | ||
| 83 | private String managementVirtualHost; | ||
| 73 | 84 | ||
| 74 | @Bean(name = "memberServiceRabbitListenerContainerFactory") | 85 | @Bean(name = "managementConnectionFactory") |
| 86 | public ConnectionFactory managementConnectionFactory(){ | ||
| 87 | CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | ||
| 88 | /*connectionFactory.setHost("139.196.192.242"); | ||
| 89 | connectionFactory.setPort(5672); | ||
| 90 | connectionFactory.setUsername("member_center"); | ||
| 91 | connectionFactory.setPassword("Tjlh@2021"); | ||
| 92 | connectionFactory.setVirtualHost("member_center");*/ | ||
| 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 = "managementRabbitListenerContainerFactory") | ||
| 75 | public RabbitListenerContainerFactory memberServiceRabbitListenerContainerFactory( | 102 | public RabbitListenerContainerFactory memberServiceRabbitListenerContainerFactory( |
| 76 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | 103 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, |
| 77 | @Qualifier("memberServiceConnectionFactory") ConnectionFactory connectionFactory) { | 104 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { |
| 78 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | 105 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); |
| 79 | containerFactoryConfigurer.configure(factory,connectionFactory); | 106 | containerFactoryConfigurer.configure(factory,connectionFactory); |
| 80 | return factory; | 107 | return factory; |
| 81 | } | 108 | } |
| 82 | 109 | ||
| 83 | /* | 110 | @Bean(name = "managementRabbitTemplate") |
| 84 | @Bean(name = "userCenterRabbitTemplate") | 111 | public RabbitTemplate memberServiceRabbitTemplate(ConnectionFactory ucGatewayConnectionFactory){ |
| 85 | public RabbitTemplate userCenterRabbitTemplate(ConnectionFactory userCenterConnectionFactory){ | 112 | RabbitTemplate u = new RabbitTemplate(ucGatewayConnectionFactory); |
| 86 | RabbitTemplate u = new RabbitTemplate(userCenterConnectionFactory); | ||
| 87 | return u; | 113 | return u; |
| 88 | } | 114 | } |
| 89 | 115 | ||
| 90 | @Bean(name = "memberServiceRabbitTemplate") | ||
| 91 | public RabbitTemplate memberServiceRabbitTemplate(ConnectionFactory memberServiceConnectionFactory){ | ||
| 92 | RabbitTemplate u = new RabbitTemplate(memberServiceConnectionFactory); | ||
| 93 | return u; | ||
| 94 | } | ||
| 95 | */ | ||
| 96 | |||
| 97 | |||
| 98 | /** | 116 | /** |
| 99 | * 处理事件 | 117 | * 处理事件 |
| 100 | * @return org.springframework.amqp.core.Queue | 118 | * @return org.springframework.amqp.core.Queue | ... | ... |
| 1 | package com.topdraw.config; | ||
| 2 | |||
| 3 | import com.topdraw.utils.StringUtils; | ||
| 4 | import org.redisson.Redisson; | ||
| 5 | import org.redisson.config.Config; | ||
| 6 | import org.springframework.beans.factory.annotation.Value; | ||
| 7 | import org.springframework.context.annotation.Bean; | ||
| 8 | import org.springframework.context.annotation.Configuration; | ||
| 9 | |||
| 10 | @Configuration | ||
| 11 | public class RedissonConfig { | ||
| 12 | |||
| 13 | @Value("${spring.redis.host}") | ||
| 14 | private String redisHost; | ||
| 15 | |||
| 16 | @Value("${spring.redis.port}") | ||
| 17 | private String port; | ||
| 18 | |||
| 19 | @Value("${spring.redis.password}") | ||
| 20 | private String password; | ||
| 21 | |||
| 22 | @Bean | ||
| 23 | public Redisson redisson(){ | ||
| 24 | Config config = new Config(); | ||
| 25 | if (StringUtils.isNotEmpty(password)) { | ||
| 26 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password); | ||
| 27 | } else { | ||
| 28 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port); | ||
| 29 | } | ||
| 30 | /* config.useClusterServers().addNodeAddress( | ||
| 31 | "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377", | ||
| 32 | "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380") | ||
| 33 | .setPassword("a123456").setScanInterval(5000);*/ | ||
| 34 | Redisson redissonClient = (Redisson)Redisson.create(config); | ||
| 35 | return redissonClient; | ||
| 36 | } | ||
| 37 | |||
| 38 | } |
| ... | @@ -7,10 +7,10 @@ import org.springframework.stereotype.Component; | ... | @@ -7,10 +7,10 @@ import org.springframework.stereotype.Component; |
| 7 | @Component | 7 | @Component |
| 8 | public class ServiceEnvConfig { | 8 | public class ServiceEnvConfig { |
| 9 | 9 | ||
| 10 | // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 | 10 | // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧 |
| 11 | public static String UC_SERVICE_TYPE; | 11 | public static String UC_SERVICE_TYPE; |
| 12 | 12 | ||
| 13 | @Value("${uc.service.type:mobile}") | 13 | @Value("${service.area:mobile}") |
| 14 | public void setUcServiceType(String ucServiceType) { | 14 | public void setUcServiceType(String ucServiceType) { |
| 15 | UC_SERVICE_TYPE = ucServiceType; | 15 | UC_SERVICE_TYPE = ucServiceType; |
| 16 | } | 16 | } |
| ... | @@ -23,4 +23,21 @@ public class ServiceEnvConfig { | ... | @@ -23,4 +23,21 @@ public class ServiceEnvConfig { |
| 23 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS); | 23 | return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS); |
| 24 | } | 24 | } |
| 25 | 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 | |||
| 26 | } | 43 | } | ... | ... |
| 1 | package com.topdraw.mq.consumer; | 1 | package com.topdraw.mq.consumer; |
| 2 | 2 | ||
| 3 | import com.topdraw.config.ServiceEnvConfig; | ||
| 4 | import com.topdraw.config.RabbitMqConfig; | 3 | import com.topdraw.config.RabbitMqConfig; |
| 5 | import com.topdraw.mq.domain.TableOperationMsg; | 4 | import com.topdraw.mq.domain.TableOperationMsg; |
| 6 | import com.topdraw.util.JSONUtil; | 5 | import com.topdraw.util.JSONUtil; |
| ... | @@ -14,9 +13,9 @@ import org.springframework.stereotype.Component; | ... | @@ -14,9 +13,9 @@ import org.springframework.stereotype.Component; |
| 14 | 13 | ||
| 15 | @Component | 14 | @Component |
| 16 | @Slf4j | 15 | @Slf4j |
| 17 | public class MemberServiceConsumer { | 16 | public class UcEngineManageConsumer { |
| 18 | 17 | ||
| 19 | private static final Logger LOG = LoggerFactory.getLogger(MemberServiceConsumer.class); | 18 | private static final Logger LOG = LoggerFactory.getLogger(UcEngineManageConsumer.class); |
| 20 | 19 | ||
| 21 | @Autowired | 20 | @Autowired |
| 22 | AutoRoute autoUser; | 21 | AutoRoute autoUser; |
| ... | @@ -27,13 +26,11 @@ public class MemberServiceConsumer { | ... | @@ -27,13 +26,11 @@ public class MemberServiceConsumer { |
| 27 | * @author Hongyan Wang | 26 | * @author Hongyan Wang |
| 28 | * @date 2021/9/7 11:26 上午 | 27 | * @date 2021/9/7 11:26 上午 |
| 29 | */ | 28 | */ |
| 30 | @RabbitHandler | 29 | /*@RabbitHandler |
| 31 | // @RabbitListener(queues = "#{memberServiceConsumer.platform()}") | ||
| 32 | @RabbitListener(bindings = { | 30 | @RabbitListener(bindings = { |
| 33 | @QueueBinding(value = @Queue(value = "#{memberServiceConsumer.platform()}"), | 31 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_CCC), |
| 34 | exchange = @Exchange(value = RabbitMqConfig.UC_EXCHANGE_FANOUT,type = ExchangeTypes.FANOUT)) | 32 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) |
| 35 | } | 33 | }, containerFactory = "managementRabbitListenerContainerFactory") |
| 36 | ,containerFactory = "memberServiceRabbitListenerContainerFactory") | ||
| 37 | public void memberServiceFanoutConsumer(String content) { | 34 | public void memberServiceFanoutConsumer(String content) { |
| 38 | try { | 35 | try { |
| 39 | log.info(" receive dataSync msg , content is : {} ", content); | 36 | log.info(" receive dataSync msg , content is : {} ", content); |
| ... | @@ -43,21 +40,5 @@ public class MemberServiceConsumer { | ... | @@ -43,21 +40,5 @@ public class MemberServiceConsumer { |
| 43 | } catch (Exception e) { | 40 | } catch (Exception e) { |
| 44 | log.error(" LocalDataSyncMsg || msg:{} || error:{} ", content, e.getMessage()); | 41 | log.error(" LocalDataSyncMsg || msg:{} || error:{} ", content, e.getMessage()); |
| 45 | } | 42 | } |
| 46 | } | 43 | }*/ |
| 47 | |||
| 48 | /** | ||
| 49 | * @return java.lang.String | ||
| 50 | * @description 根据环境获取队列名称 | ||
| 51 | * @author Hongyan Wang | ||
| 52 | * @date 2021/9/8 4:00 下午 | ||
| 53 | */ | ||
| 54 | public String platform() { | ||
| 55 | String platform = ""; | ||
| 56 | if (ServiceEnvConfig.isMobile()) { | ||
| 57 | platform = RabbitMqConfig.UC_QUEUE_FANOUT_WEIXIN; | ||
| 58 | } else { | ||
| 59 | if (ServiceEnvConfig.isVis()) platform = RabbitMqConfig.UC_QUEUE_FANOUT_IPTV; | ||
| 60 | } | ||
| 61 | return platform; | ||
| 62 | } | ||
| 63 | } | 44 | } | ... | ... |
| 1 | package com.topdraw.mq.consumer; | ||
| 2 | |||
| 3 | import com.topdraw.config.RabbitMqConfig; | ||
| 4 | import com.topdraw.mq.domain.TableOperationMsg; | ||
| 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 | |||
| 13 | @Component | ||
| 14 | @Slf4j | ||
| 15 | public class UcEngineServiceConsumer { | ||
| 16 | |||
| 17 | @Autowired | ||
| 18 | RestTemplateClient restTemplateClient; | ||
| 19 | |||
| 20 | @Autowired | ||
| 21 | AutoRoute autoUser; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * 事件 | ||
| 25 | * @param content | ||
| 26 | * @description 基础数据同步 | ||
| 27 | * @author Hongyan Wang | ||
| 28 | * @date 2021/9/7 11:26 上午 | ||
| 29 | */ | ||
| 30 | @RabbitHandler | ||
| 31 | @RabbitListener(bindings = { | ||
| 32 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_BBB), | ||
| 33 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | ||
| 34 | }, containerFactory = "serviceRabbitListenerContainerFactory") | ||
| 35 | public void ucEventConsumer(String content) { | ||
| 36 | log.info(" receive dataSync msg , content is : {} ", content); | ||
| 37 | TableOperationMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, TableOperationMsg.class); | ||
| 38 | autoUser.route(dataSyncMsg); | ||
| 39 | log.info("ucEventConsumer ====>>>> end"); | ||
| 40 | } | ||
| 41 | |||
| 42 | } |
| ... | @@ -5,6 +5,7 @@ import com.topdraw.mq.domain.DataSyncMsg; | ... | @@ -5,6 +5,7 @@ import com.topdraw.mq.domain.DataSyncMsg; |
| 5 | import com.topdraw.resttemplate.RestTemplateClient; | 5 | import com.topdraw.resttemplate.RestTemplateClient; |
| 6 | import com.topdraw.util.JSONUtil; | 6 | import com.topdraw.util.JSONUtil; |
| 7 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
| 8 | import org.springframework.amqp.core.ExchangeTypes; | ||
| 8 | import org.springframework.amqp.rabbit.annotation.*; | 9 | import org.springframework.amqp.rabbit.annotation.*; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
| ... | @@ -12,11 +13,14 @@ import org.springframework.util.Assert; | ... | @@ -12,11 +13,14 @@ import org.springframework.util.Assert; |
| 12 | 13 | ||
| 13 | @Component | 14 | @Component |
| 14 | @Slf4j | 15 | @Slf4j |
| 15 | public class UserCenterConsumer { | 16 | public class UcGatewayConsumer { |
| 16 | 17 | ||
| 17 | @Autowired | 18 | @Autowired |
| 18 | RestTemplateClient restTemplateClient; | 19 | RestTemplateClient restTemplateClient; |
| 19 | 20 | ||
| 21 | @Autowired | ||
| 22 | AutoRoute autoUser; | ||
| 23 | |||
| 20 | /** | 24 | /** |
| 21 | * 事件 | 25 | * 事件 |
| 22 | * @param content | 26 | * @param content |
| ... | @@ -24,15 +28,17 @@ public class UserCenterConsumer { | ... | @@ -24,15 +28,17 @@ public class UserCenterConsumer { |
| 24 | * @author Hongyan Wang | 28 | * @author Hongyan Wang |
| 25 | * @date 2021/9/7 11:26 上午 | 29 | * @date 2021/9/7 11:26 上午 |
| 26 | */ | 30 | */ |
| 27 | @RabbitHandler | 31 | /*@RabbitHandler |
| 28 | @RabbitListener(queues = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA, | 32 | @RabbitListener(bindings = { |
| 29 | containerFactory = "userCenterRabbitListenerContainerFactory") | 33 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA), |
| 34 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | ||
| 35 | }, containerFactory = "serviceRabbitListenerContainerFactory") | ||
| 30 | public void ucEventConsumer(String content) { | 36 | public void ucEventConsumer(String content) { |
| 31 | log.info(" receive dataSync msg , content is : {} ", content); | 37 | log.info(" receive dataSync msg , content is : {} ", content); |
| 32 | DataSyncMsg dataSyncMsg = this.parseContent(content); | 38 | DataSyncMsg dataSyncMsg = this.parseContent(content); |
| 33 | this.taskDeal(dataSyncMsg); | 39 | this.taskDeal(dataSyncMsg); |
| 34 | log.info("ucEventConsumer ====>>>> end"); | 40 | log.info("ucEventConsumer ====>>>> end"); |
| 35 | } | 41 | }*/ |
| 36 | 42 | ||
| 37 | /** | 43 | /** |
| 38 | * 数据解析 | 44 | * 数据解析 | ... | ... |
| 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 | } |
-
Please register or sign in to post a comment