123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.Common.EvaluationManage;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.ViewModel.EvaluationManage;
- using EMIS.CommonLogic.SystemServices;
- using Bowin.Common.Linq;
- namespace EMIS.CommonLogic.EvaluationManage
- {
- public class EvaluationTargetServices : BaseServices, IEvaluationTargetServices
- {
- public EvaluationTargetDAL evaluationTargetDAL { get; set; }
- public ISerialNumberServices SerialNumberServices { get; set; }
- /// <summary>
- /// 查询评价指标信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="tableID">评价表名ID</param>
- /// <param name="normID">评分标准ID</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<EvaluationTargetView> GetEvaluationTargetViewGrid(ConfiguretView configuretView, Guid? tableID, Guid? normID, int pageIndex, int pageSize)
- {
- var query = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true);
- if (tableID.HasValue && tableID != Guid.Empty)
- query = query.Where(x => x.TableID == tableID);
- if (normID.HasValue && normID != Guid.Empty)
- query = query.Where(x => x.NormID == normID);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationTargetView>(pageIndex, pageSize);
- return query.OrderBy(x => x.Code).OrderBy(x => x.OrderID).ToGridResultSet<EvaluationTargetView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询评价指标信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="tableID">评价表名ID</param>
- /// <param name="normID">评分标准ID</param>
- /// <returns></returns>
- public List<EvaluationTargetView> GetEvaluationTargetViewList(ConfiguretView configuretView, Guid? tableID, Guid? normID)
- {
- var query = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true);
- if (tableID.HasValue && tableID != Guid.Empty)
- query = query.Where(x => x.TableID == tableID);
- if (normID.HasValue && normID != Guid.Empty)
- query = query.Where(x => x.NormID == normID);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.OrderID).ToList();
- return query.OrderBy(x => x.OrderID).ToList();
- }
- /// <summary>
- /// 获取评价指标信息
- /// </summary>
- /// <param name="targetID">主键ID</param>
- /// <returns></returns>
- public EM_EvaluationTarget GetEvaluationTarget(Guid? targetID)
- {
- //查询条件
- Expression<Func<EM_EvaluationTarget, bool>> expression = (x => x.EvaluationTargetID == targetID.Value);
- return evaluationTargetDAL.evaluationTargetRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评分标准信息
- /// </summary>
- /// <param name="Name">评价指标名称</param>
- /// <returns></returns>
- public EMIS.Entities.EM_EvaluationTarget GetEvaluationTarget(string Name)
- {
- //查询条件
- Expression<Func<EMIS.Entities.EM_EvaluationTarget, bool>> expression = (x => x.Name == Name);
- return evaluationTargetDAL.evaluationTargetRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评价指标信息
- /// </summary>
- /// <param name="targetID">主键ID</param>
- /// <returns></returns>
- public EvaluationTargetView GetEvaluationTargetView(Guid? targetID)
- {
- EvaluationTargetView evaluationTargetView = new EvaluationTargetView();
- if (targetID.HasValue && targetID != Guid.Empty)
- evaluationTargetView = evaluationTargetDAL.GetEvaluationTargetQueryable(x => true).Where(x => x.TargetID == targetID).FirstOrDefault();
- return evaluationTargetView;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="evaluationTarget">实体</param>
- /// <returns></returns>
- public bool EvaluationTargetAdd(EM_EvaluationTarget evaluationTarget)
- {
- try
- {
- UnitOfWork.Add(evaluationTarget);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="evaluationTarget">实体</param>
- /// <returns></returns>
- public bool EvaluationTargetUpdate(EM_EvaluationTarget evaluationTarget)
- {
- try
- {
- UnitOfWork.Update(evaluationTarget);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="targetIDs"></param>
- /// <returns></returns>
- public bool EvaluationTargetDelete(List<Guid> targetIDs)
- {
- try
- {
- UnitOfWork.Delete<EM_EvaluationTarget>(x => targetIDs.Contains(x.EvaluationTargetID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 验证
- /// </summary>
- /// <param name="targetID"></param>
- /// <param name="code"></param>
- /// <param name="name"></param>
- public void Verification(Guid targetID, string code, string name)
- {
- var sameCode = evaluationTargetDAL.evaluationTargetRepository.GetSingle(x => x.Code == code && x.EvaluationTargetID != targetID);
- if (sameCode != null)
- {
- throw new Exception("评价指标代码已存在,请重新输入!");
- }
- var sameName = evaluationTargetDAL.evaluationTargetRepository.GetSingle(x => x.Name == name && x.EvaluationTargetID != targetID);
- if (sameName != null)
- {
- throw new Exception("评价指标名称已存在,请重新输入!");
- }
- }
- public bool ValidateEvaluationTarget(EvaluationTargetView model)
- {
- if (string.IsNullOrWhiteSpace(model.Name))
- {
- throw new Exception("指标名称不能为空!");
- }
- if (!model.TableID.HasValue || model.TableID == Guid.Empty)
- {
- throw new Exception("评价表不能为空!");
- }
- model.Name = model.Name.Trim();
- Expression<Func<EM_EvaluationTarget, bool>> nameFilter = w => w.Name == model.Name && w.EvaluationTableID == model.TableID;
- if (model.TargetID.HasValue && model.TargetID != Guid.Empty) //编辑状态
- {
- nameFilter = nameFilter.And(w => w.EvaluationTargetID != model.TargetID);
- }
- var hasName = evaluationTargetDAL.evaluationTargetRepository.Entities.Any(nameFilter);
- if (hasName)
- {
- throw new Exception("指标名称已存在!");
- }
- //var table = evaluationTargetDAL.evaluationTableRepository.GetSingle(w => w.TableID == model.TableID);
- //if (model.Weight > table.Weight || model.Weight < 0)
- //{
- // throw new Exception("指标权重 必须在0到" + table.Weight + "之间!");
- //}
- //var weightSum = evaluationTargetDAL.evaluationTargetRepository.GetList(w => w.TableID == model.TableID).Sum(s => s.Weight ?? 0);
- //weightSum += model.Weight.Value;
- //if (weightSum > table.Weight)
- //{
- // throw new Exception("指标权重 之和(" + weightSum + ")必须等于" + table.Weight + "!");
- //}
- return true;
- }
- public void SaveOrUpdateEvaluationTarget(EvaluationTargetView model)
- {
- ValidateEvaluationTarget(model);
- var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- EM_EvaluationTarget entity = new EM_EvaluationTarget();
- if (!model.TargetID.HasValue || model.TargetID == Guid.Empty)
- {
- var table = evaluationTargetDAL.evaluationTableRepository.GetSingle(w => w.EvaluationTableID == model.TableID);
- entity.EvaluationTargetID = Guid.NewGuid();
- entity.Code = SerialNumberServices.SetSN(table.Code);
- entity.CreateTime = DateTime.Now;
- entity.CreateUserID = user.UserID;
- UnitOfWork.Add(entity);
- }
- else
- {
- entity = GetEvaluationTarget(model.TargetID);
- Guid? tableID = entity.EvaluationTableID;
- if (evaluationTargetDAL.evaluationEnterRepository.Entities.Any(x => x.EM_EvaluationTable.EvaluationTableID == tableID))
- {
- throw new Exception("该信息已经被使用不能进行修改");
- }
- }
- entity.Name = model.Name;
- entity.EvaluationTableID = model.TableID;
- entity.EvaluationNormID = model.NormID;
- entity.OrderNo = model.OrderID;
- entity.Weight = model.Weight;
- entity.Remark = model.Remark;
- entity.ModifyUserID = user.UserID;
- entity.ModifyTime = DateTime.Now;
- UnitOfWork.Commit();
- }
- public IList<EM_EvaluationTarget> GetEvaluationTargetList(List<Guid> targetIDs)
- {
- return evaluationTargetDAL.evaluationTargetRepository.GetList(x => targetIDs.Contains(x.EvaluationTargetID)).ToList();
- }
- public IList<EM_EvaluationProject> GetEvaluationProjectList(Guid targetID)
- {
- return evaluationTargetDAL.evaluationProjectRepository.GetList(x => x.EvaluationTargetID == targetID).ToList();
- }
- }
- }
|