Merge branch 'release/1.0.3'
Showing
49 changed files
with
1120 additions
and
417 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)") | ... | ... |
| ... | @@ -121,7 +121,7 @@ public class Member implements Serializable { | ... | @@ -121,7 +121,7 @@ public class Member implements Serializable { |
| 121 | 121 | ||
| 122 | // 是否在黑名单 1:是;0否 | 122 | // 是否在黑名单 1:是;0否 |
| 123 | @Column(name = "black_status") | 123 | @Column(name = "black_status") |
| 124 | private Integer blackStatus; | 124 | private Long blackStatus; |
| 125 | 125 | ||
| 126 | public void copy(Member source){ | 126 | public void copy(Member source){ |
| 127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | 127 | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); | ... | ... |
| 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 | } |
| ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; | ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelDTO; |
| 9 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; | 9 | import com.topdraw.business.basicdata.member.level.service.dto.MemberLevelQueryCriteria; |
| 10 | import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper; | 10 | import com.topdraw.business.basicdata.member.level.service.mapper.MemberLevelMapper; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.cache.annotation.Cacheable; | ||
| 12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
| 14 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; | ... | ... |
| ... | @@ -83,5 +83,5 @@ public class MemberDTO implements Serializable { | ... | @@ -83,5 +83,5 @@ public class MemberDTO implements Serializable { |
| 83 | private Timestamp updateTime; | 83 | private Timestamp updateTime; |
| 84 | 84 | ||
| 85 | // 是否在黑名单 1:是;0否 | 85 | // 是否在黑名单 1:是;0否 |
| 86 | private Integer blackStatus; | 86 | private Long blackStatus; |
| 87 | } | 87 | } | ... | ... |
| ... | @@ -19,13 +19,18 @@ import org.redisson.api.RLock; | ... | @@ -19,13 +19,18 @@ import org.redisson.api.RLock; |
| 19 | import org.redisson.api.RedissonClient; | 19 | import org.redisson.api.RedissonClient; |
| 20 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.cache.annotation.CacheConfig; | ||
| 22 | import org.springframework.cache.annotation.Cacheable; | 23 | import org.springframework.cache.annotation.Cacheable; |
| 23 | import org.springframework.dao.EmptyResultDataAccessException; | 24 | import org.springframework.dao.EmptyResultDataAccessException; |
| 24 | import org.springframework.data.domain.Page; | 25 | import org.springframework.data.domain.Page; |
| 25 | import org.springframework.data.domain.Pageable; | 26 | import org.springframework.data.domain.Pageable; |
| 26 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| 28 | import org.springframework.transaction.PlatformTransactionManager; | ||
| 29 | import org.springframework.transaction.TransactionDefinition; | ||
| 30 | import org.springframework.transaction.TransactionStatus; | ||
| 27 | import org.springframework.transaction.annotation.Propagation; | 31 | import org.springframework.transaction.annotation.Propagation; |
| 28 | import org.springframework.transaction.annotation.Transactional; | 32 | import org.springframework.transaction.annotation.Transactional; |
| 33 | import org.springframework.transaction.support.DefaultTransactionDefinition; | ||
| 29 | import org.springframework.util.Assert; | 34 | import org.springframework.util.Assert; |
| 30 | 35 | ||
| 31 | import java.util.List; | 36 | import java.util.List; |
| ... | @@ -38,6 +43,7 @@ import java.util.Objects; | ... | @@ -38,6 +43,7 @@ import java.util.Objects; |
| 38 | */ | 43 | */ |
| 39 | @Service | 44 | @Service |
| 40 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) | 45 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) |
| 46 | //@CacheConfig(cacheNames = "uc-member-info") | ||
| 41 | public class MemberServiceImpl implements MemberService { | 47 | public class MemberServiceImpl implements MemberService { |
| 42 | 48 | ||
| 43 | @Autowired | 49 | @Autowired |
| ... | @@ -61,12 +67,12 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -61,12 +67,12 @@ public class MemberServiceImpl implements MemberService { |
| 61 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); | 67 | return memberMapper.toDto(memberRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| 62 | } | 68 | } |
| 63 | 69 | ||
| 64 | // @Cacheable(cacheNames = "",key = "") | ||
| 65 | @Override | 70 | @Override |
| 66 | public MemberDTO findById(Long id) { | 71 | public MemberDTO findById(Long id) { |
| 67 | Member member = memberRepository.findById(id).orElseGet(Member::new); | 72 | Member member = memberRepository.findById(id).orElseGet(Member::new); |
| 68 | ValidationUtil.isNull(member.getId(),"Member","id",id); | 73 | ValidationUtil.isNull(member.getId(),"Member","id",id); |
| 69 | return memberMapper.toDto(member); | 74 | return memberMapper.toDto(member); |
| 75 | |||
| 70 | } | 76 | } |
| 71 | 77 | ||
| 72 | @Override | 78 | @Override |
| ... | @@ -99,6 +105,9 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -99,6 +105,9 @@ public class MemberServiceImpl implements MemberService { |
| 99 | return member; | 105 | return member; |
| 100 | } | 106 | } |
| 101 | 107 | ||
| 108 | @Autowired | ||
| 109 | PlatformTransactionManager platformTransactionManager; | ||
| 110 | |||
| 102 | @Override | 111 | @Override |
| 103 | @Transactional(rollbackFor = Exception.class) | 112 | @Transactional(rollbackFor = Exception.class) |
| 104 | @AsyncMqSend() | 113 | @AsyncMqSend() |
| ... | @@ -106,10 +115,18 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -106,10 +115,18 @@ public class MemberServiceImpl implements MemberService { |
| 106 | RLock rLock = this.redissonClient.getLock("updateMember" + resources.getId().toString()); | 115 | RLock rLock = this.redissonClient.getLock("updateMember" + resources.getId().toString()); |
| 107 | try { | 116 | try { |
| 108 | RedissonUtil.lock(rLock); | 117 | RedissonUtil.lock(rLock); |
| 118 | String name = Thread.currentThread().getName(); | ||
| 119 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> start ===>> "); | ||
| 120 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【resources】 ===>> " + resources); | ||
| 109 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); | 121 | Member member = memberRepository.findById(resources.getId()).orElseGet(Member::new); |
| 110 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); | 122 | ValidationUtil.isNull(member.getId(), "Member", "id", resources.getId()); |
| 123 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【member-search】 ===>> " + member); | ||
| 111 | member.copy(resources); | 124 | member.copy(resources); |
| 112 | memberRepository.save(member); | 125 | this.save(member); |
| 126 | // platformTransactionManager.commit(transaction); | ||
| 127 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【exp】 ===>> " + member.getExp()); | ||
| 128 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【point】 ===>> " + member.getPoints()); | ||
| 129 | System.out.println("=============>>>>【name】 ===== >> " + name + " =======>> 【member】 ===>> " + member); | ||
| 113 | } catch (Exception e) { | 130 | } catch (Exception e) { |
| 114 | e.printStackTrace(); | 131 | e.printStackTrace(); |
| 115 | throw e; | 132 | throw e; |
| ... | @@ -118,6 +135,11 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -118,6 +135,11 @@ public class MemberServiceImpl implements MemberService { |
| 118 | } | 135 | } |
| 119 | } | 136 | } |
| 120 | 137 | ||
| 138 | @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| 139 | public void save(Member member){ | ||
| 140 | memberRepository.save(member); | ||
| 141 | } | ||
| 142 | |||
| 121 | @Override | 143 | @Override |
| 122 | @Transactional(rollbackFor = Exception.class) | 144 | @Transactional(rollbackFor = Exception.class) |
| 123 | @AsyncMqSend() | 145 | @AsyncMqSend() | ... | ... |
| ... | @@ -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) { | ... | ... |
| ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.task.service.dto.TaskDTO; | ... | @@ -9,6 +9,7 @@ import com.topdraw.business.basicdata.task.service.dto.TaskDTO; |
| 9 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; | 9 | import com.topdraw.business.basicdata.task.service.dto.TaskQueryCriteria; |
| 10 | import com.topdraw.business.basicdata.task.service.mapper.TaskMapper; | 10 | import com.topdraw.business.basicdata.task.service.mapper.TaskMapper; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.cache.annotation.Cacheable; | ||
| 12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.transaction.annotation.Propagation; | 14 | import org.springframework.transaction.annotation.Propagation; |
| 14 | import org.springframework.transaction.annotation.Transactional; | 15 | import org.springframework.transaction.annotation.Transactional; |
| ... | @@ -79,6 +80,7 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -79,6 +80,7 @@ public class TaskServiceImpl implements TaskService { |
| 79 | TaskRepository.delete(Task); | 80 | TaskRepository.delete(Task); |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 83 | // @Cacheable(cacheNames = "uc-admin_taskList" , key = "#taskTemplateId") | ||
| 82 | @Override | 84 | @Override |
| 83 | public List<Task> findByTemplateId(Long taskTemplateId) { | 85 | public List<Task> findByTemplateId(Long taskTemplateId) { |
| 84 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | 86 | return Objects.nonNull(taskTemplateId) ? this.TaskRepository.findByTaskTemplateId(taskTemplateId) : null; | ... | ... |
| ... | @@ -87,12 +87,13 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { | ... | @@ -87,12 +87,13 @@ public class TaskTemplateServiceImpl implements TaskTemplateService { |
| 87 | : new TaskTemplateDTO(); | 87 | : new TaskTemplateDTO(); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | // @Cacheable(cacheNames = "uc.taskTemplate" , key = "event") | 90 | |
| 91 | @Override | 91 | @Override |
| 92 | public TaskTemplate findByEvent(String event) { | 92 | public TaskTemplate findByEvent(String event) { |
| 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 | @Override | 97 | @Override |
| 97 | public TaskTemplate findByType(Integer event) { | 98 | public TaskTemplate findByType(Integer event) { |
| 98 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; | 99 | return Objects.nonNull(event) ? this.TaskTemplateRepository.findByType(event) : null; | ... | ... |
| ... | @@ -20,6 +20,14 @@ public class TempRights { | ... | @@ -20,6 +20,14 @@ public class TempRights { |
| 20 | @Transient | 20 | @Transient |
| 21 | protected Long id; | 21 | protected Long id; |
| 22 | 22 | ||
| 23 | /** 编号 */ | ||
| 24 | @Transient | ||
| 25 | protected String code; | ||
| 26 | |||
| 27 | /** 权益名称 */ | ||
| 28 | @Transient | ||
| 29 | protected String name; | ||
| 30 | |||
| 23 | /** 会员ID */ | 31 | /** 会员ID */ |
| 24 | @Transient | 32 | @Transient |
| 25 | @NotNull(message = "") | 33 | @NotNull(message = "") | ... | ... |
| ... | @@ -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(); | ... | ... |
| ... | @@ -5,6 +5,7 @@ import com.topdraw.business.basicdata.task.domain.Task; | ... | @@ -5,6 +5,7 @@ import com.topdraw.business.basicdata.task.domain.Task; |
| 5 | import com.topdraw.business.process.domian.TempPoints; | 5 | import com.topdraw.business.process.domian.TempPoints; |
| 6 | 6 | ||
| 7 | import java.util.List; | 7 | import java.util.List; |
| 8 | import java.util.Map; | ||
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| 10 | * @description 积分操作接口 | 11 | * @description 积分操作接口 |
| ... | @@ -34,13 +35,11 @@ public interface PointsOperationService { | ... | @@ -34,13 +35,11 @@ public interface PointsOperationService { |
| 34 | */ | 35 | */ |
| 35 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); | 36 | void grantPointsThroughTempRightsList(List<TempPoints> tempPointsList); |
| 36 | 37 | ||
| 37 | /** | ||
| 38 | * 清理过期的积分 | ||
| 39 | */ | ||
| 40 | void cleanInvalidAvailablePoints(); | ||
| 41 | 38 | ||
| 42 | /** | 39 | /** |
| 43 | * 清理过期的积分 | 40 | * 清理过期并计算可用总积分 |
| 41 | * @param memberId | ||
| 42 | * @return | ||
| 44 | */ | 43 | */ |
| 45 | void cleanInvalidAvailablePointsByMemberId(Long memberId); | 44 | Long cleanInvalidPointsAndCalculateCurrentPoints(Long memberId); |
| 46 | } | 45 | } | ... | ... |
| ... | @@ -19,10 +19,14 @@ import org.springframework.beans.factory.annotation.Autowired; | ... | @@ -19,10 +19,14 @@ import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 21 | 21 | ||
| 22 | import javax.annotation.Resource; | ||
| 22 | import java.sql.Timestamp; | 23 | import java.sql.Timestamp; |
| 23 | import java.time.LocalDateTime; | 24 | import java.time.LocalDateTime; |
| 25 | import java.util.HashMap; | ||
| 24 | import java.util.List; | 26 | import java.util.List; |
| 27 | import java.util.Map; | ||
| 25 | import java.util.Objects; | 28 | import java.util.Objects; |
| 29 | import java.util.concurrent.ConcurrentHashMap; | ||
| 26 | import java.util.concurrent.locks.ReentrantLock; | 30 | import java.util.concurrent.locks.ReentrantLock; |
| 27 | 31 | ||
| 28 | 32 | ||
| ... | @@ -45,9 +49,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -45,9 +49,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 45 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| 46 | 50 | ||
| 47 | // 过期阀值(默认一个月) | 51 | // 过期阀值(默认一个月) |
| 48 | private static final Integer EXPIRE_FACTOR_MONTH = 1; | 52 | private static final Integer EXPIRE_FACTOR_DAY = 30; |
| 49 | |||
| 50 | |||
| 51 | 53 | ||
| 52 | @Override | 54 | @Override |
| 53 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { | 55 | public void grantCouponThroughTempCoupon(List<TempCoupon> tempCouponList) { |
| ... | @@ -80,10 +82,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -80,10 +82,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 80 | * @param tempCoupon 领取的优惠券 | 82 | * @param tempCoupon 领取的优惠券 |
| 81 | */ | 83 | */ |
| 82 | private void refresh(TempCoupon tempCoupon) { | 84 | private void refresh(TempCoupon tempCoupon) { |
| 83 | // 1.保存优惠券领取、使用历史记录表 | 85 | // 1.更新会员优惠券数量 |
| 84 | this.threadPoolTaskExecutor.execute(()->this.doInsertCouponHistory(tempCoupon)); | ||
| 85 | // 2.更新会员优惠券数量 | ||
| 86 | this.refreshMemberCoupon(tempCoupon); | 86 | this.refreshMemberCoupon(tempCoupon); |
| 87 | // 2.保存优惠券领取、使用历史记录表 | ||
| 88 | this.doInsertCouponHistory(tempCoupon); | ||
| 87 | } | 89 | } |
| 88 | 90 | ||
| 89 | 91 | ||
| ... | @@ -92,17 +94,20 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -92,17 +94,20 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 92 | * @param tempCoupon 账号id | 94 | * @param tempCoupon 账号id |
| 93 | */ | 95 | */ |
| 94 | private void refreshMemberCoupon(TempCoupon tempCoupon) { | 96 | private void refreshMemberCoupon(TempCoupon tempCoupon) { |
| 95 | Long userId = tempCoupon.getUserId(); | 97 | // Long userId = tempCoupon.getUserId(); |
| 96 | Long memberId = tempCoupon.getMemberId(); | 98 | Long memberId = tempCoupon.getMemberId(); |
| 99 | Integer rightsAmount = tempCoupon.getRightsAmount(); | ||
| 97 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); | 100 | RLock rLock = this.redissonClient.getLock("refreshMemberCoupon:" + memberId.toString()); |
| 98 | try { | 101 | try { |
| 99 | RedissonUtil.lock(rLock); | 102 | RedissonUtil.lock(rLock); |
| 100 | // 1.获取用户领取的总优惠券 | 103 | // 1.历史总优惠券数量 |
| 101 | Long totalCouponCount = this.getTotalCoupon(userId); | 104 | Long historyCouponCount = this.getTotalHistoryCoupon(memberId); |
| 105 | // 1.当前总优惠券数量 | ||
| 106 | Long totalCouponCount = this.getTotalCoupon(historyCouponCount,rightsAmount); | ||
| 102 | // 2.获取已过期的优惠券数量 | 107 | // 2.获取已过期的优惠券数量 |
| 103 | Long expireCouponCount = this.getTotalExpireCoupon(userId); | 108 | Long expireCouponCount = this.getTotalExpireCoupon(memberId); |
| 104 | // 3.即将过期的优惠券数量 | 109 | // 3.即将过期的优惠券数量 |
| 105 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(userId,EXPIRE_FACTOR_MONTH); | 110 | Long expireSoonCouponCount = this.getTotalExpireSoonCoupon(memberId,EXPIRE_FACTOR_DAY); |
| 106 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 | 111 | // 4.当前优惠券数量 = 总优惠券-已过期的优惠券 |
| 107 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); | 112 | Long currentCoupon = this.getCurrentCoupon(totalCouponCount,expireCouponCount); |
| 108 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) | 113 | // 5.更新用户信息(优惠券数量、即将过期的优惠券数量) |
| ... | @@ -115,6 +120,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -115,6 +120,10 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 115 | } | 120 | } |
| 116 | } | 121 | } |
| 117 | 122 | ||
| 123 | private Long getTotalCoupon(Long historyCouponCount, Integer rightsAmount) { | ||
| 124 | return (Objects.nonNull(historyCouponCount) ? historyCouponCount: 0L) + (Objects.nonNull(rightsAmount) ? rightsAmount: 0L); | ||
| 125 | } | ||
| 126 | |||
| 118 | 127 | ||
| 119 | /** | 128 | /** |
| 120 | * 更新当前用户优惠券信息 | 129 | * 更新当前用户优惠券信息 |
| ... | @@ -149,28 +158,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -149,28 +158,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 149 | * @return | 158 | * @return |
| 150 | */ | 159 | */ |
| 151 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { | 160 | private Long getTotalExpireSoonCoupon(Long userId, Integer expireFactor) { |
| 152 | LocalDateTime localDateTime = LocalDateTime.now(); | 161 | Timestamp expireTime = TimestampUtil.localDateTime2Timestamp(LocalDateTime.now().plusDays(expireFactor)); |
| 153 | String s = EXPIRE_FACTOR_MONTH.toString(); | ||
| 154 | String[] s1 = s.split("_"); | ||
| 155 | String s2 = s1[s1.length-1]; | ||
| 156 | switch (s2) { | ||
| 157 | case "YEAR": | ||
| 158 | localDateTime.plusYears(expireFactor); | ||
| 159 | break; | ||
| 160 | case "MONTH": | ||
| 161 | localDateTime.plusMonths(expireFactor); | ||
| 162 | break; | ||
| 163 | case "DAY": | ||
| 164 | localDateTime.plusDays(expireFactor); | ||
| 165 | break; | ||
| 166 | case "HOUR": | ||
| 167 | localDateTime.plusHours(expireFactor); | ||
| 168 | break; | ||
| 169 | default: | ||
| 170 | break; | ||
| 171 | } | ||
| 172 | |||
| 173 | Timestamp expireTime = TimestampUtil.now(localDateTime); | ||
| 174 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); | 162 | return this.couponHistoryService.countByUserIdAndExpireTimeBetween(userId,TimestampUtil.now(),expireTime); |
| 175 | } | 163 | } |
| 176 | 164 | ||
| ... | @@ -190,7 +178,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -190,7 +178,7 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 190 | * @param userId | 178 | * @param userId |
| 191 | * @return | 179 | * @return |
| 192 | */ | 180 | */ |
| 193 | private Long getTotalCoupon(Long userId) { | 181 | private Long getTotalHistoryCoupon(Long userId) { |
| 194 | return this.couponHistoryService.countByUserId(userId); | 182 | return this.couponHistoryService.countByUserId(userId); |
| 195 | } | 183 | } |
| 196 | 184 | ||
| ... | @@ -204,10 +192,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { | ... | @@ -204,10 +192,12 @@ public class CouponOperationServiceImpl implements CouponOperationService { |
| 204 | BeanUtils.copyProperties(tempCoupon,couponHistory); | 192 | BeanUtils.copyProperties(tempCoupon,couponHistory); |
| 205 | couponHistory.setId(null); | 193 | couponHistory.setId(null); |
| 206 | couponHistory.setCouponId(tempCoupon.getId()); | 194 | couponHistory.setCouponId(tempCoupon.getId()); |
| 207 | couponHistory.setUserId(tempCoupon.getUserId()); | 195 | couponHistory.setUserId(tempCoupon.getMemberId()); |
| 208 | couponHistory.setCouponCode(tempCoupon.getCode()); | 196 | couponHistory.setCouponCode(tempCoupon.getCode()); |
| 209 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); | 197 | couponHistory.setUserNickname(tempCoupon.getUserNickname()); |
| 210 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); | 198 | couponHistory.setOrderDetailId(tempCoupon.getOrderId()); |
| 199 | couponHistory.setReceiveTime(TimestampUtil.now()); | ||
| 200 | couponHistory.setUseStatus(Objects.nonNull(couponHistory.getUseStatus()) ? couponHistory.getUseStatus():0); | ||
| 211 | this.couponHistoryService.create(couponHistory); | 201 | this.couponHistoryService.create(couponHistory); |
| 212 | } | 202 | } |
| 213 | 203 | ... | ... |
| ... | @@ -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 |
| ... | @@ -75,18 +75,19 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -75,18 +75,19 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 75 | * @param tempExp | 75 | * @param tempExp |
| 76 | */ | 76 | */ |
| 77 | private void refresh(TempExp tempExp) { | 77 | private void refresh(TempExp tempExp) { |
| 78 | RLock lock = this.redissonClient.getLock("refresh_exp:" + tempExp.getMemberId()); | 78 | RLock lock = this.redissonClient.getLock("uc-refresh-exp:" + tempExp.getMemberId()); |
| 79 | try { | 79 | try { |
| 80 | RedissonUtil.lock(lock); | 80 | RedissonUtil.lock(lock); |
| 81 | // 原始积分 | 81 | // 原始积分 |
| 82 | long originExp = this.getExpByMemberId(tempExp); | 82 | long originExp = this.getExpByMemberId(tempExp); |
| 83 | // 总积分 | 83 | // 总积分 |
| 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); | 84 | long totalExp = this.calculateTotalExp(originExp, tempExp); |
| 85 | |||
| 86 | // 1.添加成长值记录 | 85 | // 1.添加成长值记录 |
| 87 | this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); | 86 | // this.threadPoolTaskExecutor.execute(() -> this.doInsertExpDetail(tempExp, originExp, totalExp)); |
| 88 | // 2.更新成长值与等级 | 87 | // 2.更新成长值与等级 |
| 89 | this.refreshMemberExpAndLevel(tempExp); | 88 | this.refreshMemberExpAndLevel(tempExp,totalExp); |
| 89 | |||
| 90 | this.doInsertExpDetail(tempExp, originExp, totalExp); | ||
| 90 | 91 | ||
| 91 | } catch (Exception e) { | 92 | } catch (Exception e) { |
| 92 | e.printStackTrace(); | 93 | e.printStackTrace(); |
| ... | @@ -98,7 +99,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -98,7 +99,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 98 | 99 | ||
| 99 | private long calculateTotalExp(long originalExp,TempExp tempExp) { | 100 | private long calculateTotalExp(long originalExp,TempExp tempExp) { |
| 100 | Long rewardExp = tempExp.getRewardExp(); | 101 | Long rewardExp = tempExp.getRewardExp(); |
| 101 | return (Objects.nonNull(rewardExp) ? rewardExp : 0L) + (Objects.nonNull(originalExp) ? originalExp : 0L); | 102 | return rewardExp + originalExp; |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | private long getExpByMemberId(TempExp tempExp) { | 105 | private long getExpByMemberId(TempExp tempExp) { |
| ... | @@ -114,57 +115,43 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -114,57 +115,43 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 114 | * | 115 | * |
| 115 | * @param tempExp 成长值列表 | 116 | * @param tempExp 成长值列表 |
| 116 | */ | 117 | */ |
| 117 | private void refreshMemberExpAndLevel(TempExp tempExp) { | 118 | private void refreshMemberExpAndLevel(TempExp tempExp,long totalExp) { |
| 118 | 119 | ||
| 119 | Long memberId = tempExp.getMemberId(); | 120 | Long memberId = tempExp.getMemberId(); |
| 120 | |||
| 121 | RLock rLock = this.redissonClient.getLock("refreshMemberExpAndLevel" + memberId.toString()); | ||
| 122 | try { | ||
| 123 | RedissonUtil.lock(rLock); | ||
| 124 | // 1.获取当前成长值 | 121 | // 1.获取当前成长值 |
| 125 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); | 122 | MemberDTO memberDTO = this.getMemberInfoByMemberId(memberId); |
| 126 | // 2.获取下一级需要的成长值 | 123 | // 2.获取下一级需要的成长值 |
| 127 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); | 124 | MemberLevelDTO memberLevelDTO = this.getNextLevelExp(memberDTO.getLevel() + 1, 1); |
| 128 | // 3.成长值累加 | ||
| 129 | Long newExp = memberDTO.getExp() + tempExp.getRewardExp(); | ||
| 130 | // 4.成长值比较,判断是否升级 | 125 | // 4.成长值比较,判断是否升级 |
| 131 | long i = this.compareExp(newExp, memberLevelDTO); | 126 | Integer level = this.compareExp(totalExp, memberLevelDTO,memberDTO); |
| 132 | // 5.更新用户信息 | 127 | // 5.更新用户信息 |
| 133 | this.updateMemberInfo(i, newExp, memberLevelDTO, memberId); | 128 | this.updateMemberInfo(level, totalExp, memberId); |
| 134 | } catch (Exception e) { | ||
| 135 | e.printStackTrace(); | ||
| 136 | throw e; | ||
| 137 | } finally { | ||
| 138 | RedissonUtil.unlock(rLock); | ||
| 139 | } | ||
| 140 | } | 129 | } |
| 141 | 130 | ||
| 142 | /** | 131 | /** |
| 143 | * | 132 | * |
| 144 | * @param i | 133 | * @param level |
| 145 | * @param newExp 总积分 | 134 | * @param totalExp 总积分 |
| 146 | * @param memberLevelDTO 下一级 | ||
| 147 | * @param memberId 会员id | 135 | * @param memberId 会员id |
| 148 | */ | 136 | */ |
| 149 | private void updateMemberInfo(long i,Long newExp,MemberLevelDTO memberLevelDTO,Long memberId) { | 137 | private void updateMemberInfo(Integer level,Long totalExp,Long memberId) { |
| 150 | Member member = new Member(); | 138 | Member member = new Member(); |
| 151 | member.setId(memberId); | 139 | member.setId(memberId); |
| 152 | member.setExp(newExp); | 140 | member.setExp(totalExp); |
| 153 | if (i > 0) { | ||
| 154 | Integer level = memberLevelDTO.getLevel(); | ||
| 155 | member.setLevel(level); | 141 | member.setLevel(level); |
| 156 | } | ||
| 157 | member.setUpdateTime(TimestampUtil.now()); | 142 | member.setUpdateTime(TimestampUtil.now()); |
| 158 | this.memberOperationService.doUpdateMemberInfo(member); | 143 | this.memberOperationService.doUpdateMemberInfo(member); |
| 159 | } | 144 | } |
| 160 | 145 | ||
| 161 | private long compareExp(long newExp, MemberLevelDTO memberLevelDTO) { | 146 | private Integer compareExp(long newExp, MemberLevelDTO memberLevelDTO,MemberDTO memberDTO) { |
| 162 | if (Objects.nonNull(memberLevelDTO)) { | 147 | if (Objects.nonNull(memberLevelDTO)) { |
| 163 | Long nextLevelExp = memberLevelDTO.getExpValue(); | 148 | Long nextLevelExp = memberLevelDTO.getExpValue(); |
| 164 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) | 149 | if (Objects.nonNull(nextLevelExp) && nextLevelExp > 0) |
| 165 | return newExp - nextLevelExp; | 150 | if(newExp - nextLevelExp >= 0){ |
| 151 | return memberLevelDTO.getLevel(); | ||
| 152 | } | ||
| 166 | } | 153 | } |
| 167 | return -1; | 154 | return memberDTO.getLevel(); |
| 168 | } | 155 | } |
| 169 | 156 | ||
| 170 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { | 157 | private MemberLevelDTO getNextLevelExp(Integer i,Integer status) { |
| ... | @@ -200,7 +187,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { | ... | @@ -200,7 +187,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { |
| 200 | 187 | ||
| 201 | expDetail.setCode(String.valueOf(IdWorker.generator())); | 188 | expDetail.setCode(String.valueOf(IdWorker.generator())); |
| 202 | // 原始积分 | 189 | // 原始积分 |
| 203 | expDetail.setOriginalExp(Objects.nonNull(originalExp) ? originalExp : 0L); | 190 | expDetail.setOriginalExp(originalExp); |
| 204 | // 总积分 | 191 | // 总积分 |
| 205 | expDetail.setResultExp(totalExp); | 192 | expDetail.setResultExp(totalExp); |
| 206 | // 获得的积分 | 193 | // 获得的积分 | ... | ... |
| ... | @@ -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; | ||
| 312 | } | ||
| 313 | |||
| 314 | /** | ||
| 315 | * 获取可用总积分 | ||
| 316 | * @param memberId | ||
| 317 | * @return | ||
| 318 | */ | ||
| 319 | private long findAvailablePointsByMemberId(Long memberId){ | ||
| 320 | return this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | ||
| 296 | } | 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,19 +385,38 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -344,19 +385,38 @@ 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(); |
| 347 | RLock rLock = this.redissonClient.getLock("refresh_point:" + memberId.toString()); | 388 | log.info("----------->> points refresh start"); |
| 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); |
| 354 | // 2.添加积分明细,并计算总积分 | 400 | log.info("----------->> refresh findAvailablePointsByMemberId totalPoints " + totalPoints); |
| 355 | this.threadPoolTaskExecutor.execute(()->this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints)); | 401 | |
| 356 | // 4.更新会员的总积分 | 402 | // 3.添加积分明细,并计算总积分 |
| 357 | this.freshMemberCurrentPoints(memberId, totalPoints); | 403 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail start "); |
| 358 | // 5.添加可用积分 | 404 | this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints, totalPoints); |
| 405 | log.info(Thread.currentThread().getName() + "----------->> refresh doInsertTrPointsDetail end "); | ||
| 406 | |||
| 407 | // 4.添加可用积分 | ||
| 408 | log.info("----------->> refresh doInsertTrPointsAvailable start "); | ||
| 359 | this.doInsertTrPointsAvailable(tempPoints); | 409 | this.doInsertTrPointsAvailable(tempPoints); |
| 410 | log.info("----------->> refresh doInsertTrPointsAvailable end "); | ||
| 411 | |||
| 412 | // 即将过期的积分 | ||
| 413 | long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints); | ||
| 414 | |||
| 415 | // 6.更新会员的总积分 | ||
| 416 | log.info("----------->> refresh freshMemberCurrentPoints start "); | ||
| 417 | this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints); | ||
| 418 | log.info("----------->> refresh freshMemberCurrentPoints end "); | ||
| 419 | |||
| 360 | } catch (Exception e) { | 420 | } catch (Exception e) { |
| 361 | e.printStackTrace(); | 421 | e.printStackTrace(); |
| 362 | throw e; | 422 | throw e; |
| ... | @@ -371,11 +431,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -371,11 +431,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 371 | * @param currentPoints | 431 | * @param currentPoints |
| 372 | * @return | 432 | * @return |
| 373 | */ | 433 | */ |
| 374 | private long calculateTotalPoints(TempPoints tempPoints, long currentPoints) { | 434 | private Long calculateTotalPoints(TempPoints tempPoints, Long currentPoints) { |
| 375 | // 获取的积分 | 435 | // 获取的积分 |
| 376 | long rewardPoints = tempPoints.getPoints(); | 436 | Long rewardPoints = tempPoints.getPoints(); |
| 377 | // 总积分 | 437 | // 总积分 |
| 378 | long totalPoints = currentPoints + rewardPoints; | 438 | Long totalPoints = currentPoints + rewardPoints; |
| 379 | return totalPoints; | 439 | return totalPoints; |
| 380 | } | 440 | } |
| 381 | 441 | ||
| ... | @@ -410,11 +470,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -410,11 +470,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 410 | * @param memberId 会员Id | 470 | * @param memberId 会员Id |
| 411 | * @param currentPoints 当前总积分 | 471 | * @param currentPoints 当前总积分 |
| 412 | */ | 472 | */ |
| 413 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints) { | 473 | private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints) { |
| 414 | Member member = new Member(); | 474 | Member member = new Member(); |
| 415 | member.setId(memberId); | 475 | member.setId(memberId); |
| 416 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); | 476 | member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); |
| 417 | // member.setDuePoints(duePoints); | 477 | member.setDuePoints(duePoints); |
| 418 | member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); | 478 | member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); |
| 419 | try { | 479 | try { |
| 420 | this.memberOperationService.doUpdateMemberPoints(member); | 480 | this.memberOperationService.doUpdateMemberPoints(member); |
| ... | @@ -428,9 +488,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -428,9 +488,9 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 428 | * @param memberId 会员id | 488 | * @param memberId 会员id |
| 429 | * @return | 489 | * @return |
| 430 | */ | 490 | */ |
| 431 | private long findAvailablePointsByMemberId(long memberId){ | 491 | private Long findAvailablePointsByMemberId(long memberId){ |
| 432 | long availablePointsByMemberId = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); | 492 | Long availablePoints = this.pointsAvailableService.findAvailablePointsByMemberId(memberId); |
| 433 | return availablePointsByMemberId; | 493 | return Objects.nonNull(availablePoints) ? availablePoints : 0L; |
| 434 | } | 494 | } |
| 435 | 495 | ||
| 436 | /** | 496 | /** |
| ... | @@ -468,23 +528,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -468,23 +528,18 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 468 | * @param tempPoints 积分 | 528 | * @param tempPoints 积分 |
| 469 | * @return Integer 总积分 | 529 | * @return Integer 总积分 |
| 470 | */ | 530 | */ |
| 471 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long totalPoints,long currentPoints){ | 531 | private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,Long currentPoints,Long totalPoints){ |
| 472 | 532 | ||
| 473 | PointsDetail pointsDetail = new PointsDetail(); | 533 | PointsDetail pointsDetail = new PointsDetail(); |
| 474 | BeanUtils.copyProperties(tempPoints,pointsDetail); | 534 | BeanUtils.copyProperties(tempPoints,pointsDetail); |
| 475 | 535 | pointsDetail.setId(null); | |
| 476 | /* // 获取的积分 | ||
| 477 | long rewardPoints = tempPoints.getPoints(); | ||
| 478 | // 原始积分 | ||
| 479 | long originalPoints = currentPoints; | ||
| 480 | // 总积分 | ||
| 481 | long totalPoints = originalPoints + rewardPoints;*/ | ||
| 482 | |||
| 483 | pointsDetail.setMemberId(memberId); | 536 | pointsDetail.setMemberId(memberId); |
| 484 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); | 537 | pointsDetail.setCode(String.valueOf(IdWorker.generator())); |
| 485 | 538 | pointsDetail.setPoints(tempPoints.getPoints()); | |
| 486 | pointsDetail.setOriginalPoints(currentPoints); | 539 | pointsDetail.setOriginalPoints(currentPoints); |
| 487 | pointsDetail.setResultPoints(totalPoints); | 540 | pointsDetail.setResultPoints(totalPoints); |
| 541 | pointsDetail.setCreateTime(null); | ||
| 542 | pointsDetail.setUpdateTime(null); | ||
| 488 | String description = pointsDetail.getDescription(); | 543 | String description = pointsDetail.getDescription(); |
| 489 | if (StringUtils.isEmpty(description)) { | 544 | if (StringUtils.isEmpty(description)) { |
| 490 | 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; |
| ... | @@ -17,10 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired; | ... | @@ -17,10 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
| 17 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 19 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 18 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 19 | import org.springframework.util.CollectionUtils; | 21 | import org.springframework.util.CollectionUtils; |
| 22 | import org.springframework.util.StringUtils; | ||
| 20 | 23 | ||
| 21 | import javax.annotation.Resource; | ||
| 22 | import java.sql.Timestamp; | ||
| 23 | import java.util.*; | 24 | import java.util.*; |
| 25 | import java.util.concurrent.*; | ||
| 24 | 26 | ||
| 25 | /** | 27 | /** |
| 26 | * 权益处理 | 28 | * 权益处理 |
| ... | @@ -44,9 +46,13 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -44,9 +46,13 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 44 | ExpOperationService expOperationService; | 46 | ExpOperationService expOperationService; |
| 45 | @Autowired | 47 | @Autowired |
| 46 | PointsOperationService pointsOperationService; | 48 | PointsOperationService pointsOperationService; |
| 49 | @Autowired | ||
| 50 | CouponService couponService; | ||
| 51 | |||
| 52 | // @Autowired | ||
| 53 | // ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 47 | 54 | ||
| 48 | @Resource(name = "executorTask") | 55 | private ExecutorService threadPoolTaskExecutor = Executors.newFixedThreadPool(10); |
| 49 | ThreadPoolTaskExecutor threadPoolTaskExecutor; | ||
| 50 | 56 | ||
| 51 | /** | 57 | /** |
| 52 | * 系统手动发放 | 58 | * 系统手动发放 |
| ... | @@ -71,16 +77,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -71,16 +77,15 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 71 | @Override | 77 | @Override |
| 72 | public void grantRights(Map<RightType, Object> tempRightsMap) { | 78 | public void grantRights(Map<RightType, Object> tempRightsMap) { |
| 73 | 79 | ||
| 74 | this.threadPoolTaskExecutor.execute(()-> { | 80 | // this.threadPoolTaskExecutor.execute(()-> { |
| 75 | // 2.创建权益历史对象 | 81 | // 2.创建权益历史对象 |
| 76 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); | 82 | List<RightsHistory> rightsList = this.getRightHistory(tempRightsMap); |
| 77 | // 3.保存权益历史 | 83 | // 3.保存权益历史 |
| 78 | this.doInsertTrRightHistory(rightsList); | 84 | this.doInsertTrRightHistory(rightsList); |
| 79 | }); | 85 | // }); |
| 80 | 86 | ||
| 81 | // 1.权益下发 | 87 | // 1.权益下发 |
| 82 | this.refresh(tempRightsMap); | 88 | this.refresh(tempRightsMap); |
| 83 | |||
| 84 | } | 89 | } |
| 85 | 90 | ||
| 86 | /** | 91 | /** |
| ... | @@ -104,7 +109,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -104,7 +109,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 104 | return rightsHistoryList; | 109 | return rightsHistoryList; |
| 105 | } | 110 | } |
| 106 | 111 | ||
| 107 | |||
| 108 | /** | 112 | /** |
| 109 | * 成长值发放,基于已获得的权益 | 113 | * 成长值发放,基于已获得的权益 |
| 110 | * @param tempExpList 权益列表 | 114 | * @param tempExpList 权益列表 |
| ... | @@ -114,18 +118,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -114,18 +118,18 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 114 | this.expOperationService.grantPointsThroughTempExp(tempExpList); | 118 | this.expOperationService.grantPointsThroughTempExp(tempExpList); |
| 115 | } | 119 | } |
| 116 | 120 | ||
| 117 | |||
| 118 | /** | 121 | /** |
| 119 | * 发放积分,基于已获得的权益 | 122 | * 发放积分,基于已获得的权益 |
| 120 | * | 123 | * |
| 121 | * @param tempPointsList 权益列表 | 124 | * @param tempPointsList 权益列表 |
| 122 | */ | 125 | */ |
| 123 | private void grantPoint(List<TempPoints> tempPointsList) { | 126 | private void grantPoint(List<TempPoints> tempPointsList) { |
| 127 | log.info(Thread.currentThread().getName() + "=========>>grantPoint start"); | ||
| 124 | if (!CollectionUtils.isEmpty(tempPointsList)) | 128 | if (!CollectionUtils.isEmpty(tempPointsList)) |
| 129 | log.info("=======>> tempPointsList ======>> " + tempPointsList.toString()); | ||
| 125 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); | 130 | this.pointsOperationService.grantPointsThroughTempRightsList(tempPointsList); |
| 126 | } | 131 | } |
| 127 | 132 | ||
| 128 | |||
| 129 | /** | 133 | /** |
| 130 | * 发放优惠券,基于已获得的权益 | 134 | * 发放优惠券,基于已获得的权益 |
| 131 | * | 135 | * |
| ... | @@ -137,31 +141,78 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -137,31 +141,78 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 137 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); | 141 | this.couponOperationService.grantCouponThroughTempCoupon(tempCouponList); |
| 138 | } | 142 | } |
| 139 | 143 | ||
| 140 | |||
| 141 | /** | 144 | /** |
| 142 | * 权益发放 | 145 | * 权益发放 |
| 143 | * @param tempRightsMap | 146 | * @param tempRightsMap |
| 144 | */ | 147 | */ |
| 145 | private void refresh(Map<RightType, Object> tempRightsMap) { | 148 | private void refresh(Map<RightType, Object> tempRightsMap) { |
| 146 | 149 | /*FutureTask<Map<Long,Long>> futureTask1 = new FutureTask(()->{ | |
| 147 | this.threadPoolTaskExecutor.execute(()->{ | 150 | log.info(Thread.currentThread().getName() + "=========>> start"); |
| 148 | // 积分 | 151 | // 积分 |
| 149 | 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; | ||
| 150 | }); | 159 | }); |
| 151 | 160 | FutureTask<Map<Long,Long>> futureTask2 = new FutureTask(()->{ | |
| 152 | this.threadPoolTaskExecutor.execute(()->{ | 161 | // 积分 |
| 162 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 153 | // 成长值 | 163 | // 成长值 |
| 154 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | 164 | this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); |
| 165 | // 优惠券 | ||
| 166 | // this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); | ||
| 167 | return null; | ||
| 155 | }); | 168 | }); |
| 156 | 169 | FutureTask<Map<Long,Long>> futureTask3 = new FutureTask(()->{ | |
| 157 | this.threadPoolTaskExecutor.execute(()->{ | 170 | // 积分 |
| 171 | // this.grantPoint((List<TempPoints>) tempRightsMap.get(RightType.POINTS)); | ||
| 172 | // 成长值 | ||
| 173 | // this.grantExp((List<TempExp>) tempRightsMap.get(RightType.EXP)); | ||
| 158 | // 优惠券 | 174 | // 优惠券 |
| 159 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON)); | 175 | this.grantCoupon((List<TempCoupon>) tempRightsMap.get(RightType.COUPON)); |
| 176 | return null; | ||
| 160 | }); | 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 | } | ||
| 161 | 215 | ||
| 162 | /*this.grantPoint((List<TempPoints>)tempRightsMap.get(RightType.POINTS)); | ||
| 163 | this.grantExp((List<TempExp>)tempRightsMap.get(RightType.EXP)); | ||
| 164 | this.grantCoupon((List<TempCoupon>)tempRightsMap.get(RightType.COUPON));*/ | ||
| 165 | } | 216 | } |
| 166 | 217 | ||
| 167 | /** | 218 | /** |
| ... | @@ -175,8 +226,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -175,8 +226,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 175 | 226 | ||
| 176 | // 优惠券 | 227 | // 优惠券 |
| 177 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 228 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
| 178 | List<TempExp> tempExpList = new ArrayList<>(); | ||
| 179 | List<TempPoints> tempPointsList = new ArrayList<>(); | ||
| 180 | 229 | ||
| 181 | for (RightsHistory right : rightsList) { | 230 | for (RightsHistory right : rightsList) { |
| 182 | Long rightId = right.getRightsId(); | 231 | Long rightId = right.getRightsId(); |
| ... | @@ -186,62 +235,55 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -186,62 +235,55 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 186 | RightsDTO rightsDTO = this.getRights(rightId); | 235 | RightsDTO rightsDTO = this.getRights(rightId); |
| 187 | // 权益的实体类型 1:积分;2成长值;3优惠券 | 236 | // 权益的实体类型 1:积分;2成长值;3优惠券 |
| 188 | String type = rightsDTO.getEntityType(); | 237 | String type = rightsDTO.getEntityType(); |
| 189 | String code = rightsDTO.getCode(); | ||
| 190 | Long expireTime = rightsDTO.getExpireTime(); | 238 | Long expireTime = rightsDTO.getExpireTime(); |
| 191 | Timestamp validTime = rightsDTO.getValidTime(); | ||
| 192 | |||
| 193 | 239 | ||
| 194 | switch (type) { | 240 | switch (type) { |
| 195 | // 优惠券 | 241 | // 优惠券 |
| 196 | case "3": | 242 | case "1": |
| 243 | Long entityId = rightsDTO.getEntityId(); | ||
| 244 | CouponDTO couponDTO = this.findCouponById(entityId); | ||
| 245 | if (Objects.nonNull(couponDTO)) { | ||
| 197 | TempCoupon tempCoupon = new TempCoupon(); | 246 | TempCoupon tempCoupon = new TempCoupon(); |
| 198 | tempCoupon.setId(rightId); | 247 | tempCoupon.setId(couponDTO.getId()); |
| 199 | tempCoupon.setMemberId(memberId); | 248 | tempCoupon.setMemberId(memberId); |
| 200 | tempCoupon.setUserId(userId); | 249 | tempCoupon.setUserId(userId); |
| 201 | tempCoupon.setRightsAmount(1); | 250 | tempCoupon.setRightsAmount(1); |
| 202 | tempCoupon.setRightsSendStrategy(0); | 251 | tempCoupon.setRightsSendStrategy(0); |
| 252 | tempCoupon.setCode(couponDTO.getCode()); | ||
| 253 | if (Objects.nonNull(expireTime)) | ||
| 203 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); | 254 | tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); |
| 204 | tempCouponList.add(tempCoupon); | 255 | tempCouponList.add(tempCoupon); |
| 256 | } | ||
| 205 | break; | 257 | break; |
| 206 | // 成长值 | 258 | // 观影券 |
| 207 | case "2": | 259 | case "2": |
| 208 | TempExp tempExp = new TempExp(); | ||
| 209 | tempExp.setId(rightId); | ||
| 210 | tempExp.setMemberId(memberId); | ||
| 211 | tempExp.setUserId(userId); | ||
| 212 | tempExp.setRightsAmount(1); | ||
| 213 | tempExp.setRightsSendStrategy(0); | ||
| 214 | tempExpList.add(tempExp); | ||
| 215 | break; | 260 | break; |
| 216 | // 积分 | 261 | // 活动参与机会 |
| 217 | case "1": | 262 | case "3": |
| 218 | TempPoints tempPoints = new TempPoints(); | 263 | break; |
| 219 | tempPoints.setId(rightId); | 264 | |
| 220 | tempPoints.setMemberId(memberId); | 265 | default: |
| 221 | tempPoints.setUserId(userId); | ||
| 222 | tempPoints.setRightsAmount(1); | ||
| 223 | tempPoints.setRightsSendStrategy(0); | ||
| 224 | tempPointsList.add(tempPoints); | ||
| 225 | break; | 266 | break; |
| 226 | } | 267 | } |
| 227 | } | 268 | } |
| 228 | 269 | ||
| 229 | // TODO 其他 | ||
| 230 | |||
| 231 | // 优惠券 | 270 | // 优惠券 |
| 232 | if (!CollectionUtils.isEmpty(tempCouponList)) | 271 | if (!CollectionUtils.isEmpty(tempCouponList)) |
| 233 | map.put(RightType.COUPON,tempCouponList); | 272 | map.put(RightType.COUPON,tempCouponList); |
| 234 | // 成长值 | ||
| 235 | if (!CollectionUtils.isEmpty(tempExpList)) | ||
| 236 | map.put(RightType.EXP,tempExpList); | ||
| 237 | // 积分 | ||
| 238 | if (!CollectionUtils.isEmpty(tempPointsList)) | ||
| 239 | map.put(RightType.POINTS,tempPointsList); | ||
| 240 | |||
| 241 | return map; | 273 | return map; |
| 242 | } | 274 | } |
| 243 | 275 | ||
| 244 | /** | 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 | /** | ||
| 245 | * 权益详情 | 287 | * 权益详情 |
| 246 | * @param rightsId | 288 | * @param rightsId |
| 247 | * @return | 289 | * @return |
| ... | @@ -260,8 +302,11 @@ public class RightsOperationServiceImpl implements RightsOperationService { | ... | @@ -260,8 +302,11 @@ public class RightsOperationServiceImpl implements RightsOperationService { |
| 260 | if (!CollectionUtils.isEmpty(rightsHistories)) { | 302 | if (!CollectionUtils.isEmpty(rightsHistories)) { |
| 261 | 303 | ||
| 262 | for (RightsHistory rightsHistory : rightsHistories) { | 304 | for (RightsHistory rightsHistory : rightsHistories) { |
| 305 | Long operatorId = rightsHistory.getOperatorId(); | ||
| 306 | String operatorName = rightsHistory.getOperatorName(); | ||
| 263 | rightsHistory.setSendTime(TimestampUtil.now()); | 307 | rightsHistory.setSendTime(TimestampUtil.now()); |
| 264 | 308 | rightsHistory.setOperatorId(Objects.nonNull(operatorId)?operatorId:0); | |
| 309 | rightsHistory.setOperatorName(!StringUtils.isEmpty(operatorName)?operatorName:"系统发放"); | ||
| 265 | this.rightsHistoryService.create(rightsHistory); | 310 | this.rightsHistoryService.create(rightsHistory); |
| 266 | } | 311 | } |
| 267 | 312 | ... | ... |
| 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,30 +23,24 @@ import com.topdraw.business.basicdata.task.service.TaskService; | ... | @@ -18,30 +23,24 @@ 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; |
| 25 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; | 30 | import org.slf4j.LoggerFactory; |
| 31 | import org.springframework.beans.BeanUtils; | ||
| 27 | import org.springframework.beans.factory.annotation.Autowired; | 32 | import org.springframework.beans.factory.annotation.Autowired; |
| 28 | import org.springframework.cache.annotation.CacheEvict; | ||
| 29 | import org.springframework.cache.annotation.Cacheable; | ||
| 30 | import org.springframework.cache.annotation.EnableCaching; | ||
| 31 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 32 | import org.springframework.stereotype.Service; | 33 | import org.springframework.stereotype.Service; |
| 33 | import org.springframework.util.CollectionUtils; | 34 | import org.springframework.util.CollectionUtils; |
| 34 | import org.springframework.util.StringUtils; | 35 | import org.springframework.util.StringUtils; |
| 35 | 36 | ||
| 36 | import javax.annotation.Resource; | ||
| 37 | import java.math.BigDecimal; | 37 | import java.math.BigDecimal; |
| 38 | import java.math.RoundingMode; | 38 | import java.math.RoundingMode; |
| 39 | import java.sql.Timestamp; | 39 | import java.sql.Timestamp; |
| 40 | import java.time.LocalDate; | 40 | import java.time.LocalDate; |
| 41 | import java.util.*; | 41 | import java.util.*; |
| 42 | import java.util.concurrent.locks.ReentrantLock; | 42 | |
| 43 | import java.util.concurrent.locks.ReentrantReadWriteLock; | 43 | import static java.util.stream.Collectors.toList; |
| 44 | import java.util.stream.Collectors; | ||
| 45 | 44 | ||
| 46 | /** | 45 | /** |
| 47 | * 任务处理 | 46 | * 任务处理 |
| ... | @@ -56,21 +55,23 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -56,21 +55,23 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 56 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); | 55 | private static final Logger LOG = LoggerFactory.getLogger(PointsOperationServiceImpl.class); |
| 57 | 56 | ||
| 58 | @Autowired | 57 | @Autowired |
| 59 | private TaskService taskService; | 58 | TaskService taskService; |
| 60 | @Autowired | 59 | @Autowired |
| 61 | private MemberService memberService; | 60 | MemberService memberService; |
| 62 | @Autowired | 61 | @Autowired |
| 63 | private RightsService rightsService; | 62 | RightsService rightsService; |
| 64 | @Autowired | 63 | @Autowired |
| 65 | private TaskTemplateService taskTemplateService; | 64 | TaskTemplateService taskTemplateService; |
| 66 | @Autowired | 65 | @Autowired |
| 67 | private RightsOperationService rightsOperationService; | 66 | RightsOperationService rightsOperationService; |
| 68 | @Autowired | 67 | @Autowired |
| 69 | private TrTaskProgressService trTaskProgressService; | 68 | TrTaskProgressService trTaskProgressService; |
| 70 | @Autowired | 69 | @Autowired |
| 71 | private PermanentRightsService permanentRightsService; | 70 | PermanentRightsService permanentRightsService; |
| 72 | 71 | @Autowired | |
| 73 | private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(); | 72 | CouponService couponService; |
| 73 | @Autowired | ||
| 74 | MemberGroupService memberGroupService; | ||
| 74 | 75 | ||
| 75 | private static final Integer TASK_FINISH_STATUS = 1; | 76 | private static final Integer TASK_FINISH_STATUS = 1; |
| 76 | private static final Integer TASK_UNFINISH_STATUS = 2; | 77 | private static final Integer TASK_UNFINISH_STATUS = 2; |
| ... | @@ -86,11 +87,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -86,11 +87,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 86 | Long memberId = msgData.getMemberId(); | 87 | Long memberId = msgData.getMemberId(); |
| 87 | 88 | ||
| 88 | long l = System.currentTimeMillis(); | 89 | long l = System.currentTimeMillis(); |
| 89 | // 验证会员信息 | ||
| 90 | boolean b = this.validatedMember(memberId); | ||
| 91 | if (b) { | ||
| 92 | throw new BadRequestException("【member status exception!!】"); | ||
| 93 | } | ||
| 94 | 90 | ||
| 95 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 | 91 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 |
| 96 | TaskTemplate taskTemplate = this.getTaskTemplate(event); | 92 | TaskTemplate taskTemplate = this.getTaskTemplate(event); |
| ... | @@ -99,9 +95,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -99,9 +95,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 99 | // 4.判断当前用户是否满足任务完成条件 | 95 | // 4.判断当前用户是否满足任务完成条件 |
| 100 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); | 96 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); |
| 101 | if (checkResult) { | 97 | if (checkResult) { |
| 98 | |||
| 102 | // 5.权益区分(积分、权益、成长值) | 99 | // 5.权益区分(积分、权益、成长值) |
| 103 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 100 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); |
| 104 | |||
| 105 | // 6.权益发放 | 101 | // 6.权益发放 |
| 106 | this.grantRight(tempRightsMap); | 102 | this.grantRight(tempRightsMap); |
| 107 | 103 | ||
| ... | @@ -120,12 +116,13 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -120,12 +116,13 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 120 | private boolean validatedMember(Long memberId) { | 116 | private boolean validatedMember(Long memberId) { |
| 121 | log.info("validatedMember -->>【memberId】 -->> " + memberId); | 117 | log.info("validatedMember -->>【memberId】 -->> " + memberId); |
| 122 | MemberDTO memberDTO = this.memberService.findById(memberId); | 118 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| 123 | Integer blackStatus = memberDTO.getBlackStatus(); | 119 | Long blackStatus = memberDTO.getBlackStatus(); |
| 124 | if (Objects.nonNull(blackStatus) && blackStatus == 1) { | 120 | // TODO 检查balckStatus无法获取的原因 |
| 125 | log.error("validatedMember -->> 会员已被加入黑名单 【blackStatus】 -->> " + blackStatus); | 121 | if (Objects.isNull(blackStatus) || blackStatus == 1) { |
| 122 | log.error("validatedMember -->> 会员不存在或者已被加入黑名单 【blackStatus】 -->> " + blackStatus); | ||
| 126 | return false; | 123 | return false; |
| 127 | } | 124 | } |
| 128 | return Objects.nonNull(memberDTO) ? true:false; | 125 | return true; |
| 129 | } | 126 | } |
| 130 | 127 | ||
| 131 | /** | 128 | /** |
| ... | @@ -133,6 +130,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -133,6 +130,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 133 | * @param memberId 会员id | 130 | * @param memberId 会员id |
| 134 | * @return PermanentRightsDTO 永久权益 | 131 | * @return PermanentRightsDTO 永久权益 |
| 135 | */ | 132 | */ |
| 133 | @Deprecated | ||
| 136 | private PermanentRightsDTO getPermanentRights(Long memberId) { | 134 | private PermanentRightsDTO getPermanentRights(Long memberId) { |
| 137 | PermanentRightsDTO permanentRights = null; | 135 | PermanentRightsDTO permanentRights = null; |
| 138 | MemberDTO memberDTO = this.memberService.findById(memberId); | 136 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| ... | @@ -149,6 +147,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -149,6 +147,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 149 | * @param taskTemplate 任务模板 | 147 | * @param taskTemplate 任务模板 |
| 150 | * @return Map<String, Object> 模板参数解析结果 | 148 | * @return Map<String, Object> 模板参数解析结果 |
| 151 | */ | 149 | */ |
| 150 | @Deprecated | ||
| 152 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { | 151 | private Map<String, Object> parseTaskTemplateParam(TaskTemplate taskTemplate) { |
| 153 | if (Objects.nonNull(taskTemplate)) { | 152 | if (Objects.nonNull(taskTemplate)) { |
| 154 | String params = taskTemplate.getParams(); | 153 | String params = taskTemplate.getParams(); |
| ... | @@ -166,20 +165,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -166,20 +165,12 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 166 | */ | 165 | */ |
| 167 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { | 166 | private void doRefreshTrTaskProcess(TrTaskProgress resources) { |
| 168 | Long id = resources.getId(); | 167 | Long id = resources.getId(); |
| 169 | ReentrantReadWriteLock.WriteLock writeLock = this.reentrantReadWriteLock.writeLock(); | ||
| 170 | try { | ||
| 171 | writeLock.lock(); | ||
| 172 | if (Objects.nonNull(id)) { | 168 | if (Objects.nonNull(id)) { |
| 173 | resources.setUpdateTime(TimestampUtil.now()); | 169 | resources.setUpdateTime(TimestampUtil.now()); |
| 174 | this.trTaskProgressService.update(resources); | 170 | this.trTaskProgressService.update(resources); |
| 175 | } else { | 171 | } else { |
| 176 | this.trTaskProgressService.create(resources); | 172 | this.trTaskProgressService.create(resources); |
| 177 | } | 173 | } |
| 178 | } catch (Exception e) { | ||
| 179 | e.printStackTrace(); | ||
| 180 | } finally { | ||
| 181 | writeLock.unlock(); | ||
| 182 | } | ||
| 183 | } | 174 | } |
| 184 | 175 | ||
| 185 | /** | 176 | /** |
| ... | @@ -326,16 +317,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -326,16 +317,15 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 326 | /** | 317 | /** |
| 327 | * 创建权益 | 318 | * 创建权益 |
| 328 | * @param memberId | 319 | * @param memberId |
| 329 | * @param rightsId | ||
| 330 | * @param rightsAmount | 320 | * @param rightsAmount |
| 331 | * @param expireTime | ||
| 332 | * @return | 321 | * @return |
| 333 | */ | 322 | */ |
| 334 | private TempRights tmpRightsBuild(Long memberId ,Long rightsId, Integer rightsAmount,Long expireTime){ | 323 | private TempRights tmpRightsBuild(Long memberId ,Integer rightsAmount,RightsDTO rightsDTO){ |
| 335 | TempRights tempRights = new TempRights(); | 324 | TempRights tempRights = new TempRights(); |
| 325 | BeanUtils.copyProperties(rightsDTO,tempRights); | ||
| 336 | tempRights.setMemberId(memberId); | 326 | tempRights.setMemberId(memberId); |
| 337 | tempRights.setRightsAmount(rightsAmount); | 327 | tempRights.setRightsAmount(rightsAmount); |
| 338 | tempRights.setId(rightsId); | 328 | Long expireTime = rightsDTO.getExpireTime(); |
| 339 | if (Objects.nonNull(expireTime)) | 329 | if (Objects.nonNull(expireTime)) |
| 340 | tempRights.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); | 330 | tempRights.setExpireTime(TimestampUtil.long2Timestamp(expireTime)); |
| 341 | return tempRights; | 331 | return tempRights; |
| ... | @@ -344,17 +334,18 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -344,17 +334,18 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 344 | /** | 334 | /** |
| 345 | * 优惠券 | 335 | * 优惠券 |
| 346 | * @param memberId | 336 | * @param memberId |
| 347 | * @param rightsId | ||
| 348 | * @param rightsAmount | 337 | * @param rightsAmount |
| 349 | * @param rightsSendStrategy | 338 | * @param rightsSendStrategy |
| 350 | * @return | 339 | * @return |
| 351 | */ | 340 | */ |
| 352 | private TempCoupon tempCouponBuild(Long memberId ,Long rightsId, Integer rightsAmount,Integer rightsSendStrategy){ | 341 | private TempCoupon tempCouponBuild(Long memberId ,Integer rightsAmount,Integer rightsSendStrategy,CouponDTO couponDTO,String nickname){ |
| 353 | TempCoupon tempCoupon = new TempCoupon(); | 342 | TempCoupon tempCoupon = new TempCoupon(); |
| 343 | BeanUtils.copyProperties(couponDTO,tempCoupon); | ||
| 344 | tempCoupon.setCode(couponDTO.getCode()); | ||
| 354 | tempCoupon.setMemberId(memberId); | 345 | tempCoupon.setMemberId(memberId); |
| 355 | tempCoupon.setId(rightsId); | ||
| 356 | tempCoupon.setRightsAmount(rightsAmount); | 346 | tempCoupon.setRightsAmount(rightsAmount); |
| 357 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); | 347 | tempCoupon.setRightsSendStrategy(Objects.isNull(rightsSendStrategy) ? 0 : rightsSendStrategy); |
| 348 | tempCoupon.setUserNickname(nickname); | ||
| 358 | return tempCoupon; | 349 | return tempCoupon; |
| 359 | } | 350 | } |
| 360 | 351 | ||
| ... | @@ -369,6 +360,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -369,6 +360,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 369 | List<TempCoupon> tempCouponList = new ArrayList<>(); | 360 | List<TempCoupon> tempCouponList = new ArrayList<>(); |
| 370 | // 权益列表,用以保存权益记录 | 361 | // 权益列表,用以保存权益记录 |
| 371 | List<TempRights> rightsList = new ArrayList<>(); | 362 | List<TempRights> rightsList = new ArrayList<>(); |
| 363 | // 会员信息 | ||
| 364 | MemberDTO memberDTO = this.findMemberById(memberId); | ||
| 372 | 365 | ||
| 373 | // 权益1 | 366 | // 权益1 |
| 374 | Long rights1Id = task.getRightsId(); | 367 | Long rights1Id = task.getRightsId(); |
| ... | @@ -378,7 +371,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -378,7 +371,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 378 | // TODO 权益1发放的策略 | 371 | // TODO 权益1发放的策略 |
| 379 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 372 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
| 380 | // 权益分类 | 373 | // 权益分类 |
| 381 | this.getTempRightType(memberId,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList); | 374 | this.getTempRightType(memberDTO,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList); |
| 382 | } | 375 | } |
| 383 | 376 | ||
| 384 | // 权益2 | 377 | // 权益2 |
| ... | @@ -388,7 +381,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -388,7 +381,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 388 | // TODO 权益2发放的策略 | 381 | // TODO 权益2发放的策略 |
| 389 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 382 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
| 390 | // 权权益分类 | 383 | // 权权益分类 |
| 391 | this.getTempRightType(memberId,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList); | 384 | this.getTempRightType(memberDTO,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList); |
| 392 | } | 385 | } |
| 393 | 386 | ||
| 394 | // 权益3 | 387 | // 权益3 |
| ... | @@ -398,7 +391,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -398,7 +391,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 398 | // TODO 权益3发放的策略 | 391 | // TODO 权益3发放的策略 |
| 399 | Integer rightsSendStrategy = task.getRightsSendStrategy(); | 392 | Integer rightsSendStrategy = task.getRightsSendStrategy(); |
| 400 | // 权益分类 | 393 | // 权益分类 |
| 401 | this.getTempRightType(memberId,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList); | 394 | this.getTempRightType(memberDTO,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList); |
| 402 | } | 395 | } |
| 403 | // 优惠券 | 396 | // 优惠券 |
| 404 | map.put(RightType.COUPON,tempCouponList); | 397 | map.put(RightType.COUPON,tempCouponList); |
| ... | @@ -406,35 +399,51 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -406,35 +399,51 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 406 | return map; | 399 | return map; |
| 407 | } | 400 | } |
| 408 | 401 | ||
| 402 | |||
| 409 | /** | 403 | /** |
| 410 | * 权益分类 | 404 | * 会员对象 |
| 411 | * @param memberId | 405 | * @param memberId |
| 406 | * @return | ||
| 407 | */ | ||
| 408 | private MemberDTO findMemberById(Long memberId) { | ||
| 409 | return this.memberService.findById(memberId); | ||
| 410 | } | ||
| 411 | |||
| 412 | /** | ||
| 413 | * 权益分类 | ||
| 414 | * @param memberDTO | ||
| 412 | * @param rightsId | 415 | * @param rightsId |
| 413 | * @param rightsAmount | 416 | * @param rightsAmount |
| 414 | * @param rightsSendStrategy | 417 | * @param rightsSendStrategy |
| 415 | * @param tempCouponList | 418 | * @param tempCouponList |
| 416 | * @param rightsList | 419 | * @param rightsList |
| 417 | */ | 420 | */ |
| 418 | private void getTempRightType(Long memberId , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, | 421 | private void getTempRightType(MemberDTO memberDTO , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList, |
| 419 | List<TempRights> rightsList) { | 422 | List<TempRights> rightsList) { |
| 420 | 423 | ||
| 421 | 424 | Long memberId = memberDTO.getId(); | |
| 425 | String nickname = memberDTO.getNickname(); | ||
| 422 | // 权益详情 | 426 | // 权益详情 |
| 423 | RightsDTO rightsDTO = this.getRight(rightsId); | 427 | RightsDTO rightsDTO = this.getRight(rightsId); |
| 424 | 428 | ||
| 425 | if (Objects.nonNull(rightsDTO)){ | 429 | if (Objects.nonNull(rightsDTO)){ |
| 426 | // 用以保存权益历史 | 430 | // 用以保存权益历史 |
| 427 | Long expireTime = rightsDTO.getExpireTime(); | 431 | TempRights tempRights = this.tmpRightsBuild(memberId,rightsAmount,rightsDTO); |
| 428 | TempRights tempRights = this.tmpRightsBuild(memberId,rightsId,rightsAmount,expireTime); | ||
| 429 | rightsList.add(tempRights); | 432 | rightsList.add(tempRights); |
| 430 | 433 | ||
| 431 | // 权益类型 | 434 | // 权益类型 |
| 432 | String type = rightsDTO.getEntityType(); | 435 | String type = rightsDTO.getEntityType(); |
| 433 | switch (type) { | 436 | switch (type) { |
| 434 | 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)) { | ||
| 435 | // 优惠券 | 442 | // 优惠券 |
| 436 | TempCoupon tempCoupon = this.tempCouponBuild(memberId,rightsId,rightsAmount,rightsSendStrategy); | 443 | TempCoupon tempCoupon = this.tempCouponBuild(memberId, rightsAmount, rightsSendStrategy, couponDTO, nickname); |
| 437 | tempCouponList.add(tempCoupon); | 444 | tempCouponList.add(tempCoupon); |
| 445 | } | ||
| 446 | } | ||
| 438 | break; | 447 | break; |
| 439 | default: | 448 | default: |
| 440 | break; | 449 | break; |
| ... | @@ -443,6 +452,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -443,6 +452,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 443 | } | 452 | } |
| 444 | 453 | ||
| 445 | /** | 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 | /** | ||
| 446 | * | 465 | * |
| 447 | * @param rightsId | 466 | * @param rightsId |
| 448 | * @return | 467 | * @return |
| ... | @@ -528,7 +547,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -528,7 +547,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 528 | * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次 | 547 | * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次 |
| 529 | * 5. member_level 会员等级门槛(0表示无门槛) | 548 | * 5. member_level 会员等级门槛(0表示无门槛) |
| 530 | * 6. member_vip 会员vip门槛(0表示没有门槛) | 549 | * 6. member_vip 会员vip门槛(0表示没有门槛) |
| 531 | * 7. groups 能够获取该任务的用户分组,为空则都能获取 | 550 | * 7. groups 能够获取该任务的用户分组,为空则都能获取 , 0 |
| 532 | * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发) | 551 | * 8. action_amount 行为量(完成此任务需要多少次相同行为的触发) |
| 533 | * | 552 | * |
| 534 | * @param taskList 任务列表 | 553 | * @param taskList 任务列表 |
| ... | @@ -539,24 +558,33 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -539,24 +558,33 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 539 | if (!CollectionUtils.isEmpty(taskList)) { | 558 | if (!CollectionUtils.isEmpty(taskList)) { |
| 540 | // 会员信息 | 559 | // 会员信息 |
| 541 | MemberDTO memberDTO = this.memberService.findById(memberId); | 560 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| 561 | |||
| 542 | // 判断是否完成任务 | 562 | // 判断是否完成任务 |
| 543 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { | 563 | CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { |
| 544 | 564 | ||
| 545 | List<Task> taskStream = taskList1.stream().filter(task1 -> | 565 | List<Task> taskStream = taskList1.stream().filter(task1 -> |
| 546 | task1.getStatus() == 1 && | 566 | task1.getStatus() == 1 && |
| 547 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && | 567 | (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && |
| 548 | (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && | ||
| 549 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && | 568 | (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && |
| 550 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) && | 569 | (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) && |
| 551 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() <= memberDTO1.getVip()) | 570 | (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip()) |
| 552 | ).collect(Collectors.toList()); | 571 | ).collect(toList()); |
| 553 | 572 | ||
| 573 | // 没有满足条件的数据 | ||
| 554 | 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 | |||
| 555 | // 获取当前任务的完成情况 | 583 | // 获取当前任务的完成情况 |
| 556 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); | 584 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); |
| 557 | return result; | 585 | return result; |
| 558 | } | 586 | } |
| 559 | return true; | 587 | |
| 560 | }; | 588 | }; |
| 561 | return compareTaskCondition.compareCondition(memberDTO,taskList); | 589 | return compareTaskCondition.compareCondition(memberDTO,taskList); |
| 562 | } | 590 | } |
| ... | @@ -565,6 +593,96 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -565,6 +593,96 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
| 565 | } | 593 | } |
| 566 | 594 | ||
| 567 | /** | 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 | /** | ||
| 568 | * 检查并更新当前任务的完成情况 | 686 | * 检查并更新当前任务的完成情况 |
| 569 | * | 687 | * |
| 570 | * 1.每天都能做,但要求总次数达到行为量 | 688 | * 1.每天都能做,但要求总次数达到行为量 | ... | ... |
| ... | @@ -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 | ... | ... |
| ... | @@ -8,7 +8,7 @@ public class LocalDateTimeUtil { | ... | @@ -8,7 +8,7 @@ public class LocalDateTimeUtil { |
| 8 | public static String todayStart() { | 8 | public static String todayStart() { |
| 9 | LocalDate now = LocalDate.now(); | 9 | LocalDate now = LocalDate.now(); |
| 10 | 10 | ||
| 11 | return now+" 00:00:00"; | 11 | return now.toString(); |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | public static String todayEnd() { | 14 | public static String todayEnd() { | ... | ... |
| ... | @@ -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,29 +13,46 @@ public class TimestampUtil { | ... | @@ -12,29 +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 | ||
| 25 | public static Timestamp localDateTime2Timestamp(LocalDateTime localDateTime){ | ||
| 26 | long epochSecond = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); | ||
| 27 | return long2Timestamp(epochSecond); | ||
| 28 | } | ||
| 24 | public static Timestamp long2Timestamp(long timestamp){ | 29 | public static Timestamp long2Timestamp(long timestamp){ |
| 25 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochSecond(timestamp)); | 30 | Timestamp timestamp1 = Timestamp.from(Instant.ofEpochMilli(timestamp)); |
| 26 | return timestamp1; | 31 | return timestamp1; |
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | public static long Timestamp2long(Timestamp timestamp){ | 34 | public static long timestamp2long(Timestamp timestamp){ |
| 30 | return timestamp.toInstant().getEpochSecond(); | 35 | long l = timestamp.toInstant().toEpochMilli(); |
| 36 | return l; | ||
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | public static void main(String[] args) { | 39 | public static void main(String[] args) { |
| 34 | LocalDateTime of = LocalDateTime.of(2021, 10, 28, 11, 00, 00); | 40 | long a = 1636616464000L; |
| 35 | long l = localDateTime2Timestamp(of); | 41 | long b = 1637046948588L; |
| 42 | long c = 1637047122176L; | ||
| 43 | // long l = 16342727230L; | ||
| 44 | // Timestamp now = now(LocalDateTime.now()); | ||
| 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); | ||
| 36 | // long l = 16342727230L; | 51 | // long l = 16342727230L; |
| 37 | Timestamp timestamp = long2Timestamp(l); | 52 | // Timestamp timestamp = long2Timestamp(l); |
| 38 | System.out.println(timestamp.toString()); | 53 | System.out.println(timestamp1.toString()); |
| 54 | |||
| 55 | long l1 = localDateTime2long(LocalDateTime.now()); | ||
| 56 | System.out.println(l1); | ||
| 39 | } | 57 | } |
| 40 | } | 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的部分属性。 | ... | ... |
| 1 | server: | 1 | server: |
| 2 | port: 8447 | 2 | port: 8447 |
| 3 | |||
| 4 | spring: | 3 | spring: |
| 5 | application: | 4 | application: |
| 6 | name: member-service | 5 | name: member-service |
| ... | @@ -10,6 +9,8 @@ spring: | ... | @@ -10,6 +9,8 @@ spring: |
| 10 | active: dev | 9 | active: dev |
| 11 | jackson: | 10 | jackson: |
| 12 | time-zone: GMT+8 | 11 | time-zone: GMT+8 |
| 12 | cache: | ||
| 13 | type: simple | ||
| 13 | data: | 14 | data: |
| 14 | redis: | 15 | redis: |
| 15 | repositories: | 16 | repositories: | ... | ... |
| ... | @@ -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 -> { | ... | ... |
| ... | @@ -13,7 +13,7 @@ public class MemberServiceTest extends BaseTest { | ... | @@ -13,7 +13,7 @@ public class MemberServiceTest extends BaseTest { |
| 13 | 13 | ||
| 14 | @Test | 14 | @Test |
| 15 | public void findById(){ | 15 | public void findById(){ |
| 16 | Long memberId = 1L; | 16 | Long memberId = 3L; |
| 17 | MemberDTO memberDTO = this.memberService.findById(memberId); | 17 | MemberDTO memberDTO = this.memberService.findById(memberId); |
| 18 | LOG.info("=====>>>" + memberDTO); | 18 | LOG.info("=====>>>" + memberDTO); |
| 19 | 19 | ... | ... |
| 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 | } |
| ... | @@ -21,12 +21,11 @@ public class ExpOperationControllerTest extends BaseTest { | ... | @@ -21,12 +21,11 @@ public class ExpOperationControllerTest extends BaseTest { |
| 21 | 21 | ||
| 22 | @Test | 22 | @Test |
| 23 | public void grantExpByManual(){ | 23 | public void grantExpByManual(){ |
| 24 | Long memberId = 2L; | 24 | Long memberId = 3L; |
| 25 | Long userId = 2L; | 25 | Long userId = 2L; |
| 26 | TempExp tempExp = new TempExp(); | 26 | TempExp tempExp = new TempExp(); |
| 27 | tempExp.setMemberId(memberId); | 27 | tempExp.setMemberId(memberId); |
| 28 | tempExp.setRewardExp(10L); | 28 | tempExp.setRewardExp(10L); |
| 29 | tempExp.setMemberId(2L); | ||
| 30 | tempExp.setRightsSendStrategy(0); | 29 | tempExp.setRightsSendStrategy(0); |
| 31 | tempExp.setAccountId(userId); | 30 | tempExp.setAccountId(userId); |
| 32 | tempExp.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00")); | 31 | tempExp.setExpireTime(Timestamp.valueOf("2021-10-28 09:00:00")); | ... | ... |
| ... | @@ -53,25 +53,47 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -53,25 +53,47 @@ 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-10-27 09:00:00")); | 61 | tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); |
| 62 | tempPoints.setDeviceType(2); | 62 | tempPoints.setDeviceType(2); |
| 63 | tempPoints.setAppCode("WEI_XIN_GOLD_PANDA"); | 63 | tempPoints.setAppCode("WEI_XIN_GOLD_PANDA"); |
| 64 | tempPoints.setOrderId(null); | 64 | tempPoints.setOrderId(null); |
| 65 | tempPoints.setMediaId(null); | 65 | tempPoints.setMediaId(null); |
| 66 | tempPoints.setActivityId(null); | 66 | tempPoints.setActivityId(null); |
| 67 | tempPoints.setItemId(null); | 67 | tempPoints.setItemId(null); |
| 68 | tempPoints.setDescription("#"); | 68 | tempPoints.setDescription("系统发放"); |
| 69 | tempPoints.setEvtType(1); | 69 | tempPoints.setEvtType(1); |
| 70 | String s = JSON.toJSONString(tempPoints); | 70 | String s = JSON.toJSONString(tempPoints); |
| 71 | ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints); | 71 | ResultInfo byId = this.pointsOperationController.grantPointsByManual(tempPoints); |
| 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(); | ... | ... |
| ... | @@ -18,7 +18,7 @@ public class RightOperationControllerTest extends BaseTest { | ... | @@ -18,7 +18,7 @@ public class RightOperationControllerTest extends BaseTest { |
| 18 | public void grantRightsByManual(){ | 18 | public void grantRightsByManual(){ |
| 19 | RightsHistory rightsHistory = new RightsHistory(); | 19 | RightsHistory rightsHistory = new RightsHistory(); |
| 20 | rightsHistory.setRightsId(1L); | 20 | rightsHistory.setRightsId(1L); |
| 21 | rightsHistory.setMemberId(5L); | 21 | rightsHistory.setMemberId(3L); |
| 22 | rightsHistory.setOperatorId(3L); | 22 | rightsHistory.setOperatorId(3L); |
| 23 | rightsHistory.setOperatorName("鲁二龙"); | 23 | rightsHistory.setOperatorName("鲁二龙"); |
| 24 | rightsHistory.setExpireTime(TimestampUtil.now()); | 24 | rightsHistory.setExpireTime(TimestampUtil.now()); | ... | ... |
| ... | @@ -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