BaseNoticeController.java 8.5 KB

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