using Edu.Model.Entity.EduTask;
using Edu.Model.ViewModel.EduTask;
using Edu.Repository.EduTask;
using System.Collections.Generic;
using VT.FW.AOP.CustomerAttribute;
using VT.FW.DB;

namespace Edu.Module.EduTask
{
    /// <summary>
    /// 调课计划处理类
    /// </summary>
    public class ChangeClassPlanModule
    {
        /// <summary>
        /// 教务单据仓储层对象
        /// </summary>
        private readonly RB_Education_ReceiptRepository education_ReceiptRepository = new RB_Education_ReceiptRepository();

        /// <summary>
        /// 调课计划仓储层对象
        /// </summary>
        private readonly RB_Change_ClassPlanRepository change_ClassPlanRepository = new RB_Change_ClassPlanRepository();



        /// <summary>
        /// 获取调课计划列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Change_ClassPlan_ViewModel> GetChangeClassPlanListModule(RB_Change_ClassPlan_ViewModel query)
        {
            return change_ClassPlanRepository.GetChangeClassPlanListRepository(query);
        }



        public bool UpdateChangeClassPlan(int id)
        {

            return change_ClassPlanRepository.UpdateChangeClassPlan(id);
        }

        /// <summary>
        /// 新增修改调课计划
        /// </summary>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool SetChangeClassPlanModule(RB_Change_ClassPlan_ViewModel extModel)
        {
            bool flag = false;
            if (extModel.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Change_ClassPlan_ViewModel.ChangeType),extModel.ChangeType },
                    {nameof(RB_Change_ClassPlan_ViewModel.MoveType),extModel.MoveType },
                    {nameof(RB_Change_ClassPlan_ViewModel.TakeEffectTime),extModel.TakeEffectTime },
                    {nameof(RB_Change_ClassPlan_ViewModel.SourceData),extModel.SourceData },
                    {nameof(RB_Change_ClassPlan_ViewModel.TargetData),extModel.TargetData },
                    {nameof(RB_Change_ClassPlan_ViewModel.UpdateBy),extModel.UpdateBy },
                    {nameof(RB_Change_ClassPlan_ViewModel.UpdateTime),extModel.UpdateTime },
                };
                flag = change_ClassPlanRepository.Update(fileds, new WhereHelper(nameof(RB_Change_ClassPlan_ViewModel.Id), extModel.Id));
            }
            else
            {
                var newId = change_ClassPlanRepository.Insert(extModel);
                extModel.Id = newId;
                flag = newId > 0;
                if (flag)
                {
                    var educationReceipt = new RB_Education_Receipt()
                    {
                        Id = 0,
                        Title = "调课申请",
                        ReceiptType = Common.Enum.Finance.ReceiptTypeEnum.ChangeClass,
                        RelationId = newId,
                        ClassId = extModel.ClassId,
                        Group_Id = extModel.Group_Id,
                        School_Id = extModel.School_Id,
                        CreateBy = extModel.CreateBy,
                        CreateTime = extModel.CreateTime,
                        UpdateBy = extModel.UpdateBy,
                        UpdateTime = extModel.UpdateTime,
                        VerifyStatus = Common.Enum.EduTask.EduTaskRrocessStatus.NotAudit
                    };
                    flag = education_ReceiptRepository.SetEducationReceiptRepository(educationReceipt, out string message);
                }
            }
            return flag;
        }
    }
}
