Merge tag '1.0.3' into develop
Tagging version 1.0.4 1.0.3
Showing
41 changed files
with
986 additions
and
301 deletions
document/sql/structure/update.sql
0 → 100644
... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
10 | <entry key="lastExternalPluginCheckTime" value="1636770952724" /> | 10 | <entry key="lastExternalPluginCheckTime" value="1636770952724" /> |
11 | </map> | 11 | </map> |
12 | </option> | 12 | </option> |
13 | <option name="version" value="5" /> | 13 | <option name="version" value="6" /> |
14 | </configuration> | 14 | </configuration> |
15 | </facet> | 15 | </facet> |
16 | </component> | 16 | </component> | ... | ... |
1 | package com.topdraw.module.mq; | 1 | package com.topdraw.module.mq; |
2 | 2 | ||
3 | import javax.annotation.Resource; | ||
4 | |||
3 | // 关注的事件 | 5 | // 关注的事件 |
4 | public enum EventType { | 6 | public enum EventType { |
5 | 7 | ||
... | @@ -22,7 +24,7 @@ public enum EventType { | ... | @@ -22,7 +24,7 @@ public enum EventType { |
22 | // 登录 | 24 | // 登录 |
23 | LOGIN, | 25 | LOGIN, |
24 | // 订购产品包 | 26 | // 订购产品包 |
25 | SUBSCRIBE_PRODUCT_PACKAGE | 27 | SUBSCRIBE_PRODUCT_PACKAGE, |
26 | 28 | // 签到 | |
27 | 29 | SIGN | |
28 | } | 30 | } | ... | ... |
... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
10 | <entry key="lastExternalPluginCheckTime" value="1636770952726" /> | 10 | <entry key="lastExternalPluginCheckTime" value="1636770952726" /> |
11 | </map> | 11 | </map> |
12 | </option> | 12 | </option> |
13 | <option name="version" value="5" /> | 13 | <option name="version" value="6" /> |
14 | </configuration> | 14 | </configuration> |
15 | </facet> | 15 | </facet> |
16 | </component> | 16 | </component> | ... | ... |
... | @@ -125,6 +125,17 @@ | ... | @@ -125,6 +125,17 @@ |
125 | 125 | ||
126 | <build> | 126 | <build> |
127 | <finalName>member-service</finalName> | 127 | <finalName>member-service</finalName> |
128 | <resources> | ||
129 | <resource> | ||
130 | <directory>src/main/java</directory> | ||
131 | <includes> | ||
132 | <include>**/*.xml</include> | ||
133 | </includes> | ||
134 | </resource> | ||
135 | <resource> | ||
136 | <directory>src/main/resources</directory> | ||
137 | </resource> | ||
138 | </resources> | ||
128 | <plugins> | 139 | <plugins> |
129 | <plugin> | 140 | <plugin> |
130 | <groupId>org.springframework.boot</groupId> | 141 | <groupId>org.springframework.boot</groupId> |
... | @@ -143,6 +154,7 @@ | ... | @@ -143,6 +154,7 @@ |
143 | </plugin> | 154 | </plugin> |
144 | <!-- 复制指定配置文件到指定目录 --> | 155 | <!-- 复制指定配置文件到指定目录 --> |
145 | <plugin> | 156 | <plugin> |
157 | <groupId>org.apache.maven.plugins</groupId> | ||
146 | <artifactId>maven-resources-plugin</artifactId> | 158 | <artifactId>maven-resources-plugin</artifactId> |
147 | <executions> | 159 | <executions> |
148 | <execution> | 160 | <execution> | ... | ... |
... | @@ -28,7 +28,7 @@ public class AsyncMqProducer { | ... | @@ -28,7 +28,7 @@ public class AsyncMqProducer { |
28 | @Autowired | 28 | @Autowired |
29 | MessageProducer messageProducer; | 29 | MessageProducer messageProducer; |
30 | 30 | ||
31 | @Resource(name = "executorTask") | 31 | @Autowired |
32 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 32 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
33 | 33 | ||
34 | @Pointcut(value = "@annotation(asyncMqSend)") | 34 | @Pointcut(value = "@annotation(asyncMqSend)") | ... | ... |
1 | package com.topdraw.business.basicdata.member.group.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 2021-11-17 | ||
18 | */ | ||
19 | @Entity | ||
20 | @Data | ||
21 | @EntityListeners(AuditingEntityListener.class) | ||
22 | @Accessors(chain = true) | ||
23 | @Table(name="uc_member_group") | ||
24 | public class MemberGroup implements Serializable { | ||
25 | |||
26 | // ID ID | ||
27 | @Id | ||
28 | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
29 | @Column(name = "id") | ||
30 | private Long id; | ||
31 | |||
32 | // 分组ID | ||
33 | @Column(name = "group_id") | ||
34 | private Long groupId; | ||
35 | |||
36 | // 会员ID | ||
37 | @Column(name = "member_id") | ||
38 | private Long memberId; | ||
39 | |||
40 | // 运营商平台账号 | ||
41 | @Column(name = "platform_account") | ||
42 | private String platformAccount; | ||
43 | |||
44 | // 手机号 | ||
45 | @Column(name = "cellphone") | ||
46 | private String cellphone; | ||
47 | |||
48 | // 设备 | ||
49 | @Column(name = "stb_id") | ||
50 | private String stbId; | ||
51 | |||
52 | // 有线MAC地址 | ||
53 | @Column(name = "eth_mac") | ||
54 | private String ethMac; | ||
55 | |||
56 | // 无线MAC地址 | ||
57 | @Column(name = "wifi_mac") | ||
58 | private String wifiMac; | ||
59 | |||
60 | // 描述 | ||
61 | @Column(name = "description") | ||
62 | private String description; | ||
63 | |||
64 | // 创建者 | ||
65 | @Column(name = "create_by") | ||
66 | private String createBy; | ||
67 | |||
68 | // 创建时间 | ||
69 | @CreatedDate | ||
70 | @Column(name = "create_time") | ||
71 | private Timestamp createTime; | ||
72 | |||
73 | // 更新者 | ||
74 | @Column(name = "update_by") | ||
75 | private String updateBy; | ||
76 | |||
77 | // 更新时间 | ||
78 | @LastModifiedDate | ||
79 | @Column(name = "update_time") | ||
80 | private Timestamp updateTime; | ||
81 | |||
82 | public void copy(MemberGroup source){ | ||
83 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ||
84 | } | ||
85 | } |
1 | package com.topdraw.business.basicdata.member.group.repository; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.group.domain.MemberGroup; | ||
4 | import org.springframework.data.jpa.repository.JpaRepository; | ||
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
6 | |||
7 | import java.util.Optional; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-11-17 | ||
12 | */ | ||
13 | public interface MemberGroupRepository extends JpaRepository<MemberGroup, Long>, JpaSpecificationExecutor<MemberGroup> { | ||
14 | |||
15 | } |
1 | package com.topdraw.business.basicdata.member.group.rest; | ||
2 | |||
3 | import com.topdraw.common.ResultInfo; | ||
4 | import com.topdraw.annotation.Log; | ||
5 | import com.topdraw.business.basicdata.member.group.domain.MemberGroup; | ||
6 | import com.topdraw.business.basicdata.member.group.service.MemberGroupService; | ||
7 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupQueryCriteria; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.data.domain.Pageable; | ||
10 | import org.springframework.http.HttpStatus; | ||
11 | import org.springframework.http.ResponseEntity; | ||
12 | import org.springframework.validation.annotation.Validated; | ||
13 | import org.springframework.web.bind.annotation.*; | ||
14 | import io.swagger.annotations.*; | ||
15 | import java.io.IOException; | ||
16 | import javax.servlet.http.HttpServletResponse; | ||
17 | |||
18 | /** | ||
19 | * @author XiangHan | ||
20 | * @date 2021-11-17 | ||
21 | */ | ||
22 | @Api(tags = "MemberGroup管理") | ||
23 | @RestController | ||
24 | @RequestMapping("/api/MemberGroup") | ||
25 | public class MemberGroupController { | ||
26 | |||
27 | @Autowired | ||
28 | private MemberGroupService MemberGroupService; | ||
29 | |||
30 | @GetMapping | ||
31 | @ApiOperation("查询MemberGroup") | ||
32 | public ResultInfo getMemberGroups(MemberGroupQueryCriteria criteria, Pageable pageable) { | ||
33 | return ResultInfo.successPage(MemberGroupService.queryAll(criteria,pageable)); | ||
34 | } | ||
35 | |||
36 | @GetMapping(value = "/all") | ||
37 | @ApiOperation("查询所有MemberGroup") | ||
38 | public ResultInfo getMemberGroups(MemberGroupQueryCriteria criteria) { | ||
39 | return ResultInfo.success(MemberGroupService.queryAll(criteria)); | ||
40 | } | ||
41 | |||
42 | @Log | ||
43 | @PostMapping | ||
44 | @ApiOperation("新增MemberGroup") | ||
45 | public ResultInfo create(@Validated @RequestBody MemberGroup resources) { | ||
46 | MemberGroupService.create(resources); | ||
47 | return ResultInfo.success(); | ||
48 | } | ||
49 | |||
50 | @Log | ||
51 | @PutMapping | ||
52 | @ApiOperation("修改MemberGroup") | ||
53 | public ResultInfo update(@Validated @RequestBody MemberGroup resources) { | ||
54 | MemberGroupService.update(resources); | ||
55 | return ResultInfo.success(); | ||
56 | } | ||
57 | |||
58 | |||
59 | @Log | ||
60 | @DeleteMapping(value = "/{id}") | ||
61 | @ApiOperation("删除MemberGroup") | ||
62 | public ResultInfo delete(@PathVariable Long id) { | ||
63 | MemberGroupService.delete(id); | ||
64 | return ResultInfo.success(); | ||
65 | } | ||
66 | |||
67 | } |
1 | package com.topdraw.business.basicdata.member.group.service; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.group.domain.MemberGroup; | ||
4 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupDTO; | ||
5 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupQueryCriteria; | ||
6 | import org.springframework.data.domain.Pageable; | ||
7 | import java.util.Map; | ||
8 | import java.util.List; | ||
9 | import java.io.IOException; | ||
10 | import javax.servlet.http.HttpServletResponse; | ||
11 | |||
12 | /** | ||
13 | * @author XiangHan | ||
14 | * @date 2021-11-17 | ||
15 | */ | ||
16 | public interface MemberGroupService { | ||
17 | |||
18 | /** | ||
19 | * 查询数据分页 | ||
20 | * @param criteria 条件参数 | ||
21 | * @param pageable 分页参数 | ||
22 | * @return Map<String,Object> | ||
23 | */ | ||
24 | Map<String,Object> queryAll(MemberGroupQueryCriteria criteria, Pageable pageable); | ||
25 | |||
26 | /** | ||
27 | * 查询所有数据不分页 | ||
28 | * @param criteria 条件参数 | ||
29 | * @return List<MemberGroupDTO> | ||
30 | */ | ||
31 | List<MemberGroupDTO> queryAll(MemberGroupQueryCriteria criteria); | ||
32 | |||
33 | /** | ||
34 | * 根据ID查询 | ||
35 | * @param id ID | ||
36 | * @return MemberGroupDTO | ||
37 | */ | ||
38 | MemberGroupDTO findById(Long id); | ||
39 | |||
40 | void create(MemberGroup resources); | ||
41 | |||
42 | void update(MemberGroup resources); | ||
43 | |||
44 | void delete(Long id); | ||
45 | |||
46 | } |
1 | package com.topdraw.business.basicdata.member.group.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 2021-11-17 | ||
11 | */ | ||
12 | @Data | ||
13 | public class MemberGroupDTO implements Serializable { | ||
14 | |||
15 | // ID ID | ||
16 | private Long id; | ||
17 | |||
18 | // 分组ID | ||
19 | private Long groupId; | ||
20 | |||
21 | // 会员ID | ||
22 | private Long memberId; | ||
23 | |||
24 | // 运营商平台账号 | ||
25 | private String platformAccount; | ||
26 | |||
27 | // 手机号 | ||
28 | private String cellphone; | ||
29 | |||
30 | // 设备 | ||
31 | private String stbId; | ||
32 | |||
33 | // 有线MAC地址 | ||
34 | private String ethMac; | ||
35 | |||
36 | // 无线MAC地址 | ||
37 | private String wifiMac; | ||
38 | |||
39 | // 描述 | ||
40 | private String description; | ||
41 | |||
42 | // 创建者 | ||
43 | private String createBy; | ||
44 | |||
45 | // 创建时间 | ||
46 | private Timestamp createTime; | ||
47 | |||
48 | // 更新者 | ||
49 | private String updateBy; | ||
50 | |||
51 | // 更新时间 | ||
52 | private Timestamp updateTime; | ||
53 | } |
1 | package com.topdraw.business.basicdata.member.group.service.dto; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import com.topdraw.annotation.Query; | ||
5 | |||
6 | /** | ||
7 | * @author XiangHan | ||
8 | * @date 2021-11-17 | ||
9 | */ | ||
10 | @Data | ||
11 | public class MemberGroupQueryCriteria{ | ||
12 | |||
13 | @Query(type = Query.Type.EQUAL) | ||
14 | private Long memberId; | ||
15 | } |
1 | package com.topdraw.business.basicdata.member.group.service.impl; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.group.domain.MemberGroup; | ||
4 | import com.topdraw.utils.ValidationUtil; | ||
5 | import com.topdraw.utils.FileUtil; | ||
6 | import com.topdraw.business.basicdata.member.group.repository.MemberGroupRepository; | ||
7 | import com.topdraw.business.basicdata.member.group.service.MemberGroupService; | ||
8 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupDTO; | ||
9 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupQueryCriteria; | ||
10 | import com.topdraw.business.basicdata.member.group.service.mapper.MemberGroupMapper; | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | ||
12 | import org.springframework.stereotype.Service; | ||
13 | import org.springframework.transaction.annotation.Propagation; | ||
14 | import org.springframework.transaction.annotation.Transactional; | ||
15 | import org.springframework.dao.EmptyResultDataAccessException; | ||
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 | import com.topdraw.utils.StringUtils; | ||
22 | |||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.io.IOException; | ||
26 | import javax.servlet.http.HttpServletResponse; | ||
27 | import java.util.ArrayList; | ||
28 | import java.util.LinkedHashMap; | ||
29 | |||
30 | /** | ||
31 | * @author XiangHan | ||
32 | * @date 2021-11-17 | ||
33 | */ | ||
34 | @Service | ||
35 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | ||
36 | public class MemberGroupServiceImpl implements MemberGroupService { | ||
37 | |||
38 | @Autowired | ||
39 | private MemberGroupRepository MemberGroupRepository; | ||
40 | |||
41 | @Autowired | ||
42 | private MemberGroupMapper MemberGroupMapper; | ||
43 | |||
44 | @Override | ||
45 | public Map<String, Object> queryAll(MemberGroupQueryCriteria criteria, Pageable pageable) { | ||
46 | Page<MemberGroup> page = MemberGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); | ||
47 | return PageUtil.toPage(page.map(MemberGroupMapper::toDto)); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public List<MemberGroupDTO> queryAll(MemberGroupQueryCriteria criteria) { | ||
52 | return MemberGroupMapper.toDto(MemberGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public MemberGroupDTO findById(Long id) { | ||
57 | MemberGroup MemberGroup = MemberGroupRepository.findById(id).orElseGet(MemberGroup::new); | ||
58 | ValidationUtil.isNull(MemberGroup.getId(),"MemberGroup","id",id); | ||
59 | return MemberGroupMapper.toDto(MemberGroup); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | @Transactional(rollbackFor = Exception.class) | ||
64 | public void create(MemberGroup resources) { | ||
65 | MemberGroupRepository.save(resources); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | @Transactional(rollbackFor = Exception.class) | ||
70 | public void update(MemberGroup resources) { | ||
71 | MemberGroup MemberGroup = MemberGroupRepository.findById(resources.getId()).orElseGet(MemberGroup::new); | ||
72 | ValidationUtil.isNull( MemberGroup.getId(),"MemberGroup","id",resources.getId()); | ||
73 | MemberGroup.copy(resources); | ||
74 | MemberGroupRepository.save(MemberGroup); | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | @Transactional(rollbackFor = Exception.class) | ||
79 | public void delete(Long id) { | ||
80 | Assert.notNull(id, "The given id must not be null!"); | ||
81 | MemberGroup MemberGroup = MemberGroupRepository.findById(id).orElseThrow( | ||
82 | () -> new EmptyResultDataAccessException(String.format("No %s entity " + "with id %s " + "exists!", MemberGroup.class, id), 1)); | ||
83 | MemberGroupRepository.delete(MemberGroup); | ||
84 | } | ||
85 | |||
86 | |||
87 | } |
1 | package com.topdraw.business.basicdata.member.group.service.mapper; | ||
2 | |||
3 | import com.topdraw.base.BaseMapper; | ||
4 | import com.topdraw.business.basicdata.member.group.domain.MemberGroup; | ||
5 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupDTO; | ||
6 | import org.mapstruct.Mapper; | ||
7 | import org.mapstruct.ReportingPolicy; | ||
8 | |||
9 | /** | ||
10 | * @author XiangHan | ||
11 | * @date 2021-11-17 | ||
12 | */ | ||
13 | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
14 | public interface MemberGroupMapper extends BaseMapper<MemberGroupDTO, MemberGroup> { | ||
15 | |||
16 | } |
... | @@ -90,7 +90,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { | ... | @@ -90,7 +90,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { |
90 | : new MemberLevelDTO(); | 90 | : new MemberLevelDTO(); |
91 | } | 91 | } |
92 | 92 | ||
93 | @Cacheable(cacheNames = "uc-member_level",key = "#level") | ||
94 | @Override | 93 | @Override |
95 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { | 94 | public List<MemberLevelDTO> findLevelAndStatus(Integer level, Integer status) { |
96 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | 95 | return MemberLevelMapper.toDto(MemberLevelRepository.findByLevelAndStatus(level,status)); | ... | ... |
... | @@ -75,7 +75,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -75,7 +75,7 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
75 | * @param memberId | 75 | * @param memberId |
76 | * @return | 76 | * @return |
77 | */ | 77 | */ |
78 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time >= now()" | 78 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1 and upa.expire_time > now()" |
79 | ,nativeQuery = true) | 79 | ,nativeQuery = true) |
80 | Long findAvailablePointsByMemberId(long memberId); | 80 | Long findAvailablePointsByMemberId(long memberId); |
81 | 81 | ||
... | @@ -87,4 +87,10 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable | ... | @@ -87,4 +87,10 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable |
87 | void deleteBatchByIds(List<Long> id); | 87 | void deleteBatchByIds(List<Long> id); |
88 | 88 | ||
89 | List<PointsAvailable> findByExpireTimeBefore(Timestamp now); | 89 | List<PointsAvailable> findByExpireTimeBefore(Timestamp now); |
90 | |||
91 | @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1" | ||
92 | ,nativeQuery = true) | ||
93 | long findTotalCountByMemberId(Long memberId); | ||
94 | |||
95 | List<PointsAvailable> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp); | ||
90 | } | 96 | } | ... | ... |
... | @@ -80,6 +80,8 @@ public interface PointsAvailableService { | ... | @@ -80,6 +80,8 @@ public interface PointsAvailableService { |
80 | */ | 80 | */ |
81 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp); | 81 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp); |
82 | 82 | ||
83 | List<PointsAvailableDTO> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp); | ||
84 | |||
83 | /** | 85 | /** |
84 | * 即将过期的积分 | 86 | * 即将过期的积分 |
85 | * @param memberId 会员id | 87 | * @param memberId 会员id |
... | @@ -136,4 +138,6 @@ public interface PointsAvailableService { | ... | @@ -136,4 +138,6 @@ public interface PointsAvailableService { |
136 | 138 | ||
137 | 139 | ||
138 | List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now); | 140 | List<PointsAvailableDTO> findByExpireTimeBefore(Timestamp now); |
141 | |||
142 | long findTotalPointsByMemberId(Long memberId); | ||
139 | } | 143 | } | ... | ... |
... | @@ -127,6 +127,13 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -127,6 +127,13 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
127 | } | 127 | } |
128 | 128 | ||
129 | @Override | 129 | @Override |
130 | public List<PointsAvailableDTO> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp) { | ||
131 | return Objects.nonNull(memberId)? | ||
132 | PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeAfter(memberId, timestamp)) | ||
133 | :null; | ||
134 | } | ||
135 | |||
136 | @Override | ||
130 | public Long findSoonExpireTime(Long memberId, Integer factor) { | 137 | public Long findSoonExpireTime(Long memberId, Integer factor) { |
131 | return PointsAvailableRepository.findSoonExpireTime(memberId, factor); | 138 | return PointsAvailableRepository.findSoonExpireTime(memberId, factor); |
132 | } | 139 | } |
... | @@ -163,4 +170,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { | ... | @@ -163,4 +170,9 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { |
163 | return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now)); | 170 | return PointsAvailableMapper.toDto(this.PointsAvailableRepository.findByExpireTimeBefore(now)); |
164 | } | 171 | } |
165 | 172 | ||
173 | @Override | ||
174 | public long findTotalPointsByMemberId(Long memberId) { | ||
175 | return this.PointsAvailableRepository.findTotalCountByMemberId(memberId); | ||
176 | } | ||
177 | |||
166 | } | 178 | } | ... | ... |
... | @@ -20,7 +20,7 @@ import io.swagger.annotations.*; | ... | @@ -20,7 +20,7 @@ import io.swagger.annotations.*; |
20 | //@RequestMapping("/api/Points") | 20 | //@RequestMapping("/api/Points") |
21 | public class PointsController { | 21 | public class PointsController { |
22 | 22 | ||
23 | /* @Autowired | 23 | /*@Autowired |
24 | private PointsService PointsService; | 24 | private PointsService PointsService; |
25 | 25 | ||
26 | @GetMapping | 26 | @GetMapping |
... | @@ -33,9 +33,9 @@ public class PointsController { | ... | @@ -33,9 +33,9 @@ public class PointsController { |
33 | @ApiOperation("查询所有Points") | 33 | @ApiOperation("查询所有Points") |
34 | public ResultInfo getPointss(PointsQueryCriteria criteria) { | 34 | public ResultInfo getPointss(PointsQueryCriteria criteria) { |
35 | return ResultInfo.success(PointsService.queryAll(criteria)); | 35 | return ResultInfo.success(PointsService.queryAll(criteria)); |
36 | } | 36 | }*/ |
37 | 37 | ||
38 | @Log | 38 | /*@Log |
39 | @PostMapping | 39 | @PostMapping |
40 | @ApiOperation("新增Points") | 40 | @ApiOperation("新增Points") |
41 | public ResultInfo create(@Validated @RequestBody Points resources) { | 41 | public ResultInfo create(@Validated @RequestBody Points resources) { | ... | ... |
... | @@ -80,7 +80,7 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -80,7 +80,7 @@ public class TaskServiceImpl implements TaskService { |
80 | TaskRepository.delete(Task); | 80 | TaskRepository.delete(Task); |
81 | } | 81 | } |
82 | 82 | ||
83 | @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") | 83 | // @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") |
84 | @Override | 84 | @Override |
85 | public List<Task> findByTemplateId(Long taskTemplateId) { | 85 | public List<Task> findByTemplateId(Long taskTemplateId) { |
86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | 86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | ... | ... |
... | @@ -93,10 +93,9 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { | ... | @@ -93,10 +93,9 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { |
93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; | 93 | return StringUtils.isNotEmpty(event) ? this.TaskTemplateRepository.findByEvent(event) : null; |
94 | } | 94 | } |
95 | 95 | ||
96 | @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event") | 96 | // @Cacheable(cacheNames = "uc-admin_taskTemplate" , key = "#event") |
97 | @Override | 97 | @Override |
98 | public TaskTemplate findByType(Integer event) { | 98 | public TaskTemplate findByType(Integer event) { |
99 | System.out.println("查询数据库了!!"); | ||
100 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; | 99 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; |
101 | } | 100 | } |
102 | } | 101 | } | ... | ... |
... | @@ -17,9 +17,13 @@ import org.slf4j.LoggerFactory; | ... | @@ -17,9 +17,13 @@ import org.slf4j.LoggerFactory; |
17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
18 | import org.springframework.data.domain.Pageable; | 18 | import org.springframework.data.domain.Pageable; |
19 | import org.springframework.util.Assert; | 19 | import org.springframework.util.Assert; |
20 | import org.springframework.util.CollectionUtils; | ||
20 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
21 | import org.springframework.web.bind.annotation.*; | 22 | import org.springframework.web.bind.annotation.*; |
22 | 23 | ||
24 | import java.util.List; | ||
25 | import java.util.Objects; | ||
26 | |||
23 | /** | 27 | /** |
24 | * @author XiangHan | 28 | * @author XiangHan |
25 | * @date 2021-10-22 | 29 | * @date 2021-10-22 |
... | @@ -32,11 +36,11 @@ public class PointsOperationController { | ... | @@ -32,11 +36,11 @@ public class PointsOperationController { |
32 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class); | 36 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationController.class); |
33 | 37 | ||
34 | @Autowired | 38 | @Autowired |
35 | private PointsOperationService pointsOperationService; | 39 | PointsOperationService pointsOperationService; |
36 | @Autowired | 40 | @Autowired |
37 | private PointsDetailService pointsDetailService; | 41 | PointsDetailService pointsDetailService; |
38 | @Autowired | 42 | @Autowired |
39 | private PointsAvailableService pointsAvailableService; | 43 | PointsAvailableService pointsAvailableService; |
40 | 44 | ||
41 | @GetMapping(value = "/pagePointsDetails") | 45 | @GetMapping(value = "/pagePointsDetails") |
42 | @ApiOperation("查询PointsDetail") | 46 | @ApiOperation("查询PointsDetail") |
... | @@ -56,10 +60,29 @@ public class PointsOperationController { | ... | @@ -56,10 +60,29 @@ public class PointsOperationController { |
56 | } | 60 | } |
57 | 61 | ||
58 | @Log | 62 | @Log |
63 | @GetMapping(value = "/cleanInvalidPointsAndCalculateCurrentPoints/{id}") | ||
64 | @ApiOperation("清除过期积分并计算总积分,供客户端会员查询积分时调用") | ||
65 | public ResultInfo cleanInvalidPointsAndCalculateCurrentPoints(@PathVariable("id") Long id) { | ||
66 | Long aLong = this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(id); | ||
67 | return ResultInfo.success(Objects.isNull(aLong) ? 0L : aLong); | ||
68 | } | ||
69 | |||
70 | /*@Log | ||
71 | @PostMapping(value = "/cleanInvalidPointsAndCalculateCurrentPointsByMemberIds") | ||
72 | @ApiOperation("清除过期积分并计算总积分,管理端使用") | ||
73 | public ResultInfo cleanInvalidPointsAndCalculateCurrentPointsByMemberIds(List<Long> memberIds) { | ||
74 | if (!CollectionUtils.isEmpty(memberIds)) { | ||
75 | for (Long memberId : memberIds) { | ||
76 | this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId); | ||
77 | } | ||
78 | } | ||
79 | return ResultInfo.success(); | ||
80 | }*/ | ||
81 | |||
82 | @Log | ||
59 | @PostMapping(value = "/grantPointsByManual") | 83 | @PostMapping(value = "/grantPointsByManual") |
60 | @ApiOperation("新增PointsDetail") | 84 | @ApiOperation("新增PointsDetail") |
61 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { | 85 | public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { |
62 | LOG.info("======>>>>> grantPointsByManual start"); | ||
63 | Long memberId = tempPoints.getMemberId(); | 86 | Long memberId = tempPoints.getMemberId(); |
64 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); | 87 | this.pointsOperationService.grantPointsByManual(memberId,tempPoints); |
65 | return ResultInfo.success(); | 88 | return ResultInfo.success(); | ... | ... |
... | @@ -35,13 +35,11 @@ public interface PointsOperationService { | ... | @@ -35,13 +35,11 @@ public interface PointsOperationService { |
35 | */ | 35 | */ |
36 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); | 36 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); |
37 | 37 | ||
38 | /** | ||
39 | * 清理过期的积分 | ||
40 | */ | ||
41 | void cleanInvalidAvailablePoints(); | ||
42 | 38 | ||
43 | /** | 39 | /** |
44 | * 清理过期的积分 | 40 | * 清理过期并计算可用总积分 |
41 | * @param memberId | ||
42 | * @return | ||
45 | */ | 43 | */ |
46 | void cleanInvalidAvailablePointsByMemberId(Long memberId); | 44 | Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); |
47 | } | 45 | } | ... | ... |
... | @@ -45,14 +45,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -45,14 +45,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
45 | RightsOperationService rightsOperationService; | 45 | RightsOperationService rightsOperationService; |
46 | @Autowired | 46 | @Autowired |
47 | RedissonClient redissonClient; | 47 | RedissonClient redissonClient; |
48 | @Resource(name = "executorTask") | 48 | @Autowired |
49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
50 | 50 | ||
51 | // 过期阀值(默认一个月) | 51 | // 过期阀值(默认一个月) |
52 | private static final Integer EXPIRE_FACTOR_DAY = 30; | 52 | private static final Integer EXPIRE_FACTOR_DAY = 30; |
53 | 53 | ||
54 | |||
55 | |||
56 | @Override | 54 | @Override |
57 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { | 55 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { |
58 | // 优惠券领取、使用历史记录表 | 56 | // 优惠券领取、使用历史记录表 |
... | @@ -99,9 +97,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -99,9 +97,9 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
99 | // Long userId = tempCoupon.getUserId(); | 97 | // Long userId = tempCoupon.getUserId(); |
100 | Long memberId = tempCoupon.getMemberId(); | 98 | Long memberId = tempCoupon.getMemberId(); |
101 | Integer rightsAmount = tempCoupon.getRightsAmount(); | 99 | Integer rightsAmount = tempCoupon.getRightsAmount(); |
102 | // RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); | 100 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); |
103 | try { | 101 | try { |
104 | // RedissonUtil.lock(rLock); | 102 | RedissonUtil.lock(rLock); |
105 | // 1.历史总优惠券数量 | 103 | // 1.历史总优惠券数量 |
106 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); | 104 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); |
107 | // 1.当前总优惠券数量 | 105 | // 1.当前总优惠券数量 |
... | @@ -118,7 +116,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -118,7 +116,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
118 | e.printStackTrace(); | 116 | e.printStackTrace(); |
119 | throw e; | 117 | throw e; |
120 | } finally { | 118 | } finally { |
121 | // RedissonUtil.unlock(rLock); | 119 | RedissonUtil.unlock(rLock); |
122 | } | 120 | } |
123 | } | 121 | } |
124 | 122 | ||
... | @@ -160,7 +158,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -160,7 +158,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
160 | * @return | 158 | * @return |
161 | */ | 159 | */ |
162 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | 160 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { |
163 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp1(LocalDateTime.now().plusDays(expireFactor)); | 161 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp(LocalDateTime.now().plusDays(expireFactor)); |
164 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); | 162 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); |
165 | } | 163 | } |
166 | 164 | ... | ... |
... | @@ -43,7 +43,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -43,7 +43,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
43 | MemberLevelService memberLevelService; | 43 | MemberLevelService memberLevelService; |
44 | @Autowired | 44 | @Autowired |
45 | RedissonClient redissonClient; | 45 | RedissonClient redissonClient; |
46 | @Resource(name = "executorTask") | 46 | @Autowired |
47 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 47 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
48 | 48 | ||
49 | @Override | 49 | @Override |
... | @@ -83,10 +83,12 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -83,10 +83,12 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
83 | // 总积分 | 83 | // 总积分 |
84 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); |
85 | // 1.添加成长值记录 | 85 | // 1.添加成长值记录 |
86 | this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | 86 | // this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); |
87 | // this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
88 | // 2.更新成长值与等级 | 87 | // 2.更新成长值与等级 |
89 | this.refreshMemberExpAndLevel(tempExp,totalExp); | 88 | this.refreshMemberExpAndLevel(tempExp,totalExp); |
89 | |||
90 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
91 | |||
90 | } catch (Exception e) { | 92 | } catch (Exception e) { |
91 | e.printStackTrace(); | 93 | e.printStackTrace(); |
92 | throw e; | 94 | throw e; |
... | @@ -116,10 +118,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -116,10 +118,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
116 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { | 118 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { |
117 | 119 | ||
118 | Long memberId = tempExp.getMemberId(); | 120 | Long memberId = tempExp.getMemberId(); |
119 | |||
120 | // RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); | ||
121 | try { | ||
122 | // RedissonUtil.lock(rLock); | ||
123 | // 1.获取当前成长值 | 121 | // 1.获取当前成长值 |
124 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | 122 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); |
125 | // 2.获取下一级需要的成长值 | 123 | // 2.获取下一级需要的成长值 |
... | @@ -128,12 +126,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -128,12 +126,6 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
128 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); | 126 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); |
129 | // 5.更新用户信息 | 127 | // 5.更新用户信息 |
130 | this.updateMemberInfo(level, totalExp, memberId); | 128 | this.updateMemberInfo(level, totalExp, memberId); |
131 | } catch (Exception e) { | ||
132 | e.printStackTrace(); | ||
133 | throw e; | ||
134 | } finally { | ||
135 | // RedissonUtil.unlock(rLock); | ||
136 | } | ||
137 | } | 129 | } |
138 | 130 | ||
139 | /** | 131 | /** | ... | ... |
... | @@ -16,6 +16,7 @@ import com.topdraw.util.IdWorker; | ... | @@ -16,6 +16,7 @@ import com.topdraw.util.IdWorker; |
16 | import com.topdraw.util.RedissonUtil; | 16 | import com.topdraw.util.RedissonUtil; |
17 | import com.topdraw.util.TimestampUtil; | 17 | import com.topdraw.util.TimestampUtil; |
18 | import com.topdraw.utils.StringUtils; | 18 | import com.topdraw.utils.StringUtils; |
19 | import lombok.extern.slf4j.Slf4j; | ||
19 | import org.redisson.api.RLock; | 20 | import org.redisson.api.RLock; |
20 | import org.redisson.api.RedissonClient; | 21 | import org.redisson.api.RedissonClient; |
21 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
... | @@ -39,6 +40,7 @@ import java.util.stream.Collectors; | ... | @@ -39,6 +40,7 @@ import java.util.stream.Collectors; |
39 | */ | 40 | */ |
40 | @Service | 41 | @Service |
41 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 42 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
43 | @Slf4j | ||
42 | public class PointsOperationServiceImpl implements PointsOperationService { | 44 | public class PointsOperationServiceImpl implements PointsOperationService { |
43 | 45 | ||
44 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); | 46 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); |
... | @@ -62,12 +64,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -62,12 +64,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
62 | 64 | ||
63 | @Autowired | 65 | @Autowired |
64 | RedissonClient redissonClient; | 66 | RedissonClient redissonClient; |
65 | @Resource(name = "executorTask") | 67 | @Autowired |
66 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 68 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
67 | 69 | ||
68 | @Override | 70 | @Override |
69 | @Transactional(rollbackFor = Exception.class) | 71 | @Transactional(rollbackFor = Exception.class) |
70 | public void grantPointsByManual(Long memberId,TempPoints tempPoints){ | 72 | public void grantPointsByManual(Long memberId,TempPoints tempPoints){ |
73 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) | ||
71 | this.refresh(tempPoints); | 74 | this.refresh(tempPoints); |
72 | } | 75 | } |
73 | 76 | ||
... | @@ -99,8 +102,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -99,8 +102,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
99 | this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); | 102 | this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); |
100 | // 4.更新可用积分表,超过的删除,剩余的新增 | 103 | // 4.更新可用积分表,超过的删除,剩余的新增 |
101 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); | 104 | long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); |
105 | // 5.即将过期的积分 | ||
106 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
102 | // 6.更新会员积分信息 | 107 | // 6.更新会员积分信息 |
103 | this.freshMemberCurrentPoints(memberId, totalPoints); | 108 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints); |
104 | 109 | ||
105 | return true; | 110 | return true; |
106 | } | 111 | } |
... | @@ -167,7 +172,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -167,7 +172,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
167 | BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); | 172 | BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); |
168 | BeanUtils.copyProperties(tempPoints,tempPoints1); | 173 | BeanUtils.copyProperties(tempPoints,tempPoints1); |
169 | tempPoints1.setPoints(-(Math.abs(points))); | 174 | tempPoints1.setPoints(-(Math.abs(points))); |
170 | long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints); | 175 | Long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints); |
171 | this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints); | 176 | this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints); |
172 | } | 177 | } |
173 | } | 178 | } |
... | @@ -265,58 +270,95 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -265,58 +270,95 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
265 | @Override | 270 | @Override |
266 | @Transactional(rollbackFor = Exception.class) | 271 | @Transactional(rollbackFor = Exception.class) |
267 | public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){ | 272 | public void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList){ |
273 | log.info("------->>grantPointsThroughTempRightsList start1"); | ||
268 | for (TempPoints tempPoints : tempPointsList){ | 274 | for (TempPoints tempPoints : tempPointsList){ |
275 | log.info("------->>grantPointsThroughTempRightsList start"); | ||
269 | this.refresh(tempPoints); | 276 | this.refresh(tempPoints); |
270 | } | 277 | } |
271 | } | 278 | } |
272 | 279 | ||
273 | /** | 280 | /** |
274 | * 定时清理过期的可用积分 | 281 | * 清理过期积分 |
282 | * @param memberId | ||
275 | */ | 283 | */ |
276 | @Override | 284 | private void cleanInvalidAvailablePointsByMemberId(Long memberId) { |
277 | public void cleanInvalidAvailablePoints() { | 285 | List<PointsAvailableDTO> pointsAvailableDTOS = |
278 | // 获取已过期的积分 | 286 | pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,TimestampUtil.now()); |
279 | List<PointsAvailableDTO> pointsAvailableDTOS = pointsAvailableService.findByExpireTimeBefore(TimestampUtil.now()); | ||
280 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | 287 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { |
288 | //1.获取原始积分 | ||
289 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | ||
281 | // 添加积分明细 uc_points_detail | 290 | // 添加积分明细 uc_points_detail |
282 | this.doCreatePointsDetail(pointsAvailableDTOS); | 291 | this.doCreatePointsDetail(pointsAvailableDTO); |
283 | // 删除已过期的积分 | 292 | // 删除已过期的积分 |
284 | this.doDeleteInvalidAvailablePoints(pointsAvailableDTOS); | 293 | this.doDeleteInvalidAvailablePoints(pointsAvailableDTO); |
294 | } | ||
295 | |||
285 | } | 296 | } |
286 | } | 297 | } |
287 | 298 | ||
288 | @Override | 299 | @Override |
289 | public void cleanInvalidAvailablePointsByMemberId(Long memberId) { | 300 | public Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId) { |
290 | List<PointsAvailableDTO> pointsAvailableDTOS = pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,TimestampUtil.now()); | 301 | |
291 | if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { | 302 | // 清理当前用户的过期积分 |
292 | // 添加积分明细 uc_points_detail | 303 | this.cleanInvalidAvailablePointsByMemberId(memberId); |
293 | this.doCreatePointsDetail(pointsAvailableDTOS); | 304 | // 获取当前用户的可用总积分 |
294 | // 删除已过期的积分 | 305 | long currentPoints = this.findAvailablePointsByMemberId(memberId); |
295 | this.doDeleteInvalidAvailablePoints(pointsAvailableDTOS); | 306 | // 即将过期的积分 |
307 | long soonExpirePoints = this.getSoonExpirePoints(memberId, null); | ||
308 | // 更新会员信息 | ||
309 | this.doUpdateMemberPoints(memberId,currentPoints,soonExpirePoints); | ||
310 | |||
311 | return currentPoints; | ||
296 | } | 312 | } |
313 | |||
314 | /** | ||
315 | * 获取可用总积分 | ||
316 | * @param memberId | ||
317 | * @return | ||
318 | */ | ||
319 | private long findAvailablePointsByMemberId(Long memberId){ | ||
320 | return this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * 修改会员信息 | ||
325 | * @param memberId | ||
326 | * @param currentPoints | ||
327 | */ | ||
328 | private void doUpdateMemberPoints(Long memberId, long currentPoints,long soonExpirePoints) { | ||
329 | Member member = new Member(); | ||
330 | member.setId(memberId); | ||
331 | member.setPoints(currentPoints); | ||
332 | member.setDuePoints(soonExpirePoints); | ||
333 | this.memberOperationService.doUpdateMemberPoints(member); | ||
297 | } | 334 | } |
298 | 335 | ||
299 | /** | 336 | /** |
300 | * | 337 | * |
301 | * @param pointsAvailableDTOS | 338 | * @param pointsAvailableDTOS |
302 | */ | 339 | */ |
303 | private void doDeleteInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) { | 340 | private void doDeleteBatchInvalidAvailablePoints(List<PointsAvailableDTO> pointsAvailableDTOS) { |
304 | List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList()); | 341 | List<Long> collect = pointsAvailableDTOS.stream().map(pointsAvailableDTO -> pointsAvailableDTO.getId()).collect(Collectors.toList()); |
305 | this.pointsAvailableService.deleteBatchByIds(collect); | 342 | this.pointsAvailableService.deleteBatchByIds(collect); |
306 | } | 343 | } |
307 | 344 | ||
308 | /** | 345 | /** |
309 | * | 346 | * |
310 | * @param pointsAvailableDTOS | 347 | * @param pointsAvailableDTO |
311 | */ | 348 | */ |
312 | private void doCreatePointsDetail(List<PointsAvailableDTO> pointsAvailableDTOS) { | 349 | private void doDeleteInvalidAvailablePoints(PointsAvailableDTO pointsAvailableDTO) { |
350 | this.pointsAvailableService.delete(pointsAvailableDTO.getId()); | ||
351 | } | ||
313 | 352 | ||
314 | //1.获取原始积分 | 353 | /** |
315 | for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { | 354 | * 可用积分 |
355 | * @param pointsAvailableDTO | ||
356 | */ | ||
357 | private void doCreatePointsDetail(PointsAvailableDTO pointsAvailableDTO) { | ||
316 | 358 | ||
317 | Long memberId = pointsAvailableDTO.getMemberId(); | 359 | Long memberId = pointsAvailableDTO.getMemberId(); |
318 | // 原始积分 | 360 | // 原始积分 |
319 | long availablePoints = this.findAvailablePointsByMemberId(memberId); | 361 | long availablePoints = this.pointsAvailableService.findTotalPointsByMemberId(memberId);//this.findAvailablePointsByMemberId(memberId); |
320 | // 过期积分 | 362 | // 过期积分 |
321 | long l = pointsAvailableDTO.getPoints(); | 363 | long l = pointsAvailableDTO.getPoints(); |
322 | // 结果积分 | 364 | // 结果积分 |
... | @@ -324,17 +366,16 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -324,17 +366,16 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
324 | 366 | ||
325 | PointsDetail pointsDetail = new PointsDetail(); | 367 | PointsDetail pointsDetail = new PointsDetail(); |
326 | BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail); | 368 | BeanUtils.copyProperties(pointsAvailableDTO,pointsDetail); |
369 | pointsDetail.setId(null); | ||
370 | pointsDetail.setPoints(-Math.abs(l)); | ||
327 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 371 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); |
328 | pointsDetail.setOriginalPoints(availablePoints); | 372 | pointsDetail.setOriginalPoints(availablePoints); |
329 | pointsDetail.setResultPoints(resultPoints); | 373 | pointsDetail.setResultPoints(resultPoints); |
330 | pointsDetail.setDescription("过期积分"); | 374 | pointsDetail.setDescription("过期积分"); |
331 | pointsDetail.setEvtType(99); | 375 | pointsDetail.setEvtType(99); |
376 | pointsDetail.setCreateTime(TimestampUtil.now()); | ||
377 | pointsDetail.setUpdateTime(TimestampUtil.now()); | ||
332 | this.doInsertPointsDetail(pointsDetail); | 378 | this.doInsertPointsDetail(pointsDetail); |
333 | |||
334 | // 更新会员积分 | ||
335 | this.freshMemberCurrentPoints(memberId,resultPoints); | ||
336 | } | ||
337 | |||
338 | } | 379 | } |
339 | 380 | ||
340 | /** | 381 | /** |
... | @@ -344,23 +385,37 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -344,23 +385,37 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
344 | */ | 385 | */ |
345 | private void refresh(TempPoints tempPoints) { | 386 | private void refresh(TempPoints tempPoints) { |
346 | Long memberId = tempPoints.getMemberId(); | 387 | Long memberId = tempPoints.getMemberId(); |
388 | log.info("----------->> points refresh start"); | ||
347 | RLock rLock = this.redissonClient.getLock("uc-refresh-points:" + memberId.toString()); | 389 | RLock rLock = this.redissonClient.getLock("uc-refresh-points:" + memberId.toString()); |
390 | log.info("----------->> rLock --->> start" ); | ||
348 | try { | 391 | try { |
349 | RedissonUtil.lock(rLock); | 392 | RedissonUtil.lock(rLock); |
393 | log.info("----------->> refresh findAvailablePointsByMemberId start"); | ||
350 | // 1.可用总积分 | 394 | // 1.可用总积分 |
351 | long currentPoints = this.findAvailablePointsByMemberId(memberId); | 395 | Long currentPoints = this.findAvailablePointsByMemberId(memberId); |
396 | log.info("----------->> refresh findAvailablePointsByMemberId currentPoints " + currentPoints); | ||
397 | |||
352 | // 2.计算总积分 | 398 | // 2.计算总积分 |
353 | long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); | 399 | Long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints); |
400 | log.info("----------->> refresh findAvailablePointsByMemberId totalPoints " + totalPoints); | ||
354 | 401 | ||
355 | // 3.添加积分明细,并计算总积分 | 402 | // 3.添加积分明细,并计算总积分 |
356 | this.threadPoolTaskExecutor.execute(()->this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints)); | 403 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail start "); |
357 | // this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints); | 404 | this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); |
405 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail end "); | ||
358 | 406 | ||
359 | // 4.添加可用积分 | 407 | // 4.添加可用积分 |
408 | log.info("----------->> refresh doInsertTrPointsAvailable start "); | ||
360 | this.doInsertTrPointsAvailable(tempPoints); | 409 | this.doInsertTrPointsAvailable(tempPoints); |
410 | log.info("----------->> refresh doInsertTrPointsAvailable end "); | ||
411 | |||
412 | // 即将过期的积分 | ||
413 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
361 | 414 | ||
362 | // 6.更新会员的总积分 | 415 | // 6.更新会员的总积分 |
363 | this.freshMemberCurrentPoints(memberId, totalPoints); | 416 | log.info("----------->> refresh freshMemberCurrentPoints start "); |
417 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints); | ||
418 | log.info("----------->> refresh freshMemberCurrentPoints end "); | ||
364 | 419 | ||
365 | } catch (Exception e) { | 420 | } catch (Exception e) { |
366 | e.printStackTrace(); | 421 | e.printStackTrace(); |
... | @@ -376,11 +431,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -376,11 +431,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
376 | * @param currentPoints | 431 | * @param currentPoints |
377 | * @return | 432 | * @return |
378 | */ | 433 | */ |
379 | private long calculateTotalPoints(TempPoints tempPoints, long currentPoints) { | 434 | private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) { |
380 | // 获取的积分 | 435 | // 获取的积分 |
381 | long rewardPoints = tempPoints.getPoints(); | 436 | Long rewardPoints = tempPoints.getPoints(); |
382 | // 总积分 | 437 | // 总积分 |
383 | long totalPoints = currentPoints + rewardPoints; | 438 | Long totalPoints = currentPoints + rewardPoints; |
384 | return totalPoints; | 439 | return totalPoints; |
385 | } | 440 | } |
386 | 441 | ||
... | @@ -415,11 +470,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -415,11 +470,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
415 | * @param memberId 会员Id | 470 | * @param memberId 会员Id |
416 | * @param currentPoints 当前总积分 | 471 | * @param currentPoints 当前总积分 |
417 | */ | 472 | */ |
418 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints) { | 473 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints) { |
419 | Member member = new Member(); | 474 | Member member = new Member(); |
420 | member.setId(memberId); | 475 | member.setId(memberId); |
421 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); | 476 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); |
422 | // member.setDuePoints(duePoints); | 477 | member.setDuePoints(duePoints); |
423 | member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); | 478 | member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); |
424 | try { | 479 | try { |
425 | this.memberOperationService.doUpdateMemberPoints(member); | 480 | this.memberOperationService.doUpdateMemberPoints(member); |
... | @@ -433,9 +488,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -433,9 +488,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
433 | * @param memberId 会员id | 488 | * @param memberId 会员id |
434 | * @return | 489 | * @return |
435 | */ | 490 | */ |
436 | private long findAvailablePointsByMemberId(long memberId){ | 491 | private Long findAvailablePointsByMemberId(long memberId){ |
437 | long availablePointsByMemberId = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | 492 | Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); |
438 | return availablePointsByMemberId; | 493 | return Objects.nonNull(availablePoints) ? availablePoints : 0L; |
439 | } | 494 | } |
440 | 495 | ||
441 | /** | 496 | /** |
... | @@ -473,15 +528,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -473,15 +528,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
473 | * @param tempPoints 积分 | 528 | * @param tempPoints 积分 |
474 | * @return Integer 总积分 | 529 | * @return Integer 总积分 |
475 | */ | 530 | */ |
476 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long currentPoints,long totalPoints){ | 531 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){ |
477 | 532 | ||
478 | PointsDetail pointsDetail = new PointsDetail(); | 533 | PointsDetail pointsDetail = new PointsDetail(); |
479 | BeanUtils.copyProperties(tempPoints,pointsDetail); | 534 | BeanUtils.copyProperties(tempPoints,pointsDetail); |
535 | pointsDetail.setId(null); | ||
480 | pointsDetail.setMemberId(memberId); | 536 | pointsDetail.setMemberId(memberId); |
481 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 537 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); |
482 | pointsDetail.setPoints(tempPoints.getPoints()); | 538 | pointsDetail.setPoints(tempPoints.getPoints()); |
483 | pointsDetail.setOriginalPoints(currentPoints); | 539 | pointsDetail.setOriginalPoints(currentPoints); |
484 | pointsDetail.setResultPoints(totalPoints); | 540 | pointsDetail.setResultPoints(totalPoints); |
541 | pointsDetail.setCreateTime(null); | ||
542 | pointsDetail.setUpdateTime(null); | ||
485 | String description = pointsDetail.getDescription(); | 543 | String description = pointsDetail.getDescription(); |
486 | if (StringUtils.isEmpty(description)) { | 544 | if (StringUtils.isEmpty(description)) { |
487 | pointsDetail.setDescription("#"); | 545 | pointsDetail.setDescription("#"); | ... | ... |
1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
2 | 2 | ||
3 | import com.topdraw.business.basicdata.coupon.service.CouponService; | ||
4 | import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO; | ||
3 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; | 5 | import com.topdraw.business.basicdata.rights.history.domain.RightsHistory; |
4 | import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService; | 6 | import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService; |
5 | import com.topdraw.business.basicdata.rights.service.RightsService; | 7 | import com.topdraw.business.basicdata.rights.service.RightsService; |
... | @@ -19,10 +21,8 @@ import org.springframework.stereotype.Service; | ... | @@ -19,10 +21,8 @@ import org.springframework.stereotype.Service; |
19 | import org.springframework.util.CollectionUtils; | 21 | import org.springframework.util.CollectionUtils; |
20 | import org.springframework.util.StringUtils; | 22 | import org.springframework.util.StringUtils; |
21 | 23 | ||
22 | import javax.annotation.Resource; | ||
23 | import java.sql.Timestamp; | ||
24 | import java.util.*; | 24 | import java.util.*; |
25 | import java.util.concurrent.Future; | 25 | import java.util.concurrent.*; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * 权益处理 | 28 | * 权益处理 |
... | @@ -46,9 +46,13 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -46,9 +46,13 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
46 | ExpOperationService expOperationService; | 46 | ExpOperationService expOperationService; |
47 | @Autowired | 47 | @Autowired |
48 | PointsOperationService pointsOperationService; | 48 | PointsOperationService pointsOperationService; |
49 | @Autowired | ||
50 | CouponService couponService; | ||
51 | |||
52 | // @Autowired | ||
53 | // ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
49 | 54 | ||
50 | @Resource(name = "executorTask") | 55 | private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10); |
51 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
52 | 56 | ||
53 | /** | 57 | /** |
54 | * 系统手动发放 | 58 | * 系统手动发放 |
... | @@ -73,16 +77,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -73,16 +77,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
73 | @Override | 77 | @Override |
74 | public void grantRights(Map<RightType, Object> tempRightsMap) { | 78 | public void grantRights(Map<RightType, Object> tempRightsMap) { |
75 | 79 | ||
76 | this.threadPoolTaskExecutor.execute(()-> { | 80 | // this.threadPoolTaskExecutor.execute(()-> { |
77 | // 2.创建权益历史对象 | 81 | // 2.创建权益历史对象 |
78 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | 82 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); |
79 | // 3.保存权益历史 | 83 | // 3.保存权益历史 |
80 | this.doInsertTrRightHistory(rightsList); | 84 | this.doInsertTrRightHistory(rightsList); |
81 | }); | 85 | // }); |
82 | 86 | ||
83 | // 1.权益下发 | 87 | // 1.权益下发 |
84 | this.refresh(tempRightsMap); | 88 | this.refresh(tempRightsMap); |
85 | |||
86 | } | 89 | } |
87 | 90 | ||
88 | /** | 91 | /** |
... | @@ -106,7 +109,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -106,7 +109,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
106 | return rightsHistoryList; | 109 | return rightsHistoryList; |
107 | } | 110 | } |
108 | 111 | ||
109 | |||
110 | /** | 112 | /** |
111 | * 成长值发放,基于已获得的权益 | 113 | * 成长值发放,基于已获得的权益 |
112 | * @param tempExpList 权益列表 | 114 | * @param tempExpList 权益列表 |
... | @@ -116,18 +118,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -116,18 +118,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
116 | this.expOperationService.grantPointsThroughTempExp(tempExpList); | 118 | this.expOperationService.grantPointsThroughTempExp(tempExpList); |
117 | } | 119 | } |
118 | 120 | ||
119 | |||
120 | /** | 121 | /** |
121 | * 发放积分,基于已获得的权益 | 122 | * 发放积分,基于已获得的权益 |
122 | * | 123 | * |
123 | * @param tempPointsList 权益列表 | 124 | * @param tempPointsList 权益列表 |
124 | */ | 125 | */ |
125 | private void grantPoint(List<TempPoints> tempPointsList) { | 126 | private void grantPoint(List<TempPoints> tempPointsList) { |
127 | log.info(Thread.currentThread().getName() + "=========>>grantPoint start"); | ||
126 | if (!CollectionUtils.isEmpty(tempPointsList)) | 128 | if (!CollectionUtils.isEmpty(tempPointsList)) |
129 | log.info("=======>> tempPointsList ======>> " + tempPointsList.toString()); | ||
127 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); | 130 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); |
128 | } | 131 | } |
129 | 132 | ||
130 | |||
131 | /** | 133 | /** |
132 | * 发放优惠券,基于已获得的权益 | 134 | * 发放优惠券,基于已获得的权益 |
133 | * | 135 | * |
... | @@ -139,21 +141,78 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -139,21 +141,78 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
139 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); | 141 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); |
140 | } | 142 | } |
141 | 143 | ||
142 | |||
143 | /** | 144 | /** |
144 | * 权益发放 | 145 | * 权益发放 |
145 | * @param tempRightsMap | 146 | * @param tempRightsMap |
146 | */ | 147 | */ |
147 | private void refresh(Map<RightType, Object> tempRightsMap) { | 148 | private void refresh(Map<RightType, Object> tempRightsMap) { |
148 | 149 | /*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{ | |
149 | this.threadPoolTaskExecutor.submit(() -> { | 150 | log.info(Thread.currentThread().getName() + "=========>> start"); |
150 | // 积分 | 151 | // 积分 |
151 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | 152 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); |
153 | log.info(Thread.currentThread().getName() + "=========>>grantPoint end"); | ||
154 | // 成长值 | ||
155 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
156 | // 优惠券 | ||
157 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
158 | return null; | ||
159 | }); | ||
160 | FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{ | ||
161 | // 积分 | ||
162 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
152 | // 成长值 | 163 | // 成长值 |
153 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | 164 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); |
154 | // 优惠券 | 165 | // 优惠券 |
166 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
167 | return null; | ||
168 | }); | ||
169 | FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{ | ||
170 | // 积分 | ||
171 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
172 | // 成长值 | ||
173 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
174 | // 优惠券 | ||
155 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | 175 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); |
176 | return null; | ||
156 | }); | 177 | }); |
178 | this.threadPoolTaskExecutor.execute(futureTask1); | ||
179 | this.threadPoolTaskExecutor.execute(futureTask2); | ||
180 | this.threadPoolTaskExecutor.execute(futureTask3);*/ | ||
181 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
182 | // 积分 | ||
183 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
184 | // 成长值 | ||
185 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
186 | // 优惠券 | ||
187 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
188 | });*/ | ||
189 | |||
190 | |||
191 | /*this.threadPoolTaskExecutor.execute(() -> { | ||
192 | log.info(Thread.currentThread().getName() + "=========>> start"); | ||
193 | // 积分 | ||
194 | this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
195 | log.info(Thread.currentThread().getName() + "=========>> end"); | ||
196 | });*/ | ||
197 | |||
198 | List<TempPoints> tempPointsList = (List<TempPoints>) tempRightsMap.get(RightType.POINTS); | ||
199 | if (!CollectionUtils.isEmpty(tempPointsList)) { | ||
200 | // 积分 | ||
201 | this.grantPoint(tempPointsList); | ||
202 | } | ||
203 | |||
204 | List<TempExp> tempExpList = (List<TempExp>) tempRightsMap.get(RightType.EXP); | ||
205 | if (!CollectionUtils.isEmpty(tempExpList)) { | ||
206 | // 成长值 | ||
207 | this.grantExp(tempExpList); | ||
208 | } | ||
209 | |||
210 | List<TempCoupon> tempCouponList = (List<TempCoupon>) tempRightsMap.get(RightType.COUPON); | ||
211 | if (!CollectionUtils.isEmpty(tempCouponList)) { | ||
212 | // 优惠券 | ||
213 | this.grantCoupon(tempCouponList); | ||
214 | } | ||
215 | |||
157 | } | 216 | } |
158 | 217 | ||
159 | /** | 218 | /** |
... | @@ -167,8 +226,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -167,8 +226,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
167 | 226 | ||
168 | // 优惠券 | 227 | // 优惠券 |
169 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 228 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
170 | List<TempExp> tempExpList = new ArrayList<>(); | ||
171 | List<TempPoints> tempPointsList = new ArrayList<>(); | ||
172 | 229 | ||
173 | for (RightsHistory right : rightsList) { | 230 | for (RightsHistory right : rightsList) { |
174 | Long rightId = right.getRightsId(); | 231 | Long rightId = right.getRightsId(); |
... | @@ -178,62 +235,55 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -178,62 +235,55 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
178 | RightsDTO rightsDTO = this.getRights(rightId); | 235 | RightsDTO rightsDTO = this.getRights(rightId); |
179 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 236 | // 权益的实体类型 1:积分;2成长值;3优惠券 |
180 | String type = rightsDTO.getEntityType(); | 237 | String type = rightsDTO.getEntityType(); |
181 | String code = rightsDTO.getCode(); | ||
182 | Long expireTime = rightsDTO.getExpireTime(); | 238 | Long expireTime = rightsDTO.getExpireTime(); |
183 | Timestamp validTime = rightsDTO.getValidTime(); | ||
184 | |||
185 | 239 | ||
186 | switch (type) { | 240 | switch (type) { |
187 | // 优惠券 | 241 | // 优惠券 |
188 | case "3": | 242 | case "1": |
243 | Long entityId = rightsDTO.getEntityId(); | ||
244 | CouponDTO couponDTO = this.findCouponById(entityId); | ||
245 | if (Objects.nonNull(couponDTO)) { | ||
189 | TempCoupon tempCoupon = new TempCoupon(); | 246 | TempCoupon tempCoupon = new TempCoupon(); |
190 | tempCoupon.setId(rightId); | 247 | tempCoupon.setId(couponDTO.getId()); |
191 | tempCoupon.setMemberId(memberId); | 248 | tempCoupon.setMemberId(memberId); |
192 | tempCoupon.setUserId(userId); | 249 | tempCoupon.setUserId(userId); |
193 | tempCoupon.setRightsAmount(1); | 250 | tempCoupon.setRightsAmount(1); |
194 | tempCoupon.setRightsSendStrategy(0); | 251 | tempCoupon.setRightsSendStrategy(0); |
252 | tempCoupon.setCode(couponDTO.getCode()); | ||
253 | if (Objects.nonNull(expireTime)) | ||
195 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); | 254 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); |
196 | tempCouponList.add(tempCoupon); | 255 | tempCouponList.add(tempCoupon); |
256 | } | ||
197 | break; | 257 | break; |
198 | // 成长值 | 258 | // 观影券 |
199 | case "2": | 259 | case "2": |
200 | TempExp tempExp = new TempExp(); | ||
201 | tempExp.setId(rightId); | ||
202 | tempExp.setMemberId(memberId); | ||
203 | tempExp.setUserId(userId); | ||
204 | tempExp.setRightsAmount(1); | ||
205 | tempExp.setRightsSendStrategy(0); | ||
206 | tempExpList.add(tempExp); | ||
207 | break; | 260 | break; |
208 | // 积分 | 261 | // 活动参与机会 |
209 | case "1": | 262 | case "3": |
210 | TempPoints tempPoints = new TempPoints(); | 263 | break; |
211 | tempPoints.setId(rightId); | 264 | |
212 | tempPoints.setMemberId(memberId); | 265 | default: |
213 | tempPoints.setUserId(userId); | ||
214 | tempPoints.setRightsAmount(1); | ||
215 | tempPoints.setRightsSendStrategy(0); | ||
216 | tempPointsList.add(tempPoints); | ||
217 | break; | 266 | break; |
218 | } | 267 | } |
219 | } | 268 | } |
220 | 269 | ||
221 | // TODO 其他 | ||
222 | |||
223 | // 优惠券 | 270 | // 优惠券 |
224 | if (!CollectionUtils.isEmpty(tempCouponList)) | 271 | if (!CollectionUtils.isEmpty(tempCouponList)) |
225 | map.put(RightType.COUPON,tempCouponList); | 272 | map.put(RightType.COUPON,tempCouponList); |
226 | // 成长值 | ||
227 | if (!CollectionUtils.isEmpty(tempExpList)) | ||
228 | map.put(RightType.EXP,tempExpList); | ||
229 | // 积分 | ||
230 | if (!CollectionUtils.isEmpty(tempPointsList)) | ||
231 | map.put(RightType.POINTS,tempPointsList); | ||
232 | |||
233 | return map; | 273 | return map; |
234 | } | 274 | } |
235 | 275 | ||
236 | /** | 276 | /** |
277 | * 获取优惠券信息 | ||
278 | * @param id | ||
279 | * @return | ||
280 | */ | ||
281 | private CouponDTO findCouponById(Long id) { | ||
282 | CouponDTO couponDTO = this.couponService.findById(id); | ||
283 | return couponDTO; | ||
284 | } | ||
285 | |||
286 | /** | ||
237 | * 权益详情 | 287 | * 权益详情 |
238 | * @param rightsId | 288 | * @param rightsId |
239 | * @return | 289 | * @return | ... | ... |
1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.topdraw.business.basicdata.coupon.service.CouponService; | ||
5 | import com.topdraw.business.basicdata.coupon.service.dto.CouponDTO; | ||
6 | import com.topdraw.business.basicdata.member.group.service.MemberGroupService; | ||
7 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupDTO; | ||
8 | import com.topdraw.business.basicdata.member.group.service.dto.MemberGroupQueryCriteria; | ||
4 | import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService; | 9 | import com.topdraw.business.basicdata.rights.permanentrights.service.PermanentRightsService; |
5 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; | 10 | import com.topdraw.business.basicdata.rights.permanentrights.service.dto.PermanentRightsDTO; |
6 | import com.topdraw.business.basicdata.rights.service.RightsService; | 11 | import com.topdraw.business.basicdata.rights.service.RightsService; |
... | @@ -18,7 +23,6 @@ import com.topdraw.business.basicdata.task.service.TaskService; | ... | @@ -18,7 +23,6 @@ import com.topdraw.business.basicdata.task.service.TaskService; |
18 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; | 23 | import com.topdraw.business.basicdata.task.template.domain.TaskTemplate; |
19 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; | 24 | import com.topdraw.business.basicdata.task.template.service.TaskTemplateService; |
20 | import com.topdraw.business.process.domian.*; | 25 | import com.topdraw.business.process.domian.*; |
21 | import com.topdraw.exception.BadRequestException; | ||
22 | import com.topdraw.module.mq.DataSyncMsg; | 26 | import com.topdraw.module.mq.DataSyncMsg; |
23 | import com.topdraw.util.*; | 27 | import com.topdraw.util.*; |
24 | import lombok.extern.slf4j.Slf4j; | 28 | import lombok.extern.slf4j.Slf4j; |
... | @@ -35,8 +39,8 @@ import java.math.RoundingMode; | ... | @@ -35,8 +39,8 @@ import java.math.RoundingMode; |
35 | import java.sql.Timestamp; | 39 | import java.sql.Timestamp; |
36 | import java.time.LocalDate; | 40 | import java.time.LocalDate; |
37 | import java.util.*; | 41 | import java.util.*; |
38 | import java.util.concurrent.locks.ReentrantReadWriteLock; | 42 | |
39 | import java.util.stream.Collectors; | 43 | import static java.util.stream.Collectors.toList; |
40 | 44 | ||
41 | /** | 45 | /** |
42 | * 任务处理 | 46 | * 任务处理 |
... | @@ -64,6 +68,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -64,6 +68,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
64 | TrTaskProgressService trTaskProgressService; | 68 | TrTaskProgressService trTaskProgressService; |
65 | @Autowired | 69 | @Autowired |
66 | PermanentRightsService permanentRightsService; | 70 | PermanentRightsService permanentRightsService; |
71 | @Autowired | ||
72 | CouponService couponService; | ||
73 | @Autowired | ||
74 | MemberGroupService memberGroupService; | ||
67 | 75 | ||
68 | private static final Integer TASK_FINISH_STATUS = 1; | 76 | private static final Integer TASK_FINISH_STATUS = 1; |
69 | private static final Integer TASK_UNFINISH_STATUS = 2; | 77 | private static final Integer TASK_UNFINISH_STATUS = 2; |
... | @@ -79,11 +87,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -79,11 +87,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
79 | Long memberId = msgData.getMemberId(); | 87 | Long memberId = msgData.getMemberId(); |
80 | 88 | ||
81 | long l = System.currentTimeMillis(); | 89 | long l = System.currentTimeMillis(); |
82 | // 验证会员信息 | ||
83 | /*boolean b = this.validatedMember(memberId); | ||
84 | if (!b) { | ||
85 | throw new BadRequestException("【member status exception!!】"); | ||
86 | }*/ | ||
87 | 90 | ||
88 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 | 91 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 |
89 | TaskTemplate taskTemplate = this.getTaskTemplate(event); | 92 | TaskTemplate taskTemplate = this.getTaskTemplate(event); |
... | @@ -92,10 +95,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -92,10 +95,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
92 | // 4.判断当前用户是否满足任务完成条件 | 95 | // 4.判断当前用户是否满足任务完成条件 |
93 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); | 96 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); |
94 | if (checkResult) { | 97 | if (checkResult) { |
98 | |||
95 | // 5.权益区分(积分、权益、成长值) | 99 | // 5.权益区分(积分、权益、成长值) |
96 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 100 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); |
97 | // 6.权益发放 | 101 | // 6.权益发放 |
98 | this.grantRight(tempRightsMap); | 102 | this.grantRight(tempRightsMap); |
103 | |||
99 | } | 104 | } |
100 | 105 | ||
101 | long r = System.currentTimeMillis(); | 106 | long r = System.currentTimeMillis(); |
... | @@ -333,9 +338,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -333,9 +338,10 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
333 | * @param rightsSendStrategy | 338 | * @param rightsSendStrategy |
334 | * @return | 339 | * @return |
335 | */ | 340 | */ |
336 | private TempCoupon tempCouponBuild(Long memberId ,Integer rightsAmount,Integer rightsSendStrategy,TempRights tempRights,String nickname){ | 341 | private TempCoupon tempCouponBuild(Long memberId ,Integer rightsAmount,Integer rightsSendStrategy,CouponDTO couponDTO,String nickname){ |
337 | TempCoupon tempCoupon = new TempCoupon(); | 342 | TempCoupon tempCoupon = new TempCoupon(); |
338 | BeanUtils.copyProperties(tempRights,tempCoupon); | 343 | BeanUtils.copyProperties(couponDTO,tempCoupon); |
344 | tempCoupon.setCode(couponDTO.getCode()); | ||
339 | tempCoupon.setMemberId(memberId); | 345 | tempCoupon.setMemberId(memberId); |
340 | tempCoupon.setRightsAmount(rightsAmount); | 346 | tempCoupon.setRightsAmount(rightsAmount); |
341 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); | 347 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); |
... | @@ -429,9 +435,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -429,9 +435,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
429 | String type = rightsDTO.getEntityType(); | 435 | String type = rightsDTO.getEntityType(); |
430 | switch (type) { | 436 | switch (type) { |
431 | case "1": | 437 | case "1": |
438 | Long entityId = rightsDTO.getEntityId(); | ||
439 | if (Objects.nonNull(entityId)) { | ||
440 | CouponDTO couponDTO = this.findCouponById(entityId); | ||
441 | if (Objects.nonNull(couponDTO)) { | ||
432 | // 优惠券 | 442 | // 优惠券 |
433 | TempCoupon tempCoupon = this.tempCouponBuild(memberId,rightsAmount,rightsSendStrategy,tempRights,nickname); | 443 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, rightsAmount, rightsSendStrategy, couponDTO, nickname); |
434 | tempCouponList.add(tempCoupon); | 444 | tempCouponList.add(tempCoupon); |
445 | } | ||
446 | } | ||
435 | break; | 447 | break; |
436 | default: | 448 | default: |
437 | break; | 449 | break; |
... | @@ -440,6 +452,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -440,6 +452,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
440 | } | 452 | } |
441 | 453 | ||
442 | /** | 454 | /** |
455 | * 获取优惠券信息 | ||
456 | * @param id | ||
457 | * @return | ||
458 | */ | ||
459 | private CouponDTO findCouponById(Long id) { | ||
460 | CouponDTO couponDTO = this.couponService.findById(id); | ||
461 | return couponDTO; | ||
462 | } | ||
463 | |||
464 | /** | ||
443 | * | 465 | * |
444 | * @param rightsId | 466 | * @param rightsId |
445 | * @return | 467 | * @return |
... | @@ -525,7 +547,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -525,7 +547,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
525 | * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次 | 547 | * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次 |
526 | * 5. member_level 会员等级门槛(0表示无门槛) | 548 | * 5. member_level 会员等级门槛(0表示无门槛) |
527 | * 6. member_vip 会员vip门槛(0表示没有门槛) | 549 | * 6. member_vip 会员vip门槛(0表示没有门槛) |
528 | * 7. groups 能够获取该任务的用户分组,为空则都能获取 | 550 | * 7. groups 能够获取该任务的用户分组,为空则都能获取 , 0 |
529 | * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发) | 551 | * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发) |
530 | * | 552 | * |
531 | * @param taskList 任务列表 | 553 | * @param taskList 任务列表 |
... | @@ -536,24 +558,33 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -536,24 +558,33 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
536 | if (!CollectionUtils.isEmpty(taskList)) { | 558 | if (!CollectionUtils.isEmpty(taskList)) { |
537 | // 会员信息 | 559 | // 会员信息 |
538 | MemberDTO memberDTO = this.memberService.findById(memberId); | 560 | MemberDTO memberDTO = this.memberService.findById(memberId); |
561 | |||
539 | // 判断是否完成任务 | 562 | // 判断是否完成任务 |
540 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { | 563 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { |
541 | 564 | ||
542 | List<Task> taskStream = taskList1.stream().filter(task1 -> | 565 | List<Task> taskStream = taskList1.stream().filter(task1 -> |
543 | task1.getStatus() == 1 && | 566 | task1.getStatus() == 1 && |
544 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && | 567 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && |
545 | (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && | ||
546 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && | 568 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && |
547 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) && | 569 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) && |
548 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() <= memberDTO1.getVip()) | 570 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip()) |
549 | ).collect(Collectors.toList()); | 571 | ).collect(toList()); |
550 | 572 | ||
573 | // 没有满足条件的数据 | ||
551 | if (CollectionUtils.isEmpty(taskStream)) { | 574 | if (CollectionUtils.isEmpty(taskStream)) { |
575 | return false; | ||
576 | } else { | ||
577 | |||
578 | // 验证会员分组 | ||
579 | boolean result1 = this.validatedMemberGroup(memberId,taskList); | ||
580 | if (!result1) | ||
581 | return false; | ||
582 | |||
552 | // 获取当前任务的完成情况 | 583 | // 获取当前任务的完成情况 |
553 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); | 584 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); |
554 | return result; | 585 | return result; |
555 | } | 586 | } |
556 | return true; | 587 | |
557 | }; | 588 | }; |
558 | return compareTaskCondition.compareCondition(memberDTO,taskList); | 589 | return compareTaskCondition.compareCondition(memberDTO,taskList); |
559 | } | 590 | } |
... | @@ -562,6 +593,96 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -562,6 +593,96 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
562 | } | 593 | } |
563 | 594 | ||
564 | /** | 595 | /** |
596 | * 验证会员分组 | ||
597 | * @param memberId | ||
598 | * @param taskList | ||
599 | * @return | ||
600 | */ | ||
601 | private boolean validatedMemberGroup(Long memberId,List<Task> taskList) { | ||
602 | List<MemberGroupDTO> groupDTO = this.findGroupByMemberId(memberId); | ||
603 | |||
604 | if (!CollectionUtils.isEmpty(groupDTO)) { | ||
605 | |||
606 | // 会员分组 | ||
607 | List<String> list = new ArrayList<>(); | ||
608 | for (MemberGroupDTO memberGroupDTO : groupDTO) { | ||
609 | String groupId = memberGroupDTO.getGroupId().toString(); | ||
610 | list.add(groupId); | ||
611 | } | ||
612 | |||
613 | // 任务分组 | ||
614 | List<String> strings = new ArrayList<>(); | ||
615 | for (Task task : taskList) { | ||
616 | String groups = task.getGroups(); | ||
617 | List<String> strings1 = UcStringUtils.parse2StrList(groups); | ||
618 | if (StringUtils.isEmpty(groups)) { | ||
619 | return true; | ||
620 | } | ||
621 | strings.addAll(strings1); | ||
622 | break; | ||
623 | } | ||
624 | |||
625 | // 如果任务分组为null或者空字符,则放过所有的会员 | ||
626 | if (CollectionUtils.isEmpty(strings)) { | ||
627 | return true; | ||
628 | } | ||
629 | |||
630 | // 如果任务分组为0,则放过所有的分组 | ||
631 | if (!CollectionUtils.isEmpty(strings) && (!CollectionUtils.isEmpty(list) && strings.contains("0")) ) { | ||
632 | return true; | ||
633 | } | ||
634 | |||
635 | if (!CollectionUtils.isEmpty(list)) { | ||
636 | // 只要会员分组满足任务分组之一就满足要求 | ||
637 | if (list.size() > strings.size()) { | ||
638 | for (String s : list) { | ||
639 | boolean contains = strings.contains(s); | ||
640 | if (contains) { | ||
641 | return true; | ||
642 | } | ||
643 | } | ||
644 | } | ||
645 | } | ||
646 | |||
647 | if (!CollectionUtils.isEmpty(strings)) { | ||
648 | for (String s : strings) { | ||
649 | boolean contains = list.contains(s); | ||
650 | if (contains) { | ||
651 | return true; | ||
652 | } | ||
653 | } | ||
654 | } | ||
655 | |||
656 | |||
657 | } | ||
658 | return false; | ||
659 | } | ||
660 | |||
661 | |||
662 | /** | ||
663 | * | ||
664 | * @param memberId | ||
665 | * @return | ||
666 | */ | ||
667 | private List<MemberGroupDTO> findGroupByMemberId(Long memberId) { | ||
668 | MemberGroupQueryCriteria memberGroupQueryCriteria = new MemberGroupQueryCriteria(); | ||
669 | memberGroupQueryCriteria.setMemberId(memberId); | ||
670 | return this.memberGroupService.queryAll(memberGroupQueryCriteria); | ||
671 | } | ||
672 | |||
673 | /** | ||
674 | * 通过会员id获取分组 | ||
675 | * @param memberId | ||
676 | * @return | ||
677 | */ | ||
678 | /*private List<GroupDTO> findGroupByMemberId(Long memberId) { | ||
679 | GroupQueryCriteria groupQueryCriteria = new GroupQueryCriteria(); | ||
680 | groupQueryCriteria.setUserId(memberId); | ||
681 | List<GroupDTO> groupDTO = this.groupService.queryAll(groupQueryCriteria); | ||
682 | return groupDTO; | ||
683 | }*/ | ||
684 | |||
685 | /** | ||
565 | * 检查并更新当前任务的完成情况 | 686 | * 检查并更新当前任务的完成情况 |
566 | * | 687 | * |
567 | * 1.每天都能做,但要求总次数达到行为量 | 688 | * 1.每天都能做,但要求总次数达到行为量 |
... | @@ -614,7 +735,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -614,7 +735,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
614 | Objects.nonNull(completionTime1) && | 735 | Objects.nonNull(completionTime1) && |
615 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | 736 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { |
616 | 737 | ||
617 | throw new BadRequestException("任务已完成,请明日再来"); | 738 | return false; |
618 | 739 | ||
619 | // 未做,成功 | 740 | // 未做,成功 |
620 | } else { | 741 | } else { | ... | ... |
... | @@ -22,11 +22,10 @@ public class RedissonConfig { | ... | @@ -22,11 +22,10 @@ public class RedissonConfig { |
22 | private String password; | 22 | private String password; |
23 | 23 | ||
24 | @Bean | 24 | @Bean |
25 | public RedissonClient redisson(){ | 25 | public Redisson redisson(){ |
26 | Config config = new Config(); | 26 | Config config = new Config(); |
27 | // config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword("redis123"); | ||
28 | if (StringUtils.isNotEmpty(password)) { | 27 | if (StringUtils.isNotEmpty(password)) { |
29 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password);; | 28 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port).setPassword(password); |
30 | } else { | 29 | } else { |
31 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port); | 30 | config.useSingleServer().setAddress("redis://"+redisHost+":"+port); |
32 | } | 31 | } |
... | @@ -34,7 +33,8 @@ public class RedissonConfig { | ... | @@ -34,7 +33,8 @@ public class RedissonConfig { |
34 | "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377", | 33 | "redis://172.29.3.245:6375","redis://172.29.3.245:6376", "redis://172.29.3.245:6377", |
35 | "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380") | 34 | "redis://172.29.3.245:6378","redis://172.29.3.245:6i379", "redis://172.29.3.245:6380") |
36 | .setPassword("a123456").setScanInterval(5000);*/ | 35 | .setPassword("a123456").setScanInterval(5000);*/ |
37 | return Redisson.create(config); | 36 | Redisson redissonClient = (Redisson)Redisson.create(config); |
37 | return redissonClient; | ||
38 | } | 38 | } |
39 | 39 | ||
40 | } | 40 | } | ... | ... |
... | @@ -11,13 +11,12 @@ import org.springframework.stereotype.Component; | ... | @@ -11,13 +11,12 @@ import org.springframework.stereotype.Component; |
11 | 11 | ||
12 | import java.util.concurrent.ThreadPoolExecutor; | 12 | import java.util.concurrent.ThreadPoolExecutor; |
13 | 13 | ||
14 | @Configuration | 14 | /*@Configuration |
15 | @PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8") | 15 | @PropertySource(value = {"classpath:executor.properties"}, ignoreResourceNotFound=false, encoding="UTF-8") |
16 | @Slf4j | 16 | @Slf4j*/ |
17 | @EnableAsync | ||
18 | public class ThreadPoolTaskExecutorConfig { | 17 | public class ThreadPoolTaskExecutorConfig { |
19 | 18 | ||
20 | @Value("${threadPoolExecutor.core_pool_size}") | 19 | /*@Value("${threadPoolExecutor.core_pool_size}") |
21 | private int corePoolSize; | 20 | private int corePoolSize; |
22 | @Value("${threadPoolExecutor.max_pool_size}") | 21 | @Value("${threadPoolExecutor.max_pool_size}") |
23 | private int maxPoolSize; | 22 | private int maxPoolSize; |
... | @@ -28,7 +27,7 @@ public class ThreadPoolTaskExecutorConfig { | ... | @@ -28,7 +27,7 @@ public class ThreadPoolTaskExecutorConfig { |
28 | @Value("${threadPoolExecutor.keep_alive_seconds}") | 27 | @Value("${threadPoolExecutor.keep_alive_seconds}") |
29 | private int keepAliveSeconds; | 28 | private int keepAliveSeconds; |
30 | 29 | ||
31 | @Bean(value = "executorTask") | 30 | @Bean |
32 | public ThreadPoolTaskExecutor executorTask(){ | 31 | public ThreadPoolTaskExecutor executorTask(){ |
33 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | 32 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
34 | // 核心线程数 | 33 | // 核心线程数 |
... | @@ -46,6 +45,6 @@ public class ThreadPoolTaskExecutorConfig { | ... | @@ -46,6 +45,6 @@ public class ThreadPoolTaskExecutorConfig { |
46 | // 线程初始化 | 45 | // 线程初始化 |
47 | executor.initialize(); | 46 | executor.initialize(); |
48 | return executor; | 47 | return executor; |
49 | } | 48 | }*/ |
50 | 49 | ||
51 | } | 50 | } | ... | ... |
... | @@ -31,12 +31,12 @@ public class RabbitMqConfig { | ... | @@ -31,12 +31,12 @@ public class RabbitMqConfig { |
31 | } | 31 | } |
32 | 32 | ||
33 | @Bean | 33 | @Bean |
34 | Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv){ | 34 | Binding fanoutExchangeBindingIptv(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueIptv) { |
35 | return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange); | 35 | return BindingBuilder.bind(ucFanoutQueueIptv).to(ucFanoutExchange); |
36 | } | 36 | } |
37 | 37 | ||
38 | @Bean | 38 | @Bean |
39 | Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin){ | 39 | Binding fanoutExchangeBindingWeiXin(FanoutExchange ucFanoutExchange , Queue ucFanoutQueueWeiXin) { |
40 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); | 40 | return BindingBuilder.bind(ucFanoutQueueWeiXin).to(ucFanoutExchange); |
41 | } | 41 | } |
42 | 42 | ... | ... |
... | @@ -3,6 +3,7 @@ package com.topdraw.util; | ... | @@ -3,6 +3,7 @@ package com.topdraw.util; |
3 | import java.sql.Timestamp; | 3 | import java.sql.Timestamp; |
4 | import java.time.Instant; | 4 | import java.time.Instant; |
5 | import java.time.LocalDateTime; | 5 | import java.time.LocalDateTime; |
6 | import java.time.ZoneId; | ||
6 | import java.time.ZoneOffset; | 7 | import java.time.ZoneOffset; |
7 | 8 | ||
8 | public class TimestampUtil { | 9 | public class TimestampUtil { |
... | @@ -12,33 +13,46 @@ public class TimestampUtil { | ... | @@ -12,33 +13,46 @@ public class TimestampUtil { |
12 | } | 13 | } |
13 | 14 | ||
14 | public static Timestamp now(LocalDateTime localDateTime) { | 15 | public static Timestamp now(LocalDateTime localDateTime) { |
15 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).getEpochSecond(); | 16 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
16 | return new Timestamp(epochSecond); | 17 | return new Timestamp(epochSecond); |
17 | } | 18 | } |
18 | 19 | ||
19 | public static long localDateTime2Timestamp(LocalDateTime localDateTime){ | 20 | public static long localDateTime2long(LocalDateTime localDateTime){ |
20 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | 21 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
21 | return epochSecond; | 22 | return epochSecond; |
22 | } | 23 | } |
23 | 24 | ||
24 | public static Timestamp localDateTime2Timestamp1(LocalDateTime localDateTime){ | 25 | public static Timestamp localDateTime2Timestamp(LocalDateTime localDateTime){ |
25 | long epochSecond = localDateTime.atZone(ZoneOffset.systemDefault()).toEpochSecond(); | 26 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
26 | return long2Timestamp(epochSecond); | 27 | return long2Timestamp(epochSecond); |
27 | } | 28 | } |
28 | public static Timestamp long2Timestamp(long timestamp){ | 29 | public static Timestamp long2Timestamp(long timestamp){ |
29 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); | 30 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochMilli(timestamp)); |
30 | return timestamp1; | 31 | return timestamp1; |
31 | } | 32 | } |
32 | 33 | ||
33 | public static long Timestamp2long(Timestamp timestamp){ | 34 | public static long timestamp2long(Timestamp timestamp){ |
34 | return timestamp.toInstant().getEpochSecond(); | 35 | long l = timestamp.toInstant().toEpochMilli(); |
36 | return l; | ||
35 | } | 37 | } |
36 | 38 | ||
37 | public static void main(String[] args) { | 39 | public static void main(String[] args) { |
38 | LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00); | 40 | long a = 1636616464000L; |
39 | long l = localDateTime2Timestamp(of); | 41 | long b = 1637046948588L; |
42 | long c = 1637047122176L; | ||
40 | // long l = 16342727230L; | 43 | // long l = 16342727230L; |
41 | Timestamp timestamp = long2Timestamp(l); | 44 | // Timestamp now = now(LocalDateTime.now()); |
42 | System.out.println(timestamp.toString()); | 45 | long l = localDateTime2long(LocalDateTime.now()); |
46 | System.out.println(l); | ||
47 | // System.out.println(now.toString()); | ||
48 | |||
49 | Timestamp timestamp1 = long2Timestamp(a); | ||
50 | // long l = localDateTime2Timestamp(of); | ||
51 | // long l = 16342727230L; | ||
52 | // Timestamp timestamp = long2Timestamp(l); | ||
53 | System.out.println(timestamp1.toString()); | ||
54 | |||
55 | long l1 = localDateTime2long(LocalDateTime.now()); | ||
56 | System.out.println(l1); | ||
43 | } | 57 | } |
44 | } | 58 | } | ... | ... |
1 | package com.topdraw.util; | ||
2 | |||
3 | import java.util.Arrays; | ||
4 | import java.util.List; | ||
5 | import java.util.stream.Collectors; | ||
6 | |||
7 | public class UcStringUtils { | ||
8 | |||
9 | |||
10 | public static List<String> parse2StrList(String resouce){ | ||
11 | String[] split = resouce.split(","); | ||
12 | if (split.length > 0) { | ||
13 | List<String> collect = Arrays.stream(resouce.split(",")).collect(Collectors.toList()); | ||
14 | return collect; | ||
15 | } else { | ||
16 | List<String> strings = Arrays.asList(resouce); | ||
17 | return strings; | ||
18 | } | ||
19 | } | ||
20 | |||
21 | } |
... | @@ -2,12 +2,15 @@ | ... | @@ -2,12 +2,15 @@ |
2 | spring: | 2 | spring: |
3 | datasource: | 3 | datasource: |
4 | # 测试/演示库 | 4 | # 测试/演示库 |
5 | url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 5 | # url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
6 | # username: root | ||
7 | # password: Tjlh@2017 | ||
8 | |||
9 | url: jdbc:log4jdbc:mysql://47.100.212.170:3306/ucs?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
6 | username: root | 10 | username: root |
7 | password: Tjlh@2017 | 11 | password: Tjlh@2021 |
8 | 12 | ||
9 | # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 13 | # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
10 | # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
11 | # username: root | 14 | # username: root |
12 | # password: root | 15 | # password: root |
13 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | 16 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | ... | ... |
... | @@ -2,14 +2,9 @@ | ... | @@ -2,14 +2,9 @@ |
2 | spring: | 2 | spring: |
3 | datasource: | 3 | datasource: |
4 | # 测试/演示库 | 4 | # 测试/演示库 |
5 | url: jdbc:log4jdbc:mysql://139.196.192.242:3306/tj_user_0819?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | 5 | url: jdbc:log4jdbc:mysql://172.0.31.10:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false |
6 | username: root | 6 | username: root |
7 | password: Tjlh@2017 | 7 | password: Tjlh@2021 |
8 | |||
9 | # url: jdbc:log4jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
10 | # url: jdbc:mysql://122.112.214.149:3306/tj_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false | ||
11 | # username: root | ||
12 | # password: root | ||
13 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | 8 | driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy |
14 | #Druid | 9 | #Druid |
15 | type: com.alibaba.druid.pool.DruidDataSource | 10 | type: com.alibaba.druid.pool.DruidDataSource |
... | @@ -53,24 +48,21 @@ spring: | ... | @@ -53,24 +48,21 @@ spring: |
53 | max-request-size: 200MB | 48 | max-request-size: 200MB |
54 | redis: | 49 | redis: |
55 | #数据库索引 | 50 | #数据库索引 |
56 | database: 16 | 51 | database: 0 |
57 | host: 122.112.214.149 | 52 | host: 127.0.0.1 |
58 | # host: 139.196.4.234 | ||
59 | port: 6379 | 53 | port: 6379 |
60 | password: redis123 | ||
61 | # password: | ||
62 | #连接超时时间 | 54 | #连接超时时间 |
63 | timeout: 5000 | 55 | timeout: 5000 |
64 | rabbitmq: | 56 | rabbitmq: |
65 | host: 122.112.214.149 # rabbitmq的连接地址 | 57 | host: 172.0.31.96 # rabbitmq的连接地址 |
66 | #host: 139.196.192.242 # rabbitmq的连接地址 | 58 | #host: 139.196.192.242 # rabbitmq的连接地址 |
67 | port: 5672 # rabbitmq的连接端口号 | 59 | port: 5672 # rabbitmq的连接端口号 |
68 | #virtual-host: /member_center # rabbitmq的虚拟host | 60 | #virtual-host: /member_center # rabbitmq的虚拟host |
69 | #username: member_center # rabbitmq的用户名 | 61 | #username: member_center # rabbitmq的用户名 |
70 | #password: Tjlh@2021 # rabbitmq的密码 | 62 | #password: Tjlh@2021 # rabbitmq的密码 |
71 | virtual-host: / # rabbitmq的虚拟host | 63 | virtual-host: member_center # rabbitmq的虚拟host |
72 | username: guest # rabbitmq的用户名 | 64 | username: admin # rabbitmq的用户名 |
73 | password: guest # rabbitmq的密码 | 65 | password: Tjlh@2021 # rabbitmq的密码 |
74 | publisher-confirms: true #如果对异步消息需要回调必须设置为true | 66 | publisher-confirms: true #如果对异步消息需要回调必须设置为true |
75 | 67 | ||
76 | #jwt。依赖的common中有需要jwt的部分属性。 | 68 | #jwt。依赖的common中有需要jwt的部分属性。 | ... | ... |
... | @@ -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_tr_task_progress"; | 42 | var dbName = "uc_member_group"; |
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.business.basicdata.task."; | 49 | var preRoute = "com.topdraw.business.basicdata.member."; |
50 | StringBuilder builder = new StringBuilder(preRoute); | 50 | StringBuilder builder = new StringBuilder(preRoute); |
51 | builder.append("progress"); | 51 | builder.append("group"); |
52 | // builder.append(target); | 52 | // builder.append(target); |
53 | 53 | ||
54 | tableNames.forEach(tableName -> { | 54 | tableNames.forEach(tableName -> { | ... | ... |
1 | package com.topdraw.test.business.basicdata.task; | ||
2 | |||
3 | import com.topdraw.business.basicdata.member.domain.Member; | ||
4 | import com.topdraw.business.basicdata.member.service.dto.MemberDTO; | ||
5 | import com.topdraw.business.basicdata.task.domain.Task; | ||
6 | import com.topdraw.business.basicdata.task.service.TaskService; | ||
7 | import com.topdraw.BaseTest; | ||
8 | import com.topdraw.business.process.service.impl.CompareTaskCondition; | ||
9 | import com.topdraw.util.IdWorker; | ||
10 | import com.topdraw.util.TimestampUtil; | ||
11 | import org.assertj.core.util.Arrays; | ||
12 | import org.junit.Assert; | ||
13 | import org.junit.Test; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.util.CollectionUtils; | ||
16 | |||
17 | import java.sql.Timestamp; | ||
18 | import java.util.ArrayList; | ||
19 | import java.util.List; | ||
20 | import java.util.Objects; | ||
21 | import java.util.stream.Collectors; | ||
22 | |||
23 | //public class TaskServiceTest extends BaseTest { | ||
24 | public class TaskServiceTest { | ||
25 | |||
26 | @Test | ||
27 | public void dealTaskTest(){ | ||
28 | // List<Task> taskList = this.taskService.findByTemplateId(1L); | ||
29 | // LOG.info("=====>>>" + taskList); | ||
30 | Task task = new Task(); | ||
31 | task.setTaskTemplateId(1L); | ||
32 | task.setTaskDailyReset(1); | ||
33 | task.setActionAmount(1); | ||
34 | task.setValidTime(TimestampUtil.now()); | ||
35 | task.setExpireTime(TimestampUtil.now()); | ||
36 | task.setSequence(1); | ||
37 | task.setRewardExp(10L); | ||
38 | task.setRewardPoints(1L); | ||
39 | task.setRewardPointsExpireTime(TimestampUtil.Timestamp2long(TimestampUtil.now())); | ||
40 | task.setPointsType(1); | ||
41 | task.setRewardMaxPoints(1); | ||
42 | task.setGroups("groups"); | ||
43 | task.setRightsSendStrategy(1); | ||
44 | task.setMemberLevel(1); | ||
45 | task.setMemberVip(1); | ||
46 | task.setRightsId(1L); | ||
47 | task.setRightsAmount(1); | ||
48 | task.setRights2Id(2L); | ||
49 | task.setRights2Amount(1); | ||
50 | task.setRights3Id(3L); | ||
51 | task.setRights3Amount(1); | ||
52 | task.setStatus(1); | ||
53 | List<Task> taskList = new ArrayList<>(); | ||
54 | taskList.add(task); | ||
55 | |||
56 | MemberDTO member = new MemberDTO(); | ||
57 | member.setCode(String.valueOf(IdWorker.generator())); | ||
58 | member.setType(1); | ||
59 | member.setStatus(1); | ||
60 | member.setNickname("nickname"); | ||
61 | member.setDescription("description"); | ||
62 | member.setGender(1); | ||
63 | member.setBirthday("birthday"); | ||
64 | member.setAvatarUrl("avatarUrl"); | ||
65 | member.setGroups("groups"); | ||
66 | member.setTags("tags"); | ||
67 | member.setVip(1); | ||
68 | member.setLevel(1); | ||
69 | member.setExp(10L); | ||
70 | member.setPoints(5L); | ||
71 | member.setDuePoints(0L); | ||
72 | member.setCouponAmount(1L); | ||
73 | member.setDueCouponAmount(0L); | ||
74 | member.setUserIptvId(1L); | ||
75 | member.setBindIptvPlatformType(0); | ||
76 | member.setUpdateTime(TimestampUtil.now()); | ||
77 | |||
78 | // 判断是否完成任务 | ||
79 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1, List<Task> taskList1) -> { | ||
80 | |||
81 | List<Task> taskStream = taskList1.stream().filter(task1 -> | ||
82 | task1.getStatus() == 1 && | ||
83 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) <= 0) && | ||
84 | (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && | ||
85 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && | ||
86 | (task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) && | ||
87 | (task1.getMemberVip() == 0 || task1.getMemberVip() == memberDTO1.getVip()) | ||
88 | ).collect(Collectors.toList()); | ||
89 | |||
90 | if (CollectionUtils.isEmpty(taskStream)) { | ||
91 | return false; | ||
92 | } | ||
93 | return true; | ||
94 | }; | ||
95 | boolean b = compareTaskCondition.compareCondition(member, taskList); | ||
96 | System.out.println(b); | ||
97 | } | ||
98 | } |
... | @@ -53,9 +53,9 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -53,9 +53,9 @@ public class PointsOperationControllerTest extends BaseTest { |
53 | @Test | 53 | @Test |
54 | public void grantPointsByManual(){ | 54 | public void grantPointsByManual(){ |
55 | TempPoints tempPoints = new TempPoints(); | 55 | TempPoints tempPoints = new TempPoints(); |
56 | tempPoints.setMemberId(10L); | ||
56 | tempPoints.setPoints(10L); | 57 | tempPoints.setPoints(10L); |
57 | tempPoints.setPointsType(0); | 58 | tempPoints.setPointsType(0); |
58 | tempPoints.setMemberId(3L); | ||
59 | tempPoints.setRightsSendStrategy(0); | 59 | tempPoints.setRightsSendStrategy(0); |
60 | tempPoints.setAccountId(2L); | 60 | tempPoints.setAccountId(2L); |
61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); | 61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); |
... | @@ -72,6 +72,28 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -72,6 +72,28 @@ public class PointsOperationControllerTest extends BaseTest { |
72 | LOG.info("===>>>"+byId); | 72 | LOG.info("===>>>"+byId); |
73 | } | 73 | } |
74 | 74 | ||
75 | @Test | ||
76 | public void cleanInvalidPointsAndCalculateCurrentPoints(){ | ||
77 | /*TempPoints tempPoints = new TempPoints(); | ||
78 | tempPoints.setMemberId(5L); | ||
79 | tempPoints.setPoints(10L); | ||
80 | tempPoints.setPointsType(0); | ||
81 | tempPoints.setRightsSendStrategy(0); | ||
82 | tempPoints.setAccountId(2L); | ||
83 | tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); | ||
84 | tempPoints.setDeviceType(2); | ||
85 | tempPoints.setAppCode("WEI_XIN_GOLD_PANDA"); | ||
86 | tempPoints.setOrderId(null); | ||
87 | tempPoints.setMediaId(null); | ||
88 | tempPoints.setActivityId(null); | ||
89 | tempPoints.setItemId(null); | ||
90 | tempPoints.setDescription("系统发放"); | ||
91 | tempPoints.setEvtType(1); | ||
92 | String s = JSON.toJSONString(tempPoints);*/ | ||
93 | ResultInfo byId = this.pointsOperationController.cleanInvalidPointsAndCalculateCurrentPoints(5L); | ||
94 | LOG.info("===>>>"+byId); | ||
95 | } | ||
96 | |||
75 | /*@Test | 97 | /*@Test |
76 | public void update(){ | 98 | public void update(){ |
77 | MemberAddress memberAddress = new MemberAddress(); | 99 | MemberAddress memberAddress = new MemberAddress(); | ... | ... |
... | @@ -8,8 +8,17 @@ import com.topdraw.module.mq.DataSyncMsg; | ... | @@ -8,8 +8,17 @@ import com.topdraw.module.mq.DataSyncMsg; |
8 | import com.topdraw.module.mq.EntityType; | 8 | import com.topdraw.module.mq.EntityType; |
9 | import com.topdraw.module.mq.EventType; | 9 | import com.topdraw.module.mq.EventType; |
10 | import com.topdraw.BaseTest; | 10 | import com.topdraw.BaseTest; |
11 | import com.topdraw.utils.StringUtils; | ||
11 | import org.junit.Test; | 12 | import org.junit.Test; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
14 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
15 | |||
16 | import javax.annotation.Resource; | ||
17 | import java.util.List; | ||
18 | import java.util.concurrent.ArrayBlockingQueue; | ||
19 | import java.util.concurrent.FutureTask; | ||
20 | import java.util.concurrent.ThreadPoolExecutor; | ||
21 | import java.util.concurrent.TimeUnit; | ||
13 | 22 | ||
14 | public class TaskOperationControllerTest extends BaseTest { | 23 | public class TaskOperationControllerTest extends BaseTest { |
15 | 24 | ||
... | @@ -20,11 +29,11 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -20,11 +29,11 @@ public class TaskOperationControllerTest extends BaseTest { |
20 | public void dealTask() { | 29 | public void dealTask() { |
21 | try { | 30 | try { |
22 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); | 31 | DataSyncMsg dataSyncMsg = new DataSyncMsg(); |
23 | dataSyncMsg.setEventType(EventType.LOGIN.name()); | 32 | dataSyncMsg.setEventType(EventType.VIEWING.name()); |
24 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); | 33 | DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); |
25 | msgData.setEvent(1); | 34 | msgData.setEvent(6); // 类型 1-登录 2-观影 3-参加活动 4-订购 5-优享会员 6-签到 |
26 | msgData.setRemarks("remark"); | 35 | msgData.setRemarks("remark"); |
27 | msgData.setMemberId(3L); | 36 | msgData.setMemberId(4L); |
28 | msgData.setDeviceType(2); | 37 | msgData.setDeviceType(2); |
29 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); | 38 | msgData.setAppCode("WEI_XIN_GOLD_PANDA"); |
30 | dataSyncMsg.setMsg(msgData); | 39 | dataSyncMsg.setMsg(msgData); |
... | @@ -37,9 +46,72 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -37,9 +46,72 @@ public class TaskOperationControllerTest extends BaseTest { |
37 | } catch (Exception e) { | 46 | } catch (Exception e) { |
38 | e.printStackTrace(); | 47 | e.printStackTrace(); |
39 | } | 48 | } |
49 | } | ||
50 | |||
51 | |||
52 | @Autowired | ||
53 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
54 | |||
55 | |||
56 | |||
57 | public void t1() throws InterruptedException { | ||
58 | |||
59 | Thread.sleep(1*1000); | ||
60 | System.out.println(Thread.currentThread().getName()+"=======>>> t1"); | ||
61 | |||
62 | } | ||
63 | public void t2() throws InterruptedException { | ||
64 | |||
65 | Thread.sleep(1*1000); | ||
66 | System.out.println(Thread.currentThread().getName()+"=======>>> t2"); | ||
67 | |||
68 | } | ||
69 | public void t3() throws InterruptedException { | ||
70 | |||
71 | Thread.sleep(1*1000); | ||
72 | System.out.println(Thread.currentThread().getName()+"=======>>> t3"); | ||
40 | 73 | ||
41 | } | 74 | } |
42 | 75 | ||
76 | @Test | ||
77 | public void main() { | ||
78 | long l = System.currentTimeMillis(); | ||
79 | FutureTask futureTask1 = new FutureTask(()->{ | ||
80 | t1(); | ||
81 | return null; | ||
82 | }); | ||
83 | FutureTask futureTask2 = new FutureTask(()->{ | ||
84 | t2(); | ||
85 | return null; | ||
86 | }); | ||
87 | |||
88 | FutureTask futureTask3 = new FutureTask(()->{ | ||
89 | t3(); | ||
90 | return null; | ||
91 | }); | ||
92 | |||
93 | threadPoolTaskExecutor.execute(futureTask1); | ||
94 | threadPoolTaskExecutor.execute(futureTask2); | ||
95 | threadPoolTaskExecutor.execute(futureTask3); | ||
96 | |||
97 | long l1 = System.currentTimeMillis(); | ||
98 | System.out.println(l1-l); | ||
99 | /*threadPoolTaskExecutor.execute(()->{ | ||
100 | for (int i = 0; i < 10; i++) { | ||
101 | try { | ||
102 | // Thread.sleep(2*1000); | ||
103 | System.out.println("===>>>> "); | ||
104 | } catch (Exception e) { | ||
105 | e.printStackTrace(); | ||
106 | } | ||
107 | |||
108 | } | ||
109 | });*/ | ||
110 | |||
111 | System.out.println("======>>> main end"); | ||
112 | } | ||
113 | |||
114 | |||
43 | 115 | ||
44 | 116 | ||
45 | } | 117 | } | ... | ... |
... | @@ -46,7 +46,8 @@ public class PointsOperationServiceTest extends BaseTest { | ... | @@ -46,7 +46,8 @@ public class PointsOperationServiceTest extends BaseTest { |
46 | 46 | ||
47 | @Test | 47 | @Test |
48 | public void cleanInvalidAvailablePoints() { | 48 | public void cleanInvalidAvailablePoints() { |
49 | this.pointsOperationService.cleanInvalidAvailablePoints(); | 49 | Long memberId = 10L; |
50 | this.pointsOperationService.cleanInvalidPointsAndCalculateCurrentPoints(memberId); | ||
50 | } | 51 | } |
51 | 52 | ||
52 | } | 53 | } | ... | ... |
-
Please register or sign in to post a comment