public ResResultModel SavePandianAsset(PdaPandianAssetFmModel model) { object userId = null; SecurityService.DoCheckLogin(model.AppKey, model.UserName, out userId); if (model == null) { return(ResResult.Response(false, "请求参数集为空字符串", "")); } var pandianId = Guid.Empty; if (model.PandianId == null || !Guid.TryParse(model.PandianId.ToString(), out pandianId)) { return(ResResult.Response(false, "参数PandianId值为“" + model.PandianId + "”无效", "")); } if (model.ItemList == null || model.ItemList.Count == 0) { return(ResResult.Response(false, "请求参数集为空字符串", "")); } var pdaBll = new PandianAsset(); var aisBll = new AssetInStore(); var pdBll = new Pandian(); var effect = 0; foreach (var item in model.ItemList) { PandianAssetInfo pdaModel = null; AssetInStoreInfo assetModel = null; var assetId = Guid.Empty; if (item.AssetId != null) { Guid.TryParse(item.AssetId.ToString(), out assetId); } if (assetId == Guid.Empty) { if (string.IsNullOrWhiteSpace(item.Barcode)) { continue; } if (pdaBll.IsExist(item.Barcode)) { assetModel = aisBll.GetModelByBarcode(item.Barcode); if (assetModel != null) { CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); pdaModel.AssetId = assetModel.Id; pdaModel.PandianId = pandianId; assetModel.UserId = Guid.Parse(userId.ToString()); pdaModel.UserId = assetModel.UserId; effect += aisBll.Update(assetModel); effect += pdaBll.Update(pdaModel); } } else { CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); assetModel.Id = Guid.NewGuid(); pdaModel.AssetId = assetModel.Id; pdaModel.PandianId = pandianId; assetModel.UserId = Guid.Parse(userId.ToString()); pdaModel.UserId = assetModel.UserId; effect += aisBll.InsertByOutput(assetModel); effect += pdaBll.Insert(pdaModel); } } else { assetModel = aisBll.GetModel(assetId); pdaModel = pdaBll.GetModel(pandianId, assetId); CreateAssetInStoreInfo(item, ref assetModel, ref pdaModel); pdaModel.UserId = Guid.Parse(userId.ToString()); effect += pdaBll.Update(pdaModel); } } if (effect < 1) { return(ResResult.Response(false, "操作失败", "")); } return(ResResult.Response(true, "调用成功", "")); }
public ResResultModel SavePandianAsset(PdaPandianAssetFmModel model) { try { if (model == null) { return(ResResult.Response(false, "请求参数集为空字符串", "")); } var userId = WebCommon.GetUserId(); if (userId.Equals(Guid.Empty)) { return(ResResult.Response((int)ResCode.未登录, MC.Login_NotExist, "")); } var depmtId = new Staff().GetOrgId(userId); var pandianId = Guid.Empty; if (!Guid.TryParse(model.PandianId, out pandianId)) { return(ResResult.Response(false, "参数PandianId值为“" + model.PandianId + "”无效", "")); } var currTime = DateTime.Now; var gEmpty = Guid.Empty; var minDate = DateTime.Parse("1754-01-01"); var pdaBll = new PandianAsset(); var pBll = new Product(); var pdBll = new Pandian(); var effect = 0; foreach (var item in model.ItemList) { var assetId = Guid.Empty; if (!string.IsNullOrEmpty(item.AssetId)) { Guid.TryParse(item.AssetId, out assetId); } var categoryId = Guid.Empty; if (!string.IsNullOrEmpty(item.CategoryId)) { Guid.TryParse(item.CategoryId, out categoryId); } var useDepmtId = Guid.Empty; if (!string.IsNullOrEmpty(item.UseDepmtId)) { Guid.TryParse(item.UseDepmtId, out useDepmtId); } var mgrDepmtId = Guid.Empty; if (!string.IsNullOrEmpty(item.MgrDepmtId)) { Guid.TryParse(item.MgrDepmtId, out mgrDepmtId); } var storeLocationId = Guid.Empty; if (!string.IsNullOrEmpty(item.StoreLocationId)) { Guid.TryParse(item.StoreLocationId, out storeLocationId); } ProductInfo productInfo = null; if (item.Status == (int)EnumPandianAssetStatus.盘盈) { #region 盘盈 productInfo = new ProductInfo(GlobalConfig.SiteCode, userId, depmtId, Guid.NewGuid(), categoryId, item.Barcode, item.AssetName, item.Barcode, item.SpecModel, 1, 0, 0, item.Unit, 0, string.Empty, string.Empty, string.Empty, minDate, "1754-01-01", string.Empty, useDepmtId, item.UsePerson, mgrDepmtId, storeLocationId, string.Empty, item.Status, 0, true, currTime, currTime); effect += pBll.InsertByOutput(productInfo); var pandianAssetInfo = new PandianAssetInfo(pandianId, productInfo.Id, productInfo.AppCode, productInfo.UserId, productInfo.DepmtId, gEmpty, gEmpty, gEmpty, string.Empty, 0, item.Remark, item.Status, currTime, currTime); pdaBll.Insert(pandianAssetInfo); #endregion } else { #region 非盘盈 productInfo = pBll.GetModel(assetId); var pandianAssetInfo = pdaBll.GetModel(pandianId, assetId); if (!useDepmtId.Equals(Guid.Empty) && !useDepmtId.Equals(productInfo.UseDepmtId)) { pandianAssetInfo.LastUseDepmtId = useDepmtId; } if (!mgrDepmtId.Equals(Guid.Empty) && !mgrDepmtId.Equals(productInfo.MgrDepmtId)) { pandianAssetInfo.LastMgrDepmtId = mgrDepmtId; } if (!storeLocationId.Equals(Guid.Empty) && !storeLocationId.Equals(productInfo.StoragePlaceId)) { pandianAssetInfo.LastStoragePlaceId = storeLocationId; } if (!string.IsNullOrEmpty(item.UsePerson) && item.UsePerson != productInfo.UsePersonName) { pandianAssetInfo.LastUsePerson = item.UsePerson; } pandianAssetInfo.Status = item.Status; effect += pdaBll.Update(pandianAssetInfo); #endregion } } if (effect < 1) { return(ResResult.Response(false, "操作失败", "")); } return(ResResult.Response(true, "调用成功", "")); } catch (Exception ex) { return(ResResult.Response(false, ex.Message, "")); } }