| // import * as sql from "mssql"; | 
| import { Post } from "egg-shell-decorators"; | 
| import BaseController from "../../baseController"; | 
| import { xStatStorageDay } from "../../../entity/stat/storage/xStatStorageDay"; | 
| import moment = require("moment"); | 
| import { StatStorageDay } from "../../../entity/stat/storage/statStorageDay"; | 
| import { StatStorageDayDetails } from "../../../entity/stat/storage/statStorageDayDetails"; | 
|   | 
| /** | 
|  * 库存统计 | 
|  */ | 
| export default class VpurchaseOrderController extends BaseController { | 
|   // #region 获取库存总数量信息 | 
|   /** | 
|         / 获取库存总数量信息 | 
|         */ | 
|   @Post() | 
|   public async getStorageDayStatistics() { | 
|     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 userProduct_Id = body.userProduct_Id; | 
|     let provider_Id = body.provider_Id; | 
|     let beginTime = body.beginTime; | 
|     let endTime = body.endTime; | 
|     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 (beginTime) { | 
|     //   where.storageDay = moment(beginTime).format("YYYY-MM-DD"); | 
|     // } | 
|     // if (endTime) { | 
|     //   where.storageDay = moment(endTime).format("YYYY-MM-DD"); | 
|     // } | 
|     try { | 
|       let quantityInfo; | 
|       // 库存总量查询 | 
|       quantityInfo = await this.dbRead | 
|         .createQueryBuilder(xStatStorageDay, "t") | 
|         .select("MAX(productName)", "productName") | 
|         .addSelect("sum(productStorage)", "sumproductStorage") | 
|         .addSelect("sum(validStorage)", "sumvalidStorage") | 
|         .where(where) | 
|         .andWhere("storageDay>=:beginTime and  storageDay<=:endTime", { | 
|           beginTime: beginTime, | 
|           endTime: endTime | 
|         }) | 
|         .getRawMany(); | 
|   | 
|       this.info.result = true; | 
|       this.info.msg = "获取成功"; | 
|       this.info.data = quantityInfo; | 
|     } catch (ex) { | 
|       this.info.result = false; | 
|       this.info.msg = "获取数据时出错:" + ex.message; | 
|     } | 
|     ctx.body = this.info; | 
|   } | 
|   // #endregion | 
|   | 
|   // #region 获取每日库存总数量信息 | 
|   /** | 
|         / 获取每日库存总数量信息 | 
|         */ | 
|   @Post() | 
|   public async getProductStatistics() { | 
|     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 userProduct_Id = body.userProduct_Id; | 
|     let provider_Id = body.provider_Id; | 
|     let beginTime = body.beginTime; | 
|     let type = body.type; | 
|     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 (beginTime) { | 
|       where.storageDay = moment(beginTime).format("YYYY-MM-DD"); | 
|     } | 
|     try { | 
|       let quantityInfo; | 
|       if (type === "每日库存主表") { | 
|         // 每日物料库存总量查询 | 
|         quantityInfo = await this.dbRead | 
|           .createQueryBuilder(StatStorageDay, "t") | 
|           .select("MAX(productName)", "productName") | 
|           .addSelect("sum(productStorage)", "sumproductStorage") | 
|           .addSelect("sum(validStorage)", "sumvalidStorage") | 
|           .where(where) | 
|           .getRawMany(); | 
|       } else { | 
|         // 每日物料明细库存总量查询 | 
|         quantityInfo = await this.dbRead | 
|           .createQueryBuilder(StatStorageDayDetails, "t") | 
|           .select("MAX(productName)", "productName") | 
|           .addSelect("sum(productStorage)", "sumproductStorage") | 
|           .addSelect("sum(validStorage)", "sumvalidStorage") | 
|           .where(where) | 
|           .getRawMany(); | 
|       } | 
|   | 
|       this.info.result = true; | 
|       this.info.msg = "获取成功"; | 
|       this.info.data = quantityInfo; | 
|     } catch (ex) { | 
|       this.info.result = false; | 
|       this.info.msg = "获取数据时出错:" + ex.message; | 
|     } | 
|     ctx.body = this.info; | 
|   } | 
|   // #endregion | 
| } |