Commit 0cf41771 by 吕明尚

活动增加根据选择日期输出活动列表

parent 913f484c
......@@ -9,6 +9,8 @@ import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.core.page.TableDataInfo;
import share.system.domain.Activity;
import share.system.domain.vo.ActivityDto;
import share.system.domain.vo.ActivityVo;
import share.system.service.ActivityService;
import java.util.List;
......@@ -36,8 +38,8 @@ public class ActivityController extends BaseController {
}
@GetMapping("/query")
public AjaxResult query(Activity activity) {
List<Activity> list = activityService.selectActivityList(activity);
public AjaxResult query(ActivityDto dto) {
List<ActivityVo> list = activityService.queryList(dto);
return success(list);
}
......
package share.system.domain.vo;
import lombok.Data;
import share.system.domain.Activity;
import java.util.Date;
@Data
public class ActivityDto extends Activity {
private Date day;
}
package share.system.domain.vo;
import lombok.Data;
import share.system.domain.Activity;
@Data
public class ActivityVo extends Activity {
}
......@@ -2,6 +2,8 @@ package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.Activity;
import share.system.domain.vo.ActivityDto;
import share.system.domain.vo.ActivityVo;
import java.util.List;
......@@ -59,4 +61,6 @@ public interface ActivityService extends IService<Activity> {
* @return 结果
*/
public int deleteActivityById(Long id);
List<ActivityVo> queryList(ActivityDto dto);
}
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cronutils.model.Cron;
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.model.time.ExecutionTime;
import com.cronutils.parser.CronParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.utils.DateUtils;
import share.common.utils.StringUtils;
import share.common.utils.bean.BeanUtils;
import share.system.domain.Activity;
import share.system.domain.ConsumerMember;
import share.system.domain.SConsumer;
import share.system.domain.SStore;
import share.system.domain.vo.ActivityDto;
import share.system.domain.vo.ActivityVo;
import share.system.mapper.ActivityMapper;
import share.system.service.ActivityService;
import share.system.service.ConsumerMemberService;
import share.system.service.ISStoreService;
import share.system.service.SConsumerService;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -26,6 +43,10 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
private ActivityMapper activityMapper;
@Autowired
private ISStoreService storeService;
@Autowired
private SConsumerService sConsumerService;
@Autowired
private ConsumerMemberService consumerMemberService;
/**
* 查询活动
......@@ -97,4 +118,32 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
public int deleteActivityById(Long id) {
return activityMapper.deleteActivityById(id);
}
@Override
public List<ActivityVo> queryList(ActivityDto dto) {
SConsumer user = sConsumerService.getInfo();
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>()
.eq(ConsumerMember::getConsumerId, user.getId())
);
if (ObjectUtil.isEmpty(consumerMember)) {
return new ArrayList<>();
}
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);
}
});
return voList;
}
}
......@@ -45,7 +45,7 @@
<select id="selectActivityList" parameterType="Activity" resultMap="ActivityResult">
<include refid="selectActivityVo"/>
<where>
where is_open = 1 and is_delete = 0
<if test="activityName != null and activityName != ''">and activity_name like concat('%', #{activityName},
'%')
</if>
......@@ -58,9 +58,6 @@
<if test="labelId != null ">and label_id = #{labelId}</if>
<if test="packId != null ">and pack_id = #{packId}</if>
<if test="cronExpression != null and cronExpression != ''">and cron_expression = #{cronExpression}</if>
<if test="isOpen != null ">and is_open = #{isOpen}</if>
<if test="isDelete != null ">and is_delete = #{isDelete}</if>
</where>
</select>
<select id="selectActivityById" parameterType="Long" resultMap="ActivityResult">
......
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