套餐启用增加生效时间

This commit is contained in:
wuweihua
2026-09-17 14:42:48 +08:00
parent 51c8013cd9
commit f3ef2df949
25 changed files with 684 additions and 287 deletions
@@ -7,73 +7,42 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.ruoyi.price.mapper.BmsProductCountryMapper;
import com.ruoyi.price.mapper.BmsProductMapper;
import com.ruoyi.price.service.IPrcPriceSetService;
/**
* bms_product / bms_product_country 状态自动刷新
*
* <p>每天 02:00 根据 effective_date / expire_date 与当天日期,回填 status:
* <ul>
* <li>'2' 已失效 EXPIRED:expire_date 非空且 &lt;= 今天</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
* Refresh prc_price_set_version status (draft/pending/effect/expired).
* Startup + every 5 minutes so PENDING becomes EFFECT when effective_time is reached.
*/
@Component
public class BmsStatusRefreshTask implements ApplicationRunner
{
private static final Logger log = LoggerFactory.getLogger(BmsStatusRefreshTask.class);
@Autowired
private BmsProductMapper productMapper;
@Autowired
private BmsProductCountryMapper productCountryMapper;
@Autowired
private IPrcPriceSetService priceSetService;
/** 每天 02:00 跑(cron: sec min hour DOM month DOW) */
@Scheduled(cron = "0 0 2 * * ?")
public void scheduled()
{
refreshNow();
}
@Override
public void run(ApplicationArguments args)
{
refresh("startup");
}
@Scheduled(cron = "0 0/5 * * * ?")
public void scheduledRefresh()
{
refresh("scheduled");
}
private void refresh(String scene)
{
try
{
int n = priceSetService.refreshAllVersionStatus();
log.info("startup prc_price_set_version expire/status refreshed, sets={}", n);
log.info("{} prc_price_set_version expire/status refreshed, sets={}", scene, n);
}
catch (Exception e)
{
log.error("startup prc_price_set_version refresh failed", e);
log.error("{} prc_price_set_version refresh failed", scene, e);
}
}
/**
* Refresh product/country status and chain version expire_time.
* Returns [product rows, country rows, price-set count].
*/
public int[] refreshNow()
{
int productCount = productMapper.refreshStatusByDates();
int countryCount = productCountryMapper.refreshStatusByDates();
int versionSets = priceSetService.refreshAllVersionStatus();
log.info("BmsStatusRefreshTask done: bms_product={}, bms_product_country={}, price_set_version_sets={}",
productCount, countryCount, versionSets);
return new int[] { productCount, countryCount, versionSets };
}
}
}