|
@@ -0,0 +1,152 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.dto.GroupDTO;
|
|
|
+import com.welampiot.dto.PolicyDTO;
|
|
|
+import com.welampiot.dto.UserDTO;
|
|
|
+import com.welampiot.service.GroupService;
|
|
|
+import com.welampiot.service.PolicyService;
|
|
|
+import com.welampiot.service.UserService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.GroupVO;
|
|
|
+import com.welampiot.vo.ListResponseVO;
|
|
|
+import com.welampiot.vo.PolicyVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import static com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken.Policy;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/policy")
|
|
|
+public class PolicyController{
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PolicyService policyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GroupService groupService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private PolicyCmdMapper policyCmdMapper;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private GroupMapper groupMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 策略列表
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/getlist")
|
|
|
+ private BaseResult getList(HttpServletRequest request){
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
|
|
|
+ Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
|
|
|
+ page = page == 0 ? 1 : page;
|
|
|
+ count = count == 0 ? 16 : count;
|
|
|
+ toolUtils.getSectionList(request);
|
|
|
+ Integer userId = toolUtils.getUser().getId();
|
|
|
+ Integer role = toolUtils.getUser().getRole();
|
|
|
+ String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
|
|
|
+ List userList = new ArrayList<>();
|
|
|
+ Map w;
|
|
|
+ if (role != 1){
|
|
|
+ userList.add(userId);
|
|
|
+ w = new HashMap<>();
|
|
|
+ w.put("parent_id",userId);
|
|
|
+ List<UserDTO> listByParentId = userService.getListByParentId(userId);
|
|
|
+ for (UserDTO user :listByParentId) {
|
|
|
+ userList.add(user.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer limit = count;
|
|
|
+ Integer offset = (page-1)*count;
|
|
|
+ PolicyVO policyVO = new PolicyVO();
|
|
|
+ policyVO.setUserList(userList);
|
|
|
+ policyVO.setOffset(offset);
|
|
|
+ policyVO.setLimit(limit);
|
|
|
+ if (keyword != null && keyword.length() != 0) policyVO.setKeyword(keyword);
|
|
|
+ List<PolicyDTO> listByVO = policyService.getListByVO(policyVO);
|
|
|
+ policyVO = new PolicyVO();
|
|
|
+ policyVO.setUserList(userList);
|
|
|
+ if (keyword != null && keyword.length() != 0) policyVO.setKeyword(keyword);
|
|
|
+ Integer countByVO = policyService.getCountByVO(policyVO);
|
|
|
+ ListResponseVO listResponseVO = new ListResponseVO();
|
|
|
+ listResponseVO.setList(listByVO);
|
|
|
+ listResponseVO.setTotal((int)Math.ceil((double)countByVO/count));
|
|
|
+
|
|
|
+ return toolUtils.response("0000",version,listResponseVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分组设置 策略列表
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/groupSetList")
|
|
|
+ private BaseResult groupSetList(HttpServletRequest request){
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer groupId = (Integer) toolUtils.getRequestContent(request,"groupId",1);
|
|
|
+ toolUtils.getSectionList(request);
|
|
|
+ Integer userId = (Integer) toolUtils.getUser().getId();
|
|
|
+ Integer role = (Integer) toolUtils.getUser().getRole();
|
|
|
+ List userList = new ArrayList<>();
|
|
|
+ Map w;
|
|
|
+ if (role != 1){
|
|
|
+ userList.add(userId);
|
|
|
+ w = new HashMap<>();
|
|
|
+ w.put("parent_id",userId);
|
|
|
+ List<UserDTO> list = userService.getListByParentId(userId);
|
|
|
+ if (list != null && !list.isEmpty()){
|
|
|
+ for (UserDTO u :list) {
|
|
|
+ userList.add(u.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PolicyVO policyVO = new PolicyVO();
|
|
|
+ policyVO.setUserList(userList);
|
|
|
+ List<PolicyDTO> listByUser = policyService.getNavByVO(policyVO);
|
|
|
+ List list = new ArrayList<>();
|
|
|
+ if (groupId != 0){
|
|
|
+ GroupVO groupVO = new GroupVO();
|
|
|
+ groupVO.setId(groupId);
|
|
|
+ groupVO.setVersion(version);
|
|
|
+ GroupDTO group = groupService.getDetailByVO(groupVO);
|
|
|
+ PolicyDTO temp = null;
|
|
|
+ List listT = new ArrayList<>();
|
|
|
+ for (int i = 0; i < listByUser.size(); i++) {
|
|
|
+ PolicyDTO m = listByUser.get(i);
|
|
|
+ Integer id = m.getId();
|
|
|
+ if (group.getValue().intValue() == id.intValue() && group.getType() == 1){
|
|
|
+ temp = m;
|
|
|
+ temp.setSelect(1);
|
|
|
+ }else {
|
|
|
+ m.setSelect(0);
|
|
|
+ listT.add(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (temp != null){
|
|
|
+ list.add(temp);
|
|
|
+ }
|
|
|
+ for (Object o :listT) {
|
|
|
+ list.add(o);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ListResponseVO listResponseVO = new ListResponseVO();
|
|
|
+ listResponseVO.setList(list);
|
|
|
+ return toolUtils.response("0000",version,listResponseVO);
|
|
|
+ }
|
|
|
+}
|