|
|
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 Dapper;
|
|
|
using System.Text;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:库位零件管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
|
|
|
public class LocatePartDefineService : BaseService<SysLocatePart>, ILocatePartDefineService
|
|
|
{
|
|
|
private readonly ILocatePartDefineRepository repository;
|
|
|
public LocatePartDefineService(ILocatePartDefineRepository _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 partNo, string partSpec, string partSpec2, string enabled, int factoryId, Pager pager, String direction, string safetyPullOrder, string isSafetyPull, 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 b.locate_desc like '%" + locateDesc.Trim() + "%'";
|
|
|
}
|
|
|
if (safetyPullOrder != null && !safetyPullOrder.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.safety_pull_order like '%" + safetyPullOrder.Trim() + "%'";
|
|
|
}
|
|
|
if (isSafetyPull != null && !isSafetyPull.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.is_safety_pull like '%" + isSafetyPull.Trim() + "%'";
|
|
|
}
|
|
|
if (partNo != null && !partNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.part_no like '%" + partNo.Trim() + "%'";
|
|
|
}
|
|
|
if (partSpec != null && !partSpec.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and c.part_spec like '%" + partSpec.Trim() + "%'";
|
|
|
}
|
|
|
if (partSpec2 != null && !partSpec2.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and c.part_spec2 like '%" + partSpec2.Trim() + "%'";
|
|
|
}
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.enabled like '%" + enabled.Trim() + "%'";
|
|
|
}
|
|
|
|
|
|
strWhere += " and a.factory_id = " + factoryId + " ";
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += "a." + typeof(SysLocatePart).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += "a." + typeof(SysLocatePart).GetEntityColumnName("locateId") + " " + direction;
|
|
|
}
|
|
|
|
|
|
Hashtable dt = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取下拉框中的菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getSelectWarehouse(string factoryId)
|
|
|
{
|
|
|
return repository.getSelectWarehouse(factoryId);
|
|
|
}
|
|
|
|
|
|
public List<KeyValueResult> getSelectZone(string warehouseId)
|
|
|
{
|
|
|
return repository.getSelectZone(warehouseId);
|
|
|
}
|
|
|
|
|
|
public List<SysWarehouse> getSelectWarehouseInfo(string warehouseId)
|
|
|
{
|
|
|
return repository.getSelectWarehouseInfo(warehouseId);
|
|
|
}
|
|
|
|
|
|
public List<SysZone> getSelectZoneInfo(string zone_id)
|
|
|
{
|
|
|
return repository.getSelectZoneInfo(zone_id);
|
|
|
}
|
|
|
|
|
|
public List<SysLocate> getSelectLocateInfo(string locateName)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (locateName != null && !locateName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.locate_name like '%" + locateName.Trim() + "%'";
|
|
|
}
|
|
|
return repository.getSelectLocateInfo(strWhere);
|
|
|
}
|
|
|
|
|
|
public List<SysLocatePart> getSelectLocatePartInfo(string locateName, string partNo)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (locateName != null && !locateName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.locate_name like '%" + locateName.Trim() + "%'";
|
|
|
}
|
|
|
if (partNo != null && !partNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.part_no like '%" + partNo.Trim() + "%'";
|
|
|
}
|
|
|
return repository.getSelectLocatePartInfo(strWhere);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveLocatePart(SysLocatePart ht)
|
|
|
{
|
|
|
return repository.saveLocatePart(ht);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateLocatePart(SysLocatePart ht)
|
|
|
{
|
|
|
return repository.updateLocatePart(ht);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getLocateDetail(String guid)
|
|
|
{
|
|
|
string strWhere = " 1=1 ";
|
|
|
if (!string.IsNullOrEmpty(guid))
|
|
|
{
|
|
|
strWhere += " and a.guid='" + guid + "'";
|
|
|
}
|
|
|
List<SysLocatePart> dt = repository.getList(strWhere, "");
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("locateId", dt[0].LocateId);
|
|
|
result.Add("locateName", dt[0].LocateName);
|
|
|
result.Add("locateDesc", dt[0].LocateDesc);
|
|
|
|
|
|
result.Add("partId", dt[0].PartId);
|
|
|
result.Add("partNo", dt[0].PartNo);
|
|
|
result.Add("partSpec", dt[0].PartSpec);
|
|
|
result.Add("enabled", dt[0].Enabled);
|
|
|
|
|
|
result.Add("maxQty", dt[0].MaxQty);
|
|
|
result.Add("minQty", dt[0].MinQty);
|
|
|
result.Add("safetyQty", dt[0].SafetyQty);
|
|
|
result.Add("wipMinQty", dt[0].WipMinQty);
|
|
|
result.Add("guid", dt[0].Guid);
|
|
|
|
|
|
result.Add("factoryId", dt[0].FactoryId);
|
|
|
result.Add("factoryCode", dt[0].FactoryCode);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteLocatePart(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteLocatePart(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);
|
|
|
}
|
|
|
|
|
|
public List<SysLocate> GetLocateInfo(string locateName)
|
|
|
{
|
|
|
return repository.GetLocateInfo(locateName);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int EnableLocatePart(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.EnableLocatePart(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableLocatePart(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.DisableLocatePart(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
public SysPart GetPartInfoByPartNo(string partNo)
|
|
|
{
|
|
|
return repository.GetPartInfoByPartNo(partNo);
|
|
|
}
|
|
|
|
|
|
public List<LocatePart> getExportList(string locateName, string locateDesc, string partNo, string partSpec, string partSpec2, string enabled, int factoryId)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (locateName != null && !locateName.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and b.locate_name like '%" + locateName.Trim() + "%' ";
|
|
|
}
|
|
|
if (locateDesc != null && !locateDesc.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and b.locate_desc like '%" + locateDesc.Trim() + "%' ";
|
|
|
}
|
|
|
if (partNo != null && !partNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and a.part_no like '%" + partNo.Trim() + "%' ";
|
|
|
}
|
|
|
if (partSpec != null && !partSpec.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and c.part_spec like '%" + partSpec.Trim() + "%' ";
|
|
|
}
|
|
|
if (partSpec2 != null && !partSpec2.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and c.part_spec2 like '%" + partSpec2.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<LocatePart> 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;
|
|
|
}
|
|
|
|
|
|
string sql = @"delete FROM sys_locate_part ";
|
|
|
SqlStrings.Add(sql);
|
|
|
Params = new DynamicParameters();
|
|
|
Params.Add("@maxQty", "");
|
|
|
Parameters.Add(Params);
|
|
|
|
|
|
|
|
|
//判断零件号是否存在
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(inputStream[i].LocateName))
|
|
|
{
|
|
|
result.Add("message", "导入失败,库位代码不能为空,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
string locateName = inputStream[i].LocateName.ToString();
|
|
|
//SysLocate sysExemptions = repository.ifExistsLocatePart(locateName);
|
|
|
//if (sysExemptions == null || sysExemptions.LocateType == 40)
|
|
|
//{
|
|
|
//SysLocatePart sysLocatePart = repository.ifExistsLocatePartByPartNo(locateName, inputStream[i].PartNo);
|
|
|
//if (sysLocatePart == null)
|
|
|
//{
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_locate_part ");
|
|
|
SqlStringBuilder.Append(" (locate_id,locate_name ");
|
|
|
SqlStringBuilder.Append(" ,part_id,part_no ");
|
|
|
SqlStringBuilder.Append(" ,max_qty,min_qty ");
|
|
|
SqlStringBuilder.Append(" ,safety_qty,factory_id ");
|
|
|
SqlStringBuilder.Append(" ,factory_code,enabled ");
|
|
|
SqlStringBuilder.Append(" ,create_userid,create_time,guid) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@locateId,@locateName ");
|
|
|
SqlStringBuilder.Append(" ,@partId,@partNo,@maxQty,@minQty ");
|
|
|
SqlStringBuilder.Append(" ,@safetyQty,@factoryId ");
|
|
|
SqlStringBuilder.Append(" ,@factoryCode,@enabled, ");
|
|
|
SqlStringBuilder.Append(" @createUserid,@createTime,@guid) ");
|
|
|
|
|
|
Params = new DynamicParameters();
|
|
|
|
|
|
SysLocate sysLocate = repository.GetLocateInfoByName(locateName);
|
|
|
if (sysLocate != null)
|
|
|
{
|
|
|
Params.Add("@locateId", sysLocate.LocateId);
|
|
|
Params.Add("@locateName", sysLocate.LocateName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,库位代码不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
SysPart sysPart = repository.GetPartInfoByPartNo(inputStream[i].PartNo.ToString());
|
|
|
if (sysPart != null)
|
|
|
{
|
|
|
Params.Add("@partId", sysPart.PartId);
|
|
|
Params.Add("@partNo", sysPart.PartNo);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,零件号不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
Params.Add("@maxQty", inputStream[i].MaxQty);
|
|
|
Params.Add("@minQty", inputStream[i].MinQty);
|
|
|
Params.Add("@safetyQty", inputStream[i].SafetyQty);
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |