|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class ResourceController extends BaseController { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/resource/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | EntityWrapper<Resource> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(resourceService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | @RequestMapping(value = "/resource/tree/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R tree(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | EntityWrapper<Resource> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)) { | 
|---|
|  |  |  | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.orderBy("sort"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.parse("0-操作成功").add(resourceService.selectList(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)){ | 
|---|
|  |  |  | 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])); | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/resource/edit/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "菜单编辑") | 
|---|
|  |  |  | public R edit(Resource resource) { | 
|---|
|  |  |  | if (Cools.isEmpty(resource)){ | 
|---|
|  |  |  | if (Cools.isEmpty(resource)) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null == resource.getId()){ | 
|---|
|  |  |  | if (resource.getSort() == null){ | 
|---|
|  |  |  | if (null == resource.getId()) { | 
|---|
|  |  |  | if (resource.getSort() == null) { | 
|---|
|  |  |  | resource.setSort(999); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resourceService.insert(resource); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/resource/update/auth") | 
|---|
|  |  |  | @RequestMapping(value = "/resource/update/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "菜单修改") | 
|---|
|  |  |  | public R update(Resource resource){ | 
|---|
|  |  |  | if (Cools.isEmpty(resource) || null==resource.getId()){ | 
|---|
|  |  |  | public R update(Resource resource) { | 
|---|
|  |  |  | if (Cools.isEmpty(resource) || null == resource.getId()) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resourceService.updateById(resource); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    @RequestMapping(value = "/resource/delete/auth") | 
|---|
|  |  |  | //    @ManagerAuth(memo = "菜单删除") | 
|---|
|  |  |  | //    public R delete(Integer[] ids){ | 
|---|
|  |  |  | //        if (Cools.isEmpty(ids)){ | 
|---|
|  |  |  | //            return R.error(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        resourceService.deleteBatchIds(Arrays.asList(ids)); | 
|---|
|  |  |  | //        return R.ok(); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/resource/delete/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "菜单删除") | 
|---|
|  |  |  | public R delete(Integer[] ids){ | 
|---|
|  |  |  | if (Cools.isEmpty(ids)){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestParam(value = "ids[]") Long[] ids) { | 
|---|
|  |  |  | for (Long id : ids) { | 
|---|
|  |  |  | resourceService.deleteById(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resourceService.deleteBatchIds(Arrays.asList(ids)); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/resource/export/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "菜单导出") | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param) { | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | EntityWrapper<Resource> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("resource")); | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.like("name", condition); | 
|---|
|  |  |  | Page<Resource> page = resourceService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Resource resource : page.getRecords()){ | 
|---|
|  |  |  | for (Resource resource : page.getRecords()) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("id", resource.getId()); | 
|---|
|  |  |  | map.put("value", resource.getName().concat("(").concat(resource.getLevel$().substring(0, 2).concat(")"))); | 
|---|