package cn.stylefeng.guns.workflow.modular.controller; import cn.stylefeng.guns.sys.modular.system.entity.Role; import cn.stylefeng.guns.sys.modular.system.mapper.RoleMapper; import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper; import cn.stylefeng.roses.core.util.ToolUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Act通用Controller * * @author stylefeng * @date 2019/8/27 - 17:34 */ @Controller @RequestMapping("/common") public class ActCommonController { @Autowired private UserMapper userMapper; @Autowired private RoleMapper roleMapper; /** * 设置用户页面 * * @author yaopu * @date 2019/8/30 - 09:34 */ @RequestMapping(value = "/toSetUserPage") public String toSetUserPage() { return "/modular/act/model/user.html"; } /** * 设置角色页面 * * @author yaopu * @date 2019/8/30 - 09:34 */ @RequestMapping(value = "/toSetRolePage") public String toSetRolePage() { return "/modular/act/model/role.html"; } /** * 显示用户列表(弹窗选择用) * * @author stylefeng * @date 2019/8/27 - 17:34 */ @RequestMapping(value = "/listUsersForWindow") @ResponseBody public Object listUsersForWindow(@RequestParam("currentPage") Integer currentPage, @RequestParam("showCount") Integer showCount, @RequestParam(value = "KEYWORDS", required = false) String keywords, @RequestParam("ROLE_ID") String roleId, @RequestParam(value = "STRARTTIME", required = false) String strarttime) { Page page = new Page(); page.setCurrent(currentPage); if (showCount == -1) { showCount = 10; } page.setSize(showCount); //查询人员列表信息 Page> mapPage = userMapper.selectUsersByRole(page, keywords, strarttime, null, roleId); List> records = mapPage.getRecords(); //查询角色信息 Page rolePage = new Page(); rolePage.setSize(9999); IPage> listRole = roleMapper.listRole(rolePage, null); List> roleList = listRole.getRecords(); //设置前端所需参数 if (ToolUtil.isNotEmpty(records) && records.size() > 0) { for (int i = 0; i < records.size(); i++) { records.get(i).put("USERNAME", records.get(i).get("account")); records.get(i).put("NAME", records.get(i).get("name")); String roleIdItem = (String) records.get(i).get("roleId"); String[] split = roleIdItem.split(","); List roles = roleMapper.selectBatchIds(Arrays.asList(split)); StringBuilder roleNameString = new StringBuilder(""); for (int j = 0; j < roles.size(); j++) { if (j == roles.size() - 1) { roleNameString.append(roles.get(j).getName()); break; } roleNameString.append(roles.get(j).getName()).append(","); } records.get(i).put("ROLE_NAME", roleNameString); } } if (ToolUtil.isNotEmpty(roleList) && roleList.size() > 0) { for (int i = 0; i < roleList.size(); i++) { roleList.get(i).put("role_NAME", roleList.get(i).get("name")); roleList.get(i).put("role_ID", roleList.get(i).get("id")); } } //分页信息 int totalResult = (int) page.getTotal(); int totalPage = (int) page.getPages(); int currentResult = (currentPage - 1) * showCount; if (currentResult < 0) { currentResult = 0; } Map pageInfo = new HashMap<>(); pageInfo.put("showCount", showCount); pageInfo.put("totalPage", totalPage); pageInfo.put("totalResult", totalResult); pageInfo.put("currentPage", currentPage); pageInfo.put("currentResult", currentResult); pageInfo.put("entityOrField", true); pageInfo.put("pageStr", getPageStr(totalResult, currentPage, totalPage, showCount)); pageInfo.put("pageStrSimplify", getPageStrSimplify(totalResult, currentPage, totalPage)); pageInfo.put("pageStrSimplify2", getPageStrSimplify2(totalResult, currentPage, totalPage)); //返回结果 Map resultMap = new HashMap<>(); resultMap.put("userList", records); resultMap.put("result", "success"); resultMap.put("roleList", roleList); resultMap.put("page", pageInfo); resultMap.put("pd", ""); return resultMap; } /** * 选择角色(弹窗选择用) * * @author stylefeng * @date 2019/8/28 - 13:10 */ @RequestMapping(value = "/roleListWindow") @ResponseBody public Object roleListWindow(@RequestParam("currentPage") Integer currentPage, @RequestParam("showCount") Integer showCount, @RequestParam("KEYWORDS") String keywords) { Page page = new Page(); page.setCurrent(currentPage); if (showCount == -1) { showCount = 10; } page.setSize(showCount); //查询角色列表信息 Page> mapPage = roleMapper.selectRoles(page, keywords); List> records = mapPage.getRecords(); //设置前端所需参数 if (ToolUtil.isNotEmpty(records) && records.size() > 0) { for (int i = 0; i < records.size(); i++) { records.get(i).put("RNUMBER", records.get(i).get("roleId")); records.get(i).put("ROLE_NAME", records.get(i).get("name")); } } //分页信息 int totalResult = (int) page.getTotal(); int totalPage = (int) page.getPages(); int currentResult = (currentPage - 1) * showCount; if (currentResult < 0) { currentResult = 0; } Map pageInfo = new HashMap<>(); pageInfo.put("showCount", showCount); pageInfo.put("totalPage", totalPage); pageInfo.put("totalResult", totalResult); pageInfo.put("currentPage", currentPage); pageInfo.put("currentResult", currentResult); pageInfo.put("entityOrField", true); pageInfo.put("pageStr", getPageStr(totalResult, currentPage, totalPage, showCount)); pageInfo.put("pageStrSimplify", getPageStrSimplify(totalResult, currentPage, totalPage)); pageInfo.put("pageStrSimplify2", getPageStrSimplify2(totalResult, currentPage, totalPage)); //返回结果 Map resultMap = new HashMap<>(); resultMap.put("roleList", records); resultMap.put("result", "success"); resultMap.put("page", pageInfo); return resultMap; } /** * 拼接分页 页面及JS函数 * * @author fengshuonan * @Date 2019-08-29 14:10 */ private String getPageStr(int totalResult, int currentPage, int totalPage, int showCount) { StringBuffer sb = new StringBuffer(); if (totalResult > 0) { sb.append(" \n"); } return sb.toString(); } /** * 拼接分页 页面及JS函数 * * @author fengshuonan * @Date 2019-08-29 14:10 */ private String getPageStrSimplify(int totalResult, int currentPage, int totalPage) { StringBuilder buffer = new StringBuilder(); if (totalResult > 0) { buffer.append(" \n"); } return buffer.toString(); } /** * 拼接分页 页面及JS函数 * * @author fengshuonan * @Date 2019-08-29 14:11 */ public String getPageStrSimplify2(int totalResult, int currentPage, int totalPage) { StringBuilder sb = new StringBuilder(); if (totalResult > 0) { sb.append(" \n"); } return sb.toString(); } }