using Dapper; 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.Text; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:产线定义 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Services { public class PDLineDefineService : BaseService, IPDLineDefineService { private readonly IPDLineDefineRepository repository; public PDLineDefineService(IPDLineDefineRepository _repository) : base(_repository) { repository = _repository; } /// /// 根据分页条件获取分页菜单数据 /// /// /// /// /// /// public Hashtable getPDLineListByPage(String pdlineCode, String pdlineName, int factoryid, Pager pager, String direction, String sort, string enabled) { String strWhere = "1=1 "; if (pdlineCode != null && !pdlineCode.Trim().Equals("")) { strWhere += " and a.pdline_code like '%" + pdlineCode.Trim() + "%'"; } if (pdlineName != null && !pdlineName.Trim().Equals("")) { strWhere += " and a.pdline_name like '%" + pdlineName.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 += "a." + typeof(SysPdline).GetEntityColumnName(sort.Trim()) + " " + direction; } else { orderBy += "a." + typeof(SysPdline).GetEntityColumnName("PdlineId") + " " + direction; } return repository.getListByPage(pager.pageSize, pager.pageNo, strWhere, orderBy); } public List getSelectZone() { return repository.getSelectZone(); } public List getSelectLocate() { return repository.getSelectLocate(); } public SysWarehouse getSelectWarehouse(string warehouseName, int factoryId) { return repository.getSelectWarehouse(warehouseName, factoryId); } public List getSelectSrcZone(int factoryId) { return repository.getSelectSrcZone(factoryId); } public List getSelectSrcLocate(string zone_Id, int factoryId) { return repository.getSelectSrcLocate(zone_Id, factoryId); } public List getSelectDestZone(int factoryId) { return repository.getSelectDestZone(factoryId); } public List getSelectDestLocate(string zone_Id, int factoryId) { return repository.getSelectDestLocate(zone_Id, factoryId); } /// /// 保存菜单数据 /// /// /// public int savePdline(SysPdline htParams) { return repository.savePdline(htParams); } /// /// 更新菜单数据 /// /// /// public int updatePdline(SysPdline htParams) { return repository.updatePdline(htParams); } /// /// 查看菜单详情 /// /// /// public Hashtable getPdlineDetail(String pdline_id) { pdline_id = " pdline_id = " + pdline_id; List lists = repository.getList(pdline_id, ""); Hashtable result = new Hashtable(); result.Add("factoryId", lists[0].FactoryId); result.Add("factoryName", lists[0].FactoryName); result.Add("pdlineCode", lists[0].PdlineCode); result.Add("pdlineName", lists[0].PdlineName); result.Add("pdlineId", lists[0].PdlineId); result.Add("pdlineDesc", lists[0].PdlineDesc); result.Add("srcLocateId", lists[0].SrcLocateId); result.Add("srcZoneId", lists[0].SrcZoneId); result.Add("destLocateId", lists[0].DestLocateId); result.Add("destZoneId", lists[0].DestZoneId); result.Add("enabled", lists[0].Enabled); result.Add("partPrepare", lists[0].PartPrepare); result.Add("isIndex", lists[0].Enabled); return result; } /// /// 获得零件信息 /// /// 零件类型 /// public List GetPartInfo(string part_no) { return repository.GetPartInfo(part_no); } public List GetLocateInfo(string locateName) { return repository.GetLocateInfo(locateName); } /// /// 删除菜单 /// /// /// public int deleteMenu(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.deleteMenu(id); } } return count; } /// /// 启用 /// /// /// public int EnablePdline(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.EnablePdLine(id); } } return count; } /// /// 禁用 /// /// /// public int DisablePdline(String ids) { String[] idArray = ids.Split(','); int count = 0; foreach (String id in idArray) { if (!"".Equals(id)) { count += this.repository.DisablePdline(id); } } return count; } //导出查询 public List getExportList(string pdlineCode, string pdlineName, string enabled, int factoryid) { String strWhere = "1=1 "; if (pdlineCode != null && !pdlineCode.Trim().Equals("")) { strWhere += " and a.pdline_code like '%" + pdlineCode.Trim() + "%'"; } if (pdlineName != null && !pdlineName.Trim().Equals("")) { strWhere += " and a.pdline_name like '%" + pdlineName.Trim() + "%'"; } if (enabled != null && !enabled.Trim().Equals("")) { strWhere += " and a.enabled = '" + enabled.Trim() + "'"; } strWhere += " and a.factory_id =" + factoryid; string orderBy = " order by pdline_code "; return repository.getExportList(strWhere, orderBy); } /// /// 导入零件免检 /// public Hashtable ImportExcel(List inputStream, int factoryId, string factoryCode, int empId) { try { Hashtable result = new Hashtable(); List SqlStrings = new List(); List Parameters = new List(); 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? pdlineCode = inputStream[i].PdlineCode.ToString(); string? srcZoneName = inputStream[i].SrcZoneName.ToString(); string? destZoneName = inputStream[i].DestZoneName.ToString(); string? destLocateName = inputStream[i].DestLocateName.ToString(); List sysExemptions = repository.ifExistsPdLine(pdlineCode, srcZoneName, destZoneName, destLocateName); if (sysExemptions.Count <= 0) { StringBuilder querySen = new StringBuilder(1024); querySen.AppendLine("INSERT INTO dbo.sys_pdline "); querySen.AppendLine(" ( pdline_code , "); querySen.AppendLine(" pdline_name , "); querySen.AppendLine(" pdline_desc , "); querySen.AppendLine(" dest_warehouse_id , "); querySen.AppendLine(" dest_warehouse_name , "); querySen.AppendLine(" dest_zone_id , "); querySen.AppendLine(" dest_zone_name , "); querySen.AppendLine(" dest_locate_id , "); querySen.AppendLine(" dest_locate_name , "); querySen.AppendLine(" src_warehouse_id , "); querySen.AppendLine(" src_warehouse_name , "); querySen.AppendLine(" src_zone_id , "); querySen.AppendLine(" src_zone_name , "); querySen.AppendLine(" src_locate_id , "); querySen.AppendLine(" src_locate_name , "); querySen.AppendLine(" enabled , "); querySen.AppendLine(" factory_id , "); querySen.AppendLine(" factory_code , "); querySen.AppendLine(" create_userid , "); querySen.AppendLine(" create_time "); querySen.AppendLine(" ) "); querySen.AppendLine("VALUES ( @pdlineCode ,"); querySen.AppendLine(" @pdlineName , "); querySen.AppendLine(" @pdlineDesc , "); querySen.AppendLine(" @destWarehouseId , "); querySen.AppendLine(" @destWarehouseName , "); querySen.AppendLine(" @destZoneId , "); querySen.AppendLine(" @destZoneName , "); querySen.AppendLine(" @destLocateId , "); querySen.AppendLine(" @destLocateName , "); querySen.AppendLine(" @srcWarehouseId , "); querySen.AppendLine(" @srcWarehouseName , "); querySen.AppendLine(" @srcZoneId , "); querySen.AppendLine(" @srcZoneName , "); querySen.AppendLine(" @srcLocateId , "); querySen.AppendLine(" @srcLocateName , "); querySen.AppendLine(" @enabled,"); querySen.AppendLine(" @factoryId ,"); querySen.AppendLine(" @factoryCode ,"); querySen.AppendLine(" @createUserid,"); querySen.AppendLine(" @createTime"); querySen.AppendLine(" ) "); Params = new DynamicParameters(); Params.Add("@pdlineCode", inputStream[i].PdlineCode); Params.Add("@pdlineName", inputStream[i].PdlineName); Params.Add("@pdlineDesc", inputStream[i].PdlineDesc); if (!string.IsNullOrEmpty(inputStream[i].DestZoneName)) { SysZone sysZone = repository.getSelectZone(inputStream[i].DestZoneName, factoryId); if (sysZone != null) { Params.Add("@destWarehouseId", sysZone.WarehouseId); Params.Add("@destWarehouseName", sysZone.WarehouseName); Params.Add("@destZoneId", sysZone.ZoneId); Params.Add("@destZoneName", sysZone.ZoneName); } else { result.Add("message", "导入失败,成品库区不存在,请检查"); result.Add("flag", "error"); return result; } } else { result.Add("message", "导入失败,成品库区不能为空,请检查"); result.Add("flag", "error"); return result; } if (!string.IsNullOrEmpty(inputStream[i].DestLocateName)) { SysLocate sysLocate = repository.getSelectLocate(inputStream[i].DestLocateName, factoryId); if (sysLocate != null) { Params.Add("@destLocateId", sysLocate.LocateId); Params.Add("@destLocateName", sysLocate.LocateName); } else { result.Add("message", "导入失败,成品库位不存在,请检查"); result.Add("flag", "error"); return result; } } else { result.Add("message", "导入失败,成品库位不能为空,请检查"); result.Add("flag", "error"); return result; } if (!string.IsNullOrEmpty(inputStream[i].SrcZoneName)) { SysZone sysZone = repository.getSelectZone(inputStream[i].SrcZoneName, factoryId); if (sysZone != null) { Params.Add("@srcWarehouseId", sysZone.WarehouseId); Params.Add("@srcWarehouseName", sysZone.WarehouseName); Params.Add("@srcZoneId", sysZone.ZoneId); Params.Add("@srcZoneName", sysZone.ZoneName); } else { result.Add("message", "导入失败,线边库区不存在,请检查"); result.Add("flag", "error"); return result; } } else { result.Add("message", "导入失败,线边库区不能为空,请检查"); result.Add("flag", "error"); return result; } Params.Add("@srcLocateId", 0); Params.Add("@srcLocateName", ""); 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; } } } }