Commit 4c1f519d by 吕明尚

增加查询活动日

parent 0cf41771
......@@ -13,7 +13,9 @@ import share.system.domain.vo.ActivityDto;
import share.system.domain.vo.ActivityVo;
import share.system.service.ActivityService;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 活动Controller
......@@ -39,8 +41,8 @@ public class ActivityController extends BaseController {
@GetMapping("/query")
public AjaxResult query(ActivityDto dto) {
List<ActivityVo> list = activityService.queryList(dto);
return success(list);
Map<Date, List<ActivityVo>> map = activityService.queryList(dto);
return success(map);
}
......
......@@ -5,7 +5,9 @@ import share.system.domain.Activity;
import share.system.domain.vo.ActivityDto;
import share.system.domain.vo.ActivityVo;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 活动Service接口
......@@ -62,5 +64,5 @@ public interface ActivityService extends IService<Activity> {
*/
public int deleteActivityById(Long id);
List<ActivityVo> queryList(ActivityDto dto);
Map<Date, List<ActivityVo>> queryList(ActivityDto dto);
}
......@@ -27,8 +27,7 @@ import share.system.service.SConsumerService;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -120,30 +119,47 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
}
@Override
public List<ActivityVo> queryList(ActivityDto dto) {
public Map<Date, List<ActivityVo>> queryList(ActivityDto dto) {
SConsumer user = sConsumerService.getInfo();
if (ObjectUtil.isEmpty(user)) {
return new HashMap<>();
}
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>()
.eq(ConsumerMember::getConsumerId, user.getId())
);
if (ObjectUtil.isEmpty(consumerMember)) {
return new ArrayList<>();
return new HashMap<>();
}
List<Date> days = new ArrayList<>();
//从当前的日期开始,加4天
for (int i = 0; i <= 4; i++) {
days.add(DateUtils.addDays(new Date(), i));
}
Activity activity = new Activity();
BeanUtils.copyProperties(dto, activity);
List<Activity> activities = selectActivityList(activity);
CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
List<ActivityVo> voList = new ArrayList<>();
activities.stream().forEach(item -> {
Cron cron = cronParser.parse(item.getCronExpression());
ExecutionTime executionTime = ExecutionTime.forCron(cron);
boolean match = executionTime.isMatch(ZonedDateTime.ofInstant(dto.getDay().toInstant(), ZoneId.systemDefault()));
if (match && consumerMember.getMemberType().equals(item.getMemberType())) {
ActivityVo activityVo = new ActivityVo();
BeanUtils.copyProperties(item, activityVo);
voList.add(activityVo);
Map<Date, List<ActivityVo>> map = new HashMap<>();
days.stream().forEach(day -> {
List<ActivityVo> voList = new ArrayList<>();
activities.stream().forEach(item -> {
Cron cron = cronParser.parse(item.getCronExpression());
ExecutionTime executionTime = ExecutionTime.forCron(cron);
boolean match = executionTime.isMatch(ZonedDateTime.ofInstant(day.toInstant(), ZoneId.systemDefault()));
if (match && consumerMember.getMemberType().equals(item.getMemberType())) {
ActivityVo activityVo = new ActivityVo();
BeanUtils.copyProperties(item, activityVo);
voList.add(activityVo);
}
});
if (voList.size() > 0) {
map.put(day, voList);
} else {
map.put(day, new ArrayList<>());
}
});
return voList;
return map;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment