|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.common.sys.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.common.sys.entity.Role; | 
|---|
|  |  |  | import com.zy.asrs.common.sys.service.RoleService; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PathVariable; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | EntityWrapper<Role> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | wrapper.orderBy("id", false); | 
|---|
|  |  |  | LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.orderByDesc(Role::getId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (9527 == getUserId()) { | 
|---|
|  |  |  | return R.ok(roleService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | return R.ok(roleService.page(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long roleId = getUser().getRoleId(); | 
|---|
|  |  |  | Role role = roleService.selectById(roleId); | 
|---|
|  |  |  | Role role = roleService.getById(roleId); | 
|---|
|  |  |  | Long leaderId = role.getLeader(); | 
|---|
|  |  |  | if (null != leaderId) { | 
|---|
|  |  |  | List<Long> leaderIds = new ArrayList<>(); | 
|---|
|  |  |  | leaderIds.add(roleId); | 
|---|
|  |  |  | while (leaderId != null) { | 
|---|
|  |  |  | Role leader = roleService.selectById(leaderId); | 
|---|
|  |  |  | Role leader = roleService.getById(leaderId); | 
|---|
|  |  |  | leaderIds.add(leader.getId()); | 
|---|
|  |  |  | leaderId = leader.getLeader(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.notIn("id", leaderIds); | 
|---|
|  |  |  | wrapper.notIn(Role::getId, leaderIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (null != role.getLevel()) { | 
|---|
|  |  |  | //            wrapper.gt("level", role.getLevel()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | return R.ok(roleService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | return R.ok(roleService.page(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | String val = String.valueOf(entry.getValue()); | 
|---|
|  |  |  | if (val.contains(RANGE_TIME_LINK)){ | 
|---|
|  |  |  | String[] dates = val.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
|---|
|  |  |  | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.like(entry.getKey(), val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/role/edit/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "角色编辑") | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/role/add/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "角色添加") | 
|---|
|  |  |  | public R add(Role role) { | 
|---|
|  |  |  | roleService.insert(role); | 
|---|
|  |  |  | roleService.save(role); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(ids)){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | roleService.deleteBatchIds(Arrays.asList(ids)); | 
|---|
|  |  |  | roleService.removeByIds(Arrays.asList(ids)); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/role/export/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "角色导出") | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | EntityWrapper<Role> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("role")); | 
|---|
|  |  |  | convert(map, wrapper); | 
|---|
|  |  |  | List<Role> list = roleService.selectList(wrapper); | 
|---|
|  |  |  | return R.ok(exportSupport(list, fields)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/roleQuery/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R query(String condition) { | 
|---|
|  |  |  | EntityWrapper<Role> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.like("name", condition); | 
|---|
|  |  |  | LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.like(Role::getName, condition); | 
|---|
|  |  |  | // 上下级管理 | 
|---|
|  |  |  | if (9527 != getUserId()) { | 
|---|
|  |  |  | Long roleId = getUser().getRoleId(); | 
|---|
|  |  |  | Role role = roleService.selectById(roleId); | 
|---|
|  |  |  | Role role = roleService.getById(roleId); | 
|---|
|  |  |  | Long leaderId = role.getLeader(); | 
|---|
|  |  |  | if (null != leaderId) { | 
|---|
|  |  |  | List<Long> leaderIds = new ArrayList<>(); | 
|---|
|  |  |  | while (leaderId != null) { | 
|---|
|  |  |  | Role leader = roleService.selectById(leaderId); | 
|---|
|  |  |  | Role leader = roleService.getById(leaderId); | 
|---|
|  |  |  | leaderIds.add(leader.getId()); | 
|---|
|  |  |  | leaderId = leader.getLeader(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wrapper.notIn("id", leaderIds); | 
|---|
|  |  |  | wrapper.notIn(Role::getId, leaderIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            if (null != role.getLevel()) { | 
|---|
|  |  |  | //                wrapper.ge("level", role.getLevel()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<Role> page = roleService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | Page<Role> page = roleService.page(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Role role : page.getRecords()){ | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|