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.

264 lines
8.8 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.Dapper;
using Estsh.Core.Model.ExcelModel;
using Dapper;
using System.Text;
/***************************************************************************************************
*
* 更新人sitong.dong
* 描述:
* 修改时间2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Services
{
/// <summary>
/// 菜单业务处理类
/// </summary>
public class VendorService : BaseService<SysVendor>, IVendorService
{
private readonly IVendorRepository repository;
public VendorService(IVendorRepository _repository) : base(_repository)
{
repository = _repository;
}
/// <summary>
/// 根据分页条件获取分页菜单数据
/// </summary>
/// <param name="VendorName"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public Hashtable getVendorListByPage(String enabled, String vendor_code, String vendor_name, int factoryId, Pager pager, String direction, String sort)
{
Hashtable result = new Hashtable();
String strWhere = " 1=1 ";
if (vendor_name != null && !vendor_name.Trim().Equals(""))
{
strWhere = " vendor_name like '%" + vendor_name.Trim() + "%' ";
}
if (vendor_code != null && !vendor_code.Trim().Equals(""))
{
strWhere += " AND vendor_code like '%" + vendor_code.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " AND enabled like '%" + enabled.Trim() + "%'";
}
strWhere += " and a.factory_id = " + factoryId + " ";
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += typeof(SysVendor).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += " vendor_id " + direction;
}
result = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
return result;
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int saveVendor(SysVendor htParams)
{
return repository.saveVendor(htParams);
}
/// <summary>
/// 更新菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int updateVendor(SysVendor htParams)
{
return repository.updateVendor(htParams);
}
public SysVendor getVendorByExistName(string vendorCode)
{
return repository.getVendorByExistName(vendorCode);
}
/// <summary>
/// 导入道口信息
/// </summary>
/// <param name="inputStream">文件全路径</param>
public Hashtable ImportExcel(List<VendorDock> 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.UpdateAllVendorDock();//初始化所有供应商道口号
//判断零件号是否存在
for (int i = 0; i < inputStream.Count; i++)
{
if (!string.IsNullOrEmpty(inputStream[i].VerdorCode))
{
string vendorCode = inputStream[i].VerdorCode.ToString();
List<SysVendor> sysVendors = repository.ifVendorDock(vendorCode);
if (sysVendors.Count > 0)
{
StringBuilder stringBuilder = new StringBuilder(1024);
stringBuilder.Append("update sys_vendor set dock=@dock where vendor_code=@vendorCode");
SqlStrings.Add(stringBuilder.ToString());
DynamicParameters dynamic = new DynamicParameters();
dynamic.Add("@dock", inputStream[i].Dock);
dynamic.Add("@vendorCode", inputStream[i].VerdorCode);
Parameters.Add(dynamic);
}
}
}
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="ruid"></param>
/// <returns></returns>
public List<SysVendor> getVendor(String vendor_id)
{
vendor_id = "vendor_id = " + vendor_id;
return repository.getList(vendor_id, "");
}
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int deleteVendor(String ids)
{
String[] idArray = ids.Split(',');
int count = 0;
foreach (String id in idArray)
{
if (!"".Equals(id))
{
count += this.repository.deleteVendor(id);
}
}
return count;
}
/// <summary>
/// 获取下拉框中的菜单数据
/// </summary>
/// <returns></returns>
public List<KeyValueResult> getSelectVendor()
{
return repository.getSelectVendor();
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int EnableVendor(String ids)
{
String[] idArray = ids.Split(',');
int count = 0;
foreach (String id in idArray)
{
if (!"".Equals(id))
{
count += this.repository.EnableVendor(id);
}
}
return count;
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int DisableVendor(String ids)
{
String[] idArray = ids.Split(',');
int count = 0;
foreach (String id in idArray)
{
if (!"".Equals(id))
{
count += this.repository.DisableVendor(id);
}
}
return count;
}
public List<Vendor> getExportList(string vendorCode, string vendorName, string enabled,int factoryId)
{
String strWhere = " 1=1 ";
if (vendorCode != null && !vendorCode.Trim().Equals(""))
{
strWhere = " vendor_code like '%" + vendorCode.Trim() + "%' ";
}
if (vendorName != null && !vendorName.Trim().Equals(""))
{
strWhere += " AND vendor_name like '%" + vendorName.Trim() + "%'";
}
if (enabled != null && !enabled.Trim().Equals(""))
{
strWhere += " AND enabled = '" + enabled.Trim() + "'";
}
strWhere += " and factory_id = " + factoryId + " ";
String orderBy = " order by vendor_code ";
return repository.getExportList(strWhere,orderBy);
}
}
}