12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package com.caimei365.tools.task;
- import com.caimei365.tools.mapper.BaseMapper;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import javax.annotation.Resource;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- /**
- * 商品定时器
- *
- * @author : Charles
- * @date : 2021/10/26
- */
- @Slf4j
- @Configuration
- @EnableScheduling
- @RequiredArgsConstructor
- public class ProductTask {
- @Resource
- private BaseMapper baseMapper;
- /**
- * 每天凌晨1点执行一次
- * todo 二手商品暂无,弃用二手商品自动下架 同时商品下架标记进入 cm_organize_product_info 恢复使用时需修改sql
- */
- // @Scheduled(cron = "0 0 1 * * ?")
- public void task() {
- long currentTime = System.currentTimeMillis();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date currentDate = new Date(currentTime);
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>【自动】采美二手商品到期下架,时间:" + formatter.format(currentDate));
- try {
- //得到日历
- Calendar calendar = Calendar.getInstance();
- //把当前时间赋给日历
- calendar.setTime(currentDate);
- //设置为day月前
- calendar.add(Calendar.MONTH, -3);
- //得到3月前的时间
- Date beforeDays = calendar.getTime();
- // 获取时间到期且未下架的二手商品Id
- List<Integer> secondIdList = baseMapper.getMaturitySecondProductIds(beforeDays);
- if (CollectionUtils.isNotEmpty(secondIdList)) {
- for (Integer productId : secondIdList) {
- baseMapper.updateProductValidFlag(productId, "3");
- }
- }
- } catch (Exception e) {
- log.error("try-catch:",e);
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>采美二手商品到期下架失败");
- }
- }
- }
|