package com.gkhy.safePlatform.account.controller; import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.account.model.annotation.CommonLogEnable; import com.gkhy.safePlatform.account.model.dto.req.DepartmentAddReqDTO; import com.gkhy.safePlatform.account.model.dto.req.DepartmentModReqDTO; import com.gkhy.safePlatform.account.model.dto.resp.DepRespDTO; import com.gkhy.safePlatform.account.model.dto.resp.DepartmentRespDTO; import com.gkhy.safePlatform.account.service.DepartmentService; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.Module; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.security.Principal; import java.util.List; @RestController @RequestMapping("/department") public class DepartmentController { @Autowired private DepartmentService departmentService; @RequestMapping(value = "/list",method = RequestMethod.POST) public ResultVO> getListTree(){ List res = departmentService.getDepartmentEnableList(); return new ResultVO<>(ResultCodes.OK,res); } @RequestMapping(value = "/add", method = RequestMethod.POST) @CommonLogEnable(module = Module.ACCOUNT,content = "新增部门") public ResultVO addDepartment(Authentication authentication, @RequestBody DepartmentAddReqDTO departmentAddReqDTO) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); departmentService.addDepartment(currentUser, departmentAddReqDTO); return new ResultVO<>(ResultCodes.OK); } @RequestMapping(value = "/mod", method = RequestMethod.POST) @CommonLogEnable(module = Module.ACCOUNT,content = "修改部门") public ResultVO modDepartment(Authentication authentication, @RequestBody DepartmentModReqDTO departmentAddReqDTO) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); departmentService.modDepartment(currentUser, departmentAddReqDTO); return new ResultVO<>(ResultCodes.OK); } @RequestMapping(value = "/del", method = RequestMethod.POST) @CommonLogEnable(module = Module.ACCOUNT,content = "删除部门") public ResultVO delDepartment(Authentication authentication, @RequestBody JSONObject json) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); Long id = json.getLong("depId"); departmentService.delDepartment(currentUser, id); return new ResultVO<>(ResultCodes.OK); } }