|
|
|
@ -2,9 +2,7 @@ package com.shxy.xymanager_service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
@ -24,6 +22,7 @@ import com.shxy.xymanager_common.util.xinyin.ProcessExecUtils;
|
|
|
|
|
import com.shxy.xymanager_common.util.xinyin.ScheduleListUtils;
|
|
|
|
|
import com.shxy.xymanager_common.vo.*;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.*;
|
|
|
|
|
import com.shxy.xymanager_service.service.CacheService;
|
|
|
|
|
import com.shxy.xymanager_service.service.TerminalScheduleRuleService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -31,9 +30,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 时间任务实现层
|
|
|
|
@ -63,13 +62,15 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
@Autowired
|
|
|
|
|
TerminalScheduleDetailsDao terminalScheduleDetailsDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
@Value("${cma.clientid}")
|
|
|
|
|
public int clientid;
|
|
|
|
|
|
|
|
|
|
@Value("${cma.scheduletype}")
|
|
|
|
|
public int scheduletype;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取时间任务规则列表
|
|
|
|
|
*
|
|
|
|
@ -182,6 +183,7 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
}
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
Schedules schedule = new Schedules();
|
|
|
|
|
schedule.setId(scheduleid);
|
|
|
|
|
schedule.setName(vo.getName());
|
|
|
|
|
schedule.setRemark(vo.getRemark());
|
|
|
|
|
schedule.setUpdateTime(date);
|
|
|
|
@ -236,48 +238,68 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
return Asserts.error("没有该装置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScheduleAndRuleDto dto = schedulesDao.selectSingleScheduleAndDetailsList(scheduleid, CommonStatus.EFFECTIVE.value());
|
|
|
|
|
if (BeanUtil.isEmpty(dto)) {
|
|
|
|
|
return Asserts.error("没有该拍照时间规则");
|
|
|
|
|
}
|
|
|
|
|
List<ScheduleDetailsDto> dtoList = dto.getList();
|
|
|
|
|
if (CollectionUtil.isEmpty(dtoList)) {
|
|
|
|
|
return Asserts.error("没有该拍照时间规则");
|
|
|
|
|
}
|
|
|
|
|
// ScheduleAndRuleDto dto = schedulesDao.selectSingleScheduleAndDetailsList(scheduleid, CommonStatus.EFFECTIVE.value());
|
|
|
|
|
// if (BeanUtil.isEmpty(dto)) {
|
|
|
|
|
// return Asserts.error("没有该拍照时间规则");
|
|
|
|
|
// }
|
|
|
|
|
// List<ScheduleDetailsDto> dtoList = dto.getList();
|
|
|
|
|
// if (CollectionUtil.isEmpty(dtoList)) {
|
|
|
|
|
// return Asserts.error("没有该拍照时间规则");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Map<Integer, Terminals> terminalMap = cacheService.getTerminalMap();
|
|
|
|
|
ArrayList<GetScheduleRequestIdListModel.RequestBean> requestIdList = new ArrayList<>();
|
|
|
|
|
for (int x = 0; x < terminalsList.size(); x++) {
|
|
|
|
|
ChannelAndTermDto channelAndTermDto = terminalsList.get(x);
|
|
|
|
|
int requestId = Constants.REQUEST_ID.addAndGet(1);
|
|
|
|
|
int offset = 0;
|
|
|
|
|
for (int i = 0; i < termlist.size(); i++) {
|
|
|
|
|
if (channelAndTermDto.getTermid().intValue() == termlist.get(i).getTermid().intValue()) {
|
|
|
|
|
offset = termlist.get(i).getOffset();
|
|
|
|
|
}
|
|
|
|
|
ArrayList<TerminalSchedulesTemp> templist = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < termlist.size(); i++) {
|
|
|
|
|
String cmdid = null;
|
|
|
|
|
RelateTerminalListRuleIdVo.Items items = termlist.get(i);
|
|
|
|
|
Integer termid = items.getTermid();
|
|
|
|
|
Integer channelid = items.getChannelid();
|
|
|
|
|
Integer offset = items.getOffset();
|
|
|
|
|
if (terminalMap != null && termid != null) {
|
|
|
|
|
Terminals terminals = terminalMap.get(termid);
|
|
|
|
|
cmdid = terminals.getCmdid();
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(cmdid)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String timestr = ScheduleListUtils.relateTime(dtoList, offset);
|
|
|
|
|
List<ScheduleRuleVo> timelist = items.getList();
|
|
|
|
|
if (CollectionUtil.isEmpty(timelist)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String timestr = ScheduleListUtils.relateTime(timelist);
|
|
|
|
|
int requestId = Constants.REQUEST_ID.addAndGet(1);
|
|
|
|
|
|
|
|
|
|
String cmd = CmaUtil.relateSchelduleRule(dtoList, channelAndTermDto.getCmdid(), requestId, channelAndTermDto.getChannelid(), timestr);
|
|
|
|
|
String cmd = CmaUtil.relateSchelduleRule(timelist, cmdid, requestId, channelid, timestr);
|
|
|
|
|
ProcessExecUtils.exec(cmd);
|
|
|
|
|
|
|
|
|
|
log.info("cma下发时间表命令", cmd);
|
|
|
|
|
|
|
|
|
|
GetScheduleRequestIdListModel.RequestBean requestBean = new GetScheduleRequestIdListModel.RequestBean();
|
|
|
|
|
requestBean.setTermid(channelAndTermDto.getTermid());
|
|
|
|
|
requestBean.setChannelid(channelAndTermDto.getChannelid());
|
|
|
|
|
requestBean.setTermid(termid);
|
|
|
|
|
requestBean.setChannelid(channelid);
|
|
|
|
|
requestBean.setRequestid(requestId);
|
|
|
|
|
requestIdList.add(requestBean);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < timelist.size(); j++) {
|
|
|
|
|
ScheduleRuleVo scheduleRuleVo = timelist.get(j);
|
|
|
|
|
Integer hour = scheduleRuleVo.getHour();
|
|
|
|
|
Integer minute = scheduleRuleVo.getMinute();
|
|
|
|
|
Integer preset = scheduleRuleVo.getPreset();
|
|
|
|
|
TerminalSchedulesTemp temp = new TerminalSchedulesTemp();
|
|
|
|
|
temp.setTermId(termid);
|
|
|
|
|
temp.setChannelId(channelid);
|
|
|
|
|
temp.setScheduleId(scheduleid);
|
|
|
|
|
temp.setRequestId(requestId);
|
|
|
|
|
temp.setHour(hour);
|
|
|
|
|
temp.setMinute(minute);
|
|
|
|
|
temp.setPreset(preset);
|
|
|
|
|
temp.setOffset(offset);
|
|
|
|
|
templist.add(temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(templist)) {
|
|
|
|
|
terminalSchedulesTempDao.deleteByTermidAndChannelid(templist);
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
TerminalSchedulesTemp temp = new TerminalSchedulesTemp();
|
|
|
|
|
temp.setTermId(channelAndTermDto.getTermid());
|
|
|
|
|
temp.setChannelId(channelAndTermDto.getChannelid());
|
|
|
|
|
temp.setScheduleId(scheduleid);
|
|
|
|
|
temp.setRequestId(requestId);
|
|
|
|
|
temp.setStatus(CommonStatus.DELETE.value());
|
|
|
|
|
temp.setOffset(offset);
|
|
|
|
|
temp.setCreateTime(date);
|
|
|
|
|
temp.setUpdateTime(date);
|
|
|
|
|
terminalSchedulesTempDao.insertSelective(temp);
|
|
|
|
|
terminalSchedulesTempDao.insertList(templist, CommonStatus.DELETE.value(), date, date);
|
|
|
|
|
}
|
|
|
|
|
model.setList(requestIdList);
|
|
|
|
|
return Asserts.success(model);
|
|
|
|
@ -321,16 +343,19 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
model.setList(modellist);
|
|
|
|
|
return Asserts.success(model);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Integer, Integer> map = new HashMap<>();
|
|
|
|
|
for (TerminalSchedulesTemp item : resultsList) {
|
|
|
|
|
map.put(item.getRequestId(), CommonStatus.EFFECTIVE.value());
|
|
|
|
|
}
|
|
|
|
|
for (RequestIdListVo.RequestBean it : list) {
|
|
|
|
|
ScheduleRequestIdListModel.RequestStatusBean requestBean = new ScheduleRequestIdListModel.RequestStatusBean();
|
|
|
|
|
requestBean.setRequestid(it.getRequestid());
|
|
|
|
|
requestBean.setChannelid(it.getChannelid());
|
|
|
|
|
requestBean.setTermid(it.getTermid());
|
|
|
|
|
requestBean.setStatus(CommonStatus.DELETE.value());
|
|
|
|
|
for (int i = 0; i < resultsList.size(); i++) {
|
|
|
|
|
if (it.getRequestid().intValue() == requestidlist.get(i).intValue()) {
|
|
|
|
|
requestBean.setStatus(CommonStatus.EFFECTIVE.value());
|
|
|
|
|
}
|
|
|
|
|
if (map.get(it.getRequestid()) != null) {
|
|
|
|
|
requestBean.setStatus(CommonStatus.EFFECTIVE.value());
|
|
|
|
|
} else {
|
|
|
|
|
requestBean.setStatus(CommonStatus.DELETE.value());
|
|
|
|
|
}
|
|
|
|
|
modellist.add(requestBean);
|
|
|
|
|
}
|
|
|
|
@ -349,7 +374,9 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
@Override
|
|
|
|
|
public ServiceBody<TerminalScheduleRuleTimeListModel> getChannelSchelduleRule(TerminalAndChannelIdVo vo) {
|
|
|
|
|
TerminalScheduleRuleTimeListModel model = new TerminalScheduleRuleTimeListModel();
|
|
|
|
|
TerminalSchedule mapper = terminalScheduleDao.selectByChannelId(vo.getChannelid(), vo.getTerminalid());
|
|
|
|
|
Integer channelid = vo.getChannelid();
|
|
|
|
|
Integer terminalid = vo.getTerminalid();
|
|
|
|
|
TerminalSchedule mapper = terminalScheduleDao.selectByChannelId(channelid, terminalid);
|
|
|
|
|
if (BeanUtil.isEmpty(mapper)) {
|
|
|
|
|
model.setList(new ArrayList<>());
|
|
|
|
|
return Asserts.success(model);
|
|
|
|
@ -362,28 +389,22 @@ public class TerminalScheduleRuleServiceImpl implements TerminalScheduleRuleServ
|
|
|
|
|
if (mapper == null) {
|
|
|
|
|
model.setList(new ArrayList<>());
|
|
|
|
|
} else {
|
|
|
|
|
Integer scheduleId = mapper.getScheduleId();
|
|
|
|
|
ScheduleAndRuleDto bean = schedulesDao.selectSingleScheduleAndDetailsList(scheduleId, CommonStatus.EFFECTIVE.value());
|
|
|
|
|
if (BeanUtil.isEmpty(bean)) {
|
|
|
|
|
List<TerminalScheduleDetails> list = terminalScheduleDetailsDao.selectByTermidAndChannelid(terminalid, channelid);
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
|
|
model.setList(new ArrayList<>());
|
|
|
|
|
} else {
|
|
|
|
|
List<ScheduleDetailsDto> list = bean.getList();
|
|
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
|
|
model.setList(new ArrayList<>());
|
|
|
|
|
} else {
|
|
|
|
|
ArrayList<TerminalScheduleRuleTimeListModel.ScheduleRuleBean> timestrlist = new ArrayList<>();
|
|
|
|
|
for (ScheduleDetailsDto item : list) {
|
|
|
|
|
TerminalScheduleRuleTimeListModel.ScheduleRuleBean scheduleRuleBean = new TerminalScheduleRuleTimeListModel.ScheduleRuleBean();
|
|
|
|
|
Integer hour = item.getHour();
|
|
|
|
|
Integer minute = item.getMinute();
|
|
|
|
|
Integer preset = item.getPreset();
|
|
|
|
|
scheduleRuleBean.setHour(hour);
|
|
|
|
|
scheduleRuleBean.setMinute(minute);
|
|
|
|
|
scheduleRuleBean.setPreset(preset);
|
|
|
|
|
timestrlist.add(scheduleRuleBean);
|
|
|
|
|
}
|
|
|
|
|
model.setList(timestrlist);
|
|
|
|
|
ArrayList<TerminalScheduleRuleTimeListModel.ScheduleRuleBean> timestrlist = new ArrayList<>();
|
|
|
|
|
for (TerminalScheduleDetails item : list) {
|
|
|
|
|
TerminalScheduleRuleTimeListModel.ScheduleRuleBean scheduleRuleBean = new TerminalScheduleRuleTimeListModel.ScheduleRuleBean();
|
|
|
|
|
Integer hour = item.getHour();
|
|
|
|
|
Integer minute = item.getMinute();
|
|
|
|
|
Integer preset = item.getPreset();
|
|
|
|
|
scheduleRuleBean.setHour(hour);
|
|
|
|
|
scheduleRuleBean.setMinute(minute);
|
|
|
|
|
scheduleRuleBean.setPreset(preset);
|
|
|
|
|
timestrlist.add(scheduleRuleBean);
|
|
|
|
|
}
|
|
|
|
|
model.setList(timestrlist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Asserts.success(model);
|
|
|
|
|