parent
042bad3ab3
commit
f56b5df6ca
@ -0,0 +1,232 @@
|
||||
package com.example.flower.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.example.flower.entity.Notice;
|
||||
import com.example.flower.service.NoticeService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.example.flower.unit.JWTUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/notice")
|
||||
public class NoticeController {
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
@PostMapping("/list") //noticeList获取公告信息列表
|
||||
public JSONObject noticeList(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
// if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
// JWTUtil.checkTokenFailed(jsonObject);
|
||||
// return jsonObject;
|
||||
// }
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
int page=param.getIntValue("page");
|
||||
int page_size=param.getIntValue("page_size");
|
||||
|
||||
List<Notice> noticeList = noticeService.noticeList(page,page_size).getList();
|
||||
|
||||
jsonObject1.put("page_number", noticeService.noticeList(page,page_size).getPages());
|
||||
jsonObject1.put("total",noticeService.noticeList(page,page_size).getTotal());
|
||||
|
||||
int size=noticeList.size();
|
||||
|
||||
JSONObject[] objects = new JSONObject[size];
|
||||
for(int i = 0;i<size;i++){
|
||||
objects[i]=new JSONObject();
|
||||
objects[i].put("notice_id", noticeList.get(i).getNotice_id());
|
||||
objects[i].put("notice_title",noticeList.get(i).getNotice_title());
|
||||
objects[i].put("notice_content", noticeList.get(i).getNotice_content());
|
||||
objects[i].put("notice_time", noticeList.get(i).getNotice_time());
|
||||
}
|
||||
jsonObject1.put("notices",objects);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","token认证成功!" );
|
||||
jsonObject.put("data",jsonObject1);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/query") //noticeQuery查询公告信息列表
|
||||
public JSONObject noticeListByQuery(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
int page=param.getIntValue("page");
|
||||
int page_size=param.getIntValue("page_size");
|
||||
String notice_content = param.getString("notice_content");
|
||||
|
||||
List<Notice> noticeList = noticeService.noticeListByQuery(page,page_size,notice_content).getList();
|
||||
|
||||
jsonObject1.put("page_number", noticeService.noticeListByQuery(page,page_size,notice_content).getPages());
|
||||
jsonObject1.put("total",noticeService.noticeListByQuery(page,page_size,notice_content).getTotal());
|
||||
|
||||
int size=noticeList.size();
|
||||
|
||||
JSONObject[] objects = new JSONObject[size];
|
||||
for(int i = 0;i<size;i++){
|
||||
objects[i]=new JSONObject();
|
||||
objects[i].put("notice_id", noticeList.get(i).getNotice_id());
|
||||
objects[i].put("notice_title",noticeList.get(i).getNotice_title());
|
||||
objects[i].put("notice_content", noticeList.get(i).getNotice_content());
|
||||
objects[i].put("notice_time", noticeList.get(i).getNotice_time());
|
||||
}
|
||||
jsonObject1.put("notices",objects);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","token认证成功!" );
|
||||
jsonObject.put("data",jsonObject1);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/add") //noticeAdd添加新公告
|
||||
public JSONObject noticeAdd(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Notice notice = new Notice();
|
||||
notice.setNotice_title(param.getString("notice_title"));
|
||||
notice.setNotice_content(param.getString("notice_content"));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化
|
||||
Date date = new Date();
|
||||
notice.setNotice_time(sdf.format(date));
|
||||
|
||||
noticeService.noticeAdd(notice);
|
||||
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","成功" );
|
||||
jsonObject.put("notice_id",notice.getNotice_id());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/deletePer") //noticeDeletePer删除单个公告
|
||||
public JSONObject noticeDeletePer(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
int flag = noticeService.noticeDeletePer(param.getIntValue("notice_id"));
|
||||
if(flag==1){
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","成功" );
|
||||
}
|
||||
else {
|
||||
jsonObject.put("code",403 );
|
||||
jsonObject.put("msg","删除失败" );
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/deleteMul") //noticeDeleteMul批量删除公告
|
||||
public JSONObject noticeDeleteMul(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
//获取请求参数
|
||||
JSONArray notice_ids = param.getJSONArray("notice_ids");
|
||||
|
||||
int [] ids = new int[notice_ids.size()];
|
||||
|
||||
//把userid中的数据进行类型转换并存入到int数组中
|
||||
for (int i = 0; i < notice_ids.size(); i++) {
|
||||
ids[i] = Integer.parseInt(notice_ids.getString(i));
|
||||
}
|
||||
|
||||
int result = noticeService.noticeDeleteMul(ids);
|
||||
if(result == ids.length){
|
||||
jsonObject.put("code",200);
|
||||
jsonObject.put("msg","批量删除成功,删除了"+result+"条公告数据");
|
||||
}else{
|
||||
jsonObject.put("code",403);
|
||||
jsonObject.put("msg","批量删除失败,删除了"+result+"条公告数据");
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/info") //noticeInfo获取公告初始信息
|
||||
public JSONObject noticeInfo(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
int notice_id = param.getIntValue("notice_id");
|
||||
Notice notice = noticeService.noticeInfo(notice_id);
|
||||
|
||||
if(notice!=null){
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("notice_id",notice.getNotice_id());
|
||||
jsonObject1.put("notice_title",notice.getNotice_title());
|
||||
jsonObject1.put("notice_content",notice.getNotice_content());
|
||||
|
||||
jsonObject.put("code",200);
|
||||
jsonObject.put("msg","成功");
|
||||
jsonObject.put("data",jsonObject1);
|
||||
|
||||
}
|
||||
else{
|
||||
jsonObject.put("code",403);
|
||||
jsonObject.put("msg","获取公告信息失败");
|
||||
jsonObject.put("data",null);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping("/modify") //noticeModify修改公告
|
||||
public JSONObject noticeModify(@RequestHeader String Authorization, @RequestBody JSONObject param){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
|
||||
JWTUtil.checkTokenFailed(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
Notice notice = new Notice();
|
||||
notice.setNotice_id(param.getIntValue("notice_id"));
|
||||
notice.setNotice_title(param.getString("notice_title"));
|
||||
notice.setNotice_content(param.getString("notice_content"));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化
|
||||
Date date = new Date();
|
||||
notice.setNotice_time(sdf.format(date));
|
||||
|
||||
int flag = noticeService.noticeModify(notice);
|
||||
if(flag==1){
|
||||
jsonObject.put("code",200 );
|
||||
jsonObject.put("msg","修改成功" );
|
||||
}
|
||||
else{
|
||||
jsonObject.put("code",403 );
|
||||
jsonObject.put("msg","修改失败" );
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue