kaiyu
2021-05-06 52d8cf200d7a54890845d4c468c24b6ab97a4762
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.moral.api.controller;
 
import com.moral.api.pojo.dto.organization.OrganizationDTO;
import com.moral.api.pojo.dto.organization.OrganizationQueryDTO;
import com.moral.api.pojo.dto.organization.OrganizationQueryNamesDTO;
import com.moral.api.pojo.form.organization.*;
import com.moral.api.pojo.vo.organization.*;
import com.moral.api.service.OrganizationService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @ClassName OrganizationController
 * @Description 用户组织控制器
 * @Author 陈凯裕
 * @Date 2021/3/22 14:10
 * @Version TODO
 **/
@Slf4j
@Api(tags = {"用户组织控制器"})
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/organization")
public class OrganizationController {
    @Autowired
    OrganizationService organizationService;
 
    @PostMapping("insert")
    public ResultMessage insert(@RequestBody OrganizationInsertForm form, HttpServletRequest request) {
 
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
 
        //判断参数是否有效
        OrganizationDTO conditionDTO = form.paramValid();
        if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
            return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null);
        }
 
        //处理插入业务
        OrganizationDTO dto = organizationService.insertOrganization(form);
 
        //转换前端需要的参数
        OrganizationInsertVO vo = OrganizationInsertVO.convert(dto);
 
        return new ResultMessage(dto.getCode(), dto.getMsg(), vo);
    }
 
    @PostMapping("update")
    public ResultMessage update(@RequestBody OrganizationUpdateForm form, HttpServletRequest request) {
 
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
 
        //判断参数是否有效
        OrganizationDTO conditionDTO = form.paramValid();
        if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
            return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null);
        }
 
        //处理更新业务
        OrganizationDTO dto = organizationService.updateOrganization(form);
 
        //转换前端需要的参数
        OrganizationUpdateVO vo = OrganizationUpdateVO.convert(dto);
 
        return new ResultMessage(dto.getCode(), dto.getMsg(), vo);
    }
 
    @PostMapping("delete")
    public ResultMessage delete(@RequestBody OrganizationDeleteForm form,HttpServletRequest request) {
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
 
        //处理删除业务
        OrganizationDTO dto = organizationService.deleteOrganization(form);
 
        //转换前端需要的参数
        OrganizationDeleteVO vo = OrganizationDeleteVO.convert(dto);
 
        return new ResultMessage(dto.getCode(), dto.getMsg(), vo);
    }
 
    @GetMapping("query")
    public ResultMessage query(OrganizationQueryForm form) {
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
 
        //处理查询业务
        OrganizationQueryDTO dto = organizationService.queryOrganization(form);
 
        //转换前端需要参数
        OrganizationQueryVO vo = OrganizationQueryVO.convert(dto);
 
        return new ResultMessage(dto.getCode(), dto.getMsg(), vo);
    }
 
    @GetMapping("queryNames")
    public ResultMessage queryNames(OrganizationQueryNamesForm form){
 
        //处理查询业务
        OrganizationQueryNamesDTO dto = organizationService.queryNames(form);
 
        //转换前端所需参数
        OrganizationQueryAllNamesVO vo = OrganizationQueryAllNamesVO.convert(dto);
 
        return new ResultMessage(dto.getCode(),dto.getMsg(),vo);
    }
 
}