Commit 628c824e by 王昆

gsb

parent 936b0814
# Default ignored files
/workspace.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/zhichan.iml" filepath="$PROJECT_DIR$/.idea/zhichan.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
...@@ -83,20 +83,5 @@ class UploadCtl extends CtlBase{ ...@@ -83,20 +83,5 @@ class UploadCtl extends CtlBase{
// return system.getErrResult2("您的网络不稳, 请稍后重试") // return system.getErrResult2("您的网络不稳, 请稍后重试")
// } // }
// } // }
async paramXlsx(queryobj, qobj, req) {
try {
var rs = await this.workloadSve.paramXlsx(req.session.user.id, qobj.url);
if (rs.code == 0) {
return system.getErrResult2(rs.msg || "文件解析失败");
}
return system.getResult2(rs);
} catch (e) {
console.log(e);
return system.getErrResult2("您的网络不稳, 请稍后重试")
}
}
} }
module.exports=UploadCtl; module.exports=UploadCtl;
...@@ -223,6 +223,8 @@ class Dao { ...@@ -223,6 +223,8 @@ class Dao {
} }
return this.db.query(sql, tmpParas); return this.db.query(sql, tmpParas);
} }
async findCount(whereObj = null) { async findCount(whereObj = null) {
return this.model.count(whereObj, { logging: false }).then(c => { return this.model.count(whereObj, { logging: false }).then(c => {
return c; return c;
......
const system=require("../../../system"); const system = require("../../../system");
const Dao=require("../../dao.base"); const Dao = require("../../dao.base");
class WorkloadDao extends Dao{
constructor(){ class WorkloadDao extends Dao {
constructor() {
super(Dao.getModelName(WorkloadDao)); super(Dao.getModelName(WorkloadDao));
} }
async countHistory(params) {
var sql = [];
sql.push("SELECT COUNT(DISTINCT(id_nu)) AS num FROM `workload_info` WHERE status = 1");
this.setCondition(sql, params);
let rs = await this.customQuery(sql.join(" "), params);
if (!rs || rs.length == 0) {
return 0;
}
return rs[0].num || 0;
}
async pageHistory(params) {
var sql = [];
sql.push("SELECT");
sql.push("`id`, `username`, `iphone`, `id_nu`, `card_nu`, `send_amount`,");
sql.push("`created_at`, `updated_time`, `workload`, ");
sql.push("`created_time`, `updated_at`, `status`,");
sql.push("sum(send_amount) AS allAmount, COUNT(1) AS times");
sql.push("FROM `workload_info`")
sql.push("WHERE status = 1")
this.setCondition(sql, params);
sql.push("GROUP BY id_nu");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
async findByIdNo(params) {
var sql = [];
sql.push("SELECT");
sql.push("`id`, `username`, `iphone`, `id_nu`, `card_nu`, `send_amount`,");
sql.push("`created_at`, `updated_time`, `workload`, ");
sql.push("`created_time`, `updated_at`, `status`");
sql.push("FROM `workload_info`");
sql.push("WHERE id_nu = :id_nu");
return await this.customQuery(sql.join(" "), params);
}
setCondition(sql, params) {
if (params.username) {
sql.push("AND username = :username");
}
if (params.iphone) {
sql.push("AND iphone = :iphone");
}
if (params.id_nu) {
sql.push("AND id_nu = :id_nu");
}
}
} }
module.exports=WorkloadDao;
module.exports = WorkloadDao;
...@@ -9,6 +9,98 @@ class WorkloadService extends ServiceBase { ...@@ -9,6 +9,98 @@ class WorkloadService extends ServiceBase {
this.restClient = system.getObject("util.restClient"); this.restClient = system.getObject("util.restClient");
} }
async pageByCondition(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var username = this.trim(params.username);
var iphone = this.trim(params.iphone);
var id_nu = this.trim(params.id_nu);
var status = this.trim(params.status);
var where = {};
var orderby = [
["id", 'desc']
];
if (username) {
where.username = username;
}
if (iphone) {
where.iphone = iphone;
}
if (id_nu) {
where.id_nu = id_nu
}
if (params.status === 0 || params.status === 1) {
where.status = params.status;
}
var page = await this.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var item of page.rows) {
this.handleDate(item, ['created_time', 'updated_time'], 'YYYY-MM-DD');
this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
}
}
return page;
}
async workloadConfirm(params) {
var sql = [];
sql.push("UPDATE");
sql.push("workload_info");
sql.push("SET `status` = 1, updated_at = NOW()");
sql.push("WHERE `status` = 0");
if (params.id) {
sql.push("AND id = :id ");
}
await this.customUpdate(sql.join(" "), params);
return 1;
}
async historyPage(params) {
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.username = this.trim(params.username);
params.iphone = this.trim(params.iphone);
params.id_nu = this.trim(params.id_nu);
params.status = this.trim(params.status);
let total = await this.dao.countHistory(params);
if (total == 0) {
return {count: 1, rows: []};
}
params.startRow = (params.currentPage - 1) * params.pageSize;
let list = await this.dao.pageHistory(params);
if (list) {
for (var item of list) {
this.handleDate(item, ['created_time', 'updated_time'], 'YYYY-MM-DD');
this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
}
}
return {count: total, rows: list};
}
async historyInfo(params) {
let wl = await this.findById(params.id);
if (!wl) {
return [];
}
let list = await this.dao.findByIdNo({id_nu: wl.id_nu});
if (list) {
for (var item of list) {
this.handleDate(item, ['created_time', 'updated_time'], 'YYYY-MM-DD');
this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
}
}
return list;
}
async paramXlsx(userId, ossurl) { async paramXlsx(userId, ossurl) {
var result = { var result = {
code: 0, code: 0,
...@@ -27,21 +119,26 @@ class WorkloadService extends ServiceBase { ...@@ -27,21 +119,26 @@ class WorkloadService extends ServiceBase {
} }
var heads = rows[0]; var heads = rows[0];
var cells = rows[i]; var cells = rows[i];
if (cells.length < 9) {
result.msg = "excel第" + i + "行,数据不全";
return result;
}
for (let j = 0; j < cells.length; j++) { for (let j = 0; j < cells.length; j++) {
if (cells[j] === undefined) { if (!cells[j]) {
result.msg = "excel序号为" + cells[0] + "的" + heads[j] + "不能为空"; result.msg = "excel序号为" + cells[0] + "的" + heads[j] + "不能为空";
return result; return result;
} }
} }
var data = {}; var data = {};
data.username = "" + cells[1]; data.username = this.trim(cells[1]);
data.iphone = "" + cells[2]; data.iphone = this.trim(cells[2]);
data.id_nu = "" + cells[3]; data.id_nu = this.trim(cells[3]);
data.card_nu = "" + cells[4]; data.card_nu = this.trim(cells[4]);
data.send_amount = "" + cells[5]; data.send_amount = this.trim(cells[5]);
data.created_time = "" + new Date(1900, 0, cells[6]); data.created_time = new Date(1900, 0, cells[6]);
data.updated_time = "" + new Date(1900, 0, cells[7]); data.updated_time = new Date(1900, 0, cells[7]);
data.workload = "" + cells[8]; data.workload = this.trim(cells[8]);
resu.push(data) resu.push(data)
} }
await this.dao.model.bulkCreate(resu, {fields: ["username", "iphone", "id_nu", "card_nu", "send_amount", "created_time", "updated_time", "workload"]}); await this.dao.model.bulkCreate(resu, {fields: ["username", "iphone", "id_nu", "card_nu", "send_amount", "created_time", "updated_time", "workload"]});
...@@ -53,10 +150,7 @@ class WorkloadService extends ServiceBase { ...@@ -53,10 +150,7 @@ class WorkloadService extends ServiceBase {
result.msg = "接口异常"; result.msg = "接口异常";
return result; return result;
} }
} }
} }
module.exports = WorkloadService; module.exports = WorkloadService;
\ No newline at end of file
...@@ -49,6 +49,9 @@ class ServiceBase { ...@@ -49,6 +49,9 @@ class ServiceBase {
async customQuery(sql, paras, t) { async customQuery(sql, paras, t) {
return this.dao.customQuery(sql, paras, t); return this.dao.customQuery(sql, paras, t);
} }
async customUpdate(sql, paras, t) {
return this.dao.customUpdate(sql, paras, t);
}
async findCount(whereObj = null) { async findCount(whereObj = null) {
return this.dao.findCount(whereObj); return this.dao.findCount(whereObj);
} }
...@@ -105,5 +108,30 @@ class ServiceBase { ...@@ -105,5 +108,30 @@ class ServiceBase {
} }
return uuid.join(''); return uuid.join('');
} }
handleDate(row, fields, pattern, addHours) {
pattern = pattern || "YYYY-MM-DD HH:mm:ss";
if (!row) {
return;
}
for (var field of fields) {
if (row[field]) {
if(addHours) {
row[field] = moment(row[field]).add(addHours,"hours").format(pattern);
} else {
row[field] = moment(row[field]).format(pattern);
}
}
}
}
trim(o) {
if (!o) {
return "";
}
return o.toString().trim();
}
} }
module.exports = ServiceBase; module.exports = ServiceBase;
...@@ -134,6 +134,37 @@ class System { ...@@ -134,6 +134,37 @@ class System {
} }
}; };
static y2f(y) {
if (!y) {
return 0;
}
return (Number(y) * 100).toFixed(0);
}
static f2y(f) {
if (!f) {
return 0;
}
return parseFloat((Number(f) / 100).toFixed(2));
}
static f2y4list(list, fields, prev) {
if (!list || list.length == 0 || !fields || fields.length == 0) {
return;
}
prev = prev || "";
for (var item of list) {
for (var f of fields) {
var v = item[f] || 0;
try {
item[f + "_y"] = prev + parseFloat((Number(v) / 100).toFixed(2));
} catch (error) {
console.log(error);
}
}
}
}
} }
Date.prototype.Format = function (fmt) { //author: meizz Date.prototype.Format = function (fmt) { //author: meizz
var o = { var o = {
......
...@@ -7,13 +7,13 @@ var settings={ ...@@ -7,13 +7,13 @@ var settings={
}, },
database:{ database:{
dbname : "laowubao", dbname : "laowubao",
user : "root", // user : "root",
password : "root", // password : "root",
// dbname : "laowubao", // dbname : "laowubao",
// user: "write", user: "write",
// password: "write", password: "write",
config : { config : {
host: '192.168.18.110', host: '192.168.18.237',
// dbname : "laowubao", // dbname : "laowubao",
// user: "write", // user: "write",
// password: "write", // password: "write",
......
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