OrganizationController.java
4.79 KB
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
/*
* Copyright (c) 2018, 2028, glsx and/or its affiliates. All rights reserved.
* GLSX PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package com.glsx.usercenter.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.StringUtils;
import com.glsx.usercenter.constants.ResultCodeEnum;
import com.glsx.usercenter.pojo.menu.SysOrganization;
import com.glsx.usercenter.service.ISysOrganizationService;
/**
* @ClassName: OrganizationController
* @Description: TODO(这里用一句话描述这个类的作用)
* @author Zheng Xiajun
* @date 2019年1月22日
*
*/
@RestController
@RequestMapping("/organization")
public class OrganizationController extends BaseController{
@Autowired
private ISysOrganizationService organizationService;
@RequestMapping(value = "/getByParams", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject getByParams( SysOrganization sysOrganization ) {
Integer id=sysOrganization.getId();
String name=sysOrganization.getName();
Byte orgStatus=sysOrganization.getOrgStatus();
logger.info("接收到的id参数值为:"+id);
if (!StringUtils.isNull(name)) {
name = name.replaceAll(" ", "");
}
Map map = new HashMap();
if (StringUtils.isNull(name) && orgStatus == null && id == null) {
// 菜单状态:1,正常、0.停用、2.注销
// 只查询一级菜单
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(),
organizationService.selectByExample(null, null));
} else {
if (StringUtils.isNull(name) && (orgStatus != null || id != null)) {
if (orgStatus == null) {
// 根据id递归查询子菜单
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(),
organizationService.findOrgById(id));
} else if (id != null) {
// // 根据id和状态递归查询子菜单
map.put("orgStatus", orgStatus);
map.put("id", id);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(),
organizationService.findOrgsByParams(map));
}
}
// 根据名字和状态搜索
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(),
organizationService.selectByExample(name, orgStatus));
}
}
@RequestMapping(value = "/add", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject add(SysOrganization sysOrganization) {
int i = organizationService.insertSelective(sysOrganization);
String msg = i == 0 ? ResultCodeEnum.FAIL.getMsg() : ResultCodeEnum.SUCCESS.getMsg();
int code = i == 0 ? ResultCodeEnum.FAIL.getCode() : ResultCodeEnum.SUCCESS.getCode();
return new ResultObject(code, msg);
}
@RequestMapping(value = "/deleteById", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject deleteById( SysOrganization organization) {
if (organization==null||organization.getId() == null) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL);
}
int i = organizationService.deleteByPrimaryKey(organization.getId());
String msg = i == 0 ? ResultCodeEnum.FAIL.getMsg() : ResultCodeEnum.SUCCESS.getMsg();
int code = i == 0 ? ResultCodeEnum.FAIL.getCode() : ResultCodeEnum.SUCCESS.getCode();
return new ResultObject(code, msg);
}
@RequestMapping(value = "/update", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject update( SysOrganization sysOrganization) {
organizationService.updateByPrimaryKeySelective(sysOrganization);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
}
@RequestMapping(value = "/selectDetailById", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject selectDetailById( SysOrganization organization) {
if (organization == null) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL);
}
SysOrganization sysOrganization =organizationService.selectByPrimaryKey(organization.getId() );
SysOrganization parent=organizationService.selectByPrimaryKey(sysOrganization.getParentId());
if(parent!=null){
sysOrganization.setParentName(parent.getName());
}else{
sysOrganization.setParentName("无");
}
return new ResultObject(ResultCodeEnum.SUCCESS.getCode() , ResultCodeEnum.SUCCESS.getMsg(),sysOrganization);
}
}