using iWareCommon.Common.Service;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.Dao;
|
using iWareDataCore.BASE.Entity;
|
using iWareDataCore.ORM;
|
using iWareDataCore.Properties;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareDataCore.BASE.Service
|
{
|
public class PlaceMaterialViewService : CommonService<PlaceMaterialViewEntity, BASEPlaceMaterialView, DbModelCore>
|
{
|
|
private static object Lock = new object();
|
|
private PlaceMaterialViewService() : base(PlaceMaterialViewDao.GetInstance()) { }
|
|
private static PlaceMaterialViewService Instance = null;
|
|
/// <summary>
|
/// 获取单例的方法
|
/// </summary>
|
/// <returns>角色服务的单例实体</returns>
|
public static PlaceMaterialViewService GetInstance()
|
{
|
|
if (Instance == null)
|
{
|
lock (Lock)
|
{
|
if (Instance == null)
|
{
|
Instance = new PlaceMaterialViewService();
|
}
|
}
|
}
|
return Instance;
|
}
|
|
|
|
|
/// <summary>
|
/// 获取各种状态的库位
|
/// </summary>
|
/// <returns></returns>
|
public List<PlaceStatusNumEntity> GetPlaceStatusNum(out string msg)
|
{
|
msg = "";
|
List<PlaceStatusNumEntity> psnlst = new List<PlaceStatusNumEntity>();
|
try
|
{
|
using (DbModelCore mcore = new DbModelCore())
|
{
|
string sql = @"select A.EmptyPlace,B.FullPlace,C.LockPlace from
|
(select 1 as id,COUNT(id) as EmptyPlace from BASEPlace where typeid=4 and status=0 )A left join
|
(select 1 as id,COUNT(id) as FullPlace from BASEPlace where typeid=4 and status=2)B on A.id=B.id left join
|
(select 1 as id,COUNT(id) as LockPlace from BASEPlace where typeid=4 and islock=1)C on A.id=C.id";
|
psnlst = mcore.Database.SqlQuery<PlaceStatusNumEntity>(sql).ToList();
|
}
|
return psnlst;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.ToString();
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetPlaceStatusNum", ex.Message);
|
return psnlst;
|
}
|
}
|
|
/// <summary>
|
/// 给调度界面的库位预览及库位信息显示提供的查询结果(也包含placetypeid=17的,17的是无用库位,再次查询出来主要方便前端构图使用,对实际业务并没有意义)
|
/// </summary>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public List<PlaceMaterialViewEntity> GetPlacePreview(out string msg)
|
{
|
msg = "";
|
List<PlaceMaterialViewEntity> psnlst = new List<PlaceMaterialViewEntity>();
|
try
|
{
|
using (DbModelCore mcore = new DbModelCore())
|
{
|
string sql = @"SELECT A.id, ISNULL(C.createtime,'1990-01-01') as createtime, ISNULL(C.updatetime,'1990-01-01') as updatetime, A.code AS placecode, A.status,
|
A.islock, A.isexecute, B.name as placetypename, B.remark as placetyperemark, D.name, D.code AS materialcode, D.description, D.typeremark, D.typename,
|
ISNULL(D.status,0) AS materialstatus, A.id as placeid, ISNULL(C.materialid,0) as materialid, D.remark, A.layer, A.col, A.row, A.typeid as placetypeid
|
FROM dbo.BASEPlace AS A LEFT OUTER JOIN
|
dbo.BASEPlaceType AS B ON A.typeid = B.id LEFT OUTER JOIN
|
dbo.BASEPlaceMaterial as C on A.id=C.placeid LEFT OUTER JOIN
|
dbo.BASEMaterialView AS D ON C.materialid= D.id where A.typeid=4 or A.typeid=17 order by layer desc,col asc ";
|
psnlst = mcore.Database.SqlQuery<PlaceMaterialViewEntity>(sql).ToList();
|
}
|
return psnlst;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.ToString();
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetPlacePreview", ex.Message);
|
return psnlst;
|
}
|
}
|
|
/// <summary>
|
/// 根据物料信息找取指定的库位物料信息
|
/// </summary>
|
/// <param name="materialcode"></param>
|
/// <returns></returns>
|
public string GetPlaceMaterialViews(string materialcode)
|
{
|
try
|
{
|
using (DbModelCore mcore = new DbModelCore())
|
{
|
|
return mcore.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == materialcode).placecode;
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetPlaceMaterialViews", ex.Message);
|
return "";
|
}
|
}
|
|
}
|
}
|