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.

275 lines
10 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 Dapper;
using Estsh.Core.Dapper;
using Estsh.Core.Model.ExcelModel;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Repository.IRepositories;
using Estsh.Core.Services.IServices;
using Estsh.Core.Util;
using System.Collections;
using System.Text;
/***************************************************************************************************
*
* 更新人sitong.dong
* 描述:支给件维护
* 修改时间2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Services
{
/// <summary>
/// 菜单业务处理类
/// </summary>
public class SupportingPartDefineService : BaseService<WmsCustomerToStock>, ISupportingPartDefineService
{
private readonly ISupportingPartDefineRepository repository;
public SupportingPartDefineService(ISupportingPartDefineRepository _repository) : base(_repository)
{
repository = _repository;
}
/// <summary>
/// 根据分页条件获取分页菜单数据
/// </summary>
/// <param name="part_no"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public Hashtable GetListByPage(String customerPart, String part_no, String partSpec, Pager pager, String direction, String sort, String enabled)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (customerPart != null && !customerPart.Trim().Equals(""))
{
strWhere += " and customer_part like '%" + customerPart.Trim() + "%'";
}
if (part_no != null && !part_no.Trim().Equals(""))
{
strWhere += " and part_no like '%" + part_no.Trim() + "%'";
}
if (partSpec != null && !partSpec.Trim().Equals(""))
{
strWhere += " and part_spec like '%" + partSpec.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " and enabled = '" + enabled + "'";
}
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += " " + typeof(WmsCustomerToStock).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += " " + typeof(WmsCustomerToStock).GetEntityColumnName("ruid") + " " + direction;
}
result = repository.GetListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
return result;
}
/// <summary>
/// 获取下拉框中的菜单数据
/// </summary>
/// <returns></returns>
public List<KeyValueResult> GetSelect()
{
return repository.GetSelect();
}
/// <summary>
/// 查看零件详情
/// </summary>
/// <param name="part_id">零件ID</param>
/// <returns></returns>
public List<SysPart> GetDetailByName(String part_no)
{
part_no = "part_no = '" + part_no + "' ";
List<SysPart> dt = repository.GetListFromPart(part_no);
return dt;
}
public List<WmsCustomerToStock> ifExemptionList(String ruid)
{
return repository.ifExemptionList(ruid);
}
public List<WmsCustomerToStock> ifExemptionList(String customerPart, String partNo)
{
return repository.ifExemptionList(customerPart, partNo);
}
//导出查询
public List<SupportingPartDefine> getExportList(String partNo, String enabled)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (partNo != null && !partNo.Trim().Equals(""))
{
strWhere += " and part_no like '%" + partNo.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " and enabled = '" + enabled + "'";
}
String orderBy = " order by part_no ";
return repository.getExportList(strWhere, orderBy);
}
/// <summary>
/// 导入零件免检
/// </summary>
public Hashtable ImportExcel(List<SupportingPartDefine> 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;
}
//this.repository.DeleteAll();//清空免检清单列表
//判断零件号是否存在
for (int i = 0; i < inputStream.Count; i++)
{
string customerPart = inputStream[i].CustomerPart.ToString();
string partNo = inputStream[i].PartNo.ToString();
List<WmsCustomerToStock> sysExemptions = repository.ifExemptionList(customerPart,partNo);
if (sysExemptions.Count <= 0)
{
StringBuilder querySen = new StringBuilder(1024);
querySen.AppendLine("INSERT INTO dbo.wms_customer_to_stock ");
querySen.AppendLine(" ( part_id , ");
querySen.AppendLine(" customer_part , ");
querySen.AppendLine(" part_no , ");
querySen.AppendLine(" part_spec , ");
querySen.AppendLine(" part_spec2 , ");
querySen.AppendLine(" enabled , ");
querySen.AppendLine(" factory_id , ");
querySen.AppendLine(" factory_code , ");
querySen.AppendLine(" create_userid , ");
querySen.AppendLine(" create_time ");
querySen.AppendLine(" ) ");
querySen.AppendLine("VALUES ( @partId ,");
querySen.AppendLine(" @customerPart , ");
querySen.AppendLine(" @partNo,");
querySen.AppendLine(" @partSpec,");
querySen.AppendLine(" @partSpec2,");
querySen.AppendLine(" @enabled,");
querySen.AppendLine(" @factoryId ,");
querySen.AppendLine(" @factoryCode ,");
querySen.AppendLine(" @createUserid,");
querySen.AppendLine(" @createTime");
querySen.AppendLine(" ) ");
Params = new DynamicParameters();
List<SysPart> dtPart = repository.ifPartNo(inputStream[i].PartNo);
if (dtPart.Count > 0)
{
Params.Add("@partId", dtPart[0].PartId);
Params.Add("@partNo", dtPart[0].PartNo);
Params.Add("@partSpec", dtPart[0].PartSpec);
Params.Add("@partSpec2", dtPart[0].PartSpec2);
}
else
{
result.Add("message", "导入失败,零件号不存在,请检查");
result.Add("flag", "error");
return result;
}
Params.Add("@customerPart", inputStream[i].CustomerPart);
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"));
SqlStrings.Add(querySen.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;
}
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int Insert(WmsCustomerToStock htParams)
{
return repository.Insert(htParams);
}
/// <summary>
/// 更新菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int Update(WmsCustomerToStock htParams)
{
return repository.Update(htParams);
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int EnableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.EnableData(ids);
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int DisableData(String ids)
{
ids = ids.Substring(0, ids.Length - 1);
return this.repository.DisableData(ids);
}
}
}