diff --git a/DigitalSchoolApi/App_Data/LogHelper.cs b/DigitalSchoolApi/App_Data/LogHelper.cs new file mode 100644 index 0000000..491d0ec --- /dev/null +++ b/DigitalSchoolApi/App_Data/LogHelper.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; + +namespace Util.Log +{ + public class LogHelper + { + public static void Info(string msg) + { + try + { + #region log + //文件路径 + string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + //文件 + string fileName = Path.Combine(path, $"{DateTime.Now:yyyyMMdd}.log"); + string message = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} logInfo:{msg}。{Environment.NewLine}"; + File.AppendAllText(fileName, message); + #endregion + } + catch + { + + + } + } + } +} diff --git a/DigitalSchoolApi/Controllers/HTSchoolController.cs b/DigitalSchoolApi/Controllers/HTSchoolController.cs index 752d89b..7ef35bb 100644 --- a/DigitalSchoolApi/Controllers/HTSchoolController.cs +++ b/DigitalSchoolApi/Controllers/HTSchoolController.cs @@ -73,7 +73,7 @@ namespace DigitalSchoolApi.Controllers DepartmentEntity model = null; using (IDbConnection xbconn = new SqlConnection(_admsConnection)) { - model = xbconn.QueryFirstOrDefault($"select * from LR_BASE_DEPARTMENT where DeptNo='{item.CODE}'"); + model = xbconn.QueryFirstOrDefault($"select * from LR_BASE_DEPARTMENT where F_EnCode='{item.CODE}'"); } if (model == null) { @@ -162,17 +162,16 @@ namespace DigitalSchoolApi.Controllers 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,'学生'," + + $"'{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)) + using (IDbConnection conn =new SqlConnection(_misConnection)) { stu= conn.QueryFirstOrDefault($"select * from StuInfoBasic where StuNo='{item.USERNAME}'"); @@ -180,11 +179,11 @@ namespace DigitalSchoolApi.Controllers { 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) " + + "InSchoolTelephone,Remark,mobile,CheckMark,InSchoolStatus,F_SchoolId,EduSystem,StudyModality) " + $"VALUES('{id}','{item.USERNAME}','{item.CODE}','','','', '{item.DeptNo}', '{item.MajorNo}'," + - $"'{item.Grade}','{item.ClassNo}','{item.StuName}', '','{xb}','','',''," + + $"'{item.Grade}','{item.ClassNo}','{item.StuName}', '',{xb},'','',''," + $"'{item.NationalityNo}','','1','2','0','','{item.IdentityCardNo}','','',''," + - $"'{item.MOBILE}','1','','207fa1a9-160c-4943-a89b-8fa4db0547ce', '2', '1','','');"; + $"'{item.MOBILE}','1','','207fa1a9-160c-4943-a89b-8fa4db0547ce', '2', '1');"; conn.Execute(sql); } else @@ -195,6 +194,7 @@ namespace DigitalSchoolApi.Controllers $"MajorNo='{item.MajorNo}',ClassNo='{item.ClassNo}' where StuNo='{stu.StuNo}';"; conn.Execute(sql); } + } @@ -212,8 +212,8 @@ namespace DigitalSchoolApi.Controllers 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())"); + "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),998,'从中间库同步学生信息到数校异常','" + + e.ToString() + "',getdate())"); } } } @@ -223,7 +223,7 @@ namespace DigitalSchoolApi.Controllers { conn.Execute( "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步学生信息到数校异常','错误信息:" + - e.Message + "',getdate())"); + e.ToString() + "',getdate())"); } } } @@ -241,7 +241,7 @@ namespace DigitalSchoolApi.Controllers { entityList = conn.Query($"SELECT * FROM nc_user"); } - + try { //插入sql @@ -249,7 +249,7 @@ namespace DigitalSchoolApi.Controllers { var id = item.ID.Length == 30 ? Guid.ParseExact(item.ID, "N") : Guid.NewGuid(); var MZ = ""; - var xb = item.GENDER == "1" ? 1 : 0; + var xb = item.GENDER == "男性" ? 1 : 0; UserEntity model = null; EmpInfoEntity stu = null; @@ -267,24 +267,21 @@ namespace DigitalSchoolApi.Controllers 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,'教师'," + + $"'{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)) + using (IDbConnection conn = new SqlConnection(_misConnection)) { stu = conn.QueryFirstOrDefault($"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}'," + + $"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); } @@ -303,7 +300,7 @@ namespace DigitalSchoolApi.Controllers 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,'从中间库同步学生信息到数校完成','学生同步数量:" + + "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),000,'从中间库同步老师信息到数校完成','老师同步数量:" + entityList.Count() + "条',getdate())"); } } @@ -312,8 +309,8 @@ namespace DigitalSchoolApi.Controllers 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())"); + "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),998,'从中间库同步老师信息到数校异常','" + + e.ToString() + "',getdate())"); } } } @@ -322,8 +319,8 @@ namespace DigitalSchoolApi.Controllers 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())"); + "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'从中间库同步老师信息到数校异常','错误信息:" + + e.ToString() + "',getdate())"); } } } diff --git a/DigitalSchoolApi/DigitalSchoolApi.csproj b/DigitalSchoolApi/DigitalSchoolApi.csproj index 799cabb..ffb3842 100644 --- a/DigitalSchoolApi/DigitalSchoolApi.csproj +++ b/DigitalSchoolApi/DigitalSchoolApi.csproj @@ -382,6 +382,7 @@ +