import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
import { In, MoreThanOrEqual } from "typeorm";
|
import moment = require("moment");
|
|
/**
|
* WMS首页统计数据
|
*/
|
export default class TmsController extends BaseController {
|
//#region WMS首页第一屏统计
|
/**
|
* WMS首页第一屏统计
|
*/
|
@Post()
|
public async getOrderSummary() {
|
let { ctx } = this;
|
let redis = ctx.app.redis.clients.get("common");
|
let userInfo = await ctx.helper.userInfo();
|
let appKey = this.app.config.keys;
|
let key = "REDIS_" + appKey + userInfo.userProduct_Id + "_" + userInfo.user_Id + "_DASHBORAD_getOrderSummary";
|
try {
|
let cacheValue = await redis.get(key);
|
if (cacheValue) {
|
this.info.result = true;
|
this.info.data = JSON.parse(cacheValue);
|
ctx.body = this.info;
|
return;
|
}
|
let authWhere = {};
|
if (!userInfo.isAdministrator) {
|
// 获得仓库权限
|
let _where = await this.ctx.service.auth.getStorageAuth();
|
authWhere = Object.assign(authWhere, _where);
|
// 获得货主权限
|
_where = await this.ctx.service.auth.getConsignorAuth();
|
authWhere = Object.assign(authWhere, _where);
|
}
|
|
let where: any = {
|
userProduct_Id: userInfo.userProduct_Id
|
};
|
where = Object.assign(where, authWhere);
|
let data1 = await this.dbRead.count(SaleOrder, where);
|
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
statusText: In(["新建", "待审核"])
|
};
|
where = Object.assign(where, authWhere);
|
let data2 = await this.dbRead.count(SaleOrder, where);
|
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
statusText: In(["等待打包"])
|
};
|
where = Object.assign(where, authWhere);
|
let data3 = await this.dbRead.count(SaleOrder, where);
|
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
statusText: In(["打包完成", "发运完成"])
|
};
|
where = Object.assign(where, authWhere);
|
let data4 = await this.dbRead.count(SaleOrder, where);
|
|
let dataInfo: any = {};
|
dataInfo.data1 = data1;
|
dataInfo.data2 = data2;
|
dataInfo.data3 = data3;
|
dataInfo.data4 = data4;
|
this.info.result = true;
|
this.info.data = dataInfo;
|
|
// 缓存数据
|
await redis.set(key, JSON.stringify(dataInfo));
|
await redis.expire(key, 60 * 60 * 0.5);
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region WMS首页第二屏左侧统计
|
/**
|
* WMS首页第二屏左侧统计
|
*/
|
@Post()
|
public async getRingData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let redis = ctx.app.redis.clients.get("common");
|
let userInfo = await ctx.helper.userInfo();
|
let appKey = this.app.config.keys;
|
let key = "REDIS_" + appKey + userInfo.userProduct_Id + "_" + userInfo.user_Id + "_DASHBORAD_getRingData";
|
try {
|
let cacheValue = await redis.get(key);
|
if (cacheValue && !this.body.refresh) {
|
this.info.result = true;
|
this.info.data = JSON.parse(cacheValue);
|
ctx.body = this.info;
|
return;
|
}
|
let authWhere = {};
|
if (!userInfo.isAdministrator) {
|
// 获得仓库权限
|
let _where = await this.ctx.service.auth.getStorageAuth();
|
authWhere = Object.assign(authWhere, _where);
|
// 获得货主权限
|
_where = await this.ctx.service.auth.getConsignorAuth();
|
authWhere = Object.assign(authWhere, _where);
|
}
|
|
let where: any = {
|
userProduct_Id: userInfo.userProduct_Id
|
};
|
where = Object.assign(where, authWhere);
|
let date = moment(new Date()).set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
if (body.dateType == "今日") {
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近两日") {
|
date = date.add(-1, "days");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近一星期") {
|
date = date.add(-6, "days");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近一月") {
|
date = date.add(-1, "months");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近三月") {
|
date = date.add(-3, "months");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近半年") {
|
date = date.add(-6, "months");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
} else if (body.dateType == "近一年") {
|
date = date.add(-1, "years");
|
where.createDate = MoreThanOrEqual(date.toDate());
|
}
|
let data1 = await this.dbRead.count(SaleOrder, where);
|
|
where.statusText = In(["新建", "待审核"]);
|
let data2 = await this.dbRead.count(SaleOrder, where);
|
|
where.statusText = In(["等待打包", "波次完成"]);
|
let data3 = await this.dbRead.count(SaleOrder, where);
|
|
where.statusText = In(["打包完成", "发运完成"]);
|
let data4 = await this.dbRead.count(SaleOrder, where);
|
|
let dataInfo: any = {};
|
dataInfo.data1 = data1;
|
dataInfo.data2 = data2;
|
dataInfo.data3 = data3;
|
dataInfo.data4 = data4;
|
this.info.result = true;
|
this.info.data = dataInfo;
|
|
// 缓存数据
|
await redis.set(key, JSON.stringify(dataInfo));
|
await redis.expire(key, 60 * 60 * 0.5);
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region WMS首页第二屏右侧统计
|
/**
|
* WMS首页第二屏右侧统计
|
*/
|
@Post()
|
public async getColumnData() {
|
let { ctx } = this;
|
let dataList: Array<any> = [];
|
let redis = ctx.app.redis.clients.get("common");
|
let userInfo = await ctx.helper.userInfo();
|
let appKey = this.app.config.keys;
|
let key = "REDIS_" + appKey + userInfo.userProduct_Id + "_" + userInfo.user_Id + "DASHBORAD_getColumnData";
|
try {
|
let where = " And userProduct_Id=" + userInfo.userProduct_Id;
|
if (userInfo.userType === "consignor") {
|
where = " AND consignor_Id=" + userInfo.consignor_Id;
|
key += "_" + userInfo.consignor_Id;
|
} else {
|
if (!userInfo.isAdministrator) {
|
// 获得仓库权限
|
where += " And " + (await this.ctx.service.auth.getStorageAuth("string"));
|
// 获得货主权限
|
where += " And " + (await this.ctx.service.auth.getConsignorAuth("string"));
|
}
|
}
|
let cacheValue = await redis.get(key);
|
if (cacheValue) {
|
this.info.result = true;
|
this.info.data = JSON.parse(cacheValue);
|
ctx.body = this.info;
|
return;
|
}
|
|
let sql = `SELECT year(CreateDate) as year,month(CreateDate) as month,count(1) as count
|
from Sale_Order
|
WHERE CreateDate IS NOT NULL ${where}
|
GROUP BY year(CreateDate), month(CreateDate)
|
ORDER BY year(CreateDate), month(CreateDate)`;
|
let dt = await this.dbRead.query(sql);
|
for (let dr of dt) {
|
let year = dr["year"];
|
let month = dr["month"];
|
let count = dr["count"];
|
let dataInfo = {
|
year: year,
|
month: month,
|
count: count
|
};
|
dataList.push(dataInfo);
|
}
|
|
this.info.result = true;
|
this.info.data = dataList;
|
|
// 缓存数据
|
await redis.set(key, JSON.stringify(dataList));
|
await redis.expire(key, 60 * 60 * 0.5);
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region WMS首页第三屏统计
|
/**
|
* WMS首页第三屏统计
|
*/
|
@Post()
|
public async getEveryday() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let redis = ctx.app.redis.clients.get("common");
|
let userInfo = await ctx.helper.userInfo();
|
let appKey = this.app.config.keys;
|
let key = "REDIS_" + appKey + userInfo.userProduct_Id + "_" + userInfo.user_Id + "DASHBORAD_getEveryday";
|
try {
|
let where = "userProduct_Id=" + userInfo.userProduct_Id + " ";
|
if (!userInfo.isAdministrator) {
|
// 获得仓库权限
|
where += " And " + (await this.ctx.service.auth.getStorageAuth("string"));
|
// 获得货主权限
|
where += " And " + (await this.ctx.service.auth.getConsignorAuth("string"));
|
}
|
let cacheValue = await redis.get(key);
|
if (cacheValue && !this.body.refresh) {
|
this.info.result = true;
|
this.info.data = JSON.parse(cacheValue);
|
ctx.body = this.info;
|
return;
|
}
|
|
if (body.dateType == "今日") {
|
where += "and DateDiff(dd,CreateDate,getdate())=0";
|
} else if (body.dateType == "近两日") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=1";
|
} else if (body.dateType == "近一星期") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=6";
|
} else if (body.dateType == "近一月") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=30";
|
} else if (body.dateType == "近三月") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=90";
|
} else if (body.dateType == "近半年") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=180";
|
} else if (body.dateType == "近一年") {
|
where += "and DateDiff(dd,CreateDate,getdate())<=365";
|
}
|
let dataList: Array<any> = [];
|
|
let sql = `SELECT year(CreateDate) as year,month(CreateDate) as month,DAY(CreateDate) AS day,count(1) as count
|
from Sale_Order where ${where}
|
GROUP BY year(CreateDate), month(CreateDate),DAY(CreateDate)
|
ORDER BY year(CreateDate),month(CreateDate),DAY(CreateDate)`;
|
let dt = await this.dbRead.query(sql);
|
for (let dr of dt) {
|
let year = dr["year"];
|
let month = dr["month"];
|
let day = dr["day"];
|
let countWayBillNum = dr["count"];
|
let dataInfo = {
|
year: year,
|
month: month,
|
day: day,
|
countWayBillNum: countWayBillNum
|
};
|
dataList.push(dataInfo);
|
}
|
|
this.info.result = true;
|
this.info.data = dataList;
|
|
// 缓存数据
|
await redis.set(key, JSON.stringify(dataList));
|
await redis.expire(key, 60 * 60 * 0.5);
|
} catch (ex) {
|
this.info.msg = ex.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|