| | |
| | | using System.Reflection; |
| | | using Dm.filter; |
| | | using System.Dynamic; |
| | | using System.Data.Entity.Core.Metadata.Edm; |
| | | using SqlSugar; |
| | | |
| | | namespace Tiger.Business.MES |
| | | { |
| | |
| | | try |
| | | { |
| | | |
| | | List<T> list = JsonConvert.DeserializeObject<List<T>>(input.EntityJson); |
| | | DbClient db = Biz.Db; |
| | | if (list.Any()) |
| | | List<BIZ_MES_WO_BATCH> list = JsonConvert.DeserializeObject<List<BIZ_MES_WO_BATCH>>(input.EntityJson); |
| | | List<BIZ_MES_WO> woList = new List<BIZ_MES_WO>(); |
| | | if (!list.Any(q => q.VALIDATION_TYPE == "异常")) |
| | | { |
| | | if (list.Count > 100) |
| | | foreach (var item in list) |
| | | { |
| | | db.Utilities.PageEach(list, 100, pageList => |
| | | item.ID = Guid.NewGuid().ToString("N"); |
| | | if (item.VALIDATION_TYPE == "新增") |
| | | { |
| | | var y = db.Storageable(pageList) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.ExecuteCommand(); |
| | | }); |
| | | var _batchWos = await Biz.Db.Queryable<V_MES_WO_BATCH>().Where(x => x.ORDER_NO == item.ORDER_NO).ToListAsync(); |
| | | if (_batchWos.Count > 0) |
| | | { |
| | | item.BATCH_NO = $"{item.ORDER_NO}-{(_batchWos.Max(x => x.BATCH) + 1).ToString("D2")}"; |
| | | } |
| | | else |
| | | { |
| | | item.BATCH_NO = $"{item.ORDER_NO}-01"; |
| | | } |
| | | } |
| | | BIZ_MES_WO wo = Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == item.ORDER_NO).First(); |
| | | if (wo != null) |
| | | { |
| | | wo.PLAN_DATE = (wo.PLAN_DATE ?? "") + ((wo.PLAN_DATE ?? "").Contains(item.PLAN_DATE.ToString("yyyy-MM-dd")) ? "" : $",{item.PLAN_DATE.ToString("yyyy-MM-dd")}"); |
| | | item.ITEM_CODE = wo.ITEM_CODE; |
| | | item.CUST_CODE = wo.CUST_CODE; |
| | | woList.Add(wo); |
| | | } |
| | | } |
| | | else |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | var s = db.Storageable(list) |
| | | .ToStorage(); |
| | | s.AsInsertable.ExecuteCommand(); |
| | | s.AsUpdateable.ExecuteCommand(); |
| | | if (list.Count > 100) |
| | | { |
| | | db.Utilities.PageEach(list, 100, pageList => |
| | | { |
| | | var y = db.Storageable(pageList) |
| | | .WhereColumns(t => new { t.ORDER_NO, t.PLAN_DATE, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | var s = db.Storageable(list) |
| | | .WhereColumns(t => new { t.ORDER_NO, t.PLAN_DATE, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | s.AsInsertable.ExecuteCommand(); |
| | | s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | db.Updateable(woList).UpdateColumns(x => new { x.PLAN_DATE }).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"保存批次工单异常"); |
| | | } |
| | | } |
| | | |
| | | else |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new("导入数据有异常,不能导入!"); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | |
| | | /// <param name="newEntity"></param> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<List<T>>> ValidateTableImport<T>(T newEntity, ImportValidateInput input) { |
| | | public async Task<ApiAction<List<T>>> ValidateTableImport<T>(T newEntity, ImportValidateInput input) |
| | | { |
| | | var result = new ApiAction<List<T>>(); |
| | | try |
| | | { |
| | | List<T> list = JsonConvert.DeserializeObject<List<T>>(input.EntityJson); |
| | | List<BIZ_MES_WO_BATCH> baths = list as List<BIZ_MES_WO_BATCH>; |
| | | List<string> chkColumns = JsonConvert.DeserializeObject<List<string>>(input.CheckJson); |
| | | List<string> wheres = JsonConvert.DeserializeObject<List<string>>(input.where); //目前只有=,以后可以增加其他的查询条件 |
| | | Type entityType = typeof(T); //T泛型 |
| | | //通过属性名获取属性值 “VALIDATION_TYPE”属性名称 |
| | | PropertyInfo typeInfo = entityType.GetProperty("VALIDATION_TYPE"); |
| | | //通过属性名获取属性值 “VALIDATION_RESULT”属性名称 |
| | | PropertyInfo retInfo = entityType.GetProperty("VALIDATION_RESULT"); |
| | | foreach (var item in list) |
| | | foreach (var item in baths) |
| | | { |
| | | string where = " 1=1 "; |
| | | typeInfo.SetValue(item, "新增"); |
| | | retInfo.SetValue(item, ""); |
| | | foreach (var col in chkColumns) |
| | | item.VALIDATION_TYPE = "新增"; |
| | | item.VALIDATION_RESULT = ""; |
| | | |
| | | if (!Biz.Db.Queryable<BIZ_MES_WO>().Any(x => x.ORDER_NO == item.ORDER_NO) || Biz.Db.Queryable<BIZ_MES_WO>().Any(x => x.ORDER_NO == item.ORDER_NO && x.STATUS == BIZ_MES_WO_BATCH.STATUSs.Closed.GetValue())) |
| | | { |
| | | PropertyInfo colInfo = entityType.GetProperty(col); |
| | | if (!colInfo.IsNullOrEmpty() && colInfo.GetValue(item).IsNullOrEmpty()) { |
| | | typeInfo.SetValue(item, "数据异常"); |
| | | retInfo.SetValue(item, "值为空或不存在"); |
| | | item.VALIDATION_TYPE = "异常"; |
| | | item.VALIDATION_RESULT = "工单不存在或者已经关闭,不能导入计划!"; |
| | | } |
| | | else |
| | | { |
| | | if (item.PLAN_DATE.IsNullOrEmpty()) |
| | | { |
| | | item.VALIDATION_TYPE = "异常"; |
| | | item.VALIDATION_RESULT += $"计划日期值为空或不存在; "; |
| | | } |
| | | } |
| | | foreach (var w in wheres) |
| | | { |
| | | PropertyInfo wInfo = entityType.GetProperty(w); |
| | | where += $"AND {w} = '{wInfo.GetValue(item)}'"; |
| | | } |
| | | if (await Biz.Db.Queryable<T>().Where(where).AnyAsync()) |
| | | { |
| | | typeInfo.SetValue(item, "修改"); |
| | | retInfo.SetValue(item, "数据已经存在,使用更新"); |
| | | |
| | | if (item.PLAN_QTY.IsNullOrEmpty()) |
| | | { |
| | | item.VALIDATION_TYPE = "异常"; |
| | | item.VALIDATION_RESULT += $"计划数量为空; "; |
| | | } |
| | | var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == item.ORDER_NO).FirstAsync(); |
| | | var _batchs = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == item.ORDER_NO).ToListAsync(); |
| | | if (_batchs.Count > 0) |
| | | { |
| | | if ((_batchs.Sum(x => x.PLAN_QTY) + item.PLAN_QTY > _wo.PLAN_QTY) || item.PLAN_QTY > _wo.PLAN_QTY) |
| | | { |
| | | item.VALIDATION_TYPE = "异常"; |
| | | item.VALIDATION_RESULT += $"工单下发的数量超过工单计划数量,不能下发!"; |
| | | } |
| | | } |
| | | var _woBatch = _batchs.Where(x => x.ORDER_NO == item.ORDER_NO && SqlFunc.DateIsSame(x.PLAN_DATE, item.PLAN_DATE) && BIZ_MES_WO_BATCH.STATUSs.Init.GetValue() < x.STATUS && x.STATUS < BIZ_MES_WO_BATCH.STATUSs.Closed.GetValue()).FirstOrDefault(); |
| | | if (!_woBatch.IsNullOrEmpty()) |
| | | { |
| | | item.VALIDATION_TYPE = "异常"; |
| | | item.VALIDATION_RESULT += $"数据已经存在且状态不是初始化,不能更新。存在的计划数量为[{_woBatch.PLAN_QTY}]"; |
| | | } |
| | | var _woBatch2 = Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == item.ORDER_NO && SqlFunc.DateIsSame(x.PLAN_DATE, item.PLAN_DATE) && x.STATUS == BIZ_MES_WO_BATCH.STATUSs.Init.GetValue()).First(); |
| | | if (!_woBatch2.IsNullOrEmpty()) |
| | | { |
| | | item.VALIDATION_TYPE = "更新"; |
| | | item.VALIDATION_RESULT = $"数据可以更新"; |
| | | item.BATCH_NO = _woBatch2.BATCH_NO; |
| | | } |
| | | } |
| | | } |
| | | result.Data = list; |