|
|
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 System.Text;
|
|
|
using Dapper;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:委外BOM
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Services
|
|
|
{
|
|
|
|
|
|
public class OutsourceBomService : BaseService<WmsOutsourceBom>, IOutsourceBomService
|
|
|
{
|
|
|
private readonly IOutsourceBomRepository repository;
|
|
|
public OutsourceBomService(IOutsourceBomRepository _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 getBomListByPage(string partNo, string itemPartNo, string enabled, int factoryId, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (partNo != null && !partNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.part_no like '%" + partNo.Trim() + "%'";
|
|
|
}
|
|
|
if (itemPartNo != null && !itemPartNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.item_part_no like '%" + itemPartNo.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(WmsOutsourceBom).GetEntityColumnName(sort.Trim()) + " " + direction;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += "a." + typeof(WmsOutsourceBom).GetEntityColumnName("partNo") + " " + direction;
|
|
|
}
|
|
|
|
|
|
Hashtable dt = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int saveOutsourceBom(WmsOutsourceBom ht)
|
|
|
{
|
|
|
return repository.saveOutsourceBom(ht);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新菜单数据
|
|
|
/// </summary>
|
|
|
/// <param name="htParams"></param>
|
|
|
/// <returns></returns>
|
|
|
public int updateOutsourceBom(WmsOutsourceBom ht)
|
|
|
{
|
|
|
return repository.updateOutsourceBom(ht);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getOutsourceBomDetail(String ruid)
|
|
|
{
|
|
|
string strWhere = " 1=1 ";
|
|
|
if (!string.IsNullOrEmpty(ruid))
|
|
|
{
|
|
|
strWhere += " and ruid='" + ruid + "'";
|
|
|
}
|
|
|
List<WmsOutsourceBom> dt = repository.getList(strWhere);
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("partNo", dt[0].PartNo);
|
|
|
result.Add("itemPartNo", dt[0].ItemPartNo);
|
|
|
result.Add("enabled", dt[0].Enabled);
|
|
|
result.Add("ruid", dt[0].Ruid);
|
|
|
result.Add("factoryId", dt[0].FactoryId);
|
|
|
result.Add("factoryCode", dt[0].FactoryCode);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteOutsourceBom(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteOutsourceBom(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
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 EnableOutsourceBom(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.EnableOutsourceBom(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int DisableOutsourceBom(String ids)
|
|
|
{
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.DisableOutsourceBom(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
public List<WmsOutsourceBom> getExportList(string partNo, string itemPartNo, string enabled, int factoryId)
|
|
|
{
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (partNo != null && !partNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and part_no like '%" + partNo.Trim() + "%' ";
|
|
|
}
|
|
|
if (itemPartNo != null && !itemPartNo.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and part_no like '%" + itemPartNo.Trim() + "%' ";
|
|
|
}
|
|
|
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += "and enabled = '" + enabled.Trim() + "' ";
|
|
|
}
|
|
|
strWhere += " and factory_id = " + factoryId + " ";
|
|
|
String orderBy = " order by zone_name ";
|
|
|
|
|
|
return repository.getExportList(strWhere, orderBy);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导入
|
|
|
/// </summary>
|
|
|
public Hashtable ImportExcel(List<ZonePart> 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? zoneName = inputStream[i].ZoneName;
|
|
|
string? vendorCode = inputStream[i].VendorCode;
|
|
|
string? partNo = inputStream[i].PartNo;
|
|
|
WmsOutsourceBom sysExemptions = repository.ifExistsOutsourceBom(zoneName, vendorCode, partNo);
|
|
|
if (sysExemptions == null)
|
|
|
{
|
|
|
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("INSERT INTO dbo.sys_zone_part ");
|
|
|
SqlStringBuilder.Append(" (zone_id,zone_name ");
|
|
|
SqlStringBuilder.Append(" ,vendor_id,vendor_code ");
|
|
|
SqlStringBuilder.Append(" ,part_id,part_no ");
|
|
|
SqlStringBuilder.Append(" ,part_spec,priority ");
|
|
|
SqlStringBuilder.Append(" ,factory_id,factory_code ");
|
|
|
SqlStringBuilder.Append(" ,enabled,create_userid ");
|
|
|
SqlStringBuilder.Append(" ,create_time,guid) ");
|
|
|
SqlStringBuilder.Append(" VALUES(@zoneId,@zoneName ");
|
|
|
SqlStringBuilder.Append(" ,@vendorId,@vendorCode ");
|
|
|
SqlStringBuilder.Append(" ,@partId,@partNo ");
|
|
|
SqlStringBuilder.Append(" ,@partSpec,@priority ");
|
|
|
SqlStringBuilder.Append(" ,@factoryId,@factoryCode ");
|
|
|
SqlStringBuilder.Append(" ,@enabled,@createUserid ");
|
|
|
SqlStringBuilder.Append(" ,@createTime,@guid) ");
|
|
|
|
|
|
|
|
|
//Params = new DynamicParameters();
|
|
|
//List<SysZone> sysZones = repository.getSelectZoneInfo(zoneName);
|
|
|
|
|
|
//if (sysZones.Count > 0)
|
|
|
//{
|
|
|
// Params.Add("@zoneId", sysZones[0].ZoneId);
|
|
|
// Params.Add("@zoneName", sysZones[0].ZoneName);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// result.Add("message", "导入失败,库区代码不存在,请检查");
|
|
|
// result.Add("flag", "error");
|
|
|
// return result;
|
|
|
//}
|
|
|
|
|
|
List<SysPart> sysParts = repository.GetPartInfo(partNo);
|
|
|
if (sysParts.Count>0)
|
|
|
{
|
|
|
Params.Add("@partId", sysParts[0].PartId);
|
|
|
Params.Add("@partNo", sysParts[0].PartNo);
|
|
|
Params.Add("@partSpec", sysParts[0].PartSpec);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Add("message", "导入失败,零件号不存在,请检查");
|
|
|
result.Add("flag", "error");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Params.Add("@priority", inputStream[i].Priority);
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |