BaseNoticeController.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package com.ozs.web.controller.base;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.ozs.base.domain.BaseNotice;
  6. import com.ozs.base.domain.BaseNoticeType;
  7. import com.ozs.base.service.BaseNoticeService;
  8. import com.ozs.base.service.BaseNoticeTypeService;
  9. import com.ozs.base.vo.BaseNoticePageReqVo;
  10. import com.ozs.base.vo.BaseNoticeVo;
  11. import com.ozs.common.annotation.Log;
  12. import com.ozs.common.constant.Constants;
  13. import com.ozs.common.constant.ModularConstans;
  14. import com.ozs.common.core.controller.BaseController;
  15. import com.ozs.common.core.domain.AjaxResult;
  16. import com.ozs.common.core.domain.entity.SysDept;
  17. import com.ozs.common.core.domain.entity.SysRole;
  18. import com.ozs.common.enums.BusinessType;
  19. import com.ozs.plan.doman.MonthlyReconciliation;
  20. import com.ozs.system.service.ISysDeptService;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.security.access.prepost.PreAuthorize;
  27. import org.springframework.util.ObjectUtils;
  28. import org.springframework.web.bind.annotation.*;
  29. import javax.validation.constraints.NotEmpty;
  30. import java.util.Date;
  31. import java.util.List;
  32. import java.util.stream.Collectors;
  33. @Api(tags = ModularConstans.notice)
  34. @RestController
  35. @RequestMapping("/base/notice")
  36. public class BaseNoticeController extends BaseController {
  37. @Autowired
  38. private BaseNoticeService baseNoticeService;
  39. @Autowired
  40. private BaseNoticeTypeService baseNoticeTypeService;
  41. @Autowired
  42. private ISysDeptService iSysDeptService;
  43. @ApiOperation(value = "分页查询公告信息")
  44. @PostMapping("/page")
  45. @PreAuthorize("@ss.hasPermi('base:notice:list')")
  46. @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY)
  47. public AjaxResult page(@NotEmpty(message = "数据为空")
  48. @RequestBody BaseNoticePageReqVo vo) {
  49. LambdaQueryWrapper<BaseNotice> lw = new LambdaQueryWrapper<>();
  50. if (!StringUtils.isBlank(vo.getTitle())) {
  51. lw.like(BaseNotice::getTitle, vo.getTitle());
  52. }
  53. if (!ObjectUtils.isEmpty(vo.getStartTime())) {
  54. lw.ge(BaseNotice::getReleaseTime, vo.getStartTime());
  55. }
  56. if (!ObjectUtils.isEmpty(vo.getStartTime())) {
  57. lw.le(BaseNotice::getReleaseTime, vo.getEntTime());
  58. }
  59. if (!ObjectUtils.isEmpty(vo.getType())) {
  60. lw.eq(BaseNotice::getType, vo.getType());
  61. }
  62. lw.orderByDesc(BaseNotice::getReleaseTime);
  63. IPage<BaseNotice> page = baseNoticeService.page(new Page<>(vo.getPageNum(), vo.getPageSize()), lw);
  64. IPage<BaseNoticeVo> pagev = new Page<>();
  65. pagev.setTotal(page.getTotal());
  66. pagev.setCurrent(page.getCurrent());
  67. pagev.setPages(page.getPages());
  68. if (!ObjectUtils.isEmpty(page) && page.getRecords().size() > 0) {
  69. List<BaseNoticeType> list = baseNoticeTypeService.list();
  70. List<Long> ids = list.stream().map(BaseNoticeType::getId).collect(Collectors.toList());
  71. List<BaseNoticeVo> collect = page.getRecords().stream().map(o -> {
  72. BaseNoticeVo baseNoticeVo = new BaseNoticeVo();
  73. BeanUtils.copyProperties(o, baseNoticeVo);
  74. if (ids.contains(o.getType())) {
  75. List<BaseNoticeType> collect1 = list.stream().filter(tdto -> tdto.getId().equals(o.getType())).collect(Collectors.toList());
  76. if(!ObjectUtils.isEmpty(collect1)){
  77. baseNoticeVo.setTypeName(collect1.get(0).getName());
  78. }
  79. }
  80. return baseNoticeVo;
  81. }).collect(Collectors.toList());
  82. pagev.setRecords(collect);
  83. }else {
  84. pagev.setRecords(null);
  85. }
  86. return success(pagev);
  87. }
  88. @ApiOperation(value = "新增公告信息")
  89. @PostMapping("/insert")
  90. @PreAuthorize("@ss.hasPermi('base:notice:add')")
  91. @Log(title = ModularConstans.notice, businessType = BusinessType.INSERT)
  92. public AjaxResult insert(@NotEmpty(message = "数据为空")
  93. @RequestBody BaseNotice vo) {
  94. vo.setCreated(getUserId().toString());
  95. vo.setCreateTime(new Date());
  96. vo.setUpdated(vo.getCreated());
  97. vo.setUpdateTime(vo.getCreateTime());
  98. return toAjax(baseNoticeService.save(vo));
  99. }
  100. @ApiOperation(value = "删除公告信息")
  101. @PostMapping("/remove")
  102. @PreAuthorize("@ss.hasPermi('base:notice:remove')")
  103. @Log(title = ModularConstans.notice, businessType = BusinessType.DELETE)
  104. public AjaxResult remove(@NotEmpty(message = "主键id不能为空")
  105. @RequestBody List<Long> ids) {
  106. return toAjax(baseNoticeService.removeBatchByIds(ids));
  107. }
  108. @ApiOperation(value = "查看公告信息")
  109. @PostMapping("/getInfo")
  110. @PreAuthorize("@ss.hasPermi('base:notice:query')")
  111. @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY)
  112. public AjaxResult getInfo(@NotEmpty(message = "主键id不能为空")
  113. @RequestParam(value = "id", required = true)
  114. Long id) {
  115. BaseNotice vo = baseNoticeService.getById(id);
  116. BaseNoticeVo baseNoticeVo = new BaseNoticeVo();
  117. if(!ObjectUtils.isEmpty(vo)){
  118. BeanUtils.copyProperties(vo, baseNoticeVo);
  119. List<BaseNoticeType> list = baseNoticeTypeService.list();
  120. List<BaseNoticeType> collect1 = list.stream().filter(tdto -> tdto.getId().equals(vo.getType())).collect(Collectors.toList());
  121. if(!ObjectUtils.isEmpty(collect1)){
  122. baseNoticeVo.setTypeName(collect1.get(0).getName());
  123. }
  124. }
  125. return success(baseNoticeVo);
  126. }
  127. @ApiOperation(value = "首页分页查询公告信息")
  128. @PostMapping("/homePage")
  129. @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY)
  130. public AjaxResult homePage(@NotEmpty(message = "数据为空")
  131. @RequestBody BaseNoticePageReqVo vo) {
  132. // LambdaQueryWrapper<BaseNotice> lw = new LambdaQueryWrapper<>();
  133. // if(!StringUtils.isBlank(vo.getTitle())){
  134. // lw.like(BaseNotice::getTitle,vo.getTitle());
  135. // }
  136. // if(!ObjectUtils.isEmpty(vo.getStartTime())){
  137. // lw.ge(BaseNotice::getReleaseTime,vo.getStartTime());
  138. // }
  139. // if(!ObjectUtils.isEmpty(vo.getStartTime())){
  140. // lw.le(BaseNotice::getReleaseTime,vo.getEntTime());
  141. // }
  142. // if (!ObjectUtils.isEmpty(vo.getType())) {
  143. // lw.eq(BaseNotice::getType, vo.getType());
  144. // }
  145. // lw.orderByDesc(BaseNotice::getReleaseTime);
  146. vo.setUserId(getUserId());
  147. vo.setDeptId(getDeptId());
  148. IPage<BaseNotice> page = baseNoticeService.queryPage(vo);
  149. IPage<BaseNoticeVo> pagev = new Page<>();
  150. pagev.setTotal(page.getTotal());
  151. pagev.setCurrent(page.getCurrent());
  152. pagev.setPages(page.getPages());
  153. if (!ObjectUtils.isEmpty(page) && page.getRecords().size() > 0) {
  154. List<BaseNoticeType> list = baseNoticeTypeService.list();
  155. List<Long> ids = list.stream().map(BaseNoticeType::getId).collect(Collectors.toList());
  156. List<BaseNoticeVo> collect = page.getRecords().stream().map(o -> {
  157. BaseNoticeVo baseNoticeVo = new BaseNoticeVo();
  158. BeanUtils.copyProperties(o, baseNoticeVo);
  159. if (ids.contains(o.getType())) {
  160. List<BaseNoticeType> collect1 = list.stream().filter(tdto -> tdto.getId().equals(o.getType())).collect(Collectors.toList());
  161. if(!ObjectUtils.isEmpty(collect1)){
  162. baseNoticeVo.setTypeName(collect1.get(0).getName());
  163. }
  164. }
  165. return baseNoticeVo;
  166. }).collect(Collectors.toList());
  167. pagev.setRecords(collect);
  168. }else {
  169. pagev.setRecords(null);
  170. }
  171. return success(pagev);
  172. }
  173. }