Commit fab50ddf by xmh

转发服务:

1. <feat> 录像存储添加 eventTime 字段

运维服务:
1. <feat> 重构 nvs3000 拉取,拉取时自动创建相应 cate 和 code
2. <feat> 视频通道按名称过滤,并且支持树状结构
3. <feat> 接口优化,能合并的就合并

任务服务:
1. <fix> 任务初始化优化逻辑
1 parent e0d8a6b4
......@@ -28,6 +28,7 @@ public class DateConverter implements Converter<String, Date> {
formarts.add("HH:mm:ss");
formarts.add("HH:mm");
formarts.add("yyyy-MM-dd'T'HH:mm:ss");
formarts.add("yyyy-MM-dd HH:mm:ss.S");
}
@Override
......@@ -50,6 +51,8 @@ public class DateConverter implements Converter<String, Date> {
return parseDate(source, formarts.get(5));
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{1,2}:\\d{1,2}[-,+]\\d{1,2}:\\d{1,2}$")) {
return parseDate(source, formarts.get(6));
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}\\.\\d{1,3}$")) {
return parseDate(source, formarts.get(7));
} else {
throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
}
......
......@@ -5,6 +5,8 @@ import com.viontech.fanxing.commons.vobase.ChannelVoBase;
public class ChannelVo extends ChannelVoBase {
private Boolean tree;
public ChannelVo() {
super();
}
......@@ -12,4 +14,13 @@ public class ChannelVo extends ChannelVoBase {
public ChannelVo(Channel channel) {
super(channel);
}
public Boolean getTree() {
return tree;
}
public ChannelVo setTree(Boolean tree) {
this.tree = tree;
return this;
}
}
\ No newline at end of file
......@@ -8,6 +8,9 @@ import java.util.List;
public class DictCodeVo extends DictCodeVoBase {
private List<DictCodeVo> children;
private List<ChannelVo> channels;
private Boolean tree;
public DictCodeVo() {
super();
......@@ -24,4 +27,22 @@ public class DictCodeVo extends DictCodeVoBase {
public void setChildren(List<DictCodeVo> children) {
this.children = children;
}
public List<ChannelVo> getChannels() {
return channels;
}
public DictCodeVo setChannels(List<ChannelVo> channels) {
this.channels = channels;
return this;
}
public Boolean getTree() {
return tree;
}
public DictCodeVo setTree(Boolean tree) {
this.tree = tree;
return this;
}
}
\ No newline at end of file
......@@ -72,8 +72,7 @@ public class DataReceiveController {
public Object video(VideoResult videoResult) throws Exception {
String unid = videoResult.getRefid();
log.info("接收到视频录像文件,refId:{},文件名:{}", unid, videoResult.getFile().getOriginalFilename());
// todo 之后会加上 eventTime 字段,目前先 new Date()
String filePath = picUtils.getFilePath(unid, new Date(), videoResult.getFormat() == null ? "mp4" : videoResult.getFormat());
String filePath = picUtils.getFilePath(unid, videoResult.getEventTime() == null ? new Date() : videoResult.getEventTime(), videoResult.getFormat() == null ? "mp4" : videoResult.getFormat());
File file = new File(filePath);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
......
......@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
/**
* .
*
......@@ -23,4 +25,6 @@ public class VideoResult {
private String unid;
private Date eventTime;
}
package com.viontech.fanxing.ops.controller.web;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.controller.base.ChannelBaseController;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;
import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/channels")
......@@ -30,68 +24,25 @@ public class ChannelController extends ChannelBaseController {
return channelExample;
}
@PostMapping("/nvs3000")
public Object nvs3000(@RequestBody JSONObject jsonObject) {
String addressUnid = jsonObject.getString("addressUnid");
String nvsUrl = jsonObject.getString("nvsUrl");
String nvsRegex = jsonObject.getString("nvsRegex");
ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andAddressUnidEqualTo(addressUnid).andExpandEqualTo("nvs3000");
channelExample.createColumns().hasChannelUnidColumn();
List<Channel> channels = getService().selectByExample(channelExample);
Set<String> channelUnidSet = channels.stream().map(Channel::getChannelUnid).collect(Collectors.toSet());
JSONObject nvsPostData = new JSONObject();
nvsPostData.put("fromindex", 0);
nvsPostData.put("toindex", -1);
JSONObject nvsResponse = WebClient.create()
.post()
.uri(nvsUrl + "/nvsthird/getcamlist")
.bodyValue(nvsPostData)
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(10));
if (nvsResponse == null || !nvsResponse.containsKey("group")) {
return JsonMessageUtil.getSuccessJsonMsg("没有数据");
}
JSONArray group = nvsResponse.getJSONArray("group");
int repeat = 0;
int filtered = 0;
int success = 0;
for (int i = 0; i < group.size(); i++) {
JSONObject item = group.getJSONObject(i);
String description = item.getString("description");
if (StringUtils.isBlank(description)) {
filtered++;
continue;
}
String name = item.getString("name");
String id = item.getString("id");
if (channelUnidSet.contains(id)) {
repeat++;
continue;
}
Channel channel = new Channel();
channel.setChannelUnid(id);
channel.setName(name);
channel.setAddressUnid(addressUnid);
channel.setType(1);
channel.setExpand("nvs3000");
channel.setStreamType(0);
channel.setStreamPath(nvsRegex + id);
getService().insertSelective(channel);
success++;
@Override
@GetMapping()
public Object page(ChannelVo channelVo,
@RequestParam(value = "page", defaultValue = "-1") int page,
@RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
String sortName, String sortOrder) {
if (channelVo.getTree() != null && channelVo.getTree()) {
BaseExample example = getExample(channelVo, EXAMPLE_TYPE_PAGE);
List<Channel> channels = channelService.selectByExample(example);
List<DictCodeVo> dictCodeVos = channelService.channelOrg(channels);
return JsonMessageUtil.getSuccessJsonMsg(dictCodeVos);
} else {
return super.page(channelVo, page, pageSize, sortName, sortOrder);
}
}
jsonObject.put("filtered", filtered);
jsonObject.put("repeat", repeat);
jsonObject.put("insert", success);
log.info("拉取nvs3000 : {}", jsonObject);
return JsonMessageUtil.getSuccessJsonMsg(jsonObject);
@PostMapping("/nvs3000")
public Object nvs3000(@RequestBody JSONObject jsonObject) {
JSONObject result = channelService.nvs3000(jsonObject.getString("nvsUrl"), jsonObject.getString("nvsRegex"));
return JsonMessageUtil.getSuccessJsonMsg(result);
}
}
\ No newline at end of file
package com.viontech.fanxing.ops.controller.web;
import com.viontech.fanxing.ops.controller.base.DictCodeBaseController;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.DictCodeExample;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.controller.base.DictCodeBaseController;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/dictCodes")
......@@ -29,28 +27,15 @@ public class DictCodeController extends DictCodeBaseController {
return dictCodeExample;
}
@GetMapping("/tree")
@ResponseBody
public Object getTreeCode(@RequestParam Long cateId) {
DictCodeExample dictCodeExample = new DictCodeExample();
dictCodeExample.createCriteria().andCateIdEqualTo(cateId);
Map<Long, DictCodeVo> map = getService().selectByExample(dictCodeExample).stream().map(DictCodeVo::new).collect(Collectors.toMap(DictCode::getId, x -> x, (x, y) -> x));
List<DictCodeVo> result = new ArrayList<>();
for (Map.Entry<Long, DictCodeVo> entry : map.entrySet()) {
DictCodeVo value = entry.getValue();
if (value.getParentId() == null) {
result.add(value);
} else {
DictCodeVo parent = map.get(value.getParentId());
if (parent != null) {
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(value);
}
}
@Override
@GetMapping
public Object page(DictCodeVo dictCodeVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize, String sortName, String sortOrder) {
if (dictCodeVo.getTree() != null && dictCodeVo.getTree()) {
BaseExample example = getExample(dictCodeVo, EXAMPLE_TYPE_PAGE);
List<DictCode> dictCodes = dictCodeService.selectByExample(example);
ImmutablePair<Map<Long, DictCodeVo>, List<DictCodeVo>> treeCode = dictCodeService.getTreeCode(dictCodes);
return JsonMessageUtil.getSuccessJsonMsg(treeCode.right);
}
return JsonMessageUtil.getSuccessJsonMsg(result);
return super.page(dictCodeVo, page, pageSize, sortName, sortOrder);
}
}
\ No newline at end of file
package com.viontech.fanxing.ops.service.adapter;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import java.util.List;
public interface ChannelService extends BaseService<Channel> {
JSONObject nvs3000(String nvsUrl, String nvsRegex);
List<DictCodeVo> channelOrg(List<Channel> channels);
}
\ No newline at end of file
......@@ -4,4 +4,6 @@ import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.DictCate;
public interface DictCateService extends BaseService<DictCate> {
DictCate getVideoOrgCate();
}
\ No newline at end of file
......@@ -2,6 +2,15 @@ package com.viontech.fanxing.ops.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import org.apache.commons.lang3.tuple.ImmutablePair;
import java.util.List;
import java.util.Map;
public interface DictCodeService extends BaseService<DictCode> {
DictCode getNVS3000Code();
ImmutablePair<Map<Long,DictCodeVo>,List<DictCodeVo>> getTreeCode(List<DictCode> dictCodes);
}
\ No newline at end of file
package com.viontech.fanxing.ops.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.mapper.ChannelMapper;
import com.viontech.fanxing.ops.service.adapter.ChannelService;
import javax.annotation.Resource;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Service
@Slf4j
public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements ChannelService {
@Resource
private ChannelMapper channelMapper;
@Resource
private DictCodeService dictcodeService;
@Resource
private DictCateService dictCateService;
@Override
public BaseMapper<Channel> getMapper() {
return channelMapper;
}
/**
* 以树状结构获取所有的组织关系和视频资源
*/
@Override
public List<DictCodeVo> channelOrg(List<Channel> channels) {
if (channels.size() == 0) {
return null;
}
DictCodeVo noAddressChannel = new DictCodeVo();
noAddressChannel.setName("其他");
noAddressChannel.setChannels(new ArrayList<>());
Map<String, List<ChannelVo>> addressUnid_channel_map = channels.stream()
.map(ChannelVo::new)
.filter(x -> {
if (StringUtils.isBlank(x.getAddressUnid())) {
noAddressChannel.getChannels().add(x);
return false;
}
return true;
})
.collect(Collectors.groupingBy(ChannelVo::getAddressUnid, Collectors.toList()));
DictCate videoOrgCate = dictCateService.getVideoOrgCate();
Long orgCateId = videoOrgCate.getId();
DictCodeExample dictCodeExample = new DictCodeExample();
dictCodeExample.createCriteria().andCateIdEqualTo(orgCateId);
List<DictCode> dictCodes = dictcodeService.selectByExample(dictCodeExample);
ImmutablePair<Map<Long, DictCodeVo>, List<DictCodeVo>> codePair = dictcodeService.getTreeCode(dictCodes);
Map<Long, DictCodeVo> codeVoMap = codePair.left;
Map<String, DictCodeVo> unid_code_map = codeVoMap.values().stream().collect(Collectors.toMap(DictCodeVo::getUnid, x -> x, (x, y) -> x));
List<DictCodeVo> right = codePair.getRight();
for (Map.Entry<String, List<ChannelVo>> entry : addressUnid_channel_map.entrySet()) {
String codeUnid = entry.getKey();
DictCodeVo dictCodeVo = unid_code_map.get(codeUnid);
if (dictCodeVo != null) {
dictCodeVo.setChannels(entry.getValue());
}
}
right.removeIf(this::needRemoveFromTree);
if (noAddressChannel.getChannels().size() > 0) {
right.add(noAddressChannel);
}
return right;
}
private boolean needRemoveFromTree(DictCodeVo dictCodeVo) {
if (dictCodeVo.getChildren() != null) {
dictCodeVo.getChildren().removeIf(this::needRemoveFromTree);
}
if (dictCodeVo.getChannels() == null) {
if (dictCodeVo.getChildren() == null || dictCodeVo.getChildren().size() == 0) {
return true;
}
}
return false;
}
/**
* 拉取 nvs3000 视频资源
*/
@Override
public JSONObject nvs3000(String nvsUrl, String nvsRegex) {
DictCode nvs3000Code = dictcodeService.getNVS3000Code();
String addressUnid = nvs3000Code.getUnid();
ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andAddressUnidEqualTo(addressUnid).andExpandEqualTo("nvs3000");
channelExample.createColumns().hasChannelUnidColumn();
List<Channel> channels = selectByExample(channelExample);
Set<String> channelUnidSet = channels.stream().map(Channel::getChannelUnid).collect(Collectors.toSet());
JSONObject nvsPostData = new JSONObject();
nvsPostData.put("fromindex", 0);
nvsPostData.put("toindex", -1);
JSONObject nvsResponse = WebClient.create()
.post()
.uri(nvsUrl + "/nvsthird/getcamlist")
.bodyValue(nvsPostData)
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(10));
if (nvsResponse == null || !nvsResponse.containsKey("group")) {
return null;
}
JSONArray group = nvsResponse.getJSONArray("group");
int repeat = 0;
int filtered = 0;
int success = 0;
for (int i = 0; i < group.size(); i++) {
JSONObject item = group.getJSONObject(i);
String description = item.getString("description");
if (StringUtils.isBlank(description)) {
filtered++;
continue;
}
String name = item.getString("name");
String id = item.getString("id");
if (channelUnidSet.contains(id)) {
repeat++;
continue;
}
Channel channel = new Channel();
channel.setChannelUnid(id);
channel.setName(name);
channel.setAddressUnid(addressUnid);
channel.setType(1);
channel.setExpand("nvs3000");
channel.setStreamType(0);
channel.setStreamPath(nvsRegex + id);
insertSelective(channel);
success++;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("filtered", filtered);
jsonObject.put("repeat", repeat);
jsonObject.put("insert", success);
log.info("拉取nvs3000 : {}", jsonObject);
return jsonObject;
}
}
\ No newline at end of file
package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.ops.mapper.DictCateMapper;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.DictCate;
import com.viontech.fanxing.commons.model.DictCateExample;
import com.viontech.fanxing.ops.mapper.DictCateMapper;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements DictCateService {
......@@ -18,4 +20,21 @@ public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements Di
public BaseMapper<DictCate> getMapper() {
return dictCateMapper;
}
@Override
public DictCate getVideoOrgCate() {
DictCateExample dictCateExample = new DictCateExample();
dictCateExample.createCriteria().andCodeEqualTo("video_org");
List<DictCate> dictCates = selectByExample(dictCateExample);
if (dictCates.size() == 0) {
DictCate dictCate = new DictCate();
dictCate.setName("视频资源组织结构");
dictCate.setCode("video_org");
dictCate.setType("org");
dictCate.setNote("视频资源组织结构");
insertSelective(dictCate);
return getVideoOrgCate();
}
return dictCates.get(0);
}
}
\ No newline at end of file
......@@ -2,20 +2,81 @@ package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.DictCate;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.DictCodeExample;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.mapper.DictCodeMapper;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class DictCodeServiceImpl extends BaseServiceImpl<DictCode> implements DictCodeService {
@Resource
private DictCodeMapper dictCodeMapper;
@Resource
private DictCateService dictCateService;
@Override
public BaseMapper<DictCode> getMapper() {
return dictCodeMapper;
}
@Override
public ImmutablePair<Map<Long,DictCodeVo>,List<DictCodeVo>> getTreeCode(List<DictCode> dictCodes) {
Map<Long, DictCodeVo> map = dictCodes.stream().map(DictCodeVo::new).collect(Collectors.toMap(DictCode::getId, x -> x, (x, y) -> x));
List<DictCodeVo> result = new ArrayList<>();
for (Map.Entry<Long, DictCodeVo> entry : map.entrySet()) {
DictCodeVo value = entry.getValue();
if (value.getParentId() == null) {
result.add(value);
} else {
DictCodeVo parent = map.get(value.getParentId());
if (parent != null) {
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(value);
}
}
}
return ImmutablePair.of(map, result);
}
@Override
public DictCode getNVS3000Code() {
DictCate videoOrgCate = dictCateService.getVideoOrgCate();
Long cateId = videoOrgCate.getId();
DictCodeExample dictCodeExample = new DictCodeExample();
dictCodeExample.createCriteria().andCateIdEqualTo(cateId);
List<DictCode> dictCodes = selectByExample(dictCodeExample);
DictCode nvs3000Code = null;
for (DictCode dictCode : dictCodes) {
if ("nvs3000".equals(dictCode.getCode())) {
nvs3000Code = dictCode;
break;
}
}
if (nvs3000Code == null) {
nvs3000Code = new DictCode();
nvs3000Code.setCode("nvs3000");
nvs3000Code.setName("nvs3000");
nvs3000Code.setCateId(cateId);
nvs3000Code.setNote("nvs3000");
insertSelective(nvs3000Code);
return getNVS3000Code();
}
return nvs3000Code;
}
}
\ No newline at end of file
package com.viontech.fanxing.ops;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.ops.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/9/2
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class MainTest {
@Resource
private ChannelService channelService;
@Test
public void nvs3000CodeTest() {
ChannelVo channelVo = new ChannelVo();
channelVo.setChannelUnid("123");
ArrayList<ChannelVo> objects = new ArrayList<>();
objects.add(channelVo);
Map<String, List<ChannelVo>> addressUnid_channel_map = objects.stream().map(ChannelVo::new).collect(Collectors.groupingBy(ChannelVo::getAddressUnid, Collectors.toList()));
System.out.println(addressUnid_channel_map);
}
}
......@@ -2,9 +2,9 @@ package com.viontech.fanxing.task.runner;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample;
import com.viontech.fanxing.task.feign.OpsClient;
import com.viontech.fanxing.task.mapper.TaskMapper;
import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.service.TaskDataService;
import com.viontech.fanxing.task.service.adapter.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
......@@ -25,22 +25,23 @@ import java.util.List;
public class TaskInitRunner implements CommandLineRunner {
@Resource
private TaskService taskService;
private TaskMapper taskMapper;
@Resource
private TaskDataService taskDataService;
@Resource
private OpsClient opsClient;
@Override
public void run(String... args) throws Exception {
log.info("===================任务初始化开始===================");
List<Task> tasks = taskService.selectByExample(new TaskExample());
List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
for (Task task : tasks) {
if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null) {
try {
taskDataService.addTask(task);
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) {
taskDataService.addTask(task);
}
} catch (Exception e) {
log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage());
}
......
......@@ -45,12 +45,10 @@ public class TaskDataService {
throw new FanXingException("无法获取对应的存储配置");
}
taskData.setStoreConfig(storeConfigVo.getContent());
taskDataRedisRepository.addOrUpdateTaskData(taskData);
// 计算运行时间并生成任务
boolean success = distributeTask(taskData);
if (success) {
taskDataRedisRepository.addOrUpdateTaskData(taskData);
} else {
if (!success) {
throw new FanXingException("任务找不到可执行时间");
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!