Skip to content

Commit

Permalink
feat:申购后延迟10秒领取耐力
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed Aug 18, 2023
1 parent efac99d commit 3acd906
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

/**
* 异步任务管理器
*
*
* @author ruoyi
*/
public class AsyncManager
{
public class AsyncManager {
/**
* 操作延迟10毫秒
*/
Expand All @@ -27,30 +26,28 @@ public class AsyncManager
/**
* 单例模式
*/
private AsyncManager(){}
private AsyncManager() {
}

private static AsyncManager me = new AsyncManager();

public static AsyncManager me()
{
public static AsyncManager me() {
return me;
}

/**
* 执行任务
*
*
* @param task 任务
*/
public void execute(TimerTask task)
{
public void execute(TimerTask task) {
executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
}

/**
* 停止任务线程池
*/
public void shutdown()
{
public void shutdown() {
Threads.shutdownAndAwaitTermination(executor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.oddfar.campus.common.domain.PageResult;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
Expand Down Expand Up @@ -43,7 +42,7 @@ default PageResult<IUser> selectPage(IUser iUser, Long userId) {

default List<IUser> selectReservationUser() {
return selectList(new LambdaQueryWrapperX<IUser>()
.gt(IUser::getExpireTime, new Date())
// .gt(IUser::getExpireTime, new Date())
.ne(IUser::getLat, "")
.ne(IUser::getLng, "")
.ne(IUser::getShopType, "")
Expand All @@ -59,15 +58,15 @@ default List<IUser> selectReservationUser() {
default List<IUser> selectReservationUserByMinute(int minute) {
return selectList(new LambdaQueryWrapperX<IUser>()
.eq(IUser::getMinute, minute)
.gt(IUser::getExpireTime, new Date())
// .gt(IUser::getExpireTime, new Date())
.ne(IUser::getLat, "")
.ne(IUser::getLng, "")
.ne(IUser::getShopType, "")
.ne(IUser::getItemCode, "")
);
}

@Select("UPDATE i_user SET `minute` = (SELECT FLOOR(RAND() * 59 + 1)) WHERE random_minute = \"0\"")
@Select("UPDATE i_user SET `minute` = (SELECT FLOOR(RAND() * 50 + 1)) WHERE random_minute = \"0\"")
void updateUserMinuteBatch();

int deleteIUser(Long[] iUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ public interface IMTService {
void appointmentResults();



}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.oddfar.campus.business.entity.IUser;
import com.oddfar.campus.business.mapper.IShopMapper;
import com.oddfar.campus.business.mapper.IUserMapper;
import com.oddfar.campus.business.service.IMTLogFactory;
import com.oddfar.campus.business.service.IMTService;
Expand Down Expand Up @@ -46,8 +45,6 @@ public class IMTServiceImpl implements IMTService {

private static final Logger logger = LoggerFactory.getLogger(IMTServiceImpl.class);

@Autowired
private IShopMapper iShopMapper;
@Autowired
private IUserMapper iUserMapper;

Expand Down Expand Up @@ -195,15 +192,44 @@ public void reservation(IUser iUser) {
logContent += String.format("执行报错--[预约项目]:%s\n[结果返回]:%s\n\n", itemId, e.getMessage());
}
}
try {
//预约后领取耐力值
String energyAward = getEnergyAward(iUser);
logContent += "[申购耐力值]:" + energyAward;
} catch (Exception e) {
logContent += "执行报错--[申购耐力值]:" + e.getMessage();
}

// try {
// //预约后领取耐力值
// String energyAward = getEnergyAward(iUser);
// logContent += "[申购耐力值]:" + energyAward;
// } catch (Exception e) {
// logContent += "执行报错--[申购耐力值]:" + e.getMessage();
// }
//日志记录
IMTLogFactory.reservation(iUser, logContent);
//预约后延迟领取耐力值
getEnergyAwardDelay(iUser);
}

/**
* 延迟执行:获取申购耐力值,并记录日志
*
* @param iUser
*/
public void getEnergyAwardDelay(IUser iUser) {
Runnable runnable = new Runnable() {
@Override
public void run() {
String logContent = "";
//sleep 10秒
try {
Thread.sleep(10000);
//预约后领取耐力值
String energyAward = getEnergyAward(iUser);
logContent += "[申购耐力值]:" + energyAward;
} catch (Exception e) {
logContent += "执行报错--[申购耐力值]:" + e.getMessage();
}
//日志记录
IMTLogFactory.reservation(iUser, logContent);
}
};
new Thread(runnable).start();

}

Expand All @@ -220,7 +246,6 @@ public String getEnergyAward(IUser iUser) {
.header("MT-Lng", iUser.getLng())
.cookie("MT-Token-Wap=" + iUser.getCookie() + ";MT-Device-ID-Wap=" + iUser.getDeviceId() + ";");


String body = request.execute().body();

JSONObject jsonObject = JSONObject.parseObject(body);
Expand Down

0 comments on commit 3acd906

Please sign in to comment.