离线提醒

camera_merge
王一鸣 5 years ago
parent b43dca8420
commit 017d3f1377

@ -32,6 +32,7 @@ public class CameraControlController {
}
private NetSDKLib.LLong cameraLogin(Integer cameraId){
log.info("相机登录 cameraId:{}",cameraId);
Camera camera = cameraMapper.selectById(cameraId);
Assert.notNull(camera,"球机不存在");
NetSDKLib.LLong lLong = LoginModule.login(camera.getIp(),camera.getPort(),camera.getUser(),camera.getPassword(),cameraId);
@ -300,8 +301,7 @@ public class CameraControlController {
private void checkLogin(Integer cameraId){
if(CameraConnMap.getConnId(cameraId) == null){
log.info("相机登录 cameraId:{}",cameraId);
checkLogin(cameraId);
cameraLogin(cameraId);
}
}
}

@ -48,10 +48,16 @@ public class PLCController {
@GetMapping("/disPlc")
@ApiOperation(value = "未连接的PLC")
public Result<List<Street>> disConn(){
public Result<List<StreetConn.PlcStatus>> disConn(){
return Result.success(plcService.disStreets());
}
@GetMapping("/plcStatus")
@ApiOperation(value = "是否存在连接异常的PLC 返回 true 表示有存在异常的")
public Result<Integer> plcStatus(){
return Result.success(plcService.plcStatus());
}
}

@ -0,0 +1,61 @@
package com.zhehekeji.web.controller;
import com.github.pagehelper.PageInfo;
import com.zhehekeji.common.util.ValidatorUtil;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.web.entity.Order;
import com.zhehekeji.web.entity.Warn;
import com.zhehekeji.web.pojo.OrderSaveReq;
import com.zhehekeji.web.pojo.OrderSearch;
import com.zhehekeji.web.pojo.warn.WarnSearch;
import com.zhehekeji.web.service.OrderService;
import com.zhehekeji.web.service.PlcService;
import com.zhehekeji.web.service.WarnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Api(value = "Warn",tags = "告警管理")
@RestController
@RequestMapping("/warn")
public class WarnController {
@Resource
private WarnService warnService;
@Resource
private ValidatorUtil validatorUtil;
@PostMapping("/list")
@ApiOperation(value = "查询")
//@SessionHandler
public Result<PageInfo<Warn>> orders(@RequestBody WarnSearch warnSearch) {
validatorUtil.validate(warnSearch);
return Result.success(warnService.page(warnSearch));
}
@GetMapping("/media")
//@ApiOperation(value = "视频测试")
//@SessionHandler(userType = UserType.ACCOUNT)
public void media() {
}
/*@GetMapping("/userCenter")
@ApiOperation("用户中心地址")
public Result<IndexVO> userCenter(){
return Result.success(applicationService.userCenter());
}*/
}

@ -0,0 +1,20 @@
package com.zhehekeji.web.pojo.warn;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
@Data
public class WarnSearch {
@NotNull(message = "pageNum不能为空")
private Integer pageNum;
@NotNull(message = "pageSize不能为空")
private Integer pageSize;
private LocalDateTime startTime;
private LocalDateTime endTime;
}

@ -37,7 +37,7 @@ public class InitService implements ApplicationRunner {
//plc 连接状态初始化
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));
streets.forEach(street -> {
StreetConn.init(street.getId());
StreetConn.init(street.getId(),street.getPlcId());
try {
nettyClient.createClient(street);
}catch (Exception e){

@ -90,7 +90,7 @@ public class MyProtocolDecoder extends FixedLengthFrameDecoder {
} else if(type.equals("0D")){
log.info(" warn code:{}",code);
if("D0".equals(code)){
log.info("warn start ,plcId:{}",plcId);
log.info("warn start ,plcId:{},warnInfo:b1:{},b2:{},b3:{},b4:{},b5:{},b6:{},b7:{},b8:{}",plcId,b1, b2, b3, b4, b5, b6, b7, b8);
plcService.warnStart(plcId);
//动作
//解析具体的告警 具体规则见文档
@ -114,8 +114,6 @@ public class MyProtocolDecoder extends FixedLengthFrameDecoder {
plcService.warnStop(plcId);
}
}
log.debug("1:{},b1:{},b2:{},b3:{},b4:{},b5:{},b6:{},b7:{},b8:{}",w, b1, b2, b3, b4, b5, b6, b7, b8);
in.release();
return null;

@ -51,10 +51,15 @@ public class PlcService {
@Resource
private CameraIOMapper ioMapper;
public List<Street> disStreets(){
public List<StreetConn.PlcStatus> disStreets(){
return StreetConn.disConnList();
}
public Integer plcStatus(){
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));
List<Integer> connIds = StreetConn.connList();
return streets.stream().filter(s->!connIds.contains(s.getId())).collect(Collectors.toList());
return (streets.size() - connIds.size());
}
/**
@ -92,6 +97,7 @@ public class PlcService {
}
if(times == 1 || times == 3){
//找到球机IO配置的预置点
log.info("预置点:{}",code);
move(street.getCamera1Id(),street.getCamera2Id(),code);
return;
}

@ -1,8 +1,10 @@
package com.zhehekeji.web.service;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -11,14 +13,16 @@ import java.util.Map;
@Data
public class StreetConn {
private static Map<Integer,Boolean> connMap = new HashMap<>();
private static Map<Integer,PlcStatus> connMap = new HashMap<>();
/**
* plc
* @param streetId
*/
public static void conn(Integer streetId){
connMap.put(streetId,Boolean.TRUE);
PlcStatus plcStatus = connMap.get(streetId);
plcStatus.status = true;
connMap.put(streetId,plcStatus);
}
/**
@ -27,33 +31,48 @@ public class StreetConn {
* @return
*/
public static Boolean checkStreetConn(Integer streetId){
Boolean conn = connMap.get(streetId);
if(conn != null && conn){
PlcStatus plcStatus = connMap.get(streetId);
if(plcStatus != null && plcStatus.status){
return true;
}
return false;
}
/**
* plc
* plc
* @return
*/
public static List<Integer> connList(){
List<Integer> disConnIds = new ArrayList<>();
connMap.forEach((k,v)->{
if(v){
if(v.status){
disConnIds.add(k);
}
});
return disConnIds;
}
public static List<PlcStatus> disConnList(){
List<PlcStatus> plcStatuses = new ArrayList<>();
connMap.forEach((k,v)->{
if(!v.status){
plcStatuses.add(v);
}
});
return plcStatuses;
}
/**
* plc
* @param streetId
*/
public static void init(Integer streetId){
connMap.put(streetId,Boolean.FALSE);
public static void init(Integer streetId,String plcId){
PlcStatus plcStatus = new PlcStatus();
plcStatus.status = Boolean.FALSE;
plcStatus.time = LocalDateTime.now();
plcStatus.plcId = plcId;
connMap.put(streetId,plcStatus);
}
/**
@ -61,7 +80,10 @@ public class StreetConn {
* @param streetId
*/
public static void disConn(Integer streetId){
init(streetId);
PlcStatus plcStatus = connMap.get(streetId);
plcStatus.setStatus(Boolean.FALSE);
plcStatus.setTime(LocalDateTime.now());
connMap.put(streetId,plcStatus);
}
/**
@ -72,5 +94,14 @@ public class StreetConn {
connMap.remove(streetId);
}
@Data
public static class PlcStatus{
private Boolean status;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;
private String plcId;
}
}

@ -42,7 +42,7 @@ public class StreetService {
}catch (DuplicateKeyException e){
Assert.isTrue(false,"PLC ID已存在");
}
StreetConn.init(street.getId());
StreetConn.init(street.getId(),street.getPlcId());
//连接
nettyClient.createClient(street);
return street.getId();

@ -0,0 +1,29 @@
package com.zhehekeji.web.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhehekeji.web.entity.Warn;
import com.zhehekeji.web.mapper.WarnMapper;
import com.zhehekeji.web.pojo.warn.WarnSearch;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class WarnService {
@Resource
private WarnMapper warnMapper;
public PageInfo<Warn> page(WarnSearch warnSearch){
PageHelper.startPage(warnSearch.getPageNum(),warnSearch.getPageSize());
QueryWrapper<Warn> queryWrapper = new QueryWrapper<>();
if(warnSearch.getStartTime() != null && warnSearch.getEndTime() != null){
queryWrapper.between("start_time",warnSearch.getStartTime(),warnSearch.getEndTime());
}
List<Warn> warns = warnMapper.selectList(queryWrapper);
return new PageInfo<>(warns);
}
}
Loading…
Cancel
Save