using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.BLL; using QMAPP.FJC.Entity.ProductionPlan; using QMAPP.FJC.DAL.ProductionPlan; using QMFrameWork.Data; using QMAPP.Entity; using System.Data; using QMAPP.FJC.Entity.Operation; using QMAPP.FJC.Entity.FIS; using QMAPP.FJC.DAL.TianJin; using QMAPP.FJC.Entity.TianJin; namespace QMAPP.FJC.BLL.TianJin { /// /// 模块名称:派工单 /// 作 者:张鹏 /// 编写日期:2017年10月24日 /// public class TJWorkOrderBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public WorkOrder Get(WorkOrder info) { try { return new TWorkOrderDAL().Get(info); } catch (Exception ex) { throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(WorkOrder condition, DataPage page) { try { return new TWorkOrderDAL().GetList(condition, page); } catch (Exception ex) { throw ex; } } /// /// 获取指定工序的生产计划清单 /// /// 工序编码 /// 过滤选项:0全部;1隐藏挂起;2只看挂起 /// public List GetOrderInCell(string workcellcode,int filter, DataPage dataPage) { try { return new TWorkOrderDAL().GetOrderInCell(workcellcode,filter,dataPage.PageSize); } catch (Exception ex) { throw ex; } } /// /// /// /// /// public List GetOrderInfo(string orderplanno) { try { return new TWorkOrderDAL().GetWorkOrderInfo(orderplanno); } catch (Exception ex) { throw ex; } } public List GetOrderUnPrintedF(string RouteCode, int filter, DataPage dataPage,string Direction,string SHIFTCODE, string BeginTime, string EndTime) { try { return new TWorkOrderDAL().GetOrderUnPrintedF(RouteCode, Direction, SHIFTCODE, BeginTime, EndTime, filter, dataPage.PageSize); } catch (Exception ex) { throw ex; } } public List GetOrderUnPrintedR(string RouteCode, int filter, DataPage dataPage, string Direction, string SHIFTCODE, string BeginTime, string EndTime) { try { return new TWorkOrderDAL().GetOrderUnPrintedR(RouteCode, Direction, SHIFTCODE, BeginTime, EndTime, filter, dataPage.PageSize); } catch (Exception ex) { throw ex; } } public List GetOrderUnPrinted018DF(string RouteCode, int filter, DataPage dataPage, string Direction, string SHIFTCODE, string BeginTime, string EndTime) { try { return new TWorkOrderDAL().GetOrderUnPrinted018DF(RouteCode, Direction, SHIFTCODE, BeginTime, EndTime, filter, dataPage.PageSize); } catch (Exception ex) { throw ex; } } public List GetOrderUnPrinted018DR(string RouteCode, int filter, DataPage dataPage, string Direction, string SHIFTCODE, string BeginTime, string EndTime) { try { return new TWorkOrderDAL().GetOrderUnPrinted018DR(RouteCode, Direction, SHIFTCODE, BeginTime, EndTime, filter, dataPage.PageSize); } catch (Exception ex) { throw ex; } } public int SetOrderPrinted(string orderpid) { try { return new TWorkOrderDAL().SetOrderPrinted(orderpid); } catch (Exception ex) { throw ex; } } /// /// 获取指定工序下待完成计划数量 /// /// 工序编码 /// 班次 /// 日期 /// public int GetOrderCountInCell(string workcellcode, string shift) { try { var date = DateTime.Now; return new TWorkOrderDAL().GetOrderCountInCell(workcellcode, shift, date); } catch (Exception ex) { throw ex; } } /// /// 获取工作中心当日的总计划数量 /// /// 工作中心 /// public int GetDayPlanCount(string workcentercode) { try { var date = DateTime.Now; return new TWorkOrderDAL().GetDayPlanCount(workcentercode, date); } catch (Exception ex) { throw ex; } } /// /// 获取计划标签数据 /// /// /// public Entity.View.PlanLabel GetPlanLabel(string workorderid) { Entity.View.PlanLabel labeldata = new Entity.View.PlanLabel(); TWorkOrderDAL dal = new TWorkOrderDAL(); var order = dal.Get(new WorkOrder { PID = workorderid }); if (order == null) { throw new Exception("获取工单信息失败!"); } labeldata.BOM = order.PBOM_CODE; labeldata.PN = order.MATERIAL_CODE; labeldata.SEQ = order.SEQ; labeldata.PlanDate = order.PLAN_DATE.ToString("yyyy-MM-dd HH:mm:ss"); switch (order.ORDER_TYPE) { case "0": { labeldata.PlanType = "FIS"; break; } case "1": { labeldata.PlanType = "STOCK"; break; } case "2": { labeldata.PlanType = "INSERT"; break; } } var plandal = new DAL.FIS.OrderPlanDAL(); var plan = plandal.Get(new Entity.FIS.OrderPlan { PID = order.ORDERPLANID }); if (plan == null) { throw new Exception("获取计划信息异常!"); } labeldata.PlanNo = plan.PLAN_NO; if (order.ORDER_TYPE == "0") { var fisdal = new DAL.FIS.FISOrderDAL(); var fis = fisdal.GetByPlan(plan.PLAN_NO, plan.MATERIAL_CODE); if (fis == null) { throw new Exception("获取FIS信息异常!"); } labeldata.VIN = fis.VIN; labeldata.KIN = fis.KIN; } else { labeldata.VIN = "N/A"; labeldata.KIN = "N/A"; } var materialdal = new MD.DAL.MaterialDAL(); var material = materialdal.Get(new MD.Entity.Material { MATERIAL_CODE = order.MATERIAL_CODE }); if (material == null) { throw new Exception("获取物料信息异常!"); } labeldata.HBType = material.HBTYPE; labeldata.ProjectCode = material.PROJECTCODE; labeldata.Color = material.COLOR; labeldata.ProdName = material.MATERIAL_NAME; return labeldata; } /// /// 获取计划标签数据 /// /// /// public Entity.View.PlanLabel GetPlanLabelBindProdut(Product Product) { Entity.View.PlanLabel labeldata = new Entity.View.PlanLabel(); var plandal = new DAL.FIS.OrderPlanDAL(); var plan = plandal.Get(new Entity.FIS.OrderPlan { PID = Product.PLAN_ID }); if (plan == null) { throw new Exception("获取计划信息异常!"); } labeldata.BOM = plan.PBOM_CODE; labeldata.PN = plan.MATERIAL_CODE; labeldata.PlanDate = plan.PLAN_DATE.ToString("yyyy-MM-dd HH:mm:ss"); TWorkOrderDAL dal = new TWorkOrderDAL(); var order = dal.GetOneByProduct(Product.PRODUCTCODE); if (order != null) { labeldata.SEQ = order.SEQ; } else { labeldata.SEQ = "N/A"; } switch (plan.PLANSOURCE) { case "0": { labeldata.PlanType = "FIS"; break; } case "1": { labeldata.PlanType = "STOCK"; break; } case "2": { labeldata.PlanType = "INSERT"; break; } } labeldata.PlanNo = plan.PLAN_NO; if (plan.PLANSOURCE == "0") { var fisdal = new DAL.FIS.FISOrderDAL(); var fis = fisdal.GetByPlan(plan.PLAN_NO, plan.MATERIAL_CODE); if (fis == null) { throw new Exception("获取FIS信息异常!"); } labeldata.VIN = fis.VIN; labeldata.KIN = fis.KIN; } else { labeldata.VIN = "N/A"; labeldata.KIN = "N/A"; } var materialdal = new MD.DAL.MaterialDAL(); var material = materialdal.Get(new MD.Entity.Material { MATERIAL_CODE = plan.MATERIAL_CODE }); if (material == null) { throw new Exception("获取物料信息异常!"); } labeldata.HBType = material.HBTYPE; labeldata.ProjectCode = material.PROJECTCODE; labeldata.Color = material.COLOR; labeldata.ProdName = material.MATERIAL_NAME; return labeldata; } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// 信息 /// true:已存在;fasel:不存在。 public bool Exists(WorkOrder info) { try { return new TWorkOrderDAL().Exists(info); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult Insert(WorkOrder info) { DataResult result = new DataResult(); try { if (string.IsNullOrWhiteSpace(info.PID)) { info.PID = Guid.NewGuid().ToString(); } TWorkOrderDAL cmdDAL = new TWorkOrderDAL(); result.Result = new TWorkOrderDAL().Insert(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// 信息 /// 更新行数 public DataResult Update(WorkOrder info) { DataResult result = new DataResult(); try { result.Result = new TWorkOrderDAL().Update(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } /// /// 挂起工单 /// /// public int SuspendOrder(List orderid) { var orders = GetListByID(orderid.ToArray()); foreach (var order in orders) { if (int.Equals(order.STATE, 2)) { throw new Exception("不可将状态为执行中的工单挂起!"); } order.STATE = 4; } var dal = new TWorkOrderDAL(); return dal.Update(orders); } /// /// 取消挂起 /// /// /// public int CancelSuspend(List orderid) { var orders = GetListByID(orderid.ToArray()); foreach (var order in orders) { if (!int.Equals(order.STATE, 4)) { throw new Exception("只可取消状态为挂起状态的工单!"); } order.STATE = 1; } var dal = new TWorkOrderDAL(); return dal.Update(orders); } /// /// 回收工单 /// /// /// public int TakeBack(List orderid) { var orders = GetListByID(orderid.ToArray()); foreach (var order in orders) { if (!int.Equals(order.STATE, 4)) { throw new Exception("只可回收状态为挂起状态的工单!"); } //order.ORDER_TYPE = "1"; order.PRI = 1; order.STATE = 0; } var dal = new TWorkOrderDAL(); return dal.Update(orders); } /// /// 重置工单 /// /// /// public int ResetOrder(List orderid) { var orders = GetListByID(orderid.ToArray()); var first = orders.FirstOrDefault(); if (first != null) { QMAPP.MD.DAL.WorkCellDAL workCelldal = new QMAPP.MD.DAL.WorkCellDAL(); string pbomcode = first.PBOM_CODE; QMAPP.MD.Entity.ProcessRouteWorkCellSeq workcell = workCelldal.GetFirstWorkCell(pbomcode).FirstOrDefault(); foreach (var order in orders) { if (!int.Equals(order.STATE, 4)) { throw new Exception("只可重置状态为挂起状态的工单!"); } //order.ORDER_TYPE = "1"; order.WORKCELL_CODE = workcell.WORKCELL_CODE; order.PRI = 1; order.STATE = 0; } var dal = new TWorkOrderDAL(); return dal.Update(orders); } return 0; } /// /// 忽略FIS断号 /// /// /// public int IgnoreFISBreak(List orderid) { var orders = GetListByID(orderid.ToArray()); var first = orders.FirstOrDefault(); var plans = new List(); var plandal = new DAL.FIS.OrderPlanDAL(); foreach (var order in orders) { if (!int.Equals(order.ORDER_TYPE, "0")) { throw new Exception("只可对FIS工单进行忽略断号操作!"); } var plan = plandal.Get(new OrderPlan { PID = order.ORDERPLANID }); if (plan != null) { plan.IGNORE_FISBREAK = "1"; plandal.Update(plan); plans.Add(plan); } } return plans.Count; } /// /// 删除工单 /// /// /// public int DeleteOrder(List orderid) { var orders = GetListByID(orderid.ToArray()); foreach (var order in orders) { if (!int.Equals(order.STATE, 4)) { throw new Exception("只可删除状态为挂起状态的工单!"); } //order.STATE = 1; } var dal = new TWorkOrderDAL(); return dal.Delete(orders); } /// /// 根据主键获取列表 /// /// /// private List GetListByID(params string[] orderid) { var dal = new TWorkOrderDAL(); return dal.GetListByID(orderid); } #endregion #region 删除 /// /// 删除信息 /// /// 主键串 /// 删除个数 public DataResult DeleteArray(string strs) { int count = 0; DataResult result = new DataResult(); string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { count += this.Delete(new WorkOrder { PID = str }); } result.Result = count; result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } /// /// 删除信息 /// /// 信息 /// 删除个数 public int Delete(WorkOrder info) { try { return new TWorkOrderDAL().Delete(info); } catch (Exception ex) { throw ex; } } #endregion #region 导出数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(WorkOrder info) { try { return new TWorkOrderDAL().GetExportData(info); } catch (Exception ex) { throw ex; } } #endregion #region 导入数据 /// /// 导入数据 /// /// 数据 /// 导入结果 public DataResult ImportData(List list) { DataResult result = new DataResult(); TWorkOrderDAL cmDal = new TWorkOrderDAL(); List List = new List(); int index = 0; try { result.Result = new ImportMessage(); result.Result.Errors = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { //状态判断 foreach (WorkOrder ma in list) { index++; if (!string.IsNullOrEmpty(ma.InfoError)) { ma.PID = null; result.Result.failureNum += 1; continue; } //修改改时根据主键等信息获取详细内容信息 WorkOrder oldInfo = cmDal.Get(ma); if (oldInfo != null) { //更新 ma.PID = oldInfo.PID; ma.IsNewInfo = false; result.Result.updateNum += 1; } else { //新增 oldInfo = new WorkOrder(); if (string.IsNullOrWhiteSpace(ma.PID)) { ma.PID = Guid.NewGuid().ToString(); } ma.IsNewInfo = true; result.Result.insertNum += 1; } List.Add(ma); } } //导入 cmDal.GetImportData(List); result.Msg = "导入成功"; result.IsSuccess = true; return result; } catch (Exception ex) { result.IsSuccess = false; result.Ex = ex; return result; } } #endregion } }