// import * as sql from "mssql";
|
import { Post } from "egg-shell-decorators";
|
import BaseController from "../../baseController";
|
import { StsNodeWarn } from "../../../entity/stat/warn/stsNodeWarn";
|
// import { Like, Between } from "typeorm";
|
import { Between } from "typeorm";
|
import { vShelfLifeEarlyWarning } from "../../../entity/storage/stat/vShelfLifeEarlyWarning";
|
import { vOldLibraryEarlyWarning } from "../../../entity/storage/stat/vOldLibraryEarlyWarning";
|
import { vBaseProductPositionLower } from "../../../entity/storage/stat/vBaseProductPositionLower";
|
import { BaseProductPositionHistory } from "../../../entity/storage/log/baseProductPositionHistory";
|
|
/**
|
* 库存统计
|
*/
|
export default class VpurchaseOrderController extends BaseController {
|
// #region 节点延误报警
|
@Post()
|
public async getStsNodeWarn() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userProduct_Id = body.userProduct_Id;
|
|
let where: any = {};
|
where.userProduct_Id = userProduct_Id;
|
try {
|
let warnList = await this.dbRead.find(StsNodeWarn, where);
|
this.info.result = true;
|
this.info.msg = "获取节点延误报警成功";
|
this.info.data = warnList;
|
ctx.body = this.info;
|
return;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = error.message;
|
ctx.body = this.info;
|
return;
|
}
|
}
|
|
// #endregion
|
|
// #region 保质期报警
|
/**
|
/ 保质期报警
|
*/
|
@Post()
|
public async getvShelfLifeEarly() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
// let userInfo = await ctx.helper.userInfo();
|
let storage_Id = body.storage_Id;
|
let consignor_Id = body.consignor_Id;
|
let beginDate = body.beginDate;
|
let endDate = body.endDate;
|
let userProduct_Id = body.userProduct_Id;
|
let provider_Id = body.provider_Id;
|
// let likeCode = body.likeCode;
|
let where: any = {};
|
where.userProduct_Id = userProduct_Id;
|
if (storage_Id) {
|
where.storage_Id = storage_Id;
|
}
|
if (provider_Id) {
|
where.provider_Id = provider_Id;
|
}
|
if (consignor_Id) {
|
where.consignor_Id = consignor_Id;
|
}
|
// if (likeCode) {
|
// [
|
// (where.productCode = Like("%" + likeCode + "%")),
|
// (where.productName = Like("%" + likeCode + "%")),
|
// (where.areaCode = Like("%" + likeCode + "%")),
|
// (where.positionName = Like("%" + likeCode + "%")),
|
// (where.productModel = Like("%" + likeCode + "%"))
|
// ];
|
// }
|
if (beginDate && endDate) {
|
endDate = endDate + " 23:59:59";
|
where.inStorageDate = Between(beginDate, endDate);
|
}
|
try {
|
let qantity;
|
let enterQuantity;
|
let inQuantity;
|
let shelvedQuantity;
|
//已超过库存有效期
|
qantity = await this.dbRead
|
.createQueryBuilder(vShelfLifeEarlyWarning, "t")
|
.select("count(distinct product_Id)", "sum")
|
.where(where)
|
.andWhere("validityDay<0")
|
.getRawOne();
|
|
// 库存有效期剩余1/3
|
enterQuantity = await this.dbRead
|
.createQueryBuilder(vShelfLifeEarlyWarning, "t")
|
.select("count(distinct product_Id)", "sum")
|
.where(where)
|
.andWhere("ValidityDay<ShelfLifeDay*0.3333333")
|
.getRawOne();
|
|
//库存有效期剩余2/3
|
inQuantity = await this.dbRead
|
.createQueryBuilder(vShelfLifeEarlyWarning, "t")
|
.select("count(distinct product_Id)", "sum")
|
.where(where)
|
.andWhere("ValidityDay<ShelfLifeDay*0.6666666 AND ValidityDay>ShelfLifeDay*0.3333333")
|
.getRawOne();
|
|
// 库存有效期剩余2/3以上
|
shelvedQuantity = await this.dbRead
|
.createQueryBuilder(vShelfLifeEarlyWarning, "t")
|
.select("count(distinct product_Id)", "sum")
|
.where(where)
|
.andWhere("(ValidityDay>ShelfLifeDay*0.6666666 OR ShelfLifeDay IS NULL)")
|
.getRawOne();
|
|
this.info.result = true;
|
this.info.msg = "获取成功";
|
qantity = qantity.sum; // 已超过库存有效期
|
enterQuantity = enterQuantity.sum;
|
inQuantity = inQuantity.sum;
|
shelvedQuantity = shelvedQuantity.sum;
|
this.info.data = {
|
quantityCount: qantity,
|
enterQuantityCount: enterQuantity,
|
inQuantityCount: inQuantity,
|
shelvedQuantityCount: shelvedQuantity
|
};
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据时出错:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
// #endregion
|
|
// #region 库龄预警
|
@Post()
|
public async getvOldLibraryEarlyWarning() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let storage_Id = body.storage_Id;
|
let consignor_Id = body.consignor_Id;
|
let userProduct_Id = body.userProduct_Id;
|
let where: any = {};
|
where.userProduct_Id = userProduct_Id;
|
if (storage_Id) {
|
where.storage_Id = storage_Id;
|
}
|
if (consignor_Id) {
|
where.consignor_Id = consignor_Id;
|
}
|
try {
|
let productList;
|
|
productList = await this.dbRead.createQueryBuilder(vOldLibraryEarlyWarning, "t").select(["productName", "inDay"]).where(where).getRawMany();
|
let datalist = productList.slice(0, 10);
|
let datainfo: any = {};
|
let category = [];
|
let seriesList: any = [];
|
for (let item of datalist) {
|
category.push(item.productName);
|
seriesList.push(item.inDay);
|
}
|
let series = [
|
{
|
name: "入库量",
|
type: "bar",
|
data: seriesList
|
}
|
];
|
datainfo = {
|
category: category,
|
series: series
|
};
|
|
this.info.result = true;
|
this.info.msg = "获取图标成功";
|
this.info.data = datainfo;
|
ctx.body = this.info;
|
return;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = error.message;
|
ctx.body = this.info;
|
return;
|
}
|
}
|
|
// #endregion
|
|
// #region 库存预警
|
/**
|
/ 库存预警
|
*/
|
@Post()
|
public async getProductPositionLower() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
// let userInfo = await ctx.helper.userInfo();
|
let storage_Id = body.storage_Id;
|
let consignor_Id = body.consignor_Id;
|
let beginDate = body.beginDate;
|
let endDate = body.endDate;
|
let userProduct_Id = body.userProduct_Id;
|
let provider_Id = body.provider_Id;
|
// let likeCode = body.likeCode;
|
let where: any = {};
|
where.userProduct_Id = userProduct_Id;
|
if (storage_Id) {
|
where.storage_Id = storage_Id;
|
}
|
if (provider_Id) {
|
where.provider_Id = provider_Id;
|
}
|
if (consignor_Id) {
|
where.consignor_Id = consignor_Id;
|
}
|
// if (likeCode) {
|
// [
|
// (where.productCode = Like("%" + likeCode + "%")),
|
// (where.productName = Like("%" + likeCode + "%")),
|
// (where.areaCode = Like("%" + likeCode + "%")),
|
// (where.positionName = Like("%" + likeCode + "%")),
|
// (where.productModel = Like("%" + likeCode + "%"))
|
// ];
|
// }
|
if (beginDate && endDate) {
|
endDate = endDate + " 23:59:59";
|
where.inStorageDate = Between(beginDate, endDate);
|
}
|
try {
|
let qantity;
|
let enterQuantity;
|
//预警货位数量
|
qantity = await this.dbRead
|
.createQueryBuilder(vBaseProductPositionLower, "t")
|
.select("COUNT(consignor_Id)", "sum")
|
.where(where)
|
.andWhere("productStorage<minCapacity")
|
.getRawOne();
|
|
// 低于数量
|
enterQuantity = await this.dbRead
|
.createQueryBuilder(vBaseProductPositionLower, "t")
|
.select("sum(diffStorage)", "sum")
|
.where(where)
|
// .andWhere("productStorage<minCapacity")
|
.getRawOne();
|
|
this.info.result = true;
|
this.info.msg = "获取成功";
|
qantity = qantity.sum;
|
enterQuantity = enterQuantity.sum;
|
this.info.data = {
|
quantityCount: qantity,
|
enterQuantityCount: enterQuantity
|
};
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据时出错:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
// #endregion
|
|
// #region 出入轨迹
|
/**
|
/ 出入轨迹
|
*/
|
@Post()
|
public async getProductPositionHistory() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
// let userInfo = await ctx.helper.userInfo();
|
let storage_Id = body.storage_Id;
|
let consignor_Id = body.consignor_Id;
|
let beginDate = body.beginDate;
|
let endDate = body.endDate;
|
let userProduct_Id = body.userProduct_Id;
|
let provider_Id = body.provider_Id;
|
// let likeCode = body.likeCode;
|
let where: any = {};
|
where.userProduct_Id = userProduct_Id;
|
if (storage_Id) {
|
where.storage_Id = storage_Id;
|
}
|
if (provider_Id) {
|
where.provider_Id = provider_Id;
|
}
|
if (consignor_Id) {
|
where.consignor_Id = consignor_Id;
|
}
|
// if (likeCode) {
|
// [
|
// (where.productCode = Like("%" + likeCode + "%")),
|
// (where.productName = Like("%" + likeCode + "%")),
|
// (where.areaCode = Like("%" + likeCode + "%")),
|
// (where.positionName = Like("%" + likeCode + "%")),
|
// (where.productModel = Like("%" + likeCode + "%"))
|
// ];
|
// }
|
if (beginDate && endDate) {
|
endDate = endDate + " 23:59:59";
|
where.createDate = Between(beginDate, endDate);
|
}
|
try {
|
let qantity;
|
let enterQuantity;
|
let inQuantity;
|
let shelvedQuantity;
|
//当前入库数量合计
|
qantity = await this.dbRead
|
.createQueryBuilder(BaseProductPositionHistory, "t")
|
.select("sum(inQuantity)", "sum")
|
.where(where)
|
// .andWhere("validityDay<0")
|
.getRawOne();
|
|
// 当前出库数量合计
|
enterQuantity = await this.dbRead
|
.createQueryBuilder(BaseProductPositionHistory, "t")
|
.select("sum(outQuantity)", "sum")
|
.where(where)
|
// .andWhere("ValidityDay<ShelfLifeDay*0.3333333")
|
.getRawOne();
|
|
//当前入库重量合计
|
inQuantity = await this.dbRead
|
.createQueryBuilder(BaseProductPositionHistory, "t")
|
.select("sum(inWeight)", "sum")
|
.where(where)
|
// .andWhere("ValidityDay<ShelfLifeDay*0.6666666 AND ValidityDay>ShelfLifeDay*0.3333333")
|
.getRawOne();
|
|
// 当前出库重量合计
|
shelvedQuantity = await this.dbRead
|
.createQueryBuilder(BaseProductPositionHistory, "t")
|
.select("sum(outWeight)", "sum")
|
.where(where)
|
// .andWhere("(ValidityDay>ShelfLifeDay*0.6666666 OR ShelfLifeDay IS NULL)")
|
.getRawOne();
|
|
this.info.result = true;
|
this.info.msg = "获取成功";
|
qantity = qantity.sum;
|
enterQuantity = enterQuantity.sum;
|
inQuantity = inQuantity.sum;
|
shelvedQuantity = shelvedQuantity.sum;
|
this.info.data = {
|
quantityCount: qantity,
|
enterQuantityCount: enterQuantity,
|
inQuantityCount: inQuantity,
|
shelvedQuantityCount: shelvedQuantity
|
};
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据时出错:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
// #endregion
|
}
|