You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Notice;
|
|
import com.yanzhen.entity.User;
|
|
import com.yanzhen.service.NoticeService; //
|
|
import com.yanzhen.service.UserService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.Map;
|
|
//公告通知管理的控制器
|
|
@RestController
|
|
@RequestMapping("/notice")
|
|
public class NoticeController {
|
|
//注入实例
|
|
//注入通知公告服务类
|
|
@Autowired
|
|
private NoticeService noticeService;
|
|
//注入用户服务类
|
|
@Autowired
|
|
private UserService userService;
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Notice notice, HttpServletRequest request){
|
|
//获取当前登录的用户信息
|
|
User user = (User) request.getAttribute("user");
|
|
// 设置当前用户的ID
|
|
notice.setUserId(user.getId());
|
|
//在通知公告服务类中引用create方法
|
|
int flag = noticeService.create(notice);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//删除通知公告信息
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在通知公告服务类中引用delete方法
|
|
int flag = noticeService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新通知公告信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Notice notice){
|
|
//在通知公告服务类中引用update方法
|
|
int flag = noticeService.updateSelective(notice);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取通知公告详细信息
|
|
@GetMapping("detail")
|
|
public Notice detail(Integer id){
|
|
//返回结果
|
|
return noticeService.detail(id);
|
|
}
|
|
//查询通知公告信息
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Notice notice){
|
|
//创建分页对象
|
|
PageInfo<Notice> pageInfo = noticeService.query(notice);
|
|
//遍历查询结果列表
|
|
pageInfo.getList().forEach(entity->{
|
|
// 为公告设置对应的用户信息
|
|
entity.setUser(userService.detail(entity.getUserId()));
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
|
|
} |