Commit 8189259a 8189259af592c47545929f81786d211967df96e0 by xianghan

Merge branch '2.2.0-release'

# Conflicts:
#	.gitignore
#	member-service-impl/src/main/java/com/topdraw/business/module/member/domain/Member.java
#	member-service-impl/src/main/java/com/topdraw/business/module/member/repository/MemberRepository.java
#	member-service-impl/src/main/java/com/topdraw/business/module/member/service/impl/MemberServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/domian/constant/RightType.java
#	member-service-impl/src/main/java/com/topdraw/business/process/rest/TaskOperationController.java
#	member-service-impl/src/main/java/com/topdraw/business/process/rest/UserOperationController.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/CouponOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/ExpOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/PointsOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/RightsOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/TaskOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/business/process/service/impl/UserOperationServiceImpl.java
#	member-service-impl/src/main/java/com/topdraw/mq/module/mq/DataSyncMsg.java
#	member-service-impl/src/main/resources/config/application-dev.yml
#	member-service-impl/src/test/java/com/topdraw/test/business/process/rest/TaskOperationControllerTest.java
#	member-service-impl/src/test/java/com/topdraw/test/business/process/service/TaskOperationServiceTest.java
#	member-service-impl/src/test/java/com/topdraw/test/mq/MqTest.java
2 parents 7d0ef571 4fb34343
Showing 200 changed files with 8343 additions and 3079 deletions
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
3 /logs/ 3 /logs/
4 /member-service-impl/target/ 4 /member-service-impl/target/
5 /member-service-api/target/ 5 /member-service-api/target/
6 member-service.iml 6 /.member-service.iml
...\ No newline at end of file ...\ No newline at end of file
......
1 package com.topdraw.config; 1 package com.topdraw.business;
2 2
3 public class LocalConstants { 3 public class LocalConstants {
4 4
...@@ -28,4 +28,10 @@ public class LocalConstants { ...@@ -28,4 +28,10 @@ public class LocalConstants {
28 28
29 // 事件类型 3:参加活动 29 // 事件类型 3:参加活动
30 public static final Integer EVT_TYPE_ACTIVITY = 3; 30 public static final Integer EVT_TYPE_ACTIVITY = 3;
31
32
33
34
35 // 会员黑名单状态
36 public static final Long BLACK_STATUS = 1L;
31 } 37 }
......
1 package com.topdraw.business;
2
3 /**
4 * @author :
5 * @description:\
6 * @function :
7 * @date :Created in 2022/6/18 13:25
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/18 13:25
11 */
12 public interface RedisKeyConstants {
13 // 全量会员信息
14 String cacheMemberById = "uce::member::id";
15 // 任务处理时会员信息
16 String cacheMemberSimpleById = "uce::memberSimple::id";
17 String cacheMemberSimpleByCode = "uce::memberSimple::code";
18 // 会员全量信息
19 String cacheMemberByCode = "uce::member::code";
20
21 // 修改会员积分时的分布式锁
22 String updateCachePointsByMemberId = "uce::updatePoints::memberId";
23 // 修改会员成长值时的分布式锁
24 String updateCacheExpByMemberId = "uce::updateExp::memberId";
25 // 修改会员优惠券时的分布式锁
26 String updateCacheCouponByMemberId = "uce::updateCoupon::memberId";
27
28 // 全量大屏信息
29 String cacheUserTvByPlatformAccount = "uce::userTv::platformAccount";
30 String cacheVisUserByPlatformAccount = "uus::visUser";
31 // 会员已完成的任务进度
32 String cacheTaskProcessByMemberId = "uce::taskProcess::memberId";
33 // 任务模板类型对应的全量任务
34 String cacheTaskByEvent = "uce::task::event";
35 // 全量优惠券信息
36 String cacheCouponById = "uce::coupon::id";
37
38 // 权益全量信息
39 String cacheRightById = "uce::right::id";
40
41 // 会员可以做的任务
42 String cacheTaskByEventAndMemberLevelAndVip = "uce::task::eventAndMemberLevelAndVip";
43
44 // 全量会员等级
45 String cacheMemberLevelByLevel = "uce::memberLevel::level";
46
47 // 今天处理完成任务数量
48 String cacheTodayFinishTaskCount = "uce::todayCount::memberId";
49 // 历史完成的任务数量
50 String cacheTotalFinishTaskCount = "uce::totalCount::memberId";
51
52
53
54 String CACHE_PLATFROMACCOUNT_PLAYDURATION = "uce::eventPlay::playduration";
55
56
57 String CACHE_TODAY_FINISH_COUNT = "todayFinishCount";
58 String CACHE_TOTAL_FINISH_COUNT = "totalFinishCount";
59 }
1 package com.topdraw.business.module.coupon.service.impl; 1 package com.topdraw.business.module.coupon.service.impl;
2 2
3 import com.topdraw.business.module.coupon.domain.Coupon; 3 import com.topdraw.business.module.coupon.domain.Coupon;
4 import com.topdraw.business.RedisKeyConstants;
4 import com.topdraw.exception.GlobeExceptionMsg; 5 import com.topdraw.exception.GlobeExceptionMsg;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.module.coupon.repository.CouponRepository; 6 import com.topdraw.business.module.coupon.repository.CouponRepository;
7 import com.topdraw.business.module.coupon.service.CouponService; 7 import com.topdraw.business.module.coupon.service.CouponService;
8 import com.topdraw.business.module.coupon.service.dto.CouponDTO; 8 import com.topdraw.business.module.coupon.service.dto.CouponDTO;
9 import com.topdraw.business.module.coupon.service.mapper.CouponMapper; 9 import com.topdraw.business.module.coupon.service.mapper.CouponMapper;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.cache.annotation.Cacheable;
11 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
12 import org.springframework.transaction.annotation.Propagation; 13 import org.springframework.transaction.annotation.Propagation;
13 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
...@@ -30,9 +31,9 @@ public class CouponServiceImpl implements CouponService { ...@@ -30,9 +31,9 @@ public class CouponServiceImpl implements CouponService {
30 private CouponRepository couponRepository; 31 private CouponRepository couponRepository;
31 32
32 @Override 33 @Override
34 @Cacheable(cacheNames = RedisKeyConstants.cacheCouponById, key = "#id", unless = "#result.id == null")
33 public CouponDTO findById(Long id) { 35 public CouponDTO findById(Long id) {
34 Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL); 36 Assert.notNull(id, GlobeExceptionMsg.COUPON_ID_IS_NULL);
35
36 Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new); 37 Coupon coupon = this.couponRepository.findById(id).orElseGet(Coupon::new);
37 // ValidationUtil.isNull(coupon.getId(),"Coupon","id",id); 38 // ValidationUtil.isNull(coupon.getId(),"Coupon","id",id);
38 return this.couponMapper.toDto(coupon); 39 return this.couponMapper.toDto(coupon);
......
...@@ -3,6 +3,9 @@ package com.topdraw.business.module.exp.detail.repository; ...@@ -3,6 +3,9 @@ package com.topdraw.business.module.exp.detail.repository;
3 import com.topdraw.business.module.exp.detail.domain.ExpDetail; 3 import com.topdraw.business.module.exp.detail.domain.ExpDetail;
4 import org.springframework.data.jpa.repository.JpaRepository; 4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Modifying;
7 import org.springframework.data.jpa.repository.Query;
8 import org.springframework.data.repository.query.Param;
6 9
7 import java.util.Optional; 10 import java.util.Optional;
8 11
...@@ -13,4 +16,15 @@ import java.util.Optional; ...@@ -13,4 +16,15 @@ import java.util.Optional;
13 public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> { 16 public interface ExpDetailRepository extends JpaRepository<ExpDetail, Long>, JpaSpecificationExecutor<ExpDetail> {
14 17
15 Optional<ExpDetail> findFirstByCode(String code); 18 Optional<ExpDetail> findFirstByCode(String code);
19
20
21
22
23 @Modifying
24 @Query(value = "INSERT INTO `uc_exp_detail`(`code`, `member_id`, `account_id`, `original_exp`, `result_exp`, `exp`, " +
25 "`device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `description`, `app_code`, `create_time`, `update_time`)\n" +
26 " VALUES (:#{#resources.code}, :#{#resources.memberId}, :#{#resources.accountId}, :#{#resources.originalExp}, " +
27 " :#{#resources.resultExp}, :#{#resources.exp}, :#{#resources.deviceType}, :#{#resources.evtType}, " +
28 " :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, '#', NULL, now(), now())", nativeQuery = true)
29 void insertIntoExpDetail(@Param("resources") ExpDetail expDetail);
16 } 30 }
......
...@@ -44,7 +44,7 @@ public class ExpDetailServiceImpl implements ExpDetailService { ...@@ -44,7 +44,7 @@ public class ExpDetailServiceImpl implements ExpDetailService {
44 @Transactional(rollbackFor = Exception.class) 44 @Transactional(rollbackFor = Exception.class)
45 public void create(ExpDetail resources) { 45 public void create(ExpDetail resources) {
46 ExpDetail expDetail = ExpDetailBuilder.build(resources); 46 ExpDetail expDetail = ExpDetailBuilder.build(resources);
47 this.expDetailRepository.save(expDetail); 47 this.expDetailRepository.insertIntoExpDetail(expDetail);
48 } 48 }
49 49
50 @Override 50 @Override
......
...@@ -3,6 +3,7 @@ package com.topdraw.business.module.member.address.repository; ...@@ -3,6 +3,7 @@ package com.topdraw.business.module.member.address.repository;
3 import com.topdraw.business.module.member.address.domain.MemberAddress; 3 import com.topdraw.business.module.member.address.domain.MemberAddress;
4 import org.springframework.data.jpa.repository.JpaRepository; 4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Modifying;
6 import org.springframework.data.jpa.repository.Query; 7 import org.springframework.data.jpa.repository.Query;
7 8
8 /** 9 /**
...@@ -14,4 +15,12 @@ public interface MemberAddressRepository extends JpaRepository<MemberAddress, Lo ...@@ -14,4 +15,12 @@ public interface MemberAddressRepository extends JpaRepository<MemberAddress, Lo
14 @Query(value = "select IFNULL(max(sequence),0) from uc_member_address where member_id = ?1" , nativeQuery = true) 15 @Query(value = "select IFNULL(max(sequence),0) from uc_member_address where member_id = ?1" , nativeQuery = true)
15 int findMaxSequenceByMemberId(Long memberId); 16 int findMaxSequenceByMemberId(Long memberId);
16 17
18 @Modifying
19 @Query(value = "UPDATE `uc_member_address` SET `is_default` = 1, `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
20 Integer updateDefaultMemberAddressById(Long id);
21
22 @Modifying
23 @Query(value = "UPDATE `uc_member_address` SET `is_default` = 0, `update_time` = now() WHERE `member_id` = ?1", nativeQuery = true)
24 Integer updateUnDefaultMemberAddressByMemberId(Long memberId);
25
17 } 26 }
......
...@@ -40,4 +40,8 @@ public interface MemberAddressService { ...@@ -40,4 +40,8 @@ public interface MemberAddressService {
40 * @return 40 * @return
41 */ 41 */
42 int findMaxSequenceByMemberId(Long memberId); 42 int findMaxSequenceByMemberId(Long memberId);
43
44 Integer updateDefaultMemberAddressById(Long id);
45
46 Integer updateUnDefaultMemberAddressByMemberId(Long memberId);
43 } 47 }
......
...@@ -105,6 +105,18 @@ public class MemberAddressServiceImpl implements MemberAddressService { ...@@ -105,6 +105,18 @@ public class MemberAddressServiceImpl implements MemberAddressService {
105 return this.memberAddressRepository.findMaxSequenceByMemberId(memberId); 105 return this.memberAddressRepository.findMaxSequenceByMemberId(memberId);
106 } 106 }
107 107
108 @Override
109 @Transactional(rollbackFor = Exception.class)
110 public Integer updateDefaultMemberAddressById(Long id) {
111 return this.memberAddressRepository.updateDefaultMemberAddressById(id);
112 }
113
114 @Override
115 @Transactional(rollbackFor = Exception.class)
116 public Integer updateUnDefaultMemberAddressByMemberId(Long memberId) {
117 return this.memberAddressRepository.updateUnDefaultMemberAddressByMemberId(memberId);
118 }
119
108 /** 120 /**
109 * 检查会员 121 * 检查会员
110 * @param memberAddress 122 * @param memberAddress
......
...@@ -44,7 +44,7 @@ public class Member implements Serializable { ...@@ -44,7 +44,7 @@ public class Member implements Serializable {
44 @Column(name = "code") 44 @Column(name = "code")
45 private String code; 45 private String code;
46 46
47 /** 类型 1:大屏;2:小屏 */ 47 /** 类型 1:大屏;2:小屏 3:app;*/
48 @Column(name = "`type`") 48 @Column(name = "`type`")
49 private Integer type; 49 private Integer type;
50 50
......
1 package com.topdraw.business.module.member.domain;
2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.bean.copier.CopyOptions;
5 import com.topdraw.business.module.common.validated.UpdateGroup;
6 import lombok.Data;
7 import lombok.experimental.Accessors;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11
12 import javax.persistence.*;
13 import javax.validation.constraints.NotNull;
14 import java.io.Serializable;
15 import java.sql.Timestamp;
16
17 /**
18 * @author XiangHan
19 * @date 2021-10-22
20 */
21 @Entity
22 @Data
23 @EntityListeners(AuditingEntityListener.class)
24 @Accessors(chain = true)
25 @Table(name="uc_member")
26 public class MemberSimple implements Serializable {
27
28 /** 主键 */
29 @Id
30 @GeneratedValue(strategy = GenerationType.IDENTITY)
31 @Column(name = "id")
32 @NotNull(message = "id can't be null!!",groups = {UpdateGroup.class})
33 private Long id;
34
35 /** 标识 */
36 @Column(name = "code")
37 private String code;
38
39 /** 状态 0:不可用;1:可用 */
40 @Column(name = "`status`")
41 private Integer status;
42
43 /** 分组信息 */
44 @Column(name = "`groups`")
45 private String groups;
46
47 /** 是否会员 0:非会员;1:会员 */
48 @Column(name = "vip")
49 private Integer vip;
50
51 /** 会员等级(对应level表的level字段,非id) */
52 @Column(name = "`level`")
53 private Integer level;
54
55 /** iptv账号id */
56 @Column(name = "user_iptv_id")
57 private Long userIptvId;
58
59 /** 是否在黑名单 1:是;0否 */
60 @Column(name = "black_status")
61 private Long blackStatus;
62
63 public void copy(MemberSimple source){
64 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false));
65 }
66 }
1 package com.topdraw.business.module.member.domain;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/27 15:38
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/27 15:38
11 */
12 public interface MemberTypeConstant {
13
14 // 大屏
15 Integer vis = 1;
16 // 微信
17 Integer weixin = 2;
18 // app
19 Integer app = 3;
20 }
...@@ -15,5 +15,5 @@ public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>, ...@@ -15,5 +15,5 @@ public interface MemberLevelRepository extends JpaRepository<MemberLevel, Long>,
15 15
16 Optional<MemberLevel> findFirstByCode(String code); 16 Optional<MemberLevel> findFirstByCode(String code);
17 17
18 List<MemberLevel> findByLevelAndStatus(Integer level, Integer status); 18 Optional<MemberLevel> findByLevelAndStatus(Integer level, Integer status);
19 } 19 }
......
...@@ -25,12 +25,9 @@ public interface MemberLevelService { ...@@ -25,12 +25,9 @@ public interface MemberLevelService {
25 MemberLevelDTO getByCode(String code); 25 MemberLevelDTO getByCode(String code);
26 26
27 /** 27 /**
28 * 通过等级和状态检索 28 *
29 * @param i 29 * @param i
30 * @param status
31 * @return 30 * @return
32 */ 31 */
33 List<MemberLevelDTO> findLevelAndStatus(Integer i, Integer status); 32 MemberLevelDTO findByLevel(int i);
34
35
36 } 33 }
......
1 package com.topdraw.business.module.member.level.service.impl; 1 package com.topdraw.business.module.member.level.service.impl;
2 2
3 import com.topdraw.business.module.member.level.domain.MemberLevel; 3 import com.topdraw.business.module.member.level.domain.MemberLevel;
4 import com.topdraw.business.RedisKeyConstants;
4 import com.topdraw.utils.ValidationUtil; 5 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.business.module.member.level.repository.MemberLevelRepository; 6 import com.topdraw.business.module.member.level.repository.MemberLevelRepository;
6 import com.topdraw.business.module.member.level.service.MemberLevelService; 7 import com.topdraw.business.module.member.level.service.MemberLevelService;
7 import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; 8 import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO;
8 import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper; 9 import com.topdraw.business.module.member.level.service.mapper.MemberLevelMapper;
9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.cache.annotation.Cacheable;
10 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation; 13 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
13 import com.topdraw.utils.StringUtils; 15 import com.topdraw.utils.StringUtils;
14 16
15 import java.util.List;
16
17 /** 17 /**
18 * @author XiangHan 18 * @author XiangHan
19 * @date 2021-10-22 19 * @date 2021-10-22
...@@ -29,6 +29,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { ...@@ -29,6 +29,7 @@ public class MemberLevelServiceImpl implements MemberLevelService {
29 private MemberLevelMapper memberLevelMapper; 29 private MemberLevelMapper memberLevelMapper;
30 30
31 @Override 31 @Override
32 @Transactional(readOnly = true)
32 public MemberLevelDTO findById(Long id) { 33 public MemberLevelDTO findById(Long id) {
33 MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new); 34 MemberLevel MemberLevel = this.memberLevelRepository.findById(id).orElseGet(MemberLevel::new);
34 ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id); 35 ValidationUtil.isNull(MemberLevel.getId(),"MemberLevel","id",id);
...@@ -36,14 +37,18 @@ public class MemberLevelServiceImpl implements MemberLevelService { ...@@ -36,14 +37,18 @@ public class MemberLevelServiceImpl implements MemberLevelService {
36 } 37 }
37 38
38 @Override 39 @Override
40 @Transactional(readOnly = true)
39 public MemberLevelDTO getByCode(String code) { 41 public MemberLevelDTO getByCode(String code) {
40 return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new)) 42 return StringUtils.isNotEmpty(code) ? this.memberLevelMapper.toDto(this.memberLevelRepository.findFirstByCode(code).orElseGet(MemberLevel::new))
41 : new MemberLevelDTO(); 43 : new MemberLevelDTO();
42 } 44 }
43 45
44 @Override 46 @Override
45 public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { 47 @Transactional(readOnly = true)
46 return this.memberLevelMapper.toDto(this.memberLevelRepository.findByLevelAndStatus(level,status)); 48 @Cacheable(cacheNames = RedisKeyConstants.cacheMemberLevelByLevel, key = "#level", unless = "#result.id == null")
49 public MemberLevelDTO findByLevel(int level) {
50 MemberLevel memberLevel = this.memberLevelRepository.findByLevelAndStatus(level, 1).orElseGet(MemberLevel::new);
51 return this.memberLevelMapper.toDto(memberLevel);
47 } 52 }
48 53
49 } 54 }
......
...@@ -7,7 +7,6 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; ...@@ -7,7 +7,6 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
7 import com.topdraw.business.process.service.member.MemberProfileOperationService; 7 import com.topdraw.business.process.service.member.MemberProfileOperationService;
8 import com.topdraw.common.ResultInfo; 8 import com.topdraw.common.ResultInfo;
9 import com.topdraw.business.module.member.profile.domain.MemberProfile; 9 import com.topdraw.business.module.member.profile.domain.MemberProfile;
10 import com.topdraw.business.module.member.profile.service.MemberProfileService;
11 import lombok.extern.slf4j.Slf4j; 10 import lombok.extern.slf4j.Slf4j;
12 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.validation.annotation.Validated; 12 import org.springframework.validation.annotation.Validated;
...@@ -32,10 +31,8 @@ public class MemberProfileController { ...@@ -32,10 +31,8 @@ public class MemberProfileController {
32 @RequestMapping(value = "/update") 31 @RequestMapping(value = "/update")
33 @ApiOperation("修改会员属性") 32 @ApiOperation("修改会员属性")
34 @AnonymousAccess 33 @AnonymousAccess
35 @Deprecated
36 public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody MemberProfile resources) { 34 public ResultInfo update(@Validated(value = {UpdateGroup.class}) @RequestBody MemberProfile resources) {
37 35 log.info("memberProfile ==>> update ==>> resources ===>> {}",resources);
38 log.info("memberProfile ==>> update ==>> resources ===>> [{}]",resources);
39 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources); 36 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources);
40 return ResultInfo.success(memberProfileDTO); 37 return ResultInfo.success(memberProfileDTO);
41 } 38 }
...@@ -44,8 +41,7 @@ public class MemberProfileController { ...@@ -44,8 +41,7 @@ public class MemberProfileController {
44 @ApiOperation("修改会员属性并同步会员信息") 41 @ApiOperation("修改会员属性并同步会员信息")
45 @AnonymousAccess 42 @AnonymousAccess
46 public ResultInfo updateMemberProfileAndMember(@Validated @RequestBody MemberProfile resources) { 43 public ResultInfo updateMemberProfileAndMember(@Validated @RequestBody MemberProfile resources) {
47 log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> [{}]",resources); 44 log.info("MemberProfileServiceImpl ==>> update ==>> resources ===>> {}",resources);
48
49 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources); 45 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.updateMemberProfileAndMember(resources);
50 return ResultInfo.success(memberProfileDTO); 46 return ResultInfo.success(memberProfileDTO);
51 } 47 }
...@@ -55,9 +51,7 @@ public class MemberProfileController { ...@@ -55,9 +51,7 @@ public class MemberProfileController {
55 @AnonymousAccess 51 @AnonymousAccess
56 @Deprecated 52 @Deprecated
57 public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberProfile resources) { 53 public ResultInfo create(@Validated(value = {CreateGroup.class}) @RequestBody MemberProfile resources) {
58 54 log.info("memberProfile ==>> update ==>> resources ===>> {}",resources);
59 log.info("memberProfile ==>> update ==>> resources ===>> [{}]",resources);
60
61 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.createMemberProfileAndSyncMember(resources); 55 MemberProfileDTO memberProfileDTO = this.memberProfileOperationService.createMemberProfileAndSyncMember(resources);
62 return ResultInfo.success(memberProfileDTO); 56 return ResultInfo.success(memberProfileDTO);
63 } 57 }
......
...@@ -6,6 +6,7 @@ import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; ...@@ -6,6 +6,7 @@ import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder;
6 import com.topdraw.business.module.member.service.MemberService; 6 import com.topdraw.business.module.member.service.MemberService;
7 import com.topdraw.business.module.member.service.dto.MemberDTO; 7 import com.topdraw.business.module.member.service.dto.MemberDTO;
8 import com.topdraw.util.Base64Util; 8 import com.topdraw.util.Base64Util;
9 import com.topdraw.util.RegexUtil;
9 import com.topdraw.utils.RedisUtils; 10 import com.topdraw.utils.RedisUtils;
10 import com.topdraw.utils.ValidationUtil; 11 import com.topdraw.utils.ValidationUtil;
11 import com.topdraw.business.module.member.profile.repository.MemberProfileRepository; 12 import com.topdraw.business.module.member.profile.repository.MemberProfileRepository;
...@@ -141,6 +142,13 @@ public class MemberProfileServiceImpl implements MemberProfileService { ...@@ -141,6 +142,13 @@ public class MemberProfileServiceImpl implements MemberProfileService {
141 memberProfile.setGender(_memberProfileDTO1.getGender()); 142 memberProfile.setGender(_memberProfileDTO1.getGender());
142 } 143 }
143 144
145 String phone = resources.getPhone();
146 if (StringUtils.isNotBlank(phone) && RegexUtil.mobileRegex(phone)) {
147 memberProfile.setPhone(phone);
148 } else {
149 memberProfile.setPhone(_memberProfileDTO1.getPhone());
150 }
151
144 MemberProfile _memberProfile = this.memberProfileRepository.save(memberProfile); 152 MemberProfile _memberProfile = this.memberProfileRepository.save(memberProfile);
145 153
146 MemberProfileDTO memberProfileDTO = new MemberProfileDTO(); 154 MemberProfileDTO memberProfileDTO = new MemberProfileDTO();
...@@ -171,31 +179,35 @@ public class MemberProfileServiceImpl implements MemberProfileService { ...@@ -171,31 +179,35 @@ public class MemberProfileServiceImpl implements MemberProfileService {
171 log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources); 179 log.info("MemberProfileServiceImpl ==>> updateMemberProfileAndMember ==>> resources ===>> [{}]",resources);
172 MemberProfileDTO memberProfileDTO = this.update(resources); 180 MemberProfileDTO memberProfileDTO = this.update(resources);
173 // 同步会员信息 181 // 同步会员信息
174 this.synchronizedMemberData(resources, memberDTO);
175 return memberProfileDTO;
176 }
177
178 private void synchronizedMemberData(MemberProfile resources, MemberDTO memberDTO) {
179 182
180 log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",resources); 183 log.info("updateMemberProfileAndMember ==>> resources ==>> [{}]",memberProfileDTO);
181 184
182 memberDTO.setId(resources.getMemberId()); 185 Member member = new Member();
183 if(StringUtils.isNotBlank(resources.getRealname())) { 186 member.setId(memberDTO.getId());
184 memberDTO.setNickname(resources.getRealname()); 187 member.setCode(memberDTO.getCode());
188 if(StringUtils.isNotBlank(memberProfileDTO.getRealname())) {
189 member.setNickname(memberProfileDTO.getRealname());
190 } else {
191 member.setNickname(memberDTO.getNickname());
185 } 192 }
186 if(Objects.nonNull(resources.getGender()) && resources.getGender() != -1) { 193 if(Objects.nonNull(memberProfileDTO.getGender()) && memberProfileDTO.getGender() != -1) {
187 memberDTO.setGender(resources.getGender()); 194 member.setGender(memberProfileDTO.getGender());
195 } else {
196 member.setGender(memberDTO.getGender());
188 } 197 }
189 if(StringUtils.isNotBlank(resources.getBirthday())) { 198 if(StringUtils.isNotBlank(memberProfileDTO.getBirthday())) {
190 memberDTO.setBirthday(resources.getBirthday()); 199 member.setBirthday(memberProfileDTO.getBirthday());
200 } else {
201 member.setBirthday(memberDTO.getBirthday());
191 } 202 }
192 if(StringUtils.isNotBlank(resources.getAvatarUrl())) { 203 if(StringUtils.isNotBlank(resources.getAvatarUrl())) {
193 memberDTO.setAvatarUrl(resources.getAvatarUrl()); 204 member.setAvatarUrl(resources.getAvatarUrl());
205 } else {
206 member.setAvatarUrl(memberDTO.getAvatarUrl());
194 } 207 }
208 this.memberService.doUpdateMemberAvatarUrlAndNicknameAndGender(member);
195 209
196 Member member = new Member(); 210 return memberProfileDTO;
197 BeanUtils.copyProperties(memberDTO,member);
198
199 this.memberService.update(member);
200 } 211 }
212
201 } 213 }
......
1 package com.topdraw.business.module.member.repository; 1 package com.topdraw.business.module.member.repository;
2 2
3 import com.topdraw.business.module.member.domain.Member; 3 import com.topdraw.business.module.member.domain.Member;
4 import com.topdraw.business.module.member.domain.MemberSimple;
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 import org.springframework.data.jpa.repository.Modifying; 7 import org.springframework.data.jpa.repository.Modifying;
...@@ -10,6 +11,7 @@ import org.springframework.data.repository.query.Param; ...@@ -10,6 +11,7 @@ import org.springframework.data.repository.query.Param;
10 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
11 import java.util.List; 12 import java.util.List;
12 import java.util.Optional; 13 import java.util.Optional;
14 import java.util.Set;
13 15
14 /** 16 /**
15 * @author XiangHan 17 * @author XiangHan
...@@ -23,7 +25,6 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif ...@@ -23,7 +25,6 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
23 25
24 Optional<Member> findByIdOrCode(Long id,String code); 26 Optional<Member> findByIdOrCode(Long id,String code);
25 27
26
27 @Modifying 28 @Modifying
28 @Query(value = "UPDATE `uc_member` SET `user_iptv_id` = ?2, `update_time` = ?3 , `bind_iptv_platform_type`= 0, " + 29 @Query(value = "UPDATE `uc_member` SET `user_iptv_id` = ?2, `update_time` = ?3 , `bind_iptv_platform_type`= 0, " +
29 "`bind_iptv_time`=?3 WHERE `id` = ?1", nativeQuery = true) 30 "`bind_iptv_time`=?3 WHERE `id` = ?1", nativeQuery = true)
...@@ -32,15 +33,40 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif ...@@ -32,15 +33,40 @@ public interface MemberRepository extends JpaRepository<Member, Long>, JpaSpecif
32 @Modifying 33 @Modifying
33 @Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, `level` = :#{#resources.level} , `update_time`= now() " + 34 @Query(value = "UPDATE `uc_member` SET `exp` = :#{#resources.exp}, `level` = :#{#resources.level} , `update_time`= now() " +
34 " WHERE `id` = :#{#resources.id}", nativeQuery = true) 35 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
35 void updateExpAndLevel(@Param("resources") Member member); 36 Integer updateExpAndLevel(@Param("resources") Member member);
36 37
37 @Modifying 38 @Modifying
38 @Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `due_points` = :#{#resources.duePoints} , `update_time`= now() " + 39 @Query(value = "UPDATE `uc_member` SET `points` = :#{#resources.points}, `update_time`= now() WHERE `id` = :#{#resources.id}", nativeQuery = true)
39 " WHERE `id` = :#{#resources.id}", nativeQuery = true) 40 Integer updatePointAndDuePoint(@Param("resources") Member resources);
40 void updatePointAndDuePoint(@Param("resources") Member resources);
41 41
42 @Modifying 42 @Modifying
43 @Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, `due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " + 43 @Query(value = "UPDATE `uc_member` SET `coupon_amount` = :#{#resources.couponAmount}, `due_coupon_amount` = :#{#resources.dueCouponAmount} , `update_time`= now() " +
44 " WHERE `id` = :#{#resources.id}", nativeQuery = true) 44 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
45 void doUpdateMemberCoupon(@Param("resources") Member member); 45 Integer doUpdateMemberCoupon(@Param("resources") Member member);
46
47 @Query(value = "SELECT um.* FROM uc_member um LEFT JOIN uc_user_tv tv ON um.id = tv.member_id " +
48 " WHERE tv.platform_account = ?1 ", nativeQuery = true)
49 Optional<Member> findByPlatformAccount(String platformAccount);
50
51 @Modifying
52 @Query(value = "UPDATE `uc_member` SET `vip` = :#{#resources.vip}, `vip_expire_time` = :#{#resources.vipExpireTime} , `update_time`= now() " +
53 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
54 Integer updateMemberVipAndVipExpireTime(@Param("resources") Member member);
55
56 @Modifying
57 @Query(value = "UPDATE `uc_member` SET `user_iptv_id` = :#{#resources.userIptvId}, `update_time` = now() , `bind_iptv_platform_type`= :#{#resources.bindIptvPlatformType}, " +
58 " `bind_iptv_time`=:#{#resources.bindIptvTime} WHERE `id` = :#{#resources.id}", nativeQuery = true)
59 Integer updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(@Param("resources") Member member);
60
61 @Modifying
62 @Query(value = "UPDATE `uc_member` SET `avatar_url` = :#{#resources.avatarUrl}, `update_time` = now() , `nickname`= :#{#resources.nickname}, " +
63 " `gender`=:#{#resources.gender} WHERE `id` = :#{#resources.id}", nativeQuery = true)
64 Integer updateMemberAvatarUrlAndNicknameAndGender(@Param("resources") Member resource);
65
66 @Query(value = "SELECT IFNULL(`exp`,0) AS exp FROM uc_member WHERE `id` = ?1 ", nativeQuery = true)
67 Long findExpByMemberId(Long memberId);
68
69 @Modifying
70 @Query(value = "UPDATE `uc_member` SET `groups` = ?1, `update_time` = now() WHERE `code` IN ?2 ", nativeQuery = true)
71 Integer doUpdateGroupsBatch(String groups, Set<String> codes);
46 } 72 }
......
1 package com.topdraw.business.module.member.repository;
2
3 import com.topdraw.business.module.member.domain.MemberSimple;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Query;
7
8 import java.util.Optional;
9
10 /**
11 * @author XiangHan
12 * @date 2021-10-22
13 */
14 public interface MemberSimpleRepository extends JpaRepository<MemberSimple, Long>, JpaSpecificationExecutor<MemberSimple> {
15
16 @Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `id` = ?1", nativeQuery = true)
17 Optional<MemberSimple> findSimpleById(Long id);
18
19 @Query(value = "SELECT `id`, `code`, `status`, `groups`, `vip`, `level`,`user_iptv_id`, `black_status` FROM `uc_member` WHERE `code` = ?1", nativeQuery = true)
20 Optional<MemberSimple> findSimpleByCode(String code);
21 }
...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.validation.annotation.Validated; 18 import org.springframework.validation.annotation.Validated;
19 import org.springframework.web.bind.annotation.*; 19 import org.springframework.web.bind.annotation.*;
20 20
21 import java.util.List;
21 import java.util.Objects; 22 import java.util.Objects;
22 23
23 /** 24 /**
...@@ -52,11 +53,22 @@ public class MemberController { ...@@ -52,11 +53,22 @@ public class MemberController {
52 @AnonymousAccess 53 @AnonymousAccess
53 @ApiOperation("手动修改vip") 54 @ApiOperation("手动修改vip")
54 public ResultInfo doUpdateVipByCode(@Validated(value = {UpdateGroup.class}) @RequestBody Member resources) { 55 public ResultInfo doUpdateVipByCode(@Validated(value = {UpdateGroup.class}) @RequestBody Member resources) {
55 log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources); 56 log.info("member ==>> doUpdateVipByCode ==>> param ==>> {}",resources);
56 this.memberOperationService.updateMemberVip(resources); 57 this.memberOperationService.doUpdateMemberVipAndVipExpireTime(resources);
57 return ResultInfo.success(); 58 return ResultInfo.success();
58 } 59 }
59 60
61
62 @RequestMapping(value = "/doUpdateGroupsBatch")
63 @AnonymousAccess
64 @ApiOperation("批量手动修改会员分组")
65 public ResultInfo doUpdateGroupsBatch(@Validated(value = {UpdateGroup.class}) @RequestBody List<Member> resources) {
66 log.info("doUpdateGroupsBatch ==>> param ==>> {}",resources);
67 Integer count = this.memberOperationService.doUpdateGroupsBatch(resources);
68 return ResultInfo.success(count);
69 }
70
71
60 @PutMapping(value = "/update") 72 @PutMapping(value = "/update")
61 @ApiOperation("修改会员信息") 73 @ApiOperation("修改会员信息")
62 @AnonymousAccess 74 @AnonymousAccess
...@@ -67,7 +79,6 @@ public class MemberController { ...@@ -67,7 +79,6 @@ public class MemberController {
67 if (StringUtils.isNotBlank(code)) { 79 if (StringUtils.isNotBlank(code)) {
68 MemberDTO memberDTO = this.memberOperationService.findByCode(code); 80 MemberDTO memberDTO = this.memberOperationService.findByCode(code);
69 resources.setId(memberDTO.getId()); 81 resources.setId(memberDTO.getId());
70 // BeanUtils.copyProperties(resources, memberDTO);
71 } 82 }
72 83
73 MemberDTO memberDTO = this.memberOperationService.update(resources); 84 MemberDTO memberDTO = this.memberOperationService.update(resources);
......
...@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.service; ...@@ -2,6 +2,8 @@ package com.topdraw.business.module.member.service;
2 2
3 import com.topdraw.business.module.member.domain.Member; 3 import com.topdraw.business.module.member.domain.Member;
4 import com.topdraw.business.module.member.service.dto.MemberDTO; 4 import com.topdraw.business.module.member.service.dto.MemberDTO;
5 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
6 import org.springframework.transaction.annotation.Transactional;
5 7
6 import java.util.List; 8 import java.util.List;
7 9
...@@ -26,6 +28,13 @@ public interface MemberService { ...@@ -26,6 +28,13 @@ public interface MemberService {
26 MemberDTO findById(Long id); 28 MemberDTO findById(Long id);
27 29
28 /** 30 /**
31 *
32 * @param id
33 * @return
34 */
35 MemberSimpleDTO findSimpleById(Long id);
36
37 /**
29 * 通过code查询会员 38 * 通过code查询会员
30 * @param code 会员编码 39 * @param code 会员编码
31 * @return MemberDTO 40 * @return MemberDTO
...@@ -33,6 +42,13 @@ public interface MemberService { ...@@ -33,6 +42,13 @@ public interface MemberService {
33 MemberDTO findByCode(String code); 42 MemberDTO findByCode(String code);
34 43
35 /** 44 /**
45 *
46 * @param code
47 * @return
48 */
49 MemberSimpleDTO findSimpleByCode(String code);
50
51 /**
36 * 保存 52 * 保存
37 * @param resources 53 * @param resources
38 * @return Long id 54 * @return Long id
...@@ -40,13 +56,6 @@ public interface MemberService { ...@@ -40,13 +56,6 @@ public interface MemberService {
40 MemberDTO create(Member resources); 56 MemberDTO create(Member resources);
41 57
42 /** 58 /**
43 * 创建并返回会员
44 * @param resources 会员
45 * @return Member
46 */
47 MemberDTO createAndReturnMember(Member resources);
48
49 /**
50 * 修改会员 59 * 修改会员
51 * @param resources 60 * @param resources
52 */ 61 */
...@@ -56,7 +65,7 @@ public interface MemberService { ...@@ -56,7 +65,7 @@ public interface MemberService {
56 * 修改会员积分 65 * 修改会员积分
57 * @param member 会员 66 * @param member 会员
58 */ 67 */
59 MemberDTO doUpdateMemberPoints(Member member); 68 Integer doUpdateMemberPoints(Member member);
60 69
61 /** 70 /**
62 * 查询绑定了大屏会员列表 71 * 查询绑定了大屏会员列表
...@@ -83,12 +92,53 @@ public interface MemberService { ...@@ -83,12 +92,53 @@ public interface MemberService {
83 * @param resources 92 * @param resources
84 * @return 93 * @return
85 */ 94 */
86 MemberDTO doUpdateMemberExpAndLevel(Member resources); 95 Integer doUpdateMemberExpAndLevel(Member resources);
87 96
88 /** 97 /**
89 * 98 *
90 * @param member 99 * @param member
91 * @return 100 * @return
92 */ 101 */
93 MemberDTO doUpdateMemberCoupon(Member member); 102 Integer doUpdateMemberCoupon(Member member);
103
104 /**
105 *
106 * @param platformAccount
107 * @return
108 */
109 MemberDTO findByPlatformAccount(String platformAccount);
110
111 /**
112 *
113 * @param member
114 * @return
115 */
116 MemberDTO doUpdateMemberVipAndVipExpireTime(Member member);
117
118 /**
119 *
120 * @param member
121 * @return
122 */
123 MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member member);
124
125 /**
126 *
127 * @param member
128 */
129 MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member member);
130
131 /**
132 *
133 * @param memberId
134 * @return
135 */
136 Long findExpByMemberId(Long memberId);
137
138 /**
139 *
140 * @param resources
141 * @return
142 */
143 Integer doUpdateGroupsBatch(List<Member> resources);
94 } 144 }
......
1 package com.topdraw.business.module.member.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-22
12 */
13 @Data
14 public class MemberSimpleDTO implements Serializable {
15
16 /** 主键 */
17 private Long id;
18
19 /** 标识 */
20 private String code;
21
22 /** 昵称 */
23 private String nickname;
24
25 /** 状态 0:不可用;1:可用 */
26 private Integer status;
27
28 /** 分组信息 */
29 private String groups;
30
31 /** 是否会员 0:非会员;1:会员 */
32 private Integer vip;
33
34 /** vip过期时间 */
35 private Timestamp vipExpireTime;
36
37 /** 会员等级(对应level表的level字段,非id) */
38 private Integer level;
39
40 /** iptv账号id */
41 private Long userIptvId;
42
43 /** 是否在黑名单 1:是;0否 */
44 private Long blackStatus;
45
46 }
1 package com.topdraw.business.module.member.service.impl; 1 package com.topdraw.business.module.member.service.impl;
2 2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
3 import com.topdraw.business.module.member.domain.Member; 5 import com.topdraw.business.module.member.domain.Member;
4 import com.topdraw.business.module.member.domain.MemberBuilder; 6 import com.topdraw.business.module.member.domain.MemberBuilder;
7 import com.topdraw.business.module.member.domain.MemberSimple;
5 import com.topdraw.business.module.member.profile.domain.MemberProfile; 8 import com.topdraw.business.module.member.profile.domain.MemberProfile;
6 import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder; 9 import com.topdraw.business.module.member.profile.domain.MemberProfileBuilder;
7 import com.topdraw.business.module.member.profile.service.MemberProfileService; 10 import com.topdraw.business.module.member.profile.service.MemberProfileService;
8 import com.topdraw.business.module.member.repository.MemberRepository; 11 import com.topdraw.business.module.member.repository.MemberRepository;
12 import com.topdraw.business.module.member.repository.MemberSimpleRepository;
9 import com.topdraw.business.module.member.service.MemberService; 13 import com.topdraw.business.module.member.service.MemberService;
10 import com.topdraw.business.module.member.service.dto.MemberDTO; 14 import com.topdraw.business.module.member.service.dto.MemberDTO;
15 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
11 import com.topdraw.business.module.member.service.mapper.MemberMapper; 16 import com.topdraw.business.module.member.service.mapper.MemberMapper;
17 import com.topdraw.business.module.member.service.mapper.MemberSimpleMapper;
18 import com.topdraw.business.RedisKeyConstants;
12 import com.topdraw.exception.BadRequestException; 19 import com.topdraw.exception.BadRequestException;
13 import com.topdraw.exception.GlobeExceptionMsg; 20 import com.topdraw.exception.GlobeExceptionMsg;
14 import com.topdraw.utils.RedisUtils; 21 import com.topdraw.utils.RedisUtils;
15 import com.topdraw.utils.ValidationUtil;
16 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
17 import org.apache.commons.lang3.StringUtils; 23 import org.apache.commons.lang3.StringUtils;
18 import org.springframework.beans.BeanUtils; 24 import org.springframework.beans.BeanUtils;
19 import org.springframework.beans.factory.annotation.Autowired; 25 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.cache.annotation.CacheEvict;
21 import org.springframework.cache.annotation.CachePut;
22 import org.springframework.cache.annotation.Cacheable; 26 import org.springframework.cache.annotation.Cacheable;
23 import org.springframework.stereotype.Service; 27 import org.springframework.stereotype.Service;
24 import org.springframework.transaction.annotation.Propagation; 28 import org.springframework.transaction.annotation.Propagation;
25 import org.springframework.transaction.annotation.Transactional; 29 import org.springframework.transaction.annotation.Transactional;
26 30
27 import java.util.*; 31 import java.util.*;
32 import java.util.stream.Collectors;
28 33
29 /** 34 /**
30 * @author XiangHan 35 * @author XiangHan
...@@ -40,51 +45,69 @@ public class MemberServiceImpl implements MemberService { ...@@ -40,51 +45,69 @@ public class MemberServiceImpl implements MemberService {
40 @Autowired 45 @Autowired
41 private MemberRepository memberRepository; 46 private MemberRepository memberRepository;
42 @Autowired 47 @Autowired
48 private MemberSimpleRepository memberSimpleRepository;
49 @Autowired
43 private MemberProfileService memberProfileService; 50 private MemberProfileService memberProfileService;
51 @Autowired
52 private MemberSimpleMapper memberSimpleMapper;
44 53
45 @Autowired 54 @Autowired
46 private RedisUtils redisUtils; 55 private RedisUtils redisUtils;
47 56
48
49 @Override 57 @Override
58 @Transactional(readOnly = true)
50 public String findCodeById(Long id) { 59 public String findCodeById(Long id) {
51 MemberDTO memberDTO = this.findById(id); 60 MemberDTO memberDTO = this.findById(id);
52 return memberDTO.getCode(); 61 return memberDTO.getCode();
53 } 62 }
54 63
55 @Override 64 @Override
65 @Transactional(readOnly = true)
56 public MemberDTO findById(Long id) { 66 public MemberDTO findById(Long id) {
57 Member member = this.memberRepository.findById(id).orElseGet(Member::new); 67 Member member = this.memberRepository.findById(id).orElseGet(Member::new);
58 return this.memberMapper.toDto(member); 68 return this.memberMapper.toDto(member);
69 }
70
59 71
72 @Override
73 @Transactional(readOnly = true)
74 public MemberSimpleDTO findSimpleById(Long id) {
75 Object memberSimpleRedis = this.redisUtils.get(RedisKeyConstants.cacheMemberSimpleById + "::" + id);
76 log.info("从redis中获取会员信息, 结果集 dealTask# memberSimpleRedis ==>> {} ", memberSimpleRedis);
77 if (Objects.nonNull(memberSimpleRedis)) {
78 return JSONObject.parseObject(JSON.toJSONString(memberSimpleRedis), MemberSimpleDTO.class);
79 }
80
81 MemberSimple memberSimple = this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new);
82 log.info("从数据库中获取会员信息, 结果集 dealTask# memberSimple ==>> {} ", memberSimple);
83 if (Objects.nonNull(memberSimple.getId())) {
84 MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO();
85 BeanUtils.copyProperties(memberSimple, memberSimpleDTO);
86 boolean result = this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO);
87 log.info("将结果存入redis中, dealTask# memberSimpleDTO ==>> {} || 存入结果 ==>> {}", memberSimpleDTO, result);
88 }
89 return this.memberSimpleMapper.toDto(memberSimple);
60 } 90 }
61 91
62 @Override 92 @Override
93 @Transactional(readOnly = true)
63 public MemberDTO findByCode(String code) { 94 public MemberDTO findByCode(String code) {
64
65 Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new); 95 Member member = this.memberRepository.findFirstByCode(code).orElseGet(Member::new);
66 ValidationUtil.isNull(member.getId(),"Member","id",code);
67
68 return this.memberMapper.toDto(member); 96 return this.memberMapper.toDto(member);
69
70 } 97 }
71 98
72 private MemberDTO findByIdOrCode(Long id,String code) { 99 @Override
73 100 @Transactional(readOnly = true)
74 Member member = this.memberRepository.findByIdOrCode(id,code).orElseGet(Member::new); 101 @Cacheable(cacheNames = RedisKeyConstants.cacheMemberSimpleByCode, key = "#code", unless = "#result.id == null")
75 ValidationUtil.isNull(member.getId(),"Member","param",code); 102 public MemberSimpleDTO findSimpleByCode(String code) {
76 103 return this.memberSimpleMapper.toDto(this.memberSimpleRepository.findSimpleByCode(code).orElseGet(MemberSimple::new));
77 return this.memberMapper.toDto(member);
78
79 } 104 }
80 105
81 @Override 106 @Override
107 @Transactional(readOnly = true)
82 public List<MemberDTO> findByUserIptvId(Long id) { 108 public List<MemberDTO> findByUserIptvId(Long id) {
83
84 List<Member> memberList = this.memberRepository.findByUserIptvId(id); 109 List<Member> memberList = this.memberRepository.findByUserIptvId(id);
85
86 return this.memberMapper.toDto(memberList); 110 return this.memberMapper.toDto(memberList);
87
88 } 111 }
89 112
90 @Override 113 @Override
...@@ -94,11 +117,11 @@ public class MemberServiceImpl implements MemberService { ...@@ -94,11 +117,11 @@ public class MemberServiceImpl implements MemberService {
94 throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_AND_CODE_ARE_NULL); 117 throw new BadRequestException(GlobeExceptionMsg.MEMBER_ID_AND_CODE_ARE_NULL);
95 118
96 if (StringUtils.isNotBlank(memberCode)) { 119 if (StringUtils.isNotBlank(memberCode)) {
97 MemberDTO memberDTO = this.findByCode(memberCode); 120 Member member = this.memberRepository.findFirstByCode(memberCode).orElseGet(Member::new);
98 return memberDTO; 121 return this.memberMapper.toDto(member);
99 } else if (Objects.nonNull(id)) { 122 } else if (Objects.nonNull(id)) {
100 MemberDTO memberDTO = this.findById(id); 123 Member member = this.memberRepository.findById(id).orElseGet(Member::new);
101 return memberDTO; 124 return this.memberMapper.toDto(member);
102 } 125 }
103 126
104 return null; 127 return null;
...@@ -106,52 +129,104 @@ public class MemberServiceImpl implements MemberService { ...@@ -106,52 +129,104 @@ public class MemberServiceImpl implements MemberService {
106 129
107 @Override 130 @Override
108 public MemberDTO checkMember(Member member) { 131 public MemberDTO checkMember(Member member) {
109
110 String memberCode = member.getCode(); 132 String memberCode = member.getCode();
111 Long memberId = member.getId(); 133 Long memberId = member.getId();
112
113 return this.checkMember(memberId,memberCode); 134 return this.checkMember(memberId,memberCode);
135 }
136
137 @Override
138 @Transactional(rollbackFor = Exception.class)
139 public Integer doUpdateMemberExpAndLevel(Member resource) {
140 return this.memberRepository.updateExpAndLevel(resource);
141 }
114 142
143 @Override
144 @Transactional(rollbackFor = Exception.class)
145 public Integer doUpdateMemberCoupon(Member resource) {
146 return this.memberRepository.doUpdateMemberCoupon(resource);
147 }
148
149 @Override
150 @Transactional(readOnly = true)
151 public MemberDTO findByPlatformAccount(String platformAccount) {
152 log.info("从数据库中检索大屏账号对应的会员, platformAccount ==>> {}", platformAccount);
153 Member member = this.memberRepository.findByPlatformAccount(platformAccount).orElseGet(Member::new);
154 return this.memberMapper.toDto(member);
115 } 155 }
116 156
117 @Override 157 @Override
118 @Transactional(rollbackFor = Exception.class) 158 @Transactional(rollbackFor = Exception.class)
119 public MemberDTO doUpdateMemberExpAndLevel(Member resources) { 159 public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) {
120 this.redisUtils.doLock("member::code" + resources.getCode()); 160 log.info("修改会员vip和vip过期时间 ==>> {}", resource);
121 try { 161 try {
122 MemberDTO memberDTO = this.findById(resources.getId()); 162 // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId());
123 if (Objects.nonNull(memberDTO)) { 163
124 this.memberRepository.updateExpAndLevel(resources); 164 Integer count = this.memberRepository.updateMemberVipAndVipExpireTime(resource);
165 if (Objects.nonNull(count) && count > 0) {
166 Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new);
167 return this.memberMapper.toDto(member);
125 } 168 }
126 return memberDTO; 169
127 } catch (Exception e) { 170 } catch (Exception e) {
128 e.printStackTrace(); 171 log.info("修改会员vip和vip过期时间,"+e.getMessage());
129 throw e;
130 } finally { 172 } finally {
131 this.redisUtils.doUnLock("member::code" + resources.getCode()); 173 // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId());
174 }
175
176 return this.memberMapper.toDto(resource);
132 } 177 }
178
179 @Override
180 @Transactional(rollbackFor = Exception.class)
181 public MemberDTO doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(Member resource) {
182 Integer count = this.memberRepository.updateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(resource);
183 log.info("修改会员绑定关系的结果, count ==>> {}", count);
184 if (count > 0) {
185 Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new);
186 log.info("修改会员绑定关系成功,==>> {}", member);
187 return this.memberMapper.toDto(member);
188 }
189
190 return this.memberMapper.toDto(resource);
133 } 191 }
134 192
135 @Override 193 @Override
136 @Transactional(rollbackFor = Exception.class) 194 @Transactional(rollbackFor = Exception.class)
137 public MemberDTO doUpdateMemberCoupon(Member member) { 195 public MemberDTO doUpdateMemberAvatarUrlAndNicknameAndGender(Member resource) {
138 // MemberDTO memberDTO = this.update(member); 196 log.info("修改会员头像、昵称、性别 ==>> {}", resource);
139 this.redisUtils.doLock("member::code" + member.getCode());
140 try { 197 try {
141 MemberDTO memberDTO = this.findById(member.getId()); 198 // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resource.getId());
142 if (Objects.nonNull(memberDTO)) { 199
143 this.memberRepository.doUpdateMemberCoupon(member); 200 Integer count = this.memberRepository.updateMemberAvatarUrlAndNicknameAndGender(resource);
201 if (Objects.nonNull(count) && count > 0) {
202 Member member = this.memberRepository.findById(resource.getId()).orElseGet(Member::new);
203 return this.memberMapper.toDto(member);
144 } 204 }
145 return memberDTO; 205
146 } catch (Exception e) { 206 } catch (Exception e) {
147 e.printStackTrace(); 207 log.info("修改会员头像、昵称、性别异常,"+e.getMessage());
148 throw e;
149 } finally { 208 } finally {
150 this.redisUtils.doUnLock("member::code" + member.getCode()); 209 // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resource.getId());
151 } 210 }
211
212 return this.memberMapper.toDto(resource);
152 } 213 }
153 214
154 @Override 215 @Override
216 @Transactional(readOnly = true)
217 public Long findExpByMemberId(Long memberId) {
218 return this.memberRepository.findExpByMemberId(memberId);
219 }
220
221 @Override
222 @Transactional(rollbackFor = Exception.class)
223 public Integer doUpdateGroupsBatch(List<Member> resources) {
224 Set<String> codes = resources.stream().map(t -> t.getCode()).collect(Collectors.toSet());
225 return this.memberRepository.doUpdateGroupsBatch( resources.get(0).getGroups(), codes);
226 }
227
228
229 @Override
155 @Transactional(rollbackFor = Exception.class) 230 @Transactional(rollbackFor = Exception.class)
156 public MemberDTO create(Member resources) { 231 public MemberDTO create(Member resources) {
157 232
...@@ -170,38 +245,25 @@ public class MemberServiceImpl implements MemberService { ...@@ -170,38 +245,25 @@ public class MemberServiceImpl implements MemberService {
170 245
171 @Override 246 @Override
172 @Transactional(rollbackFor = Exception.class) 247 @Transactional(rollbackFor = Exception.class)
173 public MemberDTO createAndReturnMember(Member resources) {
174
175 MemberDTO memberDTO = this.create(MemberBuilder.build(resources));
176
177 return memberDTO;
178
179 }
180
181 @Override
182 @Transactional(rollbackFor = Exception.class)
183 public MemberDTO update(Member resources) { 248 public MemberDTO update(Member resources) {
184 249 log.info("修改会员信息 ==>> {}", resources);
185 log.info("MemberServiceImpl ==>> update ==>> resources ==>> [{}]" , resources);
186 this.redisUtils.doLock("member::code" + resources.getCode());
187 try { 250 try {
188 MemberDTO memberDTO = this.checkMember(resources); 251 // this.redisUtils.doLock(RedisKeyConstants.updateCacheMemberById + resources.getId());
189 252
253 MemberDTO memberDTO = this.checkMember(resources);
190 Member member = new Member(); 254 Member member = new Member();
191 BeanUtils.copyProperties(memberDTO,member); 255 BeanUtils.copyProperties(memberDTO,member);
192 member.copy(resources); 256 member.copy(resources);
193
194 Member _member = this.save(member); 257 Member _member = this.save(member);
195
196 return this.memberMapper.toDto(_member); 258 return this.memberMapper.toDto(_member);
197 259
198 } catch (Exception e) { 260 } catch (Exception e) {
199 e.printStackTrace(); 261 log.info(e.getMessage());
200 throw e;
201 } finally { 262 } finally {
202 this.redisUtils.doUnLock("member::code" + resources.getCode()); 263 // this.redisUtils.doUnLock(RedisKeyConstants.updateCacheMemberById + resources.getId());
203 } 264 }
204 265
266 return this.memberMapper.toDto(resources);
205 } 267 }
206 268
207 @Transactional(propagation = Propagation.REQUIRES_NEW) 269 @Transactional(propagation = Propagation.REQUIRES_NEW)
...@@ -211,27 +273,8 @@ public class MemberServiceImpl implements MemberService { ...@@ -211,27 +273,8 @@ public class MemberServiceImpl implements MemberService {
211 273
212 @Override 274 @Override
213 @Transactional(rollbackFor = Exception.class) 275 @Transactional(rollbackFor = Exception.class)
214 public MemberDTO doUpdateMemberPoints(Member resources) { 276 public Integer doUpdateMemberPoints(Member resources) {
215 try { 277 return this.memberRepository.updatePointAndDuePoint(resources);
216 this.redisUtils.doLock("member::code" + resources.getCode());
217
218 /*ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId());
219 member.copy(resources);
220
221 Member _member = this.save(member);*/
222 MemberDTO memberDTO = this.findById(resources.getId());
223 if (Objects.nonNull(memberDTO)) {
224 this.memberRepository.updatePointAndDuePoint(resources);
225 }
226
227 return memberDTO;
228
229 } catch (Exception e) {
230 e.printStackTrace();
231 throw e;
232 } finally {
233 this.redisUtils.doUnLock("member::code" + resources.getCode());
234 }
235 } 278 }
236 279
237 } 280 }
......
1 package com.topdraw.business.module.member.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.member.domain.MemberSimple;
5 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2021-10-22
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface MemberSimpleMapper extends BaseMapper<MemberSimpleDTO, MemberSimple> {
15
16 }
1 package com.topdraw.business.module.member.viphistory.rest;
2
3 import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
4 import com.topdraw.business.process.service.member.MemberOperationService;
5 import com.topdraw.common.ResultInfo;
6 import io.swagger.annotations.Api;
7 import io.swagger.annotations.ApiOperation;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.validation.annotation.Validated;
10 import org.springframework.web.bind.annotation.*;
11
12 /**
13 * @author luerlong
14 * @date 2021-12-10
15 */
16 @Api(tags = "会员vip历史管理")
17 @RestController
18 @RequestMapping("/uce/memberVipHistory")
19 public class MemberVipHistoryController {
20
21 @Autowired
22 private MemberOperationService memberOperationService;
23
24 @PostMapping
25 @ApiOperation("新增MemberVipHistory")
26 public ResultInfo create(@Validated @RequestBody MemberVipHistory resources) {
27 this.memberOperationService.createVipHistory(resources);
28 return ResultInfo.success();
29 }
30
31 }
...@@ -24,7 +24,7 @@ public interface MemberVipHistoryService { ...@@ -24,7 +24,7 @@ public interface MemberVipHistoryService {
24 * 24 *
25 * @param resources 25 * @param resources
26 */ 26 */
27 void create(MemberVipHistory resources); 27 MemberVipHistoryDTO create(MemberVipHistory resources);
28 28
29 /** 29 /**
30 * 30 *
......
...@@ -52,15 +52,14 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService { ...@@ -52,15 +52,14 @@ public class MemberVipHistoryServiceImpl implements MemberVipHistoryService {
52 52
53 @Override 53 @Override
54 @Transactional(rollbackFor = Exception.class) 54 @Transactional(rollbackFor = Exception.class)
55 @AsyncMqSend 55 public MemberVipHistoryDTO create(MemberVipHistory resources) {
56 public void create(MemberVipHistory resources) {
57 log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources); 56 log.info("MemberVipHistoryServiceImpl ==>> MemberVipHistoryServiceImpl ==>> param ==>> [{}]",resources);
58 MemberDTO memberDTO = this.checkMember(resources); 57 MemberDTO memberDTO = this.checkMember(resources);
59 58
60 MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(resources); 59 MemberVipHistory memberVipHistory = MemberVipHistoryBuilder.build(resources);
61 MemberVipHistory vipHistory = this.memberVipHistoryRepository.save(memberVipHistory); 60 MemberVipHistory vipHistory = this.memberVipHistoryRepository.save(memberVipHistory);
62 vipHistory.setMemberCode(memberDTO.getCode()); 61 vipHistory.setMemberCode(memberDTO.getCode());
63 62 return this.memberVipHistoryMapper.toDto(vipHistory);
64 } 63 }
65 64
66 @Override 65 @Override
......
...@@ -101,5 +101,5 @@ public interface PointsAvailableService { ...@@ -101,5 +101,5 @@ public interface PointsAvailableService {
101 * 101 *
102 * @param pointsAvailable 102 * @param pointsAvailable
103 */ 103 */
104 PointsAvailableDTO create4Custom(PointsAvailable pointsAvailable); 104 void create4Custom(PointsAvailable pointsAvailable);
105 } 105 }
......
...@@ -160,17 +160,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { ...@@ -160,17 +160,8 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
160 } 160 }
161 161
162 @Override 162 @Override
163 public PointsAvailableDTO create4Custom(PointsAvailable resources) { 163 public void create4Custom(PointsAvailable resources) {
164 this.redisUtils.doLock("PointsAvailable::create::id"+resources.getMemberId().toString()); 164 this.pointsAvailableRepository.save(resources);
165 try {
166 PointsAvailable pointsAvailable = this.pointsAvailableRepository.save(resources);
167 return this.pointsAvailableMapper.toDto(pointsAvailable);
168 } catch (Exception e) {
169 e.printStackTrace();
170 throw e;
171 } finally {
172 this.redisUtils.doUnLock("PointsAvailable::create::id"+resources.getMemberId().toString());
173 }
174 } 165 }
175 166
176 } 167 }
......
...@@ -88,6 +88,10 @@ public class PointsDetail implements Serializable { ...@@ -88,6 +88,10 @@ public class PointsDetail implements Serializable {
88 @Column(name = "item_id") 88 @Column(name = "item_id")
89 private Long itemId; 89 private Long itemId;
90 90
91 // 状态:0:异常;1:正常
92 @Column(name = "status")
93 private Long status;
94
91 // 创建时间 95 // 创建时间
92 @CreatedDate 96 @CreatedDate
93 @Column(name = "create_time") 97 @Column(name = "create_time")
......
...@@ -3,6 +3,9 @@ package com.topdraw.business.module.points.detail.repository; ...@@ -3,6 +3,9 @@ package com.topdraw.business.module.points.detail.repository;
3 import com.topdraw.business.module.points.detail.domain.PointsDetail; 3 import com.topdraw.business.module.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 import org.springframework.data.jpa.repository.Modifying;
7 import org.springframework.data.jpa.repository.Query;
8 import org.springframework.data.repository.query.Param;
6 9
7 import java.util.List; 10 import java.util.List;
8 import java.util.Optional; 11 import java.util.Optional;
...@@ -16,4 +19,14 @@ public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long ...@@ -16,4 +19,14 @@ public interface PointsDetailRepository extends JpaRepository<PointsDetail, Long
16 Optional<PointsDetail> findFirstByCode(String code); 19 Optional<PointsDetail> findFirstByCode(String code);
17 20
18 List<PointsDetail> findByMemberId(Long memberId); 21 List<PointsDetail> findByMemberId(Long memberId);
22
23
24 @Modifying
25 @Query(value = "INSERT INTO `uc_points_detail`(`code`, `app_code`, `member_id`, `account_id`, `original_points`, `result_points`, " +
26 " `points`, `device_type`, `evt_type`, `order_id`, `media_id`, `activity_id`, `item_id`, `status`, `description`, `create_time`, `update_time`)" +
27 " VALUES (:#{#resources.code}, :#{#resources.appCode}, :#{#resources.memberId}, :#{#resources.accountId}," +
28 " :#{#resources.originalPoints}, :#{#resources.resultPoints}, :#{#resources.points}, :#{#resources.deviceType}," +
29 " :#{#resources.evtType}, :#{#resources.orderId}, :#{#resources.mediaId}, :#{#resources.activityId}, " +
30 " :#{#resources.itemId}, :#{#resources.status}, :#{#resources.description}, now(), now())", nativeQuery = true)
31 Integer insertPointsDetail(@Param("resources") PointsDetail pointsDetail);
19 } 32 }
......
...@@ -46,13 +46,6 @@ public interface PointsDetailService { ...@@ -46,13 +46,6 @@ public interface PointsDetailService {
46 PointsDetailDTO getByCode(String code); 46 PointsDetailDTO getByCode(String code);
47 47
48 /** 48 /**
49 *
50 * @param memberId
51 * @return
52 */
53 List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId);
54
55 /**
56 * 已过期的积分 49 * 已过期的积分
57 * @param memberId 50 * @param memberId
58 * @return 51 * @return
...@@ -63,5 +56,5 @@ public interface PointsDetailService { ...@@ -63,5 +56,5 @@ public interface PointsDetailService {
63 * 56 *
64 * @param pointsDetail 57 * @param pointsDetail
65 */ 58 */
66 void create4Custom(PointsDetail pointsDetail); 59 void insertPointsDetail(PointsDetail pointsDetail);
67 } 60 }
......
...@@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable { ...@@ -54,6 +54,9 @@ public class PointsDetailDTO implements Serializable {
54 // 积分变化描述,用于管理侧显示 54 // 积分变化描述,用于管理侧显示
55 private String description; 55 private String description;
56 56
57 // 状态:0:异常;1:正常
58 private Long status;
59
57 // 商品id 60 // 商品id
58 private Long itemId; 61 private Long itemId;
59 62
......
...@@ -31,6 +31,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { ...@@ -31,6 +31,7 @@ public class PointsDetailServiceImpl implements PointsDetailService {
31 private PointsDetailMapper pointsDetailMapper; 31 private PointsDetailMapper pointsDetailMapper;
32 32
33 @Override 33 @Override
34 @Transactional(readOnly = true)
34 public PointsDetailDTO findById(Long id) { 35 public PointsDetailDTO findById(Long id) {
35 PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new); 36 PointsDetail pointsDetail = this.pointsDetailRepository.findById(id).orElseGet(PointsDetail::new);
36 ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id); 37 ValidationUtil.isNull(pointsDetail.getId(),"PointsDetail","id",id);
...@@ -40,8 +41,7 @@ public class PointsDetailServiceImpl implements PointsDetailService { ...@@ -40,8 +41,7 @@ public class PointsDetailServiceImpl implements PointsDetailService {
40 @Override 41 @Override
41 @Transactional(rollbackFor = Exception.class) 42 @Transactional(rollbackFor = Exception.class)
42 public PointsDetailDTO create(PointsDetail resources) { 43 public PointsDetailDTO create(PointsDetail resources) {
43 PointsDetail pointsDetail = this.pointsDetailRepository.save(resources); 44 return this.pointsDetailMapper.toDto(this.pointsDetailRepository.save(resources));
44 return this.pointsDetailMapper.toDto(pointsDetail);
45 } 45 }
46 46
47 @Override 47 @Override
...@@ -65,17 +65,14 @@ public class PointsDetailServiceImpl implements PointsDetailService { ...@@ -65,17 +65,14 @@ public class PointsDetailServiceImpl implements PointsDetailService {
65 65
66 66
67 @Override 67 @Override
68 @Transactional(readOnly = true)
68 public PointsDetailDTO getByCode(String code) { 69 public PointsDetailDTO getByCode(String code) {
69 return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new)) 70 return StringUtils.isNotEmpty(code) ? this.pointsDetailMapper.toDto(this.pointsDetailRepository.findFirstByCode(code).orElseGet(PointsDetail::new))
70 : new PointsDetailDTO(); 71 : new PointsDetailDTO();
71 } 72 }
72 73
73 @Override 74 @Override
74 public List<PointsDetailDTO> loadListExpirePointsByMemberId(Long memberId) { 75 @Transactional(readOnly = true)
75 return null;
76 }
77
78 @Override
79 public List<PointsDetailDTO> findByMemberId(Long memberId) { 76 public List<PointsDetailDTO> findByMemberId(Long memberId) {
80 return Objects.nonNull(memberId)? 77 return Objects.nonNull(memberId)?
81 this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId)) 78 this.pointsDetailMapper.toDto(this.pointsDetailRepository.findByMemberId(memberId))
...@@ -83,7 +80,8 @@ public class PointsDetailServiceImpl implements PointsDetailService { ...@@ -83,7 +80,8 @@ public class PointsDetailServiceImpl implements PointsDetailService {
83 } 80 }
84 81
85 @Override 82 @Override
86 public void create4Custom(PointsDetail pointsDetail) { 83 @Transactional(rollbackFor = Exception.class)
87 this.pointsDetailRepository.save(pointsDetail); 84 public void insertPointsDetail(PointsDetail pointsDetail) {
85 this.pointsDetailRepository.insertPointsDetail(pointsDetail);
88 } 86 }
89 } 87 }
......
1 package com.topdraw.business.process.domian.constant; 1 package com.topdraw.business.module.rights.constant;
2 2
3 public enum RightType { 3 public enum RightType {
4 /**积分*/ 4 /**积分*/
......
1 package com.topdraw.business.module.rights.constant;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/18 16:06
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/18 16:06
11 */
12 public interface RightTypeConstants {
13
14 // 优惠券
15 int DISCOUNT_COUPON = 1;
16 // 观影券
17 int VIEW_COUPON= 2;
18 // 参加活动
19 int JOIN_ACTIVITY = 3;
20 // 积分商品
21 int POINTS_GOODS = 4;
22 // IPTV产品包
23 int IPTV_PRODUCT = 5;
24 // IPTV观影权益
25 int IPTV_VIEW = 6;
26
27 }
1 package com.topdraw.business.module.rights.constant;
2
3 public class RightsType {
4
5 public static String TYPE_1 = "1";
6 Integer TYPE_2 = 2;
7 Integer TYPE_3 = 3;
8
9 }
...@@ -47,7 +47,7 @@ public class Rights implements Serializable { ...@@ -47,7 +47,7 @@ public class Rights implements Serializable {
47 47
48 /** 权益的实体类型 1:积分;2成长值;3优惠券 */ 48 /** 权益的实体类型 1:积分;2成长值;3优惠券 */
49 @Column(name = "entity_type", nullable = false) 49 @Column(name = "entity_type", nullable = false)
50 private String entityType; 50 private Integer entityType;
51 51
52 /** 实体id */ 52 /** 实体id */
53 @Column(name = "entity_id", nullable = false) 53 @Column(name = "entity_id", nullable = false)
......
...@@ -28,7 +28,7 @@ public class RightsDTO implements Serializable { ...@@ -28,7 +28,7 @@ public class RightsDTO implements Serializable {
28 private Integer type; 28 private Integer type;
29 29
30 /** 权益的实体类型 1:积分;2成长值;3优惠券 */ 30 /** 权益的实体类型 1:积分;2成长值;3优惠券 */
31 private String entityType; 31 private Integer entityType;
32 32
33 /** 实体id */ 33 /** 实体id */
34 private Long entityId; 34 private Long entityId;
......
1 package com.topdraw.business.module.rights.service.impl; 1 package com.topdraw.business.module.rights.service.impl;
2 2
3 import com.topdraw.business.module.rights.domain.Rights; 3 import com.topdraw.business.module.rights.domain.Rights;
4 import com.topdraw.business.RedisKeyConstants;
4 import com.topdraw.utils.*; 5 import com.topdraw.utils.*;
5 import com.topdraw.business.module.rights.repository.RightsRepository; 6 import com.topdraw.business.module.rights.repository.RightsRepository;
6 import com.topdraw.business.module.rights.service.RightsService; 7 import com.topdraw.business.module.rights.service.RightsService;
7 import com.topdraw.business.module.rights.service.dto.RightsDTO; 8 import com.topdraw.business.module.rights.service.dto.RightsDTO;
8 import com.topdraw.business.module.rights.service.mapper.RightsMapper; 9 import com.topdraw.business.module.rights.service.mapper.RightsMapper;
9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.cache.annotation.Cacheable;
10 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation; 13 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
...@@ -25,9 +27,9 @@ public class RightsServiceImpl implements RightsService { ...@@ -25,9 +27,9 @@ public class RightsServiceImpl implements RightsService {
25 private RightsMapper rightsMapper; 27 private RightsMapper rightsMapper;
26 28
27 @Override 29 @Override
30 @Cacheable(cacheNames = RedisKeyConstants.cacheRightById, key = "#id", unless = "#result.id == null")
28 public RightsDTO findById(Long id) { 31 public RightsDTO findById(Long id) {
29 Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new); 32 Rights Rights = this.rightsRepository.findById(id).orElseGet(Rights::new);
30 ValidationUtil.isNull(Rights.getId(),"Rights","id",id);
31 return this.rightsMapper.toDto(Rights); 33 return this.rightsMapper.toDto(Rights);
32 } 34 }
33 35
......
...@@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository; ...@@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository;
3 import com.topdraw.business.module.task.attribute.domain.TaskAttr; 3 import com.topdraw.business.module.task.attribute.domain.TaskAttr;
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.Query;
6 7
8 import java.util.List;
9 import java.util.Map;
7 import java.util.Optional; 10 import java.util.Optional;
11 import java.util.Set;
8 12
9 /** 13 /**
10 * @author XiangHan 14 * @author XiangHan
...@@ -13,4 +17,7 @@ import java.util.Optional; ...@@ -13,4 +17,7 @@ import java.util.Optional;
13 public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> { 17 public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> {
14 18
15 Optional<TaskAttr> findByTaskId(Long taskId); 19 Optional<TaskAttr> findByTaskId(Long taskId);
20
21 @Query(value = "SELECT * FROM `tr_task_attr` WHERE task_id IN(?1)", nativeQuery = true)
22 List<Map<String, Object>> findTasksByTaskIds(Set<Object> taskIds);
16 } 23 }
......
...@@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service; ...@@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service;
3 import com.topdraw.business.module.task.attribute.domain.TaskAttr; 3 import com.topdraw.business.module.task.attribute.domain.TaskAttr;
4 import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; 4 import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
5 5
6 import java.util.List;
7 import java.util.Set;
8
6 /** 9 /**
7 * @author XiangHan 10 * @author XiangHan
8 * @date 2022-01-13 11 * @date 2022-01-13
...@@ -39,4 +42,6 @@ public interface TaskAttrService { ...@@ -39,4 +42,6 @@ public interface TaskAttrService {
39 * @return 42 * @return
40 */ 43 */
41 TaskAttrDTO findByTaskId(Long taskId); 44 TaskAttrDTO findByTaskId(Long taskId);
45
46 List<TaskAttrDTO> findTasksByTaskIds(Set<Object> id);
42 } 47 }
......
1 package com.topdraw.business.module.task.attribute.service.impl; 1 package com.topdraw.business.module.task.attribute.service.impl;
2 2
3 import com.alibaba.fastjson.JSON;
3 import com.topdraw.business.module.task.attribute.domain.TaskAttr; 4 import com.topdraw.business.module.task.attribute.domain.TaskAttr;
4 import com.topdraw.utils.ValidationUtil; 5 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository; 6 import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository;
...@@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation; ...@@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional; 13 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException; 14 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert; 15 import org.springframework.util.Assert;
16 import org.springframework.util.CollectionUtils;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
15 22
16 /** 23 /**
17 * @author XiangHan 24 * @author XiangHan
...@@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService { ...@@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService {
64 return this.taskAttrMapper.toDto(taskAttr); 71 return this.taskAttrMapper.toDto(taskAttr);
65 } 72 }
66 73
74 @Override
75 public List<TaskAttrDTO> findTasksByTaskIds(Set<Object> taskIds) {
76 List<Map<String,Object>> maps = this.taskAttrRepository.findTasksByTaskIds(taskIds);
77 if (!CollectionUtils.isEmpty(maps)) {
78 List<TaskAttr> taskAttrs = new ArrayList<>();
79 for (Map<String, Object> map : maps) {
80 TaskAttr taskAttr = JSON.parseObject(JSON.toJSONString(map), TaskAttr.class);
81 taskAttrs.add(taskAttr);
82 }
83
84 return this.taskAttrMapper.toDto(taskAttrs);
85 }
86 return new ArrayList<>();
87 }
88
67 89
68 } 90 }
......
...@@ -15,6 +15,7 @@ import java.sql.Timestamp; ...@@ -15,6 +15,7 @@ import java.sql.Timestamp;
15 15
16 import java.io.Serializable; 16 import java.io.Serializable;
17 import java.time.LocalDateTime; 17 import java.time.LocalDateTime;
18 import java.util.List;
18 19
19 /** 20 /**
20 * @author XiangHan 21 * @author XiangHan
...@@ -151,6 +152,9 @@ public class Task implements Serializable { ...@@ -151,6 +152,9 @@ public class Task implements Serializable {
151 @Transient 152 @Transient
152 private String attr; 153 private String attr;
153 154
155 @Transient
156 private Integer event;
157
154 /** 创建时间 */ 158 /** 创建时间 */
155 @CreatedDate 159 @CreatedDate
156 @Column(name = "create_time") 160 @Column(name = "create_time")
......
...@@ -61,7 +61,7 @@ public class TaskBuilder { ...@@ -61,7 +61,7 @@ public class TaskBuilder {
61 61
62 task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark()); 62 task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark());
63 63
64 task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr()); 64 // task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr());
65 return task_; 65 return task_;
66 } 66 }
67 67
......
...@@ -27,6 +27,9 @@ import java.io.Serializable; ...@@ -27,6 +27,9 @@ import java.io.Serializable;
27 @NoArgsConstructor 27 @NoArgsConstructor
28 public class TrTaskProgress implements Serializable { 28 public class TrTaskProgress implements Serializable {
29 29
30 @Transient
31 private String memberCode;
32
30 @Id 33 @Id
31 @GeneratedValue(strategy = GenerationType.IDENTITY) 34 @GeneratedValue(strategy = GenerationType.IDENTITY)
32 @Column(name = "id") 35 @Column(name = "id")
......
...@@ -5,7 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -5,7 +5,10 @@ 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.Query; 6 import org.springframework.data.jpa.repository.Query;
7 7
8 import java.util.HashMap;
8 import java.util.List; 9 import java.util.List;
10 import java.util.Map;
11 import java.util.Optional;
9 12
10 /** 13 /**
11 * @author XiangHan 14 * @author XiangHan
...@@ -13,8 +16,17 @@ import java.util.List; ...@@ -13,8 +16,17 @@ import java.util.List;
13 */ 16 */
14 public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> { 17 public interface TrTaskProgressRepository extends JpaRepository<TrTaskProgress, Long>, JpaSpecificationExecutor<TrTaskProgress> {
15 18
16 @Query(value = "select id, member_id, task_id , current_action_amount , \n" + 19 @Query(value = "select id, member_id, task_id, current_action_amount," +
17 " target_action_amount , `status` , completion_time,create_time,update_time from uc_tr_task_progress where member_id = ?1 \n" + 20 " target_action_amount, `status`, completion_time, create_time, update_time from uc_tr_task_progress where member_id = ?1 " +
18 " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true) 21 " and task_id = ?2 and Date(completion_time) = ?3 ",nativeQuery = true)
19 List<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); 22 Optional<TrTaskProgress> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
23
24
25 Integer countByMemberIdAndTaskId(Long memberId, Long taskId);
26
27 @Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and `status` = 1 GROUP BY `task_id` ", nativeQuery = true)
28 List<Map<String, Object>> countFinishTaskGroupByMemberId(Long memberId);
29
30 @Query(value = "select `task_id` AS taskId, count(*) AS finishCount from uc_tr_task_progress where member_id = ?1 and Date(completion_time) = ?2 and `status` = 1 GROUP BY `task_id`", nativeQuery = true)
31 List<Map<String, Object>> countFinishTaskGroupByMemberIdAndToday(Long memberId, String todayStart);
20 } 32 }
......
...@@ -2,7 +2,11 @@ package com.topdraw.business.module.task.progress.service; ...@@ -2,7 +2,11 @@ package com.topdraw.business.module.task.progress.service;
2 2
3 import com.topdraw.business.module.task.progress.domain.TrTaskProgress; 3 import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
4 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; 4 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
5
6 import java.time.LocalDateTime;
7 import java.util.HashMap;
5 import java.util.List; 8 import java.util.List;
9 import java.util.Map;
6 10
7 /** 11 /**
8 * @author XiangHan 12 * @author XiangHan
...@@ -21,13 +25,13 @@ public interface TrTaskProgressService { ...@@ -21,13 +25,13 @@ public interface TrTaskProgressService {
21 * 25 *
22 * @param resources 26 * @param resources
23 */ 27 */
24 void create(TrTaskProgress resources); 28 TrTaskProgress create(TrTaskProgress resources, String date);
25 29
26 /** 30 /**
27 * 31 *
28 * @param resources 32 * @param resources
29 */ 33 */
30 void update(TrTaskProgress resources); 34 TrTaskProgress update(TrTaskProgress resources, String date);
31 35
32 /** 36 /**
33 * 37 *
...@@ -42,5 +46,28 @@ public interface TrTaskProgressService { ...@@ -42,5 +46,28 @@ public interface TrTaskProgressService {
42 * @param time1 46 * @param time1
43 * @return 47 * @return
44 */ 48 */
45 List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1); 49 TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1);
50
51 /**
52 *
53 * @param memberId
54 * @param taskId
55 * @return
56 */
57 Integer countByMemberIdAndTaskId(Long memberId, Long taskId);
58
59 /**
60 *
61 * @param id
62 * @return
63 */
64 Map<Object, Object> countTotalFinishTaskByMemberId(Long id);
65
66 /**
67 *
68 * @param id
69 * @param todayStart
70 * @return
71 */
72 Map<Object, Object> countTodayFinishTaskByMemberId(Long id, String todayStart);
46 } 73 }
......
1 package com.topdraw.business.module.task.progress.service.impl; 1 package com.topdraw.business.module.task.progress.service.impl;
2 2
3 import com.topdraw.business.module.task.progress.domain.TrTaskProgress; 3 import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
4 import com.topdraw.utils.ValidationUtil; 4 import com.topdraw.business.RedisKeyConstants;
5 import com.topdraw.utils.RedisUtils;
5 import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository; 6 import com.topdraw.business.module.task.progress.repository.TrTaskProgressRepository;
6 import com.topdraw.business.module.task.progress.service.TrTaskProgressService; 7 import com.topdraw.business.module.task.progress.service.TrTaskProgressService;
7 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO; 8 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
8 import com.topdraw.business.module.task.progress.service.mapper.TrTaskProgressMapper; 9 import com.topdraw.business.module.task.progress.service.mapper.TrTaskProgressMapper;
10 import lombok.extern.slf4j.Slf4j;
9 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation; 13 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException; 15 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert; 16 import org.springframework.util.Assert;
17 import org.springframework.util.CollectionUtils;
15 18
16 import java.util.List; 19 import java.time.LocalDate;
20 import java.util.*;
17 21
18 /** 22 /**
19 * @author XiangHan 23 * @author XiangHan
...@@ -21,34 +25,35 @@ import java.util.List; ...@@ -21,34 +25,35 @@ import java.util.List;
21 */ 25 */
22 @Service 26 @Service
23 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 27 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
28 @Slf4j
24 public class TrTaskProgressServiceImpl implements TrTaskProgressService { 29 public class TrTaskProgressServiceImpl implements TrTaskProgressService {
25 30
26 @Autowired 31 @Autowired
27 private TrTaskProgressRepository trTaskProgressRepository; 32 private TrTaskProgressRepository trTaskProgressRepository;
28
29 @Autowired 33 @Autowired
30 private TrTaskProgressMapper trTaskProgressMapper; 34 private TrTaskProgressMapper trTaskProgressMapper;
31 35
36 @Autowired
37 private RedisUtils redisUtils;
38
32 @Override 39 @Override
33 public TrTaskProgressDTO findById(Long id) { 40 public TrTaskProgressDTO findById(Long id) {
34 TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new); 41 TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(id).orElseGet(TrTaskProgress::new);
35 ValidationUtil.isNull(TrTaskProgress.getId(),"TrTaskProgress","id",id);
36 return this.trTaskProgressMapper.toDto(TrTaskProgress); 42 return this.trTaskProgressMapper.toDto(TrTaskProgress);
37 } 43 }
38 44
39 @Override 45 @Override
40 @Transactional(rollbackFor = Exception.class) 46 @Transactional(rollbackFor = Exception.class)
41 public void create(TrTaskProgress resources) { 47 // @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
42 this.trTaskProgressRepository.save(resources); 48 public TrTaskProgress create(TrTaskProgress resources, String date) {
49 return this.trTaskProgressRepository.save(resources);
43 } 50 }
44 51
45 @Override 52 @Override
46 @Transactional(rollbackFor = Exception.class) 53 @Transactional(rollbackFor = Exception.class)
47 public void update(TrTaskProgress resources) { 54 // @CachePut(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#resources.memberId+':'+#resources.taskId+':'+#date", unless = "#result == null ")
48 TrTaskProgress TrTaskProgress = this.trTaskProgressRepository.findById(resources.getId()).orElseGet(TrTaskProgress::new); 55 public TrTaskProgress update(TrTaskProgress resources, String date) {
49 ValidationUtil.isNull( TrTaskProgress.getId(),"TrTaskProgress","id",resources.getId()); 56 return this.trTaskProgressRepository.save(resources);
50 TrTaskProgress.copy(resources);
51 this.trTaskProgressRepository.save(TrTaskProgress);
52 } 57 }
53 58
54 @Override 59 @Override
...@@ -61,8 +66,73 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { ...@@ -61,8 +66,73 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService {
61 } 66 }
62 67
63 @Override 68 @Override
64 public List<TrTaskProgressDTO> findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) { 69 // @Cacheable(cacheNames = RedisKeyConstants.cacheTaskProcessByMemberId, key = "#memberId+':'+#taskId+':'+#time1", unless = "#result.id == null")
65 return this.trTaskProgressMapper.toDto(this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1)); 70 public TrTaskProgress findByMemberIdAndTaskIdAndCompletionTime(Long memberId, Long taskId, String time1) {
71 log.info("从数据库查询当前会员今天是否完成了此任务, memberId ==>> {} || taskId ==>> {}", memberId, taskId);
72 return this.trTaskProgressRepository.findByMemberIdAndTaskIdAndCompletionTime(memberId, taskId, time1).orElseGet(TrTaskProgress::new);
73 }
74
75 @Override
76 public Integer countByMemberIdAndTaskId(Long memberId, Long taskId) {
77 return this.trTaskProgressRepository.countByMemberIdAndTaskId(memberId, taskId);
78 }
79
80 @Override
81 public Map<Object, Object> countTotalFinishTaskByMemberId(Long memberId) {
82 Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId);
83 if (Objects.isNull(hmget)) {
84 List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberId(memberId);
85 if (!CollectionUtils.isEmpty(maps)) {
86 Map<Object, Object> finishTasks = new HashMap<>();
87 for (Map<String, Object> map : maps) {
88 Object taskId = map.get("taskId");
89 if (Objects.isNull(taskId)) {
90 continue;
91 }
92 finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString()));
93
94 }
95 if (finishTasks.size() > 0) {
96 // 总记录一直存储
97 this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks);
98 }
99
100 return finishTasks;
101 }
102 }
103
104 return hmget;
105 }
106
107 @Override
108 public Map<Object, Object> countTodayFinishTaskByMemberId(Long memberId, String todayStart) {
109
110 Map<Object, Object> hmget = this.redisUtils.hmget(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + todayStart);
111 if (Objects.isNull(hmget)) {
112 List<Map<String, Object>> maps = this.trTaskProgressRepository.countFinishTaskGroupByMemberIdAndToday(memberId, todayStart);
113 if (!CollectionUtils.isEmpty(maps)){
114 Map<Object, Object> finishTasks = new HashMap<>();
115 for (Map<String, Object> map : maps) {
116 Object taskId = map.get("taskId");
117 if (Objects.isNull(taskId)) {
118 continue;
119 }
120
121 finishTasks.put(taskId, Integer.valueOf(map.get("finishCount").toString()));
122
123 }
124
125 if (finishTasks.size() > 0) {
126 // 单天的记录只存储一天
127 this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60);
128 }
129
130 return finishTasks;
131
132 }
133 }
134
135 return hmget;
66 } 136 }
67 137
68 138
......
...@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; ...@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
8 import org.springframework.transaction.annotation.Transactional; 8 import org.springframework.transaction.annotation.Transactional;
9 9
10 import java.util.List; 10 import java.util.List;
11 import java.util.Map;
11 import java.util.Optional; 12 import java.util.Optional;
12 13
13 /** 14 /**
...@@ -21,7 +22,12 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat ...@@ -21,7 +22,12 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat
21 @Modifying 22 @Modifying
22 @Transactional 23 @Transactional
23 @Query(value = "UPDATE `tr_task` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true) 24 @Query(value = "UPDATE `tr_task` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
24 void updateDeleteMark(Long id); 25 Integer updateDeleteMark(Long id);
25 26
26 Optional<Task> findByCode(String code); 27 Optional<Task> findByCode(String code);
28
29 @Query(value = "SELECT ta.* FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " +
30 " WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " +
31 " tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true)
32 List<Map<String,Object>> findByEventAndLevelAndVip(Integer event, Integer level, Integer vip);
27 } 33 }
......
1 package com.topdraw.business.module.task.service; 1 package com.topdraw.business.module.task.service;
2 2
3 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
3 import com.topdraw.business.module.task.domain.Task; 4 import com.topdraw.business.module.task.domain.Task;
5 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
4 import com.topdraw.business.module.task.service.dto.TaskDTO; 6 import com.topdraw.business.module.task.service.dto.TaskDTO;
7
8 import java.time.LocalDateTime;
5 import java.util.List; 9 import java.util.List;
6 10
7 /** 11 /**
...@@ -47,11 +51,19 @@ public interface TaskService { ...@@ -47,11 +51,19 @@ public interface TaskService {
47 * 51 *
48 * @param task 52 * @param task
49 */ 53 */
50 void delete(Task task); 54 Integer delete(Task task);
51 55
52 /** 56 /**
53 * 57 *
54 * @param id 58 * @param id
55 */ 59 */
56 void delete(Long id); 60 Integer delete(Long id);
61
62 /**
63 *
64 * @param event
65 * @return
66 */
67 List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip);
68
57 } 69 }
......
1 package com.topdraw.business.module.task.service.impl; 1 package com.topdraw.business.module.task.service.impl;
2 2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONArray;
5 import com.alibaba.fastjson.JSONObject;
6 import com.topdraw.business.module.task.attribute.service.TaskAttrService;
7 import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
3 import com.topdraw.business.module.task.domain.Task; 8 import com.topdraw.business.module.task.domain.Task;
4 import com.topdraw.business.module.task.repository.TaskRepository; 9 import com.topdraw.business.module.task.repository.TaskRepository;
5 import com.topdraw.business.module.task.service.TaskService; 10 import com.topdraw.business.module.task.service.TaskService;
6 import com.topdraw.business.module.task.service.dto.TaskDTO; 11 import com.topdraw.business.module.task.service.dto.TaskDTO;
7 import com.topdraw.business.module.task.service.mapper.TaskMapper; 12 import com.topdraw.business.module.task.service.mapper.TaskMapper;
13 import com.topdraw.business.RedisKeyConstants;
14 import com.topdraw.utils.RedisUtils;
15 import lombok.extern.slf4j.Slf4j;
8 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
10 import org.springframework.transaction.annotation.Propagation; 18 import org.springframework.transaction.annotation.Propagation;
11 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
20 import org.springframework.util.CollectionUtils;
12 21
22 import java.util.ArrayList;
13 import java.util.List; 23 import java.util.List;
24 import java.util.Map;
14 import java.util.Objects; 25 import java.util.Objects;
26 import java.util.stream.Collectors;
15 27
16 /** 28 /**
17 * @author XiangHan 29 * @author XiangHan
...@@ -19,12 +31,18 @@ import java.util.Objects; ...@@ -19,12 +31,18 @@ import java.util.Objects;
19 */ 31 */
20 @Service 32 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 33 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
34 @Slf4j
22 public class TaskServiceImpl implements TaskService { 35 public class TaskServiceImpl implements TaskService {
23 36
24 @Autowired 37 @Autowired
38 private TaskAttrService taskAttrService;
39
40 @Autowired
25 private TaskMapper taskMapper; 41 private TaskMapper taskMapper;
26 @Autowired 42 @Autowired
27 private TaskRepository taskRepository; 43 private TaskRepository taskRepository;
44 @Autowired
45 private RedisUtils redisUtils;
28 46
29 @Override 47 @Override
30 public TaskDTO findById(Long id) { 48 public TaskDTO findById(Long id) {
...@@ -56,14 +74,70 @@ public class TaskServiceImpl implements TaskService { ...@@ -56,14 +74,70 @@ public class TaskServiceImpl implements TaskService {
56 } 74 }
57 75
58 @Override 76 @Override
59 public void delete(Task task) { 77 public Integer delete(Task task) {
60 Long id = task.getId(); 78 Long id = task.getId();
61 this.delete(id); 79 return this.delete(id);
62 } 80 }
63 81
64 @Override 82 @Override
65 public void delete(Long id) { 83 public Integer delete(Long id) {
66 this.taskRepository.updateDeleteMark(id); 84 return this.taskRepository.updateDeleteMark(id);
85 }
86
87 @Override
88 @Transactional(readOnly = true)
89 public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) {
90 try {
91 boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip);
92
93 if (b) {
94 List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1);
95 return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class);
96 }
97
98 List<Map<String, Object>> maps = this.taskRepository.findByEventAndLevelAndVip(event, level, vip);
99
100 List<Task> tasks = new ArrayList<>();
101 if (CollectionUtils.isEmpty(maps)) {
102 return tasks;
103 }
104
105 List<TaskAttrDTO> taskAttrDTOS = this.taskAttrService.findTasksByTaskIds(maps.stream().map(t -> t.get("id")).collect(Collectors.toSet()));
106
107 if (!CollectionUtils.isEmpty(taskAttrDTOS)) {
108
109 for (Map<String, Object> map : maps) {
110 Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
111
112 List<String> taskAttrs = taskAttrDTOS.stream().filter(taskAttrDTO -> taskAttrDTO.getTaskId().equals(task.getId())).
113 map(TaskAttrDTO::getAttrStr).collect(Collectors.toList());
114 log.info("任务属性值, dealTask# taskAttrs ==>> {}", taskAttrs);
115 if (!CollectionUtils.isEmpty(taskAttrs)) {
116 task.setAttr(String.join(",", taskAttrs));
117 }
118
119 tasks.add(task);
120 }
121
122 } else {
123
124 for (Map<String, Object> map : maps) {
125 Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
126 tasks.add(task);
127 }
128
129 }
130
131 if (!CollectionUtils.isEmpty(tasks)) {
132 this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60);
67 } 133 }
68 134
135 return tasks;
136
137 } catch (Exception e) {
138 log.error(e.getMessage());
139 }
140
141 return new ArrayList<>();
142 }
69 } 143 }
......
1 package com.topdraw.business.module.task.template.constant;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/18 14:30
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/18 14:30
11 */
12 public interface TaskEventType {
13 //类型 1:登录;2:观影;3:参加活动;4:订购;5:优享会员;6:签到;7:完成设置;
14 // 8:播放记录;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
15 int LOGIN = 1;
16 int VIEW = 2;
17 int ACTIVITY = 3;
18 int ORDER = 4;
19 int MEMBER_PRIORITY = 5;
20 int SIGN = 6;
21 int COMPLETE_INFO = 7;
22 int PLAY = 8;
23 int BINDING = 10;
24 int POINTS_TRANS = 11;
25 int POINTS_EXCHANGE_GOODS = 30;
26 int SYSTEM_OPERATE = 98;
27 int OHHER = 99;
28
29 }
...@@ -26,4 +26,6 @@ public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long ...@@ -26,4 +26,6 @@ public interface TaskTemplateRepository extends JpaRepository<TaskTemplate, Long
26 @Transactional 26 @Transactional
27 @Query(value = "UPDATE `tr_task_template` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true) 27 @Query(value = "UPDATE `tr_task_template` SET `delete_mark` = 1 , `update_time` = now() WHERE `id` = ?1", nativeQuery = true)
28 void updateDeleteMark(Long id); 28 void updateDeleteMark(Long id);
29
30 Long countByCodeAndType(String code, Integer type);
29 } 31 }
......
...@@ -61,4 +61,11 @@ public interface TaskTemplateService { ...@@ -61,4 +61,11 @@ public interface TaskTemplateService {
61 * @return 61 * @return
62 */ 62 */
63 TaskTemplateDTO findByType(Integer event); 63 TaskTemplateDTO findByType(Integer event);
64
65 /**
66 *
67 * @param taskTemplate
68 * @return
69 */
70 Long countByCodeAndType(TaskTemplate taskTemplate);
64 } 71 }
......
...@@ -83,4 +83,10 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { ...@@ -83,4 +83,10 @@ public class TaskTemplateServiceImpl implements TaskTemplateService {
83 return Objects.nonNull(event) ? this.taskTemplateMapper.toDto(this.taskTemplateRepository.findByType(event).orElseGet(TaskTemplate::new)) : new TaskTemplateDTO(); 83 return Objects.nonNull(event) ? this.taskTemplateMapper.toDto(this.taskTemplateRepository.findByType(event).orElseGet(TaskTemplate::new)) : new TaskTemplateDTO();
84 } 84 }
85 85
86 @Override
87 public Long countByCodeAndType(TaskTemplate taskTemplate) {
88 Long count = this.taskTemplateRepository.countByCodeAndType(taskTemplate.getCode(), taskTemplate.getType());
89 return count;
90 }
91
86 } 92 }
......
1 package com.topdraw.business.module.user.app.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-06-27
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_user_app")
24 public class UserApp implements Serializable {
25
26 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
27 @Transient
28 private Integer accountType;
29
30 // 第三方账号
31 @Transient
32 private String account;
33
34 // ID
35 @Id
36 @GeneratedValue(strategy = GenerationType.IDENTITY)
37 @Column(name = "id")
38 private Long id;
39
40 // 会员id
41 @Column(name = "member_id")
42 private Long memberId;
43
44 // 用户名(一般为手机号)
45 @Column(name = "username", nullable = false)
46 private String username;
47
48 // 密码
49 @Column(name = "password")
50 private String password;
51
52 // 类型 0:苹果;1:安卓;-1:未知
53 @Column(name = "type", nullable = false)
54 private Integer type;
55
56 // 状态 0:禁用;1:生效;-1:注销
57 @Column(name = "status", nullable = false)
58 private Integer status;
59
60 // 昵称
61 @Column(name = "nickname")
62 private String nickname;
63
64 // 头像地址
65 @Column(name = "headimgurl")
66 private String headimgurl;
67
68 // 邮箱
69 @Column(name = "email")
70 private String email;
71
72 // 手机号
73 @Column(name = "cellphone")
74 private String cellphone;
75
76 // 性别 0:女;1:男;-1:其他
77 @Column(name = "gender")
78 private Integer gender;
79
80 // 生日
81 @Column(name = "birthday")
82 private String birthday;
83
84 // 最近活跃时间
85 @Column(name = "last_active_time")
86 private Timestamp lastActiveTime;
87
88 // 注销时间
89 @Column(name = "delete_time")
90 private Timestamp deleteTime;
91
92 // 标签
93 @Column(name = "tags")
94 private String tags;
95
96 // 描述
97 @Column(name = "description")
98 private String description;
99
100 // 创建时间
101 @CreatedDate
102 @Column(name = "create_time")
103 private Timestamp createTime;
104
105 // 更新时间
106 @LastModifiedDate
107 @Column(name = "update_time")
108 private Timestamp updateTime;
109
110 public void copy(UserApp source){
111 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
112 }
113 }
1 package com.topdraw.business.module.user.app.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-06-27
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_user_app_bind")
24 public class UserAppBind implements Serializable {
25
26 @Transient
27 private String username;
28
29 @Transient
30 private String password;
31 @Transient
32 private String headimgurl;
33
34 // 主键
35 @Id
36 @GeneratedValue(strategy = GenerationType.IDENTITY)
37 @Column(name = "id")
38 private Long id;
39
40 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
41 @Column(name = "account_type", nullable = false)
42 private Integer accountType;
43
44 // 第三方账号
45 @Column(name = "account", nullable = false)
46 private String account;
47
48 // app账号id
49 @Column(name = "user_app_id", nullable = false)
50 private Long userAppId;
51
52 // 绑定状态 0:解绑;1 绑定
53 @Column(name = "status", nullable = false)
54 private Integer status;
55
56 // 昵称
57 @Column(name = "nickname", nullable = false)
58 private String nickname;
59
60 // 创建时间
61 @CreatedDate
62 @Column(name = "create_time")
63 private Timestamp createTime;
64
65 // 更新时间
66 @LastModifiedDate
67 @Column(name = "update_time")
68 private Timestamp updateTime;
69
70 public void copy(UserAppBind source){
71 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
72 }
73 }
1 package com.topdraw.business.module.user.app.domain;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/30 13:18
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/30 13:18
11 */
12 public class UserAppBindBuilder {
13
14 public static UserAppBind build(Long userAppId, String account, Integer accountType){
15 UserAppBind userAppBind = new UserAppBind();
16 userAppBind.setAccount(account);
17 userAppBind.setUserAppId(userAppId);
18 userAppBind.setAccountType(accountType);
19 userAppBind.setStatus(UserAppStatusConstant.VALID_STATUS);
20 return userAppBind;
21 }
22
23 }
1 package com.topdraw.business.module.user.app.domain;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/30 11:42
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/30 11:42
11 */
12 public interface UserAppBindStatusConstant {
13 // 绑定状态 0:解绑;1 绑定
14 Integer VALID_STATUS = 1;
15 Integer INVALID_STATUS = 0;
16
17 }
1 package com.topdraw.business.module.user.app.domain;
2
3 import com.topdraw.util.TimestampUtil;
4 import org.apache.commons.lang3.StringUtils;
5 import org.springframework.beans.BeanUtils;
6
7 import java.util.Objects;
8
9 /**
10 * @author :
11 * @description:
12 * @function :
13 * @date :Created in 2022/6/30 11:35
14 * @version: :
15 * @modified By:
16 * @since : modified in 2022/6/30 11:35
17 */
18 public class UserAppBuilder {
19
20
21
22 public static UserApp build(Long memberId, UserApp resource){
23
24 UserApp userApp = new UserApp();
25 userApp.setId(null);
26 userApp.setMemberId(memberId);
27 userApp.setUsername(resource.getUsername());
28 userApp.setTags(resource.getTags());
29 userApp.setLastActiveTime(TimestampUtil.now());
30 userApp.setEmail(resource.getEmail());
31 userApp.setType(Objects.isNull(resource.getType()) ? -1 : resource.getType());
32 userApp.setNickname(StringUtils.isNotBlank(resource.getNickname()) ? resource.getNickname() : resource.getUsername());
33 userApp.setHeadimgurl(resource.getHeadimgurl());
34 userApp.setPassword(resource.getPassword());
35 userApp.setCellphone(StringUtils.isNotBlank(resource.getCellphone()) ? resource.getCellphone() : resource.getUsername());
36 userApp.setBirthday(StringUtils.isNotBlank(resource.getBirthday()) ? resource.getBirthday() : null);
37 userApp.setGender(Objects.nonNull(resource.getGender()) ? resource.getGender() : -1);
38 userApp.setStatus(UserAppStatusConstant.VALID_STATUS);
39 userApp.setCreateTime(null);
40 userApp.setUpdateTime(null);
41 return userApp;
42 }
43
44
45 }
1 package com.topdraw.business.module.user.app.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 2022-06-27
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_user_app")
24 public class UserAppIdManual implements Serializable {
25
26 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
27 @Transient
28 private Integer accountType;
29
30 // 第三方账号
31 @Transient
32 private String account;
33
34 @Transient
35 private String memberCode;
36
37 // ID
38 @Id
39 @GeneratedValue(strategy = GenerationType.SEQUENCE)
40 @Column(name = "id")
41 private Long id;
42
43 // 会员id
44 @Column(name = "member_id")
45 private Long memberId;
46
47 // 用户名(一般为手机号)
48 @Column(name = "username", nullable = false)
49 private String username;
50
51 // 密码
52 @Column(name = "password")
53 private String password;
54
55 // 类型 0:苹果;1:安卓;-1:未知
56 @Column(name = "type", nullable = false)
57 private Integer type;
58
59 // 状态 0:禁用;1:生效;-1:注销
60 @Column(name = "status", nullable = false)
61 private Integer status;
62
63 // 昵称
64 @Column(name = "nickname")
65 private String nickname;
66
67 // 头像地址
68 @Column(name = "headimgurl")
69 private String headimgurl;
70
71 // 邮箱
72 @Column(name = "email")
73 private String email;
74
75 // 手机号
76 @Column(name = "cellphone")
77 private String cellphone;
78
79 // 性别 0:女;1:男;-1:其他
80 @Column(name = "gender")
81 private Integer gender;
82
83 // 生日
84 @Column(name = "birthday")
85 private String birthday;
86
87 // 最近活跃时间
88 @Column(name = "last_active_time")
89 private Timestamp lastActiveTime;
90
91 // 注销时间
92 @Column(name = "delete_time")
93 private Timestamp deleteTime;
94
95 // 标签
96 @Column(name = "tags")
97 private String tags;
98
99 // 描述
100 @Column(name = "description")
101 private String description;
102
103 // 创建时间
104 @CreatedDate
105 @Column(name = "create_time")
106 private Timestamp createTime;
107
108 // 更新时间
109 @LastModifiedDate
110 @Column(name = "update_time")
111 private Timestamp updateTime;
112
113 public void copy(UserAppIdManual source){
114 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
115 }
116 }
1 package com.topdraw.business.module.user.app.domain;
2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.bean.copier.CopyOptions;
5 import lombok.Data;
6 import lombok.experimental.Accessors;
7 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
8
9 import javax.persistence.*;
10 import java.io.Serializable;
11
12 /**
13 * @author XiangHan
14 * @date 2022-06-27
15 */
16 @Entity
17 @Data
18 @EntityListeners(AuditingEntityListener.class)
19 @Accessors(chain = true)
20 @Table(name="uc_user_app")
21 public class UserAppSimple implements Serializable {
22
23 // ID
24 @Id
25 @GeneratedValue(strategy = GenerationType.IDENTITY)
26 @Column(name = "id")
27 private Long id;
28
29 // 会员id
30 @Column(name = "member_id")
31 private Long memberId;
32
33 // 用户名(一般为手机号)
34 @Column(name = "username", nullable = false)
35 private String username;
36
37 // 状态 0:禁用;1:生效;-1:注销
38 @Column(name = "status", nullable = false)
39 private Integer status;
40
41 // 昵称
42 @Column(name = "nickname")
43 private String nickname;
44
45 // 头像地址
46 @Column(name = "headimgurl")
47 private String headimgurl;
48
49 // 邮箱
50 @Column(name = "email")
51 private String email;
52
53 // 手机号
54 @Column(name = "cellphone")
55 private String cellphone;
56
57 // 性别 0:女;1:男;-1:其他
58 @Column(name = "gender")
59 private Integer gender;
60
61 // 生日
62 @Column(name = "birthday")
63 private String birthday;
64
65 // 标签
66 @Column(name = "tags")
67 private String tags;
68
69 // 描述
70 @Column(name = "description")
71 private String description;
72
73 public void copy(UserAppSimple source){
74 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
75 }
76 }
1 package com.topdraw.business.module.user.app.domain;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/6/30 11:42
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/6/30 11:42
11 */
12 public interface UserAppStatusConstant {
13 // 状态 0:禁用;1:生效;-1:注销
14 Integer VALID_STATUS = 1;
15 Integer FORBID_STATUS = 0;
16 Integer INVALID_STATUS = -1;
17
18 }
1 package com.topdraw.business.module.user.app.repository;
2
3 import com.topdraw.business.module.user.app.domain.UserAppBind;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Modifying;
7 import org.springframework.data.jpa.repository.Query;
8 import org.springframework.data.repository.query.Param;
9 import org.springframework.transaction.annotation.Transactional;
10
11 import java.util.List;
12 import java.util.Optional;
13
14 /**
15 * @author XiangHan
16 * @date 2022-06-27
17 */
18 public interface UserAppBindRepository extends JpaRepository<UserAppBind, Long>, JpaSpecificationExecutor<UserAppBind> {
19
20 Optional<UserAppBind> findFirstByAccount(String account);
21
22 @Modifying
23 @Query(value = "UPDATE `uc_user_app_bind` SET `status` = 0 , `update_time` = now() WHERE `account` = ?1 AND `account_type` = ?2", nativeQuery = true)
24 Integer cancelUserAppBind(String account, Integer accountType);
25
26 Optional<UserAppBind> findFirstByAccountAndAccountType(String account, Integer accountType);
27
28 @Modifying
29 @Query(value = "UPDATE `uc_user_app_bind` SET `status` = :#{#resources.status}, `update_time` = now(), " +
30 " `user_app_id` = :#{#resources.userAppId}, `nickname` = :#{#resources.nickname} " +
31 " WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}", nativeQuery = true)
32 Integer updateThirdAccount(@Param("resources") UserAppBind resources);
33
34 @Modifying
35 @Query(value = "UPDATE `uc_user_app_bind` SET `status` = :#{#resources.status}, `update_time` = now(), " +
36 " `user_app_id` = :#{#resources.userAppId} WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}",
37 nativeQuery = true)
38 Integer updateThirdAccountStatusAndUserAppId(@Param("resources") UserAppBind resources);
39
40 @Modifying
41 @Query(value = "UPDATE `uc_user_app_bind` SET `status` = 1, `update_time` = now(), " +
42 " `user_app_id` = :#{#resources.userAppId} WHERE `account` = :#{#resources.account} AND accountType = :#{#resources.accountType}",
43 nativeQuery = true)
44 Integer updateValidStatusAndUserAppId(@Param("resources") UserAppBind resources);
45
46
47 @Modifying
48 @Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `nickname` = :#{#resources.nickname} " +
49 " WHERE `account` = :#{#resources.account} AND `account_type` = :#{#resources.accountType}", nativeQuery = true)
50 Integer updateThirdAccountNickname(@Param("resources") UserAppBind resources);
51
52 @Modifying
53 @Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `nickname` = :#{#resources.nickname}, `status` = 1, `user_app_id` = :#{#resources.userAppId} " +
54 " WHERE `account` = :#{#resources.account} AND `account_type` = :#{#resources.accountType}", nativeQuery = true)
55 Integer updateValidStatusAndUserAppIdAndNickname(@Param("resources") UserAppBind resources);
56
57 @Modifying
58 @Query(value = "UPDATE `uc_user_app_bind` SET `update_time` = now(), `status` = 0 WHERE `id` IN ?1", nativeQuery = true)
59 Integer appCancellation(List<Long> ids);
60
61 List<UserAppBind> findByUserAppId(Long id);
62 }
63
1 package com.topdraw.business.module.user.app.repository;
2
3 import com.topdraw.business.module.user.app.domain.UserApp;
4 import com.topdraw.business.module.user.app.domain.UserAppIdManual;
5 import org.springframework.data.jpa.repository.JpaRepository;
6 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
7 import org.springframework.data.jpa.repository.Modifying;
8 import org.springframework.data.jpa.repository.Query;
9 import org.springframework.data.repository.query.Param;
10
11 import java.util.Optional;
12
13 /**
14 * @author XiangHan
15 * @date 2022-06-27
16 */
17 public interface UserAppRepository extends JpaRepository<UserApp, Long>, JpaSpecificationExecutor<UserApp> {
18
19 @Query(value = "SELECT ua.* FROM uc_user_app ua WHERE ua.`username` = ?1 and ua.`status` IN (0 , 1)", nativeQuery = true)
20 Optional<UserApp> findByUsername(String username);
21
22 Optional<UserApp> findByUsernameAndPassword(String username, String password);
23
24 @Modifying
25 @Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `last_active_time` = now() WHERE `username` = ?1 AND `status` = 1 ", nativeQuery = true)
26 Integer updateLastActiveTime(String username);
27
28 @Modifying
29 @Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `password` = ?2 WHERE `username` = ?1 AND `status` = 1", nativeQuery = true)
30 Integer updatePasswordByUsername(String username, String password);
31
32 @Modifying
33 @Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `nickname` = :#{#resources.nickname}, " +
34 " `headimgurl` = :#{#resources.headimgurl}, `email` = :#{#resources.email}, `cellphone` = :#{#resources.cellphone}, " +
35 " `gender` = :#{#resources.gender}, `birthday` = :#{#resources.birthday}, `tags` = :#{#resources.tags}, `description` = :#{#resources.description}" +
36 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
37 Integer updateAppInfo(@Param("resources") UserApp resources);
38
39 @Modifying
40 @Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `password` = ?2 WHERE `id` = ?1", nativeQuery = true)
41 Integer updatePasswordById(Long id, String password);
42
43 @Modifying
44 @Query(value = "UPDATE `uc_user_app` SET `update_time` = now(), `delete_time` = now(), `status` = -1 WHERE `id` = ?1", nativeQuery = true)
45 Integer appCancellation(Long id);
46
47 @Modifying
48 @Query(value = "UPDATE `uc_user_app` SET `last_active_time` = now(), `nickname` = ?2, `headimgurl` = ?3 " +
49 " WHERE `username` = ?1 and `status` = 1 ", nativeQuery = true)
50 Integer updateAppLastActiveTimeAndNicknameAndHeadImg(String username, String nickname, String headimgurl);
51
52 @Modifying
53 @Query(value = "UPDATE `uc_user_app` SET `cellphone`= :#{#resources.cellphone}, `username`= :#{#resources.username},`last_active_time` = now(), `nickname` = :#{#resources.nickname}, `headimgurl` = :#{#resources.headimgurl} " +
54 " WHERE `id` = :#{#resources.id} and `status` = 1 ", nativeQuery = true)
55 Integer updateAppLastActiveTimeAndNicknameAndHeadImgById(@Param("resources") UserApp userApp);
56
57 @Modifying
58 @Query(value = "INSERT INTO `uc_user_app`(`id`, `member_id`, `username`, `password`, `type`, `status`, `nickname`, `headimgurl`, `email`, `cellphone`, `gender`, `birthday`, `last_active_time`, `delete_time`, `tags`, `description`, `create_time`, `update_time`) " +
59 " VALUES (:#{#resources.id}, :#{#resources.memberId}, :#{#resources.username}, :#{#resources.password}, :#{#resources.type}," +
60 " 1, :#{#resources.nickname}, :#{#resources.headimgurl}, :#{#resources.email}, :#{#resources.cellphone}, " +
61 " :#{#resources.gender}, NULL, now(), NULL, :#{#resources.tags}, " +
62 " :#{#resources.description}, :#{#resources.createTime}, now());", nativeQuery = true)
63 void saveByIdManual(@Param("resources") UserAppIdManual userAppIdManual);
64 }
1 package com.topdraw.business.module.user.app.repository;
2
3 import com.topdraw.business.module.user.app.domain.UserAppSimple;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2022-06-27
10 */
11 public interface UserAppSimpleRepository extends JpaRepository<UserAppSimple, Long>, JpaSpecificationExecutor<UserAppSimple> {
12
13 }
1 package com.topdraw.business.module.user.app.rest;
2
3 import com.topdraw.annotation.AnonymousAccess;
4 import com.topdraw.business.module.user.app.domain.UserApp;
5 import com.topdraw.business.module.user.app.domain.UserAppBind;
6 import com.topdraw.business.module.user.app.service.UserAppBindService;
7 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
8 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
9 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
10 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
11 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
12 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
13 import com.topdraw.common.ResultInfo;
14 import com.topdraw.annotation.Log;
15 import com.topdraw.business.module.user.app.service.UserAppService;
16 import lombok.extern.slf4j.Slf4j;
17 import org.apache.commons.lang3.StringUtils;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.validation.annotation.Validated;
20 import org.springframework.web.bind.annotation.*;
21 import io.swagger.annotations.*;
22
23 import java.util.Objects;
24
25 /**
26 * @author XiangHan
27 * @date 2022-06-27
28 */
29 @Api(tags = "UserApp管理")
30 @RestController
31 @RequestMapping("/uce/userApp")
32 @Slf4j
33 public class UserAppController {
34
35 @Autowired
36 private UserAppService userAppService;
37 @Autowired
38 private UserAppBindService userAppBindService;
39
40 @Log
41 @PostMapping(value = "/saveAppAndBindApple4Vis")
42 @ApiOperation("兼容海南app苹果数据")
43 @AnonymousAccess
44 public ResultInfo saveAppAndBindApple4Vis(@Validated @RequestBody VisUserApple resources) {
45 log.info("兼容海南app苹果数据,参数 ==>> [saveAppAndBindApple4Vis#{}]", resources);
46 String user = resources.getUser();
47
48 if (StringUtils.isBlank(user)) {
49 log.error("兼容海南app苹果数据,参数错误,app账号不得为空,[saveAppAndBindApple4Vis#{}]", resources);
50 return ResultInfo.failure("兼容海南app苹果数据,参数错误,app账号不得为空");
51 }
52
53 return this.userAppService.saveAppAndBindApple4Vis(resources);
54 }
55
56 @Log
57 @PostMapping(value = "/saveAppAndBindWeibo4Vis")
58 @ApiOperation("兼容海南app原微博数据")
59 @AnonymousAccess
60 public ResultInfo saveAppAndBindWeibo4Vis(@Validated @RequestBody VisUserWeibo resources) {
61 log.info("兼容海南app原weibo数据,参数 ==>> [saveAppAndBindWeibo4Vis#{}]", resources);
62 String userId = resources.getUserId();
63
64 if (StringUtils.isBlank(userId)) {
65 log.error("兼容海南app原weibo数据,参数错误,app账号不得为空,[saveAppAndBindWeibo4Vis#{}]", resources);
66 return ResultInfo.failure("兼容海南app原weibo数据,参数错误,app账号不得为空");
67 }
68
69 return this.userAppService.saveAppAndBindWeibo4Vis(resources);
70 }
71
72 @Log
73 @PostMapping(value = "/saveAppAndBindQq4Vis")
74 @ApiOperation("兼容海南app原QQ数据")
75 @AnonymousAccess
76 public ResultInfo saveAppAndBindQq4Vis(@Validated @RequestBody VisUserQq resources) {
77 log.info("兼容海南app原QQ数据,参数 ==>> [saveAppAndBindQq4Vis#{}]", resources);
78 String openid = resources.getOpenid();
79 if (StringUtils.isBlank(openid)) {
80 log.error("兼容海南app原QQ数据,参数错误,app账号不得为空,[saveAppAndBindWeibo4Vis#{}]", resources);
81 return ResultInfo.failure("兼容海南app原QQ数据,参数错误,无openid");
82 }
83
84 return this.userAppService.saveAppAndBindQq4Vis(resources);
85
86 }
87
88 @Log
89 @PostMapping(value = "/saveAppAndBindWeixin4Vis")
90 @ApiOperation("兼容海南app原微信数据")
91 @AnonymousAccess
92 public ResultInfo saveAppAndBindWeixin4Vis(@Validated @RequestBody VisUserWeixin resources) {
93 log.info("兼容海南app原weibo数据,参数 ==>> [saveAppAndBindWeixin4Vis#{}]", resources);
94 String openid = resources.getOpenid();
95 if (StringUtils.isBlank(openid)) {
96 log.error("兼容海南app原微信数据,参数错误,app账号不得为空,[saveAppAndBindWeixin4Vis#{}]", resources);
97 return ResultInfo.failure("兼容海南app原微信数据,参数错误,无openid");
98 }
99
100 /*String username = resources.getUsername();
101 if (StringUtils.isBlank(username)) {
102 log.error("兼容海南app原微信数据,参数错误,app账号不得为空,[saveAppAndBindWeixin4Vis#{}]", resources);
103 return ResultInfo.failure("兼容海南app原微信数据失败,参数错误,无username");
104 }*/
105
106 return this.userAppService.saveAppAndBindWeixin4Vis(resources);
107
108 }
109
110
111 @Log
112 @PostMapping(value = "/updateAppLastActiveTimeAndNicknameAndHeadImgById")
113 @ApiOperation("修改app账号最后登录时间、昵称和头像和用户名")
114 @AnonymousAccess
115 public ResultInfo updateAppLastActiveTimeAndNicknameAndHeadImgById(@Validated @RequestBody UserApp resources) {
116 log.info("修改app账号最后登录时间、昵称和头像和用户名,参数 ==>> [updatePassword#{}]", resources);
117
118 Long id = resources.getId();
119 if (Objects.isNull(id)) {
120 log.error("修改app账号最后登录时间、昵称和头像和用户名,参数错误,id不存在,[updateAppLastActiveTimeAndNicknameAndHeadImgById#{}]", resources);
121 return ResultInfo.failure("修改app账号密码失败,参数错误,app账号不得为空");
122 }
123
124 String username = resources.getUsername();
125 if (StringUtils.isBlank(username)) {
126 log.error("修改app账号最后登录时间、昵称和头像和用户名,参数错误,app账号不得为空,[updateAppLastActiveTimeAndNicknameAndHeadImgById#{}]", resources);
127 return ResultInfo.failure("修改app账号最后登录时间、昵称和头像和用户名失败,参数错误,app账号不得为空");
128 }
129
130 boolean result = this.userAppService.updateAppLastActiveTimeAndNicknameAndHeadImgById(resources);
131 return ResultInfo.success(result);
132 }
133
134 @Log
135 @PostMapping(value = "/updateAppLastActiveTimeAndNicknameAndHeadImg")
136 @ApiOperation("修改app账号最后登录时间、昵称和头像")
137 @AnonymousAccess
138 public ResultInfo updateAppLastActiveTimeAndNicknameAndHeadImg(@Validated @RequestBody UserApp resources) {
139 log.info("修改app账号密码,参数 ==>> [updateAppLastActiveTimeAndNicknameAndHeadImg#{}]", resources);
140 String username = resources.getUsername();
141 if (StringUtils.isBlank(username)) {
142 log.error("修改app账号密码,参数错误,app账号不得为空,[updateAppLastActiveTimeAndNicknameAndHeadImg#{}]", resources);
143 return ResultInfo.failure("修改app账号密码失败,参数错误,app账号不得为空");
144 }
145
146 boolean result = this.userAppService.updateAppLastActiveTimeAndNicknameAndHeadImg(resources);
147 return ResultInfo.success(result);
148 }
149
150 @Log
151 @PostMapping(value = "/updateAppPasswordByUsername")
152 @ApiOperation("修改app账号密码")
153 @AnonymousAccess
154 public ResultInfo updateAppPasswordByUsername(@Validated @RequestBody UserApp resources) {
155 log.info("修改app账号密码,参数 ==>> [updatePassword#{}]", resources);
156 String username = resources.getUsername();
157 if (StringUtils.isBlank(username)) {
158 log.error("修改app账号密码,参数错误,app账号不得为空,[updateLastActiveTime#{}]", resources);
159 return ResultInfo.failure("修改app账号密码失败,参数错误,app账号不得为空");
160 }
161
162 String password = resources.getPassword();
163 if (StringUtils.isBlank(password)) {
164 log.error("修改app账号密码失败,参数错误,密码不得为空,[updatePassword#{}]", resources);
165 return ResultInfo.failure("修改app账号最新登录时间失败,参数错误,app账号不得为空");
166 }
167
168 // boolean passwordRegexResult = RegexUtil.appPasswordRegex(password);
169 // if (!passwordRegexResult) {
170 // log.error("修改app账号密码失败,参数错误,密码格式不正确,[updatePassword#{}]", resources);
171 // return ResultInfo.failure("密码必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-25 之间");
172 // }
173
174 boolean result = this.userAppService.updatePasswordByUsername(resources);
175 return ResultInfo.success(result);
176 }
177
178 @Log
179 @PostMapping(value = "/updateLastActiveTime")
180 @ApiOperation("修改app账号最新登录时间")
181 @AnonymousAccess
182 public ResultInfo updateLastActiveTime(@Validated @RequestBody UserAppBind resources) {
183 log.info("修改app账号最新登录时间 ==>> param ==>> [updateLastActiveTime#{}]", resources);
184 String username = resources.getUsername();
185 if (StringUtils.isBlank(username)) {
186 log.error("修改app账号最新登录时间失败,参数错误,app账号不得为空,[updateLastActiveTime#{}]", resources);
187 return ResultInfo.failure("修改app账号最新登录时间失败,参数错误,app账号不得为空");
188 }
189 boolean result = this.userAppService.updateLastActiveTime(resources);
190 return ResultInfo.success(result);
191 }
192
193 @Log
194 @PostMapping(value = "/saveThirdAccount")
195 @ApiOperation("保存第三方账号")
196 @AnonymousAccess
197 public ResultInfo saveThirdAccount(@Validated @RequestBody UserAppBind resources) {
198 log.info("保存第三方账号, 参数 ==>> [saveUserBindApp#{}]", resources);
199 String username = resources.getUsername();
200 if (StringUtils.isBlank(username)) {
201 log.error("修改app账号最新登录时间失败,参数错误,app账号不得为空,[updateLastActiveTime#{}]", resources);
202 return ResultInfo.failure("修改app账号最新登录时间失败,参数错误,app账号不得为空");
203 }
204
205 UserAppDTO userAppDTO = this.userAppService.findByUsername(username);
206 if (Objects.nonNull(userAppDTO.getId())) {
207 Long id = userAppDTO.getId();
208 resources.setUserAppId(id);
209 }
210
211 UserAppBindDTO userAppBindDTO = this.userAppBindService.create(resources);
212 return ResultInfo.success(userAppBindDTO);
213 }
214
215 @Log
216 @PostMapping(value = "/updateValidStatusAndUserAppIdAndNickname")
217 @ApiOperation("修改第三方账号绑定状态、绑定的app账号以及第三方账号昵称")
218 @AnonymousAccess
219 public ResultInfo updateValidStatusAndUserAppIdAndNickname(@Validated @RequestBody UserAppBind resources) {
220 log.info("修改第三方账号 ==>> param ==>> [updateThirdAccountStatusAndUserAppId#{}]", resources);
221 String username = resources.getUsername();
222 if (StringUtils.isBlank(username)) {
223 log.error("修改app账号最新登录时间失败,参数错误,app账号不得为空,[updateLastActiveTime#{}]", resources);
224 return ResultInfo.failure("修改app账号最新登录时间失败,参数错误,app账号不得为空");
225 }
226
227 String account = resources.getAccount();
228 Integer accountType = resources.getAccountType();
229 if (StringUtils.isBlank(account) || Objects.isNull(accountType)) {
230 log.error("检查app账号是否绑定了第三方账号失败, 参数错误, 第三方账号或者第三方账号类型不得为空 [checkThirdAccount# resources ==>> {}]", resources);
231 return ResultInfo.failure("检查第三方账号是否绑定了第三方账号失败, 参数错误, 第三方账号或者第三方账号类型不得为空");
232 }
233
234 UserAppDTO userAppDTO = this.userAppService.findByUsername(username);
235 if (Objects.nonNull(userAppDTO.getId())) {
236 Long id = userAppDTO.getId();
237 resources.setUserAppId(id);
238 } else {
239 log.error("修改第三方账号, 参数错误, app账号不得为空 [updateValidStatusAndUserAppIdAndNickname# resources ==>> {}]", resources);
240 return ResultInfo.failure("修改第三方账号, 参数错误, app账号不得为空");
241 }
242
243 boolean result = this.userAppBindService.updateValidStatusAndUserAppIdAndNickname(resources);
244 return ResultInfo.success(result);
245 }
246
247 @Log
248 @PostMapping(value = "/updateThirdAccountNickname")
249 @ApiOperation("修改第三方账号昵称")
250 @AnonymousAccess
251 public ResultInfo updateThirdAccountNickname(@Validated @RequestBody UserAppBind resources) {
252 log.info("修改第三方账号 ==>> param ==>> [updateThirdAccountNickname#{}]", resources);
253 String account = resources.getAccount();
254 Integer accountType = resources.getAccountType();
255 if (StringUtils.isBlank(account) || Objects.isNull(accountType)) {
256 log.error("修改第三方账号昵称, 参数错误, 第三方账号或者第三方账号类型不得为空 [checkThirdAccount# resources ==>> {}]", resources);
257 return ResultInfo.failure("修改第三方账号昵称, 参数错误, 第三方账号或者第三方账号类型不得为空");
258 }
259
260 String nickname = resources.getNickname();
261 if (StringUtils.isBlank(nickname)) {
262 log.error("修改第三方账号昵称, 参数错误, 昵称不得为空 [updateThirdAccountNickname# resources ==>> {}]", resources);
263 return ResultInfo.failure("修改第三方账号昵称, 参数错误, 昵称不得为空");
264 }
265
266 boolean result = this.userAppBindService.updateThirdAccountNickname(resources);
267 return ResultInfo.success(result);
268 }
269 }
1 package com.topdraw.business.module.user.app.service;
2
3 import com.topdraw.business.module.user.app.domain.UserAppBind;
4 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
5
6 import java.util.List;
7
8 /**
9 * @author XiangHan
10 * @date 2022-06-27
11 */
12 public interface UserAppBindService {
13
14 /**
15 * 根据ID查询
16 * @param id ID
17 * @return UserAppBindDTO
18 */
19 UserAppBindDTO findById(Long id);
20
21 /**
22 *
23 * @param resources
24 */
25 UserAppBindDTO create(UserAppBind resources);
26
27 /**
28 *
29 * @param resources
30 */
31 void update(UserAppBind resources);
32
33 /**
34 *
35 * @param id
36 */
37 void delete(Long id);
38
39 /**
40 *
41 * @param account
42 * @return
43 */
44 UserAppBindDTO findFirstByAccount(String account);
45
46 /**
47 *
48 * @param account
49 * @return
50 */
51 boolean cancelUserAppBind(String account, Integer accountType);
52
53 /**
54 *
55 * @param account
56 * @param accountType
57 * @return
58 */
59 UserAppBindDTO findFirstByAccountAndAccountType(String account, Integer accountType);
60
61 /**
62 *
63 * @param resources
64 * @return
65 */
66 boolean updateThirdAccount(UserAppBind resources);
67
68 /**
69 *
70 * @param resources
71 * @return
72 */
73 boolean updateThirdAccountNickname(UserAppBind resources);
74
75 /**
76 *
77 * @param resources
78 * @return
79 */
80 boolean updateValidStatusAndUserAppIdAndNickname(UserAppBind resources);
81
82 boolean appCancellation(List<Long> ids);
83
84 List<UserAppBindDTO> findByUserAppId(Long id);
85 }
1 package com.topdraw.business.module.user.app.service;
2
3 import com.topdraw.business.module.user.app.domain.UserApp;
4 import com.topdraw.business.module.user.app.domain.UserAppBind;
5 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
6 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
7 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
8 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
9 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
10 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
11 import com.topdraw.common.ResultInfo;
12
13 /**
14 * @author XiangHan
15 * @date 2022-06-27
16 */
17 public interface UserAppService {
18
19 /**
20 * 根据ID查询
21 * @param id ID
22 * @return UserAppDTO
23 */
24 UserAppDTO findById(Long id);
25
26 /**
27 * 检查账号和秘密
28 * @param username
29 * @return
30 */
31 UserAppDTO findByUsername(String username);
32
33
34 /**
35 *
36 * @param resources
37 */
38 UserAppDTO create(UserApp resources);
39
40 /**
41 *
42 * @param resources
43 */
44 UserAppDTO update(UserApp resources);
45
46 /**
47 *
48 * @param id
49 */
50 void delete(Long id);
51
52 /**
53 *
54 * @param resources
55 * @return
56 */
57 boolean updateLastActiveTime(UserAppBind resources);
58
59 /**
60 *
61 * @param resources
62 * @return
63 */
64 boolean updatePasswordByUsername(UserApp resources);
65
66 /**
67 *
68 * @param resources
69 * @return
70 */
71 boolean updatePasswordById(UserApp resources);
72
73 /**
74 *
75 * @param resources
76 * @return
77 */
78 UserAppSimpleDTO updateAppInfo(UserApp resources);
79
80
81 boolean appCancellation(Long id);
82
83
84 boolean updateAppLastActiveTimeAndNicknameAndHeadImg(UserApp resources);
85
86 boolean updateAppLastActiveTimeAndNicknameAndHeadImgById(UserApp resources);
87
88 ResultInfo saveAppAndBindApple4Vis(VisUserApple resources);
89
90 ResultInfo saveAppAndBindWeibo4Vis(VisUserWeibo resources);
91
92 ResultInfo saveAppAndBindWeixin4Vis(VisUserWeixin resources);
93
94 ResultInfo saveAppAndBindQq4Vis(VisUserQq resources);
95 }
1 package com.topdraw.business.module.user.app.service.dto;
2
3 import com.topdraw.business.module.member.service.dto.MemberDTO;
4 import lombok.Data;
5
6 import java.io.Serializable;
7
8 /**
9 * @author :
10 * @description:
11 * @function :
12 * @date :Created in 2022/7/11 21:21
13 * @version: :
14 * @modified By:
15 * @since : modified in 2022/7/11 21:21
16 */
17 @Data
18 public class AppRegisterDTO implements Serializable {
19
20 private UserAppDTO userAppDTO;
21
22 private MemberDTO memberDTO;
23
24 }
1 package com.topdraw.business.module.user.app.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-06-27
11 */
12 @Data
13 public class UserAppBindDTO implements Serializable {
14
15 // 主键
16 private Long id;
17
18 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
19 private Integer accountType;
20
21 // 第三方账号
22 private String account;
23
24 // app账号id
25 private Long userAppId;
26
27 // 绑定状态 0:解绑;1 绑定
28 private Integer status;
29
30 // 昵称
31 private String nickname;
32
33 // 创建时间
34 private Timestamp createTime;
35
36 // 更新时间
37 private Timestamp updateTime;
38 }
1 package com.topdraw.business.module.user.app.service.dto;
2
3 import lombok.Data;
4
5 import javax.persistence.Transient;
6 import java.sql.Timestamp;
7 import java.io.Serializable;
8
9
10 /**
11 * @author XiangHan
12 * @date 2022-06-27
13 */
14 @Data
15 public class UserAppDTO implements Serializable {
16
17 private Integer accountType;
18
19 // 第三方账号
20 private String account;
21
22 // ID
23 private Long id;
24
25 // 会员id
26 private Long memberId;
27
28 // 用户名(一般为手机号)
29 private String username;
30
31 // 密码
32 private String password;
33
34 // 类型 0:苹果;1:安卓;-1:未知
35 private Integer type;
36
37 // 状态 0:禁用;1:生效;-1:注销
38 private Integer status;
39
40 // 昵称
41 private String nickname;
42
43 // 头像地址
44 private String headimgurl;
45
46 // 邮箱
47 private String email;
48
49 // 手机号
50 private String cellphone;
51
52 // 性别 0:女;1:男;-1:其他
53 private Integer gender;
54
55 // 生日
56 private String birthday;
57
58 // 最近活跃时间
59 private Timestamp lastActiveTime;
60
61 // 注销时间
62 private Timestamp deleteTime;
63
64 // 标签
65 private String tags;
66
67 // 描述
68 private String description;
69
70 // 创建时间
71 private Timestamp createTime;
72
73 // 更新时间
74 private Timestamp updateTime;
75 }
1 package com.topdraw.business.module.user.app.service.dto;
2
3 import com.topdraw.business.module.member.service.dto.MemberDTO;
4 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
5 import lombok.Data;
6
7 import java.io.Serializable;
8 import java.sql.Timestamp;
9
10 /**
11 * @author XiangHan
12 * @date 2022-06-27
13 */
14 @Data
15 public class UserAppSimpleDTO implements Serializable {
16
17 // ID
18 private Long id;
19
20 // 会员id
21 private Long memberId;
22
23 // 用户名(一般为手机号)
24 private String username;
25
26 // 状态 0:禁用;1:生效;-1:注销
27 private Integer status;
28
29 // 昵称
30 private String nickname;
31
32 // 头像地址
33 private String headimgurl;
34
35 // 邮箱
36 private String email;
37
38 // 手机号
39 private String cellphone;
40
41 // 性别 0:女;1:男;-1:其他
42 private Integer gender;
43
44 // 生日
45 private String birthday;
46
47 // 标签
48 private String tags;
49
50 // 描述
51 private String description;
52
53 private MemberSimpleDTO member;
54
55 }
1 package com.topdraw.business.module.user.app.service.impl;
2
3 import com.topdraw.business.module.user.app.domain.UserAppBind;
4 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.business.module.user.app.repository.UserAppBindRepository;
6 import com.topdraw.business.module.user.app.service.UserAppBindService;
7 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
8 import com.topdraw.business.module.user.app.service.mapper.UserAppBindMapper;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 import java.util.List;
17
18 /**
19 * @author XiangHan
20 * @date 2022-06-27
21 */
22 @Service
23 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
24 public class UserAppBindServiceImpl implements UserAppBindService {
25
26 @Autowired
27 private UserAppBindRepository userAppBindRepository;
28
29 @Autowired
30 private UserAppBindMapper userAppBindMapper;
31
32 @Override
33 public UserAppBindDTO findById(Long id) {
34 UserAppBind userAppBind = this.userAppBindRepository.findById(id).orElseGet(UserAppBind::new);
35 ValidationUtil.isNull(userAppBind.getId(),"UserAppBind","id",id);
36 return this.userAppBindMapper.toDto(userAppBind);
37 }
38
39 @Override
40 @Transactional(rollbackFor = Exception.class)
41 public UserAppBindDTO create(UserAppBind resources) {
42 UserAppBind userAppBind = this.userAppBindRepository.save(resources);
43 return this.userAppBindMapper.toDto(userAppBind);
44 }
45
46 @Override
47 @Transactional(rollbackFor = Exception.class)
48 public void update(UserAppBind resources) {
49 UserAppBind userAppBind = this.userAppBindRepository.findById(resources.getId()).orElseGet(UserAppBind::new);
50 ValidationUtil.isNull( userAppBind.getId(),"UserAppBind","id",resources.getId());
51 userAppBind.copy(resources);
52 this.userAppBindRepository.save(userAppBind);
53 }
54
55 @Override
56 @Transactional(rollbackFor = Exception.class)
57 public void delete(Long id) {
58 Assert.notNull(id, "The given id must not be null!");
59 UserAppBind UserAppBind = this.userAppBindRepository.findById(id).orElseThrow(
60 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserAppBind.class, id), 1));
61 this.userAppBindRepository.delete(UserAppBind);
62 }
63
64 @Override
65 public UserAppBindDTO findFirstByAccount(String account) {
66 UserAppBind userAppBind = this.userAppBindRepository.findFirstByAccount(account).orElseGet(UserAppBind::new);
67 return this.userAppBindMapper.toDto(userAppBind);
68 }
69
70 @Override
71 @Transactional(rollbackFor = Exception.class)
72 public boolean cancelUserAppBind(String account, Integer accountType) {
73 return this.userAppBindRepository.cancelUserAppBind(account, accountType) > 0;
74 }
75
76 @Override
77 @Transactional(readOnly = true)
78 public UserAppBindDTO findFirstByAccountAndAccountType(String account, Integer accountType) {
79 UserAppBind userAppBind = this.userAppBindRepository.findFirstByAccountAndAccountType(account, accountType).orElseGet(UserAppBind::new);
80 return this.userAppBindMapper.toDto(userAppBind);
81 }
82
83 @Override
84 @Transactional(rollbackFor = Exception.class)
85 public boolean updateThirdAccount(UserAppBind resources) {
86 return this.userAppBindRepository.updateThirdAccount(resources) > 0;
87 }
88
89 @Override
90 @Transactional(rollbackFor = Exception.class)
91 public boolean updateThirdAccountNickname(UserAppBind resources) {
92 return this.userAppBindRepository.updateThirdAccountNickname(resources) > 0;
93 }
94
95 @Override
96 @Transactional(rollbackFor = Exception.class)
97 public boolean updateValidStatusAndUserAppIdAndNickname(UserAppBind resources) {
98 return this.userAppBindRepository.updateValidStatusAndUserAppIdAndNickname(resources) > 0;
99 }
100
101 @Override
102 @Transactional(rollbackFor = Exception.class)
103 public boolean appCancellation(List<Long> ids) {
104 return this.userAppBindRepository.appCancellation(ids) > 0;
105 }
106
107 @Override
108 @Transactional(readOnly = true)
109 public List<UserAppBindDTO> findByUserAppId(Long id) {
110 List<UserAppBind> userAppBinds = this.userAppBindRepository.findByUserAppId(id);
111 return this.userAppBindMapper.toDto(userAppBinds);
112 }
113
114
115 }
1 package com.topdraw.business.module.user.app.service.impl;
2
3 import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.module.member.domain.Member;
5 import com.topdraw.business.module.member.domain.MemberBuilder;
6 import com.topdraw.business.module.member.domain.MemberTypeConstant;
7 import com.topdraw.business.module.member.service.MemberService;
8 import com.topdraw.business.module.member.service.dto.MemberDTO;
9 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
10 import com.topdraw.business.module.user.app.domain.UserApp;
11 import com.topdraw.business.module.user.app.domain.UserAppBind;
12 import com.topdraw.business.module.user.app.domain.UserAppIdManual;
13 import com.topdraw.business.module.user.app.domain.UserAppSimple;
14 import com.topdraw.business.module.user.app.repository.UserAppSimpleRepository;
15 import com.topdraw.business.module.user.app.service.UserAppBindService;
16 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
17 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
18 import com.topdraw.business.module.vis.hainan.app.service.VisUserService;
19 import com.topdraw.business.module.vis.hainan.app.service.dto.VisUserDTO;
20 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
21 import com.topdraw.business.module.vis.hainan.apple.service.VisUserAppleService;
22 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
23 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
24 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
25 import com.topdraw.common.ResultInfo;
26 import com.topdraw.util.Base64Util;
27 import com.topdraw.util.TimestampUtil;
28 import com.topdraw.utils.StringUtils;
29 import com.topdraw.utils.ValidationUtil;
30 import com.topdraw.business.module.user.app.repository.UserAppRepository;
31 import com.topdraw.business.module.user.app.service.UserAppService;
32 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
33 import com.topdraw.business.module.user.app.service.mapper.UserAppMapper;
34 import lombok.extern.slf4j.Slf4j;
35 import org.springframework.aop.framework.AopContext;
36 import org.springframework.beans.BeanUtils;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Service;
39 import org.springframework.transaction.annotation.Propagation;
40 import org.springframework.transaction.annotation.Transactional;
41 import org.springframework.dao.EmptyResultDataAccessException;
42 import org.springframework.util.Assert;
43 import org.springframework.util.Base64Utils;
44
45 import java.sql.Timestamp;
46 import java.util.Objects;
47
48 /**
49 * @author XiangHan
50 * @date 2022-06-27
51 */
52 @Service
53 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
54 @Slf4j
55 public class UserAppServiceImpl implements UserAppService {
56
57 @Autowired
58 private UserAppRepository userAppRepository;
59 @Autowired
60 private UserAppSimpleRepository userAppSimpleRepository;
61 @Autowired
62 private UserAppMapper userAppMapper;
63 @Autowired
64 private MemberService memberService;
65 @Autowired
66 private VisUserService visUserService;
67 @Autowired
68 private UserAppBindService userAppBindService;
69 @Autowired
70 private VisUserAppleService visUserAppleService;
71
72
73 @Override
74 @Transactional(readOnly = true)
75 public UserAppDTO findById(Long id) {
76 UserApp userApp = this.userAppRepository.findById(id).orElseGet(UserApp::new);
77 ValidationUtil.isNull(userApp.getId(),"UserApp","id",id);
78 return this.userAppMapper.toDto(userApp);
79 }
80
81 @Override
82 @Transactional(readOnly = true)
83 public UserAppDTO findByUsername(String username) {
84 UserApp userApp = this.userAppRepository.findByUsername(username).orElseGet(UserApp::new);
85 return this.userAppMapper.toDto(userApp);
86 }
87
88 @Override
89 @Transactional(rollbackFor = Exception.class)
90 public UserAppDTO create(UserApp resources) {
91 UserApp userApp = this.userAppRepository.save(resources);
92 return this.userAppMapper.toDto(userApp);
93 }
94
95 @Override
96 @Transactional(rollbackFor = Exception.class)
97 public UserAppDTO update(UserApp resources) {
98 UserApp userApp = this.userAppRepository.findById(resources.getId()).orElseGet(UserApp::new);
99 ValidationUtil.isNull( userApp.getId(),"UserApp","id",resources.getId());
100 userApp.copy(resources);
101 UserApp _userApp = this.userAppRepository.save(userApp);
102 if (Objects.nonNull(_userApp.getId())) {
103 return this.userAppMapper.toDto(_userApp);
104 }
105
106 return this.userAppMapper.toDto(resources);
107 }
108
109 @Override
110 @Transactional(rollbackFor = Exception.class)
111 public void delete(Long id) {
112 Assert.notNull(id, "The given id must not be null!");
113 UserApp UserApp = this.userAppRepository.findById(id).orElseThrow(
114 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", UserApp.class, id), 1));
115 this.userAppRepository.delete(UserApp);
116 }
117
118 @Override
119 @Transactional(rollbackFor = Exception.class)
120 public boolean updateLastActiveTime(UserAppBind resources) {
121 return this.userAppRepository.updateLastActiveTime(resources.getUsername()) > 0;
122 }
123
124 @Override
125 @Transactional(rollbackFor = Exception.class)
126 public boolean updatePasswordByUsername(UserApp resources) {
127 return this.userAppRepository.updatePasswordByUsername(resources.getUsername(), resources.getPassword()) > 0;
128 }
129
130 @Override
131 @Transactional(rollbackFor = Exception.class)
132 public UserAppSimpleDTO updateAppInfo(UserApp resources) {
133
134 Long id = resources.getId();
135 UserApp userApp = this.userAppRepository.findById(id).orElseGet(UserApp::new);
136 if (Objects.isNull(userApp.getId())) {
137 log.error("修改app信息失败,app账号信息不存在[updateAppInfo#]");
138 return new UserAppSimpleDTO();
139 }
140
141 userApp.copy(resources);
142
143 if (this.userAppRepository.updateAppInfo(userApp) > 0) {
144 UserAppSimple userAppSimple = this.userAppSimpleRepository.findById(resources.getId()).orElseGet(UserAppSimple::new);
145 if (Objects.nonNull(userAppSimple.getId())) {
146 MemberDTO memberDTO = this.memberService.findById(userAppSimple.getMemberId());
147
148 UserAppSimpleDTO userAppSimpleDTO = new UserAppSimpleDTO();
149 BeanUtils.copyProperties(userAppSimple, userAppSimpleDTO);
150
151 MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO();
152 BeanUtils.copyProperties(memberDTO, memberSimpleDTO);
153 userAppSimpleDTO.setMember(memberSimpleDTO);
154 return userAppSimpleDTO;
155 }
156 }
157
158 return null;
159 }
160
161 @Override
162 @Transactional(rollbackFor = Exception.class)
163 public boolean appCancellation(Long id) {
164 return this.userAppRepository.appCancellation(id) > 0;
165 }
166
167 @Override
168 @Transactional(rollbackFor = Exception.class)
169 public boolean updateAppLastActiveTimeAndNicknameAndHeadImg(UserApp resources) {
170 return this.userAppRepository.updateAppLastActiveTimeAndNicknameAndHeadImg(resources.getUsername(),
171 resources.getNickname(), resources.getHeadimgurl()) > 0;
172 }
173
174 @Override
175 @Transactional(rollbackFor = Exception.class)
176 public boolean updateAppLastActiveTimeAndNicknameAndHeadImgById(UserApp resources) {
177 Integer count = this.userAppRepository.updateAppLastActiveTimeAndNicknameAndHeadImgById(resources);
178 if (count > 0) {
179 ((UserAppServiceImpl) AopContext.currentProxy()).asyncUpdateAppLastActiveTimeAndNicknameAndHeadImgById(resources);
180 return true;
181 }
182
183 return false;
184 }
185
186 @Override
187 @Transactional(rollbackFor = Exception.class)
188 public ResultInfo saveAppAndBindApple4Vis(VisUserApple resources) {
189 String username = resources.getUsername();
190 UserAppDTO userAppDTO = this.findByUsername(username);
191
192 if (Objects.nonNull(userAppDTO.getId()) && StringUtils.isNotBlank(userAppDTO.getHeadimgurl())) {
193
194 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUser(), 6);
195 if (Objects.nonNull(userAppBindDTO.getId())) {
196
197 UserAppBind userAppBind = new UserAppBind();
198 userAppBind.setAccount(resources.getUser());
199 userAppBind.setAccountType(6);
200 userAppBind.setUserAppId(userAppDTO.getId());
201 userAppBind.setStatus(1);
202 userAppBind.setNickname(resources.getNickname());
203 userAppBind.setHeadimgurl(resources.getIcon());
204 this.userAppBindService.create(userAppBind);
205 }
206
207 return ResultInfo.success(userAppDTO);
208 }
209
210 Long visUserId = resources.getVisUserId();
211 VisUserDTO visUserDTO = this.visUserService.findById(visUserId);
212 if (Objects.nonNull(visUserDTO.getId())) {
213
214 UserAppIdManual userAppIdManual = new UserAppIdManual();
215
216 Long id = visUserDTO.getId();
217 userAppIdManual.setId(id);
218
219 // vis 手机号
220 String cellphone = visUserDTO.getCellphone();
221 userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username : cellphone);
222 userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone);
223
224 if (StringUtils.isBlank(visUserDTO.getNickname())) {
225 userAppIdManual.setNickname(resources.getNickname());
226 } else {
227 if(!Base64Util.isBase64(visUserDTO.getNickname())) {
228 userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes()));
229 } else {
230 userAppIdManual.setNickname(visUserDTO.getNickname());
231 }
232 }
233
234 Integer gender = visUserDTO.getGender();
235 userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender);
236
237 userAppIdManual.setHeadimgurl(resources.getIcon());
238
239 String email = visUserDTO.getEmail();
240 userAppIdManual.setEmail(StringUtils.isBlank(email) ? null : email);
241
242 String tags = visUserDTO.getTags();
243 userAppIdManual.setTags(StringUtils.isBlank(tags) ? null : tags);
244
245 Timestamp createTime = visUserDTO.getCreateTime();
246 userAppIdManual.setCreateTime(Objects.isNull(createTime) ? TimestampUtil.now() : createTime);
247
248 Member member = MemberBuilder.build(MemberTypeConstant.app, resources.getIcon(), userAppIdManual.getNickname(), 0);
249 MemberDTO memberDTO = this.memberService.create(member);
250
251 userAppIdManual.setMemberCode(memberDTO.getCode());
252 userAppIdManual.setMemberId(memberDTO.getId());
253 userAppIdManual.setType(resources.getType());
254 this.userAppRepository.saveByIdManual(userAppIdManual);
255
256 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUser(), 6);
257 if (Objects.isNull(userAppBindDTO.getId())) {
258
259 UserAppBind userAppBind = new UserAppBind();
260 userAppBind.setAccount(resources.getUser());
261 userAppBind.setAccountType(6);
262 userAppBind.setUserAppId(visUserId);
263 userAppBind.setStatus(1);
264 userAppBind.setNickname(resources.getNickname());
265 userAppBind.setHeadimgurl(resources.getIcon());
266 this.userAppBindService.create(userAppBind);
267 }
268
269 ((UserAppServiceImpl) AopContext.currentProxy()).asyncSaveByIdManual(userAppIdManual);
270
271 return ResultInfo.success(userAppIdManual);
272 }
273
274 return ResultInfo.failure(null);
275 }
276
277 @Override
278 @Transactional(rollbackFor = Exception.class)
279 public ResultInfo saveAppAndBindWeibo4Vis(VisUserWeibo resources) {
280
281 String username1 = resources.getUsername();
282 UserAppDTO userAppDTO = this.findByUsername(username1);
283 if (Objects.nonNull(userAppDTO.getId()) && StringUtils.isNotBlank(userAppDTO.getHeadimgurl())) {
284
285 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUserId(), 5);
286 if (Objects.nonNull(userAppBindDTO.getId())) {
287
288 UserAppBind userAppBind = new UserAppBind();
289 userAppBind.setAccount(resources.getUserId());
290 userAppBind.setAccountType(3);
291 userAppBind.setUserAppId(userAppDTO.getId());
292 userAppBind.setStatus(1);
293 userAppBind.setNickname(resources.getNickname());
294 userAppBind.setHeadimgurl(resources.getIcon());
295 this.userAppBindService.create(userAppBind);
296 }
297
298 return ResultInfo.success(userAppDTO);
299 }
300
301 Long visUserId = resources.getVisUserId();
302 VisUserDTO visUserDTO = this.visUserService.findById(visUserId);
303 if (Objects.nonNull(visUserDTO.getId())) {
304
305 UserAppIdManual userAppIdManual = new UserAppIdManual();
306
307 Long id = visUserDTO.getId();
308 userAppIdManual.setId(id);
309
310 String cellphone = visUserDTO.getCellphone();
311 userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone);
312 userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone);
313
314 if (StringUtils.isBlank(visUserDTO.getNickname())) {
315 userAppIdManual.setNickname(resources.getNickname());
316 } else {
317 if(!Base64Util.isBase64(visUserDTO.getNickname())) {
318 userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes()));
319 } else {
320 userAppIdManual.setNickname(visUserDTO.getNickname());
321 }
322 }
323
324 Integer gender = visUserDTO.getGender();
325 userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender);
326
327 userAppIdManual.setHeadimgurl(resources.getIcon());
328
329 String email = visUserDTO.getEmail();
330 userAppIdManual.setEmail(StringUtils.isBlank(email) ? null : email);
331
332 String tags = visUserDTO.getTags();
333 userAppIdManual.setTags(StringUtils.isBlank(tags) ? null : tags);
334
335 Timestamp createTime = visUserDTO.getCreateTime();
336 userAppIdManual.setCreateTime(Objects.isNull(createTime) ? TimestampUtil.now() : createTime);
337
338 Member member = MemberBuilder.build(MemberTypeConstant.app, resources.getIcon(), userAppIdManual.getNickname(), 0);
339 MemberDTO memberDTO = this.memberService.create(member);
340
341 userAppIdManual.setMemberCode(memberDTO.getCode());
342 userAppIdManual.setMemberId(memberDTO.getId());
343 userAppIdManual.setType(resources.getType());
344
345 this.userAppRepository.saveByIdManual(userAppIdManual);
346
347 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUserId(), 5);
348 if (Objects.isNull(userAppBindDTO.getId())) {
349
350 UserAppBind userAppBind = new UserAppBind();
351 userAppBind.setAccount(resources.getUserId());
352 userAppBind.setAccountType(5);
353 userAppBind.setUserAppId(visUserId);
354 userAppBind.setStatus(1);
355 userAppBind.setNickname(resources.getNickname());
356 userAppBind.setHeadimgurl(resources.getIcon());
357 this.userAppBindService.create(userAppBind);
358 }
359
360 ((UserAppServiceImpl) AopContext.currentProxy()).asyncSaveByIdManual(userAppIdManual);
361 return ResultInfo.success(userAppIdManual);
362 }
363
364 return ResultInfo.failure(null);
365 }
366
367
368
369 @Override
370 @Transactional(rollbackFor = Exception.class)
371 public ResultInfo saveAppAndBindWeixin4Vis(VisUserWeixin resources) {
372 String username1 = resources.getUsername();
373 UserAppDTO userAppDTO = this.findByUsername(username1);
374 if (Objects.nonNull(userAppDTO.getId()) && StringUtils.isNotBlank(userAppDTO.getHeadimgurl())) {
375
376 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getOpenid(), 3);
377 if (Objects.nonNull(userAppBindDTO.getId())) {
378
379 UserAppBind userAppBind = new UserAppBind();
380 userAppBind.setAccount(resources.getOpenid());
381 userAppBind.setAccountType(3);
382 userAppBind.setUserAppId(userAppDTO.getId());
383 userAppBind.setStatus(1);
384 userAppBind.setNickname(resources.getNickname());
385 userAppBind.setHeadimgurl(resources.getHeadimgurl());
386 this.userAppBindService.create(userAppBind);
387 }
388
389 return ResultInfo.success(userAppDTO);
390 }
391
392 Long visUserId = resources.getVisUserId();
393 VisUserDTO visUserDTO = this.visUserService.findById(visUserId);
394 if (Objects.nonNull(visUserDTO.getId())) {
395
396 UserAppIdManual userAppIdManual = new UserAppIdManual();
397
398 Long id = visUserDTO.getId();
399 userAppIdManual.setId(id);
400
401 String cellphone = visUserDTO.getCellphone();
402 userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone);
403 userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone);
404
405 if (StringUtils.isBlank(visUserDTO.getNickname())) {
406 userAppIdManual.setNickname(resources.getNickname());
407 } else {
408 if(!Base64Util.isBase64(visUserDTO.getNickname())) {
409 userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes()));
410 } else {
411 userAppIdManual.setNickname(visUserDTO.getNickname());
412 }
413 }
414
415 Integer gender = visUserDTO.getGender();
416 userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender);
417
418 userAppIdManual.setHeadimgurl(resources.getHeadimgurl());
419
420 String email = visUserDTO.getEmail();
421 userAppIdManual.setEmail(StringUtils.isBlank(email) ? null : email);
422
423 String tags = visUserDTO.getTags();
424 userAppIdManual.setTags(StringUtils.isBlank(tags) ? null : tags);
425
426 Timestamp createTime = visUserDTO.getCreateTime();
427 userAppIdManual.setCreateTime(Objects.isNull(createTime) ? TimestampUtil.now() : createTime);
428
429 Member member = MemberBuilder.build(MemberTypeConstant.app, resources.getHeadimgurl(), userAppIdManual.getNickname(), 0);
430 MemberDTO memberDTO = this.memberService.create(member);
431
432 userAppIdManual.setMemberCode(memberDTO.getCode());
433 userAppIdManual.setMemberId(memberDTO.getId());
434 userAppIdManual.setType(resources.getType());
435
436 this.userAppRepository.saveByIdManual(userAppIdManual);
437
438
439 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getOpenid(), 3);
440 if (Objects.isNull(userAppBindDTO.getId())) {
441
442 UserAppBind userAppBind = new UserAppBind();
443 userAppBind.setAccount(resources.getOpenid());
444 userAppBind.setAccountType(3);
445 userAppBind.setUserAppId(visUserId);
446 userAppBind.setStatus(1);
447 userAppBind.setNickname(resources.getNickname());
448 userAppBind.setHeadimgurl(resources.getHeadimgurl());
449 this.userAppBindService.create(userAppBind);
450 }
451
452 ((UserAppServiceImpl) AopContext.currentProxy()).asyncSaveByIdManual(userAppIdManual);
453 return ResultInfo.success(userAppIdManual);
454 }
455
456 return ResultInfo.failure(null);
457 }
458
459
460
461 @Override
462 @Transactional(rollbackFor = Exception.class)
463 public ResultInfo saveAppAndBindQq4Vis(VisUserQq resources) {
464 String username1 = resources.getUsername();
465 UserAppDTO userAppDTO = this.findByUsername(username1);
466 if (Objects.nonNull(userAppDTO.getId()) && StringUtils.isNotBlank(userAppDTO.getHeadimgurl())) {
467
468 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getOpenid(), 4);
469 if (Objects.nonNull(userAppBindDTO.getId())) {
470
471 UserAppBind userAppBind = new UserAppBind();
472 userAppBind.setAccount(resources.getOpenid());
473 userAppBind.setAccountType(4);
474 userAppBind.setUserAppId(userAppDTO.getId());
475 userAppBind.setStatus(1);
476 userAppBind.setNickname(resources.getNickname());
477 userAppBind.setHeadimgurl(resources.getIcon());
478 this.userAppBindService.create(userAppBind);
479 }
480
481 return ResultInfo.success(userAppDTO);
482 }
483
484 Long visUserId = resources.getVisUserId();
485 VisUserDTO visUserDTO = this.visUserService.findById(visUserId);
486 if (Objects.nonNull(visUserDTO.getId())) {
487
488 UserAppIdManual userAppIdManual = new UserAppIdManual();
489
490 Long id = visUserDTO.getId();
491 userAppIdManual.setId(id);
492
493 String cellphone = visUserDTO.getCellphone();
494 userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone);
495 userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone);
496
497 if (StringUtils.isBlank(visUserDTO.getNickname())) {
498 userAppIdManual.setNickname(resources.getNickname());
499 } else {
500 if(!Base64Util.isBase64(visUserDTO.getNickname())) {
501 userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes()));
502 } else {
503 userAppIdManual.setNickname(visUserDTO.getNickname());
504 }
505 }
506
507 Integer gender = visUserDTO.getGender();
508 userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender);
509
510 userAppIdManual.setHeadimgurl(resources.getIcon());
511
512 String email = visUserDTO.getEmail();
513 userAppIdManual.setEmail(StringUtils.isBlank(email) ? null : email);
514
515 String tags = visUserDTO.getTags();
516 userAppIdManual.setTags(StringUtils.isBlank(tags) ? null : tags);
517
518 Timestamp createTime = visUserDTO.getCreateTime();
519 userAppIdManual.setCreateTime(Objects.isNull(createTime) ? TimestampUtil.now() : createTime);
520
521 Member member = MemberBuilder.build(MemberTypeConstant.app, resources.getIcon(), userAppIdManual.getNickname(), 0);
522 MemberDTO memberDTO = this.memberService.create(member);
523
524 userAppIdManual.setMemberCode(memberDTO.getCode());
525 userAppIdManual.setMemberId(memberDTO.getId());
526
527 userAppIdManual.setType(resources.getType());
528
529 this.userAppRepository.saveByIdManual(userAppIdManual);
530
531 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getOpenid(), 4);
532 if (Objects.isNull(userAppBindDTO.getId())) {
533
534 UserAppBind userAppBind = new UserAppBind();
535 userAppBind.setAccount(resources.getOpenid());
536 userAppBind.setAccountType(4);
537 userAppBind.setUserAppId(visUserId);
538 userAppBind.setStatus(1);
539 userAppBind.setNickname(resources.getNickname());
540 userAppBind.setHeadimgurl(resources.getIcon());
541 this.userAppBindService.create(userAppBind);
542 }
543
544 ((UserAppServiceImpl) AopContext.currentProxy()).asyncSaveByIdManual(userAppIdManual);
545
546 return ResultInfo.success(userAppIdManual);
547 }
548
549 return ResultInfo.failure(null);
550 }
551
552
553
554 @Override
555 @Transactional(rollbackFor = Exception.class)
556 public boolean updatePasswordById(UserApp resources) {
557 return this.userAppRepository.updatePasswordById(resources.getId(), resources.getPassword()) > 0;
558 }
559
560 @AsyncMqSend
561 public void asyncUpdateAppLastActiveTimeAndNicknameAndHeadImgById(UserApp resources) {}
562 @AsyncMqSend
563 public void asyncSaveByIdManual(UserAppIdManual userAppIdManual) {}
564 }
1 package com.topdraw.business.module.user.app.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.app.domain.UserAppBind;
5 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-06-27
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface UserAppBindMapper extends BaseMapper<UserAppBindDTO, UserAppBind> {
15
16 }
1 package com.topdraw.business.module.user.app.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.app.domain.UserApp;
5 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-06-27
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface UserAppMapper extends BaseMapper<UserAppDTO, UserApp> {
15
16 }
1 package com.topdraw.business.module.user.app.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.app.domain.UserApp;
5 import com.topdraw.business.module.user.app.domain.UserAppSimple;
6 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
7 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
8 import org.mapstruct.Mapper;
9 import org.mapstruct.ReportingPolicy;
10
11 /**
12 * @author XiangHan
13 * @date 2022-06-27
14 */
15 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
16 public interface UserAppSimpleMapper extends BaseMapper<UserAppSimpleDTO, UserAppSimple> {
17
18 }
...@@ -24,28 +24,17 @@ public class UserTvBuilder { ...@@ -24,28 +24,17 @@ public class UserTvBuilder {
24 private static final String DEFAULT_CREATE_BY = "system"; 24 private static final String DEFAULT_CREATE_BY = "system";
25 private static final String DEFAULT_UPDATE_BY = "system"; 25 private static final String DEFAULT_UPDATE_BY = "system";
26 26
27 public static UserTv build(UserTv userTv){ 27
28 return build(userTv.getMemberId(),userTv.getMemberCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
29 userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
30 }
31 28
32 public static UserTv build(Long memberId, String memberCode , UserTv userTv){ 29 public static UserTv build(Long memberId, String memberCode , UserTv userTv){
33 return build(memberId,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(), 30 return build(memberId,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
34 userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId()); 31 userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId(),
35 } 32 userTv.getPlatform(), userTv.getPassword(), userTv.getGroups());
36
37 public static UserTv build(String memberCode, UserTv userTv){
38 return build(null,memberCode,userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
39 userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
40 }
41
42 public static UserTv build(Member member, UserTv userTv){
43 return build(member.getId() , member.getCode(),userTv.getId(),userTv.getPlatformAccount(),userTv.getNickname(),userTv.getUsername(),
44 userTv.getLoginDays(),userTv.getStatus(),userTv.getContinueDays(),userTv.getCreateBy(),userTv.getUpdateBy(), userTv.getVisUserId());
45 } 33 }
46 34
47 public static UserTv build(Long memberId , String memberCode , Long id , String platformAccount , String nickname , String username, 35 public static UserTv build(Long memberId , String memberCode , Long id , String platformAccount , String nickname , String username,
48 Integer loginDays , Integer status ,Integer continueDays , String createBy , String updateBy,Long visUserId){ 36 Integer loginDays , Integer status ,Integer continueDays , String createBy , String updateBy,Long visUserId,
37 String platform, String password, String groups){
49 Assert.notNull(memberId,GlobeExceptionMsg.MEMBER_ID_IS_NULL); 38 Assert.notNull(memberId,GlobeExceptionMsg.MEMBER_ID_IS_NULL);
50 Assert.notNull(memberCode,GlobeExceptionMsg.MEMBER_CODE_IS_NULL); 39 Assert.notNull(memberCode,GlobeExceptionMsg.MEMBER_CODE_IS_NULL);
51 Assert.notNull(platformAccount,GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL); 40 Assert.notNull(platformAccount,GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
...@@ -55,10 +44,13 @@ public class UserTvBuilder { ...@@ -55,10 +44,13 @@ public class UserTvBuilder {
55 UserTv userTv = new UserTv(); 44 UserTv userTv = new UserTv();
56 userTv.setId(id); 45 userTv.setId(id);
57 userTv.setPlatformAccount(platformAccount); 46 userTv.setPlatformAccount(platformAccount);
47 userTv.setPlatform(platform);
58 userTv.setMemberCode(memberCode); 48 userTv.setMemberCode(memberCode);
59 userTv.setMemberId(memberId); 49 userTv.setMemberId(memberId);
60 userTv.setNickname(StringUtils.isBlank(nickname)?platformAccount:nickname); 50 userTv.setNickname(StringUtils.isBlank(nickname)?platformAccount:nickname);
61 userTv.setUsername(StringUtils.isBlank(username)?platformAccount:username); 51 userTv.setUsername(StringUtils.isBlank(username)?platformAccount:username);
52 userTv.setPassword(password);
53 userTv.setGroups(groups);
62 userTv.setLoginDays(Objects.nonNull(loginDays)?loginDays:DEFAULT_VALUE); 54 userTv.setLoginDays(Objects.nonNull(loginDays)?loginDays:DEFAULT_VALUE);
63 userTv.setLoginType(DEFAULT_VALUE); 55 userTv.setLoginType(DEFAULT_VALUE);
64 userTv.setStatus(Objects.nonNull(status)?status:DEFAULT_VALUE); 56 userTv.setStatus(Objects.nonNull(status)?status:DEFAULT_VALUE);
......
1 package com.topdraw.business.module.user.iptv.domain;
2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.bean.copier.CopyOptions;
5 import com.topdraw.business.module.common.domain.AsyncMqModule;
6 import com.topdraw.business.module.common.validated.CreateGroup;
7 import com.topdraw.business.module.common.validated.UpdateGroup;
8 import lombok.Data;
9 import lombok.experimental.Accessors;
10 import org.springframework.data.annotation.CreatedDate;
11 import org.springframework.data.annotation.LastModifiedDate;
12 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
13
14 import javax.persistence.*;
15 import javax.validation.constraints.NotNull;
16 import java.io.Serializable;
17 import java.sql.Timestamp;
18
19 /**
20 * @author XiangHan
21 * @date 2021-12-16
22 */
23 @Entity
24 @Data
25 @EntityListeners(AuditingEntityListener.class)
26 @Accessors(chain = true)
27 @Table(name="uc_user_tv")
28 public class UserTvSimple extends AsyncMqModule implements Serializable {
29
30 /** ID */
31 @Id
32 @GeneratedValue(strategy = GenerationType.IDENTITY)
33 @Column(name = "id")
34 private Long id;
35
36 /** 会员id */
37 @Column(name = "member_id")
38 private Long memberId;
39
40 /** 原vis_user_id */
41 @Column(name = "vis_user_id")
42 private Long visUserId;
43
44 /** 绑定的小屏账户会员编码 */
45 @Column(name = "priority_member_code")
46 private String priorityMemberCode;
47
48 /** 绑定的小屏账户会员编码 */
49 @Column(name = "platform_account")
50 private String platformAccount;
51
52 public void copy(UserTvSimple source){
53 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(false));
54 }
55 }
1 package com.topdraw.business.module.user.iptv.growreport.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-07
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="uc_growth_report")
24 public class GrowthReport implements Serializable {
25
26 @Id
27 @Column(name = "id")
28 private Long id;
29
30 // 用户id
31 @Column(name = "user_id")
32 private Long userId;
33
34 // 会员id
35 @Column(name = "member_id")
36 private Long memberId;
37
38 // 会员code
39 @Column(name = "member_code")
40 private String memberCode;
41
42 // 大屏账号
43 @Column(name = "platform_account")
44 private String platformAccount;
45
46 // 开始日期
47 @Column(name = "start_date")
48 private String startDate;
49
50 // 结束时间
51 @Column(name = "end_date")
52 private String endDate;
53
54 // 栏目播放时长数据
55 @Column(name = "data")
56 private String data;
57
58 // 创建时间
59 @CreatedDate
60 @Column(name = "create_time")
61 private Timestamp createTime;
62
63 // 修改时间
64 @LastModifiedDate
65 @Column(name = "update_time")
66 private Timestamp updateTime;
67
68 public void copy(GrowthReport source){
69 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
70 }
71 }
1 package com.topdraw.business.module.user.iptv.growreport.repository;
2
3 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Modifying;
7 import org.springframework.data.jpa.repository.Query;
8
9 import java.util.Optional;
10
11 /**
12 * @author XiangHan
13 * @date 2022-07-07
14 */
15 public interface GrowthReportRepository extends JpaRepository<GrowthReport, Long>, JpaSpecificationExecutor<GrowthReport> {
16
17
18 Optional<GrowthReport> findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay);
19
20
21 @Modifying
22 @Query(value = "UPDATE `uc_growth_report` SET `data` = ?2, `update_time` = now() WHERE `id` =?1", nativeQuery = true)
23 Integer updateGrowthReportData(Long id, String data);
24
25 }
1 package com.topdraw.business.module.user.iptv.growreport.rest;
2
3 import com.topdraw.common.ResultInfo;
4 import com.topdraw.annotation.Log;
5 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
6 import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.data.domain.Pageable;
9 import org.springframework.validation.annotation.Validated;
10 import org.springframework.web.bind.annotation.*;
11 import io.swagger.annotations.*;
12
13 /**
14 * @author XiangHan
15 * @date 2022-07-07
16 */
17 @Api(tags = "GrowthReport管理")
18 @RestController
19 @RequestMapping("/api/GrowthReport")
20 public class GrowthReportController {
21
22 @Autowired
23 private GrowthReportService GrowthReportService;
24
25 @Log
26 @PostMapping
27 @ApiOperation("新增GrowthReport")
28 public ResultInfo create(@Validated @RequestBody GrowthReport resources) {
29 GrowthReportService.create(resources);
30 return ResultInfo.success();
31 }
32
33 @Log
34 @PutMapping
35 @ApiOperation("修改GrowthReport")
36 public ResultInfo update(@Validated @RequestBody GrowthReport resources) {
37 GrowthReportService.update(resources);
38 return ResultInfo.success();
39 }
40
41
42 @Log
43 @DeleteMapping(value = "/{id}")
44 @ApiOperation("删除GrowthReport")
45 public ResultInfo delete(@PathVariable Long id) {
46 GrowthReportService.delete(id);
47 return ResultInfo.success();
48 }
49
50 }
1 package com.topdraw.business.module.user.iptv.growreport.service;
2
3 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
4 import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
5
6 /**
7 * @author XiangHan
8 * @date 2022-07-07
9 */
10 public interface GrowthReportService {
11
12 /**
13 * 根据ID查询
14 * @param id ID
15 * @return GrowthReportDTO
16 */
17 GrowthReportDTO findById(Long id);
18
19 void create(GrowthReport resources);
20
21 void update(GrowthReport resources);
22
23 void delete(Long id);
24
25 /**
26 *
27 * @param platformAccount
28 * @param weekFirstDay
29 * @param weekLastDay
30 * @return
31 */
32 GrowthReportDTO findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay);
33
34
35 Integer updateGrowthReportData(Long id, String data);
36 }
1 package com.topdraw.business.module.user.iptv.growreport.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
7 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8
9
10 /**
11 * @author XiangHan
12 * @date 2022-07-07
13 */
14 @Data
15 public class GrowthReportDTO implements Serializable {
16
17 // 处理精度丢失问题
18 @JsonSerialize(using= ToStringSerializer.class)
19 private Long id;
20
21 // 用户id
22 private Long userId;
23
24 // 会员id
25 private Long memberId;
26
27 // 会员code
28 private String memberCode;
29
30 // 大屏账号
31 private String platformAccount;
32
33 // 开始日期
34 private String startDate;
35
36 // 结束时间
37 private String endDate;
38
39 // 栏目播放时长数据
40 private String data;
41
42 // 创建时间
43 private Timestamp createTime;
44
45 // 修改时间
46 private Timestamp updateTime;
47 }
1 package com.topdraw.business.module.user.iptv.growreport.service.dto;
2
3 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
4 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
5 import lombok.Data;
6
7 import java.io.Serializable;
8 import java.sql.Timestamp;
9 import java.util.List;
10
11
12 /**
13 * @author XiangHan
14 * @date 2022-07-07
15 */
16 @Data
17 public class GrowthReportRequest implements Serializable {
18
19 private String platformAccount;
20
21 private List<CategoryContent> playDurationWithCategory;
22
23 @Data
24 public static class CategoryContent{
25 private String categoryName;
26 private Long playDuration;
27 private String categoryCode;
28 }
29
30 }
1 package com.topdraw.business.module.user.iptv.growreport.service.impl;
2
3 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
4 import com.topdraw.utils.ValidationUtil;
5 import com.topdraw.business.module.user.iptv.growreport.repository.GrowthReportRepository;
6 import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
7 import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
8 import com.topdraw.business.module.user.iptv.growreport.service.mapper.GrowthReportMapper;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import cn.hutool.core.lang.Snowflake;
15 import cn.hutool.core.util.IdUtil;
16 import org.springframework.data.domain.Page;
17 import org.springframework.data.domain.Pageable;
18 import org.springframework.util.Assert;
19 import com.topdraw.utils.PageUtil;
20 import com.topdraw.utils.QueryHelp;
21
22 import java.util.List;
23 import java.util.Map;
24
25 /**
26 * @author XiangHan
27 * @date 2022-07-07
28 */
29 @Service
30 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
31 public class GrowthReportServiceImpl implements GrowthReportService {
32
33 @Autowired
34 private GrowthReportRepository growthReportRepository;
35
36 @Autowired
37 private GrowthReportMapper growthReportMapper;
38
39 @Override
40 @Transactional(readOnly = true)
41 public GrowthReportDTO findById(Long id) {
42 GrowthReport growthReport = this.growthReportRepository.findById(id).orElseGet(GrowthReport::new);
43 ValidationUtil.isNull(growthReport.getId(),"GrowthReport","id",id);
44 return this.growthReportMapper.toDto(growthReport);
45 }
46
47 @Override
48 @Transactional(rollbackFor = Exception.class)
49 public void create(GrowthReport resources) {
50 Snowflake snowflake = IdUtil.createSnowflake(1, 1);
51 resources.setId(snowflake.nextId());
52 this.growthReportRepository.save(resources);
53 }
54
55 @Override
56 @Transactional(rollbackFor = Exception.class)
57 public void update(GrowthReport resources) {
58 GrowthReport growthReport = this.growthReportRepository.findById(resources.getId()).orElseGet(GrowthReport::new);
59 ValidationUtil.isNull( growthReport.getId(),"GrowthReport","id",resources.getId());
60 growthReport.copy(resources);
61 this.growthReportRepository.save(growthReport);
62 }
63
64 @Override
65 @Transactional(rollbackFor = Exception.class)
66 public void delete(Long id) {
67 Assert.notNull(id, "The given id must not be null!");
68 GrowthReport growthReport = this.growthReportRepository.findById(id).orElseThrow(
69 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", GrowthReport.class, id), 1));
70 this.growthReportRepository.delete(growthReport);
71 }
72
73 @Override
74 @Transactional(readOnly = true)
75 public GrowthReportDTO findByPlatformAccountAndStartDateAndEndDate(String platformAccount, String weekFirstDay, String weekLastDay) {
76 GrowthReport growthReport = this.growthReportRepository.findByPlatformAccountAndStartDateAndEndDate(platformAccount, weekFirstDay, weekLastDay).orElseGet(GrowthReport::new);
77 return this.growthReportMapper.toDto(growthReport);
78 }
79
80 @Override
81 @Transactional(rollbackFor = Exception.class)
82 public Integer updateGrowthReportData(Long id, String data) {
83 return this.growthReportRepository.updateGrowthReportData(id, data);
84 }
85
86
87 }
1 package com.topdraw.business.module.user.iptv.growreport.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
5 import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-07
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface GrowthReportMapper extends BaseMapper<GrowthReportDTO, GrowthReport> {
15
16 }
1 package com.topdraw.business.module.user.iptv.repository; 1 package com.topdraw.business.module.user.iptv.repository;
2 2
3 import com.topdraw.business.module.user.iptv.domain.UserTv; 3 import com.topdraw.business.module.user.iptv.domain.UserTv;
4 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
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;
7 import org.springframework.data.jpa.repository.Modifying;
8 import org.springframework.data.jpa.repository.Query;
9 import org.springframework.data.repository.query.Param;
10 import org.springframework.transaction.annotation.Transactional;
6 11
12 import java.time.LocalDateTime;
7 import java.util.Optional; 13 import java.util.Optional;
8 14
9 /** 15 /**
...@@ -17,4 +23,13 @@ public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecif ...@@ -17,4 +23,13 @@ public interface UserTvRepository extends JpaRepository<UserTv, Long>, JpaSpecif
17 Optional<UserTv> findByPriorityMemberCode(String memberCode); 23 Optional<UserTv> findByPriorityMemberCode(String memberCode);
18 24
19 Optional<UserTv> findByMemberId(Long memberId); 25 Optional<UserTv> findByMemberId(Long memberId);
26
27 @Modifying
28 @Query(value = "UPDATE `uc_user_tv` SET `vis_user_id` = ?2, `update_time` = ?3 WHERE `id` = ?1", nativeQuery = true)
29 Integer updateUserTvVisUserId(Long id, Long visUserId, LocalDateTime now);
30
31 @Modifying
32 @Query(value = "UPDATE `uc_user_tv` SET `priority_member_code` = :#{#resources.priorityMemberCode}, `update_time` = now()" +
33 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
34 Integer updatePriorityMemberCode(@Param("resources") UserTv resources);
20 } 35 }
......
1 package com.topdraw.business.module.user.iptv.repository;
2
3 import com.topdraw.business.module.user.iptv.domain.UserTvSimple;
4 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
5 import org.springframework.data.jpa.repository.JpaRepository;
6 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
7 import org.springframework.data.jpa.repository.Query;
8
9 /**
10 * @author XiangHan
11 * @date 2021-12-16
12 */
13 public interface UserTvSimpleRepository extends JpaRepository<UserTvSimple, Long>, JpaSpecificationExecutor<UserTvSimple> {
14
15 @Query(value = "SELECT `id`, `vis_user_id` , `member_id` , `platform_account`, `priority_member_code` FROM `uc_user_tv` WHERE `platform_account` = ?1", nativeQuery = true)
16 UserTvSimple findSimpleByPlatformAccount(String platformAccount);
17 }
1 package com.topdraw.business.module.user.iptv.rest;
2
3 import com.topdraw.annotation.AnonymousAccess;
4 import com.topdraw.business.module.user.iptv.domain.UserTv;
5 import com.topdraw.business.module.user.iptv.service.UserTvService;
6 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
7 import com.topdraw.common.ResultInfo;
8 import com.topdraw.exception.BadRequestException;
9 import com.topdraw.exception.GlobeExceptionMsg;
10 import io.swagger.annotations.Api;
11 import io.swagger.annotations.ApiOperation;
12 import lombok.extern.slf4j.Slf4j;
13 import org.apache.commons.lang3.StringUtils;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.*;
17
18 import java.util.Objects;
19
20 /**
21 * @author XiangHan
22 * @date 2021-12-16
23 */
24 @Api(tags = "微信管理")
25 @RestController
26 @RequestMapping("/uce/userTv")
27 @Slf4j
28 public class UserTvController {
29
30 @Autowired
31 private UserTvService userTvService;
32
33 @PostMapping(value = "/updateUserTvVisUserId")
34 @ApiOperation("新增UserWeixin")
35 @AnonymousAccess
36 public ResultInfo updateUserTvVisUserId(@Validated @RequestBody UserTv resources) {
37
38 log.info("UserOperationController ==> updateUserTvVisUserId ==>> param ==> {}",resources);
39
40 if (StringUtils.isBlank(resources.getPlatformAccount())){
41 throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
42 }
43
44 if (Objects.isNull(resources.getVisUserId())){
45 throw new BadRequestException(GlobeExceptionMsg.VIS_USER_ID_IS_NULL);
46 }
47
48 UserTvDTO userTvDTO = this.userTvService.updateUserTvVisUserId(resources);
49 if (Objects.nonNull(userTvDTO.getId()))
50 return ResultInfo.success(userTvDTO);
51 else return ResultInfo.failure("操作失败,请检查 ==>> /uce/userTv/updateUserTvVisUserId");
52 }
53
54 }
...@@ -3,6 +3,7 @@ package com.topdraw.business.module.user.iptv.service; ...@@ -3,6 +3,7 @@ package com.topdraw.business.module.user.iptv.service;
3 import com.topdraw.business.module.member.service.dto.MemberDTO; 3 import com.topdraw.business.module.member.service.dto.MemberDTO;
4 import com.topdraw.business.module.user.iptv.domain.UserTv; 4 import com.topdraw.business.module.user.iptv.domain.UserTv;
5 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 5 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
6 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
6 7
7 /** 8 /**
8 * @author XiangHan 9 * @author XiangHan
...@@ -51,6 +52,13 @@ public interface UserTvService { ...@@ -51,6 +52,13 @@ public interface UserTvService {
51 52
52 /** 53 /**
53 * 54 *
55 * @param platformAccount
56 * @return
57 */
58 UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount);
59
60 /**
61 *
54 * @param memberCode 62 * @param memberCode
55 * @return 63 * @return
56 */ 64 */
...@@ -69,7 +77,7 @@ public interface UserTvService { ...@@ -69,7 +77,7 @@ public interface UserTvService {
69 * @param memberCode 77 * @param memberCode
70 * @return 78 * @return
71 */ 79 */
72 boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId,String memberCode); 80 boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode);
73 81
74 /** 82 /**
75 * 83 *
...@@ -77,4 +85,18 @@ public interface UserTvService { ...@@ -77,4 +85,18 @@ public interface UserTvService {
77 * @return 85 * @return
78 */ 86 */
79 MemberDTO findMemberByPlatformAccount(String platformAccount); 87 MemberDTO findMemberByPlatformAccount(String platformAccount);
88
89 /**
90 *
91 * @param resources
92 * @return
93 */
94 UserTvDTO updateUserTvVisUserId(UserTv resources);
95
96 /**
97 *
98 * @param resources
99 * @return
100 */
101 UserTvDTO doUpdatePriorityMemberCode(UserTv resources);
80 } 102 }
......
1 package com.topdraw.business.module.user.iptv.service.dto;
2
3 import lombok.Data;
4
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2021-12-16
11 */
12 @Data
13 public class UserTvSimpleDTO implements Serializable {
14
15 private Long visUserId;
16 /** 绑定的小屏账户会员编码 */
17 private String priorityMemberCode;
18 /** 会员id */
19 private Long memberId;
20
21 private String platformAccount;
22 }
23
24
1 package com.topdraw.business.module.user.iptv.service.impl; 1 package com.topdraw.business.module.user.iptv.service.impl;
2 2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.topdraw.aspect.AsyncMqSend;
3 import com.topdraw.business.module.member.service.MemberService; 6 import com.topdraw.business.module.member.service.MemberService;
4 import com.topdraw.business.module.member.service.dto.MemberDTO; 7 import com.topdraw.business.module.member.service.dto.MemberDTO;
5 import com.topdraw.business.module.user.iptv.domain.UserTv; 8 import com.topdraw.business.module.user.iptv.domain.UserTv;
9 import com.topdraw.business.module.user.iptv.domain.UserTvSimple;
10 import com.topdraw.business.module.user.iptv.repository.UserTvSimpleRepository;
11 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
12 import com.topdraw.business.module.user.iptv.service.mapper.UserTvSimpleMapper;
13 import com.topdraw.business.RedisKeyConstants;
6 import com.topdraw.exception.EntityNotFoundException; 14 import com.topdraw.exception.EntityNotFoundException;
7 import com.topdraw.exception.GlobeExceptionMsg; 15 import com.topdraw.exception.GlobeExceptionMsg;
16 import com.topdraw.utils.RedisUtils;
8 import com.topdraw.utils.ValidationUtil; 17 import com.topdraw.utils.ValidationUtil;
9 import com.topdraw.business.module.user.iptv.repository.UserTvRepository; 18 import com.topdraw.business.module.user.iptv.repository.UserTvRepository;
10 import com.topdraw.business.module.user.iptv.service.UserTvService; 19 import com.topdraw.business.module.user.iptv.service.UserTvService;
11 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 20 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
12 import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper; 21 import com.topdraw.business.module.user.iptv.service.mapper.UserTvMapper;
22 import lombok.extern.slf4j.Slf4j;
13 import org.apache.commons.lang3.StringUtils; 23 import org.apache.commons.lang3.StringUtils;
24 import org.springframework.aop.framework.AopContext;
14 import org.springframework.beans.factory.annotation.Autowired; 25 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service; 26 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Propagation; 27 import org.springframework.transaction.annotation.Propagation;
...@@ -18,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -18,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
18 import org.springframework.dao.EmptyResultDataAccessException; 29 import org.springframework.dao.EmptyResultDataAccessException;
19 import org.springframework.util.Assert; 30 import org.springframework.util.Assert;
20 31
32 import java.time.LocalDateTime;
33 import java.util.Map;
21 import java.util.Objects; 34 import java.util.Objects;
22 import java.util.Optional; 35 import java.util.Optional;
23 36
...@@ -27,15 +40,26 @@ import java.util.Optional; ...@@ -27,15 +40,26 @@ import java.util.Optional;
27 */ 40 */
28 @Service 41 @Service
29 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 42 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
43 @Slf4j
30 public class UserTvServiceImpl implements UserTvService { 44 public class UserTvServiceImpl implements UserTvService {
31 45
32 46
33 @Autowired 47 @Autowired
34 private UserTvMapper userTvMapper; 48 private UserTvMapper userTvMapper;
35 @Autowired 49 @Autowired
50 private UserTvSimpleMapper userTvSimpleMapper;
51 @Autowired
36 private MemberService memberService; 52 private MemberService memberService;
37 @Autowired 53 @Autowired
38 private UserTvRepository userTvRepository; 54 private UserTvRepository userTvRepository;
55 @Autowired
56 private UserTvSimpleRepository userTvSimpleRepository;
57
58 @Autowired
59 private RedisUtils redisUtils;
60
61 @AsyncMqSend
62 public void asyncUpdateUserTvVisUserId(UserTvDTO userTvDTO) {}
39 63
40 /** 64 /**
41 * 获取大屏账户对应的会员 65 * 获取大屏账户对应的会员
...@@ -46,6 +70,7 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -46,6 +70,7 @@ public class UserTvServiceImpl implements UserTvService {
46 * @return 70 * @return
47 */ 71 */
48 @Override 72 @Override
73 @Transactional(readOnly = true)
49 public MemberDTO findMemberByPlatformAccount(String platformAccount){ 74 public MemberDTO findMemberByPlatformAccount(String platformAccount){
50 // 大屏账户 75 // 大屏账户
51 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); 76 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
...@@ -64,6 +89,41 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -64,6 +89,41 @@ public class UserTvServiceImpl implements UserTvService {
64 throw new EntityNotFoundException(UserTvDTO.class,"platformAccount", GlobeExceptionMsg.IPTV_IS_NULL); 89 throw new EntityNotFoundException(UserTvDTO.class,"platformAccount", GlobeExceptionMsg.IPTV_IS_NULL);
65 } 90 }
66 91
92 @Override
93 @Transactional(rollbackFor = Exception.class)
94 public UserTvDTO updateUserTvVisUserId(UserTv resources) {
95
96 String platformAccount = resources.getPlatformAccount();
97
98 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
99
100 if (Objects.nonNull(userTvDTO.getId())) {
101
102 Integer integer = this.userTvRepository.updateUserTvVisUserId(userTvDTO.getId(), resources.getVisUserId(), LocalDateTime.now());
103
104 if (integer == 1) {
105 log.info("修改大屏vis_user id成功,同步至大屏侧数据库, userTvDTO ==>> {}", userTvDTO);
106 ((UserTvServiceImpl) AopContext.currentProxy()).asyncUpdateUserTvVisUserId(userTvDTO);
107 }
108
109 return this.findById(userTvDTO.getId());
110 }
111
112 return null;
113 }
114
115 @Override
116 @Transactional(rollbackFor = Exception.class)
117 public UserTvDTO doUpdatePriorityMemberCode(UserTv resources) {
118 Integer count = this.userTvRepository.updatePriorityMemberCode(resources);
119 if (Objects.nonNull(count) && count > 0) {
120 UserTv userTv = this.userTvRepository.findById(resources.getId()).orElseGet(UserTv::new);
121 return this.userTvMapper.toDto(userTv);
122 }
123 return this.userTvMapper.toDto(resources);
124 }
125
126
67 private MemberDTO findMemberByMemberCode(String memberCode) { 127 private MemberDTO findMemberByMemberCode(String memberCode) {
68 return this.memberService.findByCode(memberCode); 128 return this.memberService.findByCode(memberCode);
69 } 129 }
...@@ -73,6 +133,7 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -73,6 +133,7 @@ public class UserTvServiceImpl implements UserTvService {
73 } 133 }
74 134
75 @Override 135 @Override
136 @Transactional(readOnly = true)
76 public UserTvDTO findById(Long id) { 137 public UserTvDTO findById(Long id) {
77 UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new); 138 UserTv UserTv = this.userTvRepository.findById(id).orElseGet(UserTv::new);
78 ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id); 139 ValidationUtil.isNull(UserTv.getId(),"UserTv","id",id);
...@@ -123,16 +184,38 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -123,16 +184,38 @@ public class UserTvServiceImpl implements UserTvService {
123 } 184 }
124 185
125 @Override 186 @Override
187 @Transactional(readOnly = true)
126 public UserTvDTO findByPlatformAccount(String platformAccount) { 188 public UserTvDTO findByPlatformAccount(String platformAccount) {
127 Optional<UserTv> userTv = this.userTvRepository.findByPlatformAccount(platformAccount); 189 UserTv userTv = this.userTvRepository.findByPlatformAccount(platformAccount).orElseGet(UserTv::new);
128 if (userTv.isPresent()) { 190 return this.userTvMapper.toDto(userTv);
129 ValidationUtil.isNull( userTv.get().getId(),"UserTv","id",userTv.get().getId());
130 return this.userTvMapper.toDto(userTv.get());
131 } 191 }
132 return null; 192
193 @Override
194 // @Cacheable(cacheNames = RedisKeyConstants.cacheUserTvByPlatformAccount, key = "#platformAccount")
195 public UserTvSimpleDTO findSimpleByPlatformAccount(String platformAccount) {
196
197 Object userTvSimpleObj = this.redisUtils.get(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount);
198 if (Objects.nonNull(userTvSimpleObj)) {
199 Map<String, Object> map = (Map<String, Object>)userTvSimpleObj;
200 UserTvSimpleDTO userTvSimpleDTO = new UserTvSimpleDTO();
201 userTvSimpleDTO.setPlatformAccount(map.get("platformAccount").toString());
202 userTvSimpleDTO.setMemberId(Long.valueOf(map.get("memberId").toString()));
203 userTvSimpleDTO.setPriorityMemberCode(map.get("priorityMemberCode") == null ? "" : map.get("priorityMemberCode").toString());
204 return userTvSimpleDTO;
205 }
206
207 UserTvSimple userTvSimple = this.userTvSimpleRepository.findSimpleByPlatformAccount(platformAccount);
208 if (Objects.nonNull(userTvSimple)) {
209 JSONObject userTvSimpleJSON = JSONObject.parseObject(JSON.toJSONString(userTvSimple), JSONObject.class);
210 this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, userTvSimpleJSON);
211 return this.userTvSimpleMapper.toDto(userTvSimple);
212 }
213
214 return this.userTvSimpleMapper.toDto(userTvSimple);
133 } 215 }
134 216
135 @Override 217 @Override
218 @Transactional(readOnly = true)
136 public UserTvDTO findByPriorityMemberCode(String memberCode) { 219 public UserTvDTO findByPriorityMemberCode(String memberCode) {
137 Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode); 220 Optional<UserTv> userTv = this.userTvRepository.findByPriorityMemberCode(memberCode);
138 if (userTv.isPresent()) { 221 if (userTv.isPresent()) {
...@@ -143,6 +226,7 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -143,6 +226,7 @@ public class UserTvServiceImpl implements UserTvService {
143 } 226 }
144 227
145 @Override 228 @Override
229 @Transactional(readOnly = true)
146 public UserTvDTO findByMemberId(Long memberId) { 230 public UserTvDTO findByMemberId(Long memberId) {
147 Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId); 231 Optional<UserTv> userTv = this.userTvRepository.findByMemberId(memberId);
148 if (userTv.isPresent()) { 232 if (userTv.isPresent()) {
...@@ -153,6 +237,7 @@ public class UserTvServiceImpl implements UserTvService { ...@@ -153,6 +237,7 @@ public class UserTvServiceImpl implements UserTvService {
153 } 237 }
154 238
155 @Override 239 @Override
240 @Transactional(readOnly = true)
156 public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) { 241 public boolean checkPriorityMemberByMemberIdOrMemberCode(Long memberId, String memberCode) {
157 // 检查会员是否存在 242 // 检查会员是否存在
158 this.checkMember(memberId, memberCode); 243 this.checkMember(memberId, memberCode);
......
1 package com.topdraw.business.module.user.iptv.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.iptv.domain.UserTv;
5 import com.topdraw.business.module.user.iptv.domain.UserTvSimple;
6 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
7 import org.mapstruct.Mapper;
8 import org.mapstruct.ReportingPolicy;
9
10 /**
11 * @author XiangHan
12 * @date 2021-12-16
13 */
14 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
15 public interface UserTvSimpleMapper extends BaseMapper<UserTvSimpleDTO, UserTvSimple> {
16
17 }
...@@ -29,9 +29,7 @@ public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, J ...@@ -29,9 +29,7 @@ public interface UserWeixinRepository extends JpaRepository<UserWeixin, Long>, J
29 Optional<UserWeixin> findFirstByMemberId(Long memberId); 29 Optional<UserWeixin> findFirstByMemberId(Long memberId);
30 30
31 @Modifying 31 @Modifying
32 @Transactional 32 @Query(value = "UPDATE `uc_user_weixin` SET update_time = now(), `status` = :#{#resources.status}" +
33 @Query(value = "update `uc_user_weixin` set update_time = :#{#resources.updateTime} " + 33 " WHERE `id` = :#{#resources.id}", nativeQuery = true)
34 "where appid = :#{#resources.appid} and openid = :#{#resources.openid}", nativeQuery = true) 34 Integer updateWeixinStatus(@Param("resources") UserWeixin resource);
35 void updateTime(@Param("resources") UserWeixin resources);
36
37 } 35 }
......
...@@ -31,12 +31,6 @@ public interface UserWeixinService { ...@@ -31,12 +31,6 @@ public interface UserWeixinService {
31 31
32 /** 32 /**
33 * 33 *
34 * @param resources
35 */
36 void updateTime(UserWeixin resources);
37
38 /**
39 *
40 * @param id 34 * @param id
41 */ 35 */
42 void delete(Long id); 36 void delete(Long id);
...@@ -87,4 +81,11 @@ public interface UserWeixinService { ...@@ -87,4 +81,11 @@ public interface UserWeixinService {
87 * @return 81 * @return
88 */ 82 */
89 UserWeixinDTO findFirstByMemberId(Long memberId); 83 UserWeixinDTO findFirstByMemberId(Long memberId);
84
85 /**
86 *
87 * @param userWeixin
88 * @return
89 */
90 UserWeixinDTO doUpdateWeixinStatus(UserWeixin userWeixin);
90 } 91 }
......
...@@ -14,6 +14,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -14,6 +14,8 @@ import org.springframework.transaction.annotation.Transactional;
14 import org.springframework.dao.EmptyResultDataAccessException; 14 import org.springframework.dao.EmptyResultDataAccessException;
15 import org.springframework.util.Assert; 15 import org.springframework.util.Assert;
16 16
17 import java.util.Objects;
18
17 /** 19 /**
18 * @author XiangHan 20 * @author XiangHan
19 * @date 2021-12-16 21 * @date 2021-12-16
...@@ -54,11 +56,6 @@ public class UserWeixinServiceImpl implements UserWeixinService { ...@@ -54,11 +56,6 @@ public class UserWeixinServiceImpl implements UserWeixinService {
54 } 56 }
55 57
56 @Override 58 @Override
57 public void updateTime(UserWeixin resources) {
58 this.userWeixinRepository.updateTime(resources);
59 }
60
61 @Override
62 @Transactional(rollbackFor = Exception.class) 59 @Transactional(rollbackFor = Exception.class)
63 public void delete(Long id) { 60 public void delete(Long id) {
64 Assert.notNull(id, "The given id must not be null!"); 61 Assert.notNull(id, "The given id must not be null!");
...@@ -104,4 +101,15 @@ public class UserWeixinServiceImpl implements UserWeixinService { ...@@ -104,4 +101,15 @@ public class UserWeixinServiceImpl implements UserWeixinService {
104 return this.userWeixinMapper.toDto(userWeixin); 101 return this.userWeixinMapper.toDto(userWeixin);
105 } 102 }
106 103
104 @Override
105 @Transactional(rollbackFor = Exception.class)
106 public UserWeixinDTO doUpdateWeixinStatus(UserWeixin resource) {
107 Integer count = this.userWeixinRepository.updateWeixinStatus(resource);
108 if (Objects.nonNull(count) && count > 0) {
109 UserWeixin userWeixin = this.userWeixinRepository.findById(resource.getId()).orElseGet(UserWeixin::new);
110 return this.userWeixinMapper.toDto(userWeixin);
111 }
112 return this.userWeixinMapper.toDto(resource);
113 }
114
107 } 115 }
......
1 package com.topdraw.weixin.subscribe.domain; 1 package com.topdraw.business.module.user.weixin.subscribe.domain;
2 2
3 import lombok.Data; 3 import lombok.Data;
4 import lombok.experimental.Accessors; 4 import lombok.experimental.Accessors;
...@@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable { ...@@ -54,14 +54,22 @@ public class WechatSubscribeRecord implements Serializable {
54 @Column(name = "entity_type") 54 @Column(name = "entity_type")
55 private Integer entityType; 55 private Integer entityType;
56 56
57 // 来源类型 1:大屏;2:营销活动;3:其他; 57 // 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他;
58 @Column(name = "source_type") 58 @Column(name = "source_scence")
59 private Integer sourceType; 59 private Integer sourceScence;
60 60
61 // 来源描述 61 // 来源描述,前端参数源
62 @Column(name = "source_info") 62 @Column(name = "source_info")
63 private String sourceInfo; 63 private String sourceInfo;
64 64
65 // 来源描述,系统/运营手动维护
66 @Column(name = "source_desc")
67 private String sourceDesc;
68
69 // 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
70 @Column(name = "wx_scence")
71 private Integer wxScence;
72
65 // 创建时间 73 // 创建时间
66 @CreatedDate 74 @CreatedDate
67 @Column(name = "create_time") 75 @Column(name = "create_time")
......
1 package com.topdraw.weixin.subscribe.repository; 1 package com.topdraw.business.module.user.weixin.subscribe.repository;
2 2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord; 3 import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
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
...@@ -13,4 +13,6 @@ import java.util.Optional; ...@@ -13,4 +13,6 @@ import java.util.Optional;
13 public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> { 13 public interface WechatSubscribeRecordRepository extends JpaRepository<WechatSubscribeRecord, Long>, JpaSpecificationExecutor<WechatSubscribeRecord> {
14 14
15 Optional<WechatSubscribeRecord> findFirstByCode(String code); 15 Optional<WechatSubscribeRecord> findFirstByCode(String code);
16
17 Optional<WechatSubscribeRecord> findFirstByMemberId(Long memberId);
16 } 18 }
......
1 package com.topdraw.weixin.subscribe.service; 1 package com.topdraw.business.module.user.weixin.subscribe.service;
2 2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord; 3 import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
4 4
5 /** 5 /**
6 * @author XiangHan 6 * @author XiangHan
......
1 package com.topdraw.weixin.subscribe.service.dto; 1 package com.topdraw.business.module.user.weixin.subscribe.service.dto;
2 2
3 import lombok.Data; 3 import lombok.Data;
4 import java.sql.Timestamp; 4
5 import javax.persistence.Column;
5 import java.io.Serializable; 6 import java.io.Serializable;
7 import java.sql.Timestamp;
6 8
7 9
8 /** 10 /**
...@@ -33,12 +35,20 @@ public class WechatSubscribeRecordDTO implements Serializable { ...@@ -33,12 +35,20 @@ public class WechatSubscribeRecordDTO implements Serializable {
33 // 实例类型 1:大屏扫码;2:营销活动; 35 // 实例类型 1:大屏扫码;2:营销活动;
34 private Integer entityType; 36 private Integer entityType;
35 37
36 // 来源类型 1:大屏;2:营销活动;3:其他; 38 // 业务场景 0:分享;1:大屏扫码免费看;2:大屏线上活动扫码引导关注;3:小屏线上活动长按二维码引导关注;4:线下活动海报;5:线下机构/渠道引流;99:其他;
37 private Integer sourceType; 39 private Integer sourceType;
38 40
39 // 来源描述 41 private Integer sourceScence;
42
43 // 来源描述,前端参数源
40 private String sourceInfo; 44 private String sourceInfo;
41 45
46 // 来源描述,系统/运营手动维护
47 private String sourceDesc;
48
49 // 微信场景值 1007:单人聊天会话中的小程序消息卡片;1047:扫描小程序码;详见:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
50 private Integer wxScence;
51
42 // 创建时间 52 // 创建时间
43 private Timestamp createTime; 53 private Timestamp createTime;
44 54
......
1 package com.topdraw.weixin.subscribe.service.impl; 1 package com.topdraw.business.module.user.weixin.subscribe.service.impl;
2 2
3 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord; 3 import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
4 import com.topdraw.weixin.subscribe.repository.WechatSubscribeRecordRepository; 4 import com.topdraw.business.module.user.weixin.subscribe.repository.WechatSubscribeRecordRepository;
5 import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService; 5 import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService;
6 import com.topdraw.weixin.subscribe.service.mapper.WechatSubscribeRecordMapper; 6 import com.topdraw.util.TimestampUtil;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
9 import org.springframework.transaction.annotation.Propagation; 9 import org.springframework.transaction.annotation.Propagation;
10 import org.springframework.transaction.annotation.Transactional; 10 import org.springframework.transaction.annotation.Transactional;
11 11
12 import java.util.Optional;
13
12 /** 14 /**
13 * @author XiangHan 15 * @author XiangHan
14 * @date 2022-05-21 16 * @date 2022-05-21
...@@ -20,12 +22,18 @@ public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordSe ...@@ -20,12 +22,18 @@ public class WechatSubscribeRecordServiceImpl implements WechatSubscribeRecordSe
20 @Autowired 22 @Autowired
21 private WechatSubscribeRecordRepository wechatSubscribeRecordRepository; 23 private WechatSubscribeRecordRepository wechatSubscribeRecordRepository;
22 24
23 @Autowired
24 private WechatSubscribeRecordMapper wechatSubscribeRecordMapper;
25
26 @Override 25 @Override
27 @Transactional(rollbackFor = Exception.class) 26 @Transactional(rollbackFor = Exception.class)
28 public void create(WechatSubscribeRecord resources) { 27 public void create(WechatSubscribeRecord resources) {
29 this.wechatSubscribeRecordRepository.save(resources); 28 this.wechatSubscribeRecordRepository.save(resources);
29 /* Optional<WechatSubscribeRecord> wechatSubscribeRecordOptional = this.wechatSubscribeRecordRepository.findFirstByMemberId(resources.getMemberId());
30 if (!wechatSubscribeRecordOptional.isPresent()) {
31 this.wechatSubscribeRecordRepository.save(resources);
32 } else {
33 WechatSubscribeRecord wechatSubscribeRecord = wechatSubscribeRecordOptional.get();
34 wechatSubscribeRecord.copy(wechatSubscribeRecord);
35 wechatSubscribeRecord.setUpdateTime(TimestampUtil.now());
36 this.wechatSubscribeRecordRepository.save(resources);
37 }*/
30 } 38 }
31 } 39 }
......
1 package com.topdraw.weixin.subscribe.service.mapper; 1 package com.topdraw.business.module.user.weixin.subscribe.service.mapper;
2 2
3 import com.topdraw.base.BaseMapper; 3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord; 4 import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
5 import com.topdraw.weixin.subscribe.service.dto.WechatSubscribeRecordDTO; 5 import com.topdraw.business.module.user.weixin.subscribe.service.dto.WechatSubscribeRecordDTO;
6 import org.mapstruct.Mapper; 6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy; 7 import org.mapstruct.ReportingPolicy;
8 8
......
1 package com.topdraw.business.module.user.weixin.wechatshare.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12 import java.util.UUID;
13
14 import java.io.Serializable;
15
16 /**
17 * @author XiangHan
18 * @date 2022-06-06
19 */
20 @Entity
21 @Data
22 @EntityListeners(AuditingEntityListener.class)
23 @Accessors(chain = true)
24 @Table(name="uc_wechat_share_record")
25 public class WechatShareRecord implements Serializable {
26
27 // ID
28 @Id
29 @GeneratedValue(strategy = GenerationType.IDENTITY)
30 @Column(name = "id")
31 private Long id;
32
33 // 标识
34 @Column(name = "code", nullable = false)
35 private String code;
36
37 // 微信账号id
38 @Column(name = "user_id")
39 private Long userId;
40
41 // 会员id
42 @Column(name = "member_id", nullable = false)
43 private Long memberId;
44
45 // 会员code
46 @Column(name = "member_code", nullable = false)
47 private String memberCode;
48
49 // 实例id
50 @Column(name = "entity_id")
51 private Long entityId;
52
53 // 实例code
54 @Column(name = "entity_code")
55 private String entityCode;
56
57 // 实例类型 1:营销活动;2:小程序;3:商品;4:投票对象;5:文章;6:视频;99:其他;
58 @Column(name = "entity_type")
59 private Long entityType;
60
61 // 分享对象 1:朋友;2:朋友圈;99:其他;
62 @Column(name = "share_type")
63 private Integer shareType;
64
65 // 分享对象昵称
66 @Column(name = "share_to")
67 private String shareTo;
68
69 // 分享对象查看次数
70 @Column(name = "click_count")
71 private Long clickCount;
72
73 // 分享对象查看次数
74 @Column(name = "share_count")
75 private Long shareCount;
76
77 // 来源描述
78 @Column(name = "source_info")
79 private String sourceInfo;
80
81 // 创建时间
82 @CreatedDate
83 @Column(name = "create_time")
84 private Timestamp createTime;
85
86 // 更新时间
87 @LastModifiedDate
88 @Column(name = "update_time")
89 private Timestamp updateTime;
90
91 public void copy(WechatShareRecord source){
92 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
93 }
94 }
1 package com.topdraw.business.module.user.weixin.wechatshare.repository;
2
3 import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6 import org.springframework.data.jpa.repository.Modifying;
7 import org.springframework.data.jpa.repository.Query;
8
9 import java.util.Optional;
10
11 /**
12 * @author XiangHan
13 * @date 2022-06-06
14 */
15 public interface WechatShareRecordRepository extends JpaRepository<WechatShareRecord, Long>, JpaSpecificationExecutor<WechatShareRecord> {
16
17 Optional<WechatShareRecord> findFirstByCode(String code);
18
19 Optional<WechatShareRecord> findFirstByMemberCodeAndEntityCode(String memberCode, String entityCode);
20
21 @Modifying
22 @Query(value = "UPDATE uc_wechat_share_record SET `share_count` = ?2 WHERE id = ?1", nativeQuery = true)
23 void updateShareCount(Long id, long l);
24 }
1 package com.topdraw.business.module.user.weixin.wechatshare.rest;
2
3 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.common.ResultInfo;
5 import com.topdraw.annotation.Log;
6 import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
7 import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService;
8 import lombok.extern.slf4j.Slf4j;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.validation.annotation.Validated;
11 import org.springframework.web.bind.annotation.*;
12 import io.swagger.annotations.*;
13
14 /**
15 * @author XiangHan
16 * @date 2022-06-06
17 */
18 @Api(tags = "WechatShareRecord管理")
19 @RestController
20 @RequestMapping("/uce/wechatShareRecord/")
21 @Slf4j
22 public class WechatShareRecordController {
23
24 @Autowired
25 private WechatShareRecordService wechatShareRecordService;
26
27 @Log
28 @PostMapping(value = "/create")
29 @ApiOperation("新增WechatShareRecord")
30 public ResultInfo create(@Validated @RequestBody WechatShareRecord resources) {
31 this.wechatShareRecordService.create(resources);
32 return ResultInfo.success();
33 }
34
35 @Log
36 @PostMapping(value = "/update")
37 @ApiOperation("修改WechatShareRecord")
38 public ResultInfo update(@Validated @RequestBody WechatShareRecord resources) {
39 this.wechatShareRecordService.update(resources);
40 return ResultInfo.success();
41 }
42
43 @Log
44 @PostMapping(value = "/createOrUpdate")
45 @ApiOperation("修改WechatShareRecord")
46 public ResultInfo createOrUpdate(@Validated @RequestBody String content) {
47 log.info("wechatShareRecord ==>> createOrUpdate ==>> {}",content);
48 WechatShareRecord wechatShareRecord = JSONObject.parseObject(content, WechatShareRecord.class);
49 this.wechatShareRecordService.createOrUpdate(wechatShareRecord);
50 return ResultInfo.success();
51 }
52
53 @GetMapping(value = "/getByCode")
54 @ApiOperation(value = "根据标识查询")
55 public ResultInfo getByCode(@RequestParam(value = "code") String code) {
56 return ResultInfo.success(this.wechatShareRecordService.getByCode(code));
57 }
58 }
1 package com.topdraw.business.module.user.weixin.wechatshare.service;
2
3 import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
4 import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
5
6 /**
7 * @author XiangHan
8 * @date 2022-06-06
9 */
10 public interface WechatShareRecordService {
11
12 /**
13 * 根据ID查询
14 * @param id ID
15 * @return WechatShareRecordDTO
16 */
17 WechatShareRecordDTO findById(Long id);
18
19 /**
20 *
21 * @param resources
22 */
23 void create(WechatShareRecord resources);
24
25 /**
26 *
27 * @param resources
28 */
29 void update(WechatShareRecord resources);
30
31 /**
32 * Code校验
33 * @param code
34 * @return WechatShareRecordDTO
35 */
36 WechatShareRecordDTO getByCode(String code);
37
38 void createOrUpdate(WechatShareRecord resources);
39 }
1 package com.topdraw.business.module.user.weixin.wechatshare.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-06-06
11 */
12 @Data
13 public class WechatShareRecordDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 标识
19 private String code;
20
21 // 微信账号id
22 private Long userId;
23
24 // 会员id
25 private Long memberId;
26
27 // 会员code
28 private String memberCode;
29
30 // 实例id
31 private Long entityId;
32
33 // 实例code
34 private String entityCode;
35
36 // 实例类型 1:营销活动;2:小程序;3:商品;4:投票对象;5:文章;6:视频;99:其他;
37 private Long entityType;
38
39 // 分享对象 1:朋友;2:朋友圈;99:其他;
40 private Integer shareType;
41
42 // 分享对象昵称
43 private String shareTo;
44
45 // 分享对象查看次数
46 private Long clickCount;
47
48 // 分享次数
49 private Long shareCount;
50
51 // 来源描述
52 private String sourceInfo;
53
54 // 创建时间
55 private Timestamp createTime;
56
57 // 更新时间
58 private Timestamp updateTime;
59 }
1 package com.topdraw.business.module.user.weixin.wechatshare.service.impl;
2
3 import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
4 import com.topdraw.util.IdWorker;
5 import com.topdraw.utils.ValidationUtil;
6 import com.topdraw.business.module.user.weixin.wechatshare.repository.WechatShareRecordRepository;
7 import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService;
8 import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
9 import com.topdraw.business.module.user.weixin.wechatshare.service.mapper.WechatShareRecordMapper;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Service;
12 import org.springframework.transaction.annotation.Propagation;
13 import org.springframework.transaction.annotation.Transactional;
14 import com.topdraw.utils.StringUtils;
15
16 import java.util.*;
17
18 /**
19 * @author XiangHan
20 * @date 2022-06-06
21 */
22 @Service
23 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
24 public class WechatShareRecordServiceImpl implements WechatShareRecordService {
25
26 @Autowired
27 private WechatShareRecordRepository wechatShareRecordRepository;
28
29 @Autowired
30 private WechatShareRecordMapper wechatShareRecordMapper;
31
32 @Override
33 public WechatShareRecordDTO findById(Long id) {
34 WechatShareRecord wechatShareRecord = this.wechatShareRecordRepository.findById(id).orElseGet(WechatShareRecord::new);
35 ValidationUtil.isNull(wechatShareRecord.getId(),"WechatShareRecord","id",id);
36 return this.wechatShareRecordMapper.toDto(wechatShareRecord);
37 }
38
39 @Override
40 @Transactional(rollbackFor = Exception.class)
41 public void create(WechatShareRecord resources) {
42 this.wechatShareRecordRepository.save(resources);
43 }
44
45 @Override
46 @Transactional(rollbackFor = Exception.class)
47 public void update(WechatShareRecord resources) {
48 WechatShareRecord wechatShareRecord = this.wechatShareRecordRepository.findById(resources.getId()).orElseGet(WechatShareRecord::new);
49 ValidationUtil.isNull( wechatShareRecord.getId(),"WechatShareRecord","id",resources.getId());
50 wechatShareRecord.copy(resources);
51 this.wechatShareRecordRepository.save(wechatShareRecord);
52 }
53
54 @Override
55 public WechatShareRecordDTO getByCode(String code) {
56 return StringUtils.isNotEmpty(code) ?
57 this.wechatShareRecordMapper.toDto(this.wechatShareRecordRepository.findFirstByCode(code).orElseGet(WechatShareRecord::new))
58 : new WechatShareRecordDTO();
59 }
60
61 @Transactional(rollbackFor = Exception.class)
62 @Override
63 public void createOrUpdate(WechatShareRecord resources) {
64 String memberCode = resources.getMemberCode();
65 Long memberId = resources.getMemberId();
66 String entityCode = resources.getEntityCode();
67 Long entityId = resources.getEntityId();
68 WechatShareRecord wechatShareRecord =
69 this.wechatShareRecordRepository.findFirstByMemberCodeAndEntityCode(memberCode, entityCode).orElseGet(WechatShareRecord::new);
70 if (Objects.isNull(wechatShareRecord.getId())) {
71 resources.setCode(IdWorker.generatorString());
72 resources.setShareCount(1L);
73 resources.setClickCount(0L);
74 this.create(resources);
75 } else {
76 Long id = wechatShareRecord.getId();
77 Long shareCount = wechatShareRecord.getShareCount();
78 if (Objects.isNull(shareCount))
79 shareCount = 0L;
80 this.wechatShareRecordRepository.updateShareCount(id, shareCount+1);
81 }
82
83 }
84 }
1 package com.topdraw.business.module.user.weixin.wechatshare.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord;
5 import com.topdraw.business.module.user.weixin.wechatshare.service.dto.WechatShareRecordDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-06-06
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface WechatShareRecordMapper extends BaseMapper<WechatShareRecordDTO, WechatShareRecord> {
15
16 }
1 package com.topdraw.business.module.vis.hainan.app.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-14
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="vis_user")
24 public class VisUser 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 = "person_id")
34 private Long personId;
35
36 // 平台
37 @Column(name = "platform")
38 private String platform;
39
40 // 平台账号
41 @Column(name = "platform_account")
42 private String platformAccount;
43
44 // 用户名
45 @Column(name = "username")
46 private String username;
47
48 // 密码
49 @Column(name = "password")
50 private String password;
51
52 // 积分
53 @Column(name = "points")
54 private Integer points;
55
56 // 昵称
57 @Column(name = "nickname")
58 private String nickname;
59
60 // 真实姓名
61 @Column(name = "realname")
62 private String realname;
63
64 // 头像
65 @Column(name = "image")
66 private String image;
67
68 // 电子邮件
69 @Column(name = "email")
70 private String email;
71
72 // 手机号
73 @Column(name = "cellphone")
74 private String cellphone;
75
76 // 0-女 1-男 2-其他
77 @Column(name = "gender")
78 private Integer gender;
79
80 // 生日
81 @Column(name = "birthday")
82 private Integer birthday;
83
84 // 登录天数(总天数)
85 @Column(name = "login_days")
86 private Integer loginDays;
87
88 // 连续天数
89 @Column(name = "continue_days")
90 private Integer continueDays;
91
92 // 活跃时间
93 @Column(name = "active_time")
94 private Timestamp activeTime;
95
96 // 标签
97 @Column(name = "tags")
98 private String tags;
99
100 // 登录类型:1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录
101 @Column(name = "login_type")
102 private Integer loginType;
103
104 // 用户绑定ID
105 @Column(name = "vis_user_id")
106 private Long visUserId;
107
108 // 微信绑定ID
109 @Column(name = "vis_user_weixin_id")
110 private Long visUserWeixinId;
111
112 // QQ绑定ID
113 @Column(name = "vis_user_qq_id")
114 private Long visUserQqId;
115
116 // 微博绑定ID
117 @Column(name = "vis_user_weibo_id")
118 private Long visUserWeiboId;
119
120 // 苹果绑定ID
121 @Column(name = "vis_user_apple_id")
122 private Long visUserAppleId;
123
124 // 状态:默认1-生效 2-失效
125 @Column(name = "status")
126 private Integer status;
127
128 // 创建时间
129 @CreatedDate
130 @Column(name = "create_time")
131 private Timestamp createTime;
132
133 // 更新时间
134 @LastModifiedDate
135 @Column(name = "update_time")
136 private Timestamp updateTime;
137
138 public void copy(VisUser source){
139 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
140 }
141 }
1 package com.topdraw.business.module.vis.hainan.app.repository;
2
3
4 import com.topdraw.business.module.vis.hainan.app.domain.VisUser;
5 import org.springframework.data.jpa.repository.JpaRepository;
6 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 public interface VisUserRepository extends JpaRepository<VisUser, Long>, JpaSpecificationExecutor<VisUser> {
13
14 }
1 package com.topdraw.business.module.vis.hainan.app.service;
2
3 import com.topdraw.business.module.vis.hainan.app.domain.VisUser;
4 import com.topdraw.business.module.vis.hainan.app.service.dto.VisUserDTO;
5
6 /**
7 * @author XiangHan
8 * @date 2022-07-14
9 */
10 public interface VisUserService {
11
12 /**
13 * 根据ID查询
14 * @param id ID
15 * @return UserDTO
16 */
17 VisUserDTO findById(Long id);
18
19 void create(VisUser resources);
20
21 void update(VisUser resources);
22
23 void delete(Long id);
24
25 }
1 package com.topdraw.business.module.vis.hainan.app.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 @Data
13 public class VisUserDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 所有者ID
19 private Long personId;
20
21 // 平台
22 private String platform;
23
24 // 平台账号
25 private String platformAccount;
26
27 // 用户名
28 private String username;
29
30 // 密码
31 private String password;
32
33 // 积分
34 private Integer points;
35
36 // 昵称
37 private String nickname;
38
39 // 真实姓名
40 private String realname;
41
42 // 头像
43 private String image;
44
45 // 电子邮件
46 private String email;
47
48 // 手机号
49 private String cellphone;
50
51 // 0-女 1-男 2-其他
52 private Integer gender;
53
54 // 生日
55 private Integer birthday;
56
57 // 登录天数(总天数)
58 private Integer loginDays;
59
60 // 连续天数
61 private Integer continueDays;
62
63 // 活跃时间
64 private Timestamp activeTime;
65
66 // 标签
67 private String tags;
68
69 // 登录类型:1-运营商隐式登录 2-手机验证登录 3-微信登录 4-QQ登录 5-微博登录 6-苹果登录
70 private Integer loginType;
71
72 // 用户绑定ID
73 private Long visUserId;
74
75 // 微信绑定ID
76 private Long visUserWeixinId;
77
78 // QQ绑定ID
79 private Long visUserQqId;
80
81 // 微博绑定ID
82 private Long visUserWeiboId;
83
84 // 苹果绑定ID
85 private Long visUserAppleId;
86
87 // 状态:默认1-生效 2-失效
88 private Integer status;
89
90 // 创建时间
91 private Timestamp createTime;
92
93 // 更新时间
94 private Timestamp updateTime;
95 }
1 package com.topdraw.business.module.vis.hainan.app.service.impl;
2
3 import com.topdraw.business.module.vis.hainan.app.domain.VisUser;
4 import com.topdraw.business.module.vis.hainan.app.repository.VisUserRepository;
5 import com.topdraw.business.module.vis.hainan.app.service.VisUserService;
6 import com.topdraw.business.module.vis.hainan.app.service.dto.VisUserDTO;
7 import com.topdraw.business.module.vis.hainan.app.service.mapper.VisUserMapper;
8 import com.topdraw.utils.ValidationUtil;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 /**
17 * @author XiangHan
18 * @date 2022-07-14
19 */
20 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
22 public class VisUserServiceImpl implements VisUserService {
23
24 @Autowired
25 private VisUserRepository visUserRepository;
26
27 @Autowired
28 private VisUserMapper visUserMapper;
29
30 @Override
31 public VisUserDTO findById(Long id) {
32 VisUser visUser = visUserRepository.findById(id).orElseGet(VisUser::new);
33 ValidationUtil.isNull(visUser.getId(),"User","id",id);
34 return visUserMapper.toDto(visUser);
35 }
36
37 @Override
38 @Transactional(rollbackFor = Exception.class)
39 public void create(VisUser resources) {
40 visUserRepository.save(resources);
41 }
42
43 @Override
44 @Transactional(rollbackFor = Exception.class)
45 public void update(VisUser resources) {
46 VisUser User = visUserRepository.findById(resources.getId()).orElseGet(VisUser::new);
47 ValidationUtil.isNull( User.getId(),"User","id",resources.getId());
48 User.copy(resources);
49 visUserRepository.save(User);
50 }
51
52 @Override
53 @Transactional(rollbackFor = Exception.class)
54 public void delete(Long id) {
55 Assert.notNull(id, "The given id must not be null!");
56 VisUser User = visUserRepository.findById(id).orElseThrow(
57 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", VisUser.class, id), 1));
58 visUserRepository.delete(User);
59 }
60
61
62 }
1 package com.topdraw.business.module.vis.hainan.app.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.vis.hainan.app.domain.VisUser;
5 import com.topdraw.business.module.vis.hainan.app.service.dto.VisUserDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface VisUserMapper extends BaseMapper<VisUserDTO, VisUser> {
15
16 }
1 package com.topdraw.business.module.vis.hainan.apple.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-14
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="vis_user_apple")
24 public class VisUserApple implements Serializable {
25
26
27 @Transient
28 private String username;
29 @Transient
30 private Integer type;
31
32 // ID
33 @Id
34 @GeneratedValue(strategy = GenerationType.IDENTITY)
35 @Column(name = "id")
36 private Long id;
37
38 // 所有者ID
39 @Column(name = "person_id")
40 private Long personId;
41
42 // 用户ID
43 @Column(name = "vis_user_id")
44 private Long visUserId;
45
46 // 苹果用户ID
47 @Column(name = "user")
48 private String user;
49
50 @Column(name = "identity_token")
51 private String identityToken;
52
53 @Column(name = "real_user_status")
54 private String realUserStatus;
55
56 @Column(name = "authorized_scopes")
57 private String authorizedScopes;
58
59 @Column(name = "authorization_code")
60 private String authorizationCode;
61
62 // 状态 0-失效 1-有效
63 @Column(name = "status")
64 private Integer status;
65
66 // 全名
67 @Column(name = "full_name")
68 private String fullName;
69
70 // E-main
71 @Column(name = "email")
72 private String email;
73
74 // 昵称
75 @Column(name = "nickname")
76 private String nickname;
77
78 // 性别
79 @Column(name = "sex")
80 private Integer sex;
81
82 // 国家
83 @Column(name = "country")
84 private String country;
85
86 // 省份
87 @Column(name = "province")
88 private String province;
89
90 // 城市
91 @Column(name = "city")
92 private String city;
93
94 // 头像地址
95 @Column(name = "icon")
96 private String icon;
97
98 // 描述
99 @Column(name = "description")
100 private String description;
101
102 // 创建时间
103 @CreatedDate
104 @Column(name = "create_time")
105 private Timestamp createTime;
106
107 // 更新时间
108 @LastModifiedDate
109 @Column(name = "update_time")
110 private Timestamp updateTime;
111
112 public void copy(VisUserApple source){
113 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
114 }
115 }
1 package com.topdraw.business.module.vis.hainan.apple.repository;
2
3 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserAppleRepository extends JpaRepository<VisUserApple, Long>, JpaSpecificationExecutor<VisUserApple> {
12
13 }
1 package com.topdraw.business.module.vis.hainan.apple.service;
2
3
4 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
5 import com.topdraw.business.module.vis.hainan.apple.service.dto.VisUserAppleDTO;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserAppleService {
12
13 /**
14 * 根据ID查询
15 * @param id ID
16 * @return VisUserAppleDTO
17 */
18 VisUserAppleDTO findById(Long id);
19
20 void create(VisUserApple resources);
21
22 void update(VisUserApple resources);
23
24 void delete(Long id);
25
26 }
1 package com.topdraw.business.module.vis.hainan.apple.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 @Data
13 public class VisUserAppleDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 所有者ID
19 private Long personId;
20
21 // 用户ID
22 private Long visUserId;
23
24 // 苹果用户ID
25 private String user;
26
27 private String identityToken;
28
29 private String realUserStatus;
30
31 private String authorizedScopes;
32
33 private String authorizationCode;
34
35 // 状态 0-失效 1-有效
36 private Integer status;
37
38 // 全名
39 private String fullName;
40
41 // E-main
42 private String email;
43
44 // 昵称
45 private String nickname;
46
47 // 性别
48 private Integer sex;
49
50 // 国家
51 private String country;
52
53 // 省份
54 private String province;
55
56 // 城市
57 private String city;
58
59 // 头像地址
60 private String icon;
61
62 // 描述
63 private String description;
64
65 // 创建时间
66 private Timestamp createTime;
67
68 // 更新时间
69 private Timestamp updateTime;
70 }
1 package com.topdraw.business.module.vis.hainan.apple.service.dto;
2
3 import lombok.Data;
4
5 /**
6 * @author XiangHan
7 * @date 2022-07-14
8 */
9 @Data
10 public class VisUserAppleQueryCriteria{
11 }
1 package com.topdraw.business.module.vis.hainan.apple.service.impl;
2
3 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
4 import com.topdraw.business.module.vis.hainan.apple.repository.VisUserAppleRepository;
5 import com.topdraw.business.module.vis.hainan.apple.service.VisUserAppleService;
6 import com.topdraw.business.module.vis.hainan.apple.service.dto.VisUserAppleDTO;
7 import com.topdraw.business.module.vis.hainan.apple.service.mapper.VisUserAppleMapper;
8 import com.topdraw.utils.ValidationUtil;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 /**
17 * @author XiangHan
18 * @date 2022-07-14
19 */
20 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
22 public class VisUserAppleServiceImpl implements VisUserAppleService {
23
24 @Autowired
25 private VisUserAppleRepository visUserAppleRepository;
26
27 @Autowired
28 private VisUserAppleMapper visUserAppleMapper;
29
30 @Override
31 public VisUserAppleDTO findById(Long id) {
32 VisUserApple visUserApple = visUserAppleRepository.findById(id).orElseGet(VisUserApple::new);
33 ValidationUtil.isNull(visUserApple.getId(),"VisUserApple","id",id);
34 return visUserAppleMapper.toDto(visUserApple);
35 }
36
37 @Override
38 @Transactional(rollbackFor = Exception.class)
39 public void create(VisUserApple resources) {
40 visUserAppleRepository.save(resources);
41 }
42
43 @Override
44 @Transactional(rollbackFor = Exception.class)
45 public void update(VisUserApple resources) {
46 VisUserApple visUserApple = visUserAppleRepository.findById(resources.getId()).orElseGet(VisUserApple::new);
47 ValidationUtil.isNull( visUserApple.getId(),"VisUserApple","id",resources.getId());
48 visUserApple.copy(resources);
49 visUserAppleRepository.save(visUserApple);
50 }
51
52 @Override
53 @Transactional(rollbackFor = Exception.class)
54 public void delete(Long id) {
55 Assert.notNull(id, "The given id must not be null!");
56 VisUserApple visUserApple = visUserAppleRepository.findById(id).orElseThrow(
57 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", VisUserApple.class, id), 1));
58 visUserAppleRepository.delete(visUserApple);
59 }
60
61
62 }
1 package com.topdraw.business.module.vis.hainan.apple.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.vis.hainan.apple.domain.VisUserApple;
5 import com.topdraw.business.module.vis.hainan.apple.service.dto.VisUserAppleDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface VisUserAppleMapper extends BaseMapper<VisUserAppleDTO, VisUserApple> {
15
16 }
1 package com.topdraw.business.module.vis.hainan.qq.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-14
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="vis_user_qq")
24 public class VisUserQq implements Serializable {
25 @Transient
26 private String username;
27 @Transient
28 private Integer type;
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 // 用户ID
40 @Column(name = "vis_user_id")
41 private Long visUserId;
42
43 // QQunionid,针对开发者
44 @Column(name = "unionid")
45 private String unionid;
46
47 // QQappid
48 @Column(name = "app_id")
49 private String appId;
50
51 // QQopenid
52 @Column(name = "openid")
53 private String openid;
54
55 // QQuserid
56 @Column(name = "user_id")
57 private String userId;
58
59 // 状态 0-失效 1-有效
60 @Column(name = "status")
61 private Integer status;
62
63 // 昵称
64 @Column(name = "nickname")
65 private String nickname;
66
67 // 性别
68 @Column(name = "sex")
69 private Integer sex;
70
71 // 国家
72 @Column(name = "country")
73 private String country;
74
75 // 省份
76 @Column(name = "province")
77 private String province;
78
79 // 城市
80 @Column(name = "city")
81 private String city;
82
83 // 头像地址
84 @Column(name = "icon")
85 private String icon;
86
87 @Column(name = "pay_token")
88 private String payToken;
89
90 @Column(name = "secretType")
91 private String secretType;
92
93 @Column(name = "secret")
94 private String secret;
95
96 @Column(name = "pfkey")
97 private String pfkey;
98
99 @Column(name = "pf")
100 private String pf;
101
102 // access_token
103 @Column(name = "access_token")
104 private String accessToken;
105
106 // expires_in
107 @Column(name = "expires_in")
108 private Integer expiresIn;
109
110 // expires_time
111 @Column(name = "expires_time")
112 private Timestamp expiresTime;
113
114 // 描述
115 @Column(name = "description")
116 private String description;
117
118 // 创建时间
119 @CreatedDate
120 @Column(name = "create_time")
121 private Timestamp createTime;
122
123 // 更新时间
124 @LastModifiedDate
125 @Column(name = "update_time")
126 private Timestamp updateTime;
127
128 public void copy(VisUserQq source){
129 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
130 }
131 }
1 package com.topdraw.business.module.vis.hainan.qq.repository;
2
3 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserQqRepository extends JpaRepository<VisUserQq, Long>, JpaSpecificationExecutor<VisUserQq> {
12
13 }
1 package com.topdraw.business.module.vis.hainan.qq.service;
2
3
4 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
5 import com.topdraw.business.module.vis.hainan.qq.service.dto.VisUserQqDTO;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserQqService {
12
13 /**
14 * 根据ID查询
15 * @param id ID
16 * @return VisUserQqDTO
17 */
18 VisUserQqDTO findById(Long id);
19
20 void create(VisUserQq resources);
21
22 void update(VisUserQq resources);
23
24 void delete(Long id);
25
26 VisUserQqDTO findByOpenid(String account);
27 }
1 package com.topdraw.business.module.vis.hainan.qq.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 @Data
13 public class VisUserQqDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 所有者ID
19 private Long personId;
20
21 // 用户ID
22 private Long visUserId;
23
24 // QQunionid,针对开发者
25 private String unionid;
26
27 // QQappid
28 private String appId;
29
30 // QQopenid
31 private String openid;
32
33 // QQuserid
34 private String userId;
35
36 // 状态 0-失效 1-有效
37 private Integer status;
38
39 // 昵称
40 private String nickname;
41
42 // 性别
43 private Integer sex;
44
45 // 国家
46 private String country;
47
48 // 省份
49 private String province;
50
51 // 城市
52 private String city;
53
54 // 头像地址
55 private String icon;
56
57 private String payToken;
58
59 private String secretType;
60
61 private String secret;
62
63 private String pfkey;
64
65 private String pf;
66
67 // access_token
68 private String accessToken;
69
70 // expires_in
71 private Integer expiresIn;
72
73 // expires_time
74 private Timestamp expiresTime;
75
76 // 描述
77 private String description;
78
79 // 创建时间
80 private Timestamp createTime;
81
82 // 更新时间
83 private Timestamp updateTime;
84 }
1 package com.topdraw.business.module.vis.hainan.qq.service.impl;
2
3 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
4 import com.topdraw.business.module.vis.hainan.qq.repository.VisUserQqRepository;
5 import com.topdraw.business.module.vis.hainan.qq.service.VisUserQqService;
6 import com.topdraw.business.module.vis.hainan.qq.service.dto.VisUserQqDTO;
7 import com.topdraw.business.module.vis.hainan.qq.service.mapper.VisUserQqMapper;
8 import com.topdraw.utils.ValidationUtil;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 /**
17 * @author XiangHan
18 * @date 2022-07-14
19 */
20 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
22 public class VisUserQqServiceImpl implements VisUserQqService {
23
24 @Autowired
25 private VisUserQqRepository visUserQqRepository;
26
27 @Autowired
28 private VisUserQqMapper visUserQqMapper;
29
30 @Override
31 public VisUserQqDTO findById(Long id) {
32 VisUserQq visUserQq = visUserQqRepository.findById(id).orElseGet(VisUserQq::new);
33 ValidationUtil.isNull(visUserQq.getId(),"VisUserQq","id",id);
34 return visUserQqMapper.toDto(visUserQq);
35 }
36
37 @Override
38 @Transactional(rollbackFor = Exception.class)
39 public void create(VisUserQq resources) {
40 visUserQqRepository.save(resources);
41 }
42
43 @Override
44 @Transactional(rollbackFor = Exception.class)
45 public void update(VisUserQq resources) {
46 VisUserQq visUserQq = visUserQqRepository.findById(resources.getId()).orElseGet(VisUserQq::new);
47 ValidationUtil.isNull( visUserQq.getId(),"VisUserQq","id",resources.getId());
48 visUserQq.copy(resources);
49 visUserQqRepository.save(visUserQq);
50 }
51
52 @Override
53 @Transactional(rollbackFor = Exception.class)
54 public void delete(Long id) {
55 Assert.notNull(id, "The given id must not be null!");
56 VisUserQq visUserQq = visUserQqRepository.findById(id).orElseThrow(
57 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", VisUserQq.class, id), 1));
58 visUserQqRepository.delete(visUserQq);
59 }
60
61 @Override
62 public VisUserQqDTO findByOpenid(String account) {
63 return null;
64 }
65
66
67 }
1 package com.topdraw.business.module.vis.hainan.qq.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq;
5 import com.topdraw.business.module.vis.hainan.qq.service.dto.VisUserQqDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface VisUserQqMapper extends BaseMapper<VisUserQqDTO, VisUserQq> {
15
16 }
1 package com.topdraw.business.module.vis.hainan.weibo.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-14
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="vis_user_weibo")
24 public class VisUserWeibo implements Serializable {
25 @Transient
26 private String username;
27 @Transient
28 private Integer type;
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 // 用户ID
40 @Column(name = "vis_user_id")
41 private Long visUserId;
42
43 // 微博appid
44 @Column(name = "app_id")
45 private String appId;
46
47 // 微博用户ID
48 @Column(name = "user_id")
49 private String userId;
50
51 // 状态 0-失效 1-有效
52 @Column(name = "status")
53 private Integer status;
54
55 // 昵称
56 @Column(name = "nickname")
57 private String nickname;
58
59 // 性别
60 @Column(name = "sex")
61 private Integer sex;
62
63 // 国家
64 @Column(name = "country")
65 private String country;
66
67 // 省份
68 @Column(name = "province")
69 private String province;
70
71 // 城市
72 @Column(name = "city")
73 private String city;
74
75 // 头像地址
76 @Column(name = "icon")
77 private String icon;
78
79 // secretType
80 @Column(name = "secretType")
81 private String secretType;
82
83 // secret
84 @Column(name = "secret")
85 private String secret;
86
87 // snsregat
88 @Column(name = "snsregat")
89 private String snsregat;
90
91 // snsUserUrl
92 @Column(name = "snsUserUrl")
93 private String snsUserUrl;
94
95 // shareCount
96 @Column(name = "shareCount")
97 private String shareCount;
98
99 // followerCount
100 @Column(name = "followerCount")
101 private String followerCount;
102
103 // refresh_token
104 @Column(name = "refresh_token")
105 private String refreshToken;
106
107 // access_token
108 @Column(name = "access_token")
109 private String accessToken;
110
111 // expires_in
112 @Column(name = "expires_in")
113 private Long expiresIn;
114
115 // expires_time
116 @Column(name = "expires_time")
117 private Timestamp expiresTime;
118
119 // 描述
120 @Column(name = "description")
121 private String description;
122
123 // 创建时间
124 @CreatedDate
125 @Column(name = "create_time")
126 private Timestamp createTime;
127
128 // 更新时间
129 @LastModifiedDate
130 @Column(name = "update_time")
131 private Timestamp updateTime;
132
133 public void copy(VisUserWeibo source){
134 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
135 }
136 }
1 package com.topdraw.business.module.vis.hainan.weibo.repository;
2
3 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserWeiboRepository extends JpaRepository<VisUserWeibo, Long>, JpaSpecificationExecutor<VisUserWeibo> {
12
13 }
1 package com.topdraw.business.module.vis.hainan.weibo.service;
2
3
4 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
5 import com.topdraw.business.module.vis.hainan.weibo.service.dto.VisUserWeiboDTO;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserWeiboService {
12
13 /**
14 * 根据ID查询
15 * @param id ID
16 * @return VisUserWeiboDTO
17 */
18 VisUserWeiboDTO findById(Long id);
19
20 void create(VisUserWeibo resources);
21
22 void update(VisUserWeibo resources);
23
24 void delete(Long id);
25
26 VisUserWeiboDTO findByUserid(String account);
27 }
1 package com.topdraw.business.module.vis.hainan.weibo.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 @Data
13 public class VisUserWeiboDTO implements Serializable {
14
15 // ID
16 private Long id;
17
18 // 所有者ID
19 private Long personId;
20
21 // 用户ID
22 private Long visUserId;
23
24 // 微博appid
25 private String appId;
26
27 // 微博用户ID
28 private String userId;
29
30 // 状态 0-失效 1-有效
31 private Integer status;
32
33 // 昵称
34 private String nickname;
35
36 // 性别
37 private Integer sex;
38
39 // 国家
40 private String country;
41
42 // 省份
43 private String province;
44
45 // 城市
46 private String city;
47
48 // 头像地址
49 private String icon;
50
51 // secretType
52 private String secretType;
53
54 // secret
55 private String secret;
56
57 // snsregat
58 private String snsregat;
59
60 // snsUserUrl
61 private String snsUserUrl;
62
63 // shareCount
64 private String shareCount;
65
66 // followerCount
67 private String followerCount;
68
69 // refresh_token
70 private String refreshToken;
71
72 // access_token
73 private String accessToken;
74
75 // expires_in
76 private Long expiresIn;
77
78 // expires_time
79 private Timestamp expiresTime;
80
81 // 描述
82 private String description;
83
84 // 创建时间
85 private Timestamp createTime;
86
87 // 更新时间
88 private Timestamp updateTime;
89 }
1 package com.topdraw.business.module.vis.hainan.weibo.service.impl;
2
3 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
4 import com.topdraw.business.module.vis.hainan.weibo.repository.VisUserWeiboRepository;
5 import com.topdraw.business.module.vis.hainan.weibo.service.VisUserWeiboService;
6 import com.topdraw.business.module.vis.hainan.weibo.service.dto.VisUserWeiboDTO;
7 import com.topdraw.business.module.vis.hainan.weibo.service.mapper.VisUserWeiboMapper;
8 import com.topdraw.utils.ValidationUtil;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 /**
17 * @author XiangHan
18 * @date 2022-07-14
19 */
20 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
22 public class VisUserWeiboServiceImpl implements VisUserWeiboService {
23
24 @Autowired
25 private VisUserWeiboRepository visUserWeiboRepository;
26
27 @Autowired
28 private VisUserWeiboMapper visUserWeiboMapper;
29
30 @Override
31 public VisUserWeiboDTO findById(Long id) {
32 VisUserWeibo visUserWeibo = visUserWeiboRepository.findById(id).orElseGet(VisUserWeibo::new);
33 ValidationUtil.isNull(visUserWeibo.getId(),"VisUserWeibo","id",id);
34 return visUserWeiboMapper.toDto(visUserWeibo);
35 }
36
37 @Override
38 @Transactional(rollbackFor = Exception.class)
39 public void create(VisUserWeibo resources) {
40 visUserWeiboRepository.save(resources);
41 }
42
43 @Override
44 @Transactional(rollbackFor = Exception.class)
45 public void update(VisUserWeibo resources) {
46 VisUserWeibo visUserWeibo = visUserWeiboRepository.findById(resources.getId()).orElseGet(VisUserWeibo::new);
47 ValidationUtil.isNull( visUserWeibo.getId(),"VisUserWeibo","id",resources.getId());
48 visUserWeibo.copy(resources);
49 visUserWeiboRepository.save(visUserWeibo);
50 }
51
52 @Override
53 @Transactional(rollbackFor = Exception.class)
54 public void delete(Long id) {
55 Assert.notNull(id, "The given id must not be null!");
56 VisUserWeibo visUserWeibo = visUserWeiboRepository.findById(id).orElseThrow(
57 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", VisUserWeibo.class, id), 1));
58 visUserWeiboRepository.delete(visUserWeibo);
59 }
60
61 @Override
62 public VisUserWeiboDTO findByUserid(String account) {
63 return null;
64 }
65
66
67 }
1 package com.topdraw.business.module.vis.hainan.weibo.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo;
5 import com.topdraw.business.module.vis.hainan.weibo.service.dto.VisUserWeiboDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface VisUserWeiboMapper extends BaseMapper<VisUserWeiboDTO, VisUserWeibo> {
15
16 }
1 package com.topdraw.business.module.vis.hainan.weixin.domain;
2
3 import lombok.Data;
4 import lombok.experimental.Accessors;
5 import cn.hutool.core.bean.BeanUtil;
6 import cn.hutool.core.bean.copier.CopyOptions;
7 import javax.persistence.*;
8 import org.springframework.data.annotation.CreatedDate;
9 import org.springframework.data.annotation.LastModifiedDate;
10 import org.springframework.data.jpa.domain.support.AuditingEntityListener;
11 import java.sql.Timestamp;
12
13 import java.io.Serializable;
14
15 /**
16 * @author XiangHan
17 * @date 2022-07-14
18 */
19 @Entity
20 @Data
21 @EntityListeners(AuditingEntityListener.class)
22 @Accessors(chain = true)
23 @Table(name="vis_user_weixin")
24 public class VisUserWeixin implements Serializable {
25
26
27 @Transient
28 private String username;
29 @Transient
30 private Integer type;
31
32 // ID
33 @Id
34 @GeneratedValue(strategy = GenerationType.IDENTITY)
35 @Column(name = "id")
36 private Long id;
37
38 // 所有者ID
39 @Column(name = "person_id")
40 private Long personId;
41
42 // 用户ID
43 @Column(name = "vis_user_id")
44 private Long visUserId;
45
46 // 微信unionid,针对开发者
47 @Column(name = "unionid")
48 private String unionid;
49
50 // 微信appid
51 @Column(name = "appid")
52 private String appid;
53
54 // 微信appid
55 @Column(name = "app_id")
56 private String appId;
57
58 // 微信openid,针对微信app
59 @Column(name = "openid")
60 private String openid;
61
62 // 状态 0-失效 1-有效
63 @Column(name = "status")
64 private Integer status;
65
66 // 昵称
67 @Column(name = "nickname")
68 private String nickname;
69
70 // 性别
71 @Column(name = "sex")
72 private Integer sex;
73
74 // 国家
75 @Column(name = "country")
76 private String country;
77
78 // 省份
79 @Column(name = "province")
80 private String province;
81
82 // 城市
83 @Column(name = "city")
84 private String city;
85
86 // 头像地址
87 @Column(name = "headimgurl")
88 private String headimgurl;
89
90 // 特权信息
91 @Column(name = "privilege")
92 private String privilege;
93
94 // refresh_token
95 @Column(name = "refresh_token")
96 private String refreshToken;
97
98 // access_token
99 @Column(name = "access_token")
100 private String accessToken;
101
102 // expires_in
103 @Column(name = "expires_in")
104 private Integer expiresIn;
105
106 // expires_time
107 @Column(name = "expires_time")
108 private Timestamp expiresTime;
109
110 // 描述
111 @Column(name = "description")
112 private String description;
113
114 // 创建时间
115 @CreatedDate
116 @Column(name = "create_time")
117 private Timestamp createTime;
118
119 // 更新时间
120 @LastModifiedDate
121 @Column(name = "update_time")
122 private Timestamp updateTime;
123
124 public void copy(VisUserWeixin source){
125 BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
126 }
127 }
1 package com.topdraw.business.module.vis.hainan.weixin.repository;
2
3 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
4 import org.springframework.data.jpa.repository.JpaRepository;
5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6
7 import java.util.Optional;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 public interface VisUserWeixinRepository extends JpaRepository<VisUserWeixin, Long>, JpaSpecificationExecutor<VisUserWeixin> {
14
15
16 Optional<VisUserWeixin> findByOpenid(String account);
17 }
1 package com.topdraw.business.module.vis.hainan.weixin.service;
2
3
4 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
5 import com.topdraw.business.module.vis.hainan.weixin.service.dto.VisUserWeixinDTO;
6
7 /**
8 * @author XiangHan
9 * @date 2022-07-14
10 */
11 public interface VisUserWeixinService {
12
13 /**
14 * 根据ID查询
15 * @param id ID
16 * @return VisUserWeixinDTO
17 */
18 VisUserWeixinDTO findById(Long id);
19
20 void create(VisUserWeixin resources);
21
22 void update(VisUserWeixin resources);
23
24 void delete(Long id);
25
26 VisUserWeixinDTO findByOpenid(String account);
27 }
1 package com.topdraw.business.module.vis.hainan.weixin.service.dto;
2
3 import lombok.Data;
4 import java.sql.Timestamp;
5 import java.io.Serializable;
6
7
8 /**
9 * @author XiangHan
10 * @date 2022-07-14
11 */
12 @Data
13 public class VisUserWeixinDTO implements Serializable {
14
15
16 // ID
17 private Long id;
18
19 // 所有者ID
20 private Long personId;
21
22 // 用户ID
23 private Long visUserId;
24
25 // 微信unionid,针对开发者
26 private String unionid;
27
28 // 微信appid
29 private String appid;
30
31 // 微信appid
32 private String appId;
33
34 // 微信openid,针对微信app
35 private String openid;
36
37 // 状态 0-失效 1-有效
38 private Integer status;
39
40 // 昵称
41 private String nickname;
42
43 // 性别
44 private Integer sex;
45
46 // 国家
47 private String country;
48
49 // 省份
50 private String province;
51
52 // 城市
53 private String city;
54
55 // 头像地址
56 private String headimgurl;
57
58 // 特权信息
59 private String privilege;
60
61 // refresh_token
62 private String refreshToken;
63
64 // access_token
65 private String accessToken;
66
67 // expires_in
68 private Integer expiresIn;
69
70 // expires_time
71 private Timestamp expiresTime;
72
73 // 描述
74 private String description;
75
76 // 创建时间
77 private Timestamp createTime;
78
79 // 更新时间
80 private Timestamp updateTime;
81 }
1 package com.topdraw.business.module.vis.hainan.weixin.service.impl;
2
3 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
4 import com.topdraw.business.module.vis.hainan.weixin.repository.VisUserWeixinRepository;
5 import com.topdraw.business.module.vis.hainan.weixin.service.VisUserWeixinService;
6 import com.topdraw.business.module.vis.hainan.weixin.service.dto.VisUserWeixinDTO;
7 import com.topdraw.business.module.vis.hainan.weixin.service.mapper.VisUserWeixinMapper;
8 import com.topdraw.utils.ValidationUtil;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Propagation;
12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.dao.EmptyResultDataAccessException;
14 import org.springframework.util.Assert;
15
16 /**
17 * @author XiangHan
18 * @date 2022-07-14
19 */
20 @Service
21 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
22 public class VisUserWeixinServiceImpl implements VisUserWeixinService {
23
24 @Autowired
25 private VisUserWeixinRepository visUserWeixinRepository;
26
27 @Autowired
28 private VisUserWeixinMapper visUserWeixinMapper;
29
30 @Override
31 public VisUserWeixinDTO findById(Long id) {
32 VisUserWeixin visUserWeixin = visUserWeixinRepository.findById(id).orElseGet(VisUserWeixin::new);
33 ValidationUtil.isNull(visUserWeixin.getId(),"VisUserWeixin","id",id);
34 return visUserWeixinMapper.toDto(visUserWeixin);
35 }
36
37 @Override
38 @Transactional(rollbackFor = Exception.class)
39 public void create(VisUserWeixin resources) {
40 visUserWeixinRepository.save(resources);
41 }
42
43 @Override
44 @Transactional(rollbackFor = Exception.class)
45 public void update(VisUserWeixin resources) {
46 VisUserWeixin visUserWeixin = visUserWeixinRepository.findById(resources.getId()).orElseGet(VisUserWeixin::new);
47 ValidationUtil.isNull( visUserWeixin.getId(),"VisUserWeixin","id",resources.getId());
48 visUserWeixin.copy(resources);
49 visUserWeixinRepository.save(visUserWeixin);
50 }
51
52 @Override
53 @Transactional(rollbackFor = Exception.class)
54 public void delete(Long id) {
55 Assert.notNull(id, "The given id must not be null!");
56 VisUserWeixin visUserWeixin = visUserWeixinRepository.findById(id).orElseThrow(
57 () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", VisUserWeixin.class, id), 1));
58 visUserWeixinRepository.delete(visUserWeixin);
59 }
60
61 @Override
62 public VisUserWeixinDTO findByOpenid(String account) {
63 VisUserWeixin visUserWeixin = visUserWeixinRepository.findByOpenid(account).orElseGet(VisUserWeixin::new);
64 return visUserWeixinMapper.toDto(visUserWeixin);
65 }
66
67
68 }
1 package com.topdraw.business.module.vis.hainan.weixin.service.mapper;
2
3 import com.topdraw.base.BaseMapper;
4 import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin;
5 import com.topdraw.business.module.vis.hainan.weixin.service.dto.VisUserWeixinDTO;
6 import org.mapstruct.Mapper;
7 import org.mapstruct.ReportingPolicy;
8
9 /**
10 * @author XiangHan
11 * @date 2022-07-14
12 */
13 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
14 public interface VisUserWeixinMapper extends BaseMapper<VisUserWeixinDTO, VisUserWeixin> {
15
16 }
...@@ -29,4 +29,7 @@ public class TempPoints extends TempRights { ...@@ -29,4 +29,7 @@ public class TempPoints extends TempRights {
29 @Transient 29 @Transient
30 protected Long rewardPointsExpireTime; 30 protected Long rewardPointsExpireTime;
31 31
32 @Transient
33 protected String description;
34
32 } 35 }
......
...@@ -35,6 +35,9 @@ public class TempRights { ...@@ -35,6 +35,9 @@ public class TempRights {
35 @Transient 35 @Transient
36 protected String memberCode; 36 protected String memberCode;
37 37
38 @Transient
39 protected Integer memberLevel;
40
38 /** 账号id */ 41 /** 账号id */
39 @Transient 42 @Transient
40 protected Long userId; 43 protected Long userId;
......
...@@ -7,26 +7,23 @@ import lombok.Data; ...@@ -7,26 +7,23 @@ import lombok.Data;
7 @Data 7 @Data
8 public class SubscribeBean extends WeiXinUserBean { 8 public class SubscribeBean extends WeiXinUserBean {
9 9
10 private JSONObject userInfoJson; 10 /**
11 11 * 大屏账号信息
12 */
12 private JSONObject iptvUserInfo; 13 private JSONObject iptvUserInfo;
13 14
14 private String msgType; 15 /**
15 16 * 昵称
16 private String event; 17 */
17
18
19 /** */
20 private String openId;
21
22 /** */
23 private String appId;
24
25 /** */
26 private String eventKey;
27
28 private String nickname; 18 private String nickname;
19
20 /**
21 * 头像
22 */
29 private String headimgurl; 23 private String headimgurl;
30 24
31 private String sourceInfo; 25 /**
26 * 来源描述
27 */
28 private JSONObject sourceInfo;
32 } 29 }
......
1 package com.topdraw.business.process.domian.weixin;
2
3 /**
4 * @author :
5 * @description:
6 * @function :
7 * @date :Created in 2022/7/4 16:36
8 * @version: :
9 * @modified By:
10 * @since : modified in 2022/7/4 16:36
11 */
12 public interface SubscribeSourceTypeConstant {
13
14 int type1 = 1;
15 int type2 = 2;
16
17 }
...@@ -5,6 +5,7 @@ import com.topdraw.business.process.service.ExpOperationService; ...@@ -5,6 +5,7 @@ import com.topdraw.business.process.service.ExpOperationService;
5 import com.topdraw.common.ResultInfo; 5 import com.topdraw.common.ResultInfo;
6 import io.swagger.annotations.Api; 6 import io.swagger.annotations.Api;
7 import io.swagger.annotations.ApiOperation; 7 import io.swagger.annotations.ApiOperation;
8 import lombok.extern.slf4j.Slf4j;
8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.validation.annotation.Validated; 10 import org.springframework.validation.annotation.Validated;
10 import org.springframework.web.bind.annotation.PostMapping; 11 import org.springframework.web.bind.annotation.PostMapping;
...@@ -13,7 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -13,7 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RestController; 14 import org.springframework.web.bind.annotation.RestController;
14 15
15 import java.util.Arrays; 16 import java.util.Arrays;
17 import java.util.Collections;
16 import java.util.List; 18 import java.util.List;
19 import java.util.Objects;
17 20
18 /** 21 /**
19 * @author XiangHan 22 * @author XiangHan
...@@ -22,16 +25,28 @@ import java.util.List; ...@@ -22,16 +25,28 @@ import java.util.List;
22 @Api(tags = "成长值管理") 25 @Api(tags = "成长值管理")
23 @RestController 26 @RestController
24 @RequestMapping("/uce/expOperation") 27 @RequestMapping("/uce/expOperation")
28 @Slf4j
25 public class ExpOperationController { 29 public class ExpOperationController {
26 30
27 @Autowired 31 @Autowired
28 private ExpOperationService expOperationService; 32 private ExpOperationService expOperationService;
29 33
30 @PostMapping(value = "/grantExpByManual") 34 @PostMapping(value = "/addExp")
31 @ApiOperation("手动发放成长值") 35 @ApiOperation("手动发放成长值")
32 public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) { 36 public ResultInfo grantExpByManual(@Validated @RequestBody TempExp tempExp) {
33 List<TempExp> tempExpList = Arrays.asList(tempExp); 37 log.info("手动发放成长值,参数 ==>> {}", tempExp);
34 this.expOperationService.grantExpByManual(tempExpList); 38 Long memberId = tempExp.getMemberId();
39 if (Objects.isNull(memberId)) {
40 log.error("发放成长值失败,参数错误,无会员id");
41 return ResultInfo.failure("发放成长值失败,参数错误,无会员id");
42 }
43
44 Long rewardExp = tempExp.getRewardExp();
45 if (Objects.isNull(rewardExp) || rewardExp <= 0L) {
46 log.error("发放成长值失败,参数错误,成长值为空或者小于0 ==>> {}", rewardExp);
47 return ResultInfo.failure("发放成长值失败,参数错误,成长值为空或者小于0");
48 }
49 this.expOperationService.grantExpByManual(Collections.singletonList(tempExp));
35 return ResultInfo.success(); 50 return ResultInfo.success();
36 } 51 }
37 52
......
...@@ -2,24 +2,22 @@ package com.topdraw.business.process.rest; ...@@ -2,24 +2,22 @@ package com.topdraw.business.process.rest;
2 2
3 import com.topdraw.annotation.AnonymousAccess; 3 import com.topdraw.annotation.AnonymousAccess;
4 import com.topdraw.business.module.common.validated.UpdateGroup; 4 import com.topdraw.business.module.common.validated.UpdateGroup;
5 import com.topdraw.business.module.member.domain.Member; 5 import com.topdraw.business.module.member.address.domain.MemberAddress;
6 import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO;
6 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; 7 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
7 import com.topdraw.business.module.member.service.dto.MemberDTO; 8 import com.topdraw.business.module.member.service.dto.MemberDTO;
8 import com.topdraw.business.process.domian.member.MemberOperationBean; 9 import com.topdraw.business.process.domian.member.MemberOperationBean;
9 import com.topdraw.business.process.domian.weixin.BuyVipBean;
10 import com.topdraw.business.process.service.member.MemberOperationService; 10 import com.topdraw.business.process.service.member.MemberOperationService;
11 import com.topdraw.common.IResultInfo; 11 import com.topdraw.common.IResultInfo;
12 import com.topdraw.common.ResultInfo; 12 import com.topdraw.common.ResultInfo;
13 import com.topdraw.exception.BadRequestException;
14 import io.swagger.annotations.Api; 13 import io.swagger.annotations.Api;
15 import io.swagger.annotations.ApiOperation; 14 import io.swagger.annotations.ApiOperation;
16 import lombok.extern.slf4j.Slf4j; 15 import lombok.extern.slf4j.Slf4j;
17 import org.springframework.beans.BeanUtils; 16 import org.apache.commons.lang3.StringUtils;
18 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.validation.annotation.Validated; 18 import org.springframework.validation.annotation.Validated;
20 import org.springframework.web.bind.annotation.*; 19 import org.springframework.web.bind.annotation.*;
21 20
22 import java.sql.Timestamp;
23 import java.util.Objects; 21 import java.util.Objects;
24 22
25 @Api("会员处理") 23 @Api("会员处理")
...@@ -32,26 +30,31 @@ public class MemberOperationController { ...@@ -32,26 +30,31 @@ public class MemberOperationController {
32 @Autowired 30 @Autowired
33 private MemberOperationService memberOperationService; 31 private MemberOperationService memberOperationService;
34 32
33 @RequestMapping(value = "/updateDefaultMemberAddressById")
34 @ApiOperation("设置默认地址")
35 @AnonymousAccess
36 public ResultInfo updateDefaultMemberAddressById(@Validated(value = {UpdateGroup.class}) @RequestBody MemberAddress resources) {
37 log.info("设置默认地址,参数 ==>> [updateDefaultMemberAddressById#{}]",resources);
38 Long id = resources.getId();
39 if (Objects.isNull(id)) {
40 return ResultInfo.failure("设置默认地址失败,参数错误,id为空");
41 }
42
43 MemberAddressDTO memberAddressDTO = this.memberOperationService.updateDefaultMemberAddressById(id);
44
45 return ResultInfo.success(memberAddressDTO);
46 }
47
35 @RequestMapping(value = "/updateVipByMemberId") 48 @RequestMapping(value = "/updateVipByMemberId")
36 @ApiOperation("手动修改vip") 49 @ApiOperation("手动修改vip")
37 @AnonymousAccess 50 @AnonymousAccess
38 public ResultInfo updateVipByMemberId(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) { 51 public ResultInfo updateVipByMemberId(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) {
39 log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources); 52 log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources);
40 Integer vip = resources.getVip();
41 Timestamp vipExpireTime = resources.getVipExpireTime();
42 Long memberId = resources.getMemberId(); 53 Long memberId = resources.getMemberId();
43 MemberDTO memberDTO = this.memberOperationService.findById(memberId); 54 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
55 resources.setMemberCode(memberDTO.getCode());
44 56
45 Member member = new Member(); 57 return this.updateVipByMemberCode(resources);
46 BeanUtils.copyProperties(memberDTO, member);
47 if (Objects.nonNull(vip)) {
48 member.setVip(vip);
49 }
50 if (Objects.nonNull(vipExpireTime)) {
51 member.setVipExpireTime(vipExpireTime);
52 }
53 this.memberOperationService.update(member);
54 return ResultInfo.success();
55 } 58 }
56 59
57 @RequestMapping(value = "/updateVipByMemberCode") 60 @RequestMapping(value = "/updateVipByMemberCode")
...@@ -59,65 +62,31 @@ public class MemberOperationController { ...@@ -59,65 +62,31 @@ public class MemberOperationController {
59 @AnonymousAccess 62 @AnonymousAccess
60 public ResultInfo updateVipByMemberCode(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) { 63 public ResultInfo updateVipByMemberCode(@Validated(value = {UpdateGroup.class}) @RequestBody MemberOperationBean resources) {
61 log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources); 64 log.info("member ==>> doUpdateVipByCode ==>> param ==>> [{}]",resources);
62 Integer vip = resources.getVip();
63 Timestamp vipExpireTime = resources.getVipExpireTime();
64 String memberCode = resources.getMemberCode(); 65 String memberCode = resources.getMemberCode();
65 MemberDTO memberDTO = this.memberOperationService.findByCode(memberCode); 66 if (StringUtils.isBlank(memberCode)) {
66 67 log.error("参数错误,memberCode 不存在");
67 Member member = new Member(); 68 return ResultInfo.failure("参数错误,memberCode 不存在");
68 BeanUtils.copyProperties(memberDTO, member);
69 if (Objects.nonNull(vip)) {
70 member.setVip(vip);
71 }
72 if (Objects.nonNull(vipExpireTime)) {
73 member.setVipExpireTime(vipExpireTime);
74 } 69 }
75 70
76 this.createVipHistory(memberDTO.getId(), memberDTO.getCode(), vip, vipExpireTime); 71 Integer vip = resources.getVip();
77 72 if (Objects.isNull(vip) || vip < 0) {
78 this.memberOperationService.updateMemberVip(member); 73 log.error("参数错误,vip为空或者小于0 , vip ==>> {}", vip);
79 return ResultInfo.success(); 74 return ResultInfo.failure("参数错误,vip为空或者小于0");
80 } 75 }
81 76
82 77 MemberDTO memberDTO = this.memberOperationService.doUpdateVipByMemberCode(resources);
83 private void createVipHistory(Long memberId, String code, Integer vip , Timestamp vipExpireTime){ 78 return ResultInfo.success(memberDTO);
84 BuyVipBean buyVipBean = new BuyVipBean();
85 buyVipBean.setMemberId(memberId);
86 buyVipBean.setMemberCode(code);
87 buyVipBean.setVip(vip);
88 buyVipBean.setVipExpireTime(vipExpireTime);
89 this.memberOperationService.buyVipByMemberId(buyVipBean);
90 } 79 }
91 80
92 81
93 @GetMapping("/getMemberProfileAndCheckVip/{appId}/{memberId}") 82 @GetMapping("/getMemberProfileAndCheckVip/{appId}/{memberId}")
94 @ApiOperation("获取会员基本信息并且检查vip状态") 83 @ApiOperation("获取会员基本信息并且检查vip状态")
95 @AnonymousAccess 84 @AnonymousAccess
85 @Deprecated
96 public IResultInfo getMemberProfileAndCheckVip(@PathVariable(value = "appId") String appId, @PathVariable(value = "memberId") Long memberId) { 86 public IResultInfo getMemberProfileAndCheckVip(@PathVariable(value = "appId") String appId, @PathVariable(value = "memberId") Long memberId) {
97 MemberProfileDTO memberProfileDTO = this.memberOperationService.getMemberProfileAndCheckVip(memberId, appId); 87 MemberProfileDTO memberProfileDTO = this.memberOperationService.getMemberProfileAndCheckVip(memberId, appId);
98 return ResultInfo.success(memberProfileDTO); 88 return ResultInfo.success(memberProfileDTO);
99 } 89 }
100
101 @PutMapping("/buyVip")
102 @ApiOperation("购买vip")
103 @AnonymousAccess
104 @Deprecated
105 public ResultInfo buyVip(@RequestBody BuyVipBean buyVipBean) {
106
107 /* // 小程序账户id
108 Long id = buyVipBean.getId();
109 if (Objects.isNull(id))
110 throw new BadRequestException("参数异常: id is null !");
111
112 // vip等级
113 Integer vip = buyVipBean.getVip();
114 if (Objects.isNull(vip) || vip <= 0)
115 throw new BadRequestException("vip 等级有误");
116
117 MemberDTO memberDTO = this.memberOperationService.buyVip(buyVipBean);
118 return ResultInfo.success(memberDTO);*/
119 return null;
120 }
121 } 90 }
122 91
123 92
......
...@@ -12,7 +12,7 @@ import com.topdraw.business.process.domian.TempPoints; ...@@ -12,7 +12,7 @@ import com.topdraw.business.process.domian.TempPoints;
12 import com.topdraw.business.process.service.dto.CustomPointsResult; 12 import com.topdraw.business.process.service.dto.CustomPointsResult;
13 import com.topdraw.business.process.service.PointsOperationService; 13 import com.topdraw.business.process.service.PointsOperationService;
14 import com.topdraw.common.ResultInfo; 14 import com.topdraw.common.ResultInfo;
15 import com.topdraw.config.LocalConstants; 15 import com.topdraw.business.LocalConstants;
16 import com.topdraw.exception.BadRequestException; 16 import com.topdraw.exception.BadRequestException;
17 import com.topdraw.exception.GlobeExceptionMsg; 17 import com.topdraw.exception.GlobeExceptionMsg;
18 import io.swagger.annotations.Api; 18 import io.swagger.annotations.Api;
...@@ -49,6 +49,7 @@ public class PointsOperationController { ...@@ -49,6 +49,7 @@ public class PointsOperationController {
49 @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}") 49 @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}")
50 @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用") 50 @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用")
51 @AnonymousAccess 51 @AnonymousAccess
52 @Deprecated
52 public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) { 53 public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) {
53 Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id); 54 Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id);
54 return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong); 55 return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong);
...@@ -59,17 +60,27 @@ public class PointsOperationController { ...@@ -59,17 +60,27 @@ public class PointsOperationController {
59 @ApiOperation("手动发放积分") 60 @ApiOperation("手动发放积分")
60 @AnonymousAccess 61 @AnonymousAccess
61 public ResultInfo addPoints(@Validated @RequestBody TempPoints tempPoints) { 62 public ResultInfo addPoints(@Validated @RequestBody TempPoints tempPoints) {
63 log.info("手动发放积分,参数 ==>>{} ", tempPoints);
64
62 Long memberId = tempPoints.getMemberId(); 65 Long memberId = tempPoints.getMemberId();
66 if (Objects.isNull(memberId)) {
67 log.error("积分发放失败,参数错误,会员id 不存在");
68 return ResultInfo.failure("积分发放失败,参数错误");
69 }
70
63 Long points = tempPoints.getPoints(); 71 Long points = tempPoints.getPoints();
64 Assert.notNull(memberId,"memberId can't be null!"); 72 if (Objects.isNull(points) || points <= 0L) {
65 Assert.notNull(points,"points can't be null!"); 73 log.error("积分发放失败,参数错误,积分不存在或者积分小于0");
74 return ResultInfo.failure("积分发放失败,参数错误");
75 }
76
66 MemberDTO memberDTO = this.memberService.findById(memberId); 77 MemberDTO memberDTO = this.memberService.findById(memberId);
67 if (Objects.nonNull(memberDTO)) { 78 if (Objects.nonNull(memberDTO.getId())) {
68 String code = memberDTO.getCode(); 79 tempPoints.setMemberId(memberDTO.getId());
69 Assert.notNull(code,"code can't be null!"); 80 tempPoints.setMemberCode(memberDTO.getCode());
70 tempPoints.setMemberCode(code);
71 this.pointsOperationService.grantPointsByManualByTempPoints(tempPoints); 81 this.pointsOperationService.grantPointsByManualByTempPoints(tempPoints);
72 } 82 }
83
73 return ResultInfo.success(); 84 return ResultInfo.success();
74 } 85 }
75 86
...@@ -176,7 +187,6 @@ public class PointsOperationController { ...@@ -176,7 +187,6 @@ public class PointsOperationController {
176 return ResultInfo.success(Arrays.asList(b),description); 187 return ResultInfo.success(Arrays.asList(b),description);
177 } 188 }
178 189
179 // @Log("积分兑换商品")
180 @PostMapping(value = "/consumeItemPoints") 190 @PostMapping(value = "/consumeItemPoints")
181 @ApiOperation("积分兑换商品") 191 @ApiOperation("积分兑换商品")
182 @AnonymousAccess 192 @AnonymousAccess
......
...@@ -38,20 +38,13 @@ public class TaskOperationController { ...@@ -38,20 +38,13 @@ public class TaskOperationController {
38 @ApiOperation("事件处理") 38 @ApiOperation("事件处理")
39 @AnonymousAccess 39 @AnonymousAccess
40 public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) { 40 public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) {
41 log.info("事件处理,开始,参数 ==>> {}", criteria); 41 log.info("事件处理,参数 ==>> dealTask#==>>{}", criteria);
42 long l = System.currentTimeMillis(); 42 return this.taskOperationService.dealTask(criteria.getContent());
43
44 // 任务处理
45 this.taskOperationService.dealTask(criteria.getContent());
46 long l2 = System.currentTimeMillis();
47 log.info("事件处理,结束,总耗时 ==>> {}", (l2-l));
48
49 return ResultInfo.success();
50 } 43 }
51 44
52 /** 45 /**
53 * 新增任务 46 * 新增任务
54 * 47 *uc_tr_task_progress
55 * @param task 消息 48 * @param task 消息
56 */ 49 */
57 @PostMapping(value = "/createTask") 50 @PostMapping(value = "/createTask")
...@@ -72,22 +65,22 @@ public class TaskOperationController { ...@@ -72,22 +65,22 @@ public class TaskOperationController {
72 /** 65 /**
73 * 修改任务 66 * 修改任务
74 * 67 *
75 * @param task 消息 68 * @param content 消息
76 */ 69 */
77 @PostMapping(value = "/updateTask") 70 @PostMapping(value = "/updateTask")
78 @ApiOperation("修改任务") 71 @ApiOperation("修改任务")
79 @AnonymousAccess 72 @AnonymousAccess
80 public void updateTask(@RequestBody @Validated Task task) { 73 public void updateTask(@RequestBody @Validated Task content) {
81 log.info("taskOperation ==>> updateTask ==>> param ==>> {}", task); 74 log.info("taskOperation ==>> updateTask ==>> param ==>> {}", content);
82 Long id = task.getId(); 75 Long id = content.getId();
83 TaskDTO taskDTO = this.taskOperationService.findById(id); 76 TaskDTO taskDTO = this.taskOperationService.findById(id);
84 if (Objects.nonNull(taskDTO.getId())) { 77 if (Objects.nonNull(taskDTO.getId())) {
85 task.setCode(taskDTO.getCode()); 78 content.setCode(taskDTO.getCode());
86 Task task_ = new Task(); 79 Task task = new Task();
87 BeanUtils.copyProperties(taskDTO, task_); 80 BeanUtils.copyProperties(taskDTO, task);
88 task_.copy(task); 81 task.copy(content);
89 // 修改任务 82 // 修改任务
90 this.taskOperationService.updateTask(task_); 83 this.taskOperationService.updateTask(task);
91 } 84 }
92 } 85 }
93 86
...@@ -99,12 +92,17 @@ public class TaskOperationController { ...@@ -99,12 +92,17 @@ public class TaskOperationController {
99 @PostMapping(value = "/deleteTask") 92 @PostMapping(value = "/deleteTask")
100 @ApiOperation("删除任务") 93 @ApiOperation("删除任务")
101 @AnonymousAccess 94 @AnonymousAccess
102 public void deleteTask(@RequestBody @Validated Task task) { 95 public ResultInfo deleteTask(@RequestBody @Validated Task task) {
103 log.info("taskOperation ==>> deleteTask ==>> param ==>> {}", task); 96 log.info("taskOperation ==>> deleteTask ==>> param ==>> {}", task);
104 97
105 Long id = task.getId(); 98 Long id = task.getId();
106 // 删除任务 99 // 删除任务
107 this.taskOperationService.deleteTask(id); 100 Integer integer = this.taskOperationService.deleteTask(id);
101 if (integer > 1) {
102 return ResultInfo.success("删除成功");
103 } else {
104 return ResultInfo.failure("删除失败");
105 }
108 } 106 }
109 107
110 /** 108 /**
......
...@@ -34,9 +34,8 @@ public class TaskTemplateOperationController { ...@@ -34,9 +34,8 @@ public class TaskTemplateOperationController {
34 log.info("taskTemplateOperation ==>> create ==>> param ==>> {}", taskTemplate); 34 log.info("taskTemplateOperation ==>> create ==>> param ==>> {}", taskTemplate);
35 String code = taskTemplate.getCode(); 35 String code = taskTemplate.getCode();
36 Integer type = taskTemplate.getType(); 36 Integer type = taskTemplate.getType();
37 TaskTemplateDTO taskTemplateDTO_ = this.taskTemplateOperationService.findByCode(code); 37 Long count = this.taskTemplateOperationService.countByCodeAndType(taskTemplate);
38 TaskTemplateDTO taskTemplateDTO_1 = this.taskTemplateOperationService.findByType(type); 38 if (count < 1) {
39 if (Objects.isNull(taskTemplateDTO_.getId()) && Objects.isNull(taskTemplateDTO_1.getId())) {
40 // 新增任务 39 // 新增任务
41 this.taskTemplateOperationService.create(taskTemplate); 40 this.taskTemplateOperationService.create(taskTemplate);
42 } 41 }
......
1 package com.topdraw.business.process.rest; 1 package com.topdraw.business.process.rest;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import cn.hutool.core.util.StrUtil;
5 4
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.JSONObject; 6 import com.alibaba.fastjson.JSONObject;
7 import com.topdraw.annotation.AnonymousAccess; 7 import com.topdraw.annotation.AnonymousAccess;
8 import com.topdraw.annotation.Log;
8 import com.topdraw.business.module.common.validated.CreateGroup; 9 import com.topdraw.business.module.common.validated.CreateGroup;
9 import com.topdraw.business.module.common.validated.UpdateGroup; 10 import com.topdraw.business.module.common.validated.UpdateGroup;
10 import com.topdraw.business.module.member.domain.Member;
11 import com.topdraw.business.module.member.service.MemberService; 11 import com.topdraw.business.module.member.service.MemberService;
12 import com.topdraw.business.module.member.service.dto.MemberDTO; 12 import com.topdraw.business.module.member.service.dto.MemberDTO;
13 import com.topdraw.business.module.user.app.domain.UserApp;
14 import com.topdraw.business.module.user.app.domain.UserAppBind;
15 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
16 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
13 import com.topdraw.business.module.user.iptv.domain.UserTv; 17 import com.topdraw.business.module.user.iptv.domain.UserTv;
18 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
19 import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportRequest;
20 import com.topdraw.business.module.user.iptv.service.UserTvService;
14 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 21 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
15 import com.topdraw.business.module.user.weixin.domain.UserWeixin; 22 import com.topdraw.business.module.user.weixin.domain.UserWeixin;
16 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 23 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
24 import com.topdraw.business.process.domian.member.MemberOperationBean;
17 import com.topdraw.business.process.domian.weixin.*; 25 import com.topdraw.business.process.domian.weixin.*;
18 import com.topdraw.business.process.service.UserOperationService; 26 import com.topdraw.business.process.service.UserOperationService;
19 import com.topdraw.business.process.service.member.MemberOperationService; 27 import com.topdraw.business.process.service.member.MemberOperationService;
20 import com.topdraw.common.ResultInfo; 28 import com.topdraw.common.ResultInfo;
21 import com.topdraw.config.RedisKeyUtil; 29 import com.topdraw.util.RedisKeyUtil;
30 import com.topdraw.config.WechatConfig;
22 import com.topdraw.exception.BadRequestException; 31 import com.topdraw.exception.BadRequestException;
23 import com.topdraw.exception.EntityNotFoundException; 32 import com.topdraw.exception.EntityNotFoundException;
24 import com.topdraw.exception.GlobeExceptionMsg; 33 import com.topdraw.exception.GlobeExceptionMsg;
...@@ -26,24 +35,25 @@ import com.topdraw.resttemplate.RestTemplateClient; ...@@ -26,24 +35,25 @@ import com.topdraw.resttemplate.RestTemplateClient;
26 import com.topdraw.util.Base64Util; 35 import com.topdraw.util.Base64Util;
27 import com.topdraw.util.JSONUtil; 36 import com.topdraw.util.JSONUtil;
28 import com.topdraw.utils.RedisUtils; 37 import com.topdraw.utils.RedisUtils;
29 import com.topdraw.weixin.util.WeChatConstants; 38 import com.topdraw.weixin.service.WeChatConstants;
30 import com.topdraw.weixin.util.WeixinUtil;
31 import io.swagger.annotations.Api; 39 import io.swagger.annotations.Api;
32 import io.swagger.annotations.ApiOperation; 40 import io.swagger.annotations.ApiOperation;
33 import lombok.extern.slf4j.Slf4j; 41 import lombok.extern.slf4j.Slf4j;
34 import org.apache.commons.lang3.StringUtils; 42 import org.apache.commons.lang3.StringUtils;
35 import org.springframework.beans.BeanUtils;
36 import org.springframework.beans.factory.annotation.Autowired; 43 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.util.Assert; 44 import org.springframework.util.Assert;
45 import org.springframework.util.Base64Utils;
46 import org.springframework.util.CollectionUtils;
38 import org.springframework.validation.annotation.Validated; 47 import org.springframework.validation.annotation.Validated;
39 import org.springframework.web.bind.annotation.*; 48 import org.springframework.web.bind.annotation.*;
40 49
50 import javax.naming.ConfigurationException;
41 import java.io.IOException; 51 import java.io.IOException;
42 import java.net.URLDecoder; 52 import java.net.URLDecoder;
43 import java.sql.Timestamp; 53 import java.sql.Timestamp;
44 import java.util.*; 54 import java.util.*;
45 55
46 @Api("账处理") 56 @Api("账处理")
47 @RestController 57 @RestController
48 @RequestMapping(value = "/uce/userOperation") 58 @RequestMapping(value = "/uce/userOperation")
49 @Slf4j 59 @Slf4j
...@@ -56,14 +66,241 @@ public class UserOperationController { ...@@ -56,14 +66,241 @@ public class UserOperationController {
56 private UserOperationService userOperationService; 66 private UserOperationService userOperationService;
57 @Autowired 67 @Autowired
58 private MemberOperationService memberOperationService; 68 private MemberOperationService memberOperationService;
69 @Autowired
70 private UserTvService userTvService;
59 71
60 @Autowired 72 @Autowired
61 private RedisUtils redisUtils; 73 private RedisUtils redisUtils;
74 @Autowired
75 private WechatConfig weixinInfoConfig;
62 76
63 private static final String SUBSCRIBE = "subscribe"; 77 private static final String SUBSCRIBE = "subscribe";
64 private static final String UNSUBSCRIBE = "unsubscribe"; 78 private static final String UNSUBSCRIBE = "unsubscribe";
65 private static final Integer SUBSCRIBE_STATUS = 1; 79 private static final Integer SUBSCRIBE_STATUS = 1;
66 80
81
82
83 /******************************************************* APP ************************************/
84
85 /**
86 * app账号退出登录
87 * @param userApp app账号
88 * @return ResultInfo
89 */
90 @Log
91 @PostMapping(value = "/appSignOut")
92 @ApiOperation("app账号退出登录")
93 @AnonymousAccess
94 public ResultInfo appSignOut(@Validated @RequestBody UserApp userApp) {
95 log.info("app账号退出登录,参数 ==>> [appSignOut#{}]", userApp.getId());
96 if (Objects.isNull(userApp.getId())) {
97 log.error("app账号退出登录失败,参数错误,id不得为空,[appSignOut#]");
98 return ResultInfo.failure("app账号退出登录失败,参数错误,id不得为空");
99 }
100
101 return ResultInfo.success(true);
102 }
103
104 /**
105 * 注销app账号
106 * @param userApp app账号
107 * @return ResultInfo
108 */
109 @Log
110 @PostMapping(value = "/appCancellation")
111 @ApiOperation("注销app账号")
112 @AnonymousAccess
113 public ResultInfo appCancellation(@Validated @RequestBody UserApp userApp) {
114 log.info("注销app账号,参数 ==>> [appCancellation#{}]", userApp.getId());
115
116 if (Objects.isNull(userApp.getId())) {
117 log.error("注销app账号失败,参数错误,id不得为空,[appCancellation#]");
118 return ResultInfo.failure("");
119 }
120
121 boolean result = this.userOperationService.appCancellation(userApp);
122
123 return ResultInfo.success(result);
124 }
125
126 @Log
127 @PostMapping(value = "/updateAppInfo")
128 @ApiOperation("修改app账号信息")
129 @AnonymousAccess
130 public ResultInfo updateAppInfo(@Validated @RequestBody UserApp resources) {
131 log.info("修改app账号信息,参数 ==>> [updateAppInfo#{}]", resources);
132 Long id = resources.getId();
133 if (Objects.isNull(id)) {
134 log.error("修改app账号密码,参数错误,id不得为空,[updateAppInfo#{}]", resources);
135 return ResultInfo.failure("修改app账号密码失败,参数错误,id不得为空");
136 }
137
138 String headimgurl = resources.getHeadimgurl();
139 log.info("前端头像地址 ==>> [updateAppInfo#{}]", headimgurl);
140 if (StringUtils.isNotBlank(headimgurl) && (headimgurl.contains("http") || headimgurl.contains("https"))) {
141 String image = RestTemplateClient.netImage(headimgurl);
142 log.info("图片本地化后的图片地址 ==>> [updateAppInfo#{}]", image);
143 resources.setHeadimgurl(image);
144 }
145
146 UserAppSimpleDTO result = this.userOperationService.updateAppInfo(resources);
147 return ResultInfo.success(result);
148 }
149
150
151 @Log
152 @PostMapping(value = "/appRegister")
153 @ApiOperation("app注册")
154 @AnonymousAccess
155 public ResultInfo appRegister(@Validated @RequestBody UserApp resources) {
156 log.info("app注册 ==>> param ==>> [appRegister#{}]", resources);
157
158 String username = resources.getUsername();
159 if (StringUtils.isBlank(username)) {
160 log.error("app注册,参数错误,账号不得为空 ");
161 return ResultInfo.failure("app注册,参数错误,账号不得为空");
162 }
163
164 Integer type = resources.getType();
165 if (Objects.isNull(type)) {
166 log.error("app注册,参数错误,账号类型不得为空 ");
167 return ResultInfo.failure("app注册,参数错误,账号类型不得为空");
168 }
169
170 String account = resources.getAccount();
171 if (StringUtils.isNotBlank(account)) {
172 if (Objects.isNull(resources.getAccountType())) {
173 log.error("app注册,参数错误,第三方账号类型不得为空");
174 return ResultInfo.failure("app注册,参数错误,第三方账号类型不得为空");
175 }
176 }
177
178 if (StringUtils.isBlank(resources.getNickname())) {
179 resources.setNickname(Base64Utils.encodeToString(username.getBytes()));
180 }
181
182 UserAppDTO userAppDTO = this.userOperationService.appRegister(resources);
183 return ResultInfo.success(userAppDTO);
184 }
185
186 @Log
187 @PostMapping(value = "/appBindThirdAccount")
188 @ApiOperation("app账号绑定第三方账号")
189 @AnonymousAccess
190 public ResultInfo appBindThirdAccount(@Validated @RequestBody UserAppBind resources) {
191 log.info("app账号绑定第三方账号,参数 ==>> [appBindThirdAccount#{}]", resources);
192
193 String username = resources.getUsername();
194 if (StringUtils.isBlank(username)) {
195 log.error("app账号绑定第三方账号,参数错误,账号不得为空 ");
196 return ResultInfo.failure("app账号绑定第三方账号,参数错误,账号不得为空");
197 }
198
199 String account = resources.getAccount();
200 if (StringUtils.isNotBlank(account)) {
201 if (Objects.isNull(resources.getAccountType())) {
202 log.error("app账号绑定第三方账号,参数错误,第三方账号不得为空");
203 return ResultInfo.failure("app账号绑定第三方账号,参数错误,第三方账号不得为空");
204 }
205 }
206
207 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
208 Integer accountType = resources.getAccountType();
209 if (Objects.isNull(accountType)) {
210 log.error("app账号绑定第三方账号,参数错误,第三方账号类型不得为空");
211 return ResultInfo.failure("app账号绑定第三方账号,参数错误,第三方账号类型不得为空");
212 }
213
214 return this.userOperationService.appBindThirdAccount(resources);
215 }
216
217 @Log
218 @PostMapping(value = "/cancelUserAppBind")
219 @ApiOperation("取消关联第三方账号")
220 @AnonymousAccess
221 public ResultInfo cancelUserAppBind(@Validated @RequestBody UserAppBind resources) {
222 log.info("取消关联第三方账号, 参数 ==>> [cancelUserAppBind#{}]", resources);
223
224 String account = resources.getAccount();
225 if (StringUtils.isBlank(account)) {
226 log.error("取消关联第三方账号失败,参数错误了,第三方账号不能为空");
227 return ResultInfo.failure("取消关联第三方账号失败,参数错误,第三方账号不能为空");
228 }
229
230 // 第三方账号类型 3:微信;4:QQ;5:微博;6:苹果账号
231 Integer accountType = resources.getAccountType();
232 if (Objects.isNull(accountType)) {
233 log.error("取消关联第三方账号失败,参数错误,第三方账号类型不得为空");
234 return ResultInfo.failure("取消关联第三方账号失败,参数错误,第三方账号类型不得为空");
235 }
236
237 return this.userOperationService.cancelUserAppBind(resources);
238 }
239
240
241 @PostMapping("/appBind")
242 @ApiOperation("app绑定大屏")
243 @AnonymousAccess
244 public ResultInfo appBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
245 log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
246
247 Long memberId = resources.getMemberId();
248 if (Objects.isNull(memberId)) {
249 return ResultInfo.failure("参数错误,memberId 不存在");
250 }
251
252 String platformAccount = resources.getPlatformAccount();
253 if (StringUtils.isBlank(platformAccount)) {
254 return ResultInfo.failure("参数错误,大屏账号不存在");
255 }
256
257 boolean result = this.userOperationService.appBind(resources);
258 return ResultInfo.success(result);
259 }
260
261 @PostMapping("/appUnbind")
262 @ApiOperation("app解绑")
263 @AnonymousAccess
264 public ResultInfo appUnbind(@Validated(value = {UnbindGroup.class}) @RequestBody WeixinUnBindBean weixinUnBindBean) {
265 log.info("UserOperationController ==> minaUnbind ==>> param ==> [{}]", weixinUnBindBean);
266
267 Long memberId = weixinUnBindBean.getMemberId();
268 if (Objects.isNull(memberId)) {
269 log.error("小屏解绑失败,参数错误,memberId不存在");
270 return ResultInfo.failure("参数错误,会员id不存在");
271 }
272
273 return this.userOperationService.minaUnbind(weixinUnBindBean);
274 }
275
276
277 /******************************************************* weixin ************************************/
278
279 @Log
280 @PostMapping(value = "/saveGrowthReport")
281 @ApiOperation("同步大屏成长报告")
282 @AnonymousAccess
283 public ResultInfo saveGrowthReport(@Validated @RequestBody String resources) {
284 log.info("同步大屏成长报告,参数 ==>> [saveGrowthReport#{}]", resources);
285 GrowthReportRequest growthReportRequest = JSON.parseObject(new String(Base64Utils.decode(resources.getBytes())), GrowthReportRequest.class);
286
287 String platformAccount = growthReportRequest.getPlatformAccount();
288 log.info("同步大屏成长报告消息,大屏账号 ==>> [saveGrowthReport#{}]", platformAccount);
289 List<GrowthReportRequest.CategoryContent> playDurationWithCategory = growthReportRequest.getPlayDurationWithCategory();
290 log.info("同步大屏成长报告消息主体,消息体 ==>> [saveGrowthReport#{}]", playDurationWithCategory);
291 if (!CollectionUtils.isEmpty(playDurationWithCategory)) {
292 GrowthReport growthReport = new GrowthReport();
293 growthReport.setPlatformAccount(platformAccount);
294
295 JSONObject jsonObject = new JSONObject();
296 jsonObject.put("playDurationWithCategory", playDurationWithCategory);
297 growthReport.setData(jsonObject.toJSONString());
298 return this.userOperationService.saveGrowthReport(growthReport);
299 }
300
301 return ResultInfo.failure("保存失败");
302 }
303
67 @PutMapping(value = "/updateWeixin") 304 @PutMapping(value = "/updateWeixin")
68 @ApiOperation("修改UserWeixin") 305 @ApiOperation("修改UserWeixin")
69 @AnonymousAccess 306 @AnonymousAccess
...@@ -80,37 +317,32 @@ public class UserOperationController { ...@@ -80,37 +317,32 @@ public class UserOperationController {
80 log.info("userOperation ==>> updateVipByUserId ==>> param ==>> [{}]",resources); 317 log.info("userOperation ==>> updateVipByUserId ==>> param ==>> [{}]",resources);
81 318
82 Integer vip = resources.getVip(); 319 Integer vip = resources.getVip();
320 if (Objects.isNull(vip) || vip < 1) {
321 return ResultInfo.failure("手动修改vip异常,参数错误,vip为空或者小于1");
322 }
83 Timestamp vipExpireTime = resources.getVipExpireTime(); 323 Timestamp vipExpireTime = resources.getVipExpireTime();
84 // 微信账号id 324 // 微信账号id
85 Long userId = resources.getUserId(); 325 Long userId = resources.getUserId();
326 if (Objects.isNull(userId)) {
327 return ResultInfo.failure("手动修改vip异常,参数错误,小屏账号id为空");
328 }
86 UserWeixinDTO userWeixinDTO = this.userOperationService.findById(userId); 329 UserWeixinDTO userWeixinDTO = this.userOperationService.findById(userId);
87 330
88 Long memberId = userWeixinDTO.getMemberId(); 331 Long memberId = userWeixinDTO.getMemberId();
89 MemberDTO memberDTO = this.memberService.findById(memberId); 332 MemberDTO memberDTO = this.memberService.findById(memberId);
90 333
91 Member member = new Member(); 334 MemberOperationBean memberOperationBean = new MemberOperationBean();
92 BeanUtils.copyProperties(memberDTO, member); 335 memberOperationBean.setMemberCode(memberDTO.getCode());
93 if (Objects.nonNull(vip)) { 336 if (vip < memberDTO.getVip()) {
94 member.setVip(vip); 337 vip = memberDTO.getVip();
95 } 338 } else {
96 if (Objects.nonNull(vipExpireTime)) { 339 memberOperationBean.setVipExpireTime(vipExpireTime);
97 member.setVipExpireTime(vipExpireTime);
98 }
99
100 this.createVipHistory(userId, vip, vipExpireTime);
101
102 this.memberOperationService.updateMemberVip(member);
103
104 return ResultInfo.success();
105 } 340 }
341 memberOperationBean.setVip(vip);
106 342
343 MemberDTO memberDTO1 = this.memberOperationService.doUpdateVipByMemberCode(memberOperationBean);
107 344
108 private void createVipHistory(Long weixinUserId, Integer vip , Timestamp vipExpireTime){ 345 return ResultInfo.success(memberDTO1);
109 BuyVipBean buyVipBean = new BuyVipBean();
110 buyVipBean.setId(weixinUserId);
111 buyVipBean.setVip(vip);
112 buyVipBean.setVipExpireTime(vipExpireTime);
113 this.memberOperationService.buyVipByUserId(buyVipBean);
114 } 346 }
115 347
116 @PostMapping(value = "/createWeixinUserAndCreateMember") 348 @PostMapping(value = "/createWeixinUserAndCreateMember")
...@@ -146,14 +378,18 @@ public class UserOperationController { ...@@ -146,14 +378,18 @@ public class UserOperationController {
146 @PostMapping("/subscribe") 378 @PostMapping("/subscribe")
147 @ApiOperation("微信公众号关注") 379 @ApiOperation("微信公众号关注")
148 @AnonymousAccess 380 @AnonymousAccess
149 public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { 381 public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws Exception {
150 log.info("UserOperationController ==> subscribe ==>> param ==> [{}]",data); 382 log.info("UserOperationController ==> subscribe ==>> param ==> [{}]",data);
151 383
152 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class); 384 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(data.getContent(), SubscribeBean.class);
153 // 解析参数 385 // 解析参数
154 this.parseSubscribe(subscribeBean); 386 this.parseSubscribe(subscribeBean);
155 this.userOperationService.subscribe(subscribeBean); 387 boolean subscribe = this.userOperationService.subscribe(subscribeBean);
156 return ResultInfo.success(); 388 if (subscribe) {
389 return ResultInfo.success("关注成功");
390 } else {
391 return ResultInfo.failure("关注失败");
392 }
157 } 393 }
158 394
159 /** 395 /**
...@@ -161,11 +397,11 @@ public class UserOperationController { ...@@ -161,11 +397,11 @@ public class UserOperationController {
161 * @param subscribeBean 397 * @param subscribeBean
162 * @throws IOException 398 * @throws IOException
163 */ 399 */
164 private void parseSubscribe(SubscribeBean subscribeBean) throws IOException { 400 private void parseSubscribe(SubscribeBean subscribeBean) throws Exception {
165 401
166 // appId 402 // appId
167 String appId = subscribeBean.getAppid(); 403 String appId = subscribeBean.getAppid();
168 Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL); 404 // Assert.notNull(appId, GlobeExceptionMsg.APP_ID_IS_NULL);
169 // openId 405 // openId
170 String openId = subscribeBean.getOpenid(); 406 String openId = subscribeBean.getOpenid();
171 Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL); 407 Assert.notNull(openId, GlobeExceptionMsg.OPEN_ID_IS_NULL);
...@@ -174,45 +410,41 @@ public class UserOperationController { ...@@ -174,45 +410,41 @@ public class UserOperationController {
174 Assert.notNull(openId, GlobeExceptionMsg.UNION_ID_IS_NULL); 410 Assert.notNull(openId, GlobeExceptionMsg.UNION_ID_IS_NULL);
175 411
176 // 匹配配置文件中的微信列表信息 412 // 匹配配置文件中的微信列表信息
177 Map<String, String> wxInfoMap = WeixinUtil.getWeixinInfoByAppid(appId); 413 Map<String, String> wxInfoMap = this.getWeixinInfoByAppid(appId);
178 414
179 if (Objects.nonNull(wxInfoMap)) {
180 // 程序类型 415 // 程序类型
181 String appType = wxInfoMap.get("appType"); 416 String appType = wxInfoMap.get("appType");
182 // 非订阅号,暂不处理。返回暂不支持 417 // 非订阅号,暂不处理。返回暂不支持
183 if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION)) 418 if (ObjectUtil.notEqual(appType, WeChatConstants.WX_SUBSCRIPTION))
184 throw new BadRequestException("非订阅号"); 419 throw new BadRequestException("非订阅号");
185 420
186 }
187 421
188 // 大屏账户信息 422 // 大屏账户信息
189 JSONObject iptvUserInfo = null; 423 JSONObject redisInfo = null;
190 // 缓存的大屏信息,使用unionid即可 424 // 缓存的大屏信息,使用unionid即可
191 String content = (String) this.redisUtils.get(RedisKeyUtil.genSeSuSubscribeKey(unionId)); 425 String content = (String) this.redisUtils.get(RedisKeyUtil.genSeSuSubscribeKey(unionId));
426 log.info("获取redis中存储的数据,[subscribe#{}]", content);
192 if (StringUtils.isNotBlank(content)) { 427 if (StringUtils.isNotBlank(content)) {
193 // 大屏信息 428 // 大屏信息
194 iptvUserInfo = JSONObject.parseObject(content); 429 redisInfo = JSONObject.parseObject(content);
195 } 430 }
196 431
197 // 用户自己搜索关注就没有大屏信息,否则表示扫码关注 432 // 用户自己搜索关注就没有大屏信息,否则表示扫码关注
198 if (Objects.nonNull(iptvUserInfo)) { 433 if (Objects.nonNull(redisInfo)) {
199 434
200 subscribeBean.setIptvUserInfo(iptvUserInfo); 435 subscribeBean.setIptvUserInfo(redisInfo);
201 Object sourceInfo1 = iptvUserInfo.get("sourceInfo"); 436 // 关注来源信息
202 if (Objects.nonNull(sourceInfo1)) { 437 log.info("关注来源信息,[subscribe#{}]", redisInfo);
203 String sourceInfo = sourceInfo1.toString(); 438 subscribeBean.setSourceInfo(redisInfo);
204 if (StringUtils.isNotBlank(sourceInfo))
205 subscribeBean.setSourceInfo(sourceInfo);
206 }
207 439
208 String nickname = iptvUserInfo.get("nickname").toString(); 440 String nickname = redisInfo.get("nickname").toString();
209 if (StringUtils.isNotBlank(nickname)) { 441 if (StringUtils.isNotBlank(nickname)) {
210 String nicknameDecode = URLDecoder.decode(nickname, "UTF-8"); 442 String nicknameDecode = URLDecoder.decode(nickname, "UTF-8");
211 String nicknameEncode = Base64Util.encode(nicknameDecode); 443 String nicknameEncode = Base64Util.encode(nicknameDecode);
212 subscribeBean.setNickname(nicknameEncode); 444 subscribeBean.setNickname(nicknameEncode);
213 } 445 }
214 446
215 String headimgurl = iptvUserInfo.get("headimgurl").toString(); 447 String headimgurl = redisInfo.get("headimgurl").toString();
216 log.info("parseSubscribe ==>> headimgurl ==>> {}", headimgurl); 448 log.info("parseSubscribe ==>> headimgurl ==>> {}", headimgurl);
217 if (StringUtils.isNotBlank(headimgurl)) { 449 if (StringUtils.isNotBlank(headimgurl)) {
218 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 450 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
...@@ -239,6 +471,24 @@ public class UserOperationController { ...@@ -239,6 +471,24 @@ public class UserOperationController {
239 471
240 } 472 }
241 473
474 /**
475 * 获取配置的微信应用列表
476 * @param appid 应用Id
477 * @return
478 * @throws ConfigurationException
479 */
480 private Map<String, String> getWeixinInfoByAppid(String appid) throws ConfigurationException {
481 if (com.topdraw.utils.StringUtils.isBlank(appid)) {
482 throw new RuntimeException("wxAppid can not be null");
483 }
484 List<Map<String, String>> list = weixinInfoConfig.getWechatAppList();
485 Optional<Map<String, String>> weixinInfoOptional = list.stream().filter(o -> o.get("appid").equals(appid)).findFirst();
486 if (!weixinInfoOptional.isPresent()) {
487 throw new RuntimeException("wxAppid error, appid is : " + appid);
488 }
489 return weixinInfoOptional.get();
490 }
491
242 @PostMapping("/unsubscribe") 492 @PostMapping("/unsubscribe")
243 @ApiOperation("微信公众号取关") 493 @ApiOperation("微信公众号取关")
244 @AnonymousAccess 494 @AnonymousAccess
...@@ -266,6 +516,16 @@ public class UserOperationController { ...@@ -266,6 +516,16 @@ public class UserOperationController {
266 public ResultInfo minaBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) { 516 public ResultInfo minaBind(@Validated(value = {BindGroup.class}) @RequestBody BindBean resources) {
267 log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources); 517 log.info("UserOperationController ==> appletBind ==>> param ==> [{}]",resources);
268 518
519 Long memberId = resources.getMemberId();
520 if (Objects.isNull(memberId)) {
521 return ResultInfo.failure("参数错误,memberId 不存在");
522 }
523
524 String platformAccount = resources.getPlatformAccount();
525 if (StringUtils.isBlank(platformAccount)) {
526 return ResultInfo.failure("参数错误,大屏账号不存在");
527 }
528
269 boolean result = this.userOperationService.minaBind(resources); 529 boolean result = this.userOperationService.minaBind(resources);
270 return ResultInfo.success(result); 530 return ResultInfo.success(result);
271 } 531 }
...@@ -274,10 +534,16 @@ public class UserOperationController { ...@@ -274,10 +534,16 @@ public class UserOperationController {
274 @ApiOperation("小屏解绑") 534 @ApiOperation("小屏解绑")
275 @AnonymousAccess 535 @AnonymousAccess
276 public ResultInfo minaUnbind(@Validated(value = {UnbindGroup.class}) @RequestBody WeixinUnBindBean weixinUnBindBean) { 536 public ResultInfo minaUnbind(@Validated(value = {UnbindGroup.class}) @RequestBody WeixinUnBindBean weixinUnBindBean) {
277 log.info("UserOperationController ==> minaUnbind ==>> param ==> [{}]", weixinUnBindBean); 537 log.info("小屏解绑,参数 ==> [minaUnbind#{}]", weixinUnBindBean);
538
539 Long memberId = weixinUnBindBean.getMemberId();
540 if (Objects.isNull(memberId)) {
541 log.error("小屏解绑失败,参数错误,memberId不存在");
542 return ResultInfo.failure("参数错误,无会员id");
543 }
544
545 return this.userOperationService.minaUnbind(weixinUnBindBean);
278 546
279 this.userOperationService.minaUnbind(weixinUnBindBean);
280 return ResultInfo.success();
281 } 547 }
282 548
283 /** 549 /**
...@@ -293,12 +559,18 @@ public class UserOperationController { ...@@ -293,12 +559,18 @@ public class UserOperationController {
293 public ResultInfo memberPreprocess(@RequestBody String data) { 559 public ResultInfo memberPreprocess(@RequestBody String data) {
294 560
295 log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data); 561 log.info("UserOperationController ==> saveUserInfo ==>> param ==>> [{}]",data);
296 Assert.notNull(data, "用户数据不可为空"); 562 if (StringUtils.isBlank(data)) {
563 log.error("预存大小屏账号信息失败,无参数");
564 return ResultInfo.failure("参数错误");
565 }
297 566
298 JSONObject json = JSONObject.parseObject(data); 567 JSONObject json = JSONObject.parseObject(data);
299 568
300 String unionid = json.getString("unionid"); 569 String unionid = json.getString("unionid");
301 Assert.state(StrUtil.isNotBlank(unionid), "unionid不可为空"); 570 if (StringUtils.isBlank(unionid)) {
571 log.error("预存大小屏账号信息失败,参数错误,unionid不存在");
572 return ResultInfo.failure("参数错误,unionid不存在");
573 }
302 574
303 575
304 List<Object> resultList = new ArrayList<>(); 576 List<Object> resultList = new ArrayList<>();
...@@ -321,7 +593,7 @@ public class UserOperationController { ...@@ -321,7 +593,7 @@ public class UserOperationController {
321 } else { 593 } else {
322 594
323 // 账号存在,未关注 595 // 账号存在,未关注
324 if (userWeixinDTO.getStatus() != SUBSCRIBE_STATUS) { 596 if (!userWeixinDTO.getStatus().equals(SUBSCRIBE_STATUS)) {
325 result = UNSUBSCRIBE; 597 result = UNSUBSCRIBE;
326 } 598 }
327 599
...@@ -384,7 +656,7 @@ public class UserOperationController { ...@@ -384,7 +656,7 @@ public class UserOperationController {
384 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 656 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
385 // String imageEncode = Base64Util.encode(headimgurlDecode); 657 // String imageEncode = Base64Util.encode(headimgurlDecode);
386 String image = RestTemplateClient.netImage(headimgurlDecode); 658 String image = RestTemplateClient.netImage(headimgurlDecode);
387 memberDTO.setAvatarUrl(StringUtils.isNotBlank(image) == true ? image:headimgurlDecode); 659 memberDTO.setAvatarUrl(StringUtils.isNotBlank(image) ? image:headimgurlDecode);
388 } 660 }
389 661
390 } 662 }
...@@ -419,8 +691,7 @@ public class UserOperationController { ...@@ -419,8 +691,7 @@ public class UserOperationController {
419 private String downloadWeixinImge(String headimgurl){ 691 private String downloadWeixinImge(String headimgurl){
420 try { 692 try {
421 if (StringUtils.isNotBlank(headimgurl)) { 693 if (StringUtils.isNotBlank(headimgurl)) {
422 String image = RestTemplateClient.netImage(headimgurl); 694 return RestTemplateClient.netImage(headimgurl);
423 return image;
424 } 695 }
425 } catch (Exception e) { 696 } catch (Exception e) {
426 log.info("头像解析失败!!!"); 697 log.info("头像解析失败!!!");
...@@ -447,8 +718,12 @@ public class UserOperationController { ...@@ -447,8 +718,12 @@ public class UserOperationController {
447 @ApiOperation("保存大屏账户同时创建会员信息") 718 @ApiOperation("保存大屏账户同时创建会员信息")
448 @AnonymousAccess 719 @AnonymousAccess
449 public ResultInfo createTvUserAndMember(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) { 720 public ResultInfo createTvUserAndMember(@Validated(value = {CreateGroup.class}) @RequestBody UserTv resources) {
450 log.info("UserOperationController ==> createUserAndCreateMember ==>> param ==> [{}]",resources); 721 log.info("UserOperationController ==> createTvUserAndMember ==>> param ==> [{}]",resources);
451 722 String platformAccount = resources.getPlatformAccount();
723 if (StringUtils.isBlank(platformAccount)) {
724 log.error("保存大屏账户同时创建会员信息异常,参数错误,大屏账号不存在");
725 return ResultInfo.failure("参数错误,大屏账号不存在");
726 }
452 UserTvDTO result = this.userOperationService.createTvUserAndMember(resources); 727 UserTvDTO result = this.userOperationService.createTvUserAndMember(resources);
453 return ResultInfo.success(result); 728 return ResultInfo.success(result);
454 } 729 }
...@@ -471,21 +746,36 @@ public class UserOperationController { ...@@ -471,21 +746,36 @@ public class UserOperationController {
471 throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL); 746 throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
472 } 747 }
473 748
474 this.userOperationService.tvUnbind(resources); 749 boolean b = this.userOperationService.tvUnbind(resources);
475 return ResultInfo.success(); 750 if (b) {
751 return ResultInfo.success("解绑成功");
752 } else return ResultInfo.failure("解绑失败");
476 } 753 }
477 754
478 @RequestMapping(value = "/changeMainAccount") 755 @RequestMapping(value = "/changeMainAccount")
479 @ApiOperation("大屏更换主账号") 756 @ApiOperation("大屏更换主账号")
480 @AnonymousAccess 757 @AnonymousAccess
481 public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody BindBean resources) { 758 public ResultInfo changeMainAccount(@Validated(value = {UpdateGroup.class}) @RequestBody BindBean resources) {
482 log.info("UserOperationController ==> changeMainAccount ==>> param ==> [{}]",resources); 759 log.info("大屏更换主账号,参数 [changeMainAccount# ==> {}]",resources);
483 760
484 Long memberId = resources.getMemberId(); 761 // Long memberId = resources.getMemberId();
485 String memberCode = resources.getMemberCode(); 762 String memberCode = resources.getMemberCode();
486 if (StringUtils.isBlank(memberCode) && Objects.nonNull(memberId)) { 763 /* if (StringUtils.isBlank(memberCode) && Objects.nonNull(memberId)) {
487 memberCode = this.memberService.findCodeById(memberId); 764 memberCode = this.memberService.findCodeById(memberId);
765 } else if (StringUtils.isNotBlank(memberCode) && Objects.isNull(memberId)) {
766 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
767 memberCode = memberDTO.getCode();
768 }*/
769
770 if (StringUtils.isBlank(memberCode))
771 return ResultInfo.failure("会员code不得为空");
772
773 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
774 if (Objects.isNull(memberDTO.getId())) {
775 log.error("大屏更换主账号失败,会员信息不存在, changeMainAccount# ==> {}", memberCode);
776 return ResultInfo.failure("会员信息不存在");
488 } 777 }
778
489 String platformAccount = resources.getPlatformAccount(); 779 String platformAccount = resources.getPlatformAccount();
490 if (StringUtils.isBlank(platformAccount)) 780 if (StringUtils.isBlank(platformAccount))
491 throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL); 781 throw new BadRequestException(GlobeExceptionMsg.IPTV_PLATFORM_ACCOUNT_IS_NULL);
...@@ -493,9 +783,9 @@ public class UserOperationController { ...@@ -493,9 +783,9 @@ public class UserOperationController {
493 UserTv userTv = new UserTv(); 783 UserTv userTv = new UserTv();
494 userTv.setMemberCode(memberCode); 784 userTv.setMemberCode(memberCode);
495 userTv.setPlatformAccount(platformAccount); 785 userTv.setPlatformAccount(platformAccount);
496 this.userOperationService.changeMainAccount(userTv); 786 boolean b = this.userOperationService.changeMainAccount(userTv);
497 787
498 return ResultInfo.success(); 788 return ResultInfo.success(b);
499 } 789 }
500 790
501 @PostMapping(value = "/deleteAllCollection") 791 @PostMapping(value = "/deleteAllCollection")
...@@ -530,6 +820,7 @@ public class UserOperationController { ...@@ -530,6 +820,7 @@ public class UserOperationController {
530 return ResultInfo.success(); 820 return ResultInfo.success();
531 } 821 }
532 822
823
533 } 824 }
534 825
535 826
......
1 package com.topdraw.business.process.service;
2
3 import lombok.extern.slf4j.Slf4j;
4 import org.springframework.stereotype.Service;
5
6 /**
7 * @author :
8 * @description:
9 * @function :
10 * @date :Created in 2022/6/22 14:05
11 * @version: :
12 * @modified By:
13 * @since : modified in 2022/6/22 14:05
14 */
15 @Service
16 @Slf4j
17 public class AsyncTaskService {
18
19
20
21 }
...@@ -18,14 +18,6 @@ public interface ExpOperationService { ...@@ -18,14 +18,6 @@ public interface ExpOperationService {
18 void grantExpThroughTempExp( List<TempExp> tempExpList); 18 void grantExpThroughTempExp( List<TempExp> tempExpList);
19 19
20 /** 20 /**
21 * 系统手动发放优惠券
22 * @param memberId
23 * @param userId
24 * @param tempExpList
25 */
26 void grantExpByManual(Long memberId,Long userId ,List<TempExp> tempExpList);
27
28 /**
29 * 21 *
30 * @param tempExpList 22 * @param tempExpList
31 */ 23 */
......
...@@ -13,13 +13,6 @@ import java.util.List; ...@@ -13,13 +13,6 @@ import java.util.List;
13 public interface PointsOperationService { 13 public interface PointsOperationService {
14 14
15 /** 15 /**
16 * 手动发放积分
17 * @param memberId 会员id
18 * @param tempPoints 积分详情
19 */
20 void grantPointsByManual(Long memberId , TempPoints tempPoints);
21
22 /**
23 * 16 *
24 * @param tempPoints 17 * @param tempPoints
25 */ 18 */
...@@ -44,5 +37,6 @@ public interface PointsOperationService { ...@@ -44,5 +37,6 @@ public interface PointsOperationService {
44 * @param memberId 37 * @param memberId
45 * @return 38 * @return
46 */ 39 */
40 @Deprecated
47 Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); 41 Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId);
48 } 42 }
......
1 package com.topdraw.business.process.service; 1 package com.topdraw.business.process.service;
2 2
3 import com.topdraw.business.module.rights.history.domain.RightsHistory; 3 import com.topdraw.business.module.rights.history.domain.RightsHistory;
4 import com.topdraw.business.process.domian.constant.RightType; 4 import com.topdraw.business.module.rights.constant.RightType;
5 5
6 import java.util.List; 6 import java.util.List;
7 import java.util.Map; 7 import java.util.Map;
...@@ -23,5 +23,5 @@ public interface RightsOperationService { ...@@ -23,5 +23,5 @@ public interface RightsOperationService {
23 * 任务完成自动发放权益 23 * 任务完成自动发放权益
24 * @param tempRightsMap 24 * @param tempRightsMap
25 */ 25 */
26 void grantRights(Map<RightType, Object> tempRightsMap); 26 Integer grantRights(Map<RightType, Object> tempRightsMap);
27 } 27 }
......
...@@ -11,8 +11,18 @@ import com.topdraw.common.ResultInfo; ...@@ -11,8 +11,18 @@ import com.topdraw.common.ResultInfo;
11 */ 11 */
12 public interface TaskOperationService { 12 public interface TaskOperationService {
13 13
14 /**
15 *
16 * @param id
17 * @return
18 */
14 TaskDTO findById(Long id); 19 TaskDTO findById(Long id);
15 20
21 /**
22 *
23 * @param code
24 * @return
25 */
16 TaskDTO findByCode(String code); 26 TaskDTO findByCode(String code);
17 27
18 /** 28 /**
...@@ -26,25 +36,25 @@ public interface TaskOperationService { ...@@ -26,25 +36,25 @@ public interface TaskOperationService {
26 * 36 *
27 * @param task 37 * @param task
28 */ 38 */
29 void createTask(Task task); 39 TaskDTO createTask(Task task);
30 40
31 /** 41 /**
32 * 42 *
33 * @param task 43 * @param task
34 */ 44 */
35 void updateTask(Task task); 45 TaskDTO updateTask(Task task);
36 46
37 /** 47 /**
38 * 48 *
39 * @param task 49 * @param task
40 */ 50 */
41 void deleteTask(Task task); 51 Integer deleteTask(Task task);
42 52
43 /** 53 /**
44 * 54 *
45 * @param id 55 * @param id
46 */ 56 */
47 void deleteTask(Long id); 57 Integer deleteTask(Long id);
48 58
49 /** 59 /**
50 * 60 *
...@@ -54,6 +64,4 @@ public interface TaskOperationService { ...@@ -54,6 +64,4 @@ public interface TaskOperationService {
54 */ 64 */
55 boolean createPoint2ChongQing(String platformAccount, Long points); 65 boolean createPoint2ChongQing(String platformAccount, Long points);
56 66
57
58
59 } 67 }
......
...@@ -43,6 +43,13 @@ public interface TaskTemplateOperationService { ...@@ -43,6 +43,13 @@ public interface TaskTemplateOperationService {
43 43
44 /** 44 /**
45 * 45 *
46 * @param taskTemplate
47 * @return
48 */
49 Long countByCodeAndType(TaskTemplate taskTemplate);
50
51 /**
52 *
46 * @param id 53 * @param id
47 * @return 54 * @return
48 */ 55 */
......
1 package com.topdraw.business.process.service; 1 package com.topdraw.business.process.service;
2 2
3 import com.topdraw.business.module.member.service.dto.MemberDTO; 3 import com.topdraw.business.module.member.service.dto.MemberDTO;
4 import com.topdraw.business.module.user.app.domain.UserApp;
5 import com.topdraw.business.module.user.app.domain.UserAppBind;
6 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
7 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
4 import com.topdraw.business.module.user.iptv.domain.UserTv; 8 import com.topdraw.business.module.user.iptv.domain.UserTv;
9 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
5 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 10 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
6 import com.topdraw.business.module.user.weixin.domain.UserWeixin; 11 import com.topdraw.business.module.user.weixin.domain.UserWeixin;
7 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 12 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
...@@ -9,6 +14,7 @@ import com.topdraw.business.process.domian.weixin.BindBean; ...@@ -9,6 +14,7 @@ import com.topdraw.business.process.domian.weixin.BindBean;
9 import com.topdraw.business.process.domian.weixin.SubscribeBean; 14 import com.topdraw.business.process.domian.weixin.SubscribeBean;
10 import com.topdraw.business.process.domian.weixin.TvUnBindBean; 15 import com.topdraw.business.process.domian.weixin.TvUnBindBean;
11 import com.topdraw.business.process.domian.weixin.WeixinUnBindBean; 16 import com.topdraw.business.process.domian.weixin.WeixinUnBindBean;
17 import com.topdraw.common.ResultInfo;
12 18
13 19
14 public interface UserOperationService { 20 public interface UserOperationService {
...@@ -52,13 +58,13 @@ public interface UserOperationService { ...@@ -52,13 +58,13 @@ public interface UserOperationService {
52 * 大屏解绑 58 * 大屏解绑
53 * @param userTv 59 * @param userTv
54 */ 60 */
55 void tvUnbind(TvUnBindBean userTv); 61 boolean tvUnbind(TvUnBindBean userTv);
56 62
57 /** 63 /**
58 * 大屏切换主账户(会员) 64 * 大屏切换主账户(会员)
59 * @param userTv 65 * @param userTv
60 */ 66 */
61 void changeMainAccount(UserTv userTv); 67 boolean changeMainAccount(UserTv userTv);
62 68
63 /** 69 /**
64 * 微信公众号关注 70 * 微信公众号关注
...@@ -70,6 +76,7 @@ public interface UserOperationService { ...@@ -70,6 +76,7 @@ public interface UserOperationService {
70 */ 76 */
71 boolean subscribe(SubscribeBean resources); 77 boolean subscribe(SubscribeBean resources);
72 78
79
73 /** 80 /**
74 * 微信公众号取关 81 * 微信公众号取关
75 * @param resources 82 * @param resources
...@@ -113,18 +120,11 @@ public interface UserOperationService { ...@@ -113,18 +120,11 @@ public interface UserOperationService {
113 boolean minaBind(BindBean resources); 120 boolean minaBind(BindBean resources);
114 121
115 /** 122 /**
116 * 123 * app绑定大屏
117 * @param memberCode 124 * @param resources
118 * @param platformAccount 125 * @return
119 */
120 void bind(String memberCode, String platformAccount);
121
122 /**
123 *
124 * @param memberDTO
125 * @param userTvDTO
126 */ 126 */
127 void bind(MemberDTO memberDTO, UserTvDTO userTvDTO); 127 boolean appBind(BindBean resources);
128 128
129 /** 129 /**
130 * 130 *
...@@ -152,7 +152,7 @@ public interface UserOperationService { ...@@ -152,7 +152,7 @@ public interface UserOperationService {
152 * 小屏解绑 152 * 小屏解绑
153 * @param weixinUnBindBean 153 * @param weixinUnBindBean
154 */ 154 */
155 void minaUnbind(WeixinUnBindBean weixinUnBindBean); 155 ResultInfo minaUnbind(WeixinUnBindBean weixinUnBindBean);
156 156
157 /** 157 /**
158 * 158 *
...@@ -173,4 +173,50 @@ public interface UserOperationService { ...@@ -173,4 +173,50 @@ public interface UserOperationService {
173 * @return 173 * @return
174 */ 174 */
175 UserTvDTO updateUserTv(UserTv resources); 175 UserTvDTO updateUserTv(UserTv resources);
176
177
178 /**
179 *
180 * @param resources
181 * @return
182 */
183 UserAppDTO appRegister(UserApp resources);
184
185 /**
186 *
187 * @param resources
188 * @return
189 */
190 ResultInfo cancelUserAppBind(UserAppBind resources);
191
192 /**
193 *
194 * @param resources
195 * @return
196 */
197 ResultInfo appBindThirdAccount(UserAppBind resources);
198
199 /**
200 *
201 * @param resources
202 * @return
203 */
204 UserAppSimpleDTO updateAppInfo(UserApp resources);
205
206 /**
207 *
208 * @param resources
209 * @return
210 */
211 boolean updatePasswordById(UserApp resources);
212
213 /**
214 *
215 * @param growthReport
216 * @return
217 */
218 ResultInfo saveGrowthReport(GrowthReport growthReport);
219
220
221 boolean appCancellation(UserApp userApp);
176 } 222 }
......
...@@ -4,7 +4,6 @@ import com.topdraw.aspect.AsyncMqSend; ...@@ -4,7 +4,6 @@ import com.topdraw.aspect.AsyncMqSend;
4 import com.topdraw.business.module.coupon.history.domain.CouponHistory; 4 import com.topdraw.business.module.coupon.history.domain.CouponHistory;
5 import com.topdraw.business.module.coupon.history.service.CouponHistoryService; 5 import com.topdraw.business.module.coupon.history.service.CouponHistoryService;
6 import com.topdraw.business.module.coupon.service.CouponService; 6 import com.topdraw.business.module.coupon.service.CouponService;
7 import com.topdraw.business.module.exp.detail.domain.ExpDetail;
8 import com.topdraw.business.module.member.domain.Member; 7 import com.topdraw.business.module.member.domain.Member;
9 import com.topdraw.business.module.member.service.MemberService; 8 import com.topdraw.business.module.member.service.MemberService;
10 import com.topdraw.business.module.member.service.dto.MemberDTO; 9 import com.topdraw.business.module.member.service.dto.MemberDTO;
...@@ -12,15 +11,16 @@ import com.topdraw.business.process.service.CouponOperationService; ...@@ -12,15 +11,16 @@ import com.topdraw.business.process.service.CouponOperationService;
12 import com.topdraw.business.process.service.member.MemberOperationService; 11 import com.topdraw.business.process.service.member.MemberOperationService;
13 import com.topdraw.business.process.domian.TempCoupon; 12 import com.topdraw.business.process.domian.TempCoupon;
14 import com.topdraw.business.process.service.RightsOperationService; 13 import com.topdraw.business.process.service.RightsOperationService;
14 import com.topdraw.business.RedisKeyConstants;
15 import com.topdraw.util.TimestampUtil; 15 import com.topdraw.util.TimestampUtil;
16 import com.topdraw.utils.RedisUtils; 16 import com.topdraw.utils.RedisUtils;
17 import lombok.extern.slf4j.Slf4j; 17 import lombok.extern.slf4j.Slf4j;
18 import org.springframework.aop.framework.AopContext; 18 import org.springframework.aop.framework.AopContext;
19 import org.springframework.beans.BeanUtils; 19 import org.springframework.beans.BeanUtils;
20 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
21 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
22 23
23 import java.time.LocalDate;
24 import java.time.LocalDateTime; 24 import java.time.LocalDateTime;
25 import java.util.List; 25 import java.util.List;
26 import java.util.Objects; 26 import java.util.Objects;
...@@ -42,6 +42,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -42,6 +42,9 @@ public class CouponOperationServiceImpl implements CouponOperationService {
42 MemberService memberService; 42 MemberService memberService;
43 43
44 @Autowired 44 @Autowired
45 private ThreadPoolTaskExecutor threadPoolTaskExecutor;
46
47 @Autowired
45 private RedisUtils redisUtils; 48 private RedisUtils redisUtils;
46 49
47 // 过期阀值(默认一个月) 50 // 过期阀值(默认一个月)
...@@ -73,7 +76,6 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -73,7 +76,6 @@ public class CouponOperationServiceImpl implements CouponOperationService {
73 } 76 }
74 } 77 }
75 78
76
77 /** 79 /**
78 * 优惠券领取历史记录表 80 * 优惠券领取历史记录表
79 * 81 *
...@@ -92,38 +94,30 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -92,38 +94,30 @@ public class CouponOperationServiceImpl implements CouponOperationService {
92 * @param tempCoupon 账号id 94 * @param tempCoupon 账号id
93 */ 95 */
94 private void refreshMemberCoupon(TempCoupon tempCoupon) { 96 private void refreshMemberCoupon(TempCoupon tempCoupon) {
95 // Long userId = tempCoupon.getUserId();
96 Long memberId = tempCoupon.getMemberId(); 97 Long memberId = tempCoupon.getMemberId();
97 Integer rightsAmount = tempCoupon.getRightsAmount(); 98 Integer rightsAmount = tempCoupon.getRightsAmount();
98 try { 99 try {
99 100 this.redisUtils.doLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString());
100 // 1.历史总优惠券数量 101 // 1.历史总优惠券数量
101 Long historyCouponCount = this.getTotalHistoryCoupon(memberId); 102 Long historyCouponCount = this.couponHistoryService.countByUserId(memberId);
102 // 1.当前总优惠券数量 103 // 1.当前总优惠券数量
103 Long totalCouponCount = this.getTotalCoupon(historyCouponCount, rightsAmount); 104 Long totalCouponCount = (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L);
104 // 2.获取已过期的优惠券数量 105 // 2.获取已过期的优惠券数量
105 Long expireCouponCount = this.getTotalExpireCoupon(memberId); 106 Long expireCouponCount = this.couponHistoryService.countByUserIdAndExpireTimeBefore(memberId, LocalDateTime.now());
106 // 3.即将过期的优惠券数量 107 // 3.即将过期的优惠券数量
107 Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId, EXPIRE_FACTOR_DAY); 108 Long expireSoonCouponCount = this.couponHistoryService.countByUserIdAndExpireTimeBetween(memberId, LocalDateTime.now(),LocalDateTime.now().plusDays(EXPIRE_FACTOR_DAY));
108 // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 109 // 4.当前优惠券数量 = 总优惠券-已过期的优惠券
109 Long currentCoupon = this.getCurrentCoupon(totalCouponCount, expireCouponCount); 110 Long currentCoupon = (Objects.nonNull(totalCouponCount)?totalCouponCount:0L)-(Objects.nonNull(expireCouponCount)?expireCouponCount:0L);
110
111 this.redisUtils.doLock("right::member::id::" + memberId.toString());
112 // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) 111 // 5.更新用户信息(优惠券数量、即将过期的优惠券数量)
113 this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount); 112 this.doUpdateMemberInfo(memberId,currentCoupon,expireSoonCouponCount);
113
114 } catch (Exception e) { 114 } catch (Exception e) {
115 e.printStackTrace(); 115 log.error(e.getMessage());
116 throw e;
117 } finally { 116 } finally {
118 this.redisUtils.doUnLock("right::member::id::" + memberId.toString()); 117 this.redisUtils.doUnLock(RedisKeyConstants.updateCacheCouponByMemberId + memberId.toString());
119 } 118 }
120 } 119 }
121 120
122 private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) {
123 return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L);
124 }
125
126
127 /** 121 /**
128 * 更新当前用户优惠券信息 122 * 更新当前用户优惠券信息
129 * @param memberId 123 * @param memberId
...@@ -134,7 +128,6 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -134,7 +128,6 @@ public class CouponOperationServiceImpl implements CouponOperationService {
134 MemberDTO memberDTO = this.findMemberByMemberId(memberId); 128 MemberDTO memberDTO = this.findMemberByMemberId(memberId);
135 129
136 Member member = new Member(); 130 Member member = new Member();
137 // BeanUtils.copyProperties(memberDTO,member);
138 member.setId(memberDTO.getId()); 131 member.setId(memberDTO.getId());
139 member.setCode(memberDTO.getCode()); 132 member.setCode(memberDTO.getCode());
140 member.setCouponAmount(currentCoupon); 133 member.setCouponAmount(currentCoupon);
...@@ -142,7 +135,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -142,7 +135,10 @@ public class CouponOperationServiceImpl implements CouponOperationService {
142 member.setUpdateTime(TimestampUtil.now()); 135 member.setUpdateTime(TimestampUtil.now());
143 this.memberOperationService.doUpdateMemberCoupon(member); 136 this.memberOperationService.doUpdateMemberCoupon(member);
144 137
138 // ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member);
139 this.threadPoolTaskExecutor.submit(() -> {
145 ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member); 140 ((CouponOperationServiceImpl) AopContext.currentProxy()).asyncMemberCoupon(member);
141 });
146 } 142 }
147 143
148 private MemberDTO findMemberByMemberId(Long memberId) { 144 private MemberDTO findMemberByMemberId(Long memberId) {
...@@ -170,27 +166,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -170,27 +166,7 @@ public class CouponOperationServiceImpl implements CouponOperationService {
170 */ 166 */
171 private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { 167 private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) {
172 LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor); 168 LocalDateTime expireTime = LocalDateTime.now().plusDays(expireFactor);
173 return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),expireTime); 169 return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,LocalDateTime.now(),LocalDateTime.now().plusDays(expireFactor));
174 }
175
176
177 /**
178 * 获取已过期的优惠券数量
179 * @param userId
180 * @return
181 */
182 private Long getTotalExpireCoupon(Long userId) {
183 return this.couponHistoryService.countByUserIdAndExpireTimeBefore(userId, LocalDateTime.now());
184 }
185
186
187 /**
188 * 获取用户领取的总优惠券
189 * @param userId
190 * @return
191 */
192 private Long getTotalHistoryCoupon(Long userId) {
193 return this.couponHistoryService.countByUserId(userId);
194 } 170 }
195 171
196 172
......
...@@ -7,11 +7,11 @@ import com.topdraw.business.module.member.domain.Member; ...@@ -7,11 +7,11 @@ import com.topdraw.business.module.member.domain.Member;
7 import com.topdraw.business.module.member.level.service.MemberLevelService; 7 import com.topdraw.business.module.member.level.service.MemberLevelService;
8 import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO; 8 import com.topdraw.business.module.member.level.service.dto.MemberLevelDTO;
9 import com.topdraw.business.module.member.service.MemberService; 9 import com.topdraw.business.module.member.service.MemberService;
10 import com.topdraw.business.module.member.service.dto.MemberDTO; 10 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
11 import com.topdraw.business.process.service.ExpOperationService; 11 import com.topdraw.business.process.service.ExpOperationService;
12 import com.topdraw.business.process.service.member.MemberOperationService; 12 import com.topdraw.business.process.service.member.MemberOperationService;
13 import com.topdraw.business.process.domian.TempExp; 13 import com.topdraw.business.process.domian.TempExp;
14 import com.topdraw.util.IdWorker; 14 import com.topdraw.business.RedisKeyConstants;
15 import com.topdraw.util.TimestampUtil; 15 import com.topdraw.util.TimestampUtil;
16 import com.topdraw.utils.RedisUtils; 16 import com.topdraw.utils.RedisUtils;
17 import com.topdraw.utils.StringUtils; 17 import com.topdraw.utils.StringUtils;
...@@ -19,11 +19,12 @@ import lombok.extern.slf4j.Slf4j; ...@@ -19,11 +19,12 @@ import lombok.extern.slf4j.Slf4j;
19 import org.springframework.aop.framework.AopContext; 19 import org.springframework.aop.framework.AopContext;
20 import org.springframework.beans.BeanUtils; 20 import org.springframework.beans.BeanUtils;
21 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
22 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
23 import org.springframework.util.CollectionUtils;
24 24
25 import java.util.List; 25 import java.util.List;
26 import java.util.Objects; 26 import java.util.Objects;
27 import java.util.UUID;
27 28
28 /** 29 /**
29 * 30 *
...@@ -42,6 +43,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -42,6 +43,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
42 MemberService memberService; 43 MemberService memberService;
43 44
44 @Autowired 45 @Autowired
46 private ThreadPoolTaskExecutor threadPoolTaskExecutor;
47
48 @Autowired
45 private RedisUtils redisUtils; 49 private RedisUtils redisUtils;
46 50
47 @AsyncMqSend 51 @AsyncMqSend
...@@ -51,73 +55,46 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -51,73 +55,46 @@ public class ExpOperationServiceImpl implements ExpOperationService {
51 55
52 @Override 56 @Override
53 public void grantExpThroughTempExp(List<TempExp> tempExpList) { 57 public void grantExpThroughTempExp(List<TempExp> tempExpList) {
54 for (TempExp tempExp : tempExpList) { 58 this.refresh(tempExpList);
55 this.refresh(tempExp);
56 }
57 } 59 }
58 60
59 @Override
60 public void grantExpByManual(Long memberId, Long userId, List<TempExp> tempExpList) {
61 for (TempExp tempExp : tempExpList) {
62 this.refresh(tempExp);
63 }
64 }
65 61
66 @Override 62 @Override
67 public void grantExpByManual(List<TempExp> tempExpList) { 63 public void grantExpByManual(List<TempExp> tempExpList) {
68 for (TempExp tempExp : tempExpList) { 64 this.refresh(tempExpList);
69 this.refresh(tempExp);
70 }
71 } 65 }
72 66
73 /** 67 /**
74 * 68 *
75 * @param tempExp 69 * @param tempExps
76 */ 70 */
77 private void refresh(TempExp tempExp) { 71 private void refresh(List<TempExp> tempExps) {
72
73 TempExp _tempExp = tempExps.get(0);
74
78 try { 75 try {
76 this.redisUtils.doLock(RedisKeyConstants.updateCacheExpByMemberId + _tempExp.getMemberId());
79 77
80 // 原始经验值 78 // 原始经验值
81 long originExp = this.getExpByMemberId(tempExp); 79 long originExp = this.memberService.findExpByMemberId(_tempExp.getMemberId());
82 log.info("----获取会员当前原始经验值 ==>> {}", originExp); 80 log.info("----获取会员当前原始经验值 ==>> {}", originExp);
81
82 long totalExp = originExp;
83 for (TempExp exp : tempExps) {
83 // 总经验值 84 // 总经验值
84 long totalExp = this.calculateTotalExp(originExp, tempExp); 85 totalExp = this.doInsertExpDetail(exp, totalExp, (exp.getRewardExp()+totalExp));
85 log.info("----计算总经验值 ==>> {}", totalExp); 86 log.info("----保存经验值历史 -->>{}", totalExp);
87 }
86 88
87 this.redisUtils.doLock("right::member::id::" + tempExp.getMemberId());
88 // 2.更新成长值与等级 89 // 2.更新成长值与等级
90 this.refreshMemberExpAndLevel(_tempExp, totalExp);
89 log.info("----更新会员经验值与对应等级 ==>> {}", totalExp); 91 log.info("----更新会员经验值与对应等级 ==>> {}", totalExp);
90 this.refreshMemberExpAndLevel(tempExp, totalExp);
91
92 log.info("----保存经验值历史 ");
93 this.doInsertExpDetail(tempExp, originExp, totalExp);
94 92
95 } catch (Exception e) { 93 } catch (Exception e) {
96 e.printStackTrace(); 94 log.error("成长值发放失败,{}",e.getMessage());
97 throw e;
98 } finally { 95 } finally {
99 this.redisUtils.doUnLock("right::member::id::" + tempExp.getMemberId()); 96 this.redisUtils.doUnLock(RedisKeyConstants.updateCacheExpByMemberId + _tempExp.getMemberId());
100 }
101 }
102
103 private long calculateTotalExp(long originalExp, TempExp tempExp) {
104 Long rewardExp = tempExp.getRewardExp();
105 return rewardExp + originalExp;
106 }
107
108 /**
109 *
110 * @param tempExp
111 * @return
112 */
113 private long getExpByMemberId(TempExp tempExp) {
114 Long memberId = tempExp.getMemberId();
115 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
116 if (Objects.nonNull(memberDTO)) {
117 Long exp = memberDTO.getExp();
118 return Objects.isNull(exp) ? 0L : exp;
119 } 97 }
120 return 0L;
121 } 98 }
122 99
123 /** 100 /**
...@@ -125,73 +102,48 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -125,73 +102,48 @@ public class ExpOperationServiceImpl implements ExpOperationService {
125 * 102 *
126 * @param tempExp 成长值列表 103 * @param tempExp 成长值列表
127 */ 104 */
128 private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { 105 private void refreshMemberExpAndLevel(TempExp tempExp, long totalExp) {
129 106
107 Integer memberLevel = tempExp.getMemberLevel();
130 Long memberId = tempExp.getMemberId(); 108 Long memberId = tempExp.getMemberId();
131 // 1.获取当前成长值 109 String memberCode = tempExp.getMemberCode();
132 MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId);
133 // 2.获取下一级需要的成长值 110 // 2.获取下一级需要的成长值
134 MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); 111 MemberLevelDTO memberLevelDTO = this.memberLevelService.findByLevel(memberLevel + 1);
135 // 4.成长值比较,判断是否升级 112 // 4.成长值比较,判断是否升级
136 Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); 113 Integer level = this.compareExp(totalExp, memberLevelDTO, memberLevel);
137 // 5.更新用户信息
138 this.updateMemberInfo(level, totalExp, memberId);
139 }
140
141 /**
142 *
143 * @param level
144 * @param totalExp 总积分
145 * @param memberId 会员id
146 */
147 private void updateMemberInfo(Integer level,Long totalExp,Long memberId) {
148 MemberDTO memberDTO = this.findMemberByMemberId(memberId);
149 114
115 // 5.更新用户信息
150 Member member = new Member(); 116 Member member = new Member();
151 // BeanUtils.copyProperties(memberDTO, member); 117 member.setId(memberId);
152 member.setId(memberDTO.getId()); 118 member.setCode(memberCode);
153 member.setCode(memberDTO.getCode());
154 member.setExp(totalExp); 119 member.setExp(totalExp);
155 member.setLevel(level); 120 member.setLevel(level);
156 member.setUpdateTime(TimestampUtil.now()); 121 member.setUpdateTime(TimestampUtil.now());
157 this.memberOperationService.doUpdateMemberExpAndLevel(member); 122 this.memberOperationService.doUpdateMemberExpAndLevel(member);
158 123
159 ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member); 124 ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncMemberExpAndLevel(member);
125
126 if (level > memberLevel) {
127 MemberSimpleDTO memberSimpleDTO = this.memberService.findSimpleById(memberId);
128 if (Objects.nonNull(memberLevelDTO.getId())) {
129 memberSimpleDTO.setLevel(level);
130 boolean result = this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + memberId, memberSimpleDTO);
131 log.info("更新redis中会员等级 ==>> {} || 更新结果 ==>>{}", memberSimpleDTO, result);
132
133 }
160 } 134 }
161 135
162 private MemberDTO findMemberByMemberId(Long memberId) {
163 MemberDTO memberDTO = this.memberService.findById(memberId);
164 return memberDTO;
165 } 136 }
166 137
167 private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO,MemberDTO memberDTO) { 138 private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO, Integer oldMemberLevel) {
168 if (Objects.nonNull(memberLevelDTO)) { 139 if (Objects.nonNull(memberLevelDTO.getId())) {
169 Long nextLevelExp = memberLevelDTO.getExpValue(); 140 Long nextLevelExp = memberLevelDTO.getExpValue();
170 if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) 141 if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0)
171 if(newExp - nextLevelExp >= 0){ 142 if(newExp - nextLevelExp >= 0){
172 return memberLevelDTO.getLevel(); 143 return memberLevelDTO.getLevel();
173 } 144 }
174 } 145 }
175 return memberDTO.getLevel(); 146 return oldMemberLevel;
176 }
177
178 private MemberLevelDTO getNextLevelExp(Integer i,Integer status) {
179 List<MemberLevelDTO> memberLevelDTOList = this.memberLevelService.findLevelAndStatus(i,status);
180 if (!CollectionUtils.isEmpty(memberLevelDTOList)) {
181 return memberLevelDTOList.get(0);
182 }
183 return null;
184 }
185
186
187 /**
188 * 获取当前会员的成长值
189 * @param memberId 会员id
190 * @return Long 当前会员成长值
191 */
192 private MemberDTO getMemberInfoByMemberId(Long memberId) {
193 MemberDTO memberDTO = this.memberOperationService.findById(memberId);
194 return memberDTO;
195 } 147 }
196 148
197 /** 149 /**
...@@ -199,14 +151,13 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -199,14 +151,13 @@ public class ExpOperationServiceImpl implements ExpOperationService {
199 * 151 *
200 * @param tempExp 成长值列表 152 * @param tempExp 成长值列表
201 */ 153 */
202 private void doInsertExpDetail(TempExp tempExp,long originalExp,long totalExp) { 154 private long doInsertExpDetail(TempExp tempExp, long originalExp, long totalExp) {
203 // 获得的积分 155 // 获得的积分
204 Long rewardExp = tempExp.getRewardExp(); 156 Long rewardExp = tempExp.getRewardExp();
205 157
206 ExpDetail expDetail = new ExpDetail(); 158 ExpDetail expDetail = new ExpDetail();
207 BeanUtils.copyProperties(tempExp,expDetail); 159 BeanUtils.copyProperties(tempExp, expDetail);
208 160 expDetail.setCode("expD_"+UUID.randomUUID().toString());
209 expDetail.setCode(String.valueOf(IdWorker.generator()));
210 // 原始积分 161 // 原始积分
211 expDetail.setOriginalExp(originalExp); 162 expDetail.setOriginalExp(originalExp);
212 // 总积分 163 // 总积分
...@@ -218,8 +169,9 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -218,8 +169,9 @@ public class ExpOperationServiceImpl implements ExpOperationService {
218 } 169 }
219 this.expDetailService.create(expDetail); 170 this.expDetailService.create(expDetail);
220 171
221
222 ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail); 172 ((ExpOperationServiceImpl) AopContext.currentProxy()).asyncExpDetail(expDetail);
173
174 return totalExp;
223 } 175 }
224 176
225 } 177 }
......
...@@ -8,24 +8,19 @@ import com.topdraw.business.module.member.service.dto.MemberDTO; ...@@ -8,24 +8,19 @@ import com.topdraw.business.module.member.service.dto.MemberDTO;
8 import com.topdraw.business.module.points.available.domain.PointsAvailable; 8 import com.topdraw.business.module.points.available.domain.PointsAvailable;
9 import com.topdraw.business.module.points.available.service.PointsAvailableService; 9 import com.topdraw.business.module.points.available.service.PointsAvailableService;
10 import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; 10 import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO;
11 import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService;
12 import com.topdraw.business.module.points.detail.domain.PointsDetail; 11 import com.topdraw.business.module.points.detail.domain.PointsDetail;
13 import com.topdraw.business.module.points.detail.service.PointsDetailService; 12 import com.topdraw.business.module.points.detail.service.PointsDetailService;
14 import com.topdraw.business.module.points.service.PointsService;
15 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
16 import com.topdraw.business.process.service.dto.CustomPointsResult; 13 import com.topdraw.business.process.service.dto.CustomPointsResult;
17 import com.topdraw.business.process.service.member.MemberOperationService; 14 import com.topdraw.business.process.service.member.MemberOperationService;
18 import com.topdraw.business.process.service.PointsOperationService; 15 import com.topdraw.business.process.service.PointsOperationService;
19 import com.topdraw.business.process.domian.TempPoints; 16 import com.topdraw.business.process.domian.TempPoints;
17 import com.topdraw.business.RedisKeyConstants;
20 import com.topdraw.util.DateUtil; 18 import com.topdraw.util.DateUtil;
21 import com.topdraw.util.IdWorker; 19 import com.topdraw.util.IdWorker;
22 import com.topdraw.util.TimestampUtil; 20 import com.topdraw.util.TimestampUtil;
23 import com.topdraw.utils.RedisUtils; 21 import com.topdraw.utils.RedisUtils;
24 import com.topdraw.utils.StringUtils; 22 import com.topdraw.utils.StringUtils;
25 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
26 import org.apache.commons.lang3.time.DateUtils;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.aop.framework.AopContext; 24 import org.springframework.aop.framework.AopContext;
30 import org.springframework.beans.BeanUtils; 25 import org.springframework.beans.BeanUtils;
31 import org.springframework.beans.factory.annotation.Autowired; 26 import org.springframework.beans.factory.annotation.Autowired;
...@@ -36,10 +31,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -36,10 +31,7 @@ import org.springframework.transaction.annotation.Transactional;
36 import org.springframework.util.CollectionUtils; 31 import org.springframework.util.CollectionUtils;
37 32
38 import java.sql.Timestamp; 33 import java.sql.Timestamp;
39 import java.time.LocalDateTime;
40 import java.util.*; 34 import java.util.*;
41 import java.util.concurrent.TimeUnit;
42 import java.util.stream.Collectors;
43 35
44 /** 36 /**
45 * 37 *
...@@ -50,22 +42,19 @@ import java.util.stream.Collectors; ...@@ -50,22 +42,19 @@ import java.util.stream.Collectors;
50 public class PointsOperationServiceImpl implements PointsOperationService { 42 public class PointsOperationServiceImpl implements PointsOperationService {
51 43
52 @Autowired 44 @Autowired
53 private PointsService pointsService;
54 @Autowired
55 private PointsDetailService pointsDetailService; 45 private PointsDetailService pointsDetailService;
56 @Autowired 46 @Autowired
57 private PointsAvailableService pointsAvailableService; 47 private PointsAvailableService pointsAvailableService;
58 @Autowired 48 @Autowired
59 private PointsDetailHistoryService pointsDetailHistoryService;
60 @Autowired
61 private MemberOperationService memberOperationService; 49 private MemberOperationService memberOperationService;
62 @Autowired 50 @Autowired
63 private MemberService memberService; 51 private MemberService memberService;
64 52
65 @Autowired 53 @Autowired
66 private RedisUtils redisUtils; 54 private ThreadPoolTaskExecutor threadPoolTaskExecutor;
55
67 @Autowired 56 @Autowired
68 ThreadPoolTaskExecutor threadPoolTaskExecutor; 57 private RedisUtils redisUtils;
69 58
70 // 过期阈值 30天 59 // 过期阈值 30天
71 private static final Integer EXPIRE_FACTOR = 30; 60 private static final Integer EXPIRE_FACTOR = 30;
...@@ -82,26 +71,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -82,26 +71,18 @@ public class PointsOperationServiceImpl implements PointsOperationService {
82 @AsyncMqSend 71 @AsyncMqSend
83 public void asyncPointsDetail(PointsDetail pointsDetail) {} 72 public void asyncPointsDetail(PointsDetail pointsDetail) {}
84 73
85 @Override 74 /**
86 @Transactional(rollbackFor = Exception.class) 75 * uc-admin调用此接口进行发放积分
87 public void grantPointsByManual(Long memberId, TempPoints tempPoints){ 76 * @param tempPoints
88 if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { 77 */
89 MemberDTO memberDTo = this.memberService.findById(memberId);
90 String memberCode = memberDTo.getCode();
91 tempPoints.setMemberCode(memberCode);
92 this.refresh(tempPoints);
93 }
94 }
95
96 @Override 78 @Override
97 public void grantPointsByManualByTempPoints(TempPoints tempPoints) { 79 public void grantPointsByManualByTempPoints(TempPoints tempPoints) {
98 if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) {
99 Timestamp expireTime = tempPoints.getExpireTime(); 80 Timestamp expireTime = tempPoints.getExpireTime();
100 if (Objects.isNull(expireTime)){ 81 if (Objects.isNull(expireTime)){
101 tempPoints.setExpireTime(TimestampUtil.localDateTime2Timestamp(DateUtil.getLastDateTimeSecondYear())); 82 tempPoints.setExpireTime(TimestampUtil.localDateTime2Timestamp(DateUtil.getLastDateTimeSecondYear()));
102 } 83 }
103 this.refresh(tempPoints); 84
104 } 85 this.refresh(Arrays.asList(tempPoints));
105 } 86 }
106 87
107 /** 88 /**
...@@ -118,7 +99,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -118,7 +99,9 @@ public class PointsOperationServiceImpl implements PointsOperationService {
118 Long memberId = tempPoints.getMemberId(); 99 Long memberId = tempPoints.getMemberId();
119 100
120 try { 101 try {
121 this.redisUtils.doLock("member::id::" + memberId.toString()); 102 this.redisUtils.doLock(RedisKeyConstants.cacheMemberById + memberId.toString());
103 MemberDTO memberDTO = this.memberService.findById(memberId);
104
122 //1.删除过期的积分 105 //1.删除过期的积分
123 this.cleanInvalidAvailablePointsByMemberId(memberId); 106 this.cleanInvalidAvailablePointsByMemberId(memberId);
124 log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> "); 107 log.info("删除过期的积分 ==>> cleanInvalidAvailablePointsByMemberId ==>> ");
...@@ -128,7 +111,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -128,7 +111,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
128 long currentPoints = this.findAvailablePointsByMemberId(memberId); 111 long currentPoints = this.findAvailablePointsByMemberId(memberId);
129 if (b) { 112 if (b) {
130 // 2.可用积分表,按照过期时间进行升序排列 113 // 2.可用积分表,按照过期时间进行升序排列
131 List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints); 114 List<PointsAvailableDTO> pointsAvailableDTOS = this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId());
132 // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 115 // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分
133 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = 116 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap =
134 this.customAvailablePoints(tempPoints, pointsAvailableDTOS); 117 this.customAvailablePoints(tempPoints, pointsAvailableDTOS);
...@@ -138,11 +121,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -138,11 +121,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
138 // 4.更新可用积分表,超过的删除,剩余的新增 121 // 4.更新可用积分表,超过的删除,剩余的新增
139 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); 122 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints);
140 // 5.即将过期的积分 123 // 5.即将过期的积分
141 long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); 124 // long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
142
143 125
144 // 6.更新会员积分信息 126 // 6.更新会员积分信息
145 this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints); 127 this.freshMemberCurrentPoints(memberId, memberDTO.getCode(), totalPoints);
146 128
147 customPointsResult.setResult(true); 129 customPointsResult.setResult(true);
148 customPointsResult.setPoint(totalPoints); 130 customPointsResult.setPoint(totalPoints);
...@@ -153,11 +135,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -153,11 +135,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
153 customPointsResult.setPoint(currentPoints); 135 customPointsResult.setPoint(currentPoints);
154 } 136 }
155 137
156 }catch (Exception e) { 138 } catch (Exception e) {
157 e.printStackTrace(); 139 log.error("消耗积分失败,"+e.getMessage());
158 throw e;
159 } finally { 140 } finally {
160 this.redisUtils.doUnLock("member::id::" + memberId.toString()); 141 this.redisUtils.doUnLock(RedisKeyConstants.cacheMemberById + memberId.toString());
161 } 142 }
162 143
163 return customPointsResult; 144 return customPointsResult;
...@@ -211,6 +192,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -211,6 +192,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
211 long currentPoints) { 192 long currentPoints) {
212 // 兑换的积分 193 // 兑换的积分
213 Long points = tempPoints.getPoints(); 194 Long points = tempPoints.getPoints();
195 String memberCode = tempPoints.getMemberCode();
214 196
215 List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS); 197 List<PointsAvailableDTO> pointsAvailableDTOS = customAvailablePointsMap.get(DELETE_AVAILABLE_POINTS);
216 198
...@@ -222,9 +204,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -222,9 +204,9 @@ public class PointsOperationServiceImpl implements PointsOperationService {
222 BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints); 204 BeanUtils.copyProperties(pointsAvailableDTO, _tempPoints);
223 BeanUtils.copyProperties(tempPoints, _tempPoints); 205 BeanUtils.copyProperties(tempPoints, _tempPoints);
224 _tempPoints.setPoints(-(Math.abs(points))); 206 _tempPoints.setPoints(-(Math.abs(points)));
225 Long totalPoints = this.calculateTotalPoints(_tempPoints, currentPoints); 207 Long totalPoints = currentPoints + tempPoints.getPoints();
226 208
227 this.doInsertTrPointsDetail(memberId, _tempPoints, currentPoints, totalPoints); 209 this.doInsertTrPointsDetail(memberId, memberCode, _tempPoints, currentPoints, totalPoints);
228 } 210 }
229 } 211 }
230 212
...@@ -288,14 +270,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -288,14 +270,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
288 return map; 270 return map;
289 } 271 }
290 272
291 /**
292 * 可用积分表,按照过期时间进行升序排列
293 * @param tempPoints
294 * @return
295 */
296 private List<PointsAvailableDTO> findByMemberIdOrderByExpireTime(TempPoints tempPoints) {
297 return this.pointsAvailableService.findByMemberIdOrderByExpireTime(tempPoints.getMemberId());
298 }
299 273
300 /** 274 /**
301 * 检查当前用户可用积分是否足够 275 * 检查当前用户可用积分是否足够
...@@ -321,9 +295,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -321,9 +295,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
321 @Override 295 @Override
322 @Transactional(rollbackFor = Exception.class) 296 @Transactional(rollbackFor = Exception.class)
323 public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){ 297 public void grantPointsThroughTempPoint(List<TempPoints> tempPointsList){
324 for (TempPoints tempPoints : tempPointsList){ 298 this.refresh(tempPointsList);
325 this.refresh(tempPoints);
326 }
327 } 299 }
328 300
329 /** 301 /**
...@@ -385,7 +357,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -385,7 +357,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
385 357
386 member.setPoints(currentPoints); 358 member.setPoints(currentPoints);
387 member.setDuePoints(soonExpirePoints); 359 member.setDuePoints(soonExpirePoints);
388 // this.memberOperationService.update(member);
389 this.memberOperationService.doUpdateMemberPoints(member); 360 this.memberOperationService.doUpdateMemberPoints(member);
390 } 361 }
391 362
...@@ -429,7 +400,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -429,7 +400,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
429 pointsDetail.setCreateTime(TimestampUtil.now()); 400 pointsDetail.setCreateTime(TimestampUtil.now());
430 pointsDetail.setUpdateTime(TimestampUtil.now()); 401 pointsDetail.setUpdateTime(TimestampUtil.now());
431 pointsDetail.setMemberCode(memberDTO.getCode()); 402 pointsDetail.setMemberCode(memberDTO.getCode());
432 this.pointsDetailService.create4Custom(pointsDetail); 403 this.pointsDetailService.insertPointsDetail(pointsDetail);
433 404
434 log.info("asyncPointsDetail ==>> pointsDetail ==>> {}",pointsDetail); 405 log.info("asyncPointsDetail ==>> pointsDetail ==>> {}",pointsDetail);
435 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); 406 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail);
...@@ -438,60 +409,44 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -438,60 +409,44 @@ public class PointsOperationServiceImpl implements PointsOperationService {
438 /** 409 /**
439 * 模板方法,提供更新积分的总体流程 410 * 模板方法,提供更新积分的总体流程
440 * 411 *
441 * @param tempPoints 积分 412 * @param tempPointsList 积分
442 */ 413 */
443 414 private void refresh(List<TempPoints> tempPointsList) {
444 private void refresh(TempPoints tempPoints) { 415 TempPoints tempPoints = tempPointsList.get(0);
445 Long memberId = tempPoints.getMemberId(); 416 Long memberId = tempPoints.getMemberId();
446 log.info("----------->> 会员id ===>>>>" + memberId); 417 String memberCode = tempPoints.getMemberCode();
447 try { 418 try {
419 this.redisUtils.doLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString());
448 420
449 // 1.可用总积分 421 // 1.可用总积分
450 Long currentPoints = this.findAvailablePointsByMemberId(memberId); 422 Long currentPoints = this.findAvailablePointsByMemberId(memberId);
451 log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints); 423 log.info("----------->> 获取会员当前可用总积分 --->>>> {}", currentPoints);
452 424
453 // 2.计算总积分 425 Long totalPoints = currentPoints;
454 Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); 426 for (TempPoints tempPoint : tempPointsList) {
455 log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints);
456
457 // 3.添加积分明细 427 // 3.添加积分明细
458 this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); 428 totalPoints = this.doInsertTrPointsDetail(memberId, memberCode, tempPoint, totalPoints, (totalPoints + tempPoint.getPoints()));
459 log.info("----------->> 添加积分明细 --->>> "); 429 log.info("----------->> 总积分(可用总积分+获得的积分) --->>> {}", totalPoints);
460 430
461 // 4.添加可用积分 431 // 4.添加可用积分
462 this.doInsertTrPointsAvailable(tempPoints); 432 this.doInsertTrPointsAvailable(tempPoint);
463 log.info("----------->> 添加可用积分 -->>> "); 433 log.info("----------->> 添加可用积分结束");
464 434
465 // 5.即将过期的积分 435 }
466 long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
467 log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints);
468 436
469 this.redisUtils.doLock("right::member::id::" + memberId.toString()); 437 // 5.即将过期的积分
438 // TODO 查询的时候再更新过期积分
439 // long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
440 // log.info("----------->> 即将过期的积分 ------->>>>> {}", soonExpirePoints);
470 441
471 // 6.更新会员的总积分 442 // 6.更新会员的总积分
443 this.freshMemberCurrentPoints(memberId, memberCode, totalPoints);
472 log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints); 444 log.info("----------->> 更新会员的总积分 ------->>>>> 总积分--->>> {}", totalPoints);
473 this.freshMemberCurrentPoints(memberId, totalPoints, soonExpirePoints);
474
475 } catch (Exception e) { 445 } catch (Exception e) {
476 e.printStackTrace(); 446 log.error(" ==>> {}", e.getMessage());
477 throw e;
478 } finally { 447 } finally {
479 this.redisUtils.doUnLock("right::member::id::" + memberId.toString()); 448 this.redisUtils.doUnLock(RedisKeyConstants.updateCachePointsByMemberId + memberId.toString());
480 }
481 } 449 }
482
483 /**
484 * 获取总积分
485 * @param tempPoints
486 * @param currentPoints
487 * @return
488 */
489 private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) {
490 // 获取的积分
491 Long rewardPoints = tempPoints.getPoints();
492 // 总积分
493 Long totalPoints = currentPoints + rewardPoints;
494 return totalPoints;
495 } 450 }
496 451
497 /** 452 /**
...@@ -523,33 +478,23 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -523,33 +478,23 @@ public class PointsOperationServiceImpl implements PointsOperationService {
523 /** 478 /**
524 * 更新会员总积分 479 * 更新会员总积分
525 * @param memberId 会员Id 480 * @param memberId 会员Id
526 * @param currentPoints 当前总积分 481 * @param memberCode 当前总积分
527 */ 482 */
528 private void freshMemberCurrentPoints(Long memberId, Long currentPoints, long duePoints) { 483 private void freshMemberCurrentPoints(Long memberId, String memberCode, Long currentPoints) {
529
530 MemberDTO memberDTO = this.findMemberByMemberId(memberId);
531
532 Member member = new Member(); 484 Member member = new Member();
533 // BeanUtils.copyProperties(memberDTO, member); 485 member.setId(memberId);
534 member.setId(memberDTO.getId()); 486 member.setCode(memberCode);
535 member.setCode(memberDTO.getCode());
536 member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0); 487 member.setPoints(Objects.nonNull(currentPoints) ? currentPoints:0);
537 member.setDuePoints(duePoints);
538 member.setUpdateTime(TimestampUtil.now()); 488 member.setUpdateTime(TimestampUtil.now());
539 try { 489 try {
540 this.memberOperationService.doUpdateMemberPoints(member); 490 this.memberOperationService.doUpdateMemberPoints(member);
541 491
542 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member); 492 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncMemberPoint(member);
543 } catch (Exception e){ 493 } catch (Exception e){
544 throw e; 494 log.error("同步会员积分异常,"+e.getMessage());
545 } 495 }
546 } 496 }
547 497
548 private MemberDTO findMemberByMemberId(Long memberId) {
549 MemberDTO memberDTO = this.memberService.findById(memberId);
550 return memberDTO;
551 }
552
553 /** 498 /**
554 * 更新可用积分表 499 * 更新可用积分表
555 * @param tempPoints 500 * @param tempPoints
...@@ -560,7 +505,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -560,7 +505,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
560 BeanUtils.copyProperties(tempPoints,pointsAvailable); 505 BeanUtils.copyProperties(tempPoints,pointsAvailable);
561 506
562 String description = pointsAvailable.getDescription(); 507 String description = pointsAvailable.getDescription();
563 pointsAvailable.setCode(String.valueOf(IdWorker.generator())); 508 pointsAvailable.setCode("pointsA_"+UUID.randomUUID().toString());
564 pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description); 509 pointsAvailable.setDescription(StringUtils.isEmpty(description)?"#":description);
565 Timestamp timestamp = tempPoints.getExpireTime(); 510 Timestamp timestamp = tempPoints.getExpireTime();
566 if (Objects.nonNull(timestamp)) { 511 if (Objects.nonNull(timestamp)) {
...@@ -570,6 +515,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -570,6 +515,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
570 this.pointsAvailableService.create4Custom(pointsAvailable); 515 this.pointsAvailableService.create4Custom(pointsAvailable);
571 516
572 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable); 517 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsAvailable(pointsAvailable);
518
573 } 519 }
574 520
575 /** 521 /**
...@@ -578,30 +524,36 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -578,30 +524,36 @@ public class PointsOperationServiceImpl implements PointsOperationService {
578 * @param tempPoints 积分 524 * @param tempPoints 积分
579 * @return Integer 总积分 525 * @return Integer 总积分
580 */ 526 */
581 private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints, Long currentPoints, Long totalPoints){ 527 private Long doInsertTrPointsDetail(Long memberId, String memberCode, TempPoints tempPoints, Long currentPoints, Long totalPoints){
582
583 MemberDTO memberDTO = this.memberService.findById(memberId);
584 528
585 PointsDetail pointsDetail = new PointsDetail(); 529 PointsDetail pointsDetail = new PointsDetail();
586 BeanUtils.copyProperties(tempPoints, pointsDetail);
587 pointsDetail.setId(null); 530 pointsDetail.setId(null);
588 pointsDetail.setMemberId(memberId); 531 pointsDetail.setMemberId(memberId);
589 pointsDetail.setMemberCode(memberDTO.getCode()); 532 pointsDetail.setMemberCode(memberCode);
590 pointsDetail.setCode(String.valueOf(IdWorker.generator())); 533 pointsDetail.setCode("pointsD_"+UUID.randomUUID().toString());
591 pointsDetail.setPoints(tempPoints.getPoints()); 534 pointsDetail.setPoints(tempPoints.getPoints());
592 pointsDetail.setOriginalPoints(currentPoints); 535 pointsDetail.setOriginalPoints(currentPoints);
593 pointsDetail.setResultPoints(totalPoints); 536 pointsDetail.setResultPoints(totalPoints);
594 pointsDetail.setCreateTime(null); 537 pointsDetail.setEvtType(tempPoints.getEvtType());
595 pointsDetail.setUpdateTime(null); 538 pointsDetail.setDeviceType(tempPoints.getDeviceType());
596 String description = pointsDetail.getDescription(); 539 pointsDetail.setOrderId(tempPoints.getOrderId());
540 pointsDetail.setMediaId(tempPoints.getMediaId());
541 pointsDetail.setAccountId(tempPoints.getAccountId());
542 pointsDetail.setActivityId(tempPoints.getActivityId());
543 pointsDetail.setAppCode(tempPoints.getAppCode());
544 String description = tempPoints.getDescription();
597 if (StringUtils.isEmpty(description)) { 545 if (StringUtils.isEmpty(description)) {
598 pointsDetail.setDescription("#"); 546 pointsDetail.setDescription("#");
547 }else {
548 pointsDetail.setDescription(description);
599 } 549 }
600 550
601 // 保存积分流水 551 // 保存积分流水
602 this.pointsDetailService.create4Custom(pointsDetail); 552 this.pointsDetailService.insertPointsDetail(pointsDetail);
603 553
604 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail); 554 ((PointsOperationServiceImpl) AopContext.currentProxy()).asyncPointsDetail(pointsDetail);
555
556 return totalPoints;
605 } 557 }
606 558
607 } 559 }
......
...@@ -6,7 +6,8 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory; ...@@ -6,7 +6,8 @@ import com.topdraw.business.module.rights.history.domain.RightsHistory;
6 import com.topdraw.business.module.rights.history.service.RightsHistoryService; 6 import com.topdraw.business.module.rights.history.service.RightsHistoryService;
7 import com.topdraw.business.module.rights.service.RightsService; 7 import com.topdraw.business.module.rights.service.RightsService;
8 import com.topdraw.business.module.rights.service.dto.RightsDTO; 8 import com.topdraw.business.module.rights.service.dto.RightsDTO;
9 import com.topdraw.business.process.domian.constant.RightType; 9 import com.topdraw.business.module.rights.constant.RightType;
10 import com.topdraw.business.module.rights.constant.RightTypeConstants;
10 import com.topdraw.business.process.service.CouponOperationService; 11 import com.topdraw.business.process.service.CouponOperationService;
11 import com.topdraw.business.process.service.ExpOperationService; 12 import com.topdraw.business.process.service.ExpOperationService;
12 import com.topdraw.business.process.service.PointsOperationService; 13 import com.topdraw.business.process.service.PointsOperationService;
...@@ -14,8 +15,6 @@ import com.topdraw.business.process.service.RightsOperationService; ...@@ -14,8 +15,6 @@ import com.topdraw.business.process.service.RightsOperationService;
14 import com.topdraw.business.process.domian.*; 15 import com.topdraw.business.process.domian.*;
15 import com.topdraw.util.TimestampUtil; 16 import com.topdraw.util.TimestampUtil;
16 import lombok.extern.slf4j.Slf4j; 17 import lombok.extern.slf4j.Slf4j;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 19 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
21 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
...@@ -24,7 +23,6 @@ import org.springframework.util.StringUtils; ...@@ -24,7 +23,6 @@ import org.springframework.util.StringUtils;
24 23
25 import java.sql.Timestamp; 24 import java.sql.Timestamp;
26 import java.util.*; 25 import java.util.*;
27 import java.util.concurrent.ThreadPoolExecutor;
28 26
29 /** 27 /**
30 * 权益处理 28 * 权益处理
...@@ -73,30 +71,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -73,30 +71,9 @@ public class RightsOperationServiceImpl implements RightsOperationService {
73 * @param tempRightsMap 权益类型 71 * @param tempRightsMap 权益类型
74 */ 72 */
75 @Override 73 @Override
76 public void grantRights(Map<RightType, Object> tempRightsMap) { 74 public Integer grantRights(Map<RightType, Object> tempRightsMap) {
77 75
78 this.threadPoolTaskExecutor.execute(()-> {
79 // 2.创建权益历史对象
80 List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap);
81 if (!CollectionUtils.isEmpty(rightsList)) {
82 log.info("异步保存权益领取历史开始 ==>> [{}]", rightsList);
83 // 3.保存权益历史
84 this.doInsertTrRightHistory(rightsList);
85 }
86 });
87
88 // 1.权益下发
89 this.refresh(tempRightsMap);
90 }
91
92 /**
93 *
94 * @param tempRightsMap
95 * @return
96 */
97 private List<RightsHistory> getRightHistory(Map<RightType, Object> tempRightsMap) {
98 List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS); 76 List<TempRights> values = (List<TempRights>)tempRightsMap.get(RightType.RIGHTS);
99 List<RightsHistory> rightsHistoryList = new ArrayList<>();
100 if (!CollectionUtils.isEmpty(values)) { 77 if (!CollectionUtils.isEmpty(values)) {
101 values.forEach(value -> { 78 values.forEach(value -> {
102 RightsHistory rightsHistory = new RightsHistory(); 79 RightsHistory rightsHistory = new RightsHistory();
...@@ -106,11 +83,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -106,11 +83,18 @@ public class RightsOperationServiceImpl implements RightsOperationService {
106 rightsHistory.setExpireTime(value.getExpireTime()); 83 rightsHistory.setExpireTime(value.getExpireTime());
107 String memberCode = value.getMemberCode(); 84 String memberCode = value.getMemberCode();
108 rightsHistory.setMemberCode(memberCode); 85 rightsHistory.setMemberCode(memberCode);
109 rightsHistoryList.add(rightsHistory); 86 Long operatorId = rightsHistory.getOperatorId();
87 String operatorName = rightsHistory.getOperatorName();
88 rightsHistory.setSendTime(TimestampUtil.now());
89 rightsHistory.setOperatorId(Objects.nonNull(operatorId)?operatorId:0);
90 rightsHistory.setOperatorName(!StringUtils.isEmpty(operatorName)?operatorName:"系统发放");
91 this.rightsHistoryService.create(rightsHistory);
110 }); 92 });
111 } 93 }
112 94
113 return rightsHistoryList; 95
96 // 1.权益下发
97 return this.refresh(tempRightsMap);
114 } 98 }
115 99
116 /** 100 /**
...@@ -143,103 +127,34 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -143,103 +127,34 @@ public class RightsOperationServiceImpl implements RightsOperationService {
143 this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); 127 this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList);
144 } 128 }
145 129
130
146 /** 131 /**
147 * 权益发放 132 * 权益发放
148 * @param tempRightsMap 133 * @param tempRightsMap
149 */ 134 */
150 private void refresh(Map<RightType, Object> tempRightsMap) { 135 private Integer refresh(Map<RightType, Object> tempRightsMap) {
151 /*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{
152 log.info(Thread.currentThread().getName() + "=========>> start");
153 // 积分
154 this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
155 log.info(Thread.currentThread().getName() + "=========>>grantPoint end");
156 // 成长值
157 // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
158 // 优惠券
159 // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
160 return null;
161 });
162 FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{
163 // 积分
164 // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
165 // 成长值
166 this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
167 // 优惠券
168 // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
169 return null;
170 });
171 FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{
172 // 积分
173 // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
174 // 成长值
175 // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
176 // 优惠券
177 this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
178 return null;
179 });
180 this.threadPoolTaskExecutor.execute(futureTask1);
181 this.threadPoolTaskExecutor.execute(futureTask2);
182 this.threadPoolTaskExecutor.execute(futureTask3);*/
183 /*this.threadPoolTaskExecutor.execute(() -> {
184 // 积分
185 this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
186 // 成长值
187 this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP));
188 // 优惠券
189 this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON));
190 });*/
191 136
192
193 /*this.threadPoolTaskExecutor.execute(() -> {
194 log.info(Thread.currentThread().getName() + "=========>> start");
195 // 积分
196 this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS));
197 log.info(Thread.currentThread().getName() + "=========>> end");
198 });*/
199 this.threadPoolTaskExecutor.execute(() -> {
200 List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); 137 List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS);
201 if (!CollectionUtils.isEmpty(tempPointsList)) { 138 if (!CollectionUtils.isEmpty(tempPointsList)) {
202 log.info("发放积分开始 ==>> [{}]", tempPointsList);
203 long l = System.currentTimeMillis();
204 // 积分 139 // 积分
140 log.info("发放积分开始 ==>> {}", tempPointsList);
205 this.grantPoint(tempPointsList); 141 this.grantPoint(tempPointsList);
206 long l2 = System.currentTimeMillis(); 142 log.info("发放积分结束 ==>> {}", tempPointsList);
207 log.info("发放积分结束,总耗时 ==>> {}", (l2 - l));
208 } 143 }
209 });
210 144
211 this.threadPoolTaskExecutor.execute(()-> {
212 List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); 145 List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP);
213 if (!CollectionUtils.isEmpty(tempExpList)) { 146 if (!CollectionUtils.isEmpty(tempExpList)) {
214 log.info("发放成长值开始 ==>> [{}]", tempExpList);
215 long l = System.currentTimeMillis();
216 // 成长值 147 // 成长值
148 log.info("发放成长值开始 ==>> {}", tempExpList);
217 this.grantExp(tempExpList); 149 this.grantExp(tempExpList);
218 long l2 = System.currentTimeMillis(); 150 log.info("发放成长值结束 ==>> ");
219 log.info("发放成长值结束,总耗时 ==>> {}", (l2 - l));
220 }
221 });
222
223 this.threadPoolTaskExecutor.execute(()-> {
224 List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON);
225 if (!CollectionUtils.isEmpty(tempCouponList)) {
226 log.info("发放优惠券开始 ==>> [{}]", tempCouponList);
227 long l = System.currentTimeMillis();
228 // 优惠券
229 this.grantCoupon(tempCouponList);
230 long l2 = System.currentTimeMillis();
231 log.info("发放优惠券结束,总耗时 ==>> {}", (l2 - l));
232 } 151 }
233 });
234
235 152
236 // 其他权益 153 // 其他权益
237 this.threadPoolTaskExecutor.execute(()-> {
238 log.info("发放其他权益开始 ==>> [{}]", tempRightsMap);
239 this.grantOtherRight(tempRightsMap); 154 this.grantOtherRight(tempRightsMap);
240 log.info("发放其他权益结束 ==>> [{}]", tempRightsMap); 155 log.info("发放其他权益结束 ==>>" );
241 });
242 156
157 return tempRightsMap.keySet().size();
243 } 158 }
244 159
245 private void grantOtherRight(Map<RightType, Object> tempRightsMap) { 160 private void grantOtherRight(Map<RightType, Object> tempRightsMap) {
...@@ -252,7 +167,7 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -252,7 +167,7 @@ public class RightsOperationServiceImpl implements RightsOperationService {
252 167
253 // 活动机会 168 // 活动机会
254 case ACTIVITYCHANCE: 169 case ACTIVITYCHANCE:
255 170 // TODO MOSS 增加活动机会接口
256 break; 171 break;
257 172
258 // 积分商品 173 // 积分商品
...@@ -296,9 +211,9 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -296,9 +211,9 @@ public class RightsOperationServiceImpl implements RightsOperationService {
296 Long memberId = right.getMemberId(); 211 Long memberId = right.getMemberId();
297 Long userId = right.getUserId(); 212 Long userId = right.getUserId();
298 // 权益类型 213 // 权益类型
299 RightsDTO rightsDTO = this.getRights(rightId); 214 RightsDTO rightsDTO = this.rightsService.findById(rightId);
300 // 权益的实体类型 1:积分;2成长值;3优惠券 215 // 权益的实体类型 1:积分;2成长值;3优惠券
301 String type = rightsDTO.getEntityType(); 216 Integer type = rightsDTO.getEntityType();
302 Long expireTime1 = rightsDTO.getExpireTime(); 217 Long expireTime1 = rightsDTO.getExpireTime();
303 Timestamp expireTime = null; 218 Timestamp expireTime = null;
304 if (Objects.nonNull(expireTime1)){ 219 if (Objects.nonNull(expireTime1)){
...@@ -307,9 +222,10 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -307,9 +222,10 @@ public class RightsOperationServiceImpl implements RightsOperationService {
307 222
308 switch (type) { 223 switch (type) {
309 // 优惠券 224 // 优惠券
310 case "1": 225 case RightTypeConstants
226 .DISCOUNT_COUPON:
311 Long entityId = rightsDTO.getEntityId(); 227 Long entityId = rightsDTO.getEntityId();
312 CouponDTO couponDTO = this.findCouponById(entityId); 228 CouponDTO couponDTO = this.couponService.findById(entityId);
313 if (Objects.nonNull(couponDTO)) { 229 if (Objects.nonNull(couponDTO)) {
314 TempCoupon tempCoupon = new TempCoupon(); 230 TempCoupon tempCoupon = new TempCoupon();
315 tempCoupon.setId(couponDTO.getId()); 231 tempCoupon.setId(couponDTO.getId());
...@@ -319,16 +235,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -319,16 +235,15 @@ public class RightsOperationServiceImpl implements RightsOperationService {
319 tempCoupon.setRightsSendStrategy(0); 235 tempCoupon.setRightsSendStrategy(0);
320 tempCoupon.setCode(couponDTO.getCode()); 236 tempCoupon.setCode(couponDTO.getCode());
321 if (Objects.nonNull(expireTime)) 237 if (Objects.nonNull(expireTime))
322 // tempCoupon.setExpireTime(TimestampUtil.long2LocalDateTime(expireTime));
323 tempCoupon.setExpireTime(expireTime); 238 tempCoupon.setExpireTime(expireTime);
324 tempCouponList.add(tempCoupon); 239 tempCouponList.add(tempCoupon);
325 } 240 }
326 break; 241 break;
327 // 观影券 242 // 观影券
328 case "2": 243 case RightTypeConstants.VIEW_COUPON:
329 break; 244 break;
330 // 活动参与机会 245 // 活动参与机会
331 case "3": 246 case RightTypeConstants.JOIN_ACTIVITY:
332 break; 247 break;
333 248
334 default: 249 default:
...@@ -343,27 +258,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -343,27 +258,6 @@ public class RightsOperationServiceImpl implements RightsOperationService {
343 } 258 }
344 259
345 /** 260 /**
346 * 获取优惠券信息
347 * @param id
348 * @return
349 */
350 private CouponDTO findCouponById(Long id) {
351 CouponDTO couponDTO = this.couponService.findById(id);
352 return couponDTO;
353 }
354
355 /**
356 * 权益详情
357 * @param rightsId
358 * @return
359 */
360 private RightsDTO getRights(Long rightsId) {
361 RightsDTO rightsDTO = this.rightsService.findById(rightsId);
362 return rightsDTO;
363 }
364
365
366 /**
367 * 添加权益领取记录 261 * 添加权益领取记录
368 * @param rightsHistories 262 * @param rightsHistories
369 */ 263 */
......
...@@ -6,8 +6,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,8 +6,7 @@ import com.alibaba.fastjson.JSONObject;
6 import com.topdraw.aspect.AsyncMqSend; 6 import com.topdraw.aspect.AsyncMqSend;
7 import com.topdraw.business.module.coupon.service.CouponService; 7 import com.topdraw.business.module.coupon.service.CouponService;
8 import com.topdraw.business.module.coupon.service.dto.CouponDTO; 8 import com.topdraw.business.module.coupon.service.dto.CouponDTO;
9 import com.topdraw.business.module.member.group.service.MemberGroupService; 9 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
10 import com.topdraw.business.module.member.group.service.dto.MemberGroupDTO;
11 import com.topdraw.business.module.rights.service.RightsService; 10 import com.topdraw.business.module.rights.service.RightsService;
12 import com.topdraw.business.module.rights.service.dto.RightsDTO; 11 import com.topdraw.business.module.rights.service.dto.RightsDTO;
13 import com.topdraw.business.module.task.attribute.domain.TaskAttr; 12 import com.topdraw.business.module.task.attribute.domain.TaskAttr;
...@@ -16,14 +15,13 @@ import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; ...@@ -16,14 +15,13 @@ import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
16 import com.topdraw.business.module.task.domain.TaskBuilder; 15 import com.topdraw.business.module.task.domain.TaskBuilder;
17 import com.topdraw.business.module.task.progress.domain.TrTaskProgress; 16 import com.topdraw.business.module.task.progress.domain.TrTaskProgress;
18 import com.topdraw.business.module.task.progress.service.TrTaskProgressService; 17 import com.topdraw.business.module.task.progress.service.TrTaskProgressService;
19 import com.topdraw.business.module.task.progress.service.dto.TrTaskProgressDTO;
20 import com.topdraw.business.module.task.service.dto.TaskDTO; 18 import com.topdraw.business.module.task.service.dto.TaskDTO;
21 import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO; 19 import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO;
22 import com.topdraw.business.module.user.iptv.domain.UserTv; 20 import com.topdraw.business.module.user.iptv.domain.UserTv;
23 import com.topdraw.business.module.user.iptv.service.UserTvService; 21 import com.topdraw.business.module.user.iptv.service.UserTvService;
24 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 22 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
25 import com.topdraw.business.process.domian.constant.TaskTemplateType; 23 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
26 import com.topdraw.business.process.domian.constant.RightType; 24 import com.topdraw.business.module.rights.constant.RightType;
27 import com.topdraw.business.process.service.PointsOperationService; 25 import com.topdraw.business.process.service.PointsOperationService;
28 import com.topdraw.business.process.service.RightsOperationService; 26 import com.topdraw.business.process.service.RightsOperationService;
29 import com.topdraw.business.process.service.TaskOperationService; 27 import com.topdraw.business.process.service.TaskOperationService;
...@@ -31,19 +29,25 @@ import com.topdraw.business.module.member.service.MemberService; ...@@ -31,19 +29,25 @@ import com.topdraw.business.module.member.service.MemberService;
31 import com.topdraw.business.module.member.service.dto.MemberDTO; 29 import com.topdraw.business.module.member.service.dto.MemberDTO;
32 import com.topdraw.business.module.task.domain.Task; 30 import com.topdraw.business.module.task.domain.Task;
33 import com.topdraw.business.module.task.service.TaskService; 31 import com.topdraw.business.module.task.service.TaskService;
34 import com.topdraw.business.module.task.template.domain.TaskTemplate;
35 import com.topdraw.business.module.task.template.service.TaskTemplateService; 32 import com.topdraw.business.module.task.template.service.TaskTemplateService;
36 import com.topdraw.business.process.domian.*; 33 import com.topdraw.business.process.domian.*;
37 import com.topdraw.business.process.service.UserOperationService; 34 import com.topdraw.business.process.service.UserOperationService;
38 import com.topdraw.common.ResultInfo; 35 import com.topdraw.common.ResultInfo;
39 import com.topdraw.exception.BadRequestException; 36 import com.topdraw.business.LocalConstants;
37 import com.topdraw.business.module.rights.constant.RightTypeConstants;
38 import com.topdraw.business.module.task.template.constant.TaskEventType;
39 import com.topdraw.business.RedisKeyConstants;
40 import com.topdraw.mq.module.mq.DataSyncMsg; 40 import com.topdraw.mq.module.mq.DataSyncMsg;
41 import com.topdraw.util.*; 41 import com.topdraw.util.*;
42 import com.topdraw.utils.RedisUtils;
42 import lombok.extern.slf4j.Slf4j; 43 import lombok.extern.slf4j.Slf4j;
43 import org.apache.commons.lang3.StringUtils; 44 import org.apache.commons.lang3.StringUtils;
44 import org.springframework.aop.framework.AopContext; 45 import org.springframework.aop.framework.AopContext;
45 import org.springframework.beans.BeanUtils; 46 import org.springframework.beans.BeanUtils;
46 import org.springframework.beans.factory.annotation.Autowired; 47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.beans.factory.annotation.Value;
49 import org.springframework.cache.annotation.CacheEvict;
50 import org.springframework.data.redis.core.RedisTemplate;
47 import org.springframework.data.redis.core.StringRedisTemplate; 51 import org.springframework.data.redis.core.StringRedisTemplate;
48 import org.springframework.data.redis.core.ValueOperations; 52 import org.springframework.data.redis.core.ValueOperations;
49 import org.springframework.stereotype.Service; 53 import org.springframework.stereotype.Service;
...@@ -55,7 +59,6 @@ import java.time.LocalDateTime; ...@@ -55,7 +59,6 @@ import java.time.LocalDateTime;
55 import java.util.*; 59 import java.util.*;
56 import java.util.concurrent.TimeUnit; 60 import java.util.concurrent.TimeUnit;
57 61
58 import static java.util.stream.Collectors.toList;
59 62
60 /** 63 /**
61 * 任务处理 64 * 任务处理
...@@ -81,67 +84,41 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -81,67 +84,41 @@ public class TaskOperationServiceImpl implements TaskOperationService {
81 @Autowired 84 @Autowired
82 private TaskAttrService taskAttrService; 85 private TaskAttrService taskAttrService;
83 @Autowired 86 @Autowired
84 private MemberGroupService memberGroupService;
85 @Autowired
86 private TaskTemplateService taskTemplateService; 87 private TaskTemplateService taskTemplateService;
87 @Autowired 88 @Autowired
88 private TrTaskProgressService trTaskProgressService; 89 private TrTaskProgressService trTaskProgressService;
89 @Autowired 90 @Autowired
90 private RightsOperationService rightsOperationService; 91 private RightsOperationService rightsOperationService;
92 @Autowired
93 private RedisUtils redisUtils;
94
95 @Value("${uc.validPriorityMember:1}")
96 private int validPriorityMember;
91 97
92 private static final Integer TASK_FINISH_STATUS = 1; 98 private static final Integer TASK_FINISH_STATUS = 1;
93 private static final Integer TASK_UNFINISH_STATUS = 2;
94 private static final Integer POINTS_TYPE_RANDOM = 1; 99 private static final Integer POINTS_TYPE_RANDOM = 1;
95 private static final Integer POINTS_MIN = 1; 100 private static final Integer POINTS_MIN = 1;
96 101
97
98 @AsyncMqSend
99 public void asyncCreateTask(Task task) {}
100 @AsyncMqSend
101 public void asyncUpdateTask(Task task) {}
102 @AsyncMqSend
103 public void asyncDeleteTask(Task task) {}
104
105 @Override 102 @Override
106 public void createTask(Task task) { 103 // @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event")
104 public TaskDTO createTask(Task task) {
107 Long taskTemplateId = task.getTaskTemplateId(); 105 Long taskTemplateId = task.getTaskTemplateId();
108 TaskTemplateDTO taskTemplateDTO = this.findByTemplateId(taskTemplateId); 106 TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId);
109 107
110 task.setTaskTemplateCode(taskTemplateDTO.getCode()); 108 task.setTaskTemplateCode(taskTemplateDTO.getCode());
111 Task task_ = TaskBuilder.build(task); 109 Task task_ = TaskBuilder.build(task);
112 TaskDTO taskDTO = this.taskService.create(task_); 110 TaskDTO taskDTO = this.taskService.create(task_);
113 if (Objects.nonNull(taskDTO.getId())) {
114 task_.setId(taskDTO.getId());
115 this.createTaskAttr(task_);
116 }
117 111
118 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncCreateTask(task_); 112 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncCreateTask(task_);
119 }
120
121 /**
122 *
123 * @param taskTemplateId
124 * @return
125 */
126 private TaskTemplateDTO findByTemplateId(Long taskTemplateId){
127 return this.taskTemplateService.findById(taskTemplateId);
128 }
129 113
130 /** 114 return taskDTO;
131 *
132 * @param task_
133 */
134 private void createTaskAttr(Task task_) {
135 TaskAttr taskAttr = new TaskAttr();
136 taskAttr.setAttrStr(task_.getAttr());
137 taskAttr.setTaskId(task_.getId());
138 this.taskAttrService.create(taskAttr);
139 } 115 }
140 116
141 @Override 117 @Override
142 public void updateTask(Task task) { 118 // @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip, key = "#task.event")
119 public TaskDTO updateTask(Task task) {
143 Long taskTemplateId = task.getTaskTemplateId(); 120 Long taskTemplateId = task.getTaskTemplateId();
144 TaskTemplateDTO taskTemplateDTO = this.findByTemplateId(taskTemplateId); 121 TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId);
145 task.setTaskTemplateCode(taskTemplateDTO.getCode()); 122 task.setTaskTemplateCode(taskTemplateDTO.getCode());
146 TaskDTO update = this.taskService.update(task); 123 TaskDTO update = this.taskService.update(task);
147 if (Objects.nonNull(update.getId())) { 124 if (Objects.nonNull(update.getId())) {
...@@ -149,44 +126,52 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -149,44 +126,52 @@ public class TaskOperationServiceImpl implements TaskOperationService {
149 } 126 }
150 127
151 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncUpdateTask(task); 128 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncUpdateTask(task);
129
130 return update;
152 } 131 }
153 132
154 /** 133 /**
155 * 134 *
156 * @param task_ 135 * @param task 任务
157 */ 136 */
158 private void updateTaskAttr(Task task_) { 137 private void updateTaskAttr(Task task) {
159 138 TaskAttrDTO taskAttrDTO = this.taskAttrService.findByTaskId(task.getId());
160 TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(task_.getId());
161 if (Objects.nonNull(taskAttrDTO.getId())) { 139 if (Objects.nonNull(taskAttrDTO.getId())) {
162 TaskAttr taskAttr = new TaskAttr(); 140 TaskAttr taskAttr = new TaskAttr();
163 BeanUtils.copyProperties(taskAttrDTO, taskAttr); 141 BeanUtils.copyProperties(taskAttrDTO, taskAttr);
164 taskAttr.setAttrStr(task_.getAttr()); 142 taskAttr.setAttrStr(task.getAttr());
165 this.taskAttrService.update(taskAttr); 143 this.taskAttrService.update(taskAttr);
166 } 144 }
167 } 145 }
168 146
169 @Override 147 @Override
170 public void deleteTask(Task task) { 148 // @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event")
149 public Integer deleteTask(Task task) {
171 Long id = task.getId(); 150 Long id = task.getId();
172 TaskDTO taskDTO = this.findById(id); 151 TaskDTO taskDTO = this.findById(id);
173 if (Objects.nonNull(taskDTO.getId())) { 152 if (Objects.nonNull(taskDTO.getId())) {
174 task.setId(taskDTO.getId()); 153 task.setId(taskDTO.getId());
175 this.taskService.delete(task); 154 Integer delete = this.taskService.delete(task);
176 task.setCode(taskDTO.getCode()); 155 task.setCode(taskDTO.getCode());
177 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncDeleteTask(task); 156 ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncDeleteTask(task);
157
158 return delete;
178 } 159 }
160
161 return 0;
179 } 162 }
180 163
181 @Override 164 @Override
182 public void deleteTask(Long id) { 165 public Integer deleteTask(Long id) {
183 TaskDTO taskDTO = this.findById(id); 166 TaskDTO taskDTO = this.findById(id);
184 if (Objects.nonNull(taskDTO.getId())) { 167 if (Objects.nonNull(taskDTO.getId())) {
185 Task task = new Task(); 168 Task task = new Task();
186 task.setId(taskDTO.getId()); 169 task.setId(taskDTO.getId());
187 task.setCode(taskDTO.getCode()); 170 task.setCode(taskDTO.getCode());
188 this.deleteTask(task); 171 return this.deleteTask(task);
189 } 172 }
173
174 return 0;
190 } 175 }
191 176
192 @Override 177 @Override
...@@ -203,148 +188,490 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -203,148 +188,490 @@ public class TaskOperationServiceImpl implements TaskOperationService {
203 188
204 @Override 189 @Override
205 public TaskDTO findByCode(String code) { 190 public TaskDTO findByCode(String code) {
206 TaskDTO taskDTO = this.taskService.findByCode(code); 191 return this.taskService.findByCode(code);
207 return taskDTO;
208 } 192 }
209 193
210 @Override 194 @Override
211 public ResultInfo dealTask(String content) { 195 public ResultInfo dealTask(String content) {
212 196
213 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class); 197 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
214 Integer event = dataSyncMsg.getEvent();
215 String msgData1 = dataSyncMsg.getMsgData();
216 DataSyncMsg.MsgData msgData = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
217 198
218 String memberCode = msgData.getMemberCode(); 199 if (StringUtils.isBlank(dataSyncMsg.getMsgData())) {
219 Long memberId = msgData.getMemberId(); 200 log.error("参数错误,事件消息体为空");
201 return ResultInfo.failure("参数错误,事件消息体为空");
202 }
220 203
221 long l = System.currentTimeMillis(); 204 JSONObject msgData = JSON.parseObject(dataSyncMsg.getMsgData(), JSONObject.class);
222 if (StringUtils.isNotBlank(memberCode)) { 205
206 Object memberIdObj = msgData.get("memberId");
207 Object platformAccountObj = msgData.get("platformAccount");
208 if (Objects.isNull(memberIdObj) && Objects.isNull(platformAccountObj)) {
209 log.error("参数错误,会员id和platformAccount都为空");
210 return ResultInfo.failure("参数错误,会员id和platformAccount都为空");
211 }
223 212
224 MemberDTO memberDTO = this.memberService.findByCode(memberCode); 213 // 大屏侧传递的参数是platformAccount
225 log.info("获取会员信息 ==>> {}", memberDTO); 214 MemberSimpleDTO memberDTO = null;
215 if (Objects.nonNull(platformAccountObj)) {
226 216
227 // 检查当前会员的黑名单状态 217 String platformAccount = platformAccountObj.toString();
228 boolean b = this.validatedMemberBlackStatus(memberDTO); 218 UserTvSimpleDTO userTvDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount);
229 log.info("会员信息 ==>> {} || 会员id ==>> {} || 黑名单状态 ==>> {}", memberDTO, memberDTO.getId(), memberDTO.getBlackStatus()); 219 log.info("查询大屏信息, dealTask# ==>> {}", userTvDTO);
230 if (!b) { 220
231 return ResultInfo.forbidden("会员已被加入黑名单"); 221 if (Objects.nonNull(userTvDTO)) {
222
223 // 开启积分自动同步至小屏主会员
224 if (validPriorityMember == 1) {
225
226 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
227 if (StringUtils.isNotBlank(priorityMemberCode)) {
228 memberDTO = this.memberService.findSimpleByCode(priorityMemberCode);
229 log.info("查询绑定的小屏的主会员信息, dealTask# member ==>> {}", memberDTO);
230 } else if (Objects.nonNull(userTvDTO.getMemberId())) {
231 memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId());
232 log.info("查询大屏自身的会员信息, dealTask# memberId ==>> {}", userTvDTO.getMemberId());
232 } 233 }
233 234
234 memberId = memberDTO.getId(); 235 } else {
236
237 memberDTO = this.memberService.findSimpleById(userTvDTO.getMemberId());
238 log.info("查询大屏会员信息, dealTask# memberDTO ==>> {}", memberDTO);
235 } 239 }
236 240
237 // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 241 } else {
238 TaskTemplate taskTemplate = this.getTaskTemplate(event, dataSyncMsg); 242 log.error("大屏账号不存在,请检查数据, dealTask# platformAccount ==>> {}", platformAccount);
239 log.info("获取任务模板 taskTemplate ==>> {} ", taskTemplate); 243 return ResultInfo.failure("大屏账号不存在,请检查数据");
244 }
240 245
241 // 2.通过任务模板获取对应的任务列表 246 } else {
242 List<Task> taskList = this.loadListTaskByTaskTemplate(taskTemplate, dataSyncMsg); 247 // 小屏侧传递的参数是memberId
243 log.info("获取任务 taskList ==>> [{}] ", taskList); 248 memberDTO = this.memberService.findSimpleById(Long.valueOf(memberIdObj.toString()));
249 }
244 250
245 // 4.判断当前用户是否满足任务完成条件 251 log.info("获取会员信息, dealTask# memberDTO ==>> {}", memberDTO);
246 boolean checkResult = this.checkTaskCompletion(memberId, taskList, event, msgData);
247 log.info("检查当前会员的任务完成情况 ==>> {} , true:未完成", checkResult);
248 if (checkResult) {
249 // 5.权益区分(积分、权益、成长值)
250 Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId, taskList, msgData, dataSyncMsg);
251 log.info("获取当前任务对应的权益 tempRightsMap ==>> {} ", tempRightsMap);
252 252
253 // 6.风控检查 253 if (Objects.isNull(memberDTO.getId())) {
254 boolean result = this.checkRiskManagement(memberId, tempRightsMap); 254 log.error("会员信息不存在 ==>> dealTask# memberDTO ==>> {}", memberDTO);
255 log.info("针对各项权益检查当前会员是否达到风控值 ==>> {},true:已达到风控指标 ", result); 255 return ResultInfo.failure("会员信息不存在");
256 }
256 257
257 if (result) throw new BadRequestException("发放失败,已达风控上限"); 258 // 检查黑名单状态 0:正常 1:黑名单
259 Long blackStatus = memberDTO.getBlackStatus();
260 if (Objects.nonNull(blackStatus) && blackStatus.equals(LocalConstants.BLACK_STATUS)) {
261 log.error("会员已被加入黑名单, dealTask# ==>> {}", memberDTO);
262 return ResultInfo.forbidden("会员已被加入黑名单");
263 }
258 264
259 long l1 = System.currentTimeMillis(); 265 // 检索满足条件的任务 1.先检查redis中是否存在符合条件的任务 2.从redis中获取当前会员未完成的任务
260 log.info("各项检查总耗时 ==>> {}", (l1-l)); 266 List<Task> tasks = this.findValidTasksAndRefreshTaskProcess(memberDTO, dataSyncMsg.getEvent(), msgData);
267 log.info("当前用户可执行的任务详情, dealTask# tasks ==>> [{}]", tasks);
268 if (CollectionUtils.isEmpty(tasks)) {
269 // 类型 1:登录;2:观影;3:参加活动;4:订购;5:优享会员;6:签到;7:完成设置;8:播放记录;
270 // 10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
271 log.warn("无可执行的任务");
272 return ResultInfo.failure("无可执行的任务");
273 }
274
275 // 5.权益区分(积分、权益、成长值)
276 Map<RightType,Object> tempRightsMap = this.distinguishRight(memberDTO, tasks, msgData, dataSyncMsg);
261 277
262 // 7.权益发放 278 // 7.权益发放
263 log.info("下发开始 ==>> {}", tempRightsMap); 279 Integer integer = this.grantRight(tempRightsMap);
264 long l2 = System.currentTimeMillis();
265 this.grantRight(tempRightsMap);
266 long l3 = System.currentTimeMillis();
267 log.info("下发结束,总耗时 ==>> {}", (l3-l2));
268 280
281 if (integer > 0) {
282 return ResultInfo.success(integer);
269 } 283 }
270 return ResultInfo.success(); 284
285 return ResultInfo.failure("任务处理失败");
271 286
272 } 287 }
273 288
289 /**
290 *
291 * @param id 主键
292 * @param memberId 会员id
293 * @param task 任务
294 * @param currentActionAmount 当前行为量
295 * @param status 完成状态
296 */
297 private void saveOrUpdateTaskProcess(Long id,Long memberId, Task task, Integer currentActionAmount, Integer status) {
298 TrTaskProgress trTaskProgress = new TrTaskProgress();
299 trTaskProgress.setId(id);
300 trTaskProgress.setCurrentActionAmount(currentActionAmount);
301 trTaskProgress.setCompletionTime(TimestampUtil.now());
302 trTaskProgress.setStatus(status);
303 trTaskProgress.setTaskId(task.getId());
304 trTaskProgress.setMemberId(memberId);
305 trTaskProgress.setTargetActionAmount(task.getActionAmount());
306 trTaskProgress.setUpdateTime(TimestampUtil.now());
307
308 log.info("更新任务完成情况 ==>> {}", trTaskProgress);
309 TrTaskProgress _trTaskProgress = this.trTaskProgressService.create(trTaskProgress, LocalDateTimeUtil.todayStart());
310
311 if (status.equals(TASK_FINISH_STATUS) && Objects.nonNull(_trTaskProgress)) {
312 boolean todayFinishCount = this.redisUtils.hHasKey(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), task.getId().toString());
313 if (!todayFinishCount) {
314 Map<Object, Object> finishTasks = new HashMap<>();
315 finishTasks.put(task.getId(), 1);
316 // 单天的记录只存储一天
317 this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60);
318 } else {
319 this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1);
320 }
321
322 // 永久
323 this.redisUtils.hincr(RedisKeyConstants.cacheTotalFinishTaskCount+"::"+memberId, task.getId().toString(), 1);
324 }
274 325
326 }
275 327
276 /** 328 /**
277 * 风控检查 329 * 获取满足条件的任务列表
278 * @param memberId 330 * @param memberDTO 会员
279 * @param tempRightsMap 331 * @param msgData 事件消息体
332 * @param event 任务模板类型
280 * @return 333 * @return
281 */ 334 */
282 private boolean checkRiskManagement(Long memberId , Map<RightType, Object> tempRightsMap) { 335 private List<Task> findValidTasksAndRefreshTaskProcess(MemberSimpleDTO memberDTO, Integer event, JSONObject msgData) {
283 // TODO 风控 336
337 // 任务是否存在
338 List<Task> tasks = this.taskService.findByEventAndMemberLevelAndVip(event, memberDTO.getLevel(), memberDTO.getVip());
339 log.info("查询任务列表, dealTask# tasks ==>> [{}]",tasks);
340 if (Objects.isNull(tasks) || CollectionUtils.isEmpty(tasks)) {
341 return Collections.singletonList(null);
342 }
343
344 // 获取当前会员所有任务的完成进度
345 Map<Object, Object> todayFinishTask =
346 this.trTaskProgressService.countTodayFinishTaskByMemberId(memberDTO.getId(), LocalDateTimeUtil.todayStart());
347 log.info("查询今天所有任务的完成进度, dealTask# todayFinishTask ==>> {}", todayFinishTask);
348
349 Map<Object, Object> finishTaskCount = this.trTaskProgressService.countTotalFinishTaskByMemberId(memberDTO.getId());
350 log.info("查询所有任务的完成次数, dealTask# finishTaskCount ==>> {}", finishTaskCount);
351
352 List<Task> tasksResult = new ArrayList<>();
353 // 检查当前会员针对这些任务的完成情况
354 for (Task task : tasks) {
355 boolean result = false;
356 // 校验用户分组
357 if (StringUtils.isNotBlank(task.getGroups()) && !task.getGroups().contains("0")) {
358 String groups = memberDTO.getGroups();
359 log.info("会员分组信息, dealTask# groups ==>> {}", groups);
360 if (StringUtils.isNotBlank(groups)) {
361 String[] split = groups.split(",");
362 if (split.length > 0) {
363 for (String s : split) {
364 if (task.getGroups().contains(s)){
365 result = true;
366 break;
367 }
368 }
369 }
370 }
371 if (!result) {
372 log.warn("此用户分组不满足任务要求,任务分组 ==>> {} || 会员分组 ==>> {}", task.getGroups(), memberDTO.getGroups());
373 continue;
374 }
375 }
376
377 // 任务每日重置 0:不重置;1:重置
378 Integer taskDailyReset = task.getTaskDailyReset();
379 // 任务重复类型,-1:不限次;1:单次;>1:多次
380 Integer taskRepeatType = task.getTaskRepeatType();
381 if (taskDailyReset.equals(0)) {
382 // 不重置,检查是否做过此任务
383 Object finishCount = finishTaskCount.get(task.getId().toString());
384 if (!taskRepeatType.equals(-1) && Objects.nonNull(finishCount)) {
385 if (Long.parseLong(finishCount.toString()) >= taskRepeatType) {
386 continue;
387 }
388 }
389
390 } else {
391
392 Object todayFinishCount = todayFinishTask.get(task.getId().toString());
393 if (taskRepeatType >= 1 && Objects.nonNull(todayFinishCount)) {
394 if (Long.parseLong(todayFinishCount.toString()) >= taskRepeatType) {
395 continue;
396 }
397 }
398
399 }
400
401 switch (event) {
402 // 开机、登录
403 case TaskEventType.LOGIN:
404 if (this.doLoginEvent(msgData, task, memberDTO)) {
405 tasksResult.add(task);
406 }
407 break;
408 // 观影
409 case TaskEventType.VIEW:
410 if (this.doViewEvent(msgData, task, memberDTO)) {
411 tasksResult.add(task);
412 }
413 break;
414 // 参加活动
415 case TaskEventType.ACTIVITY:
416 if (this.doActivityEvent(msgData, task, memberDTO)) {
417 tasksResult.add(task);
418 }
419 break;
420 // 订购
421 case TaskEventType.ORDER:
422 if (this.doOrderEvent(msgData, task, memberDTO)) {
423 tasksResult.add(task);
424 }
425 break;
426 // 优享会员
427 case TaskEventType.MEMBER_PRIORITY:
428 break;
429 // 签到
430 case TaskEventType.SIGN:
431 if (this.doSignEvent(msgData, task, memberDTO)) {
432 tasksResult.add(task);
433 }
434 break;
435 // 完善个人资料
436 case TaskEventType.COMPLETE_INFO:
437 if (this.doCompleteMemberInfoEvent(msgData, task, memberDTO)) {
438 tasksResult.add(task);
439 }
440 break;
441 // 播放时长
442 case TaskEventType.PLAY:
443 // 用户播放总时长
444 if (this.doPlayEvent(msgData, task, memberDTO)) {
445 tasksResult.add(task);
446 }
447 break;
448 // 跨屏绑定
449 case TaskEventType.BINDING:
450 // 跨屏绑定次数
451 if (this.doBindingEvent(msgData, task, memberDTO)) {
452 tasksResult.add(task);
453 }
454 break;
455 // 积分转移
456 case TaskEventType.POINTS_TRANS:
457 if (this.doPointsTransEvent(msgData, task, memberDTO)) {
458 tasksResult.add(task);
459 }
460 break;
461 // 积分兑换商品
462 case TaskEventType.POINTS_EXCHANGE_GOODS:
463 // 完成设置次数
464 if (this.doPointsExchangeGoodsEvent(msgData, task, memberDTO)) {
465 tasksResult.add(task);
466 }
467 break;
468 // 其他
469 case TaskEventType.SYSTEM_OPERATE:
470 break;
471 default:
472 log.info("没有找到对应的任务");
473 break;
474 }
475
476 }
477
478 return tasksResult;
479 }
480
481 private boolean doOrderEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
482 Integer actionAmount = task.getActionAmount();
483 // 用户行为次数
484 // TODO 后续需要按照业务对用户行为数据进行修改
485 int completeCount = 1;
486 if (completeCount >= actionAmount) {
487 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS);
488 return true;
489 }
284 return false; 490 return false;
285 } 491 }
286 492
287 /** 493 private boolean doPointsExchangeGoodsEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
288 * 验证会员信息 494 Integer actionAmount = task.getActionAmount();
289 * @param memberDTO 495 // 用户行为次数
290 * @return 496 // TODO 后续需要按照业务对用户行为数据进行修改
291 */ 497 int completeCount = 1;
292 private boolean validatedMemberBlackStatus(MemberDTO memberDTO) { 498 if (completeCount >= actionAmount) {
293 Long blackStatus = memberDTO.getBlackStatus(); 499 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS);
294 if (Objects.nonNull(blackStatus) && blackStatus == 1) { 500 return true;
295 log.error("validatedMember -->> 会员已被加入黑名单 【blackStatus】 -->> " + blackStatus); 501 }
296 return false; 502 return false;
297 } 503 }
504
505 private boolean doPointsTransEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
506 Integer actionAmount = task.getActionAmount();
507 // 用户行为次数
508 // TODO 后续需要按照业务对用户行为数据进行修改
509 int completeCount = 1;
510 if (completeCount >= actionAmount) {
511
512 log.info("保存完成用户信息设置任务进度");
513 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS);
298 return true; 514 return true;
299 } 515 }
516 return false;
517 }
518
519 private boolean doBindingEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
520 Integer actionAmount = task.getActionAmount();
521 // 用户行为次数
522 // TODO 后续需要按照业务对用户行为数据进行修改
523 int completeCount = 1;
524 if (completeCount >= actionAmount) {
525
526 log.info("保存完成用户信息设置任务进度");
527 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS);
528 return true;
529 }
530 return false;
531 }
532
533 private boolean doCompleteMemberInfoEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
534 Integer actionAmount = task.getActionAmount();
535 // 用户行为次数
536 // TODO 后续需要按照业务对用户行为数据进行修改
537 int completeCount = 1;
538 if (completeCount >= actionAmount) {
539
540 log.info("保存完成用户信息设置任务进度");
541 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, completeCount, TASK_FINISH_STATUS);
542 return true;
543 }
544 return false;
545 }
546
547 private boolean doActivityEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
548 Integer actionAmount = task.getActionAmount();
549 String attrStr = task.getAttr();
550 if (StringUtils.isBlank(attrStr)) {
551 int joinCount = 1;//msgData.getInteger("joinCount");
552 if (joinCount >= actionAmount) {
553 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS);
554 return true;
555 }
556 }
557
558 Integer marketingActivityId = msgData.getInteger("marketingActivityId");
559 if (new ArrayList<>(Arrays.asList(attrStr.split(","))).contains(Integer.toString(marketingActivityId))) {
560 int joinCount = 1;//msgData.getInteger("joinCount");
561 if (joinCount >= actionAmount) {
562 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS);
563 return true;
564 }
565 }
566
567 log.warn("未找到对应的活动,参数 marketingActivityId ==>> {} || 任务属性 ==>> {}", marketingActivityId, attrStr);
568 return false;
569 }
570
571 private boolean doSignEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
572 Integer actionAmount = task.getActionAmount();
573 // // 用户行为次数 签到天数
574 int signDays = msgData.getInteger("signDays");
575 if (signDays >= actionAmount) {
576 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, signDays, TASK_FINISH_STATUS);
577 return true;
578 }
579
580 return false;
581 }
582
583 private boolean doViewEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
584 Integer actionAmount = task.getActionAmount();
585 // 观影总时长
586 int playDuration_ = msgData.getInteger("playDuration");
587 if (playDuration_ >= actionAmount) {
588 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, playDuration_, TASK_FINISH_STATUS);
589 return true;
590 }
591 return false;
592 }
593
594 private boolean doLoginEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) {
595 Integer actionAmount = task.getActionAmount();
596
597 // 登录天数
598 int continueLogin = msgData.getInteger("CONTINUE_LOGIN");
599 if (continueLogin >= actionAmount) {
600 this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, continueLogin, TASK_FINISH_STATUS);
601 return true;
602 }
603 return false;
604 }
300 605
301 /** 606 /**
302 * 任务完成情况 607 * 播放时长
303 * @param resources 任务完成情况 608 * @param paramJsonObject
304 */ 609 */
305 private void doRefreshTrTaskProcess(TrTaskProgress resources) { 610 private boolean doPlayEvent(JSONObject paramJsonObject, Task task, MemberSimpleDTO memberSimpleDTO) {
306 Long id = resources.getId(); 611 // 任务最低行为量
307 if (Objects.nonNull(id)) { 612 Integer actionAmount = task.getActionAmount();
308 resources.setUpdateTime(TimestampUtil.now()); 613 // 用户实际播放时长
309 this.trTaskProgressService.update(resources); 614 int playDuration = paramJsonObject.getInteger("playDuration");
310 } else { 615 if (playDuration >= actionAmount) {
311 this.trTaskProgressService.create(resources); 616
617 long l4 = System.currentTimeMillis();
618 this.saveOrUpdateTaskProcess(null, memberSimpleDTO.getId(), task, playDuration, TASK_FINISH_STATUS);
619 long l5 = System.currentTimeMillis();
620 log.info("保存任务进度信息,总耗时 ==>> {}", (l5-l4));
621
622 return true;
623 }
624
625 return false;
312 } 626 }
627
628
629 /**
630 * 风控检查
631 * @param memberId
632 * @param tempRightsMap
633 * @return
634 */
635 private boolean checkRiskManagement(Long memberId , Map<RightType, Object> tempRightsMap) {
636 // TODO 风控
637 return false;
313 } 638 }
314 639
315 /** 640 /**
316 * 权益发放 641 * 权益发放
317 * @param tempRightsMap 权益 642 * @param tempRightsMap 权益
318 */ 643 */
319 private void grantRight(Map<RightType,Object> tempRightsMap) { 644 private Integer grantRight(Map<RightType,Object> tempRightsMap) {
320 this.rightsOperationService.grantRights(tempRightsMap); 645 return this.rightsOperationService.grantRights(tempRightsMap);
321 } 646 }
322 647
323 /** 648 /**
324 * 权益区分 649 * 权益区分
325 * 650 *
326 * @param taskList 任务列表 651 * @param tasks 任务列表
327 * @return Map<RightType,Object> 权益分类 652 * @return Map<RightType,Object> 权益分类
328 */ 653 */
329 private Map<RightType,Object> distinguishRight(Long memberId, List<Task> taskList, DataSyncMsg.MsgData msgData, DataSyncMsg dataSyncMsg) { 654 private Map<RightType,Object> distinguishRight(MemberSimpleDTO memberDTO, List<Task> tasks, JSONObject msgData, DataSyncMsg dataSyncMsg) {
330 655
331 Map<RightType,Object> map = new HashMap<>(); 656 Map<RightType,Object> map = new HashMap<>();
332 657
333 // 区分权益类型(成长值(reward_exp)、积分(reward_points)、实体券),并发放权益 658 // 区分权益类型(成长值(reward_exp)、积分(reward_points)、实体券),并发放权益
334 for (Task task : taskList) { 659 List<TempPoints> tempPoints = new ArrayList<>();
660 List<TempExp> tempExps = new ArrayList<>();
661 for (Task task : tasks) {
335 662
336 // 积分 663 // 积分
337 List<TempPoints> tempPointsList = this.getTempPoints(memberId, msgData, task, dataSyncMsg); 664 this.getTempPoints(memberDTO, msgData, task, dataSyncMsg, tempPoints);
338 if (!CollectionUtils.isEmpty(tempPointsList)) 665 if (!CollectionUtils.isEmpty(tempPoints))
339 map.put(RightType.POINTS,tempPointsList); 666 map.put(RightType.POINTS, tempPoints);
340 667
341 // 成长值 668 // 成长值
342 List<TempExp> tempExpList = this.getTempExp(memberId,msgData,task, dataSyncMsg); 669 this.getTempExp(memberDTO, msgData, task, dataSyncMsg, tempExps);
343 if (!CollectionUtils.isEmpty(tempExpList)) 670 if (!CollectionUtils.isEmpty(tempExps))
344 map.put(RightType.EXP,tempExpList); 671 map.put(RightType.EXP, tempExps);
345 672
346 // 权益 673 // 权益
347 map = this.getTempRight(memberId, task, map); 674 this.getTempRight(memberDTO, task, map);
348 675
349 } 676 }
350 677
...@@ -368,7 +695,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -368,7 +695,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
368 Long expireTime1 = rightsDTO.getExpireTime(); 695 Long expireTime1 = rightsDTO.getExpireTime();
369 if (Objects.nonNull(expireTime1)) { 696 if (Objects.nonNull(expireTime1)) {
370 Timestamp expireTime = TimestampUtil.long2Timestamp(expireTime1); 697 Timestamp expireTime = TimestampUtil.long2Timestamp(expireTime1);
371 if (Objects.nonNull(expireTime))
372 tempRights.setExpireTime(expireTime); 698 tempRights.setExpireTime(expireTime);
373 } 699 }
374 return tempRights; 700 return tempRights;
...@@ -395,17 +721,17 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -395,17 +721,17 @@ public class TaskOperationServiceImpl implements TaskOperationService {
395 721
396 /** 722 /**
397 * 权益1 723 * 权益1
398 * @param task 724 * @param task 任务
725 * @param memberDTO 会员
726 * @param map 权益分类
399 * @return 727 * @return
400 */ 728 */
401 private Map<RightType,Object> getTempRight(Long memberId , Task task , Map<RightType,Object> map) { 729 private Map<RightType,Object> getTempRight(MemberSimpleDTO memberDTO, Task task, Map<RightType,Object> map) {
402 730
403 // 优惠券 731 // 优惠券
404 List<TempCoupon> tempCouponList = new ArrayList<>(); 732 List<TempCoupon> tempCouponList = new ArrayList<>();
405 // 权益列表,用以保存权益记录 733 // 权益列表,用以保存权益记录
406 List<TempRights> rightsList = new ArrayList<>(); 734 List<TempRights> rightsList = new ArrayList<>();
407 // 会员信息
408 MemberDTO memberDTO = this.findMemberById(memberId);
409 735
410 // 权益1 736 // 权益1
411 Long rights1Id = task.getRightsId(); 737 Long rights1Id = task.getRightsId();
...@@ -437,27 +763,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -437,27 +763,9 @@ public class TaskOperationServiceImpl implements TaskOperationService {
437 // 权益分类 763 // 权益分类
438 this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList,map); 764 this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList,map);
439 } 765 }
440 // 优惠券
441 /*if (!CollectionUtils.isEmpty(tempCouponList)) {
442 map.put(RightType.COUPON,tempCouponList);
443 }*/
444 // 权益
445 /*if (!CollectionUtils.isEmpty(rightsList)) {
446 map.put(RightType.RIGHTS,rightsList);
447 }*/
448 return map; 766 return map;
449 } 767 }
450 768
451
452 /**
453 * 会员对象
454 * @param memberId
455 * @return
456 */
457 private MemberDTO findMemberById(Long memberId) {
458 return this.memberService.findById(memberId);
459 }
460
461 /** 769 /**
462 * 权益分类 770 * 权益分类
463 * @param memberDTO 771 * @param memberDTO
...@@ -467,16 +775,18 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -467,16 +775,18 @@ public class TaskOperationServiceImpl implements TaskOperationService {
467 * @param tempCouponList 775 * @param tempCouponList
468 * @param rightsList 776 * @param rightsList
469 */ 777 */
470 private void getTempRightType(MemberDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, 778 private void getTempRightType(MemberSimpleDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList,
471 List<TempRights> rightsList,Map<RightType,Object> map) { 779 List<TempRights> rightsList,Map<RightType,Object> map) {
472 780
473 Long memberId = memberDTO.getId(); 781 Long memberId = memberDTO.getId();
474 String nickname = memberDTO.getNickname(); 782 String nickname = memberDTO.getNickname();
475 String memberCode = memberDTO.getCode(); 783 String memberCode = memberDTO.getCode();
476 // 权益详情 784 // 权益详情
477 RightsDTO rightsDTO = this.getRight(rightsId); 785 long l = System.currentTimeMillis();
478 786 RightsDTO rightsDTO = this.rightsService.findById(rightsId);
479 if (Objects.nonNull(rightsDTO)){ 787 long l1 = System.currentTimeMillis();
788 log.info("查询权益信息,总耗时 ==>> {}", (l1-l));
789 if (Objects.nonNull(rightsDTO.getId())){
480 // 用以保存权益历史 790 // 用以保存权益历史
481 TempRights tempRights = this.tmpRightsBuild(memberId,memberCode,rightsAmount,rightsDTO); 791 TempRights tempRights = this.tmpRightsBuild(memberId,memberCode,rightsAmount,rightsDTO);
482 rightsList.add(tempRights); 792 rightsList.add(tempRights);
...@@ -486,13 +796,13 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -486,13 +796,13 @@ public class TaskOperationServiceImpl implements TaskOperationService {
486 } 796 }
487 797
488 // 权益类型 798 // 权益类型
489 String type = rightsDTO.getEntityType(); 799 Integer type = rightsDTO.getEntityType();
490 switch (type) { 800 switch (type) {
491 // 优惠券 801 // 优惠券
492 case "1": 802 case RightTypeConstants.DISCOUNT_COUPON:
493 Long entityId1 = rightsDTO.getEntityId(); 803 Long entityId1 = rightsDTO.getEntityId();
494 if (Objects.nonNull(entityId1)) { 804 if (Objects.nonNull(entityId1)) {
495 CouponDTO couponDTO = this.findCouponById(entityId1); 805 CouponDTO couponDTO = this.couponService.findById(entityId1);
496 if (Objects.nonNull(couponDTO.getId())) { 806 if (Objects.nonNull(couponDTO.getId())) {
497 // 优惠券 807 // 优惠券
498 TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); 808 TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname);
...@@ -505,10 +815,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -505,10 +815,10 @@ public class TaskOperationServiceImpl implements TaskOperationService {
505 } 815 }
506 break; 816 break;
507 // 观影券 817 // 观影券
508 case "2": 818 case RightTypeConstants.VIEW_COUPON:
509 Long entityId2 = rightsDTO.getEntityId(); 819 Long entityId2 = rightsDTO.getEntityId();
510 if (Objects.nonNull(entityId2)) { 820 if (Objects.nonNull(entityId2)) {
511 CouponDTO couponDTO = this.findCouponById(entityId2); 821 CouponDTO couponDTO = this.couponService.findById(entityId2);
512 if (Objects.nonNull(couponDTO.getId())) { 822 if (Objects.nonNull(couponDTO.getId())) {
513 // 优惠券 823 // 优惠券
514 TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname); 824 TempCoupon tempCoupon = this.tempCouponBuild(memberId, memberCode,rightsAmount, rightsSendStrategy, couponDTO, nickname);
...@@ -521,19 +831,19 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -521,19 +831,19 @@ public class TaskOperationServiceImpl implements TaskOperationService {
521 } 831 }
522 break; 832 break;
523 // 活动参与机会 833 // 活动参与机会
524 case "3": 834 case RightTypeConstants.JOIN_ACTIVITY:
525 map.put(RightType.ACTIVITYCHANCE, tempRights); 835 map.put(RightType.ACTIVITYCHANCE, tempRights);
526 break; 836 break;
527 // 积分商品 837 // 积分商品
528 case "4": 838 case RightTypeConstants.POINTS_GOODS:
529 map.put(RightType.POINTGOODS, tempRights); 839 map.put(RightType.POINTGOODS, tempRights);
530 break; 840 break;
531 // IPTV产品包 841 // IPTV产品包
532 case "5": 842 case RightTypeConstants.IPTV_PRODUCT:
533 map.put(RightType.IPTVPRODUCT, tempRights); 843 map.put(RightType.IPTVPRODUCT, tempRights);
534 break; 844 break;
535 // IPTV观影权益 845 // IPTV观影权益
536 case "6": 846 case RightTypeConstants.IPTV_VIEW:
537 map.put(RightType.IPTVVIEW, tempRights); 847 map.put(RightType.IPTVVIEW, tempRights);
538 break; 848 break;
539 default: 849 default:
...@@ -543,55 +853,32 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -543,55 +853,32 @@ public class TaskOperationServiceImpl implements TaskOperationService {
543 } 853 }
544 854
545 /** 855 /**
546 * 获取优惠券信息
547 * @param id
548 * @return
549 */
550 private CouponDTO findCouponById(Long id) {
551 CouponDTO couponDTO = this.couponService.findById(id);
552 return couponDTO;
553 }
554
555 /**
556 *
557 * @param rightsId
558 * @return
559 */
560 private RightsDTO getRight(Long rightsId) {
561 RightsDTO rightsDTO = this.rightsService.findById(rightsId);
562 return rightsDTO;
563 }
564
565 /**
566 * 成长值 856 * 成长值
567 * @param task 857 * @param task
568 * @return 858 * @return
569 */ 859 */
570 private List<TempExp> getTempExp(Long memberId, DataSyncMsg.MsgData msgData, Task task, DataSyncMsg dataSyncMsg) { 860 private void getTempExp(MemberSimpleDTO memberDTO, JSONObject msgData, Task task, DataSyncMsg dataSyncMsg, List<TempExp> tempExps) {
861
571 Long rewardExp = task.getRewardExp(); 862 Long rewardExp = task.getRewardExp();
572 if (Objects.nonNull(rewardExp) && rewardExp > 0L) { 863 if (Objects.nonNull(rewardExp) && rewardExp > 0L) {
573 864
574 TempExp tempExp = new TempExp(); 865 TempExp tempExp = new TempExp();
575 tempExp.setMemberId(memberId); 866 tempExp.setMemberId(memberDTO.getId());
576 tempExp.setAppCode(msgData.getAppCode()); 867 tempExp.setAppCode(msgData.getString("appCode"));
577 tempExp.setMemberId(memberId); 868 tempExp.setMemberCode(memberDTO.getCode());
578 tempExp.setMemberCode(msgData.getMemberCode()); 869 tempExp.setMemberLevel(memberDTO.getLevel());
579 tempExp.setItemId(msgData.getItemId()); 870 tempExp.setItemId(msgData.getLong("itemId"));
580 tempExp.setAccountId(msgData.getAccountId()); 871 tempExp.setAccountId(msgData.getLong("accountId"));
581 tempExp.setRewardExp(task.getRewardExp()); 872 tempExp.setRewardExp(task.getRewardExp());
582 tempExp.setDeviceType(dataSyncMsg.getDeviceType()); 873 tempExp.setDeviceType(dataSyncMsg.getDeviceType());
583 tempExp.setEvtType(dataSyncMsg.getEvent()); 874 tempExp.setEvtType(dataSyncMsg.getEvent());
584 tempExp.setOrderId(msgData.getOrderId()); 875 tempExp.setOrderId(msgData.getLong("orderId"));
585 tempExp.setMediaId(msgData.getMediaId()); 876 tempExp.setMediaId(msgData.getLong("mediaId"));
586 tempExp.setActivityId(msgData.getOrderId()); 877 tempExp.setActivityId(msgData.getLong("activityId"));
587 Integer rightsSendStrategy = task.getRightsSendStrategy(); 878 Integer rightsSendStrategy = task.getRightsSendStrategy();
588 tempExp.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); 879 tempExp.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy);
589 return Arrays.asList(tempExp); 880 tempExps.add(tempExp);
590
591 } 881 }
592
593 return null;
594
595 } 882 }
596 883
597 /** 884 /**
...@@ -599,8 +886,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -599,8 +886,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
599 * @param task 886 * @param task
600 * @return 887 * @return
601 */ 888 */
602 private List<TempPoints> getTempPoints(Long memberId, DataSyncMsg.MsgData msgData, Task task, DataSyncMsg dataSyncMsg) { 889 private void getTempPoints(MemberSimpleDTO memberDTO, JSONObject msgData, Task task,
603 890 DataSyncMsg dataSyncMsg, List<TempPoints> tempPoints) {
604 // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值 891 // 积分: 数值、过期时间、积分类型(定值、随机)、随机积分最大值
605 Long rewardPoints = task.getRewardPoints(); 892 Long rewardPoints = task.getRewardPoints();
606 // 过期时间 893 // 过期时间
...@@ -610,560 +897,42 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -610,560 +897,42 @@ public class TaskOperationServiceImpl implements TaskOperationService {
610 Integer pointsType = task.getPointsType(); 897 Integer pointsType = task.getPointsType();
611 // 随机积分的最大值 898 // 随机积分的最大值
612 Integer rewardMaxPoints = task.getRewardMaxPoints(); 899 Integer rewardMaxPoints = task.getRewardMaxPoints();
613 if (Objects.nonNull(rewardPoints)) { 900 if (Objects.nonNull(rewardPoints) && rewardPoints > 0) {
614 TempPoints tempPoints = new TempPoints(); 901 TempPoints tempPoint = new TempPoints();
615 // 如果积分是随机的,则取随机值 902 // 如果积分是随机的,则取随机值
616 if (pointsType == POINTS_TYPE_RANDOM) { 903 if (pointsType.equals(POINTS_TYPE_RANDOM)) {
617 rewardPoints = RandomUtil.getRandomPoints(POINTS_MIN,rewardMaxPoints); 904 rewardPoints = RandomUtil.getRandomPoints(POINTS_MIN, rewardMaxPoints);
618 } 905 }
619 tempPoints.setRewardPointsExpireTime(rewardPointsExpireTime); 906 tempPoint.setRewardPointsExpireTime(rewardPointsExpireTime);
620 tempPoints.setMemberId(memberId); 907 tempPoint.setMemberId(memberDTO.getId());
621 tempPoints.setMemberCode(msgData.getMemberCode()); 908 tempPoint.setMemberCode(memberDTO.getCode());
622 tempPoints.setAppCode(msgData.getAppCode()); 909 tempPoint.setAppCode(msgData.getString("appCode"));
623 tempPoints.setPoints(rewardPoints); 910 tempPoint.setPoints(rewardPoints);
624 tempPoints.setPointsType(pointsType); 911 tempPoint.setPointsType(pointsType);
625 tempPoints.setDeviceType(dataSyncMsg.getDeviceType()); 912 tempPoint.setDeviceType(dataSyncMsg.getDeviceType());
626 tempPoints.setExpireTime(expireTime); 913 tempPoint.setExpireTime(expireTime);
627 tempPoints.setOrderId(msgData.getOrderId()); 914 tempPoint.setOrderId(msgData.getLong("orderId"));
628 tempPoints.setActivityId(msgData.getOrderId()); 915 tempPoint.setActivityId(msgData.getLong("activityId"));
629 tempPoints.setMediaId(msgData.getMediaId()); 916 tempPoint.setMediaId(msgData.getLong("mediaId"));
630 tempPoints.setItemId(msgData.getItemId()); 917 tempPoint.setItemId(msgData.getLong("itemId"));
631 tempPoints.setAccountId(msgData.getAccountId()); 918 tempPoint.setAccountId(msgData.getLong("accountId"));
632 tempPoints.setEvtType(dataSyncMsg.getEvent()); 919 tempPoint.setEvtType(dataSyncMsg.getEvent());
633 Integer rightsSendStrategy = task.getRightsSendStrategy(); 920 Integer rightsSendStrategy = task.getRightsSendStrategy();
634 tempPoints.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); 921 tempPoint.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy);
635 return Arrays.asList(tempPoints);
636 }
637
638 return null;
639 }
640
641 /**
642 * 判断任务是否完成
643 * 完成的条件如下:->
644 * 1. status 当前任务的状态 0:失效;1:生效
645 * 2. valid_time 任务生效时间
646 * 3. expire_time 任务失效时间
647 * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次
648 * 5. member_level 会员等级门槛(0表示无门槛)
649 * 6. member_vip 会员vip门槛(0表示没有门槛)
650 * 7. groups 能够获取该任务的用户分组,为空则都能获取 , 0
651 * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发)
652 *
653 * @param taskList 任务列表
654 * @return boolean true:success false:fail
655 */
656 //<taskId,boolean>
657 private boolean checkTaskCompletion(Long memberId , List<Task> taskList, Integer event, DataSyncMsg.MsgData msgData) {
658 if (!CollectionUtils.isEmpty(taskList)) {
659 // 会员信息
660 MemberDTO memberDTO = this.memberService.findById(memberId);
661
662 // 判断是否完成任务
663 CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> {
664
665 List<Task> taskStream = taskList1.stream().filter(task1 ->
666 task1.getStatus() == 1 &&
667 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) &&
668 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
669 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
670 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip())
671 ).collect(toList());
672
673 // 没有满足条件的数据
674 if (!CollectionUtils.isEmpty(taskStream)) {
675
676 // 验证会员分组
677 boolean result1 = this.validatedMemberGroup(memberId,taskList);
678 if (!result1)
679 return false;
680
681 // 获取当前任务的完成情况
682 boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList,event,msgData);
683
684 return result;
685
686 } else {
687
688 return false;
689
690 }
691
692 };
693
694 return compareTaskCondition.compareCondition(memberDTO,taskList);
695 }
696
697 return false;
698 }
699
700 /**
701 * 验证会员分组
702 * @param memberId
703 * @param taskList
704 * @return
705 */
706 private boolean validatedMemberGroup(Long memberId,List<Task> taskList) {
707 List<MemberGroupDTO> groupDTO = this.findGroupByMemberId(memberId);
708
709 if (!CollectionUtils.isEmpty(groupDTO)) {
710
711 // 会员分组
712 List<String> list = new ArrayList<>();
713 for (MemberGroupDTO memberGroupDTO : groupDTO) {
714 String groupId = memberGroupDTO.getGroupId().toString();
715 list.add(groupId);
716 }
717
718 // 任务分组
719 List<String> strings = new ArrayList<>();
720 for (Task task : taskList) {
721 String groups = task.getGroups();
722 List<String> strings1 = UcStringUtils.parse2StrList(groups);
723 if (StringUtils.isEmpty(groups)) {
724 return true;
725 }
726 strings.addAll(strings1);
727 break;
728 }
729
730 // 如果任务分组为null或者空字符,则放过所有的会员
731 if (CollectionUtils.isEmpty(strings)) {
732 return true;
733 }
734
735 // 如果任务分组为0,则放过所有的分组
736 if (!CollectionUtils.isEmpty(strings) && (!CollectionUtils.isEmpty(list) && strings.contains("0")) ) {
737 return true;
738 }
739
740 if (!CollectionUtils.isEmpty(list)) {
741 // 只要会员分组满足任务分组之一就满足要求
742 if (list.size() > strings.size()) {
743 for (String s : list) {
744 boolean contains = strings.contains(s);
745 if (contains) {
746 return true;
747 }
748 }
749 }
750 }
751
752 if (!CollectionUtils.isEmpty(strings)) {
753 for (String s : strings) {
754 boolean contains = list.contains(s);
755 if (contains) {
756 return true;
757 }
758 }
759 }
760
761 } else {
762 return true;
763 }
764 return false;
765 }
766
767
768 /**
769 *
770 * @param memberId
771 * @return
772 */
773 private List<MemberGroupDTO> findGroupByMemberId(Long memberId) {
774 return this.memberGroupService.findByMemberId(memberId);
775 }
776
777 /**
778 * 通过会员id获取分组
779 * @param memberId
780 * @return
781 */
782 /*private List<GroupDTO> findGroupByMemberId(Long memberId) {
783 GroupQueryCriteria groupQueryCriteria = new GroupQueryCriteria();
784 groupQueryCriteria.setUserId(memberId);
785 List<GroupDTO> groupDTO = this.groupService.queryAll(groupQueryCriteria);
786 return groupDTO;
787 }*/
788
789 /**
790 * 检查并更新当前任务的完成情况
791 *
792 * 1.每天都能做,但要求总次数达到行为量
793 *
794 * @param memberId
795 * @param taskStream
796 * @return boolean false:失败 true:成功
797 */
798 private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream, Integer event, DataSyncMsg.MsgData msgData) {
799 String time1 = LocalDateTimeUtil.todayStart();
800 for (Task task : taskStream) {
801
802 Long taskId = task.getId();
803 // 任务完成记录
804 List<TrTaskProgressDTO> trTaskProgressDTOS =
805 this.trTaskProgressService.findByMemberIdAndTaskIdAndCompletionTime(memberId,taskId,time1);
806
807 Long id = null;
808 Integer currentActionAmount = null;
809 Timestamp completionTime = null;
810 Integer status = 0;
811
812 // 行为量(完成此任务需要多少次相同行为的触发)
813 Integer actionAmount = task.getActionAmount();
814
815 switch (event) {
816 // 播放记录
817 case 8:
818 if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) {
819 TrTaskProgressDTO trTaskProgressDTO_0 = trTaskProgressDTOS.get(0);
820 Integer status_0 = trTaskProgressDTO_0.getStatus();
821 Integer currentActionAmount_0 = trTaskProgressDTO_0.getCurrentActionAmount();
822 Timestamp completionTime_0 = trTaskProgressDTO_0.getCompletionTime();
823 if (status_0 == 1 && currentActionAmount_0 != null && Objects.nonNull(completionTime_0)) {
824 return false;
825 }
826 }
827 String param = msgData.getParam();
828 JSONObject jsonObject = JSON.parseObject(param);
829 Integer value = Integer.valueOf(jsonObject.get("playDuration").toString());
830 if (value >= actionAmount) {
831 currentActionAmount = actionAmount;
832 completionTime = TimestampUtil.now();
833 status = TASK_FINISH_STATUS;
834 }
835
836 break;
837
838 default:
839 // 行为量 1
840 if (actionAmount == 1) {
841
842 if (CollectionUtils.isEmpty(trTaskProgressDTOS)) {
843 currentActionAmount = 1;
844 completionTime = TimestampUtil.now();
845 status = TASK_FINISH_STATUS;
846 }
847
848 if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) {
849 // 此任务做过,但未完成
850 TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0);
851 Long id_ = trTaskProgressDTO.getId();
852 Integer status_ = trTaskProgressDTO.getStatus();
853 Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount();
854 Timestamp completionTime1 = trTaskProgressDTO.getCompletionTime();
855
856 // 任务已做,不成功
857 if (Objects.nonNull(status_) && status_ == 1 &&
858 Objects.nonNull(currentActionAmount_) && currentActionAmount_ == 1 &&
859 Objects.nonNull(completionTime1) &&
860 completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) {
861
862 // 任务重复类型
863 Integer taskDailyReset = task.getTaskDailyReset();
864 if (taskDailyReset == -1) {
865 return true;
866 } else if (currentActionAmount_ < taskDailyReset){
867 return true;
868 }
869
870
871 return false;
872
873 // 未做,成功
874 } else {
875 id = id_;
876 currentActionAmount = 1;
877 completionTime = TimestampUtil.now();
878 status = TASK_FINISH_STATUS;
879 }
880
881 }
882 }
883
884 // 行为量非1
885 if (actionAmount != 1) {
886
887 if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) {
888 // 此任务做过,但未完成
889 TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0);
890
891 Long id_ = trTaskProgressDTO.getId();
892 // 状态 0:未完成;1:已完成
893 Integer status_ = trTaskProgressDTO.getStatus();
894 Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime();
895 Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount();
896 // 行为量达到,完成
897 if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) {
898 id = id_;
899 currentActionAmount = actionAmount;
900 completionTime = TimestampUtil.now();
901 status = TASK_FINISH_STATUS;
902 } else {
903 // 行为量未达到,未完成
904 id = id_;
905 currentActionAmount = currentActionAmount_+1;
906 }
907
908 }
909
910 // 未达到行为量,未完成
911 if (CollectionUtils.isEmpty(trTaskProgressDTOS)) {
912 currentActionAmount = 1;
913 status = TASK_UNFINISH_STATUS;
914 }
915
916 }
917
918 break;
919
920 }
921
922
923
924 TrTaskProgress trTaskProgress = new TrTaskProgress();
925 trTaskProgress.setId(id);
926 trTaskProgress.setCurrentActionAmount(currentActionAmount);
927 trTaskProgress.setCompletionTime(completionTime);
928 trTaskProgress.setStatus(status);
929 trTaskProgress.setTaskId(taskId);
930 trTaskProgress.setMemberId(memberId);
931 trTaskProgress.setTargetActionAmount(actionAmount);
932
933 // 更新任务完成情况
934 this.doRefreshTrTaskProcess(trTaskProgress);
935
936 return true;
937 }
938
939 return false;
940 }
941
942 /**
943 * 获取任务模板对应的任务列表
944 *
945 * @param taskTemplate 任务模板
946 * @return List<task> 任务列表
947 */
948 private List<Task> loadListTaskByTaskTemplate(TaskTemplate taskTemplate, DataSyncMsg dataSyncMsg) {
949
950 if (Objects.nonNull(taskTemplate)) {
951
952 Long taskTemplateId = taskTemplate.getId();
953
954 List<Task> taskList = this.taskService.findByTemplateId(taskTemplateId);
955
956 Integer type = taskTemplate.getType();
957 taskList = this.pickUpTask(taskList, dataSyncMsg, type);
958
959 return taskList;
960 922
923 tempPoints.add(tempPoint);
961 } 924 }
962 925
963 return null;
964 }
965
966 /**
967 * 通过参数确定具体任务
968 * @param taskList
969 * @param dataSyncMsg
970 * @return
971 */
972 private List<Task> pickUpTask(List<Task> taskList,DataSyncMsg dataSyncMsg,Integer type) {
973
974 List<Task> taskList1 = new ArrayList<>();
975 String msgData1 = dataSyncMsg.getMsgData();
976 DataSyncMsg.MsgData msgData = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
977
978 if (Objects.nonNull(msgData.getParam())) {
979
980 String param = msgData.getParam();
981 Map<String,String> jsonObjectMap = JSONObject.parseObject(param, Map.class);
982 Collection<String> values = jsonObjectMap.values();
983
984 for (Task task : taskList) {
985
986 Long taskId = task.getId();
987 TaskAttrDTO taskAttrDTO = this.findTaskAttrByTaskId(taskId);
988 if (Objects.isNull(taskAttrDTO.getId()))
989 continue;
990
991 String attrStr = taskAttrDTO.getAttrStr();
992 if (StringUtils.isNotBlank(attrStr)) {
993 JSONObject jsonObject = JSONObject.parseObject(attrStr);
994 JSONArray values_0 = jsonObject.getJSONArray("value");
995
996 switch (type) {
997 // 登录
998 case TaskTemplateType.TYPE_1:
999
1000 Integer o1 = (Integer)values_0.get(0);
1001 Integer o2 = (Integer)values_0.get(1);
1002 List<Integer> list = Arrays.asList(o1, o2);
1003 String s = values.toArray()[0].toString();
1004 Integer i = Integer.valueOf(s);
1005 boolean b = UcListUtils.compareIntegerList(i, list);
1006 if (b)
1007 taskList1.add(task);
1008 break;
1009
1010 // 观影
1011 case TaskTemplateType.TYPE_2:
1012 Integer view0 = (Integer)values_0.get(0);
1013 Integer view1 = (Integer)values_0.get(1);
1014 List<Integer> view0List = Arrays.asList(view0, view1);
1015 String view_0 = values.toArray()[0].toString();
1016 Integer view0_ = Integer.valueOf(view_0);
1017 boolean view = UcListUtils.compareIntegerList(view0_, view0List);
1018 if (view)
1019 taskList1.add(task);
1020 break;
1021
1022 // 参加活动
1023 case TaskTemplateType.TYPE_3:
1024 /*String activityCode = values_0.get(0).toString();
1025 String activityCode_ = values.toArray()[0].toString();
1026 if (activityCode_.equalsIgnoreCase(activityCode)) {
1027 taskList1.add(task);
1028 }*/
1029 if (values_0.containsAll(values))
1030 taskList1.add(task);
1031 break;
1032
1033 // 订购
1034 case TaskTemplateType.TYPE_4:
1035 if (values_0.containsAll(values))
1036 taskList1.add(task);
1037 break;
1038
1039 // 签到
1040 case TaskTemplateType.TYPE_6:
1041 Integer sign0 = (Integer)values_0.get(0);
1042 Integer sign1 = (Integer)values_0.get(1);
1043 List<Integer> signi0List = Arrays.asList(sign0, sign1);
1044 String signs0 = values.toArray()[0].toString();
1045 Integer signi0 = Integer.valueOf(signs0);
1046 boolean signb0 = UcListUtils.compareIntegerList(signi0, signi0List);
1047 if (signb0)
1048 taskList1.add(task);
1049 break;
1050
1051 // 播放记录
1052 case TaskTemplateType.TYPE_8:
1053 Integer play0 = (Integer)values_0.get(0);
1054 Integer play1 = (Integer)values_0.get(1);
1055 List<Integer> playList = Arrays.asList(play0, play1);
1056 String s0 = values.toArray()[0].toString();
1057 Integer i0 = Integer.valueOf(s0);
1058 boolean b0 = UcListUtils.compareIntegerList(i0, playList);
1059 if (b0)
1060 taskList1.add(task);
1061 break;
1062
1063 default:
1064 break;
1065 }
1066
1067
1068 }
1069
1070 }
1071
1072 } else {
1073 return taskList;
1074 }
1075
1076 return taskList1;
1077
1078 }
1079
1080 private TaskAttrDTO findTaskAttrByTaskId(Long taskId) {
1081 return this.taskAttrService.findByTaskId(taskId);
1082 }
1083
1084
1085 /**
1086 * 获取任务模板对应的任务列表
1087 *
1088 * @param taskTemplate 任务模板
1089 * @return List<task> 任务列表
1090 */
1091 private List<Task> loadListTaskByTaskTemplate(TaskTemplate taskTemplate) {
1092
1093 if (Objects.nonNull(taskTemplate)) {
1094 Long taskTemplateId = taskTemplate.getId();
1095 return this.taskService.findByTemplateId(taskTemplateId);
1096 }
1097
1098 return null;
1099 }
1100
1101 /**
1102 * 获取任务模板
1103 * @param event 任务
1104 * @return TaskTemplate 任务模板
1105 */
1106 private TaskTemplate getTaskTemplate(Integer event, DataSyncMsg dataSyncMsg) {
1107 String msgData1 = dataSyncMsg.getMsgData();
1108 DataSyncMsg.MsgData msg = JSON.parseObject(msgData1, DataSyncMsg.MsgData.class);
1109
1110 if (Objects.nonNull(msg.getParam())) {
1111
1112 return this.findByTypeAndParam(event,msg);
1113
1114 } else {
1115
1116 TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(event);
1117
1118 if (Objects.nonNull(taskTemplateDTO)) {
1119
1120 TaskTemplate taskTemplate = new TaskTemplate();
1121 BeanUtils.copyProperties(taskTemplateDTO, taskTemplate);
1122 return taskTemplate;
1123
1124 } else {
1125
1126 return null;
1127
1128 }
1129
1130 }
1131 }
1132
1133 private TaskTemplate findByTypeAndParam(Integer event, DataSyncMsg.MsgData taskTemplateParam) {
1134 String param = taskTemplateParam.getParam();
1135 if (StringUtils.isNotBlank(param)) {
1136
1137 Map<String,String> jsonObject = JSONObject.parseObject(param,Map.class);
1138
1139 TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(event);
1140 if (Objects.nonNull(taskTemplateDTO)) {
1141
1142 String templateParams = taskTemplateDTO.getParams();
1143 if(StringUtils.isNotBlank(templateParams)) {
1144 String templateParamsUpperCase = templateParams.toUpperCase();
1145 Set<String> keySet = jsonObject.keySet();
1146 for (String key : keySet) {
1147 String s = key.toUpperCase();
1148 if (s.equals(templateParamsUpperCase)) {
1149 TaskTemplate taskTemplate = new TaskTemplate();
1150 BeanUtils.copyProperties(taskTemplateDTO, taskTemplate);
1151 return taskTemplate;
1152 }
1153 continue;
1154 }
1155 }
1156
1157 }
1158
1159 }
1160
1161
1162 return null;
1163 } 926 }
1164 927
928 @AsyncMqSend
929 public void asyncCreateTask(Task task) {}
930 @AsyncMqSend
931 public void asyncUpdateTask(Task task) {}
932 @AsyncMqSend
933 public void asyncDeleteTask(Task task) {}
1165 934
1166 //////////////////////////////////////////////////////////////////////////////////////////////////////////// 935 //////////////////////////////////////2021-11 为支持重数《反贪风暴5》活动上线临时做法需要删除//////////////////////////////////////////////////////////////////////
1167 936
1168 @Autowired 937 @Autowired
1169 private StringRedisTemplate stringRedisTemplate; 938 private StringRedisTemplate stringRedisTemplate;
......
...@@ -82,6 +82,11 @@ public class TaskTemplateOperationServiceImpl implements TaskTemplateOperationSe ...@@ -82,6 +82,11 @@ public class TaskTemplateOperationServiceImpl implements TaskTemplateOperationSe
82 } 82 }
83 83
84 @Override 84 @Override
85 public Long countByCodeAndType(TaskTemplate taskTemplate) {
86 return this.taskTemplateService.countByCodeAndType(taskTemplate);
87 }
88
89 @Override
85 public TaskTemplateDTO findById(Long id) { 90 public TaskTemplateDTO findById(Long id) {
86 return this.taskTemplateService.findById(id); 91 return this.taskTemplateService.findById(id);
87 } 92 }
......
...@@ -8,13 +8,26 @@ import com.alibaba.fastjson.JSONObject; ...@@ -8,13 +8,26 @@ import com.alibaba.fastjson.JSONObject;
8 import com.topdraw.aspect.AsyncMqSend; 8 import com.topdraw.aspect.AsyncMqSend;
9 import com.topdraw.business.module.member.domain.Member; 9 import com.topdraw.business.module.member.domain.Member;
10 import com.topdraw.business.module.member.domain.MemberBuilder; 10 import com.topdraw.business.module.member.domain.MemberBuilder;
11 import com.topdraw.business.module.member.domain.MemberTypeConstant;
11 import com.topdraw.business.module.member.service.MemberService; 12 import com.topdraw.business.module.member.service.MemberService;
12 import com.topdraw.business.module.member.service.dto.MemberDTO; 13 import com.topdraw.business.module.member.service.dto.MemberDTO;
14 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
15 import com.topdraw.business.module.user.app.domain.*;
16 import com.topdraw.business.module.user.app.service.UserAppBindService;
17 import com.topdraw.business.module.user.app.service.UserAppService;
18 import com.topdraw.business.module.user.app.service.dto.AppRegisterDTO;
19 import com.topdraw.business.module.user.app.service.dto.UserAppBindDTO;
20 import com.topdraw.business.module.user.app.service.dto.UserAppDTO;
21 import com.topdraw.business.module.user.app.service.dto.UserAppSimpleDTO;
13 import com.topdraw.business.module.user.iptv.domain.UserConstant; 22 import com.topdraw.business.module.user.iptv.domain.UserConstant;
14 import com.topdraw.business.module.user.iptv.domain.UserTv; 23 import com.topdraw.business.module.user.iptv.domain.UserTv;
15 import com.topdraw.business.module.user.iptv.domain.UserTvBuilder; 24 import com.topdraw.business.module.user.iptv.domain.UserTvBuilder;
25 import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport;
26 import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService;
27 import com.topdraw.business.module.user.iptv.growreport.service.dto.GrowthReportDTO;
16 import com.topdraw.business.module.user.iptv.service.UserTvService; 28 import com.topdraw.business.module.user.iptv.service.UserTvService;
17 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO; 29 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
30 import com.topdraw.business.module.user.iptv.service.dto.UserTvSimpleDTO;
18 import com.topdraw.business.module.user.weixin.collection.domain.UserCollection; 31 import com.topdraw.business.module.user.weixin.collection.domain.UserCollection;
19 import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail; 32 import com.topdraw.business.module.user.weixin.collection.domain.UserCollectionDetail;
20 import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository; 33 import com.topdraw.business.module.user.weixin.collection.repository.UserCollectionDetailRepository;
...@@ -26,24 +39,24 @@ import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository; ...@@ -26,24 +39,24 @@ import com.topdraw.business.module.user.weixin.repository.UserWeixinRepository;
26 import com.topdraw.business.module.user.weixin.service.UserWeixinService; 39 import com.topdraw.business.module.user.weixin.service.UserWeixinService;
27 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 40 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
28 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria; 41 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinQueryCriteria;
42 import com.topdraw.business.module.user.weixin.subscribe.domain.WechatSubscribeRecord;
43 import com.topdraw.business.module.user.weixin.subscribe.service.WechatSubscribeRecordService;
29 import com.topdraw.business.process.domian.weixin.*; 44 import com.topdraw.business.process.domian.weixin.*;
30 import com.topdraw.business.process.service.UserOperationService; 45 import com.topdraw.business.process.service.UserOperationService;
31 import com.topdraw.business.process.service.dto.MemberAndUserTvDTO; 46 import com.topdraw.business.process.service.dto.MemberAndUserTvDTO;
32 import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO; 47 import com.topdraw.business.process.service.dto.MemberAndWeixinUserDTO;
33 import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper; 48 import com.topdraw.business.process.service.mapper.CollectionMq2DetailMapper;
34 import com.topdraw.config.LocalConstants; 49 import com.topdraw.business.LocalConstants;
35 import com.topdraw.config.RedisKeyUtil; 50 import com.topdraw.business.RedisKeyConstants;
51 import com.topdraw.common.ResultInfo;
52 import com.topdraw.util.RedisKeyUtil;
36 import com.topdraw.exception.BadRequestException; 53 import com.topdraw.exception.BadRequestException;
37 import com.topdraw.exception.EntityNotFoundException; 54 import com.topdraw.exception.EntityNotFoundException;
38 import com.topdraw.exception.GlobeExceptionMsg; 55 import com.topdraw.exception.GlobeExceptionMsg;
39 import com.topdraw.resttemplate.RestTemplateClient; 56 import com.topdraw.resttemplate.RestTemplateClient;
40 import com.topdraw.util.Base64Util;
41 import com.topdraw.util.IdWorker;
42 import com.topdraw.util.TimestampUtil; 57 import com.topdraw.util.TimestampUtil;
43 import com.topdraw.utils.QueryHelp; 58 import com.topdraw.utils.QueryHelp;
44 import com.topdraw.utils.RedisUtils; 59 import com.topdraw.utils.RedisUtils;
45 import com.topdraw.weixin.subscribe.domain.WechatSubscribeRecord;
46 import com.topdraw.weixin.subscribe.service.WechatSubscribeRecordService;
47 import lombok.extern.slf4j.Slf4j; 60 import lombok.extern.slf4j.Slf4j;
48 import org.apache.commons.lang3.StringUtils; 61 import org.apache.commons.lang3.StringUtils;
49 import org.springframework.aop.framework.AopContext; 62 import org.springframework.aop.framework.AopContext;
...@@ -55,10 +68,8 @@ import org.springframework.data.domain.Sort; ...@@ -55,10 +68,8 @@ import org.springframework.data.domain.Sort;
55 import org.springframework.stereotype.Service; 68 import org.springframework.stereotype.Service;
56 import org.springframework.transaction.annotation.Propagation; 69 import org.springframework.transaction.annotation.Propagation;
57 import org.springframework.transaction.annotation.Transactional; 70 import org.springframework.transaction.annotation.Transactional;
58 import org.springframework.util.Assert;
59 import org.springframework.util.Base64Utils; 71 import org.springframework.util.Base64Utils;
60 import org.springframework.util.CollectionUtils; 72 import org.springframework.util.CollectionUtils;
61 import springfox.documentation.spring.web.json.Json;
62 73
63 import java.net.URLDecoder; 74 import java.net.URLDecoder;
64 import java.nio.charset.StandardCharsets; 75 import java.nio.charset.StandardCharsets;
...@@ -75,8 +86,14 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -75,8 +86,14 @@ public class UserOperationServiceImpl implements UserOperationService {
75 @Autowired 86 @Autowired
76 private MemberService memberService; 87 private MemberService memberService;
77 @Autowired 88 @Autowired
89 private UserAppService userAppService;
90 @Autowired
78 private UserWeixinService userWeixinService; 91 private UserWeixinService userWeixinService;
79 @Autowired 92 @Autowired
93 private UserAppBindService userAppBindService;
94 @Autowired
95 private GrowthReportService growthReportService;
96 @Autowired
80 private UserWeixinRepository userWeixinRepository; 97 private UserWeixinRepository userWeixinRepository;
81 @Autowired 98 @Autowired
82 private UserCollectionService userCollectionService; 99 private UserCollectionService userCollectionService;
...@@ -97,7 +114,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -97,7 +114,7 @@ public class UserOperationServiceImpl implements UserOperationService {
97 /** 取消关注 */ 114 /** 取消关注 */
98 private static final Integer UNSUBSCRIBE_STATUS = 0; 115 private static final Integer UNSUBSCRIBE_STATUS = 0;
99 private static final Integer SUBSCRIBE_STATUS = 1; 116 private static final Integer SUBSCRIBE_STATUS = 1;
100 117 // 服务域 0:电信 1:联通 2:移动 3:其他
101 private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3}; 118 private static final Integer[] PLATFORM_LIST = new Integer[]{0,1,2,3};
102 119
103 @Value("${uc.app.h5AppId:wxca962918dfeed88c}") 120 @Value("${uc.app.h5AppId:wxca962918dfeed88c}")
...@@ -107,22 +124,235 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -107,22 +124,235 @@ public class UserOperationServiceImpl implements UserOperationService {
107 private String appletAppid; 124 private String appletAppid;
108 125
109 126
110 @AsyncMqSend 127 @Override
111 public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {} 128 @Transactional(rollbackFor = Exception.class)
112 @AsyncMqSend 129 public UserAppDTO appRegister(UserApp resources) {
113 public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTv) {} 130
114 @AsyncMqSend 131 UserAppDTO userAppDTO = this.userAppService.findByUsername(resources.getUsername());
115 public void asyncWeixin(UserWeixinDTO weixinDTO) {} 132 if (Objects.isNull(userAppDTO.getId())) {
116 @AsyncMqSend 133
117 public void asyncUserTv(UserTvDTO userTvDTO) {} 134 // 先创建会员
118 @AsyncMqSend 135 Member member = MemberBuilder.build(MemberTypeConstant.app, resources.getHeadimgurl(), resources.getNickname(), 0);
119 public void asyncAppletBind(MemberAndUserTvDTO memberAndUserTvDTO) {} 136 MemberDTO memberDTO = this.memberService.create(member);
120 @AsyncMqSend 137
121 public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {} 138 if (Objects.nonNull(memberDTO.getId())) {
122 @AsyncMqSend 139
123 public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {} 140 // 保存app账号
124 @AsyncMqSend 141 UserAppDTO _userAppDTO = this.userAppService.create(UserAppBuilder.build(memberDTO.getId(), resources));
125 public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {} 142
143 if (Objects.nonNull(_userAppDTO.getId()) && StringUtils.isNotBlank(resources.getAccount())) {
144 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccount(resources.getAccount());
145 if (Objects.isNull(userAppBindDTO.getId())) {
146 // 保存绑定关系
147 UserAppBind userAppBind = UserAppBindBuilder.build(_userAppDTO.getId(), resources.getAccount(), resources.getAccountType());
148 this.userAppBindService.create(userAppBind);
149
150 _userAppDTO.setAccount(resources.getAccount());
151 _userAppDTO.setAccountType(resources.getAccountType());
152 }
153 }
154
155
156 AppRegisterDTO appRegisterDTO = new AppRegisterDTO();
157 appRegisterDTO.setMemberDTO(memberDTO);
158 appRegisterDTO.setUserAppDTO(_userAppDTO);
159 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncAppRegister(appRegisterDTO);
160
161 return _userAppDTO;
162
163 }
164
165 }
166
167 return userAppDTO;
168 }
169
170 @Override
171 public ResultInfo cancelUserAppBind(UserAppBind resources) {
172 String account = resources.getAccount();
173 Integer accountType = resources.getAccountType();
174 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(account, accountType);
175 if (Objects.nonNull(userAppBindDTO.getId())) {
176 if (Objects.nonNull(userAppBindDTO.getUserAppId())) {
177 UserAppDTO userAppDTO = this.userAppService.findById(userAppBindDTO.getUserAppId());
178 if (Objects.isNull(userAppDTO.getId())) {
179 return ResultInfo.failure("app账号不存在");
180 }
181 }
182 boolean b = this.userAppBindService.cancelUserAppBind(account, accountType);
183 if (b) {
184 return ResultInfo.success(true);
185 }
186 }
187
188 return ResultInfo.failure("取消绑定失败");
189 }
190
191
192 @Override
193 @Transactional(rollbackFor = Exception.class)
194 public ResultInfo appBindThirdAccount(UserAppBind resources) {
195 String username = resources.getUsername();
196 String headImgUrl = resources.getHeadimgurl();
197 String nickname = resources.getNickname();
198
199 UserAppDTO userAppDTO = this.userAppService.findByUsername(username);
200 log.info("通过app账号查询app信息是否存在,[appBindThirdAccount#{}]", userAppDTO);
201 if (Objects.isNull(userAppDTO.getId())) {
202 return ResultInfo.failure("app账号不存在");
203 }
204
205 String account = resources.getAccount();
206 Integer accountType = resources.getAccountType();
207 UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(account, accountType);
208 if (Objects.nonNull(userAppBindDTO.getId()) && userAppBindDTO.getStatus() == 1 && Objects.nonNull(userAppBindDTO.getUserAppId())) {
209 Integer bindAccountType = userAppBindDTO.getAccountType();
210 String accountStr = "";
211 switch (bindAccountType) {
212 case 3:
213 accountStr = "微信";
214 break;
215 case 4:
216 accountStr = "QQ";
217 break;
218 case 5:
219 accountStr = "微博";
220 break;
221 case 6:
222 accountStr = "苹果账号";
223 break;
224
225 }
226 return ResultInfo.failure("绑定失败,当前"+accountStr+"已经绑定了其他手机号");
227 }
228
229 if (Objects.isNull(userAppDTO.getHeadimgurl())) {
230 UserApp userApp = new UserApp();
231 userApp.setUsername(username);
232 if (StringUtils.isNotBlank(headImgUrl)) {
233 if (headImgUrl.contains("http") || headImgUrl.contains("https")) {
234 String image = this.downloadWeixinImgeFromAppEngine(headImgUrl);
235 userApp.setHeadimgurl(image);
236 }
237 }
238 userApp.setNickname(nickname);
239 log.info("同步app账号的昵称、头像,[appBindThirdAccount#{}]", userAppDTO);
240 boolean result = this.userAppService.updateAppLastActiveTimeAndNicknameAndHeadImg(userApp);
241 if (result) {
242 UserAppDTO userAppDTO1 = new UserAppDTO();
243 BeanUtils.copyProperties(userApp, userAppDTO1);
244 ((UserOperationServiceImpl) AopContext.currentProxy()).asyncUpdateAppLastActiveTimeAndNicknameAndHeadImg(userAppDTO1);
245 }
246 }
247
248 if (Objects.nonNull(userAppBindDTO.getId())) {
249 resources.setUserAppId(userAppDTO.getId());
250 boolean result = this.userAppBindService.updateValidStatusAndUserAppIdAndNickname(resources);
251 if (result) {
252 UserAppDTO userAppDTO1 = new UserAppDTO();
253 userAppDTO1.setUsername(username);
254 userAppDTO1.setNickname(nickname);
255 userAppDTO1.setHeadimgurl(headImgUrl);
256 ((UserOperationServiceImpl) AopContext.currentProxy()).asyncUpdateAppLastActiveTimeAndNicknameAndHeadImg(userAppDTO1);
257 }
258
259 } else {
260 resources.setUserAppId(userAppDTO.getId());
261 resources.setStatus(1);
262 log.info("第三方账号不存在,新增关联关系[appBindThirdAccount#{}]", resources);
263 this.userAppBindService.create(resources);
264
265 UserAppDTO userAppDTO1 = new UserAppDTO();
266 BeanUtils.copyProperties(resources, userAppDTO1);
267 userAppDTO1.setUsername(username);
268 ((UserOperationServiceImpl) AopContext.currentProxy()).asyncCreateUserAppBindThirdAccount(userAppDTO1);
269 }
270
271 return ResultInfo.success(true);
272 }
273
274 @Override
275 public UserAppSimpleDTO updateAppInfo(UserApp resources) {
276
277 UserAppSimpleDTO userAppSimpleDTO = this.userAppService.updateAppInfo(resources);
278 if (Objects.nonNull(userAppSimpleDTO.getId())) {
279 UserAppDTO userAppDTO = new UserAppDTO();
280 BeanUtils.copyProperties(resources, userAppDTO);
281 userAppDTO.setUsername(userAppSimpleDTO.getUsername());
282 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUpdateAppInfo(userAppDTO);
283 }
284 return userAppSimpleDTO;
285 }
286
287
288
289 @Override
290 public boolean updatePasswordById(UserApp resources) {
291 UserAppDTO userAppDTO = this.userAppService.findById(resources.getId());
292 if (Objects.nonNull(userAppDTO.getId())) {
293 if (this.userAppService.updatePasswordById(resources)) {
294 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUpdatePasswordByUsername(userAppDTO);
295 return true;
296 }
297
298 }
299 return false;
300 }
301
302
303
304 @Override
305 @Transactional(rollbackFor = Exception.class)
306 public ResultInfo saveGrowthReport(GrowthReport growthReport) {
307 String platformAccount = growthReport.getPlatformAccount();
308
309 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
310 if (Objects.isNull(userTvDTO.getId())) {
311 log.error("保存成长报告失败,大屏信息不存在[saveGrowthReport#]");
312 return ResultInfo.failure("保存成长报告失败,大屏信息不存在");
313 }
314
315 String weekFirstDay = com.topdraw.util.DateUtil.getWeekFirstDay();
316 String weekLastDay = com.topdraw.util.DateUtil.getWeekLastDay();
317 GrowthReportDTO growthReportDTO = this.growthReportService.findByPlatformAccountAndStartDateAndEndDate(platformAccount, weekFirstDay, weekLastDay);
318 if (Objects.isNull(growthReportDTO.getId())) {
319 Long id = userTvDTO.getId();
320 Long memberId = userTvDTO.getMemberId();
321 growthReport.setUserId(id);
322 growthReport.setMemberId(memberId);
323 growthReport.setStartDate(weekFirstDay);
324 growthReport.setEndDate(weekLastDay);
325 log.info("保存成长报告,参数[saveGrowthReport#{}]", growthReport);
326 this.growthReportService.create(growthReport);
327 } else {
328 log.info("修改成长报告,参数[saveGrowthReport#{}]", growthReport);
329 this.growthReportService.updateGrowthReportData(growthReportDTO.getId(), growthReport.getData());
330 }
331
332 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncsaveGrowthReport(growthReport);
333
334 return ResultInfo.success("保存成功");
335 }
336
337 @Override
338 public boolean appCancellation(UserApp userApp) {
339 UserAppDTO userAppDTO = this.userAppService.findById(userApp.getId());
340 if (Objects.nonNull(userAppDTO.getId())){
341 boolean b = this.userAppService.appCancellation(userApp.getId());
342 if (b) {
343 List<UserAppBindDTO> userAppBindDTOS = this.userAppBindService.findByUserAppId(userAppDTO.getId());
344 if (!CollectionUtils.isEmpty(userAppBindDTOS)) {
345 List<Long> ids = userAppBindDTOS.stream().map(UserAppBindDTO::getId).collect(Collectors.toList());
346 this.userAppBindService.appCancellation(ids);
347 }
348
349 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncAppCancellation(userAppDTO);
350 }
351
352 }
353
354 return true;
355 }
126 356
127 /** 357 /**
128 * 创建大屏账户同时创建会员 358 * 创建大屏账户同时创建会员
...@@ -131,23 +361,20 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -131,23 +361,20 @@ public class UserOperationServiceImpl implements UserOperationService {
131 * @return UserTvDTO 361 * @return UserTvDTO
132 */ 362 */
133 @Override 363 @Override
134 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 364 @Transactional(rollbackFor = Exception.class)
135 public UserTvDTO createTvUserAndMember(UserTv resources) { 365 public UserTvDTO createTvUserAndMember(UserTv resources) {
136 366
137 boolean flag = true;
138
139 // 大屏账户 367 // 大屏账户
140 String platformAccount = resources.getPlatformAccount(); 368 String platformAccount = resources.getPlatformAccount();
141 369
142 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); 370 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
143 371
144 // 无账号 372 // 无账号
145 if (Objects.isNull(userTvDTO)) { 373 if (Objects.isNull(userTvDTO.getId())) {
374
375 // 会员昵称默认采用大屏账号,昵称通过base64加密与小屏保持一致
376 String platformAccountEncode = Base64Utils.encodeToString(platformAccount.getBytes());
146 377
147 String platformAccountEncode = platformAccount;
148 if (flag) {
149 platformAccountEncode = Base64Utils.encodeToString(platformAccount.getBytes());
150 }
151 // x_member 378 // x_member
152 Member member = 379 Member member =
153 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_VIS, 380 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_VIS,
...@@ -158,14 +385,15 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -158,14 +385,15 @@ public class UserOperationServiceImpl implements UserOperationService {
158 385
159 UserTv userTv = UserTvBuilder.build(memberDTO.getId(), memberDTO.getCode(), resources); 386 UserTv userTv = UserTvBuilder.build(memberDTO.getId(), memberDTO.getCode(), resources);
160 // 创建大屏账户 387 // 创建大屏账户
161 UserTvDTO tvUserDTO = this.createTvUser(userTv, memberDTO.getId(), memberDTO.getCode()); 388 UserTvDTO _tvUserDTO = this.createTvUser(userTv, memberDTO.getId(), memberDTO.getCode());
162 389
163 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, tvUserDTO)); 390 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, _tvUserDTO));
164 391
165 return tvUserDTO; 392 return _tvUserDTO;
166 393
167 } 394 }
168 395
396 log.error("保存大屏账号信息异常,无法创建大屏账号对应的会员,platoformAccount ==> {}", platformAccount);
169 throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_ID_IS_NULL); 397 throw new EntityNotFoundException(MemberDTO.class, "code", GlobeExceptionMsg.MEMBER_ID_IS_NULL);
170 398
171 // 有账号 399 // 有账号
...@@ -190,10 +418,10 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -190,10 +418,10 @@ public class UserOperationServiceImpl implements UserOperationService {
190 UserTv userTv = new UserTv(); 418 UserTv userTv = new UserTv();
191 BeanUtils.copyProperties(userTvDTO, userTv); 419 BeanUtils.copyProperties(userTvDTO, userTv);
192 420
193 UserTvDTO userTvDTO1 = this.updateUserTvUnsyncIptv(userTv); 421 UserTvDTO _userTvDTO = this.userTvService.update(userTv);
194 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, userTvDTO1)); 422 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMemberAndUserTv4Iptv(new MemberAndUserTvDTO(memberDTO, _userTvDTO));
195 423
196 return userTvDTO1; 424 return _userTvDTO;
197 } 425 }
198 426
199 } 427 }
...@@ -204,11 +432,11 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -204,11 +432,11 @@ public class UserOperationServiceImpl implements UserOperationService {
204 432
205 /** 433 /**
206 * 创建小屏账户同时创建会员 434 * 创建小屏账户同时创建会员
207 * @param resources 435 * @param resources 微信信息
208 * @return UserWeixinDTO 436 * @return UserWeixinDTO
209 */ 437 */
210 @Override 438 @Override
211 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 439 @Transactional(rollbackFor = Exception.class)
212 public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) { 440 public UserWeixinDTO createWeixinUserAndMember(UserWeixin resources) {
213 return this.createWeixinUserAndMember(resources, 0); 441 return this.createWeixinUserAndMember(resources, 0);
214 } 442 }
...@@ -239,7 +467,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -239,7 +467,7 @@ public class UserOperationServiceImpl implements UserOperationService {
239 if (Objects.nonNull(_userWeixinDTO.getMemberId())) { 467 if (Objects.nonNull(_userWeixinDTO.getMemberId())) {
240 468
241 // 有其他账号的话,将此账号与对应的会员进行绑定 469 // 有其他账号的话,将此账号与对应的会员进行绑定
242 MemberDTO memberDTO = this.findMemberById(_userWeixinDTO.getMemberId()); 470 MemberDTO memberDTO = this.memberService.findById(_userWeixinDTO.getMemberId());
243 userWeixinDTO.setMemberId(memberDTO.getId()); 471 userWeixinDTO.setMemberId(memberDTO.getId());
244 userWeixinDTO.setMemberCode(memberDTO.getCode()); 472 userWeixinDTO.setMemberCode(memberDTO.getCode());
245 if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { 473 if (StringUtils.isBlank(userWeixinDTO.getUnionid())) {
...@@ -247,17 +475,15 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -247,17 +475,15 @@ public class UserOperationServiceImpl implements UserOperationService {
247 } 475 }
248 UserWeixin userWeixin = new UserWeixin(); 476 UserWeixin userWeixin = new UserWeixin();
249 BeanUtils.copyProperties(userWeixinDTO, userWeixin); 477 BeanUtils.copyProperties(userWeixinDTO, userWeixin);
250 UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); 478 return this.updateWeixin(userWeixin);
251 return _userWeixinDTO1;
252 479
253 } else { 480 } else {
254 481
255 // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员 482 // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员
256 Member _member = 483 Member member = MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
257 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
258 headimgurl, nickname, vip, sex); 484 headimgurl, nickname, vip, sex);
259 485
260 MemberDTO memberDTO = this.createMember(_member); 486 MemberDTO memberDTO = this.createMember(member);
261 487
262 if (Objects.nonNull(memberDTO)) { 488 if (Objects.nonNull(memberDTO)) {
263 userWeixinDTO.setMemberId(memberDTO.getId()); 489 userWeixinDTO.setMemberId(memberDTO.getId());
...@@ -267,8 +493,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -267,8 +493,7 @@ public class UserOperationServiceImpl implements UserOperationService {
267 } 493 }
268 UserWeixin userWeixin = new UserWeixin(); 494 UserWeixin userWeixin = new UserWeixin();
269 BeanUtils.copyProperties(userWeixinDTO, userWeixin); 495 BeanUtils.copyProperties(userWeixinDTO, userWeixin);
270 UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); 496 return this.updateWeixin(userWeixin);
271 return _userWeixinDTO1;
272 497
273 } 498 }
274 499
...@@ -277,11 +502,11 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -277,11 +502,11 @@ public class UserOperationServiceImpl implements UserOperationService {
277 } else { 502 } else {
278 503
279 // 该账号存在但无其他账号,新建会员 504 // 该账号存在但无其他账号,新建会员
280 Member _member = 505 Member member =
281 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, 506 MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN,
282 headimgurl, nickname, vip, sex); 507 headimgurl, nickname, vip, sex);
283 508
284 MemberDTO memberDTO = this.createMember(_member); 509 MemberDTO memberDTO = this.createMember(member);
285 510
286 if (Objects.nonNull(memberDTO)) { 511 if (Objects.nonNull(memberDTO)) {
287 userWeixinDTO.setMemberId(memberDTO.getId()); 512 userWeixinDTO.setMemberId(memberDTO.getId());
...@@ -291,8 +516,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -291,8 +516,7 @@ public class UserOperationServiceImpl implements UserOperationService {
291 } 516 }
292 UserWeixin userWeixin = new UserWeixin(); 517 UserWeixin userWeixin = new UserWeixin();
293 BeanUtils.copyProperties(userWeixinDTO, userWeixin); 518 BeanUtils.copyProperties(userWeixinDTO, userWeixin);
294 UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); 519 return this.updateWeixin(userWeixin);
295 return _userWeixinDTO1;
296 520
297 } 521 }
298 522
...@@ -374,11 +598,10 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -374,11 +598,10 @@ public class UserOperationServiceImpl implements UserOperationService {
374 return userWeixinDTO; 598 return userWeixinDTO;
375 } 599 }
376 600
377
378 /** 601 /**
379 * 服务号登录 602 * 服务号登录
380 * @param resources 603 * @param resources 微信信息
381 * @return 604 * @return UserWeiXinDTO
382 */ 605 */
383 @Override 606 @Override
384 public UserWeixinDTO serviceLogin(UserWeixin resources) { 607 public UserWeixinDTO serviceLogin(UserWeixin resources) {
...@@ -387,25 +610,23 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -387,25 +610,23 @@ public class UserOperationServiceImpl implements UserOperationService {
387 UserWeixinDTO userWeixinDTO = this.createWeixinUserAndMember(resources); 610 UserWeixinDTO userWeixinDTO = this.createWeixinUserAndMember(resources);
388 611
389 // 为了保证返回的同一用户 612 // 为了保证返回的同一用户
390 UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); 613 return this.getFirstId(userWeixinDTO);
391 return userWeixinDTO_0;
392 } 614 }
393 615
394 /** 616 /**
395 * 小程序登录 617 * 小程序登录
396 * @param resources 618 * @param resources 微信
397 * @return 619 * @return UserWeiXinDTO
398 */ 620 */
399 @Override 621 @Override
400 @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class) 622 @Transactional(rollbackFor = Exception.class)
401 public UserWeixinDTO appletLogin(UserWeixin resources) { 623 public UserWeixinDTO appletLogin(UserWeixin resources) {
402 624
403 // 创建小屏账户同时创建会员 625 // 创建小屏账户同时创建会员
404 UserWeixinDTO userWeixinDTO = this.createWeixinUserAndMember(resources); 626 UserWeixinDTO userWeixinDTO = this.createWeixinUserAndMember(resources);
405 627
406 // 为了保证返回的同一用户 628 // 为了保证返回的同一用户
407 UserWeixinDTO userWeixinDTO_0 = this.getFirstId(userWeixinDTO); 629 return this.getFirstId(userWeixinDTO);
408 return userWeixinDTO_0;
409 } 630 }
410 631
411 /** 632 /**
...@@ -417,8 +638,8 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -417,8 +638,8 @@ public class UserOperationServiceImpl implements UserOperationService {
417 * 2). 大屏账户保存小屏会员的code 638 * 2). 大屏账户保存小屏会员的code
418 * 3). 小屏会员中保存大屏的id 639 * 3). 小屏会员中保存大屏的id
419 * @description 大小屏绑定,大屏账户保存小屏会员编码 640 * @description 大小屏绑定,大屏账户保存小屏会员编码
420 * @param resources 641 * @param resources 关注信息
421 * @return 642 * @return boolean
422 */ 643 */
423 @Override 644 @Override
424 public boolean subscribe(SubscribeBean resources) { 645 public boolean subscribe(SubscribeBean resources) {
...@@ -429,76 +650,83 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -429,76 +650,83 @@ public class UserOperationServiceImpl implements UserOperationService {
429 String headImgUrl = resources.getHeadimgurl(); 650 String headImgUrl = resources.getHeadimgurl();
430 651
431 // 小屏账户 652 // 小屏账户
432 UserWeixinDTO _userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId, openId); 653 UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId, appId, openId);
433 654
434 MemberDTO memberDTO = null; 655 MemberDTO memberDTO;
435 if (Objects.isNull(_userWeixinDTO.getId()) || StringUtils.isBlank(_userWeixinDTO.getUnionid()) || 656 if (Objects.isNull(userWeixinDTO.getId()) || StringUtils.isBlank(userWeixinDTO.getUnionid()) ||
436 Objects.isNull(_userWeixinDTO.getMemberId())) { 657 Objects.isNull(userWeixinDTO.getMemberId())) {
437 658
438 UserWeixin userWeixin = new UserWeixin(); 659 UserWeixin userWeixin = new UserWeixin();
439 BeanUtils.copyProperties(resources, userWeixin); 660 BeanUtils.copyProperties(resources, userWeixin);
440 userWeixin.setStatus(SUBSCRIBE_STATUS); 661 userWeixin.setStatus(SUBSCRIBE_STATUS);
662 userWeixin.setNickname(nickname);
663 userWeixin.setHeadimgurl(headImgUrl);
441 664
442 // 创建小屏账户同时创建会员 665 // 创建小屏账户同时创建会员
443 _userWeixinDTO = this.createWeixinUserAndMember(userWeixin, 1); 666 userWeixinDTO = this.createWeixinUserAndMember(userWeixin, 1);
444 667 Long memberId = userWeixinDTO.getMemberId();
445 Long memberId = _userWeixinDTO.getMemberId();
446 memberDTO = this.memberService.findById(memberId); 668 memberDTO = this.memberService.findById(memberId);
447 memberDTO.setVip(SUBSCRIBE_STATUS);
448 669
449 } else { 670 } else {
450 671
451 // 修改微信账户关注状态 672 // 修改微信账户关注状态
452 _userWeixinDTO = this.doUpdateUserWeiXinStatus(_userWeixinDTO, SUBSCRIBE_STATUS); 673 UserWeixin userWeixin = new UserWeixin();
453 674 userWeixin.setId(userWeixinDTO.getId());
675 userWeixin.setStatus(SUBSCRIBE_STATUS);
676 userWeixinDTO = this.userWeixinService.doUpdateWeixinStatus(userWeixin);
454 // 小屏会员 677 // 小屏会员
455 memberDTO = this.findMemberByAppIdAndOpenId(appId,openId); 678 memberDTO = this.memberService.findById(userWeixinDTO.getMemberId());
456
457 if (memberDTO != null) {
458 679
459 if (StringUtils.isNotBlank(headImgUrl) && StringUtils.isNotBlank(nickname)) {
460 memberDTO.setAvatarUrl(headImgUrl);
461 memberDTO.setNickname(nickname);
462 } 680 }
463 681
682 Member member = new Member();
683 member.setId(memberDTO.getId());
684 if (Objects.nonNull(memberDTO.getId())) {
464 Integer vip = memberDTO.getVip(); 685 Integer vip = memberDTO.getVip();
465 // 未购买付费会员 686 // 未购买付费会员
466 if (Objects.isNull(vip) || vip < 1) { 687 if (Objects.isNull(vip) || vip < 1) {
467 memberDTO.setVip(1); 688 member.setVip(1);
468 } 689 member.setVipExpireTime(null);
469 690 } else {
691 member.setVip(vip);
470 } 692 }
471 } 693 }
472
473 // 修改会员信息 694 // 修改会员信息
474 MemberDTO _memberDTO1 = this.doUpdateMemberByMemberDTO(memberDTO); 695 memberDTO = this.memberService.doUpdateMemberVipAndVipExpireTime(member);
475 log.info("发送关注消息至大屏侧,发送的账号信息 ==>> {} || 会员信息 ==>> {}", _userWeixinDTO , _memberDTO1); 696 log.info("发送关注消息至大屏侧,发送的账号信息 ==>> {} || 会员信息 ==>> {}", userWeixinDTO , memberDTO);
476 // 同步至iptv 697 // 同步大屏侧
477 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncSubscribe(new MemberAndWeixinUserDTO(_memberDTO1, _userWeixinDTO)); 698 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncSubscribe(new MemberAndWeixinUserDTO(memberDTO, userWeixinDTO));
478
479 699
480 // 大屏信息 700 // 大屏信息
481 JSONObject iptvUserInfo = resources.getIptvUserInfo(); 701 JSONObject visUserInfo = resources.getIptvUserInfo();
482 log.info("存储的大小屏账号信息 iptvUserInfo ==>> {}" , iptvUserInfo); 702 log.info("存储的大小屏账号信息 iptvUserInfo ==>> {}" , visUserInfo);
483 703 if (Objects.nonNull(visUserInfo)) {
484 if (Objects.nonNull(iptvUserInfo)) {
485 // 大屏账户 704 // 大屏账户
486 String platformAccount = iptvUserInfo.getString("platformAccount"); 705 String platformAccount = visUserInfo.getString("platformAccount");
487 log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount); 706
488 log.info("绑定开始"); 707 if (StringUtils.isBlank(platformAccount)) {
708
709 platformAccount = visUserInfo.getString("platformUserId");
710
711 if (StringUtils.isBlank(platformAccount)) {
712 platformAccount = visUserInfo.getString("nNO");
713 }
489 714
490 if (StringUtils.isBlank(platformAccount)) { 715 if (StringUtils.isBlank(platformAccount)) {
491 log.warn("绑定失败,platformAccount is null "); 716 log.error("关注后绑定失败,platformAccount is null ");
492 return false; 717 return false;
493 } 718 }
719 }
494 720
721 log.info("存储的大屏账号信息 platformAccount ==>> {}" , platformAccount);
495 // 绑定 722 // 绑定
496 this.bind(memberDTO, platformAccount); 723 this.bind(memberDTO, platformAccount);
497 log.info("绑定结束"); 724 log.info("绑定结束");
498 } 725 }
499 726
500 // 保存关注记录 727 // 保存关注记录
501 String sourceInfo = resources.getSourceInfo(); 728 JSONObject sourceInfo = resources.getSourceInfo();
729 log.info("保存关注记录,数据 [subscribe#{}]", sourceInfo);
502 this.saveWechatSubscribeRecord(memberDTO, sourceInfo, 1); 730 this.saveWechatSubscribeRecord(memberDTO, sourceInfo, 1);
503 731
504 return true; 732 return true;
...@@ -507,56 +735,61 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -507,56 +735,61 @@ public class UserOperationServiceImpl implements UserOperationService {
507 735
508 /** 736 /**
509 * 737 *
510 * @param memberDTO 738 * @param memberDTO 会员
511 * @param subscribe 739 * @param subscribe 关注状态
512 * @param sourceInfo 740 * @param sourceInfo 来源描述
513 */ 741 */
514 private void saveWechatSubscribeRecord(MemberDTO memberDTO, String sourceInfo, int subscribe) { 742 private void saveWechatSubscribeRecord(MemberDTO memberDTO, JSONObject sourceInfo, int subscribe) {
515 743
516 WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord(); 744 WechatSubscribeRecord wechatSubscribeRecord = new WechatSubscribeRecord();
517 wechatSubscribeRecord.setCode(IdWorker.generatorString()); 745 wechatSubscribeRecord.setCode("subscribe_"+UUID.randomUUID().toString());
518 wechatSubscribeRecord.setMemberId(memberDTO.getId()); 746 wechatSubscribeRecord.setMemberId(memberDTO.getId());
519 wechatSubscribeRecord.setOperationFlag(subscribe); 747 wechatSubscribeRecord.setOperationFlag(subscribe);
520 if (StringUtils.isBlank(sourceInfo)) { 748 if (Objects.nonNull(sourceInfo)) {
521 wechatSubscribeRecord.setEntityType(3); 749
522 } else { 750 // 内容ID,entityId:实体ID
523 JSONObject jsonObject = JSONObject.parseObject(sourceInfo, JSONObject.class); 751 Object entityId = sourceInfo.get("entityId");
524 Object activityId = jsonObject.get("activityId"); 752 if (Objects.nonNull(entityId) && StringUtils.isNotBlank(entityId.toString())) {
525 Object activityCode = jsonObject.get("activityCode"); 753 wechatSubscribeRecord.setEntityId(Long.parseLong(entityId.toString()));
526 Object entityType = jsonObject.get("entityType"); 754 }
527 if (Objects.nonNull(entityType)) { 755 // 内容Code, entityCode: 实体Code
528 String s = entityType.toString(); 756 Object entityCode = sourceInfo.get("entityCode");
529 switch (s) { 757 if (Objects.nonNull(entityCode) && StringUtils.isNotBlank(entityCode.toString())) {
530 case "1": 758 wechatSubscribeRecord.setEntityCode(entityCode.toString());
531 wechatSubscribeRecord.setSourceType(1); 759 }
532 wechatSubscribeRecord.setEntityType(1); 760 // 内容类型,entityType:不填/空:首页;1:分类列表;2:商品;3:活动;4:投票对象;5:证书;6:用户上传内容;99:其他;
533 break; 761 Object entityType = sourceInfo.get("entityType");
534 case "2": 762 if (Objects.nonNull(entityType) && StringUtils.isNotBlank(entityType.toString())) {
535 if (Objects.nonNull(activityId)) 763 wechatSubscribeRecord.setEntityType(Integer.parseInt(entityType.toString()));
536 wechatSubscribeRecord.setEntityId(Long.valueOf(activityId.toString())); 764 }
537 if (Objects.nonNull(activityCode)) 765 // 微信场景类型,sourceType
538 wechatSubscribeRecord.setEntityCode(activityCode.toString()); 766 Object sourceType = sourceInfo.get("sourceType");
539 wechatSubscribeRecord.setSourceType(2); 767 if (Objects.nonNull(sourceType) && StringUtils.isNotBlank(sourceType.toString())) {
540 wechatSubscribeRecord.setEntityType(2); 768 wechatSubscribeRecord.setWxScence(Integer.parseInt(sourceType.toString()));
541 break;
542 default:
543 wechatSubscribeRecord.setSourceType(3);
544 wechatSubscribeRecord.setEntityType(3);
545 break;
546 } 769 }
770 // 来源描述,sourceDesc:系统/运营手动维护
771 Object sourceDesc = sourceInfo.get("sourceDesc");
772 if (Objects.nonNull(sourceType) && StringUtils.isNotBlank(sourceDesc.toString())) {
773 wechatSubscribeRecord.setSourceDesc(sourceDesc.toString());
774 }
775 // 业务场景,0-分享 1-大屏扫码免费看 2-大屏线上活动扫码引导关注 3-小屏线上活动长按二维码引导关注 4-线下活动海报 5-线下机构/渠道引流 99-其他
776 Object sourceScence = sourceInfo.get("sourceScence");
777 if (Objects.nonNull(sourceScence) && StringUtils.isNotBlank(sourceScence.toString())) {
778 wechatSubscribeRecord.setSourceScence(Integer.parseInt(sourceScence.toString()));
547 } 779 }
548 780
549 wechatSubscribeRecord.setSourceInfo(sourceInfo);
550 } 781 }
551 782
783 log.info("保存关注记录,落库对象 subscribe# wechatSubscribeRecord ==>> {}", wechatSubscribeRecord);
552 this.wechatSubscribeRecordService.create(wechatSubscribeRecord); 784 this.wechatSubscribeRecordService.create(wechatSubscribeRecord);
785
553 } 786 }
554 787
555 788
556 /** 789 /**
557 * 微信公众号取消关注 790 * 微信公众号取消关注
558 * @param resources 791 * @param resources 参数
559 * @return 792 * @return boolean
560 */ 793 */
561 @Override 794 @Override
562 public boolean unsubscribe(SubscribeBean resources) { 795 public boolean unsubscribe(SubscribeBean resources) {
...@@ -565,20 +798,44 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -565,20 +798,44 @@ public class UserOperationServiceImpl implements UserOperationService {
565 String openId = resources.getOpenid(); 798 String openId = resources.getOpenid();
566 799
567 // 修改关注状态 0:未关注 800 // 修改关注状态 0:未关注
568 UserWeixinDTO userWeixinDTO = this.doUpdateUserWeiXinStatus(appId, openId, UNSUBSCRIBE_STATUS); 801 UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId);
802
803 if (Objects.isNull(userWeixinDTO.getId())) {
804 log.error("取关失败,通过appid ==>> {} 和 openId ==>> {} 无法查询到指定的微信账号", appId, openId);
805 return false;
806 }
807
808 if (Objects.isNull(userWeixinDTO.getMemberId())) {
809 log.error("取关失败,该微信账号无会员id ==>> {}", userWeixinDTO);
810 return false;
811 }
812
813 UserWeixin userWeixin = new UserWeixin();
814 userWeixin.setId(userWeixinDTO.getId());
815 userWeixin.setStatus(UNSUBSCRIBE_STATUS);
816 userWeixinDTO = this.userWeixinService.doUpdateWeixinStatus(userWeixin);
569 817
570 // 会员 818 // 会员
571 MemberDTO memberDTO = this.findMemberByUserWeixinDTO(userWeixinDTO); 819 MemberDTO memberDTO = this.memberService.findById(userWeixinDTO.getMemberId());
572 820
573 memberDTO.setUserIptvId(null);
574 // 修改会员vip,如果没有购买会员则取消团粉 821 // 修改会员vip,如果没有购买会员则取消团粉
575 MemberDTO _memberDTO = this.doUpdateMemberVip(memberDTO, 0); 822 Integer vip = memberDTO.getVip();
576 823 vip = (vip == null ? 0 : vip);
577 // 同步至iptv 824 // 未购买付费会员
578 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(_memberDTO, userWeixinDTO)); 825 if (vip <= 1) {
826 Member member = new Member();
827 member.setId(memberDTO.getId());
828 member.setCode(memberDTO.getCode());
829 member.setVipExpireTime(null);
830 member.setVip(0);
831 memberDTO = this.memberService.doUpdateMemberVipAndVipExpireTime(member);
832 }
579 833
580 // 关注记录 834 // 关注记录
581 this.saveWechatSubscribeRecord(_memberDTO, "",2); 835 this.saveWechatSubscribeRecord(memberDTO, null,2);
836
837 // 同步至iptv
838 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnsubscribe(new MemberAndWeixinUserDTO(memberDTO, userWeixinDTO));
582 839
583 return true; 840 return true;
584 } 841 }
...@@ -588,8 +845,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -588,8 +845,7 @@ public class UserOperationServiceImpl implements UserOperationService {
588 try { 845 try {
589 if (StringUtils.isNotBlank(headimgurl)) { 846 if (StringUtils.isNotBlank(headimgurl)) {
590 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 847 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
591 String image = RestTemplateClient.netImage(headimgurlDecode); 848 return RestTemplateClient.netImage(headimgurlDecode);
592 return image;
593 } 849 }
594 } catch (Exception e) { 850 } catch (Exception e) {
595 log.info("头像解析失败!!!"); 851 log.info("头像解析失败!!!");
...@@ -601,8 +857,8 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -601,8 +857,8 @@ public class UserOperationServiceImpl implements UserOperationService {
601 857
602 /** 858 /**
603 * 更新大屏信息,同时判断是否已经关注,如果关注了则不跳转H5页面 859 * 更新大屏信息,同时判断是否已经关注,如果关注了则不跳转H5页面
604 * @param data 860 * @param data 参数
605 * @return 861 * @return UserWeixinDTO
606 */ 862 */
607 @Override 863 @Override
608 public UserWeixinDTO saveUserInfo(String data) { 864 public UserWeixinDTO saveUserInfo(String data) {
...@@ -612,7 +868,6 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -612,7 +868,6 @@ public class UserOperationServiceImpl implements UserOperationService {
612 JSONObject json = JSONObject.parseObject(data); 868 JSONObject json = JSONObject.parseObject(data);
613 String unionId = json.getString("unionid"); 869 String unionId = json.getString("unionid");
614 // 订阅号appid 870 // 订阅号appid
615 // String appId = json.getString("dyAppid");
616 String appId = json.getString("appid"); 871 String appId = json.getString("appid");
617 872
618 try { 873 try {
...@@ -642,8 +897,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -642,8 +897,7 @@ public class UserOperationServiceImpl implements UserOperationService {
642 897
643 // 若未传dyAppId。不走下面的流程 898 // 若未传dyAppId。不走下面的流程
644 if (StrUtil.isNotBlank(appId)) { 899 if (StrUtil.isNotBlank(appId)) {
645 UserWeixinDTO userWeixinDTO = this.findUserWeiXinByUnionIdAndAppId(unionId,appId); 900 return this.findUserWeiXinByUnionIdAndAppId(unionId,appId);
646 return userWeixinDTO;
647 } 901 }
648 902
649 } catch (Exception e) { 903 } catch (Exception e) {
...@@ -655,76 +909,107 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -655,76 +909,107 @@ public class UserOperationServiceImpl implements UserOperationService {
655 909
656 /** 910 /**
657 * 大屏更换主账号 911 * 大屏更换主账号
658 * @param resources 912 * @param resources 大屏账号信息
913 * @return boolean
659 */ 914 */
660 @Override 915 @Override
661 public void changeMainAccount(UserTv resources) { 916 public boolean changeMainAccount(UserTv resources) {
662 917
663 // 会员编码 918 // 会员编码
664 String memberCode = resources.getMemberCode(); 919 String memberCode = resources.getMemberCode();
665 this.findMemberByCode(memberCode);
666 920
667 String platformAccount = resources.getPlatformAccount(); 921 String platformAccount = resources.getPlatformAccount();
668 922 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
669 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount);
670
671 if (Objects.nonNull(userTvDTO)) { 923 if (Objects.nonNull(userTvDTO)) {
672 if (StringUtils.isNotBlank(userTvDTO.getPriorityMemberCode()) && userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode)) 924 if (StringUtils.isNotBlank(userTvDTO.getPriorityMemberCode()) && userTvDTO.getPriorityMemberCode().equalsIgnoreCase(memberCode))
673 throw new BadRequestException("会员已是主账户"); 925 throw new BadRequestException("会员已是主账户");
674
675 } else { 926 } else {
676
677 throw new EntityNotFoundException(UserTvDTO.class , "platformAccount" , GlobeExceptionMsg.IPTV_IS_NULL); 927 throw new EntityNotFoundException(UserTvDTO.class , "platformAccount" , GlobeExceptionMsg.IPTV_IS_NULL);
678
679 } 928 }
680 929
681 // 设置主会员 930 // 设置主会员
682 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberCode, "manual"); 931 UserTv userTv = new UserTv();
932 userTv.setId(userTvDTO.getId());
933 userTv.setPriorityMemberCode(memberCode);
934 this.userTvService.doUpdatePriorityMemberCode(userTv);
683 935
936 userTvDTO.setPriorityMemberCode(memberCode);
684 // 同步至iptv 937 // 同步至iptv
685 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUserTv(_userTvDTO); 938 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUserTvChangeMainAccount(userTvDTO);
939
940 return true;
686 } 941 }
687 942
688 /** 943 /**
689 * 大屏解绑 944 * 大屏解绑
690 * @param resources 945 * @param resources 大屏解绑参数
946 * @return boolean
691 */ 947 */
692 @Override 948 @Override
693 public void tvUnbind(TvUnBindBean resources) { 949 public boolean tvUnbind(TvUnBindBean resources) {
694 950
695 Boolean autoModel = resources.getAutoModel(); 951 // 希望绑定的会员code
696 String bindMemberCode = resources.getBindMemberCode(); 952 String bindMemberCode = resources.getBindMemberCode();
697 String platformAccount = resources.getPlatformAccount(); 953 String platformAccount = resources.getPlatformAccount();
698 String memberCode = resources.getMemberCode(); 954 String memberCode = resources.getMemberCode();
699 955
700 UserTvDTO userTvDTO = this.findByPlatformAccount(platformAccount); 956 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
701 log.info("大屏解绑,通过大屏账号查询大屏账号信息,结果 userTvDTO ==>> {}", userTvDTO); 957 log.info("大屏解绑,通过大屏账号查询大屏账号信息,结果 userTvDTO ==>> {}", userTvDTO);
702 if (Objects.isNull(userTvDTO.getId())) 958 if (Objects.isNull(userTvDTO.getId())) {
703 throw new EntityNotFoundException(UserTvDTO.class, "PlatformAccount", GlobeExceptionMsg.IPTV_IS_NULL); 959 log.error("大屏解绑失败,无对应的大屏账号信息, platformAccount ==>> {}", platformAccount);
960 return false;
961 }
704 962
705 MemberDTO memberDTO = this.memberService.findByCode(memberCode); 963 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
706 log.info("大屏解绑,通过会员code查询会员信息,结果memberDTO==>>{}", memberDTO); 964 log.info("大屏解绑,通过会员code查询会员信息,结果memberDTO==>>{}", memberDTO);
707 965 if (Objects.isNull(memberDTO.getId())) {
966 log.error("大屏解绑失败,无对应的会员信息, memberCode ==>> {}", memberCode);
967 return false;
968 }
708 969
709 // 解绑(置空大屏信息) 970 // 解绑(置空大屏信息)
710 log.info("开始置空会员的user_iptv_id ==>> {}", memberDTO); 971 Member member = new Member();
711 MemberDTO _memberDTO = this.minaUnbind_(memberDTO); 972 member.setId(memberDTO.getId());
712 if (Objects.isNull(_memberDTO)) { 973 member.setCode(memberDTO.getCode());
713 _memberDTO = memberDTO; 974 member.setBindIptvTime(null);
714 } 975 member.setUserIptvId(null);
715 log.info("会员信息置空大屏的结果,_memberDTO ==>> {}", _memberDTO); 976 member.setBindIptvPlatformType(null);
977 log.info("置空会员绑定的大屏信息, member ==>> {}", member);
978 memberDTO = this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member);
979 log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO);
980 memberDTO.setPlatformAccount(platformAccount);
716 981
717 // 置空主账号 982 if (StringUtils.isBlank(bindMemberCode)) {
718 log.info("开始置空大屏账号的主会员priorityMemberCode"); 983 UserTv userTv = new UserTv();
719 UserTvDTO _userTvDTO = this.resetMainAccount(memberCode, userTvDTO.getId(), autoModel, bindMemberCode); 984 userTv.setId(userTvDTO.getId());
720 if (Objects.isNull(_userTvDTO)){ 985 userTv.setPriorityMemberCode(null);
721 _userTvDTO = userTvDTO; 986 this.userTvService.doUpdatePriorityMemberCode(userTv);
987
988 UserTvDTO _userTvDTO = new UserTvDTO();
989 _userTvDTO.setPlatformAccount(platformAccount);
990 _userTvDTO.setPriorityMemberCode(null);
991 log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", _userTvDTO);
992 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO));
993
994 this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, "");
995
996 } else {
997
998 UserTv userTv = new UserTv();
999 userTv.setId(userTvDTO.getId());
1000 userTv.setPriorityMemberCode(bindMemberCode);
1001 // 绑定新的主账号
1002 this.userTvService.doUpdatePriorityMemberCode(userTv);
1003
1004 UserTvDTO _userTvDTO = new UserTvDTO();
1005 _userTvDTO.setPlatformAccount(platformAccount);
1006 _userTvDTO.setPriorityMemberCode(bindMemberCode);
1007 log.info("大屏账号置空主会员的结果,userTvDTO ==>> {}", userTvDTO);
1008 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO));
1009 this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, bindMemberCode);
722 } 1010 }
723 log.info("大屏账号置空主会员的结果,_userTvDTO ==>> {}", _userTvDTO);
724 1011
725 // 同步至iptv 1012 return true;
726 log.info("开始同步解绑,参数 ==>> {} ",new MemberAndUserTvDTO(_memberDTO, _userTvDTO));
727 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO));
728 } 1013 }
729 1014
730 1015
...@@ -904,7 +1189,6 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -904,7 +1189,6 @@ public class UserOperationServiceImpl implements UserOperationService {
904 } else { 1189 } else {
905 log.info("传过来的观影时间 ==>> {} 和今天的时间 ==>> {} 不相同,不做处理", userCollectionDetail.getCreateTime().getTime(), 1190 log.info("传过来的观影时间 ==>> {} 和今天的时间 ==>> {} 不相同,不做处理", userCollectionDetail.getCreateTime().getTime(),
906 new Date().toInstant().getEpochSecond()); 1191 new Date().toInstant().getEpochSecond());
907 continue;
908 } 1192 }
909 1193
910 } 1194 }
...@@ -921,57 +1205,62 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -921,57 +1205,62 @@ public class UserOperationServiceImpl implements UserOperationService {
921 @Override 1205 @Override
922 public boolean minaBind(BindBean resources) { 1206 public boolean minaBind(BindBean resources) {
923 1207
924 Long _memberId = resources.getMemberId(); 1208 Long memberId = resources.getMemberId();
925 1209
926 String platformAccount = resources.getPlatformAccount(); 1210 String platformAccount = resources.getPlatformAccount();
927 1211
928 // 大屏账户 1212 // 大屏账户
929 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount); 1213 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
1214 log.info("查询大屏账号信息, userTvDTO ==>> {}", userTvDTO);
930 // 账户是否存在 1215 // 账户是否存在
931 if (Objects.isNull(userTvDTO.getId())) { 1216 if (Objects.isNull(userTvDTO.getId())) {
932 log.error("appletBind ==> platformAccount ==> [{}]",platformAccount); 1217 log.error("大屏账号信息不存在,platformAccount ==> {}",platformAccount);
933 throw new EntityNotFoundException(UserTvDTO.class,"id",GlobeExceptionMsg.IPTV_IS_NULL); 1218 return false;
934 } 1219 }
935 1220
936 resources.setPlatformUserId(userTvDTO.getId());
937
938 UserWeixinDTO userWeixinDTO = null;
939 // 微信账户 1221 // 微信账户
940 if (Objects.nonNull(_memberId)) { 1222 if (Objects.nonNull(memberId)) {
941 userWeixinDTO = this.userWeixinService.findFirstByMemberId(_memberId); 1223 UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByMemberId(memberId);
942 } 1224 log.info("检查小屏账号是否存在, userWeixinDTO ==>> {}", userWeixinDTO);
943 // 账户是否存在 1225 // 账户是否存在
944 if (Objects.isNull(userWeixinDTO.getId())) { 1226 if (Objects.isNull(userWeixinDTO.getId())) {
945 log.error("appletBind ==> weixinId ==> [{}]",userWeixinDTO.getId()); 1227 log.error("通过会员id无法找到对应的微信账号,memberId ==> {}", memberId);
946 throw new EntityNotFoundException(UserWeixinDTO.class, "id", userWeixinDTO.getId().toString()); 1228 return false;
947 } 1229 }
948
949 // 会员
950 Long memberId = userWeixinDTO.getMemberId();
951 if (Objects.isNull(memberId)) {
952 log.error("appletBind ==> memberId ==> [{}]",memberId);
953 throw new EntityNotFoundException(UserWeixinDTO.class, "memberId", memberId.toString());
954 } 1230 }
955 1231
956 MemberDTO memberDTO = this.findMemberById(memberId); 1232 MemberDTO memberDTO = this.memberService.findById(memberId);
957 1233 log.info("检查会员是否存在, memberDTO ==>> {}", memberDTO);
1234 if (Objects.nonNull(memberDTO.getId())) {
958 Long userIptvId = memberDTO.getUserIptvId(); 1235 Long userIptvId = memberDTO.getUserIptvId();
959 if (Objects.nonNull(userIptvId)) 1236 if (Objects.nonNull(userIptvId)) {
1237 log.error("该会员已绑定,大屏id ==> {}", userIptvId);
960 throw new BadRequestException(GlobeExceptionMsg.ALREADY_BIND); 1238 throw new BadRequestException(GlobeExceptionMsg.ALREADY_BIND);
1239 }
1240 } else {
1241 log.error("会员信息不存在,请检查数据, memberId ==>> {}", memberId);
1242 return false;
1243 }
961 1244
962 // 主账户会员
963 String code = memberDTO.getCode();
964
965 // 更新大屏信息,同步大屏信息时使用
966 userTvDTO.setMemberCode(code);
967 // 主账户 1245 // 主账户
968 String priorityMemberCode = userTvDTO.getPriorityMemberCode(); 1246 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
969 1247
970 if (StringUtils.isBlank(priorityMemberCode)) { 1248 if (StringUtils.isBlank(priorityMemberCode)) {
971 // 设置主账号 1249 priorityMemberCode = memberDTO.getCode();
972 userTvDTO.setPriorityMemberCode(code); 1250 log.info("大屏账号为绑定主账号,开始设置主会员 priorityMemberCode ==>> {}", priorityMemberCode);
1251 UserTv userTv = new UserTv();
1252 userTv.setId(userTvDTO.getId());
1253 userTv.setPriorityMemberCode(priorityMemberCode);
1254 // 更新大屏账户
1255 this.userTvService.doUpdatePriorityMemberCode(userTv);
1256
1257
1258 userTvDTO.setPriorityMemberCode(memberDTO.getCode());
973 } 1259 }
974 1260
1261 Member member = new Member();
1262 member.setId(memberDTO.getId());
1263 member.setCode(memberDTO.getCode());
975 String platform = userTvDTO.getPlatform(); 1264 String platform = userTvDTO.getPlatform();
976 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 1265 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
977 Integer bindIptvPlatformType = 0; 1266 Integer bindIptvPlatformType = 0;
...@@ -987,66 +1276,42 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -987,66 +1276,42 @@ public class UserOperationServiceImpl implements UserOperationService {
987 if (UserConstant.platform_dx.contains(platform)) { 1276 if (UserConstant.platform_dx.contains(platform)) {
988 bindIptvPlatformType = PLATFORM_LIST[1]; 1277 bindIptvPlatformType = PLATFORM_LIST[1];
989 } 1278 }
990 memberDTO.setUserIptvId(userTvDTO.getId()); 1279 member.setUserIptvId(userTvDTO.getId());
991 memberDTO.setBindIptvTime(TimestampUtil.now()); 1280 member.setBindIptvTime(TimestampUtil.now());
992 memberDTO.setBindIptvPlatformType(bindIptvPlatformType); 1281 member.setBindIptvPlatformType(bindIptvPlatformType);
993 memberDTO.setPlatformAccount(platformAccount); 1282 log.info("修改小屏会员对应的绑定关系,member ==>> {}", member);
994
995 // 更新大屏账户
996 UserTvDTO _userTvDTO = this.doUpdateUserTv(userTvDTO);
997 // 修改会员信息 1283 // 修改会员信息
998 MemberDTO _memberDTO = this.doUpdateMemberByMemberDTO(memberDTO); 1284 this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member);
999 1285
1286 memberDTO.setPlatformAccount(platformAccount);
1287 log.info("发送绑定消息至大屏,memberDTO ==>> {} || userTvDTO ==>> {}", memberDTO, userTvDTO);
1000 // 同步至iptv 1288 // 同步至iptv
1001 ((UserOperationServiceImpl)AopContext.currentProxy()) 1289 ((UserOperationServiceImpl)AopContext.currentProxy())
1002 .asyncAppletBind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO)); 1290 .asyncMinaBind(new MemberAndUserTvDTO(memberDTO, userTvDTO));
1291
1292 this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, memberDTO.getCode());
1003 1293
1004 return true; 1294 return true;
1005 } 1295 }
1006 1296
1007 /**
1008 *
1009 * @param memberCode
1010 * @param platformAccount
1011 */
1012 @Override 1297 @Override
1013 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 1298 public boolean appBind(BindBean resources) {
1014 public void bind(String memberCode, String platformAccount) { 1299 return this.minaBind(resources);
1015 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
1016 this.bind(memberDTO,platformAccount);
1017 } 1300 }
1018 1301
1019 /** 1302 /**
1020 * 1303 *
1021 * @param memberDTO 1304 * @param resource 会员信息
1022 * @param userTvDTO 1305 * @param platformAccount 大屏账号
1306 * @return UserTvDTO
1023 */ 1307 */
1024 @Override 1308 @Override
1025 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) 1309 public UserTvDTO bind(MemberDTO resource, String platformAccount) {
1026 public void bind(MemberDTO memberDTO, UserTvDTO userTvDTO) { 1310 log.info("bind start");
1027 String platformAccount = userTvDTO.getPlatformAccount(); 1311 MemberDTO memberDTO = this.memberService.findByCode(resource.getCode());
1028 1312 log.info("查询会员信息 ==>> {}", memberDTO);
1029 if (StringUtils.isBlank(platformAccount)) { 1313 if (Objects.nonNull(memberDTO.getUserIptvId())) {
1030 return; 1314 return this.userTvService.findById(memberDTO.getUserIptvId());
1031 }
1032 // 绑定
1033 this.bind(memberDTO,platformAccount);
1034 }
1035
1036 /**
1037 *
1038 * @param memberDTO
1039 * @param platformAccount
1040 * @return
1041 */
1042 @Override
1043 public UserTvDTO bind(MemberDTO memberDTO, String platformAccount) {
1044 log.info("bind start");
1045 MemberDTO memberDTO1 = this.memberService.findByCode(memberDTO.getCode());
1046 log.info("查询会员信息 ==>> {}", memberDTO1);
1047 if (Objects.nonNull(memberDTO1.getUserIptvId())) {
1048 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO1.getUserIptvId());
1049 return userTvDTO;
1050 } 1315 }
1051 1316
1052 // 大屏账户 1317 // 大屏账户
...@@ -1056,9 +1321,19 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1056,9 +1321,19 @@ public class UserOperationServiceImpl implements UserOperationService {
1056 throw new BadRequestException(GlobeExceptionMsg.IPTV_IS_NULL); 1321 throw new BadRequestException(GlobeExceptionMsg.IPTV_IS_NULL);
1057 } 1322 }
1058 1323
1059 // mq同步数据时使用 1324 // 大屏是否绑定主账号,如果绑定了主账户则不操作大屏账户表
1060 memberDTO.setPlatformAccount(platformAccount); 1325 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
1326 if (StringUtils.isBlank(priorityMemberCode)) {
1327 UserTv userTv = new UserTv();
1328 userTv.setId(userTvDTO.getId());
1329 userTv.setPriorityMemberCode(memberDTO.getCode());
1330
1331 this.userTvService.doUpdatePriorityMemberCode(userTv);
1061 1332
1333 userTvDTO.setPriorityMemberCode(memberDTO.getCode());
1334 }
1335
1336 Member member = new Member();
1062 // 构建小屏会员对象,绑定user_iptv_id字段 1337 // 构建小屏会员对象,绑定user_iptv_id字段
1063 String platform = userTvDTO.getPlatform(); 1338 String platform = userTvDTO.getPlatform();
1064 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 1339 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
...@@ -1075,327 +1350,69 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1075,327 +1350,69 @@ public class UserOperationServiceImpl implements UserOperationService {
1075 if (UserConstant.platform_dx.contains(platform)) { 1350 if (UserConstant.platform_dx.contains(platform)) {
1076 bindIptvPlatformType = PLATFORM_LIST[1]; 1351 bindIptvPlatformType = PLATFORM_LIST[1];
1077 } 1352 }
1078 memberDTO.setUserIptvId(userTvDTO.getId()); 1353 member.setUserIptvId(userTvDTO.getId());
1079 memberDTO.setBindIptvTime(TimestampUtil.now()); 1354 member.setBindIptvTime(TimestampUtil.now());
1080 memberDTO.setBindIptvPlatformType(bindIptvPlatformType); 1355 member.setBindIptvPlatformType(bindIptvPlatformType);
1081 memberDTO.setPlatformAccount(platformAccount); 1356 member.setPlatformAccount(platformAccount);
1082 1357
1083 // 大屏是否绑定主账号,如果绑定了主账户则不操作大屏账户表
1084 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberDTO.getCode(), "auto");
1085 if (Objects.isNull(_userTvDTO)) {
1086 _userTvDTO = userTvDTO;
1087 }
1088 // 修改会员 1358 // 修改会员
1089 MemberDTO _memberDTO = this.doUpdateMemberByMemberDTO(memberDTO); 1359 this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member);
1090
1091 _memberDTO.setPlatformAccount(platformAccount);
1092 1360
1361 memberDTO.setPlatformAccount(platformAccount);
1093 1362
1094 log.info("发送到大屏侧的消息对象 会员信息 ==>> {} || 账号信息 ==>> {}", _memberDTO , _userTvDTO); 1363 log.info("发送绑定消息至大屏侧, 会员信息 ==>> {} || 账号信息 ==>> {}", memberDTO , userTvDTO);
1095 // 同步至iptv 1364 // 同步至大屏侧
1096 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncAppletBind(new MemberAndUserTvDTO(_memberDTO, _userTvDTO)); 1365 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncMinaBind(new MemberAndUserTvDTO(memberDTO, userTvDTO));
1097
1098 return null;
1099 }
1100
1101 /**
1102 *
1103 * @param unionid
1104 * @param appId
1105 * @return
1106 */
1107 private UserWeixinDTO findUserWeiXinByUnionIdAndAppId(String unionid, String appId) {
1108 return this.userWeixinService.findFirstByUnionidAndAppid(unionid,appId);
1109 }
1110
1111 /**
1112 * 修改会员vip状态
1113 */
1114 private MemberDTO doUpdateMemberVip(MemberDTO memberDTO,Integer vip1) {
1115 if (memberDTO != null) {
1116 Integer vip = memberDTO.getVip();
1117 vip = (vip == null ? 0 : vip);
1118 // 未购买付费会员
1119 if (vip <= 1) {
1120
1121 memberDTO.setVip(vip1);
1122 1366
1123 Member member = new Member(); 1367 this.updateUserTvSimplePriorityMemberCodeRedis(platformAccount, memberDTO.getCode());
1124 BeanUtils.copyProperties(memberDTO, member);
1125 this.memberService.update(member);
1126 1368
1127 return memberDTO; 1369 return userTvDTO;
1128 }
1129 } 1370 }
1130 1371
1131 return null;
1132 }
1133 1372
1134 /** 1373 private void updateUserTvSimplePriorityMemberCodeRedis(String platformAccount, String priorityMemberCode){
1135 * 获取小屏会员 1374 // 修改缓存中MemberSimple的大屏主账号信息,因为执行任务之前会去检查主会员d
1136 * @param userWeixinDTO 1375 UserTvSimpleDTO userTvSimpleDTO = this.userTvService.findSimpleByPlatformAccount(platformAccount);
1137 * @return 1376 if (Objects.nonNull(userTvSimpleDTO)) {
1138 */ 1377 userTvSimpleDTO.setPriorityMemberCode(priorityMemberCode);
1139 private MemberDTO findMemberByUserWeixinDTO(UserWeixinDTO userWeixinDTO) { 1378 JSONObject hashMap = JSONObject.parseObject(JSON.toJSONString(userTvSimpleDTO), JSONObject.class);
1140 Long memberId = userWeixinDTO.getMemberId(); 1379 this.redisUtils.set(RedisKeyConstants.cacheVisUserByPlatformAccount + "::" + platformAccount, hashMap);
1141 if (Objects.nonNull(memberId)) {
1142 MemberDTO memberDTO = this.findMemberById(memberId);
1143 return memberDTO;
1144 } 1380 }
1145 return null;
1146 } 1381 }
1147 1382
1148 /** 1383 /**
1149 * 修改微信公众号关注状态 1384 *
1150 * @param status 0:取消关注 1:关注 1385 * @param unionId 身份唯一标识
1151 */ 1386 * @param appId 应用标识
1152 private UserWeixinDTO doUpdateUserWeiXinStatus(String appId, String openId, Integer status) { 1387 * @return UserWeiXinDTO
1153
1154 UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId);
1155
1156 if (Objects.nonNull(userWeixinDTO.getId())) {
1157
1158 userWeixinDTO.setStatus(status);
1159
1160 UserWeixin userWeixin = new UserWeixin();
1161 BeanUtils.copyProperties(userWeixinDTO,userWeixin);
1162
1163 this.userWeixinService.update(userWeixin);
1164
1165 }
1166
1167 return userWeixinDTO;
1168
1169 }
1170
1171 /**
1172 * 修改微信公众号关注状态
1173 * @param status 0:取消关注 1:关注
1174 */ 1388 */
1175 public UserWeixinDTO doUpdateUserWeiXinStatus(UserWeixinDTO userWeixinDTO, Integer status) { 1389 private UserWeixinDTO findUserWeiXinByUnionIdAndAppId(String unionId, String appId) {
1176 1390 return this.userWeixinService.findFirstByUnionidAndAppid(unionId, appId);
1177 userWeixinDTO.setStatus(status);
1178
1179 UserWeixin userWeixin = new UserWeixin();
1180 BeanUtils.copyProperties(userWeixinDTO,userWeixin);
1181
1182 this.userWeixinService.update(userWeixin);
1183
1184 return userWeixinDTO;
1185
1186 } 1391 }
1187 1392
1188 /** 1393 /**
1189 * 获取会员 1394 * 获取会员
1190 * @param memberId 1395 * @param memberId 会员id
1191 * @return 1396 * @return MemberDTO
1192 */ 1397 */
1193 private MemberDTO findMemberById(Long memberId) { 1398 private MemberDTO findMemberById(Long memberId) {
1194 MemberDTO memberDTO = this.memberService.findById(memberId); 1399 return this.memberService.findById(memberId);
1195 return memberDTO;
1196 }
1197
1198 /**
1199 * 获取小屏会员
1200 * @param appId
1201 * @param openId
1202 * @return
1203 */
1204 private MemberDTO findMemberByAppIdAndOpenId(String appId, String openId) {
1205 UserWeixinDTO userWeixinDTO = this.userWeixinService.findFirstByAppIdAndOpenId(appId,openId);
1206 if (Objects.nonNull(userWeixinDTO)) {
1207 Long memberId = userWeixinDTO.getMemberId();
1208 return this.findMemberById(memberId);
1209 }
1210 return null;
1211 }
1212
1213 /**
1214 * 设置主会员
1215 * @description 检查大屏账户有没有绑定小屏会员,如果没有绑定就将当前会员的code保存到大屏账户中
1216 * @param userTvDTO
1217 * @param memberCode
1218 * @param auto manual:手动 auto:自动
1219 */
1220 private UserTvDTO bondPriorityMember(UserTvDTO userTvDTO, String memberCode, String auto) {
1221
1222 if (auto.equalsIgnoreCase("auto")) {
1223 // 主账户
1224 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
1225 if (StringUtils.isNotEmpty(priorityMemberCode)) {
1226 return null;
1227 }
1228 }
1229
1230 userTvDTO.setPriorityMemberCode(memberCode);
1231
1232 UserTv userTv = new UserTv();
1233 BeanUtils.copyProperties(userTvDTO, userTv);
1234 UserTvDTO _userTvDTO = this.updateUserTvUnsyncIptv(userTv);
1235
1236 return _userTvDTO;
1237 }
1238
1239 /**
1240 *
1241 * @param userTv
1242 * @return
1243 */
1244 private UserTvDTO updateUserTvUnsyncIptv(UserTv userTv){
1245 return this.userTvService.update(userTv);
1246 }
1247
1248 /**
1249 * 重置主账号
1250 * @param memberCode 会员code
1251 * @param id 大屏id
1252 * @param autoModel true:自动设置主账号 false: 手动设置
1253 */
1254 private UserTvDTO resetMainAccount(String memberCode, Long id, Boolean autoModel, String bindMemberCode) {
1255
1256 UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode);
1257 log.info("大屏解绑,重置大屏账号的主会员,查看当前会员是否是主账号 ==>>memberCode ==>> {} || 大屏账号 ==>> userTvDTO ==>> {}", userTvDTO);
1258 if (Objects.nonNull(userTvDTO.getId())) {
1259 log.info("主账号存在");
1260 if (StringUtils.isBlank(bindMemberCode)) {
1261 // 有其他绑定的小程序会员,排除自己
1262 /*List<MemberDTO> memberDTOList = this.memberService.findByUserIptvId(id);
1263 log.info("后台指定一个默认主会员,通过大屏id查询到的绑定的小屏会员memberDTOList ==>> {}", memberDTOList);
1264 if (!CollectionUtils.isEmpty(memberDTOList)) {
1265
1266 Long memberId = userTvDTO.getMemberId();
1267 MemberDTO memberDTO1 = this.memberService.findById(memberId);
1268
1269 List<MemberDTO> collect =
1270 memberDTOList.stream().filter(memberDTO ->
1271 !memberDTO.getCode().equalsIgnoreCase(memberCode) &&
1272 !memberDTO.getCode().equalsIgnoreCase(memberDTO1.getCode())).collect(Collectors.toList());
1273 log.info("过滤掉当前需要解绑的会员以及绑定的大屏会员之后剩余的会员列表 ==>> {}", memberDTOList);
1274
1275 if (!CollectionUtils.isEmpty(collect)) {
1276
1277 // 按绑定时间倒排
1278 collect.sort(new Comparator<MemberDTO>() {
1279 @Override
1280 public int compare(MemberDTO memberDTO, MemberDTO t1) {
1281 return t1.getBindIptvTime().compareTo(memberDTO.getBindIptvTime());
1282 }
1283 });
1284
1285 // 绑定新的主账号
1286 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, memberDTOList.get(0).getCode(), "manual");
1287 log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO);
1288
1289 return _userTvDTO;
1290
1291 } 1400 }
1292 1401
1293 } else {
1294
1295 log.info("无其他绑定的小屏会员信息 ");
1296 // 绑定新的主账号
1297 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, null, "manual");
1298 log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO);
1299 return _userTvDTO;
1300
1301 }*/
1302
1303 log.info("无其他绑定的小屏会员信息 ");
1304 // 绑定新的主账号
1305 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, null, "manual");
1306 log.info("绑定新的主账号 ==>> _userTvDTO ==>> {}", _userTvDTO);
1307 return _userTvDTO;
1308
1309 } else {
1310
1311 this.memberService.findByCode(bindMemberCode);
1312
1313 // 绑定新的主账号
1314 UserTvDTO _userTvDTO = this.bondPriorityMember(userTvDTO, bindMemberCode, "manual");
1315
1316 return _userTvDTO;
1317
1318 }
1319
1320 }
1321
1322 return userTvDTO;
1323
1324 }
1325
1326 /**
1327 * 解绑(置空大屏信息)
1328 * @param memberDTOS
1329 */
1330 private MemberDTO minaUnbind_(MemberDTO memberDTOS) {
1331
1332 // 若无关系,不做处理
1333 if (Objects.nonNull(memberDTOS) && Objects.isNull(memberDTOS.getUserIptvId()))
1334 return null;
1335
1336 Member member = new Member();
1337 memberDTOS.setBindIptvTime(null);
1338 memberDTOS.setUserIptvId(null);
1339 memberDTOS.setBindIptvPlatformType(null);
1340 BeanUtils.copyProperties(memberDTOS, member);
1341 log.info("大屏绑定,置空绑定的大屏信息, member ==>> {}", member);
1342 MemberDTO memberDTO = this.memberService.update(member);
1343 return memberDTO;
1344 }
1345 1402
1346 /** 1403 /**
1347 * 1404 *
1348 * @param memberCode 会员编码 1405 * @param unionId 身份标识
1349 * @return 1406 * @return UserWeixinDTO
1350 */
1351 private MemberDTO findMemberByCode(String memberCode) {
1352 return memberService.findByCode(memberCode);
1353 }
1354
1355 /**
1356 * 修改会员
1357 * @param memberDTO
1358 */
1359 private MemberDTO doUpdateMemberByMemberDTO(MemberDTO memberDTO){
1360 Member member = new Member();
1361 BeanUtils.copyProperties(memberDTO,member);
1362 member.setUpdateTime(TimestampUtil.now());
1363 log.info("doUpdateMemberByMemberDTO=====?>>member ==>> [{}]",member);
1364 return this.doUpdateMember(member);
1365 }
1366
1367 /**
1368 * 修改会员
1369 * @param member
1370 */
1371 private MemberDTO doUpdateMember(Member member){
1372 return this.memberService.update(member);
1373 }
1374
1375 /**
1376 *
1377 * @param unionId
1378 * @return
1379 */ 1407 */
1380 private UserWeixinDTO findFirstByUnionId(String unionId) { 1408 private UserWeixinDTO findFirstByUnionId(String unionId) {
1381 return this.userWeixinService.findFirstByUnionId(unionId); 1409 return this.userWeixinService.findFirstByUnionId(unionId);
1382 } 1410 }
1383 1411
1384 /** 1412 /**
1385 * 更新大屏
1386 * @param userTvDTO
1387 */
1388 private UserTvDTO doUpdateUserTv(UserTvDTO userTvDTO) {
1389 UserTv userTv = new UserTv();
1390 BeanUtils.copyProperties(userTvDTO,userTv);
1391 userTv.setUpdateTime(TimestampUtil.now());
1392 return this.userTvService.update(userTv);
1393 }
1394
1395 /**
1396 * 同一用户有多个微信APP的情况下展示同一个账户信息 1413 * 同一用户有多个微信APP的情况下展示同一个账户信息
1397 * 原则:那个先创建就用那个id 1414 * 原则:那个先创建就用那个id
1398 * @param userWeixinDTO 1415 * @param userWeixinDTO 微信信息
1399 */ 1416 */
1400 private UserWeixinDTO getFirstId(UserWeixinDTO userWeixinDTO) { 1417 private UserWeixinDTO getFirstId(UserWeixinDTO userWeixinDTO) {
1401 String unionid = userWeixinDTO.getUnionid(); 1418 String unionid = userWeixinDTO.getUnionid();
...@@ -1442,20 +1459,9 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1442,20 +1459,9 @@ public class UserOperationServiceImpl implements UserOperationService {
1442 1459
1443 /** 1460 /**
1444 * 获取小屏账户 1461 * 获取小屏账户
1445 * @param unionId 1462 * @param appId 应用标识
1446 * @param appId 1463 * @param openId 应用唯一标识
1447 * @param openId 1464 * @return UserWeixinDTO
1448 * @return
1449 */
1450 private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId(String unionId, String appId, String openId) {
1451 return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId);
1452 }
1453
1454 /**
1455 * 获取小屏账户
1456 * @param appId
1457 * @param openId
1458 * @return
1459 */ 1465 */
1460 private UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) { 1466 private UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) {
1461 return this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); 1467 return this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId);
...@@ -1463,62 +1469,64 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1463,62 +1469,64 @@ public class UserOperationServiceImpl implements UserOperationService {
1463 1469
1464 /** 1470 /**
1465 * 1471 *
1466 * @param member 1472 * @param member 会员信息
1467 * @return 1473 * @return MemberDTO
1468 */ 1474 */
1469 private MemberDTO createMember(Member member){ 1475 public MemberDTO createMember(Member member){
1470 return this.memberService.create(member); 1476 MemberDTO memberDTO = this.memberService.create(member);
1477 if (Objects.nonNull(memberDTO.getId())) {
1478 MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO();
1479 BeanUtils.copyProperties(memberDTO, memberSimpleDTO);
1480 this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById+"::"+memberDTO.getId(), memberSimpleDTO);
1481 }
1482 return memberDTO;
1471 } 1483 }
1472 1484
1473 /** 1485 /**
1474 * 1486 *
1475 * @param resources 1487 * @param resources 大屏账号信息
1476 * @param memberId 1488 * @param memberId 会员id
1477 * @return 1489 * @return UserTvDTO
1478 */ 1490 */
1479 private UserTvDTO createTvUser(UserTv resources, Long memberId, String memberCode){ 1491 private UserTvDTO createTvUser(UserTv resources, Long memberId, String memberCode){
1480 1492
1481 resources.setMemberId(memberId); 1493 resources.setMemberId(memberId);
1482 resources.setMemberCode(memberCode); 1494 resources.setMemberCode(memberCode);
1483 UserTvDTO userTvDTO = this.userTvService.create(resources); 1495 return this.userTvService.create(resources);
1484 return userTvDTO;
1485 } 1496 }
1486 1497
1487 /** 1498 /**
1488 * 1499 *
1489 * @param resource 1500 * @param resource 微信信息
1490 * @param memberId 1501 * @param memberId 会员id
1491 * @param memberCode 1502 * @param memberCode 会员code
1492 * @return 1503 * @return UserWeixinDTO
1493 */ 1504 */
1494 private UserWeixinDTO createWeixinUser(UserWeixin resource, Long memberId, String memberCode){ 1505 private UserWeixinDTO createWeixinUser(UserWeixin resource, Long memberId, String memberCode){
1495 if (Objects.nonNull(memberId)) resource.setMemberId(memberId); 1506 if (Objects.nonNull(memberId)) resource.setMemberId(memberId);
1496 if (StringUtils.isNotBlank(memberCode)) resource.setMemberCode(memberCode); 1507 if (StringUtils.isNotBlank(memberCode)) resource.setMemberCode(memberCode);
1497 1508
1498 UserWeixinDTO userWeixinDTO = this.userWeixinService.create(resource); 1509 return this.userWeixinService.create(resource);
1499
1500 return userWeixinDTO;
1501 } 1510 }
1502 1511
1503 /** 1512 /**
1504 * 1513 *
1505 * @param memberDTO 1514 * @param memberDTO 会员信息
1506 * @return 1515 * @return UserTvDTO
1507 */ 1516 */
1508 @Override 1517 @Override
1509 public UserTvDTO checkBind(MemberDTO memberDTO) { 1518 public UserTvDTO checkBind(MemberDTO memberDTO) {
1510 MemberDTO memberDTO1 = this.memberService.findByCode(memberDTO.getCode()); 1519 MemberDTO memberDTO1 = this.memberService.findByCode(memberDTO.getCode());
1511 if (Objects.nonNull(memberDTO1.getUserIptvId())) { 1520 if (Objects.nonNull(memberDTO1.getUserIptvId())) {
1512 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO1.getUserIptvId()); 1521 return this.userTvService.findById(memberDTO1.getUserIptvId());
1513 return userTvDTO;
1514 } 1522 }
1515 return null; 1523 return null;
1516 } 1524 }
1517 1525
1518 /** 1526 /**
1519 * 1527 *
1520 * @param platformAccount 1528 * @param platformAccount 大屏账号
1521 * @return 1529 * @return UserTvDTO
1522 */ 1530 */
1523 @Override 1531 @Override
1524 public UserTvDTO findByPlatformAccount(String platformAccount) { 1532 public UserTvDTO findByPlatformAccount(String platformAccount) {
...@@ -1526,27 +1534,92 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1526,27 +1534,92 @@ public class UserOperationServiceImpl implements UserOperationService {
1526 } 1534 }
1527 1535
1528 @Override 1536 @Override
1529 public void minaUnbind(WeixinUnBindBean weixinUnBindBean) { 1537 public ResultInfo minaUnbind(WeixinUnBindBean weixinUnBindBean) {
1530 1538
1531 Long memberId = weixinUnBindBean.getMemberId(); 1539 Long memberId = weixinUnBindBean.getMemberId();
1540
1532 MemberDTO memberDTO = this.memberService.findById(memberId); 1541 MemberDTO memberDTO = this.memberService.findById(memberId);
1542 if (Objects.isNull(memberDTO.getId())) {
1543 log.error("小屏解绑失败,会员信息不存在, minaUnbind# ==>> {}", memberId);
1544 return ResultInfo.failure("小屏解绑失败,当前会员信息不存在");
1545 }
1533 1546
1534 Assert.notNull(memberDTO.getUserIptvId(), GlobeExceptionMsg.IPTV_IS_NULL); 1547 if (Objects.isNull(memberDTO.getUserIptvId())) {
1548 log.error("小屏解绑失败,无绑定的大屏, memberId ==>> {}", memberId);
1549 return ResultInfo.failure("小屏解绑失败,无绑定的大屏");
1550 }
1535 1551
1536 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO.getUserIptvId()); 1552 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO.getUserIptvId());
1553 if (Objects.isNull(userTvDTO.getPlatformAccount())) {
1554 log.info("小屏解绑失败,绑定的大屏账号不存在 minaUnbind# ==>> userIptvId ==>> {}", memberDTO.getUserIptvId());
1555 return ResultInfo.failure("小屏解绑失败,大屏信息不存在请联系客服");
1556 }
1557
1558 // 解绑(置空大屏信息)
1559 Member member = new Member();
1560 member.setId(memberDTO.getId());
1561 member.setCode(memberDTO.getCode());
1562 member.setBindIptvTime(null);
1563 member.setUserIptvId(null);
1564 member.setBindIptvPlatformType(null);
1565 log.info("置空会员绑定的大屏信息, member ==>> {}", member);
1566 this.memberService.doUpdateMemberUserIptvIdAndBindIptvPlatformAndBindIptvTime(member);
1567 log.info("会员信息置空大屏的结果,memberDTO ==>> {}", memberDTO);
1568
1569 // 有其他绑定的小程序会员,排除自己
1570 List<MemberDTO> memberDTOS = this.memberService.findByUserIptvId(userTvDTO.getId());
1571 log.info("后台指定一个默认主会员,通过大屏id查询到的绑定的小屏会员memberDTOList ==>> {}", memberDTOS);
1572 if (!CollectionUtils.isEmpty(memberDTOS)) {
1573 String oldMemberCode = memberDTO.getCode();
1574 List<MemberDTO> collect =
1575 memberDTOS.stream().filter(memberDTO_ ->
1576 !memberDTO_.getCode().equalsIgnoreCase(oldMemberCode)).collect(Collectors.toList());
1577 log.info("过滤掉当前会员 ==>> {}", collect);
1578
1579 if (!CollectionUtils.isEmpty(collect)) {
1537 1580
1538 TvUnBindBean tvUnBindBean = new TvUnBindBean(); 1581 // 按绑定时间倒排
1539 tvUnBindBean.setMemberId(memberId); 1582 collect.sort((memberDTO1, t1) -> t1.getBindIptvTime().compareTo(memberDTO1.getBindIptvTime()));
1540 tvUnBindBean.setAutoModel(weixinUnBindBean.getAutoModel()); 1583 // 绑定新的主账号
1541 String platformAccount = userTvDTO.getPlatformAccount(); 1584 UserTv userTv = new UserTv();
1542 tvUnBindBean.setPlatformAccount(platformAccount); 1585 userTv.setId(userTvDTO.getId());
1543 this.tvUnbind(tvUnBindBean); 1586 userTv.setPlatform(userTvDTO.getPlatformAccount());
1587 userTv.setPriorityMemberCode(collect.get(0).getCode());
1588 this.userTvService.doUpdatePriorityMemberCode(userTv);
1589
1590 UserTvDTO _userTvDTO = new UserTvDTO();
1591 _userTvDTO.setPlatformAccount(userTvDTO.getPlatformAccount());
1592 _userTvDTO.setPriorityMemberCode(userTv.getPriorityMemberCode());
1593 log.info("同步绑定信息至大屏侧, 参数 ==>> {}", new MemberAndUserTvDTO(memberDTO, _userTvDTO));
1594 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO));
1595
1596 this.updateUserTvSimplePriorityMemberCodeRedis(userTvDTO.getPlatformAccount(), userTv.getPriorityMemberCode());
1597 }
1598
1599 } else {
1600 log.info("无其他绑定的小屏会员信息 ");
1601 // 绑定新的主账号
1602 UserTv userTv = new UserTv();
1603 userTv.setId(userTvDTO.getId());
1604 userTv.setPriorityMemberCode(null);
1605 this.userTvService.doUpdatePriorityMemberCode(userTv);
1606
1607 UserTvDTO _userTvDTO = new UserTvDTO();
1608 _userTvDTO.setPlatformAccount(userTvDTO.getPlatformAccount());
1609 _userTvDTO.setPriorityMemberCode(null);
1610 log.info("同步绑定信息至大屏侧, 参数 ==>> {}", new MemberAndUserTvDTO(memberDTO, _userTvDTO));
1611 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUnbind(new MemberAndUserTvDTO(memberDTO, _userTvDTO));
1612 this.updateUserTvSimplePriorityMemberCodeRedis(userTvDTO.getPlatformAccount(), "");
1544 } 1613 }
1545 1614
1615 return ResultInfo.success("解绑成功");
1616 }
1617
1618
1619
1546 @Override 1620 @Override
1547 public UserWeixinDTO findById(Long userId) { 1621 public UserWeixinDTO findById(Long userId) {
1548 UserWeixinDTO userWeixinDTO = this.userWeixinService.findById(userId); 1622 return this.userWeixinService.findById(userId);
1549 return userWeixinDTO;
1550 } 1623 }
1551 1624
1552 @Override 1625 @Override
...@@ -1566,10 +1639,51 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1566,10 +1639,51 @@ public class UserOperationServiceImpl implements UserOperationService {
1566 Long memberId = userTvDTO.getMemberId(); 1639 Long memberId = userTvDTO.getMemberId();
1567 if (Objects.nonNull(memberId)) { 1640 if (Objects.nonNull(memberId)) {
1568 MemberDTO memberDTO = this.memberService.findById(memberId); 1641 MemberDTO memberDTO = this.memberService.findById(memberId);
1569 resources.setMemberCode(memberDTO.getCode()); 1642 userTvDTO.setMemberCode(memberDTO.getCode());
1570 } 1643 }
1571 // 同步至iptv 1644 // 同步至iptv
1572 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUserTv(userTvDTO); 1645 ((UserOperationServiceImpl)AopContext.currentProxy()).asyncUserTv(userTvDTO);
1573 return userTvDTO; 1646 return userTvDTO;
1574 } 1647 }
1648
1649
1650
1651
1652
1653
1654 @AsyncMqSend
1655 public void asyncCreateUserAppBindThirdAccount(UserAppDTO userAppDTO) {}
1656 @AsyncMqSend
1657 public void asyncUpdateAppLastActiveTimeAndNicknameAndHeadImg(UserAppDTO userAppDTO) { }
1658 @AsyncMqSend
1659 public void asyncCancelUserAppBind(UserAppBindDTO userAppBindDTO) {}
1660 @AsyncMqSend
1661 public void asyncUpdatePasswordByUsername(UserAppDTO userAppDTO) {}
1662 @AsyncMqSend
1663 public void asyncUpdateAppInfo(UserAppDTO userAppDTO) {}
1664 @AsyncMqSend
1665 public void asyncAppCancellation(UserAppDTO userAppDTO) {}
1666 @AsyncMqSend
1667 public void asyncAppRegister(AppRegisterDTO appRegisterDTO) {}
1668 @AsyncMqSend
1669 public void asyncsaveGrowthReport(GrowthReport growthReport) {}
1670 @AsyncMqSend
1671 public void asyncMemberAndUserWeixin4Iptv(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
1672 @AsyncMqSend
1673 public void asyncMemberAndUserTv4Iptv(MemberAndUserTvDTO memberAndUserTv) {}
1674 @AsyncMqSend
1675 public void asyncWeixin(UserWeixinDTO weixinDTO) {}
1676 @AsyncMqSend
1677 public void asyncUserTv(UserTvDTO userTvDTO) {}
1678 @AsyncMqSend
1679 public void asyncUserTvChangeMainAccount(UserTvDTO userTvDTO) {}
1680 @AsyncMqSend
1681 public void asyncMinaBind(MemberAndUserTvDTO memberAndUserTvDTO) {}
1682 @AsyncMqSend
1683 public void asyncUnbind(MemberAndUserTvDTO memberAndUserTvDTO) {}
1684 @AsyncMqSend
1685 public void asyncUnsubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
1686 @AsyncMqSend
1687 public void asyncSubscribe(MemberAndWeixinUserDTO memberAndWeixinUserDTO) {}
1688
1575 } 1689 }
......
...@@ -2,196 +2,176 @@ package com.topdraw.business.process.service.impl.member; ...@@ -2,196 +2,176 @@ package com.topdraw.business.process.service.impl.member;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import com.topdraw.aspect.AsyncMqSend; 4 import com.topdraw.aspect.AsyncMqSend;
5 import com.topdraw.business.module.member.address.service.MemberAddressService;
6 import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO;
5 import com.topdraw.business.module.member.domain.Member; 7 import com.topdraw.business.module.member.domain.Member;
6 import com.topdraw.business.module.member.profile.domain.MemberProfile;
7 import com.topdraw.business.module.member.profile.service.MemberProfileService; 8 import com.topdraw.business.module.member.profile.service.MemberProfileService;
8 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; 9 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
9 import com.topdraw.business.module.member.service.MemberService; 10 import com.topdraw.business.module.member.service.MemberService;
10 import com.topdraw.business.module.member.service.dto.MemberDTO; 11 import com.topdraw.business.module.member.service.dto.MemberDTO;
11 import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; 12 import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
12 import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService; 13 import com.topdraw.business.module.member.viphistory.service.MemberVipHistoryService;
13 import com.topdraw.business.module.task.domain.Task; 14 import com.topdraw.business.module.member.viphistory.service.dto.MemberVipHistoryDTO;
14 import com.topdraw.business.module.user.weixin.domain.UserWeixin;
15 import com.topdraw.business.module.user.weixin.service.UserWeixinService; 15 import com.topdraw.business.module.user.weixin.service.UserWeixinService;
16 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 16 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
17 import com.topdraw.business.process.domian.weixin.BuyVipBean; 17 import com.topdraw.business.process.domian.member.MemberOperationBean;
18 import com.topdraw.business.process.service.member.MemberOperationService; 18 import com.topdraw.business.process.service.member.MemberOperationService;
19 import com.topdraw.business.process.service.member.MemberProfileOperationService; 19 import com.topdraw.business.RedisKeyConstants;
20 import com.topdraw.exception.EntityNotFoundException;
21 import com.topdraw.util.TimestampUtil; 20 import com.topdraw.util.TimestampUtil;
21 import lombok.extern.slf4j.Slf4j;
22 import org.springframework.aop.framework.AopContext; 22 import org.springframework.aop.framework.AopContext;
23 import org.springframework.beans.BeanUtils; 23 import org.springframework.beans.BeanUtils;
24 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.cache.annotation.CacheConfig; 25 import org.springframework.cache.annotation.CacheConfig;
26 import org.springframework.cache.annotation.CacheEvict;
27 import org.springframework.cache.annotation.CachePut;
28 import org.springframework.cache.annotation.Cacheable;
29 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
30 import org.springframework.stereotype.Service; 26 import org.springframework.stereotype.Service;
31 import org.springframework.util.Assert;
32 27
33 import java.sql.Timestamp; 28 import java.sql.Timestamp;
34 import java.time.LocalDateTime; 29 import java.util.List;
35 import java.time.ZoneOffset;
36 import java.util.Objects; 30 import java.util.Objects;
37 31
38 @Service 32 @Service
39 //@CacheConfig(cacheNames = "member") 33 @Slf4j
34 @CacheConfig(cacheNames = RedisKeyConstants.cacheMemberById)
40 public class MemberOperationServiceImpl implements MemberOperationService { 35 public class MemberOperationServiceImpl implements MemberOperationService {
41 36
37
42 @Autowired 38 @Autowired
43 private MemberService memberService; 39 private MemberService memberService;
44 @Autowired 40 @Autowired
41 private UserWeixinService userWeixinService;
42 @Autowired
45 private MemberProfileService memberProfileService; 43 private MemberProfileService memberProfileService;
46 @Autowired 44 @Autowired
47 private MemberVipHistoryService memberVipHistoryService; 45 private MemberVipHistoryService memberVipHistoryService;
48 @Autowired 46 @Autowired
49 private UserWeixinService userWeixinService; 47 private MemberAddressService memberAddressService;
50 @Autowired
51 private ThreadPoolTaskExecutor threadPoolTaskExecutor;
52
53 48
54 @AsyncMqSend 49 @AsyncMqSend
55 public void asyncUpdateMemberVip(MemberDTO me) {} 50 public void asyncUpdateMemberVipAndVipExpireTime(MemberDTO memberDTO) {}
51 @AsyncMqSend
52 public void asyncCreateMemberVipHistory(MemberVipHistoryDTO memberVipHistoryDTO) {}
53 @AsyncMqSend
54 public void asyncDoUpdateGroupsBatch(List<Member> resources) {}
56 55
57 // @CachePut(key = "#resources.memberId") 56
57 @AsyncMqSend
58 @Override 58 @Override
59 public MemberDTO buyVipByUserId(BuyVipBean resources) { 59 public MemberDTO update(Member resources) {
60 // 小程序账户id 60 return this.memberService.update(resources);
61 Long id = resources.getId();
62 // 查询微信账户
63 UserWeixinDTO userWeixin = this.findWeiXinById(id);
64 Long memberId = userWeixin.getMemberId();
65 resources.setMemberId(memberId);
66 return this.buyVipByMemberId(resources);
67 } 61 }
68 62
69 @Override 63 @Override
70 public MemberDTO buyVipByMemberId(BuyVipBean resources) { 64 public MemberDTO findByCode(String code) {
65 return this.memberService.findByCode(code);
66 }
71 67
72 Timestamp vipExpireTime1 = resources.getVipExpireTime(); 68 @Override
73 Integer vip1 = resources.getVip(); 69 public MemberDTO doInsertMember(Member resources) {
70 return this.memberService.create(resources);
71 }
74 72
75 Long memberId = resources.getMemberId(); 73 @Override
76 // 74 public MemberDTO findById(Long memberId) {
77 MemberDTO memberDTO = this.findById(memberId); 75 MemberDTO memberDTO = this.memberService.findById(memberId);
78 String memberCode = memberDTO.getCode(); 76 return Objects.nonNull(memberId) ? memberDTO : null;
79 Integer vip = memberDTO.getVip(); 77 }
80 78
81 // 79 @Override
82 Timestamp vipExpireTime = memberDTO.getVipExpireTime(); 80 public Integer doUpdateMemberExpAndLevel(Member resources) {
83 if (Objects.nonNull(vipExpireTime1)) { 81 return this.memberService.doUpdateMemberExpAndLevel(resources);
84 vipExpireTime = vipExpireTime1;
85 } 82 }
86 83
87 //判断之前有没有买过,没买过,失效时间为一年后; 84 @Override
88 if (Objects.isNull(vipExpireTime1)) { 85 public Integer doUpdateMemberPoints(Member resources) {
89 if (ObjectUtil.isNull(vipExpireTime)) { 86 return this.memberService.doUpdateMemberPoints(resources);
90 LocalDateTime now = LocalDateTime.now();
91 vipExpireTime = TimestampUtil.localDateTime2Timestamp(now.plusYears(1L));
92 } else {
93 LocalDateTime localDateTime = TimestampUtil.timestamp2LocalDateTime(vipExpireTime).plusYears(1L);
94 vipExpireTime = TimestampUtil.localDateTime2Timestamp(localDateTime);
95 } 87 }
96 88
89
90 @Override
91 // @CachePut(cacheNames = RedisKeyConstants.cacheMemberByCode, key = "#member.code", unless = "#result.id == null")
92 public Integer doUpdateMemberCoupon(Member member) {
93 return this.memberService.doUpdateMemberCoupon(member);
97 } 94 }
98 95
99 memberDTO.setVip(vip1); 96 @Override
100 memberDTO.setVipExpireTime(vipExpireTime); 97 // @CachePut(cacheNames = RedisKeyConstants.cacheMemberById, key = "#member.id")
98 public MemberDTO doUpdateMemberVipAndVipExpireTime(Member resource) {
99 MemberDTO memberDTO1 = this.memberService.findByCode(resource.getCode());
101 100
102 Member member = new Member(); 101 Member member = new Member();
103 BeanUtils.copyProperties(memberDTO,member); 102 member.setId(memberDTO1.getId());
104 this.update(member); 103 member.setCode(memberDTO1.getCode());
104 member.setVip(resource.getVip());
105 member.setVipExpireTime(resource.getVipExpireTime());
106 MemberDTO memberDTO = this.memberService.doUpdateMemberVipAndVipExpireTime(member);
105 107
106 MemberVipHistory memberVipHistory = new MemberVipHistory(); 108 ((MemberOperationServiceImpl) AopContext.currentProxy()).asyncUpdateMemberVipAndVipExpireTime(memberDTO);
107 memberVipHistory.setMemberId(memberId).setVip(vip1).setBeforeVip(vip);
108 if (ObjectUtil.equal(vip1,vip)) {
109 memberVipHistory.setStatus(1);
110 }
111 memberVipHistory.setMemberCode(memberCode);
112 memberVipHistory.setVipExpireTime(member.getVipExpireTime());
113 this.createVipHistory(memberVipHistory);
114 109
115 return memberDTO; 110 return memberDTO;
116 } 111 }
117 112
118 @Override 113 @Override
119 public void createVipHistory(MemberVipHistory memberVipHistory){ 114 public MemberDTO doUpdateVipByMemberCode(MemberOperationBean resources) {
120 this.memberVipHistoryService.create(memberVipHistory); 115 Integer nowVip = resources.getVip();
121 } 116 Long memberId = resources.getMemberId();
117 String memberCode = resources.getMemberCode();
118 Timestamp vipExpireTime = resources.getVipExpireTime();
122 119
123 @AsyncMqSend 120 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
124 @Override
125 public MemberDTO update(Member resources) {
126 MemberDTO memberDTO = this.memberService.update(resources);
127 return memberDTO;
128 }
129 121
130 @Override 122 Integer vip = memberDTO.getVip();
131 public MemberDTO findByCode(String code) {
132 return this.memberService.findByCode(code);
133 }
134 123
135 private UserWeixinDTO findWeiXinById(Long id) { 124 Member member = new Member();
136 UserWeixinDTO userWeixinDTO = this.userWeixinService.findById(id); 125 member.setId(memberDTO.getId());
137 if (Objects.isNull(userWeixinDTO)) { 126 member.setCode(memberCode);
138 throw new EntityNotFoundException(UserWeixin.class, "id", userWeixinDTO.getId().toString()); 127 member.setVip(nowVip);
139 } 128 member.setVipExpireTime(vipExpireTime);
140 129
141 return userWeixinDTO; 130 MemberDTO memberDTO_ = this.memberService.doUpdateMemberVipAndVipExpireTime(member);
142 }
143 131
144 @Override 132 ((MemberOperationServiceImpl) AopContext.currentProxy()).asyncUpdateMemberVipAndVipExpireTime(memberDTO_);
145 public MemberDTO doUpdateMember(Member resources) {
146 Long id = resources.getId();
147 Assert.notNull(id,"ERROR MSG: MemberOperationServiceImpl -> doUpdateMemberInfo -> id not be null!!");
148 return this.update(resources);
149 }
150 133
151 // @CachePut(key = "#resources.id") 134 MemberVipHistory memberVipHistory = new MemberVipHistory();
152 @Override 135 memberVipHistory.setMemberId(memberId).setVip(nowVip).setBeforeVip(vip);
153 public MemberDTO doInsertMember(Member resources) { 136 memberVipHistory.setMemberCode(memberCode);
154 return this.memberService.create(resources); 137 memberVipHistory.setVipExpireTime(vipExpireTime);
155 } 138 MemberVipHistoryDTO memberVipHistoryDTO = this.memberVipHistoryService.create(memberVipHistory);
156 139
157 @Override 140 ((MemberOperationServiceImpl) AopContext.currentProxy()).asyncCreateMemberVipHistory(memberVipHistoryDTO);
158 public MemberDTO findById(Long memberId) { 141
159 MemberDTO memberDTO = this.memberService.findById(memberId); 142 return memberDTO_;
160 return Objects.nonNull(memberId) ? memberDTO : null;
161 } 143 }
162 144
163 // @CachePut(key = "#resources.id")
164 @Override 145 @Override
165 public MemberDTO doUpdateMemberExpAndLevel(Member resources) { 146 public Integer doUpdateGroupsBatch(List<Member> resources) {
166 return this.memberService.doUpdateMemberExpAndLevel(resources); 147 Integer count = this.memberService.doUpdateGroupsBatch(resources);
148 if (count > 0) {
149 ((MemberOperationServiceImpl) AopContext.currentProxy()).asyncDoUpdateGroupsBatch(resources);
167 } 150 }
168 151
169 // @CachePut(key = "#resources.id") 152 return count;
170 @Override
171 public MemberDTO doUpdateMemberPoints(Member resources) {
172 return this.memberService.doUpdateMemberPoints(resources);
173 } 153 }
174 154
175 // @CachePut(key = "#resources.id")
176 @Override 155 @Override
177 public MemberDTO doUpdateMemberCoupon(Member member) { 156 public MemberAddressDTO updateDefaultMemberAddressById(Long id) {
178 return this.memberService.doUpdateMemberCoupon(member); 157 MemberAddressDTO memberAddressDTO = this.memberAddressService.findById(id);
158 if (Objects.nonNull(memberAddressDTO.getId())) {
159 Long memberId = memberAddressDTO.getMemberId();
160 Integer _count = this.memberAddressService.updateUnDefaultMemberAddressByMemberId(memberId);
161 if (_count > 0) {
162 Integer count = this.memberAddressService.updateDefaultMemberAddressById(id);
163 if (count > 0 ) {
164 return this.memberAddressService.findById(id);
165 }
166 }
179 } 167 }
180 168
181 @Override 169 return null;
182 public MemberDTO updateMemberVip(Member member) {
183 MemberDTO memberDTO1 = this.memberService.findByCode(member.getCode());
184 Member member1 = new Member();
185 BeanUtils.copyProperties(memberDTO1, member1);
186 member1.setVip(member.getVip());
187 member1.setVipExpireTime(member.getVipExpireTime());
188 MemberDTO memberDTO = this.update(member1);
189 ((MemberOperationServiceImpl) AopContext.currentProxy()).asyncUpdateMemberVip(memberDTO);
190 return memberDTO;
191 } 170 }
192 171
172
193 @Override 173 @Override
194 public MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appid) { 174 public MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appId) {
195 175
196 // 会员加密信息 176 // 会员加密信息
197 MemberProfileDTO memberProfileDTO_0 = this.findMemberProfileByMemberId(memberId); 177 MemberProfileDTO memberProfileDTO_0 = this.findMemberProfileByMemberId(memberId);
...@@ -200,13 +180,11 @@ public class MemberOperationServiceImpl implements MemberOperationService { ...@@ -200,13 +180,11 @@ public class MemberOperationServiceImpl implements MemberOperationService {
200 MemberDTO memberDTO = this.findById(memberId); 180 MemberDTO memberDTO = this.findById(memberId);
201 181
202 // 初始化会员加密信息 182 // 初始化会员加密信息
203 MemberProfileDTO memberProfileDTO_1 = this.configMemberProfile(memberProfileDTO_0,memberDTO,appid); 183 return this.configMemberProfile(memberProfileDTO_0, memberDTO, appId);
204
205 return memberProfileDTO_1;
206 } 184 }
207 185
208 186
209 private MemberProfileDTO configMemberProfile(MemberProfileDTO memberProfileDTO_0, MemberDTO memberDTO, String appid) { 187 private MemberProfileDTO configMemberProfile(MemberProfileDTO memberProfileDTO_0, MemberDTO memberDTO, String appId) {
210 188
211 if (Objects.isNull(memberProfileDTO_0)) return memberProfileDTO_0; 189 if (Objects.isNull(memberProfileDTO_0)) return memberProfileDTO_0;
212 190
...@@ -218,18 +196,19 @@ public class MemberOperationServiceImpl implements MemberOperationService { ...@@ -218,18 +196,19 @@ public class MemberOperationServiceImpl implements MemberOperationService {
218 // 过期时间 196 // 过期时间
219 Timestamp vipExpireTime = memberDTO.getVipExpireTime(); 197 Timestamp vipExpireTime = memberDTO.getVipExpireTime();
220 198
221 Long timeLong = 0L; 199 long timeLong = 0L;
222 if (ObjectUtil.isNotNull(vipExpireTime)) { 200 if (ObjectUtil.isNotNull(vipExpireTime)) {
223 201
224 // 检查vip 202 // 检查vip
225 MemberDTO memberDTO1 = this.checkVipStatus(memberDTO,vipExpireTime,appid); 203 MemberDTO memberDTO1 = this.checkVipStatus(memberDTO, vipExpireTime, appId);
226 204
227 // 更新会员信息 205 // 更新会员信息
228 this.threadPoolTaskExecutor.execute(()->{
229 Member member = new Member(); 206 Member member = new Member();
230 BeanUtils.copyProperties(memberDTO1,member); 207 member.setId(memberDTO1.getId());
231 this.update(member); 208 member.setCode(memberDTO1.getCode());
232 }); 209 member.setVip(memberDTO1.getVip());
210 member.setVipExpireTime(memberDTO1.getVipExpireTime());
211 this.doUpdateMemberVipAndVipExpireTime(member);
233 212
234 vip = memberDTO1.getVip(); 213 vip = memberDTO1.getVip();
235 Timestamp vipExpireTime1 = memberDTO1.getVipExpireTime(); 214 Timestamp vipExpireTime1 = memberDTO1.getVipExpireTime();
...@@ -259,10 +238,10 @@ public class MemberOperationServiceImpl implements MemberOperationService { ...@@ -259,10 +238,10 @@ public class MemberOperationServiceImpl implements MemberOperationService {
259 * 1.当前vip如果过期则查看是否有vip历史变动 238 * 1.当前vip如果过期则查看是否有vip历史变动
260 * 2.如果vip变动历史有记录则获取vip变动记录 239 * 2.如果vip变动历史有记录则获取vip变动记录
261 * 3.如果vip没有记录则查看是否关注了公众号 240 * 3.如果vip没有记录则查看是否关注了公众号
262 * @param vipExpireTime 241 * @param vipExpireTime 过期时间
263 * @return 242 * @return MemberDTO
264 */ 243 */
265 private MemberDTO checkVipStatus(MemberDTO memberDTO,Timestamp vipExpireTime, String appid) { 244 private MemberDTO checkVipStatus(MemberDTO memberDTO,Timestamp vipExpireTime, String appId) {
266 245
267 Long memberId = memberDTO.getId(); 246 Long memberId = memberDTO.getId();
268 Timestamp nowTime = TimestampUtil.now(); 247 Timestamp nowTime = TimestampUtil.now();
...@@ -271,16 +250,16 @@ public class MemberOperationServiceImpl implements MemberOperationService { ...@@ -271,16 +250,16 @@ public class MemberOperationServiceImpl implements MemberOperationService {
271 if (nowTime.compareTo(vipExpireTime) >= 0 ) { 250 if (nowTime.compareTo(vipExpireTime) >= 0 ) {
272 251
273 Integer vip = 0; 252 Integer vip = 0;
274 Timestamp vipExpireTime1 = memberDTO.getVipExpireTime(); 253 Timestamp vipExpireTime1;
275 254
276 //查询小于失效时间的那条记录 查不到 取微信表里 关注状态 255 //查询小于失效时间的那条记录 查不到 取微信表里 关注状态
277 MemberVipHistory memberVipHistory = this.memberVipHistoryService.findByTime(memberId, nowTime); 256 MemberVipHistory memberVipHistory = this.memberVipHistoryService.findByTime(memberId, nowTime);
278 257
279 if (ObjectUtil.isNull(memberVipHistory.getId())) { 258 if (ObjectUtil.isNull(memberVipHistory.getId())) {
280 259
281 UserWeixinDTO userWeixin = this.userWeixinService.findFirstByMemberIdAndAppid(memberId, appid); 260 UserWeixinDTO userWeiXin = this.userWeixinService.findFirstByMemberIdAndAppid(memberId, appId);
282 // 微信公众号关注的状态 0:未关注 1:关注 261 // 微信公众号关注的状态 0:未关注 1:关注
283 Integer status = userWeixin.getStatus(); 262 Integer status = userWeiXin.getStatus();
284 263
285 if (status != 1) vip = 0; else vip = 1; 264 if (status != 1) vip = 0; else vip = 1;
286 vipExpireTime1 = null; 265 vipExpireTime1 = null;
...@@ -300,8 +279,8 @@ public class MemberOperationServiceImpl implements MemberOperationService { ...@@ -300,8 +279,8 @@ public class MemberOperationServiceImpl implements MemberOperationService {
300 279
301 /** 280 /**
302 * 查询会员加密信息 281 * 查询会员加密信息
303 * @param memberId 282 * @param memberId 会员id
304 * @return 283 * @return MemberProfileDTO
305 */ 284 */
306 private MemberProfileDTO findMemberProfileByMemberId(Long memberId) { 285 private MemberProfileDTO findMemberProfileByMemberId(Long memberId) {
307 return this.memberProfileService.findByMemberId(memberId); 286 return this.memberProfileService.findByMemberId(memberId);
......
...@@ -11,13 +11,11 @@ import com.topdraw.business.process.service.dto.MemberProfileAndMemberDTO; ...@@ -11,13 +11,11 @@ import com.topdraw.business.process.service.dto.MemberProfileAndMemberDTO;
11 import com.topdraw.business.process.service.member.MemberProfileOperationService; 11 import com.topdraw.business.process.service.member.MemberProfileOperationService;
12 import com.topdraw.exception.EntityExistException; 12 import com.topdraw.exception.EntityExistException;
13 import com.topdraw.exception.EntityNotFoundException; 13 import com.topdraw.exception.EntityNotFoundException;
14 import org.apache.commons.lang3.StringUtils;
15 import org.springframework.aop.framework.AopContext; 14 import org.springframework.aop.framework.AopContext;
16 import org.springframework.beans.BeanUtils; 15 import org.springframework.beans.BeanUtils;
17 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
19 18
20 import javax.validation.constraints.NotNull;
21 import java.util.Objects; 19 import java.util.Objects;
22 20
23 21
...@@ -39,25 +37,16 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation ...@@ -39,25 +37,16 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation
39 private MemberService memberService; 37 private MemberService memberService;
40 38
41 @AsyncMqSend 39 @AsyncMqSend
42 public void asyncMemberProfile(MemberProfileDTO memberProfileDTO){} 40 public void asyncUpdateMemberProfileAndSyncMember(MemberProfileAndMemberDTO memberProfileAndMemberDTO){}
43 @AsyncMqSend 41 @AsyncMqSend
44 public void asyncMemberProfileAndMember(MemberProfileAndMemberDTO memberProfileAndMemberDTO){} 42 public void asyncCreateMemberProfileAndSyncMember(MemberProfileDTO memberProfileDTO) {}
45 @AsyncMqSend
46 public void asyncCreateMemberProfile(MemberProfileDTO memberProfileDTO) {}
47
48 @Override
49 public MemberProfileDTO update(MemberProfile resources) {
50 MemberProfileDTO memberProfileDTO = this.memberProfileService.update(resources);
51 memberProfileDTO.setMemberCode(resources.getMemberCode());
52 ((MemberProfileOperationServiceImpl) AopContext.currentProxy()).asyncMemberProfile(memberProfileDTO);
53 return memberProfileDTO;
54 }
55 43
56 @Override 44 @Override
57 public MemberProfileDTO updateMemberProfileAndMember(MemberProfile resources) { 45 public MemberProfileDTO updateMemberProfileAndMember(MemberProfile resources) {
58 Long id = resources.getId(); 46 Long id = resources.getId();
59 MemberProfileDTO _memberProfile = this.memberProfileService.findById(id); 47 MemberProfileDTO memberProfile = this.memberProfileService.findById(id);
60 Long memberId = _memberProfile.getMemberId(); 48
49 Long memberId = memberProfile.getMemberId();
61 resources.setMemberId(memberId); 50 resources.setMemberId(memberId);
62 51
63 MemberDTO memberDTO = this.memberService.checkMember(resources.getMemberId(), resources.getMemberCode()); 52 MemberDTO memberDTO = this.memberService.checkMember(resources.getMemberId(), resources.getMemberCode());
...@@ -68,7 +57,7 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation ...@@ -68,7 +57,7 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation
68 memberProfileDTO.setMemberCode(memberDTO.getCode()); 57 memberProfileDTO.setMemberCode(memberDTO.getCode());
69 58
70 ((MemberProfileOperationServiceImpl)AopContext.currentProxy()) 59 ((MemberProfileOperationServiceImpl)AopContext.currentProxy())
71 .asyncMemberProfileAndMember(new MemberProfileAndMemberDTO(memberProfileDTO, memberDTO)); 60 .asyncUpdateMemberProfileAndSyncMember(new MemberProfileAndMemberDTO(memberProfileDTO, memberDTO));
72 61
73 return memberProfileDTO; 62 return memberProfileDTO;
74 } 63 }
...@@ -88,7 +77,7 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation ...@@ -88,7 +77,7 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation
88 77
89 this.createMemberProfileAndSyncMember(memberProfileDTO, memberDTO); 78 this.createMemberProfileAndSyncMember(memberProfileDTO, memberDTO);
90 79
91 ((MemberProfileOperationServiceImpl) AopContext.currentProxy()).asyncCreateMemberProfile(memberProfileDTO); 80 ((MemberProfileOperationServiceImpl) AopContext.currentProxy()).asyncCreateMemberProfileAndSyncMember(memberProfileDTO);
92 81
93 } else { 82 } else {
94 83
...@@ -111,12 +100,13 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation ...@@ -111,12 +100,13 @@ public class MemberProfileOperationServiceImpl implements MemberProfileOperation
111 } 100 }
112 101
113 private void syncMember(MemberProfileDTO memberProfileDTO, MemberDTO memberDTO) { 102 private void syncMember(MemberProfileDTO memberProfileDTO, MemberDTO memberDTO) {
114 memberDTO.setAvatarUrl(memberProfileDTO.getAvatarUrl());
115 memberDTO.setNickname(memberProfileDTO.getRealname());
116 memberDTO.setGender(memberProfileDTO.getGender());
117 Member member = new Member(); 103 Member member = new Member();
118 BeanUtils.copyProperties(memberDTO, member); 104 member.setId(memberDTO.getId());
119 this.memberService.update(member); 105 member.setCode(memberDTO.getCode());
106 member.setAvatarUrl(memberProfileDTO.getAvatarUrl());
107 member.setNickname(memberProfileDTO.getRealname());
108 member.setGender(memberProfileDTO.getGender());
109 this.memberService.doUpdateMemberAvatarUrlAndNicknameAndGender(member);
120 } 110 }
121 111
122 112
......
1 package com.topdraw.business.process.service.member; 1 package com.topdraw.business.process.service.member;
2 2
3 import com.topdraw.business.module.member.address.service.dto.MemberAddressDTO;
3 import com.topdraw.business.module.member.domain.Member; 4 import com.topdraw.business.module.member.domain.Member;
4 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; 5 import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
5 import com.topdraw.business.module.member.service.dto.MemberDTO; 6 import com.topdraw.business.module.member.service.dto.MemberDTO;
6 import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory; 7 import com.topdraw.business.module.member.viphistory.domain.MemberVipHistory;
8 import com.topdraw.business.process.domian.member.MemberOperationBean;
7 import com.topdraw.business.process.domian.weixin.BuyVipBean; 9 import com.topdraw.business.process.domian.weixin.BuyVipBean;
8 10
11 import java.util.List;
12
9 public interface MemberOperationService { 13 public interface MemberOperationService {
10 14
11 /** 15 /**
...@@ -31,64 +35,49 @@ public interface MemberOperationService { ...@@ -31,64 +35,49 @@ public interface MemberOperationService {
31 MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appid); 35 MemberProfileDTO getMemberProfileAndCheckVip(Long memberId, String appid);
32 36
33 /** 37 /**
34 * 38 * 修改会员
35 * @param resources 39 * @param resources
36 * @return
37 */ 40 */
38 MemberDTO buyVipByUserId(BuyVipBean resources); 41 MemberDTO update(Member resources);
39 42
40 /** 43 /**
41 * 44 *
42 * @param resources 45 * @param resources
43 * @return
44 */ 46 */
45 MemberDTO buyVipByMemberId(BuyVipBean resources); 47 MemberDTO doInsertMember(Member resources);
46 48
47 /** 49 /**
48 * 50 *
49 * @param memberVipHistory
50 */
51 void createVipHistory(MemberVipHistory memberVipHistory);
52
53 /**
54 * 修改会员
55 * @param resources 51 * @param resources
56 */ 52 */
57 MemberDTO update(Member resources); 53 Integer doUpdateMemberExpAndLevel(Member resources);
58 54
59 /** 55 /**
60 * 56 *
61 * @param resources 57 * @param resources
62 */ 58 */
63 MemberDTO doUpdateMember(Member resources); 59 Integer doUpdateMemberPoints(Member resources);
64 60
65 /** 61 /**
66 * 62 *
67 * @param resources 63 * @param resources
68 */ 64 */
69 MemberDTO doInsertMember(Member resources); 65 Integer doUpdateMemberCoupon(Member resources);
70 66
71 /** 67 /**
72 * 68 *
73 * @param resources 69 * @param member
74 */ 70 */
75 MemberDTO doUpdateMemberExpAndLevel(Member resources); 71 MemberDTO doUpdateMemberVipAndVipExpireTime(Member member);
76 72
77 /** 73 /**
78 * 74 *
79 * @param resources 75 * @param resources
80 */ 76 */
81 MemberDTO doUpdateMemberPoints(Member resources); 77 MemberDTO doUpdateVipByMemberCode(MemberOperationBean resources);
82 78
83 /**
84 *
85 * @param resources
86 */
87 MemberDTO doUpdateMemberCoupon(Member resources);
88 79
89 /** 80 Integer doUpdateGroupsBatch(List<Member> resources);
90 * 81
91 * @param member 82 MemberAddressDTO updateDefaultMemberAddressById(Long memberId);
92 */
93 MemberDTO updateMemberVip(Member member);
94 } 83 }
......
...@@ -6,12 +6,6 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO; ...@@ -6,12 +6,6 @@ import com.topdraw.business.module.member.profile.service.dto.MemberProfileDTO;
6 public interface MemberProfileOperationService { 6 public interface MemberProfileOperationService {
7 7
8 /** 8 /**
9 * 修改
10 * @param resources
11 */
12 MemberProfileDTO update(MemberProfile resources);
13
14 /**
15 * 修改会员属性并同步会员信息 9 * 修改会员属性并同步会员信息
16 * @param resources 10 * @param resources
17 */ 11 */
......
1 package com.topdraw.mq.config; 1 package com.topdraw.config;
2 2
3 import org.apache.commons.lang3.StringUtils; 3 import org.apache.commons.lang3.StringUtils;
4 import org.springframework.amqp.core.*; 4 import org.springframework.amqp.core.*;
5 import org.springframework.amqp.rabbit.core.RabbitTemplate;
6 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
6 import org.springframework.context.annotation.Bean; 8 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration; 9 import org.springframework.context.annotation.Configuration;
...@@ -12,35 +14,35 @@ public class RabbitMqConfig { ...@@ -12,35 +14,35 @@ public class RabbitMqConfig {
12 public static final String UCE_EXCHANGE = "uce.exchange"; 14 public static final String UCE_EXCHANGE = "uce.exchange";
13 public static final String UCE_QUEUE = "uce.queue"; 15 public static final String UCE_QUEUE = "uce.queue";
14 16
15 @Value("${service.mq.exchange}") 17 @Autowired
16 private String exchange; 18 private RabbitTemplate rabbitTemplate;
17 19
18 @Value("${service.mq.queue}") 20 public String getExchange() {
19 private String queue;
20 21
21 public String getExchange(){ 22 String exchange = this.rabbitTemplate.getExchange();
22 if (StringUtils.isEmpty(this.exchange)) { 23 if (StringUtils.isNotBlank(exchange)) {
23 this.exchange = UCE_EXCHANGE; 24 return exchange;
24 } 25 }
25 26
26 return this.exchange; 27 return UCE_EXCHANGE;
27 } 28 }
28 29
29 public String getQueue() { 30 public String getQueue() {
30 if (StringUtils.isEmpty(this.queue)) { 31 String queue = this.rabbitTemplate.getRoutingKey();
31 this.queue = UCE_QUEUE; 32 if (StringUtils.isNotBlank(queue)) {
33 return queue;
32 } 34 }
33 35
34 return this.queue; 36 return UCE_QUEUE;
35 } 37 }
36 38
37 @Bean 39 @Bean
38 DirectExchange directExchange(){ 40 DirectExchange directExchange(){
39 return ExchangeBuilder.directExchange(getExchange()).build(); 41 return ExchangeBuilder.directExchange(this.getExchange()).build();
40 } 42 }
41 43
42 @Bean 44 @Bean
43 Queue queue(){ return new Queue(getQueue()); } 45 Queue queue(){ return new Queue(this.getQueue()); }
44 46
45 @Bean 47 @Bean
46 Binding binding(DirectExchange directExchange , Queue queue) { 48 Binding binding(DirectExchange directExchange , Queue queue) {
......
1 package com.topdraw.config;
2
3
4 import org.springframework.scheduling.annotation.EnableScheduling;
5 import org.springframework.stereotype.Component;
6
7 @Component
8
9 public class ScheduledTaskConfig {
10 }
1 package com.topdraw.config;
2
3 import cn.hutool.core.util.ObjectUtil;
4 import org.springframework.beans.factory.annotation.Value;
5 import org.springframework.stereotype.Component;
6
7 @Component
8 public class ServiceEnvConfig {
9
10 // uc两侧部署,需配置位于哪一侧 mobile小屏侧 vis大屏侧
11 public static String UC_SERVICE_TYPE;
12
13 @Value("${uc.service.type:mobile}")
14 public void setUcServiceType(String ucServiceType) {
15 UC_SERVICE_TYPE = ucServiceType;
16 }
17
18 public static boolean isMobile() {
19 return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_MOBILE);
20 }
21
22 public static boolean isVis() {
23 return ObjectUtil.equals(UC_SERVICE_TYPE, LocalConstants.ENV_VIS);
24 }
25
26 }
1 package com.topdraw.config;
2
3 import org.springframework.beans.factory.annotation.Value;
4 import org.springframework.context.annotation.Bean;
5 import org.springframework.context.annotation.Configuration;
6 import org.springframework.context.annotation.Primary;
7 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
8
9 import java.util.concurrent.ArrayBlockingQueue;
10 import java.util.concurrent.Executor;
11 import java.util.concurrent.ThreadPoolExecutor;
12 import java.util.concurrent.TimeUnit;
13
14 /**
15 * @author :
16 * @description:
17 * @function :
18 * @date :Created in 2022/6/22 11:06
19 * @version: :
20 * @modified By:
21 * @since : modified in 2022/6/22 11:06
22 */
23 @Configuration
24 public class TheadPoolTaskExecutorConfiguration {
25
26 @Value("${task.pool.core-pool-size:16}")
27 private Integer corePoolSize;
28 @Value("${task.pool.core-pool-size:35}")
29 private Integer maxPoolSize;
30 @Value("${task.pool.keep-alive-seconds:10}")
31 private Integer keepAliveSeconds;
32 @Value("${task.pool.queue-capacity:300}")
33 private Integer queueCapacity;
34
35 @Bean
36 @Primary
37 public ThreadPoolTaskExecutor getThreadPoolTaskExecutor() {
38 ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
39 threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
40 threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
41 threadPoolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds);
42 threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
43 threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
44 threadPoolTaskExecutor.initialize();
45 return threadPoolTaskExecutor;
46 }
47
48
49 /*@Bean
50 public ThreadPoolExecutor getThreadPoolTaskExecutor() {
51 ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(queueCapacity);
52 ThreadPoolExecutor threadPoolTaskExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.SECONDS, arrayBlockingQueue);
53 return threadPoolTaskExecutor;
54 }*/
55
56 }
1 package com.topdraw.config;
2
3 import cn.hutool.core.map.MapUtil;
4 import lombok.Data;
5 import org.springframework.boot.context.properties.ConfigurationProperties;
6 import org.springframework.context.annotation.Configuration;
7 import org.springframework.util.CollectionUtils;
8
9 import javax.naming.ConfigurationException;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Map;
13
14 @Configuration
15 @Data
16 @ConfigurationProperties(prefix = "wechat", ignoreInvalidFields = true)
17 public class WechatConfig {
18
19 private Map<String, String> miniprogram;
20
21 private Map<String, String> subscribe;
22
23 public List<Map<String, String>> getWechatAppList() throws ConfigurationException {
24 Map<String, String> miniprogram = this.miniprogram;
25 Map<String, String> subscribe = this.subscribe;
26
27 List<Map<String, String>> list = new ArrayList<>();
28 if (MapUtil.isNotEmpty(miniprogram)) {
29 list.add(miniprogram);
30 }
31 if (MapUtil.isNotEmpty(subscribe)) {
32 list.add(subscribe);
33 }
34
35 if (CollectionUtils.isEmpty(list)) {
36 throw new ConfigurationException("配置错误,未配置微信应用");
37 }
38
39 return list;
40 }
41 }
1 package com.topdraw.config;
2
3 import lombok.Data;
4 import org.springframework.boot.context.properties.ConfigurationProperties;
5 import org.springframework.context.annotation.Configuration;
6
7 import java.util.List;
8 import java.util.Map;
9
10 @Configuration
11 @Data
12 @ConfigurationProperties(prefix = "weixin")
13 public class WeixinInfoConfig {
14
15 private List<Map<String, String>> list;
16 }
...@@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; ...@@ -6,7 +6,6 @@ import lombok.NoArgsConstructor;
6 6
7 import javax.validation.constraints.NotNull; 7 import javax.validation.constraints.NotNull;
8 import java.io.Serializable; 8 import java.io.Serializable;
9 import java.sql.Timestamp;
10 import java.time.LocalDateTime; 9 import java.time.LocalDateTime;
11 10
12 /** 11 /**
...@@ -23,38 +22,10 @@ public class DataSyncMsg implements Serializable { ...@@ -23,38 +22,10 @@ public class DataSyncMsg implements Serializable {
23 // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他 22 // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
24 private Integer event; 23 private Integer event;
25 //设备类型 1:大屏;2:小屏(微信)3.小屏(xx) 24 //设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
26 @NotNull
27 private Integer deviceType; 25 private Integer deviceType;
28 // 发送时间 26 // 发送时间
29 private LocalDateTime time; 27 private LocalDateTime time;
30 // 消息体 28 // 消息体
31 private String msgData; 29 private String msgData;
32 30
33 /**
34 * 消息体
35 */
36 @Data
37 @AllArgsConstructor
38 @NoArgsConstructor
39 public static class MsgData {
40 private String remarks; //备注
41 @NotNull
42 private Integer event; // 具体事件 行为事件类型 1:登录;2:观影;3:参与活动;4:订购;10:跨屏绑定;11:积分转移;30:积分兑换商品;98:系统操作;99:其他
43 @NotNull
44 private Long memberId; // 会员id
45 private Long userId; // 账户id
46 @NotNull
47 private Integer deviceType; //设备类型 1:大屏;2:小屏(微信)3.小屏(xx)
48 @NotNull
49 private String appCode; //用户对应的应用code
50 private String memberCode;
51 private Long accountId; // 账号id
52 private Long orderId;
53 private Long activityId;
54 private Long mediaId;
55 private Long itemId;
56 private String param;
57 private String description;
58 }
59
60 } 31 }
......
1 package com.topdraw.mq.producer; 1 package com.topdraw.mq.producer;
2 2
3 import com.topdraw.business.process.service.impl.PointsOperationServiceImpl;
3 import lombok.extern.slf4j.Slf4j; 4 import lombok.extern.slf4j.Slf4j;
4 import org.springframework.amqp.core.AmqpTemplate; 5 import org.springframework.amqp.core.AmqpTemplate;
6 import org.springframework.aop.framework.AopContext;
5 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.beans.factory.annotation.Value; 8 import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
...@@ -57,4 +59,5 @@ public class MessageProducer { ...@@ -57,4 +59,5 @@ public class MessageProducer {
57 amqpTemplate.convertAndSend(exchange, queue, msg); 59 amqpTemplate.convertAndSend(exchange, queue, msg);
58 log.info("send sendMessage msg || exchange: {} || queue: {} || msg:{} ", exchange, queue, msg); 60 log.info("send sendMessage msg || exchange: {} || queue: {} || msg:{} ", exchange, queue, msg);
59 } 61 }
62
60 } 63 }
......
1 package com.topdraw.security; 1 package com.topdraw.util;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.utils.StringUtils; 4 import com.topdraw.utils.StringUtils;
......
1 package com.topdraw.util; 1 package com.topdraw.util;
2 2
3 import org.apache.commons.lang3.StringUtils;
4 import org.springframework.util.Base64Utils;
5
3 import java.nio.charset.StandardCharsets; 6 import java.nio.charset.StandardCharsets;
4 import java.util.Base64; 7 import java.util.Base64;
8 import java.util.regex.Pattern;
5 9
6 public class Base64Util { 10 public class Base64Util {
7 11
...@@ -10,10 +14,32 @@ public class Base64Util { ...@@ -10,10 +14,32 @@ public class Base64Util {
10 return name1; 14 return name1;
11 } 15 }
12 16
17
18
19 public static boolean isBase64(String str) {
20 if (StringUtils.isBlank(str)) {
21 return false;
22 }
23 String base64Pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
24 boolean matches = Pattern.matches(base64Pattern, str);
25 if (matches) {
26 String decodeBase64Str = new String(Base64Utils.decode(str.getBytes()));
27 String encodeBase64Str = Base64Utils.encodeToString(decodeBase64Str.getBytes());
28 if (str.equals(encodeBase64Str)) {
29 return true;
30 }
31 }
32 return false;
33 }
34
35
36
13 public static void main(String[] args) { 37 public static void main(String[] args) {
14 // String name = "test005@itv"; 38 // String name = "test005@itv";
15 String name = "18580619168a@iptv"; 39 // String name = "18580619168a@iptv";
16 String encode = encode(name); 40 // String encode = encode(name);
17 System.out.println(encode); 41 // System.out.println(encode);
42 boolean a = isBase64("fdsfdsf");
43 System.out.println(a);
18 } 44 }
19 } 45 }
......
1 package com.topdraw.util; 1 package com.topdraw.util;
2 2
3 import java.time.Instant; 3 import java.text.SimpleDateFormat;
4 import java.time.LocalDate; 4 import java.time.*;
5 import java.time.LocalDateTime; 5 import java.time.temporal.TemporalAdjusters;
6 import java.time.ZoneId; 6 import java.time.temporal.TemporalUnit;
7 import java.util.Calendar; 7 import java.util.Calendar;
8 import java.util.Date; 8 import java.util.Date;
9 import java.util.TimeZone; 9 import java.util.TimeZone;
...@@ -174,6 +174,29 @@ public class DateUtil { ...@@ -174,6 +174,29 @@ public class DateUtil {
174 return calendar.getTimeInMillis(); 174 return calendar.getTimeInMillis();
175 } 175 }
176 176
177 public static String getWeekFirstDay() {
178 SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
179
180 Calendar calendar1=Calendar.getInstance();
181
182 calendar1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
183
184 System.out.println("本周一: "+sdf.format(calendar1.getTime()));
185
186 return sdf.format(calendar1.getTime());
187 }
188
189 public static String getWeekLastDay() {
190 SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
191
192 Calendar calendar1=Calendar.getInstance();
193 calendar1.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
194 calendar1.add( Calendar.DAY_OF_MONTH,1);
195 System.out.println("本周日: "+sdf.format(calendar1.getTime()));
196
197 return sdf.format(calendar1.getTime());
198 }
199
177 /** 200 /**
178 * 时间戳转字符串 201 * 时间戳转字符串
179 * 202 *
...@@ -188,6 +211,10 @@ public class DateUtil { ...@@ -188,6 +211,10 @@ public class DateUtil {
188 } 211 }
189 212
190 public static void main(String[] args) { 213 public static void main(String[] args) {
214 String weekFirstDay = getWeekFirstDay();
215 System.out.println(weekFirstDay);
216 String weekLastDay = getWeekLastDay();
217 System.out.println(weekLastDay);
191 /*Long currentTime = System.currentTimeMillis(); 218 /*Long currentTime = System.currentTimeMillis();
192 System.out.println("Current Time : " + currentTime + " = " + timestampToStr(currentTime, "GMT+8")); 219 System.out.println("Current Time : " + currentTime + " = " + timestampToStr(currentTime, "GMT+8"));
193 Long dailyStart = getDailyStartTime(currentTime, "GMT+8:00"); 220 Long dailyStart = getDailyStartTime(currentTime, "GMT+8:00");
...@@ -201,7 +228,8 @@ public class DateUtil { ...@@ -201,7 +228,8 @@ public class DateUtil {
201 System.out.println("Month Start : " + monthStart + " = " + timestampToStr(monthStart, "GMT+8") + " Month End : " + monthEnd + " = " + timestampToStr(monthEnd, "GMT+8")); 228 System.out.println("Month Start : " + monthStart + " = " + timestampToStr(monthStart, "GMT+8") + " Month End : " + monthEnd + " = " + timestampToStr(monthEnd, "GMT+8"));
202 System.out.println("Year Start : " + yearStart + " = " + timestampToStr(yearStart, "GMT+8") + " Year End : " + yearEnd + " = " + timestampToStr(yearEnd, "GMT+8")); 229 System.out.println("Year Start : " + yearStart + " = " + timestampToStr(yearStart, "GMT+8") + " Year End : " + yearEnd + " = " + timestampToStr(yearEnd, "GMT+8"));
203 */ 230 */
204 LocalDateTime lastDateTimeCurrentYear = getLastDateTimeSecondYear(); 231 // LocalDateTime lastDateTimeCurrentYear = getLastDateTimeSecondYear();
232
205 } 233 }
206 234
207 } 235 }
......
1 package com.topdraw.util;
2
3 /*
4 import java.security.NoSuchAlgorithmException;
5 import java.security.SecureRandom;
6 import java.util.UUID;
7
8 import org.afflatus.utility.AppConfiguration;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 import com.aliyun.mns.client.CloudAccount;
13 import com.aliyun.mns.client.CloudTopic;
14 import com.aliyun.mns.client.MNSClient;
15 import com.aliyun.mns.common.ServiceException;
16 import com.aliyun.mns.model.BatchSmsAttributes;
17 import com.aliyun.mns.model.MessageAttributes;
18 import com.aliyun.mns.model.RawTopicMessage;
19 import com.aliyun.mns.model.TopicMessage;
20 import com.aliyuncs.DefaultAcsClient;
21 import com.aliyuncs.IAcsClient;
22 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
23 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
24 import com.aliyuncs.http.MethodType;
25 import com.aliyuncs.profile.DefaultProfile;
26 import com.aliyuncs.profile.IClientProfile;
27 */
28
29 public class MsgUtil {
30
31 // private static Logger log = LoggerFactory.getLogger(MsgUtil.class.getName());
32
33 /* private static final String ACCESSID = AppConfiguration.get("MESSAGE.ACCESSID");
34 private static final String ACCESSKEY = AppConfiguration.get("MESSAGE.ACCESSKEY");
35 private static final String MNSENDPOINT = AppConfiguration.get("MESSAGE.MNSENDPOINT");
36 private static final String TOPIC = AppConfiguration.get("MESSAGE.TOPIC");
37 private static final String SIGNNAME = AppConfiguration.get("MESSAGE.SIGNNAME");
38 private static final String TEMPLATECODE = AppConfiguration.get("MESSAGE.TEMPLATECODE");
39 private static final String REGION = AppConfiguration.get("MESSAGE.REGION");
40
41 public static String generateVerifyCodeAndSend(String verifyKey, String phone) {
42 String verifyCode;
43 try {
44 verifyCode = getRandom(4);
45 } catch (NoSuchAlgorithmException e) {
46 verifyCode = "8673";
47 }
48 // sendMsg(phone, ":" + verifyCode + ",序号:" + verifyKey);
49 sendMsg2(phone, verifyCode);
50 return verifyCode;
51 }*/
52
53 public static void sendMsg(String phone, String verifyCode) {
54 /**
55 * Step 1. 获取主题引用
56 */
57 /*CloudAccount account = new CloudAccount(ACCESSID, ACCESSKEY, MNSENDPOINT);
58 MNSClient client = account.getMNSClient();
59 CloudTopic topic = client.getTopicRef(TOPIC);*/
60 /**
61 * Step 2. 设置SMS消息体(必须)
62 *
63 * 注:目前暂时不支持消息内容为空,需要指定消息内容,不为空即可。
64 */
65 /*RawTopicMessage msg = new RawTopicMessage();
66 msg.setMessageBody("sms-message");*/
67 /**
68 * Step 3. 生成SMS消息属性
69 */
70 /*MessageAttributes messageAttributes = new MessageAttributes();
71 BatchSmsAttributes batchSmsAttributes = new BatchSmsAttributes();
72 // 3.1 设置发送短信的签名(SMSSignName)
73 batchSmsAttributes.setFreeSignName(SIGNNAME);
74 // 3.2 设置发送短信使用的模板(SMSTempateCode)
75 batchSmsAttributes.setTemplateCode(TEMPLATECODE);
76 // 3.3 设置发送短信所使用的模板中参数对应的值(在短信模板中定义的,没有可以不用设置)
77 BatchSmsAttributes.SmsReceiverParams smsReceiverParams = new BatchSmsAttributes.SmsReceiverParams();
78 smsReceiverParams.setParam("code", verifyCode);
79 // 3.4 增加接收短信的号码
80 batchSmsAttributes.addSmsReceiver(phone, smsReceiverParams);
81 messageAttributes.setBatchSmsAttributes(batchSmsAttributes);*/
82 // try {
83 /**
84 * Step 4. 发布SMS消息
85 */
86 /*TopicMessage ret = topic.publishMessage(msg, messageAttributes);
87 log.info("sendMsg | MessageId: " + ret.getMessageId() + " MessageMD5: " + ret.getMessageBodyMD5());
88 } catch (ServiceException se) {
89 System.out.println(se.getErrorCode() + se.getRequestId());
90 System.out.println(se.getMessage());
91 se.printStackTrace();
92 } catch (Exception e) {
93 e.printStackTrace();
94 } finally {
95 client.close();
96 }*/
97 }
98
99 public static void sendMsg2(String phone, String verifyCode) {
100 /*
101 try {
102 // 设置超时时间-可自行调整
103 System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
104 System.setProperty("sun.net.client.defaultReadTimeout", "10000");
105 // 初始化ascClient需要的几个参数
106 final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改)
107 final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改)
108 // 替换成你的AK
109 final String accessKeyId = ACCESSID;// 你的accessKeyId,参考本文档步骤2
110 final String accessKeySecret = ACCESSKEY;// 你的accessKeySecret,参考本文档步骤2
111 // 初始化ascClient,暂时不支持多region(请勿修改)
112 IClientProfile profile = DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret);
113 DefaultProfile.addEndpoint(REGION, REGION, product, domain);
114 IAcsClient acsClient = new DefaultAcsClient(profile);
115 // 组装请求对象
116 SendSmsRequest request = new SendSmsRequest();
117 // 使用post提交
118 request.setMethod(MethodType.POST);
119 // 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
120 request.setPhoneNumbers(phone);
121 // 必填:短信签名-可在短信控制台中找到
122 request.setSignName(SIGNNAME);
123 // 必填:短信模板-可在短信控制台中找到
124 request.setTemplateCode(TEMPLATECODE);
125 // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
126 // 友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
127 request.setTemplateParam("{\"code\":\"" + verifyCode + "\"}");
128 // 可选-上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
129 // request.setSmsUpExtendCode("90997");
130 // 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
131 request.setOutId(UUID.randomUUID().toString().replaceAll("-", ""));
132 // 请求失败这里会抛ClientException异常
133 SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
134 if (null != sendSmsResponse) {
135 log.info("sendMsg | RequestId: " + sendSmsResponse.getRequestId() + " Code: "
136 + sendSmsResponse.getCode() + " Message: " + sendSmsResponse.getMessage());
137 }
138 if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
139 // 请求成功
140 }
141 } catch (Exception e) {
142 e.printStackTrace();
143 } finally {
144
145 }
146 */
147
148 }
149
150 /*public static String getRandom(int count) throws NoSuchAlgorithmException {
151 StringBuilder sb = new StringBuilder();
152 String str = "0123456789";
153 SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
154 for (int i = 0; i < count; i++) {
155 int num = sr.nextInt(str.length());
156 sb.append(str.charAt(num));
157 str = str.replace(("" + str.charAt(num)), "");
158 }
159 return sb.toString();
160 }
161 */
162 }
1 package com.topdraw.config; 1 package com.topdraw.util;
2 2
3 import cn.hutool.core.util.StrUtil; 3 import cn.hutool.core.util.StrUtil;
4 4
......
1 package com.topdraw.util;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 /**
7 * @author :
8 * @description:
9 * @function :
10 * @date :Created in 2022/6/29 15:10
11 * @version: :
12 * @modified By:
13 * @since : modified in 2022/6/29 15:10
14 */
15 public class RegexUtil {
16
17
18 public static boolean mobileRegex(String mobile){
19 // String pattern = "0?(13|14|15|17|18|19)[0-9]{9}";
20 String pattern = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
21 Pattern r = Pattern.compile(pattern);
22 Matcher m = r.matcher(mobile);
23 return m.find();
24 }
25
26 public static boolean appPasswordRegex(String password) {
27 String pattern = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,25}$";
28 Pattern r = Pattern.compile(pattern);
29 Matcher m = r.matcher(password);
30 return m.find();
31 }
32
33 }
1 package com.topdraw.weixin.beans;
2
3 import lombok.Data;
4
5 @Data
6 public class ActionInfo {
7 private Scene scene;
8 }
1 package com.topdraw.weixin.beans;
2
3 import com.alibaba.fastjson.annotation.JSONField;
4 import lombok.Data;
5
6 @Data
7 public class QrCode {
8
9 @JSONField(name = "action_name")
10 private String actionName;
11
12 @JSONField(name = "expire_seconds")
13 private Integer expireSeconds;
14
15 @JSONField(name = "action_info")
16 private ActionInfo actionInfo;
17
18
19
20 }
1 package com.topdraw.weixin.beans;
2
3 import com.alibaba.fastjson.annotation.JSONField;
4 import lombok.Data;
5
6 @Data
7 public class Scene {
8 @JSONField(name = "scene_id")
9 private Long sceneId;
10
11 @JSONField(name = "scene_str")
12 private String sceneStr;
13 }
1 package com.topdraw.weixin.beans;
2
3 import com.alibaba.fastjson.annotation.JSONField;
4 import lombok.Data;
5
6 import java.util.Map;
7
8 @Data
9 public class WeiXinNotice {
10
11 @JSONField(serialize=false)
12 private String appid;
13
14 @JSONField(serialize=false)
15 private Long userId;
16
17 //目标用户
18 @JSONField(name = "touser")
19 private String toUser;
20
21 // 模板code
22 @JSONField(serialize=false)
23 private String code;
24
25 // 模板id
26 @JSONField(name = "template_id")
27 private String templateId;
28
29 // 点击通知跳转页面
30 private String page;
31
32 // 小程序版本
33 @JSONField(name = "miniprogram_state")
34 private String miniprogramState;
35
36 // 填充数据
37 private Map<String, Object> data;
38 }
1 package com.topdraw.weixin.service;
2
3 public class WeChatConstants {
4
5 // 订阅号
6 public static final String WX_SUBSCRIPTION = "subscription";
7
8
9 }
1 package com.topdraw.weixin.util;
2
3 public class WeChatConstants {
4
5 public static String HTTPS_AUTHORIZE_WITH_SNSAPI_USERINFO = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
6
7 public static final String HTTPS_TOKEN = "https://api.weixin.qq.com/cgi-bin/token";
8
9 public static final String HTTPS_TICKET_GETTICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
10
11 public static final String HTTPS_SNS_OAUTH2_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
12
13 public static final String HTTPS_SNS_USERINFO = "https://api.weixin.qq.com/sns/userinfo";
14
15 public static final String CODE2SESSION = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
16
17 /**
18 * 把媒体文件上传到微信服务器。目前仅支持图片。用于发送客服消息或被动回复用户消息。
19 */
20 public static String UPLOAD_URL = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type=image";
21
22 /**
23 * 获取客服消息内的临时素材。即下载临时的多媒体文件。
24 */
25 public static String GET_MEDIA = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}";
26
27 /**
28 * 用于向微信服务端申请二维码的url
29 */
30 public static String URL_QR_CODE = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}";
31
32 /**
33 * 用于聊天时向用户发送消息的url
34 */
35 public static String CUSTOM_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}";
36
37 /**
38 * 发送小程序订阅消息
39 */
40 public static final String SUBSCRIBE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}";
41
42 /**
43 * 生成带参数二维码
44 */
45 public static final String QR_CODE_URL = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";
46
47 /**
48 * 获取用户基本信息
49 */
50 public static final String GET_USER_INFO = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN";
51
52
53 // 批量获取关注者列表
54 public static final String GET_USER_LIST = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}";
55
56 /**
57 * 成功
58 */
59 public static String SUCCESS = "SUCCESS";
60
61 /**
62 * 微信系统错误
63 */
64 public static String SYSTEMERROR = "SYSTEMERROR";
65
66 /**
67 * 失败 (注意:微信有的接口返回的失败用FAIL字符串表示,有的接口用FAILED表示)
68 */
69 public static String FAIL = "FAIL";
70
71 /**
72 * 微信企业付款到个人失败 (注意:微信有的接口返回的失败用FAIL字符串表示,有的接口用FAILED表示)
73 */
74 public static String FAILED = "FAILED";
75
76 public static String ACCESS_TOKEN = "access_token";
77
78 public static String ERR_CODE = "errcode";
79
80 /**
81 * 微信请求时,返回ACCESS_TOKEN错误码
82 */
83 public static final String ACCESS_TOKEN_INVALID_CODE = "40001";
84
85
86 /**
87 * 文本消息
88 */
89 public static String MSG_TYPE_TEXT = "text";
90
91 public static String MSG_TYPE_MINIPROGRAMPAGE = "miniprogrampage";
92
93 public static String MSG_TYPE_LINK = "link";
94
95 public static String MSG_TYPE_IMAGE = "image";
96
97 /**
98 * 事件消息
99 */
100 public static String MSG_TYPE_EVENT = "event";
101
102
103 /**
104 * 二维码类型,临时的整型参数值
105 */
106 public static String QR_SCENE = "QR_SCENE";
107
108 /**
109 * 二维码类型,临时的字符串参数值
110 */
111 public static String QR_STR_SCENE = "QR_STR_SCENE";
112
113 /**
114 * 二维码类型,永久的整型参数值
115 */
116 public static String QR_LIMIT_SCENE = "QR_LIMIT_SCENE";
117
118 /**
119 * 二维码类型,永久的字符串参数值
120 */
121 public static String QR_LIMIT_STR_SCENE = "QR_LIMIT_STR_SCENE";
122
123
124 /******** 事件推送事件类型BEGIN********/
125
126 /**
127 * 取消订阅
128 */
129 public static final String EVENT_UNSUBSCRIBE = "unsubscribe";
130
131
132 /**
133 * 订阅
134 */
135 public static final String EVENT_SUBSCRIBE = "subscribe";
136
137 /**
138 * 扫描带参数二维码事件,用户已关注时的事件推送
139 */
140 public static final String EVENT_SCAN = "SCAN";
141
142 /**
143 * 上报地理位置事件
144 */
145 public static final String EVENT_LOCATION = "LOCATION";
146
147 /**
148 * 自定义菜单事件
149 */
150 public static final String EVENT_CLICK = "CLICK";
151
152 /******** 事件推送事件类型END********/
153
154
155 /**
156 * 微信ACCESS_TOKEN缓存KEY
157 */
158 public static final String TOKEN_KEY = "GLOBAL_WX_ACCESS_TOKEN_";
159
160
161 /**
162 * 微信临时素材缓存KEY
163 */
164 public static final String WEIXIN_MEDIA_KEY = "WEIXIN_MEDIA_KEY_";
165
166 // 微信应用类型 小程序 服务号 订阅号
167 // 小程序
168 public static final String WX_APPLET = "applet";
169 // 服务号
170 public static final String WX_SERVICE = "service";
171 // 订阅号
172 public static final String WX_SUBSCRIPTION = "subscription";
173
174
175 }
1 package com.topdraw.weixin.util;
2
3 import com.topdraw.config.WeixinInfoConfig;
4 import com.topdraw.utils.StringUtils;
5 import lombok.extern.slf4j.Slf4j;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component;
8
9 import javax.servlet.ServletOutputStream;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 import java.io.IOException;
13 import java.io.UnsupportedEncodingException;
14 import java.security.MessageDigest;
15 import java.security.NoSuchAlgorithmException;
16 import java.util.Arrays;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Optional;
20
21
22 @Component
23 @Slf4j
24 public class WeixinUtil {
25
26
27 private static WeixinInfoConfig WEIXININFOCONFIG;
28
29 @Autowired
30 public void setWeixinInfoConfig(WeixinInfoConfig weixinInfoConfig) {
31 WEIXININFOCONFIG = weixinInfoConfig;
32 }
33
34 public static Map<String, String> getWeixinInfoByAppid(String appid) {
35 if (StringUtils.isBlank(appid)) {
36 throw new RuntimeException("wxAppid can not be null");
37 }
38 List<Map<String, String>> list = WEIXININFOCONFIG.getList();
39 Optional<Map<String, String>> weixinInfoOptional = list.stream().filter(o -> o.get("appid").equals(appid)).findFirst();
40 if (!weixinInfoOptional.isPresent()) {
41 throw new RuntimeException("wxAppid error, appid is : " + appid);
42 }
43 return weixinInfoOptional.get();
44 }
45
46
47 public static Map<String, String> getWeixinInfoByIndex(Integer index) {
48 List<Map<String, String>> list = WEIXININFOCONFIG.getList();
49 if (list.size() < index + 1) {
50 throw new RuntimeException("wxinfo error, index out of range : {}" + index);
51 }
52 return list.get(index);
53 }
54 /**
55 * 使用SHA1算法对字符串数组进行加密
56 *
57 * @param strList
58 * @return
59 */
60 public static String encodeUsingSHA1(String... strList) {
61 //将strList的值进行字典排序
62 Arrays.sort(strList);
63 StringBuilder content = new StringBuilder();
64 for (int i = 0; i < strList.length; i++) {
65 content.append(strList[i]);
66 }
67
68 return doEncodeUsingSHA1(content.toString());
69 }
70
71
72 /**
73 * SHA1实现
74 *
75 * @return sha1加密后的字符串
76 */
77 private static String doEncodeUsingSHA1(String inStr) {
78 byte[] byteArray ;
79
80 try {
81 MessageDigest sha = MessageDigest.getInstance("SHA-1");
82 byteArray = sha.digest(inStr.getBytes("UTF-8"));
83 } catch (NoSuchAlgorithmException e) {
84 throw new RuntimeException("no sha-1 algorithm");
85 } catch (UnsupportedEncodingException e) {
86 throw new RuntimeException("unsupported utf-8 encoding");
87 }
88
89 StringBuilder sb = new StringBuilder();
90 for (int i = 0; i < byteArray.length; i++) {
91 sb.append(Integer.toString((byteArray[i] & 0xff) + 0x100, 16).substring(1));
92 }
93 return sb.toString();
94 }
95
96 /**
97 * 公众号,小程序后台配置服务器,初次检验时使用
98 * @throws IOException
99 */
100 public static void doGet(HttpServletRequest request, HttpServletResponse response, Map<String, String> weixinInfo) throws IOException {
101 log.info("doGet receive WeChat server request parameters:{}", request.getParameterMap());
102 String signature = request.getParameter("signature");
103 String timestamp = request.getParameter("timestamp");
104 String nonce = request.getParameter("nonce");
105 String echoStr = request.getParameter("echostr");
106 String[] arr = new String[]{weixinInfo.get("token"), timestamp, nonce};
107 String encrypt = WeixinUtil.encodeUsingSHA1(arr);
108 if (encrypt.equals(signature)) {
109 ServletOutputStream outputStream = response.getOutputStream();
110 outputStream.write(echoStr.getBytes());
111 outputStream.flush();
112 }
113 }
114
115
116 }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
2 spring: 2 spring:
3 datasource: 3 datasource:
4 # 测试/演示库url: 4 # 测试/演示库url:
5 url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_admin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false 5 # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user_admin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
6 username: root
7 password: root
8 # url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs_admin_chongshu?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
9 # username: root 6 # username: root
10 # password: Tjlh@2021 7 # password: root
8 url: jdbc:log4jdbc:mysql://139.196.145.150:3306/ucs_stage_admin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
9 username: root
10 password: Tjlh@2021
11 11
12 driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy 12 driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
13 #Druid 13 #Druid
...@@ -20,7 +20,7 @@ spring: ...@@ -20,7 +20,7 @@ spring:
20 # 最大连接数 20 # 最大连接数
21 max-active: 15 21 max-active: 15
22 # 获取连接超时时间 22 # 获取连接超时时间
23 max-wait: 5000 23 max-wait: 5000000
24 # 连接有效性检测时间 24 # 连接有效性检测时间
25 time-between-eviction-runs-millis: 90000 25 time-between-eviction-runs-millis: 90000
26 # 最大空闲时间 26 # 最大空闲时间
...@@ -28,29 +28,39 @@ spring: ...@@ -28,29 +28,39 @@ spring:
28 test-while-idle: true 28 test-while-idle: true
29 test-on-borrow: false 29 test-on-borrow: false
30 test-on-return: false 30 test-on-return: false
31
32 validation-query: select 1 31 validation-query: select 1
33 # 配置监控统计拦截的filters 32 # 配置监控统计拦截的filters
34 filters: stat 33 filters: stat
35 stat-view-servlet: 34 stat-view-servlet:
36 url-pattern: /druid/* 35 url-pattern: /druid/*
37 reset-enable: false 36 reset-enable: false
38
39 web-stat-filter: 37 web-stat-filter:
40 url-pattern: /* 38 url-pattern: /*
41 exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" 39 exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
42 40
41 jackson:
42 time-zone: GMT+8
43
44 data:
45 redis:
46 repositories:
47 enabled: false
48
43 #配置 Jpa 49 #配置 Jpa
44 jpa: 50 jpa:
51 properties:
45 hibernate: 52 hibernate:
46 # 生产环境设置成 none,避免程序运行时自动更新数据库结构 53 dialect: org.hibernate.dialect.MySQL5InnoDBDialect
47 ddl-auto: none 54 ddl-auto: none
55 open-in-view: true
48 show-sql: false 56 show-sql: false
57
49 servlet: 58 servlet:
50 multipart: 59 multipart:
51 file-size-threshold: 2KB 60 file-size-threshold: 2KB
52 max-file-size: 100MB 61 max-file-size: 100MB
53 max-request-size: 200MB 62 max-request-size: 200MB
63
54 # redis 64 # redis
55 redis: 65 redis:
56 #数据库索引 66 #数据库索引
...@@ -60,6 +70,7 @@ spring: ...@@ -60,6 +70,7 @@ spring:
60 password: redis123 70 password: redis123
61 #连接超时时间 71 #连接超时时间
62 timeout: 5000 72 timeout: 5000
73
63 rabbitmq: 74 rabbitmq:
64 # host: 139.196.145.150 # rabbitmq的连接地址 75 # host: 139.196.145.150 # rabbitmq的连接地址
65 # port: 5672 # rabbitmq的连接端口号 76 # port: 5672 # rabbitmq的连接端口号
...@@ -73,72 +84,3 @@ spring: ...@@ -73,72 +84,3 @@ spring:
73 username: guest # rabbitmq的用户名 84 username: guest # rabbitmq的用户名
74 password: guest # rabbitmq的密码 85 password: guest # rabbitmq的密码
75 publisher-confirms: true #如果对异步消息需要回调必须设置为true 86 publisher-confirms: true #如果对异步消息需要回调必须设置为true
...\ No newline at end of file ...\ No newline at end of file
76
77 #jwt。依赖的common中有需要jwt的部分属性。
78 jwt:
79 header: Authorization
80 secret: mySecret
81 # token 过期时间/毫秒,6小时 1小时 = 3600000 毫秒
82 expiration: 7200000
83 # 在线用户key
84 online: online-token
85 # 验证码
86 codeKey: code-key
87 # token 续期检查时间范围(60分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
88 detect: 3600000
89 # 续期时间,2小时,单位毫秒
90 renew: 7200000
91
92 #是否允许生成代码,生产环境设置为false
93 generator:
94 enabled: false
95
96 #是否开启 swagger-ui
97 swagger:
98 enabled: false
99
100 file:
101 path: system/file
102 avatar: system/avatar
103 upload: upload
104 # 文件大小 /M
105 maxSize: 100
106 avatarMaxSize: 5
107
108 service:
109 mq:
110 exchange: exchange.MemberInfoSync
111 queue: queue.MemberInfoSync
112
113 weixin:
114 list:
115 - appid: wxfaa765183a332521
116 secret: b5c1c39cb95b45b599a02fd68b5fcf17
117 token:
118 encodingAesKey:
119 imagePath:
120 content: 长按识别二维码,加入微信群。
121 miniprogramState: formal
122 # 点击模板卡片后的默认跳转页面
123 page: pages/index/main
124 # 生成带参数二维码的有效期
125 qrCodeExpireSeconds: 86400
126 env: dev
127 # 订阅号
128 - appid: wx5d88c7fe99f89f32
129 secret: b213afe99a469d4be576f330dad643b8
130 token: topdraw
131 encodingAesKey: g3mYB6yx2ZiebxwKcI1H2iw3LlYNBHb7PqsVYFHUQzi
132 # 应用类型 小程序 服务号 订阅号, 当前基于订阅号有特殊逻辑
133 appType: subscription
134 imagePath: /topdraw/app/user_center_service_te/upload/customer/weChat.png
135 content: 长按识别二维码,关注订阅号。
136 miniprogramState: formal
137 # 点击模板卡片后的默认跳转页面
138 page: pages/index/main
139 # 生成带参数二维码的有效期
140 qrCodeExpireSeconds: 300
141 env: dev
142
143 api:
144 uc-service: http://127.0.0.1:8446
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,40 +2,45 @@ server: ...@@ -2,40 +2,45 @@ server:
2 port: 8447 2 port: 8447
3 spring: 3 spring:
4 application: 4 application:
5 name: member-service 5 name: uc-engine
6 freemarker:
7 check-template-location: false
8 profiles: 6 profiles:
9 active: dev 7 active: dev
10 jackson:
11 time-zone: GMT+8
12 data:
13 redis:
14 repositories:
15 enabled: false
16 8
17 #配置 Jpa 9 # 微信
18 jpa: 10 wechat:
19 properties: 11 # 小程序
20 hibernate: 12 miniprogram:
21 dialect: org.hibernate.dialect.MySQL5InnoDBDialect 13 appid: wxfaa765183a332521
22 open-in-view: true 14 secret: b5c1c39cb95b45b599a02fd68b5fcf17
15 token:
16 encodingAesKey:
17 imagePath:
18 content: 长按识别二维码,加入微信群。
19 miniprogramState: formal
20 # 点击模板卡片后的默认跳转页面
21 page: pages/index/main
22 # 生成带参数二维码的有效期
23 qrCodeExpireSeconds: 86400
24 env: dev
23 25
26 # 订阅号
27 subscribe:
28 appid: wx5d88c7fe99f89f32
29 secret: b213afe99a469d4be576f330dad643b8
30 token: topdraw
31 encodingAesKey: g3mYB6yx2ZiebxwKcI1H2iw3LlYNBHb7PqsVYFHUQzi
32 # 应用类型 小程序 服务号 订阅号, 当前基于订阅号有特殊逻辑
33 appType: subscription
34 imagePath: /topdraw/app/user_center_service_te/upload/customer/weChat.png
35 content: 长按识别二维码,关注订阅号。
36 miniprogramState: formal
37 # 点击模板卡片后的默认跳转页面
38 page: pages/index/main
39 # 生成带参数二维码的有效期
40 qrCodeExpireSeconds: 300
41 env: dev
24 42
25 task: 43 #第三方接口
26 pool: 44 api:
27 # 核心线程池大小 45 # ucs
28 core-pool-size: 10 46 uc-service: http://127.0.0.1:8446
29 # 最大线程数
30 max-pool-size: 30
31 # 活跃时间
32 keep-alive-seconds: 60
33 # 队列容量
34 queue-capacity: 50
35
36 #登录图形验证码有效时间/分钟
37 loginCode:
38 expiration: 2
39
40 #默认上传图片类型
41 default-image-type: -1
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest { ...@@ -39,16 +39,16 @@ public class GeneratorCode extends BaseTest {
39 @Rollback(value = false) 39 @Rollback(value = false)
40 @Transactional(rollbackFor = Exception.class) 40 @Transactional(rollbackFor = Exception.class)
41 public void generator() { 41 public void generator() {
42 var dbName = "uc_wechat_subscribe_record"; 42 var dbName = "uc_growth_report";
43 // 表名称,支持多表 43 // 表名称,支持多表
44 var tableNames = Arrays.asList(dbName); 44 var tableNames = Arrays.asList(dbName);
45 String[] s = dbName.split("_"); 45 String[] s = dbName.split("_");
46 46
47 var pre = s[0]; 47 var pre = s[0];
48 var target1 = s[s.length-1]; 48 var target1 = s[s.length-1];
49 var preRoute = "com.topdraw.weixin."; 49 var preRoute = "com.topdraw.business.module.user.iptv.growreport";
50 StringBuilder builder = new StringBuilder(preRoute); 50 StringBuilder builder = new StringBuilder(preRoute);
51 builder.append("subscribe"); 51 // builder.append("wechatshare");
52 // builder.append(target); 52 // builder.append(target);
53 53
54 tableNames.forEach(tableName -> { 54 tableNames.forEach(tableName -> {
......
...@@ -96,11 +96,12 @@ public class TaskOperationControllerTest extends BaseTest { ...@@ -96,11 +96,12 @@ public class TaskOperationControllerTest extends BaseTest {
96 public void play() { 96 public void play() {
97 try { 97 try {
98 String s = "{\"evt\":\"PLAY\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," + 98 String s = "{\"evt\":\"PLAY\",\"event\":8,\"time\":\"2022-05-03 23:10:09\",\"deviceType\":1," +
99 "\"msgData\":{\"memberCode\":\"1537253277861699584\",\"param\":\"{\\\"playDuration\\\":60}\"}}"; 99 "\"msgData\":{\"platformAccount\":\"1537253277861699584\",\"param\":\"{\\\"playDuration\\\":60}\"}}";
100 TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria(); 100 TaskOperationQueryCriteria pointsQueryCriteria = new TaskOperationQueryCriteria();
101 pointsQueryCriteria.setContent(s); 101 pointsQueryCriteria.setContent(s);
102 String s1 = JSON.toJSONString(pointsQueryCriteria); 102 String s1 = JSON.toJSONString(pointsQueryCriteria);
103 this.taskOperationController.dealTask(pointsQueryCriteria); 103 System.out.println(s1);
104 // this.taskOperationController.dealTask(pointsQueryCriteria);
104 } catch (Exception e) { 105 } catch (Exception e) {
105 e.printStackTrace(); 106 e.printStackTrace();
106 } 107 }
...@@ -154,7 +155,7 @@ public class TaskOperationControllerTest extends BaseTest { ...@@ -154,7 +155,7 @@ public class TaskOperationControllerTest extends BaseTest {
154 task.setValidTime(TimestampUtil.now()); 155 task.setValidTime(TimestampUtil.now());
155 task.setPointsType(0); 156 task.setPointsType(0);
156 157
157 task.setAttr("{\"value\":\"[1,2]\"}"); 158 // task.setAttr("{\"value\":\"[1,2]\"}");
158 159
159 task.setTaskTemplateId(13L); 160 task.setTaskTemplateId(13L);
160 161
...@@ -168,7 +169,7 @@ public class TaskOperationControllerTest extends BaseTest { ...@@ -168,7 +169,7 @@ public class TaskOperationControllerTest extends BaseTest {
168 Task task = new Task(); 169 Task task = new Task();
169 BeanUtils.copyProperties(taskDTO, task); 170 BeanUtils.copyProperties(taskDTO, task);
170 task.setName("testTask4455"); 171 task.setName("testTask4455");
171 task.setAttr("{\"value\":\"[4,10]\"}"); 172 // task.setAttr("{\"value\":\"[4,10]\"}");
172 this.taskOperationController.updateTask(task); 173 this.taskOperationController.updateTask(task);
173 } 174 }
174 175
...@@ -179,6 +180,13 @@ public class TaskOperationControllerTest extends BaseTest { ...@@ -179,6 +180,13 @@ public class TaskOperationControllerTest extends BaseTest {
179 this.taskOperationController.deleteTask(task); 180 this.taskOperationController.deleteTask(task);
180 } 181 }
181 182
183 @Test
184 public void dealTask() {
185 String content = "{\"deviceType\":1,\"event\":8,\"evt\":\"PLAY\",\"msgData\":\"{\\\"description\\\":\\\"{\\\\\\\"playDuration\\\\\\\":1,\\\\\\\"time\\\\\\\":\\\\\\\"2022-05-03 23:10:09\\\\\\\",\\\\\\\"mediaId\\\\\\\":432,\\\\\\\"mediaCode\\\\\\\":\\\\\\\"media_123\\\\\\\",\\\\\\\"mediaName\\\\\\\":\\\\\\\"白宫陷落\\\\\\\"}\\\",\\\"mediaId\\\":432,\\\"platformAccount\\\":\\\"6002110106@ITVP\\\",\\\"param\\\":\\\"{\\\\\\\"playDuration\\\\\\\":1}\\\"}\",\"time\":\"2022-06-17T13:07:16.433\"}\n";
186 TaskOperationQueryCriteria task = new TaskOperationQueryCriteria();
187 task.setContent(content);
188 this.taskOperationController.dealTask(task);
189 }
182 190
183 191
184 } 192 }
......
1 package com.topdraw.test.business.process.rest; 1 package com.topdraw.test.business.process.rest;
2 2
3 import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.BaseTest; 5 import com.topdraw.BaseTest;
6 import com.topdraw.business.module.user.app.domain.UserApp;
5 import com.topdraw.business.module.user.iptv.domain.UserTv; 7 import com.topdraw.business.module.user.iptv.domain.UserTv;
6 import com.topdraw.business.module.user.weixin.domain.UserWeixin; 8 import com.topdraw.business.module.user.weixin.domain.UserWeixin;
7 import com.topdraw.business.process.domian.weixin.BindBean; 9 import com.topdraw.business.process.domian.weixin.BindBean;
10 import com.topdraw.business.process.domian.weixin.SubscribeBean;
8 import com.topdraw.business.process.domian.weixin.TvUnBindBean; 11 import com.topdraw.business.process.domian.weixin.TvUnBindBean;
9 import com.topdraw.business.process.domian.weixin.WeixinUnBindBean; 12 import com.topdraw.business.process.domian.weixin.WeixinUnBindBean;
10 import com.topdraw.business.process.rest.UserOperationController; 13 import com.topdraw.business.process.rest.UserOperationController;
11 import com.topdraw.common.ResultInfo; 14 import com.topdraw.common.ResultInfo;
12 import org.junit.Test; 15 import org.junit.Test;
13 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.util.Base64Utils;
14 18
15 import java.sql.Timestamp; 19 import java.sql.Timestamp;
20 import java.util.HashMap;
16 21
17 public class UserOperationControllerTest extends BaseTest { 22 public class UserOperationControllerTest extends BaseTest {
18 23
...@@ -60,8 +65,7 @@ public class UserOperationControllerTest extends BaseTest { ...@@ -60,8 +65,7 @@ public class UserOperationControllerTest extends BaseTest {
60 try { 65 try {
61 WeixinUnBindBean bindBean = new WeixinUnBindBean(); 66 WeixinUnBindBean bindBean = new WeixinUnBindBean();
62 // 小屏会员 67 // 小屏会员
63 bindBean.setMemberId(4L); 68 bindBean.setMemberId(21821L);
64 bindBean.setAutoModel(true);
65 ResultInfo weixinUserAndMember = this.userOperationController.minaUnbind(bindBean); 69 ResultInfo weixinUserAndMember = this.userOperationController.minaUnbind(bindBean);
66 System.out.println(weixinUserAndMember); 70 System.out.println(weixinUserAndMember);
67 } catch (Exception e) { 71 } catch (Exception e) {
...@@ -151,6 +155,25 @@ public class UserOperationControllerTest extends BaseTest { ...@@ -151,6 +155,25 @@ public class UserOperationControllerTest extends BaseTest {
151 } 155 }
152 156
153 @Test 157 @Test
158 public void appRegister() {
159 try {
160 UserApp userApp = new UserApp();
161 userApp.setUsername("18271269120");
162 // 类型 0:苹果;1:安卓;-1:未知
163 userApp.setType(1);
164
165
166 userApp.setAccount("fdsfsdfsdfs");
167 userApp.setAccountType(3);
168
169 ResultInfo weixinUserAndMember = this.userOperationController.appRegister(userApp);
170 System.out.println(weixinUserAndMember);
171 } catch (Exception e) {
172 e.printStackTrace();
173 }
174 }
175
176 @Test
154 public void createTvUserAndMember() { 177 public void createTvUserAndMember() {
155 try { 178 try {
156 String a = "{\n" + 179 String a = "{\n" +
......
...@@ -2,6 +2,8 @@ package com.topdraw.test.business.process.service; ...@@ -2,6 +2,8 @@ package com.topdraw.test.business.process.service;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.business.module.member.domain.Member; 4 import com.topdraw.business.module.member.domain.Member;
5 import com.topdraw.business.module.member.service.MemberService;
6 import com.topdraw.business.module.member.service.dto.MemberSimpleDTO;
5 import com.topdraw.business.process.service.member.MemberOperationService; 7 import com.topdraw.business.process.service.member.MemberOperationService;
6 import com.topdraw.BaseTest; 8 import com.topdraw.BaseTest;
7 import com.topdraw.util.IdWorker; 9 import com.topdraw.util.IdWorker;
...@@ -16,39 +18,19 @@ public class MemberOperationServiceTest extends BaseTest { ...@@ -16,39 +18,19 @@ public class MemberOperationServiceTest extends BaseTest {
16 @Autowired 18 @Autowired
17 MemberOperationService memberOperationService; 19 MemberOperationService memberOperationService;
18 20
21 @Autowired
22 MemberService memberService;
23
19 @Test 24 @Test
20 public void findById() { 25 public void findMemberSimpleTest(){
21 Long memberId = 2L; 26 MemberSimpleDTO memberSimpleDTO = this.memberService.findSimpleById(20718L);
22 this.memberOperationService.findById(memberId); 27 System.out.println(memberSimpleDTO);
23 } 28 }
24 29
25 @Test 30 @Test
26 public void doUpdateMemberInfo() { 31 public void findById() {
27 Member member = new Member(); 32 Long memberId = 2L;
28 member.setId(2L); 33 this.memberOperationService.findById(memberId);
29 member.setCode(String.valueOf(IdWorker.generator()));
30 member.setType(1);
31 member.setStatus(1);
32 member.setNickname("nickname");
33 member.setDescription("description");
34 member.setGender(1);
35 member.setBirthday("birthday");
36 member.setAvatarUrl("avatarUrl");
37 member.setGroups("groups");
38 member.setTags("tags");
39 member.setVip(1);
40 member.setLevel(1);
41 member.setExp(10L);
42 member.setPoints(5L);
43 member.setDuePoints(0L);
44 member.setCouponAmount(1L);
45 member.setDueCouponAmount(0L);
46 member.setUserIptvId(1L);
47 member.setBindIptvPlatformType(0);
48 member.setUpdateTime(TimestampUtil.now());
49 String s = JSONObject.toJSONString(member);
50
51 this.memberOperationService.doUpdateMember(member);
52 } 34 }
53 35
54 @Test 36 @Test
......
...@@ -19,13 +19,7 @@ public class TaskOperationServiceTest extends BaseTest { ...@@ -19,13 +19,7 @@ public class TaskOperationServiceTest extends BaseTest {
19 DataSyncMsg dataSyncMsg = new DataSyncMsg(); 19 DataSyncMsg dataSyncMsg = new DataSyncMsg();
20 // dataSyncMsg.setEntityType(EntityType.MEMBER); 20 // dataSyncMsg.setEntityType(EntityType.MEMBER);
21 dataSyncMsg.setEvt(EventType.LOGIN.name()); 21 dataSyncMsg.setEvt(EventType.LOGIN.name());
22 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
23 msgData.setEvent(1);
24 msgData.setRemarks("remark");
25 msgData.setMemberId(memberId);
26 msgData.setDeviceType(2);
27 22
28 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
29 // dataSyncMsg.setMsgData(msgData); 23 // dataSyncMsg.setMsgData(msgData);
30 24
31 String s = JSON.toJSONString(dataSyncMsg); 25 String s = JSON.toJSONString(dataSyncMsg);
......
...@@ -22,12 +22,10 @@ public class MqTest extends BaseTest { ...@@ -22,12 +22,10 @@ public class MqTest extends BaseTest {
22 DataSyncMsg dataSyncMsg = new DataSyncMsg(); 22 DataSyncMsg dataSyncMsg = new DataSyncMsg();
23 // dataSyncMsg.setEventType(EventType.LOGIN.name()); 23 // dataSyncMsg.setEventType(EventType.LOGIN.name());
24 dataSyncMsg.setEvt(EventType.LOGIN.name()); 24 dataSyncMsg.setEvt(EventType.LOGIN.name());
25 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); 25 /* DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
26 msgData.setEvent(1);
27 msgData.setRemarks("remark"); 26 msgData.setRemarks("remark");
28 msgData.setMemberId(1L); 27 msgData.setMemberId(1L);
29 msgData.setDeviceType(2); 28 msgData.setAppCode("WEI_XIN_GOLD_PANDA");*/
30 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
31 // dataSyncMsg.setMsgData(msgData); 29 // dataSyncMsg.setMsgData(msgData);
32 String s = JSON.toJSONString(dataSyncMsg); 30 String s = JSON.toJSONString(dataSyncMsg);
33 amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s); 31 amqpTemplate.convertAndSend( "uc.route.key.direct.event.aaa", s);
......