|
@@ -1,11 +1,17 @@
|
|
|
package cn.iaun.it.controller;
|
|
package cn.iaun.it.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.iaun.it.model.ItResourceAttribute;
|
|
|
|
|
+import cn.iaun.it.model.ItResourceGroup;
|
|
|
import cn.iaun.it.model.ItResourceType;
|
|
import cn.iaun.it.model.ItResourceType;
|
|
|
import cn.iaun.it.service.ItResourceService;
|
|
import cn.iaun.it.service.ItResourceService;
|
|
|
import cn.iaun.it.util.Result;
|
|
import cn.iaun.it.util.Result;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import cn.iaun.it.util.ResultCode;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/resource")
|
|
@RequestMapping("/resource")
|
|
@@ -17,7 +23,122 @@ public class ItResourceController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping(value = "/type/get")
|
|
@GetMapping(value = "/type/get")
|
|
|
- public Result<ItResourceType> getItResourceType() {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ public Result<List<ItResourceType>> getItResourceTypes() {
|
|
|
|
|
+ return new Result<>(ResultCode.SUCCESS, itResourceService.getResourceType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/type/add")
|
|
|
|
|
+ public Result<?> addItResourceType(@Validated @RequestBody ItResourceType itResourceType) {
|
|
|
|
|
+ itResourceType.setTypeId(null);
|
|
|
|
|
+ if (itResourceType.getParentTypeId() != null && itResourceType.getParentTypeId() != -1L) {
|
|
|
|
|
+ List<ItResourceType> itResourceTypes = itResourceService.getResourceType();
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (ItResourceType type : itResourceTypes) {
|
|
|
|
|
+ if (type.getTypeId().equals(itResourceType.getParentTypeId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ int result = itResourceService.addResourceType(itResourceType);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/type/del/{i}")
|
|
|
|
|
+ public Result<?> delItResourceType(@PathVariable String i) {
|
|
|
|
|
+ long id = Long.parseLong(i);
|
|
|
|
|
+ int result = itResourceService.delResourceType(id);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/type/set")
|
|
|
|
|
+ public Result<?> setItResourceType(@Validated @RequestBody ItResourceType itResourceType) {
|
|
|
|
|
+ if (itResourceType.getParentTypeId() != null && itResourceType.getParentTypeId() != -1L) {
|
|
|
|
|
+ List<ItResourceType> itResourceTypes = itResourceService.getResourceType();
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (ItResourceType type : itResourceTypes) {
|
|
|
|
|
+ if (type.getTypeId().equals(itResourceType.getParentTypeId())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ int result = itResourceService.setResourceType(itResourceType);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping(value = "/group/get")
|
|
|
|
|
+ public Result<List<ItResourceGroup>> getItResourceGroups() {
|
|
|
|
|
+ return new Result<>(ResultCode.SUCCESS, itResourceService.getResourceGroup());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/group/add")
|
|
|
|
|
+ public Result<?> addItResourceGroup(@Validated @RequestBody ItResourceGroup itResourceGroup) {
|
|
|
|
|
+ itResourceGroup.setGroupId(null);
|
|
|
|
|
+ int result = itResourceService.addResourceGroup(itResourceGroup);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/group/del/{i}")
|
|
|
|
|
+ public Result<?> delItResourceGroup(@PathVariable String i) {
|
|
|
|
|
+ long id = Long.parseLong(i);
|
|
|
|
|
+ int result = itResourceService.delResourceGroup(id);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/group/set")
|
|
|
|
|
+ public Result<?> setItResourceGroup(@Validated @RequestBody ItResourceGroup itResourceGroup) {
|
|
|
|
|
+ int result = itResourceService.setResourceGroup(itResourceGroup);
|
|
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping(value = "/attribute/get")
|
|
|
|
|
+ public Result<IPage<ItResourceAttribute>> getItResourceAttribute(@Validated @RequestBody ItResourceAttributePageData page) {
|
|
|
|
|
+ if (page.pageNo == null) {
|
|
|
|
|
+ page.pageNo = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (page.pageSize == null) {
|
|
|
|
|
+ page.pageSize = 20;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return new Result<>(ResultCode.SUCCESS, itResourceService.getResourceAttribute(page.pageNo, page.pageSize, page.groupId));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+class ItResourceAttributePageData {
|
|
|
|
|
+ Integer pageNo;
|
|
|
|
|
+ Integer pageSize;
|
|
|
|
|
+ @NotNull
|
|
|
|
|
+ Long groupId;
|
|
|
|
|
+
|
|
|
|
|
+ public Integer getPageNo() {
|
|
|
|
|
+ return pageNo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setPageNo(Integer pageNo) {
|
|
|
|
|
+ this.pageNo = pageNo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Integer getPageSize() {
|
|
|
|
|
+ return pageSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setPageSize(Integer pageSize) {
|
|
|
|
|
+ this.pageSize = pageSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Long getGroupId() {
|
|
|
|
|
+ return groupId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setGroupId(Long groupId) {
|
|
|
|
|
+ this.groupId = groupId;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|