package com.boying.controller;
|
|
import com.boying.common.BaseController;
|
import com.boying.entity.ZiLiaoDir;
|
import com.boying.service.ZiLiaoDirService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("ziLiaoDir")
|
public class ZiLiaoDirController extends BaseController {
|
|
@Autowired
|
private ZiLiaoDirService ziLiaoDirService;
|
|
@PostMapping("findPage")
|
public Object findPage() {
|
return success("",ziLiaoDirService.findAll("parentId", null));
|
}
|
|
@PostMapping("findByParentId")
|
public Object findByParentId(Long id) {
|
return success("",ziLiaoDirService.findAll("parentId", id));
|
}
|
|
@PostMapping("save")
|
public Object save(ZiLiaoDir ziLiaoDir) {
|
if(ziLiaoDir.getParentId()!=null&&ziLiaoDir.getId()==null){
|
ZiLiaoDir byId = (ZiLiaoDir) ziLiaoDirService.findById(ziLiaoDir.getParentId());
|
byId.setHasChildren(true);
|
ziLiaoDirService.save(byId);
|
}
|
ziLiaoDirService.save(ziLiaoDir);
|
return success("保存成功");
|
}
|
|
@PostMapping("delete")
|
public Object delete(Long id) {
|
|
ZiLiaoDir studyDir = (ZiLiaoDir) ziLiaoDirService.findById(id);
|
|
ziLiaoDirService.delete(id);
|
|
if(studyDir.getParentId()!=null){
|
List parentId = ziLiaoDirService.findAll("parentId", id);
|
if(parentId.size()==0){
|
ZiLiaoDir studyDir2 = (ZiLiaoDir) ziLiaoDirService.findById(studyDir.getParentId());
|
studyDir2.setHasChildren(false);
|
ziLiaoDirService.save(studyDir2);
|
}
|
}
|
|
return success("删除成功");
|
}
|
|
}
|