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{
// 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;
......@@ -223,6 +223,8 @@ class Dao {
}
return this.db.query(sql, tmpParas);
}
async findCount(whereObj = null) {
return this.model.count(whereObj, { logging: false }).then(c => {
return c;
......
const system=require("../../../system");
const Dao=require("../../dao.base");
class WorkloadDao extends Dao{
constructor(){
super(Dao.getModelName(WorkloadDao));
const system = require("../../../system");
const Dao = require("../../dao.base");
class WorkloadDao extends Dao {
constructor() {
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;
......@@ -42,7 +42,7 @@ module.exports = (db, DataTypes) => {
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'user_info',
tableName: 'user_info',
validate: {
},
......
......@@ -4,59 +4,153 @@ const xlsx = require('node-xlsx');
const fs = require("fs");
class WorkloadService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(WorkloadService));
this.restClient = system.getObject("util.restClient");
}
async paramXlsx(userId, ossurl) {
var result = {
code: 0,
msg: "",
list: [],
};
var filePath = "/tmp/esettle_offline_" + userId + ".xlsx";
try {
await this.restClient.execDownload("'" + ossurl + "'", filePath);
var sheets = xlsx.parse(filePath);
var rows = sheets[0].data;
var resu = [];
for (let i = 0; i < rows.length; i++) {
if (2 > i) {
continue;
}
var heads = rows[0];
var cells = rows[i];
for (let j = 0; j < cells.length; j++) {
if (cells[j] === undefined) {
result.msg = "excel序号为" + cells[0] + "的" + heads[j] + "不能为空";
return result;
}
}
var data = {};
data.username = "" + cells[1];
data.iphone = "" + cells[2];
data.id_nu = "" + cells[3];
data.card_nu = "" + cells[4];
data.send_amount = "" + cells[5];
data.created_time = "" + new Date(1900, 0, cells[6]);
data.updated_time = "" + new Date(1900, 0, cells[7]);
data.workload = "" + cells[8];
resu.push(data)
}
await this.dao.model.bulkCreate(resu, {fields: ["username", "iphone", "id_nu", "card_nu", "send_amount", "created_time", "updated_time", "workload"]});
result.code = 1;
result.msg = "上传成功";
return result;
} catch (e) {
console.log(e);
result.msg = "接口异常";
constructor() {
super("common", ServiceBase.getDaoName(WorkloadService));
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) {
var result = {
code: 0,
msg: "",
list: [],
};
var filePath = "/tmp/esettle_offline_" + userId + ".xlsx";
try {
await this.restClient.execDownload("'" + ossurl + "'", filePath);
var sheets = xlsx.parse(filePath);
var rows = sheets[0].data;
var resu = [];
for (let i = 0; i < rows.length; i++) {
if (2 > i) {
continue;
}
var heads = rows[0];
var cells = rows[i];
if (cells.length < 9) {
result.msg = "excel第" + i + "行,数据不全";
return result;
}
for (let j = 0; j < cells.length; j++) {
if (!cells[j]) {
result.msg = "excel序号为" + cells[0] + "的" + heads[j] + "不能为空";
return result;
}
}
var data = {};
data.username = this.trim(cells[1]);
data.iphone = this.trim(cells[2]);
data.id_nu = this.trim(cells[3]);
data.card_nu = this.trim(cells[4]);
data.send_amount = this.trim(cells[5]);
data.created_time = new Date(1900, 0, cells[6]);
data.updated_time = new Date(1900, 0, cells[7]);
data.workload = this.trim(cells[8]);
resu.push(data)
}
await this.dao.model.bulkCreate(resu, {fields: ["username", "iphone", "id_nu", "card_nu", "send_amount", "created_time", "updated_time", "workload"]});
result.code = 1;
result.msg = "上传成功";
return result;
} catch (e) {
console.log(e);
result.msg = "接口异常";
return result;
}
}
}
module.exports = WorkloadService;
\ No newline at end of file
......@@ -49,6 +49,9 @@ class ServiceBase {
async 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) {
return this.dao.findCount(whereObj);
}
......@@ -105,5 +108,30 @@ class ServiceBase {
}
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;
......@@ -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
var o = {
......
......@@ -7,13 +7,13 @@ var settings={
},
database:{
dbname : "laowubao",
user : "root",
password : "root",
// user : "root",
// password : "root",
// dbname : "laowubao",
// user: "write",
// password: "write",
user: "write",
password: "write",
config : {
host: '192.168.18.110',
host: '192.168.18.237',
// dbname : "laowubao",
// user: "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