dev:代码优化,该切计划和业务员
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package org.nl.system.controller.notice;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.notice.ISysNoticeService;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "消息通知管理")
|
||||
@RequestMapping("/api/notice")
|
||||
public class SysNoticeController {
|
||||
|
||||
@Autowired
|
||||
private ISysNoticeService noticeService;
|
||||
|
||||
@GetMapping
|
||||
@Log("查询消息通知")
|
||||
@ApiOperation("查询消息通知")
|
||||
//@SaCheckPermission("@el.check('sysNotice:list')")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page){
|
||||
return new ResponseEntity<>(TableDataInfo.build(noticeService.queryAll(whereJson,page)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增消息通知")
|
||||
@ApiOperation("新增消息通知")
|
||||
//@SaCheckPermission("@el.check('sysNotice:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SysNotice entity){
|
||||
noticeService.create(entity);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改消息通知")
|
||||
@ApiOperation("修改消息通知")
|
||||
//@SaCheckPermission("@el.check('sysNotice:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody SysNotice entity){
|
||||
noticeService.update(entity);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除消息通知")
|
||||
@ApiOperation("删除消息通知")
|
||||
//@SaCheckPermission("@el.check('sysNotice:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||
noticeService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("获取未读的接收消息条数")
|
||||
@GetMapping("/countByReceiveNotRead")
|
||||
public ResponseEntity<Object> countByReceiveNotRead(){
|
||||
return new ResponseEntity<>(noticeService.countByReceiveNotRead(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("接收消息分页")
|
||||
@GetMapping("/pageByReceive")
|
||||
public ResponseEntity<Object> pageByReceive(){
|
||||
return new ResponseEntity<>(noticeService.pageByReceive(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("标为已读")
|
||||
@PostMapping("/read")
|
||||
public ResponseEntity<Object> read(@RequestBody String id){
|
||||
noticeService.read(id);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("消息详情")
|
||||
@PostMapping("/findById")
|
||||
public ResponseEntity<Object> findById(@RequestBody String id){
|
||||
return new ResponseEntity<>(noticeService.getById(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改已处理")
|
||||
@PostMapping("/deal")
|
||||
public ResponseEntity<Object> deal(@RequestBody String id){
|
||||
noticeService.deal(id);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("批量已读")
|
||||
@PostMapping("/changeRead")
|
||||
@ApiOperation("批量已读")
|
||||
public ResponseEntity<Object> changeRead(@RequestBody JSONObject jsonObject) {
|
||||
noticeService.changeRead(jsonObject);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.nl.system.service.notice;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @description 服务接口
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
public interface ISysNoticeService extends IService<SysNotice> {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param whereJson 条件
|
||||
* @param pageable 分页参数
|
||||
* @return IPage<SysNotice>
|
||||
*/
|
||||
IPage<SysNotice> queryAll(Map whereJson, PageQuery pageable);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param entity /
|
||||
*/
|
||||
void create(SysNotice entity);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param entity /
|
||||
*/
|
||||
void update(SysNotice entity);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 获取未读的接收消息条数
|
||||
* @return
|
||||
*/
|
||||
Integer countByReceiveNotRead();
|
||||
|
||||
/**
|
||||
* 获取不同类型的前三条信息
|
||||
* @return
|
||||
*/
|
||||
LinkedList<List<SysNotice>> pageByReceive();
|
||||
|
||||
/**
|
||||
* 标记已读
|
||||
* @param id
|
||||
*/
|
||||
void read(String id);
|
||||
|
||||
/**
|
||||
* 处理信息
|
||||
* @param id
|
||||
*/
|
||||
void deal(String id);
|
||||
|
||||
/**
|
||||
* 批量已读
|
||||
* @param jsonObject
|
||||
*/
|
||||
void changeRead(JSONObject jsonObject);
|
||||
|
||||
/**
|
||||
* 写入信息
|
||||
* @param msg: 数据信息
|
||||
* @param title: 唯一
|
||||
* @param type: 类型
|
||||
*/
|
||||
void createNotice(String msg, String title, String type);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.system.service.notice;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2023/5/9
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum NoticeEnum {
|
||||
/**
|
||||
* 未读
|
||||
*/
|
||||
HAVE_READ_OFF("1","未读"),
|
||||
/**
|
||||
* 已读
|
||||
*/
|
||||
HAVE_READ_ON("2", "已读"),
|
||||
/**
|
||||
* 未处理
|
||||
*/
|
||||
DEAL_STATUS_NO("1", "未处理"),
|
||||
/**
|
||||
* 已处理
|
||||
*/
|
||||
DEAL_STATUS_YES("2", "已处理"),
|
||||
/**
|
||||
* 无需处理
|
||||
*/
|
||||
DEAL_STATUS_NO_NEED("3", "无需处理");
|
||||
|
||||
private final String value;
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.nl.system.service.notice;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 通知类型枚举
|
||||
* @Date: 2023/6/15
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum NoticeTypeEnum {
|
||||
/**
|
||||
* 异常
|
||||
*/
|
||||
EXCEPTION("1", "异常"),
|
||||
/**
|
||||
* 警告
|
||||
*/
|
||||
WARN("2", "警告"),
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
NOTIFICATION("3", "通知");
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.nl.system.service.notice.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_notice")
|
||||
public class SysNotice implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "notice_id", type = IdType.NONE)
|
||||
@ApiModelProperty(value = "信息标识")
|
||||
private String notice_id;
|
||||
|
||||
@ApiModelProperty(value = "信息标题")
|
||||
private String notice_title;
|
||||
|
||||
@ApiModelProperty(value = "信息内容")
|
||||
private String notice_content;
|
||||
|
||||
@ApiModelProperty(value = "信息类型")
|
||||
private String notice_type;
|
||||
|
||||
@ApiModelProperty(value = "读取状态")
|
||||
private String have_read;
|
||||
|
||||
@ApiModelProperty(value = "读取时间")
|
||||
private String read_time;
|
||||
|
||||
@ApiModelProperty(value = "处理状态")
|
||||
private String deal_status;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private String create_time;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.nl.system.service.notice.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
public interface SysNoticeMapper extends BaseMapper<SysNotice> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?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="org.nl.system.service.notice.dao.mapper.SysNoticeMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.system.service.notice.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description /
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
@Data
|
||||
public class SysNoticeDto implements Serializable {
|
||||
|
||||
/** 信息标识 */
|
||||
private String notice_id;
|
||||
|
||||
/** 信息标题 */
|
||||
private String notice_title;
|
||||
|
||||
/** 信息内容 */
|
||||
private String notice_content;
|
||||
|
||||
/** 信息类型 */
|
||||
private String notice_type;
|
||||
|
||||
/** 读取状态 */
|
||||
private String have_read;
|
||||
|
||||
/** 读取时间 */
|
||||
private String read_time;
|
||||
|
||||
/** 处理状态 */
|
||||
private String deal_status;
|
||||
|
||||
/** 创建时间 */
|
||||
private String create_time;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.nl.system.service.notice.dto;
|
||||
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
public class SysNoticeQuery extends BaseQuery<SysNotice> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package org.nl.system.service.notice.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.mnt.websocket.MsgType;
|
||||
import org.nl.modules.mnt.websocket.SocketMsg;
|
||||
import org.nl.modules.mnt.websocket.WebSocketServer;
|
||||
import org.nl.system.service.notice.ISysNoticeService;
|
||||
import org.nl.system.service.notice.NoticeEnum;
|
||||
import org.nl.system.service.notice.dao.SysNotice;
|
||||
import org.nl.system.service.notice.dao.mapper.SysNoticeMapper;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @description 服务实现
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {
|
||||
|
||||
@Autowired
|
||||
private SysNoticeMapper sysNoticeMapper;
|
||||
|
||||
@Autowired
|
||||
private SysDictMapper dictMapper;
|
||||
|
||||
@Resource
|
||||
private WebSocketServer webSocketServer;
|
||||
|
||||
@Override
|
||||
public IPage<SysNotice> queryAll(Map whereJson, PageQuery page) {
|
||||
String notice_title = ObjectUtil.isNotEmpty(whereJson.get("notice_title"))
|
||||
? whereJson.get("notice_title").toString() : null;
|
||||
String notice_type = ObjectUtil.isNotEmpty(whereJson.get("notice_type"))
|
||||
? whereJson.get("notice_type").toString() : null;
|
||||
String have_read = ObjectUtil.isNotEmpty(whereJson.get("have_read"))
|
||||
? whereJson.get("have_read").toString() : null;
|
||||
String deal_status = ObjectUtil.isNotEmpty(whereJson.get("deal_status"))
|
||||
? whereJson.get("deal_status").toString() : null;
|
||||
LambdaQueryWrapper<SysNotice> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(notice_title), SysNotice::getNotice_title, notice_title)
|
||||
.eq(ObjectUtil.isNotEmpty(notice_type), SysNotice::getNotice_type, notice_type)
|
||||
.eq(ObjectUtil.isNotEmpty(have_read), SysNotice::getHave_read, have_read)
|
||||
.eq(ObjectUtil.isNotEmpty(deal_status), SysNotice::getDeal_status, deal_status)
|
||||
.orderByAsc(SysNotice::getHave_read)
|
||||
.orderByDesc(SysNotice::getCreate_time);
|
||||
IPage<SysNotice> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
sysNoticeMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(SysNotice entity) {
|
||||
String now = DateUtil.now();
|
||||
|
||||
entity.setNotice_id(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
entity.setCreate_time(now);
|
||||
sysNoticeMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(SysNotice entity) {
|
||||
SysNotice dto = sysNoticeMapper.selectById(entity.getNotice_id());
|
||||
if (dto == null) {
|
||||
throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
}
|
||||
sysNoticeMapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Set<String> ids) {
|
||||
// 真删除
|
||||
sysNoticeMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countByReceiveNotRead() {
|
||||
List<SysNotice> sysNotices = sysNoticeMapper.selectList(new LambdaQueryWrapper<SysNotice>()
|
||||
.eq(SysNotice::getHave_read, NoticeEnum.HAVE_READ_OFF.getValue()));
|
||||
return ObjectUtil.isNotEmpty(sysNotices) ? sysNotices.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedList<List<SysNotice>> pageByReceive() {
|
||||
LinkedList<List<SysNotice>> result = new LinkedList<>();
|
||||
List<Dict> dictList = dictMapper.selectList(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getCode, "notice_type")
|
||||
.orderByAsc(Dict::getDictSort));
|
||||
dictList.forEach(dict -> {
|
||||
List<SysNotice> sysNotices = sysNoticeMapper.selectList(new LambdaQueryWrapper<SysNotice>()
|
||||
.eq(SysNotice::getNotice_type, dict.getValue())
|
||||
.eq(SysNotice::getHave_read, NoticeEnum.HAVE_READ_OFF.getValue())
|
||||
.orderByDesc(SysNotice::getCreate_time)
|
||||
.last("LIMIT 0,3"));
|
||||
result.add(sysNotices);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(String id) {
|
||||
SysNotice notice = this.getById(id);
|
||||
if (ObjectUtil.isEmpty(notice)) {
|
||||
throw new BadRequestException("该信息不存在!");
|
||||
}
|
||||
notice.setHave_read(NoticeEnum.HAVE_READ_ON.getValue());
|
||||
notice.setRead_time(DateUtil.now());
|
||||
sysNoticeMapper.updateById(notice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deal(String id) {
|
||||
SysNotice notice = this.getById(id);
|
||||
if (ObjectUtil.isEmpty(notice)) {
|
||||
throw new BadRequestException("该信息不存在!");
|
||||
}
|
||||
// 设置处理
|
||||
notice.setDeal_status(NoticeEnum.DEAL_STATUS_YES.getValue());
|
||||
// 判断是否读取
|
||||
if (notice.getHave_read().equals(NoticeEnum.HAVE_READ_OFF.getValue())) {
|
||||
// 标记已读并设置读取时间
|
||||
notice.setHave_read(NoticeEnum.HAVE_READ_ON.getValue());
|
||||
notice.setRead_time(DateUtil.now());
|
||||
}
|
||||
sysNoticeMapper.updateById(notice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeRead(JSONObject jsonObject) {
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
String haveRead = jsonObject.getString("have_read");
|
||||
List<SysNotice> sysNotices = JSON.parseArray(data.toJSONString(), SysNotice.class);
|
||||
sysNotices.forEach(sysNotice -> sysNotice.setHave_read(haveRead));
|
||||
this.updateBatchById(sysNotices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createNotice(String msg, String title, String type) {
|
||||
// log.info("创建消息通知-信息:{}, 标题:{}, 类型:{}", msg, title, type);
|
||||
// 获取标题相同的信息
|
||||
List<SysNotice> sysNotices = sysNoticeMapper.selectList(new LambdaQueryWrapper<SysNotice>()
|
||||
.eq(SysNotice::getNotice_title, title)
|
||||
.eq(SysNotice::getHave_read, NoticeEnum.HAVE_READ_OFF.getValue()));
|
||||
SysNotice noticeDto = SysNotice.builder()
|
||||
.notice_id(IdUtil.getSnowflake(1, 1).nextIdStr())
|
||||
.notice_type(type)
|
||||
.notice_title(title)
|
||||
.notice_content(msg)
|
||||
.deal_status(NoticeEnum.DEAL_STATUS_NO.getValue())
|
||||
.have_read(NoticeEnum.HAVE_READ_OFF.getValue())
|
||||
.create_time(DateUtil.now())
|
||||
.build();
|
||||
if (ObjectUtil.isNotEmpty(sysNotices)) {
|
||||
noticeDto.setNotice_id(sysNotices.get(0).getNotice_id());
|
||||
}
|
||||
// 插入/修改
|
||||
this.saveOrUpdate(noticeDto);
|
||||
JSONObject res = new JSONObject();
|
||||
res.put("data", "notice_message_update");
|
||||
SocketMsg messageInfo = new SocketMsg(res, MsgType.INFO);
|
||||
try {
|
||||
WebSocketServer.sendInfo(messageInfo, "messageInfo");
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("消息发送失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user