信息通知前端、后端代码、websocket(el-admin版本)、添加sys_dict到excel

This commit is contained in:
2023-03-15 15:39:56 +08:00
parent 86a211c1de
commit 5328c04432
18 changed files with 1455 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
package org.nl.common.websocket;
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author ZhangHouYing
* @date 2019-08-10 9:56
*/
public enum MsgType {
/** 连接 */
CONNECT,
/** 关闭 */
CLOSE,
/** 信息 */
INFO,
/** 错误 */
ERROR
}

View File

@@ -0,0 +1,18 @@
package org.nl.common.websocket;
import lombok.Data;
/**
* @author ZhangHouYing
* @date 2019-08-10 9:55
*/
@Data
public class SocketMsg {
private Object msg;
private MsgType msgType;
public SocketMsg(Object msg, MsgType msgType) {
this.msg = msg;
this.msgType = msgType;
}
}

View File

@@ -0,0 +1,138 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.common.websocket;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author ZhangHouYing
* @date 2019-08-10 15:46
*/
@ServerEndpoint("/webSocket/{sid}")
@Slf4j
@Component
public class WebSocketServer {
/**
* concurrent包的线程安全Set用来存放每个客户端对应的MyWebSocket对象。
*/
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
/**
* 接收sid
*/
private String sid="";
/**
* 连接建立成功调用的方法
* */
@OnOpen
public void onOpen(Session session,@PathParam("sid") String sid) {
this.session = session;
//如果存在就先删除一个,防止重复推送消息
for (WebSocketServer webSocket:webSocketSet) {
if (webSocket.sid.equals(sid)) {
webSocketSet.remove(webSocket);
}
}
webSocketSet.add(this);
this.sid=sid;
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
webSocketSet.remove(this);
}
/**
* 收到客户端消息后调用的方法
* @param message 客户端发送过来的消息*/
@OnMessage
public void onMessage(String message, Session session) {
log.info("收到来"+sid+"的信息:"+message);
//群发消息
for (WebSocketServer item : webSocketSet) {
try {
item.sendMessage(message);
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
@OnError
public void onError(Session session, Throwable error) {
log.error("发生错误");
error.printStackTrace();
}
/**
* 实现服务器主动推送
*/
private void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
/**
* 群发自定义消息
* */
public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException {
String message = JSONObject.toJSONString(socketMsg);
log.info("推送消息到"+sid+",推送内容:"+message);
for (WebSocketServer item : webSocketSet) {
try {
//这里可以设定只推送给这个sid的为null则全部推送
if(sid==null) {
item.sendMessage(message);
}else if(item.sid.equals(sid)){
item.sendMessage(message);
}
} catch (IOException ignored) { }
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
WebSocketServer that = (WebSocketServer) o;
return Objects.equals(session, that.session) &&
Objects.equals(sid, that.sid);
}
@Override
public int hashCode() {
return Objects.hash(session, sid);
}
}

View File

@@ -0,0 +1,100 @@
package org.nl.config.mybatis;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.springframework.util.StringUtils;
import java.util.Scanner;
public class CodeGenerator {
/**
* <p>
* 读取控制台内容
* </p>
*/
public static String scanner(String tip) {
Scanner scanner = new Scanner(System.in);
StringBuilder help = new StringBuilder();
help.append("请输入" + tip + "");
System.out.println(help.toString());
if (scanner.hasNext()) {
String ipt = scanner.next();
if (!StringUtils.isEmpty(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输入正确的" + tip + "");
}
public static void main(String[] args) {
String menusName = scanner("请输入对应菜单名称");
String moduleName = scanner("请输入模块名称");
// Mybatis代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
// 默认不覆盖
gc.setFileOverride(false);
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java/");
gc.setAuthor("generator");
gc.setOpen(false);
// gc.setSwagger2(true);
gc.setEntityName("%s");
gc.setServiceName("I%sService");
gc.setServiceImplName("%sServiceImpl");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://192.168.81.252:3306/hl_one_mes?setUnicode=true&characterEncoding=utf8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("Root.123456");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName("");
pc.setParent("org.nl."+menusName);
pc.setController("controller." + moduleName);
pc.setMapper("service."+moduleName+".dao.mapper");
pc.setService("service." + moduleName);
pc.setServiceImpl("service." + moduleName + ".impl");
pc.setEntity("service." + moduleName + ".dao");
pc.setXml("service." + moduleName + ".dao.mapper");
mpg.setPackageInfo(pc);
// // 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
}
};
mpg.setCfg(cfg);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父类
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
// 写于父类中的公共字段
// strategy.setSuperEntityColumns("id");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(false);
// strategy.setTablePrefix("sys_");
mpg.setStrategy(strategy);
// mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
}

View File

@@ -0,0 +1,104 @@
package org.nl.system.controller.notice;
import com.alibaba.fastjson.JSONObject;
import org.nl.common.anno.Log;
import org.nl.system.service.notice.NoticeService;
import org.nl.system.service.notice.dto.NoticeDto;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
/**
* @author lyd
* @date 2023-03-10
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "消息通知管理")
@RequestMapping("/api/notice")
@Slf4j
public class NoticeController {
private final NoticeService noticeService;
@GetMapping
@Log("查询消息通知")
@ApiOperation("查询消息通知")
//@SaCheckPermission("@el.check('notice:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){
return new ResponseEntity<>(noticeService.queryAll(whereJson,page),HttpStatus.OK);
}
@PostMapping
@Log("新增消息通知")
@ApiOperation("新增消息通知")
//@SaCheckPermission("@el.check('notice:add')")
public ResponseEntity<Object> create(@Validated @RequestBody NoticeDto dto){
noticeService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改消息通知")
@ApiOperation("修改消息通知")
//@SaCheckPermission("@el.check('notice:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody NoticeDto dto){
noticeService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除消息通知")
@ApiOperation("删除消息通知")
//@SaCheckPermission("@el.check('notice:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] 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.selectById(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);
}
}

View File

@@ -0,0 +1,103 @@
package org.nl.system.service.notice;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.system.service.notice.dto.NoticeDto;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
/**
* @description 服务接口
* @author lyd
* @date 2023-03-10
**/
public interface NoticeService {
/**
* 查询数据分页
* @param whereJson 条件
* @param page 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
* @param whereJson 条件参数
* @return List<NoticeDto>
*/
List<NoticeDto> queryAll(Map whereJson);
/**
* 根据ID查询
* @param notice_id ID
* @return Notice
*/
NoticeDto findById(String notice_id);
/**
* 根据编码查询
* @param code code
* @return Notice
*/
NoticeDto findByCode(String code);
/**
* 创建
* @param dto /
*/
void create(NoticeDto dto);
/**
* 编辑
* @param dto /
*/
void update(NoticeDto dto);
/**
* 多选删除
* @param ids /
*/
void deleteAll(Long[] ids);
void createNotice(String msg, String title, String type);
/**
* 获取未读的接收消息条数
*/
Integer countByReceiveNotRead();
/**
* 获取未读数据
* @return
*/
JSONArray pageByReceive();
/**
* 修改成已读
* @param id
*/
void read(String id);
/**
* 根据id获取消息
* @param id
* @return
*/
JSONObject selectById(String id);
/**
* 修改已处理
* @param id
* @return
*/
void deal(String id);
/**
* 批量已读
* @param jsonObject
*/
void changeRead(JSONObject jsonObject);
}

View File

@@ -0,0 +1,43 @@
package org.nl.system.service.notice.dto;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
/**
* @description /
* @author lyd
* @date 2023-03-10
**/
@Data
@Builder
public class NoticeDto implements Serializable {
/** 信息标识 */
/** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class)
private Long 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;
}

View File

@@ -0,0 +1,217 @@
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.websocket.MsgType;
import org.nl.common.websocket.SocketMsg;
import org.nl.common.websocket.WebSocketServer;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.system.service.notice.NoticeService;
import org.nl.system.service.notice.dto.NoticeDto;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description 服务实现
* @author lyd
* @date 2023-03-10
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class NoticeServiceImpl implements NoticeService {
private final WebSocketServer webSocketServer;
@Override
public Map<String,Object> queryAll(Map whereJson, Pageable page){
// WQLObject wo = WQLObject.getWQLObject("sys_notice");
// ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "1=1", "have_read, create_time desc");
// final JSONObject json = rb.pageResult();
// return json;
Map param = new HashMap();
param.put("flag", "1");
param.put("notice_title", ObjectUtil.isNotEmpty(whereJson.get("notice_title"))?whereJson.get("notice_title"):"");
param.put("deal_status", ObjectUtil.isNotEmpty(whereJson.get("deal_status"))?whereJson.get("deal_status"):"");
param.put("notice_type", ObjectUtil.isNotEmpty(whereJson.get("notice_type"))?whereJson.get("notice_type"):"");
param.put("have_read", ObjectUtil.isNotEmpty(whereJson.get("have_read"))?whereJson.get("have_read"):"");
JSONObject queryNotice = WQL.getWO("QUERY_NOTICE").addParamMap(param).pageQuery(WqlUtil.getHttpContext(page), "have_read, create_time desc");
return queryNotice;
}
@Override
public List<NoticeDto> queryAll(Map whereJson){
WQLObject wo = WQLObject.getWQLObject("sys_notice");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(NoticeDto.class);
return null;
}
@Override
public NoticeDto findById(String notice_id) {
WQLObject wo = WQLObject.getWQLObject("sys_notice");
JSONObject json = wo.query("notice_id = '" + notice_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)){
return json.toJavaObject( NoticeDto.class);
}
return null;
}
@Override
public NoticeDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("sys_notice");
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)){
return json.toJavaObject( NoticeDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(NoticeDto dto) {
String now = DateUtil.now();
dto.setNotice_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setCreate_time(now);
WQLObject wo = WQLObject.getWQLObject("sys_notice");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(NoticeDto dto) {
NoticeDto entity = this.findById(String.valueOf(dto.getNotice_id()));
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
WQLObject wo = WQLObject.getWQLObject("sys_notice");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
WQLObject wo = WQLObject.getWQLObject("sys_notice");
for (Long notice_id: ids) {
wo.delete("notice_id = '" + notice_id + "'");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void createNotice(String msg, String title, String type) {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONObject jsonObject = sysNotice.query("notice_title = '" + title + "' AND have_read = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonObject)) return;
NoticeDto noticeDto = NoticeDto.builder()
.notice_id(IdUtil.getSnowflake(1,1).nextId())
.notice_type(type)
.notice_title(title)
.notice_content(msg)
.deal_status("1")
.have_read("1")
.create_time(DateUtil.now())
.build();
JSONObject json = JSONObject.parseObject(JSON.toJSONString(noticeDto));
sysNotice.insert(json);
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("消息发送失败");
}
}
@Override
public Integer countByReceiveNotRead() {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONArray objects = sysNotice.query("have_read = '1'").getResultJSONArray(0);
return ObjectUtil.isEmpty(objects) ? 0 : objects.size();
}
@Override
public JSONArray pageByReceive() {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
WQLObject dict = WQLObject.getWQLObject("sys_dict");
JSONArray res = new JSONArray();
JSONArray dicts = dict.query("code = 'notice_type'", "value").getResultJSONArray(0);
for (int i = 0; i < dicts.size(); i++) {
JSONObject dictsJSONObject = dicts.getJSONObject(i);
JSONArray resultJSONArray = sysNotice.query("notice_type = '"
+ dictsJSONObject.getString("value") + "' AND have_read = '1' limit 0,3").getResultJSONArray(0);
res.add(resultJSONArray);
}
return res;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void read(String id) {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONObject object = sysNotice.query("notice_id = '" + id + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(object)) throw new BadRequestException("该信息不存在!");
object.put("have_read", "2");
object.put("read_time", DateUtil.now());
sysNotice.update(object);
}
@Override
public JSONObject selectById(String id) {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONObject object = sysNotice.query("notice_id = '" + id + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(object)) throw new BadRequestException("该信息不存在!");
return object;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deal(String id) {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONObject object = this.selectById(id);
if (ObjectUtil.isEmpty(object)) throw new BadRequestException("该信息不存在!");
// 标记已修改
object.put("deal_status", "2");
// 判断是否读取
if (object.getString("have_read").equals("1")) {
object.put("have_read", "2");
object.put("read_time", DateUtil.now());
}
sysNotice.update(object);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void changeRead(JSONObject jsonObject) {
WQLObject sysNotice = WQLObject.getWQLObject("sys_notice");
JSONArray data = jsonObject.getJSONArray("data");
String haveRead = jsonObject.getString("have_read");
for (int i = 0; i < data.size(); i++) {
JSONObject jsonObject1 = data.getJSONObject(i);
if (jsonObject1.getString("have_read").equals(haveRead)) continue;
jsonObject1.put("have_read", haveRead);
jsonObject1.put("read_time", DateUtil.now());
sysNotice.update(jsonObject1);
}
}
}

View File

@@ -0,0 +1,64 @@
[交易说明]
交易名: 通知查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.notice_title TYPEAS s_string
输入.deal_status TYPEAS s_string
输入.notice_type TYPEAS s_string
输入.have_read TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT *
FROM sys_notice
WHERE
1 = 1
OPTION 输入.notice_title <> ""
notice_title like "%" 输入.notice_title "%"
ENDOPTION
OPTION 输入.deal_status <> ""
deal_status = 输入.deal_status
ENDOPTION
OPTION 输入.notice_type <> ""
notice_type = 输入.notice_type
ENDOPTION
OPTION 输入.have_read <> ""
have_read = 输入.have_read
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF

View File

@@ -33,7 +33,6 @@
"url": "https://github.com/elunez/eladmin/issues"
},
"dependencies": {
"vue-color": "^2.8.1",
"@logicflow/core": "^1.1.22",
"@logicflow/extension": "^1.1.22",
"@riophae/vue-treeselect": "0.4.0",
@@ -62,6 +61,8 @@
"screenfull": "4.2.0",
"sortablejs": "1.8.4",
"vue": "2.6.10",
"vue-bus": "^1.2.1",
"vue-color": "^2.8.1",
"vue-count-to": "1.0.13",
"vue-cropper": "0.4.9",
"vue-echarts": "^5.0.0-beta.0",

View File

@@ -15,6 +15,8 @@
<el-tooltip content="全屏缩放" effect="dark" placement="bottom">
<screenfull id="screenfull" class="right-menu-item hover-effect" />
</el-tooltip>
<notice-icon class="right-menu-item"/>
<notice-icon-reader ref="noticeIconReader"/>
<el-tooltip content="布局设置" effect="dark" placement="bottom">
<size-select id="size-select" class="right-menu-item hover-effect" />
@@ -58,9 +60,13 @@ import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'
import Avatar from '@/assets/images/avatar.png'
import NoticeIcon from "@/views/system/notice/NoticeIcon.vue";
import NoticeIconReader from "@/views/system/notice/NoticeIconReader.vue";
export default {
components: {
NoticeIconReader,
NoticeIcon,
Breadcrumb,
Hamburger,
Screenfull,

View File

@@ -40,6 +40,8 @@ import { getValueByCode } from '@/api/system/param'
import 'jquery'
// 安装总线
import VueBus from 'vue-bus'
Vue.use(scroll)
Vue.use(AFTableColumn)
@@ -48,6 +50,7 @@ Vue.use(VueHighlightJS)
Vue.use(mavonEditor)
Vue.use(permission)
Vue.use(dict)
Vue.use(VueBus)
// 全局设置控件样式https://codeantenna.com/a/0IN5FMJk5h
Element.Table.props.border = { type: Boolean, default: true }

View File

@@ -0,0 +1,125 @@
<template>
<el-popover
placement="top-end"
width="450"
trigger="manual"
v-model="visible">
<div style="margin: 5px" v-loading="loading">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :label="d.label" :name="d.value" v-for="d in dict.notice_type" :key="d.id">
<el-empty v-show="notReadMsgList[d.value-1].length == 0" description="暂无信息" ></el-empty>
<div v-for="o in notReadMsgList[d.value-1]" :key="o.notice_id">
<a href="javascript:" @click="showMessage(o)">
<el-row @click="showMessage">
<el-col :span="6">
<el-tag type="danger">{{ dict.label.notice_type[o.notice_type] }}</el-tag>
</el-col>
<el-col :span="9" style="font-weight: bolder">{{o.notice_title}}</el-col>
<el-col :span="9" style="color: #cccccc">{{o.create_time}}</el-col>
</el-row>
<el-divider ></el-divider>
</a>
</div>
</el-tab-pane>
</el-tabs>
<div style="text-align: right">
<el-button type="text" @click="visible = !visible">取消</el-button>
<el-button type="text" @click="toSiteMessage" >查看更多>></el-button>
</div>
</div>
<span slot="reference" @click="fetchNotice">
<el-badge :value="notReadMsgCount" :hidden="notReadMsgCount==0">
<el-icon class="el-icon-bell" style="font-size: 22px;"></el-icon>
</el-badge>
</span>
</el-popover>
</template>
<script>
import crudNotice from './api/notice'
import { NOTICE_MESSAGE_UPDATE, NOTICE_SHOW_MESSAGE } from './code/VueBaseCode'
export default {
dicts: ['deal_status', 'have_read_type', 'notice_type'],
name: 'NoticeIcon',
data() {
return {
loading: false,
visible: false,
activeName: '1',
// 未读消息数量
notReadMsgCount: 0,
// 消息内容
notReadMsgList: []
}
},
methods: {
/**
* 打开列表页
*/
fetchNotice() {
if (this.visible) {
this.visible = false
this.loading = false
} else {
this.visible = true
this.loading = true
// 消息列表
crudNotice.pageByReceive().then(res => {
this.notReadMsgList = res
this.loading = false
console.log(this.notReadMsgList)
})
}
},
/**
* 未读的消息数量
*/
receivedCount() {
// 查询当前用户的未读消息数量
crudNotice.countByReceiveNotRead().then(res => {
this.notReadMsgCount = res
})
},
/**
* 查看消息
*/
showMessage(message) {
// 标记已读
crudNotice.read(message.notice_id).then(() => {
this.receivedCount()
})
this.$bus.emit(NOTICE_SHOW_MESSAGE, message)
this.visible = false
},
/**
* 跳转到站内信界面
*/
toSiteMessage() {
this.$router.push({
path: '/monitor/notice'
})
this.visible = false
},
handleClick(tab, event) {
// console.log(this.dict.notice_type)
// console.log(tab, event)
}
},
mounted() {
this.receivedCount()
this.$bus.on(NOTICE_MESSAGE_UPDATE, this.receivedCount) // 监听事件
},
destroyed() {
this.$bus.off(NOTICE_MESSAGE_UPDATE)
}
}
</script>
<style scoped>
/deep/.el-badge__content.is-fixed {
top: 10px;
}
.el-divider{
margin: 8px 0;
}
</style>

View File

@@ -0,0 +1,122 @@
<template>
<el-dialog
title="消息详情"
:visible.sync="visible"
:modal-append-to-body="false"
:append-to-body="true"
width="40%">
<div style="margin-top: 5px">
<el-descriptions class="margin-top" :column="3" border>
<el-descriptions-item>
<template slot="label">
<i class="el-icon-user"></i>
标题
</template>
{{message.notice_title}}
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
<i class="el-icon-mobile-phone"></i>
信息类型
</template>
<el-tag size="small" type="danger">
{{ dict.label.notice_type[message.notice_type] }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
<i class="el-icon-location-outline"></i>
创建时间
</template>
{{ message.create_time }}
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
<i class="el-icon-tickets"></i>
处理情况
</template>
<el-tag size="small" type="warning">
{{ dict.label.deal_status[message.deal_status] }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
<i class="el-icon-office-building"></i>
内容
</template>
{{message.notice_content}}
</el-descriptions-item>
</el-descriptions>
</div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" size="mini" @click="handleCancel"> </el-button>
</span>
</el-dialog>
</template>
<script>
import crudNotice from './api/notice'
import { NOTICE_SHOW_MESSAGE } from './code/VueBaseCode'
export default {
dicts: ['deal_status', 'have_read_type', 'notice_type'],
name: 'NoticeIconReader',
data() {
return {
visible: false,
confirmLoading: false,
message: {
have_read: false,
notice_type: null,
deal_status: null,
notice_content: null,
notice_id: '',
create_time: '',
notice_title: '',
read_time: ''
},
bodyStyle: {
padding: '0',
maxHeight: (window.innerHeight * 0.6) + 'px',
'overflow-y': 'auto'
},
modelStyle: {
width: '60%',
style: { top: '10px' },
fullScreen: false
}
}
},
methods: {
/**
* 显示消息内容
*/
show(row) {
// console.log('sss', row)
this.visible = true
this.confirmLoading = true
this.message = row
crudNotice.findById(row.notice_id).then(res => {
this.message = res
this.confirmLoading = false
})
},
/**
* 关闭
*/
handleCancel() {
this.visible = false
}
},
mounted() {
// 绑定查看站内信消息事件
this.$bus.on(NOTICE_SHOW_MESSAGE, this.show)
},
destroyed() {
this.$bus.off(NOTICE_SHOW_MESSAGE)
}
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,94 @@
import request from '@/utils/request'
/**
* 获取未读信息
* @returns {AxiosPromise}
*/
export function pageByReceive() {
return request({
url: '/api/notice/pageByReceive',
method: 'get'
})
}
/**
* 未读消息数量
*/
export function countByReceiveNotRead() {
return request({
url: '/api/notice/countByReceiveNotRead',
method: 'GET'
})
}
/**
* 标记为已读
*/
export function read(id) {
return request({
url: '/api/notice/read',
method: 'post',
data: id
})
}
/**
* 标记为已修改
*/
export function deal(id) {
return request({
url: '/api/notice/deal',
method: 'post',
data: id
})
}
/**
* 批量已读
* @param data
* @returns {*}
*/
export function changeRead(data) {
return request({
url: 'api/notice/changeRead',
method: 'post',
data: data
})
}
/**
* 查看消息
*/
export function findById(id) {
return request({
url: '/api/notice/findById',
method: 'post',
data: id
})
}
export function add(data) {
return request({
url: 'api/notice',
method: 'post',
data
})
}
export function del(ids) {
return request({
url: 'api/notice/',
method: 'delete',
data: ids
})
}
export function edit(data) {
return request({
url: 'api/notice',
method: 'put',
data
})
}
export default { add, edit, del, pageByReceive, countByReceiveNotRead, read, findById, deal, changeRead }

View File

@@ -0,0 +1,15 @@
/* 消息服务 */
/**
* 显示站内信消息
*/
export const NOTICE_SHOW_MESSAGE = 'notice_show_message'
/**
* 通知消息发生消息更新 主要是 未读数量更新
*/
export const NOTICE_MESSAGE_UPDATE = 'notice_message_update'
/* 其他 */
/**
* ws测试事件
*/
export const EVENT_TEST_WEBSOCKET = 'event_test_websocket'

View File

@@ -0,0 +1,270 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<el-form
:inline="true"
class="demo-form-inline"
label-position="right"
label-width="90px"
label-suffix=":"
>
<el-form-item label="信息标题">
<el-input
v-model="query.notice_title"
clearable
size="mini"
placeholder="请输入标题"
@keyup.enter.native="crud.toQuery"
/>
</el-form-item>
<el-form-item label="信息类型">
<el-select
v-model="query.notice_type"
clearable
size="mini"
placeholder="信息类型"
class="filter-item"
@change="hand"
>
<el-option
v-for="item in dict.notice_type"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="读取状态">
<el-select
v-model="query.have_read"
clearable
size="mini"
placeholder="读取状态"
class="filter-item"
@change="hand"
>
<el-option
v-for="item in dict.have_read_type"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="处理情况">
<el-select
v-model="query.deal_status"
clearable
size="mini"
placeholder="处理情况"
class="filter-item"
@change="hand"
>
<el-option
v-for="item in dict.deal_status"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<rrOperation />
</el-form>
</div>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission">
<el-button
slot="right"
class="filter-item"
size="mini"
type="success"
icon="el-icon-circle-check"
:disabled="crud.selections.length === 0"
@click="changeRead(crud.selections)"
>
批量已读
</el-button>
</crudOperation>
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="信息标题" prop="notice_title">
<el-input v-model="form.notice_title" style="width: 370px;" />
</el-form-item>
<el-form-item label="信息内容" prop="notice_content">
<el-input v-model="form.notice_content" style="width: 370px;" />
</el-form-item>
<el-form-item label="信息类型" prop="notice_type">
<el-input v-model="form.notice_type" style="width: 370px;" />
</el-form-item>
<el-form-item label="读取状态" prop="have_read">
<el-input v-model="form.have_read" style="width: 370px;" />
</el-form-item>
<el-form-item label="读取时间">
<el-input v-model="form.read_time" style="width: 370px;" />
</el-form-item>
<el-form-item label="处理状态" prop="deal_status">
<el-input v-model="form.deal_status" style="width: 370px;" />
</el-form-item>
<el-form-item label="创建时间" prop="create_time">
<el-input v-model="form.create_time" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="notice_title" label="信息标题" :min-width="flexWidth('notice_title',crud.data,'信息标题')" />
<el-table-column prop="notice_content" label="信息内容" :min-width="flexWidth('notice_content',crud.data,'信息内容')" />
<el-table-column prop="notice_type" label="信息类型" :min-width="flexWidth('notice_type',crud.data,'信息类型')">
<template slot-scope="scope">
<el-tag v-if="scope.row.notice_type == 1" type="danger">{{ dict.label.notice_type[scope.row.notice_type] }}</el-tag>
<el-tag v-else type="warning">{{ dict.label.notice_type[scope.row.notice_type] }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="have_read" label="读取状态" :min-width="flexWidth('have_read',crud.data,'读取状态')" >
<template slot-scope="scope">
<el-tag v-if="scope.row.have_read == 1" type="danger">{{ dict.label.have_read_type[scope.row.have_read] }}</el-tag>
<el-tag v-else type="success">{{ dict.label.have_read_type[scope.row.have_read] }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="read_time" label="读取时间" :min-width="flexWidth('read_time',crud.data,'读取时间')" />
<el-table-column prop="deal_status" label="处理状态" :min-width="flexWidth('deal_status',crud.data,'处理状态')" >
<template slot-scope="scope">
<el-tag v-if="scope.row.deal_status == 1" type="info">{{ dict.label.deal_status[scope.row.deal_status] }}</el-tag>
<el-tag v-else>{{ dict.label.deal_status[scope.row.deal_status] }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="create_time" label="创建时间" :min-width="flexWidth('create_time',crud.data,'创建时间')" />
<el-table-column v-permission="[]" label="操作" width="200px" align="center" fixed="right">
<template slot-scope="scope">
<el-button
type="text"
slot="left"
icon="el-icon-view"
@click="show(scope.row)">
查看
</el-button>
<el-button
type="text"
slot="left"
icon="el-icon-help"
@click="deal(scope.row)">
处理
</el-button>
<udOperation
:data="scope.row"
:permission="permission"
:is-visiable-edit="false"
style="display: inline"
/>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
</div>
</div>
</template>
<script>
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import crudNotice from './api/notice'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'
import { NOTICE_SHOW_MESSAGE, NOTICE_MESSAGE_UPDATE } from '@/views/system/notice/code/VueBaseCode'
const defaultForm = { notice_id: null, notice_title: null, notice_content: null, notice_type: null, have_read: null, read_time: null, deal_status: null, create_time: null }
export default {
name: 'Notice',
dicts: ['deal_status', 'have_read_type', 'notice_type'],
components: { pagination, crudOperation, rrOperation, udOperation },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({
title: '消息通知',
url: 'api/notice',
idField: 'notice_id',
sort: 'notice_id,desc',
crudMethod: { ...crudNotice },
optShow: {
add: false,
edit: false,
del: true,
download: false,
reset: true
}
})
},
data() {
return {
permission: {},
rules: {
notice_title: [
{ required: true, message: '信息标题不能为空', trigger: 'blur' }
],
notice_content: [
{ required: true, message: '信息内容不能为空', trigger: 'blur' }
],
notice_type: [
{ required: true, message: '信息类型不能为空', trigger: 'blur' }
],
have_read: [
{ required: true, message: '读取状态不能为空', trigger: 'blur' }
],
deal_status: [
{ required: true, message: '处理状态不能为空', trigger: 'blur' }
],
create_time: [
{ required: true, message: '创建时间不能为空', trigger: 'blur' }
]
}}
},
methods: {
// 钩子在获取表格数据之前执行false 则代表不获取数据
[CRUD.HOOK.beforeRefresh]() {
return true
},
show(record) {
if (record.have_read == '1') {
crudNotice.read(record.notice_id).then(() => {
record.have_read = '2'
this.$bus.emit(NOTICE_MESSAGE_UPDATE)
})
}
this.$bus.emit(NOTICE_SHOW_MESSAGE, record)
this.crud.toQuery()
},
hand(value) {
this.crud.toQuery()
},
deal(row) {
crudNotice.deal(row.notice_id).then(() => {
row.have_read = '2'
this.$bus.emit(NOTICE_MESSAGE_UPDATE)
})
this.crud.toQuery()
},
changeRead(data) {
const param = {}
param.data = data
param.have_read = '2'
crudNotice.changeRead(param).then(() => {
this.$bus.emit(NOTICE_MESSAGE_UPDATE)
})
this.crud.notify('操作成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
this.crud.toQuery()
}
}
}
</script>
<style scoped>
</style>