88 lines
3.3 KiB
Java
88 lines
3.3 KiB
Java
|
|
package com.zhgd.xmgl.task;
|
||
|
|
|
||
|
|
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||
|
|
import com.zhgd.xmgl.modules.environment.entity.SprayDev;
|
||
|
|
import com.zhgd.xmgl.modules.environment.mapper.SprayDevMapper;
|
||
|
|
import com.zhgd.xmgl.modules.environment.mapper.SprayDevTimingTaskMapper;
|
||
|
|
import com.zhgd.xmgl.util.DustUtils;
|
||
|
|
import lombok.extern.log4j.Log4j;
|
||
|
|
import net.javacrumbs.shedlock.core.SchedulerLock;
|
||
|
|
import org.apache.commons.collections.MapUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
|
||
|
|
import java.util.Calendar;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @program: wisdomSite
|
||
|
|
* @description: 雾炮喷淋设备定时任务
|
||
|
|
* @author: Mr.Peng
|
||
|
|
* @create: 2021-07-07 19:17
|
||
|
|
**/
|
||
|
|
@Log4j
|
||
|
|
@Component
|
||
|
|
public class SprayDevTask {
|
||
|
|
@Autowired
|
||
|
|
private SprayDevMapper sprayDevMapper;
|
||
|
|
@Autowired
|
||
|
|
private SprayDevTimingTaskMapper sprayDevTimingTaskMapper;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 雾炮喷淋设备定时任务执行
|
||
|
|
*/
|
||
|
|
@Scheduled(cron = "0 0/3 * * * ?")
|
||
|
|
@SchedulerLock(name = "executeSprayDevTask", lockAtMostFor = 1000*60*2, lockAtLeastFor = 1000*60*1)
|
||
|
|
public void executeTask(){
|
||
|
|
try{
|
||
|
|
Calendar cal = Calendar.getInstance();
|
||
|
|
cal.setTime(new Date());
|
||
|
|
int weekDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||
|
|
if (weekDay == 0) {
|
||
|
|
weekDay = 7;
|
||
|
|
}
|
||
|
|
List<EntityMap> list=sprayDevTimingTaskMapper.selectSprayDevTimingTaskList(weekDay);
|
||
|
|
if(list!=null&&list.size()>0){
|
||
|
|
for(EntityMap data:list){
|
||
|
|
Integer switchStatus= MapUtils.getInteger(data,"switchStatus");
|
||
|
|
String type="0";
|
||
|
|
if(switchStatus==1){
|
||
|
|
type="-1";
|
||
|
|
}
|
||
|
|
boolean falg=false;
|
||
|
|
Integer deviceType=MapUtils.getInteger(data,"deviceType");
|
||
|
|
if(deviceType==2){
|
||
|
|
String result = DustUtils.sendDualChannelDevOperation(MapUtils.getString(data,"deviceId"), type,MapUtils.getInteger(data,"openChannelNo"),MapUtils.getInteger(data,"closeChannelNo"));
|
||
|
|
if ("success".equals(result)) {
|
||
|
|
falg=true;
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
String result = DustUtils.sendSingleChannelDevOperation(MapUtils.getString(data,"deviceId"), type);
|
||
|
|
if ("success".equals(result)) {
|
||
|
|
falg=true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(falg) {
|
||
|
|
SprayDev sprayDev = new SprayDev();
|
||
|
|
sprayDev.setSwitchStatus(switchStatus);
|
||
|
|
sprayDev.setId(MapUtils.getLong(data, "sprayDevId"));
|
||
|
|
sprayDevMapper.updateById(sprayDev);
|
||
|
|
}
|
||
|
|
//将只执行一次的任务删除
|
||
|
|
if("1".equals(MapUtils.getString(data, "isRepeat"))){
|
||
|
|
sprayDevTimingTaskMapper.deleteById(MapUtils.getString(data, "id"));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}catch (Exception e){
|
||
|
|
e.printStackTrace();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|