package com.ruoyi.aibrain.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.ruoyi.activeMQ.vo.RuleAreaVO;
|
import com.ruoyi.aibrain.domain.AiCameraRule;
|
import com.ruoyi.aibrain.mapper.AiCameraRuleMapper;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.system.mapper.AiRuleMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import com.ruoyi.aibrain.mapper.AiCameraMapper;
|
import com.ruoyi.aibrain.domain.AiCamera;
|
import com.ruoyi.aibrain.service.IAiCameraService;
|
|
/**
|
* 设备管理Service业务层处理
|
*
|
* @author wf
|
* @date 2023-03-08
|
*/
|
@Service
|
public class AiCameraServiceImpl implements IAiCameraService
|
{
|
@Autowired
|
private AiCameraMapper aiCameraMapper;
|
|
@Autowired
|
private AiCameraRuleMapper aiCameraRuleMapper;
|
|
@Autowired
|
private AiRuleMapper aiRuleMapper;
|
|
/**
|
* 查询设备管理
|
*
|
* @param id 设备管理主键
|
* @return 设备管理
|
*/
|
@Override
|
public AiCamera selectAiCameraById(Long id)
|
{
|
AiCamera aiCamera = aiCameraMapper.selectAiCameraById(id);
|
List<AiCameraRule> rules = aiCameraRuleMapper.selectAiCameraRuleListByCameraId(id);
|
for (AiCameraRule rule : rules){
|
String left = "[";
|
String center = "[";
|
String right = "[";
|
JSONArray array = JSONArray.parseArray(rule.getRuleArea());
|
List<RuleAreaVO> areas = new ArrayList<>();
|
if (array != null){
|
for (int i = 0; i < array.size(); i++) {
|
if(rule.getRuleId() == 1){
|
if(i >= 0 && i < 4){
|
left = left + array.getJSONObject(i) + ",";
|
}
|
if(i >= 4 && i < 8){
|
center = center + array.getJSONObject(i)+ ",";
|
}
|
if(i >= 8){
|
right = right + array.getJSONObject(i)+ ",";
|
}
|
}
|
JSONObject json = array.getJSONObject(i);
|
RuleAreaVO area = new RuleAreaVO();
|
// area.setX(Float.parseFloat(json.get("x").toString()));
|
// area.setY(Float.parseFloat(json.get("y").toString()));
|
areas.add(area);
|
}
|
}
|
// if(rule.getRuleId() == 1){
|
// rule.setLeftArea(left.substring(0, left.lastIndexOf(','))+"]");
|
// rule.setCenterArea(center.substring(0, center.lastIndexOf(','))+"]");
|
// rule.setRightArea(right.substring(0, right.lastIndexOf(','))+"]");
|
// }
|
rule.setAreas(areas);
|
}
|
aiCamera.setRules(rules);
|
return aiCamera;
|
}
|
|
/**
|
* 查询设备管理列表
|
*
|
* @param aiCamera 设备管理
|
* @return 设备管理
|
*/
|
@Override
|
public List<AiCamera> selectAiCameraList(AiCamera aiCamera)
|
{
|
List<AiCamera> aiCameras = aiCameraMapper.selectAiCameraList(aiCamera);
|
for (AiCamera camera : aiCameras) {
|
List<AiCameraRule> rules = aiCameraRuleMapper.selectAiCameraRuleListByCameraId(camera.getId());
|
for (AiCameraRule rule : rules){
|
String left = "[";
|
String center = "[";
|
String right = "[";
|
JSONArray array = JSONArray.parseArray(rule.getRuleArea());
|
List<RuleAreaVO> areas = new ArrayList<>();
|
if (array != null){
|
for (int i = 0; i < array.size(); i++) {
|
if(rule.getRuleId() == 1){
|
if(i >= 0 && i < 5){
|
left = left + array.getJSONObject(i);
|
}
|
if(i >= 5 && i < 9){
|
center = center + array.getJSONObject(i);
|
}
|
if(i >= 9){
|
right = right + array.getJSONObject(i);
|
}
|
}
|
JSONObject json = array.getJSONObject(i);
|
RuleAreaVO area = new RuleAreaVO();
|
// area.setX(Float.parseFloat(json.get("x").toString()));
|
// area.setY(Float.parseFloat(json.get("y").toString()));
|
areas.add(area);
|
}
|
}
|
rule.setLeftArea(left+"]");
|
rule.setCenterArea(center+"]");
|
rule.setRightArea(right+"]");
|
rule.setAreas(areas);
|
}
|
camera.setRules(rules);
|
}
|
return aiCameras;
|
}
|
|
/**
|
* 新增设备管理
|
*
|
* @param aiCamera 设备管理
|
* @return 结果
|
*/
|
@Override
|
public int insertAiCamera(AiCamera aiCamera)
|
{
|
aiCamera.setCreateTime(DateUtils.getNowDate());
|
aiCamera.setCreateBy(SecurityUtils.getUsername());
|
|
aiCamera.setRtspUrl("rtsp://"+aiCamera.getCameraUser()+":"+aiCamera.getCameraPassword()+
|
"@"+aiCamera.getCameraIp()+":554/h264/1/main/av_stream");
|
|
aiCameraMapper.insertAiCamera(aiCamera);
|
insertCameraRule(aiCamera);
|
aiCamera.setCameraNum("AIC0" + aiCamera.getRegion() + String.format("%03d", aiCamera.getId()));
|
return aiCameraMapper.updateAiCamera(aiCamera);
|
}
|
|
private void insertCameraRule(AiCamera aiCamera) {
|
//清除原设备算法
|
aiCameraRuleMapper.deleteAiCameraRuleByCameraId(aiCamera.getId());
|
for (AiCameraRule rule : aiCamera.getRules()){
|
rule.setCameraId(aiCamera.getId());
|
rule.setCreateBy(SecurityUtils.getUsername());
|
rule.setRuleName(aiRuleMapper.selectAiRuleById(rule.getRuleId()).getRuleName());
|
// if(rule.getRuleId() == 1){
|
// String left = rule.getLeftArea().replace("]", "");
|
// String center = rule.getCenterArea().replace("[", "");
|
// String centerArea = center.replace("]", "");
|
// String right = rule.getRightArea().replace("[", "");
|
// rule.setRuleArea(left +","+ centerArea +","+ right);
|
// }
|
aiCameraRuleMapper.insertAiCameraRule(rule);
|
}
|
}
|
|
/**
|
* 修改设备管理
|
*
|
* @param aiCamera 设备管理
|
* @return 结果
|
*/
|
@Override
|
public int updateAiCamera(AiCamera aiCamera)
|
{
|
aiCamera.setUpdateTime(DateUtils.getNowDate());
|
insertCameraRule(aiCamera);
|
aiCamera.setRtspUrl("rtsp://"+aiCamera.getCameraUser()+":"+aiCamera.getCameraPassword()+
|
"@"+aiCamera.getCameraIp()+":554/h264/1/main/av_stream");
|
return aiCameraMapper.updateAiCamera(aiCamera);
|
}
|
|
/**
|
* 批量删除设备管理
|
*
|
* @param ids 需要删除的设备管理主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteAiCameraByIds(Long[] ids)
|
{
|
return aiCameraMapper.deleteAiCameraByIds(ids);
|
}
|
|
/**
|
* 删除设备管理信息
|
*
|
* @param id 设备管理主键
|
* @return 结果
|
*/
|
@Override
|
public int deleteAiCameraById(Long id)
|
{
|
return aiCameraMapper.deleteAiCameraById(id);
|
}
|
|
/**
|
* 查询要启动的AI识别设备
|
* @return
|
*/
|
@Override
|
public List<AiCamera> queryCameraToStart() {
|
List<AiCamera> cameraList = aiCameraMapper.queryCameraToStart();
|
for (AiCamera camera : cameraList){
|
List<AiCameraRule> rules = aiCameraRuleMapper.selectAiCameraRuleListByCameraId(camera.getId());
|
for (AiCameraRule rule : rules){
|
JSONArray array = JSONArray.parseArray(rule.getRuleArea());
|
List<RuleAreaVO> areas = new ArrayList<>();
|
if (array != null){
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject json = array.getJSONObject(i);
|
RuleAreaVO area = new RuleAreaVO();
|
// area.setX(Float.parseFloat(json.get("x").toString()));
|
// area.setY(Float.parseFloat(json.get("y").toString()));
|
areas.add(area);
|
}
|
}
|
rule.setAreas(areas);
|
}
|
camera.setRules(rules);
|
}
|
return cameraList;
|
}
|
|
/**
|
* 变更设备状态
|
* @return
|
*/
|
@Override
|
public void updateAiCameraStatus(AiCamera aiCamera) {
|
aiCameraMapper.updateAiCamera(aiCamera);
|
}
|
|
/**
|
* 查询所有设备
|
* @return
|
*/
|
@Override
|
public List<AiCamera> selectAllCamera() {
|
AiCamera camera = new AiCamera();
|
List<AiCamera> aiCameras = aiCameraMapper.selectAiCameraList(camera);
|
for (AiCamera aiCamera : aiCameras) {
|
List<AiCameraRule> rules = aiCameraRuleMapper.selectAiCameraRuleListByCameraId(aiCamera.getId());
|
for (AiCameraRule rule : rules){
|
String left = "[";
|
String center = "[";
|
String right = "[";
|
JSONArray array = JSONArray.parseArray(rule.getRuleArea());
|
List<RuleAreaVO> areas = new ArrayList<>();
|
if (array != null){
|
for (int i = 0; i < array.size(); i++) {
|
if(rule.getRuleId() == 1){
|
if(i >= 0 && i < 4){
|
left = left + array.getJSONObject(i) + ",";
|
}
|
if(i >= 4 && i < 8){
|
center = center + array.getJSONObject(i)+ ",";
|
}
|
if(i >= 8){
|
right = right + array.getJSONObject(i)+ ",";
|
}
|
}
|
JSONObject json = array.getJSONObject(i);
|
RuleAreaVO area = new RuleAreaVO();
|
// area.setX(Float.parseFloat(json.get("x").toString()));
|
// area.setY(Float.parseFloat(json.get("y").toString()));
|
areas.add(area);
|
}
|
}
|
// if(rule.getRuleId() == 1){
|
// rule.setLeftArea(left.substring(0, left.lastIndexOf(','))+"]");
|
// rule.setCenterArea(center.substring(0, center.lastIndexOf(','))+"]");
|
// rule.setRightArea(right.substring(0, right.lastIndexOf(','))+"]");
|
// }
|
rule.setAreas(areas);
|
}
|
aiCamera.setRules(rules);
|
}
|
return aiCameras;
|
}
|
}
|