Compare commits
8 Commits
98cb67b136
...
main
Author | SHA1 | Date | |
---|---|---|---|
1a2f35a092 | |||
bdbbd5a12f | |||
8462fed747 | |||
7aa02635f2 | |||
626296adbc | |||
9bbed77170 | |||
a5b8cdffec | |||
f839883f82 |
@ -6,7 +6,9 @@ import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import com.fuyuanshen.web.service.device.DeviceXinghanBizService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -33,6 +35,15 @@ public class AppDeviceXinghanController extends BaseController {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送紧急通知
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
|
@ -47,4 +47,9 @@ public class DeviceRedisKeyConstants {
|
||||
* 告警
|
||||
*/
|
||||
public static final String DEVICE_ALARM_KEY_PREFIX = ":alarm";
|
||||
|
||||
/**
|
||||
* 告警信息
|
||||
*/
|
||||
public static final String DEVICE_ALARM_MESSAGE_KEY_PREFIX = ":alarmMessage";
|
||||
}
|
||||
|
@ -117,28 +117,28 @@ public class BjqLocationDataRule implements MqttMessageRule {
|
||||
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
|
||||
return;
|
||||
}
|
||||
// String[] latArr = latitude.split("\\.");
|
||||
// String[] lonArr = longitude.split("\\.");
|
||||
// // 将位置信息存储到Redis中
|
||||
String[] latArr = latitude.split("\\.");
|
||||
String[] lonArr = longitude.split("\\.");
|
||||
// 将位置信息存储到Redis中
|
||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
|
||||
// String redisObj = RedisUtils.getCacheObject(redisKey);
|
||||
// JSONObject jsonOBj = JSONObject.parseObject(redisObj);
|
||||
// if(jsonOBj != null){
|
||||
// String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
|
||||
// String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
|
||||
//
|
||||
// String cacheLatitude = jsonOBj.getString("wgs84_latitude");
|
||||
// String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
// String[] latArr1 = cacheLatitude.split("\\.");
|
||||
// String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
//
|
||||
// String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
|
||||
// String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
|
||||
// if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
|
||||
// log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
String redisObj = RedisUtils.getCacheObject(redisKey);
|
||||
JSONObject jsonOBj = JSONObject.parseObject(redisObj);
|
||||
if(jsonOBj != null){
|
||||
String str1 = latArr[0] +"."+ latArr[1].substring(0,4);
|
||||
String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4);
|
||||
|
||||
String cacheLatitude = jsonOBj.getString("wgs84_latitude");
|
||||
String cacheLongitude = jsonOBj.getString("wgs84_longitude");
|
||||
String[] latArr1 = cacheLatitude.split("\\.");
|
||||
String[] lonArr1 = cacheLongitude.split("\\.");
|
||||
|
||||
String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4);
|
||||
String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4);
|
||||
if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){
|
||||
log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 构造位置信息对象
|
||||
Map<String, Object> locationInfo = new LinkedHashMap<>();
|
||||
|
@ -114,13 +114,24 @@ public class XinghanBootLogoRule implements MqttMessageRule {
|
||||
|
||||
private static final int CHUNK_SIZE = 256;
|
||||
|
||||
/**
|
||||
* 计算数据的CRC32校验值,并将结果转换为整数列表
|
||||
*
|
||||
* @param data 需要计算CRC32校验值的字节数组
|
||||
* @return 包含CRC32校验值的整数列表,每个字节对应一个无符号整数
|
||||
*/
|
||||
private static ArrayList<Integer> crc32AsList(byte[] data) {
|
||||
// 计算CRC32校验值
|
||||
CRC32 crc = new CRC32();
|
||||
crc.update(data);
|
||||
|
||||
// 将CRC32值转换为字节数组
|
||||
byte[] crcBytes = ByteBuffer.allocate(4)
|
||||
.order(ByteOrder.BIG_ENDIAN)
|
||||
.putInt((int) crc.getValue())
|
||||
.array();
|
||||
|
||||
// 将字节数组转换为无符号整数列表
|
||||
ArrayList<Integer> list = new ArrayList<>(4);
|
||||
for (byte b : crcBytes) {
|
||||
list.add(Byte.toUnsignedInt(b));
|
||||
@ -128,6 +139,7 @@ public class XinghanBootLogoRule implements MqttMessageRule {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- DTO ---------- */
|
||||
|
||||
@Data
|
||||
|
@ -14,11 +14,13 @@ import com.fuyuanshen.global.mqtt.base.MqttXinghanJson;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -58,6 +60,7 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext context) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
|
||||
try {
|
||||
// Latitude, longitude
|
||||
//主灯档位,激光灯档位,电量百分比,充电状态,电池剩余续航时间
|
||||
@ -65,8 +68,10 @@ public class XinghanDeviceDataRule implements MqttMessageRule {
|
||||
|
||||
// 发送设备状态和位置信息到Redis
|
||||
asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),deviceStatus);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
} catch (Exception e) {
|
||||
log.error("处理上报数据命令时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,118 @@
|
||||
package com.fuyuanshen.global.mqtt.rule.xinghan;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
|
||||
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.XingHanCommandTypeConstants;
|
||||
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_ALARM_MESSAGE_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 星汉设备发送紧急通知 下发规则:
|
||||
* <p>
|
||||
* 1. 设备上行 sta_BreakNews=cover! => 仅标记成功<br>
|
||||
* 2. 设备上行 sta_BreakNews=数字 => GBK编码,每行文字为一包,一共4包,第一字节为包序号
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class XinghanSendAlarmMessageRule implements MqttMessageRule {
|
||||
|
||||
private final MqttGateway mqttGateway;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return XingHanCommandTypeConstants.XingHan_BREAK_NEWS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MqttRuleContext ctx) {
|
||||
String functionAccess = FUNCTION_ACCESS_KEY + ctx.getDeviceImei();
|
||||
try {
|
||||
XinghanSendAlarmMessageRule.MqttXinghanAlarmMsgJson payload = objectMapper.convertValue(
|
||||
ctx.getPayloadDict(), XinghanSendAlarmMessageRule.MqttXinghanAlarmMsgJson.class);
|
||||
|
||||
String respText = payload.getStaBreakNews();
|
||||
log.info("设备上报紧急通知握手: {} ", respText);
|
||||
|
||||
// 1. cover! —— 成功标记
|
||||
if ("cover!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
log.info("设备 {} 发送紧急通知完成", ctx.getDeviceImei());
|
||||
return;
|
||||
}
|
||||
// 2. 数字 —— 下发数据块
|
||||
int blockIndex;
|
||||
try {
|
||||
blockIndex = Integer.parseInt(respText);
|
||||
} catch (NumberFormatException ex) {
|
||||
log.warn("设备 {} 紧急通知上报非法块号:{}", ctx.getDeviceImei(), respText);
|
||||
return;
|
||||
}
|
||||
// 将发送的信息原文本以List<String>形式存储在Redis中
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + ctx.getDeviceImei() + DEVICE_ALARM_MESSAGE_KEY_PREFIX);
|
||||
if (data == null || data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(blockIndex);
|
||||
// 获取块原内容 转成GBK 再转成无符号十进制整数
|
||||
String blockTxt = data.split("\\|")[blockIndex-1];
|
||||
// 再按 GBK 编码把字符串转成字节数组,并逐个转为无符号十进制整数
|
||||
for (byte b : blockTxt.getBytes(GBK)) {
|
||||
intData.add(b & 0xFF); // b & 0xFF 得到 0~255 的整数
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("ins_BreakNews", intData);
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + ctx.getDeviceImei();
|
||||
String json = JsonUtils.toJsonString(map);
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
log.info("发送设备紧急通知=>topic:{},payload:{}",
|
||||
MqttConstants.GLOBAL_PUB_KEY + ctx.getDeviceImei(),
|
||||
JsonUtils.toJsonString(map));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理发送设备紧急通知时出错", e);
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
}
|
||||
}
|
||||
|
||||
private static final Charset GBK = Charset.forName("GBK");
|
||||
|
||||
/* ---------- DTO ---------- */
|
||||
|
||||
@Data
|
||||
private static class MqttXinghanAlarmMsgJson {
|
||||
/**
|
||||
* 设备上行:
|
||||
* 数字 -> 请求对应块号
|
||||
* cover! -> 写入成功
|
||||
*/
|
||||
@JsonProperty("sta_BreakNews")
|
||||
private String staBreakNews;
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
|
||||
// 1. genius! —— 成功标记
|
||||
if ("genius!".equalsIgnoreCase(respText)) {
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));
|
||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||
log.info("设备 {} 发送消息完成", ctx.getDeviceImei());
|
||||
return;
|
||||
}
|
||||
@ -79,6 +79,7 @@ public class XinghanSendMsgRule implements MqttMessageRule {
|
||||
intData.add(blockIndex);
|
||||
// 获取块原内容 转成GBK 再转成无符号十进制整数
|
||||
String blockTxt = data.get(blockIndex-1);
|
||||
log.warn("设备上报人员登记信息:{}", blockTxt);
|
||||
// 再按 GBK 编码把字符串转成字节数组,并逐个转为无符号十进制整数
|
||||
for (byte b : blockTxt.getBytes(GBK)) {
|
||||
intData.add(b & 0xFF); // b & 0xFF 得到 0~255 的整数
|
||||
|
@ -2,9 +2,6 @@ package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
@ -13,7 +10,9 @@ import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
|
||||
import com.fuyuanshen.web.service.DeviceShareService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 设备分享管理
|
||||
@ -40,12 +39,5 @@ public class DeviceShareController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备分享
|
||||
*/
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/deviceShare")
|
||||
public R<Void> deviceShare(@Validated(AddGroup.class) @RequestBody AppDeviceShareBo bo) {
|
||||
return toAjax(appDeviceShareService.deviceShare(bo));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.equipment.domain.vo.AlarmInformationVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.EquipmentClassificationVo;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 首页数据
|
||||
@ -38,36 +39,29 @@ public class HomePageController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 设备分类
|
||||
* DataOverview
|
||||
*/
|
||||
@GetMapping("/getEquipmentClassification")
|
||||
public R<EquipmentClassificationVo> getEquipmentClassification() {
|
||||
return R.ok(deviceService.getEquipmentClassification());
|
||||
|
||||
|
||||
// 获取设备使用数据
|
||||
@GetMapping("/{deviceId}")
|
||||
public Map<String, Object> getUsageData(
|
||||
@PathVariable String deviceId,
|
||||
@RequestParam String range) {
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
if ("halfYear".equals(range)) {
|
||||
response.put("months", Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月"));
|
||||
response.put("data", Arrays.asList(45, 52, 38, 60, 56, 48));
|
||||
} else if ("oneYear".equals(range)) {
|
||||
response.put("months", Arrays.asList("7月", "8月", "9月", "10月", "11月", "12月",
|
||||
"1月", "2月", "3月", "4月", "5月", "6月"));
|
||||
response.put("data", Arrays.asList(42, 38, 45, 48, 52, 55, 45, 52, 38, 60, 56, 48));
|
||||
}
|
||||
|
||||
response.put("deviceId", deviceId);
|
||||
response.put("range", range);
|
||||
response.put("lastUpdate", new Date());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 报警信息
|
||||
* DataOverview
|
||||
*/
|
||||
@GetMapping("/getAlarmInformation")
|
||||
public R<AlarmInformationVo> getAlarmInformation() {
|
||||
return R.ok(deviceService.getAlarmInformation());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
@GetMapping("/getEquipmentUsageData/{deviceId}/{range}")
|
||||
public R<List<Map<String, Object>>> getEquipmentUsageData(@PathVariable Long deviceId, @PathVariable Integer range) {
|
||||
return R.ok(deviceService.getEquipmentUsageData(deviceId, range));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_K
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_BOOT_LOGO_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -62,7 +61,7 @@ public class DeviceXinghanBizService {
|
||||
"ins_DetectGrade", Map.of(1, "低档", 2, "中档", 3, "高档"),
|
||||
"ins_LightGrade", Map.of(1, "强光", 2, "弱光"),
|
||||
"ins_SOSGrade", Map.of(1, "爆闪模式", 2, "红蓝模式"),
|
||||
"ins_ShakeBit", Map.of(0, "未静止报警", 1, "正在静止报警")
|
||||
"ins_ShakeBit", Map.of(1, "开启报警")
|
||||
// 再加 4、5、6…… 档,直接往 Map 里塞即可
|
||||
);
|
||||
|
||||
@ -161,11 +160,12 @@ public class DeviceXinghanBizService {
|
||||
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(bo.getUnitName());
|
||||
list.add(bo.getName());
|
||||
list.add(bo.getPosition());
|
||||
list.add(bo.getUnitName());
|
||||
list.add(bo.getCode());
|
||||
RedisUtils.setCacheList(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data", list);
|
||||
RedisUtils.expire(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceObj.getDeviceImei() + ":app_send_message_data", Duration.ofSeconds(5 * 60L));
|
||||
|
||||
Map<String, Object> payload = Map.of("ins_TexTrans",
|
||||
Collections.singletonList(0));
|
||||
@ -195,38 +195,136 @@ public class DeviceXinghanBizService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
public int sendAlarmMessage(AppDeviceSendMsgBo bo) {
|
||||
List<Long> deviceIds = bo.getDeviceIds();
|
||||
|
||||
// 1. 简化非空检查和抛出异常
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
// 使用 in 语句根据id集合查询
|
||||
queryWrapper.in("id", deviceIds);
|
||||
// 2. 将批量查询设备,减少数据库交互次数
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if (devices.size() != deviceIds.size()) {
|
||||
// 如果查询回来的设备数量不一致,说明有设备不存在,此处可以优化为更详细的提示
|
||||
throw new ServiceException("部分设备不存在");
|
||||
}
|
||||
|
||||
try {
|
||||
for (Device device : devices) {
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String deviceName = device.getDeviceName();
|
||||
|
||||
// 3. 在循环中进行设备状态检查,快速失败
|
||||
if (isDeviceOffline(deviceImei)) {
|
||||
// 如果设备离线,可以选择继续处理下一个设备,或者抛出异常。这里选择抛出异常。
|
||||
throw new ServiceException(deviceName + ", 设备已断开连接");
|
||||
}
|
||||
|
||||
// 4. 将Redis和MQTT操作封装在一个方法中,提高可读性
|
||||
sendSingleAlarmMessage(device, bo.getSendMsg());
|
||||
|
||||
// 5. 批量更新设备状态,提高效率
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", device.getId())
|
||||
.eq("binding_user_id", AppLoginHelper.getUserId())
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
|
||||
// 6. 记录操作日志
|
||||
recordDeviceLog(device.getId(), deviceName, "发送紧急通知", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (ServiceException e) {
|
||||
// 捕获并重新抛出自定义异常,避免内层异常被外层泛化捕获
|
||||
log.error("发送告警信息指令失败: {}", e.getMessage(), e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("发送告警信息指令发生未知错误", e);
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/* ---------------------------------- 私有通用方法 ---------------------------------- */
|
||||
|
||||
private void sendCommand(DeviceInstructDto dto,
|
||||
String payloadKey,String deviceAction) {
|
||||
long deviceId = dto.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if (isDeviceOffline(device.getDeviceImei())) {
|
||||
throw new ServiceException("设备已断开连接:" + device.getDeviceName());
|
||||
}
|
||||
/**
|
||||
* 封装单个设备发送告警信息的逻辑
|
||||
*/
|
||||
private void sendSingleAlarmMessage(Device device, String message) {
|
||||
String deviceImei = device.getDeviceImei();
|
||||
|
||||
Integer value = Integer.parseInt(dto.getInstructValue());
|
||||
// 缓存告警消息到Redis
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_ALARM_MESSAGE_KEY_PREFIX, message, Duration.ofSeconds(5 * 60L));
|
||||
|
||||
Map<String, Object> payload = Map.of(payloadKey,
|
||||
Collections.singletonList(value));
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei();
|
||||
// 构建并发送MQTT消息
|
||||
Map<String, Object> payload = Map.of("ins_BreakNews", Collections.singletonList(0));
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + deviceImei;
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
try {
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
log.info("发送紧急通知成功 => topic:{}, payload:{}", topic, json);
|
||||
} catch (Exception e) {
|
||||
log.error("发送紧急通知失败, topic={}, payload={}", topic, json, e);
|
||||
throw new ServiceException("发送紧急通知失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送设备控制指令
|
||||
*
|
||||
* @param dto 设备指令数据传输对象,包含设备ID和指令值等信息
|
||||
* @param payloadKey 指令负载数据的键名
|
||||
* @param deviceAction 设备操作类型描述
|
||||
*/
|
||||
private void sendCommand(DeviceInstructDto dto, String payloadKey, String deviceAction) {
|
||||
long deviceId = dto.getDeviceId();
|
||||
|
||||
// 1. 使用Optional简化空值检查,使代码更简洁
|
||||
Device device = Optional.ofNullable(deviceMapper.selectById(deviceId))
|
||||
.orElseThrow(() -> new ServiceException("设备不存在"));
|
||||
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String deviceName = device.getDeviceName();
|
||||
|
||||
// 2. 提前进行设备状态检查,逻辑更清晰
|
||||
if (isDeviceOffline(deviceImei)) {
|
||||
throw new ServiceException("设备已断开连接:" + deviceName);
|
||||
}
|
||||
|
||||
// 3. 统一处理类型转换异常,避免在业务逻辑中混杂try-catch
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt(dto.getInstructValue());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("指令值格式不正确,必须为整数。", e);
|
||||
}
|
||||
|
||||
// 4. 使用Map.of()或Map.ofEntries()创建不可变Map,更简洁且线程安全
|
||||
Map<String, List<Integer>> payload = Map.of(payloadKey, List.of(value));
|
||||
|
||||
String topic = MqttConstants.GLOBAL_PUB_KEY + deviceImei;
|
||||
String json = JsonUtils.toJsonString(payload);
|
||||
|
||||
try {
|
||||
mqttGateway.sendMsgToMqtt(topic, 1, json);
|
||||
log.info("发送指令成功 => topic:{}, payload:{}", topic, json);
|
||||
} catch (Exception e) {
|
||||
log.error("发送指令失败, topic={}, payload={}", topic, json, e);
|
||||
throw new ServiceException("发送指令失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
log.info("发送指令成功 => topic:{}, payload:{}", topic, json);
|
||||
// 5. 将日志记录和描述解析放在try-catch块之外,确保无论是否成功发送指令都能执行
|
||||
String content = resolveGradeDesc("ins_DetectGrade", value);
|
||||
recordDeviceLog(device.getId(),
|
||||
device.getDeviceName(),
|
||||
deviceName,
|
||||
deviceAction,
|
||||
content,
|
||||
AppLoginHelper.getUserId());
|
||||
|
@ -39,8 +39,8 @@ public class EncryptUtilsTest {
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("0");
|
||||
loginBody.setUuid("1d6615668c7f410da77c4e002c601073");
|
||||
loginBody.setCode("9");
|
||||
loginBody.setUuid("d5be31eac1244cee851a9903f358bc6a");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("dyf");
|
||||
|
@ -36,7 +36,6 @@ public class VideoUploadController {
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@SaIgnore
|
||||
public R<List<String>> upload(@RequestParam("file") MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return R.fail("上传文件不能为空");
|
||||
|
@ -126,26 +126,26 @@ public class DeviceController extends BaseController {
|
||||
|
||||
|
||||
// @Log("分配客户")
|
||||
// @Operation(summary = "分配客户")
|
||||
// @PutMapping(value = "/assignCustomer")
|
||||
// public R<Void> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
// deviceService.assignCustomer(customerVo);
|
||||
// return R.ok();
|
||||
// }
|
||||
@Operation(summary = "分配客户")
|
||||
@PutMapping(value = "/assignCustomer")
|
||||
public R<Void> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
deviceService.assignCustomer(customerVo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
// @Log("撤回设备")
|
||||
// @Operation(summary = "撤回分配设备")
|
||||
// @PostMapping(value = "/withdraw")
|
||||
// public R<Void> withdrawDevice(@RequestBody List<Long> ids) {
|
||||
// try {
|
||||
// deviceService.withdrawDevice(ids);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return R.fail(e.getMessage());
|
||||
// }
|
||||
// return R.ok();
|
||||
// }
|
||||
@Operation(summary = "撤回分配设备")
|
||||
@PostMapping(value = "/withdraw")
|
||||
public R<Void> withdrawDevice(@RequestBody List<Long> ids) {
|
||||
try {
|
||||
deviceService.withdrawDevice(ids);
|
||||
} catch (Exception e) {
|
||||
log.error("updateDevice error: " + e.getMessage());
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//
|
||||
// /**
|
||||
|
@ -2,6 +2,11 @@ package com.fuyuanshen.equipment.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceRepairRecordsQueryCriteria;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
@ -41,8 +46,10 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("equipment:repairRecords:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<DeviceRepairRecordsVo> list(DeviceRepairRecordsBo bo, PageQuery pageQuery) {
|
||||
return deviceRepairRecordsService.queryPageList(bo, pageQuery);
|
||||
@Operation(summary = "分页查询维修记录列表")
|
||||
public TableDataInfo<DeviceRepairRecordsVo> list(DeviceRepairRecordsQueryCriteria criteria) {
|
||||
Page<DeviceRepairRecords> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
|
||||
return deviceRepairRecordsService.queryPageList(criteria, page);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +58,7 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
@SaCheckPermission("equipment:repairRecords:export")
|
||||
@Log(title = "设备维修记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(DeviceRepairRecordsBo bo, HttpServletResponse response) {
|
||||
public void export(DeviceRepairRecordsQueryCriteria bo, HttpServletResponse response) {
|
||||
List<DeviceRepairRecordsVo> list = deviceRepairRecordsService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
|
||||
}
|
||||
@ -74,8 +81,8 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
@SaCheckPermission("equipment:repairRecords:add")
|
||||
@Log(title = "设备维修记录", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceRepairRecordsBo bo) {
|
||||
@PostMapping(consumes = "multipart/form-data")
|
||||
public R<Void> add(@Validated(AddGroup.class) DeviceRepairRecordsBo bo) {
|
||||
return toAjax(deviceRepairRecordsService.insertByBo(bo));
|
||||
}
|
||||
|
||||
@ -85,8 +92,8 @@ public class DeviceRepairRecordsController extends BaseController {
|
||||
@SaCheckPermission("equipment:repairRecords:edit")
|
||||
@Log(title = "设备维修记录", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceRepairRecordsBo bo) {
|
||||
@PutMapping(consumes = "multipart/form-data")
|
||||
public R<Void> edit(@Validated(EditGroup.class) DeviceRepairRecordsBo bo) {
|
||||
return toAjax(deviceRepairRecordsService.updateByBo(bo));
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ public class Device extends TenantEntity {
|
||||
private Date productionDate;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线,2异常)
|
||||
* 在线状态(0离线,1在线)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
}
|
||||
|
@ -36,10 +36,8 @@ public class DeviceAlarm extends TenantEntity {
|
||||
|
||||
/**
|
||||
* 报警事项
|
||||
* 0-强制报警,1-撞击闯入,2-手动报警,3-电子围栏告警,4-强制告警
|
||||
* device_action
|
||||
*/
|
||||
private Integer deviceAction;
|
||||
private String deviceAction;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
@ -94,7 +92,6 @@ public class DeviceAlarm extends TenantEntity {
|
||||
|
||||
/**
|
||||
* 0已处理,1未处理
|
||||
* treatment_state
|
||||
*/
|
||||
private Long treatmentState;
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.fuyuanshen.equipment.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.fuyuanshen.equipment.enums.RepairImageType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 设备维修图片对象 device_repair_images
|
||||
*
|
||||
*
|
||||
* @date 2025-09-02
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("device_repair_images")
|
||||
public class DeviceRepairImages extends TenantEntity {
|
||||
/**
|
||||
* 维修图片ID
|
||||
*/
|
||||
@TableId(value = "image_id", type = IdType.AUTO)
|
||||
@TableField(insertStrategy = FieldStrategy.NEVER)
|
||||
private Long imageId;
|
||||
/**
|
||||
* 维修记录ID
|
||||
*/
|
||||
@Schema(title = "维修记录ID")
|
||||
private Long recordId;
|
||||
/**
|
||||
* 图片类型(维修前/维修后)
|
||||
*/
|
||||
@Schema(title = "图片类型(维修前/维修后)")
|
||||
private RepairImageType imageType;
|
||||
/**
|
||||
* 图片存储路径
|
||||
*/
|
||||
@Schema(title = "图片存储路径")
|
||||
private String imageUrl;
|
||||
}
|
@ -26,7 +26,8 @@ public class DeviceRepairRecords extends TenantEntity {
|
||||
/**
|
||||
* 维修记录ID
|
||||
*/
|
||||
@TableId(value = "record_id")
|
||||
@TableId(value = "record_id", type = IdType.AUTO)
|
||||
@TableField(insertStrategy = FieldStrategy.NEVER)
|
||||
private Long recordId;
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public class DeviceType extends TenantEntity {
|
||||
@Schema(title = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
@Schema(title = "通讯方式", example = "0:4G;1:蓝牙,2 4G&蓝牙")
|
||||
@Schema(title = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
/**
|
||||
|
@ -1,15 +1,19 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 设备维修记录业务对象 device_repair_records
|
||||
@ -37,6 +41,7 @@ public class DeviceRepairRecordsBo extends BaseEntity {
|
||||
/**
|
||||
* 维修时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@NotNull(message = "维修时间不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Date repairTime;
|
||||
|
||||
@ -58,5 +63,11 @@ public class DeviceRepairRecordsBo extends BaseEntity {
|
||||
@NotBlank(message = "维修人员不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String repairPerson;
|
||||
|
||||
@Schema(title = "维修前图片")
|
||||
@JsonIgnore
|
||||
private MultipartFile beforeFile;
|
||||
|
||||
@Schema(title = "维修后图片")
|
||||
@JsonIgnore
|
||||
private MultipartFile afterFile;
|
||||
}
|
||||
|
@ -83,7 +83,6 @@ public class DeviceQueryCriteria extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
* communication_mode
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 设备维修记录查询
|
||||
*
|
||||
* @Description:
|
||||
* @Author: WY
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
public class DeviceRepairRecordsQueryCriteria extends BaseEntity {
|
||||
/**
|
||||
* 维修记录ID
|
||||
*/
|
||||
private Long recordId;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 维修时间
|
||||
*/
|
||||
private Date repairTime;
|
||||
|
||||
/**
|
||||
* 维修部位
|
||||
*/
|
||||
private String repairPart;
|
||||
|
||||
/**
|
||||
* 维修原因
|
||||
*/
|
||||
private String repairReason;
|
||||
|
||||
/**
|
||||
* 维修人员
|
||||
*/
|
||||
private String repairPerson;
|
||||
|
||||
@Schema(title = "维修开始时间")
|
||||
private Date repairBeginTime;
|
||||
@Schema(title = "维修结束时间")
|
||||
private Date repairEndTime;
|
||||
|
||||
@Schema(title = "所属客户")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(title = "com.fuyuanshen")
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private Integer pageNum = 1;
|
||||
|
||||
/**
|
||||
* 每页数据量
|
||||
*/
|
||||
private Integer pageSize = 10;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairImages;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.equipment.enums.RepairImageType;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 设备维修图片视图对象 device_repair_records
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-09-01
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = DeviceRepairImages.class)
|
||||
public class DeviceRepairImagesVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 维修图片ID
|
||||
*/
|
||||
@Schema(title = "维修图片ID")
|
||||
private Long imageId;
|
||||
/**
|
||||
* 维修记录ID
|
||||
*/
|
||||
@Schema(title = "维修记录ID")
|
||||
private Long recordId;
|
||||
/**
|
||||
* 图片类型(维修前/维修后)
|
||||
*/
|
||||
@Schema(title = "图片类型(维修前/维修后)")
|
||||
private RepairImageType imageType;
|
||||
/**
|
||||
* 图片存储路径
|
||||
*/
|
||||
@Schema(title = "图片存储路径")
|
||||
private String imageUrl;
|
||||
}
|
@ -2,6 +2,7 @@ package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
@ -13,7 +14,7 @@ import lombok.Data;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -25,7 +26,7 @@ import java.util.Date;
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = DeviceRepairRecords.class)
|
||||
public class DeviceRepairRecordsVo implements Serializable {
|
||||
public class DeviceRepairRecordsVo extends TenantEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -65,6 +66,12 @@ public class DeviceRepairRecordsVo implements Serializable {
|
||||
*/
|
||||
@ExcelProperty(value = "维修人员")
|
||||
private String repairPerson;
|
||||
/**
|
||||
* 维修人员
|
||||
*/
|
||||
@ExcelProperty(value = "设备名称")
|
||||
private String deviceName;
|
||||
|
||||
private List<DeviceRepairImagesVo> images;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.fuyuanshen.equipment.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum RepairImageType {
|
||||
BEFORE(1, "维修前"),
|
||||
AFTER(2, "维修后");
|
||||
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
public static RepairImageType of(Integer code) {
|
||||
return Arrays.stream(values())
|
||||
.filter(e -> e.getCode() == code)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
@ -6,12 +6,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.LocationHistoryVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -71,42 +72,7 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
|
||||
AppDeviceVo getDeviceInfo(@Param("deviceMac") String deviceMac);
|
||||
|
||||
Page<WebDeviceVo> queryWebDeviceList(Page<Object> build, @Param("criteria") DeviceQueryCriteria criteria);
|
||||
Page<WebDeviceVo> queryWebDeviceList(Page<Object> build,@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
Page<LocationHistoryVo> getLocationHistory(Page<Object> build, @Param("bo") InstructionRecordDto criteria);
|
||||
|
||||
/**
|
||||
* 获取数据总览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
DataOverviewVo getDataOverview();
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EquipmentClassificationVo getEquipmentClassification();
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AlarmInformationVo getAlarmInformation();
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range);
|
||||
|
||||
// 在DeviceMapper.java中添加方法
|
||||
int getUsageDataForMonth(@Param("deviceId") Long deviceId,
|
||||
@Param("year") int year,
|
||||
@Param("month") int month);
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairImages;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceRepairImagesVo;
|
||||
|
||||
public interface DeviceRepairImagesMapper extends BaseMapperPlus<DeviceRepairImages, DeviceRepairImagesVo> {
|
||||
}
|
@ -1,8 +1,16 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceRepairRecordsQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备维修记录Mapper接口
|
||||
@ -11,5 +19,19 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
* @date 2025-08-08
|
||||
*/
|
||||
public interface DeviceRepairRecordsMapper extends BaseMapperPlus<DeviceRepairRecords, DeviceRepairRecordsVo> {
|
||||
|
||||
/**
|
||||
* 分页查询维修记录
|
||||
*
|
||||
* @param criteria
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
IPage<DeviceRepairRecordsVo> findAll(@Param("criteria") DeviceRepairRecordsQueryCriteria criteria, Page<DeviceRepairRecords> page);
|
||||
/**
|
||||
* 查询所有维修记录
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
List<DeviceRepairRecordsVo> findAll(@Param("criteria") DeviceRepairRecordsQueryCriteria criteria);
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -121,27 +122,4 @@ public interface DeviceService extends IService<Device> {
|
||||
* @return
|
||||
*/
|
||||
DataOverviewVo getDataOverview();
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EquipmentClassificationVo getEquipmentClassification();
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AlarmInformationVo getAlarmInformation();
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range);
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceRepairRecordsQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
@ -14,7 +19,7 @@ import java.util.List;
|
||||
* @author Lion Li
|
||||
* @date 2025-08-08
|
||||
*/
|
||||
public interface IDeviceRepairRecordsService {
|
||||
public interface IDeviceRepairRecordsService extends IService<DeviceRepairRecords> {
|
||||
|
||||
/**
|
||||
* 查询设备维修记录
|
||||
@ -31,7 +36,7 @@ public interface IDeviceRepairRecordsService {
|
||||
* @param pageQuery 分页参数
|
||||
* @return 设备维修记录分页列表
|
||||
*/
|
||||
TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsBo bo, PageQuery pageQuery);
|
||||
TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsQueryCriteria criteria, Page<DeviceRepairRecords> page);
|
||||
|
||||
/**
|
||||
* 查询符合条件的设备维修记录列表
|
||||
@ -39,7 +44,7 @@ public interface IDeviceRepairRecordsService {
|
||||
* @param bo 查询条件
|
||||
* @return 设备维修记录列表
|
||||
*/
|
||||
List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsBo bo);
|
||||
List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 新增设备维修记录
|
||||
|
@ -99,7 +99,6 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
|
||||
lqw.in(CollectionUtil.isNotEmpty(bo.getDeviceIds()), DeviceLog::getDeviceId, bo.getDeviceIds());
|
||||
lqw.orderByDesc(DeviceLog::getCreateTime);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,25 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairImages;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceRepairRecordsQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceRepairImagesVo;
|
||||
import com.fuyuanshen.equipment.enums.RepairImageType;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceRepairImagesMapper;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -15,10 +29,10 @@ import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceRepairRecordsMapper;
|
||||
import com.fuyuanshen.equipment.service.IDeviceRepairRecordsService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 设备维修记录Service业务层处理
|
||||
@ -29,9 +43,11 @@ import java.util.Collection;
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsService {
|
||||
public class DeviceRepairRecordsServiceImpl extends ServiceImpl<DeviceRepairRecordsMapper, DeviceRepairRecords> implements IDeviceRepairRecordsService {
|
||||
|
||||
private final DeviceRepairRecordsMapper baseMapper;
|
||||
private final DeviceRepairImagesMapper imagesMapper;
|
||||
private final ISysOssService ossService;
|
||||
|
||||
/**
|
||||
* 查询设备维修记录
|
||||
@ -41,33 +57,53 @@ public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsServi
|
||||
*/
|
||||
@Override
|
||||
public DeviceRepairRecordsVo queryById(Long recordId){
|
||||
return baseMapper.selectVoById(recordId);
|
||||
// 1. 主表
|
||||
DeviceRepairRecordsVo vo = baseMapper.selectVoById(recordId);
|
||||
if (vo == null) {
|
||||
throw new RuntimeException("维修记录不存在");
|
||||
}
|
||||
|
||||
// 2. 子表图片
|
||||
List<DeviceRepairImagesVo> images = imagesMapper.selectVoList(
|
||||
new LambdaQueryWrapper<DeviceRepairImages>()
|
||||
.eq(DeviceRepairImages::getRecordId, recordId)
|
||||
.orderByAsc(DeviceRepairImages::getImageType)); // 如有排序需求
|
||||
// 3. 组装到 VO
|
||||
vo.setImages(images); // 需要在 DeviceRepairRecordsVo 里加该字段
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询设备维修记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @param criteria 查询条件
|
||||
* @param page 分页参数
|
||||
* @return 设备维修记录分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<DeviceRepairRecords> lqw = buildQueryWrapper(bo);
|
||||
Page<DeviceRepairRecordsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
public TableDataInfo<DeviceRepairRecordsVo> queryPageList(DeviceRepairRecordsQueryCriteria criteria, Page<DeviceRepairRecords> page) {
|
||||
// 管理员
|
||||
String username = LoginHelper.getUsername();
|
||||
if (!username.equals("admin")) {
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
}
|
||||
|
||||
if(criteria.getRepairEndTime() !=null ){
|
||||
criteria.setRepairEndTime(DateUtil.endOfDay(criteria.getRepairEndTime()));
|
||||
}
|
||||
IPage<DeviceRepairRecordsVo> deviceRepairRecordsIPage = baseMapper.findAll(criteria, page);
|
||||
return new TableDataInfo<DeviceRepairRecordsVo>(deviceRepairRecordsIPage.getRecords(), deviceRepairRecordsIPage.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的设备维修记录列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param criteria 查询条件
|
||||
* @return 设备维修记录列表
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsBo bo) {
|
||||
LambdaQueryWrapper<DeviceRepairRecords> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
public List<DeviceRepairRecordsVo> queryList(DeviceRepairRecordsQueryCriteria criteria) {
|
||||
return baseMapper.findAll(criteria);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DeviceRepairRecords> buildQueryWrapper(DeviceRepairRecordsBo bo) {
|
||||
@ -89,14 +125,30 @@ public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsServi
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(DeviceRepairRecordsBo bo) {
|
||||
DeviceRepairRecords add = MapstructUtils.convert(bo, DeviceRepairRecords.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setRecordId(add.getRecordId());
|
||||
// 1. 保存主表
|
||||
DeviceRepairRecords entity = MapstructUtils.convert(bo, DeviceRepairRecords.class);
|
||||
validEntityBeforeSave(entity);
|
||||
boolean ok = baseMapper.insert(entity) > 0;
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
return flag;
|
||||
|
||||
// 2. 回填主键
|
||||
Long recordId = entity.getRecordId();
|
||||
bo.setRecordId(recordId);
|
||||
|
||||
// 3. 组装图片实体
|
||||
List<DeviceRepairImages> images = new ArrayList<>(2);
|
||||
addImageIfPresent(images, recordId, bo.getBeforeFile(), RepairImageType.BEFORE);
|
||||
addImageIfPresent(images, recordId, bo.getAfterFile(), RepairImageType.AFTER);
|
||||
|
||||
// 4. 批量插入
|
||||
if (!images.isEmpty()) {
|
||||
imagesMapper.insertBatch(images);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,10 +158,56 @@ public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsServi
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateByBo(DeviceRepairRecordsBo bo) {
|
||||
DeviceRepairRecords update = MapstructUtils.convert(bo, DeviceRepairRecords.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
Long recordId = bo.getRecordId();
|
||||
|
||||
// 1. 校验记录是否存在
|
||||
DeviceRepairRecords dbRecord = baseMapper.selectById(recordId);
|
||||
if (dbRecord == null) {
|
||||
throw new RuntimeException("维修记录不存在");
|
||||
}
|
||||
|
||||
// 2. 更新主表
|
||||
DeviceRepairRecords entity = MapstructUtils.convert(bo, DeviceRepairRecords.class);
|
||||
validEntityBeforeSave(entity);
|
||||
if (!StringUtils.isNotEmpty(entity.getDeviceId())){
|
||||
throw new RuntimeException("维修记录不能为空!!!");
|
||||
}
|
||||
boolean updated = baseMapper.updateById(entity) > 0;
|
||||
if (!updated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 收集需要保存的图片
|
||||
List<DeviceRepairImages> images = new ArrayList<>(2);
|
||||
addImageIfPresent(images, recordId, bo.getBeforeFile(), RepairImageType.BEFORE);
|
||||
addImageIfPresent(images, recordId, bo.getAfterFile(), RepairImageType.AFTER);
|
||||
|
||||
// 4. 批量插入
|
||||
if (!images.isEmpty()) {
|
||||
imagesMapper.insertBatch(images);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ---------- 工具方法 ---------- */
|
||||
|
||||
private void addImageIfPresent(List<DeviceRepairImages> list,
|
||||
Long recordId,
|
||||
MultipartFile file,
|
||||
RepairImageType imageType) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SysOssVo ossVo = ossService.upload(file);
|
||||
|
||||
DeviceRepairImages image = new DeviceRepairImages();
|
||||
image.setRecordId(recordId);
|
||||
image.setImageType(imageType);
|
||||
image.setImageUrl(ossVo.getUrl());
|
||||
|
||||
list.add(image);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,6 +215,9 @@ public class DeviceRepairRecordsServiceImpl implements IDeviceRepairRecordsServi
|
||||
*/
|
||||
private void validEntityBeforeSave(DeviceRepairRecords entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
if (!StringUtils.isNotEmpty(entity.getDeviceId())){
|
||||
throw new RuntimeException("维修设备不能为空!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,9 @@ import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||
@ -51,9 +53,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -592,6 +596,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备MAC号
|
||||
*
|
||||
@ -617,46 +623,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
*/
|
||||
@Override
|
||||
public DataOverviewVo getDataOverview() {
|
||||
DataOverviewVo dataOverviewVo = deviceMapper.getDataOverview();
|
||||
return dataOverviewVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EquipmentClassificationVo getEquipmentClassification() {
|
||||
EquipmentClassificationVo equipmentClassification = deviceMapper.getEquipmentClassification();
|
||||
return equipmentClassification;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AlarmInformationVo getAlarmInformation() {
|
||||
AlarmInformationVo alarmInformation = deviceMapper.getAlarmInformation();
|
||||
return alarmInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range) {
|
||||
List<Map<String, Object>> equipmentUsageData = deviceMapper.getEquipmentUsageData(deviceId, range);
|
||||
return equipmentUsageData;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,9 +74,6 @@
|
||||
<if test="criteria.groupId != null">
|
||||
and d.group_id = #{criteria.groupId}
|
||||
</if>
|
||||
<if test="criteria.communicationMode != null">
|
||||
and t.communication_mode = #{criteria.communicationMode}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
@ -283,7 +280,7 @@
|
||||
</if>
|
||||
</select>
|
||||
<select id="getLocationHistory" resultType="com.fuyuanshen.equipment.domain.vo.LocationHistoryVo">
|
||||
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a
|
||||
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a
|
||||
inner join device_type b on a.device_type = b.id
|
||||
|
||||
<if test="bo.deviceType != null">
|
||||
@ -314,93 +311,4 @@
|
||||
a.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 获取数据总览 -->
|
||||
<select id="getDataOverview" resultType="com.fuyuanshen.equipment.domain.vo.DataOverviewVo">
|
||||
SELECT (SELECT COUNT(1) FROM device) AS devicesNumber,
|
||||
(SELECT COUNT(1) FROM device WHERE device_status = 1) AS equipmentOnline,
|
||||
(SELECT COUNT(1) FROM device WHERE DATE (create_time) = CURDATE()) AS bindingNew, (
|
||||
SELECT COUNT (1)
|
||||
FROM device
|
||||
WHERE device_status = 2) AS equipmentAbnormal
|
||||
</select>
|
||||
|
||||
<!-- 获取设备分类 -->
|
||||
<select id="getEquipmentClassification"
|
||||
resultType="com.fuyuanshen.equipment.domain.vo.EquipmentClassificationVo">
|
||||
SELECT (SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 0) AS equipment4G,
|
||||
(SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 1) AS deviceBluetooth,
|
||||
(SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 2) AS devices4GAndBluetooth
|
||||
</select>
|
||||
|
||||
<!-- 获取告警信息 -->
|
||||
<select id="getAlarmInformation" resultType="com.fuyuanshen.equipment.domain.vo.AlarmInformationVo">
|
||||
SELECT (SELECT COUNT(1) FROM device_alarm WHERE treatment_state = 0 AND DATE (create_time) = CURDATE()) AS alarmsTotal, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE treatment_state = 0
|
||||
AND DATE (create_time) = CURDATE()) AS processingAlarm
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 0
|
||||
AND DATE (create_time) = CURDATE()) AS alarmForced
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 1
|
||||
AND DATE (create_time) = CURDATE()) AS intrusionImpact
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 2
|
||||
AND DATE (create_time) = CURDATE()) AS alarmManual
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 3 AND DATE (create_time) = CURDATE()) AS fenceElectronic
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 获取设备使用数据 -->
|
||||
<select id="getEquipmentUsageData" resultType="map">
|
||||
SELECT COUNT(CASE WHEN MONTH (dl.create_time) = 1 THEN 1 END) AS m1,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 2 THEN 1 END) AS m2,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 3 THEN 1 END) AS m3,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 4 THEN 1 END) AS m4,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 5 THEN 1 END) AS m5,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 6 THEN 1 END) AS m6,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 7 THEN 1 END) AS m7,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 8 THEN 1 END) AS m8,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 9 THEN 1 END) AS m9,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 10 THEN 1 END) AS m10,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 11 THEN 1 END) AS m11,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 12 THEN 1 END) AS m12
|
||||
FROM device_log dl
|
||||
LEFT JOIN device d ON dl.device_id = d.id
|
||||
LEFT JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.id = #{deviceId}
|
||||
AND (
|
||||
(#{range} = 1 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)) OR
|
||||
(#{range} = 2 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 12 MONTH))
|
||||
)
|
||||
</select>
|
||||
|
||||
<select id="getUsageDataForMonth" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM device_log dl
|
||||
WHERE dl.device_id = #{deviceId}
|
||||
AND YEAR (
|
||||
dl.create_time) = #{year}
|
||||
AND MONTH (dl.create_time) = #{month}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceRepairImagesMapper">
|
||||
|
||||
</mapper>
|
@ -3,5 +3,41 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceRepairRecordsMapper">
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo">
|
||||
<id column="record_id" property="recordId"/>
|
||||
<result column="device_id" property="deviceId"/>
|
||||
<result column="deviceName" property="deviceName"/>
|
||||
<result column="repair_time" property="repairTime"/>
|
||||
<result column="repair_part" property="repairPart"/>
|
||||
<result column="repair_reason" property="repairReason"/>
|
||||
<result column="repair_person" property="repairPerson"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="update_by" property="updateBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询所有设备类型 -->
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT dr.*,d.device_name as deviceName
|
||||
FROM device_repair_records dr
|
||||
JOIN device d ON dr.device_id = d.id
|
||||
<where>
|
||||
<if test="criteria.deviceId != null">
|
||||
and dr.device_id = #{criteria.deviceId}
|
||||
</if>
|
||||
<if test="criteria.repairPart != null">
|
||||
and dr.repairPart like concat('%', TRIM(#{criteria.repairPart}), '%')
|
||||
</if>
|
||||
<!-- 时间段条件 -->
|
||||
<if test="criteria.repairBeginTime != null">
|
||||
AND dr.repair_time <![CDATA[ >= ]]> #{criteria.repairBeginTime}
|
||||
</if>
|
||||
<if test="criteria.repairEndTime != null">
|
||||
<!-- 如果想默认包含当天 23:59:59,可在 Java 代码里把结束时间设为 endOfDay -->
|
||||
AND dr.repair_time <![CDATA[ <= ]]> #{criteria.repairEndTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY dr.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user