|
@@ -3,12 +3,12 @@ package com.xy.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.xy.dto.DeviceErrorsRecordDto;
|
|
|
|
|
|
+import com.xy.dto.DeviceEventMsgDto;
|
|
import com.xy.dto.DeviceInfoDto;
|
|
import com.xy.dto.DeviceInfoDto;
|
|
-import com.xy.entity.DeviceErrorsRecord;
|
|
|
|
|
|
+import com.xy.entity.DeviceEventMsg;
|
|
import com.xy.entity.DeviceInfo;
|
|
import com.xy.entity.DeviceInfo;
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
-import com.xy.mapper.DeviceErrorsRecordMapper;
|
|
|
|
|
|
+import com.xy.mapper.DeviceEventMsgMapper;
|
|
import com.xy.utils.*;
|
|
import com.xy.utils.*;
|
|
import com.xy.utils.enums.SysCodeConfigureEnum;
|
|
import com.xy.utils.enums.SysCodeConfigureEnum;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
+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;
|
|
import java.util.stream.Collectors;
|
|
@@ -30,56 +31,62 @@ import static com.xy.utils.PlusBeans.toPageBean;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
- * 机器-故障表 服务实现类
|
|
|
|
|
|
+ * 机器-消息表 服务实现类
|
|
* </p>
|
|
* </p>
|
|
*
|
|
*
|
|
* @author lijin
|
|
* @author lijin
|
|
* @since 2023-01-09
|
|
* @since 2023-01-09
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-@Api(tags = "机器-故障表")
|
|
|
|
|
|
+@Api(tags = "机器-消息表")
|
|
@AllArgsConstructor(onConstructor_ = @Lazy)
|
|
@AllArgsConstructor(onConstructor_ = @Lazy)
|
|
-public class DeviceErrorsRecordServiceImpl extends ServiceImpl<DeviceErrorsRecordMapper, DeviceErrorsRecord> implements DeviceErrorsRecordService {
|
|
|
|
|
|
+public class DeviceEventMsgServiceImpl extends ServiceImpl<DeviceEventMsgMapper, DeviceEventMsg> implements DeviceEventMsgService {
|
|
|
|
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@ApiOperation("添加")
|
|
@ApiOperation("添加")
|
|
- public R save(DeviceErrorsRecordDto.Save save) {
|
|
|
|
|
|
+ public R save(DeviceEventMsgDto.Save save) {
|
|
DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(save.getDeviceId()).setIsSysinfo(true)).getData();
|
|
DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(save.getDeviceId()).setIsSysinfo(true)).getData();
|
|
if (deviceInfo == null) {
|
|
if (deviceInfo == null) {
|
|
return R.fail("设备不存在");
|
|
return R.fail("设备不存在");
|
|
}
|
|
}
|
|
- //添加故障记录
|
|
|
|
|
|
+ //查询消息编码信息
|
|
|
|
+ String paterCode = save.getCode().substring(0, save.getCode().length() - 1);
|
|
|
|
+ SysCodeConfigureRedis sysCodeConfigureRedis = SysCodeConfigureUtils.get(paterCode, save.getCode());
|
|
|
|
+ //添加消息记录
|
|
save.setMercId(deviceInfo.getMercId());
|
|
save.setMercId(deviceInfo.getMercId());
|
|
- DeviceErrorsRecord deviceErrorsRecord = copy(DeviceErrorsRecord.class, save)
|
|
|
|
|
|
+ DeviceEventMsg deviceEventMsg = copy(DeviceEventMsg.class, save)
|
|
.setCreateTime(LocalDateTime.now());
|
|
.setCreateTime(LocalDateTime.now());
|
|
- save(deviceErrorsRecord);
|
|
|
|
- SysCodeConfigureRedis sysCodeConfigureRedis = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode(), save.getCode());
|
|
|
|
- //修改设备当前故障等级
|
|
|
|
- if (Emptys.check(sysCodeConfigureRedis.getExpand())) {
|
|
|
|
- DeviceInfo updateDeviceInfo = new DeviceInfo()
|
|
|
|
- .setDeviceId(deviceInfo.getDeviceId())
|
|
|
|
- .setFaultLevel(Integer.valueOf(sysCodeConfigureRedis.getExpand()));
|
|
|
|
- deviceInfoService.updateById(updateDeviceInfo);
|
|
|
|
|
|
+ save(deviceEventMsg);
|
|
|
|
+ //异常消息,修改设备当前故障等级
|
|
|
|
+ if (paterCode.equals(SysCodeConfigureEnum.D01.getCode())) {
|
|
|
|
+ if (Emptys.check(sysCodeConfigureRedis.getExpand())) {
|
|
|
|
+ DeviceInfo updateDeviceInfo = new DeviceInfo()
|
|
|
|
+ .setDeviceId(deviceInfo.getDeviceId())
|
|
|
|
+ .setFaultLevel(Integer.valueOf(sysCodeConfigureRedis.getExpand()));
|
|
|
|
+ deviceInfoService.updateById(updateDeviceInfo);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@ApiOperation("分页查询")
|
|
@ApiOperation("分页查询")
|
|
- public R<PageBean<DeviceErrorsRecordDto.Vo>> page(@RequestBody DeviceErrorsRecordDto.Page page) {
|
|
|
|
|
|
+ public R<PageBean<DeviceEventMsgDto.Vo>> page(@RequestBody DeviceEventMsgDto.Page page) {
|
|
|
|
+ List<String> codes = getCodes(page.getCode());
|
|
PageBean pageBean = page.getPage();
|
|
PageBean pageBean = page.getPage();
|
|
- LambdaQueryWrapper<DeviceErrorsRecord> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceErrorsRecord.class)
|
|
|
|
- .ge(DeviceErrorsRecord::getCreateTime, page.getBeginCreateTime())
|
|
|
|
- .le(DeviceErrorsRecord::getCreateTime, page.getEndCreateTime())
|
|
|
|
|
|
+ LambdaQueryWrapper<DeviceEventMsg> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceEventMsg.class)
|
|
|
|
+ .ge(DeviceEventMsg::getCreateTime, page.getBeginCreateTime())
|
|
|
|
+ .le(DeviceEventMsg::getCreateTime, page.getEndCreateTime())
|
|
|
|
+ .in(DeviceEventMsg::getCode, codes)
|
|
.build()
|
|
.build()
|
|
- .orderByDesc(!Emptys.check(pageBean.getOrders()), DeviceErrorsRecord::getId);
|
|
|
|
- IPage<DeviceErrorsRecord> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
|
|
|
|
- PageBean<DeviceErrorsRecordDto.Vo> voPageBean = toPageBean(DeviceErrorsRecordDto.Vo.class, iPage);
|
|
|
|
|
|
+ .orderByDesc(!Emptys.check(pageBean.getOrders()), DeviceEventMsg::getId);
|
|
|
|
+ IPage<DeviceEventMsg> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
|
|
|
|
+ PageBean<DeviceEventMsgDto.Vo> voPageBean = toPageBean(DeviceEventMsgDto.Vo.class, iPage);
|
|
//反显设备名称
|
|
//反显设备名称
|
|
if (Emptys.check(voPageBean.getRecords())) {
|
|
if (Emptys.check(voPageBean.getRecords())) {
|
|
- List<Long> deviceIdList = voPageBean.getRecords().stream().map(DeviceErrorsRecordDto.Vo::getDeviceId).collect(Collectors.toList());
|
|
|
|
|
|
+ List<Long> deviceIdList = voPageBean.getRecords().stream().map(DeviceEventMsgDto.Vo::getDeviceId).collect(Collectors.toList());
|
|
Map<Long, String> deviceMap = deviceInfoService.getDeviceNameList(new DeviceInfoDto.DeviceIdDto().setDeviceId(deviceIdList)).getData();
|
|
Map<Long, String> deviceMap = deviceInfoService.getDeviceNameList(new DeviceInfoDto.DeviceIdDto().setDeviceId(deviceIdList)).getData();
|
|
Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
|
|
Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
|
|
voPageBean.getRecords().forEach(i -> {
|
|
voPageBean.getRecords().forEach(i -> {
|
|
@@ -95,14 +102,16 @@ public class DeviceErrorsRecordServiceImpl extends ServiceImpl<DeviceErrorsRecor
|
|
|
|
|
|
@PostMapping("list")
|
|
@PostMapping("list")
|
|
@ApiOperation("集合查询")
|
|
@ApiOperation("集合查询")
|
|
- public R<List<DeviceErrorsRecordDto.Vo>> list(@RequestBody DeviceErrorsRecordDto.SelectList selectList) {
|
|
|
|
- LambdaQueryWrapper<DeviceErrorsRecord> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceErrorsRecord.class)
|
|
|
|
- .in(DeviceErrorsRecord::getId, selectList.getIds())
|
|
|
|
- .in(DeviceErrorsRecord::getDeviceId, selectList.getDeviceIds())
|
|
|
|
|
|
+ public R<List<DeviceEventMsgDto.Vo>> list(@RequestBody DeviceEventMsgDto.SelectList selectList) {
|
|
|
|
+ List<String> codes = getCodes(selectList.getCode());
|
|
|
|
+ LambdaQueryWrapper<DeviceEventMsg> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceEventMsg.class)
|
|
|
|
+ .in(DeviceEventMsg::getId, selectList.getIds())
|
|
|
|
+ .in(DeviceEventMsg::getDeviceId, selectList.getDeviceIds())
|
|
|
|
+ .in(DeviceEventMsg::getCode, codes)
|
|
.build();
|
|
.build();
|
|
- List<DeviceErrorsRecord> list = list(lambdaQueryWrapper);
|
|
|
|
|
|
+ List<DeviceEventMsg> list = list(lambdaQueryWrapper);
|
|
Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
|
|
Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
|
|
- List<DeviceErrorsRecordDto.Vo> vos = copy(DeviceErrorsRecordDto.Vo.class, list);
|
|
|
|
|
|
+ List<DeviceEventMsgDto.Vo> vos = copy(DeviceEventMsgDto.Vo.class, list);
|
|
vos.forEach(vo -> {
|
|
vos.forEach(vo -> {
|
|
SysCodeConfigureRedis sysCodeConfigureRedis = stringSysCodeConfigureRedisMap.get(vo.getCode());
|
|
SysCodeConfigureRedis sysCodeConfigureRedis = stringSysCodeConfigureRedisMap.get(vo.getCode());
|
|
if (sysCodeConfigureRedis != null) {
|
|
if (sysCodeConfigureRedis != null) {
|
|
@@ -112,4 +121,16 @@ public class DeviceErrorsRecordServiceImpl extends ServiceImpl<DeviceErrorsRecor
|
|
return R.ok(vos);
|
|
return R.ok(vos);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private List<String> getCodes(String code) {
|
|
|
|
+ List<String> codes = new ArrayList<>();
|
|
|
|
+ if (Emptys.check(code)) {
|
|
|
|
+ Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(code);
|
|
|
|
+ if (Emptys.check(stringSysCodeConfigureRedisMap)) {
|
|
|
|
+ stringSysCodeConfigureRedisMap.forEach((code2, sysCodeConfigureRedis) -> codes.add(code2));
|
|
|
|
+ } else {
|
|
|
|
+ codes.add(code);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return codes;
|
|
|
|
+ }
|
|
}
|
|
}
|