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.

279 lines
9.3 KiB
C#

2 years ago
using Estsh.Core.Dapper;
using Estsh.Core.IRepositories;
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.Data;
using System.Text;
/***************************************************************************************************
*
* sitong.dong
*
* 2022.06.22
*
*
**************************************************************************************************/
namespace Estsh.Core.Services
{
public class PartSNRuleDefineService : BaseService<SysPartSnRule>, IPartSNRuleDefineService
{
private readonly IPartSNRuleDefineRepository repository;
public PartSNRuleDefineService(IPartSNRuleDefineRepository _repository) : base(_repository)
{
repository = _repository;
}
/// <summary>
/// 根据分页条件获取分页菜单数据
/// </summary>
/// <param name="partNo"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public Hashtable getPartSNRuleListByPage(String partNo_search, String type_test, Pager pager, String direction, String sort, String enabled)
{
String strWhere = " 1=1 ";
if (!String.IsNullOrEmpty(partNo_search))
{
strWhere += " and b.part_no like '%" + partNo_search.Trim() + "%'";
}
if (!String.IsNullOrEmpty(type_test))
{
strWhere += " and a.type like '%" + type_test.Trim() + "%'";
}
if (!String.IsNullOrEmpty(enabled))
{
strWhere += " and a.enabled = '" + enabled.Trim() + "'";
}
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += typeof(SysPartSnRule).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += typeof(SysPartSnRule).GetEntityColumnName("Ruid") + " " + direction;
}
Hashtable dt = repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
return dt;
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int savePartSNRule(SysPartSnRule htParams)
{
return repository.savePartSNRule(htParams);
}
/// <summary>
/// 更新菜单数据
/// </summary>
/// <param name="htParams"></param>
/// <returns></returns>
public int updatePartSNRule(SysPartSnRule htParams)
{
return repository.updatePartSNRule(htParams);
}
/// <summary>
/// 查看菜单详情
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public Hashtable getPartSNRuleDetail(String ruid)
{
ruid = " ruid = " + ruid;
List<SysPartSnRule> dt = repository.getList(ruid, "");
Hashtable result = new Hashtable();
result.Add("ruid", dt[0].Ruid);
result.Add("type", dt[0].Type);
result.Add("lenght", dt[0].Lenght);
result.Add("from1", dt[0].From1);
result.Add("partNo", dt[0].PartNo);
result.Add("to1", dt[0].To1);
result.Add("fix1", dt[0].Fix1);
result.Add("from2", dt[0].From2);
result.Add("to2", dt[0].To2);
result.Add("fix2", dt[0].Fix2);
result.Add("partId", dt[0].PartId);
//result.Add("ext_rule", dt[0]["ext_rule"]);
result.Add("enabled", dt[0].Enabled);
result.Add("isValidateUnique", dt[0].IsValidateUnique);
result.Add("isValidateLength", dt[0].IsValidateLength);
return result;
}
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public int deletePartSNRule(String ids)
{
String[] idArray = ids.Split(',');
int count = 0;
foreach (String id in idArray)
{
if (!"".Equals(id))
{
count += this.repository.deletePartSNRule(id);
}
}
return count;
}
/// <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);
}
/// <summary>
/// 获取 类型 信息
/// BY NOAH
/// </summary>
/// <returns></returns>
public List<KeyValueResult> getTypeData()
{
return repository.getTypeData();
}
/// <summary>
/// 判断是否存在 用户输入的零件号
/// BY NOAH
/// </summary>
/// <param name="part_no"></param>
/// <returns></returns>
public String isExsitPart_no(String part_no)
{
return this.repository.isExsitPart_no(part_no);
}
/// <summary>
/// 根据分页条件获取分页菜单数据
/// </summary>
/// <param name="menuName">查询条件</param>
/// <param name="pager"></param>
/// <param name="direction">排序方式</param>
/// <param name="sort">排序字段</param>
/// <returns></returns>
public Hashtable getTableListByPage(String partNo_search, String type_test, String enabled, Pager pager, String direction, String sort, Boolean isPage)
{
int rowCount = 0;
String strWhere = " 1=1 ";
if (!String.IsNullOrEmpty(partNo_search))
{
strWhere += " and b.part_no like '%" + partNo_search.Trim() + "%'";
}
if (!String.IsNullOrEmpty(type_test))
{
strWhere += " and a.type like '%" + type_test.Trim() + "%'";
}
if (!String.IsNullOrEmpty(enabled))
{
strWhere += " and a.enabled = '" + enabled.Trim() + "'";
}
if (isPage)
{
rowCount = pager.pageSize;
}
else
{
rowCount = pager.pageSize;
}
String orderBy = "";
if (sort != null && !"".Equals(sort.Trim()))
{
orderBy += typeof(SysPartSnRule).GetEntityColumnName(sort.Trim()) + " " + direction;
}
else
{
orderBy += typeof(SysPartSnRule).GetEntityColumnName("Ruid") + " " + direction;
}
Hashtable result = repository.getTableListByPage(rowCount, pager.pageNo, strWhere, orderBy);
return result;
}
/// <summary>
/// 读取文件并更新至数据库
/// </summary>
/// <param name="inputStream">文件全路径</param>
/// <param name="userInfo">登录用户信息</param>
public Hashtable ImportExcel(List<PartSNRuleDefine> inputStream, int userId)
{
Hashtable result = new Hashtable();
Hashtable Cache = new Hashtable();
if (inputStream == null || inputStream.Count == 0)
{
result.Add("message", "导入数据为空,请重新导入");
result.Add("flag", "error");
return result;
}
string partNo = string.Empty;
StringBuilder ErrorMessage = new StringBuilder(1024);
// 验证数据
for (int i = 0; i < inputStream.Count; i++)
{
partNo = inputStream[i].PartNo.ToString();
// 判断零件号是否存在
int partID = repository.GetPartID(partNo);
if (partID == 0)
{
ErrorMessage.Append("零件号 " + partNo + " 不存在!" + '\r' + '\n' + Environment.NewLine);
}
}
if (ErrorMessage.Length != 0)
{
result.Add("message", ErrorMessage.ToString());
result.Add("flag", "error");
return result;
}
// 处理表身数据
if (repository.InsertData(inputStream, userId.ToString()))
{
result.Add("message", "导入成功");
result.Add("flag", "error");
return result;
}
else
{
result.Add("message", "导入失败");
result.Add("flag", "error");
return result;
}
}
}
}