添加 设备是否启用 enable 字段
This commit is contained in:
parent
38ef2228e7
commit
6d280daed8
@ -8,6 +8,7 @@ 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.api.device.dto.ModifyDeviceDTO;
|
||||
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;
|
||||
@ -86,4 +87,10 @@ public class DeviceController {
|
||||
MockingDevice.setId(id);
|
||||
return JsonResponse.success(deviceService.deleteDevice(MockingDevice));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据主键 id 修改指定设备")
|
||||
@PostJson(value = "/modify/id")
|
||||
public JsonResponse<Boolean> modifyById(@RequestBody ModifyDeviceDTO dto){
|
||||
return JsonResponse.success(deviceService.modifyDevice(DeviceDTOConvertor.INSTANCE.dto2dao(dto)));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
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.api.device.dto.ModifyDeviceDTO;
|
||||
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@ -10,4 +11,6 @@ public abstract class DeviceDTOConvertor {
|
||||
public static final DeviceDTOConvertor INSTANCE = Mappers.getMapper(DeviceDTOConvertor.class);
|
||||
|
||||
abstract public MockingDevice dto2dao(AddDeviceDTO dto);
|
||||
|
||||
abstract public MockingDevice dto2dao(ModifyDeviceDTO dto);
|
||||
}
|
||||
|
@ -21,4 +21,7 @@ public class AddDeviceDTO {
|
||||
|
||||
@Schema(description = "地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private boolean enable = true;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
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 ModifyDeviceDTO {
|
||||
@NotBlank(message = "id 不能为空")
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@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;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean enable = true;
|
||||
}
|
@ -27,6 +27,9 @@ public final class MockingDeviceDynamicSqlSupport {
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
||||
public static final SqlColumn<String> address = mockingDevice.address;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.enable")
|
||||
public static final SqlColumn<Boolean> enable = mockingDevice.enable;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||
public static final class MockingDevice extends AliasableSqlTable<MockingDevice> {
|
||||
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
|
||||
@ -41,6 +44,8 @@ public final class MockingDeviceDynamicSqlSupport {
|
||||
|
||||
public final SqlColumn<String> address = column("address", JDBCType.VARCHAR);
|
||||
|
||||
public final SqlColumn<Boolean> enable = column("enable", JDBCType.BIT);
|
||||
|
||||
public MockingDevice() {
|
||||
super("mocking_device", MockingDevice::new);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
||||
@Mapper
|
||||
public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<MockingDevice>, CommonUpdateMapper {
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, deviceCode, gbDeviceId, gbChannelId, name, address);
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, deviceCode, gbDeviceId, gbChannelId, name, address, enable);
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||
@ -42,7 +42,8 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
@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="address", property="address", jdbcType=JdbcType.VARCHAR)
|
||||
@Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
|
||||
})
|
||||
List<MockingDevice> selectMany(SelectStatementProvider selectStatement);
|
||||
|
||||
@ -77,6 +78,7 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.map(gbChannelId).toProperty("gbChannelId")
|
||||
.map(name).toProperty("name")
|
||||
.map(address).toProperty("address")
|
||||
.map(enable).toProperty("enable")
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,6 +91,7 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.map(gbChannelId).toProperty("gbChannelId")
|
||||
.map(name).toProperty("name")
|
||||
.map(address).toProperty("address")
|
||||
.map(enable).toProperty("enable")
|
||||
);
|
||||
}
|
||||
|
||||
@ -101,6 +104,7 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.map(gbChannelId).toPropertyWhenPresent("gbChannelId", row::getGbChannelId)
|
||||
.map(name).toPropertyWhenPresent("name", row::getName)
|
||||
.map(address).toPropertyWhenPresent("address", row::getAddress)
|
||||
.map(enable).toPropertyWhenPresent("enable", row::getEnable)
|
||||
);
|
||||
}
|
||||
|
||||
@ -138,7 +142,8 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.set(gbDeviceId).equalTo(row::getGbDeviceId)
|
||||
.set(gbChannelId).equalTo(row::getGbChannelId)
|
||||
.set(name).equalTo(row::getName)
|
||||
.set(address).equalTo(row::getAddress);
|
||||
.set(address).equalTo(row::getAddress)
|
||||
.set(enable).equalTo(row::getEnable);
|
||||
}
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||
@ -148,7 +153,8 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.set(gbDeviceId).equalToWhenPresent(row::getGbDeviceId)
|
||||
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId)
|
||||
.set(name).equalToWhenPresent(row::getName)
|
||||
.set(address).equalToWhenPresent(row::getAddress);
|
||||
.set(address).equalToWhenPresent(row::getAddress)
|
||||
.set(enable).equalToWhenPresent(row::getEnable);
|
||||
}
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: mocking_device")
|
||||
@ -159,6 +165,7 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.set(gbChannelId).equalTo(row::getGbChannelId)
|
||||
.set(name).equalTo(row::getName)
|
||||
.set(address).equalTo(row::getAddress)
|
||||
.set(enable).equalTo(row::getEnable)
|
||||
.where(id, isEqualTo(row::getId))
|
||||
);
|
||||
}
|
||||
@ -171,6 +178,7 @@ public interface MockingDeviceMapper extends CommonCountMapper, CommonDeleteMapp
|
||||
.set(gbChannelId).equalToWhenPresent(row::getGbChannelId)
|
||||
.set(name).equalToWhenPresent(row::getName)
|
||||
.set(address).equalToWhenPresent(row::getAddress)
|
||||
.set(enable).equalToWhenPresent(row::getEnable)
|
||||
.where(id, isEqualTo(row::getId))
|
||||
);
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ public class MockingDevice {
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.address")
|
||||
private String address;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.enable")
|
||||
private Boolean enable;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.id")
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -85,4 +88,14 @@ public class MockingDevice {
|
||||
public void setAddress(String address) {
|
||||
this.address = address == null ? null : address.trim();
|
||||
}
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.enable")
|
||||
public Boolean getEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: mocking_device.enable")
|
||||
public void setEnable(Boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
}
|
@ -5,15 +5,16 @@
|
||||
<mapper namespace="cn.skcks.docking.gb28181.mocking.orm.mybatis.operation.MockingOperateTableMapper">
|
||||
<update id="createDeviceTable">
|
||||
CREATE TABLE IF NOT EXISTS `mocking_device` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`device_code` varchar(50) NOT NULL,
|
||||
`gb_device_id` varchar(50) NOT NULL,
|
||||
`gb_channel_id` varchar(50) NOT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`address` varchar(255) DEFAULT NULL,
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`device_code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`gb_device_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`gb_channel_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`enable` tinyint(1) DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `device_code` (`device_code`),
|
||||
UNIQUE KEY `gb_device_id` (`gb_device_id`,`gb_channel_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
</update>
|
||||
</mapper>
|
||||
|
@ -106,6 +106,19 @@ public class DeviceService {
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public boolean modifyDevice(MockingDevice device){
|
||||
if(device == null){
|
||||
return false;
|
||||
}
|
||||
Long id = device.getId();
|
||||
if(id == null){
|
||||
throw new JsonException("id 不能为空");
|
||||
}
|
||||
|
||||
return deviceMapper.updateByPrimaryKey(device) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询设备
|
||||
* @param page 页数
|
||||
|
Loading…
Reference in New Issue
Block a user