import { default as BaseController } from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
export default class PositionShowController extends BaseController {
|
//#region 货位总数量
|
/**
|
*货位总数量
|
*/
|
@Post()
|
public async getPostionNameSum() {
|
let { ctx } = this;
|
let body = ctx.body; // 接收前端发来的数据
|
let userInfo = await ctx.helper.userInfo(); // 权限
|
let userProduct_Id = userInfo.userProduct_Id; // 获取权限id
|
try {
|
// 总数量
|
let sql = `SELECT COUNT(positionName) AS positionCount FROM Base_Position WHERE Enable = 1 AND AreaCode =${body.areaCode} AND UserProduct_Id= ${userProduct_Id} AND Storage_Id=${body.storage_Id}`;
|
let positionCount = await this.dbRead.query(sql);
|
positionCount = positionCount[0].positionCount;
|
|
// 有库存
|
sql = `SELECT COUNT(positionName) AS hasStorageCount FROM Base_Position p WHERE Enable = 1
|
AND AreaCode =${body.areaCode} AND UserProduct_Id= ${userProduct_Id} AND Storage_Id=${body.storage_Id}
|
AND EXISTS(SELECT 1 FROM dbo.Base_ProductPosition pp WHERE pp.Storage_Id=p.Storage_Id AND pp.PositionName=p.PositionName AND pp.ProductStorage>0)
|
`;
|
let hasStorageCount = await this.dbRead.query(sql);
|
hasStorageCount = hasStorageCount[0].hasStorageCount;
|
|
// 物料总数量
|
sql = `SELECT isnull(SUM(pp.ProductStorage),0) AS productStorage FROM dbo.vBase_ProductPosition pp WHERE pp.Storage_Id=${body.storage_Id} AND pp.ProductStorage>0
|
AND pp.AreaCode=${body.areaCode}
|
`;
|
let productStorage = await this.dbRead.query(sql);
|
productStorage = productStorage[0].productStorage;
|
|
this.info.data = {
|
positionCount: positionCount,
|
hasStorageCount: hasStorageCount,
|
noStorageCount: positionCount - hasStorageCount,
|
productStorage: productStorage
|
};
|
this.info.result = true;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|