From 3906539c0aae98f42625d6e4c2ae897ff6e09f19 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 16:38:30 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/common/ErrorCode.java | 25 ++- .../controller/UserBusinessController.java | 177 ++++++++++++++++++ .../dispose/manager/UserBusinessManager.java | 27 +++ .../manager/impl/UserBusinessManagerImpl.java | 57 ++++++ .../dispose/mapper/ServiceGroupMapper.java | 8 + .../device/business/AddUserSvrReq.java | 33 ++++ .../device/business/AddUserSvrRsp.java | 26 +++ .../device/business/BusinessIdArray.java | 28 +++ .../protocol/device/business/UserSvrInfo.java | 43 +++++ .../protocol/device/business/UserSvrRsp.java | 27 +++ .../service/UserBusinessManagerService.java | 38 ++++ .../impl/UserBusinessManagerServiceImpl.java | 93 +++++++++ .../dispose/validation/group/ValidGroups.java | 8 + src/main/resources/mappers/ServiceGroup.xml | 6 + 14 files changed, 595 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/dispose/controller/UserBusinessController.java create mode 100644 src/main/java/com/dispose/manager/UserBusinessManager.java create mode 100644 src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java create mode 100644 src/main/java/com/dispose/service/UserBusinessManagerService.java create mode 100644 src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index df067baa..f7112dc2 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -247,14 +247,37 @@ public enum ErrorCode { ERR_NOSUCHUMCPROTECTOBJECT(200, "没有找到UMC防护对象"), /** - * Err protectobjectexists error code. + * The Err protectobjectexists. */ ERR_PROTECTOBJECTEXISTS(201, "该防护对象已经存在"), + /** + * The Err tractionstrategyrunning. + */ ERR_TRACTIONSTRATEGYRUNNING(201, "该防护策略正在运行"), + /** + * The Err nosuchprotectstrategy. + */ ERR_NOSUCHPROTECTSTRATEGY(202, "没有该防护策略"), + + /** + * The Err businessexists. + */ + ERR_BUSINESSEXISTS(300, "该业务已经存在"), + + /** + * Err businessnotexists error code. + */ + ERR_BUSINESSNOTEXISTS(301, "该业务不存在"), + + /** + * Err addbusiness error code. + */ + ERR_ADDBUSINESS(302, "添加客户业务失败"), + + ERR_DELBUSINESS(303, "删除客户业务失败"), ; /** diff --git a/src/main/java/com/dispose/controller/UserBusinessController.java b/src/main/java/com/dispose/controller/UserBusinessController.java new file mode 100644 index 00000000..f9c34ad4 --- /dev/null +++ b/src/main/java/com/dispose/controller/UserBusinessController.java @@ -0,0 +1,177 @@ +package com.dispose.controller; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.device.business.AddUserSvrReq; +import com.dispose.pojo.dto.protocol.device.business.AddUserSvrRsp; +import com.dispose.pojo.dto.protocol.device.business.BusinessIdArray; +import com.dispose.pojo.dto.protocol.device.business.UserSvrInfo; +import com.dispose.pojo.dto.protocol.device.business.UserSvrRsp; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.security.annotation.Decryption; +import com.dispose.security.annotation.Encryption; +import com.dispose.service.UserBusinessManagerService; +import com.dispose.validation.group.ValidGroups; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business controller. + * + * @author + */ +@Controller +@RequestMapping(value = "/business") +@Slf4j +@Api(value = "抗DDoS处置平台客户业务管理接口", tags = "抗DDoS处置平台客户业务管理接口") +@Component +@Validated +@Encryption +@Decryption +public class UserBusinessController { + /** + * The User business manager service. + */ + @Resource + private UserBusinessManagerService userBusinessManagerService; + + /** + * Add user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @PutMapping("/manage") + @ResponseBody + @ApiOperation("添加客户业务信息") + public ProtocolRespDTO addUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + List svrList = new ArrayList<>(); + + // 参数转换 + for (UserSvrInfo v : mr.getMsgContent().getItems()) { + svrList.add(ServiceInfo.builder() + .serviceId(v.getBusinessId()) + .serviceType(v.getBusinessType()) + .serviceBandwidth((long) Math.ceil(Double.parseDouble(v.getBusinessBandwidth()))) + .serviceIp(v.getBusinessIp()) + .build()); + } + + // 添加业务 + List> ret = userBusinessManagerService.addUserBusiness(svrList); + + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + // 处理放回值 + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } + + /** + * Del user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @DeleteMapping("/manage") + @ResponseBody + @ApiOperation("删除客户业务信息") + public ProtocolRespDTO delUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + // 删除业务 + List> ret = userBusinessManagerService.delUserBusiness(mr.getMsgContent() + .getBusinessId()); + + // 处理放回值 + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } + + /** + * Upgrade user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @PostMapping("/updateBusiness") + @ResponseBody + @ApiOperation("更新客户业务信息") + public ProtocolRespDTO upgradeUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + List svrList = new ArrayList<>(); + + // 参数转换 + for (UserSvrInfo v : mr.getMsgContent().getItems()) { + svrList.add(ServiceInfo.builder() + .serviceId(v.getBusinessId()) + .serviceType(v.getBusinessType()) + .serviceBandwidth((long) Math.ceil(Double.parseDouble(v.getBusinessBandwidth()))) + .serviceIp(v.getBusinessIp()) + .build()); + } + + // 更新业务 + List> ret = userBusinessManagerService.upgradeUserBusiness(svrList); + + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + // 处理放回值 + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } +} diff --git a/src/main/java/com/dispose/manager/UserBusinessManager.java b/src/main/java/com/dispose/manager/UserBusinessManager.java new file mode 100644 index 00000000..f65d5893 --- /dev/null +++ b/src/main/java/com/dispose/manager/UserBusinessManager.java @@ -0,0 +1,27 @@ +package com.dispose.manager; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.entity.ServiceInfo; + +/** + * The interface User business manager. + * + * @author + */ +public interface UserBusinessManager { + /** + * Add user business error code. + * + * @param svrInfo the svr info + * @return the error code + */ + ErrorCode addUserBusiness(ServiceInfo svrInfo); + + /** + * Del user business error code. + * + * @param svrId the svr id + * @return the error code + */ + ErrorCode delUserBusiness(String svrId); +} diff --git a/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java new file mode 100644 index 00000000..903d8d52 --- /dev/null +++ b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java @@ -0,0 +1,57 @@ +package com.dispose.manager.impl; + +import com.dispose.common.ErrorCode; +import com.dispose.manager.UserBusinessManager; +import com.dispose.mapper.ServiceGroupMapper; +import com.dispose.pojo.entity.ServiceInfo; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business manager. + * + * @author + */ +public class UserBusinessManagerImpl implements UserBusinessManager { + /** + * The Service group mapper. + */ + @Resource + private ServiceGroupMapper serviceGroupMapper; + + /** + * Add user business error code. + * + * @param svrInfo the svr info + * @return the error code + */ + @Override + public ErrorCode addUserBusiness(ServiceInfo svrInfo) { + + if (serviceGroupMapper.selectByServiceId(svrInfo.getServiceId()) != null) { + return ErrorCode.ERR_BUSINESSEXISTS; + } + + List svrList = new ArrayList<>(); + svrList.add(svrInfo); + + return serviceGroupMapper.addServiceGroup(svrList) != 1 ? ErrorCode.ERR_ADDBUSINESS : ErrorCode.ERR_OK; + } + + /** + * Del user business error code. + * + * @param svrId the svr id + * @return the error code + */ + @Override + public ErrorCode delUserBusiness(String svrId) { + if (serviceGroupMapper.selectByServiceId(svrId) == null) { + return ErrorCode.ERR_BUSINESSNOTEXISTS; + } + + return serviceGroupMapper.delServiceGroupByServiceId(svrId) != 1 ? ErrorCode.ERR_DELBUSINESS : ErrorCode.ERR_OK; + } +} diff --git a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java index a90d07aa..5f518812 100644 --- a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java +++ b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java @@ -18,6 +18,14 @@ public interface ServiceGroupMapper { */ List selectAll(); + /** + * Select by service id service info. + * + * @param serviceId the service id + * @return the service info + */ + ServiceInfo selectByServiceId(@Param("serviceId") String serviceId); + /** * Add service group int. * diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java new file mode 100644 index 00000000..9e5d256a --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java @@ -0,0 +1,33 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * The type Add user svr req. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AddUserSvrReq { + /** + * The Items. + */ + @NotNull(message = "items 设备列表不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Size(min = 1, message = "items 至少需要有一个元素", groups = ValidGroups.AddUserInfoValid.class) + @Valid + private List items; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java new file mode 100644 index 00000000..054377b6 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java @@ -0,0 +1,26 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Add user svr rsp. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AddUserSvrRsp { + /** + * The Items. + */ + private List items; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java new file mode 100644 index 00000000..017a6c8f --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java @@ -0,0 +1,28 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * The type Business id array. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BusinessIdArray { + /** + * The Business id. + */ + @NotNull(message = "businessId 字段不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Size(min = 1, message = "businessId 字段必须指定明确编号", groups = ValidGroups.AddUserInfoValid.class) + private String[] businessId; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java new file mode 100644 index 00000000..f05ab975 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java @@ -0,0 +1,43 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +/** + * The type User svr info. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class UserSvrInfo { + /** + * The Business id. + */ + @NotBlank(message = "businessId 客户业务ID能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessId; + /** + * The Business type. + */ + @NotBlank(message = "businessType 客户业务类型不能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessType; + /** + * The Business ip. + */ + @JsonProperty("businessIP") + @NotBlank(message = "businessIp 业务IP地址段不能为空", groups = ValidGroups.UpgradeDeviceValid.class) + private String businessIp; + /** + * The Business bandwidth. + */ + @NotBlank(message = "businessBandwidth 客户业务带宽不能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessBandwidth; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java new file mode 100644 index 00000000..511f77f3 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java @@ -0,0 +1,27 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * The type User svr rsp. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonPropertyOrder({"businessId", "status", "message"}) +public class UserSvrRsp extends BaseRespStatus { + /** + * The Business id. + */ + private String businessId; +} diff --git a/src/main/java/com/dispose/service/UserBusinessManagerService.java b/src/main/java/com/dispose/service/UserBusinessManagerService.java new file mode 100644 index 00000000..419f6cab --- /dev/null +++ b/src/main/java/com/dispose/service/UserBusinessManagerService.java @@ -0,0 +1,38 @@ +package com.dispose.service; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; + +import java.util.List; + +/** + * The interface User business manager service. + * + * @author + */ +public interface UserBusinessManagerService { + /** + * Add user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + List> addUserBusiness(List svrInfoList); + + /** + * Upgrade user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + List> upgradeUserBusiness(List svrInfoList); + + /** + * Del user business list. + * + * @param svrId the svr id + * @return the list + */ + List> delUserBusiness(String[] svrId); +} diff --git a/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java new file mode 100644 index 00000000..9d69a69f --- /dev/null +++ b/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java @@ -0,0 +1,93 @@ +package com.dispose.service.impl; + +import com.dispose.common.ErrorCode; +import com.dispose.manager.UserBusinessManager; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.UserBusinessManagerService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business manager service. + * + * @author + */ +@Service +@Slf4j +public class UserBusinessManagerServiceImpl implements UserBusinessManagerService { + /** + * The User business manager. + */ + @Resource + private UserBusinessManager userBusinessManager; + + /** + * Add user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + @Override + public List> addUserBusiness(List svrInfoList) { + List> rsp = new ArrayList<>(); + + for (ServiceInfo v : svrInfoList) { + rsp.add(new MulReturnType<>( + userBusinessManager.addUserBusiness(v), + v.getServiceId() + )); + } + + return rsp; + } + + /** + * Upgrade user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + @Override + public List> upgradeUserBusiness(List svrInfoList) { + + List> rsp = new ArrayList<>(); + + for (ServiceInfo v : svrInfoList) { + // 删除旧业务 + userBusinessManager.delUserBusiness(v.getServiceId()); + + // 添加新业务 + rsp.add(new MulReturnType<>( + userBusinessManager.addUserBusiness(v), + v.getServiceId() + )); + } + + return rsp; + } + + /** + * Del user business list. + * + * @param svrId the svr id + * @return the list + */ + @Override + public List> delUserBusiness(String[] svrId) { + List> rsp = new ArrayList<>(); + + for (String v : svrId) { + rsp.add(new MulReturnType<>( + userBusinessManager.delUserBusiness(v), + v + )); + } + + return rsp; + } +} diff --git a/src/main/java/com/dispose/validation/group/ValidGroups.java b/src/main/java/com/dispose/validation/group/ValidGroups.java index 353c8223..b0ab2fcc 100644 --- a/src/main/java/com/dispose/validation/group/ValidGroups.java +++ b/src/main/java/com/dispose/validation/group/ValidGroups.java @@ -101,4 +101,12 @@ public interface ValidGroups { */ interface GetDevVerReqValid extends ProtocolCommonValid { } + + /** + * The interface Add device valid. + * + * @author + */ + interface AddUserInfoValid extends ProtocolCommonValid { + } } diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index e2eb2675..930ef68c 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -14,6 +14,12 @@ FROM service_group + + INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp)