信息通知前端、后端代码、websocket(el-admin版本)、添加sys_dict到excel
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
Binary file not shown.
Reference in New Issue
Block a user