mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 06:51:23 +08:00
Temp commit on 2023-05-01 5:00
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.INoticeService;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,45 +29,45 @@ public class NoticeController {
|
||||
|
||||
//根据公告id查公告信息及发布人
|
||||
@GetMapping("/{nid}")
|
||||
public Result selectByNoticeId(@PathVariable Long nid) {
|
||||
public ResponseResult selectByNoticeId(@PathVariable Long nid) {
|
||||
Notice noticeById = noticeService.selectByNoticeId(nid);
|
||||
Integer code = noticeById != null ? Code.SELECT_NOTICE_OK : Code.SELECT_NOTICE_ERR;
|
||||
Integer code = noticeById != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = noticeById != null ? "" : "数据查询失败,请尝试!";
|
||||
return new Result(code, noticeById, msg);
|
||||
return ResponseResult.build(code, msg, noticeById);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
//添加公告
|
||||
@GetMapping
|
||||
public Result selectAllNoticeId() {
|
||||
List<Notice> noticeList = noticeService.selectAllNoticeId();
|
||||
Integer code = noticeList != null ? Code.SELECT_ALL_OK : Code.SELECT_ALL_ERR;
|
||||
public ResponseResult selectAllNotice() {
|
||||
List<Notice> noticeList = noticeService.selectAllNotice();
|
||||
Integer code = noticeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
|
||||
String msg = noticeList != null ? "" : "数据查询失败,请尝试!";
|
||||
return new Result(code, noticeList, msg);
|
||||
return ResponseResult.build(code, msg, noticeList);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Result updateNotice(@RequestBody Notice notice) {
|
||||
public ResponseResult updateNotice(@RequestBody Notice notice) {
|
||||
notice.setId(null); //清除id,使新插入的数据id自增
|
||||
notice.setModifyTime(LocalDateTime.now());
|
||||
notice.setOriginId(notice.getId());
|
||||
boolean updateById = noticeService.save(notice);
|
||||
Result result = new Result(updateById ? Code.UPDATE_OK : Code.UPDATE_ERR, updateById);
|
||||
return result;
|
||||
String msg = updateById ? "" : "数据修改失败,请尝试!";
|
||||
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateById);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Result addNotice(@RequestBody Notice notice){
|
||||
public ResponseResult addNotice(@RequestBody Notice notice) {
|
||||
boolean insertNotice = noticeService.save(notice);
|
||||
Result result = new Result(insertNotice ? Code.SAVE_OK : Code.SAVE_ERR, insertNotice);
|
||||
return result;
|
||||
String msg = insertNotice ? "" : "数据添加失败,请尝试!";
|
||||
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{nid}")
|
||||
public Result deleteByNoticeId(@PathVariable Long nid){
|
||||
boolean removeById= noticeService.removeById(nid);
|
||||
Result result = new Result(removeById ? Code.DELETE_OK : Code.DELETE_ERR, removeById);
|
||||
return result;
|
||||
public ResponseResult deleteByNoticeId(@PathVariable Long nid) {
|
||||
boolean removeById = noticeService.deleteById(nid);
|
||||
String msg = removeById ? "" : "数据删除失败,请尝试!";
|
||||
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 公告接收 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/noticeReceive")
|
||||
public class NoticeReceiveController {
|
||||
|
||||
}
|
||||
@@ -45,17 +45,29 @@ public class Notice implements Serializable {
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 公告类型
|
||||
* 公告类型Id
|
||||
*/
|
||||
@TableField("type_id")
|
||||
private Long typeId;
|
||||
|
||||
/**
|
||||
* 公告类型
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private NoticeType noticeType;
|
||||
|
||||
/**
|
||||
* 发布者id
|
||||
*/
|
||||
@TableField("sender_id")
|
||||
private Long senderId;
|
||||
|
||||
/**
|
||||
* 发布者
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private User sender;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@@ -104,12 +116,6 @@ public class Notice implements Serializable {
|
||||
@TableField("old")
|
||||
private Integer old;
|
||||
|
||||
/**
|
||||
* 发布者
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private User sender;
|
||||
|
||||
@TableField("deleted")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@@ -32,17 +32,29 @@ public class NoticeReceive implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* 用户Id
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 公告
|
||||
* 用户
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* 公告Id
|
||||
*/
|
||||
@TableField("notice_id")
|
||||
private Long noticeId;
|
||||
|
||||
/**
|
||||
* 公告
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Notice notice;
|
||||
|
||||
/**
|
||||
* 已读
|
||||
*/
|
||||
|
||||
@@ -18,5 +18,5 @@ import java.util.List;
|
||||
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||
Notice selectByNoticeId(Long nid);
|
||||
|
||||
List<Notice> selectAllNoticeId();
|
||||
List<Notice> selectAllNotice();
|
||||
}
|
||||
|
||||
@@ -16,5 +16,7 @@ import java.util.List;
|
||||
public interface INoticeService extends IService<Notice> {
|
||||
Notice selectByNoticeId(Long nid);
|
||||
|
||||
List<Notice> selectAllNoticeId();
|
||||
List<Notice> selectAllNotice();
|
||||
|
||||
Boolean deleteById(Long nid);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.Notice;
|
||||
import com.cfive.pinnacle.entity.NoticeReceive;
|
||||
import com.cfive.pinnacle.mapper.NoticeMapper;
|
||||
import com.cfive.pinnacle.mapper.NoticeReceiveMapper;
|
||||
import com.cfive.pinnacle.service.INoticeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,13 +24,28 @@ import java.util.List;
|
||||
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
||||
@Autowired
|
||||
NoticeMapper noticeMapper;
|
||||
@Autowired
|
||||
NoticeReceiveMapper noticeReceiveMapper;
|
||||
@Override
|
||||
public Notice selectByNoticeId(Long nid) {
|
||||
return noticeMapper.selectByNoticeId(nid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notice> selectAllNoticeId() {
|
||||
return noticeMapper.selectAllNoticeId();
|
||||
public List<Notice> selectAllNotice() {
|
||||
return noticeMapper.selectAllNotice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteById(Long nid) {
|
||||
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(NoticeReceive::getNoticeId, nid);
|
||||
List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw);
|
||||
for (NoticeReceive nrc:
|
||||
noticeReceives) {
|
||||
noticeReceiveMapper.deleteById(nrc.getId());
|
||||
}
|
||||
return noticeMapper.deleteById(nid)==0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.NoticeMapper">
|
||||
<!-- 根据公告id查公告信息及发布人 -->
|
||||
<!-- 根据公告id查公告信息及发布人、公告类别名 -->
|
||||
<select id="selectByNoticeId" resultMap="NoticeByIdResultMap" parameterType="long">
|
||||
select *
|
||||
from t_user u,
|
||||
t_notice t
|
||||
where u.id = t.sender_id
|
||||
and t.id = #{nid}
|
||||
and t.deleted = 0
|
||||
|
||||
|
||||
t_notice n,
|
||||
t_notice_type type
|
||||
where u.id = n.sender_id
|
||||
and type.id=n.type_id
|
||||
and n.id = #{nid}
|
||||
and n.deleted = 0
|
||||
and n.old=0
|
||||
</select>
|
||||
<resultMap id="NoticeByIdResultMap" type="notice" autoMapping="true">
|
||||
<association property="sender" javaType="user" autoMapping="true"/>
|
||||
<association property="noticeType" javaType="noticeType" autoMapping="true"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询所有公告 -->
|
||||
<select id="selectAllNoticeId" resultMap="NoticeAllResultMap">
|
||||
<select id="selectAllNotice" resultMap="NoticeAllResultMap">
|
||||
select *
|
||||
from t_user u,
|
||||
t_notice t
|
||||
where u.id = t.sender_id
|
||||
and t.deleted = 0
|
||||
t_notice n,
|
||||
t_notice_type type
|
||||
where u.id = n.sender_id
|
||||
and type.id=n.type_id
|
||||
and n.deleted = 0
|
||||
and n.old=0
|
||||
</select>
|
||||
<resultMap id="NoticeAllResultMap" type="notice" autoMapping="true">
|
||||
<association property="sender" javaType="user" autoMapping="true"/>
|
||||
<association property="noticeType" javaType="noticeType" autoMapping="true"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user