实现自动脚本修改产品状态
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.ruoyi.price.task;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.price.mapper.BmsProductCountryMapper;
|
||||
import com.ruoyi.price.mapper.BmsProductMapper;
|
||||
|
||||
/**
|
||||
* bms_product / bms_product_country 状态自动刷新
|
||||
*
|
||||
* <p>每天 02:00 根据 effective_date / expire_date 与当天日期,回填 status:
|
||||
* <ul>
|
||||
* <li>'2' 已失效 EXPIRED:expire_date 非空且 <= 今天</li>
|
||||
* <li>'0' 待生效 PENDING:effective_date 为空 / 未来</li>
|
||||
* <li>'1' 已生效 ACTIVE:其余(已生效且仍在有效期)</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>对应字典 bms_product_effect_status 的 value=ACTIVE/PENDING/EXPIRED。
|
||||
* 实际存储使用 0/1/2 与列 comment 保持一致;前端 dict-tag 需做 value 映射或调整 dict_value。
|
||||
*
|
||||
* <p>手动触发:调用 refreshNow()(运维/测试用,详见 StatusRefreshController)。
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class BmsStatusRefreshTask
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(BmsStatusRefreshTask.class);
|
||||
|
||||
@Autowired
|
||||
private BmsProductMapper productMapper;
|
||||
|
||||
@Autowired
|
||||
private BmsProductCountryMapper productCountryMapper;
|
||||
|
||||
/** 每天 02:00 跑(cron: sec min hour DOM month DOW) */
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void scheduled()
|
||||
{
|
||||
refreshNow();
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即刷新两表状态。返回 [product 影响行数, country 影响行数]。
|
||||
* 异常时打印 ERROR 并原样抛出,便于调用方(手动触发接口)回滚事务。
|
||||
*/
|
||||
public int[] refreshNow()
|
||||
{
|
||||
int productCount = productMapper.refreshStatusByDates();
|
||||
int countryCount = productCountryMapper.refreshStatusByDates();
|
||||
log.info("BmsStatusRefreshTask done: bms_product={}, bms_product_country={}",
|
||||
productCount, countryCount);
|
||||
return new int[] { productCount, countryCount };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user