Commit fdd7f7f8 fdd7f7f82e49b2dbaaad7918d7e1de9907c9aa9c by xianghan

1.添加参加活动、首次消耗积分、完善用户信息任务

1 parent 9c602b84
......@@ -73,15 +73,18 @@ public class MemberServiceImpl implements MemberService {
@Transactional(readOnly = true)
public MemberSimpleDTO findSimpleById(Long id) {
Object memberSimpleRedis = this.redisUtils.get(RedisKeyConstants.cacheMemberSimpleById + "::" + id);
log.info("从redis中获取会员信息, 结果集 dealTask# memberSimpleRedis ==>> {} ", memberSimpleRedis);
if (Objects.nonNull(memberSimpleRedis)) {
return JSONObject.parseObject(JSON.toJSONString(memberSimpleRedis), MemberSimpleDTO.class);
}
MemberSimple memberSimple = this.memberSimpleRepository.findSimpleById(id).orElseGet(MemberSimple::new);
log.info("从数据库中获取会员信息, 结果集 dealTask# memberSimple ==>> {} ", memberSimple);
if (Objects.nonNull(memberSimple.getId())) {
MemberSimpleDTO memberSimpleDTO = new MemberSimpleDTO();
BeanUtils.copyProperties(memberSimple, memberSimpleDTO);
this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO);
boolean result = this.redisUtils.set(RedisKeyConstants.cacheMemberSimpleById + "::" + id, memberSimpleDTO);
log.info("将结果存入redis中, dealTask# memberSimpleDTO ==>> {} || 存入结果 ==>> {}", memberSimpleDTO, result);
}
return this.memberSimpleMapper.toDto(memberSimple);
}
......
......@@ -3,8 +3,12 @@ package com.topdraw.business.module.task.attribute.repository;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* @author XiangHan
......@@ -13,4 +17,7 @@ import java.util.Optional;
public interface TaskAttrRepository extends JpaRepository<TaskAttr, Long>, JpaSpecificationExecutor<TaskAttr> {
Optional<TaskAttr> findByTaskId(Long taskId);
@Query(value = "SELECT * FROM `tr_task_attr` WHERE task_id IN(?1)", nativeQuery = true)
List<Map<String, Object>> findTasksByTaskIds(Set<Object> taskIds);
}
......
......@@ -3,6 +3,9 @@ package com.topdraw.business.module.task.attribute.service;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
import java.util.List;
import java.util.Set;
/**
* @author XiangHan
* @date 2022-01-13
......@@ -39,4 +42,6 @@ public interface TaskAttrService {
* @return
*/
TaskAttrDTO findByTaskId(Long taskId);
List<TaskAttrDTO> findTasksByTaskIds(Set<Object> id);
}
......
package com.topdraw.business.module.task.attribute.service.impl;
import com.alibaba.fastjson.JSON;
import com.topdraw.business.module.task.attribute.domain.TaskAttr;
import com.topdraw.utils.ValidationUtil;
import com.topdraw.business.module.task.attribute.repository.TaskAttrRepository;
......@@ -12,6 +13,12 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author XiangHan
......@@ -64,5 +71,20 @@ public class TaskAttrServiceImpl implements TaskAttrService {
return this.taskAttrMapper.toDto(taskAttr);
}
@Override
public List<TaskAttrDTO> findTasksByTaskIds(Set<Object> taskIds) {
List<Map<String,Object>> maps = this.taskAttrRepository.findTasksByTaskIds(taskIds);
if (!CollectionUtils.isEmpty(maps)) {
List<TaskAttr> taskAttrs = new ArrayList<>();
for (Map<String, Object> map : maps) {
TaskAttr taskAttr = JSON.parseObject(JSON.toJSONString(map), TaskAttr.class);
taskAttrs.add(taskAttr);
}
return this.taskAttrMapper.toDto(taskAttrs);
}
return new ArrayList<>();
}
}
......
......@@ -15,6 +15,7 @@ import java.sql.Timestamp;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author XiangHan
......
......@@ -61,7 +61,7 @@ public class TaskBuilder {
task_.setDeleteMark(Objects.isNull(task.getDeleteMark()) ? 0 : task.getDeleteMark());
task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr());
// task_.setAttr(StringUtils.isBlank(task.getAttr()) ? null : task.getAttr());
return task_;
}
......
......@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
......@@ -25,9 +26,8 @@ public interface TaskRepository extends JpaRepository<Task, Long>, JpaSpecificat
Optional<Task> findByCode(String code);
@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 " +
" LEFT JOIN tr_task_attr attr ON attr.task_id = ta.id " +
@Query(value = "SELECT ta.* FROM tr_task ta LEFT JOIN tr_task_template tm ON ta.task_template_id = tm.id " +
" WHERE ta.`status` = 1 AND ta.valid_time <= now() and ta.expire_time >= now() AND ta.delete_mark = 0 AND " +
" tm.type = ?1 AND ta.`member_level` <= ?2 and ta.`member_vip` <= ?3", nativeQuery = true)
List<Task> findByEvent(Integer event, Integer level, Integer vip);
List<Map<String,Object>> findByEventAndLevelAndVip(Integer event, Integer level, Integer vip);
}
......
package com.topdraw.business.module.task.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.topdraw.business.module.task.attribute.service.TaskAttrService;
import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
import com.topdraw.business.module.task.domain.Task;
import com.topdraw.business.module.task.repository.TaskRepository;
import com.topdraw.business.module.task.service.TaskService;
......@@ -17,7 +21,9 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author XiangHan
......@@ -29,6 +35,9 @@ import java.util.Objects;
public class TaskServiceImpl implements TaskService {
@Autowired
private TaskAttrService taskAttrService;
@Autowired
private TaskMapper taskMapper;
@Autowired
private TaskRepository taskRepository;
......@@ -80,11 +89,45 @@ public class TaskServiceImpl implements TaskService {
public List<Task> findByEventAndMemberLevelAndVip(Integer event, Integer level, Integer vip) {
try {
boolean b = this.redisUtils.hasKey(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip);
if (b) {
List<Object> tasksObjs = redisUtils.lGet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, 0, -1);
return JSONArray.parseArray(tasksObjs.get(0).toString(), Task.class);
}
List<Task> tasks = this.taskRepository.findByEvent(event, level, vip);
List<Map<String, Object>> maps = this.taskRepository.findByEventAndLevelAndVip(event, level, vip);
List<Task> tasks = new ArrayList<>();
if (CollectionUtils.isEmpty(maps)) {
return tasks;
}
List<TaskAttrDTO> taskAttrDTOS = this.taskAttrService.findTasksByTaskIds(maps.stream().map(t -> t.get("id")).collect(Collectors.toSet()));
if (!CollectionUtils.isEmpty(taskAttrDTOS)) {
for (Map<String, Object> map : maps) {
Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
List<String> taskAttrs = taskAttrDTOS.stream().filter(taskAttrDTO -> taskAttrDTO.getTaskId().equals(task.getId())).
map(TaskAttrDTO::getAttrStr).collect(Collectors.toList());
log.info("任务属性值, dealTask# taskAttrs ==>> {}", taskAttrs);
if (!CollectionUtils.isEmpty(taskAttrs)) {
task.setAttr(String.join(",", taskAttrs));
}
tasks.add(task);
}
} else {
for (Map<String, Object> map : maps) {
Task task = JSONObject.parseObject(JSON.toJSONString(map), Task.class);
tasks.add(task);
}
}
if (!CollectionUtils.isEmpty(tasks)) {
this.redisUtils.lSet(RedisKeyConstants.cacheTaskByEventAndMemberLevelAndVip + "::" + event + ":" + level + ":" + vip, tasks, 45 * 60);
}
......
......@@ -38,15 +38,8 @@ public class TaskOperationController {
@ApiOperation("事件处理")
@AnonymousAccess
public IResultInfo dealTask(@RequestBody @Validated TaskOperationQueryCriteria criteria) {
log.info("事件处理,开始,参数 ==>> {}", criteria);
long l = System.currentTimeMillis();
// 任务处理
ResultInfo resultInfo = this.taskOperationService.dealTask(criteria.getContent());
long l2 = System.currentTimeMillis();
log.info("事件处理,结束,总耗时 ==>> {}", (l2-l));
return resultInfo;
log.info("事件处理,参数 ==>> dealTask#==>>{}", criteria);
return this.taskOperationService.dealTask(criteria.getContent());
}
/**
......
......@@ -164,7 +164,7 @@ public class UserOperationServiceImpl implements UserOperationService {
}
return null;
return userAppDTO;
}
@Override
......
......@@ -64,7 +64,7 @@
<!--监控sql日志输出 -->
<logger name="jdbc.sqlonly" level="INFO" additivity="false">
<logger name="jdbc.sqlonly" level="OFF" additivity="false">
<appender-ref ref="console" />
<appender-ref ref="info" />
</logger>
......
......@@ -155,7 +155,7 @@ public class TaskOperationControllerTest extends BaseTest {
task.setValidTime(TimestampUtil.now());
task.setPointsType(0);
task.setAttr("{\"value\":\"[1,2]\"}");
// task.setAttr("{\"value\":\"[1,2]\"}");
task.setTaskTemplateId(13L);
......@@ -169,7 +169,7 @@ public class TaskOperationControllerTest extends BaseTest {
Task task = new Task();
BeanUtils.copyProperties(taskDTO, task);
task.setName("testTask4455");
task.setAttr("{\"value\":\"[4,10]\"}");
// task.setAttr("{\"value\":\"[4,10]\"}");
this.taskOperationController.updateTask(task);
}
......