新增功能

This commit is contained in:
2026-06-05 17:38:10 +08:00
parent 51b979c182
commit 2997f49dd7
46 changed files with 4321 additions and 1103 deletions

View File

@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
const { Op } = require('sequelize');
const moment = require('moment');
const fileName = "Business";
class BusinessService extends Service {
@@ -82,27 +84,27 @@ class BusinessService extends Service {
}
}
//远程搜索公司业务
async SearchBusiness(body) {
const { ctx } = this;
try {
let { query, key, timeBefor } = body;
let attributes = ['temporary_id', 'name', 'created_at'], where = {}, dbOptions;
if (query == '*空') {
delete where[key]
} else {
where[key] = { [Op.substring]: query };
}
where.created_at = { [Op.lt]: timeBefor };
dbOptions = { attributes, where };
const Business = await ctx.model3.Business.findAll(dbOptions);
return Business.length == 0 ? false : Business;
} catch (error) {
const blockName = fileName + "--" + "SearchBusiness";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
//远程搜索公司业务
async SearchBusiness(body) {
const { ctx } = this;
try {
let { query, key, timeBefor } = body;
let attributes = ['temporary_id', 'name', 'created_at'], where = {}, dbOptions;
if (query == '*空') {
delete where[key]
} else {
where[key] = { [Op.substring]: query };
}
where.created_at = { [Op.lt]: timeBefor };
dbOptions = { attributes, where };
const Business = await ctx.model3.Business.findAll(dbOptions);
return Business.length == 0 ? false : Business;
} catch (error) {
const blockName = fileName + "--" + "SearchBusiness";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 编辑公司业务
async editBusiness(uid, modelType, password, updateMsg, requestMsg) {
@@ -206,6 +208,124 @@ class BusinessService extends Service {
return 'error';
}
}
// 管理系统导出公司业务
async downloadBusiness(uid, searchMsg) {
const { ctx } = this;
try {
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
if (!user || user.dataValues.role < 3) return false;
let { searchOptions, sortOptions } = searchMsg;
let attributes = ['login_url', 'client_url', 'temporary_id', 'client_id', 'client_secret', 'name', 'type', 'level', 'status', 'created_at', 'updated_at'],
where = {}, order = [], dbOptions,
joinSubstring = [],
substring = ['login_url', 'client_url', 'temporary_id', 'client_id', 'client_secret', 'name'],
key = ['type', 'level', 'status'],
between = ['created_at', 'updated_at'];
attributes.forEach(element => {
if (searchOptions[element]) {
if (searchOptions[element] == '*空') {
if (joinSubstring.includes(element)) {
where[element] = null;
} else {
where[element] = [null, ''];
}
} else if (joinSubstring.includes(element)) {
let targetKeyArr = [];
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
} else if (substring.includes(element)) {
where[element] = { [Op.substring]: searchOptions[element] };
} else if (key.includes(element)) {
where[element] = searchOptions[element];
} else if (between.includes(element)) {
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
}
}
if (sortOptions[element] == true) {
order.push([element, 'ASC']);
} else if (sortOptions[element] == false) {
order.push([element, 'DESC']);
}
});
dbOptions = { attributes, where, order };
const result = await ctx.model3.Business.findAll(dbOptions);
if (result.length == 0) return { code: false };
let data = [];
const typeOptions = [
{
value: "0",
label: "B端业务"
},
{
value: "1",
label: "C端业务"
},
{
value: "2",
label: "通用业务"
}
];
const levelOptions = [
{
value: "0",
label: "一般等级"
},
{
value: "1",
label: "重要等级"
},
{
value: "2",
label: "紧要等级"
}
];
const statusOptions = [
{
value: "0",
label: "未启动"
},
{
value: "1",
label: "已启动"
},
{
value: "2",
label: "已关闭"
}
];
result.forEach(element => {
typeOptions.forEach((item) => {
if (item.value == element.dataValues["type"]) {
element.dataValues["type"] = item.label;
}
});
levelOptions.forEach((item) => {
if (item.value == element.dataValues["level"]) {
element.dataValues["level"] = item.label;
}
});
statusOptions.forEach((item) => {
if (item.value == element.dataValues["status"]) {
element.dataValues["status"] = item.label;
}
});
element.dataValues.created_at = moment
.utc(element.dataValues.created_at)
.add(8, "hours")
.format("YYYY年MM月DD日HH时mm分ss秒");
element.dataValues.updated_at = moment
.utc(element.dataValues.updated_at)
.add(8, "hours")
.format("YYYY年MM月DD日HH时mm分ss秒");
data.push(element.dataValues);
});
return { code: true, data };
} catch (error) {
const blockName = fileName + "--" + "downloadBusiness";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
}
module.exports = BusinessService;