Commit ff107f04 by chenjinjing

no message

parent b91db75d
import { Op } from "sequelize"; import { Op, Sequelize } from "sequelize";
import { ERRORENUM } from "../../config/errorEnum"; import { ERRORENUM } from "../../config/errorEnum";
import { modelMap } from "../../model/modelBind"; import { modelMap } from "../../model/modelBind";
import { BizError } from "../../util/bizError"; import { BizError } from "../../util/bizError";
...@@ -14,12 +14,16 @@ import { BizError } from "../../util/bizError"; ...@@ -14,12 +14,16 @@ import { BizError } from "../../util/bizError";
* %lte%:小于等于 {列名: {"%lte%": }} * %lte%:小于等于 {列名: {"%lte%": }}
* %between%:查询范围内数据 {列名: {"%between%": ["开始参数", "结束参数"]}} ---BETWEEN 开始参数 AND 结束参数 * %between%:查询范围内数据 {列名: {"%between%": ["开始参数", "结束参数"]}} ---BETWEEN 开始参数 AND 结束参数
* %notBetween%:查询不在范围内数据 {列名: {"%notBetween%": ["开始参数", "结束参数"]}} ---NOT BETWEEN 开始参数 AND 结束参数 * %notBetween%:查询不在范围内数据 {列名: {"%notBetween%": ["开始参数", "结束参数"]}} ---NOT BETWEEN 开始参数 AND 结束参数
* %orderDesc%: order by DESC {"%orderDesc%": "列名"}
* %limit%: {"%limit%": 数量}
* @param column * @param column
* @returns * @returns
*/ */
function analysisParamToWhere(param, column) { function analysisParamToWhere(param, column) {
let where = {}; let where = {};
for (let key in param) { let order = [];
let limit = 0;
for (let key in param) {
if (typeof param[key] == "object") { if (typeof param[key] == "object") {
where[key] = {}; where[key] = {};
for (let whereKey in param[key]){ for (let whereKey in param[key]){
...@@ -48,12 +52,25 @@ function analysisParamToWhere(param, column) { ...@@ -48,12 +52,25 @@ function analysisParamToWhere(param, column) {
} }
} }
}else { }else {
where[key] = param[key]; switch (key) {
case "%orderDesc%":
order = [[Sequelize.col(param[key]), "DESC"]];
break;
case "%orderAsc%":
order = [[Sequelize.col(param[key]), "ASC"]];
break;
case "%limit%":
limit = param[key];
break;
default: where[key] = param[key];
}
} }
} }
let selectParam:any = {where}; let selectParam:any = {where};
if (column && column.length) selectParam.attributes = column; if (column && column.length) selectParam.attributes = column;
if (order) selectParam.order = order;
if (limit) selectParam.limit = limit;
return selectParam; return selectParam;
} }
......
...@@ -250,11 +250,12 @@ export const TablesConfig = [ ...@@ -250,11 +250,12 @@ export const TablesConfig = [
autoIncrement:true, //允许自增 autoIncrement:true, //允许自增
unique:true //表示该列的值必须唯一 unique:true //表示该列的值必须唯一
}, },
pmId: {type:Sequelize.STRING(100), allowNull:false}, //党员id 外键 pmId: {type:Sequelize.STRING(100), allowNull:false}, //党员id
partyMemberName: {type:Sequelize.STRING(100), allowNull:false}, //党员姓名 partyMemberName: {type:Sequelize.STRING(100), allowNull:false}, //党员姓名
bId: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //支部表id 外键 [1,2] --多选 bId: {type:Sequelize.INTEGER, allowNull:false}, //支部表id 外键
monthIntegral: {type:Sequelize.INTEGER, allowNull:false}, //本月积分 dayIntegral: {type:Sequelize.INTEGER, allowNull:false}, //当日积分
totalIntegral: {type:Sequelize.INTEGER, allowNull:false},//总积分 totalIntegral: {type:Sequelize.INTEGER, allowNull:false},//总积分
dataTime: {type:Sequelize.DATE, allowNull:false}, //数据时间
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选 fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型 fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间 uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
......
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