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:
@@ -1,7 +1,13 @@
|
|||||||
package com.cfive.pinnacle.controller;
|
package com.cfive.pinnacle.controller;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import com.cfive.pinnacle.entity.Notice;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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>
|
* <p>
|
||||||
@@ -11,8 +17,55 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
* @author FatttSnake
|
* @author FatttSnake
|
||||||
* @since 2023-04-30
|
* @since 2023-04-30
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/notice")
|
@RequestMapping("/notice")
|
||||||
|
@CrossOrigin
|
||||||
public class NoticeController {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class Notice implements Serializable {
|
|||||||
private Long typeId;
|
private Long typeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布者
|
* 发布者id
|
||||||
*/
|
*/
|
||||||
@TableField("sender_id")
|
@TableField("sender_id")
|
||||||
private Long senderId;
|
private Long senderId;
|
||||||
@@ -104,6 +104,12 @@ public class Notice implements Serializable {
|
|||||||
@TableField("old")
|
@TableField("old")
|
||||||
private Integer old;
|
private Integer old;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布者
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private User sender;
|
||||||
|
|
||||||
@TableField("deleted")
|
@TableField("deleted")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer deleted;
|
private Integer deleted;
|
||||||
@@ -111,4 +117,6 @@ public class Notice implements Serializable {
|
|||||||
@TableField("version")
|
@TableField("version")
|
||||||
@Version
|
@Version
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.cfive.pinnacle.entity.Notice;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 公告 Mapper 接口
|
* 公告 Mapper 接口
|
||||||
@@ -14,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface NoticeMapper extends BaseMapper<Notice> {
|
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||||
|
Notice selectByNoticeId(Long nid);
|
||||||
|
|
||||||
|
List<Notice> selectAllNoticeId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
|
|||||||
import com.cfive.pinnacle.entity.Notice;
|
import com.cfive.pinnacle.entity.Notice;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 公告 服务类
|
* 公告 服务类
|
||||||
@@ -12,5 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
* @since 2023-04-30
|
* @since 2023-04-30
|
||||||
*/
|
*/
|
||||||
public interface INoticeService extends IService<Notice> {
|
public interface INoticeService extends IService<Notice> {
|
||||||
|
Notice selectByNoticeId(Long nid);
|
||||||
|
|
||||||
|
List<Notice> selectAllNoticeId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import com.cfive.pinnacle.entity.Notice;
|
|||||||
import com.cfive.pinnacle.mapper.NoticeMapper;
|
import com.cfive.pinnacle.mapper.NoticeMapper;
|
||||||
import com.cfive.pinnacle.service.INoticeService;
|
import com.cfive.pinnacle.service.INoticeService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 公告 服务实现类
|
* 公告 服务实现类
|
||||||
@@ -16,5 +19,15 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!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">
|
<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>
|
</mapper>
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
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.NoticeType;
|
||||||
|
import com.cfive.pinnacle.entity.User;
|
||||||
|
import com.cfive.pinnacle.service.IDepartmentService;
|
||||||
|
import com.cfive.pinnacle.service.INoticeReceiveService;
|
||||||
|
import com.cfive.pinnacle.service.INoticeTypeService;
|
||||||
|
import com.cfive.pinnacle.service.IUserService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class NoticeTest {
|
||||||
|
@Autowired
|
||||||
|
private NoticeController noticeController;
|
||||||
|
@Autowired
|
||||||
|
private INoticeTypeService iNoticeTypeService;
|
||||||
|
@Autowired
|
||||||
|
private IDepartmentService iDepartmentService;
|
||||||
|
@Autowired
|
||||||
|
private IUserService iUserService;
|
||||||
|
@Autowired
|
||||||
|
private INoticeReceiveService iNoticeReceiveService;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectByIdTest() {
|
||||||
|
Result notice = noticeController.selectByNoticeId(21L);
|
||||||
|
System.out.println(notice.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectAllTest() {
|
||||||
|
Result noticeList = noticeController.selectAllNoticeId();
|
||||||
|
System.out.println(noticeList.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateTest() {
|
||||||
|
Result notice =noticeController.selectByNoticeId(23L);
|
||||||
|
Result updateNotice = noticeController.updateNotice((Notice)notice.getData());
|
||||||
|
System.out.println(updateNotice.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertNoticeTest() {
|
||||||
|
Notice notice = new Notice();
|
||||||
|
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);
|
||||||
|
notice.setContent("Content1");
|
||||||
|
Result updateNotice = noticeController.addNotice(notice);
|
||||||
|
System.out.println(updateNotice.getData());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void insertNoticeTypeTest(){
|
||||||
|
NoticeType noticeType = new NoticeType();
|
||||||
|
noticeType.setName("通知公告");
|
||||||
|
iNoticeTypeService.save(noticeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertNoticeRecTest(){
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername("cyb");
|
||||||
|
user.setPasswd("123");
|
||||||
|
user.setDepartmentId(1652713919467151362L);
|
||||||
|
iUserService.save(user);
|
||||||
|
// iNoticeTypeService.save(noticeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
131
ui/src/components/NoticeTable.vue
Normal file
131
ui/src/components/NoticeTable.vue
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<template>
|
||||||
|
<el-button @click="resetDateFilter">reset date filter</el-button>
|
||||||
|
<el-button @click="clearFilter">reset all filters</el-button>
|
||||||
|
<el-table
|
||||||
|
ref="tableRef"
|
||||||
|
row-key="date"
|
||||||
|
:data="tableData"
|
||||||
|
style="width: 100%"
|
||||||
|
border
|
||||||
|
highlight-current-row
|
||||||
|
>
|
||||||
|
<el-table-column
|
||||||
|
prop="title"
|
||||||
|
label="公告标题"
|
||||||
|
width="180"
|
||||||
|
: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="sendTime"
|
||||||
|
label="创建时间"
|
||||||
|
sortable
|
||||||
|
width="180"
|
||||||
|
column-key="date"
|
||||||
|
:filters="[
|
||||||
|
{ text: '2016-05-01', value: '2016-05-01' },
|
||||||
|
{ text: '2016-05-02', value: '2016-05-02' },
|
||||||
|
{ text: '2016-05-03', value: '2016-05-03' },
|
||||||
|
{ text: '2016-05-04', value: '2016-05-04' }
|
||||||
|
]"
|
||||||
|
:filter-method="filterHandler"
|
||||||
|
:formatter="formatDate"
|
||||||
|
/>
|
||||||
|
<el-table-column
|
||||||
|
prop="endDate"
|
||||||
|
label="失效时间"
|
||||||
|
sortable
|
||||||
|
width="180"
|
||||||
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
|
:formatter="formatDate"
|
||||||
|
/>
|
||||||
|
<el-table-column
|
||||||
|
prop="sender.userName"
|
||||||
|
label="发布人"
|
||||||
|
width="100"
|
||||||
|
:filters="[
|
||||||
|
{ text: 'Home', value: 'Home' },
|
||||||
|
{ text: 'Office', value: 'Office' }
|
||||||
|
]"
|
||||||
|
:filter-method="filterTag"
|
||||||
|
filter-placement="bottom-end"
|
||||||
|
>
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tag
|
||||||
|
:type="scope.row.sender.userName === 'Home' ? '' : 'success'"
|
||||||
|
disable-transitions
|
||||||
|
>{{ scope.row.sender.userName }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="Operations">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button size="small" @click="handleEdit(scope.$index, scope.row)"
|
||||||
|
>编辑</el-button
|
||||||
|
>
|
||||||
|
<el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
tableData: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
resetDateFilter() {
|
||||||
|
this.$refs.tableRef.clearFilter(['date'])
|
||||||
|
},
|
||||||
|
clearFilter() {
|
||||||
|
this.$refs.tableRef.clearFilter()
|
||||||
|
},
|
||||||
|
formatter(row, column) {
|
||||||
|
return row.title
|
||||||
|
},
|
||||||
|
filterTag(value, row) {
|
||||||
|
return row.sender.userName === value
|
||||||
|
},
|
||||||
|
filterHandler(value, row, column) {
|
||||||
|
const property = column['property']
|
||||||
|
return row[property] === value
|
||||||
|
},
|
||||||
|
formatDate(row, column) {
|
||||||
|
// 获取单元格数据
|
||||||
|
let data = row[column.property]
|
||||||
|
if (data == null) return null
|
||||||
|
|
||||||
|
let dt = data.replace('T', ' ')
|
||||||
|
return dt
|
||||||
|
},
|
||||||
|
handleEdit(index, row) {
|
||||||
|
console.log(index, row.id)
|
||||||
|
},
|
||||||
|
handleDelete(index, row) {
|
||||||
|
axios.delete('http://localhost:8080/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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.selectAllNotice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
Reference in New Issue
Block a user