|
|
using System.Collections;
|
|
|
using Estsh.Core.Util;
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.IRepositories;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
using Dapper;
|
|
|
using System.Text;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:库位管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
|
|
|
public class LocateDefineService : BaseService<SysLocate>, ILocateDefineService
|
|
|
{
|
|
|
private readonly ILocateDefineRepository repository;
|
|
|
public LocateDefineService(ILocateDefineRepository _repository) : base(_repository)
|
|
|
{
|
|
|
repository = _repository;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据分页条件获取分页菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="menuName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getLocateListByPage(string locateName, string locateDesc, string locateType, string zoneName, string enabled, int factoryId, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (locateName != null && !locateName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.locate_name like '%" + locateName.Trim() + "%'";
|
|
|
}
|
|
|
if (locateDesc != null && !locateDesc.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.locate_desc like '%" + locateDesc.Trim() + "%'";
|
|
|
}
|
|
|
if (locateType != null && !locateType.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.locate_type like '%" + locateType.Trim() + "%'";
|
|
|
}
|
|
|
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.enabled like '%" + enabled.Trim() + "%'";
|
|
|
}
|
|
|
|
|
|
if (zoneName != null && !zoneName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.zone_name like '%" + zoneName.Trim() + "%'";
|
|
|
}
|
|
|
|
|
|
strWhere += " and a.factory_id = " + factoryId + " ";
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += "a."+typeof(SysLocate).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += "a." + typeof(SysLocate).GetEntityColumnName("LocateID") + " " + direction;
|
|
|
}
|
|
|
|
|
|
return repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框中的菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectWarehouse(string factoryId)
|
|
|
{
|
|
|
return repository.getSelectWarehouse(factoryId);
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> getSelectZone(int warehouseId)
|
|
|
{
|
|
|
return repository.getSelectZone(warehouseId);
|
|
|
}
|
|
|
|
|
|
public List<SysWarehouse> getSelectWarehouseInfo(string warehouseId)
|
|
|
{
|
|
|
return repository.getSelectWarehouseInfo(warehouseId);
|
|
|
}
|
|
|
public SysWarehouse getSelectWarehouseInfoByName(string warehouseName)
|
|
|
{
|
|
|
return repository.getSelectWarehouseInfoByName(warehouseName);
|
|
|
}
|
|
|
|
|
|
public SysLocate getlocateByExistName(string locateName)
|
|
|
{
|
|
|
return repository.getlocateByExistName(locateName);
|
|
|
}
|
|
|
public List<SysZone> getSelectZoneInfo(string zone_id)
|
|
|
{
|
|
|
return repository.getSelectZoneInfo(zone_id);
|
|
|
}
|
|
|
public SysZone getSelectZoneInfoByName(string zone_name)
|
|
|
{
|
|
|
return repository.getSelectZoneInfoByName(zone_name);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveLocate(SysLocate htParams, bool flag, SysLocatePart ht)
|
|
|
{
|
|
|
return repository.saveLocate(htParams, flag, ht);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateLocate(SysLocate htParams, bool flag, SysLocatePart ht)
|
|
|
{
|
|
|
return repository.updateLocate(htParams, flag, ht);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getLocateDetail(String locate_id)
|
|
|
{
|
|
|
locate_id = " a.locate_id = " + locate_id;
|
|
|
List<SysLocate> dt = repository.getList(locate_id, "");
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("locateId", dt[0].LocateId);
|
|
|
result.Add("locateName", dt[0].LocateName);
|
|
|
result.Add("locateDesc", dt[0].LocateDesc);
|
|
|
|
|
|
result.Add("warehouseId", dt[0].WarehouseId);
|
|
|
result.Add("warehouseName", dt[0].WarehouseName);
|
|
|
result.Add("enabled", dt[0].Enabled);
|
|
|
result.Add("warehouseDesc", dt[0].WarehouseDesc);
|
|
|
|
|
|
result.Add("zoneId", dt[0].ZoneId);
|
|
|
result.Add("locateCapacity", dt[0].LocateCapacity);
|
|
|
|
|
|
result.Add("locateType", dt[0].LocateType);
|
|
|
|
|
|
result.Add("partNo", dt[0].PartNo);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteLocate(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteLocate(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> GetLocateType()
|
|
|
{
|
|
|
return repository.GetLocateType();
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> GetpartInfo()
|
|
|
{
|
|
|
return repository.GetpartInfo();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获得零件信息
|
|
|
/// </summary>
|
|
|
/// <param name="type">零件类型</param>
|
|
|
/// <returns></returns>
|
|
|
public List<SysPart> GetPartInfo(string part_no)
|
|
|
{
|
|
|
return repository.GetPartInfo(part_no);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableLocate(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.EnableLocate(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableLocate(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.DisableLocate(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
public List<LocateDefine> getExportList(string locateName, string locateDesc, string locateType, string enabled, int factoryId)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (locateName != null && !locateName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.locate_name like '%" + locateName.Trim() + "%' ";
|
|
|
}
|
|
|
if (locateDesc != null && !locateDesc.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.locate_desc like '%" + locateDesc.Trim() + "%' ";
|
|
|
}
|
|
|
if (locateType != null && !locateType.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.locate_type = '" + locateType.Trim() + "' ";
|
|
|
}
|
|
|
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.enabled = '" + enabled.Trim() + "' ";
|
|
|
}
|
|
|
strWhere += " and a.factory_id = " + factoryId + " ";
|
|
|
String orderBy = " order by a.locate_name ";
|
|
|
|
|
|
return repository.getExportList(strWhere, orderBy);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导入
|
|
|
/// </summary>
|
|
|
public Hashtable ImportExcel(List<LocateDefine> inputStream, int factoryId, string factoryCode, int empId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
List<string> SqlStrings = new List<string>();
|
|
|
List<DynamicParameters> Parameters = new List<DynamicParameters>();
|
|
|
|
|
|
DynamicParameters Params = new DynamicParameters();
|
|
|
|
|
|
//判断EXCEL是否存在数据
|
|
|
if (inputStream == null || inputStream.Count == 0)
|
|
|
{
|
|
|
result.Add("message", "导入数据为空,请重新导入!");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//判断零件号是否存在
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
{
|
|
|
string locateName = inputStream[i].LocateName.ToString();
|
|
|
SysLocate sysExemptions = repository.ifExistsLocate(locateName);
|
|
|
if (sysExemptions == null)
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_locate ");
|
|
|
SqlStringBuilder.Append(" (locate_name,locate_desc ");
|
|
|
SqlStringBuilder.Append(" ,locate_type,locate_capacity ");
|
|
|
SqlStringBuilder.Append(" ,max_locate_qty,warehouse_id ");
|
|
|
SqlStringBuilder.Append(" ,warehouse_name,zone_id,zone_name");
|
|
|
SqlStringBuilder.Append(" ,enabled,factory_id ");
|
|
|
SqlStringBuilder.Append(" ,factory_code,create_userid,create_time,guid ) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@locateName,@locateDesc ");
|
|
|
SqlStringBuilder.Append(" ,@locateType,@locateCapacity ");
|
|
|
SqlStringBuilder.Append(" ,@maxLocateQty,@warehouseId ");
|
|
|
SqlStringBuilder.Append(" ,@warehouseName,@zoneId,@zoneName ");
|
|
|
SqlStringBuilder.Append(" ,@enabled, @factoryId");
|
|
|
SqlStringBuilder.Append(" ,@factoryCode , @createUserid,@createTime,@guid)");
|
|
|
|
|
|
|
|
|
Params = new DynamicParameters();
|
|
|
Params.Add("@locateName", locateName);
|
|
|
Params.Add("@locateDesc", inputStream[i].LocateDesc);
|
|
|
Params.Add("@locateDesc", inputStream[i].LocateDesc);
|
|
|
|
|
|
if (inputStream[i].LocateType=="基础库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 10);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "机动库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 20);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "动态组合库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 30);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "线边库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 40);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "线边库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 40);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "收货库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 50);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "NC库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 60);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "在途库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 70);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "退货库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 80);
|
|
|
}
|
|
|
else if (inputStream[i].LocateType == "委外库位")
|
|
|
{
|
|
|
Params.Add("@locateType", 90);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,库位类型不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
Params.Add("@locateCapacity", inputStream[i].LocateCapacity);
|
|
|
Params.Add("@maxLocateQty", inputStream[i].MaxLocateQty);
|
|
|
|
|
|
SysWarehouse sysWarehouse = repository.getSelectWarehouseInfoByName(inputStream[i].WarehouseName);
|
|
|
if (sysWarehouse!=null)
|
|
|
{
|
|
|
Params.Add("@warehouseId", sysWarehouse.WarehouseId);
|
|
|
Params.Add("@warehouseName", sysWarehouse.WarehouseName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,仓库代码不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
SysZone sysZone = repository.getSelectZoneInfoByName(inputStream[i].ZoneName);
|
|
|
if (sysZone != null)
|
|
|
{
|
|
|
Params.Add("@zoneId", sysZone.ZoneId);
|
|
|
Params.Add("@zoneName", sysZone.ZoneName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,库区代码不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
Params.Add("@enabled", "Y");
|
|
|
Params.Add("@factoryId", factoryId);
|
|
|
Params.Add("@factoryCode", factoryCode);
|
|
|
Params.Add("@createUserid", empId);
|
|
|
Params.Add("@createTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
Params.Add("@guid", Guid.NewGuid().ToString());
|
|
|
|
|
|
SqlStrings.Add(SqlStringBuilder.ToString());
|
|
|
Parameters.Add(Params);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (repository.InsertData(SqlStrings, Parameters))
|
|
|
{
|
|
|
result.Add("message", "导入成功");
|
|
|
result.Add("flag", "OK");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败");
|
|
|
result.Add("flag", "error");
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("message", "导入失败");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |