123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Utility;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- /*using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.Internal;*/
- using Microsoft.Extensions.Caching.Memory;
- using Microsoft.Extensions.Options;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- using Z.EntityFramework.Plus;
- using Microsoft.Extensions.DependencyInjection;
- namespace YLShipBuildLandMap.Services.SystemSetting
- {
- public class DictionaryService : IDictionaryService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- readonly MemoryCacheEntryOptions mCacheOp;
- public DictionaryService(YLShipBuildLandMapContext dbContext, IOptions<MemoryCacheEntryOptions> iopCacheOp)
- {
- DbContext = dbContext;
- mCacheOp = iopCacheOp.Value;
- }
- private IQueryable<DictionaryItemView> GetDictionaryItemQuery(Expression<Func<SysDictionary, bool>> dexp, Expression<Func<SysDictionaryItem, bool>> iexp)
- {
- var query = from r in DbContext.SysDictionaryItem.Where(iexp).Where(x => x.RecordStatus > 0)
- from d in DbContext.SysDictionary.Where(dexp).Where(x => x.DictionaryCode == r.DictionaryCode && x.RecordStatus > 0 && x.IsEditable == true)
- select new DictionaryItemView
- {
- DictionaryItemID = r.DictionaryItemId,
- Code = r.Code,
- DictionaryCode = r.DictionaryCode,
- Value = r.Value,
- Name = r.Name,
- DictionaryName = d.Name,
- OrderNo = r.OrderNo
- };
- return query;
- }
- private IQueryable<SysDictionary> GetDictionaryQuery(Expression<Func<SysDictionary, bool>> exp)
- {
- var query = from r in DbContext.SysDictionary.Where(exp).Where(x => x.RecordStatus > 0 && x.IsEditable == true)
- select r;
- return query;
- }
- public Task<IGridResultSet<DictionaryItemView>> GetDictionaryItemList(int? pageIndex, int? pageSize, string dictionaryName, string dictionaryCode, string name)
- {
- Expression<Func<SysDictionary, bool>> dexp = (e => true);
- Expression<Func<SysDictionaryItem, bool>> iexp = (e => true);
- if (!string.IsNullOrEmpty(dictionaryName))
- {
- dexp = dexp.And(e => e.Name.Contains(dictionaryName.Trim()));
- }
- if (!string.IsNullOrEmpty(name))
- {
- iexp = iexp.And(e => e.Name.Contains(name.Trim()));
- }
- if (!string.IsNullOrEmpty(dictionaryCode))
- {
- iexp = iexp.And(e => e.DictionaryCode.Contains(dictionaryCode.Trim()));
- }
- var result = GetDictionaryItemQuery(dexp, iexp).OrderBy(e => e.DictionaryCode).ThenBy(e => e.OrderNo).ToGridResultSet(pageIndex, pageSize);
- return Task.FromResult(result);
- }
- public List<SysDictionaryItem> GetDictionaryItemList(string dictionaryCode, string name)
- {
- var sql = this.DbContext.SysDictionaryItem.AsQueryable();
- sql = sql.WhereIf(!string.IsNullOrEmpty(dictionaryCode), x => x.DictionaryCode == dictionaryCode);
- sql = sql.WhereIf(!string.IsNullOrEmpty(name), x => x.Name == name);
- return sql.Where(x => x.RecordStatus > 0).OrderBy(x => x.DictionaryCode).ThenBy(x => x.Value).ToList();
- }
- public Task<IEnumerable<SysDictionaryItem>> GetDictionaryItemsbyCache(string dictionaryCode)
- {
- //查询 需要一个参数
- var dics = DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == dictionaryCode).OrderBy(o=>o.OrderNo).FromCacheAsync(mCacheOp);
- return dics;
- }
- public Task<IEnumerable<SysDictionaryItem>> GetTugboatTitleDictionary(string dictionaryCode)
- {
- var dics = from a in DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == "Title")
- from b in DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == dictionaryCode && x.Value == a.Value)
- select a;
- //var dics = DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == dictionaryCode).OrderBy(o => o.OrderNo).FromCacheAsync(mCacheOp);
- return dics.OrderBy(x => x.OrderNo).FromCacheAsync(mCacheOp);
- }
- public Task<IEnumerable<SysDictionaryItem>> GetDepartmentTitleDictionary(string dictionaryCode)
- {
-
- var dics = from a in DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == "Title")
- from b in DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == dictionaryCode && x.Value == a.Value).DefaultIfEmpty()
- where b.DictionaryItemId == null
- select a;
- //var dics = DbContext.SysDictionaryItem.Where(x => x.RecordStatus > 0 && x.DictionaryCode == dictionaryCode).OrderBy(o => o.OrderNo).FromCacheAsync(mCacheOp);
- return dics.OrderBy(x => x.OrderNo).FromCacheAsync(mCacheOp);
- }
- public string GetDictionaryName(IEnumerable<SysDictionaryItem> dics,int? value)
- {
- string name = "";
- var item= dics.FirstOrDefault(w => w.Value == value);
- if (item != null) {
- name = item.Name;
- }
- return name;
- }
- public Task<IGridResultSet<SysDictionary>> GetDictionaryList(int? pageIndex, int? pageSize, string dictionaryName, string dictionaryCode)
- {
- Expression<Func<SysDictionary, bool>> exp = (e => true);
- if (!string.IsNullOrEmpty(dictionaryName))
- {
- exp = exp.And(e => e.Name.Contains(dictionaryName.Trim()));
- }
- if (!string.IsNullOrEmpty(dictionaryCode))
- {
- exp = exp.And(e => e.DictionaryCode.Contains(dictionaryCode.Trim()));
- }
- var result = GetDictionaryQuery(exp).OrderBy(e => e.OrderNo).ThenBy(e => e.DictionaryCode).ToGridResultSet(pageIndex, pageSize);
- return Task.FromResult(result);
- }
- public SysDictionaryItem GetDicItem(Guid? dicItemID)
- {
- return DbContext.SysDictionaryItem.FirstOrDefault(x => x.DictionaryItemId == dicItemID);
- }
- public async Task Save(SysDictionaryItem dicItem, Guid userID)
- {
-
- SysDictionaryItem dbDicItem = DbContext.SysDictionaryItem.FirstOrDefault(x => x.DictionaryItemId == dicItem.DictionaryItemId);
- if (dbDicItem != null)
- {
- dbDicItem.DictionaryCode = dicItem.DictionaryCode;
- dbDicItem.Value = dicItem.Value;
- dbDicItem.Name = dicItem.Name;
- dbDicItem.OrderNo = dicItem.OrderNo;
- DbContext.SysDictionaryItem.Update(dbDicItem);
- }
- else
- {
- dicItem.DictionaryItemId = Guid.NewGuid();
- dicItem.Code = "";
- dicItem.RecordStatus = 1;
- dicItem.IsEditable = true;
- this.DbContext.Add(dicItem);
- }
- await this.DbContext.SaveChangesAsync();
- }
- public async Task Delete(List<Guid> dicItemIDList)
- {
- await this.DbContext.SysDictionaryItem.Where(x => dicItemIDList.Contains(x.DictionaryItemId)).DeleteAsync();
- }
- public List<int?> GetEmployeeStatus()
- {
- var list = new List<int?>() { 1,2,4,5,6 };
- return list;
- }
- }
- }
|