using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using EMIS.ViewModel;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.ChargeManage.ChargeTotal;
using EMIS.DataLogic.ChargeManage.ChargeTotal;
using System.Text.RegularExpressions;
using EMIS.CommonLogic.ChargeManage.ChargeSituation;
using EMIS.CommonLogic.StudentManage.StudentStatistics;
namespace EMIS.CommonLogic.ChargeManage.ChargeTotal
{
public class ChargeTotalServices : BaseServices, IChargeTotalServices
{
public ChargeTotalDAL ChargeTotalDAL { get; set; }
public IInSchoolSettingServices InSchoolSettingServices { get; set; }
public IChargeDelayServices IChargeDelayServices { get; set; }
///
/// 查询费用统计信息View(以班级信息分组统计)
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetChargeTotadViewGrid(ConfiguretView configuretView, Guid? collegeID,
int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int pageIndex, int pageSize)
{
//查询对应的全部流程环节信息(WorkflowStatusView)
var chargeDelayWorkflowStatusView = IChargeDelayServices.GetStatusViewList();
if (chargeDelayWorkflowStatusView == null || chargeDelayWorkflowStatusView.Count() <= 0)
{
throw new Exception("工作流平台中,费用缓交流程未配置,请核查");
}
//查询缓交申请工作流程结束环节状态ID(通过)
var chargeDelayEndtStatus = IChargeDelayServices.GetCorrectEndStatus();
if (chargeDelayEndtStatus == null)
{
throw new Exception("工作流平台中,费用缓交结束环节流程未配置,请核查");
}
//应收名单
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> expChargeDelayPass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
//缓交申请(审核通过)
expChargeDelayPass = expChargeDelayPass.And(x => x.RecordStatus == chargeDelayEndtStatus);
//学生信息
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 = ChargeTotalDAL.GetChargeTotalView(expStudentCharge, expChargeDelayPass, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.Grade == 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());
}
return this.GetQueryByDataRangeByCollege(query)
.OrderBy(x => x.ClassNo.Length).ThenBy(x => x.ClassNo)
.ThenByDescending(x => x.Grade).ThenBy(x => x.ChargeProjectStr)
.ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询费用统计信息List(以班级信息、缴费学年、收费项目分组统计)
///
///
///
///
///
///
///
///
///
///
///
///
public List GetChargeTotalViewList(ConfiguretView configuretView, Guid? collegeID,
int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus)
{
//查询对应的全部流程环节信息(WorkflowStatusView)
var chargeDelayWorkflowStatusView = IChargeDelayServices.GetStatusViewList();
if (chargeDelayWorkflowStatusView == null || chargeDelayWorkflowStatusView.Count() <= 0)
{
throw new Exception("工作流平台中,费用缓交流程未配置,请核查");
}
//查询缓交申请工作流程结束环节状态ID(通过)
var chargeDelayEndtStatus = IChargeDelayServices.GetCorrectEndStatus();
if (chargeDelayEndtStatus == null)
{
throw new Exception("工作流平台中,费用缓交结束环节流程未配置,请核查");
}
//应收名单
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> expChargeDelayPass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
//缓交申请(审核通过)
expChargeDelayPass = expChargeDelayPass.And(x => x.RecordStatus == chargeDelayEndtStatus);
//学生信息
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 = ChargeTotalDAL.GetChargeTotalView(expStudentCharge, expChargeDelayPass, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.Grade == 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());
}
return this.GetQueryByDataRangeByCollege(query)
.OrderBy(x => x.ClassNo.Length).ThenBy(x => x.ClassNo)
.ThenByDescending(x => x.Grade).ThenBy(x => x.ChargeProjectStr)
.ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
.ToList();
}
///
/// 统计相应的费用信息(应收总额、实收总额等)
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public ChargeTotalSumView GetTotalView(ConfiguretView configuretView, Guid? collegeID,
int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem,
int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int pageIndex, int pageSize)
{
//查询对应的全部流程环节信息(WorkflowStatusView)
var chargeDelayWorkflowStatusView = IChargeDelayServices.GetStatusViewList();
if (chargeDelayWorkflowStatusView == null || chargeDelayWorkflowStatusView.Count() <= 0)
{
throw new Exception("工作流平台中,费用缓交流程未配置,请核查");
}
//查询缓交申请工作流程结束环节状态ID(通过)
var chargeDelayEndtStatus = IChargeDelayServices.GetCorrectEndStatus();
if (chargeDelayEndtStatus == null)
{
throw new Exception("工作流平台中,费用缓交结束环节流程未配置,请核查");
}
//应收名单
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> expChargeDelayPass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
//缓交申请(审核通过)
expChargeDelayPass = expChargeDelayPass.And(x => x.RecordStatus == chargeDelayEndtStatus);
//学生信息
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 = ChargeTotalDAL.GetChargeTotalView(expStudentCharge, expChargeDelayPass, expStudent);
if (collegeID.HasValue)
{
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
query = query.Where(x => x.Grade == 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 chargeTotalViewList = this.GetQueryByDataRangeByCollege(query).ToList();
int? chargeCountSum = 0;
decimal? amountSum = 0;
decimal? chargeAmountSum = 0;
decimal? actualAmountSum = 0;
int? delayCountSum = 0;
decimal? delayAmountSum = 0;
int? paymenCountSum = 0;
decimal? paymenAmountSum = 0;
foreach (var chargeTotalView in chargeTotalViewList)
{
chargeCountSum += chargeTotalView.ChargeCount;
amountSum += chargeTotalView.Amount;
chargeAmountSum += chargeTotalView.ChargeAmount;
actualAmountSum += chargeTotalView.ActualAmount;
delayCountSum += chargeTotalView.DelayCount;
delayAmountSum += chargeTotalView.DelayAmount;
paymenCountSum += chargeTotalView.PaymenCount;
paymenAmountSum += chargeTotalView.PaymenAmount;
}
var chargeTotalSumView = new ChargeTotalSumView();
chargeTotalSumView.ChargeCountSum = chargeCountSum;
chargeTotalSumView.AmountSum = amountSum;
chargeTotalSumView.ChargeAmountSum = chargeAmountSum;
chargeTotalSumView.ActualAmountSum = actualAmountSum;
chargeTotalSumView.DelayCountSum = delayCountSum;
chargeTotalSumView.DelayAmountSum = delayAmountSum;
chargeTotalSumView.PaymenCountSum = paymenCountSum;
chargeTotalSumView.PaymenAmountSum = paymenAmountSum;
return chargeTotalSumView;
}
}
}