123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using Mapster;
- using NPOI.OpenXmlFormats.Spreadsheet;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WMS.BZModels;
- using WMS.BZModels.Dto.UserCenterManager.ACLConstDtos;
- using WMS.BZModels.Dto.UserCenterManager.UserInfoDtos;
- using WMS.BZModels.Models.UserCenterManager;
- using WMS.Info;
- using WMS.BZSqlSugar;
- namespace WMS.BZServices.UserCenterManager
- {
- public class ACLConstService
- {
- private readonly Repository<AclConst> _aclConstRepository;
- private readonly SysModuleService _sysModuleService;
- public ACLConstService(Repository<AclConst> aclConstRepository, SysModuleService sysModuleService)
- {
- _aclConstRepository = aclConstRepository;
- _sysModuleService = sysModuleService;
- }
- /// <summary>
- /// 获取列表数据
- /// <summary>
- /// <returns></returns>
- public IList<ACLConstDto> GetList(string keyword)
- {
- if (string.IsNullOrEmpty(keyword))
- {
- return _aclConstRepository.Queryable().ToList().Adapt<List<ACLConstDto>>();
- }
- else
- {
- var lst = _aclConstRepository.Queryable().Where(it => it.Name.Contains(keyword)).Select(v => v.Code).ToList();
- var lists = _aclConstRepository.Queryable().Where(v => lst.Contains(v.PNO) || v.Name.Contains(keyword)).ToList();
- return lists.Adapt<List<ACLConstDto>>();
- }
- }
- /// <summary>
- /// 删除实体数据
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public void DeleteEntity(string keyValue)
- {
- _aclConstRepository.Deleteable().Where(it => it.Code == keyValue).ExecuteCommand();
- }
- public void Save(LoginUserInfo loginUser, string keyValue, AclConst entity)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(entity.Code))
- {
- throw new ArgumentException("菜单编号为空。");
- }
- if (string.IsNullOrWhiteSpace(entity.PNO))
- {
- throw new ArgumentException("父菜单编号为空。");
- }
- if (string.IsNullOrWhiteSpace(entity.Name))
- {
- throw new ArgumentException("菜单名称为空。");
- }
- DateTime nowdt = DateTime.Now;
- if (keyValue.IsEmpty() || keyValue == "undefined")
- {
- if (_aclConstRepository.Queryable().Any(o => o.Code == entity.Code))
- {
- throw new ArgumentException("菜单编号已存在。");
- }
- var sort = _aclConstRepository.Queryable().Count(o => o.PNO == entity.PNO) + 1;
- entity.Id = IdFactory.NewId();
- entity.AddTime = DateTime.Now;
- entity.AddWho = loginUser.UserNo;
- entity.EditTime = DateTime.Now;
- entity.EditWho = loginUser.UserNo;
- entity.AppTypeNum = 1;
- entity.SortNum = sort;
- entity.ACLItem = entity.Code;
- var searchentity = entity.Adapt<AclConst>();
- searchentity.Id = IdFactory.NewId();
- searchentity.Code = entity.Code + "_lr_search";
- searchentity.ACLItem = searchentity.Code;
- searchentity.PNO = entity.Code;
- searchentity.SortNum = 0;
- searchentity.Name = "查看";
- _aclConstRepository.Deleteable().Where(it => it.Code == searchentity.Code).ExecuteCommand();
- _aclConstRepository.Insert(entity);
- _aclConstRepository.Insert(searchentity);
- }
- else
- {
- entity.Id = Convert.ToInt64(keyValue);
- entity.EditTime = DateTime.Now;
- entity.EditWho = loginUser.UserNo;
- _aclConstRepository.UpdateEntity(entity);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// <param name="keyValue">主键</param>
- /// <summary>
- /// <returns></returns>
- public void SaveEntity(LoginUserInfo loginUserInfo, string keyValue, AclConst entity)
- {
- if (entity == null)
- {
- throw new ArgumentException("输入数据为空");
- }
- if (string.IsNullOrWhiteSpace(entity.Code))
- {
- throw new ArgumentException("编号为空");
- }
- if (string.IsNullOrWhiteSpace(entity.Name))
- {
- throw new ArgumentException("名称为空");
- }
- entity.EditTime = DateTime.Now;
- entity.EditWho = loginUserInfo.UserNo;
- if (string.IsNullOrEmpty(keyValue))
- {
- entity.Id = IdFactory.NewId();
- entity.AddTime = DateTime.Now;
- entity.AddWho = loginUserInfo.UserNo;
- _aclConstRepository.Insert(entity);
- }
- else
- {
- entity.Id = Convert.ToInt64(keyValue);
- _aclConstRepository.UpdateEntity(entity);
- }
- }
- public void SaveWebACLConst(LoginUserInfo loginUser)
- {
- var list = _sysModuleService.GetList();
- if (list == null)
- {
- return;
- }
- _aclConstRepository.Deleteable().Where(it => it.AppTypeNum == (int)EAppType.PC).ExecuteCommand();
- List<AclConst> aclConstList = new List<AclConst>();
- foreach (var item in list)
- {
- if (item.Code.Contains("Web_DevelopmentM"))
- {
- continue;
- }
- aclConstList.Add(new AclConst()
- {
- ACLItem = item.Code,
- AddTime = DateTime.Now,
- AddWho = loginUser.UserNo,
- AppTypeNum = (int)EAppType.PC,
- Code = item.Code,
- EditTime = DateTime.Now,
- EditWho = loginUser.UserNo,
- Name = item.Name,
- PNO = item.PNO,
- SortNum = item.SortNum
- });
- }
- _aclConstRepository.Insert(aclConstList);
- }
- public void SaveWebACLBtnConst(LoginUserInfo loginUser, string keyValue, List<AclConst> AclList)
- {
- _aclConstRepository.Deleteable().Where(it => it.PNO == keyValue).ExecuteCommand();
- List<AclConst> list = new List<AclConst>();
- if (AclList == null)
- {
- return;
- }
- AclList.ForEach(it =>
- {
- int i = 0;
- it.AddTime = DateTime.Now;
- it.AddWho = loginUser.UserNo;
- it.AppTypeNum = (int)EAppType.PC;
- it.EditTime = DateTime.Now;
- it.EditWho = loginUser.UserNo;
- it.PNO = keyValue;
- it.SortNum = i++;
- it.Code = it.ACLItem;
- });
- _aclConstRepository.Insert(AclList);
- }
- }
- }
|