package com.ozs.web.controller.base; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ozs.base.domain.BaseNotice; import com.ozs.base.domain.BaseNoticeType; import com.ozs.base.service.BaseNoticeService; import com.ozs.base.service.BaseNoticeTypeService; import com.ozs.base.vo.BaseNoticePageReqVo; import com.ozs.base.vo.BaseNoticeVo; import com.ozs.common.annotation.Log; import com.ozs.common.constant.Constants; import com.ozs.common.constant.ModularConstans; import com.ozs.common.core.controller.BaseController; import com.ozs.common.core.domain.AjaxResult; import com.ozs.common.core.domain.entity.SysDept; import com.ozs.common.core.domain.entity.SysRole; import com.ozs.common.enums.BusinessType; import com.ozs.plan.doman.MonthlyReconciliation; import com.ozs.system.service.ISysDeptService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotEmpty; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Api(tags = ModularConstans.notice) @RestController @RequestMapping("/base/notice") public class BaseNoticeController extends BaseController { @Autowired private BaseNoticeService baseNoticeService; @Autowired private BaseNoticeTypeService baseNoticeTypeService; @Autowired private ISysDeptService iSysDeptService; @ApiOperation(value = "分页查询公告信息") @PostMapping("/page") @PreAuthorize("@ss.hasPermi('base:notice:list')") @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY) public AjaxResult page(@NotEmpty(message = "数据为空") @RequestBody BaseNoticePageReqVo vo) { LambdaQueryWrapper lw = new LambdaQueryWrapper<>(); if (!StringUtils.isBlank(vo.getTitle())) { lw.like(BaseNotice::getTitle, vo.getTitle()); } if (!ObjectUtils.isEmpty(vo.getStartTime())) { lw.ge(BaseNotice::getReleaseTime, vo.getStartTime()); } if (!ObjectUtils.isEmpty(vo.getStartTime())) { lw.le(BaseNotice::getReleaseTime, vo.getEntTime()); } if (!ObjectUtils.isEmpty(vo.getType())) { lw.eq(BaseNotice::getType, vo.getType()); } lw.orderByDesc(BaseNotice::getReleaseTime); IPage page = baseNoticeService.page(new Page<>(vo.getPageNum(), vo.getPageSize()), lw); IPage pagev = new Page<>(); pagev.setTotal(page.getTotal()); pagev.setCurrent(page.getCurrent()); pagev.setPages(page.getPages()); if (!ObjectUtils.isEmpty(page) && page.getRecords().size() > 0) { List list = baseNoticeTypeService.list(); List ids = list.stream().map(BaseNoticeType::getId).collect(Collectors.toList()); List collect = page.getRecords().stream().map(o -> { BaseNoticeVo baseNoticeVo = new BaseNoticeVo(); BeanUtils.copyProperties(o, baseNoticeVo); if (ids.contains(o.getType())) { List collect1 = list.stream().filter(tdto -> tdto.getId().equals(o.getType())).collect(Collectors.toList()); if(!ObjectUtils.isEmpty(collect1)){ baseNoticeVo.setTypeName(collect1.get(0).getName()); } } return baseNoticeVo; }).collect(Collectors.toList()); pagev.setRecords(collect); }else { pagev.setRecords(null); } return success(pagev); } @ApiOperation(value = "新增公告信息") @PostMapping("/insert") @PreAuthorize("@ss.hasPermi('base:notice:add')") @Log(title = ModularConstans.notice, businessType = BusinessType.INSERT) public AjaxResult insert(@NotEmpty(message = "数据为空") @RequestBody BaseNotice vo) { vo.setCreated(getUserId().toString()); vo.setCreateTime(new Date()); vo.setUpdated(vo.getCreated()); vo.setUpdateTime(vo.getCreateTime()); return toAjax(baseNoticeService.save(vo)); } @ApiOperation(value = "删除公告信息") @PostMapping("/remove") @PreAuthorize("@ss.hasPermi('base:notice:remove')") @Log(title = ModularConstans.notice, businessType = BusinessType.DELETE) public AjaxResult remove(@NotEmpty(message = "主键id不能为空") @RequestBody List ids) { return toAjax(baseNoticeService.removeBatchByIds(ids)); } @ApiOperation(value = "查看公告信息") @PostMapping("/getInfo") @PreAuthorize("@ss.hasPermi('base:notice:query')") @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY) public AjaxResult getInfo(@NotEmpty(message = "主键id不能为空") @RequestParam(value = "id", required = true) Long id) { BaseNotice vo = baseNoticeService.getById(id); BaseNoticeVo baseNoticeVo = new BaseNoticeVo(); if(!ObjectUtils.isEmpty(vo)){ BeanUtils.copyProperties(vo, baseNoticeVo); List list = baseNoticeTypeService.list(); List collect1 = list.stream().filter(tdto -> tdto.getId().equals(vo.getType())).collect(Collectors.toList()); if(!ObjectUtils.isEmpty(collect1)){ baseNoticeVo.setTypeName(collect1.get(0).getName()); } } return success(baseNoticeVo); } @ApiOperation(value = "首页分页查询公告信息") @PostMapping("/homePage") @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY) public AjaxResult homePage(@NotEmpty(message = "数据为空") @RequestBody BaseNoticePageReqVo vo) { vo.setUserId(getUserId()); vo.setDeptId(getDeptId()); vo.setRoleFlay(false); // 添加数据权限 List roleKeys = getLoginUser().getUser().getRoles().stream().map(SysRole::getRoleKey).collect(Collectors.toList()); if (roleKeys.contains(Constants.PURCHASING_MANAGEMENT) || roleKeys.contains(Constants.PURCHASE_SERVICES)) { vo.setRoleFlay(true); } IPage page = baseNoticeService.queryPage(vo); IPage pagev = new Page<>(); pagev.setTotal(page.getTotal()); pagev.setCurrent(page.getCurrent()); pagev.setPages(page.getPages()); pagev.setSize(page.getSize()); if (!ObjectUtils.isEmpty(page) && page.getRecords().size() > 0) { List list = baseNoticeTypeService.list(); List ids = list.stream().map(BaseNoticeType::getId).collect(Collectors.toList()); List collect = page.getRecords().stream().map(o -> { BaseNoticeVo baseNoticeVo = new BaseNoticeVo(); BeanUtils.copyProperties(o, baseNoticeVo); if (ids.contains(o.getType())) { List collect1 = list.stream().filter(tdto -> tdto.getId().equals(o.getType())).collect(Collectors.toList()); if(!ObjectUtils.isEmpty(collect1)){ baseNoticeVo.setTypeName(collect1.get(0).getName()); } } return baseNoticeVo; }).collect(Collectors.toList()); pagev.setRecords(collect); }else { pagev.setRecords(null); } return success(pagev); } }