123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package com.xy.service;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.xy.dto.DeviceEventMsgDto;
- import com.xy.dto.DeviceInfoDto;
- import com.xy.entity.DeviceEventMsg;
- import com.xy.entity.DeviceInfo;
- import com.xy.entity.SysCodeConfigureRedis;
- import com.xy.mapper.DeviceEventMsgMapper;
- import com.xy.utils.*;
- import com.xy.utils.enums.SysCodeConfigureEnum;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import static com.xy.utils.Beans.copy;
- import static com.xy.utils.PlusBeans.toIPage;
- import static com.xy.utils.PlusBeans.toPageBean;
- /**
- * <p>
- * 机器-消息表 服务实现类
- * </p>
- *
- * @author lijin
- * @since 2023-01-09
- */
- @Service
- @Api(tags = "机器-消息表")
- @AllArgsConstructor(onConstructor_ = @Lazy)
- public class DeviceEventMsgServiceImpl extends ServiceImpl<DeviceEventMsgMapper, DeviceEventMsg> implements DeviceEventMsgService {
- private DeviceInfoServiceImpl deviceInfoService;
- @Override
- @ApiOperation("添加")
- public R save(DeviceEventMsgDto.Save save) {
- DeviceInfoDto.Vo deviceInfo = deviceInfoService.obj(new DeviceInfoDto.Obj().setDeviceId(save.getDeviceId()).setIsSysinfo(true)).getData();
- if (deviceInfo == null) {
- return R.fail("设备不存在");
- }
- //查询消息编码信息
- String paterCode = save.getCode().substring(0, save.getCode().length() - 1);
- SysCodeConfigureRedis sysCodeConfigureRedis = SysCodeConfigureUtils.get(paterCode, save.getCode());
- //添加消息记录
- save.setMercId(deviceInfo.getMercId());
- DeviceEventMsg deviceEventMsg = copy(DeviceEventMsg.class, save)
- .setCreateTime(LocalDateTime.now());
- 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();
- }
- @Override
- @ApiOperation("分页查询")
- public R<PageBean<DeviceEventMsgDto.Vo>> page(@RequestBody DeviceEventMsgDto.Page page) {
- List<String> codes = getCodes(page.getCode());
- PageBean pageBean = page.getPage();
- LambdaQueryWrapper<DeviceEventMsg> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceEventMsg.class)
- .ge(DeviceEventMsg::getCreateTime, page.getBeginCreateTime())
- .le(DeviceEventMsg::getCreateTime, page.getEndCreateTime())
- .in(DeviceEventMsg::getCode, codes)
- .build()
- .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())) {
- 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<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
- voPageBean.getRecords().forEach(i -> {
- i.setDeviceName(deviceMap.get(i.getDeviceId()));
- SysCodeConfigureRedis sysCodeConfigureRedis = stringSysCodeConfigureRedisMap.get(i.getCode());
- if (sysCodeConfigureRedis != null) {
- i.setSysCodeConfigureRedis(sysCodeConfigureRedis);
- }
- });
- }
- return R.ok(voPageBean);
- }
- @PostMapping("list")
- @ApiOperation("集合查询")
- 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();
- List<DeviceEventMsg> list = list(lambdaQueryWrapper);
- Map<String, SysCodeConfigureRedis> stringSysCodeConfigureRedisMap = SysCodeConfigureUtils.get(SysCodeConfigureEnum.D01.getCode());
- List<DeviceEventMsgDto.Vo> vos = copy(DeviceEventMsgDto.Vo.class, list);
- vos.forEach(vo -> {
- SysCodeConfigureRedis sysCodeConfigureRedis = stringSysCodeConfigureRedisMap.get(vo.getCode());
- if (sysCodeConfigureRedis != null) {
- vo.setSysCodeConfigureRedis(sysCodeConfigureRedis);
- }
- });
- 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;
- }
- }
|