| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- using YiSha.Data.Repository;
- using YiSha.Entity.OrganizationManage;
- using YiSha.Enum;
- using YiSha.Model;
- using YiSha.Model.Param.OrganizationManage;
- using YiSha.Util;
- using YiSha.Util.Extension;
- using YiSha.Util.Model;
- namespace YiSha.Service.OrganizationManage
- {
- public partial class DepartmentService
- {
- private IRepositoryFactory _baseRepository;
- public DepartmentService(IRepositoryFactory baseRepository)
- {
- _baseRepository = baseRepository;
- }
- #region 获取数据
- public async Task<List<DepartmentEntity>> GetListPartial(DepartmentListParam param)
- {
- var expression = ListFilterPartial(param);
- var list = await _baseRepository.BaseRepository(dbConnectType).FindList(expression);
- return list.OrderBy(p => p.DepartmentSort).ToList();
- }
- public async Task<DepartmentEntity> GetEntityPartial(int id)
- {
- return await _baseRepository.BaseRepository(dbConnectType).FindEntity<DepartmentEntity>(id);
- }
- public async Task<int> GetMaxSortPartial()
- {
- object result = await _baseRepository.BaseRepository(dbConnectType).FindObject("SELECT MAX(DepartmentSort) FROM SysDepartment");
- int sort = result.ParseToInt();
- sort++;
- return sort;
- }
- /// <summary>
- /// 部门名称是否存在
- /// </summary>
- /// <param name="entity"></param>
- ///// <returns></returns>
- public bool ExistDepartmentNamePartial(DepartmentEntity entity)
- {
- var expression = LinqExtensions.True<DepartmentEntity>();
- expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
- if (entity.Id.IsNullOrZero())
- {
- expression = expression.And(t => t.DepartmentName == entity.DepartmentName);
- }
- else
- {
- expression = expression.And(t => t.DepartmentName == entity.DepartmentName && t.Id != entity.Id);
- }
- return _baseRepository.BaseRepository(dbConnectType).IQueryable(expression).Count() > 0 ? true : false;
- }
- /// <summary>
- /// 是否存在子部门
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool ExistChildrenDepartmentPartial(int id)
- {
- var expression = LinqExtensions.True<DepartmentEntity>();
- expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
- expression = expression.And(t => t.ParentId == id);
- return _baseRepository.BaseRepository(dbConnectType).IQueryable(expression).Count() > 0 ? true : false;
- }
- #endregion
- #region 提交数据
- public async Task SaveFormPartial(DepartmentEntity entity)
- {
- if (entity.Id.IsNullOrZero())
- {
- await entity.Create();
- await _baseRepository.BaseRepository(dbConnectType).Insert(entity);
- }
- else
- {
- await entity.Modify();
- await _baseRepository.BaseRepository(dbConnectType).Update(entity);
- }
- }
- #endregion
- #region 私有方法
- private Expression<Func<DepartmentEntity, bool>> ListFilterPartial(DepartmentListParam param)
- {
- var expression = LinqExtensions.True<DepartmentEntity>();
- expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
- if (param != null)
- {
- if (!param.DepartmentName.IsEmpty())
- {
- expression = expression.And(t => t.DepartmentName.Contains(param.DepartmentName));
- }
- }
- return expression;
- }
- #endregion
- }
- }
|