package com.lkd.job;
import com.lkd.common.VMSystem;
import com.lkd.entity.UserEntity;
import com.lkd.service.UserService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Component
@Slf4j
public class UserJob {
@Autowired
private UserService userService;
@Autowired
private RedisTemplate<String,Object> redisTemplate;
/**
* 每日工单量列表初始化
* @param param
* @return
* @throws Exception
*/
@XxlJob("workCountInitJobHandler")
public ReturnT<String> workCountInitJobHandler(String param) throws Exception{
//查询用户列表
List<UserEntity> userList = userService.list();
//如果param为0表示 初始化数据 ,1表示 生成次日数据
int plusDay="0".equals(param)?0:1;
userList.forEach(user->{
if (user.getRegionId().intValue()!=0){//只考虑运维人员和运营人员
String key=VMSystem.REGION_TASK_KEY_PREF
+LocalDate.now().plusDays(plusDay)
.format(DateTimeFormatter.ofPattern("YYYYMMddd"))
+"."+user.getRegionId()+"."+user.getRoleCode();
redisTemplate.opsForZSet().add(key,user.getId(),0);
redisTemplate.expire(key,Duration.ofDays(2));//设置过期时间为2天
}
});
return ReturnT.SUCCESS;
}
}
前一天人员初始化完毕数据,第二天为每个员工从新分配工单
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)