NewGaoKaoApi/New_College.Services/T_LongIdMapServices.cs

271 lines
12 KiB
C#

using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
using New_College.IRepository;
using New_College.Common.Excel;
using System.Data;
using System.Threading.Tasks;
using System;
using System.Linq;
using System.Collections.Generic;
namespace New_College.Services
{
public class T_LongIdMapServices : BaseServices<T_LongIdMap>, IT_LongIdMapServices
{
private readonly IBaseRepository<T_LongIdMap> _dal;
private readonly IT_EnrollmentBatchRepository t_EnrollmentBatchRepository;
private readonly IT_EnrollmentPlaneRepository t_EnrollmentPlaneRepository;
private readonly IT_EnrollmentPlanedescRepository t_EnrollmentPlanedescRepository;
private readonly ID_LongIdMapRepository d_LongIdMapRepository;
private readonly IT_BatchlineRepository t_BatchlineRepository;
private readonly IT_BatchTypeInfoRepository t_BatchTypeInfoRepository;
public T_LongIdMapServices(IBaseRepository<T_LongIdMap> dal
, IT_EnrollmentBatchRepository IT_EnrollmentBatchRepository
, IT_EnrollmentPlaneRepository IT_EnrollmentPlaneRepository
, IT_EnrollmentPlanedescRepository IT_EnrollmentPlanedescRepository
, ID_LongIdMapRepository ID_LongIdMapRepository
, IT_BatchlineRepository IT_BatchlineRepository
, IT_BatchTypeInfoRepository IT_BatchTypeInfoRepository)
{
this._dal = dal;
t_EnrollmentBatchRepository = IT_EnrollmentBatchRepository;
t_EnrollmentPlaneRepository = IT_EnrollmentPlaneRepository;
t_EnrollmentPlanedescRepository = IT_EnrollmentPlanedescRepository;
d_LongIdMapRepository = ID_LongIdMapRepository;
t_BatchlineRepository = IT_BatchlineRepository;
t_BatchTypeInfoRepository = IT_BatchTypeInfoRepository;
base.BaseDal = dal;
}
#region EnrollmentBatch
/// <summary>
/// EnrollmentBatch
/// </summary>
/// <returns></returns>
public async Task<bool> ImportEnrollmentBatch()
{
var dataSet = ExcelUtil.ReadExcelToDataSet("D:\\Ashuju\\志愿填报\\EnrollmentBatch.xlsx");
if (dataSet.Tables.Count > 0)
{
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string id = dr["_id"].ToString();
string areaName = dr["areaName"].ToString();
string year = dr["year"].ToString();
string batch_name = dr["batch_name"].ToString();
string Type = dr["Type"].ToString();
string subjectlevel = dr["subjectlevel"].ToString();
var info = await t_EnrollmentBatchRepository.Add(new T_EnrollmentBatch()
{
AreaName = areaName,
Year = Convert.ToInt32(year),
Batch_name = batch_name,
Subjectlevel = Convert.ToInt32(subjectlevel),
Type = Type,
});
if (info > 0)
{
await _dal.Add(new T_LongIdMap() { longid = id, newid = info, tablename = "EnrollmentBatch" });
}
}
}
return true;
}
#endregion
#region EnrollmentPlane
/// <summary>
/// EnrollmentPlane
/// </summary>
/// <returns></returns>
public async Task<bool> ImportEnrollmentPlane()
{
var dataSet = ExcelUtil.ReadExcelToDataSet("D:\\Ashuju\\志愿填报\\EnrollmentPlane.xlsx");
if (dataSet.Tables.Count > 0)
{
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string id = dr["_id"].ToString();
string EnrollmentName = dr["EnrollmentName"].ToString();
string Area_Id = dr["Area_Id"].ToString();
string Years = dr["Years"].ToString();
var info = await t_EnrollmentPlaneRepository.Add(new T_EnrollmentPlane()
{
Area_Id = Convert.ToInt32(Area_Id),
EnrollmentName = EnrollmentName,
Years = Convert.ToInt32(Years),
});
if (info > 0)
{
await _dal.Add(new T_LongIdMap() { longid = id, newid = info, tablename = "EnrollmentPlane" });
}
}
}
return true;
}
#endregion
#region EnrollmentPlanedesc
/// <summary>
/// EnrollmentPlanedesc
/// </summary>
/// <returns></returns>
public async Task<bool> ImportEnrollmentPlanedesc()
{
var dlongidmap = await d_LongIdMapRepository.Query(x => x.IsDelete == false);
var PlanInfo = await _dal.Query(x => x.IsDelete == false && x.tablename == "EnrollmentPlane");
var BatchInfo = await _dal.Query(x => x.IsDelete == false && x.tablename == "EnrollmentBatch");
for (int i = 1; i <= 29; i++)
{
var dataSet = ExcelUtil.ReadExcelToDataSet("D:\\Ashuju\\志愿填报\\EnrollmentPlanedesc\\" + i + ".xlsx");
if (dataSet.Tables.Count > 0)
{
List<T_LongIdMap> T_LongIdMaplist = new List<T_LongIdMap>() { };
List<T_EnrollmentPlanedesc> T_EnrollmentPlanedesclist = new List<T_EnrollmentPlanedesc>() { };
int num = 1;
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string id = dr["_id"].ToString();
string Name = dr["Name"].ToString();
string PlanId = dr["PlanId"].ToString();
string BatchtypeId = dr["BatchtypeId"].ToString();
string UniversityId = dr["UniversityId"].ToString();
string Majorgroup = dr["Majorgroup"].ToString();
string Subjectclaim = dr["Subjectclaim"].ToString();
string Plancount = dr["Plancount"].ToString() == "" ? "0" : dr["Plancount"].ToString() == null ? "0" : dr["Plancount"].ToString();
string Tuitionfee = dr["Tuitionfee"].ToString();
string Languageclaim = dr["Languageclaim"].ToString();
string Tags = dr["Tags"].ToString();
string Scoreline = dr["Scoreline"].ToString() == "" ? "0" : dr["Scoreline"].ToString() == null ? "0" : dr["Scoreline"].ToString();
string Remark = dr["Remark"].ToString();
string Studyyears = dr["Studyyears"].ToString();
string MajorName = dr["MajorName"].ToString();
var schoollowscore = dr["schoollowscore"].ToString() == "" ? "0" : dr["schoollowscore"].ToString() == null ? "0" : dr["schoollowscore"].ToString();
string schoolprovinline = dr["schoolprovinline"].ToString() == "" ? "0" : dr["schoolprovinline"].ToString() == null ? "0" : dr["schoolprovinline"].ToString();
string majoraverage = dr["majoraverage"].ToString() == "" ? "0" : dr["majoraverage"].ToString() == null ? "0" : dr["majoraverage"].ToString();
string heightscore = dr["heightscore"].ToString() == "" ? "0" : dr["heightscore"].ToString() == null ? "0" : dr["heightscore"].ToString();
string scorepostion = dr["scorepostion"].ToString() == "" ? "0" : dr["scorepostion"].ToString() == null ? "0" : dr["scorepostion"].ToString();
int newid = (i - 1) * 10000 + num;
T_EnrollmentPlanedesclist.Add(new T_EnrollmentPlanedesc()
{
Id = newid,
//Name = Name,
BatchtypeId = BatchInfo.Where(x => x.longid == BatchtypeId).Select(x => x.newid).FirstOrDefault(),
PlanId = PlanInfo.Where(x => x.longid == PlanId).Select(x => x.newid).FirstOrDefault(),
UniversityId = dlongidmap.Where(x => x.longid == UniversityId).Select(x => x.newid).FirstOrDefault(),
//Majorgroup = Majorgroup,
Subjectclaim = Subjectclaim,
Plancount = Convert.ToInt32(Plancount),
Tuitionfee = Tuitionfee,
//Languageclaim = Languageclaim,
Tags = Tags,
Scoreline = float.Parse(Scoreline),
Remark = Remark,
Studyyears = Studyyears,
MajorName = MajorName,
//schoollowscore = float.Parse(schoollowscore),
//schoolprovinline = float.Parse(schoolprovinline),
majoraverage = float.Parse(majoraverage),
//heightscore = float.Parse(heightscore),
scorepostion = float.Parse(scorepostion)
});
T_LongIdMaplist.Add(new T_LongIdMap() { longid = id, newid = newid, tablename = "EnrollmentPlanedesc" });
num++;
}
await t_EnrollmentPlanedescRepository.Add(T_EnrollmentPlanedesclist);
await _dal.Add(T_LongIdMaplist);
}
}
return true;
}
#endregion
#region Batchline
/// <summary>
/// Batchline
/// </summary>
/// <returns></returns>
public async Task<bool> ImportBatchline()
{
var dataSet = ExcelUtil.ReadExcelToDataSet("D:\\Ashuju\\志愿填报\\Batchline.xlsx");
if (dataSet.Tables.Count > 0)
{
List<T_LongIdMap> list = new List<T_LongIdMap>() { };
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string id = dr["_id"].ToString();
string areaName = dr["areaName"].ToString();
string year = dr["year"].ToString();
string average = dr["average"].ToString();
string type_name = dr["type_name"].ToString();
string batch_name = dr["batch_name"].ToString();
var info = await t_BatchlineRepository.Add(new T_Batchline()
{
AreaName = areaName,
Average = Convert.ToInt32(average),
Batch_name = batch_name,
Type_name = type_name,
Year = Convert.ToInt32(year)
});
if (info > 0)
{
list.Add(new T_LongIdMap() { longid = id, newid = info, tablename = "Batchline" });
}
}
await _dal.Add(list);
}
return true;
}
#endregion
#region BatchTypeInfo
/// <summary>
/// BatchTypeInfo
/// </summary>
/// <returns></returns>
public async Task<bool> ImportBatchTypeInfo()
{
var dataSet = ExcelUtil.ReadExcelToDataSet("D:\\Ashuju\\志愿填报\\BatchTypeInfo.xlsx");
if (dataSet.Tables.Count > 0)
{
List<T_LongIdMap> list = new List<T_LongIdMap>() { };
foreach (DataRow dr in dataSet.Tables[0].Rows)
{
string id = dr["_id"].ToString();
string AreaName = dr["AreaName"].ToString();
string BatchName = dr["BatchName"].ToString();
string Year = dr["Year"].ToString();
var info = await t_BatchTypeInfoRepository.Add(new T_BatchTypeInfo()
{
AreaName = AreaName,
Year = Convert.ToInt32(Year),
BatchName=BatchName,
});
if (info > 0)
{
list.Add(new T_LongIdMap() { longid = id, newid = info, tablename = "BatchTypeInfo" });
}
}
await _dal.Add(list);
}
return true;
}
#endregion
}
}