using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json.Linq; using Opsoft.Data; using Opsoft.NetCore.O3App.Domain; using Opsoft.NetCore.O3App.Domain.Enums.ReportCodes; using Opsoft.NetCore.O3App.Domain.Interface; using Opsoft.NetCore.O3App.Domain.UnitOfWork.BaseData.IRepositories; using Opsoft.NetCore.O3App.Domain.UnitOfWork.IPadReport.IRepositories; using Opsoft.NetCore.O3App.Domain.UnitOfWork.IPadReport.IServices; using Opsoft.NetCore.O3App.Domain.UnitOfWork.IPadReport.Model; using Opsoft.NetCore.O3App.Shared; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; namespace Opsoft.NetCore.O3App.Services.IPadReport { /// /// 汇报信息操作服务层实现 /// [MapTo(typeof(IReportProduceService), ServiceLifetime.Transient)] public class ReportProduceService : ServiceBase, IReportProduceService { private IMemoryCache _cache; private IReportCheckRepository _iReportCheck; private ISysConfigDataRepository _iSysConfigData; private IReportInfoLoadRepository _iReportInfoLoad; private IInspectionRepository _iInspection; /// /// 带注入的构造函数 /// /// public ReportProduceService( IReportProduceRepository repository, IMemoryCache memoryCache, IReportCheckRepository iReportCheckRepository, ISysConfigDataRepository iSysConfigDataRepository, IReportInfoLoadRepository iReportInfoLoadRepository, IInspectionRepository inspectionRepository) : base(repository) { _cache = memoryCache; _iReportCheck = iReportCheckRepository; _iSysConfigData = iSysConfigDataRepository; _iReportInfoLoad = iReportInfoLoadRepository; _iInspection = inspectionRepository; Init(repository); Init(_iReportCheck); Init(_iSysConfigData); Init(_iReportInfoLoad); Init(_iInspection); } #region 员工上下岗操作 /// /// 员工上下岗操作 /// /// /// public async Task SubmitEmployee(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); List emplistData = new List(); //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //barType 1=上岗,2=下岗 //获取数据的类型 if (!paramaters.ContainsKey("basicType")) { throw new O3AppException("【操作类型】传参信息错误,未定义", 400); } //判断数据类型 if (!int.TryParse(paramaters["basicType"].ToStringEx(), out int basicType)) { throw new O3AppException("【操作类型】传参类型错误,值设定有误", 400); } try { #region 参数验证 //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //职员信息为空 if (!paramaters.ContainsKey("data")) { throw new O3AppException("【职员列表】传参信息错误,未定义", 400); } List employeeList = JsonOperator.JsonDeserialize>(paramaters["data"].ToStringEx()); if (employeeList == null || employeeList.Count <= 0) { throw new O3AppException("【职员列表】信息为空", 400); } //班次班组信息获取 string teamNO = string.Empty, shiftNO = string.Empty; if (paramaters.ContainsKey("team")) { teamNO = paramaters["team"].ToStringEx(); } if (paramaters.ContainsKey("shift")) { shiftNO = paramaters["shift"].ToStringEx(); } #endregion #region 数据处理 List listData = null; #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查班组信息 Basic teamData = null; if (!teamNO.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", teamNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { throw new O3AppException($"班组信息【{teamNO}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(teamNO)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!shiftNO.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", shiftNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { throw new O3AppException($"班次信息【{shiftNO}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(shiftNO)); } #endregion #region 检查职员信息 //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)10, out listData); if (listData == null) listData = new List(); foreach (var empNO in employeeList) { if (!listData.Exists(o => o.FNO.Equals(empNO))) { List listDataTemp = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "10" }, { "basicNO", empNO } }); if (listDataTemp.Count <= 0 || !listDataTemp.Exists(o => o.FNO.Equals(empNO))) { throw new O3AppException($"职员信息【{empNO}】未找到", 404); } emplistData.Add(listDataTemp[0]); } else { emplistData.Add(listData.First(o => o.FNO.Equals(empNO))); } } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 检查职员是否已上岗 //1=basicType:上岗操作 if (basicType == 1) { if (reportMsg.EmpDutys.Count > 0) { foreach (var sub in reportMsg.EmpDutys) { if (emplistData.Exists(o => o.FID.Equals(sub.FEmpID))) { throw new O3AppException($"职员信息【{sub.FEmpName}】已上岗", 400); } } } } #endregion #region 使用传递的班组班次信息,给汇报信息赋值 //存在班组班次时,使用传递的值赋值 if (teamData != null) { reportMsg.TeamID = teamData.FID; reportMsg.TeamNO = teamData.FNO; reportMsg.TeamName = teamData.FNAME; } if (shiftData != null) { reportMsg.ShiftID = shiftData.FID; reportMsg.ShiftNO = shiftData.FNO; reportMsg.ShiftName = shiftData.FNAME; } #endregion #region 判断班组、班次是否为空 ,以上岗员工为准重新赋值 //上岗时间 DateTime dateTime = DateTime.Now; if (reportMsg.TeamID.IsNullOrEmpty() && basicType == 1) { //查询班组班次信息 DataTable dtEmpInfo = await _iReportInfoLoad.GetTeamShift(emplistData[0].FID, dateTime); if (dtEmpInfo != null && dtEmpInfo.Rows.Count > 0) { //判断班次班组是否已经有值 if (reportMsg.TeamID.IsNullOrEmpty()) { reportMsg.TeamID = dtEmpInfo.Rows[0]["FTeamID"].ToStringEx(); reportMsg.TeamNO = dtEmpInfo.Rows[0]["FTeamNO"].ToStringEx(); reportMsg.TeamName = dtEmpInfo.Rows[0]["FTeamName"].ToStringEx(); } if (reportMsg.ShiftID.IsNullOrEmpty()) { reportMsg.ShiftID = dtEmpInfo.Rows[0]["FShiftID"].ToStringEx(); reportMsg.ShiftNO = dtEmpInfo.Rows[0]["FShiftNO"].ToStringEx(); reportMsg.ShiftName = dtEmpInfo.Rows[0]["FShiftName"].ToStringEx(); } } } #endregion #region 进行员工上下岗操作 await (repository as IReportProduceRepository).EmpUpDownWork(basicType, emplistData, reportMsg, dateTime); #endregion #region 更新缓存中汇报信息 switch (basicType) { case 1: #region 员工上岗 foreach (var emp in emplistData) { reportMsg.EmpDutys.Add(new EmpDuty { FEmpID = emp.FID, FEmpNumber = emp.FNO, FEmpName = emp.FNAME, FStartTime = dateTime, }); } foreach (var emp in emplistData) { reportMsg.EmpReports.Add(new Employee { FEmpID = emp.FID, FEmpNumber = emp.FNO, FEmpName = emp.FNAME, FStartTime = dateTime, FIsWork = true }); } #endregion break; case 2: #region 员工下岗 foreach (var empNO in employeeList) { var sub = reportMsg.EmpDutys.FirstOrDefault(o => o.FEmpNumber == empNO); if (sub != null) { reportMsg.EmpDutys.Remove(sub); } var subReport = reportMsg.EmpReports.FirstOrDefault(o => o.FEmpNumber == empNO); if (subReport != null) { reportMsg.EmpReports.Remove(subReport); } } break; #endregion } await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, string.Join(",", emplistData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "员工上岗" : "员工下岗"), "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); #endregion } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, string.Join(",", emplistData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "员工上岗" : "员工下岗"), ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; #endregion } #endregion #region 员工上下岗操作(Web) /// /// 员工上下岗操作 /// /// /// public async Task SubmitEmployeeWeb(JObject paramaters) { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //barType 1=上岗,2=下岗 //获取数据的类型 if (!paramaters.ContainsKey("basicType")) { throw new O3AppException("【操作类型】传参信息错误,未定义", 400); } //判断数据类型 if (!int.TryParse(paramaters["basicType"].ToStringEx(), out int basicType)) { throw new O3AppException("【操作类型】传参类型错误,值设定有误", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } List resourceList = JsonOperator.JsonDeserialize>(paramaters["resource"].ToStringEx()); if (resourceList == null || resourceList.Count <= 0) { throw new O3AppException("【资源】信息为空", 400); } //职员信息为空 List employeeList = JsonOperator.JsonDeserialize>(paramaters["data"].ToStringEx()); if (basicType == 1) { if (!paramaters.ContainsKey("data")) { throw new O3AppException("【职员列表】传参信息错误,未定义", 400); } if (employeeList == null || employeeList.Count <= 0) { throw new O3AppException("【职员列表】信息为空", 400); } } //班次班组信息获取 string teamNO = string.Empty, shiftNO = string.Empty; if (paramaters.ContainsKey("team")) { teamNO = paramaters["team"].ToStringEx(); } if (paramaters.ContainsKey("shift")) { shiftNO = paramaters["shift"].ToStringEx(); } #endregion #region 数据处理 List listData = null; #region 检查班组信息 Basic teamData = null; if (!teamNO.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", teamNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { throw new O3AppException($"班组信息【{teamNO}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(teamNO)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!shiftNO.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", shiftNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { throw new O3AppException($"班次信息【{shiftNO}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(shiftNO)); } #endregion #region 检查职员信息 List emplistData = new List(); //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)10, out listData); if (listData == null) listData = new List(); foreach (var empNO in employeeList) { if (!listData.Exists(o => o.FNO.Equals(empNO))) { List listDataTemp = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "10" }, { "basicNO", empNO } }); if (listDataTemp.Count <= 0 || !listDataTemp.Exists(o => o.FNO.Equals(empNO))) { throw new O3AppException($"职员信息【{empNO}】未找到", 404); } emplistData.Add(listDataTemp[0]); } else { emplistData.Add(listData.First(o => o.FNO.Equals(empNO))); } } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } #endregion foreach (string resource in resourceList) { try { await OnAndOffDuty(paramaters, resource, reportData, teamData, shiftData, basicType, emplistData); var reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesNO.Equals(resource)); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, string.Join(",", emplistData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "员工批量上岗" : "员工批量下岗"), "", paramaters["phoneID"].ToStringEx()); } catch (Exception ex) { var reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesNO.Equals(resource)); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, string.Join(",", emplistData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "员工批量上岗" : "员工批量下岗"), ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } } //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); #endregion return "上下岗成功"; } #region 员工上下岗处理过程 public async Task OnAndOffDuty(JObject paramaters, string resource, ReportData reportData, Basic teamData, Basic shiftData, int basicType, List emplistData) { #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), resource); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } var reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #region 使用传递的班组班次信息,给汇报信息赋值 //存在班组班次时,使用传递的值赋值 if (teamData != null) { reportMsg.TeamID = teamData.FID; reportMsg.TeamNO = teamData.FNO; reportMsg.TeamName = teamData.FNAME; } if (shiftData != null) { reportMsg.ShiftID = shiftData.FID; reportMsg.ShiftNO = shiftData.FNO; reportMsg.ShiftName = shiftData.FNAME; } #endregion #region 判断班组、班次是否为空 ,以上岗员工为准重新赋值 //上岗时间 DateTime dateTime = DateTime.Now; if (reportMsg.TeamID.IsNullOrEmpty() && basicType == 1) { //查询班组班次信息 DataTable dtEmpInfo = await _iReportInfoLoad.GetTeamShift(emplistData[0].FID, dateTime); if (dtEmpInfo != null && dtEmpInfo.Rows.Count > 0) { //判断班次班组是否已经有值 if (reportMsg.TeamID.IsNullOrEmpty()) { reportMsg.TeamID = dtEmpInfo.Rows[0]["FTeamID"].ToStringEx(); reportMsg.TeamNO = dtEmpInfo.Rows[0]["FTeamNO"].ToStringEx(); reportMsg.TeamName = dtEmpInfo.Rows[0]["FTeamName"].ToStringEx(); } if (reportMsg.ShiftID.IsNullOrEmpty()) { reportMsg.ShiftID = dtEmpInfo.Rows[0]["FShiftID"].ToStringEx(); reportMsg.ShiftNO = dtEmpInfo.Rows[0]["FShiftNO"].ToStringEx(); reportMsg.ShiftName = dtEmpInfo.Rows[0]["FShiftName"].ToStringEx(); } } } #endregion #region 进行员工上下岗操作 List resourceEmp = await (repository as IReportProduceRepository).EmpUpDownWorkWeb(basicType, emplistData, reportMsg, dateTime); #endregion #region 更新缓存中汇报信息 switch (basicType) { case 1: #region 员工上岗 foreach (var emp in resourceEmp) { reportMsg.EmpDutys.Add(new EmpDuty { FEmpID = emp.FID, FEmpNumber = emp.FNO, FEmpName = emp.FNAME, FStartTime = dateTime, }); } foreach (var emp in resourceEmp) { reportMsg.EmpReports.Add(new Employee { FEmpID = emp.FID, FEmpNumber = emp.FNO, FEmpName = emp.FNAME, FStartTime = dateTime, FIsWork = true }); } #endregion break; case 2: #region 员工下岗 reportMsg.EmpDutys = null; reportMsg.EmpReports = null; break; #endregion } #endregion } #endregion #endregion #region 绑定/解绑设备 /// /// 绑定/解绑设备 /// /// /// public async Task SubmitEmquipment(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); List equipmentData = new List(); //barType 1=绑定,2=重置 //获取数据的类型 if (!paramaters.ContainsKey("basicType")) { throw new O3AppException("【操作类型】传参信息错误,未定义", 400); } //判断数据类型 if (!int.TryParse(paramaters["basicType"].ToStringEx(), out int basicType)) { throw new O3AppException("【操作类型】传参类型错误,值设定有误", 400); } try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //设备信息为空 if (!paramaters.ContainsKey("data")) { throw new O3AppException("【设备列表】传参信息错误,未定义", 400); } List equipmentList = JsonOperator.JsonDeserialize>(paramaters["data"].ToStringEx()); if (equipmentList == null || equipmentList.Count <= 0) { throw new O3AppException("【设备列表】信息为空", 400); } #endregion #region 数据处理 List listData = null; #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查设备信息 listData = new List(); //if (basicType == 1) //{ _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)4, out listData); if (listData == null) listData = new List(); foreach (var equipNO in equipmentList) { if (!listData.Exists(o => o.FNO.Equals(equipNO))) { List listDataTemp = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "4" }, { "basicNO", equipNO } }); if (listDataTemp.Count <= 0 || !listDataTemp.Exists(o => o.FNO.Equals(equipNO))) { throw new O3AppException($"设备信息【{equipNO}】未找到", 404); } equipmentData.Add(listDataTemp[0]); } else { equipmentData.Add(listData.First(o => o.FNO.Equals(equipNO))); } } //} #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } //判断是否已经有上岗信息 if (reportMsg.EmpDutys.Count <= 0) { throw new O3AppException($"资源中上岗信息为空", 400); } #endregion #region 检查设备信息是否绑定 //1=basicType:绑定操作 if (basicType == 1) { if (reportMsg.EquipmentBinds.Count > 0) { foreach (var sub in reportMsg.EquipmentBinds) { if (equipmentData.Exists(o => o.FID.Equals(sub.FID))) { throw new O3AppException($"设备信息【{sub.FNAME}】已绑定", 400); } } } } #endregion #region 进行设备操作 await (repository as IReportProduceRepository).EmquipmentUpDownWork(basicType, equipmentData, reportMsg); #endregion #region 更新缓存中汇报信息 switch (basicType) { case 1: #region 绑定设备 reportMsg.EquipmentBinds = equipmentData; #endregion break; case 2: #region 解绑设备 reportMsg.EquipmentBinds.RemoveAll(o => equipmentList.Exists(q => q == o.FNO)); break; #endregion } await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "设备" + string.Join(",", equipmentData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "绑定" : "解绑"), "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); #endregion #endregion } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "设备" + string.Join(",", equipmentData.Select(s => s.FNAME).ToList()) + (basicType == 1 ? "绑定" : "解绑"), ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; } #endregion #region 工序开工 /// /// 工序开工 /// /// /// public async Task ProcessStartServices(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断班组 string teamNO = string.Empty, shiftNO = string.Empty; if (!paramaters.ContainsKey("team")) { throw new O3AppException("【班组】传参信息错误,未定义", 400); } else { teamNO = paramaters["team"].ToStringEx(); } //判断班次 if (!paramaters.ContainsKey("shift")) { throw new O3AppException("【班次】传参信息错误,未定义", 400); } else { shiftNO = paramaters["shift"].ToStringEx(); } //判断条码类型 if (!paramaters.ContainsKey("barType")) { throw new O3AppException("【条码类型】传参信息错误,未定义", 400); } //判断扫描条码是否传值正确 if (!paramaters.ContainsKey("barCode")) { throw new O3AppException("【扫描条码】传参信息错误,未定义", 400); } if (paramaters["barCode"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【扫描条码】信息为空", 400); } #endregion #region 自定义变量 decimal reportQty = 0; string SQL = string.Empty, flowcardDetailID = string.Empty; List listData = null; #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查班组信息 Basic teamData = null; if (!teamNO.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", teamNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { throw new O3AppException($"班组信息【{teamNO}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(teamNO)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!shiftNO.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", shiftNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { throw new O3AppException($"班次信息【{shiftNO}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(shiftNO)); } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 设置开工模式 //开工模式 switch (Convert.ToInt32(paramaters["barType"])) { case 1: #region 流转卡开工 reportQty = _iReportCheck.CheckFcode(paramaters["barCode"].ToStringEx(), paramaters["resource"].ToStringEx()); break; #endregion case 2: #region 序列号开工 flowcardDetailID = _iReportCheck.CheckSNAndReturnFlowDetailId(resourceID, paramaters["barCode"].ToStringEx(), 1, paramaters["resource"].ToStringEx()); reportQty = 1; break; #endregion case 3: #region 周转码开工 flowcardDetailID = _iReportCheck.CheckTCAndReturnFlowDetailId(resourceID, paramaters["barCode"].ToStringEx(), 1, paramaters["resource"].ToStringEx(), out reportQty); break; #endregion case 4: #region 在制品开工 flowcardDetailID = _iReportCheck.CheckWIPAndReturnFlowDetailId(resourceID, paramaters["barCode"].ToStringEx(), reportMsg, out reportQty); break; #endregion default: throw new O3AppException("当前条码对应的开工模式未定义", 400); } #endregion #region 校验资源是否在当前流转卡中 if (flowcardDetailID.IsNullOrEmpty()) { _iReportCheck.CanResourceUse(1, paramaters["barCode"].ToStringEx(), resourceID, paramaters["resource"].ToStringEx()); } else { _iReportCheck.CanResourceUse(2, flowcardDetailID, resourceID, paramaters["resource"].ToStringEx()); } #endregion #region 预先更新数据类中的汇报信息 reportMsg.ReportStartTimeLength = 0; reportMsg.FInputBarType = paramaters["barType"].ToInt(); reportMsg.FInputBarCode = paramaters["barCode"].ToStringEx(); reportMsg.TeamID = teamData != null ? teamData.FID : ""; reportMsg.TeamNO = teamData != null ? teamData.FNO : ""; reportMsg.TeamName = teamData != null ? teamData.FNAME : ""; reportMsg.ShiftID = shiftData != null ? shiftData.FID : ""; reportMsg.ShiftNO = shiftData != null ? shiftData.FNO : ""; reportMsg.ShiftName = shiftData != null ? shiftData.FNAME : ""; reportMsg.StandPro = Convert.ToDecimal(retDicData["standPro"]); #endregion #region 进行开工操作 paramaters.Add("reportQty", reportQty.ToString()); paramaters.Add("flowcardDetailID", flowcardDetailID); //apserver服务 using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { //开始事务 context.Database.BeginTransaction(); await (repository as IReportProduceRepository).ProcessStartRepository(context, paramaters, reportMsg); //提交事务 context.Database.CommitTransaction(); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } throw ex; } #endregion await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "条码" + reportMsg.FInputBarCode + "开工", "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "条码" + reportMsg.FInputBarCode + "开工", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; } #endregion #region 工序开工(Web) /// /// 工序开工 /// /// /// public async Task ProcessStartServicesWeb(JObject paramaters) { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断批次开工的条码信息是否传值正确 if (!paramaters.ContainsKey("barCodeInfo")) { throw new O3AppException("【批次开工】传参信息错误,未定义", 400); } List batchProcessStarts = paramaters["barCodeInfo"].ToObject>(); if (batchProcessStarts == null || batchProcessStarts.Count <=0) { throw new O3AppException("【批次开工】信息为空", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //apserver服务 using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); foreach (var processStart in batchProcessStarts) { ProductionAct reportMsg = new ProductionAct(); try { if (processStart.barCode.IsNullOrEmpty()) { throw new O3AppException($"资源【{processStart.resource}】:【扫描条码】信息为空", 400); } #region 自定义变量 decimal reportQty = 0; string SQL = string.Empty, flowcardDetailID = string.Empty; List listData = null; #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), processStart.resource); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查班组信息 Basic teamData = null; if (!processStart.team.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(processStart.team))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", processStart.team } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(processStart.team))) { throw new O3AppException($"资源【{processStart.resource}】:班组信息【{processStart.team}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(processStart.team)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!processStart.shift.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(processStart.shift))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", processStart.shift } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(processStart.shift))) { throw new O3AppException($"资源【{processStart.resource}】:班次信息【{processStart.shift}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(processStart.shift)); } #endregion #region 检查汇报记录 //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源【{processStart.resource}】汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源【{processStart.resource}】汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源【{processStart.resource}】中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 设置开工模式 //开工模式 switch (Convert.ToInt32(processStart.barType)) { case 1: #region 流转卡开工 reportQty = _iReportCheck.CheckFcode(processStart.barCode, processStart.resource); break; #endregion case 2: #region 序列号开工 flowcardDetailID = _iReportCheck.CheckSNAndReturnFlowDetailId(resourceID, processStart.barCode, 1, processStart.resource); reportQty = 1; break; #endregion case 3: #region 周转码开工 flowcardDetailID = _iReportCheck.CheckTCAndReturnFlowDetailId(resourceID, processStart.barCode, 1, processStart.resource, out reportQty); break; #endregion case 4: #region 在制品开工 flowcardDetailID = _iReportCheck.CheckWIPAndReturnFlowDetailId(resourceID, processStart.barCode, reportMsg, out reportQty); break; #endregion default: throw new O3AppException($"资源【{processStart.resource}】:当前条码对应的开工模式未定义", 400); } #endregion #region 校验资源是否在当前流转卡中 if (flowcardDetailID.IsNullOrEmpty()) { _iReportCheck.CanResourceUse(1, processStart.barCode, resourceID, processStart.resource); } else { _iReportCheck.CanResourceUse(2, flowcardDetailID, resourceID, processStart.resource); } #endregion #region 预先更新数据类中的汇报信息 reportMsg.ReportStartTimeLength = 0; reportMsg.FInputBarType = processStart.barType.ToInt(); reportMsg.FInputBarCode = processStart.barCode; reportMsg.TeamID = teamData != null ? teamData.FID : ""; reportMsg.TeamNO = teamData != null ? teamData.FNO : ""; reportMsg.TeamName = teamData != null ? teamData.FNAME : ""; reportMsg.ShiftID = shiftData != null ? shiftData.FID : ""; reportMsg.ShiftNO = shiftData != null ? shiftData.FNO : ""; reportMsg.ShiftName = shiftData != null ? shiftData.FNAME : ""; reportMsg.StandPro = Convert.ToDecimal(retDicData["standPro"]); #endregion processStart.reportQty = reportQty.ToDecimal(); processStart.flowcardDetailID = flowcardDetailID; processStart.resourceId = resourceID; await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量开工:条码" + processStart.barCode + "开工校验", "", paramaters["phoneID"].ToStringEx()); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量开工:条码" + processStart.barCode + "开工校验", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } } try { //开始事务 context.Database.BeginTransaction(); foreach (var processStart in batchProcessStarts) { var reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(processStart.resourceId)); try { #region 进行开工操作 await (repository as IReportProduceRepository).ProcessStartWebRepository(context, processStart, reportMsg, paramaters["phoneID"].ToStringEx()); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量开工:条码" + processStart.barCode + "开工", "", paramaters["phoneID"].ToStringEx(), context); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量开工:条码" + processStart.barCode + "开工", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } #endregion } //提交事务 context.Database.CommitTransaction(); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } throw ex; } //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); return "批次开工成功"; } #endregion #region 工序上下模 /// /// 工序上下模PB-HX_TIMEA /// /// /// public async Task ProcessInputMould(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); List mouldData = new List(); //判断上下模类型 if (!paramaters.ContainsKey("isUp")) { throw new O3AppException("【上下模类型】传参信息错误,未定义", 400); } bool isUp = paramaters["isUp"].ToBoolean(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //设模具信息为空 if (!paramaters.ContainsKey("data")) { throw new O3AppException("【模具列表】传参信息错误,未定义", 400); } List mouldList = JsonOperator.JsonDeserialize>(paramaters["data"].ToStringEx()); if (mouldList == null || mouldList.Count <= 0) { throw new O3AppException("【模具列表】信息为空", 400); } #endregion #region 自定义变量 string SQL = string.Empty; #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查汇报记录 DateTime dtNow = DateTime.Now; //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, dtNow); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 检查模具信息 List listData = new List(); _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)12, out listData); if (listData == null) listData = new List(); foreach (var mouldNO in mouldList) { if (!listData.Exists(o => o.FNO.Equals(mouldNO))) { List listDataTemp = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "12" }, { "basicNO", mouldNO } }); if (listDataTemp.Count <= 0 || !listDataTemp.Exists(o => o.FNO.Equals(mouldNO))) { throw new O3AppException($"模具信息【{mouldNO}】未找到", 404); } mouldData.Add(listDataTemp[0]); } else { mouldData.Add(listData.First(o => o.FNO.Equals(mouldNO))); } } if (mouldData.Count <= 0) { throw new O3AppException($"模具信息未找到", 404); } #endregion #region 检查模具是否在流转卡中绑定 if (isUp) { //上模时验证模具状态 _iReportCheck.CheckMouldInFlowCard(mouldData, reportMsg); } else { #region 下模验证模具是否未上模状态 //检验是否已经上模 if (reportMsg.MouldInfos.Count > 0) { foreach (var item in mouldData) { if (!reportMsg.MouldInfos.Exists(o => o.FINTERID.Equals(item.FID) && !o.FENDTIME.HasValue)) { throw new O3AppException($"模具信息【{item.FNAME}】未上模,不可以下模", 500); } } } else { throw new O3AppException($"没有已上模的模治具", 500); } #endregion } #endregion #region 上下模数据处理 await (repository as IReportProduceRepository).ProcessInputMouldRepository(isUp, mouldData, reportMsg); #endregion #region 更新缓存中汇报信息 if (isUp) { foreach (var mould in mouldData) { if (reportMsg.MouldInfos.Exists(o => o.FINTERID == mould.FID && o.FENDTIME.HasValue)) { reportMsg.MouldInfos.FirstOrDefault(o => o.FINTERID == mould.FID && o.FENDTIME.HasValue).FSTARTTIME = dtNow; reportMsg.MouldInfos.FirstOrDefault(o => o.FINTERID == mould.FID && o.FENDTIME.HasValue).FENDTIME = null; } else { reportMsg.MouldInfos.Add(new MouldInfo { FINTERID = mould.FID, FNUMBER = mould.FNO, FNAME = mould.FNAME, FSTARTTIME = dtNow, }); } } var mouldCount = reportMsg.MouldInfos.Where(w => w.FENDTIME.IsNullOrEmpty()).ToList().Count; reportMsg.FIsMouldAll = reportMsg.FMouldCount == mouldCount ? true : false; } else { foreach (var mould in mouldData) { if (reportMsg.MouldInfos.Exists(o => o.FINTERID == mould.FID && !o.FENDTIME.HasValue)) { reportMsg.MouldInfos.FirstOrDefault(o => o.FINTERID == mould.FID && !o.FENDTIME.HasValue).FENDTIME = dtNow; } } reportMsg.FIsMouldAll = false; } #endregion await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "模具" + string.Join(",", mouldData.Select(s => s.FNAME).ToList()) + (isUp ? "工序上模" : "工序下模"), "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "模具" + string.Join(",", mouldData.Select(s => s.FNAME).ToList()) + (isUp ? "工序上模" : "工序下模"), ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; } #endregion #region 工序投料 /// /// 工序投料 /// /// /// public async Task ProcessInputMaterialServices(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断条码类型 if (!paramaters.ContainsKey("barType")) { throw new O3AppException("【条码类型】传参信息错误,未定义", 400); } if (paramaters["barType"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【条码类型】信息为空", 400); } //条码信息 if (!paramaters.ContainsKey("barCode")) { throw new O3AppException("【条码】传参信息错误,未定义", 400); } if (paramaters["barCode"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【条码】信息为空", 400); } //条码数量 if (!paramaters.ContainsKey("fQty")) { throw new O3AppException("【条码数量】传参信息错误,未定义", 400); } if (paramaters["fQty"].ToStringEx().IsNullOrEmpty() || paramaters["fQty"].ToDecimal() < 1) { throw new O3AppException("【条码数量】应该大于0", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查汇报记录 DateTime dtNow = DateTime.Now; //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, dtNow); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } //if (!reportMsg.FIsFeed) //{ // throw new O3AppException($"当前资源汇报无需投料", 404); //} if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } if (reportMsg.FReportID.IsNullOrEmpty()) { throw new O3AppException($"当前资源汇报信息为空,请重新加载", 404); } //投料需要人员上岗 if (reportMsg.EmpDutys.Count <= 0) { throw new O3AppException($"当前资源中上岗信息为空", 404); } #endregion #region 投料信息检查 Dictionary receiveData = _iReportCheck.CheckUseMaterialInfo(paramaters, reportMsg); #endregion await (repository as IReportProduceRepository).ProcessInputMaterialRepository(receiveData, paramaters, reportMsg); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "物料条码" + paramaters["barCode"].ToStringEx() + "工序投料", "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "物料条码" + paramaters["barCode"].ToStringEx() + "工序投料", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; } #endregion #region 安灯呼叫 /// /// 安灯呼叫 /// /// /// public async Task ProcessWarningCallServices(JObject paramaters) { Basic callData = null; ProductionAct reportMsg = new ProductionAct(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断汇报ID if (!paramaters.ContainsKey("reportID")) { throw new O3AppException("【汇报ID】传参信息错误,未定义", 400); } if (paramaters["reportID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【汇报ID】信息为空", 400); } //工序识别码 if (!paramaters.ContainsKey("fCode")) { throw new O3AppException("【工序识别码】传参信息错误,未定义", 400); } if (paramaters["fCode"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【工序识别码】信息为空", 400); } //呼叫代码 if (!paramaters.ContainsKey("callNO")) { throw new O3AppException("【呼叫代码】传参信息错误,未定义", 400); } if (paramaters["callNO"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【呼叫代码】信息为空", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; //汇报ID是否一致 if (!reportID.Equals(paramaters["reportID"].ToStringEx())) { throw new O3AppException("当前资源中汇报ID和系统中汇报ID不同", 500); } #endregion #region 检查呼叫类别信息 List listData = new List(); if (!paramaters["callNO"].ToStringEx().IsNullOrEmpty()) { _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)14, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(paramaters["callNO"].ToStringEx()))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "14" }, { "basicNO", paramaters["callNO"].ToStringEx() } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(paramaters["callNO"].ToStringEx()))) { throw new O3AppException($"呼叫类别信息【{paramaters["callNO"].ToStringEx()}】未找到", 404); } callData = listData.First(o => o.FNO.Equals(paramaters["callNO"].ToStringEx())); } #endregion #region 检查汇报记录 DateTime dtNow = DateTime.Now; //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, dtNow); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } if (reportMsg.FReportID.IsNullOrEmpty()) { throw new O3AppException($"当前资源汇报信息为空,请重新加载", 404); } //投料需要人员上岗 if (reportMsg.EmpDutys.Count <= 0) { throw new O3AppException($"当前资源中上岗信息为空", 404); } #endregion await (repository as IReportProduceRepository).ProcessWarningCallRepository(callData, reportMsg); reportMsg.AndonCallInfos = await _iInspection.GetAbnormalCallResource(resourceID); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "安灯呼叫:" + callData.FNAME, "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { if (!callData.IsNullOrEmpty()) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "安灯呼叫:" + callData.FNAME, ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); } throw ex; } return reportMsg; } #endregion #region 安灯异常呼叫处理(Web) /// /// 安灯异常呼叫处理(Web) /// /// /// public async Task DoAbnormalCallWeb(DoAbnormalCall SData) { ProductionAct reportMsg = new ProductionAct(); try { if (SData.DoType == null) { throw new O3AppException("传参信息错误,操作类型未定义", 400); } if (SData.ListFInterID == null) { throw new O3AppException("传参信息错误,内码列表未定义", 400); } //安灯内码列表 List listFInterID = SData.ListFInterID; if (listFInterID.Count == 0) { throw new O3AppException("未勾选需要操作的数据", 400); } //判断值是否为空 if (SData.DoType.ToStringEx() == "") { throw new O3AppException("操作类型为空", 400); } if (SData.phoneID.IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } if (SData.resource.IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } if (SData.reportID.IsNullOrEmpty()) { throw new O3AppException("【汇报ID】信息为空", 400); } #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(SData.phoneID, SData.resource); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; //汇报ID是否一致 if (!reportID.Equals(SData.reportID)) { throw new O3AppException("当前资源中汇报ID和系统中汇报ID不同", 500); } #endregion #region 检查汇报记录 DateTime dtNow = DateTime.Now; //汇报缓存key string cacheName = LoginInfo.DBAias + SData.phoneID; if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(SData.phoneID, LoginInfo.UserID, dtNow); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(SData.phoneID, resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } if (reportMsg.FReportID.IsNullOrEmpty()) { throw new O3AppException($"当前资源汇报信息为空,请重新加载", 404); } //投料需要人员上岗 if (reportMsg.EmpDutys.Count <= 0) { throw new O3AppException($"当前资源中上岗信息为空", 404); } #endregion if (SData.DoType.ToStringEx() == "2") { if (SData.IsDule == null) { throw new O3AppException("传参信息错误,是否处理未定义", 400); } if (SData.IsDule.ToStringEx().ToBoolean()) { //需要处理的操作,需要处理人等信息 if (SData.DuleUserID == null) { throw new O3AppException("传参信息错误,处理人未定义", 400); } if (SData.DuleTime == null) { throw new O3AppException("传参信息错误,处理时间未定义", 400); } if (SData.DuleResult == null) { throw new O3AppException("传参信息错误,处理结果未定义", 400); } if (SData.DuleTime.ToStringEx().IsNullOrEmpty()) { throw new O3AppException("处理时间为空", 400); } } } await _iInspection.DoAbnormalCall(SData); reportMsg.AndonCallInfos = await _iInspection.GetAbnormalCallResource(resourceID); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "安灯呼叫" + (SData.DoType.ToStringEx() == "1" ? "响应" : "关闭"), "", SData.phoneID); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "安灯呼叫" + (SData.DoType.ToStringEx() == "1" ? "响应" : "关闭"), ex.Message.ToStringEx(), SData.phoneID); throw ex; } return "保存成功"; } #endregion #region 生产汇报前检查检验状态 /// /// 生产汇报前检查检验状态 /// /// /// public async Task CheckInspectionStatusServices(Dictionary paramaters) { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion #region 检查汇报记录 DateTime dtNow = DateTime.Now; //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, dtNow); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } var reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } if (reportMsg.FReportID.IsNullOrEmpty()) { throw new O3AppException($"当前资源汇报信息为空,请重新加载", 404); } //投料需要人员上岗 if (reportMsg.EmpDutys.Count <= 0) { throw new O3AppException($"当前资源中上岗信息为空", 404); } #endregion #region 验证首检、巡检状态 _iReportCheck.CheckInspectionStatus(reportMsg); #endregion return "检查通过"; } #endregion #region 工序换型,工序调机,工序暂停 /// /// 工序换型,工序调机,工序暂停 /// /// /// public async Task ProcessChangeStateServices(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); string operateType = string.Empty; try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断操作类型 1=工序换型, 2=工序调机,3=工序暂停, 4=结束暂停 if (!paramaters.ContainsKey("basicType")) { throw new O3AppException("【操作类型】传参信息错误,未定义", 400); } //判断数据类型 if (!int.TryParse(paramaters["basicType"].ToStringEx(), out int basicType)) { throw new O3AppException("【操作类型】传参类型错误,值设定有误", 400); } #endregion //班次班组信息获取 string teamNO = string.Empty, shiftNO = string.Empty; if (paramaters.ContainsKey("team")) { teamNO = paramaters["team"].ToStringEx(); } if (paramaters.ContainsKey("shift")) { shiftNO = paramaters["shift"].ToStringEx(); } #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; #endregion List listData = null; #region 检查班组信息 Basic teamData = null; if (!teamNO.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", teamNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { throw new O3AppException($"班组信息【{teamNO}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(teamNO)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!shiftNO.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", shiftNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { throw new O3AppException($"班次信息【{shiftNO}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(shiftNO)); } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 使用传递的班组班次信息,给汇报信息赋值 //存在班组班次时,使用传递的值赋值 if (teamData != null) { reportMsg.TeamID = teamData.FID; reportMsg.TeamNO = teamData.FNO; reportMsg.TeamName = teamData.FNAME; } if (shiftData != null) { reportMsg.ShiftID = shiftData.FID; reportMsg.ShiftNO = shiftData.FNO; reportMsg.ShiftName = shiftData.FNAME; } #endregion #region 判断班组、班次是否为空 ,以上岗员工为准重新赋值 //上岗时间 DateTime dateTime = DateTime.Now; if (reportMsg.TeamID.IsNullOrEmpty() && reportMsg.EmpDutys.Count > 0) { //查询班组班次信息 DataTable dtEmpInfo = await _iReportInfoLoad.GetTeamShift(reportMsg.EmpDutys[0].FEmpID, dateTime); if (dtEmpInfo != null && dtEmpInfo.Rows.Count > 0) { //判断班次班组是否已经有值 if (reportMsg.TeamID.IsNullOrEmpty()) { reportMsg.TeamID = dtEmpInfo.Rows[0]["FTeamID"].ToStringEx(); reportMsg.TeamNO = dtEmpInfo.Rows[0]["FTeamNO"].ToStringEx(); reportMsg.TeamName = dtEmpInfo.Rows[0]["FTeamName"].ToStringEx(); } if (reportMsg.ShiftID.IsNullOrEmpty()) { reportMsg.ShiftID = dtEmpInfo.Rows[0]["FShiftID"].ToStringEx(); reportMsg.ShiftNO = dtEmpInfo.Rows[0]["FShiftNO"].ToStringEx(); reportMsg.ShiftName = dtEmpInfo.Rows[0]["FShiftName"].ToStringEx(); } } } #endregion #region 工序状态变更 //操作模式 switch (paramaters["basicType"].ToInt()) { case 1: #region 工序换型 if (reportMsg.FIsUpperMold && reportMsg.MouldInfos.Count <= 0) { throw new Exception("当前工序必须上模"); } operateType = "工序换型"; await (repository as IReportProduceRepository).ProcessRemodelRepository(reportMsg); break; #endregion case 2: #region 工序调机 if (reportMsg.FIsUpperMold && reportMsg.MouldInfos.Count <= 0) { throw new Exception("当前工序必须上模"); } if (reportMsg.FIsFeed) { var remainder = reportMsg.MatInventorys.FirstOrDefault(s => s.FQty <= 0); if (!remainder.IsNullOrEmpty()) throw new Exception("工序所投料不齐全"); } //需要首检时,则为检验方案数据 DataTable dtInspection = _iReportCheck.CheckInspectSolution(reportMsg); operateType = "工序调机"; await (repository as IReportProduceRepository).ProcessDebugMachineRepository(dtInspection, reportMsg); break; #endregion case 3: #region 工序暂停 if (reportMsg.FDataStatus.Equals("H") || reportMsg.FDataStatus.Equals("F") || reportMsg.FDataStatus.Equals("K") || reportMsg.FDataStatus.Equals("L")) { throw new O3AppException("当前资源处于安灯停工状态,不能工序暂停", 400); } operateType = "工序暂停"; await (repository as IReportProduceRepository).ProcessPauseRepository(paramaters, reportMsg); break; #endregion case 4: #region 结束暂停 operateType = "结束暂停"; await (repository as IReportProduceRepository).ProcessPauseOverRepository(reportMsg); break; #endregion default: throw new O3AppException("当前操作模式未定义", 400); } #endregion //数据重新添加到缓存中 await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, operateType, "", paramaters["phoneID"].ToStringEx()); _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, operateType, ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportMsg; } #endregion #region 完工注销 /// /// 完工注销 /// /// /// public async Task ProcessAllCancelServices(JObject paramaters) { List reportListTempp = new List(); ProductionAct reportMsg = new ProductionAct(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断汇报内码是否传值正确 if (!paramaters.ContainsKey("reportID")) { throw new O3AppException("【汇报内码】传参信息错误,未定义", 400); } if (paramaters["reportID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【汇报内码】信息为空", 400); } //判断工序识别码是否传值正确 if (!paramaters.ContainsKey("fCode")) { throw new O3AppException("【工序识别码】传参信息错误,未定义", 400); } if (paramaters["fCode"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【工序识别码】信息为空", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; if (!reportID.Equals(paramaters["reportID"].ToStringEx())) { throw new O3AppException("当前资源中汇报ID和系统中汇报ID不同", 500); } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 更新汇报记录 DataTable dtFlowCard = _iReportCheck.CheckFlowCardInfo(paramaters["fCode"].ToStringEx(), 1, paramaters["resource"].ToStringEx()); //0表示工序汇报,1表示完工注销 //await (repository as IReportProduceRepository).ProcessAllCancelRepository(dtFlowCard, reportMsg); //apserver服务 using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { //开始事务 context.Database.BeginTransaction(); await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); //提交事务 context.Database.CommitTransaction(); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } throw ex; } #endregion #region 重新加载内存汇报信息 reportListTempp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); //判断数据是否存在 if (reportListTempp == null || reportListTempp.Count == 0) { throw new O3AppException("当前资源汇报信息未找到,请重新加载", 404); } else { //移除现有项,再添加 reportData.AllReport.Remove(reportMsg); reportData.AllReport.Add(reportListTempp[0]); } #endregion //数据重新添加到缓存中 await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "完工注销", "", paramaters["phoneID"].ToStringEx()); _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "完工注销", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } return reportListTempp[0]; } #endregion #region 完工注销(Web) /// /// 完工注销(Web) /// /// /// public async Task ProcessAllCancelServicesWeb(JObject paramaters) { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断批次完工注销是否传值正确 if (!paramaters.ContainsKey("barCodeInfo")) { throw new O3AppException("【批次完工注销】传参信息错误,未定义", 400); } List batchProcessCancels = paramaters["barCodeInfo"].ToObject>(); if (batchProcessCancels == null || batchProcessCancels.Count <= 0) { throw new O3AppException("【批次完工注销】信息为空", 400); } #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //apserver服务 using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); List> listResource = new List>(); foreach (var batchProcessCancel in batchProcessCancels) { ProductionAct reportMsg = new ProductionAct(); try { //判断资源是否传值正确 if (batchProcessCancel.resource.IsNullOrEmpty()) { throw new O3AppException($"资源【{batchProcessCancel.resource}】:【资源】信息为空", 400); } //判断汇报内码是否传值正确 if (batchProcessCancel.reportID.IsNullOrEmpty()) { throw new O3AppException($"资源【{batchProcessCancel.resource}】:【汇报内码】信息为空", 400); } //判断工序识别码是否传值正确 if (batchProcessCancel.fCode.IsNullOrEmpty()) { throw new O3AppException($"资源【{batchProcessCancel.resource}】:【工序识别码】信息为空", 400); } #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), batchProcessCancel.resource); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; if (!reportID.Equals(batchProcessCancel.reportID)) { throw new O3AppException($"当前资源【{batchProcessCancel.resource}】中汇报ID和系统中汇报ID不同", 500); } #endregion #region 检查汇报记录 //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源【{batchProcessCancel.resource}】汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源【{batchProcessCancel.resource}】汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源【{batchProcessCancel.resource}】中汇报ID和缓存中汇报ID不同", 400); } } #endregion DataTable dtFlowCard = _iReportCheck.CheckFlowCardInfo(batchProcessCancel.fCode, 1, batchProcessCancel.resource); //0表示工序汇报,1表示完工注销 Dictionary keyValues = new Dictionary(); keyValues.Add("resID", resourceID); keyValues.Add("resNo", batchProcessCancel.resource); keyValues.Add("resReportMsg", reportMsg); keyValues.Add("resFlowCard", dtFlowCard); listResource.Add(keyValues); await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量完工注销校验", "", paramaters["phoneID"].ToStringEx()); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量完工注销校验", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } } try { //开始事务 context.Database.BeginTransaction(); foreach (var resItem in listResource) { ProductionAct reportMsg = resItem["resReportMsg"] as ProductionAct; try { #region 更新汇报记录 await (repository as IReportProduceRepository).AutoProcessAllCancel(context, resItem["resFlowCard"] as DataTable, resItem["resReportMsg"] as ProductionAct); #endregion await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量完工注销", "", paramaters["phoneID"].ToStringEx(), context); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "批量完工注销", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw ex; } } //提交事务 context.Database.CommitTransaction(); } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } throw ex; } #region 重新加载内存汇报信息 foreach (var resItem in listResource) { List reportListTempp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resItem["resID"].ToStringEx()); //判断数据是否存在 if (reportListTempp == null || reportListTempp.Count == 0) { throw new O3AppException($"当前资源{resItem["resNo"].ToStringEx()}汇报信息未找到,请重新加载", 404); } else { //移除现有项,再添加 reportData.AllReport.Remove(resItem["resReportMsg"] as ProductionAct); reportData.AllReport.Add(reportListTempp[0]); } } #endregion //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); return "批次完工注销成功"; } #endregion #region 工序/调机汇报 /// /// 工序汇报 /// /// /// public async Task ProcessReportServices(JObject paramaters) { ProductionAct reportMsg = new ProductionAct(); ReportClass reportClass = new ReportClass(); try { #region 参数验证 //判断手机ID是否传参 if (!paramaters.ContainsKey("phoneID")) { throw new O3AppException("【手机ID】传参信息错误,未定义", 400); } if (paramaters["phoneID"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【手机ID】信息为空", 400); } //判断资源是否传值正确 if (!paramaters.ContainsKey("resource")) { throw new O3AppException("【资源】传参信息错误,未定义", 400); } if (paramaters["resource"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【资源】信息为空", 400); } //判断班组 string teamNO = string.Empty, shiftNO = string.Empty; if (!paramaters.ContainsKey("team")) { throw new O3AppException("【班组】传参信息错误,未定义", 400); } if (paramaters["team"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【班组】信息为空", 400); } else { teamNO = paramaters["team"].ToStringEx(); } //判断班次 if (!paramaters.ContainsKey("shift")) { throw new O3AppException("【班次】传参信息错误,未定义", 400); } if (paramaters["shift"].ToStringEx().IsNullOrEmpty()) { throw new O3AppException("【班次】信息为空", 400); } else { shiftNO = paramaters["shift"].ToStringEx(); } //汇报关闭状态 if (!paramaters.ContainsKey("isClose")) { throw new O3AppException("【汇报状态】传参信息错误,未定义", 400); } if (!int.TryParse(paramaters["isClose"].ToStringEx(), out int isClose)) { throw new O3AppException("【汇报状态】传参类型错误,值设定有误", 400); } //汇报信息 if (!paramaters.ContainsKey("submitData")) { throw new O3AppException("【汇报信息】传参信息错误,未定义", 400); } //汇报不良信息 if (!paramaters.ContainsKey("data")) { throw new O3AppException("【汇报不良信息】传参信息错误,未定义", 400); } //参数值获取 //汇报信息 reportClass = paramaters["submitData"].ToObject(); #endregion #region 自定义变量 List listData = null; #endregion #region 检查系统参数 if (!ReportParams.IsIni) { throw new O3AppException("系统参数加载已失效,请重新登录", 500); } #endregion #region 检查资源信息 Dictionary retDicData = _iReportCheck.JudgeResourceIsUsed(paramaters["phoneID"].ToStringEx(), paramaters["resource"].ToStringEx()); string resourceID = retDicData["resourceID"]; string reportID = retDicData["reportID"]; if (!reportID.Equals(reportClass.FReportID)) { throw new O3AppException("当前资源中汇报ID和系统中汇报ID不同", 500); } #endregion #region 检查班组信息 Basic teamData = null; if (!teamNO.IsNullOrEmpty()) { //获取班组缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)8, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "8" }, { "basicNO", teamNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(teamNO))) { throw new O3AppException($"班组信息【{teamNO}】未找到", 404); } teamData = listData.First(o => o.FNO.Equals(teamNO)); } #endregion #region 检查班次信息 Basic shiftData = null; if (!shiftNO.IsNullOrEmpty()) { //获取班次缓存 _cache.TryGetValue(LoginInfo.DBAias + (BasicTableName)9, out listData); if (listData == null) listData = new List(); if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { listData = await _iSysConfigData.QueryALLResource(new Dictionary { { "basicType", "9" }, { "basicNO", shiftNO } }); } if (listData.Count <= 0 || !listData.Exists(o => o.FNO.Equals(shiftNO))) { throw new O3AppException($"班次信息【{shiftNO}】未找到", 404); } shiftData = listData.First(o => o.FNO.Equals(shiftNO)); } #endregion #region 检查汇报记录 //汇报缓存key string cacheName = LoginInfo.DBAias + paramaters["phoneID"].ToStringEx(); if (!_cache.TryGetValue(cacheName, out ReportData reportData)) { reportData = new ReportData(paramaters["phoneID"].ToStringEx(), LoginInfo.UserID, DateTime.Now); } //不存在当前资源信息时,重新拉取 if (!reportData.AllReport.Exists(o => o.ResourcesID.Equals(resourceID))) { //获取设备资源信息 List reportListTemp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); if (reportListTemp == null || reportListTemp.Count == 0) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } else { reportData.AllReport.Add(reportListTemp[0]); } } reportMsg = reportData.AllReport.FirstOrDefault(o => o.ResourcesID.Equals(resourceID)); if (reportMsg == null) { throw new O3AppException($"当前资源汇报信息未找到,请重新加载", 404); } if (!reportID.IsNullOrEmpty()) { if (!reportID.Equals(reportMsg.FReportID)) { throw new O3AppException($"资源中汇报ID和缓存中汇报ID不同", 400); } } #endregion #region 校验工序状态、已经获取数据 DataTable dtFlowCard = _iReportCheck.CheckFlowCardInfo(reportMsg.FCode, 0, paramaters["resource"].ToStringEx(), true, reportClass); //0表示工序汇报,1表示完工注销 #endregion #region 使用传递的班组班次信息,给汇报信息赋值 //存在班组班次时,使用传递的值赋值 if (teamData != null) { reportMsg.TeamID = teamData.FID; reportMsg.TeamNO = teamData.FNO; reportMsg.TeamName = teamData.FNAME; } if (shiftData != null) { reportMsg.ShiftID = shiftData.FID; reportMsg.ShiftNO = shiftData.FNO; reportMsg.ShiftName = shiftData.FNAME; } #endregion #region 汇报模式 // 汇报模式 1=手工汇报;2=单件汇报;3=序列号汇报;4=周转码汇报;5=脉冲信号汇报 switch (dtFlowCard.Rows[0]["FREPORTMODE"].ToInt()) { case 1: #region 手工汇报 //无需验证 break; #endregion case 2: #region 单件汇报 //单件汇报数量只能为1 //if (reportClass.FPassQty + reportClass.FBadQty > 1) //{ throw new O3AppException("单件汇报:但是汇报数量不为1,请确认!", 500); } #endregion break; case 3: #region 序列号汇报 //判断本次开工是否已经汇报过 //if (reportMsg.FReportedQty > 0) //{ throw new O3AppException("序列号汇报:已经汇报过不能再进行汇报,请确认!", 500); } //序列号汇报,数量只能为1 //if (reportClass.FPassQty + reportClass.FBadQty > 1) //{ throw new O3AppException("序列号汇报:但是汇报数量不为1,请确认!", 500); } break; #endregion case 4: #region 周转码汇报 if (reportMsg.FInputBarType != 3) { throw new O3AppException("当前为周转码汇报,但不是以周转码开工的,请确认!", 500); } break; #endregion } #endregion //apserver服务 using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { //开始事务 context.Database.BeginTransaction(); if (paramaters["basicType"].ToInt() == 2) //调机汇报 { if (dtFlowCard.Rows[0]["FISHEADQC"].ToBoolean()) { await (repository as IReportProduceRepository).CreateFirstInspectionBillRepository(context, dtFlowCard, reportMsg, reportClass); } } else { if (reportClass.FPassQty + reportClass.FBadQty == 0) { throw new O3AppException("【汇报数据】合格数+不合格数为0,不能汇报", 400); } #region 首检、巡检检查 _iReportCheck.CheckInspectionStatus(reportMsg); #endregion } Dictionary res = new Dictionary(); DataTable snQtyInfo = new DataTable(); switch (reportMsg.FReportMode) { case 1: case 2: if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 3) { snQtyInfo = _iReportCheck.DoCheckTCBeforeReport(reportMsg, reportClass, paramaters["basicType"].ToInt()); } if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 4) { snQtyInfo = _iReportCheck.DoCheckWipBeforeReport(reportMsg, reportClass, paramaters["basicType"].ToInt()); } res = await (repository as IReportProduceRepository).ProcessBatchReportRepository(context, paramaters, dtFlowCard, reportMsg, snQtyInfo, paramaters["basicType"].ToInt()); break; case 3: if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 3) { snQtyInfo = _iReportCheck.DoCheckTCBeforeReport(reportMsg, reportClass, paramaters["basicType"].ToInt()); } if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 4) { snQtyInfo = _iReportCheck.DoCheckWipBeforeReport(reportMsg, reportClass, paramaters["basicType"].ToInt()); } //SN汇报列表 List reportSnList = paramaters["data"].ToObject>(); foreach (var item in reportSnList) { _iReportCheck.CheckSnReport(reportMsg, reportClass, dtFlowCard, item.FSNCode, paramaters["basicType"].ToInt()); } res = await (repository as IReportProduceRepository).ProcessSNReportRepository(context, paramaters, dtFlowCard, reportMsg, snQtyInfo, paramaters["basicType"].ToInt()); break; case 4: snQtyInfo = _iReportCheck.DoCheckTCBeforeReport(reportMsg, reportClass, paramaters["basicType"].ToInt()); res = await (repository as IReportProduceRepository).ProcessTCReportRepository(context, paramaters, dtFlowCard, reportMsg, snQtyInfo, paramaters["basicType"].ToInt()); break; } await (repository as IReportProduceRepository).CommonAfterReportRepository(context, paramaters, dtFlowCard, reportMsg, res); bool cancelRes = false; //完工注销 switch (reportMsg.FReportMode) { case 1: case 2: if ((dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 3 && snQtyInfo.Rows[0]["FTOTQUAQTY"].ToDecimal() + reportClass.FPassQty + reportClass.FBadQty == snQtyInfo.Rows[0]["FQTY"].ToDecimal()) || (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 4 && snQtyInfo.Rows[0]["FTOTQTY"].ToDecimal() + reportClass.FPassQty + reportClass.FBadQty == snQtyInfo.Rows[0]["FQTY"].ToDecimal())) { cancelRes = await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); } if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 1 && res["isComplete"].ToBoolean()) { if (ReportParams.FIsCloseAfterReport) { cancelRes = await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); } } break; case 3: if ((dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 2 && reportClass.FPassQty + reportClass.FBadQty == 1) || (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 3 && snQtyInfo.Rows[0]["FTOTQUAQTY"].ToDecimal() + reportClass.FPassQty + reportClass.FBadQty == snQtyInfo.Rows[0]["FQTY"].ToDecimal()) || (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 4 && snQtyInfo.Rows[0]["FTOTQTY"].ToDecimal() + reportClass.FPassQty + reportClass.FBadQty == snQtyInfo.Rows[0]["FQTY"].ToDecimal()) ) { cancelRes = await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); } if (dtFlowCard.Rows[0]["FSTARTMODE"].ToInt() == 1 && res["isComplete"].ToBoolean()) { if (ReportParams.FIsCloseAfterReport) { cancelRes = await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); } } break; case 4: if (snQtyInfo.Rows[0]["FTOTQUAQTY"].ToDecimal() + reportClass.FPassQty + reportClass.FBadQty == snQtyInfo.Rows[0]["FQTY"].ToDecimal()) { cancelRes = await (repository as IReportProduceRepository).AutoProcessAllCancel(context, dtFlowCard, reportMsg); } break; } //提交事务 context.Database.CommitTransaction(); #region 完工注销重新加载内存汇报信息 if (cancelRes) { List reportListTempp = await _iReportInfoLoad.GetReportDataFromDB(paramaters["phoneID"].ToStringEx(), resourceID); //判断数据是否存在 if (reportListTempp == null || reportListTempp.Count == 0) { throw new O3AppException("当前资源汇报信息未找到,请重新加载", 404); } else { //移除现有项,再添加 reportMsg = reportListTempp[0]; } } #endregion } catch (Exception ex) { if (context.Database.CurrentTransaction != null) { context.Database.RollbackTransaction(); } throw ex; } #region 记录工序汇报信息 //bool isOver = await (repository as IReportProduceRepository).ProcessReportRepository(paramaters, dtFlowCard, reportMsg); #endregion await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "汇报(合格数:" + reportClass.FPassQty + "不良数:" + reportClass.FBadQty + ")", "", paramaters["phoneID"].ToStringEx()); //数据重新添加到缓存中 _cache.Remove(cacheName); _cache.Set(cacheName, reportData, TimeSpan.FromMinutes(60)); } catch (Exception ex) { await (repository as IReportProduceRepository).ProcessLogRepository(reportMsg, "汇报(合格数:" + reportClass.FPassQty + "不良数:" + reportClass.FBadQty + ")", ex.Message.ToStringEx(), paramaters["phoneID"].ToStringEx()); throw; } return reportMsg; } #endregion } }