Commit c136b23b authored by ml's avatar ml

消息通知

parent ab6e8c30
......@@ -24,5 +24,6 @@ export const ErrorCode = {
TOTP_KEY_OVERSTAYED: '30022',//密钥已失效,请重新获取
USER_TYPE_ILLEGAL: '30023',//用户类型不合法
NEED_INPUT_GOOGLE_CODE: '30024',//请输入Google验证码
PUSH_NOT_UPDATE: '30025',//已经推送不允许修改
}
import * as noticeService from "../service/notice.service";
import { NoticeVO, NoticePageVO } from "../service/notice.service";
let { logger, Res3Utils, optionalUtils: Optional, apiAssertUtils: ApiAssert } = require('@madex/ex-js-public');
import { ErrorCode } from "../../../constant/errorCode";
/**
* 消息列表
* @param req
* @param infoVO
*/
export const list = async (req: any, noticePageVO: NoticePageVO) => {
let func_name = "noticeCtrl.list";
try {
noticePageVO.page = Optional.opt(noticePageVO, 'page', 1);
noticePageVO.size = Optional.opt(noticePageVO, 'size', 20);
let res = await noticeService.list(noticePageVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 新增消息
* @param req
* @param infoVO
*/
export const add = async (req: any, noticeVO: NoticeVO) => {
let func_name = "noticeCtrl.add";
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, noticeVO.content);
ApiAssert.notNull(ErrorCode.PARAM_MISS, noticeVO.notice_type);
ApiAssert.notNull(ErrorCode.PARAM_MISS, noticeVO.push_time);
let res = await noticeService.add(noticeVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 修改消息 删除 就传 del_sign = 1
* 推送给指定的多个用户的消息 目前只能一个一个修改 不支持批量修改
* 需要支持的话 可能数据库要调整 增加一个 group_id 字段
* @param req
* @param infoVO
*/
export const update = async (req: any, noticeVO: NoticeVO) => {
let func_name = "noticeCtrl.update";
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, noticeVO.id);
let res = await noticeService.update(noticeVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
import { ormDB, noticeModel, noticeRead } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode";
let _ = require('lodash');
let { logger, datetimeUtils } = require('@madex/ex-js-public');
export interface NoticeVO {
id?: number;
content?: string | any;
publish_flag?: number;
user_id?: string | any;
notice_type?: number;
push_type?: number;
push_time?: Date | any;
del_sign?: number;
status?: number;
createdAt?: Date | any;
updatedAt?: Date | any;
}
export interface NoticePageVO extends NoticeVO {
page?: number,
size?: number
}
export async function list(noticePageVO: NoticePageVO) {
let where = Object.create(null);
if (noticePageVO.publish_flag) {
where.publish_flag = noticePageVO.publish_flag;
}
if (Number(noticePageVO.user_id) >= 0) {
where.user_id = noticePageVO.user_id;
}
if (noticePageVO.notice_type) {
where.notice_type = noticePageVO.notice_type;
}
if (noticePageVO.push_type) {
where.push_type = noticePageVO.push_type;
}
if (noticePageVO.push_time) {
let date = datetimeUtils.trim(noticePageVO.push_time, 's');
where.push_time = { [ormDB.Op.gte]: date };
}
if (!noticePageVO.del_sign) {
where.del_sign = 0;
}
if (noticePageVO.status) {
where.status = noticePageVO.status;
}
if (noticePageVO.createdAt) {
let date = datetimeUtils.trim(noticePageVO.createdAt, 's');
where.createdAt = { [ormDB.Op.gte]: date }
}
let resList = await noticeModel.prototype.findAndCount({
where: where,
limit: noticePageVO.size,
offset: (Number(noticePageVO.page) - 1) * Number(noticePageVO.size),
order: [["id", "desc"]],
raw: true
});
return resList;
}
export async function add(noticeVO: NoticeVO) {
let insertList: any = [];
if (!noticeVO.publish_flag) {
noticeVO.publish_flag = 0;
}
if (!noticeVO.push_type) {
noticeVO.push_type = 1;
}
noticeVO.del_sign = 0;
noticeVO.status = 0;
noticeVO.createdAt = new Date();
noticeVO.updatedAt = new Date();
if (!noticeVO.user_id) {
noticeVO.user_id = 0;
insertList.push(noticeVO);
}
else {//多个uid 的消息
let uids = noticeVO.user_id.split(',');
for (let oneUid of uids) {
let item = {
content: noticeVO.content,
publish_flag: noticeVO.publish_flag,
user_id: oneUid,
notice_type: noticeVO.notice_type,
push_type: noticeVO.push_type,
push_time: noticeVO.push_time,
del_sign: noticeVO.del_sign,
status: noticeVO.status,
createdAt: noticeVO.createdAt,
updatedAt: noticeVO.updatedAt,
}
insertList.push(item);
}
}
await noticeModel.prototype.bulkCreate(insertList);
return 'success'
}
export async function update(noticeVO: NoticeVO) {
let dbInfo = await noticeModel.prototype.findOne({
where: {
id: noticeVO.id
},
raw: true
});
if (!dbInfo) {
throw ErrorCode.DATA_NOT_EXIST;
}
if (dbInfo.status == 1) {
throw ErrorCode.PUSH_NOT_UPDATE;
}
let updateInfo = {};
if (noticeVO.content) {
updateInfo['content'] = noticeVO.content;
}
if (noticeVO.publish_flag) {
updateInfo['publish_flag'] = noticeVO.publish_flag;
}
if (noticeVO.notice_type) {
updateInfo['notice_type'] = noticeVO.notice_type;
}
if (noticeVO.push_type) {
updateInfo['push_type'] = noticeVO.push_type;
}
if (noticeVO.push_time) {
updateInfo['push_time'] = noticeVO.push_time;
}
if (noticeVO.del_sign) {
updateInfo['del_sign'] = noticeVO.del_sign;
}
updateInfo['updatedAt'] = new Date();
await noticeModel.prototype.update(updateInfo, {
where: {
id: Number(noticeVO.id)
}
});
return 'success'
}
......@@ -19,6 +19,7 @@ import * as ReqUtils from "../../../utils/req-utils";
import * as spotPairCtrl from "../../mvc/control/spotPair.control";
import * as coinTypeCtrl from "../../mvc/control/coinType.control";
import * as noticeCtrl from "../../mvc/control/notice.control";
const getFunc = {
'user/info': userController.getUserInfo,
};
......@@ -78,6 +79,10 @@ const postFunc = {
'hot/pair/config/update': hotPairConfigCtrl.update,
'hot/pair/config/del': hotPairConfigCtrl.del,
'notice/list': noticeCtrl.list,
'notice/add': noticeCtrl.add,
'notice/update': noticeCtrl.update,
};
......
......@@ -8,13 +8,16 @@ const {
let cmdWhiteList = {
'i18n/info/list': 1,
let cmdWhiteList = {'i18n/info/list': 1,
'i18n/info/add': 1,
'i18n/info/update': 1,
'i18n/info/del': 1,
'i18n/info/log/list': 1,
'i18n/info/log/revert': 1,
'spotpair/add': 1,
'spotpair/list': 1,
'coinType/add': 1,
'coinType/list': 1,
'acl/user/add': 1,
'acl/user/list': 1,
'acl/user/update': 1,
......@@ -48,6 +51,9 @@ let cmdWhiteList = {
'hot/pair/config/add': 1,
'hot/pair/config/update': 1,
'hot/pair/config/del': 1,
'notice/list': 1,
'notice/add': 1,
'notice/update': 1,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment