1.修改任务关联实体id
Showing
16 changed files
with
309 additions
and
88 deletions
... | @@ -15,24 +15,24 @@ | ... | @@ -15,24 +15,24 @@ |
15 | <maven.compiler.source>8</maven.compiler.source> | 15 | <maven.compiler.source>8</maven.compiler.source> |
16 | <maven.compiler.target>8</maven.compiler.target> | 16 | <maven.compiler.target>8</maven.compiler.target> |
17 | <jjwt.version>0.9.1</jjwt.version> | 17 | <jjwt.version>0.9.1</jjwt.version> |
18 | <cronos.version>1.1.0</cronos.version> | 18 | <cronos.version>1.2.0</cronos.version> |
19 | </properties> | 19 | </properties> |
20 | 20 | ||
21 | 21 | ||
22 | <dependencies> | 22 | <dependencies> |
23 | 23 | ||
24 | <!--<dependency> | 24 | <dependency> |
25 | <groupId>com.topdraw</groupId> | 25 | <groupId>com.topdraw</groupId> |
26 | <artifactId>cronos-system</artifactId> | 26 | <artifactId>cronos-system</artifactId> |
27 | <version>${cronos.version}</version> | 27 | <version>${cronos.version}</version> |
28 | </dependency>--> | 28 | </dependency> |
29 | 29 | ||
30 | <dependency> | 30 | <!--<dependency> |
31 | <groupId>com.topdraw</groupId> | 31 | <groupId>com.topdraw</groupId> |
32 | <artifactId>code-generator</artifactId> | 32 | <artifactId>code-generator</artifactId> |
33 | <version>3.1.0</version> | 33 | <version>3.1.0</version> |
34 | </dependency> | 34 | </dependency> |
35 | 35 | --> | |
36 | <dependency> | 36 | <dependency> |
37 | <groupId>org.springframework.boot</groupId> | 37 | <groupId>org.springframework.boot</groupId> |
38 | <artifactId>spring-boot-starter-cache</artifactId> | 38 | <artifactId>spring-boot-starter-cache</artifactId> | ... | ... |
... | @@ -38,6 +38,10 @@ public class Task implements Serializable { | ... | @@ -38,6 +38,10 @@ public class Task implements Serializable { |
38 | @NotNull(message = "taskTemplateId is null", groups = {CreateGroup.class}) | 38 | @NotNull(message = "taskTemplateId is null", groups = {CreateGroup.class}) |
39 | private Long taskTemplateId; | 39 | private Long taskTemplateId; |
40 | 40 | ||
41 | /** 关联实体id */ | ||
42 | @Column(name = "entity_id", nullable = false) | ||
43 | private String entityId; | ||
44 | |||
41 | @Transient | 45 | @Transient |
42 | private String taskTemplateCode; | 46 | private String taskTemplateCode; |
43 | 47 | ... | ... |
... | @@ -94,7 +94,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -94,7 +94,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
94 | } | 94 | } |
95 | if (finishTasks.size() > 0) { | 95 | if (finishTasks.size() > 0) { |
96 | // 总记录一直存储 | 96 | // 总记录一直存储 |
97 | this.redisUtils.hmset(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks); | 97 | this.redisUtils.hmsetForObject(RedisKeyConstants.cacheTotalFinishTaskCount + "::" + memberId, finishTasks); |
98 | } | 98 | } |
99 | 99 | ||
100 | return finishTasks; | 100 | return finishTasks; |
... | @@ -124,7 +124,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { | ... | @@ -124,7 +124,7 @@ public class TrTaskProgressServiceImpl implements TrTaskProgressService { |
124 | 124 | ||
125 | if (finishTasks.size() > 0) { | 125 | if (finishTasks.size() > 0) { |
126 | // 单天的记录只存储一天 | 126 | // 单天的记录只存储一天 |
127 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); | 127 | this.redisUtils.hmsetForObject(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); |
128 | } | 128 | } |
129 | 129 | ||
130 | return finishTasks; | 130 | return finishTasks; | ... | ... |
... | @@ -20,6 +20,9 @@ public class TaskDTO implements Serializable { | ... | @@ -20,6 +20,9 @@ public class TaskDTO implements Serializable { |
20 | /** 任务模板id */ | 20 | /** 任务模板id */ |
21 | private Long taskTemplateId; | 21 | private Long taskTemplateId; |
22 | 22 | ||
23 | /** 关联实体id */ | ||
24 | private String entityId; | ||
25 | |||
23 | /** 删除标识 0:正常;1:已删除;*/ | 26 | /** 删除标识 0:正常;1:已删除;*/ |
24 | private Integer deleteMark; | 27 | private Integer deleteMark; |
25 | 28 | ... | ... |
member-service-impl/src/main/java/com/topdraw/business/module/task/service/impl/TaskServiceImpl.java
... | @@ -19,10 +19,7 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -19,10 +19,7 @@ import org.springframework.transaction.annotation.Propagation; |
19 | import org.springframework.transaction.annotation.Transactional; | 19 | import org.springframework.transaction.annotation.Transactional; |
20 | import org.springframework.util.CollectionUtils; | 20 | import org.springframework.util.CollectionUtils; |
21 | 21 | ||
22 | import java.util.ArrayList; | 22 | import java.util.*; |
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.util.Objects; | ||
26 | import java.util.stream.Collectors; | 23 | import java.util.stream.Collectors; |
27 | 24 | ||
28 | /** | 25 | /** |
... | @@ -69,8 +66,14 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -69,8 +66,14 @@ public class TaskServiceImpl implements TaskService { |
69 | 66 | ||
70 | @Override | 67 | @Override |
71 | public TaskDTO update(Task task) { | 68 | public TaskDTO update(Task task) { |
72 | Task save = this.taskRepository.save(task); | 69 | Optional<Task> taskOptional = this.taskRepository.findById(task.getId()); |
73 | return this.taskMapper.toDto(save); | 70 | if (taskOptional.isPresent()) { |
71 | Task task1 = taskOptional.get(); | ||
72 | task1.copy(task); | ||
73 | Task result = this.taskRepository.save(task1); | ||
74 | return this.taskMapper.toDto(result); | ||
75 | } | ||
76 | return this.taskMapper.toDto(task); | ||
74 | } | 77 | } |
75 | 78 | ||
76 | @Override | 79 | @Override |
... | @@ -102,32 +105,11 @@ public class TaskServiceImpl implements TaskService { | ... | @@ -102,32 +105,11 @@ public class TaskServiceImpl implements TaskService { |
102 | return tasks; | 105 | return tasks; |
103 | } | 106 | } |
104 | 107 | ||
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) { | 108 | for (Map<String, Object> map : maps) { |
125 | Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class); | 109 | Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class); |
126 | tasks.add(task); | 110 | tasks.add(task); |
127 | } | 111 | } |
128 | 112 | ||
129 | } | ||
130 | |||
131 | if (!CollectionUtils.isEmpty(tasks)) { | 113 | if (!CollectionUtils.isEmpty(tasks)) { |
132 | this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60); | 114 | this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60); |
133 | } | 115 | } | ... | ... |
1 | package com.topdraw.business.module.user.app.rest; | 1 | package com.topdraw.business.module.user.app.rest; |
2 | 2 | ||
3 | import com.topdraw.annotation.AnonymousAccess; | 3 | import com.topdraw.annotation.AnonymousAccess; |
4 | import com.topdraw.aop.log.Log; | ||
4 | import com.topdraw.business.module.user.app.domain.UserApp; | 5 | import com.topdraw.business.module.user.app.domain.UserApp; |
5 | import com.topdraw.business.module.user.app.domain.UserAppBind; | 6 | import com.topdraw.business.module.user.app.domain.UserAppBind; |
6 | import com.topdraw.business.module.user.app.service.UserAppBindService; | 7 | import com.topdraw.business.module.user.app.service.UserAppBindService; |
... | @@ -11,7 +12,6 @@ import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq; | ... | @@ -11,7 +12,6 @@ import com.topdraw.business.module.vis.hainan.qq.domain.VisUserQq; |
11 | import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo; | 12 | import com.topdraw.business.module.vis.hainan.weibo.domain.VisUserWeibo; |
12 | import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin; | 13 | import com.topdraw.business.module.vis.hainan.weixin.domain.VisUserWeixin; |
13 | import com.topdraw.common.ResultInfo; | 14 | import com.topdraw.common.ResultInfo; |
14 | import com.topdraw.annotation.Log; | ||
15 | import com.topdraw.business.module.user.app.service.UserAppService; | 15 | import com.topdraw.business.module.user.app.service.UserAppService; |
16 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
17 | import org.apache.commons.lang3.StringUtils; | 17 | import org.apache.commons.lang3.StringUtils; | ... | ... |
1 | package com.topdraw.business.module.user.iptv.growreport.rest; | 1 | package com.topdraw.business.module.user.iptv.growreport.rest; |
2 | 2 | ||
3 | import com.topdraw.aop.log.Log; | ||
3 | import com.topdraw.common.ResultInfo; | 4 | import com.topdraw.common.ResultInfo; |
4 | import com.topdraw.annotation.Log; | ||
5 | import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport; | 5 | import com.topdraw.business.module.user.iptv.growreport.domain.GrowthReport; |
6 | import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService; | 6 | import com.topdraw.business.module.user.iptv.growreport.service.GrowthReportService; |
7 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; | ... | ... |
1 | package com.topdraw.business.module.user.weixin.wechatshare.rest; | 1 | package com.topdraw.business.module.user.weixin.wechatshare.rest; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.topdraw.aop.log.Log; | ||
4 | import com.topdraw.common.ResultInfo; | 5 | import com.topdraw.common.ResultInfo; |
5 | import com.topdraw.annotation.Log; | ||
6 | import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord; | 6 | import com.topdraw.business.module.user.weixin.wechatshare.domain.WechatShareRecord; |
7 | import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService; | 7 | import com.topdraw.business.module.user.weixin.wechatshare.service.WechatShareRecordService; |
8 | import lombok.extern.slf4j.Slf4j; | 8 | import lombok.extern.slf4j.Slf4j; | ... | ... |
... | @@ -9,6 +9,7 @@ import com.topdraw.business.process.service.TaskOperationService; | ... | @@ -9,6 +9,7 @@ import com.topdraw.business.process.service.TaskOperationService; |
9 | import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria; | 9 | import com.topdraw.business.process.service.dto.TaskOperationQueryCriteria; |
10 | import com.topdraw.common.IResultInfo; | 10 | import com.topdraw.common.IResultInfo; |
11 | import com.topdraw.common.ResultInfo; | 11 | import com.topdraw.common.ResultInfo; |
12 | import com.topdraw.exception.BadRequestException; | ||
12 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
13 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
14 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
... | @@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.*; | ... | @@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.*; |
19 | 20 | ||
20 | import java.util.Arrays; | 21 | import java.util.Arrays; |
21 | import java.util.Objects; | 22 | import java.util.Objects; |
23 | //byte[] b = Base64Utils.decodeFromString(baseStrs[1]); | ||
22 | 24 | ||
23 | @Api("任务处理") | 25 | @Api("任务处理") |
24 | @RestController | 26 | @RestController |
... | @@ -70,18 +72,14 @@ public class TaskOperationController { | ... | @@ -70,18 +72,14 @@ public class TaskOperationController { |
70 | @PostMapping(value = "/updateTask") | 72 | @PostMapping(value = "/updateTask") |
71 | @ApiOperation("修改任务") | 73 | @ApiOperation("修改任务") |
72 | @AnonymousAccess | 74 | @AnonymousAccess |
73 | public void updateTask(@RequestBody @Validated Task content) { | 75 | public ResultInfo updateTask(@RequestBody @Validated Task content) { |
74 | log.info("taskOperation ==>> updateTask ==>> param ==>> {}", content); | 76 | log.info("修改任务,参数 updateTask# ==>> {}", content); |
75 | Long id = content.getId(); | 77 | Long id = content.getId(); |
76 | TaskDTO taskDTO = this.taskOperationService.findById(id); | 78 | if (Objects.isNull(id)) { |
77 | if (Objects.nonNull(taskDTO.getId())) { | 79 | throw new BadRequestException("修改任务失败,id不得为空"); |
78 | content.setCode(taskDTO.getCode()); | ||
79 | Task task = new Task(); | ||
80 | BeanUtils.copyProperties(taskDTO, task); | ||
81 | task.copy(content); | ||
82 | // 修改任务 | ||
83 | this.taskOperationService.updateTask(task); | ||
84 | } | 80 | } |
81 | // 修改任务 | ||
82 | return this.taskOperationService.updateTask(content); | ||
85 | } | 83 | } |
86 | 84 | ||
87 | /** | 85 | /** | ... | ... |
... | @@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil; | ... | @@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil; |
5 | import com.alibaba.fastjson.JSON; | 5 | import com.alibaba.fastjson.JSON; |
6 | import com.alibaba.fastjson.JSONObject; | 6 | import com.alibaba.fastjson.JSONObject; |
7 | import com.topdraw.annotation.AnonymousAccess; | 7 | import com.topdraw.annotation.AnonymousAccess; |
8 | import com.topdraw.annotation.Log; | 8 | import com.topdraw.aop.log.Log; |
9 | import com.topdraw.business.module.common.validated.CreateGroup; | 9 | import com.topdraw.business.module.common.validated.CreateGroup; |
10 | import com.topdraw.business.module.common.validated.UpdateGroup; | 10 | import com.topdraw.business.module.common.validated.UpdateGroup; |
11 | import com.topdraw.business.module.member.service.MemberService; | 11 | import com.topdraw.business.module.member.service.MemberService; | ... | ... |
... | @@ -51,6 +51,7 @@ import org.springframework.data.redis.core.RedisTemplate; | ... | @@ -51,6 +51,7 @@ import org.springframework.data.redis.core.RedisTemplate; |
51 | import org.springframework.data.redis.core.StringRedisTemplate; | 51 | import org.springframework.data.redis.core.StringRedisTemplate; |
52 | import org.springframework.data.redis.core.ValueOperations; | 52 | import org.springframework.data.redis.core.ValueOperations; |
53 | import org.springframework.stereotype.Service; | 53 | import org.springframework.stereotype.Service; |
54 | import org.springframework.transaction.annotation.Transactional; | ||
54 | import org.springframework.util.CollectionUtils; | 55 | import org.springframework.util.CollectionUtils; |
55 | 56 | ||
56 | import java.sql.Timestamp; | 57 | import java.sql.Timestamp; |
... | @@ -100,66 +101,70 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -100,66 +101,70 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
100 | private static final Integer POINTS_MIN = 1; | 101 | private static final Integer POINTS_MIN = 1; |
101 | 102 | ||
102 | @Override | 103 | @Override |
103 | public TaskDTO createTask(Task task) { | 104 | @Transactional(rollbackFor = Exception.class) |
104 | Long taskTemplateId = task.getTaskTemplateId(); | 105 | public TaskDTO createTask(Task content) { |
106 | Long taskTemplateId = content.getTaskTemplateId(); | ||
105 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); | 107 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); |
106 | 108 | ||
107 | task.setTaskTemplateCode(taskTemplateDTO.getCode()); | 109 | content.setTaskTemplateCode(taskTemplateDTO.getCode()); |
108 | Task task_ = TaskBuilder.build(task); | 110 | Task task = TaskBuilder.build(content); |
109 | TaskDTO taskDTO = this.taskService.create(task_); | 111 | TaskDTO taskDTO = this.taskService.create(task); |
110 | 112 | ||
111 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncCreateTask(task_); | 113 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncCreateTask(task); |
112 | 114 | ||
113 | return taskDTO; | 115 | return taskDTO; |
114 | } | 116 | } |
115 | 117 | ||
116 | @Override | 118 | @Override |
117 | public TaskDTO updateTask(Task task) { | 119 | @Transactional(rollbackFor = Exception.class) |
118 | Long taskTemplateId = task.getTaskTemplateId(); | 120 | public ResultInfo updateTask(Task content) { |
121 | |||
122 | Long taskTemplateId = content.getTaskTemplateId(); | ||
123 | if (Objects.nonNull(taskTemplateId)) { | ||
119 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); | 124 | TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findById(taskTemplateId); |
120 | task.setTaskTemplateCode(taskTemplateDTO.getCode()); | 125 | content.setTaskTemplateCode(taskTemplateDTO.getCode()); |
121 | TaskDTO update = this.taskService.update(task); | ||
122 | if (Objects.nonNull(update.getId())) { | ||
123 | this.updateTaskAttr(task); | ||
124 | } | 126 | } |
125 | 127 | ||
126 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncUpdateTask(task); | 128 | TaskDTO taskDTO = this.taskService.update(content); |
129 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncUpdateTask(content); | ||
127 | 130 | ||
128 | return update; | 131 | Set<Object> tasks = this.redisUtils.keys(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip+"*"); |
132 | if (!CollectionUtils.isEmpty(tasks)) { | ||
133 | for (Object key : tasks) { | ||
134 | this.redisUtils.del(key.toString()); | ||
129 | } | 135 | } |
130 | |||
131 | /** | ||
132 | * | ||
133 | * @param task 任务 | ||
134 | */ | ||
135 | private void updateTaskAttr(Task task) { | ||
136 | TaskAttrDTO taskAttrDTO = this.taskAttrService.findByTaskId(task.getId()); | ||
137 | if (Objects.nonNull(taskAttrDTO.getId())) { | ||
138 | TaskAttr taskAttr = new TaskAttr(); | ||
139 | BeanUtils.copyProperties(taskAttrDTO, taskAttr); | ||
140 | taskAttr.setAttrStr(task.getAttr()); | ||
141 | this.taskAttrService.update(taskAttr); | ||
142 | } | 136 | } |
137 | |||
138 | return ResultInfo.success(taskDTO); | ||
143 | } | 139 | } |
144 | 140 | ||
141 | |||
145 | @Override | 142 | @Override |
146 | // @CacheEvict(cacheNames = RedisKeyConstants.cacheTaskByEvent, key = "#task.event") | 143 | @Transactional(rollbackFor = Exception.class) |
147 | public Integer deleteTask(Task task) { | 144 | public Integer deleteTask(Task content) { |
148 | Long id = task.getId(); | 145 | Long id = content.getId(); |
149 | TaskDTO taskDTO = this.findById(id); | 146 | TaskDTO taskDTO = this.findById(id); |
150 | if (Objects.nonNull(taskDTO.getId())) { | 147 | if (Objects.nonNull(taskDTO.getId())) { |
151 | task.setId(taskDTO.getId()); | 148 | content.setId(taskDTO.getId()); |
152 | Integer delete = this.taskService.delete(task); | 149 | Integer count = this.taskService.delete(content); |
153 | task.setCode(taskDTO.getCode()); | 150 | content.setCode(taskDTO.getCode()); |
154 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncDeleteTask(task); | 151 | ((TaskOperationServiceImpl) AopContext.currentProxy()).asyncDeleteTask(content); |
152 | |||
153 | Set<Object> tasks = this.redisUtils.keys(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip+"*"); | ||
154 | if (!CollectionUtils.isEmpty(tasks)) { | ||
155 | for (Object key : tasks) { | ||
156 | this.redisUtils.del(key.toString()); | ||
157 | } | ||
158 | } | ||
155 | 159 | ||
156 | return delete; | 160 | return count; |
157 | } | 161 | } |
158 | 162 | ||
159 | return 0; | 163 | return 0; |
160 | } | 164 | } |
161 | 165 | ||
162 | @Override | 166 | @Override |
167 | @Transactional(rollbackFor = Exception.class) | ||
163 | public Integer deleteTask(Long id) { | 168 | public Integer deleteTask(Long id) { |
164 | TaskDTO taskDTO = this.findById(id); | 169 | TaskDTO taskDTO = this.findById(id); |
165 | if (Objects.nonNull(taskDTO.getId())) { | 170 | if (Objects.nonNull(taskDTO.getId())) { |
... | @@ -173,6 +178,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -173,6 +178,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
173 | } | 178 | } |
174 | 179 | ||
175 | @Override | 180 | @Override |
181 | @Transactional(readOnly = true) | ||
176 | public TaskDTO findById(Long id) { | 182 | public TaskDTO findById(Long id) { |
177 | TaskDTO taskDTO = this.taskService.findById(id); | 183 | TaskDTO taskDTO = this.taskService.findById(id); |
178 | Long id1 = taskDTO.getId(); | 184 | Long id1 = taskDTO.getId(); |
... | @@ -185,6 +191,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -185,6 +191,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
185 | } | 191 | } |
186 | 192 | ||
187 | @Override | 193 | @Override |
194 | @Transactional(readOnly = true) | ||
188 | public TaskDTO findByCode(String code) { | 195 | public TaskDTO findByCode(String code) { |
189 | return this.taskService.findByCode(code); | 196 | return this.taskService.findByCode(code); |
190 | } | 197 | } |
... | @@ -312,7 +319,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -312,7 +319,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
312 | Map<Object, Object> finishTasks = new HashMap<>(); | 319 | Map<Object, Object> finishTasks = new HashMap<>(); |
313 | finishTasks.put(task.getId(), 1); | 320 | finishTasks.put(task.getId(), 1); |
314 | // 单天的记录只存储一天 | 321 | // 单天的记录只存储一天 |
315 | this.redisUtils.hmset(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); | 322 | this.redisUtils.hmsetForObject(RedisKeyConstants.cacheTodayFinishTaskCount + "::" + memberId + ":" + LocalDate.now(), finishTasks, 24*60*60); |
316 | } else { | 323 | } else { |
317 | this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1); | 324 | this.redisUtils.hincr(RedisKeyConstants.cacheTodayFinishTaskCount+"::"+memberId+":"+LocalDate.now(), task.getId().toString(), 1); |
318 | } | 325 | } |
... | @@ -544,8 +551,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -544,8 +551,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
544 | 551 | ||
545 | private boolean doActivityEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { | 552 | private boolean doActivityEvent(JSONObject msgData, Task task, MemberSimpleDTO memberDTO) { |
546 | Integer actionAmount = task.getActionAmount(); | 553 | Integer actionAmount = task.getActionAmount(); |
547 | String attrStr = task.getAttr(); | 554 | String entityId = task.getEntityId(); |
548 | if (StringUtils.isBlank(attrStr)) { | 555 | if (StringUtils.isBlank(entityId)) { |
549 | int joinCount = 1;//msgData.getInteger("joinCount"); | 556 | int joinCount = 1;//msgData.getInteger("joinCount"); |
550 | if (joinCount >= actionAmount) { | 557 | if (joinCount >= actionAmount) { |
551 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS); | 558 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS); |
... | @@ -554,7 +561,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -554,7 +561,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
554 | } | 561 | } |
555 | 562 | ||
556 | Integer marketingActivityId = msgData.getInteger("marketingActivityId"); | 563 | Integer marketingActivityId = msgData.getInteger("marketingActivityId"); |
557 | if (new ArrayList<>(Arrays.asList(attrStr.split(","))).contains(Integer.toString(marketingActivityId))) { | 564 | if (new ArrayList<>(Arrays.asList(entityId.split(","))).contains(Integer.toString(marketingActivityId))) { |
558 | int joinCount = 1;//msgData.getInteger("joinCount"); | 565 | int joinCount = 1;//msgData.getInteger("joinCount"); |
559 | if (joinCount >= actionAmount) { | 566 | if (joinCount >= actionAmount) { |
560 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS); | 567 | this.saveOrUpdateTaskProcess(null, memberDTO.getId(), task, joinCount, TASK_FINISH_STATUS); |
... | @@ -562,7 +569,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -562,7 +569,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
562 | } | 569 | } |
563 | } | 570 | } |
564 | 571 | ||
565 | log.warn("未找到对应的活动,参数 marketingActivityId ==>> {} || 任务属性 ==>> {}", marketingActivityId, attrStr); | 572 | log.warn("未找到对应的活动,参数 marketingActivityId ==>> {} || 营销活动id ==>> [{}]", marketingActivityId, entityId); |
566 | return false; | 573 | return false; |
567 | } | 574 | } |
568 | 575 | ... | ... |
1 | package com.topdraw.common; | ||
2 | |||
3 | import java.io.Serializable; | ||
4 | import java.util.List; | ||
5 | |||
6 | /** | ||
7 | * @author lvjian | ||
8 | * @Title: | ||
9 | * @Package | ||
10 | * @Description: | ||
11 | * @date 2021/1/7 17:26 | ||
12 | */ | ||
13 | public interface IResultInfo<T> extends Serializable { | ||
14 | long getBusinessCode(); | ||
15 | |||
16 | List<T> getResultSet(); | ||
17 | |||
18 | String getDescription(); | ||
19 | |||
20 | long getCount(); | ||
21 | } |
1 | package com.topdraw.common; | ||
2 | |||
3 | /** | ||
4 | * 枚举了一些常用API返回码 | ||
5 | * Created by cy on 2021/01/08. | ||
6 | */ | ||
7 | public enum ResultCode implements IResultCode { | ||
8 | SUCCESS(200, "操作成功"), | ||
9 | FAILED(500, "操作失败"), | ||
10 | VALIDATE_FAILED(400, "参数检验失败"), | ||
11 | UNAUTHORIZED(401, "未登录或token已经过期"), | ||
12 | FORBIDDEN(403, "无权限"), | ||
13 | METHOD_NOT_ALLOWED(405, "方法不允许"); | ||
14 | private long code; | ||
15 | private String description; | ||
16 | |||
17 | ResultCode(long code, String description) { | ||
18 | this.code = code; | ||
19 | this.description = description; | ||
20 | } | ||
21 | |||
22 | public long getCode() { | ||
23 | return code; | ||
24 | } | ||
25 | |||
26 | public String getDescription() { | ||
27 | return description; | ||
28 | } | ||
29 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | package com.topdraw.common; | ||
2 | |||
3 | import com.alibaba.fastjson.JSON; | ||
4 | import com.fasterxml.jackson.annotation.JsonFormat; | ||
5 | import lombok.Getter; | ||
6 | |||
7 | import java.time.LocalDateTime; | ||
8 | import java.util.ArrayList; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | /** | ||
13 | * 通用返回对象 | ||
14 | * Created by cy on 2021/01/08. | ||
15 | */ | ||
16 | @Getter | ||
17 | public class ResultInfo<T> implements IResultInfo<T> { | ||
18 | private static final long serialVersionUID = -7313465544799377989L; | ||
19 | private long businessCode; | ||
20 | private List<T> resultSet; | ||
21 | private String description; | ||
22 | private long count; | ||
23 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
24 | private LocalDateTime currentTime; | ||
25 | |||
26 | public ResultInfo(long businessCode, List<T> resultSet, String description) { | ||
27 | this.businessCode = businessCode; | ||
28 | this.resultSet = resultSet; | ||
29 | this.description = description; | ||
30 | this.count = resultSet.size(); | ||
31 | currentTime = LocalDateTime.now(); | ||
32 | } | ||
33 | |||
34 | public ResultInfo(long businessCode, Map<String, Object> page, String description) { | ||
35 | this.businessCode = businessCode; | ||
36 | this.resultSet = (List<T>) page.get("content"); | ||
37 | this.count = (Long) page.get("totalElements"); | ||
38 | this.description = description; | ||
39 | currentTime = LocalDateTime.now(); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * 成功返回不分页结果集 | ||
44 | * @param resultSet | ||
45 | * @param <T> | ||
46 | * @return | ||
47 | */ | ||
48 | public static <T> ResultInfo<T> success(List<T> resultSet) { | ||
49 | return new ResultInfo<T>(ResultCode.SUCCESS.getCode(), resultSet, ""); | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * 成功返回单一实体结果集 | ||
54 | * @param result | ||
55 | * @param <T> | ||
56 | * @return | ||
57 | */ | ||
58 | public static <T> ResultInfo<T> success(T result) { | ||
59 | List<T> list = new ArrayList<>(); | ||
60 | list.add(result); | ||
61 | return new ResultInfo<T>(ResultCode.SUCCESS.getCode(), list, ""); | ||
62 | } | ||
63 | |||
64 | public static <T> ResultInfo<T> success() { | ||
65 | return new ResultInfo<>(ResultCode.SUCCESS.getCode(), new ArrayList<>(), ""); | ||
66 | } | ||
67 | /** | ||
68 | * 成功返回分页结果集 | ||
69 | * @param page | ||
70 | * @param <T> | ||
71 | * @return | ||
72 | */ | ||
73 | public static <T> ResultInfo<T> successPage(Map<String, Object> page) { | ||
74 | return new ResultInfo<T>(ResultCode.SUCCESS.getCode(), page, ""); | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * 成功返回带描述的不分页结果集 | ||
79 | * @param resultSet | ||
80 | * @param description | ||
81 | * @param <T> | ||
82 | * @return | ||
83 | */ | ||
84 | public static <T> ResultInfo<T> success(List<T> resultSet, String description) { | ||
85 | return new ResultInfo<T>(ResultCode.SUCCESS.getCode(), resultSet, description); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * 带描述的服务端处理失败返回 | ||
90 | * @param description | ||
91 | * @param <T> | ||
92 | * @return | ||
93 | */ | ||
94 | public static <T> ResultInfo<T> failed(String description) { | ||
95 | return new ResultInfo<T>(ResultCode.FAILED.getCode(), new ArrayList<>(), description); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * 带描述的服务端处理失败返回 | ||
100 | * @param description | ||
101 | * @param <T> | ||
102 | * @return | ||
103 | */ | ||
104 | public static <T> ResultInfo<T> failure(String description) { | ||
105 | return new ResultInfo<T>(ResultCode.FAILED.getCode(), new ArrayList<>(), description); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * 未登录或token过期的失败返回 | ||
110 | * @param <T> | ||
111 | * @return | ||
112 | */ | ||
113 | public static <T> ResultInfo<T> unauthorized() { | ||
114 | return new ResultInfo<T>(ResultCode.UNAUTHORIZED.getCode(), new ArrayList<>(), ResultCode.UNAUTHORIZED.getDescription()); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * 未授权的失败返回 | ||
119 | * @param description | ||
120 | * @param <T> | ||
121 | * @return | ||
122 | */ | ||
123 | public static <T> ResultInfo<T> forbidden(String description) { | ||
124 | return new ResultInfo<T>(ResultCode.FORBIDDEN.getCode(), new ArrayList<>(), description); | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * 参数验证失败的返回 | ||
129 | * @param <T> | ||
130 | * @return | ||
131 | */ | ||
132 | public static <T> ResultInfo<T> validateFailed() { | ||
133 | return new ResultInfo<T>(ResultCode.VALIDATE_FAILED.getCode(), new ArrayList<>(), ResultCode.VALIDATE_FAILED.getDescription()); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * 带描述的参数验证失败返回 | ||
138 | * @param description | ||
139 | * @param <T> | ||
140 | * @return | ||
141 | */ | ||
142 | public static <T> ResultInfo<T> validateFailed(String description) { | ||
143 | return new ResultInfo<T>(ResultCode.VALIDATE_FAILED.getCode(), new ArrayList<>(), description); | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * 请求方法错误的返回 | ||
148 | * @param description | ||
149 | * @param <T> | ||
150 | * @return | ||
151 | */ | ||
152 | public static <T> ResultInfo<T> methodNotAllowed(String description) { | ||
153 | return new ResultInfo<T>(ResultCode.METHOD_NOT_ALLOWED.getCode(), new ArrayList<>(), description); | ||
154 | } | ||
155 | |||
156 | |||
157 | |||
158 | @Override | ||
159 | public String toString() { | ||
160 | return JSON.toJSONString(this); | ||
161 | } | ||
162 | } |
-
Please register or sign in to post a comment