HomeNoticeController.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package com.ozs.web.controller.home;
  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.common.annotation.Log;
  6. import com.ozs.common.constant.ModularConstans;
  7. import com.ozs.common.core.controller.BaseController;
  8. import com.ozs.common.core.domain.AjaxResult;
  9. import com.ozs.common.core.domain.entity.SysUser;
  10. import com.ozs.common.enums.BusinessType;
  11. import com.ozs.common.utils.SecurityUtils;
  12. import com.ozs.common.utils.StringUtils;
  13. import com.ozs.home.domain.HomeNotice;
  14. import com.ozs.home.domain.vo.HomeNoticeVo;
  15. import com.ozs.home.domain.vo.HomeToDoQueryResVo;
  16. import com.ozs.home.service.HomeNoticeService;
  17. import com.ozs.plan.doman.PlanQuarter;
  18. import com.ozs.plan.doman.PlanYears;
  19. import com.ozs.plan.doman.vo.requestVo.PlanYearsStandardVo;
  20. import com.ozs.plan.service.PlanQuarterService;
  21. import com.ozs.plan.service.PlanYearsService;
  22. import com.ozs.pm.doman.PmDemand;
  23. import com.ozs.pm.doman.PmDemandExpertRef;
  24. import com.ozs.pm.service.IPmDemandService;
  25. import io.swagger.annotations.ApiOperation;
  26. import org.springframework.beans.BeanUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.security.access.prepost.PreAuthorize;
  29. import org.springframework.util.ObjectUtils;
  30. import org.springframework.web.bind.annotation.PostMapping;
  31. import org.springframework.web.bind.annotation.RequestBody;
  32. import org.springframework.web.bind.annotation.RequestMapping;
  33. import org.springframework.web.bind.annotation.RestController;
  34. import javax.annotation.Resource;
  35. import java.text.ParseException;
  36. import java.text.SimpleDateFormat;
  37. import java.util.Date;
  38. import java.util.List;
  39. import java.util.Map;
  40. /**
  41. * 首页公告控制层
  42. *
  43. * @author buzhanyi
  44. */
  45. @RestController
  46. @RequestMapping("/home/homeNotice")
  47. public class HomeNoticeController extends BaseController {
  48. @Resource
  49. private HomeNoticeService homeNoticeService;
  50. @Autowired
  51. private PlanYearsService planYearsService;
  52. @Autowired
  53. private PlanQuarterService planQuarterService;
  54. @Autowired
  55. private IPmDemandService demandService;
  56. @ApiOperation(value = "查询首页公告")
  57. @PostMapping("/selectHomeNotice")
  58. // @PreAuthorize("@ss.hasPermi('home:homeNotice:selecthomeNotice')")
  59. @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY)
  60. public AjaxResult selectHomeNotice(@RequestBody HomeNoticeVo homeNoticeVo) {
  61. LambdaQueryWrapper<HomeNotice> lw = new LambdaQueryWrapper<HomeNotice>();
  62. if (!StringUtils.isBlank(homeNoticeVo.getNoticeName())) {
  63. lw.like(HomeNotice::getNoticeName, "%" + homeNoticeVo.getNoticeName() + "%");
  64. }
  65. if (!StringUtils.isBlank(homeNoticeVo.getAnnouncementClassification())) {
  66. lw.eq(HomeNotice::getAnnouncementClassification, homeNoticeVo.getAnnouncementClassification());
  67. }
  68. if (!StringUtils.isBlank(homeNoticeVo.getHomepageClassification())) {
  69. lw.eq(HomeNotice::getHomepageClassification, homeNoticeVo.getHomepageClassification());
  70. }
  71. if (!ObjectUtils.isEmpty(homeNoticeVo.getBeginTime())) {
  72. lw.ge(HomeNotice::getNoticeTime, homeNoticeVo.getBeginTime());
  73. }
  74. if (!ObjectUtils.isEmpty(homeNoticeVo.getEndTime())) {
  75. lw.le(HomeNotice::getNoticeTime, homeNoticeVo.getEndTime());
  76. }
  77. IPage<HomeNotice> page = homeNoticeService.page(new Page<HomeNotice>(homeNoticeVo.getPageNum(), homeNoticeVo.getPageSize()), lw);
  78. return success(page);
  79. }
  80. @ApiOperation(value = "搜索项目列表")
  81. @PostMapping("/listPlanYears")
  82. public AjaxResult listPlanYears(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  83. if (ObjectUtils.isEmpty(yearsStandardVo.getProjectName())) {
  84. return error("查询项目名称不能为空!");
  85. }
  86. LambdaQueryWrapper<PlanYears> lw = new LambdaQueryWrapper<PlanYears>();
  87. lw.like(PlanYears::getProjectName, "%" + yearsStandardVo.getProjectName() + "%");
  88. lw.eq(PlanYears::getDelFlay, 0);
  89. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  90. //查出不在季度计划表中的id
  91. List<Integer> ids = planYearsService.idNotInQuarter();
  92. if (ObjectUtils.isEmpty(ids)) {
  93. lw.in(PlanYears::getPlanYearId, ids);
  94. }
  95. lw.eq(PlanYears::getPurchaseDeptId, SecurityUtils.getDeptId());
  96. }
  97. List<PlanYears> list = planYearsService.list(lw);
  98. //项目搜索的结果中要包含季度、临时计划(过滤掉已同步到项目管理的临时、季度计划)
  99. LambdaQueryWrapper<PlanQuarter> ls = new LambdaQueryWrapper<PlanQuarter>();
  100. ls.like(PlanQuarter::getProjectName, "%" + yearsStandardVo.getProjectName() + "%");
  101. ls.eq(PlanQuarter::getDelFlay, 0);
  102. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  103. //查出不在项目表中的季度、临时id
  104. List<Integer> ids = planQuarterService.idNotDemand();
  105. if (ObjectUtils.isEmpty(ids)) {
  106. ls.in(PlanQuarter::getPlanPracticalId, ids);
  107. }
  108. ls.eq(PlanQuarter::getPurchaseDeptId, SecurityUtils.getDeptId());
  109. }
  110. List<PlanQuarter> lists = planQuarterService.list(ls);
  111. //年度计划融合季度、临时计划
  112. for (PlanYears year : list) {
  113. PlanQuarter quarter = new PlanQuarter();
  114. BeanUtils.copyProperties(year, quarter);
  115. lists.add(quarter);
  116. }
  117. //查询项目信息,
  118. LambdaQueryWrapper<PmDemand> lq = new LambdaQueryWrapper<PmDemand>();
  119. lq.like(PmDemand::getProjectName, "%" + yearsStandardVo.getProjectName() + "%");
  120. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  121. lq.eq(PmDemand::getPurchaseDeptId, SecurityUtils.getDeptId());
  122. }
  123. List<PmDemand> demandList = demandService.list(lq);
  124. //放在同一个列表里返回
  125. List<HomeToDoQueryResVo> home = planYearsService.listToHome(lists, demandList);
  126. return AjaxResult.success(home);
  127. }
  128. @ApiOperation(value = "搜索项目--选择项目查看详情")
  129. @PostMapping("/projectDetails")
  130. public AjaxResult projectDetails(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  131. if (StringUtils.isNull(yearsStandardVo.getPlanYearId())) {
  132. return error("项目ID不能为空!");
  133. }
  134. return planYearsService.projectDetails(yearsStandardVo);
  135. }
  136. /**
  137. * 查询不同类型的公告
  138. */
  139. @PreAuthorize("@ss.hasPermi('home:homeNotice:getNoticesByType')")
  140. @Log(title = "查询公告", businessType = BusinessType.QUERY)
  141. @PostMapping("getNoticesByType")
  142. @ApiOperation("查询不同类型的公告")
  143. public AjaxResult getNoticesByType(@RequestBody HomeNoticeVo homeNoticeVo) {
  144. LambdaQueryWrapper<HomeNotice> lw = new LambdaQueryWrapper<>();
  145. if (!ObjectUtils.isEmpty(homeNoticeVo.getNoticeName())) {
  146. lw.like(HomeNotice::getNoticeName, homeNoticeVo.getNoticeName());
  147. }
  148. if (!ObjectUtils.isEmpty(homeNoticeVo.getAnnouncementClassification())) {
  149. lw.eq(HomeNotice::getAnnouncementClassification, homeNoticeVo.getAnnouncementClassification());
  150. }
  151. if (!ObjectUtils.isEmpty(homeNoticeVo.getBeginTime())) {
  152. lw.ge(HomeNotice::getNoticeTime, homeNoticeVo.getBeginTime());
  153. }
  154. if (!ObjectUtils.isEmpty(homeNoticeVo.getEndTime())) {
  155. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  156. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  157. Date parse = null;
  158. try {
  159. parse = dateFormatT.parse((dateFormat.format(homeNoticeVo.getEndTime()) + " 23:59:59:999"));
  160. } catch (ParseException e) {
  161. e.printStackTrace();
  162. }
  163. lw.le(HomeNotice::getNoticeTime, parse);
  164. }
  165. List<HomeNotice> noticeList = homeNoticeService.list(lw);
  166. return AjaxResult.success(noticeList);
  167. }
  168. }