修改套餐价格

This commit is contained in:
wuweihua
2026-09-16 17:14:19 +08:00
parent 7172621fd3
commit 4441aa12bf
48 changed files with 4258 additions and 682 deletions
@@ -3,10 +3,13 @@ package com.ruoyi.price.task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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 状态自动刷新
@@ -26,7 +29,7 @@ import com.ruoyi.price.mapper.BmsProductMapper;
* @author ruoyi
*/
@Component
public class BmsStatusRefreshTask
public class BmsStatusRefreshTask implements ApplicationRunner
{
private static final Logger log = LoggerFactory.getLogger(BmsStatusRefreshTask.class);
@@ -36,6 +39,9 @@ public class BmsStatusRefreshTask
@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()
@@ -43,16 +49,31 @@ public class BmsStatusRefreshTask
refreshNow();
}
@Override
public void run(ApplicationArguments args)
{
try
{
int n = priceSetService.refreshAllVersionStatus();
log.info("startup prc_price_set_version expire/status refreshed, sets={}", n);
}
catch (Exception e)
{
log.error("startup prc_price_set_version refresh failed", e);
}
}
/**
* 立即刷新两表状态。返回 [product 影响行数, country 影响行数]。
* 异常时打印 ERROR 并原样抛出,便于调用方(手动触发接口)回滚事务。
* 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();
log.info("BmsStatusRefreshTask done: bms_product={}, bms_product_country={}",
productCount, countryCount);
return new int[] { productCount, countryCount };
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 };
}
}
@@ -0,0 +1,70 @@
package com.ruoyi.price.task;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcPriceSet;
import com.ruoyi.price.domain.PrcPriceSetSaveTask;
import com.ruoyi.price.service.IPrcPriceSetService;
/**
* Async runner for price-set save (avoids HTTP timeout on large detail snapshots).
*/
@Component
public class PrcPriceSetSaveAsyncRunner
{
private static final Logger log = LoggerFactory.getLogger(PrcPriceSetSaveAsyncRunner.class);
public static final String CACHE_KEY_PREFIX = "price:set:save:task:";
public static final int TTL_MINUTES = 60;
@Autowired
private IPrcPriceSetService priceSetService;
@Autowired
private RedisCache redisCache;
@Async("threadPoolTaskExecutor")
public void run(String taskId, PrcPriceSet set)
{
try
{
put(taskId, PrcPriceSetSaveTask.STATUS_RUNNING, 8, "saving basic", null, null);
set.setSaveTaskId(taskId);
Long id = priceSetService.savePrcPriceSet(set);
put(taskId, PrcPriceSetSaveTask.STATUS_SUCCESS, 100, "done", id, null);
}
catch (Exception e)
{
log.error("async save price set failed, taskId={}", taskId, e);
String msg = e.getMessage();
if (StringUtils.isEmpty(msg))
{
msg = e.getClass().getSimpleName();
}
put(taskId, PrcPriceSetSaveTask.STATUS_FAIL, 100, "failed", null, msg);
}
}
public void put(String taskId, String status, int percent, String message, Long priceSetId, String error)
{
PrcPriceSetSaveTask task = new PrcPriceSetSaveTask();
task.setTaskId(taskId);
task.setStatus(status);
task.setPercent(percent);
task.setMessage(message);
task.setPriceSetId(priceSetId);
task.setError(error);
redisCache.setCacheObject(CACHE_KEY_PREFIX + taskId, task, TTL_MINUTES, TimeUnit.MINUTES);
}
public PrcPriceSetSaveTask get(String taskId)
{
return redisCache.getCacheObject(CACHE_KEY_PREFIX + taskId);
}
}