zxs 10 months ago
parent 5d5ca89a49
commit 53a0d2d7e7

@ -0,0 +1,95 @@
package com.jubilantz.entity;
import java.io.Serializable;
import java.sql.Date;
/**
* @Author JubilantZ
*
* @Date: 2021/4/27 10:21
*/
public class EasNotice implements Serializable {
private Integer id;
private String title;
private String author;
private String content;
private Integer type;
private Date releasedate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Date getReleasedate() {
return releasedate;
}
public void setReleasedate(Date releasedate) {
this.releasedate = releasedate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EasNotice easNotice = (EasNotice) o;
if (id != null ? !id.equals(easNotice.id) : easNotice.id != null) return false;
if (title != null ? !title.equals(easNotice.title) : easNotice.title != null) return false;
if (author != null ? !author.equals(easNotice.author) : easNotice.author != null) return false;
if (content != null ? !content.equals(easNotice.content) : easNotice.content != null) return false;
if (type != null ? !type.equals(easNotice.type) : easNotice.type != null) return false;
if (releasedate != null ? !releasedate.equals(easNotice.releasedate) : easNotice.releasedate != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (author != null ? author.hashCode() : 0);
result = 31 * result + (content != null ? content.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (releasedate != null ? releasedate.hashCode() : 0);
return result;
}
}

@ -0,0 +1,180 @@
package com.jubilantz.controller;
import com.jubilantz.entity.EasNotice;
import com.jubilantz.services.EasNoticeService;
import com.jubilantz.utils.PageUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author JubilantZ
* @Date: 2021/4/27 11:35
*/
@RequestMapping("/easNotice")
@Controller
public class EasNoticeController {
@Autowired
private EasNoticeService easNoticeService;
@RequestMapping("/index")
@RequiresPermissions("notice:query")
public String index() throws Exception{
return "system/notice/adminNoticeList";
}
@ResponseBody
@RequestMapping("/list")
public Map<String, Object> getNoticeList(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@RequestParam(defaultValue="")String searchKey) throws Exception {
Map<String,Object> map = new HashMap<>();
//一共三个权限 获取全部的行数
int type = 3;
int count = easNoticeService.getCountByType(type,searchKey);
PageUtil pageUtil = new PageUtil(page,limit);
List<EasNotice> list = easNoticeService.getNoticeListByType(type,searchKey,pageUtil);
map.put("count",count);
map.put("data",list);
map.put("code",0);
map.put("msg","");
return map;
}
@RequestMapping("/look")
public ModelAndView showNotice(){
return new ModelAndView("system/notice/notice");
}
@RequestMapping("/addPage")
public ModelAndView toAddPage() {
return new ModelAndView("system/notice/noticeAdd");
}
@RequestMapping("/addNotice")
@ResponseBody
public Map<String, Object> addNotice(@RequestParam(defaultValue="2")Integer opType, EasNotice easNotice) throws Exception {
Map<String, Object> map = new HashMap<>();
// System.out.println("通知id:"+easNotice.getId());
// System.out.println("opType为:"+opType);
// System.out.println("content为:"+easNotice.getContent());
int res = 0;
//opType等于0是添加 1是更新
if (opType == 0) {
try {
res = easNoticeService.addNotice(easNotice);
} catch (Exception e) {
// System.out.println("添加失败!");
map.put("result",false);
}
if (res > 0){
map.put("result",true);
}else{
map.put("result",false);
}
} else if (opType == 1) {
res = easNoticeService.updateNotice(easNotice);
if (res > 0) {
map.put("result",true);
}else{
map.put("result",false);
}
};
return map;
}
@ResponseBody
@RequestMapping("/deleteNotice")
public Map<String, Object> deleteNotice(EasNotice easNotice) {
Map<String, Object> map = new HashMap<>();
if (easNoticeService.deleteNotice(easNotice) > 0) {
map.put("result",true);
map.put("msg","删除成功");
}else {
map.put("result",false);
map.put("msg","删除失败");
}
return map;
}
/**
*
* @param nIds
* @return
*/
@ResponseBody
@RequestMapping("/deleteList")
public Map<String, Object> deleteNoticeList(String nIds) {
Map<String, Object> map = new HashMap<>();
List<Integer> list = new ArrayList<Integer>();
try {
String[] ids = nIds.split(",");
for (String id: ids) {
list.add(Integer.parseInt(id));
}
if (easNoticeService.deleteNoticeList(list) > 0) {
map.put("result",true);
map.put("msg","批量删除成功");
}else {
map.put("result",false);
map.put("msg","批量删除失败");
}
} catch (Exception e) {
e.printStackTrace();
map.put("result",false);
map.put("msg","批量删除失败");
}
return map;
}
@ResponseBody
@RequestMapping(value="/uploadImg")
public String uploadImg(MultipartFile file, HttpServletRequest request) throws IOException {
System.out.println("comming!");
String path = request.getSession().getServletContext().getRealPath("/images");
System.out.println("path>>"+path);
//获取上传图片的名称
String fileName = file.getOriginalFilename();
System.out.println("fileName>>"+fileName);
// //获取图片的后缀 例:.jpg
// fileName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
// System.out.println("fileName1>>"+fileName);
// //生成图片名称
// fileName = System.currentTimeMillis() + fileName; //System.currentTimeMillis()产生一个当前的毫秒 +文件后缀 例.jpg
System.out.println("fileName2>>"+fileName);
File dir = new File(path, fileName);
System.out.println("File>>"+dir);
if(!dir.exists()){
dir.mkdirs();
}
// MultipartFile自带的解析方法
file.transferTo(dir);
String jsonStr = "{\"code\":0,\"msg\":\"\",\"count\":" + null + ",\"data\":" + "{\"src\":\"" + "/images/" + fileName + "\"}" + "}";
return jsonStr;
}
}

@ -0,0 +1,235 @@
package com.jubilantz.controller;
import com.jubilantz.entity.EasNotice;
import com.jubilantz.services.EasNoticeService;
import com.jubilantz.utils.PageUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 通知管理控制器
* 处理通知的查询、添加、修改、删除以及图片上传等功能
* @Author JubilantZ
* @Date: 2021/4/27 11:35
*/
@RequestMapping("/easNotice")
@Controller
public class EasNoticeController {
@Autowired
private EasNoticeService easNoticeService;
/**
* 进入通知管理首页
* @RequiresPermissions 注解用于权限控制只有拥有notice:query权限的用户才能访问
* @return 通知管理页面路径
* @throws Exception 抛出可能发生的异常
*/
@RequestMapping("/index")
@RequiresPermissions("notice:query")
public String index() throws Exception{
return "system/notice/adminNoticeList";
}
/**
* 获取通知列表
* @param page 当前页码默认值为1
* @param limit 每页显示数量默认值为10
* @param searchKey 搜索关键词,默认值为空字符串
* @return 包含通知列表、总数、状态码和消息的Map对象
* @throws Exception 抛出可能发生的异常
*/
@ResponseBody
@RequestMapping("/list")
public Map<String, Object> getNoticeList(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@RequestParam(defaultValue="")String searchKey) throws Exception {
Map<String,Object> map = new HashMap<>();
// 权限类型3表示获取全部权限的通知假设1、2、3分别代表不同权限等级
int type = 3;
// 获取符合条件的通知总数
int count = easNoticeService.getCountByType(type,searchKey);
// 初始化分页工具
PageUtil pageUtil = new PageUtil(page,limit);
// 根据权限类型和搜索关键词获取通知列表
List<EasNotice> list = easNoticeService.getNoticeListByType(type,searchKey,pageUtil);
map.put("count",count);
map.put("data",list);
map.put("code",0);
map.put("msg","");
return map;
}
/**
* 显示通知详情页面
* @return 通知详情页面的ModelAndView对象
*/
@RequestMapping("/look")
public ModelAndView showNotice(){
return new ModelAndView("system/notice/notice");
}
/**
* 跳转到添加通知页面
* @return 添加通知页面的ModelAndView对象
*/
@RequestMapping("/addPage")
public ModelAndView toAddPage() {
return new ModelAndView("system/notice/noticeAdd");
}
/**
* 添加或更新通知
* @param opType 操作类型0表示添加1表示更新默认值为2需要确认默认值的业务含义
* @param easNotice 通知实体对象
* @return 包含操作结果和消息的Map对象
* @throws Exception 抛出可能发生的异常
*/
@RequestMapping("/addNotice")
@ResponseBody
public Map<String, Object> addNotice(@RequestParam(defaultValue="2")Integer opType, EasNotice easNotice) throws Exception {
Map<String, Object> map = new HashMap<>();
// 打印调试信息(已注释,生产环境建议移除)
// System.out.println("通知id:"+easNotice.getId());
// System.out.println("opType为:"+opType);
// System.out.println("content为:"+easNotice.getContent());
int res = 0;
// 根据操作类型执行添加或更新操作
if (opType == 0) {
try {
res = easNoticeService.addNotice(easNotice);
} catch (Exception e) {
// 添加失败时设置结果为false打印语句已注释
// System.out.println("添加失败!");
map.put("result",false);
}
if (res > 0){
map.put("result",true);
}else{
map.put("result",false);
}
} else if (opType == 1) {
res = easNoticeService.updateNotice(easNotice);
if (res > 0) {
map.put("result",true);
}else{
map.put("result",false);
}
};
return map;
}
/**
* 删除单个通知
* @param easNotice 包含要删除通知ID的实体对象
* @return 包含删除结果和消息的Map对象
*/
@ResponseBody
@RequestMapping("/deleteNotice")
public Map<String, Object> deleteNotice(EasNotice easNotice) {
Map<String, Object> map = new HashMap<>();
if (easNoticeService.deleteNotice(easNotice) > 0) {
map.put("result",true);
map.put("msg","删除成功");
}else {
map.put("result",false);
map.put("msg","删除失败");
}
return map;
}
/**
* 批量删除通知
* @param nIds 以逗号分隔的通知ID字符串
* @return 包含删除结果和消息的Map对象
*/
@ResponseBody
@RequestMapping("/deleteList")
public Map<String, Object> deleteNoticeList(String nIds) {
Map<String, Object> map = new HashMap<>();
List<Integer> list = new ArrayList<Integer>();
try {
// 分割ID字符串为数组
String[] ids = nIds.split(",");
// 转换为Integer列表
for (String id: ids) {
list.add(Integer.parseInt(id));
}
if (easNoticeService.deleteNoticeList(list) > 0) {
map.put("result",true);
map.put("msg","批量删除成功");
}else {
map.put("result",false);
map.put("msg","批量删除失败");
}
} catch (Exception e) {
e.printStackTrace();
map.put("result",false);
map.put("msg","批量删除失败");
}
return map;
}
/**
* 上传通知图片
* @param file 上传的文件对象
* @param request HTTP请求对象
* @return 包含上传结果的JSON字符串
* @throws IOException 处理文件操作时可能抛出的IO异常
*/
@ResponseBody
@RequestMapping(value="/uploadImg")
public String uploadImg(MultipartFile file, HttpServletRequest request) throws IOException {
System.out.println("comming!");
// 获取图片存储的物理路径
String path = request.getSession().getServletContext().getRealPath("/images");
System.out.println("path>>"+path);
// 获取上传图片的原始名称
String fileName = file.getOriginalFilename();
System.out.println("fileName>>"+fileName);
// 以下代码为生成唯一文件名的注释(当前未启用)
// //获取图片的后缀 例:.jpg
// fileName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
// System.out.println("fileName1>>"+fileName);
// //生成图片名称(使用当前时间戳+后缀,避免文件名冲突)
// fileName = System.currentTimeMillis() + fileName;
System.out.println("fileName2>>"+fileName);
// 创建文件对象
File dir = new File(path, fileName);
System.out.println("File>>"+dir);
// 若目录不存在则创建
if(!dir.exists()){
dir.mkdirs();
}
// 保存上传的文件
file.transferTo(dir);
// 构造并返回包含图片路径的JSON响应
String jsonStr = "{\"code\":0,\"msg\":\"\",\"count\":" + null + ",\"data\":" + "{\"src\":\"" + "/images/" + fileName + "\"}" + "}";
return jsonStr;
}
}
Loading…
Cancel
Save