1.添加参加活动、首次消耗积分、完善用户信息任务
Showing
13 changed files
with
93 additions
and
19 deletions
| ... | @@ -73,15 +73,18 @@ public class MemberServiceImpl implements MemberService { | ... | @@ -73,15 +73,18 @@ public class MemberServiceImpl implements MemberService { |
| 73 | @Transactional(readOnly = true) | 73 | @Transactional(readOnly = true) |
| 74 | public MemberSimpleDTO findSimpleById(Long id) { | 74 | public MemberSimpleDTO findSimpleById(Long id) { |
| 75 | Object memberSimpleRedis = this.redisUtils.get(RedisKeyConstants.cacheMemberSimpleById + "::" + id); | 75 | Object memberSimpleRedis = this.redisUtils.get(RedisKeyConstants.cacheMemberSimpleById + "::" + id); |
| 76 | log.info("从redis中获取会员信息, 结果集 dealTask# memberSimpleRedis ==>> {} ", memberSimpleRedis); | ||
| 76 | if (Objects.nonNull(memberSimpleRedis)) { | 77 | if (Objects.nonNull(memberSimpleRedis)) { |
| 77 | return JSONObject.parseObject(JSON.toJSONString(memberSimpleRedis), MemberSimpleDTO.class); | 78 | return JSONObject.parseObject(JSON.toJSONString(memberSimpleRedis), MemberSimpleDTO.class); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | MemberSimple memberSimple = this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new); | 81 | MemberSimple memberSimple = this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new); |
| 82 | log.info("从数据库中获取会员信息, 结果集 dealTask# memberSimple ==>> {} ", memberSimple); | ||
| 81 | if (Objects.nonNull(memberSimple.getId())) { | 83 | if (Objects.nonNull(memberSimple.getId())) { |
| 82 | MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO(); | 84 | MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO(); |
| 83 | BeanUtils.copyProperties(memberSimple, memberSimpleDTO); | 85 | BeanUtils.copyProperties(memberSimple, memberSimpleDTO); |
| 84 | this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO); | 86 | boolean result = this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO); |
| 87 | log.info("将结果存入redis中, dealTask# memberSimpleDTO ==>> {} || 存入结果 ==>> {}", memberSimpleDTO, result); | ||
| 85 | } | 88 | } |
| 86 | return this.memberSimpleMapper.toDto(memberSimple); | 89 | return this.memberSimpleMapper.toDto(memberSimple); |
| 87 | } | 90 | } | ... | ... |
| ... | @@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository; | ... | @@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository; |
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; |
| 4 | import org.springframework.data.jpa.repository.JpaRepository; | 4 | import org.springframework.data.jpa.repository.JpaRepository; |
| 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
| 6 | import org.springframework.data.jpa.repository.Query; | ||
| 6 | 7 | ||
| 8 | import java.util.List; | ||
| 9 | import java.util.Map; | ||
| 7 | import java.util.Optional; | 10 | import java.util.Optional; |
| 11 | import java.util.Set; | ||
| 8 | 12 | ||
| 9 | /** | 13 | /** |
| 10 | * @author XiangHan | 14 | * @author XiangHan |
| ... | @@ -13,4 +17,7 @@ import java.util.Optional; | ... | @@ -13,4 +17,7 @@ import java.util.Optional; |
| 13 | public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> { | 17 | public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> { |
| 14 | 18 | ||
| 15 | Optional<TaskAttr> findByTaskId(Long taskId); | 19 | Optional<TaskAttr> findByTaskId(Long taskId); |
| 20 | |||
| 21 | @Query(value = "SELECT * FROM `tr_task_attr` WHERE task_id IN(?1)", nativeQuery = true) | ||
| 22 | List<Map<String, Object>> findTasksByTaskIds(Set<Object> taskIds); | ||
| 16 | } | 23 | } | ... | ... |
| ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service; | ... | @@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service; |
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; |
| 4 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | 4 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; |
| 5 | 5 | ||
| 6 | import java.util.List; | ||
| 7 | import java.util.Set; | ||
| 8 | |||
| 6 | /** | 9 | /** |
| 7 | * @author XiangHan | 10 | * @author XiangHan |
| 8 | * @date 2022-01-13 | 11 | * @date 2022-01-13 |
| ... | @@ -39,4 +42,6 @@ public interface TaskAttrService { | ... | @@ -39,4 +42,6 @@ public interface TaskAttrService { |
| 39 | * @return | 42 | * @return |
| 40 | */ | 43 | */ |
| 41 | TaskAttrDTO findByTaskId(Long taskId); | 44 | TaskAttrDTO findByTaskId(Long taskId); |
| 45 | |||
| 46 | List<TaskAttrDTO> findTasksByTaskIds(Set<Object> id); | ||
| 42 | } | 47 | } | ... | ... |
| 1 | package com.topdraw.business.module.task.attribute.service.impl; | 1 | package com.topdraw.business.module.task.attribute.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 3 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; | 4 | import com.topdraw.business.module.task.attribute.domain.TaskAttr; |
| 4 | import com.topdraw.utils.ValidationUtil; | 5 | import com.topdraw.utils.ValidationUtil; |
| 5 | import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository; | 6 | import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository; |
| ... | @@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation; |
| 12 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 13 | import org.springframework.dao.EmptyResultDataAccessException; | 14 | import org.springframework.dao.EmptyResultDataAccessException; |
| 14 | import org.springframework.util.Assert; | 15 | import org.springframework.util.Assert; |
| 16 | import org.springframework.util.CollectionUtils; | ||
| 17 | |||
| 18 | import java.util.ArrayList; | ||
| 19 | import java.util.List; | ||
| 20 | import java.util.Map; | ||
| 21 | import java.util.Set; | ||
| 15 | 22 | ||
| 16 | /** | 23 | /** |
| 17 | * @author XiangHan | 24 | * @author XiangHan |
| ... | @@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService { | ... | @@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService { |
| 64 | return this.taskAttrMapper.toDto(taskAttr); | 71 | return this.taskAttrMapper.toDto(taskAttr); |
| 65 | } | 72 | } |
| 66 | 73 | ||
| 74 | @Override | ||
| 75 | public List<TaskAttrDTO> findTasksByTaskIds(Set<Object> taskIds) { | ||
| 76 | List<Map<String,Object>> maps = this.taskAttrRepository.findTasksByTaskIds(taskIds); | ||
| 77 | if (!CollectionUtils.isEmpty(maps)) { | ||
| 78 | List<TaskAttr> taskAttrs = new ArrayList<>(); | ||
| 79 | for (Map<String, Object> map : maps) { | ||
| 80 | TaskAttr taskAttr = JSON.parseObject(JSON.toJSONString(map), TaskAttr.class); | ||
| 81 | taskAttrs.add(taskAttr); | ||
| 82 | } | ||
| 83 | |||
| 84 | return this.taskAttrMapper.toDto(taskAttrs); | ||
| 85 | } | ||
| 86 | return new ArrayList<>(); | ||
| 87 | } | ||
| 88 | |||
| 67 | 89 | ||
| 68 | } | 90 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ import java.sql.Timestamp; | ... | @@ -15,6 +15,7 @@ import java.sql.Timestamp; |
| 15 | 15 | ||
| 16 | import java.io.Serializable; | 16 | import java.io.Serializable; |
| 17 | import java.time.LocalDateTime; | 17 | import java.time.LocalDateTime; |
| 18 | import java.util.List; | ||
| 18 | 19 | ||
| 19 | /** | 20 | /** |
| 20 | * @author XiangHan | 21 | * @author XiangHan | ... | ... |
| ... | @@ -61,7 +61,7 @@ public class TaskBuilder { | ... | @@ -61,7 +61,7 @@ public class TaskBuilder { |
| 61 | 61 | ||
| 62 | task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark()); | 62 | task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark()); |
| 63 | 63 | ||
| 64 | task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr()); | 64 | // task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr()); |
| 65 | return task_; | 65 | return task_; |
| 66 | } | 66 | } |
| 67 | 67 | ... | ... |
| ... | @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; | ... | @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; |
| 8 | import org.springframework.transaction.annotation.Transactional; | 8 | import org.springframework.transaction.annotation.Transactional; |
| 9 | 9 | ||
| 10 | import java.util.List; | 10 | import java.util.List; |
| 11 | import java.util.Map; | ||
| 11 | import java.util.Optional; | 12 | import java.util.Optional; |
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| ... | @@ -25,9 +26,8 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat | ... | @@ -25,9 +26,8 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat |
| 25 | 26 | ||
| 26 | Optional<Task> findByCode(String code); | 27 | Optional<Task> findByCode(String code); |
| 27 | 28 | ||
| 28 | @Query(value = "SELECT ta.*, attr.attr_str AS attr FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " + | 29 | @Query(value = "SELECT ta.* FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " + |
| 29 | " LEFT JOIN tr_task_attr attr ON attr.task_id = ta.id " + | ||
| 30 | " WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " + | 30 | " WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " + |
| 31 | " tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true) | 31 | " tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true) |
| 32 | List<Task> findByEvent(Integer event, Integer level, Integer vip); | 32 | List<Map<String,Object>> findByEventAndLevelAndVip(Integer event, Integer level, Integer vip); |
| 33 | } | 33 | } | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
| 1 | package com.topdraw.business.module.task.service.impl; | 1 | package com.topdraw.business.module.task.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | ||
| 3 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | import com.alibaba.fastjson.JSONObject; | ||
| 6 | import com.topdraw.business.module.task.attribute.service.TaskAttrService; | ||
| 7 | import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO; | ||
| 4 | import com.topdraw.business.module.task.domain.Task; | 8 | import com.topdraw.business.module.task.domain.Task; |
| 5 | import com.topdraw.business.module.task.repository.TaskRepository; | 9 | import com.topdraw.business.module.task.repository.TaskRepository; |
| 6 | import com.topdraw.business.module.task.service.TaskService; | 10 | import com.topdraw.business.module.task.service.TaskService; |
| ... | @@ -17,7 +21,9 @@ import org.springframework.util.CollectionUtils; | ... | @@ -17,7 +21,9 @@ import org.springframework.util.CollectionUtils; |
| 17 | 21 | ||
| 18 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
| 19 | import java.util.List; | 23 | import java.util.List; |
| 24 | import java.util.Map; | ||
| 20 | import java.util.Objects; | 25 | import java.util.Objects; |
| 26 | import java.util.stream.Collectors; | ||
| 21 | 27 | ||
| 22 | /** | 28 | /** |
| 23 | * @author XiangHan | 29 | * @author XiangHan |
| ... | @@ -29,6 +35,9 @@ import java.util.Objects; | ... | @@ -29,6 +35,9 @@ import java.util.Objects; |
| 29 | public class TaskServiceImpl implements TaskService { | 35 | public class TaskServiceImpl implements TaskService { |
| 30 | 36 | ||
| 31 | @Autowired | 37 | @Autowired |
| 38 | private TaskAttrService taskAttrService; | ||
| 39 | |||
| 40 | @Autowired | ||
| 32 | private TaskMapper taskMapper; | 41 | private TaskMapper taskMapper; |
| 33 | @Autowired | 42 | @Autowired |
| 34 | private TaskRepository taskRepository; | 43 | private TaskRepository taskRepository; |
| ... | @@ -80,11 +89,45 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -80,11 +89,45 @@ public class TaskServiceImpl implements TaskService { |
| 80 | public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) { | 89 | public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) { |
| 81 | try { | 90 | try { |
| 82 | boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip); | 91 | boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip); |
| 92 | |||
| 83 | if (b) { | 93 | if (b) { |
| 84 | List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1); | 94 | List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1); |
| 85 | return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class); | 95 | return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class); |
| 86 | } | 96 | } |
| 87 | List<Task> tasks = this.taskRepository.findByEvent(event, level, vip); | 97 | |
| 98 | List<Map<String, Object>> maps = this.taskRepository.findByEventAndLevelAndVip(event, level, vip); | ||
| 99 | |||
| 100 | List<Task> tasks = new ArrayList<>(); | ||
| 101 | if (CollectionUtils.isEmpty(maps)) { | ||
| 102 | return tasks; | ||
| 103 | } | ||
| 104 | |||
| 105 | List<TaskAttrDTO> taskAttrDTOS = this.taskAttrService.findTasksByTaskIds(maps.stream().map(t -> t.get("id")).collect(Collectors.toSet())); | ||
| 106 | |||
| 107 | if (!CollectionUtils.isEmpty(taskAttrDTOS)) { | ||
| 108 | |||
| 109 | for (Map<String, Object> map : maps) { | ||
| 110 | Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class); | ||
| 111 | |||
| 112 | List<String> taskAttrs = taskAttrDTOS.stream().filter(taskAttrDTO -> taskAttrDTO.getTaskId().equals(task.getId())). | ||
| 113 | map(TaskAttrDTO::getAttrStr).collect(Collectors.toList()); | ||
| 114 | log.info("任务属性值, dealTask# taskAttrs ==>> {}", taskAttrs); | ||
| 115 | if (!CollectionUtils.isEmpty(taskAttrs)) { | ||
| 116 | task.setAttr(String.join(",", taskAttrs)); | ||
| 117 | } | ||
| 118 | |||
| 119 | tasks.add(task); | ||
| 120 | } | ||
| 121 | |||
| 122 | } else { | ||
| 123 | |||
| 124 | for (Map<String, Object> map : maps) { | ||
| 125 | Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class); | ||
| 126 | tasks.add(task); | ||
| 127 | } | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 88 | if (!CollectionUtils.isEmpty(tasks)) { | 131 | if (!CollectionUtils.isEmpty(tasks)) { |
| 89 | this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60); | 132 | this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60); |
| 90 | } | 133 | } | ... | ... |
| ... | @@ -38,15 +38,8 @@ public class TaskOperationController { | ... | @@ -38,15 +38,8 @@ public class TaskOperationController { |
| 38 | @ApiOperation("事件处理") | 38 | @ApiOperation("事件处理") |
| 39 | @AnonymousAccess | 39 | @AnonymousAccess |
| 40 | public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) { | 40 | public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) { |
| 41 | log.info("事件处理,开始,参数 ==>> {}", criteria); | 41 | log.info("事件处理,参数 ==>> dealTask#==>>{}", criteria); |
| 42 | long l = System.currentTimeMillis(); | 42 | return this.taskOperationService.dealTask(criteria.getContent()); |
| 43 | |||
| 44 | // 任务处理 | ||
| 45 | ResultInfo resultInfo = this.taskOperationService.dealTask(criteria.getContent()); | ||
| 46 | long l2 = System.currentTimeMillis(); | ||
| 47 | log.info("事件处理,结束,总耗时 ==>> {}", (l2-l)); | ||
| 48 | |||
| 49 | return resultInfo; | ||
| 50 | } | 43 | } |
| 51 | 44 | ||
| 52 | /** | 45 | /** | ... | ... |
This diff is collapsed.
Click to expand it.
| ... | @@ -164,7 +164,7 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -164,7 +164,7 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 164 | 164 | ||
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | return null; | 167 | return userAppDTO; |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | @Override | 170 | @Override | ... | ... |
| ... | @@ -64,7 +64,7 @@ | ... | @@ -64,7 +64,7 @@ |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | <!--监控sql日志输出 --> | 66 | <!--监控sql日志输出 --> |
| 67 | <logger name="jdbc.sqlonly" level="INFO" additivity="false"> | 67 | <logger name="jdbc.sqlonly" level="OFF" additivity="false"> |
| 68 | <appender-ref ref="console" /> | 68 | <appender-ref ref="console" /> |
| 69 | <appender-ref ref="info" /> | 69 | <appender-ref ref="info" /> |
| 70 | </logger> | 70 | </logger> | ... | ... |
| ... | @@ -155,7 +155,7 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -155,7 +155,7 @@ public class TaskOperationControllerTest extends BaseTest { |
| 155 | task.setValidTime(TimestampUtil.now()); | 155 | task.setValidTime(TimestampUtil.now()); |
| 156 | task.setPointsType(0); | 156 | task.setPointsType(0); |
| 157 | 157 | ||
| 158 | task.setAttr("{\"value\":\"[1,2]\"}"); | 158 | // task.setAttr("{\"value\":\"[1,2]\"}"); |
| 159 | 159 | ||
| 160 | task.setTaskTemplateId(13L); | 160 | task.setTaskTemplateId(13L); |
| 161 | 161 | ||
| ... | @@ -169,7 +169,7 @@ public class TaskOperationControllerTest extends BaseTest { | ... | @@ -169,7 +169,7 @@ public class TaskOperationControllerTest extends BaseTest { |
| 169 | Task task = new Task(); | 169 | Task task = new Task(); |
| 170 | BeanUtils.copyProperties(taskDTO, task); | 170 | BeanUtils.copyProperties(taskDTO, task); |
| 171 | task.setName("testTask4455"); | 171 | task.setName("testTask4455"); |
| 172 | task.setAttr("{\"value\":\"[4,10]\"}"); | 172 | // task.setAttr("{\"value\":\"[4,10]\"}"); |
| 173 | this.taskOperationController.updateTask(task); | 173 | this.taskOperationController.updateTask(task); |
| 174 | } | 174 | } |
| 175 | 175 | ... | ... |
-
Please register or sign in to post a comment