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> { ...@@ -28,6 +28,7 @@ public class DateConverter implements Converter<String, Date> {
formarts.add("HH:mm:ss"); formarts.add("HH:mm:ss");
formarts.add("HH:mm"); formarts.add("HH:mm");
formarts.add("yyyy-MM-dd'T'HH:mm:ss"); formarts.add("yyyy-MM-dd'T'HH:mm:ss");
formarts.add("yyyy-MM-dd HH:mm:ss.S");
} }
@Override @Override
...@@ -50,6 +51,8 @@ public class DateConverter implements Converter<String, Date> { ...@@ -50,6 +51,8 @@ public class DateConverter implements Converter<String, Date> {
return parseDate(source, formarts.get(5)); 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}$")) { } 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)); 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 { } else {
throw new IllegalArgumentException("Invalid boolean value '" + source + "'"); throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
} }
......
...@@ -5,6 +5,8 @@ import com.viontech.fanxing.commons.vobase.ChannelVoBase; ...@@ -5,6 +5,8 @@ import com.viontech.fanxing.commons.vobase.ChannelVoBase;
public class ChannelVo extends ChannelVoBase { public class ChannelVo extends ChannelVoBase {
private Boolean tree;
public ChannelVo() { public ChannelVo() {
super(); super();
} }
...@@ -12,4 +14,13 @@ public class ChannelVo extends ChannelVoBase { ...@@ -12,4 +14,13 @@ public class ChannelVo extends ChannelVoBase {
public ChannelVo(Channel channel) { public ChannelVo(Channel channel) {
super(channel); super(channel);
} }
public Boolean getTree() {
return tree;
}
public ChannelVo setTree(Boolean tree) {
this.tree = tree;
return this;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,9 @@ import java.util.List; ...@@ -8,6 +8,9 @@ import java.util.List;
public class DictCodeVo extends DictCodeVoBase { public class DictCodeVo extends DictCodeVoBase {
private List<DictCodeVo> children; private List<DictCodeVo> children;
private List<ChannelVo> channels;
private Boolean tree;
public DictCodeVo() { public DictCodeVo() {
super(); super();
...@@ -24,4 +27,22 @@ public class DictCodeVo extends DictCodeVoBase { ...@@ -24,4 +27,22 @@ public class DictCodeVo extends DictCodeVoBase {
public void setChildren(List<DictCodeVo> children) { public void setChildren(List<DictCodeVo> children) {
this.children = 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 \ No newline at end of file
...@@ -72,8 +72,7 @@ public class DataReceiveController { ...@@ -72,8 +72,7 @@ public class DataReceiveController {
public Object video(VideoResult videoResult) throws Exception { public Object video(VideoResult videoResult) throws Exception {
String unid = videoResult.getRefid(); String unid = videoResult.getRefid();
log.info("接收到视频录像文件,refId:{},文件名:{}", unid, videoResult.getFile().getOriginalFilename()); log.info("接收到视频录像文件,refId:{},文件名:{}", unid, videoResult.getFile().getOriginalFilename());
// todo 之后会加上 eventTime 字段,目前先 new Date() String filePath = picUtils.getFilePath(unid, videoResult.getEventTime() == null ? new Date() : videoResult.getEventTime(), videoResult.getFormat() == null ? "mp4" : videoResult.getFormat());
String filePath = picUtils.getFilePath(unid, new Date(), videoResult.getFormat() == null ? "mp4" : videoResult.getFormat());
File file = new File(filePath); File file = new File(filePath);
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
......
...@@ -4,6 +4,8 @@ import lombok.Getter; ...@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
/** /**
* . * .
* *
...@@ -23,4 +25,6 @@ public class VideoResult { ...@@ -23,4 +25,6 @@ public class VideoResult {
private String unid; private String unid;
private Date eventTime;
} }
package com.viontech.fanxing.ops.controller.web; package com.viontech.fanxing.ops.controller.web;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.ChannelExample; import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.vo.ChannelVo; 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.fanxing.ops.controller.base.ChannelBaseController;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; 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.bind.annotation.*;
import org.springframework.web.reactive.function.client.WebClient;
import java.time.Duration;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/channels") @RequestMapping("/channels")
...@@ -30,68 +24,25 @@ public class ChannelController extends ChannelBaseController { ...@@ -30,68 +24,25 @@ public class ChannelController extends ChannelBaseController {
return channelExample; return channelExample;
} }
@PostMapping("/nvs3000") @Override
public Object nvs3000(@RequestBody JSONObject jsonObject) { @GetMapping()
String addressUnid = jsonObject.getString("addressUnid"); public Object page(ChannelVo channelVo,
String nvsUrl = jsonObject.getString("nvsUrl"); @RequestParam(value = "page", defaultValue = "-1") int page,
String nvsRegex = jsonObject.getString("nvsRegex"); @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
String sortName, String sortOrder) {
ChannelExample channelExample = new ChannelExample(); if (channelVo.getTree() != null && channelVo.getTree()) {
channelExample.createCriteria().andAddressUnidEqualTo(addressUnid).andExpandEqualTo("nvs3000"); BaseExample example = getExample(channelVo, EXAMPLE_TYPE_PAGE);
channelExample.createColumns().hasChannelUnidColumn(); List<Channel> channels = channelService.selectByExample(example);
List<Channel> channels = getService().selectByExample(channelExample); List<DictCodeVo> dictCodeVos = channelService.channelOrg(channels);
Set<String> channelUnidSet = channels.stream().map(Channel::getChannelUnid).collect(Collectors.toSet()); return JsonMessageUtil.getSuccessJsonMsg(dictCodeVos);
} else {
JSONObject nvsPostData = new JSONObject(); return super.page(channelVo, page, pageSize, sortName, sortOrder);
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++;
} }
}
jsonObject.put("filtered", filtered); @PostMapping("/nvs3000")
jsonObject.put("repeat", repeat); public Object nvs3000(@RequestBody JSONObject jsonObject) {
jsonObject.put("insert", success); JSONObject result = channelService.nvs3000(jsonObject.getString("nvsUrl"), jsonObject.getString("nvsRegex"));
log.info("拉取nvs3000 : {}", jsonObject); return JsonMessageUtil.getSuccessJsonMsg(result);
return JsonMessageUtil.getSuccessJsonMsg(jsonObject);
} }
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.ops.controller.web; 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.base.BaseExample;
import com.viontech.fanxing.commons.model.DictCode; import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.DictCodeExample; import com.viontech.fanxing.commons.model.DictCodeExample;
import com.viontech.fanxing.commons.vo.DictCodeVo; import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.controller.base.DictCodeBaseController;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; 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.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Controller @Controller
@RequestMapping("/dictCodes") @RequestMapping("/dictCodes")
...@@ -29,28 +27,15 @@ public class DictCodeController extends DictCodeBaseController { ...@@ -29,28 +27,15 @@ public class DictCodeController extends DictCodeBaseController {
return dictCodeExample; return dictCodeExample;
} }
@GetMapping("/tree") @Override
@ResponseBody @GetMapping
public Object getTreeCode(@RequestParam Long cateId) { public Object page(DictCodeVo dictCodeVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize, String sortName, String sortOrder) {
DictCodeExample dictCodeExample = new DictCodeExample(); if (dictCodeVo.getTree() != null && dictCodeVo.getTree()) {
dictCodeExample.createCriteria().andCateIdEqualTo(cateId); BaseExample example = getExample(dictCodeVo, EXAMPLE_TYPE_PAGE);
Map<Long, DictCodeVo> map = getService().selectByExample(dictCodeExample).stream().map(DictCodeVo::new).collect(Collectors.toMap(DictCode::getId, x -> x, (x, y) -> x)); List<DictCode> dictCodes = dictCodeService.selectByExample(example);
ImmutablePair<Map<Long, DictCodeVo>, List<DictCodeVo>> treeCode = dictCodeService.getTreeCode(dictCodes);
List<DictCodeVo> result = new ArrayList<>(); return JsonMessageUtil.getSuccessJsonMsg(treeCode.right);
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 JsonMessageUtil.getSuccessJsonMsg(result); return super.page(dictCodeVo, page, pageSize, sortName, sortOrder);
} }
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.ops.service.adapter; package com.viontech.fanxing.ops.service.adapter;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseService; import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.vo.DictCodeVo;
import java.util.List;
public interface ChannelService extends BaseService<Channel> { public interface ChannelService extends BaseService<Channel> {
JSONObject nvs3000(String nvsUrl, String nvsRegex);
List<DictCodeVo> channelOrg(List<Channel> channels);
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,4 +4,6 @@ import com.viontech.fanxing.commons.base.BaseService; ...@@ -4,4 +4,6 @@ import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.DictCate; import com.viontech.fanxing.commons.model.DictCate;
public interface DictCateService extends BaseService<DictCate> { public interface DictCateService extends BaseService<DictCate> {
DictCate getVideoOrgCate();
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,15 @@ package com.viontech.fanxing.ops.service.adapter; ...@@ -2,6 +2,15 @@ package com.viontech.fanxing.ops.service.adapter;
import com.viontech.fanxing.commons.base.BaseService; import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.DictCode; 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> { public interface DictCodeService extends BaseService<DictCode> {
DictCode getNVS3000Code();
ImmutablePair<Map<Long,DictCodeVo>,List<DictCodeVo>> getTreeCode(List<DictCode> dictCodes);
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.ops.service.impl; 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.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; 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.mapper.ChannelMapper;
import com.viontech.fanxing.ops.service.adapter.ChannelService; 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.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 @Service
@Slf4j
public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements ChannelService { public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements ChannelService {
@Resource @Resource
private ChannelMapper channelMapper; private ChannelMapper channelMapper;
@Resource
private DictCodeService dictcodeService;
@Resource
private DictCateService dictCateService;
@Override @Override
public BaseMapper<Channel> getMapper() { public BaseMapper<Channel> getMapper() {
return channelMapper; 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 \ No newline at end of file
package com.viontech.fanxing.ops.service.impl; 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.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.DictCate; 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 org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
@Service @Service
public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements DictCateService { public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements DictCateService {
...@@ -18,4 +20,21 @@ public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements Di ...@@ -18,4 +20,21 @@ public class DictCateServiceImpl extends BaseServiceImpl<DictCate> implements Di
public BaseMapper<DictCate> getMapper() { public BaseMapper<DictCate> getMapper() {
return dictCateMapper; 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 \ No newline at end of file
...@@ -2,20 +2,81 @@ package com.viontech.fanxing.ops.service.impl; ...@@ -2,20 +2,81 @@ package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; 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.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.mapper.DictCodeMapper;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService; import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class DictCodeServiceImpl extends BaseServiceImpl<DictCode> implements DictCodeService { public class DictCodeServiceImpl extends BaseServiceImpl<DictCode> implements DictCodeService {
@Resource @Resource
private DictCodeMapper dictCodeMapper; private DictCodeMapper dictCodeMapper;
@Resource
private DictCateService dictCateService;
@Override @Override
public BaseMapper<DictCode> getMapper() { public BaseMapper<DictCode> getMapper() {
return dictCodeMapper; 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 \ 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; ...@@ -2,9 +2,9 @@ package com.viontech.fanxing.task.runner;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample; 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.TaskDataService;
import com.viontech.fanxing.task.service.adapter.TaskService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
...@@ -25,22 +25,23 @@ import java.util.List; ...@@ -25,22 +25,23 @@ import java.util.List;
public class TaskInitRunner implements CommandLineRunner { public class TaskInitRunner implements CommandLineRunner {
@Resource @Resource
private TaskService taskService; private TaskMapper taskMapper;
@Resource @Resource
private TaskDataService taskDataService; private TaskDataService taskDataService;
@Resource
private OpsClient opsClient;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
log.info("===================任务初始化开始==================="); log.info("===================任务初始化开始===================");
List<Task> tasks = taskService.selectByExample(new TaskExample()); List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
for (Task task : tasks) { for (Task task : tasks) {
if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null) { if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null) {
try { try {
taskDataService.addTask(task); TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) {
taskDataService.addTask(task);
}
} catch (Exception e) { } catch (Exception e) {
log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage()); log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage());
} }
......
...@@ -45,12 +45,10 @@ public class TaskDataService { ...@@ -45,12 +45,10 @@ public class TaskDataService {
throw new FanXingException("无法获取对应的存储配置"); throw new FanXingException("无法获取对应的存储配置");
} }
taskData.setStoreConfig(storeConfigVo.getContent()); taskData.setStoreConfig(storeConfigVo.getContent());
taskDataRedisRepository.addOrUpdateTaskData(taskData);
// 计算运行时间并生成任务 // 计算运行时间并生成任务
boolean success = distributeTask(taskData); boolean success = distributeTask(taskData);
if (success) { if (!success) {
taskDataRedisRepository.addOrUpdateTaskData(taskData);
} else {
throw new FanXingException("任务找不到可执行时间"); throw new FanXingException("任务找不到可执行时间");
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!