2023-02-16 15:28:15 +08:00

68 lines
2.5 KiB
Java

package com.zhgd.xmgl.task;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhgd.xmgl.async.AsyncAiAnalyse;
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
import com.zhgd.xmgl.modules.inspection.entity.InspectionRecord;
import com.zhgd.xmgl.modules.inspection.mapper.InspectionRecordMapper;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.worker.entity.WorkerHealthyHistory;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import lombok.extern.log4j.Log4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.apache.commons.lang.time.DateUtils;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 信息推送定时任务
*/
@Log4j
@Component
@EnableScheduling
public class MsgPushTask {
@Autowired
private AsyncAiAnalyse asyncAiAnalyse;
@Autowired
private InspectionRecordMapper inspectionRecordMapper;
@Autowired
private SystemUserMapper systemUserMapper;
@Scheduled(cron = "0 0 8 * * ?")
@SchedulerLock(name = "msgPushTask", lockAtMostFor = 1000*60*5, lockAtLeastFor = 1000*100)
public void msgPushTask(){
List<InspectionRecord> inspectionRecords = inspectionRecordMapper.selectInspectionRecordByDate();
if(CollectionUtil.isNotEmpty(inspectionRecords)){
//1.查询用户信息
List<Long> rectifyPeopleIds=inspectionRecords.stream().map(InspectionRecord::getRectifyPeople).collect(Collectors.toList());
QueryWrapper<SystemUser> userQueryWrapperQueryWrapper=new QueryWrapper<SystemUser>();
userQueryWrapperQueryWrapper.lambda().in(SystemUser::getUserId,rectifyPeopleIds);
//2.查询用户信息
List<SystemUser> systemUsers = systemUserMapper.selectList(userQueryWrapperQueryWrapper);
//3.推送消息到手机app
asyncAiAnalyse.sendMsgGotoPeople(systemUsers);
}
}
}