|
@@ -0,0 +1,167 @@
|
|
1
|
+package com.yunzhi.marketing.xlk.controller;
|
|
2
|
+
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
5
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
6
|
+import com.yunzhi.marketing.base.BaseController;
|
|
7
|
+import com.yunzhi.marketing.base.ResponseBean;
|
|
8
|
+import com.yunzhi.marketing.common.StringUtils;
|
|
9
|
+import com.yunzhi.marketing.xlk.entity.Institution;
|
|
10
|
+import com.yunzhi.marketing.xlk.service.IInstitutionService;
|
|
11
|
+import io.swagger.annotations.Api;
|
|
12
|
+import io.swagger.annotations.ApiOperation;
|
|
13
|
+import org.slf4j.Logger;
|
|
14
|
+import org.slf4j.LoggerFactory;
|
|
15
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
16
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
17
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
18
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
19
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
20
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
21
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
22
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
23
|
+import org.springframework.web.bind.annotation.RestController;
|
|
24
|
+
|
|
25
|
+import javax.servlet.http.HttpServletRequest;
|
|
26
|
+import java.util.List;
|
|
27
|
+
|
|
28
|
+/**
|
|
29
|
+ * <p>
|
|
30
|
+ * 组织结构表 前端控制器
|
|
31
|
+ * </p>
|
|
32
|
+ *
|
|
33
|
+ * @author jobob
|
|
34
|
+ * @since 2021-06-22
|
|
35
|
+ */
|
|
36
|
+@RestController
|
|
37
|
+@RequestMapping("/api")
|
|
38
|
+@Api(value = "组织结构相关接口", tags = "xlk-组织结构相关接口")
|
|
39
|
+public class InstitutionController extends BaseController {
|
|
40
|
+
|
|
41
|
+ private final Logger logger = LoggerFactory.getLogger(InstitutionController.class);
|
|
42
|
+
|
|
43
|
+ @Autowired
|
|
44
|
+ public IInstitutionService iInstitutionService;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * 分页查询列表
|
|
49
|
+ * @param institutionId
|
|
50
|
+ * @return
|
|
51
|
+ */
|
|
52
|
+ @ApiOperation(value = "admin-组织机构列表查询", notes = "admin-组织机构列表查询")
|
|
53
|
+ @RequestMapping(value="/admin/institution/list",method= RequestMethod.GET)
|
|
54
|
+ public ResponseBean institutionList(@RequestParam(value ="institutionId",required = false) String institutionId,
|
|
55
|
+ @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
56
|
+ ResponseBean responseBean = new ResponseBean();
|
|
57
|
+ try {
|
|
58
|
+ LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
|
59
|
+ queryWrapper.eq(Institution::getOrgId,getOrgId(request));
|
|
60
|
+ if (StringUtils.isEmpty(institutionId)){
|
|
61
|
+ queryWrapper.eq(Institution::getType,1);
|
|
62
|
+ }else {
|
|
63
|
+ Institution institution = iInstitutionService.getById(institutionId);
|
|
64
|
+ queryWrapper.eq(Institution::getType,institution.getType() + 1);
|
|
65
|
+ queryWrapper.likeLeft(Institution::getInstitutionCode,institution.getInstitutionCode());
|
|
66
|
+ }
|
|
67
|
+ queryWrapper.orderByDesc(Institution::getCreateDate);
|
|
68
|
+
|
|
69
|
+ List<Institution> list = iInstitutionService.list(queryWrapper);
|
|
70
|
+ responseBean.addSuccess(list);
|
|
71
|
+ }catch (Exception e){
|
|
72
|
+ e.printStackTrace();
|
|
73
|
+ logger.error("institutionList -=- {}",e.toString());
|
|
74
|
+ responseBean.addError(e.getMessage());
|
|
75
|
+ }
|
|
76
|
+ return responseBean;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ /**
|
|
80
|
+ * 保存对象
|
|
81
|
+ * @param institution 实体对象
|
|
82
|
+ * @return
|
|
83
|
+ */
|
|
84
|
+ @ApiOperation(value = "admin-组织机构列表查询", notes = "admin-组织机构列表查询")
|
|
85
|
+ @RequestMapping(value="/institution",method= RequestMethod.POST)
|
|
86
|
+ public ResponseBean institutionAdd(@RequestBody Institution institution, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
87
|
+ ResponseBean responseBean = new ResponseBean();
|
|
88
|
+ try {
|
|
89
|
+ if (iInstitutionService.save(institution)){
|
|
90
|
+ responseBean.addSuccess(institution);
|
|
91
|
+ }else {
|
|
92
|
+ responseBean.addError("fail");
|
|
93
|
+ }
|
|
94
|
+ }catch (Exception e){
|
|
95
|
+ e.printStackTrace();
|
|
96
|
+ logger.error("institutionAdd -=- {}",e.toString());
|
|
97
|
+ responseBean.addError(e.getMessage());
|
|
98
|
+ }
|
|
99
|
+ return responseBean;
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ /**
|
|
103
|
+ * 根据id删除对象
|
|
104
|
+ * @param id 实体ID
|
|
105
|
+ */
|
|
106
|
+ @ApiOperation(value = "", notes = "")
|
|
107
|
+ @ResponseBody
|
|
108
|
+ @RequestMapping(value="/institution/{id}", method= RequestMethod.DELETE)
|
|
109
|
+ public ResponseBean institutionDelete(@PathVariable String id, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
110
|
+ ResponseBean responseBean = new ResponseBean();
|
|
111
|
+ try {
|
|
112
|
+ if(iInstitutionService.removeById(id)){
|
|
113
|
+ responseBean.addSuccess("success");
|
|
114
|
+ }else {
|
|
115
|
+ responseBean.addError("fail");
|
|
116
|
+ }
|
|
117
|
+ }catch (Exception e){
|
|
118
|
+ e.printStackTrace();
|
|
119
|
+ logger.error("institutionDelete -=- {}",e.toString());
|
|
120
|
+ responseBean.addError(e.getMessage());
|
|
121
|
+ }
|
|
122
|
+ return responseBean;
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ /**
|
|
126
|
+ * 修改对象
|
|
127
|
+ * @param id 实体ID
|
|
128
|
+ * @param institution 实体对象
|
|
129
|
+ * @return
|
|
130
|
+ */
|
|
131
|
+ @ApiOperation(value = "", notes = "")
|
|
132
|
+ @RequestMapping(value="/institution/{id}",method= RequestMethod.PUT)
|
|
133
|
+ public ResponseBean institutionUpdate(@PathVariable String id,
|
|
134
|
+ @RequestBody Institution institution, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
135
|
+ ResponseBean responseBean = new ResponseBean();
|
|
136
|
+ try {
|
|
137
|
+ if (iInstitutionService.updateById(institution)){
|
|
138
|
+ responseBean.addSuccess(institution);
|
|
139
|
+ }else {
|
|
140
|
+ responseBean.addError("fail");
|
|
141
|
+ }
|
|
142
|
+ }catch (Exception e){
|
|
143
|
+ e.printStackTrace();
|
|
144
|
+ logger.error("institutionUpdate -=- {}",e.toString());
|
|
145
|
+ responseBean.addError(e.getMessage());
|
|
146
|
+ }
|
|
147
|
+ return responseBean;
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ /**
|
|
151
|
+ * 根据id查询对象
|
|
152
|
+ * @param id 实体ID
|
|
153
|
+ */
|
|
154
|
+ @ApiOperation(value = "", notes = "")
|
|
155
|
+ @RequestMapping(value="/institution/{id}",method= RequestMethod.GET)
|
|
156
|
+ public ResponseBean institutionGet(@PathVariable String id, @RequestHeader("authorization") String token, HttpServletRequest request){
|
|
157
|
+ ResponseBean responseBean = new ResponseBean();
|
|
158
|
+ try {
|
|
159
|
+ responseBean.addSuccess(iInstitutionService.getById(id));
|
|
160
|
+ }catch (Exception e){
|
|
161
|
+ e.printStackTrace();
|
|
162
|
+ logger.error("institutionDelete -=- {}",e.toString());
|
|
163
|
+ responseBean.addError(e.getMessage());
|
|
164
|
+ }
|
|
165
|
+ return responseBean;
|
|
166
|
+ }
|
|
167
|
+}
|