From e6420a641bad9eab32b4f6ffdfabfbb3376c6677 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 29 Jul 2020 19:33:42 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E8=AE=BE=E5=A4=87=E7=AE=A1?= =?UTF-8?q?=E7=90=86Mapper=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/common/DisposeDeviceType.java | 48 ++++ .../com/dispose/common/DisposeObjectType.java | 21 +- .../java/com/dispose/common/HttpType.java | 56 +++++ .../dispose/mapper/DisposeDeviceMapper.java | 34 +++ .../dispose/pojo/entity/DisposeCapacity.java | 3 +- .../dispose/pojo/entity/DisposeDevice.java | 9 +- src/main/resources/mappers/DisposeDevice.xml | 55 ++++- src/main/resources/mappers/UserAccount.xml | 8 +- .../mapper/DisposeCapacityMapperTest.java | 206 +++++++++--------- .../test/mapper/DisposeDeviceMapper.java | 24 -- .../test/mapper/DisposeDeviceMapperTest.java | 78 +++++++ 11 files changed, 393 insertions(+), 149 deletions(-) create mode 100644 src/main/java/com/dispose/common/DisposeDeviceType.java create mode 100644 src/main/java/com/dispose/common/HttpType.java delete mode 100644 src/test/java/com/dispose/test/mapper/DisposeDeviceMapper.java create mode 100644 src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java diff --git a/src/main/java/com/dispose/common/DisposeDeviceType.java b/src/main/java/com/dispose/common/DisposeDeviceType.java new file mode 100644 index 00000000..bc3f990e --- /dev/null +++ b/src/main/java/com/dispose/common/DisposeDeviceType.java @@ -0,0 +1,48 @@ +package com.dispose.common; + +/** + * The enum Dispose device type. + * + * @author + */ +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; + } +} diff --git a/src/main/java/com/dispose/common/DisposeObjectType.java b/src/main/java/com/dispose/common/DisposeObjectType.java index d1abb84b..8a4172d9 100644 --- a/src/main/java/com/dispose/common/DisposeObjectType.java +++ b/src/main/java/com/dispose/common/DisposeObjectType.java @@ -1,12 +1,11 @@ package com.dispose.common; - /** * The enum Dispose object type. * * @author */ -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; } } diff --git a/src/main/java/com/dispose/common/HttpType.java b/src/main/java/com/dispose/common/HttpType.java new file mode 100644 index 00000000..227941fb --- /dev/null +++ b/src/main/java/com/dispose/common/HttpType.java @@ -0,0 +1,56 @@ +package com.dispose.common; + +/** + * The enum Http type. + * + * @author + */ +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; + } +} diff --git a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java index a41cd300..62e53efb 100644 --- a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java +++ b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java @@ -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, * @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); } diff --git a/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java b/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java index 7601919a..607d1c17 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java @@ -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. diff --git a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java b/src/main/java/com/dispose/pojo/entity/DisposeDevice.java index 4c6430e9..b3145587 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeDevice.java @@ -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. diff --git a/src/main/resources/mappers/DisposeDevice.xml b/src/main/resources/mappers/DisposeDevice.xml index 5469dc4c..17c75666 100644 --- a/src/main/resources/mappers/DisposeDevice.xml +++ b/src/main/resources/mappers/DisposeDevice.xml @@ -1,14 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - 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()}) + + + UPDATE dispose_device + SET status = ${@com.dispose.common.ObjectStatus@DELETED.getCode()} + WHERE id = #{id} + + + + UPDATE + dispose_device + SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getCode()} + WHERE id = #{id} + + + + UPDATE dispose_device + SET status = ${@com.dispose.common.ObjectStatus@LOCKED.getCode()} + WHERE id = #{id} + + + + UPDATE dispose_device + SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getCode()} + WHERE id = #{id} + \ No newline at end of file diff --git a/src/main/resources/mappers/UserAccount.xml b/src/main/resources/mappers/UserAccount.xml index 51c7a34b..e84526ac 100644 --- a/src/main/resources/mappers/UserAccount.xml +++ b/src/main/resources/mappers/UserAccount.xml @@ -73,18 +73,18 @@ UPDATE user_account - SET status = ${@com.dispose.common.ObjectStatus@DELETED.getCode()}, + SET status = ${@com.dispose.common.ObjectStatus@DELETED.getCode()}, operators = #{operators}, - lockTime = CURRENT_TIMESTAMP + lockTime = CURRENT_TIMESTAMP WHERE username = #{username, jdbcType=VARCHAR} UPDATE user_account - SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getCode()}, + SET status = ${@com.dispose.common.ObjectStatus@DISABLED.getCode()}, operators = #{operators}, - lockTime = CURRENT_TIMESTAMP + lockTime = CURRENT_TIMESTAMP WHERE username = #{username, jdbcType=VARCHAR} diff --git a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java index 0f358e82..0e475980 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeCapacityMapperTest.java @@ -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 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 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 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 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 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 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 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 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 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 capList = disposeCapacityMapper.getDeviceDisposeCapacity(newCapList.get(0).getDeviceId()); + + Assert.assertEquals(capList.size(), newCapList.size()); + + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(capList)); + } } diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapper.java b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapper.java deleted file mode 100644 index c8499fbf..00000000 --- a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapper.java +++ /dev/null @@ -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 - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@Slf4j -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional -@Rollback -public class DisposeDeviceMapper { -} diff --git a/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java new file mode 100644 index 00000000..b48ae4b5 --- /dev/null +++ b/src/test/java/com/dispose/test/mapper/DisposeDeviceMapperTest.java @@ -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 + */ +@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 devList = disposeDeviceMapper.selectAll(); + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList)); + } +}