using iWareCommon.Common.EnumType;
|
using iWareCommon.Common.Service;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.Dao;
|
using iWareDataCore.BASE.Entity;
|
using iWareDataCore.BASE.EnumType;
|
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 PlaceService : CommonService<PlaceEntity, BASEPlace, DbModelCore>
|
{
|
private static object Lock = new object();
|
private PlaceService() : base(PlaceDao.GetInstance()) { }
|
|
private static PlaceService Instance = null;
|
|
/// <summary>
|
/// 获取单例的方法
|
/// </summary>
|
/// <returns>角色服务的单例实体</returns>
|
public static PlaceService GetInstance()
|
{
|
|
if (Instance == null)
|
{
|
lock (Lock)
|
{
|
if (Instance == null)
|
{
|
Instance = new PlaceService();
|
}
|
}
|
}
|
return Instance;
|
}
|
|
/// <summary>
|
/// 获取指定字符串开头的库位列表
|
/// </summary>
|
/// <param name="term">指定字符串</param>
|
/// <param name="size">返回的最大条数</param>
|
/// <param name="msg">异常错误消息</param>
|
/// <returns>订单号列表</returns>
|
public List<string> GetCodes(string term, int size, out string msg)
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
msg = "";
|
if (string.IsNullOrEmpty(term)) { return new List<string>(); }
|
var places = dbModel.BASEPlaces.Select(x => new { x.id, x.code }).OrderBy(x => x.code).Where(x => x.code.StartsWith(term)).Skip(0).Take(size).ToList();
|
return places.Select(x => x.code).Distinct().ToList();
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetCodes", ex.Message);
|
return new List<string>();
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取空库位和出入库口
|
/// </summary>
|
/// <returns></returns>
|
public List<PlaceViewEntity> GetEmptyAndInOutGate()
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
List<PlaceViewEntity> placelst = new List<PlaceViewEntity>();
|
var places = dbModel.BASEPlaceViews.Where(x => x.placetypename == "gate11" || x.placetypename == "gate22" || x.placetypename == EPlaceType.普通库位.ToString() && x.status == 0 && x.placetypename != EPlaceType.不合格缓存位.ToString()).ToList();
|
places.ForEach(x =>{
|
placelst.Add(new PlaceViewEntity(x));
|
});
|
return placelst;
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetEmptyAndInOutGate", ex.Message);
|
return new List<PlaceViewEntity>();
|
}
|
}
|
}
|
|
/// <summary>
|
/// 库位状态重置
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public int PlaceReset(List<int> ids, out string msg)
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
|
placelst.ForEach(x =>
|
{
|
x.status=(int)EPlaceStatus.空库位;
|
x.islock = (int)EYesOrNo.否;
|
x.isexecute = (int)EYesOrNo.否;
|
});
|
return dbModel.SaveChanges();
|
}
|
catch (Exception ex)
|
{
|
msg = "更新失败";
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message);
|
return 0;
|
}
|
}
|
}
|
/// <summary>
|
/// 库位解锁
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public int PlaceUnLock(List<int> ids, out string msg)
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
|
placelst.ForEach(x =>
|
{
|
x.islock = (int)EYesOrNo.否;
|
x.isexecute = (int)EYesOrNo.否;
|
});
|
return dbModel.SaveChanges();
|
}
|
catch (Exception ex)
|
{
|
msg = "更新失败";
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message);
|
return 0;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 库位锁定
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public int PlaceLock(List<int> ids, out string msg)
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
|
placelst.ForEach(x =>
|
{
|
x.islock = (int)EYesOrNo.是;
|
});
|
return dbModel.SaveChanges();
|
}
|
catch (Exception ex)
|
{
|
msg = "更新失败";
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "库位锁定", ex.Message);
|
return 0;
|
}
|
}
|
}
|
}
|
}
|