获取企业每个堆场的在库数量

This commit is contained in:
陈向学 2024-06-27 16:55:42 +08:00
parent d73f83e340
commit 1c52322414
5 changed files with 251 additions and 76 deletions

View File

@ -19,6 +19,8 @@ using System.Data;
using System.Collections.Generic; using System.Collections.Generic;
using Maticsoft.Common; using Maticsoft.Common;
using Competition.Mysql.Model; using Competition.Mysql.Model;
using Competition.Mysql.Other;
using System.Reflection.Metadata;
namespace Competition.Mysql.BLL namespace Competition.Mysql.BLL
{ {
/// <summary> /// <summary>
@ -148,6 +150,25 @@ namespace Competition.Mysql.BLL
return modelList; return modelList;
} }
public List<Competition.Mysql.Other.YardStorageCheck> DataTableToList_YardStorageCheck(DataTable dt)
{
List<Competition.Mysql.Other.YardStorageCheck> modelList = new List<Competition.Mysql.Other.YardStorageCheck>();
int rowsCount = dt.Rows.Count;
if (rowsCount > 0)
{
Competition.Mysql.Other.YardStorageCheck model;
for (int n = 0; n < rowsCount; n++)
{
model = dal.DataRowToModel_YardStorageCheck(dt.Rows[n]);
if (model != null)
{
modelList.Add(model);
}
}
}
return modelList;
}
/// <summary> /// <summary>
/// 获得数据列表 /// 获得数据列表
/// </summary> /// </summary>
@ -190,6 +211,17 @@ namespace Competition.Mysql.BLL
DataSet ds = dal.GetYardStorage(siloCode); DataSet ds = dal.GetYardStorage(siloCode);
return DataTableToList(ds.Tables[0]); return DataTableToList(ds.Tables[0]);
} }
/// <summary>
/// 获取堆库存
/// </summary>
/// <param name="monotorid"></param>
/// <returns></returns>
public List<YardStorageCheck> GetYardLastStorage(string monotorid)
{
DataSet ds = dal.GetYardLastStorage(monotorid);
return DataTableToList_YardStorageCheck(ds.Tables[0]);
}
#endregion ExtensionMethod #endregion ExtensionMethod
} }
} }

View File

@ -583,6 +583,63 @@ namespace Competition.Mysql.DAL
return model; return model;
} }
public Competition.Mysql.Other.YardStorageCheck DataRowToModel_YardStorageCheck(DataRow row)
{
Competition.Mysql.Other.YardStorageCheck model = new Competition.Mysql.Other.YardStorageCheck();
if (row != null)
{
if (row["STORAGE_CODE"] != null && row["STORAGE_CODE"].ToString() != "")
{
model.STORAGE_CODE = new Guid(row["STORAGE_CODE"].ToString());
}
if (row["GOODS_CODE"] != null)
{
model.GOODS_CODE = row["GOODS_CODE"].ToString();
}
if (row["GOODS_TYPE"] != null && row["GOODS_TYPE"].ToString() != "")
{
model.GOODS_TYPE = int.Parse(row["GOODS_TYPE"].ToString());
}
if (row["STANDARD_NAME"] != null)
{
model.STANDARD_NAME = row["STANDARD_NAME"].ToString();
}
if (row["MONITOR_ID"] != null)
{
model.MONITOR_ID = row["MONITOR_ID"].ToString();
}
if (row["MONITOR_NAME"] != null)
{
model.MONITOR_NAME = row["MONITOR_NAME"].ToString();
}
if (row["CUSTOMS_CODE"] != null)
{
model.CUSTOMS_CODE = row["CUSTOMS_CODE"].ToString();
}
if (row["STOCK_BALANCE"] != null && row["STOCK_BALANCE"].ToString() != "")
{
model.STOCK_BALANCE = decimal.Parse(row["STOCK_BALANCE"].ToString());
}
if (row["INSTRG_DATE"] != null && row["INSTRG_DATE"].ToString() != "")
{
model.INSTRG_DATE = DateTime.Parse(row["INSTRG_DATE"].ToString());
}
if (row["STORAGE_SILO_CODE"] !=null && row["STORAGE_SILO_CODE"].ToString() != "")
{
model.STORAGE_SILO_CODE = new Guid(row["STORAGE_SILO_CODE"].ToString());
}
if (row["SILO_CODE"]!=null && row["SILO_CODE"].ToString()!="")
{
model.SILO_CODE = row["SILO_CODE"].ToString();
}
if (row["SILO_NAME"]!=null && row["SILO_NAME"].ToString()!="")
{
model.SILO_NAME = row["SILO_NAME"].ToString();
}
}
return model;
}
/// <summary> /// <summary>
/// 获得数据列表 /// 获得数据列表
/// </summary> /// </summary>
@ -718,6 +775,22 @@ namespace Competition.Mysql.DAL
StringBuilder strSql = new StringBuilder(); StringBuilder strSql = new StringBuilder();
strSql.Append(sql); strSql.Append(sql);
return DbHelperSQL.Query(strSql.ToString());
}
public DataSet GetYardLastStorage(string monitorid)
{
string sql = string.Format(
"select T1.STORAGE_CODE,T1.GOODS_CODE,T1.GOODS_TYPE,T1.STANDARD_NAME,T1.MONITOR_ID,T1.MONITOR_NAME,T1.CUSTOMS_CODE,T1.STOCK_BALANCE,T1.INSTRG_DATE,T2.STORAGE_SILO_CODE,T2.SILO_CODE,T2.SILO_NAME FROM "+
"(select * FROM T_STK_STORAGE where STOCK_BALANCE > 0 AND MONITOR_ID = '{0}') T1 "+
"INNER JOIN "+
"T_STK_STORAGE_SILO T2 "+
"ON T1.STORAGE_CODE = T2.STORAGE_CODE"
, monitorid);
StringBuilder strSql = new StringBuilder();
strSql.Append(sql);
return DbHelperSQL.Query(strSql.ToString()); return DbHelperSQL.Query(strSql.ToString());
} }
#endregion ExtensionMethod #endregion ExtensionMethod

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Competition.Mysql.Other
{
public class YardStorageCheck
{
public Guid STORAGE_CODE;
public string GOODS_CODE;
public int GOODS_TYPE;
public string STANDARD_NAME;
public string MONITOR_ID;
public string MONITOR_NAME;
public string CUSTOMS_CODE;
public decimal STOCK_BALANCE;
public DateTime INSTRG_DATE;
public Guid STORAGE_SILO_CODE;
public string SILO_CODE;
public string SILO_NAME;
}
}

View File

@ -1,5 +1,6 @@
using Competition.Common.Util; using Competition.Common.Util;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NPOI.POIFS.Crypt.Dsig;
namespace CompetitionAPI.Controllers.api namespace CompetitionAPI.Controllers.api
{ {
@ -36,40 +37,43 @@ namespace CompetitionAPI.Controllers.api
var mysql = Configuration.GetConnectionString("MySQL").ToString(); var mysql = Configuration.GetConnectionString("MySQL").ToString();
//福州海关下的,本年度,按货种分类 //福州海关下的,本年度,按货种分类
var list_good = bll_good.GetModelList(""); var list_good = bll_good.GetModelList("");
var list = bll_storage.GetModelList("YEAR(INSTRG_DATE) = YEAR(GETDATE())").FindAll(a=> Tool.IsFuZhouCustom(a.CUSTOMS_CODE)); //var list = bll_storage.GetModelList("YEAR(INSTRG_DATE) = YEAR(GETDATE())").FindAll(a=> Tool.IsFuZhouCustom(a.CUSTOMS_CODE));
var list = bll_storage.GetModelList(string.Format("YEAR(INSTRG_DATE) = {0}",year)).FindAll(a => Tool.IsFuZhouCustom(a.CUSTOMS_CODE));
//总进出口重量 //总进出口重量
decimal allWT = 0; decimal allWT = 0;
if(list.Count > 0)
{
//商品编号,重量 //商品编号,重量
Dictionary<string,decimal> dic = new Dictionary<string,decimal>(); Dictionary<string, decimal> dic = new Dictionary<string, decimal>();
//所有商品按种类累计重量 //所有商品按种类累计重量
list.ForEach(a => list.ForEach(a =>
{ {
allWT += a.BILL_GROSS_WT.Value; allWT += a.BILL_GROSS_WT.Value;
if(!dic.ContainsKey(a.GOODS_CODE)) if (!dic.ContainsKey(a.GOODS_CODE))
{ {
dic.Add(a.GOODS_CODE,a.BILL_GROSS_WT.Value); dic.Add(a.GOODS_CODE, a.BILL_GROSS_WT.Value);
} }
else else
{ {
dic[a.GOODS_CODE] += a.BILL_GROSS_WT.Value; dic[a.GOODS_CODE] += a.BILL_GROSS_WT.Value;
} }
}); });
var tmp=dic.OrderByDescending(a => a.Value).ToList(); var tmp = dic.OrderByDescending(a => a.Value).ToList();
//取前三个商品+其他 //取前三个商品+其他
Dictionary<string,decimal> dic2 = new Dictionary<string,decimal>(); Dictionary<string, decimal> dic2 = new Dictionary<string, decimal>();
if(tmp.Count==1) if (tmp.Count == 1)
{ {
//1种货物 //1种货物
dic2.Add(tmp[0].Key, tmp[0].Value); dic2.Add(tmp[0].Key, tmp[0].Value);
} }
else if(tmp.Count == 2) else if (tmp.Count == 2)
{ {
//2种货物 //2种货物
dic2.Add(tmp[0].Key, tmp[0].Value); dic2.Add(tmp[0].Key, tmp[0].Value);
dic2.Add(tmp[1].Key, tmp[1].Value); dic2.Add(tmp[1].Key, tmp[1].Value);
} }
else if(tmp.Count==3) else if (tmp.Count == 3)
{ {
//3种货物 //3种货物
dic2.Add(tmp[0].Key, tmp[0].Value); dic2.Add(tmp[0].Key, tmp[0].Value);
@ -102,7 +106,7 @@ namespace CompetitionAPI.Controllers.api
if (index <= 3) if (index <= 3)
{ {
//商品名称,重量,单位,占比 //商品名称,重量,单位,占比
lastTmp = new { goodCode=a ,goodName = list_good.Find(b => b.GOODS_CODE == a).STANDARD_NAME, wt = dic2[a], danWei = "kg", percent = dic2[a] / allWT }; lastTmp = new { goodCode = a, goodName = list_good.Find(b => b.GOODS_CODE == a).STANDARD_NAME, wt = dic2[a], danWei = "kg", percent = dic2[a] / allWT };
} }
else else
{ {
@ -114,10 +118,19 @@ namespace CompetitionAPI.Controllers.api
}); });
//响应数据 //响应数据
var data = new { allNum= list_good.Count, showData = showData }; var data = new { allNum = list_good.Count, showData = showData };
return Json(Tool.GetJsonWithCode(APICode.Success, data)); return Json(Tool.GetJsonWithCode(APICode.Success, data));
} }
else
{
//响应数据
var data = new { allNum = list_good.Count, showData = new List<object>() };
return Json(Tool.GetJsonWithCode(APICode.Success, data));
}
}
/// <summary> /// <summary>
/// 在库总量 /// 在库总量

View File

@ -102,6 +102,39 @@ namespace CompetitionAPI.Controllers.api
return Json(Tool.GetJsonWithCode(APICode.Success, list)); return Json(Tool.GetJsonWithCode(APICode.Success, list));
} }
/// <summary>
/// 获取企业每个堆场的在库数量
/// </summary>
/// <param name="monitorId"></param>
/// <returns></returns>
[HttpGet]
public JsonResult GetYardLastStorage(string monitorId)
{
var mysql = Configuration.GetConnectionString("MySQL").ToString();
var list = bll_storage.GetYardLastStorage(monitorId);
//堆场id重量
Dictionary<string,decimal> dic=new Dictionary<string, decimal>();
//当库存放到多个堆场,看作平均分配货物
list.GroupBy(a => a.STORAGE_CODE).ToList().ForEach(a =>
{
//平均每份货物重量
decimal one = a.First().STOCK_BALANCE / a.Count();
foreach (YardStorageCheck item in a)
{
if(!dic.ContainsKey(item.SILO_CODE))
{
dic.Add(item.SILO_CODE, 0);
}
//累计
dic[item.SILO_CODE] += one;
}
});
return Json(Tool.GetJsonWithCode(APICode.Success, dic));
}
/// <summary> /// <summary>
/// 堆场模糊查询 /// 堆场模糊查询
/// </summary> /// </summary>