|
1 | 1 | package org.nlpcn.jcoder.controller;
|
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
3 | 4 | import java.util.Date;
|
4 | 5 | import java.util.List;
|
5 | 6 |
|
| 7 | +import org.nlpcn.jcoder.domain.Task; |
6 | 8 | import org.nlpcn.jcoder.domain.UserGroup;
|
7 | 9 | import org.nlpcn.jcoder.filter.AuthoritiesManager;
|
| 10 | +import org.nlpcn.jcoder.service.TaskService; |
8 | 11 | import org.nlpcn.jcoder.util.StaticValue;
|
9 | 12 | import org.nlpcn.jcoder.util.dao.BasicDao;
|
10 | 13 | import org.nutz.dao.Cnd;
|
11 | 14 | import org.nutz.dao.Condition;
|
| 15 | +import org.nutz.ioc.loader.annotation.Inject; |
12 | 16 | import org.nutz.ioc.loader.annotation.IocBean;
|
13 | 17 | import org.nutz.mvc.annotation.At;
|
14 | 18 | import org.nutz.mvc.annotation.By;
|
|
20 | 24 | import org.slf4j.LoggerFactory;
|
21 | 25 |
|
22 | 26 | @IocBean
|
23 |
| -@Filters(@By(type = AuthoritiesManager.class, args = {"userType", "1", "/login.jsp"})) |
| 27 | +@Filters(@By(type = AuthoritiesManager.class, args = { "userType", "1", "/login.jsp" })) |
24 | 28 | public class GroupAction {
|
25 | 29 |
|
26 |
| - private static final Logger LOG = LoggerFactory.getLogger(GroupAction.class) ; |
| 30 | + private static final Logger LOG = LoggerFactory.getLogger(GroupAction.class); |
27 | 31 |
|
28 |
| - public BasicDao basicDao = StaticValue.systemDao; |
| 32 | + public BasicDao basicDao = StaticValue.systemDao; |
29 | 33 |
|
30 |
| - @At("/auth/delUserGroup") |
31 |
| - @Ok("raw") |
32 |
| - @Fail("jsp:/fail.jsp") |
33 |
| - public boolean delUserGroup(@Param("id") long id) throws Exception { |
34 |
| - boolean flag = basicDao.delById(id, UserGroup.class); |
35 |
| - if (flag) { |
36 |
| - LOG.info("add userGroup which id:" + id); |
37 |
| - } |
38 |
| - return flag; |
39 |
| - } |
| 34 | + @Inject |
| 35 | + private TaskService taskService; |
40 | 36 |
|
41 |
| - @At("/auth/updateUserGroup") |
42 |
| - @Ok("raw") |
43 |
| - public boolean updateUserGroup(@Param("groupId") Long groupId, @Param("auth") Integer auth, @Param("userId") Long userId) throws Exception { |
44 |
| - Condition con = Cnd.where("groupId", "=", groupId).and("userId", "=", userId); |
45 |
| - UserGroup userGroup = basicDao.findByCondition(UserGroup.class, con); |
46 |
| - if (userGroup == null) { |
47 |
| - userGroup = new UserGroup(); |
48 |
| - userGroup.setUserId(userId); |
49 |
| - userGroup.setGroupId(groupId); |
50 |
| - userGroup.setCreateTime(new Date()); |
51 |
| - } |
| 37 | + @At("/auth/delUserGroup") |
| 38 | + @Ok("raw") |
| 39 | + @Fail("jsp:/fail.jsp") |
| 40 | + public boolean delUserGroup(@Param("id") long id) throws Exception { |
52 | 41 |
|
53 |
| - if (auth == 0) { |
54 |
| - basicDao.delById(userGroup.getId(), UserGroup.class); |
55 |
| - } else { |
56 |
| - userGroup.setAuth(auth); |
57 |
| - if (userGroup.getId() == null) { |
58 |
| - basicDao.save(userGroup); |
59 |
| - } else { |
60 |
| - basicDao.update(userGroup); |
61 |
| - } |
62 |
| - } |
| 42 | + List<Task> tasksList = taskService.tasksList(id); // 从数据库中查出,不污染内存中的task |
63 | 43 |
|
64 |
| - return true; |
65 |
| - } |
| 44 | + for (Task task : tasksList) { |
| 45 | + taskService.delete(task); |
| 46 | + taskService.delByDB(task); |
| 47 | + } |
66 | 48 |
|
67 |
| - /** |
68 |
| - * 列出用户的所有权限 |
69 |
| - * |
70 |
| - * @param userId |
71 |
| - * @return |
72 |
| - * @throws Exception |
73 |
| - */ |
74 |
| - @At("/auth/authUser") |
75 |
| - @Ok("json") |
76 |
| - public List<UserGroup> authUser(@Param("userId") long userId) throws Exception { |
77 |
| - return basicDao.search(UserGroup.class, Cnd.where("userId", "=", userId)); |
78 |
| - } |
| 49 | + boolean flag = basicDao.delById(id, UserGroup.class); |
| 50 | + if (flag) { |
| 51 | + LOG.info("add userGroup which id:" + id); |
| 52 | + } |
| 53 | + return flag; |
| 54 | + } |
| 55 | + |
| 56 | + @At("/auth/updateUserGroup") |
| 57 | + @Ok("raw") |
| 58 | + public boolean updateUserGroup(@Param("groupId") Long groupId, @Param("auth") Integer auth, @Param("userId") Long userId) throws Exception { |
| 59 | + Condition con = Cnd.where("groupId", "=", groupId).and("userId", "=", userId); |
| 60 | + UserGroup userGroup = basicDao.findByCondition(UserGroup.class, con); |
| 61 | + if (userGroup == null) { |
| 62 | + userGroup = new UserGroup(); |
| 63 | + userGroup.setUserId(userId); |
| 64 | + userGroup.setGroupId(groupId); |
| 65 | + userGroup.setCreateTime(new Date()); |
| 66 | + } |
| 67 | + |
| 68 | + if (auth == 0) { |
| 69 | + basicDao.delById(userGroup.getId(), UserGroup.class); |
| 70 | + } else { |
| 71 | + userGroup.setAuth(auth); |
| 72 | + if (userGroup.getId() == null) { |
| 73 | + basicDao.save(userGroup); |
| 74 | + } else { |
| 75 | + basicDao.update(userGroup); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return true; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * 列出用户的所有权限 |
| 84 | + * |
| 85 | + * @param userId |
| 86 | + * @return |
| 87 | + * @throws Exception |
| 88 | + */ |
| 89 | + @At("/auth/authUser") |
| 90 | + @Ok("json") |
| 91 | + public List<UserGroup> authUser(@Param("userId") long userId) throws Exception { |
| 92 | + return basicDao.search(UserGroup.class, Cnd.where("userId", "=", userId)); |
| 93 | + } |
79 | 94 | }
|
0 commit comments