Commit 9c0735f3 by 胡悦

'第一次提交'

0 parents
'use strict';
module.exports = {
write: true,
prefix: '^',
plugin: 'autod-egg',
test: [
'test',
'benchmark',
],
dep: [
'egg',
'egg-scripts',
],
devdep: [
'egg-ci',
'egg-bin',
'egg-mock',
'autod',
'autod-egg',
'eslint',
'eslint-config-egg',
],
exclude: [
'./test/fixtures',
'./dist',
],
};
{
"extends": "eslint-config-egg"
}
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/
sudo: false
language: node_js
node_js:
- '10'
before_install:
- npm i npminstall -g
install:
- npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Egg Debug",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"debug",
"--",
"--inspect-brk"
],
"console": "integratedTerminal",
"restart": true,
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
},
{
"type": "node",
"request": "launch",
"name": "Egg Test",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"test-local",
"--",
"--inspect-brk"
],
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
},
{
"type": "node",
"request": "attach",
"name": "Egg Attach to remote",
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app",
"address": "localhost",
"protocol": "auto",
"port": 9999
}
]
}
\ No newline at end of file
# glsx-data-screen-server
广联数据大屏
## QuickStart
<!-- add docs here for user -->
see [egg docs][egg] for more detail.
### Development
```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```
### Deploy
```bash
$ npm start
$ npm stop
```
### npm scripts
- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
[egg]: https://eggjs.org
### sequelize-auto
1.安装sequelize-auto和mysql
### npm install -g sequelize-auto mysql
npm install -g egg-sequelize-auto mysql2
2. 使用说明
常用参数:
-h 数据库的IP地址
-d 数据库名
-u 用户名
-x 密码
-p 端口
-t 表名
-e 数据库类型
-a json定义文件路径,可以追加一些自定义配置,如{"timestamps": false}
- create model: $ egg-sequelize-auto -o "./app/model/screen/merchant" -d glsx_data_screen -h 14.17.100.222 -u dev_limin -p 3307 -x fdseooui -t xxx -e mysql
egg-sequelize-auto -o "./app/model/biz" -d glsx_audit -h 192.168.3.153 -u apuser -p 3308 -x 123456 -e mysql
- 不指定-t 为所有表
-- shell
#!/bin/bash
HOST="地址"
DB="数据库名"
USER="用户名"
PASS="密码"
PORT="端口号"
DIR="生成路径"
JSON_DEFINED="json文件路径"
EXEC="sequelize-auto -o ${DIR} -d ${DB} -h ${HOST} -u ${USER} -p ${PORT} -x ${PASS} -e mysql -a ${JSON_DEFINED}"
#执行
$EXEC
\ No newline at end of file
const path = require('path');
// module.exports = app => {
// app.beforeStart(async function() {
// // 应用会等待这个函数执行完成才启动
// // await app.model.sync({ force: true }); // 开发环境使用
// await app.model.sync({});
// });
class AppBootHook {
constructor(app) {
this.app = app;
this.helper = app.helper;
}
async configWillLoad() {
console.log(`
◆ 项目:广联赛讯历史保单数据服务
◆ 语言:Javascript
◆ 框架:Node.js + Egg.js + MySql
◆ 版本控制: git-github
◆ 代码风格:eslint-standard
◆ 编辑器: VSCode
◆ 数据库: mysql
◆ 服务器端脚本: Node.js
◆ author: limin
`)
}
async didReady() {
const ctx = await this.app.createAnonymousContext();
console.log(' ◆ 加载校验规则\r\n')
console.log('\r\n ◆ 应用启动成功!\r\n')
await this._init_user_validations_(ctx);
}
async _init_user_validations_() {
const directory = path.join(this.app.config.baseDir, './app/validate');
this.app.loader.loadToApp(directory, 'validate');
}
}
module.exports = AppBootHook;
/*
* @Author: limin
* @Date: 2020-04-15 15:52:40
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 15:52:40
*/
module.exports = {
};
\ No newline at end of file
/*
* @Author: limin
* @Date: 2020-04-15 15:52:48
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 15:52:48
*/
const { SUCCESS, ERROR } = require("./server_response_code");
module.exports = class ServerResponse {
constructor(status, msg, data) {
this.status = status;
this.msg = msg;
this.data = data;
}
isSuccess() {
return this.status === SUCCESS;
}
getStatus() {
return this.status;
}
getData() {
return this.data;
}
getMsg() {
return this.msg;
}
static Success(data = null,respo = SUCCESS) {
const { code,message } = respo
return new ServerResponse(code,message, data);
}
// static createBySuccess() {
// return new ServerResponse(SUCCESS);
// }
// static createBySuccessMsg(msg) {
// return new ServerResponse(SUCCESS, msg, null);
// }
// static createBySuccessData(data) {
// return new ServerResponse(SUCCESS, null, data);
// }
// static createBySuccessMsgAndData(msg, data) {
// return new ServerResponse(SUCCESS, msg, data);
// }
static Error(respo = ERROR) {
const { code=ERROR.code,message,data } = respo
return new ServerResponse(code,message, data);
}
// static createByError() {
// return new ServerResponse(ERROR, 'error', null);
// }
// static createByErrorMsg(errorMsg) {
// return new ServerResponse(ERROR, errorMsg, null);
// }
// static createByErrorCodeMsg(errorCode, errorMsg) {
// return new ServerResponse(errorCode, errorMsg, null);
// }
};
/*
* @Author: limin
* @Date: 2020-04-15 15:52:28
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 15:52:28
*/
module.exports = {
SUCCESS: {code:0,message:'SUCCESS!'},
ERROR: {code:1,message:'ERROR!'},
NEED_LOGIN: {code:10,message:'请登录!'},
NO_AUTH: {code:20,message:'无权限访问!'},
ILLEGAL_ARGUMENT: {code:2,message:'参数错误!'}
};
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-05-25 16:42:33
* @LastEditors: limin
* @LastEditTime: 2020-05-25 17:12:28
*/
'use strict';
module.exports = {
lossListSearcherConditions: {
searchKey: { type: 'string', description: 'stand_no,车架号;name,客户姓名;mobile,手机号;merchant_name:门店名称' },
searchValue: { type: 'string', description: '门店类型 0:其他;1:4S店;2:维修店;3:美容店;4:改装店;5:特许店;6:综合店' },
stopTimeStart: { type: 'string', description: '停留时长开始时间' },
stopTimeEnd: { type: 'string', description: '停留时长结束时间' },
warnTimesStart: { type: 'string', description: '预警次数开始' },
warnTimesEnd: { type: 'string', description: '预警次数结束' },
orderBy: { type: 'string', description: '预警排序:(时间:trigger_time,次数:number_of_shops,降序:"DESC",升序:‘asc’例如 ["trigger_time":"DESC"])' },
current: { type: 'integer', description: '当前页 默认1' },
size: { type: 'integer', description: '每页显示数量 默认10' }
}
};
\ No newline at end of file
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-05-25 16:42:33
* @LastEditors: limin
* @LastEditTime: 2020-05-25 16:43:49
*/
'use strict';
module.exports = {
pager: {
current: { type: 'integer', description: '当前页 默认1' },
size: { type: 'integer', description: '每页显示数量 默认10' }
}
};
\ No newline at end of file
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-05-25 16:42:33
* @LastEditors: limin
* @LastEditTime: 2020-05-25 17:45:54
*/
'use strict';
module.exports = {
response: {
status: { type: 'integer', description: '接口状态 200 正常' },
msg: { type: 'string', description: '信息' },
data: { type: 'string', description: '返回结果' }
}
};
\ No newline at end of file
/*
* @Author: limin
* @Date: 2020-04-15 15:53:03
* @Last Modified by: limin
* @Last Modified time: 2020-04-17 10:21:49
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/loss
* @Description 流失预警
*/
class LossController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validator.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.LossService = ctx.service.biz.loss;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @summary 查询所有流失预警数据
* @Router POST /biz/loss/findAll
* @Description 查询所有流失预警数据
* @Request body lossListSearcherConditions *searcher searcher
* @Response 200 response ok
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
// searcher = { stopTimeStart: '1', stopTimeEnd: '120' }
// this.validate(ctx.rule.lossListSearcherConditions);
const result = await this.LossService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = LossController;
/*
* @Author: limin
* @Date: 2020-04-15 15:53:03
* @Last Modified by: limin
* @Last Modified time: 2020-04-17 10:21:49
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/maintain
* @Description 保养
*/
class MaintainController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validator.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.MaintainService = ctx.service.biz.maintain;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router POST /biz/maintain/findAll
* @Description 查询所有保养数据(searcher:{searchKey:{stand_no,车架号;name,姓名;mobile,手机号;plate_number:车牌号} searchValue:查询值 remind_type:保养提醒类型(1:首保 2:定保) remind_rule:保养提醒规则(1:里程规则提醒 2:时间规则提醒)numbersStart:到店次数开始 numbersEnd 到店次数结束 distance:常驻地距离(0-5公里:0-5,5-10公里:5-10,10-20公里:10-20,20公里以上:20) isNew 展示最后一条数据:(1:是:0:否) pager:{current = 1 当前页 默认1, size = 10 每页条数 默认10}}
* @Request pager
* @Request searcher
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
const result = await this.MaintainService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = MaintainController;
/*
* @Author: limin
* @Date: 2020-04-15 15:53:03
* @Last Modified by: limin
* @Last Modified time: 2020-04-17 10:21:49
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/record
* @Description 跟踪记录
*/
class RecordController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validator.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.RecordService = ctx.service.biz.record;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router POST /biz/record/findAll
* @Description 查询所有跟踪记录 (searcher:{sn:设备号} pager:{current = 1 当前页 默认1, size = 10 每页条数 默认10}
* @Request pager
* @Request searcher
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
// /:{search_text:'天顺',success_date_start:'2015-09-25 00:00:00',success_date_end:'2019-09-25 23:59:59'}
const result = await this.RecordService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = RecordController;
/*
* @Author: limin
* @Date: 2020-04-15 15:53:03
* @Last Modified by: limin
* @Last Modified time: 2020-04-17 10:21:49
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/shop
* @Description 到店数据
*/
class ShopController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validator.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.ShopService = ctx.service.biz.shop;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router POST /biz/shop/findAll
* @Description 查询所有到店数据 (searcher:{searchKey:{stand_no,车架号;name,姓名;mobile,手机号;plate_number:车牌号,merchant_name:门店名称} searchValue:查询值 number_of_shops_start:到店次数开始 number_of_shops_end:到店次数结束 binding_days_start:绑定时长开始 binding_days_end:绑定时长结束 trigger_time_start:到店时间开始 trigger_time_end:到店时间结束 pager:{current = 1 当前页 默认1, size = 10 每页条数 默认10}}
* @Request pager
* @Request searcher
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
// /:{search_text:'天顺',success_date_start:'2015-09-25 00:00:00',success_date_end:'2019-09-25 23:59:59'}
const result = await this.ShopService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = ShopController;
/*
* @Author: limin
* @Date: 2020-04-15 15:53:03
* @Last Modified by: limin
* @Last Modified time: 2020-04-17 10:21:49
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller history
* @Description 历史保单数据
*/
class HistoryController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validator.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.HistoryService = ctx.service.history;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router POST /history/findAll
* @Description 查询所有保单数据
* @Request pager current = 1 当前页 默认1, size = 10 每页条数 默认10
* @Request searcher search_text 查询条件(模糊查询 车主、店面名称、保单号、车架号、设备号、序列号), insurance_status 提报状态 ,channel_code :渠道 ,success_date_start:提单成功开始时间,success_date_end:提单成功结束时间,effect_date_start:生效开始时间,effect_date_end:生效结束时间,card_version:版本类型,device_type:设备类型,insure_period: 保单期限(月),company_code:承保公司,mileage_start:累计里程起始,mileage_end:累计里程结束
*/
async findAll({request:{ body: { pager, searcher } }}) { //get : async findAll( {query: { pager, searcher } })
// /:{search_text:'天顺',success_date_start:'2015-09-25 00:00:00',success_date_end:'2019-09-25 23:59:59'}
const result = await this.HistoryService.findAll({pager,searcher});
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = HistoryController;
/*
* @Author: limin
* @Date: 2019-11-21 11:19:43
* @Last Modified by: limin
* @Last Modified time: 2020-01-08 13:51:53
*/
const moment = require("moment");
const constant = require("../common/constant");
exports.moment = moment;
/*
* string.replace_all()---字符替换所有指定字符
* @parameter: from--原文本要替换值
* @parameter: to--将要替换值
*/
String.prototype.replace_all = function (from, to) {
var regExp = new RegExp(from, "g");
return this.replace(regExp, to);
}
// exports.relativeTime = time => moment(new Date(time * 1000)).fromNow();
exports.date = (n, f = "YYYY-MM-DD") => moment().add(n, "days").format(f);
exports.format_date = (date, f = "YYYY-MM-DD") =>moment(date+'').format(f);
/**
* 结束日期格式化函数
*/
exports.format_end_date = end => `${end} 23:59:59`;
/**
* 字符串转json 如果是json字符串 返回json对象 如果不是JSON字符串 返回原始字符串
*/
exports.json_parser = str => {
var res;
try {
res = JSON.parse(str);
} catch (error) {
res = str;
}
return res;
};
/**
* json对象转字符串
*/
exports.json_stringify = obj => {
var res;
if (typeof obj === "string") {
return obj;
}
try {
res = JSON.stringify(obj);
} catch (error) {
res = obj;
}
return res;
};
/**
*
*/
exports.percent = (num, total, fixed = 2) =>
(Math.round(num / total * 10000) / 100.00 + "%");
// (~~((~~num / ~~total) * 100).toFixed(fixed)) + "%";
/**
* 简单封装 sequelize 查询参数
*/
// exports.seq_option = function({
// pid,
// cid,
// n,
// limit,
// order,
// day,
// beginDate,
// endDate
// }) {
// let where = {};
// const { between } = this.ctx.app.Sequelize.Op;
// if (cid) {
// where.city_code = cid;
// } else if (pid) {
// where.prov_code = pid;
// }
// if (day) {
// //如果有具体天数 就直接查询具体一天的数据(优先具体哪一天)
// where.day = day;
// } else if (n) {
// // 查询近N天的数据 不包括今天
// where.day = {
// [between]: [this.date(n), this.format_end_date(this.date(-1))]
// };
// } else if (n === 0) {
// // 查询
// where.day = {
// [between]: [this.date(0), this.format_end_date(this.date(0))]
// };
// } else if (beginDate) {
// if (!endDate) {
// endDate = beginDate;
// }
// if (!endDate.includes(":")) {
// endDate = this.format_end_date(endDate);
// }
// where.day = {
// [between]: [beginDate, endDate]
// };
// }
// const option = {
// where,
// raw: true
// };
// if (limit) {
// option.limit = +limit;
// }
// if (order) {
// option.order = order;
// }
// return option;
// };
exports.constant = constant;
/*
* @Author: limin
* @Date: 2019-11-21 11:19:33
* @Last Modified by: limin
* @Last Modified time: 2019-11-21 17:13:13
*/
const ServerResponse = require("../common/server_response");
const ServerResponseCode = require("../common/server_response_code");
module.exports = {
ServerResponse,
ServerResponseCode
};
/*
* @Author: limin
* @Date: 2019-11-15 10:46:30
* @Last Modified by: limin
* @Last Modified time: 2019-11-15 11:07:59
*/
module.exports = (options,app)=>{
return async function auth (ctx, next){
ctx.state.csrf = ctx.csrf;
console.log(1111);
await next()
}
}
\ No newline at end of file
module.exports = () => {
return async function errorHandler(ctx, next) {
try {
await next();
} catch (err) {
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit("error", err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
const error =
status === 500 && ctx.app.config.env === "prod"
? "Internal Server Error"
: err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.body = JSON.stringify(
ctx.response.ServerResponse.Error({ msg: error })
);
if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
}
};
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('audit_insure_order', {
id: {
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
success_date: {
type: DataTypes.DATE,
allowNull: true
},
in_storage_time: {
type: DataTypes.DATE,
allowNull: true
},
shop_name: {
type: DataTypes.STRING(128),
allowNull: true
},
name: {
type: DataTypes.STRING(128),
allowNull: true
},
full_insurance_no: {
type: DataTypes.STRING(64),
allowNull: true
},
stand_no: {
type: DataTypes.STRING(20),
allowNull: true
},
device_sn: {
type: DataTypes.STRING(32),
allowNull: true
},
device_active_time: {
type: DataTypes.DATE,
allowNull: true
},
seq_no: {
type: DataTypes.STRING(64),
allowNull: true
},
insure_period: {
type: DataTypes.INTEGER(1),
allowNull: true
},
mileage: {
type: "DOUBLE(10,2)",
allowNull: true
},
device_type: {
type: DataTypes.INTEGER(11),
allowNull: true
},
card_version: {
type: DataTypes.STRING(32),
allowNull: true
},
company_code: {
type: DataTypes.CHAR(8),
allowNull: true
},
order_create_date: {
type: DataTypes.DATE,
allowNull: true
},
effect_date: {
type: DataTypes.DATE,
allowNull: true
},
end_date: {
type: DataTypes.DATE,
allowNull: true
},
insurance_status: {
type: DataTypes.CHAR(2),
allowNull: true
},
deleted_flag: {
type: DataTypes.CHAR(1),
allowNull: false,
defaultValue: 'N'
},
prov_merchant: {
type: DataTypes.STRING(128),
allowNull: true
},
city_merchant: {
type: DataTypes.STRING(128),
allowNull: true
},
order_create_by: {
type: DataTypes.STRING(128),
allowNull: true
},
channel_code: {
type: DataTypes.CHAR(4),
allowNull: true
},
merchant: {
type: DataTypes.STRING(128),
allowNull: true
},
phone: {
type: DataTypes.STRING(16),
allowNull: true
},
idcard_no: {
type: DataTypes.STRING(64),
allowNull: true
},
sim_no: {
type: DataTypes.STRING(24),
allowNull: true
},
datasource: {
type: DataTypes.CHAR(8),
allowNull: true
},
created_time: {
type: DataTypes.DATE,
allowNull: true
},
updated_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 'audit_insure_order'
});
Model.associate = function () {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('dj_car_loss_warning', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sn: {
type: DataTypes.STRING(32),
allowNull: false
},
stand_no: {
type: DataTypes.STRING(50),
allowNull: true
},
plate_number: {
type: DataTypes.STRING(16),
allowNull: true
},
name: {
type: DataTypes.STRING(64),
allowNull: true
},
mobile: {
type: DataTypes.STRING(11),
allowNull: true
},
enter_time: {
type: DataTypes.DATE,
allowNull: true
},
out_time: {
type: DataTypes.DATE,
allowNull: true
},
trigger_time: {
type: DataTypes.DATE,
allowNull: true
},
alarm_type: {
type: DataTypes.INTEGER(11),
allowNull: true
},
is_new: {
type: DataTypes.INTEGER(1),
allowNull: true,
defaultValue: '0'
},
number_of_shops: {
type: DataTypes.INTEGER(2),
allowNull: true,
defaultValue: '0'
},
erp_mobile: {
type: DataTypes.STRING(32),
allowNull: true
},
current_mileage: {
type: DataTypes.FLOAT,
allowNull: true
},
vehicle_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_type: {
type: DataTypes.INTEGER(11),
allowNull: true
},
pmerchant_name: {
type: DataTypes.STRING(32),
allowNull: true
},
merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: false
},
created_by: {
type: DataTypes.STRING(64),
allowNull: true
},
created_date: {
type: DataTypes.DATE,
allowNull: true
},
updated_by: {
type: DataTypes.STRING(50),
allowNull: true
},
updated_date: {
type: DataTypes.DATE,
allowNull: true
},
deleted_flag: {
type: DataTypes.CHAR(1),
allowNull: false,
defaultValue: 'N'
},
last_year_loss: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '0'
},
factory_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
factory_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
province_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
city_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_name: {
type: DataTypes.STRING(64),
allowNull: true
},
area_name: {
type: DataTypes.STRING(64),
allowNull: true
},
competition_rel_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
datafrom: {
type: DataTypes.INTEGER(1),
allowNull: true
}
}, {
tableName: 'dj_car_loss_warning'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('dj_car_maintain', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sn: {
type: DataTypes.STRING(32),
allowNull: true
},
stand_no: {
type: DataTypes.STRING(50),
allowNull: true
},
plate_number: {
type: DataTypes.STRING(64),
allowNull: true
},
name: {
type: DataTypes.STRING(64),
allowNull: true
},
mobile: {
type: DataTypes.STRING(32),
allowNull: true
},
current_day_time: {
type: DataTypes.DATE,
allowNull: true
},
total_mileage: {
type: "DOUBLE(11,2)",
allowNull: true
},
in_time: {
type: DataTypes.DATE,
allowNull: true
},
prev_mileage: {
type: "DOUBLE(11,2)",
allowNull: true
},
company: {
type: DataTypes.STRING(64),
allowNull: true
},
car_brand: {
type: DataTypes.STRING(32),
allowNull: true
},
car_model: {
type: DataTypes.STRING(64),
allowNull: true
},
car_system: {
type: DataTypes.STRING(32),
allowNull: true
},
regist_time: {
type: DataTypes.DATE,
allowNull: true
},
first_time: {
type: DataTypes.DATE,
allowNull: true
},
insurance_time: {
type: DataTypes.DATE,
allowNull: true
},
status: {
type: DataTypes.INTEGER(2),
allowNull: true,
defaultValue: '1'
},
remind_type: {
type: DataTypes.INTEGER(2),
allowNull: true
},
remind_rule: {
type: DataTypes.INTEGER(2),
allowNull: true
},
diff_mileage: {
type: DataTypes.FLOAT,
allowNull: true,
defaultValue: '0'
},
diff_time: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '0'
},
is_new: {
type: DataTypes.INTEGER(1),
allowNull: true,
defaultValue: '0'
},
number_of_shops: {
type: DataTypes.INTEGER(2),
allowNull: true,
defaultValue: '0'
},
erp_mobile: {
type: DataTypes.STRING(32),
allowNull: true
},
vehicle_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
follow_result: {
type: DataTypes.INTEGER(2),
allowNull: true
},
follow_time: {
type: DataTypes.DATE,
allowNull: true
},
follow_remarks: {
type: DataTypes.STRING(480),
allowNull: true
},
numbers: {
type: DataTypes.INTEGER(3),
allowNull: true,
defaultValue: '0'
},
distance: {
type: "DOUBLE(6,2)",
allowNull: true,
defaultValue: '0.00'
},
svrtime: {
type: DataTypes.DATE,
allowNull: true
},
merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: false
},
created_by: {
type: DataTypes.STRING(64),
allowNull: true
},
created_date: {
type: DataTypes.DATE,
allowNull: true
},
updated_by: {
type: DataTypes.STRING(50),
allowNull: true
},
updated_date: {
type: DataTypes.DATE,
allowNull: true
},
deleted_flag: {
type: DataTypes.CHAR(1),
allowNull: false,
defaultValue: 'N'
},
factory_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
factory_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
province_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
city_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_name: {
type: DataTypes.STRING(64),
allowNull: true
},
area_name: {
type: DataTypes.STRING(64),
allowNull: true
},
datafrom: {
type: DataTypes.INTEGER(1),
allowNull: true
}
}, {
tableName: 'dj_car_maintain'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('dj_car_shop_warning', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sn: {
type: DataTypes.STRING(32),
allowNull: false
},
stand_no: {
type: DataTypes.STRING(50),
allowNull: true
},
plate_number: {
type: DataTypes.STRING(64),
allowNull: true
},
name: {
type: DataTypes.STRING(64),
allowNull: true
},
mobile: {
type: DataTypes.STRING(11),
allowNull: true
},
merchant_type: {
type: DataTypes.INTEGER(11),
allowNull: true
},
pmerchant_name: {
type: DataTypes.STRING(32),
allowNull: true
},
enter_time: {
type: DataTypes.DATE,
allowNull: true
},
out_time: {
type: DataTypes.DATE,
allowNull: true
},
trigger_time: {
type: DataTypes.DATE,
allowNull: true
},
alarm_type: {
type: DataTypes.INTEGER(11),
allowNull: true
},
is_new: {
type: DataTypes.INTEGER(1),
allowNull: true,
defaultValue: '0'
},
last_time_distance: {
type: DataTypes.FLOAT,
allowNull: true,
defaultValue: '0'
},
last_time_day: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '0'
},
binding_time: {
type: DataTypes.DATE,
allowNull: true
},
binding_days: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '0'
},
number_of_shops: {
type: DataTypes.INTEGER(2),
allowNull: true,
defaultValue: '0'
},
erp_mobile: {
type: DataTypes.STRING(32),
allowNull: true
},
current_mileage: {
type: "DOUBLE(11,4)",
allowNull: true
},
vehicle_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: false
},
created_by: {
type: DataTypes.STRING(64),
allowNull: true
},
created_date: {
type: DataTypes.DATE,
allowNull: true
},
updated_by: {
type: DataTypes.STRING(50),
allowNull: true
},
updated_date: {
type: DataTypes.DATE,
allowNull: true
},
deleted_flag: {
type: DataTypes.CHAR(1),
allowNull: false,
defaultValue: 'N'
},
last_year_shops: {
type: DataTypes.INTEGER(11),
allowNull: true,
defaultValue: '0'
},
factory_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
factory_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
province_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
city_merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_name: {
type: DataTypes.STRING(64),
allowNull: true
},
province_name: {
type: DataTypes.STRING(64),
allowNull: true
},
city_name: {
type: DataTypes.STRING(64),
allowNull: true
},
area_name: {
type: DataTypes.STRING(64),
allowNull: true
},
datafrom: {
type: DataTypes.INTEGER(1),
allowNull: true
}
}, {
tableName: 'dj_car_shop_warning'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('dj_follow_record', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sn: {
type: DataTypes.STRING(20),
allowNull: true
},
stand_no: {
type: DataTypes.STRING(50),
allowNull: true
},
follow_time: {
type: DataTypes.DATE,
allowNull: true
},
follow_result: {
type: DataTypes.INTEGER(11),
allowNull: true
},
remarks: {
type: DataTypes.STRING(64),
allowNull: true
},
source: {
type: DataTypes.INTEGER(11),
allowNull: true
},
LOG: {
type: DataTypes.TEXT,
allowNull: true
},
make_time: {
type: DataTypes.DATE,
allowNull: true
},
current_mileage: {
type: "DOUBLE(11,4)",
allowNull: true,
defaultValue: '0.0000'
},
vehicle_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
merchant_id: {
type: DataTypes.INTEGER(11),
allowNull: true
},
created_by: {
type: DataTypes.STRING(64),
allowNull: true
},
created_date: {
type: DataTypes.DATE,
allowNull: true
},
updated_by: {
type: DataTypes.STRING(50),
allowNull: true
},
updated_date: {
type: DataTypes.DATE,
allowNull: true
},
deleted_flag: {
type: DataTypes.CHAR(1),
allowNull: true,
defaultValue: 'N'
},
datafrom: {
type: DataTypes.INTEGER(1),
allowNull: true
}
}, {
tableName: 'dj_follow_record'
});
Model.associate = function() {
}
return Model;
};
/*
* @Author: limin
* @Date: 2019-11-21 11:18:57
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 15:34:27
*/
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller, jwt } = app;
// router.get('/',controller.home.index);
require('./router/history')(app);
require('./router/biz')(app);
};
/*
* @Author: limin
* @Date: 2019-11-21 11:19:15
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 10:11:40
*/
module.exports = (app) => {
app.router.get("/biz/loss/findAll", app.controller.biz.loss.findAll);
app.router.get("/biz/maintain/findAll", app.controller.biz.maintain.findAll);
app.router.get("/biz/shop/findAll", app.controller.biz.shop.findAll);
app.router.get("/biz/record/findAll", app.controller.biz.record.findAll);
};
/*
* @Author: limin
* @Date: 2019-11-21 11:19:15
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 10:11:40
*/
module.exports = app => {
app.router.get('/history/findAll', app.controller.history.findAll);
}
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class BizService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DjCarLossWarning,
DjCarMaintain,
DjCarShopWarning,
DjFollowRecord
} = this.app.model.Biz;
this.MDCLW = DjCarLossWarning;
this.MDCM = DjCarMaintain;
this.MDCSW = DjCarShopWarning;
this.MDFR = DjFollowRecord;
}
/**
* 绑定表关系
*/
_associate_() { }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAllLoss({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
// const {
// search_text,
// insurance_status,
// channel_code,
// success_date_start,
// success_date_end,
// effect_date_start,
// effect_date_end,
// card_version,
// device_type,
// insure_period,
// company_code,
// mileage_start,
// mileage_end,
// active_date_start,
// active_date_end
// } = searcher;
const offset = (current - 1) * size;
// const {
// Op
// } = this.app.Sequelize;
// let where = {};
// if (search_text) {
// const __like = `%${search_text}%`;
// where = {
// [Op.or]: [{
// name: {
// [Op.like]: __like
// }
// },
// {
// shop_name: {
// [Op.like]: __like
// }
// },
// {
// full_insurance_no: {
// [Op.like]: __like
// }
// },
// {
// stand_no: {
// [Op.like]: __like
// }
// },
// {
// device_sn: {
// [Op.like]: __like
// }
// },
// {
// seq_no: {
// [Op.like]: __like
// }
// },
// ],
// };
// }
// if (insurance_status || insurance_status + '' == '0') {
// where.insurance_status = insurance_status;
// }
// if (channel_code) {
// where.channel_code = channel_code;
// }
// if (success_date_start) {
// if (success_date_end) {
// where.success_date = {
// [Op.and]: [{
// [Op.gt]: success_date_start
// },
// {
// [Op.lt]: success_date_end
// }
// ]
// };
// } else {
// where.success_date = {
// [Op.gt]: success_date_start,
// };
// }
// }
// if (effect_date_start) {
// if (effect_date_end) {
// where.effect_date = {
// [Op.and]: [{
// [Op.gt]: effect_date_start
// },
// {
// [Op.lt]: effect_date_end
// }
// ]
// }
// } else {
// where.effect_date = {
// [Op.gt]: effect_date_start,
// }
// }
// }
// if (card_version) {
// where.card_version = card_version;
// }
// if (device_type) {
// where.device_type = device_type;
// }
// if (insure_period) {
// where.insure_period = insure_period;
// }
// if (company_code) {
// where.company_code = company_code;
// }
// if (mileage_start) {
// if (mileage_end) {
// where.mileage = {
// [Op.and]: [{
// [Op.gt]: mileage_start
// }, {
// [Op.lt]: mileage_end
// }]
// };
// } else {
// where.mileage = {
// [Op.gt]: mileage_start
// };
// }
// }
// if (active_date_start) {
// if (active_date_end) {
// where.device_active_time = {
// [Op.and]: [{
// [Op.gt]: active_date_start
// }, {
// [Op.lt]: active_date_end
// }]
// };
// } else {
// where.device_active_time = {
// [Op.gt]: active_date_start
// };
// }
// }
return await this.MDCLW.findAndCountAll({
offset,
limit: +size,
// where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAllMaintain({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const offset = (current - 1) * size;
return await this.MDCM.findAndCountAll({
offset,
limit: +size,
// where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAllShopWarning({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const offset = (current - 1) * size;
return await this.MDCSW.findAndCountAll({
offset,
limit: +size,
// where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAllRecord({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const offset = (current - 1) * size;
return await this.MDFR.findAndCountAll({
offset,
limit: +size,
// where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
}
module.exports = BizService;
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class LossService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const { DjCarLossWarning } = this.app.model.Biz;
this.MDCLW = DjCarLossWarning;
}
/**
* 绑定表关系
*/
_associate_() {}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({ pager = {}, searcher = {} }) {
const { current = 1, size = 10 } = pager;
const {
searchKey,
searchValue,
merchantType,
stopTimeStart,
stopTimeEnd,
warnTimesStart,
warnTimesEnd,
orderBy = ["trigger_time", "DESC"],
} = searcher;
const offset = (current - 1) * size;
const { Op, col, literal } = this.app.Sequelize;
let where = { is_new: 1 };
if (searchValue) {
const __like = `%${searchValue}%`;
where = {
// [Op.and]: [{
[searchKey]: {
[Op.like]: __like,
},
// }]
};
}
if (merchantType || merchantType + "" == "0") {
where.merchant_type = merchantType;
}
if (stopTimeStart) {
if (stopTimeEnd) {
where.out_time = {
[Op.and]: [
{
[Op.gte]: literal(
`TIMESTAMPADD(MINUTE,${stopTimeStart},enter_time)`
),
},
{
[Op.lte]: literal(
`TIMESTAMPADD(MINUTE,${stopTimeEnd},enter_time)`
),
},
],
};
} else {
where.out_time = {
[Op.gte]: literal(`TIMESTAMPADD(MINUTE,${stopTimeStart},enter_time)`),
};
}
}
if (warnTimesStart) {
if (warnTimesEnd) {
where.number_of_shops = {
[Op.and]: [
{
[Op.gte]: warnTimesStart,
},
{
[Op.lte]: warnTimesEnd,
},
],
};
} else {
where.number_of_shops = {
[Op.gte]: warnTimesStart,
};
}
}
return await this.MDCLW.findAndCountAll({
offset,
attributes: {
include: [
[literal(`TIMESTAMPDIFF(MINUTE,enter_time,out_time)`), "keepTime"],
],
},
limit: +size,
where,
order: [orderBy],
raw: true,
});
}
}
module.exports = LossService;
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class MaintainService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DjCarMaintain
} = this.app.model.Biz;
this.MDCM = DjCarMaintain;
}
/**
* 绑定表关系
*/
_associate_() { }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const {
searchKey,
searchValue,
remind_type,
remind_rule,
numbersStart,
numbersEnd,
distance,
isNew
} = searcher;
const offset = (current - 1) * size;
const {
Op
} = this.app.Sequelize;
let where = { is_new: isNew };
if (searchValue) {
const __like = `%${searchValue}%`;
where = {
[Op.and]: [{
[searchKey]: {
[Op.like]: __like
}
}]
};
}
if (remind_type) {
where.remind_type = remind_type;
}
if (remind_rule) {
where.remind_rule = remind_rule;
}
if (numbersStart) {
if (numbersEnd) {
where.numbers = {
[Op.and]: [{
[Op.gte]: numbersStart
},
{
[Op.lte]: numbersEnd
}
]
};
} else {
where.numbers = {
[Op.gte]: numbersStart,
};
}
}
if (distance) {
const [ds, de] = distance.split('-')
if (ds) {
if (de) {
where.distance = {
[Op.and]: [{
[Op.gte]: ds
},
{
[Op.lte]: de
}
]
};
} else {
where.distance = {
[Op.gte]: ds
};
}
}
}
return await this.MDCM.findAndCountAll({
offset,
limit: +size,
where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
}
module.exports = MaintainService;
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class RecordService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DjFollowRecord
} = this.app.model.Biz;
this.MDFR = DjFollowRecord;
}
/**
* 绑定表关系
*/
_associate_() { }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 1000000000
} = pager;
const {
sn,
} = searcher;
const offset = (current - 1) * size;
let where = { sn };
return await this.MDFR.findAndCountAll({
offset,
limit: +size,
where,
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
}
module.exports = RecordService;
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class ShopService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DjCarShopWarning
} = this.app.model.Biz;
this.MDCSW = DjCarShopWarning;
}
/**
* 绑定表关系
*/
_associate_() { }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const {
searchKey,
searchValue,
number_of_shops_start,
number_of_shops_end,
binding_days_start,
binding_days_end,
trigger_time_start,
trigger_time_end
} = searcher;
console.log(number_of_shops_start, number_of_shops_end, binding_days_start, binding_days_end);
const offset = (current - 1) * size;
const {
Op,
literal
} = this.app.Sequelize;
let where = { is_new: 1 };
if (searchValue) {
const __like = `%${searchValue}%`;
where = {
[Op.and]: [{
[searchKey]: {
[Op.like]: __like
}
}]
};
}
if (number_of_shops_start && number_of_shops_start != '0') {
if (number_of_shops_end && number_of_shops_end != '0') {
where.number_of_shops = {
[Op.and]: [{
[Op.gte]: number_of_shops_start
},
{
[Op.lte]: number_of_shops_end
}
]
};
} else {
where.number_of_shops = {
[Op.gte]: number_of_shops_start,
};
}
}
if (binding_days_start && binding_days_start != '0') {
if (binding_days_end && binding_days_end != '0') {
where.binding_days = {
[Op.and]: [{
[Op.gte]: binding_days_start
},
{
[Op.lte]: binding_days_end
}
]
}
} else {
where.binding_days = {
[Op.gte]: binding_days_start,
}
}
}
if (trigger_time_start) {
if (trigger_time_end) {
where.trigger_time = {
[Op.and]: [{
[Op.gte]: trigger_time_start
}, {
[Op.lte]: trigger_time_end
}]
};
} else {
where.trigger_time = {
[Op.gte]: trigger_time_start
};
}
}
return await this.MDCSW.findAndCountAll({
offset,
limit: +size,
where,
attributes: { include: [[literal(`TIMESTAMPDIFF(MINUTE,enter_time,out_time)`), 'keepTime']] },
// order: [
// ["success_date", "ASC"]
// ],
raw: true
});
}
}
module.exports = ShopService;
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-04-20 13:54:35
*/
const Service = require("egg").Service;
// var moment = require('moment');/
class HistoryService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
// this._associate_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
AuditInsureOrder
} = this.app.model;
this.MAIO = AuditInsureOrder;
}
/**
* 绑定表关系
*/
_associate_() { }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager;
const {
search_text,
insurance_status,
channel_code,
success_date_start,
success_date_end,
effect_date_start,
effect_date_end,
card_version,
device_type,
insure_period,
company_code,
mileage_start,
mileage_end,
active_date_start,
active_date_end,
storage_date_start,
storage_date_end
} = searcher;
const offset = (current - 1) * size;
const {
Op
} = this.app.Sequelize;
let where = {};
if (search_text) {
const __like = `%${search_text}%`;
where = {
[Op.or]: [{
name: {
[Op.like]: __like
}
},
{
shop_name: {
[Op.like]: __like
}
},
{
full_insurance_no: {
[Op.like]: __like
}
},
{
stand_no: {
[Op.like]: __like
}
},
{
device_sn: {
[Op.like]: __like
}
},
{
seq_no: {
[Op.like]: __like
}
},
],
};
}
if (insurance_status || insurance_status + '' == '0') {
where.insurance_status = insurance_status;
}
if (channel_code) {
where.channel_code = channel_code;
}
if (success_date_start) {
if (success_date_end) {
where.success_date = {
[Op.and]: [{
[Op.gte]: success_date_start
},
{
[Op.lte]: success_date_end
}
]
};
} else {
where.success_date = {
[Op.gte]: success_date_start,
};
}
}
if (storage_date_start) {
if (storage_date_end) {
where.in_storage_time = {
[Op.and]: [{
[Op.gte]: storage_date_start
},
{
[Op.lte]: storage_date_end
}
]
};
} else {
where.in_storage_time = {
[Op.gte]: storage_date_start,
};
}
}
if (effect_date_start) {
if (effect_date_end) {
where.effect_date = {
[Op.and]: [{
[Op.gte]: effect_date_start
},
{
[Op.lte]: effect_date_end
}
]
}
} else {
where.effect_date = {
[Op.gte]: effect_date_start,
}
}
}
if (card_version) {
where.card_version = card_version;
}
if (device_type) {
where.device_type = device_type;
}
if (insure_period) {
where.insure_period = insure_period;
}
if (company_code) {
where.company_code = company_code;
}
if (mileage_start) {
if (mileage_end) {
where.mileage = {
[Op.and]: [{
[Op.gte]: mileage_start
}, {
[Op.lte]: mileage_end
}]
};
} else {
where.mileage = {
[Op.gte]: mileage_start
};
}
}
if (active_date_start) {
if (active_date_end) {
where.device_active_time = {
[Op.and]: [{
[Op.gte]: active_date_start
}, {
[Op.lte]: active_date_end
}]
};
} else {
where.device_active_time = {
[Op.gte]: active_date_start
};
}
}
return await this.MAIO.findAndCountAll({
offset,
limit: +size,
where,
order: [
["success_date", "ASC"]
],
raw: true
});
}
}
module.exports = HistoryService;
\ No newline at end of file
module.exports = app => {
let { validator } = app;
// 校验用户名是否正确
validator.addRule("userName", (rule, value) => {
if (/^\d+$/.test(value)) {
throw new Error('用户名应该是字符串')
} else if (value.length < 3 || value.length > 10) {
console.log("用户名的长度应该在3-10之间");
}
});
// 添加自定义参数校验规则
validator.addRule("123", (rule, value) => {
if (value !== "123") {
return "must be 123";
}
});
};
environment:
matrix:
- nodejs_version: '10'
install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall
test_script:
- node --version
- npm --version
- npm run test
build: off
/*
* @Author: limin
* @Date: 2019-11-16 09:26:53
* @Last Modified by: limin
* @Last Modified time: 2020-04-16 18:49:17
*/
/* eslint valid-jsdoc: "off" */
"use strict";
/**
* @param {Egg.EggAppInfo} app app info
*/
module.exports = app => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = (exports = {});
// use for cookie sign key, should change to your own and keep security
config.keys = app.name + "_1573615133248_6253";
// add your middleware config here
// config.middleware = [ 'errorHandler'];
config.onerror = {
//全局异常捕获
all(err, ctx) {
// 在此处定义针对所有响应类型的错误处理方法
// 注意,定义了 config.all 之后,其他错误处理方法不会再生效
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit("error", err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
const error =
status === 500 && ctx.app.config.env === "prod"
? "Internal Server Error"
: err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.body = JSON.stringify(
ctx.response.ServerResponse.Error({ message: error })
);
if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
}
// html(err, ctx) {
// // html hander
// ctx.body = '<h3>error</h3>';
// ctx.status = 500;
// },
// json(err, ctx) {
// // json hander
// ctx.body = { message: 'error' };
// ctx.status = 500;
// },
// jsonp(err, ctx) {
// // 一般来说,不需要特殊针对 jsonp 进行错误定义,jsonp 的错误处理会自动调用 json 错误处理,并包装成 jsonp 的响应格式
// },
};
// add your user config here
// const userConfig = {
config.jwt = {
secret: "glsx-insurence-egg-server" //自定义 token 的加密条件字符串
};
config.cors = {
origin: "http://192.168.2.222:8085",
credentials: true,
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
config.security = {
csrf: {
enable: false,
ignoreJSON: true
},
domainWhiteList: ["http://192.168.2.222:8085"] //允许访问接口的白名单
};
config.redis = {
client: {
port: 6379, // Redis port
host: "127.0.0.1", // Redis host
password: "",
db: 0
}
};
config.validate = {
// convert: false,
// validateRoot: false,
};
config.sequelize = {
timezone: '+08:00',
define: {
freezeTableName: true, // 禁止修改表名,默认情况下,sequelize将自动将所有传递的模型名称(define的第一个参数)转换为复数
// 但是为了安全着想,复数的转换可能会发生变化,所以禁止该行为
timestamps: false, // 不自动维护时间戳 [ created_at、updated_at ]
},
dialectOptions: {
dateStrings: true, //格式化datetime
typeCast: true
}
};
config.swaggerdoc = {
dirScanner: "./app/controller",
apiInfo: {
title: "广联运营",
description: "swagger-ui for egg",
version: "1.0.0"
},
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
securityDefinitions: {},
enableSecurity: false,
// enableValidate: true,
routerMap: true,
enable: true
};
return config;
};
/*
* @Author: limin
* @Date: 2019-11-16 09:26:47
* @Last Modified by: limin
* @Last Modified time: 2020-04-15 10:59:34
*/
/* eslint valid-jsdoc: "off" */
"use strict";
const path = require("path");
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = (exports = {});
config.logger = {
level: "INFO",
dir: path.join(__dirname, "../logs/dev") // 保存路径为工程路径下`logs/dev`
};
// add your user config here
// myAppName: 'egg',
config.sequelize = {
dialect: "mysql",
host: "192.168.3.153",
port: "3308",
database: "glsx_audit",
username: "apuser",
password: "123456"
};
return config;
};
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-16 09:26:40
* @Last Modified by: limin
* @Last Modified time: 2020-04-14 17:18:45
*/
/* eslint valid-jsdoc: "off" */
"use strict";
const path = require("path");
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = (exports = {});
config.logger = {
level: "INFO",
dir: path.join(__dirname, "../logs/pro") // 保存路径为工程路径下`logs/pro`
};
config.sequelize = {
dialect: "mysql",
host: "192.168.5.20",
port: "3307",
database: "glsx_audit",
username: "data_house_user",
password: "ZhaiMiAxIg"
};
// add your user config here
// myAppName: 'egg',
return config;
};
\ No newline at end of file
/*
* @Author: limin
* @Date: 2019-11-16 09:27:00
* @Last Modified by: limin
* @Last Modified time: 2020-04-16 17:47:08
*/
"use strict";
/** @type Egg.EggPlugin */
// module.exports = {
// // had enabled by egg
// // static: {
// // enable: true,
// // }
// };
exports.sequelize = {
enable: true,
package: "egg-sequelize"
};
exports.jwt = {
enable: false,
package: "egg-jwt"
};
exports.cors = {
enable: true,
package: "egg-cors"
};
exports.redis = {
enable: false,
package: "egg-redis"
};
exports.swaggerdoc = {
enable: true,
package: 'egg-swagger-doc-feat',
};
exports.validate = {
enable: true,
package: 'egg-validate',
};
{
"include": [
"**/*"
]
}
\ No newline at end of file
{
"name": "glsx-insurence-egg-server",
"version": "1.0.0",
"description": "广联赛讯历史保单数据服务",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^2.26.0",
"egg-cors": "^2.2.3",
"egg-jwt": "^3.1.6",
"egg-redis": "^2.4.0",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^5.2.1",
"egg-validate": "^2.0.2",
"moment": "^2.24.0",
"mysql2": "^2.1.0"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"egg-bin": "^4.11.0",
"egg-ci": "^1.11.0",
"egg-mock": "^3.21.0",
"egg-swagger-doc-feat": "^2.2.13",
"eslint": "^5.13.0",
"eslint-config-egg": "^7.1.0",
"sequelize-cli": "^5.5.1"
},
"engines": {
"node": ">=10.0.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=glsx-insurence-egg-server",
"stop": "egg-scripts stop --title=glsx-insurence-egg-server",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "10"
},
"repository": {
"type": "git",
"url": ""
},
"author": "limin",
"license": "MIT"
}
'use strict';
const { app, assert } = require('egg-mock/bootstrap');
describe('test/app/controller/home.test.js', () => {
it('should assert', () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
// const ctx = app.mockContext({});
// yield ctx.service.xx();
});
it('should GET /', () => {
return app.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!