Merge remote-tracking branch 'origin/master'

This commit is contained in:
小魔仙~
2024-12-19 14:10:55 +08:00
16 changed files with 321 additions and 60 deletions

View File

@ -484,10 +484,8 @@ public class DeviceController extends BaseController {
ArrayList<Object> data = deviceService.getDeviceLogAllCurves(deviceId, beginTime, endTime);
return success(data);
}
/**
* 获取视频监控
*
* @param
* @return
*/

View File

@ -1,16 +1,28 @@
package com.fastbee.data.controller.sse;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.AjaxResultPro;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.iot.domain.DeviceReportInfo;
import com.fastbee.iot.domain.UtilDeviceNumberAdd;
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
import com.fastbee.iot.mapper.UtilDeviceNumberAddMapper;
import com.fastbee.iot.model.dto.DevicePowerDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
@ -25,6 +37,15 @@ import java.util.concurrent.ConcurrentHashMap;
public class DeviceReportSSEController extends BaseController {
private final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>();//用户消息推送集合
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private DeviceReportInfoMapper deviceReportInfoMapper;
@Autowired
private UtilDeviceNumberAddMapper numberAddMapper ;
/**
* 与客户端建立http长链接
*/
@ -37,55 +58,118 @@ public class DeviceReportSSEController extends BaseController {
}
@PostMapping("/device/init/new")
public AjaxResultPro sendMsg(@RequestBody DeviceReportInfo reportInfo) {
try{
SseEmitter emitter = emitters.get("device-init");
if(emitter==null){
return AjaxResultPro.error("审核员离线!请到管理后台打开设备初始化页面!");
}
//生成设备默认编号
// reportInfo.setDeviceId("10086");
String deviceNumber = generateDeviceNumber();
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
return AjaxResultPro.success();
}catch (Exception e){
log.error("发送消息失败",e);
return AjaxResultPro.error("系统错误!");
public AjaxResultPro sendMsg(@RequestBody DevicePowerDTO reportInfo) {
// checkDeviceReportInfo(reportInfo);
if(StringUtils.isBlank(reportInfo.getImei())){
return AjaxResultPro.success(111,"imei不能为空",null);
}
if(StringUtils.isBlank(reportInfo.getIccid())){
return AjaxResultPro.success(111,"iccid不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getMcuId())){
return AjaxResultPro.success(111,"mcuId不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getBspType())){
return AjaxResultPro.success(111,"bspType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getLteType())){
return AjaxResultPro.success(111,"lteType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getMcuType())){
return AjaxResultPro.success(111,"mcuType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getMcuFw())){
return AjaxResultPro.success(111,"mcuFw不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getLteFw())){
return AjaxResultPro.success(111,"lteFw不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getLcdType())){
return AjaxResultPro.success(111,"lcdType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getVoiceType())){
return AjaxResultPro.success(111,"voiceType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getFacType())){
return AjaxResultPro.success(111,"facType不能为空!",null);
}
if(StringUtils.isBlank(reportInfo.getTestRecord())){
return AjaxResultPro.success(111,"testRecord不能为空!",null);
}
SseEmitter emitter = emitters.get("device-init");
// String deviceNumber = generateDeviceNumber();
//映射字段
DeviceReportInfo deviceReportInfo= new DeviceReportInfo();
deviceReportInfo.setImei(reportInfo.getImei());
deviceReportInfo.setIccid(reportInfo.getIccid());
deviceReportInfo.setMcuId(reportInfo.getMcuId());
deviceReportInfo.setBspType(reportInfo.getBspType());
deviceReportInfo.setLteType(reportInfo.getLteType());
deviceReportInfo.setMcuType(reportInfo.getMcuType());
deviceReportInfo.setMcuFw(reportInfo.getMcuFw());
deviceReportInfo.setLteFw(reportInfo.getLteFw());
deviceReportInfo.setLcdManufacturer(Long.valueOf(reportInfo.getLcdType()));
deviceReportInfo.setVoiceManufacturer(Long.valueOf(reportInfo.getVoiceType()));
deviceReportInfo.setReplaceManufacturer(Long.valueOf(reportInfo.getFacType()));
deviceReportInfo.setTestRecord(reportInfo.getTestRecord());
//设置状态为未审核
if (emitter==null) {
deviceReportInfo.setStatus(0);
}
//设备编码查重
List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper)
.select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei)
.eq(DeviceReportInfo::getSerialNumber, deviceReportInfo.getSerialNumber())
.or()
.eq(DeviceReportInfo::getImei, deviceReportInfo.getImei())
.list();
if (!list.isEmpty()) {
if (list.get(0).getImei().equals(deviceReportInfo.getImei())) {
return AjaxResultPro.success(112, "IMEI号重复!", null);
}
}
//自动生成设备编码
List<UtilDeviceNumberAdd> numberAdds = new LambdaQueryChainWrapper<>(numberAddMapper).list();
System.err.println("累加列表:"+numberAdds);
if (numberAdds.isEmpty()) {
return AjaxResultPro.success(112,"未查询到设备编码排序信息!",null);
}
new LambdaUpdateChainWrapper<>(numberAddMapper).set(UtilDeviceNumberAdd::getSuffix, numberAdds.get(0).getSuffix() + 1).update();
String genDeviceNumber= numberAdds.get(0).getPrefix()+padZero(numberAdds.get(0).getSuffix()+1);
if(!list.isEmpty()){
if (list.get(0).getSerialNumber().equals(deviceReportInfo.getSerialNumber())) {
return AjaxResultPro.success(112,"设备编号重复!",null);
}
}
deviceReportInfo.setSerialNumber(genDeviceNumber);
int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo);
if(inserted==0){
return AjaxResultPro.success(113,"设备上电审核信息插入失败!",null);
}
//当开启自动审核,也就是打开自动审核页面的时候需要推送到前端
if(emitter!=null){
try {
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
} catch (IOException e) {
return AjaxResultPro.success(114,"推送上电基本信息失败!",null);
}
}
Map<String,Object> map=new HashMap<>();
map.put("regSn",deviceReportInfo.getSerialNumber());
return AjaxResultPro.success(110,"设备审核通过!",map);
}
@PostMapping("/device/init/new/remove")
public AjaxResultPro removeMsg() {
public AjaxResultPro removeMsg(){
emitters.clear();
return AjaxResultPro.success();
}
@PostMapping("/device/init/new/text")
public void sendMsgText(@RequestBody DeviceReportInfo reportInfo) throws IOException {
SseEmitter emitter = emitters.get("device-init");
DeviceReportInfo deviceReportInfo = new DeviceReportInfo();
deviceReportInfo.setImei("10086");
deviceReportInfo.setIccid("10086");
deviceReportInfo.setMcuId("wqewqewq");
deviceReportInfo.setBspType("iwqjriqw");
deviceReportInfo.setLteType("rui");
deviceReportInfo.setMcuType("mcu");
deviceReportInfo.setMcuFw("1.0.0");
deviceReportInfo.setLteFw("opodaojdao");
deviceReportInfo.setLcdManufacturer(1L);
deviceReportInfo.setVoiceManufacturer(1L);
deviceReportInfo.setFramModel("BTOOO");
deviceReportInfo.setReplaceManufacturer(1L);
deviceReportInfo.setTestRecord("test");
if(emitter!=null){
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(deviceReportInfo).build()));
}
}
/**
* 生成当前批次的设备编码
*/
@ -95,6 +179,50 @@ public class DeviceReportSSEController extends BaseController {
}
/**
* 上电审核前参数校验
*/
private void checkDeviceReportInfo(DevicePowerDTO reportInfo){
if(StringUtils.isBlank(reportInfo.getImei())){
throw new ServiceException("imei不能为空");
}
if(StringUtils.isBlank(reportInfo.getIccid())){
throw new ServiceException("iccid不能为空");
}
if(StringUtils.isBlank(reportInfo.getMcuId())){
throw new ServiceException("mcuId不能为空");
}
if(StringUtils.isBlank(reportInfo.getBspType())){
throw new ServiceException("bspType不能为空");
}
if(StringUtils.isBlank(reportInfo.getLteType())){
throw new ServiceException("lteType不能为空");
}
if(StringUtils.isBlank(reportInfo.getMcuType())){
throw new ServiceException("mcuType不能为空");
}
if(StringUtils.isBlank(reportInfo.getMcuFw())){
throw new ServiceException("mcuFw不能为空");
}
if(StringUtils.isBlank(reportInfo.getLteFw())){
throw new ServiceException("lteFw不能为空");
}
if(StringUtils.isBlank(reportInfo.getLcdType())){
throw new ServiceException("lcdType不能为空");
}
if(StringUtils.isBlank(reportInfo.getVoiceType())){
throw new ServiceException("voiceType不能为空");
}
if(StringUtils.isBlank(reportInfo.getFacType())){
throw new ServiceException("facType不能为空");
}
if(StringUtils.isBlank(reportInfo.getTestRecord())){
throw new ServiceException("testRecord不能为空");
}
}
/**
@ -117,4 +245,8 @@ public class DeviceReportSSEController extends BaseController {
deviceNumber.append(monthStr);
return deviceNumber.toString()+"00001";
}
public String padZero(Long num) {
return String.format("%05d", num);
}
}

View File

@ -1,6 +1,7 @@
package com.fastbee.data.controller.sse;
import com.fastbee.iot.domain.DeviceReportInfo;
import com.fastbee.iot.model.dto.DevicePowerDTO;
import lombok.Builder;
import lombok.Data;
@ -12,5 +13,5 @@ import lombok.Data;
public class Message {
private String content;
private Integer event;
private DeviceReportInfo data;
private DevicePowerDTO data;
}