REM:
1. 增加业务管理接口
This commit is contained in:
HuangXin 2021-01-18 16:38:30 +08:00
parent 54d9f4eed7
commit 3906539c0a
14 changed files with 595 additions and 1 deletions

View File

@ -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, "删除客户业务失败"),
;
/**

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@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<AddUserSvrRsp> addUserBusiness(
@Validated(ValidGroups.AddUserInfoValid.class)
@RequestBody ProtocolReqDTO<AddUserSvrReq> mr) {
List<ServiceInfo> 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<MulReturnType<ErrorCode, String>> 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<AddUserSvrRsp> delUserBusiness(
@Validated(ValidGroups.AddUserInfoValid.class)
@RequestBody ProtocolReqDTO<BusinessIdArray> mr) {
// 删除业务
List<MulReturnType<ErrorCode, String>> 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<AddUserSvrRsp> upgradeUserBusiness(
@Validated(ValidGroups.AddUserInfoValid.class)
@RequestBody ProtocolReqDTO<AddUserSvrReq> mr) {
List<ServiceInfo> 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<MulReturnType<ErrorCode, String>> 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);
}
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
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);
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
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<ServiceInfo> 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;
}
}

View File

@ -18,6 +18,14 @@ public interface ServiceGroupMapper {
*/
List<ServiceInfo> 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.
*

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@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<UserSvrInfo> items;
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddUserSvrRsp {
/**
* The Items.
*/
private List<UserSvrRsp> items;
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@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;
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@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;
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonPropertyOrder({"businessId", "status", "message"})
public class UserSvrRsp extends BaseRespStatus {
/**
* The Business id.
*/
private String businessId;
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
public interface UserBusinessManagerService {
/**
* Add user business list.
*
* @param svrInfoList the svr info list
* @return the list
*/
List<MulReturnType<ErrorCode, String>> addUserBusiness(List<ServiceInfo> svrInfoList);
/**
* Upgrade user business list.
*
* @param svrInfoList the svr info list
* @return the list
*/
List<MulReturnType<ErrorCode, String>> upgradeUserBusiness(List<ServiceInfo> svrInfoList);
/**
* Del user business list.
*
* @param svrId the svr id
* @return the list
*/
List<MulReturnType<ErrorCode, String>> delUserBusiness(String[] svrId);
}

View File

@ -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 <huangxin@cmhi.chinamoblie.com>
*/
@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<MulReturnType<ErrorCode, String>> addUserBusiness(List<ServiceInfo> svrInfoList) {
List<MulReturnType<ErrorCode, String>> 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<MulReturnType<ErrorCode, String>> upgradeUserBusiness(List<ServiceInfo> svrInfoList) {
List<MulReturnType<ErrorCode, String>> 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<MulReturnType<ErrorCode, String>> delUserBusiness(String[] svrId) {
List<MulReturnType<ErrorCode, String>> rsp = new ArrayList<>();
for (String v : svrId) {
rsp.add(new MulReturnType<>(
userBusinessManager.delUserBusiness(v),
v
));
}
return rsp;
}
}

View File

@ -101,4 +101,12 @@ public interface ValidGroups {
*/
interface GetDevVerReqValid extends ProtocolCommonValid {
}
/**
* The interface Add device valid.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
interface AddUserInfoValid extends ProtocolCommonValid {
}
}

View File

@ -14,6 +14,12 @@
FROM service_group
</select>
<select id="selectByServiceId" resultMap="service_grp">
SELECT *
FROM service_group
WHERE serviceId = #{serviceId}
</select>
<insert id="addServiceGroup" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.ServiceInfo">
INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp)