diff --git a/DigitalSchoolApi/Controllers/HTSchoolController.cs b/DigitalSchoolApi/Controllers/HTSchoolController.cs index 7ef35bb..28c9436 100644 --- a/DigitalSchoolApi/Controllers/HTSchoolController.cs +++ b/DigitalSchoolApi/Controllers/HTSchoolController.cs @@ -20,6 +20,7 @@ using Learun.Application.Organization; using Learun.Util; using Microsoft.AspNet.SignalR.Client; using Newtonsoft.Json; +using static DigitalSchoolApi.Controllers.HKAttendanceController; using Convert = System.Convert; using DESEncrypt = Learun.Util.DESEncrypt; using Md5Helper = Learun.Util.Md5Helper; @@ -142,14 +143,21 @@ namespace DigitalSchoolApi.Controllers //插入sql foreach (var item in entityList) { - var id = item.ID.Length == 30 ? Guid.ParseExact(item.ID, "N") : Guid.NewGuid(); + var id = Guid.NewGuid().ToString(); var MZ = ""; var xb = item.GenderNo == "1" ? 1 : 0; + UserEntity model = null; StuInfoBasicEntity stu = null; using (IDbConnection xbconn = new SqlConnection(_admsConnection)) { + var dept = xbconn.QueryFirstOrDefault($"select * from LR_BASE_DEPARTMENT where F_EnCode='{item.DeptNo}'"); + var deptId = string.Empty; + if (dept != null) + { + deptId = dept.F_DepartmentId; + } model = xbconn.QueryFirstOrDefault($"select * from LR_Base_User where F_Account='{item.USERNAME}'"); if (model == null) @@ -157,27 +165,39 @@ namespace DigitalSchoolApi.Controllers 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,'学生'," + + $"F_DepartmentId,F_DeleteMark,F_EnabledMark,F_Description,F_CreateDate,F_CreateUserId,F_CreateUserName,F_IdentityCardNo) VALUES('{id}'," + + $"'{item.USERNAME}','{item.USERNAME}','{item.MOBILE}','{pwd}','{key}','{item.StuName}',{xb},'207fa1a9-160c-4943-a89b-8fa4db0547ce','{deptId}',0,1,'学生'," + $"'{DateTime.Now:yyyy-MM-dd hh:mm:ss}','System','数据同步','{item.IdentityCardNo}');"; xbconn.Execute(userSql); } - + else + { + id = model.F_UserId; + var sql = $"UPDATE LR_Base_User SET F_RealName='{item.StuName}',F_Gender={xb},F_DepartmentId='{deptId}' WHERE F_Account='{item.USERNAME}'"; + xbconn.Execute(sql); + } + //设置默认角色 + var rel = xbconn.QueryFirstOrDefault($"select * from LR_Base_UserRelation where F_UserId='{id}' and F_ObjectId='0cfc388c-80e6-4cf0-b53b-02201827490a'"); + if (rel == null) + { + var sql = $"insert into LR_Base_UserRelation (F_UserRelationId,F_UserId,F_Category,F_ObjectId,F_CreateDate,F_CreateUserId,F_CreateUserName) values ('{Guid.NewGuid()}','{id}',1,'0cfc388c-80e6-4cf0-b53b-02201827490a','{DateTime.Now}','System','同步生成')"; + xbconn.Execute(sql); + } } - using (IDbConnection conn =new SqlConnection(_misConnection)) + using (IDbConnection conn = new SqlConnection(_misConnection)) { - stu= conn.QueryFirstOrDefault($"select * from StuInfoBasic where StuNo='{item.USERNAME}'"); + stu = conn.QueryFirstOrDefault($"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," + + 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) " + $"VALUES('{id}','{item.USERNAME}','{item.CODE}','','','', '{item.DeptNo}', '{item.MajorNo}'," + @@ -194,10 +214,10 @@ namespace DigitalSchoolApi.Controllers $"MajorNo='{item.MajorNo}',ClassNo='{item.ClassNo}' where StuNo='{stu.StuNo}';"; conn.Execute(sql); } - + } - - + + } //插入数据同步结果 using (IDbConnection conncore = new SqlConnection(_admsConnection)) @@ -241,13 +261,13 @@ namespace DigitalSchoolApi.Controllers { entityList = conn.Query($"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 id = Guid.NewGuid().ToString(); var MZ = ""; var xb = item.GENDER == "男性" ? 1 : 0; @@ -255,6 +275,12 @@ namespace DigitalSchoolApi.Controllers EmpInfoEntity stu = null; using (IDbConnection xbconn = new SqlConnection(_admsConnection)) { + var dept = xbconn.QueryFirstOrDefault($"select * from LR_BASE_DEPARTMENT where F_EnCode='{item.MOCODE}'"); + var deptId = string.Empty; + if (dept != null) + { + deptId = dept.F_DepartmentId; + } model = xbconn.QueryFirstOrDefault($"select * from LR_Base_User where F_Account='{item.USERNAME}'"); if (model == null) @@ -266,13 +292,26 @@ 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,'教师'," + + $"F_DepartmentId,F_DeleteMark,F_EnabledMark,F_Description,F_CreateDate,F_CreateUserId,F_CreateUserName,F_IdentityCardNo) VALUES('{id}'," + + $"'{item.USERNAME}','{item.USERNAME}','{item.MOBILE}','{pwd}','{key}','{item.NAME}',{xb},'207fa1a9-160c-4943-a89b-8fa4db0547ce','{deptId}',0,1,'教师'," + $"'{DateTime.Now:yyyy-MM-dd hh:mm:ss}','System','数据同步','{item.CARDNO}');"; xbconn.Execute(userSql); } + else + { + id = model.F_UserId; + var sql = $"UPDATE LR_Base_User SET F_RealName='{item.NAME}',F_Gender={xb},F_DepartmentId='{deptId}' WHERE F_Account='{item.USERNAME}'"; + xbconn.Execute(sql); + } + //设置默认角色 + var rel = xbconn.QueryFirstOrDefault($"select * from LR_Base_UserRelation where F_UserId='{id}' and F_ObjectId='ed811d67-59d6-4dfa-8061-299b73388e69'"); + if(rel==null) + { + var sql = $"insert into LR_Base_UserRelation (F_UserRelationId,F_UserId,F_Category,F_ObjectId,F_CreateDate,F_CreateUserId,F_CreateUserName) values ('{Guid.NewGuid()}','{id}',1,'ed811d67-59d6-4dfa-8061-299b73388e69','{DateTime.Now}','System','同步生成')"; + xbconn.Execute(sql); + } } using (IDbConnection conn = new SqlConnection(_misConnection))