| | |
| | | package com.zy.system.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | |
| | | @RequestMapping(value = "/announcement/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok(announcementService.selectById(String.valueOf(id))); |
| | | return R.ok(announcementService.getById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/announcement/list/auth") |
| | |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | excludeTrash(param); |
| | | EntityWrapper<Announcement> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<Announcement> wrapper = new QueryWrapper<>(); |
| | | convert(param, wrapper); |
| | | if (!Cools.isEmpty(orderByField)){ |
| | | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); |
| | | wrapper.orderBy(true, "asc".equals(orderByType), humpToLine(orderByField)); |
| | | } |
| | | return R.ok(announcementService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | return R.ok(announcementService.page(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private void convert(Map<String, Object> map, EntityWrapper wrapper){ |
| | | private void convert(Map<String, Object> map, QueryWrapper wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if ("status".equals(entry.getKey())) { |
| | | wrapper.eq(entry.getKey(), entry.getValue()); |
| | |
| | | if (null == announcement.getId()){ |
| | | announcement.setCreateTime(new Date()); |
| | | announcement.setUpdateTime(new Date()); |
| | | announcementService.insert(announcement); |
| | | announcementService.save(announcement); |
| | | } else { |
| | | announcement.setUpdateTime(new Date()); |
| | | announcementService.updateById(announcement); |
| | |
| | | public R add(Announcement announcement) { |
| | | announcement.setCreateTime(new Date()); |
| | | announcement.setUpdateTime(new Date()); |
| | | announcementService.insert(announcement); |
| | | announcementService.save(announcement); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | if (Cools.isEmpty(ids)){ |
| | | return R.error(); |
| | | } |
| | | announcementService.deleteBatchIds(Arrays.asList(ids)); |
| | | announcementService.removeByIds(Arrays.asList(ids)); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | EntityWrapper<Announcement> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<Announcement> wrapper = new QueryWrapper<>(); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("announcement")); |
| | | convert(map, wrapper); |
| | | List<Announcement> list = announcementService.selectList(wrapper); |
| | | List<Announcement> list = announcementService.list(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | @GetMapping("/announcement/top5") |
| | | public R top5(){ |
| | | EntityWrapper<Announcement> wrapper = new EntityWrapper<>(); |
| | | QueryWrapper<Announcement> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("status", 1); |
| | | wrapper.orderBy("create_time", false); |
| | | wrapper.orderBy(true, false, "create_time"); |
| | | wrapper.last("limit 5"); |
| | | return R.ok(announcementService.selectList(wrapper)); |
| | | return R.ok(announcementService.list(wrapper)); |
| | | } |
| | | } |