REM:
1. 设备管理Mapper开发
This commit is contained in:
HuangXin 2020-07-29 19:33:42 +08:00
parent fe0c0faf3e
commit e6420a641b
11 changed files with 393 additions and 149 deletions

View File

@ -0,0 +1,48 @@
package com.dispose.common;
/**
* The enum Dispose device type.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum DisposeDeviceType {
/**
* Dptech umc dispose device type.
*/
DPTECH_UMC(0, "迪普UMC管理平台"),
/**
* Haohan platform dispose device type.
*/
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
/**
* Virtual dispose dispose device type.
*/
VIRTUAL_DISPOSE(999, "虚拟处置设备");
private final int code;
private final String readme;
DisposeDeviceType(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets code.
*
* @return the code
*/
public int getCode() {
return this.code;
}
/**
* Gets readme.
*
* @return the readme
*/
public String getReadme() {
return this.readme;
}
}

View File

@ -1,12 +1,11 @@
package com.dispose.common;
/**
* The enum Dispose object type.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum DisposeObjectType implements BaseEnum {
public enum DisposeObjectType {
/**
* The Ip.
*/
@ -24,11 +23,11 @@ public enum DisposeObjectType implements BaseEnum {
/**
* The Code.
*/
private Integer value;
private final int code;
/**
* The Readme.
*/
private String description;
private final String readme;
/**
* Instantiates a new Dispose object type.
@ -37,8 +36,8 @@ public enum DisposeObjectType implements BaseEnum {
* @param readme the readme
*/
DisposeObjectType(int code, String readme) {
this.value = code;
this.description = readme;
this.code = code;
this.readme = readme;
}
/**
@ -46,9 +45,8 @@ public enum DisposeObjectType implements BaseEnum {
*
* @return the code
*/
@Override
public Integer getValue() {
return this.value;
public int getCode() {
return this.code;
}
/**
@ -56,8 +54,7 @@ public enum DisposeObjectType implements BaseEnum {
*
* @return the readme
*/
@Override
public String getDescription() {
return this.description;
public String getReadme() {
return this.readme;
}
}

View File

@ -0,0 +1,56 @@
package com.dispose.common;
/**
* The enum Http type.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum HttpType {
/**
* Http http type.
*/
HTTP(0, "HTTP 接口"),
/**
* The Https.
*/
HTTPS(1, "HTTPS 接口");
/**
* The Code.
*/
private final int code;
/**
* The Readme.
*/
private final String readme;
/**
* Instantiates a new Http type.
*
* @param code the code
* @param readme the readme
*/
HttpType(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets code.
*
* @return the code
*/
public int getCode() {
return this.code;
}
/**
* Gets readme.
*
* @return the readme
*/
public String getReadme() {
return this.readme;
}
}

View File

@ -1,6 +1,7 @@
package com.dispose.mapper;
import com.dispose.pojo.entity.DisposeDevice;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
@ -20,4 +21,37 @@ public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
* @return the int
*/
int addNewDisposeDevice(DisposeDevice dev);
/**
* Del dispose device int.
*
* @param id the id
* @return the int
*/
int delDisposeDevice(@Param("id") Long id);
/**
* Disable dispose device int.
*
* @param id the id
* @return the int
*/
int disableDisposeDevice(@Param("id") Long id);
/**
* Lock dispose device int.
*
* @param id the id
* @return the int
*/
int lockDisposeDevice(@Param("id") Long id);
/**
* Unlock dispose device int.
*
* @param id the id
* @return the int
*/
int unlockDisposeDevice(@Param("id") Long id);
}

View File

@ -1,6 +1,5 @@
package com.dispose.pojo.entity;
import com.dispose.common.DisposeObjectType;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -56,7 +55,7 @@ public class DisposeCapacity {
/**
* The Object type.
*/
private DisposeObjectType objectType;
private Integer objectType;
/**
* The Ip type.

View File

@ -49,6 +49,11 @@ public class DisposeDevice implements Serializable {
*/
private String ipAddr;
/**
* The Ip port.
*/
private String ipPort;
/**
* The Device type.
*/
@ -60,9 +65,9 @@ public class DisposeDevice implements Serializable {
private Integer areaCode;
/**
* The Name.
* The Device name.
*/
private String name;
private String deviceName;
/**
* The Manufacturer.

View File

@ -1,14 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dispose.mapper.DisposeDeviceMapper">
<resultMap id="dispose_device" type="com.dispose.pojo.entity.DisposeDevice">
<id column="id" property="id"/>
<result column="ipAddr" property="ipAddr"/>
<result column="ipPort" property="ipPort"/>
<result column="deviceType" property="deviceType"/>
<result column="areaCode" property="areaCode"/>
<result column="deviceName" property="deviceName"/>
<result column="manufacturer" property="manufacturer"/>
<result column="model" property="model"/>
<result column="version" property="version"/>
<result column="userName" property="userName"/>
<result column="password" property="password"/>
<result column="urlPath" property="urlPath"/>
<result column="urlType" property="urlType"/>
<result column="readme" property="readme"/>
<result column="status" property="status"/>
<collection property="devCapacity" ofType="com.dispose.pojo.entity.DisposeCapacity">
<id column="c_id" property="id"/>
<result column="deviceId" property="deviceId"/>
<result column="capacityType" property="capacityType"/>
<result column="objectType" property="objectType"/>
<result column="ipType" property="ipType"/>
<result column="protectIp" property="protectIp"/>
</collection>
</resultMap>
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DisposeDevice">
INSERT IGNORE INTO dispose_device(ipAddr, deviceType,
INSERT IGNORE INTO dispose_device(ipAddr, ipPort, deviceType,
areaCode, deviceName, manufacturer,
model, version, userName, password, urlPath, urlType, readme, status)
VALUES (#{ipAddr}, #{deviceType},
VALUES (#{ipAddr}, #{ipPort}, #{deviceType},
#{areaCode}, #{deviceName}, #{manufacturer},
#{model}, #{version}, #{userName}, #{password}, #{urlPath}, #{urlType}, #{readme},
${@com.dispose.common.ObjectStatus@NORMAL.getCode()})
</insert>
<update id="delDisposeDevice">
UPDATE dispose_device
SET status = ${@com.dispose.common.ObjectStatus@DELETED.getCode()}
WHERE id = #{id}
</update>
<update id="disableDisposeDevice">
UPDATE
dispose_device
SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getCode()}
WHERE id = #{id}
</update>
<update id="lockDisposeDevice">
UPDATE dispose_device
SET status = ${@com.dispose.common.ObjectStatus@LOCKED.getCode()}
WHERE id = #{id}
</update>
<update id="unlockDisposeDevice">
UPDATE dispose_device
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getCode()}
WHERE id = #{id}
</update>
</mapper>

View File

@ -59,7 +59,7 @@ public class DisposeCapacityMapperTest {
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.CLEANUP.getCode())
.objectType(DisposeObjectType.IP)
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
@ -67,7 +67,7 @@ public class DisposeCapacityMapperTest {
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.BLOCKING.getCode())
.objectType(DisposeObjectType.URL)
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
@ -80,105 +80,105 @@ public class DisposeCapacityMapperTest {
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
}
// /**
// * A 2 del dispose capacity.
// *
// * @throws JsonProcessingException the json processing exception
// */
// @Test
// public void a2_delDisposeCapacity() throws JsonProcessingException {
// List<DisposeCapacity> newCapList = new ArrayList<>();
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.CLEANUP)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.BLOCKING)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// int items = disposeCapacityMapper.addNewDisposeCapacity(newCapList);
//
// Assert.assertEquals(items, newCapList.size());
//
// List<DisposeCapacity> capList = disposeCapacityMapper.selectAll();
//
// log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
//
// items = disposeCapacityMapper.delDisposeCapacity(capList.get(0).getDeviceId(),
// capList.get(0).getCapacityType().getCode());
//
// Assert.assertEquals(items, 1);
//
// capList = disposeCapacityMapper.selectAll();
//
// Assert.assertEquals(capList.size(), 1);
//
// log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
// }
//
// @Test
// public void a3_delDeviceDisposeCapacity() {
// List<DisposeCapacity> newCapList = new ArrayList<>();
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.CLEANUP)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.BLOCKING)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
//
// Assert.assertEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()),
// newCapList.size());
//
// Assert.assertEquals(0, disposeCapacityMapper.selectAll().size());
// }
//
// @Test
// public void b1_getDeviceDisposeCapacity() throws JsonProcessingException {
// List<DisposeCapacity> newCapList = new ArrayList<>();
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.CLEANUP)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// newCapList.add(DisposeCapacity.builder()
// .deviceId(1L)
// .ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
// .capacityType(DisposeCapacityType.BLOCKING)
// .objectType(DisposeObjectType.IP)
// .protectIp("")
// .build());
//
// Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
//
// List<DisposeCapacity> capList = disposeCapacityMapper.getDeviceDisposeCapacity(newCapList.get(0).getDeviceId());
//
// Assert.assertEquals(capList.size(), newCapList.size());
//
// log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
// }
/**
* A 2 del dispose capacity.
*
* @throws JsonProcessingException the json processing exception
*/
@Test
public void a2_delDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.CLEANUP.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.BLOCKING.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
int items = disposeCapacityMapper.addNewDisposeCapacity(newCapList);
Assert.assertEquals(items, newCapList.size());
List<DisposeCapacity> capList = disposeCapacityMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
items = disposeCapacityMapper.delDisposeCapacity(capList.get(0).getDeviceId(),
capList.get(0).getCapacityType());
Assert.assertEquals(items, 1);
capList = disposeCapacityMapper.selectAll();
Assert.assertEquals(capList.size(), 1);
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
}
@Test
public void a3_delDeviceDisposeCapacity() {
List<DisposeCapacity> newCapList = new ArrayList<>();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.CLEANUP.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.BLOCKING.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
Assert.assertEquals(disposeCapacityMapper.delDeviceDisposeCapacity(newCapList.get(0).getDeviceId()),
newCapList.size());
Assert.assertEquals(0, disposeCapacityMapper.selectAll().size());
}
@Test
public void b1_getDeviceDisposeCapacity() throws JsonProcessingException {
List<DisposeCapacity> newCapList = new ArrayList<>();
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.CLEANUP.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
newCapList.add(DisposeCapacity.builder()
.deviceId(1L)
.ipType(IpAddrType.IPV4.getCode() | IpAddrType.IPV6.getCode())
.capacityType(DisposeCapacityType.BLOCKING.getCode())
.objectType(DisposeObjectType.IP.getCode())
.protectIp("")
.build());
Assert.assertEquals(disposeCapacityMapper.addNewDisposeCapacity(newCapList), newCapList.size());
List<DisposeCapacity> capList = disposeCapacityMapper.getDeviceDisposeCapacity(newCapList.get(0).getDeviceId());
Assert.assertEquals(capList.size(), newCapList.size());
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList));
}
}

View File

@ -1,24 +0,0 @@
package com.dispose.test.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.FixMethodOrder;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* The type Dispose device mapper.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class DisposeDeviceMapper {
}

View File

@ -0,0 +1,78 @@
package com.dispose.test.mapper;
import com.dispose.common.DisposeDeviceType;
import com.dispose.common.HttpType;
import com.dispose.common.ObjectStatus;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* The type Dispose device mapper test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class DisposeDeviceMapperTest {
/**
* The Object mapper.
*/
@Resource
private ObjectMapper objectMapper;
/**
* The Dispose device mapper.
*/
@Resource
private DisposeDeviceMapper disposeDeviceMapper;
/**
* A 1 add new dispose device.
*/
@Test
public void a1_addNewDisposeDevice() throws JsonProcessingException {
DisposeDevice dev = DisposeDevice.builder()
.ipAddr("10.88.77.15")
.ipPort("")
.deviceType(DisposeDeviceType.DPTECH_UMC.getCode())
.areaCode(0)
.deviceName("中移杭研实验室迪普清洗设备")
.manufacturer("DPTech")
.model("UMC")
.version("5.7.13")
.userName("admin")
.password("UMCAdministrator")
.urlPath("UMC/service/AbnormalFlowCleaningService")
.urlType(HttpType.HTTP.getCode())
.readme("实验室测试设备")
.status(ObjectStatus.NORMAL.getCode())
.build();
Assert.assertEquals(1, disposeDeviceMapper.addNewDisposeDevice(dev));
Assert.assertNotNull(dev.getId());
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
}
}