157 lines
5.5 KiB
Java
157 lines
5.5 KiB
Java
package com.muyu.system.controller;
|
|
|
|
import com.muyu.common.core.web.controller.BaseController;
|
|
import com.muyu.common.core.domain.Result;
|
|
import com.muyu.common.core.web.page.TableDataInfo;
|
|
import com.muyu.common.log.annotation.Log;
|
|
import com.muyu.common.log.enums.BusinessType;
|
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
|
import com.muyu.common.security.utils.SecurityUtils;
|
|
import com.muyu.common.system.domain.SysDept;
|
|
import com.muyu.system.domain.SysNotice;
|
|
import com.muyu.system.domain.req.NoticeListReq;
|
|
import com.muyu.system.domain.req.NoticeReq;
|
|
import com.muyu.system.domain.resp.NoticeRes;
|
|
import com.muyu.system.domain.vo.NoticeVo;
|
|
import com.muyu.system.service.SysDeptService;
|
|
import com.muyu.system.service.SysNoticeService;
|
|
import com.muyu.system.service.SysUserService;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 公告 信息操作处理
|
|
*
|
|
* @author muyu
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/notice")
|
|
public class SysNoticeController extends BaseController {
|
|
@Autowired
|
|
private SysNoticeService noticeService;
|
|
@Autowired
|
|
private SysUserService sysUserService;
|
|
@Autowired
|
|
private SysDeptService sysDeptService;
|
|
@PostMapping("/findList")
|
|
public Result findList(@RequestBody NoticeListReq req){
|
|
List<NoticeRes> list = noticeService.findList(req);
|
|
return Result.success(list);
|
|
}
|
|
@PostMapping("/look")
|
|
public Result look(@RequestParam("id") Integer id,@RequestParam("state") Integer state){
|
|
NoticeRes look = noticeService.look(id,state);
|
|
return Result.success(look);
|
|
}
|
|
|
|
/**
|
|
* 获取通知公告列表
|
|
*/
|
|
@RequiresPermissions("system:notice:list")
|
|
@GetMapping("/list")
|
|
public Result<TableDataInfo<SysNotice>> list (SysNotice notice) {
|
|
startPage();
|
|
List<SysNotice> list = noticeService.selectNoticeList(notice);
|
|
return getDataTable(list);
|
|
}
|
|
|
|
/**
|
|
* 根据通知公告编号获取详细信息
|
|
*/
|
|
@RequiresPermissions("system:notice:query")
|
|
@GetMapping(value = "/{noticeId}")
|
|
public Result getInfo (@PathVariable("noticeId") Long noticeId) {
|
|
return success(noticeService.selectNoticeById(noticeId));
|
|
}
|
|
|
|
/**
|
|
* 新增通知公告
|
|
*/
|
|
@RequiresPermissions("system:notice:add")
|
|
@Log(title = "通知公告", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
public Result add (@Validated @RequestBody NoticeReq noticeReq) {
|
|
NoticeVo notice = new NoticeVo();
|
|
BeanUtils.copyProperties(noticeReq,notice);
|
|
notice.setCreateBy(SecurityUtils.getUsername());
|
|
if (noticeReq.getNoticeType().equals("2")){
|
|
List<String> time = noticeReq.getTime();
|
|
if (!CollectionUtils.isEmpty(time)){
|
|
for (int i = 0; i < time.size(); i++) {
|
|
String startTime = time.get(i);
|
|
Instant parse = Instant.parse(startTime);
|
|
Date timeDate = Date.from(parse);
|
|
if (i==0){
|
|
notice.setStartDate(timeDate);
|
|
}else {
|
|
notice.setEndDate(timeDate);
|
|
}
|
|
notice.setUserIds(sysUserService.selectUserAll());
|
|
}
|
|
}
|
|
}else {
|
|
List<Long> deptIds = new ArrayList<>();
|
|
List<List<Integer>> depts = noticeReq.getDeptIds();
|
|
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(depts)){
|
|
List<SysDept> sysDepts = sysDeptService.selectDeptList(new SysDept());
|
|
for (List<Integer> deptList : depts) {
|
|
Integer deptId = deptList.get(deptList.size() - 1);
|
|
for (SysDept sysDept : sysDepts) {
|
|
if (sysDept.getParentId().equals(Long.valueOf(deptId))){
|
|
deptIds.add(sysDept.getDeptId());
|
|
}
|
|
}
|
|
deptIds.add(Long.valueOf(deptId));
|
|
}
|
|
HashSet<Long> longs = new HashSet<>(deptIds);
|
|
deptIds = new ArrayList<>(longs);
|
|
notice.setDeptIds(deptIds); List<Integer> userIds = sysUserService.selectUserByDeptId(deptIds);
|
|
notice.setUserIds(userIds);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
int rows = noticeService.insertNotice(notice);
|
|
return toAjax(rows);
|
|
}
|
|
|
|
/**
|
|
* 修改通知公告
|
|
*/
|
|
@RequiresPermissions("system:notice:edit")
|
|
@Log(title = "通知公告", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public Result edit (@Validated @RequestBody SysNotice notice) {
|
|
notice.setUpdateBy(SecurityUtils.getUsername());
|
|
return toAjax(noticeService.updateNotice(notice));
|
|
}
|
|
|
|
/**
|
|
* 删除通知公告
|
|
*/
|
|
@RequiresPermissions("system:notice:remove")
|
|
@Log(title = "通知公告", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{noticeIds}")
|
|
public Result remove (@PathVariable("noticeIds") Long[] noticeIds) {
|
|
return toAjax(noticeService.deleteNoticeByIds(noticeIds));
|
|
}
|
|
|
|
@PostMapping("/noticeCount/{id}")
|
|
public Result NoticeCount (@PathVariable("id") Integer id) {
|
|
return Result.success(noticeService.NoticeCount(id));
|
|
}
|
|
|
|
|
|
}
|