Browse Source

和田数据同步

master
dao 1 month ago
parent
commit
2ede1d6090
5 changed files with 457 additions and 1 deletions
  1. +344
    -0
      DigitalSchoolApi/Controllers/HTSchoolController.cs
  2. +27
    -0
      DigitalSchoolApi/Controllers/YKTController.cs
  3. +2
    -0
      DigitalSchoolApi/DigitalSchoolApi.csproj
  4. +83
    -0
      DigitalSchoolApi/Models/HtEntity.cs
  5. +1
    -1
      DigitalSchoolApi/Web.config

+ 344
- 0
DigitalSchoolApi/Controllers/HTSchoolController.cs View File

@@ -0,0 +1,344 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Dapper;
using DigitalSchoolApi.App_Data;
using DigitalSchoolApi.Models;
using Learun.Application.Organization;
using Learun.Util;
using Microsoft.AspNet.SignalR.Client;
using Newtonsoft.Json;
using Convert = System.Convert;
using DESEncrypt = Learun.Util.DESEncrypt;
using Md5Helper = Learun.Util.Md5Helper;

namespace DigitalSchoolApi.Controllers
{
/// <summary>
/// 塔里木学院定时需求
/// </summary>
public class HTSchoolController
{
private readonly static string _admsConnection = ConfigurationManager.ConnectionStrings["CoreDBString"].ConnectionString;
private readonly static string _misConnection = ConfigurationManager.ConnectionStrings["ConnectionPfcMisDBString"].ConnectionString;
private static string _htMiddleConnection = ConfigurationManager.ConnectionStrings["htMiddleDBString"].ConnectionString;

//private readonly static string _tlmMiddleConnection =ConfigurationManager.ConnectionStrings["TLMMiddleDBString"].ConnectionString;



#region 中间库同步到数校

/// <summary>
/// 从中间库同步系部数据
/// </summary>
public static void SyncDepartment()
{
try
{
IEnumerable<HTMiddleOrganize> entityList = null;
using (IDbConnection conn = new SqlConnection(_htMiddleConnection))
{
entityList = conn.Query<HTMiddleOrganize>("SELECT * FROM nc_orgnization");
}
using (IDbConnection conn = new SqlConnection(_admsConnection))
{
try
{
var maxSort = -1;
try
{
maxSort = conn.QueryFirstOrDefault<int>("select MAX(F_Order) FROM LR_BASE_DEPARTMENT");
}
catch (Exception e)
{
maxSort = -1;
}

//插入sql
foreach (var item in entityList)
{
DepartmentEntity model = null;
using (IDbConnection xbconn = new SqlConnection(_admsConnection))
{
model = xbconn.QueryFirstOrDefault<DepartmentEntity>($"select * from LR_BASE_DEPARTMENT where DeptNo='{item.CODE}'");
}
if (model == null)
{
maxSort++;
var id = item.ID.Length == 30 ? Guid.ParseExact(item.ID, "N") : Guid.NewGuid();
//没有就新增
var sql =
"INSERT INTO LR_BASE_DEPARTMENT (F_DepartmentId, F_CompanyId, F_ParentId, F_EnCode, F_FullName, F_Order,F_DeleteMark,F_EnabledMark) " +
$"VALUES ('{id}', '207fa1a9-160c-4943-a89b-8fa4db0547ce', '{item.FID}', '{item.CODE}', '{item.NAME}', {maxSort},0,1);";
conn.Execute(sql);
}
else
{
//存在就修改
var sql = $"UPDATE LR_BASE_DEPARTMENT SET F_FullName='{item.NAME}',F_ParentId='{item.FID}' where F_EnCode='{model.F_EnCode}';";
conn.Execute(sql);
}

}
//插入数据同步结果
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步部门信息到数校完成','部门同步数量:" +
entityList.Count() + "条',getdate())");
}
}
catch (Exception e)
{
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步部门信息到数校异常','" +
e.Message + "',getdate())");
}
}
}
}
catch (Exception e)
{
using (IDbConnection conn = new SqlConnection(_admsConnection))
{
conn.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步部门信息到数校异常','错误信息:" +
e.Message + "',getdate())");
}
}
}

/// <summary>
/// 从中间库同步学生数据
/// </summary>
public static void SyncStuInfoAcc()
{
try
{

IEnumerable<HTMiddleStuInfo> entityList = null;
using (IDbConnection conn = new SqlConnection(_htMiddleConnection))
{
entityList = conn.Query<HTMiddleStuInfo>($"SELECT * FROM nc_stuInfo");
}

try
{
//插入sql
foreach (var item in entityList)
{
var id = item.ID.Length == 30 ? Guid.ParseExact(item.ID, "N") : Guid.NewGuid();
var MZ = "";
var xb = item.GenderNo == "1" ? 1 : 0;

UserEntity model = null;
StuInfoBasicEntity stu = null;
using (IDbConnection xbconn = new SqlConnection(_admsConnection))
{
model = xbconn.QueryFirstOrDefault<UserEntity>($"select * from LR_Base_User where F_Account='{item.USERNAME}'");

if (model == null)
{

var key = Md5Helper.Encrypt(CreateNo(), 16).ToLower();
var pwd = Md5Helper.Encrypt(DESEncrypt.Encrypt(Md5Helper.Encrypt("ht123456", 32).ToLower(), key).ToLower(), 32).ToLower();

var userSql =
$"INSERT INTO LR_Base_User (F_UserId,F_EnCode,F_Account,F_Mobile,F_Password,F_Secretkey,F_RealName,F_Gender,F_CompanyId," +
$"F_DepartmentId,F_DeleteMark,F_EnabledMark,F_Description,F_CreateDate,F_CreateUserId,F_CreateUserName,F_IdentityCardNo) VALUES('{Guid.NewGuid():D}'," +
$"'{item.USERNAME}','{item.USERNAME}','{item.MOBILE}','{pwd}','{key}','{item.StuName}','{xb}','207fa1a9-160c-4943-a89b-8fa4db0547ce','{item.DeptNo}',0,1,'学生'," +
$"'{DateTime.Now:yyyy-MM-dd hh:mm:ss}','System','数据同步','{item.IdentityCardNo}');";

xbconn.Execute(userSql);

}
}

using (var conn=new SqlConnection(_misConnection))
{
stu= conn.QueryFirstOrDefault<StuInfoBasicEntity>($"select * from StuInfoBasic where StuNo='{item.USERNAME}'");

if (stu == null)
{
var sql= "INSERT INTO StuInfoBasic(StuId,StuNo,StuCode,NoticeNo,GraduateYear,ksh,DeptNo,MajorNo,Grade,ClassNo,StuName,SpellFull,GenderNo,Birthday,PartyFaceNo," +
"FamilyOriginNo,NationalityNo,ResidenceNo,HealthStatusNo,GraduateNo,OverseasChineseNo,GoodAt,IdentityCardNo,InSchoolAddress," +
"InSchoolTelephone,Remark,mobile,CheckMark,InSchoolStatus,F_SchoolId,EduSystem,StudyModality,XJZT,XSDQZT) " +
$"VALUES('{id}','{item.USERNAME}','{item.CODE}','','','', '{item.DeptNo}', '{item.MajorNo}'," +
$"'{item.Grade}','{item.ClassNo}','{item.StuName}', '','{xb}','','',''," +
$"'{item.NationalityNo}','','1','2','0','','{item.IdentityCardNo}','','',''," +
$"'{item.MOBILE}','1','','207fa1a9-160c-4943-a89b-8fa4db0547ce', '2', '1','','');";
conn.Execute(sql);
}
else
{
var sql =
$"UPDATE StuInfoBasic SET StuName='{item.StuName}',GenderNo={xb},IdentityCardNo='{item.IdentityCardNo}'," +
$"Grade='{item.Grade}',DeptNo='{item.DeptNo}',StuCode='{item.CODE}',mobile='{item.MOBILE}'," +
$"MajorNo='{item.MajorNo}',ClassNo='{item.ClassNo}' where StuNo='{stu.StuNo}';";
conn.Execute(sql);
}
}
}
//插入数据同步结果
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校完成','学生同步数量:" +
entityList.Count() + "条',getdate())");
}
}
catch (Exception e)
{
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校异常','" +
e.Message + "',getdate())");
}
}
}
catch (Exception e)
{
using (IDbConnection conn = new SqlConnection(_admsConnection))
{
conn.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校异常','错误信息:" +
e.Message + "',getdate())");
}
}
}

/// <summary>
/// 从中间库同步教师数据
/// </summary>
public static void SyncEmpInfoAcc()
{
try
{

IEnumerable<HTMiddleEmpInfo> entityList = null;
using (IDbConnection conn = new SqlConnection(_htMiddleConnection))
{
entityList = conn.Query<HTMiddleEmpInfo>($"SELECT * FROM nc_user");
}

try
{
//插入sql
foreach (var item in entityList)
{
var id = item.ID.Length == 30 ? Guid.ParseExact(item.ID, "N") : Guid.NewGuid();
var MZ = "";
var xb = item.GENDER == "1" ? 1 : 0;

UserEntity model = null;
EmpInfoEntity stu = null;
using (IDbConnection xbconn = new SqlConnection(_admsConnection))
{
model = xbconn.QueryFirstOrDefault<UserEntity>($"select * from LR_Base_User where F_Account='{item.USERNAME}'");

if (model == null)
{

var key = Md5Helper.Encrypt(CreateNo(), 16).ToLower();
var pwd = Md5Helper.Encrypt(DESEncrypt.Encrypt(Md5Helper.Encrypt("ht123456", 32).ToLower(), key).ToLower(), 32).ToLower();


var userSql =
$"INSERT INTO LR_Base_User (F_UserId,F_EnCode,F_Account,F_Mobile,F_Password,F_Secretkey,F_RealName,F_Gender,F_CompanyId," +
$"F_DepartmentId,F_DeleteMark,F_EnabledMark,F_Description,F_CreateDate,F_CreateUserId,F_CreateUserName,F_IdentityCardNo) VALUES('{Guid.NewGuid():D}'," +
$"'{item.USERNAME}','{item.USERNAME}','{item.MOBILE}','{pwd}','{key}','{item.NAME}','{xb}','207fa1a9-160c-4943-a89b-8fa4db0547ce','{item.MOCODE}',0,1,'教师'," +
$"'{DateTime.Now:yyyy-MM-dd hh:mm:ss}','System','数据同步','{item.CARDNO}');";

xbconn.Execute(userSql);


}

}

using (var conn = new SqlConnection(_misConnection))
{
stu = conn.QueryFirstOrDefault<EmpInfoEntity>($"select * from EmpInfo where EmpNo='{item.USERNAME}'");

if (stu == null)
{
var sql = "INSERT INTO EmpInfo (EmpId,EmpNo,EmpName,GenderNo,DeptNo,IdentityCardNo,mobile,EMail,IsInActiveStatus,CheckMark,F_CompanyId) " +
$"VALUES('{id}','{item.USERNAME}','{item.NAME}','{xb}','{item.MOCODE}','{item.CARDNO}', '{item.MOBILE}', '{item.EMAIL}'," +
$"'{item.STATUS}','1','207fa1a9-160c-4943-a89b-8fa4db0547ce');";
conn.Execute(sql);
}
else
{
var sql =
$"UPDATE EmpInfo SET EmpName='{item.NAME}',GenderNo={xb},IdentityCardNo='{item.CARDNO}'," +
$"DeptNo='{item.MOCODE}',mobile='{item.MOBILE}',EMail='{item.EMAIL}',IsInActiveStatus='{item.STATUS}' where EmpNo='{stu.EmpNo}';";
conn.Execute(sql);
}
}


}
//插入数据同步结果
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校完成','学生同步数量:" +
entityList.Count() + "条',getdate())");
}
}
catch (Exception e)
{
using (IDbConnection conncore = new SqlConnection(_admsConnection))
{
conncore.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校异常','" +
e.Message + "',getdate())");
}
}
}
catch (Exception e)
{
using (IDbConnection conn = new SqlConnection(_admsConnection))
{
conn.Execute(
"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校异常','错误信息:" +
e.Message + "',getdate())");
}
}
}
#endregion


private static string CreateNo()
{
Random random = new Random();
string strRandom = random.Next(1000, 10000).ToString(); //生成编号
string code = DateTime.Now.ToString("yyyyMMddHHmmss") + strRandom;//形如
return code;
}



}
}

+ 27
- 0
DigitalSchoolApi/Controllers/YKTController.cs View File

@@ -680,5 +680,32 @@ namespace DigitalSchoolApi.Controllers
}

#endregion

#region 和田数据同步

/// <summary>
/// 从中间库中同步到数校
/// </summary>
/// <returns></returns>
public IHttpActionResult SyncDataToDs()
{
//部门
RecurringJob.AddOrUpdate("HTSyncDepartmentToDs",
() => HTSchoolController.SyncDepartment(),
Cron.Daily(1), TimeZoneInfo.Local);

//教师
RecurringJob.AddOrUpdate("HTSyncEmpInfoToDs",
() => HTSchoolController.SyncEmpInfoAcc(),
Cron.Daily(1), TimeZoneInfo.Local);
//学生
RecurringJob.AddOrUpdate("HTSyncStuInfoToDs",
() => HTSchoolController.SyncStuInfoAcc(),
Cron.Daily(1), TimeZoneInfo.Local);

return Ok();
}
#endregion
}
}

+ 2
- 0
DigitalSchoolApi/DigitalSchoolApi.csproj View File

@@ -405,6 +405,7 @@
<Compile Include="Controllers\HLSchoolController.cs" />
<Compile Include="Controllers\PayFeeResultTwoController.cs" />
<Compile Include="Controllers\PayFeeResultController.cs" />
<Compile Include="Controllers\HTSchoolController.cs" />
<Compile Include="Controllers\TLMSchoolController.cs" />
<Compile Include="Controllers\EmailSendController.cs" />
<Compile Include="Controllers\CYDormitoryReturnController.cs" />
@@ -422,6 +423,7 @@
<Compile Include="Models\FinaChargeStuOrderEntity.cs" />
<Compile Include="Models\FinaChargeStuYearEntity.cs" />
<Compile Include="Models\FinaChargeStuYearItemEntity.cs" />
<Compile Include="Models\HtEntity.cs" />
<Compile Include="Models\NewsEntity.cs" />
<Compile Include="Models\EmailManagementEntity.cs" />
<Compile Include="Models\Acc_DormitoryBuildEntity.cs" />


+ 83
- 0
DigitalSchoolApi/Models/HtEntity.cs View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DigitalSchoolApi.Models
{
internal interface HtEntity
{
}

public class HTMiddleOrganize
{
public string ID { get; set; }

public string NAME { get; set; }

public string FID { get; set; }

public string CODE { get; set; }
}

public class HTMiddleStuInfo
{

public string ID { get; set; }
public string USERNAME { get; set; }

public string StuName { get; set; }

public string IdentityCardNo { get; set; }

public string NationalityNo { get; set; }

public string Grade { get; set; }

public string EntranceDate { get; set; }

public string RegisterDate { get; set; }

public string MailAddress { get; set; }

public string DeptNo { get; set; }

public string MajorNo { get; set; }

public string ClassNo { get; set; }

public string GenderNo { get; set; }

public string CODE { get; set; }

public string MOBILE { get; set; }

public string EMAIL { get; set; }
}

public class HTMiddleEmpInfo
{

public string ID { get; set; }

public string CODE { get; set; }


public string NAME { get; set; }
public string USERNAME { get; set; }

public string MOCODE { get; set; }

public string GENDER { get; set; }

public string CARDNO { get; set; }

public string MOBILE { get; set; }

public string EMAIL { get; set; }

public string STATUS { get; set; }

}
}

+ 1
- 1
DigitalSchoolApi/Web.config View File

@@ -68,7 +68,7 @@
<add name="XCMiddleDBString" connectionString="Data Source=FSZJK;Persist Security Info=True;User ID=fszjk;Password=fszjk20220705;Unicode=True" providerName="System.Data.OracleClient" />
<add name="HLZJMiddleDBString" connectionString="Data Source=ORCL;Persist Security Info=True;User ID=digitalschool;Password=digitalschool;Unicode=True" providerName="System.Data.OracleClient" />
<add name="TLMMiddleDBString" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=libraries.chaoxing.com)(PORT=38023)))(CONNECT_DATA=(SERVICE_NAME=jwxt01)));User Id=TLM_XG;Password=bbfc2d7e4fd0bd829b2f;Pooling='true';Max Pool Size=150" providerName="System.Data.OracleClient" />
<add name="htMiddleDBString" connectionString="Server=112.45.152.8,17049;Initial Catalog=tsgxtjh;User ID=tsgxtjh;Password=Qs6cYOzFoQupbr12MFZm" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.


Loading…
Cancel
Save