|
@@ -26,6 +26,7 @@ import lombok.AllArgsConstructor;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import org.springblade.business.dto.TrialClassificationTreeDTO;
|
|
|
+import org.springblade.business.dto.TrialClassificationTreeDTO1;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
@@ -43,6 +44,9 @@ import org.springblade.core.boot.ctrl.BladeController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 德飞试验系统检测分类树 控制器
|
|
@@ -100,15 +104,20 @@ public class TrialClassificationTreeController extends BladeController {
|
|
|
@PostMapping("/save")
|
|
|
@ApiOperationSupport(order = 4)
|
|
|
@ApiOperation(value = "新增", notes = "传入trialClassificationTree")
|
|
|
- public R save(@Valid @RequestBody List<TrialClassificationTreeDTO> list,Integer groupType) {
|
|
|
- if(groupType!=null&&groupType==1){
|
|
|
- trialClassificationTreeService.update(new UpdateWrapper<TrialClassificationTree>().set("is_deleted", 1).eq("group_type",1));
|
|
|
+ public R save(@Valid @RequestBody TrialClassificationTreeDTO1 dto) {
|
|
|
+ if(dto.getGroupType()!=null&&dto.getGroupType()==1){
|
|
|
+ trialClassificationTreeService.deleteByGroupType(dto.getGroupType());
|
|
|
}
|
|
|
+ // 假设您有一个 List<TrialClassificationTreeDTO> list
|
|
|
+ Map<Long, Long> map = dto.getList().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ TrialClassificationTreeDTO::getId, // 按 parentId 分组
|
|
|
+ TrialClassificationTreeDTO::getParentId // 收集每个分组的 id 列表
|
|
|
+ ));
|
|
|
List<TrialClassificationTree>insertList=new ArrayList<>();
|
|
|
- for (TrialClassificationTreeDTO trialClassificationTreeDTO : list) {
|
|
|
+ for (TrialClassificationTreeDTO trialClassificationTreeDTO : dto.getList()) {
|
|
|
TrialClassificationTree trialClassificationTree = new TrialClassificationTree();
|
|
|
BeanUtil.copy(trialClassificationTreeDTO, trialClassificationTree);
|
|
|
- trialClassificationTree.setId(SnowFlakeUtil.getId());
|
|
|
Long parentId = trialClassificationTree.getParentId();
|
|
|
StringBuilder classificationAncestors = new StringBuilder();
|
|
|
classificationAncestors.append(trialClassificationTree.getId());
|
|
@@ -116,23 +125,30 @@ public class TrialClassificationTreeController extends BladeController {
|
|
|
classificationAncestors.append( ",").append(parentId);
|
|
|
}
|
|
|
while (parentId!=null&&parentId!=0){
|
|
|
- parentId = selectAncestors(parentId);
|
|
|
+ parentId = selectAncestors(parentId,map);
|
|
|
if(parentId!=null&&parentId!=0){
|
|
|
- classificationAncestors.append(parentId).append(",");
|
|
|
+ classificationAncestors.append(",").append(parentId);
|
|
|
}
|
|
|
}
|
|
|
trialClassificationTree.setClassificationAncestors(classificationAncestors.toString());
|
|
|
- trialClassificationTree.setGroupType(groupType);
|
|
|
+ trialClassificationTree.setGroupType(dto.getGroupType());
|
|
|
insertList.add(trialClassificationTree);
|
|
|
}
|
|
|
- return R.status(trialClassificationTreeService.saveOrUpdateBatch(insertList));
|
|
|
+ return R.status(trialClassificationTreeService.saveBatch(insertList));
|
|
|
}
|
|
|
|
|
|
- public Long selectAncestors(Long parentId) {
|
|
|
+ public Long selectAncestors(Long parentId,Map<Long, Long> map) {
|
|
|
if(parentId==0){
|
|
|
return null;
|
|
|
}
|
|
|
- return trialClassificationTreeService.selectAncestors(parentId);
|
|
|
+ if(map.containsKey(parentId)){
|
|
|
+ if(map.get(parentId)!=null){
|
|
|
+ return map.get(parentId);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return trialClassificationTreeService.selectAncestors(parentId);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -141,8 +157,8 @@ public class TrialClassificationTreeController extends BladeController {
|
|
|
@PostMapping("/update")
|
|
|
@ApiOperationSupport(order = 5)
|
|
|
@ApiOperation(value = "修改", notes = "传入trialClassificationTree")
|
|
|
- public R update(Long dfId,String classificationName) {
|
|
|
- if(dfId==null){
|
|
|
+ public R update(Long id,String classificationName) {
|
|
|
+ if(id==null){
|
|
|
return R.fail("请选择要修改的分类");
|
|
|
}
|
|
|
if(Func.isEmpty(classificationName)){
|
|
@@ -150,7 +166,7 @@ public class TrialClassificationTreeController extends BladeController {
|
|
|
}
|
|
|
TrialClassificationTree trialClassificationTree = new TrialClassificationTree();
|
|
|
trialClassificationTree.setClassificationName(classificationName);
|
|
|
- return R.status(trialClassificationTreeService.update(new UpdateWrapper<TrialClassificationTree>().set("classification_name", classificationName).eq("df_id", dfId)));
|
|
|
+ return R.status(trialClassificationTreeService.update(new UpdateWrapper<TrialClassificationTree>().set("classification_name", classificationName).eq("id", id)));
|
|
|
}
|
|
|
|
|
|
// /**
|
|
@@ -182,6 +198,4 @@ public class TrialClassificationTreeController extends BladeController {
|
|
|
boolean update = trialClassificationTreeService.update(new UpdateWrapper<TrialClassificationTree>().set("is_deleted", 1).in("classification_ancestors", id));
|
|
|
return R.status(update);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|