| | |
| | | import com.zy.asrs.wcs.system.entity.Dept; |
| | | import com.zy.asrs.wcs.system.service.DeptService; |
| | | import com.zy.asrs.wcs.utils.ExcelUtil; |
| | | import com.zy.asrs.wcs.utils.NodeUtils; |
| | | import com.zy.asrs.wcs.utils.Utils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @PostMapping("/dept/tree") |
| | | public R tree(@RequestBody Map<String, Object> map) { |
| | | // PageParam<Dept, BaseParam> param = new PageParam<>(buildParam(map, BaseParam.class), Dept.class); |
| | | // QueryWrapper<Dept> wrapper = param.buildWrapper(true, queryWrapper -> queryWrapper.orderByAsc("sort")); |
| | | List<Dept> deptList = deptService.list(new LambdaQueryWrapper<Dept>().orderByAsc(Dept::getSort)); |
| | | List<Dept> treeData = Utils.toTreeData(deptList, 0L, Dept::getParentId, Dept::getId, Dept::setChildren); |
| | | if (!Cools.isEmpty(map.get("condition"))) { |
| | | Utils.treeRemove(treeData, String.valueOf(map.get("condition")), Dept::getName, Dept::getChildren); |
| | | Utils.treeRemove(treeData, String.valueOf(map.get("condition")), Dept::getName, Dept::getChildren); |
| | | } |
| | | return R.ok().add(treeData); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:dept:list')") |
| | | @GetMapping("/dept/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(deptService.getById(id)); |
| | |
| | | @OperationLog("添加部门") |
| | | @PostMapping("/dept/save") |
| | | public R save(@RequestBody Dept dept) { |
| | | if (dept.getParentId() != null && dept.getParentId() > 0) { |
| | | Dept parent = deptService.getById(dept.getParentId()); |
| | | if (parent != null) { |
| | | dept.setParentName(parent.getName()); |
| | | } |
| | | } else { |
| | | dept.setParentId(0L); |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> deptService.getById(item.getParentId()), dept, Dept::getId, Dept::getName, Dept::getParentId); |
| | | dept.setPath(nodeUtils.path.toString()); |
| | | dept.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | | dept.setCreateBy(getLoginUserId()); |
| | | dept.setCreateTime(new Date()); |
| | | dept.setUpdateBy(getLoginUserId()); |
| | | dept.setUpdateTime(new Date()); |
| | | if (!deptService.save(dept)) { |
| | | return R.error("添加失败"); |
| | | } |
| | |
| | | @OperationLog("修改部门") |
| | | @PostMapping("/dept/update") |
| | | public R update(@RequestBody Dept dept) { |
| | | if (dept.getParentId() != null && dept.getParentId() > 0) { |
| | | Dept parent = deptService.getById(dept.getParentId()); |
| | | if (parent != null) { |
| | | dept.setParentName(parent.getName()); |
| | | } |
| | | } else { |
| | | dept.setParentId(0L); |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> deptService.getById(item.getParentId()), dept, Dept::getId, Dept::getName, Dept::getParentId); |
| | | dept.setPath(nodeUtils.path.toString()); |
| | | dept.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | | dept.setUpdateBy(getLoginUserId()); |
| | | dept.setUpdateTime(new Date()); |
| | | if (!deptService.updateById(dept)) { |
| | | return R.error("修改失败"); |
| | | } |