|
|
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 MesRouteGroupService : BaseService<MesRouteGroupDetail>, IMesRouteGroupService
|
|
|
{
|
|
|
private readonly IMesRouteGroupRepository repository;
|
|
|
|
|
|
public MesRouteGroupService(IMesRouteGroupRepository _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 getDataListByPage(String part_no_search, Pager pager, String direction, String sort, String enabled)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (part_no_search != null && !part_no_search.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.part_no like '%" + part_no_search.Trim() + "%'";
|
|
|
}
|
|
|
if (enabled != null && !enabled.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and a.enabled = '" + enabled + "'";
|
|
|
}
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(MesRouteGroupDetail).GetEntityColumnName(sort.Trim()) + " ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += typeof(MesRouteGroupDetail).GetEntityColumnName("GroupId") + " ";
|
|
|
}
|
|
|
|
|
|
return repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取配置ID
|
|
|
/// </summary>
|
|
|
/// <param name="modelName"></param>
|
|
|
/// <returns></returns>
|
|
|
public int getModelID(string modelName)
|
|
|
{
|
|
|
return repository.GetModelID(modelName);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取总成零件ID
|
|
|
/// </summary>
|
|
|
/// <param name="modelName"></param>
|
|
|
/// <returns></returns>
|
|
|
public int getpartID(string partNo)
|
|
|
{
|
|
|
return repository.GetPartID(partNo);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="keydata_id"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable getDataDetail(String groupID, string partNO)
|
|
|
{
|
|
|
string strWhere = " a.group_id = '" + groupID + "' AND a.part_no = '" + partNO + "'";
|
|
|
List<MesRouteGroupDetail> dt = repository.getList(strWhere, "");
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("groupId", dt[0].GroupId);
|
|
|
result.Add("partNo", dt[0].PartNo);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public int deleteData(String ids)
|
|
|
{
|
|
|
if (ids.LastIndexOf(',') == ids.Length - 1)
|
|
|
{
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
}
|
|
|
String[] idArray = ids.Split(',');
|
|
|
int count = 0;
|
|
|
foreach (String id in idArray)
|
|
|
{
|
|
|
if (!"".Equals(id))
|
|
|
{
|
|
|
count += this.repository.deleteData(id);
|
|
|
}
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取 站点 信息
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getTerminalName()
|
|
|
{
|
|
|
return repository.getTerminalName();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取 产线 信息
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public List<KeyValueResult> getBoardName()
|
|
|
{
|
|
|
return repository.getBoardName();
|
|
|
}
|
|
|
/// <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 part_no_search, Pager pager, String direction, String sort, Boolean isPage)
|
|
|
{
|
|
|
Hashtable result = null;
|
|
|
int rowCount = 0;
|
|
|
|
|
|
String strWhere = " 1=1 ";
|
|
|
if (part_no_search != null && !part_no_search.Trim().Equals(""))
|
|
|
{
|
|
|
strWhere += " and b.part_no like '%" + part_no_search.Trim() + "%'";
|
|
|
}
|
|
|
|
|
|
if (isPage)
|
|
|
{
|
|
|
rowCount = pager.pageSize;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
rowCount = pager.pageSize;
|
|
|
}
|
|
|
|
|
|
String orderBy = "";
|
|
|
if (sort != null && !"".Equals(sort.Trim()))
|
|
|
{
|
|
|
orderBy += typeof(MesRouteGroupDetail).GetEntityColumnName(sort.Trim()) + " ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
orderBy += typeof(MesRouteGroupDetail).GetEntityColumnName("GroupId") + " ";
|
|
|
}
|
|
|
|
|
|
return repository.getTableListByPage(rowCount, pager.pageNo, strWhere, orderBy);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取文件并更新至数据库
|
|
|
/// </summary>
|
|
|
/// <param name="inputStream">文件全路径</param>
|
|
|
/// <param name="userInfo">登录用户信息</param>
|
|
|
public Hashtable ImportExcel(List<MesRouteGroup> 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().ToUpper().Trim();
|
|
|
string str = inputStream[i].GroupId.ToString().ToUpper().Trim();
|
|
|
//查询是否存在该零件号(零件号是否存在,part_location是否存在)
|
|
|
int partID = getpartID(partNo);
|
|
|
|
|
|
// 跳过空行
|
|
|
if (string.IsNullOrEmpty(partNo))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (partID == 0)
|
|
|
{
|
|
|
ErrorMessage.Append("零件号" + partNo + "不存在!或不属于关键零部件号!" + Environment.NewLine);
|
|
|
break;
|
|
|
}
|
|
|
if (!str.Equals("100001") && !str.Equals("100002"))
|
|
|
{
|
|
|
ErrorMessage.Append("生产区域" + str + "不存在!" + Environment.NewLine);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |