¶Ô±ÈÐÂÎļþ |
| | |
| | | using Apache.NMS.ActiveMQ.Commands; |
| | | using Rhea.Common; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Newtonsoft.Json; |
| | | using System.Diagnostics; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Tiger.IBusiness; |
| | | using Tiger.Model.Minsun; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.U9C; |
| | | using System.Reflection; |
| | | using Dm.filter; |
| | | using System.Dynamic; |
| | | |
| | | namespace Tiger.Business |
| | | { |
| | | /// <summary> |
| | | /// éç¨å¯¼å
¥Excel |
| | | /// </summary> |
| | | public class ImportExcel : IImportExcel |
| | | { |
| | | /// <summary> |
| | | /// 导å
¥ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="newEntity"></param> |
| | | /// <param name="jsonStr"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> Import<T>(T newEntity, string jsonStr) where T : class, new() |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | |
| | | List<T> list = JsonConvert.DeserializeObject<List<T>>(jsonStr); |
| | | DbClient db = Biz.Db; |
| | | if (list.Any()) |
| | | { |
| | | if (list.Count > 100) |
| | | { |
| | | db.Utilities.PageEach(list, 100, pageList => |
| | | { |
| | | var y = db.Storageable(pageList) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.ExecuteCommand(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | var s = db.Storageable(list) |
| | | .ToStorage(); |
| | | s.AsInsertable.ExecuteCommand(); |
| | | s.AsUpdateable.ExecuteCommand(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchException(ex, $"éªè¯å¯¼å
¥å¼å¸¸"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导å
¥Excelåéªè¯ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="newEntity"></param> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<List<T>>> ValidateTableImport<T>(T newEntity, ImportEntityValidate input) { |
| | | var result = new ApiAction<List<T>>(); |
| | | try |
| | | { |
| | | List<T> list = JsonConvert.DeserializeObject<List<T>>(input.EntityJson); |
| | | 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) |
| | | { |
| | | string where = " 1=1 "; |
| | | typeInfo.SetValue(item, "æ°å¢"); |
| | | retInfo.SetValue(item, ""); |
| | | foreach (var col in chkColumns) |
| | | { |
| | | PropertyInfo colInfo = entityType.GetProperty(col); |
| | | if (!colInfo.IsNullOrEmpty() && colInfo.GetValue(item).IsNullOrEmpty()) { |
| | | typeInfo.SetValue(item, "æ°æ®å¼å¸¸"); |
| | | retInfo.SetValue(item, "å¼ä¸ºç©ºæä¸åå¨"); |
| | | } |
| | | } |
| | | 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, "æ°æ®å·²ç»åå¨ï¼ä½¿ç¨æ´æ°"); |
| | | } |
| | | } |
| | | result.Data = list; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchException(ex, $"éªè¯å¯¼å
¥å¼å¸¸"); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | } |