|
@@ -0,0 +1,233 @@
|
|
|
+package com.usky.iot.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.iot.domain.BaseAlarm;
|
|
|
+import com.usky.iot.domain.BaseAlarmType;
|
|
|
+import com.usky.iot.domain.DmpDeviceInfo;
|
|
|
+import com.usky.iot.domain.DmpProductInfo;
|
|
|
+import com.usky.iot.mapper.BaseAlarmMapper;
|
|
|
+import com.usky.iot.service.BaseAlarmService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.iot.service.BaseAlarmTypeService;
|
|
|
+import com.usky.iot.service.DmpDeviceInfoService;
|
|
|
+import com.usky.iot.service.DmpProductInfoService;
|
|
|
+import com.usky.iot.service.vo.BaseAlarmListVO;
|
|
|
+import com.usky.iot.service.vo.BaseAlarmRequestVO;
|
|
|
+import com.usky.iot.service.vo.BaseAlarmResponeVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 统一告警表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author han
|
|
|
+ * @since 2023-07-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, BaseAlarm> implements BaseAlarmService {
|
|
|
+ @Autowired
|
|
|
+ private BaseAlarmTypeService baseAlarmTypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmpProductInfoService dmpProductInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmpDeviceInfoService dmpDeviceInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<BaseAlarmResponeVO> statistic(BaseAlarmRequestVO baseAlarmRequestVO){
|
|
|
+ IPage<BaseAlarmResponeVO> page = new Page<>(baseAlarmRequestVO.getCurrent(),baseAlarmRequestVO.getSize());
|
|
|
+
|
|
|
+ List<BaseAlarmResponeVO> list = new ArrayList<>();
|
|
|
+
|
|
|
+ QueryWrapper<BaseAlarmType> wrapper = new QueryWrapper<>();
|
|
|
+ if(StringUtils.isNotBlank(baseAlarmRequestVO.getProductCode())){
|
|
|
+ wrapper.select("distinct product_code as productCode")
|
|
|
+ .eq("delete_flag",0)
|
|
|
+ .eq("product_code",baseAlarmRequestVO.getProductCode());
|
|
|
+ }else{
|
|
|
+ wrapper.select("distinct product_code as productCode")
|
|
|
+ .eq("delete_flag",0);
|
|
|
+ }
|
|
|
+ List<BaseAlarmType> list1 = baseAlarmTypeService.list(wrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(list1)){
|
|
|
+ for(int i=0;i<list1.size();i++){
|
|
|
+ BaseAlarmResponeVO responeVO = new BaseAlarmResponeVO();
|
|
|
+ responeVO.setProductCode(list1.get(i).getProductCode());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DmpProductInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(DmpProductInfo::getDeleteFlag,0)
|
|
|
+ .eq(DmpProductInfo::getProductCode,list1.get(i).getProductCode());
|
|
|
+ DmpProductInfo one = dmpProductInfoService.getOne(queryWrapper);
|
|
|
+ if(one != null){
|
|
|
+ responeVO.setProductName(one.getProductName());
|
|
|
+ responeVO.setDeviceType(one.getDeviceType());
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseAlarmType> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(BaseAlarmType::getDeleteFlag,0)
|
|
|
+ .eq(BaseAlarmType::getProductCode,list1.get(i).getProductCode());
|
|
|
+ List<BaseAlarmType> list2 = baseAlarmTypeService.list(queryWrapper1);
|
|
|
+ List<Integer> alarmTypeList = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(list2)){
|
|
|
+ for(int j=0;j<list2.size();j++){
|
|
|
+ alarmTypeList.add(list2.get(j).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //未处理
|
|
|
+ int untreated = this.count(Wrappers.<BaseAlarm>query().lambda().eq(BaseAlarm::getHandleStatus,0).in(BaseAlarm::getAlarmType,alarmTypeList));
|
|
|
+ //已处理
|
|
|
+ int processed = this.count(Wrappers.<BaseAlarm>query().lambda().eq(BaseAlarm::getHandleStatus,1).in(BaseAlarm::getAlarmType,alarmTypeList));
|
|
|
+ //总数
|
|
|
+ int count = untreated+processed;
|
|
|
+ //处置率
|
|
|
+ float processRate = 0;
|
|
|
+ if(count != 0){
|
|
|
+ processRate = ((float) processed/count)*100;
|
|
|
+ }
|
|
|
+
|
|
|
+ responeVO.setTotal(count);
|
|
|
+ responeVO.setUntreated(untreated);
|
|
|
+ responeVO.setProcessed(processed);
|
|
|
+ responeVO.setProcessRate(processRate);
|
|
|
+
|
|
|
+ list.add(responeVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int total = 0;
|
|
|
+ if(list1.size()>0){
|
|
|
+ total = list1.size();
|
|
|
+ }
|
|
|
+ int current = 0;
|
|
|
+ Integer pageNum = baseAlarmRequestVO.getCurrent();
|
|
|
+ Integer pageSize = baseAlarmRequestVO.getSize();
|
|
|
+ if(pageNum != null && pageSize >0){
|
|
|
+ current = (pageNum-1)*pageSize;
|
|
|
+ }
|
|
|
+ List<BaseAlarmResponeVO> records = list.stream().skip(current).limit(pageSize).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new CommonPage<BaseAlarmResponeVO>(records,total,pageSize,pageNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CommonPage<BaseAlarm> page(BaseAlarmListVO baseAlarmListVO){
|
|
|
+ List<BaseAlarm> list = new ArrayList<>();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseAlarmType> queryWrapper2 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper2.eq(BaseAlarmType::getDeleteFlag,0)
|
|
|
+ .eq(BaseAlarmType::getProductCode,baseAlarmListVO.getProductCode());
|
|
|
+ List<BaseAlarmType> list2 = baseAlarmTypeService.list(queryWrapper2);
|
|
|
+ List<Integer> alarmTypeList = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(list2)){
|
|
|
+ for(int j=0;j<list2.size();j++){
|
|
|
+ alarmTypeList.add(list2.get(j).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseAlarm> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper
|
|
|
+ .in(BaseAlarm::getAlarmType,alarmTypeList)
|
|
|
+ .eq(baseAlarmListVO.getAlarmType() != null,BaseAlarm::getAlarmType,baseAlarmListVO.getAlarmType())
|
|
|
+ .between(StringUtils.isNotBlank(baseAlarmListVO.getStartTime()) && StringUtils.isNotBlank(baseAlarmListVO.getEndTime()),BaseAlarm::getAlarmTime,baseAlarmListVO.getStartTime(),baseAlarmListVO.getEndTime())
|
|
|
+ .orderByDesc(BaseAlarm::getId);
|
|
|
+ List<BaseAlarm> records = this.list(queryWrapper);
|
|
|
+ if(records.size()>0){
|
|
|
+ for(int i=0;i<records.size();i++){
|
|
|
+ LambdaQueryWrapper<DmpDeviceInfo> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(DmpDeviceInfo::getDeviceId,records.get(i).getDeviceId())
|
|
|
+ .eq(DmpDeviceInfo::getDeleteFlag,0);
|
|
|
+ DmpDeviceInfo deviceInfo = dmpDeviceInfoService.getOne(queryWrapper1);
|
|
|
+ if(deviceInfo != null){
|
|
|
+ records.get(i).setDeviceName(deviceInfo.getDeviceName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(baseAlarmListVO.getDeviceName())){
|
|
|
+ list = records.stream().filter(e -> baseAlarmListVO.getDeviceName().equals(e.getDeviceName())).collect(Collectors.toList());
|
|
|
+ }else {
|
|
|
+ if(records.size()>0){
|
|
|
+ for(int k=0;k<records.size();k++){
|
|
|
+ list.add(records.get(k));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ int total = 0;
|
|
|
+ if(list.size()>0){
|
|
|
+ total = list.size();
|
|
|
+ }
|
|
|
+ int current = 0;
|
|
|
+ Integer pageNum = baseAlarmListVO.getCurrent();
|
|
|
+ Integer pageSize = baseAlarmListVO.getSize();
|
|
|
+ if(pageNum != null && pageSize >0){
|
|
|
+ current = (pageNum-1)*pageSize;
|
|
|
+ }
|
|
|
+ List<BaseAlarm> info = list.stream().sorted(Comparator.comparing(BaseAlarm::getId,Comparator.reverseOrder())).skip(current).limit(pageSize).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new CommonPage<BaseAlarm>(info,total,pageSize,pageNum);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void update(BaseAlarm baseAlarm){
|
|
|
+ int handleRange = baseAlarm.getHandleRange();
|
|
|
+ if(handleRange == 0){ //批量
|
|
|
+ LambdaQueryWrapper<BaseAlarm> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(BaseAlarm::getDeviceId,baseAlarm.getDeviceId())
|
|
|
+ .eq(BaseAlarm::getAlarmType,baseAlarm.getAlarmType())
|
|
|
+ .eq(BaseAlarm::getHandleStatus,0);
|
|
|
+ List<BaseAlarm> list = this.list(queryWrapper);
|
|
|
+ if(list.size() > 0){
|
|
|
+ for(int i=0;i<list.size();i++){
|
|
|
+ list.get(i).setHandleContent(baseAlarm.getHandleContent());
|
|
|
+ list.get(i).setAlarmFalse(baseAlarm.getAlarmFalse());
|
|
|
+ list.get(i).setHandleStatus(1);
|
|
|
+ list.get(i).setHandleBy(SecurityUtils.getUsername());
|
|
|
+ list.get(i).setHandleTime(LocalDateTime.now());
|
|
|
+ list.get(i).setHandlePhone("13715215564");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateBatchById(list);
|
|
|
+
|
|
|
+ }else { // 单一
|
|
|
+ baseAlarm.setHandleStatus(1);
|
|
|
+ baseAlarm.setHandleBy(SecurityUtils.getUsername());
|
|
|
+ baseAlarm.setHandleTime(LocalDateTime.now());
|
|
|
+ baseAlarm.setHandlePhone("13715215564");
|
|
|
+ this.updateById(baseAlarm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|