1. 添加HandlerMethodValidationException全局异常器
2. 新增防护对象类,添加Service、Mapper、Controller(Controller仍然在开发中) 3. page和pageSize添加@Min注解,限定最低整数大小 4. 将所有的批量类型方法修改为forEach,在SpringBoot中循环执行并整合为事务
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
public class ProtectObjectController {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProtectObjectMapper {
|
||||
void newProtectObject(@Param("proobj") ProtectObject protectObject);
|
||||
|
||||
List<ProtectObject> queryProtectObjects(@Param("proobj_name") String protectObjectName,
|
||||
@Param("proobj_id") Integer protectObjectId,
|
||||
@Param("page") Integer page,
|
||||
@Param("page_size") Integer pageSize);
|
||||
|
||||
ProtectObject queryProtectObject(@Param("proobj_id") Integer protectObjectId);
|
||||
|
||||
Boolean updateProtectObject(@Param("proobj") ProtectObject protectObject);
|
||||
|
||||
Boolean deleteProtectObject(@Param("proobj_id") Integer protectObjectId);
|
||||
|
||||
Boolean changeProtectObjectAuditStatus(@Param("proobj_audit_status") Integer protectObjectAuditStatus);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ProtectObjectService {
|
||||
private final ProtectObjectMapper protectObjectMapper;
|
||||
|
||||
public ProtectObjectService(ProtectObjectMapper protectObjectMapper) {
|
||||
this.protectObjectMapper = protectObjectMapper;
|
||||
}
|
||||
|
||||
public Integer newProtectObject(ProtectObject protectObject) {
|
||||
protectObjectMapper.newProtectObject(protectObject);
|
||||
|
||||
if (protectObject.getProtectObjectId() == null) {
|
||||
return 0;
|
||||
}
|
||||
return protectObject.getProtectObjectId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Integer> newProtectObjects(List<ProtectObject> protectObjectList) {
|
||||
protectObjectList.forEach(protectObjectMapper::newProtectObject);
|
||||
return protectObjectList.stream().map(ProtectObject::getProtectObjectId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<ProtectObject> queryProtectObjects(String protectObjectName, Integer protectObjectId, Integer page, Integer pageSize) {
|
||||
return protectObjectMapper.queryProtectObjects(protectObjectName, protectObjectId, page, pageSize);
|
||||
}
|
||||
|
||||
public ProtectObject queryProtectObject(Integer protectObjectId) {
|
||||
return protectObjectMapper.queryProtectObject(protectObjectId);
|
||||
}
|
||||
|
||||
public Boolean updateProtectObject(ProtectObject protectObject) {
|
||||
return protectObjectMapper.updateProtectObject(protectObject);
|
||||
}
|
||||
|
||||
public Boolean deleteProtectObject(Integer protectObjectId) {
|
||||
return protectObjectMapper.deleteProtectObject(protectObjectId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Boolean deleteProtectObjects(List<Integer> protectObjectIds) {
|
||||
return protectObjectIds.stream().allMatch(protectObjectMapper::deleteProtectObject);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.realtime.protection.server.defense.template;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -41,16 +42,32 @@ public class TemplateController {
|
||||
}
|
||||
|
||||
@GetMapping("/query")
|
||||
public ResponseResult queryTemplate(@RequestParam(value = "template_name", required = false) String templateName,
|
||||
@RequestParam("page") Integer page,
|
||||
@RequestParam("page_size") Integer pageSize) {
|
||||
if (page <= 0 || pageSize <= 0) {
|
||||
return ResponseResult.invalid()
|
||||
.setData("template_list", null);
|
||||
}
|
||||
public ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
|
||||
@RequestParam("page") @Min(1) Integer page,
|
||||
@RequestParam("page_size") @Min(1) Integer pageSize) {
|
||||
List<Template> templates = templateService.queryTemplates(templateName, page, pageSize);
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("templates", templates);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/update")
|
||||
public ResponseResult updateTemplate(@PathVariable("id") @Min(1) Integer templateId,
|
||||
@RequestBody @Valid Template template) {
|
||||
Boolean success = templateService.updateTemplate(templateId, template);
|
||||
return ResponseResult.ok()
|
||||
.setData("template_id", templateId)
|
||||
.setData("success", success);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/addUsedTimes")
|
||||
public ResponseResult addTemplateUsedTimes(@PathVariable("id") @Min(1) Integer templateId,
|
||||
@RequestParam(value = "add_num") @Min(0) Integer addNum) {
|
||||
Boolean success = templateService.addTemplateUsedTimes(templateId, addNum);
|
||||
return ResponseResult.ok()
|
||||
.setData("template_id", templateId)
|
||||
.setData("success", success);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,4 +13,10 @@ public interface TemplateMapper {
|
||||
List<Template> queryTemplates(@Param("template_name") String templateName,
|
||||
@Param("page") Integer page,
|
||||
@Param("page_size") Integer pageSize);
|
||||
|
||||
Boolean updateTemplateInformation(@Param("template") Template template);
|
||||
|
||||
void countTemplateRunningTasks(@Param("template_id") Integer templateId);
|
||||
|
||||
Boolean addTemplateUsedTimes(@Param("template_id") Integer templateId, @Param("add_times") Integer addTimes);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,28 @@ public class TemplateService {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
setTemplateElements(template);
|
||||
|
||||
templateMapper.newTemplate(template);
|
||||
|
||||
if (template.getTemplateId() == null) {
|
||||
return 0;
|
||||
}
|
||||
return template.getTemplateId();
|
||||
}
|
||||
|
||||
public List<Template> queryTemplates(String templateName, Integer page, Integer pageSize) {
|
||||
return templateMapper.queryTemplates(templateName, page, pageSize);
|
||||
}
|
||||
|
||||
public Boolean updateTemplate(Integer templateId, Template template) {
|
||||
setTemplateElements(template);
|
||||
template.setTemplateId(templateId);
|
||||
|
||||
return templateMapper.updateTemplateInformation(template);
|
||||
}
|
||||
|
||||
private void setTemplateElements(Template template) {
|
||||
for (String choice : template.getTemplateElements()) {
|
||||
switch (choice) {
|
||||
case "防护对象IP" -> template.setHasProtectObjectIP(true);
|
||||
@@ -35,16 +57,10 @@ public class TemplateService {
|
||||
default -> throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
templateMapper.newTemplate(template);
|
||||
|
||||
if (template.getTemplateId() == null) {
|
||||
return 0;
|
||||
}
|
||||
return template.getTemplateId();
|
||||
}
|
||||
|
||||
public List<Template> queryTemplates(String templateName, Integer page, Integer pageSize) {
|
||||
return templateMapper.queryTemplates(templateName, page, pageSize);
|
||||
public Boolean addTemplateUsedTimes(Integer templateId, Integer addTimes) {
|
||||
return templateMapper.addTemplateUsedTimes(templateId, addTimes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user