1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 06:51:23 +08:00

Temp commit

This commit is contained in:
cccccyb
2023-05-01 01:07:41 +08:00
parent 59621baf47
commit cdf47bc0bb
8 changed files with 325 additions and 3 deletions

View File

@@ -1,7 +1,13 @@
package com.cfive.pinnacle.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.service.INoticeService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
/**
* <p>
@@ -11,8 +17,55 @@ import org.springframework.web.bind.annotation.RestController;
* @author FatttSnake
* @since 2023-04-30
*/
@RestController
@RequestMapping("/notice")
@CrossOrigin
public class NoticeController {
@Autowired
INoticeService noticeService;
//根据公告id查公告信息及发布人
@GetMapping("/{nid}")
public Result selectByNoticeId(@PathVariable Long nid) {
Notice noticeById = noticeService.selectByNoticeId(nid);
Integer code = noticeById != null ? Code.SELECT_NOTICE_OK : Code.SELECT_NOTICE_ERR;
String msg = noticeById != null ? "" : "数据查询失败,请尝试!";
return new Result(code, noticeById, msg);
}
;
//添加公告
@GetMapping
public Result selectAllNoticeId() {
List<Notice> noticeList = noticeService.selectAllNoticeId();
Integer code = noticeList != null ? Code.SELECT_ALL_OK : Code.SELECT_ALL_ERR;
String msg = noticeList != null ? "" : "数据查询失败,请尝试!";
return new Result(code, noticeList, msg);
}
@PostMapping
public Result 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;
}
@PutMapping
public Result addNotice(@RequestBody Notice notice){
boolean insertNotice = noticeService.save(notice);
Result result = new Result(insertNotice ? Code.SAVE_OK : Code.SAVE_ERR, insertNotice);
return result;
}
@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;
}
}

View File

@@ -51,7 +51,7 @@ public class Notice implements Serializable {
private Long typeId;
/**
* 发布者
* 发布者id
*/
@TableField("sender_id")
private Long senderId;
@@ -104,6 +104,12 @@ public class Notice implements Serializable {
@TableField("old")
private Integer old;
/**
* 发布者
*/
@TableField(exist = false)
private User sender;
@TableField("deleted")
@TableLogic
private Integer deleted;
@@ -111,4 +117,6 @@ public class Notice implements Serializable {
@TableField("version")
@Version
private Integer version;
}

View File

@@ -4,6 +4,8 @@ import com.cfive.pinnacle.entity.Notice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* <p>
* 公告 Mapper 接口
@@ -14,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface NoticeMapper extends BaseMapper<Notice> {
Notice selectByNoticeId(Long nid);
List<Notice> selectAllNoticeId();
}

View File

@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
import com.cfive.pinnacle.entity.Notice;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 公告 服务类
@@ -12,5 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2023-04-30
*/
public interface INoticeService extends IService<Notice> {
Notice selectByNoticeId(Long nid);
List<Notice> selectAllNoticeId();
}

View File

@@ -4,8 +4,11 @@ import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.mapper.NoticeMapper;
import com.cfive.pinnacle.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 公告 服务实现类
@@ -16,5 +19,15 @@ import org.springframework.stereotype.Service;
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {
@Autowired
NoticeMapper noticeMapper;
@Override
public Notice selectByNoticeId(Long nid) {
return noticeMapper.selectByNoticeId(nid);
}
@Override
public List<Notice> selectAllNoticeId() {
return noticeMapper.selectAllNoticeId();
}
}

View File

@@ -1,5 +1,30 @@
<?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查公告信息及发布人 -->
<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
</select>
<resultMap id="NoticeByIdResultMap" type="notice" autoMapping="true">
<association property="sender" javaType="user" autoMapping="true"/>
</resultMap>
<!-- 查询所有公告 -->
<select id="selectAllNoticeId" resultMap="NoticeAllResultMap">
select *
from t_user u,
t_notice t
where u.id = t.sender_id
and t.deleted = 0
</select>
<resultMap id="NoticeAllResultMap" type="notice" autoMapping="true">
<association property="sender" javaType="user" autoMapping="true"/>
</resultMap>
</mapper>