You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
17 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 PullGroupService : BaseService<WmsPullingGroup>, IPullGroupService
{
private readonly IPullGroupRepository repository;
public PullGroupService(IPullGroupRepository _repository) : base(_repository)
{
repository = _repository;
}
public Hashtable getPullGroupListByPage(string groupCode, string groupName, string enabled, int factoryId, Pager pager, String direction, String sort)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (groupCode != null && !groupCode.Trim().Equals(""))
{
strWhere += "and a.group_code like '%" + groupCode.Trim() + "%' ";
}
if (groupName != null && !groupName.Trim().Equals(""))
{
strWhere += "and a.group_name like '%" + groupName.Trim() + "%' ";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += "and a.enabled = '" + enabled.Trim() + "' ";
}
strWhere += " and a.factory_id = " + factoryId + " ";
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += typeof(WmsPullingGroup).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += typeof(WmsPullingGroup).GetEntityColumnName("groupCode") + " " + direction;
}
return repository.getPullGroupListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
}
public Hashtable getPullGroupDetailListByPage(string groupCode, string enabled, int factoryId)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (groupCode != null && !groupCode.Trim().Equals(""))
{
strWhere += "and a.group_code = '" + groupCode.Trim() + "' ";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += "and a.enabled = '" + enabled.Trim() + "' ";
}
strWhere += " and a.factory_id = " + factoryId + " ";
return repository.getPullGroupDetailListByPage(strWhere);
}
public List<WmsPullingGroupPart> getPullGroupDetailList(string groupCode)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (groupCode != null && !groupCode.Trim().Equals(""))
{
strWhere += "and a.group_code = '" + groupCode.Trim() + "' ";
}
return repository.getPullGroupDetailList(strWhere);
}
public List<SysPart> GetPartInfo(string part_no)
{
return repository.GetPartInfo(part_no);
}
public List<KeyValueResult> GetErpwarehouse()
{
return repository.GetErpwarehouse();
}
public List<KeyValueResult> getSelectFactory()
{
return repository.getSelectFactory();
}
public List<KeyValueResult> getSelectWarehouse()
{
return repository.getSelectWarehouse();
}
public List<SysWarehouse> getSelectWarehouse(string warehouseid)
{
return repository.getSelectWarehouse(warehouseid);
}
public List<SysZone> getSelectZone(string zoneid)
{
return repository.getSelectZone(zoneid);
}
public List<KeyValueResult> getSelectZone()
{
return repository.getSelectZone();
}
public List<KeyValueResult> getSelectVendor()
{
return repository.getSelectVendor();
}
public List<SysVendor> getSelectVendor(string vendorId)
{
return repository.getSelectVendor(vendorId);
}
public List<KeyValueResult> GetPart()
{
return repository.GetPart(0);
}
public List<SysPart> GetPart(string PartNo)
{
return repository.GetPart(0, PartNo);
}
public List<KeyValueResult> GetOrderType()
{
return repository.GetOrderType();
}
public List<SysPdline> GetPdlineByPdlineId(int pdlineId)
{
return repository.GetPdlineByPdlineId(pdlineId);
}
public SysPdline GetPdlineByPdlineCode(string pdlineCode)
{
return repository.GetPdlineByPdlineCode(pdlineCode);
}
public List<KeyValueResult> GetPdlineByKey()
{
return repository.GetPdlineByKey();
}
public bool saveHandPullGroup(string groupCode, string handPullQty)
{
return repository.saveHandPullGroup(groupCode, handPullQty);
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int savePullGroup(WmsPullingGroup htParams, IList<WmsPullingGroupPart> htDetailParams)
{
return repository.savePullGroup(htParams, htDetailParams);
}
public int updatePullGroup(WmsPullingGroup htParams, IList<WmsPullingGroupPart> htDetailParams)
{
return repository.updatePullGroup(htParams, htDetailParams);
}
public List<SysPart> GetPartNoInfo(string part_no)
{
return this.repository.GetPartNoInfo(part_no);
}
public List<SysPart> GetPartSpecInfo(string partSpec)
{
return this.repository.GetPartSpecInfo(partSpec);
}
/// <summary>
///
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public Hashtable getPullGroup(String ruid)
{
List<WmsPullingGroup> dt = repository.getList(ruid);
Hashtable result = new Hashtable();
result.Add("ruid", dt[0].Ruid);
result.Add("groupCode", dt[0].GroupCode);
result.Add("groupName", dt[0].GroupName);
result.Add("pullingType", dt[0].PullingType);
result.Add("pdlineCode", dt[0].PdlineCode);
result.Add("pdlineName", dt[0].PdlineName);
result.Add("kittingQty", Convert.ToInt32(dt[0].KittingQty));
result.Add("isAutoPrint", dt[0].IsAutoPrint);
result.Add("printCopies", dt[0].PrintCopies);
result.Add("triggerValue", dt[0].TriggerValue);
result.Add("pullValue", dt[0].PullValue);
return result;
}
public int EnableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.EnableData(ids);
}
public int DisableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.DisableData(ids);
}
public List<PullGroup> getExportList(string groupCode, string groupName, string enabled, int factoryId)
{
String strWhere = " 1=1 ";
if (groupCode != null && !groupCode.Trim().Equals(""))
{
strWhere += "and b.group_code like '%" + groupCode.Trim() + "%' ";
}
if (groupName != null && !groupName.Trim().Equals(""))
{
strWhere += "and b.group_name like '%" + groupName.Trim() + "%' ";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += "and b.enabled = '" + enabled.Trim() + "' ";
}
strWhere += " and b.factory_id = " + factoryId + " ";
String orderBy = " order by b.group_code ";
return repository.getExportList(strWhere, orderBy);
}
/// <summary>
/// 导入零件免检
/// </summary>
public Hashtable ImportExcel(List<PullGroup> 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 groupCode = inputStream[i].GroupCode.ToString();
PullGroup sysExemptions = repository.ifExistsPullGroup(groupCode);
if (sysExemptions == null)
{
StringBuilder SqlStringBuilder = new StringBuilder(1024);
SqlStringBuilder.Append("INSERT INTO dbo.wms_pulling_group ");
SqlStringBuilder.Append(" (group_code,group_name ");
SqlStringBuilder.Append(" ,pulling_type,pdline_id ");
SqlStringBuilder.Append(" ,pdline_code,kitting_qty ");
SqlStringBuilder.Append(" ,triggerValue,pullValue ");
SqlStringBuilder.Append(" ,factory_id,factory_code ");
SqlStringBuilder.Append(" ,enabled,create_userid ");
SqlStringBuilder.Append(" ,create_time,guid) ");
SqlStringBuilder.Append(" VALUES(@groupCode,@groupName ");
SqlStringBuilder.Append(" ,@pullingType,@pdlineId ");
SqlStringBuilder.Append(" ,@pdlineCode,@kittingQty ");
SqlStringBuilder.Append(" ,@triggerValue,@pullValue ");
SqlStringBuilder.Append(" ,@factoryId,@factoryCode ");
SqlStringBuilder.Append(" ,@enabled,@createUserid ");
SqlStringBuilder.Append(" ,@createTime,@guid) ");
Params = new DynamicParameters();
Params.Add("@groupCode", groupCode);
Params.Add("@groupName", inputStream[i].GroupName);
if (inputStream[i].PullingType == "JIT蓝卡队列")
{
Params.Add("@pullingType", "10");
}
else if (inputStream[i].PullingType == "JIT指示票队列")
{
Params.Add("@pullingType", "20");
}
else
{
result.Add("message", "导入失败,拉动组类型不存在,请检查");
result.Add("flag", "error");
return result;
}
SysPdline sysPdline = repository.GetPdlineByPdlineCode(inputStream[i].PdlineCode);
if (sysPdline != null)
{
Params.Add("@pdlineId", sysPdline.PdlineId);
Params.Add("@pdlineCode", sysPdline.PdlineCode);
}
else
{
result.Add("message", "导入失败,产线代码不存在,请检查");
result.Add("flag", "error");
return result;
}
Params.Add("@triggerValue", inputStream[i].TriggerValue);
Params.Add("@pullValue", inputStream[i].PullValue);
Params.Add("@kittingQty", inputStream[i].KittingQty);
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);
}
PullGroup sysPullGroupPart = repository.ifExistsPullGroupPart(groupCode, inputStream[i].PartNo);
if (sysPullGroupPart == null)
{
StringBuilder SqlStringBuilder = new StringBuilder(1024);
SqlStringBuilder.Append("INSERT INTO dbo.wms_pulling_group_part ");
SqlStringBuilder.Append(" (group_code,group_name ");
SqlStringBuilder.Append(" ,part_id,part_no ");
SqlStringBuilder.Append(" ,part_spec,pull_qty ");
SqlStringBuilder.Append(" ,factory_id,factory_code ");
SqlStringBuilder.Append(" ,enabled,create_userid ");
SqlStringBuilder.Append(" ,create_time,guid) ");
SqlStringBuilder.Append(" VALUES(@groupCode,@groupName ");
SqlStringBuilder.Append(" ,@partId,@partNo ");
SqlStringBuilder.Append(" ,@partSpec,@pullQty ");
SqlStringBuilder.Append(" ,@factoryId,@factoryCode ");
SqlStringBuilder.Append(" ,@enabled,@createUserid ");
SqlStringBuilder.Append(" ,@createTime,@guid) ");
Params = new DynamicParameters();
Params.Add("@groupCode", groupCode);
Params.Add("@groupName", inputStream[i].GroupName);
List<SysPart> sysParts = repository.GetPartNoInfo(inputStream[i].PartNo);
if (sysParts != null)
{
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("@pullQty", inputStream[i].PullQty);
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;
}
}
}
}