package com.ruoyi.web.controller.manage;
|
|
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.fuzhou.domain.DpEquipment;
|
import com.ruoyi.fuzhou.domain.ReceiveElectricityValue;
|
import com.ruoyi.fuzhou.domain.ReceiveOilValue;
|
import com.ruoyi.fuzhou.domain.ReceiveWaterValue;
|
import com.ruoyi.fuzhou.domain.vo.DpEquipmentVO;
|
import com.ruoyi.fuzhou.domain.vo.QueryAnalysisVO;
|
import com.ruoyi.fuzhou.domain.vo.ReceiveValueListVo;
|
import com.ruoyi.fuzhou.enums.DataTypeEnum;
|
import com.ruoyi.fuzhou.service.*;
|
import com.ruoyi.manage.domain.DpEquipmentType;
|
import com.ruoyi.manage.domain.DsTaskList;
|
import com.ruoyi.manage.domain.SysFileManage;
|
import com.ruoyi.manage.domain.vo.Tree;
|
import com.ruoyi.manage.service.DpEquipmentTypeService;
|
import com.ruoyi.manage.service.SysFileService;
|
import com.ruoyi.system.service.ISysDictDataService;
|
import com.ruoyi.web.controller.fuzhou.ReceiveInfoController;
|
import io.swagger.v3.oas.annotations.Hidden;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jakarta.annotation.Resource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.File;
|
import java.io.FileOutputStream;
|
import java.io.OutputStreamWriter;
|
import java.io.Writer;
|
import java.nio.charset.StandardCharsets;
|
import java.text.SimpleDateFormat;
|
import java.time.*;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author zhangyy
|
* @since 2025-03-11
|
*/
|
@RestController
|
@RequestMapping("/dp/dpEquipment")
|
@Tag(name = "大屏--设备管理")
|
public class DpEquipmentController extends BaseController {
|
@Resource
|
private EquipmentService dpEquipmentService;
|
|
@Resource
|
private ReceiveInfoController receiveInfoController;
|
|
@Resource
|
private ISysDictDataService iSysDictDataService;
|
|
@Resource
|
ReceiveModuleInfoService receiveModuleInfoService;
|
|
@Resource
|
DsTaskListController dsTaskListController;
|
|
@Resource
|
private ReceiveOilValueService receiveOilValueService;
|
|
@Resource
|
private ReceiveWaterValueService receiveWaterValueService;
|
|
@Resource
|
private ReceiveElectricityValueService receiveElectricityValueService;
|
|
@Resource
|
private HikService hikService;
|
|
@Resource
|
private DpEquipmentTypeService dpEquipmentTypeService;
|
|
@Autowired
|
SysFileService sysFileService;
|
@Autowired
|
RuoYiConfig ruoYiConfig;
|
|
|
@GetMapping("/list")
|
@Operation(summary = "设备列表")
|
public AjaxResult getList(Integer beId) {
|
List<Tree> treeList = new ArrayList<>();
|
if (null != beId) {
|
List<DpEquipmentVO> list = dpEquipmentService.getListByBeId(beId);
|
if (null != list) {
|
Map<String, List<DpEquipmentVO>> result = list.stream().collect(Collectors.groupingBy(DpEquipmentVO::getEqutype));
|
treeList = buildTree(result);
|
}
|
}
|
return AjaxResult.success(treeList);
|
}
|
|
private List<Tree> buildTree(Map<String, List<DpEquipmentVO>> result) {
|
// 构建树节点
|
List<Tree> tree = new ArrayList<>();
|
for (Map.Entry<String, List<DpEquipmentVO>> entry : result.entrySet()) {
|
Tree typeNode = new Tree();
|
typeNode.setId(generateId());
|
typeNode.setLabel(entry.getKey());
|
typeNode.setChildren(entry.getValue().stream()
|
.map(equipment -> {
|
Tree equipmentNode = new Tree();
|
equipmentNode.setLabel(equipment.getEquName());
|
equipmentNode.setId(equipment.getId());
|
equipmentNode.setIntervalTime(equipment.getIntervalTime());
|
equipmentNode.setPeriodTime(equipment.getPeriodTime());
|
equipmentNode.setIcon(equipment.getIcon());
|
return equipmentNode;
|
})
|
.collect(Collectors.toList()));
|
typeNode.setDisabled(true);
|
tree.add(typeNode);
|
}
|
|
return tree;
|
|
}
|
|
//生成不重复ID
|
private int generateId() {
|
UUID uuid = UUID.randomUUID();
|
long hash = uuid.hashCode();
|
return (int) (hash & Integer.MAX_VALUE);
|
}
|
|
@GetMapping("/pageList")
|
@Operation(summary = "泊位设备分页列表")
|
public TableDataInfo getPageList(DpEquipment dpEquipmentVO) {
|
return dpEquipmentService.getPageList(dpEquipmentVO);
|
}
|
|
@Operation(summary = "设备详情")
|
@GetMapping("/{id}")
|
public AjaxResult getById(@PathVariable Integer id) {
|
DpEquipmentVO dpEquipmentVO = dpEquipmentService.selectById(id);
|
DpEquipment dpEquipment1 = receiveModuleInfoService.getIp(String.valueOf(dpEquipmentVO.getId()), dpEquipmentVO.getEquipmentTypeId());
|
dpEquipmentVO.setIp(dpEquipment1.getIp());
|
dpEquipmentVO.setPort(dpEquipment1.getPort());
|
dpEquipmentVO.setDeviceAddress(dpEquipment1.getDeviceAddress());
|
return AjaxResult.success(dpEquipmentVO);
|
}
|
|
@GetMapping("/getListByWhId")
|
@Operation(summary = "根据码头ID获取设备树")
|
public AjaxResult getListByWhId(Integer whId) {
|
List<Tree> treeList = new ArrayList<>();
|
List<DpEquipmentVO> list = dpEquipmentService.getListByWhId(whId);
|
if (null != list) {
|
Map<String, List<DpEquipmentVO>> result = list.stream().collect(Collectors.groupingBy(DpEquipmentVO::getEqutype));
|
treeList = buildTree(result);
|
}
|
//根据系统字典排序
|
SysDictData sysDictData = new SysDictData();
|
sysDictData.setDictType("dp_equipment_type");
|
List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(sysDictData);
|
Map<String, Integer> dictSortMap = new HashMap<>();
|
for (SysDictData dictData : dictDataList) {
|
dictSortMap.put(dictData.getDictLabel(), dictData.getDictSort().intValue());
|
}
|
treeList.sort(Comparator.comparingInt(tree -> dictSortMap.getOrDefault(tree.getLabel(), Integer.MAX_VALUE)));
|
|
return AjaxResult.success(treeList);
|
}
|
|
@GetMapping("/getEquipmentsByWhId")
|
@Operation(summary = "根据码头ID获取设备详情列表")
|
public AjaxResult getEquipmentsByWhId(Integer whId) {
|
List<DpEquipmentVO> list = dpEquipmentService.getListByWhId(whId);
|
List<DpEquipmentVO> resList = new ArrayList<>();
|
resList = equipmentStatusHandling(list);
|
|
return AjaxResult.success(resList);
|
}
|
|
@GetMapping("/getEquipmentsCount")
|
@Operation(summary = "设备状态数量统计")
|
public AjaxResult getEquipmentsCount(Integer whId) {
|
List<DpEquipmentVO> list = dpEquipmentService.getListByWhId(whId);
|
List<DpEquipmentVO> resList = new ArrayList<>();
|
resList = equipmentStatusHandling(list);
|
|
LambdaQueryWrapper<DpEquipmentType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
lambdaQueryWrapper.orderByAsc(DpEquipmentType::getId);
|
List<DpEquipmentType> typeList = dpEquipmentTypeService.list(lambdaQueryWrapper);
|
|
Map<Integer, List<DpEquipmentVO>> groupMap = resList.stream().collect(Collectors.groupingBy(DpEquipmentVO::getEquipmentTypeId));
|
JSONArray jsonArray = new JSONArray();
|
List<Integer> typeIds = Arrays.asList(1, 2, 3, 4);
|
|
for (Map.Entry<Integer, List<DpEquipmentVO>> entry : groupMap.entrySet()) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("name", entry.getValue().get(0).getEqutype());
|
Long online = (long) entry.getValue().size();
|
if (typeIds.contains(entry.getKey())) {
|
online = entry.getValue().stream().filter(e -> e.getStatus() == 1).count();
|
}
|
jsonObject.put("online", online);
|
jsonObject.put("total", entry.getValue().size());
|
jsonObject.put("typeId", entry.getKey());
|
jsonArray.add(jsonObject);
|
}
|
|
Set<Integer> typeIDs = groupMap.keySet();
|
for (DpEquipmentType dpEquipmentType : typeList) {
|
if (!typeIDs.contains(dpEquipmentType.getId())) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("name", dpEquipmentType.getTypeName());
|
jsonObject.put("online", 0);
|
jsonObject.put("total", 0);
|
jsonObject.put("typeId", dpEquipmentType.getId());
|
jsonArray.add(jsonObject);
|
}
|
}
|
|
List<JSONObject> objects = jsonArray.toList(JSONObject.class);
|
objects.sort(Comparator.comparingInt(o -> o.getIntValue("typeId")));
|
|
jsonArray.clear();
|
jsonArray.addAll(objects);
|
|
return AjaxResult.success(jsonArray);
|
}
|
|
|
@GetMapping("/getEquipmentsByBeId")
|
@Operation(summary = "根据泊位ID获取设备工况信息")
|
@Hidden
|
public AjaxResult getEquipmentsByBeId(@RequestParam Integer beId, @RequestParam String startTime) {
|
List<DpEquipmentVO> list = dpEquipmentService.getListByBeId(beId);
|
return AjaxResult.success(list);
|
}
|
|
@GetMapping("/getListByBeIdTypeId")
|
@Operation(summary = "根据泊位ID和设备类型ID获取设备信息列表")
|
public AjaxResult getListByBeIdTypeId(@RequestParam Integer beId, @RequestParam Integer typeId) {
|
R<DsTaskList> res = dsTaskListController.getByBeId(beId);
|
DsTaskList dsTaskList = res.getData();
|
Date psTime = dsTaskList.getPsTime();
|
List<Integer> typeIds = new ArrayList<>();
|
if (typeId == 1) {
|
typeIds.add(1);
|
typeIds.add(12);
|
typeIds.add(13);
|
typeIds.add(14);
|
} else {
|
typeIds.add(typeId);
|
}
|
List<DpEquipmentVO> equList = dpEquipmentService.getListByBeIdTypeId(beId, typeIds);
|
List<DpEquipmentVO> voList = new ArrayList<>();
|
for (DpEquipmentVO dpEquipmentVO : equList) {
|
ReceiveValueListVo voEL = new ReceiveValueListVo();
|
voEL.setId(dpEquipmentVO.getId().longValue());
|
voEL.setEndTime(psTime);
|
List dataList = receiveInfoController.dataList(voEL).getData();
|
if (!dataList.isEmpty()) {
|
dpEquipmentVO.setDataHis(dataList.get(0));
|
}
|
voList.add(dpEquipmentVO);
|
}
|
List<DpEquipmentVO> resList = equipmentStatusHandling(voList);
|
|
JSONObject object = new JSONObject();
|
if (!equList.isEmpty()) {
|
ReceiveValueListVo vo = new ReceiveValueListVo();
|
ReceiveValueListVo voNew = new ReceiveValueListVo();
|
vo.setId(equList.get(0).getId().longValue());
|
vo.setEndTime(psTime);
|
voNew.setId(equList.get(0).getId().longValue());
|
List dataList = receiveInfoController.dataList(vo).getData();
|
List dataListNew = receiveInfoController.dataList(voNew).getData();
|
List tableList = receiveInfoController.tableList(vo.getId()).getData();
|
object.put("equList", resList);
|
if (!dataListNew.isEmpty()) {
|
object.put("dataOne", dataListNew.get(0));
|
} else {
|
object.put("dataOne", "");
|
}
|
if (!dataList.isEmpty()) {
|
object.put("dataHis", dataList.get(0));
|
} else {
|
object.put("dataHis", "");
|
}
|
object.put("tableList", tableList);
|
}
|
return AjaxResult.success(object);
|
}
|
|
@GetMapping("/getDataOneById")
|
@Operation(summary = "根据ID获取最新一条数据")
|
public AjaxResult getDataOneById(Integer id) {
|
DpEquipmentVO dpEquipmentVO = dpEquipmentService.selectById(id);
|
R<DsTaskList> res = dsTaskListController.getByBeId(dpEquipmentVO.getBeId());
|
DsTaskList dsTaskList = res.getData();
|
Date psTime = dsTaskList.getPsTime();
|
Date peTime = dsTaskList.getPeTime();
|
Integer equTypeId = dpEquipmentVO.getEquipmentTypeId();
|
|
ReceiveValueListVo vo = new ReceiveValueListVo();
|
vo.setId(id.longValue());
|
vo.setStartTime(psTime);
|
vo.setEndTime(peTime);
|
JSONObject object = new JSONObject();
|
List dataList = receiveInfoController.dataList(vo).getData();
|
List tableList = receiveInfoController.tableList(vo.getId()).getData();
|
if (dataList.size() > 0) {
|
object.put("dataOne", dataList.get(0));
|
object.put("equUpTime", getEquUptime(dataList, equTypeId));
|
} else {
|
object.put("dataOne", new JSONObject());
|
object.put("equUpTime", null);
|
}
|
object.put("tableList", tableList);
|
return AjaxResult.success(object);
|
}
|
|
private List<DpEquipmentVO> equipmentStatusHandling(List<DpEquipmentVO> list) {
|
|
List<DpEquipmentVO> resList = new ArrayList<>();
|
Map<String, Integer> onlineMap = new LinkedHashMap<>();
|
ArrayList<String> arrayList = new ArrayList<>();
|
|
for (DpEquipmentVO equipmentVO : list) {
|
Integer typeId = equipmentVO.getEquipmentTypeId();
|
if (typeId == 4 && equipmentVO.getFieldName() != null && !equipmentVO.getFieldName().isEmpty()) {
|
arrayList.add(equipmentVO.getFieldName());
|
}
|
}
|
String[] indexCodes = arrayList.toArray(new String[arrayList.size()]);
|
onlineMap = hikService.getCameraOnline(indexCodes);
|
for (DpEquipmentVO dpEquipmentVO : list) {
|
Integer typeId = dpEquipmentVO.getEquipmentTypeId();
|
Integer id = dpEquipmentVO.getId();
|
if (DataTypeEnum.LIJIUOIL.getCode().equals(typeId) || DataTypeEnum.OIL.getCode().equals(typeId) ||
|
DataTypeEnum.LIJIUJUN.getCode().equals(typeId)) {
|
ReceiveOilValue receiveOilValue = receiveOilValueService.getOne(new LambdaQueryWrapper<ReceiveOilValue>() {{
|
or().eq(ReceiveOilValue::getDeviceName, String.valueOf(id))
|
.orderByDesc(ReceiveOilValue::getCreateTime).last("LIMIT 1");
|
}});
|
if (receiveOilValue != null && receiveOilValue.getOilTimeFlow() != null) {
|
if (Double.parseDouble(receiveOilValue.getOilTimeFlow()) != 0.0) {
|
dpEquipmentVO.setStatus(1);
|
}
|
}
|
|
} else if (DataTypeEnum.WATER_FLOW.getCode().equals(typeId) || DataTypeEnum.WATER_YA.getCode().equals(typeId)
|
|| DataTypeEnum.WATER_DEPT.getCode().equals(typeId)) {
|
ReceiveWaterValue receiveWaterValue = receiveWaterValueService.getOne(new LambdaQueryWrapper<ReceiveWaterValue>() {{
|
or().eq(ReceiveWaterValue::getDeviceName, String.valueOf(id))
|
.orderByDesc(ReceiveWaterValue::getCreateTime).last("LIMIT 1");
|
}});
|
if (receiveWaterValue != null && receiveWaterValue.getTimeFlow() != null) {
|
if (Double.parseDouble(receiveWaterValue.getTimeFlow()) != 0.0) {
|
dpEquipmentVO.setStatus(1);
|
}
|
}
|
|
} else if (DataTypeEnum.ELECTRICITY.getCode().equals(typeId)) {
|
ReceiveElectricityValue receiveElectricityValue = receiveElectricityValueService.getOne(new LambdaQueryWrapper<ReceiveElectricityValue>() {{
|
or().eq(ReceiveElectricityValue::getDeviceName, String.valueOf(id))
|
.orderByDesc(ReceiveElectricityValue::getCreateTime).last("LIMIT 1");
|
}});
|
if (receiveElectricityValue != null && receiveElectricityValue.getCurrentA() != null
|
&& receiveElectricityValue.getCurrentB() != null && receiveElectricityValue.getCurrentC() != null) {
|
if (Double.parseDouble(receiveElectricityValue.getCurrentA()) != 0.0 || Double.parseDouble(receiveElectricityValue.getCurrentB()) != 0.0
|
|| Double.parseDouble(receiveElectricityValue.getCurrentC()) != 0.0) {
|
dpEquipmentVO.setStatus(1);
|
}
|
}
|
|
} else if (typeId == 4) {
|
Integer status = onlineMap.getOrDefault(dpEquipmentVO.getFieldName(), 0);
|
dpEquipmentVO.setStatus(status);
|
}
|
resList.add(dpEquipmentVO);
|
}
|
return resList;
|
}
|
|
private String getEquUptime(List dataList, Integer equTypeId) {
|
Integer size = dataList.size();
|
if (equTypeId == 1 || equTypeId == 12 || equTypeId == 13 || equTypeId == 14) {
|
for (int i = size - 1; i >= 0; i--) {
|
ReceiveOilValue receiveOilValue = (ReceiveOilValue) dataList.get(i);
|
if (receiveOilValue.getOilTimeFlow() != null
|
&& Double.parseDouble(receiveOilValue.getOilTimeFlow()) != 0.0) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String timeStr = sdf.format(receiveOilValue.getCreateTime());
|
return timeCalculator(timeStr);
|
}
|
}
|
} else if (equTypeId == 2) {
|
for (int k = size - 1; k >= 0; k--) {
|
ReceiveWaterValue receiveWaterValue = (ReceiveWaterValue) dataList.get(k);
|
if (receiveWaterValue.getTimeFlow() != null
|
&& Double.parseDouble(receiveWaterValue.getTimeFlow()) != 0.0) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String timeStr = sdf.format(receiveWaterValue.getCreateTime());
|
return timeCalculator(timeStr);
|
}
|
}
|
}
|
return null;
|
}
|
|
private String timeCalculator(String timeStr) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
LocalDateTime dateTime = LocalDateTime.parse(timeStr, formatter);
|
LocalDateTime now = LocalDateTime.now();
|
Duration duration = Duration.between(dateTime, now);
|
long total = Math.abs(duration.toMinutes());
|
long hour = total / 60;
|
long minutes = total % 60;
|
return hour + "小时" + minutes + "分钟";
|
}
|
|
@GetMapping("/getXyzById")
|
@Operation(summary = "根据ID获取设备详情")
|
public AjaxResult getXyzById(Integer id) {
|
DpEquipment dpEquipment = dpEquipmentService.getById(id);
|
DpEquipment dpEquipment1 = receiveModuleInfoService.getIp(String.valueOf(dpEquipment.getId()), dpEquipment.getEquipmentTypeId());
|
dpEquipment.setIp(dpEquipment1.getIp());
|
dpEquipment.setPort(dpEquipment1.getPort());
|
dpEquipment.setDeviceAddress(dpEquipment1.getDeviceAddress());
|
return AjaxResult.success(dpEquipment);
|
}
|
|
//获取设备数据与表头
|
@PostMapping("/getDataById")
|
@Operation(summary = "获取设备数据与表头")
|
public AjaxResult getDataById(@Validated @RequestBody ReceiveValueListVo vo) {
|
List dataList = receiveInfoController.dataList(vo).getData();
|
List tableList = receiveInfoController.tableList(vo.getId()).getData();
|
JSONObject object = new JSONObject();
|
object.put("dataList", dataList);
|
object.put("tableList", tableList);
|
return AjaxResult.success(object);
|
}
|
|
//获取设备数据与表头(分页)
|
@PostMapping("/getPageListById")
|
@Operation(summary = "获取设备数据与表头(分页)")
|
public AjaxResult getPageListById(@Validated @RequestBody ReceiveValueListVo vo) {
|
List dataList = receiveInfoController.dataList(vo).getData();
|
List tableList = receiveInfoController.tableList(vo.getId()).getData();
|
|
List sampledList = new ArrayList();
|
for (int i = 0; i < dataList.size(); i++) {
|
if (i % 5 == 0) {
|
sampledList.add(dataList.get(i));
|
}
|
}
|
TableDataInfo dataInfo = paginate(sampledList, vo.getPageNum(), vo.getPageSize());
|
|
// TableDataInfo dataInfo = paginate(dataList, vo.getPageNum(), vo.getPageSize());
|
JSONObject object = new JSONObject();
|
object.put("dataList", dataInfo);
|
object.put("tableList", tableList);
|
return AjaxResult.success(object);
|
}
|
|
//获取设备数据与表头(分页)
|
@PostMapping("/getPageListByIdRuoyi")
|
@Operation(summary = "获取设备数据与表头(分页)")
|
public AjaxResult getPageListByIdRuoyi(@Validated @RequestBody ReceiveValueListVo vo) {
|
List dataList = receiveInfoController.dataList(vo).getData();
|
List tableList = receiveInfoController.tableList(vo.getId()).getData();
|
|
TableDataInfo dataInfo = paginate(dataList, vo.getPageNum(), vo.getPageSize());
|
JSONObject object = new JSONObject();
|
object.put("dataList", dataInfo);
|
object.put("tableList", tableList);
|
return AjaxResult.success(object);
|
}
|
|
|
/**
|
* 新增泊位--设备
|
*/
|
@Operation(summary = "新增")
|
@PostMapping
|
@Transactional(rollbackFor = Exception.class)
|
public AjaxResult add(@RequestBody DpEquipment dpEquipment) {
|
dpEquipment.setEquSeType(dpEquipment.getEquipmentTypeId());
|
dpEquipmentService.save(dpEquipment);
|
receiveModuleInfoService.saveByModule(String.valueOf(dpEquipment.getId()), dpEquipment.getIp(), dpEquipment.getPort(), dpEquipment.getDeviceAddress(), dpEquipment.getEquipmentTypeId());
|
return toAjax(true);
|
}
|
|
/**
|
* 修改泊位--设备
|
*/
|
@Operation(summary = "修改")
|
@PutMapping
|
@Transactional(rollbackFor = Exception.class)
|
public AjaxResult edit(@RequestBody DpEquipment dpEquipment) {
|
DpEquipment equipment = dpEquipmentService.getById(dpEquipment.getId());
|
if (equipment == null) {
|
throw new ServiceException("设备不存在!");
|
}
|
receiveModuleInfoService.removeByModule(String.valueOf(equipment.getId()), equipment.getEquipmentTypeId());
|
dpEquipment.setEquSeType(dpEquipment.getEquipmentTypeId());
|
dpEquipmentService.updateById(dpEquipment);
|
receiveModuleInfoService.saveByModule(String.valueOf(dpEquipment.getId()), dpEquipment.getIp(), dpEquipment.getPort(), dpEquipment.getDeviceAddress(), dpEquipment.getEquipmentTypeId());
|
return toAjax(true);
|
}
|
|
/**
|
* 删除泊位--设备
|
*/
|
@Operation(summary = "删除")
|
@Transactional(rollbackFor = Exception.class)
|
@DeleteMapping("/{id}")
|
public AjaxResult remove(@PathVariable Integer id) {
|
DpEquipment equipment = dpEquipmentService.getById(id);
|
if (equipment == null) {
|
throw new ServiceException("设备不存在!");
|
}
|
receiveModuleInfoService.removeByModule(String.valueOf(equipment), equipment.getEquipmentTypeId());
|
return toAjax(dpEquipmentService.removeById(id));
|
}
|
|
//多条件查询设备列表
|
public List<DpEquipmentVO> queryDpEquipmentList(Integer beId, Integer typeId) {
|
List<Integer> typeIds = new ArrayList<>();
|
if (typeId == 1) {
|
typeIds.add(1);
|
typeIds.add(12);
|
typeIds.add(13);
|
typeIds.add(14);
|
} else {
|
typeIds.add(typeId);
|
}
|
List<DpEquipmentVO> equList = dpEquipmentService.getListByBeIdTypeId(beId, typeIds);
|
return equList;
|
}
|
|
//多条件查询水深态势分析数据
|
@PostMapping("/queryWaterDeepAnalysis")
|
@Operation(summary = "多条件查询水深态势分析数据")
|
public AjaxResult queryWaterDeepAnalysis(@Validated @RequestBody QueryAnalysisVO queryAnalysisVO) {
|
List<String> ids = new ArrayList<>();
|
Integer beId = queryAnalysisVO.getBeId();
|
List<DpEquipmentVO> equList = queryDpEquipmentList(beId, 7);
|
|
JSONArray jsonArray = new JSONArray();
|
if (equList.size() > 0) {
|
for (DpEquipmentVO dpEquipmentVO : equList) {
|
ids.add(String.valueOf(dpEquipmentVO.getId()));
|
}
|
|
LambdaQueryWrapper<ReceiveWaterValue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
Date startTime = queryAnalysisVO.getStartTime();
|
Date endTime = queryAnalysisVO.getEndTime();
|
Integer interval = queryAnalysisVO.getInterval();
|
|
Map<String, Date> timeMap = new LinkedHashMap<>();
|
LocalDate endDate = LocalDate.now();
|
LocalDate startDate = LocalDate.now().minusDays(interval);
|
|
if (startTime != null && endTime != null) {
|
timeMap = convertStartEndTime(startTime, endTime);
|
startDate = convertDate(timeMap.get("start")).toLocalDate();
|
endDate = convertDate(timeMap.get("end")).toLocalDate();
|
} else {
|
timeMap = getStartEndTime(interval);
|
}
|
|
lambdaQueryWrapper.in(ReceiveWaterValue::getDeviceName, ids)
|
.ge(ReceiveWaterValue::getCreateTime, timeMap.get("start"))
|
.lt(ReceiveWaterValue::getCreateTime, timeMap.get("end"))
|
.orderByDesc(ReceiveWaterValue::getCreateTime);
|
List<ReceiveWaterValue> waterValues = receiveWaterValueService.list(lambdaQueryWrapper);
|
|
List<LocalDate> dateRange = startDate.datesUntil(endDate.plusDays(1)).collect(Collectors.toList());
|
|
Map<LocalDate, List<ReceiveWaterValue>> groups = new LinkedHashMap<>();
|
for (LocalDate localDate : dateRange) {
|
groups.put(localDate, new ArrayList<>());
|
}
|
for (ReceiveWaterValue receiveWaterValue : waterValues) {
|
LocalDateTime localDateTime = convertDate(receiveWaterValue.getCreateTime());
|
LocalDate localDate = localDateTime.toLocalDate();
|
groups.computeIfPresent(localDate, (key, list) -> {
|
list.add(receiveWaterValue);
|
return list;
|
});
|
}
|
|
for (Map.Entry<LocalDate, List<ReceiveWaterValue>> entry : groups.entrySet()) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("date", entry.getKey());
|
jsonObject.put("avg", "0.0");
|
jsonObject.put("dif", "0.0");
|
if (entry.getValue().size() > 0) {
|
Map<String, Double> map = waterDeepMaxMin(entry.getValue());
|
Double max = map.get("max");
|
Double min = map.get("min");
|
jsonObject.put("avg", String.format("%.3f", (max + min) / 2));
|
jsonObject.put("dif", String.format("%.3f", (max - min)));
|
}
|
jsonArray.add(jsonObject);
|
}
|
}
|
return AjaxResult.success(jsonArray);
|
}
|
|
private LocalDateTime convertDate(Date date) {
|
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
}
|
|
private Map<String, Date> convertStartEndTime(Date startTime, Date endTime) {
|
SimpleDateFormat timeSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat dateSDF = new SimpleDateFormat("yyyy-MM-dd");
|
|
String dateStartStr = dateSDF.format(startTime);
|
String dateEndStr = dateSDF.format(endTime);
|
|
String startTimeStr = " 00:00:00";
|
String endTimeStr = " 23:59:59";
|
|
String newStartStr = dateStartStr + startTimeStr;
|
String newEndStr = dateEndStr + endTimeStr;
|
|
Map<String, Date> map = new LinkedHashMap<>();
|
try {
|
Date start = timeSDF.parse(newStartStr);
|
Date end = timeSDF.parse(newEndStr);
|
map.put("start", start);
|
map.put("end", end);
|
} catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
|
return map;
|
}
|
|
private Map<String, Date> getStartEndTime(Integer interval) {
|
LocalDate endDate = LocalDate.now();
|
LocalDate startDate = LocalDate.now().minusDays(interval);
|
String startTime = " 00:00:00";
|
String endTime = " 23:59:59";
|
DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
DateTimeFormatter formatterTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
String startStr = startDate.format(formatterDate) + startTime;
|
String endStr = endDate.format(formatterDate) + endTime;
|
LocalDateTime localDateTimeStart = LocalDateTime.parse(startStr, formatterTime);
|
LocalDateTime localDateTimeEnd = LocalDateTime.parse(endStr, formatterTime);
|
Instant instantStart = localDateTimeStart.atZone(ZoneId.systemDefault()).toInstant();
|
Instant instantEnd = localDateTimeEnd.atZone(ZoneId.systemDefault()).toInstant();
|
Date start = Date.from(instantStart);
|
Date end = Date.from(instantEnd);
|
|
Map<String, Date> map = new HashMap<>();
|
map.put("start", start);
|
map.put("end", end);
|
return map;
|
}
|
|
private Map<String, Double> waterDeepMaxMin(List<ReceiveWaterValue> list) {
|
OptionalDouble max = list.stream()
|
.mapToDouble(e -> Double.parseDouble(e.getWaterDeep()))
|
.max();
|
OptionalDouble min = list.stream()
|
.mapToDouble(e -> Double.parseDouble(e.getWaterDeep()))
|
.min();
|
Map<String, Double> map = new HashMap<>();
|
map.put("max", max.orElse(0.0));
|
map.put("min", min.orElse(0.0));
|
return map;
|
}
|
|
private Double convertString(String str) {
|
if (str == null || str.trim().isEmpty()) {
|
return 0.0;
|
}
|
if (str.matches(".*[eE].*")) {
|
return 0.0;
|
}
|
try {
|
double value = Double.parseDouble(str);
|
return Math.abs(value);
|
} catch (Exception e) {
|
return 0.0;
|
}
|
}
|
|
//多条件查询电表态势分析数据
|
@PostMapping("/queryElectricityAnalysis")
|
@Operation(summary = "多条件查询电表态势分析数据")
|
public AjaxResult queryElectricityAnalysis(@Validated @RequestBody QueryAnalysisVO queryAnalysisVO) {
|
List<String> ids = new ArrayList<>();
|
Integer beId = queryAnalysisVO.getBeId();
|
List<DpEquipmentVO> equList = queryDpEquipmentList(beId, 3);
|
|
JSONArray jsonArray = new JSONArray();
|
if (equList.size() > 0) {
|
for (DpEquipmentVO dpEquipmentVO : equList) {
|
ids.add(String.valueOf(dpEquipmentVO.getId()));
|
}
|
|
LambdaQueryWrapper<ReceiveElectricityValue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
Date startTime = queryAnalysisVO.getStartTime();
|
Date endTime = queryAnalysisVO.getEndTime();
|
Integer interval = queryAnalysisVO.getInterval();
|
|
Map<String, Date> timeMap = new LinkedHashMap<>();
|
LocalDate endDate = LocalDate.now();
|
LocalDate startDate = LocalDate.now().minusDays(interval);
|
|
if (startTime != null && endTime != null) {
|
timeMap = convertStartEndTime(startTime, endTime);
|
startDate = convertDate(timeMap.get("start")).toLocalDate();
|
endDate = convertDate(timeMap.get("end")).toLocalDate();
|
} else {
|
timeMap = getStartEndTime(interval);
|
}
|
|
lambdaQueryWrapper.in(ReceiveElectricityValue::getDeviceName, ids)
|
.ge(ReceiveElectricityValue::getCreateTime, timeMap.get("start"))
|
.lt(ReceiveElectricityValue::getCreateTime, timeMap.get("end"))
|
.orderByDesc(ReceiveElectricityValue::getCreateTime);
|
List<ReceiveElectricityValue> electricityValues = receiveElectricityValueService.list(lambdaQueryWrapper);
|
|
List<LocalDate> dateRange = startDate.datesUntil(endDate.plusDays(1)).collect(Collectors.toList());
|
|
Map<LocalDate, List<ReceiveElectricityValue>> groups = new LinkedHashMap<>();
|
for (LocalDate localDate : dateRange) {
|
groups.put(localDate, new ArrayList<>());
|
}
|
for (ReceiveElectricityValue receiveElectricityValue : electricityValues) {
|
LocalDateTime localDateTime = convertDate(receiveElectricityValue.getCreateTime());
|
LocalDate localDate = localDateTime.toLocalDate();
|
groups.computeIfPresent(localDate, (key, list) -> {
|
list.add(receiveElectricityValue);
|
return list;
|
});
|
}
|
|
for (Map.Entry<LocalDate, List<ReceiveElectricityValue>> entry : groups.entrySet()) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("date", entry.getKey());
|
jsonObject.put("avg", "0.0");
|
if (entry.getValue().size() > 0) {
|
List<ReceiveElectricityValue> valueList = entry.getValue();
|
Integer size = valueList.size();
|
Double total = 0.0;
|
for (ReceiveElectricityValue receiveElectricityValue : valueList) {
|
Double zhengValue = convertString(receiveElectricityValue.getZhengPower());
|
total = total + zhengValue;
|
}
|
jsonObject.put("avg", String.format("%.3f", total / size));
|
}
|
jsonArray.add(jsonObject);
|
}
|
}
|
return AjaxResult.success(jsonArray);
|
}
|
|
|
//多条件查询油表态势分析数据
|
@PostMapping("/queryOilAnalysis")
|
@Operation(summary = "多条件查询油表态势分析数据")
|
public AjaxResult queryOilAnalysis(@Validated @RequestBody QueryAnalysisVO queryAnalysisVO) {
|
List<String> ids = new ArrayList<>();
|
Integer beId = queryAnalysisVO.getBeId();
|
List<DpEquipmentVO> equList = queryDpEquipmentList(beId, 1);
|
|
JSONArray jsonArray = new JSONArray();
|
if (equList.size() > 0) {
|
for (DpEquipmentVO dpEquipmentVO : equList) {
|
ids.add(String.valueOf(dpEquipmentVO.getId()));
|
}
|
|
LambdaQueryWrapper<ReceiveOilValue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
Date startTime = queryAnalysisVO.getStartTime();
|
Date endTime = queryAnalysisVO.getEndTime();
|
Integer interval = queryAnalysisVO.getInterval();
|
|
Map<String, Date> timeMap = new LinkedHashMap<>();
|
LocalDate endDate = LocalDate.now();
|
LocalDate startDate = LocalDate.now().minusDays(interval);
|
|
if (startTime != null && endTime != null) {
|
timeMap = convertStartEndTime(startTime, endTime);
|
startDate = convertDate(timeMap.get("start")).toLocalDate();
|
endDate = convertDate(timeMap.get("end")).toLocalDate();
|
} else {
|
timeMap = getStartEndTime(interval);
|
}
|
|
lambdaQueryWrapper.in(ReceiveOilValue::getDeviceName, ids)
|
.ge(ReceiveOilValue::getCreateTime, timeMap.get("start"))
|
.lt(ReceiveOilValue::getCreateTime, timeMap.get("end"))
|
.orderByDesc(ReceiveOilValue::getCreateTime);
|
List<ReceiveOilValue> oilValues = receiveOilValueService.list(lambdaQueryWrapper);
|
|
List<LocalDate> dateRange = startDate.datesUntil(endDate.plusDays(1)).collect(Collectors.toList());
|
|
Map<LocalDate, List<ReceiveOilValue>> groups = new LinkedHashMap<>();
|
for (LocalDate localDate : dateRange) {
|
groups.put(localDate, new ArrayList<>());
|
}
|
for (ReceiveOilValue receiveOilValue : oilValues) {
|
LocalDateTime localDateTime = convertDate(receiveOilValue.getCreateTime());
|
LocalDate localDate = localDateTime.toLocalDate();
|
groups.computeIfPresent(localDate, (key, list) -> {
|
list.add(receiveOilValue);
|
return list;
|
});
|
}
|
|
for (Map.Entry<LocalDate, List<ReceiveOilValue>> entry : groups.entrySet()) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("date", entry.getKey());
|
jsonObject.put("avg", "0.0");
|
if (entry.getValue().size() > 0) {
|
List<ReceiveOilValue> valueList = entry.getValue();
|
Integer size = valueList.size();
|
Double total = 0.0;
|
for (ReceiveOilValue receiveOilValue : valueList) {
|
Double flowTotalValue = convertString(receiveOilValue.getFlowTotal());
|
total = total + flowTotalValue;
|
}
|
jsonObject.put("avg", String.format("%.3f", total / size));
|
}
|
jsonArray.add(jsonObject);
|
}
|
}
|
|
return AjaxResult.success(jsonArray);
|
}
|
|
//多条件查询水表态势分析数据
|
@PostMapping("/queryWaterAnalysis")
|
@Operation(summary = "多条件查询水表态势分析数据")
|
public AjaxResult queryWaterAnalysis(@Validated @RequestBody QueryAnalysisVO queryAnalysisVO) {
|
List<String> ids = new ArrayList<>();
|
Integer beId = queryAnalysisVO.getBeId();
|
List<DpEquipmentVO> equList = queryDpEquipmentList(beId, 2);
|
|
JSONArray jsonArray = new JSONArray();
|
if (equList.size() > 0) {
|
for (DpEquipmentVO dpEquipmentVO : equList) {
|
ids.add(String.valueOf(dpEquipmentVO.getId()));
|
}
|
|
LambdaQueryWrapper<ReceiveWaterValue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
Date startTime = queryAnalysisVO.getStartTime();
|
Date endTime = queryAnalysisVO.getEndTime();
|
Integer interval = queryAnalysisVO.getInterval();
|
|
Map<String, Date> timeMap = new LinkedHashMap<>();
|
LocalDate endDate = LocalDate.now();
|
LocalDate startDate = LocalDate.now().minusDays(interval);
|
|
if (startTime != null && endTime != null) {
|
timeMap = convertStartEndTime(startTime, endTime);
|
startDate = convertDate(timeMap.get("start")).toLocalDate();
|
endDate = convertDate(timeMap.get("end")).toLocalDate();
|
} else {
|
timeMap = getStartEndTime(interval);
|
}
|
|
lambdaQueryWrapper.in(ReceiveWaterValue::getDeviceName, ids)
|
.ge(ReceiveWaterValue::getCreateTime, timeMap.get("start"))
|
.lt(ReceiveWaterValue::getCreateTime, timeMap.get("end"))
|
.orderByDesc(ReceiveWaterValue::getCreateTime);
|
List<ReceiveWaterValue> waterValues = receiveWaterValueService.list(lambdaQueryWrapper);
|
|
List<LocalDate> dateRange = startDate.datesUntil(endDate.plusDays(1)).collect(Collectors.toList());
|
|
Map<LocalDate, List<ReceiveWaterValue>> groups = new LinkedHashMap<>();
|
for (LocalDate localDate : dateRange) {
|
groups.put(localDate, new ArrayList<>());
|
}
|
for (ReceiveWaterValue receiveWaterValue : waterValues) {
|
LocalDateTime localDateTime = convertDate(receiveWaterValue.getCreateTime());
|
LocalDate localDate = localDateTime.toLocalDate();
|
groups.computeIfPresent(localDate, (key, list) -> {
|
list.add(receiveWaterValue);
|
return list;
|
});
|
}
|
|
for (Map.Entry<LocalDate, List<ReceiveWaterValue>> entry : groups.entrySet()) {
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("date", entry.getKey());
|
jsonObject.put("avg", "0.0");
|
if (entry.getValue().size() > 0) {
|
List<ReceiveWaterValue> valueList = entry.getValue();
|
Integer size = valueList.size();
|
Double total = 0.0;
|
for (ReceiveWaterValue receiveWaterValue : valueList) {
|
Double zhengTotalValue = convertString(receiveWaterValue.getZhengTotal());
|
total = total + zhengTotalValue;
|
}
|
jsonObject.put("avg", String.format("%.3f", total / size));
|
}
|
jsonArray.add(jsonObject);
|
}
|
}
|
|
return AjaxResult.success(jsonArray);
|
}
|
|
/**
|
* 下发json文件
|
*/
|
@PostMapping("/uploadFile")
|
@Operation(summary = "下发json文件")
|
public AjaxResult uploadFile(@RequestBody JSONArray json,
|
@RequestParam(value = "name") String name) {
|
SysFileManage sysFileManage = new SysFileManage();
|
sysFileManage.setName(name + "_" + System.currentTimeMillis());
|
sysFileManage.setType("json");
|
sysFileManage.setExt("json");
|
String filePath = ruoYiConfig.getJson() + "/" + sysFileManage.getName() + ".json";
|
String path = "/profile/" + sysFileManage.getName() + ".json";
|
sysFileManage.setFilePath(path);
|
try {
|
File file = new File(filePath);
|
file.createNewFile();
|
String jsonStr = JSON.toJSONString(json);
|
|
Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
writer.write(jsonStr);
|
writer.flush();
|
writer.close();
|
|
return AjaxResult.success(sysFileService.saveData(sysFileManage));
|
} catch (Exception e) {
|
return AjaxResult.error(e.getMessage());
|
}
|
}
|
|
//对列表进行分页
|
private TableDataInfo paginate(List list, int pageNum, int pageSize) {
|
if (list == null || list.isEmpty()) {
|
return new TableDataInfo(new ArrayList<>(), 0);
|
}
|
int total = list.size();
|
int formIndex = (pageNum - 1) * pageSize;
|
int toIndex = Math.min(formIndex + pageSize, total);
|
if (formIndex >= total) {
|
return new TableDataInfo(new ArrayList<>(), total);
|
}
|
List subList = list.subList(formIndex, toIndex);
|
return new TableDataInfo(subList, total);
|
}
|
|
|
@GetMapping("/getYdkfm")
|
@Operation(summary = "获取油电控阀门")
|
public AjaxResult getYdkfm(Integer id) throws Exception {
|
if (null == id || id < 0L) return AjaxResult.error("id为空");
|
DpEquipmentVO dpEquipmentVO = dpEquipmentService.selectById(id);
|
DpEquipment dp = receiveModuleInfoService.getIp(String.valueOf(dpEquipmentVO.getId()), dpEquipmentVO.getEquipmentTypeId());
|
|
DpEquipment eq = dpEquipmentService.getEpByField(String.valueOf(dp.getPort()));
|
if (null == eq || null == eq.getId()) return AjaxResult.error("找不到油电控阀门");
|
|
Map<String, Object> map = receiveModuleInfoService.getYdkfmStatus(String.valueOf(eq.getId()));
|
return success(map);
|
}
|
|
@GetMapping("/ctrlYdkfm")
|
@Operation(summary = "控制油电控阀门")
|
public AjaxResult ctrlYdkfm(Integer id, Boolean flag) throws Exception {
|
if (null == id || id < 0L) return AjaxResult.error("id为空");
|
if (null == flag) return AjaxResult.error("flag为空");
|
|
DpEquipmentVO dpEquipmentVO = dpEquipmentService.selectById(id);
|
DpEquipment dp = receiveModuleInfoService.getIp(String.valueOf(dpEquipmentVO.getId()), dpEquipmentVO.getEquipmentTypeId());
|
|
DpEquipment eq = dpEquipmentService.getEpByField(String.valueOf(dp.getPort()));
|
if (null == eq || null == eq.getId()) return AjaxResult.error("找不到油电控阀门");
|
|
Map<String, Object> map = receiveModuleInfoService.ctrlYdkfm(String.valueOf(eq.getId()), flag);
|
return success(map);
|
}
|
}
|