添加设备查询和设备更新接口
This commit is contained in:
@@ -8,6 +8,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@Schema(description = "jt808设备")
|
||||
public class JTDevice {
|
||||
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* 省域ID
|
||||
*/
|
||||
@@ -69,6 +71,14 @@ public class JTDevice {
|
||||
private Double latitude;
|
||||
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private String createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private String updateTime;
|
||||
|
||||
@Schema(description = "状态")
|
||||
private boolean status;
|
||||
|
||||
public int getProvinceId() {
|
||||
return provinceId;
|
||||
@@ -149,4 +159,36 @@ public class JTDevice {
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.genersoft.iot.vmp.jt1078.config;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.*;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* curl http://localhost:18080/api/jt1078/start/live/18864197066/1
|
||||
@@ -26,6 +32,9 @@ public class JT1078Controller {
|
||||
@Resource
|
||||
JT1078Template jt1078Template;
|
||||
|
||||
@Resource
|
||||
Ijt1078Service service;
|
||||
|
||||
/**
|
||||
* jt1078Template 调用示例
|
||||
*/
|
||||
@@ -47,5 +56,26 @@ public class JT1078Controller {
|
||||
return wvpResult;
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询部标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||
@Parameter(name = "query", description = "查询内容")
|
||||
@Parameter(name = "online", description = "是否在线")
|
||||
@GetMapping("/device/list")
|
||||
public PageInfo<JTDevice> getDevices(int page, int count,
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) Boolean online) {
|
||||
return service.getDeviceList(page, count, query, online);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新设备信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "device", description = "设备", required = true)
|
||||
@PostMapping("/device/update")
|
||||
public void updateDevice(JTDevice device){
|
||||
assert device.getId() > 0;
|
||||
assert device.getDeviceId() != null;
|
||||
service.updateDevice(device);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.jt1078.dao;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface JTDeviceMapper {
|
||||
|
||||
@@ -25,4 +27,23 @@ public interface JTDeviceMapper {
|
||||
"WHERE device_id=#{deviceId}"+
|
||||
" </script>"})
|
||||
void updateDevice(JTDevice device);
|
||||
@Select(value = {" <script>" +
|
||||
"SELECT * " +
|
||||
"from " +
|
||||
"wvp_jt_device jd " +
|
||||
"WHERE " +
|
||||
"1=1" +
|
||||
" <if test='query != null'> AND (" +
|
||||
"jd.province_id LIKE concat('%',#{query},'%') " +
|
||||
"OR jd.city_id LIKE concat('%',#{query},'%') " +
|
||||
"OR jd.maker_id LIKE concat('%',#{query},'%') " +
|
||||
"OR jd.device_model LIKE concat('%',#{query},'%') " +
|
||||
"OR jd.device_id LIKE concat('%',#{query},'%') " +
|
||||
"OR jd.plate_no LIKE concat('%',#{query},'%')" +
|
||||
")</if> " +
|
||||
" <if test='online == true' > AND jd.status= true</if>" +
|
||||
" <if test='online == false' > AND jd.status= false</if>" +
|
||||
"ORDER BY jd.update_time " +
|
||||
" </script>"})
|
||||
List<JTDevice> getDeviceList(@Param("query") String query, @Param("online") Boolean online);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.codec.netty.Jt808Handler;
|
||||
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.J8100;
|
||||
@@ -9,6 +10,8 @@ import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import com.genersoft.iot.vmp.jt1078.session.Session;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -24,6 +27,7 @@ import java.util.UUID;
|
||||
@MsgId(id = "0100")
|
||||
public class J0100 extends Re {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(J0100.class);
|
||||
private JTDevice device;
|
||||
|
||||
@Override
|
||||
@@ -92,10 +96,16 @@ public class J0100 extends Re {
|
||||
String authenticationCode = UUID.randomUUID().toString();
|
||||
j8100.setCode(authenticationCode);
|
||||
deviceInDb.setAuthenticationCode(authenticationCode);
|
||||
deviceInDb.setStatus(true);
|
||||
service.updateDevice(deviceInDb);
|
||||
log.info("[注册成功] 设备: {}", device.getDeviceId());
|
||||
}else {
|
||||
log.info("[注册失败] 未授权设备: {}", device.getDeviceId());
|
||||
j8100.setResult(J8100.FAIL);
|
||||
// TODO 断开连接,清理资源
|
||||
// 断开连接,清理资源
|
||||
if (session.isRegistered()) {
|
||||
session.unregister();
|
||||
}
|
||||
}
|
||||
return j8100;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.genersoft.iot.vmp.jt1078.service;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Ijt1078Service {
|
||||
JTDevice getDevice(String devId);
|
||||
|
||||
void updateDevice(JTDevice deviceInDb);
|
||||
|
||||
PageInfo<JTDevice> getDeviceList(int page, int count, String query, Boolean online);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,14 @@ package com.genersoft.iot.vmp.jt1078.service.impl;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.dao.JTDeviceMapper;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
|
||||
@@ -20,6 +25,14 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
|
||||
@Override
|
||||
public void updateDevice(JTDevice device) {
|
||||
device.setUpdateTime(DateUtil.getNow());
|
||||
jtDeviceMapper.updateDevice(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<JTDevice> getDeviceList(int page, int count, String query, Boolean online) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<JTDevice> all = jtDeviceMapper.getDeviceList(query, online);
|
||||
return new PageInfo<>(all);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +111,9 @@ public class Session {
|
||||
",ip=" + channel.remoteAddress() +
|
||||
']';
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
channel.close();
|
||||
SessionManager.INSTANCE.remove(this.devId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +124,7 @@ public enum SessionManager {
|
||||
return String.join("_", devId.replaceFirst("^0*", ""), respId, requestNo.toString());
|
||||
}
|
||||
|
||||
public void remove(String devId) {
|
||||
sessionMap.remove(devId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user