砍价逻辑状态定时任务补充
This commit is contained in:
parent
0152518315
commit
cb74d80aab
@ -50,11 +50,19 @@ public interface ShopActivityCutpriceService extends IBaseService<ShopActivityCu
|
||||
|
||||
|
||||
/**
|
||||
* 修改某个砍价订单状态
|
||||
* 根据自增Id 或 activity_id,修改某个砍价订单状态
|
||||
*
|
||||
* @param ac_id 活动自增Id
|
||||
* @param state 状态
|
||||
* @param ac_id 活动自增Id (ac_id 和 activity_id 其中一个必填)
|
||||
* @param activity_id 活动Id (ac_id 和 activity_id 其中一个必填)
|
||||
* @param state 状态
|
||||
* @return
|
||||
*/
|
||||
Boolean updateCutPriceState(Integer ac_id, Integer state);
|
||||
Boolean updateCutPriceState(Integer ac_id, Integer activity_id, Integer state);
|
||||
|
||||
/**
|
||||
* 砍价活动结束后,定时修改砍价订单状态 定时任务(包括多个状态业务变更)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer autoUpdateCutPriceStateJob();
|
||||
}
|
||||
|
||||
@ -412,7 +412,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
ShopStoreActivityBase shopStoreActivityBase = shopStoreActivityBaseService.get(shopActivityCutprice.getActivity_id());
|
||||
if (shopStoreActivityBase == null) {
|
||||
// 活动不存在,更新砍价订单状态为已取消
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), CommonConstant.CutPrice_Order_State_Canceled);
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
|
||||
return CommonResult.failed(I18nUtil._("抱歉,砍价活动已失效!"));
|
||||
}
|
||||
|
||||
@ -421,7 +421,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
// 如果活动已结束或已关闭,更新砍价订单状态为已取消
|
||||
if (ObjectUtil.equal(shopStoreActivityBase.getActivity_state(), StateCode.ACTIVITY_STATE_FINISHED)
|
||||
|| ObjectUtil.equal(shopStoreActivityBase.getActivity_state(), StateCode.ACTIVITY_STATE_CLOSED)) {
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), CommonConstant.CutPrice_Order_State_Canceled);
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Canceled);
|
||||
}
|
||||
return CommonResult.failed(I18nUtil._("抱歉,砍价活动已失效!"));
|
||||
}
|
||||
@ -432,14 +432,14 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
// 检查砍价订单是否过期
|
||||
if (CheckUtil.isNotEmpty(expired_at) && expired_at < now.getTime()) {
|
||||
// 砍价订单已过期,更新状态为已过期
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), CommonConstant.CutPrice_Order_State_Expired);
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
|
||||
return CommonResult.failed(I18nUtil._("砍价已过期,下次早点来!"));
|
||||
}
|
||||
|
||||
// 检查活动是否已结束(活动时间已过)
|
||||
if (!shopStoreActivityBaseService.isActivityTimeValid(shopStoreActivityBase, now)) {
|
||||
// 活动已结束,更新砍价订单状态为已过期
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), CommonConstant.CutPrice_Order_State_Expired);
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_Expired);
|
||||
return CommonResult.failed(I18nUtil._("砍价已过期,下次早点来!"));
|
||||
}
|
||||
|
||||
@ -464,10 +464,12 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
|
||||
// 检查是否已达到最低价
|
||||
if (NumberUtil.isLessOrEqual(ac_sale_price, ac_mix_limit_price)) {
|
||||
// 根据上次的状态,立即更改状态:6-砍价助力已完成待下单;
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished);
|
||||
|
||||
return CommonResult.failed(I18nUtil._("已达到最低价!"));
|
||||
}
|
||||
|
||||
|
||||
// 检查是否已经帮过好友砍了价
|
||||
QueryWrapper<ShopActivityCutpriceHistory> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", user_id).eq("ac_id", ac_id);
|
||||
@ -522,6 +524,11 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
redisService.hSet("cutprice-" + today, user_id.toString(), cut_num + 1, 24 * 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
// 根据最新砍价信息(最后一次砍价成功之后,达到最低砍价价格),更新砍价订单状态
|
||||
if (NumberUtil.isGreaterOrEqual(shopActivityCutprice.getAc_sale_price(), ac_mix_limit_price)) {
|
||||
updateCutPriceState(shopActivityCutprice.getAc_id(), null, CommonConstant.CutPrice_Order_State_CutFinished);
|
||||
}
|
||||
|
||||
return CommonResult.success(ach_data);
|
||||
}
|
||||
|
||||
@ -653,32 +660,127 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
||||
|
||||
|
||||
/**
|
||||
* 修改某个砍价订单状态
|
||||
* 根据自增Id 或 activity_id,修改某个砍价订单状态
|
||||
*
|
||||
* @param ac_id 活动自增Id
|
||||
* @param state 状态
|
||||
* @return
|
||||
* @param ac_id 活动自增Id (ac_id 和 activity_id 其中一个必填)
|
||||
* @param activity_id 活动Id (ac_id 和 activity_id 其中一个必填)
|
||||
* @param state 状态
|
||||
* @return Boolean 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateCutPriceState(Integer ac_id, Integer state) {
|
||||
// 参数校验
|
||||
if (ac_id == null || ac_id <= 0) {
|
||||
public Boolean updateCutPriceState(Integer ac_id, Integer activity_id, Integer state) {
|
||||
// 参数校验:ac_id 和 activity_id 至少有一个不为空,且 state 不为空
|
||||
if ((ac_id == null || ac_id <= 0) && (activity_id == null || activity_id <= 0)) {
|
||||
log.warn("更新砍价订单状态参数错误:ac_id 和 activity_id 不能同时为空");
|
||||
return false;
|
||||
}
|
||||
if (state == null) {
|
||||
log.warn("更新砍价订单状态参数错误:state 不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
UpdateWrapper<ShopActivityCutprice> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("ac_id", ac_id);
|
||||
updateWrapper.set("state", state);
|
||||
// 根据 ac_id 或 activity_id 条件更新状态,避免重复更新相同状态
|
||||
if (ac_id != null && ac_id > 0) {
|
||||
updateWrapper.eq("ac_id", ac_id);
|
||||
}
|
||||
if (activity_id != null && activity_id > 0) {
|
||||
updateWrapper.eq("activity_id", activity_id);
|
||||
}
|
||||
updateWrapper.ne("state", state).set("state", state);
|
||||
return update(updateWrapper);
|
||||
} catch (Exception e) {
|
||||
log.error("更新砍价订单状态失败,ac_id={}, state={}", ac_id, state, e);
|
||||
throw new ApiException(I18nUtil._("更新砍价订单状态失败"));
|
||||
log.error("更新砍价订单状态失败,ac_id={}, activity_id={}, state={}", ac_id, activity_id, state, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 砍价活动结束后,定时修改砍价订单状态 定时任务(包括多个状态业务变更)
|
||||
* <p>
|
||||
* 砍价订单状态:1-砍价已完成下单;2-砍价未下单已取消;3-砍价助力进行中;4-砍价过期失效;6-砍价助力已完成待下单;
|
||||
* <p>
|
||||
* 1、某个砍价订单未超时情况下,更改(3-砍价助力进行中,砍到最低价时)的状态为 (6-砍价助力已完成待下单)
|
||||
* 2、某个砍价订单超时的情况下,定时更改(3-砍价助力进行中)的状态为 (4-砍价过期失效)
|
||||
* 3、砍价活动结束后,定时更改(3-砍价助力进行中和6-砍价助力已完成待下单)的状态为 (4-砍价过期失效和2-砍价未下单已取消;)
|
||||
*
|
||||
* @return 成功更新的操作次数
|
||||
*/
|
||||
@Override
|
||||
public Integer autoUpdateCutPriceStateJob() {
|
||||
int successCount = 0;
|
||||
log.info("开始执行砍价订单状态定时更新任务");
|
||||
|
||||
try {
|
||||
// 1、某个砍价订单未超时情况下,更改(3-砍价助力进行中,砍到最低价时)的状态为 (6-砍价助力已完成待下单)
|
||||
UpdateWrapper<ShopActivityCutprice> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("state", CommonConstant.CutPrice_Order_State_ING)
|
||||
.ge("expired_at", System.currentTimeMillis())
|
||||
.apply("ac_sale_price <= ac_mix_limit_price")
|
||||
.set("state", CommonConstant.CutPrice_Order_State_CutFinished);
|
||||
|
||||
log.debug("准备执行更新操作1:将状态3且未过期且达到最低价的砍价订单更新为状态6");
|
||||
if (update(updateWrapper)) {
|
||||
log.info("成功更新砍价订单状态为【砍价助力已完成待下单】,条件:state={}, ac_sale_price<=ac_mix_limit_price",
|
||||
CommonConstant.CutPrice_Order_State_ING);
|
||||
successCount++;
|
||||
} else {
|
||||
log.debug("更新操作1未匹配到任何记录");
|
||||
}
|
||||
|
||||
// 2、某个砍价订单超时的情况下,定时更改(3-砍价助力进行中)的状态为 (4-砍价过期失效)
|
||||
updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("state", CommonConstant.CutPrice_Order_State_ING)
|
||||
.lt("expired_at", System.currentTimeMillis())
|
||||
.set("state", CommonConstant.CutPrice_Order_State_Expired);
|
||||
|
||||
log.debug("准备执行更新操作2:将状态3且已过期的砍价订单更新为状态4");
|
||||
if (update(updateWrapper)) {
|
||||
log.info("成功更新砍价订单状态为【砍价过期失效】,条件:state={}, expired_at<{}",
|
||||
CommonConstant.CutPrice_Order_State_ING, System.currentTimeMillis());
|
||||
successCount++;
|
||||
} else {
|
||||
log.debug("更新操作2未匹配到任何记录");
|
||||
}
|
||||
|
||||
// 3、砍价活动结束后,定时更改(3-砍价助力进行中和6-砍价助力已完成待下单)的状态为 (4-砍价过期失效和2-砍价未下单已取消;)
|
||||
// 处理状态3(砍价助力进行中) -> 状态4(砍价过期失效)
|
||||
updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("state", CommonConstant.CutPrice_Order_State_ING)
|
||||
.exists("SELECT 1 FROM shop_store_activity_base WHERE shop_store_activity_base.activity_id = shop_activity_cutprice.activity_id AND shop_store_activity_base.activity_endtime < NOW()")
|
||||
.set("state", CommonConstant.CutPrice_Order_State_Expired);
|
||||
|
||||
log.debug("准备执行更新操作3:将状态3且活动已结束的砍价订单更新为状态4");
|
||||
if (update(updateWrapper)) {
|
||||
log.info("成功更新砍价订单状态为【砍价过期失效】,条件:state={}, activity_endtime<NOW()",
|
||||
CommonConstant.CutPrice_Order_State_ING);
|
||||
successCount++;
|
||||
} else {
|
||||
log.debug("更新操作3未匹配到任何记录");
|
||||
}
|
||||
|
||||
// 处理状态6(砍价助力已完成待下单) -> 状态2(砍价未下单已取消)
|
||||
updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("state", CommonConstant.CutPrice_Order_State_CutFinished)
|
||||
.exists("SELECT 1 FROM shop_store_activity_base WHERE shop_store_activity_base.activity_id = shop_activity_cutprice.activity_id AND shop_store_activity_base.activity_endtime < NOW()")
|
||||
.set("state", CommonConstant.CutPrice_Order_State_Canceled);
|
||||
|
||||
log.debug("准备执行更新操作4:将状态6且活动已结束的砍价订单更新为状态2");
|
||||
if (update(updateWrapper)) {
|
||||
log.info("成功更新砍价订单状态为【砍价未下单已取消】,条件:state={}, activity_endtime<NOW()",
|
||||
CommonConstant.CutPrice_Order_State_CutFinished);
|
||||
successCount++;
|
||||
} else {
|
||||
log.debug("更新操作4未匹配到任何记录");
|
||||
}
|
||||
|
||||
log.info("定时任务更新砍价订单状态完成,总共成功执行{}次更新操作", successCount);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("定时任务更新砍价订单状态时发生异常,已成功执行{}次更新操作", successCount, e);
|
||||
}
|
||||
|
||||
return successCount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.api.StateCode;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
||||
import com.suisung.mall.shop.activity.service.ShopActivityCutpriceService;
|
||||
import com.suisung.mall.shop.config.SpringUtil;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
||||
import org.quartz.JobExecutionContext;
|
||||
@ -27,6 +28,7 @@ public class UpdateActivityStatusJob extends QuartzJobBean {
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
Logger logger = LoggerFactory.getLogger(UpdateActivityStatusJob.class);
|
||||
ShopStoreActivityBaseService shopStoreActivityBaseService = SpringUtil.getBean(ShopStoreActivityBaseService.class);
|
||||
ShopActivityCutpriceService shopActivityCutpriceService = SpringUtil.getBean(ShopActivityCutpriceService.class);
|
||||
TransactionTemplate transactionTemplate = SpringUtil.getBean(TransactionTemplate.class);
|
||||
|
||||
int page = 1;
|
||||
@ -63,5 +65,8 @@ public class UpdateActivityStatusJob extends QuartzJobBean {
|
||||
page++;
|
||||
}
|
||||
|
||||
// 更新砍价订单的过期状态
|
||||
shopActivityCutpriceService.autoUpdateCutPriceStateJob();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2090,7 +2090,6 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
||||
Date starTime = shopStoreActivityBase.getActivity_starttime();
|
||||
Date endTime = shopStoreActivityBase.getActivity_endtime();
|
||||
|
||||
|
||||
return isActivityTimeValid(starTime, endTime, checkTime);
|
||||
}
|
||||
|
||||
|
||||
@ -2379,6 +2379,7 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
if (storeBizState == 3 && storeBizOpeningDate == null) {
|
||||
return CommonResult.failed("店铺如果开业(活动)筹备中,请输入开业日期:yyyy-MM-dd");
|
||||
}
|
||||
base.setStore_biz_opening_date(storeBizOpeningDate);
|
||||
}
|
||||
|
||||
// 打包费
|
||||
@ -2550,6 +2551,7 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
if (storeBizState == 3 && storeBizOpeningDate == null) {
|
||||
return CommonResult.failed("店铺如果开业(活动)筹备中,请输入开业日期:yyyy-MM-dd");
|
||||
}
|
||||
base.setStore_biz_opening_date(storeBizOpeningDate);
|
||||
}
|
||||
|
||||
ShopStoreCompany company = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user