123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Linq;
- using EMIS.ViewModel;
- using EMIS.ViewModel.SystemView;
- using EMIS.DataLogic.SystemSetting;
- using EMIS.Entities;
- using Bowin.Common.Cache;
- namespace EMIS.CommonLogic.SystemSetting
- {
- public class DictionaryItemServices : BaseServices, IDictionaryItemServices
- {
- public DictionaryItemDAL DictionaryItemDAL { get; set; }
- /// <summary>
- /// 查询对应的数据字典信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="isEditable"></param>
- /// <param name="isVisible"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<DictionaryItemView> GetDictionaryItemViewGird(ConfiguretView configuretView, string dictionaryCode, int? isEditable, int? isVisible, int pageIndex, int pageSize)
- {
- //数据字典元素
- Expression<Func<Sys_DictionaryItem, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(dictionaryCode) && dictionaryCode != "-1")
- {
- //类型代码
- exp = exp.And(x => x.DictionaryCode == dictionaryCode);
- }
- if (isEditable.HasValue)
- {
- //可否编辑
- if (isEditable == (int)CF_GeneralPurpose.IsYes)
- {
- exp = exp.And(x => x.IsEditable == true);
- }
- if (isEditable == (int)CF_GeneralPurpose.IsNo)
- {
- exp = exp.And(x => x.IsEditable != true);
- }
- }
- var query = DictionaryItemDAL.GetDictionaryItemViewQueryable(exp);
- if (isVisible.HasValue)
- {
- //可否显示
- if (isVisible == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- }
- if (isVisible == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName).ThenBy(x => x.OrderNo).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的数据字典信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="isEditable"></param>
- /// <param name="isVisible"></param>
- /// <returns></returns>
- public IList<DictionaryItemView> GetDictionaryItemViewList(ConfiguretView configuretView, string dictionaryCode, int? isEditable, int? isVisible)
- {
- //数据字典元素
- Expression<Func<Sys_DictionaryItem, bool>> exp = (x => true);
- if (!string.IsNullOrEmpty(dictionaryCode) && dictionaryCode != "-1")
- {
- //类型代码
- exp = exp.And(x => x.DictionaryCode == dictionaryCode);
- }
- if (isEditable.HasValue)
- {
- //可否编辑
- if (isEditable == (int)CF_GeneralPurpose.IsYes)
- {
- exp = exp.And(x => x.IsEditable == true);
- }
- if (isEditable == (int)CF_GeneralPurpose.IsNo)
- {
- exp = exp.And(x => x.IsEditable != true);
- }
- }
- var query = DictionaryItemDAL.GetDictionaryItemViewQueryable(exp);
- if (isVisible.HasValue)
- {
- //可否显示
- if (isVisible == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- }
- if (isVisible == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.RecordStatus <= (int)SYS_STATUS.UNUSABLE);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName).ThenBy(x => x.OrderNo).ToList();
- }
- /// <summary>
- /// 根据数据字典元素ID查询对应的数据字典信息DictionaryItemView
- /// </summary>
- /// <param name="DictionaryItemID"></param>
- /// <returns></returns>
- public DictionaryItemView GetDictionaryItemView(Guid? DictionaryItemID)
- {
- try
- {
- var dictionaryItemView = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryItemID == DictionaryItemID).SingleOrDefault();
- return dictionaryItemView;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑(新增、修改)
- /// </summary>
- /// <param name="dictionaryItemView"></param>
- public void DictionaryItemEdit(DictionaryItemView dictionaryItemView)
- {
- try
- {
- //查询数据库进行验证
- var dictionaryItemVerification = DictionaryItemDAL.DictionaryItemRepository.GetList(x => x.DictionaryItemID != dictionaryItemView.DictionaryItemID
- && x.DictionaryCode == dictionaryItemView.DictionaryCode && (x.Value == dictionaryItemView.Value || (x.Code == dictionaryItemView.Code && x.Name == dictionaryItemView.Name))).SingleOrDefault();
- if (dictionaryItemVerification == null)
- {
- //数据有误验证
- if (dictionaryItemView.DictionaryItemID != Guid.Empty)
- {
- var dictionaryItem = DictionaryItemDAL.DictionaryItemRepository.GetList(x => x.DictionaryItemID == dictionaryItemView.DictionaryItemID).SingleOrDefault();
- if (dictionaryItem == null)
- {
- throw new Exception("数据有误,请核查");
- }
- else
- {
- //表示修改
- dictionaryItem.OrderNo = (short)dictionaryItemView.OrderNo;
- //dictionaryItem.Code = dictionaryItemView.Code;
- dictionaryItem.Name = dictionaryItemView.Name;
- //dictionaryItem.IsEditable = dictionaryItemView.IsEditable;
- dictionaryItem.RecordStatus = dictionaryItemView.IsVisible == true ? (int)SYS_STATUS.USABLE : (int)SYS_STATUS.UNUSABLE;
- //SetModifyStatus(dictionaryItem);
- }
- }
- else
- {
- //表示新增
- Sys_DictionaryItem dictionaryItem = new Sys_DictionaryItem();
- dictionaryItem.DictionaryItemID = Guid.NewGuid();
- dictionaryItem.DictionaryCode = dictionaryItemView.DictionaryCode;
- dictionaryItem.OrderNo = (short)dictionaryItemView.OrderNo;
- dictionaryItem.Code = dictionaryItemView.Code;
- dictionaryItem.Name = dictionaryItemView.Name;
- dictionaryItem.Value = dictionaryItemView.Value;
- dictionaryItem.IsEditable = true;
- dictionaryItem.RecordStatus = dictionaryItemView.IsVisible == true ? (int)SYS_STATUS.USABLE : (int)SYS_STATUS.UNUSABLE;
- //SetNewStatus(dictionaryItem, dictionaryItemView.IsVisible == true ? (int)SYS_STATUS.USABLE : (int)SYS_STATUS.UNUSABLE);
- UnitOfWork.Add(dictionaryItem);
- }
- }
- else
- {
- throw new Exception("已存在相同的数据字典,请核查");
- }
- //事务提交
- UnitOfWork.Commit();
- //清除数据缓存
- var key = "Dictionary_" + dictionaryItemView.DictionaryCode;
- CacheHelper.Remove(key);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除(只可删除可编辑的信息)
- /// </summary>
- /// <param name="dictionaryItemIDList"></param>
- /// <returns></returns>
- public bool DictionaryItemDelete(IList<Guid?> dictionaryItemIDList)
- {
- try
- {
- //查询对应的数据字典信息List
- var dictionaryItemList = DictionaryItemDAL.DictionaryItemRepository.GetList(x => dictionaryItemIDList.Contains(x.DictionaryItemID)).ToList();
- if (dictionaryItemList.Any(x => x.IsEditable != true))
- {
- throw new Exception("不能对不可编辑的信息进行删除");
- }
- UnitOfWork.Delete<Sys_DictionaryItem>(x => dictionaryItemIDList.Contains(x.DictionaryItemID));
- UnitOfWork.Commit();
- foreach (var dictionaryItem in dictionaryItemList)
- {
- //清除数据缓存
- var key = "Dictionary_" + dictionaryItem.DictionaryCode;
- CacheHelper.Remove(key);
- }
- return true;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 数据字典下拉列表
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<DictionaryItemView> GetDictionaryViewComboGrid(ConfiguretView configuretView, string dictionaryCode, int pageIndex, int pageSize)
- {
- var query = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (!string.IsNullOrEmpty(dictionaryCode))
- {
- query = query.Where(x => x.DictionaryCode == dictionaryCode);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName).ThenBy(x => x.Value).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 数据字典下拉列表(市)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="proviceCode"></param>
- /// <returns></returns>
- public IGridResultSet<DictionaryItemView> GetCityComboGrid(ConfiguretView configuretView, int pageIndex, int pageSize, string proviceCode = null)
- {
- //所属地区
- var dictionaryCode = typeof(CF_Region).Name;
- //后缀"00"表示省份
- var query = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == dictionaryCode && x.Code.EndsWith("00") && !x.Code.EndsWith("0000") && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (!string.IsNullOrEmpty(proviceCode))
- {
- query = query.Where(x => x.Code.StartsWith(proviceCode));
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName).ThenBy(x => x.Value).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 数据字典下拉列表(县、区)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="cityCode"></param>
- /// <returns></returns>
- public IGridResultSet<DictionaryItemView> GetDistrictComboGrid(ConfiguretView configuretView, int pageIndex, int pageSize, string cityCode = null)
- {
- //所属地区
- var dictionaryCode = typeof(CF_Region).Name;
- //后缀"00"表示省份,中间两位表示县、区
- var query = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == dictionaryCode && !x.Code.EndsWith("00") && !x.Code.EndsWith("0000") && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (!string.IsNullOrEmpty(cityCode))
- {
- query = query.Where(x => x.Code.StartsWith(cityCode.Substring(0,4)));
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName).ThenBy(x => x.Value).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
- }
- }
- }
|