using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.ChargeManage.ChargeSituation; using EMIS.ViewModel.ChargeManage.ChargeSituation; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq.Entity; using Bowin.Common.Linq; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel; using EMIS.ViewModel.WorkflowManage; using EMIS.CommonLogic.StudentManage.StudentStatistics; namespace EMIS.CommonLogic.ChargeManage.ChargeSituation { public class ChargeDelayServices : BaseWorkflowServices, IChargeDelayServices { public ChargeDelayDAL chargeDelayDAL { get; set; } public StudentChargeDAL studentChargeDAL { get; set; } public IInSchoolSettingServices InSchoolSettingServices { get; set; } /// /// 查询缓交名单信息View /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetChargeDelayList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int? chargeDelayStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetStatusViewList(); Expression> expChargeDelay = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeDelayStatus.HasValue) { expChargeDelay = expChargeDelay.And(x => x.RecordStatus == chargeDelayStatus); } Expression> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeYearID.HasValue) { expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID); } if (chargeProjectID.HasValue) { expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID); } Expression> expStudent = (x => true); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true); if (inSchoolStatus == 1) { expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = chargeDelayDAL.GetChargeDelayQueryAble(expChargeDelay, expStudentCharge, expStudent); if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { query = query.Where(x => x.GradeStr == yearID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenBy(x => x.ChargeProjectStr) .ThenByDescending(x => x.ChargeYear).ThenBy(x => x.RecordStatus).ThenBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.RecordStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } /// /// 查询缓交名单信息List /// /// /// /// /// /// /// /// /// /// /// /// /// public List GetChargeDelayList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int? chargeDelayStatus) { //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); //缓交名单 Expression> expChargeDelay = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeDelayStatus.HasValue) { //审批状态 expChargeDelay = expChargeDelay.And(x => x.RecordStatus == chargeDelayStatus); } //应收名单 Expression> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeYearID.HasValue) { //缴费学年 expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID); } if (chargeProjectID.HasValue) { //收费项目 expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID); } //学生信息 Expression> expStudent = (x => true); if (inSchoolStatus != null && inSchoolStatus > -1) { //在校状态 var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true); if (inSchoolStatus == 1) { //表示在校 expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { //不在校 expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = chargeDelayDAL.GetChargeDelayQueryAble(expChargeDelay, expStudentCharge, expStudent); if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { query = query.Where(x => x.GradeStr == yearID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StudentNo.Length) .ThenBy(x => x.StudentNo).ThenBy(x => x.ChargeProjectStr) .ThenByDescending(x => x.ChargeYear).ThenBy(x => x.RecordStatus) .ThenBy(x => x.CreateTime) .ToList(); result.ForEach(x => x.RecordStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } /// /// 查询应收名单中对应的缴交信息View(对应的缴交信息全部查询,左联-待缓交金额、已缓交金额) /// /// /// /// /// public ChargeDelayView GetChargeDelayStandardView(Guid? userID, int? chargeYearID, Guid? chargeProjectID) { try { //查询对应的应收名单信息 var studentCharge = chargeDelayDAL.StudentChargeRepository .GetList(x => x.UserID == userID && x.ChargeYear == chargeYearID && x.ChargeProjectID == chargeProjectID).SingleOrDefault(); if (studentCharge == null) { throw new Exception("对应的应收名单不存在,请核查"); } //应收名单 Expression> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentCharge = expStudentCharge.And(x => x.StudentChargeID == studentCharge.StudentChargeID); //查询对应的全部流程环节信息(WorkflowStatusView) var chargeDelayWorkflowStatusView = this.GetStatusViewList(); if (chargeDelayWorkflowStatusView == null || chargeDelayWorkflowStatusView.Count() <= 0) { throw new Exception("工作流平台中,费用缓交流程未配置,请核查"); } //查询缓交申请工作流程开始环节状态 var chargeDelayStartStatus = this.GetStartStatus(); if (chargeDelayStartStatus == null) { throw new Exception("工作流平台中,费用缓交开始环节流程未配置,请核查"); } //缓交申请流程中的ID(包含未提交、待审核) var applyStatusList = this.GetStartApproveStatusList(); //缓交申请(流程中) Expression> expChargeDelayApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expChargeDelayApply = expChargeDelayApply.And(x => x.StudentChargeID == studentCharge.StudentChargeID); expChargeDelayApply = expChargeDelayApply.And(x => applyStatusList.Contains(x.RecordStatus)); //查询缓交申请工作流程结束环节状态 var chargeDelayEndtStatus = this.GetCorrectEndStatus(); if (chargeDelayEndtStatus == null) { throw new Exception("工作流平台中,费用缓交结束环节流程未配置,请核查"); } //缓交申请(审核通过) Expression> expChargeDelayPass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expChargeDelayPass = expChargeDelayPass.And(x => x.StudentChargeID == studentCharge.StudentChargeID); expChargeDelayPass = expChargeDelayPass.And(x => x.RecordStatus == chargeDelayEndtStatus); //查询对应的缴交信息View(对应的缴交信息全部查询,左联-待缓交金额、已缓交金额) var chargeDelayView = studentChargeDAL.GetStudentChargeChargeDelayView(expStudentCharge, expChargeDelayApply, expChargeDelayPass) .SingleOrDefault(); return chargeDelayView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的缓交名单信息View(根据缓交信息) /// /// /// public ChargeDelayView GetChargeDelayView(Guid? chargeDelayID) { var query = chargeDelayDAL.GetChargeDelayQueryAble(x => x.ChargeDelayID == chargeDelayID).SingleOrDefault(); return query; } /// /// 查询对应的缓交名单信息View(对应的应收名单信息全部查询,左联-待缓交金额、已缓交金额) /// /// /// public ChargeDelayView GetChargeDelayEditView(Guid? chargeDelayID) { try { //查询对应的缓交名单信息 var chargeDelay = chargeDelayDAL.ChargeDelayRepository .GetList(x => x.ChargeDelayID == chargeDelayID).SingleOrDefault(); if (chargeDelay == null) { throw new Exception("对应的缓交名单信息不存在,请核查"); } //缓交名单 Expression> expChargeDelay = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expChargeDelay = expChargeDelay.And(x => x.ChargeDelayID == chargeDelayID); //查询对应的全部流程环节信息(WorkflowStatusView) var chargeDelayWorkflowStatusView = this.GetStatusViewList(); if (chargeDelayWorkflowStatusView == null || chargeDelayWorkflowStatusView.Count() <= 0) { throw new Exception("工作流平台中,费用缓交流程未配置,请核查"); } //查询缓交申请工作流程开始环节状态 var chargeDelayStartStatus = this.GetStartStatus(); if (chargeDelayStartStatus == null) { throw new Exception("工作流平台中,费用缓交开始环节流程未配置,请核查"); } //缓交申请流程中的ID(未提交、待审核) var applyStatusList = this.GetStartApproveStatusList(); //缓交申请(流程中) Expression> expChargeDelayApply = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expChargeDelayApply = expChargeDelayApply.And(x => x.StudentChargeID == chargeDelay.StudentChargeID); expChargeDelayApply = expChargeDelayApply.And(x => applyStatusList.Contains(x.RecordStatus)); //查询缓交申请工作流程结束环节状态 var chargeDelayEndtStatus = this.GetCorrectEndStatus(); if (chargeDelayEndtStatus == null) { throw new Exception("工作流平台中,费用缓交结束环节流程未配置,请核查"); } //缓交申请(审核通过) Expression> expChargeDelayPass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expChargeDelayPass = expChargeDelayPass.And(x => x.StudentChargeID == chargeDelay.StudentChargeID); expChargeDelayPass = expChargeDelayPass.And(x => x.RecordStatus == chargeDelayEndtStatus); //查询对应的缴交信息View(对应的应收名单信息全部查询,左联-待缓交金额、已缓交金额) var chargeDelayView = chargeDelayDAL.GetChargeDelayQueryView(expChargeDelay, expChargeDelayApply, expChargeDelayPass) .SingleOrDefault(); return chargeDelayView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(申请、修改) /// 同时对相应的缓交信息进行验证(缓交金额需在可缓交金额范围内) /// /// public void ChaegeDelayEdit(ChargeDelayView chargeDelayView) { try { //注:可通过缓交申请表单来获取相关缓交信息(目前暂时不采用此种方式) //查询缓交申请工作流程开始环节状态 var chargeDelayStartStatus = this.GetStartStatus(); if (chargeDelayStartStatus == null) { throw new Exception("工作流平台中,费用缓交开始环节流程未配置,请核查"); } if (chargeDelayView.ChargeDelayID == null || chargeDelayView.ChargeDelayID == Guid.Empty) { //申请 var chargeDelayStandardView = this.GetChargeDelayStandardView(chargeDelayView.UserID, chargeDelayView.ChargeYear, chargeDelayView.ChargeProjectID); if (chargeDelayStandardView == null) { throw new Exception("数据有误,请核查"); } //缓交金额需在可缓交金额范围内 if (chargeDelayStandardView.DelayAmount > chargeDelayStandardView.CanDelayAmount) { throw new Exception("缓交金额不能大于可缓交金额,请核查"); } else { EC_ChargeDelay newChargeDelay = new EC_ChargeDelay(); newChargeDelay.ChargeDelayID = Guid.NewGuid(); newChargeDelay.StudentChargeID = chargeDelayStandardView.StudentChargeID; newChargeDelay.DelayAmount = chargeDelayView.DelayAmount; newChargeDelay.DelayPercent = chargeDelayView.DelayPercent; newChargeDelay.Reason = chargeDelayView.Reason; SetNewStatus(newChargeDelay, chargeDelayStartStatus.Value); UnitOfWork.Add(newChargeDelay); } } else { //修改(只能对未开始流程的信息进行修改-未提交) if (chargeDelayView.RecordStatus != chargeDelayStartStatus) { throw new Exception("只能对未提交状态的信息进行修改"); } //缓交金额需在可缓交金额范围内 if (chargeDelayView.DelayAmount > chargeDelayView.CanDelayAmount) { throw new Exception("缓交金额不能大于可缓交金额,请核查"); } else { //查询对应的缓交信息 var chargeDelay = chargeDelayDAL.ChargeDelayRepository .GetList(x => x.ChargeDelayID == chargeDelayView.ChargeDelayID).SingleOrDefault(); chargeDelay.DelayAmount = chargeDelayView.DelayAmount; chargeDelay.DelayPercent = chargeDelayView.DelayPercent; chargeDelay.Reason = chargeDelayView.Reason; SetModifyStatus(chargeDelay); } } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool ChargeDelayDelete(List chargeDelayIDs) { try { //查询缓交申请工作流程开始环节状态 var chargeDelayStartStatus = this.GetStartStatus(); if (chargeDelayStartStatus == null) { throw new Exception("工作流平台中,费用缓交开始环节流程未配置,请核查"); } //查询对应的缓交信息流程状态ID var recordStatusList = chargeDelayDAL.ChargeDelayRepository.GetList(x => chargeDelayIDs.Contains(x.ChargeDelayID)) .Select(x => x.RecordStatus).ToList(); foreach (var recordStatus in recordStatusList) { if (recordStatus != chargeDelayStartStatus) { throw new Exception("只能对未提交状态的信息进行删除"); } } UnitOfWork.Delete(x => chargeDelayIDs.Contains(x.ChargeDelayID)); UnitOfWork.Commit(); return true; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 提交 /// /// /// /// /// public string SubmitChargeDelay(List chargeDelayIDs, Guid userID, string comment) { try { //查询缓交申请工作流程开始环节状态 var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,费用缓交开始环节流程未配置,请核查"); } //查询对应的缓交信息List var chargeDelayList = chargeDelayDAL.ChargeDelayRepository .GetList(x => chargeDelayIDs.Contains(x.ChargeDelayID)).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 var submitIDList = new List(); foreach (var chargeDelay in chargeDelayList) { if (chargeDelay.RecordStatus == startStatusID) { submitIDList.Add(chargeDelay.ChargeDelayID); success++; } else { fail++; } } this.StartUp(submitIDList, userID, comment); if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:选择提交的数据有误,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 审核(可批量) /// /// /// /// /// public void ApproveChargeDelay(List chargeDelayIDs, Guid userID, Guid actionID, string comment) { try { //查询对应的缓交信息List var chargeDelayList = chargeDelayDAL.ChargeDelayRepository .GetList(x => chargeDelayIDs.Contains(x.ChargeDelayID)).ToList(); var apprveIDList = new List(); foreach (var chargeDelayID in chargeDelayIDs) { //查询对应的缓交信息 var chargeDelay = chargeDelayList.Where(x => x.ChargeDelayID == chargeDelayID).SingleOrDefault(); if (chargeDelay == null) { throw new Exception("数据有误,请核查"); } apprveIDList.Add(chargeDelay.ChargeDelayID); } //审核 this.Approve(apprveIDList, userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的缓交名单信息View(学生平台) /// /// /// /// /// /// /// /// /// public IGridResultSet GetStudentChargeDelayViewGrid(ConfiguretView configuretView, Guid userID, int? chargeYearID, Guid? chargeProjectID, int? chargeDelayStatus, int pageIndex, int pageSize) { //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); //缓交名单 Expression> expChargeDelay = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeDelayStatus.HasValue) { //审批状态 expChargeDelay = expChargeDelay.And(x => x.RecordStatus == chargeDelayStatus); } //应收名单 Expression> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //用户信息ID expStudentCharge = expStudentCharge.And(x => x.UserID == userID); if (chargeYearID.HasValue) { //缴费学年 expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID); } if (chargeProjectID.HasValue) { //收费项目 expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //学生信息ID expStudent = expStudent.And(x => x.UserID == userID); var query = chargeDelayDAL.GetChargeDelayQueryAble(expChargeDelay, expStudentCharge, expStudent); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderBy(x => x.ChargeProjectStr).ThenByDescending(x => x.ChargeYear) .ThenBy(x => x.RecordStatus).ThenBy(x => x.CreateTime) .ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.RecordStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } /// /// 查询对应的缓交名单信息List(学生平台) /// /// /// /// /// /// /// public List GetStudentChargeDelayViewList(ConfiguretView configuretView, Guid userID, int? chargeYearID, Guid? chargeProjectID, int? chargeDelayStatus) { //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); //缓交名单 Expression> expChargeDelay = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (chargeDelayStatus.HasValue) { //审批状态 expChargeDelay = expChargeDelay.And(x => x.RecordStatus == chargeDelayStatus); } //应收名单 Expression> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //用户信息ID expStudentCharge = expStudentCharge.And(x => x.UserID == userID); if (chargeYearID.HasValue) { //缴费学年 expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID); } if (chargeProjectID.HasValue) { //收费项目 expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID); } //学生信息 Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //学生信息ID expStudent = expStudent.And(x => x.UserID == userID); var query = chargeDelayDAL.GetChargeDelayQueryAble(expChargeDelay, expStudentCharge, expStudent); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = query.OrderBy(x => x.ChargeProjectStr).ThenByDescending(x => x.ChargeYear) .ThenBy(x => x.RecordStatus).ThenBy(x => x.CreateTime) .ToList(); result.ForEach(x => x.RecordStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } } }