|
|
@@ -6,6 +6,8 @@ import cn.iaun.it.util.MyPage;
|
|
|
import cn.iaun.it.util.Result;
|
|
|
import cn.iaun.it.util.ResultCode;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -288,8 +290,15 @@ public class ItResourceController {
|
|
|
return new Result<>(ResultCode.SUCCESS, itResourceService.getResourceValues(id));
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/value/add")
|
|
|
- public Result<?> addItResourceValue(@Validated @RequestBody List<ItResourceValue> itResourceValues) {
|
|
|
+ @PostMapping("/value/del/{i}")
|
|
|
+ public Result<?> delItResourceValue(@PathVariable String i) {
|
|
|
+ long id = Long.parseLong(i);
|
|
|
+ int result = itResourceService.delResourceValueByResourceId(id);
|
|
|
+ return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/value/set")
|
|
|
+ public Result<?> setItResourceValues(@RequestBody List<ItResourceValue> itResourceValues) {
|
|
|
HashSet<Long> resourceSet = new HashSet<>();
|
|
|
HashSet<Long> attributeSet = new HashSet<>();
|
|
|
for (ItResourceValue itResourceValue : itResourceValues) {
|
|
|
@@ -298,6 +307,7 @@ public class ItResourceController {
|
|
|
resourceSet.add(resourceId);
|
|
|
attributeSet.add(attributeId);
|
|
|
}
|
|
|
+
|
|
|
int attributeCount = itResourceService.countResourceValueByAttributeIds(attributeSet);
|
|
|
int resourceCount = itResourceService.countResourceValueByResourceIds(resourceSet);
|
|
|
// 判断传入的ID是否在数据库存在(判断数量是否对上)
|
|
|
@@ -305,18 +315,17 @@ public class ItResourceController {
|
|
|
return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
}
|
|
|
|
|
|
- return new Result<>(ResultCode.SUCCESS, itResourceService.addResourceValues(itResourceValues));
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/value/del/{i}")
|
|
|
- public Result<?> delItResourceValue(@PathVariable String i) {
|
|
|
- long id = Long.parseLong(i);
|
|
|
- int result = itResourceService.delResourceValueByResourceId(id);
|
|
|
- return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
- }
|
|
|
+ HashMap<Long, Long> dbAttributeIds = itResourceService.getGroupIdByAttributeId(attributeSet);
|
|
|
+ HashMap<Long, Long> dbResourceIds = itResourceService.getGroupIdByResourceId(resourceSet);
|
|
|
|
|
|
- @PostMapping("/value/set")
|
|
|
- public Result<?> setItResourceValues(@RequestBody List<ItResourceValue> itResourceValues) {
|
|
|
+ for (ItResourceValue itResourceValue : itResourceValues) {
|
|
|
+ Long resourceId = itResourceValue.getResourceId();
|
|
|
+ Long attributeId = itResourceValue.getAttributeId();
|
|
|
+ // 判断groupID是否相等
|
|
|
+ if (!dbAttributeIds.get(attributeId).equals(dbResourceIds.get(resourceId))) {
|
|
|
+ return new Result<>(ResultCode.FAILED_PARAM_INVALID, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
int result = itResourceService.setResourceValueById(itResourceValues);
|
|
|
return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED, null);
|
|
|
}
|