Repository navigation
Expand file tree
/
Copy pathGroupService.java
More file actions
73 lines (61 loc) · 1.76 KB
/
Copy pathGroupService.java
File metadata and controls
73 lines (61 loc) · 1.76 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
package bms.core.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import bms.core.dao.GroupMapper;
import bms.core.dao.UserGroupMapper;
import bms.core.model.Group;
import bms.core.model.MyResponse;
import bms.core.model.User;
import bms.core.model.UserType;
/**
* @author xu.jian
*
*/
@Service
public class GroupService extends BaseService {
@Autowired
GroupMapper groupMapper;
@Autowired
UserGroupMapper userGroupMapper;
public MyResponse add(Group group, BindingResult result) {
try {
groupMapper.insert(group);
} catch (Exception e) {
e.printStackTrace();
return msg.getFailed();
}
return msg.getSuccess();
}
public MyResponse update(Group group, BindingResult result) {
groupMapper.updateByPrimaryKeySelective(group);
return msg.getSuccess();
}
public MyResponse delete(String id) {
if (id.isEmpty())
return msg.getFailed();
int retCode = groupMapper.deleteByIDs(id.split(","));
if (retCode > 0)
return msg.getSuccess();
return msg.getFailed();
}
public List<Group> getGroups(User user) {
UserType userType = user.getUserTypeEnum();
int userId = user.getID();
GroupMapper groupMapper = sqlSession.getMapper(GroupMapper.class);
List<Group> groups = null;
if (userType == UserType.Admin) {
groups = groupMapper.selectAll();
} else {
groups = userGroupMapper.selectUserGroup(userId);
}
return groups;
}
public List<Group> getAuthGroups(int userId) {
return userGroupMapper.selectAuthGroup(userId);
}
public List<Group> selectByType(String type) {
return groupMapper.selectByType(type);
}
}