/// <summary> /// 根据菜单,获得当前菜单的所有功能权限 /// </summary> /// <returns></returns> public Task <ApiResult <List <SysCodeDto> > > GetCodeByMenu(string role, string menu) { var res = new ApiResult <List <SysCodeDto> >() { statusCode = (int)ApiEnum.Error }; try { //获得角色权限Guid-List var menuModel = SysMenuDb.GetSingle(m => m.Guid == menu); //查询授权菜单里面的按钮功能 var btnFunModel = SysPermissionsDb.GetSingle(m => m.RoleGuid == role && m.MenuGuid == menu && m.Types == 1); var codeList = new List <SysCodeDto>(); if (!string.IsNullOrEmpty(menuModel.BtnFunJson)) { var list = JsonConvert.DeserializeObject <List <string> >(menuModel.BtnFunJson); codeList = SysCodeDb.GetList(m => list.Contains(m.Guid)).Select(m => new SysCodeDto() { guid = m.Guid, name = m.Name, codeType = m.CodeType, status = string.IsNullOrEmpty(btnFunModel.BtnFunJson)?false:btnFunModel.BtnFunJson.Contains(m.Guid)?true:false }).ToList(); } res.statusCode = (int)ApiEnum.Status; res.data = codeList; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(Task.Run(() => res)); }
/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpGoodsSku parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { //判断是否存在 var isExt = ErpGoodsSkuDb.IsAny(m => m.Code == parm.Code); if (isExt) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "该条形码已存在~"; } else { //构建Code var codeType = SysCodeTypeDb.GetList(m => m.ParentGuid == "8d3158d6-e179-4046-99e9-53eb8c04ddb1").Select(m => m.Guid).ToList(); var codeList = SysCodeDb.GetList(m => codeType.Contains(m.ParentGuid)); parm.Code = codeList.Find(m => m.Guid == parm.BrankGuid).CodeType + codeList.Find(m => m.Guid == parm.YearGuid).CodeType + codeList.Find(m => m.Guid == parm.SeasonGuid).CodeType + codeList.Find(m => m.Guid == parm.StyleGuid).CodeType + codeList.Find(m => m.Guid == parm.BatchGuid).CodeType + codeList.Find(m => m.Guid == parm.SizeGuid).CodeType + parm.SalePrice + "-" + parm.DisPrice; //构建商品标题 var brankName = codeList.Find(m => m.Guid == parm.BrankGuid).Name; var styleName = codeList.Find(m => m.Guid == parm.StyleGuid).Name; var goodsName = brankName + codeList.Find(m => m.Guid == parm.SeasonGuid).Name + styleName; //构建商品信息 var goodsModel = new ErpGoods() { Guid = Guid.NewGuid().ToString(), Title = goodsName, Brank = brankName, Style = styleName }; parm.GoodsGuid = goodsModel.Guid; parm.Guid = Guid.NewGuid().ToString(); //事务保证数据一致性 Db.Ado.BeginTran(); var goodsres = ErpGoodsDb.Insert(goodsModel); if (goodsres) { var dbres = ErpGoodsSkuDb.Insert(parm); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "插入数据失败~"; } } Db.Ado.CommitTran(); } } catch (Exception ex) { Db.Ado.RollbackTran(); res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }