|
@@ -10,7 +10,10 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/resource")
|
|
@RequestMapping("/resource")
|
|
@@ -110,8 +113,41 @@ public class ItResourceController {
|
|
|
return new Result<>(ResultCode.SUCCESS, myPage);
|
|
return new Result<>(ResultCode.SUCCESS, myPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SuppressWarnings("ResultOfMethodCallIgnored")
|
|
|
@PostMapping("/attribute/add")
|
|
@PostMapping("/attribute/add")
|
|
|
public Result<?> addItResourceAttribute(@Validated @RequestBody ItResourceAttribute itResourceAttribute) {
|
|
public Result<?> addItResourceAttribute(@Validated @RequestBody ItResourceAttribute itResourceAttribute) {
|
|
|
|
|
+ itResourceAttribute.setAttributeId(null);
|
|
|
|
|
+ switch (itResourceAttribute.getAttributeType()) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ itResourceAttribute.setOptions("");
|
|
|
|
|
+ if (itResourceAttribute.getValueType() != 0 && itResourceAttribute.getValueType() != 1) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ } else if (itResourceAttribute.getValueType() == 1 && !itResourceAttribute.getDefaultValue().equals("")) { // 验证数字
|
|
|
|
|
+ Integer.parseInt(itResourceAttribute.getDefaultValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ itResourceAttribute.setValueType(0);
|
|
|
|
|
+ itResourceAttribute.setOptions("");
|
|
|
|
|
+ itResourceAttribute.setDefaultValue("");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ itResourceAttribute.setValueType(0);
|
|
|
|
|
+ if (itResourceAttribute.getDefaultValue() != null && !itResourceAttribute.getDefaultValue().equals("")) {
|
|
|
|
|
+ String[] options = itResourceAttribute.getOptions().split(",");
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (String option : options) {
|
|
|
|
|
+ if (option.equals(itResourceAttribute.getDefaultValue())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
int result = itResourceService.addResourceAttribute(itResourceAttribute);
|
|
int result = itResourceService.addResourceAttribute(itResourceAttribute);
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|
|
}
|
|
@@ -123,8 +159,41 @@ public class ItResourceController {
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SuppressWarnings("ResultOfMethodCallIgnored")
|
|
|
@PostMapping("/attribute/set")
|
|
@PostMapping("/attribute/set")
|
|
|
public Result<?> setItResourceAttribute(@Validated @RequestBody ItResourceAttribute itResourceAttribute) {
|
|
public Result<?> setItResourceAttribute(@Validated @RequestBody ItResourceAttribute itResourceAttribute) {
|
|
|
|
|
+ switch (itResourceAttribute.getAttributeType()) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ itResourceAttribute.setOptions("");
|
|
|
|
|
+ if (itResourceAttribute.getValueType() != 0 && itResourceAttribute.getValueType() != 1) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ } else if (itResourceAttribute.getValueType() == 1 && !itResourceAttribute.getDefaultValue().equals("")) { // 验证数字
|
|
|
|
|
+ Integer.parseInt(itResourceAttribute.getDefaultValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ itResourceAttribute.setValueType(0);
|
|
|
|
|
+ itResourceAttribute.setOptions("");
|
|
|
|
|
+ itResourceAttribute.setDefaultValue("");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ itResourceAttribute.setValueType(0);
|
|
|
|
|
+ if (itResourceAttribute.getDefaultValue() != null && !itResourceAttribute.getDefaultValue().equals("")) {
|
|
|
|
|
+ String[] options = itResourceAttribute.getOptions().split(",");
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (String option : options) {
|
|
|
|
|
+ if (option.equals(itResourceAttribute.getDefaultValue())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
int result = itResourceService.setResourceAttribute(itResourceAttribute);
|
|
int result = itResourceService.setResourceAttribute(itResourceAttribute);
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|
|
}
|
|
@@ -137,13 +206,40 @@ public class ItResourceController {
|
|
|
if (page.pageSize == null) {
|
|
if (page.pageSize == null) {
|
|
|
page.pageSize = 20;
|
|
page.pageSize = 20;
|
|
|
}
|
|
}
|
|
|
- IPage<ItResource> iPage = itResourceService.getResource(page.getPageNo(), page.getPageSize(), page.getResourceTypeId());
|
|
|
|
|
|
|
+ IPage<ItResource> iPage = itResourceService.getResource(page.getPageNo(), page.getPageSize(), page.getTypeId());
|
|
|
MyPage<ItResource> myPage = new MyPage<>(iPage);
|
|
MyPage<ItResource> myPage = new MyPage<>(iPage);
|
|
|
return new Result<>(ResultCode.SUCCESS, myPage);
|
|
return new Result<>(ResultCode.SUCCESS, myPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
|
public Result<?> addItResource(@Validated @RequestBody ItResource itResource) {
|
|
public Result<?> addItResource(@Validated @RequestBody ItResource itResource) {
|
|
|
|
|
+ itResource.setResourceId(null);
|
|
|
|
|
+ // 判断ID是否存在
|
|
|
|
|
+ // type
|
|
|
|
|
+ List<ItResourceType> itResourceTypes = itResourceService.getResourceType();
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (ItResourceType itResourceType : itResourceTypes) {
|
|
|
|
|
+ if (itResourceType.getTypeId().equals(itResource.getTypeId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ // group
|
|
|
|
|
+ List<ItResourceGroup> itResourceGroups = itResourceService.getResourceGroup();
|
|
|
|
|
+ exists = false;
|
|
|
|
|
+ for (ItResourceGroup itResourceGroup : itResourceGroups) {
|
|
|
|
|
+ if (itResourceGroup.getGroupId().equals(itResource.getGroupId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
int result = itResourceService.addResource(itResource);
|
|
int result = itResourceService.addResource(itResource);
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|
|
}
|
|
@@ -157,6 +253,31 @@ public class ItResourceController {
|
|
|
|
|
|
|
|
@PostMapping("/set")
|
|
@PostMapping("/set")
|
|
|
public Result<?> setItResource(@Validated @RequestBody ItResource itResource) {
|
|
public Result<?> setItResource(@Validated @RequestBody ItResource itResource) {
|
|
|
|
|
+ // 判断ID是否存在
|
|
|
|
|
+ // type
|
|
|
|
|
+ List<ItResourceType> itResourceTypes = itResourceService.getResourceType();
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (ItResourceType itResourceType : itResourceTypes) {
|
|
|
|
|
+ if (itResourceType.getTypeId().equals(itResource.getTypeId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ // group
|
|
|
|
|
+ List<ItResourceGroup> itResourceGroups = itResourceService.getResourceGroup();
|
|
|
|
|
+ exists = false;
|
|
|
|
|
+ for (ItResourceGroup itResourceGroup : itResourceGroups) {
|
|
|
|
|
+ if (itResourceGroup.getGroupId().equals(itResource.getGroupId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
int result = itResourceService.setResource(itResource);
|
|
int result = itResourceService.setResource(itResource);
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|
|
}
|
|
@@ -168,7 +289,22 @@ public class ItResourceController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/value/add")
|
|
@PostMapping("/value/add")
|
|
|
- public Result<?> addItResourceValue(@RequestBody List<ItResourceValue> itResourceValues) {
|
|
|
|
|
|
|
+ public Result<?> addItResourceValue(@Validated @RequestBody List<ItResourceValue> itResourceValues) {
|
|
|
|
|
+ HashSet<Long> resourceSet = new HashSet<>();
|
|
|
|
|
+ HashSet<Long> attributeSet = new HashSet<>();
|
|
|
|
|
+ for (ItResourceValue itResourceValue : itResourceValues) {
|
|
|
|
|
+ Long resourceId = itResourceValue.getResourceId();
|
|
|
|
|
+ Long attributeId = itResourceValue.getAttributeId();
|
|
|
|
|
+ resourceSet.add(resourceId);
|
|
|
|
|
+ attributeSet.add(attributeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ int attributeCount = itResourceService.countResourceValueByAttributeIds(attributeSet);
|
|
|
|
|
+ int resourceCount = itResourceService.countResourceValueByResourceIds(resourceSet);
|
|
|
|
|
+ // 判断传入的ID是否在数据库存在(判断数量是否对上)
|
|
|
|
|
+ if (resourceSet.size() != resourceCount || attributeSet.size() != attributeCount) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return new Result<>(ResultCode.SUCCESS, itResourceService.addResourceValues(itResourceValues));
|
|
return new Result<>(ResultCode.SUCCESS, itResourceService.addResourceValues(itResourceValues));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -190,8 +326,7 @@ public class ItResourceController {
|
|
|
class ItResourceAttributeReqData {
|
|
class ItResourceAttributeReqData {
|
|
|
Integer pageNo;
|
|
Integer pageNo;
|
|
|
Integer pageSize;
|
|
Integer pageSize;
|
|
|
- @NotNull
|
|
|
|
|
- Long groupId;
|
|
|
|
|
|
|
+ @NotNull Long groupId;
|
|
|
|
|
|
|
|
public Integer getPageNo() {
|
|
public Integer getPageNo() {
|
|
|
return pageNo;
|
|
return pageNo;
|
|
@@ -221,8 +356,7 @@ class ItResourceAttributeReqData {
|
|
|
class ItResourceReqData {
|
|
class ItResourceReqData {
|
|
|
Integer pageNo;
|
|
Integer pageNo;
|
|
|
Integer pageSize;
|
|
Integer pageSize;
|
|
|
- @NotNull
|
|
|
|
|
- Long resourceTypeId;
|
|
|
|
|
|
|
+ @NotNull Long typeId;
|
|
|
|
|
|
|
|
public Integer getPageNo() {
|
|
public Integer getPageNo() {
|
|
|
return pageNo;
|
|
return pageNo;
|
|
@@ -240,11 +374,11 @@ class ItResourceReqData {
|
|
|
this.pageSize = pageSize;
|
|
this.pageSize = pageSize;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Long getResourceTypeId() {
|
|
|
|
|
- return resourceTypeId;
|
|
|
|
|
|
|
+ public Long getTypeId() {
|
|
|
|
|
+ return typeId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setResourceTypeId(Long resourceTypeId) {
|
|
|
|
|
- this.resourceTypeId = resourceTypeId;
|
|
|
|
|
|
|
+ public void setTypeId(Long typeId) {
|
|
|
|
|
+ this.typeId = typeId;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|