1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-04 22:41:24 +08:00

Temp commit on 2023-05-01 5:00

This commit is contained in:
cccccyb
2023-05-01 05:01:54 +08:00
parent cdf47bc0bb
commit e8bc1f5945
11 changed files with 133 additions and 90 deletions

View File

@@ -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);
}
}

View File

@@ -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 {
}

View File

@@ -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;

View File

@@ -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;
/**
* 已读
*/

View File

@@ -18,5 +18,5 @@ import java.util.List;
public interface NoticeMapper extends BaseMapper<Notice> {
Notice selectByNoticeId(Long nid);
List<Notice> selectAllNoticeId();
List<Notice> selectAllNotice();
}

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -1,11 +1,11 @@
package com.cfive.pinnacle.notice;
import com.cfive.pinnacle.controller.NoticeController;
import com.cfive.pinnacle.controller.Result;
import com.cfive.pinnacle.entity.Department;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive;
import com.cfive.pinnacle.entity.NoticeType;
import com.cfive.pinnacle.entity.User;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.IDepartmentService;
import com.cfive.pinnacle.service.INoticeReceiveService;
import com.cfive.pinnacle.service.INoticeTypeService;
@@ -33,20 +33,20 @@ public class NoticeTest {
@Test
void selectByIdTest() {
Result notice = noticeController.selectByNoticeId(21L);
System.out.println(notice.getData());
ResponseResult selectByNoticeId = noticeController.selectByNoticeId(21L);
System.out.println(selectByNoticeId.getData());
}
@Test
void selectAllTest() {
Result noticeList = noticeController.selectAllNoticeId();
ResponseResult noticeList = noticeController.selectAllNotice();
System.out.println(noticeList.getData());
}
@Test
void updateTest() {
Result notice =noticeController.selectByNoticeId(23L);
Result updateNotice = noticeController.updateNotice((Notice)notice.getData());
ResponseResult notice = noticeController.selectByNoticeId(23L);
ResponseResult updateNotice = noticeController.updateNotice((Notice) notice.getData());
System.out.println(updateNotice.getData());
}
@@ -56,14 +56,13 @@ public class NoticeTest {
notice.setTitle("title1");
notice.setTypeId(1652684907554496514L);
notice.setSenderId(1652714496280469506L);
LocalDateTime startDate = LocalDateTime.parse("2023-03-21 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime endDate = LocalDateTime.parse("2023-09-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
// notice.setEffectiveDate(startDate);
// notice.setEndDate(endDate);
// notice.setSenderID(2);
LocalDateTime sendTime = LocalDateTime.parse("2023-05-11 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime endTime = LocalDateTime.parse("2023-09-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
notice.setPriority(2);
notice.setSendTime(sendTime);
notice.setEndTime(endTime);
notice.setContent("Content1");
Result updateNotice = noticeController.addNotice(notice);
System.out.println(updateNotice.getData());
noticeController.addNotice(notice);
}
@Test
void insertNoticeTypeTest(){
@@ -74,11 +73,11 @@ public class NoticeTest {
@Test
void insertNoticeRecTest(){
User user = new User();
user.setUsername("cyb");
user.setPasswd("123");
user.setDepartmentId(1652713919467151362L);
iUserService.save(user);
// iNoticeTypeService.save(noticeType);
NoticeReceive receive = new NoticeReceive();
receive.setNoticeId(1652734384348790786L);
receive.setUserId(1652714496280469506L);
iNoticeReceiveService.save(receive);
}
}

View File

@@ -16,11 +16,11 @@
:formatter="formatter"
show-overflow-tooltip
/>
<el-table-column prop="category" label="公告类别" width="180" />
<el-table-column prop="status" label="状态" width="180" />
<el-table-column prop="noticeType.name" label="公告类别" width="180" />
<el-table-column prop="priority" label="优先级" width="180" />
<el-table-column
prop="sendTime"
label="创建时间"
label="生效时间"
sortable
width="180"
column-key="date"
@@ -34,7 +34,7 @@
:formatter="formatDate"
/>
<el-table-column
prop="endDate"
prop="endTime"
label="失效时间"
sortable
width="180"
@@ -42,7 +42,7 @@
:formatter="formatDate"
/>
<el-table-column
prop="sender.userName"
prop="sender.username"
label="发布人"
width="100"
:filters="[
@@ -56,7 +56,7 @@
<el-tag
:type="scope.row.sender.userName === 'Home' ? '' : 'success'"
disable-transitions
>{{ scope.row.sender.userName }}
>{{ scope.row.sender.username }}
</el-tag>
</template>
</el-table-column>
@@ -93,7 +93,7 @@ export default {
return row.title
},
filterTag(value, row) {
return row.sender.userName === value
return row.sender.username === value
},
filterHandler(value, row, column) {
const property = column['property']
@@ -111,14 +111,16 @@ export default {
console.log(index, row.id)
},
handleDelete(index, row) {
axios.delete('http://localhost:8080/notice/' + row.id).then((response) => {
// console.log(row.id)
axios.delete('http://localhost:8621/notice/' + row.id).then((response) => {
console.log(response.data)
this.selectAllNotice()
})
},
selectAllNotice() {
axios.get('http://localhost:8080/notice').then((response) => {
this.tableData = response.data.data
axios.get('http://localhost:8621/notice').then((response) => {
this.tableData = response.data.data;
console.log(response.data.data[0].id)
})
}
},

View File

@@ -0,0 +1,14 @@
<template>
<notice-table/>
</template>
<script>
import NoticeTable from "@/components/NoticeTable.vue";
export default {
name: "NoticeHome"
};
</script>
<style scoped>
</style>