123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.ScoreManage;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.ScoreManage;
- using EMIS.DataLogic.Repositories;
- namespace EMIS.CommonLogic.ScoreManage
- {
- public class ScoreFormulaServices : BaseServices, IScoreFormulaServices
- {
- public CustomScoreFormulaRepository CustomScoreFormulaRepository { get; set; }
- public ScoreFormulaDAL scoreFormulaDAL { get; set; }
- /// <summary>
- /// 查询成绩公式设置列表
- /// </summary>
- /// <param name="name"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<Entities.ER_ScoreFormula> GetScoreFormulaGrid(string name, int pageIndex, int pageSize)
- {
- var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (!string.IsNullOrEmpty(name))
- query = query.Where(x => name.Contains(x.Name));
- return query.OrderByDescending(x => x.CreateTime).ToGridResultSet<ER_ScoreFormula>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询成绩公式设置列表
- /// </summary>
- /// <param name="name"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public List<Entities.ER_ScoreFormula> GetScoreFormulaList(string name)
- {
- var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
- if (!string.IsNullOrEmpty(name))
- query = query.Where(x => name.Contains(x.Name));
- return query.OrderByDescending(x => x.CreateTime).ToList();
- }
- // <summary>
- /// 查询成绩公式设置列表
- /// </summary>
- /// <param name="name"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public List<ScoreFormulaDropdownView> GetScoreFormulaDropdownViewList(string name)
- {
- var query = scoreFormulaDAL.scoreFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, (x => x.ER_ScoreFormulaDetail));
- if (!string.IsNullOrEmpty(name))
- query = query.Where(x => name.Contains(x.Name));
- var list = query.OrderByDescending(x => x.CreateTime).ToList();
- var result = new List<ScoreFormulaDropdownView>();
- list.ForEach(x => result.Add(new ScoreFormulaDropdownView
- {
- ScoreFormulaID = x.ScoreFormulaID,
- Name = x.Name,
- ScoreFormulaDetail = x.ER_ScoreFormulaDetail.Select(w => new ScoreFormulaDropdownDetailView
- {
- ScoreFormulaDetailID = w.ScoreFormulaDetailID,
- ScoreFormulaID = w.ScoreFormulaID,
- ScoreType = w.ScoreType,
- Percentage = w.Percentage,
- IsRequirePass = w.IsRequirePass,
- PassScore=w.PassScore
- }).ToList()
- }));
- return result;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="scoreFormulaView"></param>
- public void ScoreFormulaAdd(ScoreFormulaView scoreFormulaView, List<ScoreFormulaDropdownDetailView> scoreFormulaDetailList)
- {
- try
- {
- ER_ScoreFormula scoreFormula = null;
- if (scoreFormulaView.ScoreFormulaID == null || scoreFormulaView.ScoreFormulaID == Guid.Empty)
- {
- scoreFormula = new ER_ScoreFormula();
- scoreFormula.ScoreFormulaID = Guid.NewGuid();
- scoreFormula.Name = scoreFormulaView.Name;
- SetNewStatus(scoreFormula);
- UnitOfWork.Add(scoreFormula);
- scoreFormula.ER_ScoreFormulaDetail = new HashSet<ER_ScoreFormulaDetail>();
- foreach (var scoreDetail in scoreFormulaDetailList)
- {
- if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
- {
- throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
- }
- ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
- scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
- scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
- scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
- scoreFormulaDetail.Percentage = scoreDetail.Percentage;
- scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
- if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
- {
- scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
- }
- else {
- scoreFormulaDetail.PassScore = null;
- }
- SetNewStatus(scoreFormulaDetail);
- UnitOfWork.Add(scoreFormulaDetail);
- }
- }
- else
- {
- scoreFormula = GetScoreFormula(scoreFormulaView.ScoreFormulaID);
- if(scoreFormula == null)
- throw new Exception("未找到相对应的成绩公式设置!");
- scoreFormula.Name = scoreFormulaView.Name;
- SetModifyStatus(scoreFormula);
- scoreFormula.ER_ScoreFormulaDetail = new HashSet<ER_ScoreFormulaDetail>();
- foreach (var scoreDetail in scoreFormulaDetailList)
- {
- if (scoreDetail.IsRequirePass == true && scoreDetail.PassScore == null)
- {
- throw new Exception("勾选必须通过的项没有设置必须通过成绩!");
- }
- ER_ScoreFormulaDetail scoreFormulaDetail = new ER_ScoreFormulaDetail();
- scoreFormulaDetail.ScoreFormulaDetailID = Guid.NewGuid();
- scoreFormulaDetail.ScoreFormulaID = scoreFormula.ScoreFormulaID;
- scoreFormulaDetail.ScoreType = scoreDetail.ScoreType;
- scoreFormulaDetail.Percentage = scoreDetail.Percentage;
- scoreFormulaDetail.IsRequirePass = scoreDetail.IsRequirePass;
- if (scoreDetail.PassScoreStr != "" && scoreDetail.PassScoreStr != null)
- {
- scoreFormulaDetail.PassScore = Convert.ToDecimal(scoreDetail.PassScoreStr);
- }
- else
- {
- scoreFormulaDetail.PassScore = null;
- }
- SetNewStatus(scoreFormulaDetail);
- UnitOfWork.Add(scoreFormulaDetail);
- }
- }
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="scoreFormulaIDs"></param>
- public void ScoreFormulaDelete(List<Guid> scoreFormulaIDs)
- {
- try
- {
- if (scoreFormulaIDs.Count > 0)
- {
- UnitOfWork.Delete<ER_ScoreFormula>(x => scoreFormulaIDs.Contains(x.ScoreFormulaID));
- }
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- /// <summary>
- /// 根据ID获取成绩公式设置
- /// </summary>
- /// <param name="scoreFormulaID"></param>
- /// <returns></returns>
- public ER_ScoreFormula GetScoreFormula(Guid? scoreFormulaID)
- {
- return scoreFormulaDAL.scoreFormulaRepository.GetSingle(x => x.ScoreFormulaID == scoreFormulaID, (x => x.ER_ScoreFormulaDetail));
- }
- /// <summary>
- /// 根据成绩公式设置ID查询明细
- /// </summary>
- /// <param name="scoreFormulaID"></param>
- /// <returns></returns>
- public List<ER_ScoreFormulaDetail> GetScoreFormulaDetailList(Guid? scoreFormulaID)
- {
- if (scoreFormulaID == null)
- {
- return new List<ER_ScoreFormulaDetail>();
- }
- return scoreFormulaDAL.scoreFormulaDetailRepository
- .GetList(x => x.ScoreFormulaID == scoreFormulaID).OrderBy(x => x.ScoreType).ToList();
- }
- /// <summary>
- /// 根据成绩公式设置ID查询明细
- /// </summary>
- /// <param name="scoreFormulaID"></param>
- /// <returns></returns>
- public List<ScoreFormulaDropdownDetailView> GetScoreFormulaDetailListByScoreFormulaID(Guid? scoreFormulaID)
- {
- if (scoreFormulaID == null)
- {
- return new List<ScoreFormulaDropdownDetailView>();
- }
- return scoreFormulaDAL.GetScoreFormulaDetailViewQueryableByID(scoreFormulaID.Value).ToList();
- }
- public List<ER_CustomScoreFormula> GetCustomerScoreFormula()
- {
- return this.CustomScoreFormulaRepository.Entities.ToList();
- }
- }
- }
|