zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.shlanbao.tzsc.pms.sys.org.controller;
 
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shlanbao.tzsc.base.controller.BaseController;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.base.model.Tree;
import com.shlanbao.tzsc.pms.sys.org.beans.OrgBean;
import com.shlanbao.tzsc.pms.sys.org.service.OrgServiceI;
import com.shlanbao.tzsc.pms.sys.resource.beans.ResourceBean;
import com.shlanbao.tzsc.pms.sys.user.beans.UserBean;
/**
 * 组织机构控制器
 * @author Leejean
 * @create 2014年9月16日上午10:40:37
 */
@Controller
@RequestMapping("/pms/sysOrg")
public class OrgController extends BaseController {
    @Autowired
    private OrgServiceI orgService;
    /**
     * 获得所有组织机构 del=0 enable:-1即为忽略enable条件
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllOrgs")
    public List<OrgBean> getAllOrgs(){
        try {
            return orgService.getAllUnDelOrgs();
        } catch (Exception e) {
            log.error(message, e);
        }
        return null;
    }
    @ResponseBody
    @RequestMapping("/getAllOrgsHtml")
    public Json getAllOrgsHtml(){
        Json json = new Json();
        try {
            json.setObj(OrgHtmlUtil.getHtml(orgService.getAllEnableOrgs()));
            json.setSuccess(true);
        } catch (Exception e) {
            log.error(message, e);
            json.setSuccess(false);
        }
        return json;
    }
    /**
     * 获得所有组织机构 (新增或修改组织机构时,选择父组织机构)del=0 enable=1
     * @param id 编辑对象id 自己不可以为自己的父id 应过滤
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllOrgsSelfNotIn")
    public List<Tree> getAllOrgsSelfNotIn(String id){
        try {
            return orgService.getAllOrgsSelfNotIn(id);
        } catch (Exception e) {
            log.error(message, e);
        }
        return null;
    }
    /**
     * 获得所有启用的组织机构树
     * @author Leejean
     * @create 2014-8-18下午08:36:38
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllOrgsTree")
    public List<Tree> getAllOrgsTree(){        
        try {
            return orgService.getAllOrgsTree();
        } catch (Exception e) {
            log.error(message, e);
        }
        return null;
    }
    /**
     * 跳转跳转到新增组织机构
     * @param orgBean
     * @return
     */
    @RequestMapping("/goToOrgAddJsp")
    public String goToOrgAddJsp(){        
        return "/pms/sys/organization/orgAdd";
    }
    /**
     * 跳转跳转到编辑组织机构
     * @param orgBean
     * @return
     */
    @RequestMapping("/goToOrgEditJsp")
    public String goToOrgEditJsp(String id,HttpServletRequest request){        
        try {
            request.setAttribute("checkedOrg", orgService.getOrgById(id));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/pms/sys/organization/orgEdit";
    }
    /**
     * 添加组织机构
     * @param orgBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/addOrg")
    public Json addOrg(OrgBean orgBean){
        Json json = new  Json();
        try {
            infoId = orgService.addOrg(orgBean);
            if(infoId==1){
                json.setMsg("添加失败,已经存在根级机构");
            }else{                
                json.setMsg("添加组织机构成功!");
                json.setSuccess(true);
            }
        } catch (Exception e) {
            log.error("添加组织机构失败", e);
            json.setMsg("添加组织机构失败!");
            json.setSuccess(true);
        }
        return json;
    }
    /**
     * 编辑组织机构
     * @param orgBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/editOrg")
    public Json editOrg(OrgBean orgBean){
        Json json = new  Json();
        try {
            orgService.editOrg(orgBean);
            json.setMsg("编辑组织机构成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            log.error("编辑组织机构失败", e);
            json.setMsg("编辑组织机构失败!");
            json.setSuccess(true);
        }
        return json;
    }
    /**
     * 删除组织机构
     * @param orgBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteOrg")
    public Json deleteOrg(String id){
        Json json = new  Json();
        try {
            orgService.deleteOrg(id);
            json.setMsg("删除组织机构成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            log.error("删除组织机构失败", e);
            json.setMsg("删除组织机构失败!");
            json.setSuccess(true);
        }
        return json;
    }
    /**
     * 跳转到分配权限页面
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 组织机构id
     * @return
     */
    @RequestMapping("/goToAssignResourceJsp")
    public String goToAssignResourceJsp(HttpServletRequest request,String id){
        request.setAttribute("checkedOrgId",id);
        return "/pms/sys/organization/assignResource";
    }
    /**
     * 根据当前组织机构加载该组织机构拥有的资源列表
     * @author Leejean
     * @create 2014年8月25日下午9:40:23
     * @param id 组织机构id
     * @return 资源列表
     */
    @RequestMapping("/getResourcesByOrg")
    @ResponseBody
    public List<ResourceBean> getResourcesByOrg(String id){
        try {
            return orgService.getResourcesByOrg(id);
        } catch (Exception e) {
            log.error("根据当前组织机构加载该组织机构拥有的资源列表失败", e);
        }
        return null;
    }
    /**
     * 给组织机构配权限
     * @author Leejean
     * @create 2014-8-21上午09:04:05
     * @param id 组织机构id
     * @param ids 资源id串
     * @return
     */
    @ResponseBody
    @RequestMapping("/assignResourceToOrg")
    public Json assignResourceToOrg(String id,String ids){
        Json json = new Json();
        try {
            orgService.assignResourceToOrg(id,ids);
            json.setSuccess(true);
            json.setMsg("给组织机构配权限成功!");
        } catch (Exception e) {
            log.error("给组织机构配权限异常", e);
            json.setSuccess(false);
            json.setMsg("给组织机构配权限失败!");
        }
        return json;
    }
    /**
     * 跳转到给机构分配用户界面
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 组织机构id
     * @return
     */
    @RequestMapping("/goToAssignUserJsp")
    public String goToAssignUserJsp(HttpServletRequest request,String id){
        request.setAttribute("checkedOrgId",id);
        return "/pms/sys/organization/assignUser";
    }
    /**
     * 给机构分配用户
     * @author Leejean
     * @create 2014年8月29日上午11:38:43
     * @param id 机构id
     * @param ids 用户ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/assignUsersToOrg")
    public Json assignUsersToOrg(String id,String ids){
        Json json = new Json();
        try {
            orgService.assignUsersToOrg(id,ids);
            json.setSuccess(true);
            json.setMsg("给机构分配用户成功!");
        } catch (Exception e) {
            log.error("给机构分配用户异常", e);
            json.setMsg("给机构分配用户失败!");
        }
        return json;
    }
    /**
     * 查询待分配的机构用户
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 组织机构id
     * @return
     */
    @ResponseBody
    @RequestMapping("/getOrgUnAssignedUsers")
    public List<UserBean> getOrgUnAssignedUsers(String oid,String name,PageParams pageParams){
        try {
            return orgService.getOrgUnAssignedUsers(oid,name);
        } catch (Exception e) {
            log.error("获得该机构用户分配情况异常", e);
        }
        return null;
    }
    /**
     * 查询已分配的机构用户
     * @author Leejean
     * @create 2014年8月25日下午9:41:58
     * @param id 组织机构id
     * @return
     */
    @ResponseBody
    @RequestMapping("/getOrgAssignedUsers")
    public List<UserBean> getOrgAssignedUsers(String oid,UserBean userBean){
        try {
            return orgService.getOrgAssignedUsers(oid);
        } catch (Exception e) {
            log.error("获得该机构用户分配情况异常", e);
        }
        return null;
    }
    
}