郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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<List<DepartmentRespDTO>> getListTree(){
        List<DepartmentRespDTO> res =  departmentService.getDepartmentEnableList();
        return new ResultVO<>(ResultCodes.OK,res);
    }
 
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @CommonLogEnable(module = Module.ACCOUNT,content = "新增部门")
    public ResultVO<String> 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<String> 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<String> 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);
    }
 
 
 
 
}