|
|
@@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |