diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/MsgType.java b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/MsgType.java new file mode 100644 index 00000000..bf431697 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/MsgType.java @@ -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 +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/SocketMsg.java b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/SocketMsg.java new file mode 100644 index 00000000..1b9ad946 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/SocketMsg.java @@ -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; + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/WebSocketServer.java b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/WebSocketServer.java new file mode 100644 index 00000000..bd759cc3 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/common/websocket/WebSocketServer.java @@ -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 webSocketSet = new CopyOnWriteArraySet(); + + /** + * 与某个客户端的连接会话,需要通过它来给客户端发送数据 + */ + 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); + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/config/mybatis/CodeGenerator.java b/mes/hd/nladmin-system/src/main/java/org/nl/config/mybatis/CodeGenerator.java new file mode 100644 index 00000000..521de5de --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/config/mybatis/CodeGenerator.java @@ -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 { + + /** + *

+ * 读取控制台内容 + *

+ */ + 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(); + } + +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/system/controller/notice/NoticeController.java b/mes/hd/nladmin-system/src/main/java/org/nl/system/controller/notice/NoticeController.java new file mode 100644 index 00000000..63961ac9 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/system/controller/notice/NoticeController.java @@ -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 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 create(@Validated @RequestBody NoticeDto dto){ + noticeService.create(dto); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改消息通知") + @ApiOperation("修改消息通知") + //@SaCheckPermission("@el.check('notice:edit')") + public ResponseEntity update(@Validated @RequestBody NoticeDto dto){ + noticeService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除消息通知") + @ApiOperation("删除消息通知") + //@SaCheckPermission("@el.check('notice:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Long[] ids) { + noticeService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("获取未读的接收消息条数") + @GetMapping("/countByReceiveNotRead") + public ResponseEntity countByReceiveNotRead(){ + return new ResponseEntity<>(noticeService.countByReceiveNotRead(), HttpStatus.OK); + } + + @Log("接收消息分页") + @GetMapping("/pageByReceive") + public ResponseEntity pageByReceive(){ + return new ResponseEntity<>(noticeService.pageByReceive(), HttpStatus.OK); + } + + @Log("标为已读") + @PostMapping("/read") + public ResponseEntity read(@RequestBody String id){ + noticeService.read(id); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("消息详情") + @PostMapping("/findById") + public ResponseEntity findById(@RequestBody String id){ + return new ResponseEntity<>(noticeService.selectById(id), HttpStatus.OK); + } + + @Log("修改已处理") + @PostMapping("/deal") + public ResponseEntity deal(@RequestBody String id){ + noticeService.deal(id); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("批量已读") + @PostMapping("/changeRead") + @ApiOperation("批量已读") + public ResponseEntity changeRead(@RequestBody JSONObject jsonObject) { + noticeService.changeRead(jsonObject); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/NoticeService.java b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/NoticeService.java new file mode 100644 index 00000000..79b503ed --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/NoticeService.java @@ -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 + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询所有数据不分页 + * @param whereJson 条件参数 + * @return List + */ + List 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); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/dto/NoticeDto.java b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/dto/NoticeDto.java new file mode 100644 index 00000000..17933c7a --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/dto/NoticeDto.java @@ -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; +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/impl/NoticeServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/impl/NoticeServiceImpl.java new file mode 100644 index 00000000..afe31c7e --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/impl/NoticeServiceImpl.java @@ -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 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 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); + } + } + +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/wql/QUERY_NOTICE.wql b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/wql/QUERY_NOTICE.wql new file mode 100644 index 00000000..27c3d9b2 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/system/service/notice/wql/QUERY_NOTICE.wql @@ -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 diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pdm/wql/pdm.xls b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pdm/wql/pdm.xls index 7b1e96fc..f7301796 100644 Binary files a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pdm/wql/pdm.xls and b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pdm/wql/pdm.xls differ diff --git a/mes/qd/package.json b/mes/qd/package.json index 5fce6884..8741287f 100644 --- a/mes/qd/package.json +++ b/mes/qd/package.json @@ -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", diff --git a/mes/qd/src/layout/components/Navbar.vue b/mes/qd/src/layout/components/Navbar.vue index f2345afd..1568d7d5 100644 --- a/mes/qd/src/layout/components/Navbar.vue +++ b/mes/qd/src/layout/components/Navbar.vue @@ -15,6 +15,8 @@ + + @@ -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, diff --git a/mes/qd/src/main.js b/mes/qd/src/main.js index efb26d34..ce679a61 100644 --- a/mes/qd/src/main.js +++ b/mes/qd/src/main.js @@ -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 } diff --git a/mes/qd/src/views/system/notice/NoticeIcon.vue b/mes/qd/src/views/system/notice/NoticeIcon.vue new file mode 100644 index 00000000..343f341f --- /dev/null +++ b/mes/qd/src/views/system/notice/NoticeIcon.vue @@ -0,0 +1,125 @@ + + + + + diff --git a/mes/qd/src/views/system/notice/NoticeIconReader.vue b/mes/qd/src/views/system/notice/NoticeIconReader.vue new file mode 100644 index 00000000..d61d9c6a --- /dev/null +++ b/mes/qd/src/views/system/notice/NoticeIconReader.vue @@ -0,0 +1,122 @@ + + + + + diff --git a/mes/qd/src/views/system/notice/api/notice.js b/mes/qd/src/views/system/notice/api/notice.js new file mode 100644 index 00000000..a83b6880 --- /dev/null +++ b/mes/qd/src/views/system/notice/api/notice.js @@ -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 } diff --git a/mes/qd/src/views/system/notice/code/VueBaseCode.js b/mes/qd/src/views/system/notice/code/VueBaseCode.js new file mode 100644 index 00000000..9190b143 --- /dev/null +++ b/mes/qd/src/views/system/notice/code/VueBaseCode.js @@ -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' diff --git a/mes/qd/src/views/system/notice/index.vue b/mes/qd/src/views/system/notice/index.vue new file mode 100644 index 00000000..ed97cb5a --- /dev/null +++ b/mes/qd/src/views/system/notice/index.vue @@ -0,0 +1,270 @@ + + + + +