|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.plugins.Page; | 
|---|
|  |  |  | import com.zy.system.entity.Resource; | 
|---|
|  |  |  | import com.zy.system.service.ResourceService; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.controller.AbstractBaseController; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.system.entity.Resource; | 
|---|
|  |  |  | import com.zy.system.service.ResourceService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class ResourceController extends AbstractBaseController { | 
|---|
|  |  |  | public class ResourceController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ResourceService resourceService; | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(resourceService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void convert(Map<String, Object> map, EntityWrapper wrapper){ | 
|---|
|  |  |  | @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()){ | 
|---|
|  |  |  | if (entry.getKey().endsWith(">")) { | 
|---|
|  |  |  | wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); | 
|---|
|  |  |  | } else if (entry.getKey().endsWith("<")) { | 
|---|
|  |  |  | wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); | 
|---|
|  |  |  | 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.eq(entry.getKey(), String.valueOf(entry.getValue())); | 
|---|
|  |  |  | wrapper.like(entry.getKey(), val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|