设备审核接口

This commit is contained in:
mi9688 2024-12-19 12:28:41 +08:00
parent 6a93d26331
commit e91455eadc
16 changed files with 321 additions and 60 deletions

View File

@ -93,6 +93,9 @@ public class AjaxResultPro extends HashMap<String, Object>
return AjaxResultPro.success("操作成功", data);
}
/**
* 返回成功数据
*
@ -126,6 +129,19 @@ public class AjaxResultPro extends HashMap<String, Object>
return new AjaxResultPro(HttpStatus.SUCCESS, msg, data);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static AjaxResultPro success(int code,String msg, Object data)
{
return new AjaxResultPro(code, msg, data);
}
/**
* 返回警告消息
*

View File

@ -25,9 +25,9 @@ public class BaseEntity implements Serializable
private static final long serialVersionUID = 1L;
/** 搜索值 */
@ApiModelProperty("搜索值")
@JsonIgnore
private String searchValue;
// @ApiModelProperty("搜索值")
// @JsonIgnore
// private String searchValue;
/** 创建者 */
@ApiModelProperty("创建者")
@ -57,15 +57,15 @@ public class BaseEntity implements Serializable
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> params;
public String getSearchValue()
{
return searchValue;
}
public void setSearchValue(String searchValue)
{
this.searchValue = searchValue;
}
// public String getSearchValue()
// {
// return searchValue;
// }
//
// public void setSearchValue(String searchValue)
// {
// this.searchValue = searchValue;
// }
public String getCreateBy()
{

View File

@ -6,6 +6,7 @@ import com.fastbee.common.constant.FastBeeConstant;
import com.fastbee.common.core.mq.DeviceReportBo;
import com.fastbee.mq.redischannel.producer.IssueInstructionsProducer;
import com.fastbee.mq.service.impl.DeviceOtherMsgHandler;
import com.fastbee.mqttclient.PubMqttClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
@ -28,6 +29,10 @@ public class DeviceOtherMsgConsumer {
@Autowired
private IssueInstructionsProducer issueInstructionsProducer;
@Autowired
private PubMqttClient pubMqttClient;
@Async(FastBeeConstant.TASK.DEVICE_OTHER_TASK)
public void consume(DeviceReportBo bo){
try {
@ -58,6 +63,7 @@ public class DeviceOtherMsgConsumer {
} else if (topic.endsWith("cmd/down")) {
platformCmdHandler(new String(data));
//回应
} else if (topic.endsWith("cmd/reply")) {
deviceCmdAckHandler(new String(data));
@ -74,6 +80,8 @@ public class DeviceOtherMsgConsumer {
*/
private void deviceDataReportHandler(String data){
System.err.println("mqtt接收到设备上报数据"+ data);
//回应
//解析
// String jsonString = "{\"type\": \"waterEleData\", \"pakSn\": 123, \"data\": {\"workState\": 1, \"action\": \"startPump\", \"mcuSn\": \"MCU123456\", \"sumEle\": 5000, \"sumFlow\": 3000, \"insFlow\": 2.5, \"userSumFlow\": 1500, \"areaCode\": \"010\", \"cardId\": \"CARD12345678\", \"userBalance\": 100.0, \"userSumEle\": 3000, \"curEle\": 50, \"curFlow\": 200, \"insPower\": 2300}}";
JSONObject entries = JSONUtil.parseObj(data);
@ -119,6 +127,7 @@ public class DeviceOtherMsgConsumer {
*/
private void platformDataReportAckHandler(String data){
System.err.println("mqtt回应收到设备上报数据"+ data);
//处理
@ -128,7 +137,8 @@ public class DeviceOtherMsgConsumer {
*/
private void platformCmdHandler(String data){
System.err.println("mqtt收到平台给设备下发命令"+ data);
JSONObject obj = JSONUtil.parseObj(data);
// JSONObject obj = JSONUtil.parseObj(data);
}
/**
* 处理设备收到指令回应

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;
}

View File

@ -63,6 +63,9 @@ private static final long serialVersionUID = 1L;
private String spaceValue;
/** 搜索值 */
private String searchValue;
//------------------------------------------------拓展业务字段--------------------------------------------
/** 父菜单名称 */

View File

@ -46,5 +46,7 @@ public class GLegend extends BaseEntity
/**图例描述 */
private String description;
/** 搜索值 */
private String searchValue;
}

View File

@ -84,4 +84,7 @@ public class GSites extends BaseEntity {
/** 删除状态[0存在,2删除] */
private Long delFlag;
/** 搜索值 */
private String searchValue;
}

View File

@ -0,0 +1,54 @@
package com.fastbee.iot.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
import java.io.Serializable;
import java.util.Date;
/**
* 设备编号累加记录设备编号的排序对象 util_device_number_add
*
* @author kerwincui
* @date 2024-12-19
*/
@ApiModel(value = "UtilDeviceNumberAdd",description = "设备编号累加,记录设备编号的排序 util_device_number_add")
@Data
public class UtilDeviceNumberAdd implements Serializable {
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 设备编号前缀 */
@Excel(name = "设备编号前缀")
@ApiModelProperty("设备编号前缀")
private String prefix;
/** 后缀 */
@Excel(name = "后缀")
@ApiModelProperty("后缀")
private Long suffix;
/** 创建时间 */
@ApiModelProperty("创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新时间 */
@ApiModelProperty("更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@ -0,0 +1,11 @@
package com.fastbee.iot.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.iot.domain.UtilDeviceNumberAdd;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface UtilDeviceNumberAddMapper extends BaseMapper<UtilDeviceNumberAdd> {
// 这里可以添加自定义的方法如果需要的话
}

View File

@ -0,0 +1,20 @@
package com.fastbee.iot.model.dto;
import lombok.Data;
@Data
public class DevicePowerDTO {
private String imei;
private String iccid;
private String mcuId;
private String bspType;
private String lteType;
private String mcuType;
private String mcuFw;
private String lteFw;
private String lcdType;
private String voiceType;
private String framType;
private String facType;
private String testRecord;
}

View File

@ -158,6 +158,10 @@ public class Project extends BaseEntity
@ApiModelProperty("项目lei")
private Long type;
// @ApiModelProperty("搜索值")
// @JsonIgnore
private String searchValue;
//业务字段---------------------------------------------------------------------------
/**
* 系统账号名称

View File

@ -140,6 +140,6 @@ public class UserConsumptionDetails extends BaseEntity
/** 关于账单的额外信息或备注 */
@Excel(name = "关于账单的额外信息或备注")
@ApiModelProperty("关于账单的额外信息或备注")
private String remarks;
private String remark;
}

View File

@ -1,6 +1,8 @@
package com.fastbee.rechargecard.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.rechargecard.domain.UserConsumptionDetails;
import org.apache.ibatis.annotations.Mapper;
@ -11,7 +13,7 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2024-12-18
*/
@Mapper
public interface UserConsumptionDetailsMapper
public interface UserConsumptionDetailsMapper extends BaseMapper<UserConsumptionDetails>
{
/**
* 根据卡号查询用户充值卡账单明细记录列表

View File

@ -1,6 +1,8 @@
package com.fastbee.rechargecard.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -29,7 +31,10 @@ public class UserConsumptionDetailsServiceImpl implements IUserConsumptionDetail
@Override
public List<UserConsumptionDetails> selectUserConsumptionDetailsListById(String cardNumber)
{
return userConsumptionDetailsMapper.selectUserConsumptionDetailsListById(cardNumber);
List<UserConsumptionDetails> list = new LambdaQueryChainWrapper<>(userConsumptionDetailsMapper)
.eq(UserConsumptionDetails::getCardNumber, cardNumber)
.list();
return list;
}
/**