设备管理接口
This commit is contained in:
parent
4ac448c83a
commit
38ef2228e7
@ -0,0 +1,25 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.advice;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常处理类
|
||||||
|
*
|
||||||
|
* @author Shikong
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class BasicExceptionAdvice {
|
||||||
|
@ExceptionHandler(IOException.class)
|
||||||
|
public void exception(HttpServletRequest request, Exception e) {
|
||||||
|
if(request.getRequestURI().equals("/video")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cn.skcks.docking.gb28181.mocking.advice;
|
package cn.skcks.docking.gb28181.mocking.advice;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.common.json.JsonException;
|
||||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||||
import jakarta.validation.ConstraintViolationException;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -72,6 +73,11 @@ public class ExceptionAdvice {
|
|||||||
return JsonResponse.error("参数异常");
|
return JsonResponse.error("参数异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(JsonException.class)
|
||||||
|
public JsonResponse<String> handleJsonException(JsonException e){
|
||||||
|
return JsonResponse.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public JsonResponse<String> exception(Exception e) {
|
public JsonResponse<String> exception(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.api.device;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.annotation.web.JsonMapping;
|
||||||
|
import cn.skcks.docking.gb28181.annotation.web.methods.GetJson;
|
||||||
|
import cn.skcks.docking.gb28181.annotation.web.methods.PostJson;
|
||||||
|
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||||
|
import cn.skcks.docking.gb28181.common.page.PageWrapper;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.api.device.convertor.DeviceDTOConvertor;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.api.device.dto.AddDeviceDTO;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.api.device.dto.DevicePageDTO;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.config.SwaggerConfig;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.service.device.DeviceService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Tag(name = "设备信息")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/device")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DeviceController {
|
||||||
|
private final DeviceService deviceService;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi deviceApi() {
|
||||||
|
return SwaggerConfig.api("DeviceApi", "/device");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询设备列表")
|
||||||
|
@GetJson("/page")
|
||||||
|
public JsonResponse<PageWrapper<MockingDevice>> getDevicesWithPagePage(@ParameterObject @Validated DevicePageDTO dto) {
|
||||||
|
return JsonResponse.success(PageWrapper.of(deviceService.getDevicesWithPage(dto.getPage(), dto.getSize())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加设备")
|
||||||
|
@PostJson("/add")
|
||||||
|
public JsonResponse<Boolean> addDevice(@RequestBody AddDeviceDTO dto) {
|
||||||
|
return JsonResponse.success(deviceService.addDevice(DeviceDTOConvertor.INSTANCE.dto2dao(dto)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据设备编码(21位) 查询指定设备信息")
|
||||||
|
@GetJson("/info/deviceCode")
|
||||||
|
public JsonResponse<MockingDevice> infoByDeviceCode(@RequestParam String deviceCode) {
|
||||||
|
MockingDevice MockingDevice = deviceService.getDeviceByDeviceCode(deviceCode).orElse(null);
|
||||||
|
return JsonResponse.success(MockingDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据国标id(20位) 查询指定设备信息")
|
||||||
|
@GetJson("/info/gbDeviceId")
|
||||||
|
public JsonResponse<List<MockingDevice>> infoByGbDeviceId(@RequestParam String gbDeviceId) {
|
||||||
|
List<MockingDevice> MockingDevice = deviceService.getDeviceByGbDeviceId(gbDeviceId);
|
||||||
|
return JsonResponse.success(MockingDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据设备编码(21位) 删除指定设备")
|
||||||
|
@JsonMapping(value = "/delete/deviceCode", method = {RequestMethod.GET,RequestMethod.DELETE})
|
||||||
|
public JsonResponse<Boolean> deleteByDeviceCode(@RequestParam String deviceCode){
|
||||||
|
MockingDevice MockingDevice = new MockingDevice();
|
||||||
|
MockingDevice.setDeviceCode(deviceCode);
|
||||||
|
return JsonResponse.success(deviceService.deleteDevice(MockingDevice));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据国标id(20位) 删除指定设备")
|
||||||
|
@JsonMapping(value = "/delete/gbDeviceId",method = {RequestMethod.GET,RequestMethod.DELETE})
|
||||||
|
public JsonResponse<Boolean> deleteByGbDeviceId(@RequestParam String gbDeviceId){
|
||||||
|
MockingDevice MockingDevice = new MockingDevice();
|
||||||
|
MockingDevice.setGbDeviceId(gbDeviceId);
|
||||||
|
return JsonResponse.success(deviceService.deleteDevice(MockingDevice));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据主键 id 删除指定设备")
|
||||||
|
@JsonMapping(value = "/delete/id",method = {RequestMethod.GET,RequestMethod.DELETE})
|
||||||
|
public JsonResponse<Boolean> deleteByGbDeviceId(@RequestParam Long id){
|
||||||
|
MockingDevice MockingDevice = new MockingDevice();
|
||||||
|
MockingDevice.setId(id);
|
||||||
|
return JsonResponse.success(deviceService.deleteDevice(MockingDevice));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.api.device.convertor;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.mocking.api.device.dto.AddDeviceDTO;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public abstract class DeviceDTOConvertor {
|
||||||
|
public static final DeviceDTOConvertor INSTANCE = Mappers.getMapper(DeviceDTOConvertor.class);
|
||||||
|
|
||||||
|
abstract public MockingDevice dto2dao(AddDeviceDTO dto);
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.api.device.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AddDeviceDTO {
|
||||||
|
@NotBlank(message = "设备编码 不能为空")
|
||||||
|
@Schema(description = "设备编码")
|
||||||
|
private String deviceCode;
|
||||||
|
@NotBlank(message = "国标编码 不能为空")
|
||||||
|
@Schema(description = "国标编码")
|
||||||
|
private String gbDeviceId;
|
||||||
|
@NotBlank(message = "国标通道id 不能为空")
|
||||||
|
@Schema(description = "国标通道id")
|
||||||
|
private String gbChannelId;
|
||||||
|
@NotBlank(message = "设备名称 不能为空")
|
||||||
|
@Schema(description = "设备名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "地址")
|
||||||
|
private String address;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.api.device.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DevicePageDTO {
|
||||||
|
@Schema(description = "页数", example = "1")
|
||||||
|
@NotNull(message = "page 不能为空")
|
||||||
|
@Min(value = 1, message = "page 必须为正整数")
|
||||||
|
int page;
|
||||||
|
|
||||||
|
@Schema(description = "每页条数", example = "10")
|
||||||
|
@NotNull(message = "size 不能为空")
|
||||||
|
@Min(value = 1, message = "size 必须为正整数")
|
||||||
|
int size;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.common.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public class PageDTO {
|
||||||
|
@Schema(description = "页数", example = "10")
|
||||||
|
@NotNull(message = "page 不能为空")
|
||||||
|
@Min(value = 1, message = "page 必须为正整数")
|
||||||
|
int page;
|
||||||
|
|
||||||
|
@Schema(description = "每页条数", example = "10")
|
||||||
|
@NotNull(message = "size 不能为空")
|
||||||
|
@Min(value = 1, message = "size 必须为正整数")
|
||||||
|
int size;
|
||||||
|
}
|
@ -15,32 +15,32 @@ public final class MockingDeviceDynamicSqlSupport {
|
|||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.device_code")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.device_code")
|
||||||
public static final SqlColumn<String> deviceCode = mockingDevice.deviceCode;
|
public static final SqlColumn<String> deviceCode = mockingDevice.deviceCode;
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
||||||
|
public static final SqlColumn<String> gbDeviceId = mockingDevice.gbDeviceId;
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
||||||
|
public static final SqlColumn<String> gbChannelId = mockingDevice.gbChannelId;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
||||||
public static final SqlColumn<String> name = mockingDevice.name;
|
public static final SqlColumn<String> name = mockingDevice.name;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
||||||
public static final SqlColumn<String> address = mockingDevice.address;
|
public static final SqlColumn<String> address = mockingDevice.address;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
|
||||||
public static final SqlColumn<byte[]> gbDeviceId = mockingDevice.gbDeviceId;
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
|
||||||
public static final SqlColumn<byte[]> gbChannelId = mockingDevice.gbChannelId;
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||||
public static final class MockingDevice extends AliasableSqlTable<MockingDevice> {
|
public static final class MockingDevice extends AliasableSqlTable<MockingDevice> {
|
||||||
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
|
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
|
||||||
|
|
||||||
public final SqlColumn<String> deviceCode = column("device_code", JDBCType.VARCHAR);
|
public final SqlColumn<String> deviceCode = column("device_code", JDBCType.VARCHAR);
|
||||||
|
|
||||||
|
public final SqlColumn<String> gbDeviceId = column("gb_device_id", JDBCType.VARCHAR);
|
||||||
|
|
||||||
|
public final SqlColumn<String> gbChannelId = column("gb_channel_id", JDBCType.VARCHAR);
|
||||||
|
|
||||||
public final SqlColumn<String> name = column("name", JDBCType.VARCHAR);
|
public final SqlColumn<String> name = column("name", JDBCType.VARCHAR);
|
||||||
|
|
||||||
public final SqlColumn<String> address = column("address", JDBCType.VARCHAR);
|
public final SqlColumn<String> address = column("address", JDBCType.VARCHAR);
|
||||||
|
|
||||||
public final SqlColumn<byte[]> gbDeviceId = column("gb_device_id", JDBCType.VARBINARY);
|
|
||||||
|
|
||||||
public final SqlColumn<byte[]> gbChannelId = column("gb_channel_id", JDBCType.VARBINARY);
|
|
||||||
|
|
||||||
public MockingDevice() {
|
public MockingDevice() {
|
||||||
super("mocking_device", MockingDevice::new);
|
super("mocking_device", MockingDevice::new);
|
||||||
}
|
}
|
||||||
|
@ -32,17 +32,17 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<MockingDevice>, CommonUpdateMapper {
|
public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<MockingDevice>, CommonUpdateMapper {
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||||
BasicColumn[] selectList = BasicColumn.columnList(id, deviceCode, name, address, gbDeviceId, gbChannelId);
|
BasicColumn[] selectList = BasicColumn.columnList(id, deviceCode, gbDeviceId, gbChannelId, name, address);
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||||
@Results(id="MockingDeviceResult", value = {
|
@Results(id="MockingDeviceResult", value = {
|
||||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
||||||
@Result(column="device_code", property="deviceCode", jdbcType=JdbcType.VARCHAR),
|
@Result(column="device_code", property="deviceCode", jdbcType=JdbcType.VARCHAR),
|
||||||
|
@Result(column="gb_device_id", property="gbDeviceId", jdbcType=JdbcType.VARCHAR),
|
||||||
|
@Result(column="gb_channel_id", property="gbChannelId", jdbcType=JdbcType.VARCHAR),
|
||||||
@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
|
@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
|
||||||
@Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
|
@Result(column="address", property="address", jdbcType=JdbcType.VARCHAR)
|
||||||
@Result(column="gb_device_id", property="gbDeviceId", jdbcType=JdbcType.VARBINARY),
|
|
||||||
@Result(column="gb_channel_id", property="gbChannelId", jdbcType=JdbcType.VARBINARY)
|
|
||||||
})
|
})
|
||||||
List<MockingDevice> selectMany(SelectStatementProvider selectStatement);
|
List<MockingDevice> selectMany(SelectStatementProvider selectStatement);
|
||||||
|
|
||||||
@ -73,10 +73,10 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
|||||||
return MyBatis3Utils.insert(this::insert, row, mockingDevice, c ->
|
return MyBatis3Utils.insert(this::insert, row, mockingDevice, c ->
|
||||||
c.map(id).toProperty("id")
|
c.map(id).toProperty("id")
|
||||||
.map(deviceCode).toProperty("deviceCode")
|
.map(deviceCode).toProperty("deviceCode")
|
||||||
.map(name).toProperty("name")
|
|
||||||
.map(address).toProperty("address")
|
|
||||||
.map(gbDeviceId).toProperty("gbDeviceId")
|
.map(gbDeviceId).toProperty("gbDeviceId")
|
||||||
.map(gbChannelId).toProperty("gbChannelId")
|
.map(gbChannelId).toProperty("gbChannelId")
|
||||||
|
.map(name).toProperty("name")
|
||||||
|
.map(address).toProperty("address")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +85,10 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
|||||||
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, mockingDevice, c ->
|
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, mockingDevice, c ->
|
||||||
c.map(id).toProperty("id")
|
c.map(id).toProperty("id")
|
||||||
.map(deviceCode).toProperty("deviceCode")
|
.map(deviceCode).toProperty("deviceCode")
|
||||||
.map(name).toProperty("name")
|
|
||||||
.map(address).toProperty("address")
|
|
||||||
.map(gbDeviceId).toProperty("gbDeviceId")
|
.map(gbDeviceId).toProperty("gbDeviceId")
|
||||||
.map(gbChannelId).toProperty("gbChannelId")
|
.map(gbChannelId).toProperty("gbChannelId")
|
||||||
|
.map(name).toProperty("name")
|
||||||
|
.map(address).toProperty("address")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +97,10 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
|||||||
return MyBatis3Utils.insert(this::insert, row, mockingDevice, c ->
|
return MyBatis3Utils.insert(this::insert, row, mockingDevice, c ->
|
||||||
c.map(id).toPropertyWhenPresent("id", row::getId)
|
c.map(id).toPropertyWhenPresent("id", row::getId)
|
||||||
.map(deviceCode).toPropertyWhenPresent("deviceCode", row::getDeviceCode)
|
.map(deviceCode).toPropertyWhenPresent("deviceCode", row::getDeviceCode)
|
||||||
.map(name).toPropertyWhenPresent("name", row::getName)
|
|
||||||
.map(address).toPropertyWhenPresent("address", row::getAddress)
|
|
||||||
.map(gbDeviceId).toPropertyWhenPresent("gbDeviceId", row::getGbDeviceId)
|
.map(gbDeviceId).toPropertyWhenPresent("gbDeviceId", row::getGbDeviceId)
|
||||||
.map(gbChannelId).toPropertyWhenPresent("gbChannelId", row::getGbChannelId)
|
.map(gbChannelId).toPropertyWhenPresent("gbChannelId", row::getGbChannelId)
|
||||||
|
.map(name).toPropertyWhenPresent("name", row::getName)
|
||||||
|
.map(address).toPropertyWhenPresent("address", row::getAddress)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,30 +135,30 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
|||||||
static UpdateDSL<UpdateModel> updateAllColumns(MockingDevice row, UpdateDSL<UpdateModel> dsl) {
|
static UpdateDSL<UpdateModel> updateAllColumns(MockingDevice row, UpdateDSL<UpdateModel> dsl) {
|
||||||
return dsl.set(id).equalTo(row::getId)
|
return dsl.set(id).equalTo(row::getId)
|
||||||
.set(deviceCode).equalTo(row::getDeviceCode)
|
.set(deviceCode).equalTo(row::getDeviceCode)
|
||||||
.set(name).equalTo(row::getName)
|
|
||||||
.set(address).equalTo(row::getAddress)
|
|
||||||
.set(gbDeviceId).equalTo(row::getGbDeviceId)
|
.set(gbDeviceId).equalTo(row::getGbDeviceId)
|
||||||
.set(gbChannelId).equalTo(row::getGbChannelId);
|
.set(gbChannelId).equalTo(row::getGbChannelId)
|
||||||
|
.set(name).equalTo(row::getName)
|
||||||
|
.set(address).equalTo(row::getAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||||
static UpdateDSL<UpdateModel> updateSelectiveColumns(MockingDevice row, UpdateDSL<UpdateModel> dsl) {
|
static UpdateDSL<UpdateModel> updateSelectiveColumns(MockingDevice row, UpdateDSL<UpdateModel> dsl) {
|
||||||
return dsl.set(id).equalToWhenPresent(row::getId)
|
return dsl.set(id).equalToWhenPresent(row::getId)
|
||||||
.set(deviceCode).equalToWhenPresent(row::getDeviceCode)
|
.set(deviceCode).equalToWhenPresent(row::getDeviceCode)
|
||||||
.set(name).equalToWhenPresent(row::getName)
|
|
||||||
.set(address).equalToWhenPresent(row::getAddress)
|
|
||||||
.set(gbDeviceId).equalToWhenPresent(row::getGbDeviceId)
|
.set(gbDeviceId).equalToWhenPresent(row::getGbDeviceId)
|
||||||
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId);
|
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId)
|
||||||
|
.set(name).equalToWhenPresent(row::getName)
|
||||||
|
.set(address).equalToWhenPresent(row::getAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||||
default int updateByPrimaryKey(MockingDevice row) {
|
default int updateByPrimaryKey(MockingDevice row) {
|
||||||
return update(c ->
|
return update(c ->
|
||||||
c.set(deviceCode).equalTo(row::getDeviceCode)
|
c.set(deviceCode).equalTo(row::getDeviceCode)
|
||||||
.set(name).equalTo(row::getName)
|
|
||||||
.set(address).equalTo(row::getAddress)
|
|
||||||
.set(gbDeviceId).equalTo(row::getGbDeviceId)
|
.set(gbDeviceId).equalTo(row::getGbDeviceId)
|
||||||
.set(gbChannelId).equalTo(row::getGbChannelId)
|
.set(gbChannelId).equalTo(row::getGbChannelId)
|
||||||
|
.set(name).equalTo(row::getName)
|
||||||
|
.set(address).equalTo(row::getAddress)
|
||||||
.where(id, isEqualTo(row::getId))
|
.where(id, isEqualTo(row::getId))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -167,10 +167,10 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
|||||||
default int updateByPrimaryKeySelective(MockingDevice row) {
|
default int updateByPrimaryKeySelective(MockingDevice row) {
|
||||||
return update(c ->
|
return update(c ->
|
||||||
c.set(deviceCode).equalToWhenPresent(row::getDeviceCode)
|
c.set(deviceCode).equalToWhenPresent(row::getDeviceCode)
|
||||||
.set(name).equalToWhenPresent(row::getName)
|
|
||||||
.set(address).equalToWhenPresent(row::getAddress)
|
|
||||||
.set(gbDeviceId).equalToWhenPresent(row::getGbDeviceId)
|
.set(gbDeviceId).equalToWhenPresent(row::getGbDeviceId)
|
||||||
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId)
|
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId)
|
||||||
|
.set(name).equalToWhenPresent(row::getName)
|
||||||
|
.set(address).equalToWhenPresent(row::getAddress)
|
||||||
.where(id, isEqualTo(row::getId))
|
.where(id, isEqualTo(row::getId))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,18 @@ public class MockingDevice {
|
|||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.device_code")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.device_code")
|
||||||
private String deviceCode;
|
private String deviceCode;
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
||||||
|
private String gbDeviceId;
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
||||||
|
private String gbChannelId;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
|
||||||
private byte[] gbDeviceId;
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
|
||||||
private byte[] gbChannelId;
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.id")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.id")
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -46,6 +46,26 @@ public class MockingDevice {
|
|||||||
this.deviceCode = deviceCode == null ? null : deviceCode.trim();
|
this.deviceCode = deviceCode == null ? null : deviceCode.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
||||||
|
public String getGbDeviceId() {
|
||||||
|
return gbDeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
||||||
|
public void setGbDeviceId(String gbDeviceId) {
|
||||||
|
this.gbDeviceId = gbDeviceId == null ? null : gbDeviceId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
||||||
|
public String getGbChannelId() {
|
||||||
|
return gbChannelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
||||||
|
public void setGbChannelId(String gbChannelId) {
|
||||||
|
this.gbChannelId = gbChannelId == null ? null : gbChannelId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.name")
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -65,24 +85,4 @@ public class MockingDevice {
|
|||||||
public void setAddress(String address) {
|
public void setAddress(String address) {
|
||||||
this.address = address == null ? null : address.trim();
|
this.address = address == null ? null : address.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
|
||||||
public byte[] getGbDeviceId() {
|
|
||||||
return gbDeviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_device_id")
|
|
||||||
public void setGbDeviceId(byte[] gbDeviceId) {
|
|
||||||
this.gbDeviceId = gbDeviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
|
||||||
public byte[] getGbChannelId() {
|
|
||||||
return gbChannelId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.gb_channel_id")
|
|
||||||
public void setGbChannelId(byte[] gbChannelId) {
|
|
||||||
this.gbChannelId = gbChannelId;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `mocking_device` (
|
CREATE TABLE IF NOT EXISTS `mocking_device` (
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
`device_code` varchar(50) NOT NULL,
|
`device_code` varchar(50) NOT NULL,
|
||||||
`gb_device_id` varbinary(50) NOT NULL,
|
`gb_device_id` varchar(50) NOT NULL,
|
||||||
`gb_channel_id` varbinary(50) NOT NULL,
|
`gb_channel_id` varchar(50) NOT NULL,
|
||||||
`name` varchar(255) DEFAULT NULL,
|
`name` varchar(255) DEFAULT NULL,
|
||||||
`address` varchar(255) DEFAULT NULL,
|
`address` varchar(255) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package cn.skcks.docking.gb28181.mocking.service;
|
|
||||||
|
|
||||||
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.mapper.MockingDeviceMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Service
|
|
||||||
public class DeviceService {
|
|
||||||
private final MockingDeviceMapper deviceMapper;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,134 @@
|
|||||||
|
package cn.skcks.docking.gb28181.mocking.service.device;
|
||||||
|
|
||||||
|
import cn.skcks.docking.gb28181.common.json.JsonException;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.mapper.MockingDeviceDynamicSqlSupport;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.mapper.MockingDeviceMapper;
|
||||||
|
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
|
||||||
|
import com.github.pagehelper.ISelect;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class DeviceService {
|
||||||
|
private final MockingDeviceMapper deviceMapper;
|
||||||
|
|
||||||
|
public Optional<MockingDevice> getDeviceById(Long id){
|
||||||
|
return deviceMapper.selectOne(s->
|
||||||
|
s.where(MockingDeviceDynamicSqlSupport.id, isEqualTo(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<MockingDevice> getDeviceByDeviceCode(String deviceCode){
|
||||||
|
return deviceMapper.selectOne(s->
|
||||||
|
s.where(MockingDeviceDynamicSqlSupport.deviceCode, isEqualTo(deviceCode)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MockingDevice> getDeviceByGbDeviceId(String gbDeviceId){
|
||||||
|
return deviceMapper.select(s->
|
||||||
|
s.where(MockingDeviceDynamicSqlSupport.gbDeviceId,isEqualTo(gbDeviceId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<MockingDevice> getDeviceByGbDeviceIdAndChannel(String gbDeviceId,String channel){
|
||||||
|
return deviceMapper.selectOne(s->
|
||||||
|
s.where(MockingDeviceDynamicSqlSupport.gbDeviceId,isEqualTo(gbDeviceId))
|
||||||
|
.and(MockingDeviceDynamicSqlSupport.gbChannelId,isEqualTo(channel)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加设备
|
||||||
|
* @param device 设备
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
public boolean addDevice(MockingDevice device) {
|
||||||
|
if(device == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String deviceCode = device.getDeviceCode();
|
||||||
|
if(StringUtils.isBlank(deviceCode)){
|
||||||
|
throw new JsonException("设备编码不能为空");
|
||||||
|
}
|
||||||
|
if(getDeviceByDeviceCode(deviceCode).isPresent()){
|
||||||
|
throw new JsonException(MessageFormat.format("设备编码 {0} 已存在" ,deviceCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
String gbDeviceId = device.getGbDeviceId();
|
||||||
|
String channel = device.getGbChannelId();
|
||||||
|
if(StringUtils.isBlank(gbDeviceId)){
|
||||||
|
throw new JsonException("国标编码不能为空");
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(channel)){
|
||||||
|
throw new JsonException("国标通道不能为空");
|
||||||
|
}
|
||||||
|
if(getDeviceByGbDeviceIdAndChannel(gbDeviceId,channel).isPresent()){
|
||||||
|
throw new JsonException(MessageFormat.format("国标编码 {0}, 通道 {1} 已存在" ,gbDeviceId, channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
return deviceMapper.insert(device) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依据 id 或 deviceCode 或 gbDeviceId 删除设备信息
|
||||||
|
* @param device 设备
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
public boolean deleteDevice(MockingDevice device){
|
||||||
|
if(device == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Long id = device.getId();
|
||||||
|
String deviceCode = device.getDeviceCode();
|
||||||
|
String gbDeviceId = device.getGbDeviceId();
|
||||||
|
if(id != null){
|
||||||
|
return deviceMapper.deleteByPrimaryKey(id) > 0;
|
||||||
|
} else if(StringUtils.isNotBlank(deviceCode)){
|
||||||
|
return deviceMapper.delete(d->d.where(MockingDeviceDynamicSqlSupport.deviceCode,isEqualTo(deviceCode))) > 0;
|
||||||
|
} else if(StringUtils.isNotBlank(gbDeviceId)){
|
||||||
|
return deviceMapper.delete(d->d.where(MockingDeviceDynamicSqlSupport.gbDeviceId,isEqualTo(gbDeviceId))) > 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询设备
|
||||||
|
* @param page 页数
|
||||||
|
* @param size 数量
|
||||||
|
* @return 分页设备
|
||||||
|
*/
|
||||||
|
public PageInfo<MockingDevice> getDevicesWithPage(int page, int size){
|
||||||
|
ISelect select = () -> deviceMapper.select(u -> u.orderBy(MockingDeviceDynamicSqlSupport.id.descending()));
|
||||||
|
return getDevicesWithPage(page,size, select);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询设备
|
||||||
|
* @param page 页数
|
||||||
|
* @param size 数量
|
||||||
|
* @param select 查询语句
|
||||||
|
* @return 分页设备
|
||||||
|
*/
|
||||||
|
public PageInfo<MockingDevice> getDevicesWithPage(int page, int size, ISelect select){
|
||||||
|
PageInfo<MockingDevice> pageInfo;
|
||||||
|
try (Page<MockingDevice> startPage = PageHelper.startPage(page, size)) {
|
||||||
|
pageInfo = startPage.doSelectPageInfo(select);
|
||||||
|
}
|
||||||
|
return pageInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -33,6 +33,7 @@ gb28181:
|
|||||||
# 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。
|
# 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。
|
||||||
ip:
|
ip:
|
||||||
# - 10.27.0.1
|
# - 10.27.0.1
|
||||||
|
- 192.168.0.195
|
||||||
- 192.168.10.195
|
- 192.168.10.195
|
||||||
# - 10.10.10.20
|
# - 10.10.10.20
|
||||||
# - 10.27.0.6
|
# - 10.27.0.6
|
||||||
|
Loading…
Reference in New Issue
Block a user