Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

2551 wiersze
146 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Data.OracleClient;
  6. using System.Data.SqlClient;
  7. using System.EnterpriseServices.Internal;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Net.Http;
  12. using System.Net.Sockets;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Web;
  17. using System.Web.Http;
  18. using Dapper;
  19. using DigitalSchoolApi.Models;
  20. using DigitalSchoolApi.SynServiceReference;
  21. using DigitalSchoolApi.WebReference;
  22. using Learun.Application.Organization;
  23. using Learun.Application.TwoDevelopment.EducationalAdministration;
  24. using Learun.Application.TwoDevelopment.ReceiveSendFeeManagement;
  25. using Learun.Util;
  26. using MySql.Data.MySqlClient;
  27. using Newtonsoft.Json;
  28. using Newtonsoft.Json.Linq;
  29. namespace DigitalSchoolApi.Controllers
  30. {
  31. public static class YKTTrabs
  32. {
  33. private static string _coresqlConnection =
  34. ConfigurationManager.ConnectionStrings["CoreDBString"].ConnectionString;
  35. private static string _coresqlConnection2 =
  36. ConfigurationManager.ConnectionStrings["CoreDBString2"].ConnectionString;
  37. private static string _sqlConnection =
  38. ConfigurationManager.ConnectionStrings["ConnectionPfcMisDBString"].ConnectionString;
  39. private static string _sqlConnection2 =
  40. ConfigurationManager.ConnectionStrings["ConnectionPfcMisDBString2"].ConnectionString;
  41. private static string _yktConnection = ConfigurationManager.ConnectionStrings["YKTDBString"].ConnectionString;
  42. private static string _mjConnection = ConfigurationManager.ConnectionStrings["mjDBString"].ConnectionString;
  43. private static string _tsConnection = ConfigurationManager.ConnectionStrings["tsDBString"].ConnectionString;
  44. private static string _bachujavaConnection = ConfigurationManager.ConnectionStrings["bachuJavaDBString"].ConnectionString;
  45. //西昌中间库
  46. private static string _xzMiddleConnection = ConfigurationManager.ConnectionStrings["XCMiddleDBString"].ConnectionString;
  47. public static IEnumerable<TSource> DistinctBy<TSource, TKey>
  48. (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
  49. {
  50. HashSet<TKey> seenKeys = new HashSet<TKey>();
  51. foreach (TSource element in source)
  52. {
  53. if (seenKeys.Add(keySelector(element)))
  54. {
  55. yield return element;
  56. }
  57. }
  58. }
  59. private static readonly HttpClient Client;
  60. static YKTTrabs()
  61. {
  62. Client = new HttpClient();
  63. }
  64. public class dept
  65. {
  66. public string deptName { get; set; }
  67. public string deptType { get; set; }
  68. public string deptCode { get; set; }
  69. public string upCode { get; set; }
  70. public int delState { get; set; }
  71. }
  72. public class user
  73. {
  74. public int sex { get; set; }
  75. public string phone { get; set; }
  76. public string name { get; set; }
  77. public string account { get; set; }
  78. public string deptCode { get; set; }
  79. public int delState { get; set; }
  80. }
  81. public class lesson
  82. {
  83. public string courseNature { get; set; }
  84. public int? credits { get; set; }
  85. public string deptCode { get; set; }
  86. public string courseCode { get; set; }
  87. public int? delState { get; set; }
  88. public string courseName { get; set; }
  89. }
  90. public class major
  91. {
  92. public decimal eduTypeCode { get; set; }
  93. public string deptCode { get; set; }
  94. public string majorCode { get; set; }
  95. public string majorName { get; set; }
  96. public string majorTeacherAmount { get; set; }
  97. public int? delState { get; set; }
  98. }
  99. public class classInfo
  100. {
  101. public int? graduateState { get; set; }
  102. public string headTeacherNum { get; set; }
  103. public string classCode { get; set; }
  104. public string className { get; set; }
  105. public string majorCode { get; set; }
  106. public int? delState { get; set; }
  107. public string springAutumn { get; set; }
  108. public string headCount { get; set; }
  109. public string gradeCode { get; set; }
  110. }
  111. public class studentInfo
  112. {
  113. /// <summary>
  114. /// 部门 经管部
  115. /// </summary>
  116. public string facultyName { get; set; }
  117. /// <summary>
  118. /// 2017级
  119. /// </summary>
  120. public string gradeName { get; set; }
  121. public string idCard { get; set; }
  122. /// <summary>
  123. /// 在校
  124. /// </summary>
  125. public string status { get; set; }
  126. /// <summary>
  127. /// 汉族
  128. /// </summary>
  129. public string nationName { get; set; }
  130. /// <summary>
  131. /// 家庭住址
  132. /// </summary>
  133. public string nativeplace { get; set; }
  134. /// <summary>
  135. /// 年龄16 17
  136. /// </summary>
  137. public string age { get; set; }
  138. /// <summary>
  139. /// 学号 178020242
  140. /// </summary>
  141. public string studentNumber { get; set; }
  142. /// <summary>
  143. /// 姓名
  144. /// </summary>
  145. public string name { get; set; }
  146. /// <summary>
  147. /// 班级名称 17财税02
  148. /// </summary>
  149. public string className { get; set; }
  150. /// <summary>
  151. /// 专业 金融财税
  152. /// </summary>
  153. public string majorName { get; set; }
  154. }
  155. ///// <summary>
  156. ///// 处理结果类
  157. ///// </summary>
  158. ///// <typeparam name="T"></typeparam>
  159. //public class ResultDTO<T>
  160. //{
  161. // /// <summary>
  162. // /// 返回代码,100 处理成功,其它失败
  163. // /// </summary>
  164. // public int code;
  165. // /// <summary>
  166. // /// 返 回消息
  167. // /// </summary>
  168. // public string msg;
  169. // /// <summary>
  170. // /// 返回的结果集
  171. // /// </summary>
  172. // List<T> record;
  173. //}
  174. public class PayResult
  175. {
  176. public List<PayStudent> result { get; set; }
  177. }
  178. public class PayStudent
  179. {
  180. public string xjdm { get; set; }
  181. public string xsxm { get; set; }
  182. public string createTime { get; set; }
  183. }
  184. public static void BgeinHeNanXinAn()
  185. {
  186. try
  187. {
  188. string depturl = ConfigurationManager.AppSettings["depturl"];
  189. string userurl = ConfigurationManager.AppSettings["userurl"];
  190. string lessonurl = ConfigurationManager.AppSettings["lessonurl"];
  191. string classurl = ConfigurationManager.AppSettings["classurl"];
  192. string majorurl = ConfigurationManager.AppSettings["majorurl"];
  193. string studenturl = ConfigurationManager.AppSettings["studenturl"];
  194. string GenerateTeachersRoleId = ConfigurationManager.AppSettings["GenerateTeachersRoleId"];
  195. string secretcode = ConfigurationManager.AppSettings["secretcode"];
  196. string pwdcode = ConfigurationManager.AppSettings["pwdcode"];
  197. IEnumerable<UserEntity> baseuserlist = null;
  198. HttpClient httpClient = new HttpClient();
  199. string deptjsonstring = httpClient.GetStringAsync(depturl).Result;
  200. if (!string.IsNullOrEmpty(deptjsonstring))
  201. {
  202. var deptobj = JsonConvert.DeserializeObject<List<dept>>(deptjsonstring);
  203. if (deptobj != null && deptobj.Count > 0)
  204. {
  205. foreach (var dep in deptobj)
  206. {
  207. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  208. {
  209. if (conn.Query<dynamic>(
  210. "select * from LR_Base_Department where F_EnCode='" + dep.deptCode + "'")
  211. .Count() == 0)
  212. {
  213. conn.Execute(
  214. "insert into LR_Base_Department(F_DepartmentId,F_ParentId,F_EnCode,F_FullName,F_DeleteMark,F_EnabledMark) " +
  215. " values(newid(),'0','" + dep.deptCode + "','" + dep.deptName + "',0,1)");
  216. conn.Execute(
  217. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条部门数据',getdate())");
  218. }
  219. }
  220. using (IDbConnection conn = new SqlConnection(_coresqlConnection2))
  221. {
  222. if (conn.Query<dynamic>(
  223. "select * from LR_Base_Department where F_EnCode='" + dep.deptCode + "'")
  224. .Count() == 0)
  225. {
  226. conn.Execute(
  227. "insert into LR_Base_Department(F_DepartmentId,F_ParentId,F_EnCode,F_FullName,F_DeleteMark,F_EnabledMark) " +
  228. " values(newid(),'0','" + dep.deptCode + "','" + dep.deptName + "',0,1)");
  229. conn.Execute(
  230. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条部门数据',getdate())");
  231. }
  232. }
  233. //系
  234. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  235. {
  236. if (conn.Query<dynamic>("SELECT * FROM dbo.CdDept WHERE DeptNo ='" + dep.deptCode + "'")
  237. .Count() == 0)
  238. {
  239. conn.Execute(
  240. $"INSERT dbo.CdDept ( DeptId, DeptNo, DeptName) VALUES ( NEWID(), '{dep.deptCode}', '{dep.deptName}')");
  241. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  242. {
  243. conncore.Execute(
  244. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条系部数据',getdate())");
  245. }
  246. }
  247. }
  248. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  249. {
  250. if (conn.Query<dynamic>("SELECT * FROM dbo.CdDept WHERE DeptNo ='" + dep.deptCode + "'")
  251. .Count() == 0)
  252. {
  253. conn.Execute(
  254. $"INSERT dbo.CdDept ( DeptId, DeptNo, DeptName) VALUES ( NEWID(), '{dep.deptCode}', '{dep.deptName}')");
  255. using (IDbConnection conncore = new SqlConnection(_coresqlConnection2))
  256. {
  257. conncore.Execute(
  258. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条系部数据',getdate())");
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. string userjsonstring = httpClient.GetStringAsync(userurl).Result;
  266. //人员
  267. if (!string.IsNullOrEmpty(userjsonstring))
  268. {
  269. var userobj = JsonConvert.DeserializeObject<List<user>>(userjsonstring);
  270. if (userobj != null && userobj.Count > 0)
  271. {
  272. foreach (var use in userobj)
  273. {
  274. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  275. {
  276. if (conn.Query<dynamic>("select * from EmpInfo where EmpNo='" + use.account + "'")
  277. .Count() == 0)
  278. {
  279. conn.Execute("insert into EmpInfo(EmpId,EmpNo,EmpName,GenderNo) " +
  280. "values(newid(),'" + use.account + "','" + use.name + "'," + (use.sex == 1 ? 1 : 0) + ")");
  281. }
  282. }
  283. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  284. {
  285. string userid = Guid.NewGuid().ToString();
  286. if (conn.Query<dynamic>("select * from LR_Base_User where F_Account='" + use.account +
  287. "'")
  288. .Count() == 0)
  289. {
  290. conn.Execute(
  291. "insert into LR_Base_User(F_UserId,F_EnCode,F_Account,F_RealName,F_Password,F_Secretkey,F_Gender,F_DeleteMark,F_EnabledMark,F_Description) " +
  292. " values('" + userid + "','" + use.account + "','" + use.account + "','" +
  293. use.name +
  294. "','" + pwdcode + "','" + secretcode + "','" + (use.sex == 1 ? 1 : 0) +
  295. "',0,1,'教师')");
  296. conn.Execute(
  297. "insert into LR_Base_UserRelation(F_UserRelationId,F_UserId,F_Category,F_ObjectId) values(newid(),'" +
  298. userid + "',1,'" + GenerateTeachersRoleId + "')");
  299. conn.Execute(
  300. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条用户数据',getdate())");
  301. }
  302. }
  303. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  304. {
  305. if (conn.Query<dynamic>("select * from EmpInfo where EmpNo='" + use.account + "'")
  306. .Count() == 0)
  307. {
  308. conn.Execute("insert into EmpInfo(EmpId,EmpNo,EmpName,GenderNo) " +
  309. "values(newid(),'" + use.account + "','" + use.name + "'," + (use.sex == 1 ? 1 : 0) + ")");
  310. }
  311. }
  312. using (IDbConnection conn = new SqlConnection(_coresqlConnection2))
  313. {
  314. string userid = Guid.NewGuid().ToString();
  315. if (conn.Query<dynamic>("select * from LR_Base_User where F_Account='" + use.account +
  316. "'")
  317. .Count() == 0)
  318. {
  319. conn.Execute(
  320. "insert into LR_Base_User(F_UserId,F_EnCode,F_Account,F_RealName,F_Password,F_Secretkey,F_Gender,F_DeleteMark,F_EnabledMark,F_Description) " +
  321. " values('" + userid + "','" + use.account + "','" + use.account + "','" +
  322. use.name +
  323. "','" + pwdcode + "','" + secretcode + "','" + (use.sex == 1 ? 1 : 0) +
  324. "',0,1,'教师')");
  325. conn.Execute(
  326. "insert into LR_Base_UserRelation(F_UserRelationId,F_UserId,F_Category,F_ObjectId) values(newid(),'" +
  327. userid + "',1,'" + GenerateTeachersRoleId + "')");
  328. conn.Execute(
  329. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条用户数据',getdate())");
  330. }
  331. }
  332. }
  333. }
  334. }
  335. //课程
  336. string lessonJsonString = httpClient.GetStringAsync(lessonurl).Result;
  337. var lessonJsonObj = JsonConvert.DeserializeObject<List<lesson>>(lessonJsonString);
  338. if (lessonJsonObj != null && lessonJsonObj.Count > 0)
  339. {
  340. foreach (var item in lessonJsonObj)
  341. {
  342. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  343. {
  344. if (conn.Query<dynamic>(
  345. $"SELECT * FROM dbo.LessonInfo WHERE LessonNo='{item.courseCode}'")
  346. .Count() == 0)
  347. {
  348. conn.Execute(
  349. $"INSERT dbo.LessonInfo ( LessonId, LessonNo, LessonName, TeachDeptNo,LessonSortNo ) VALUES ( NEWID(),'{item.courseCode}','{item.courseName}','{item.deptCode}','1')"
  350. );
  351. }
  352. }
  353. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  354. {
  355. if (conn.Query<dynamic>(
  356. $"SELECT * FROM dbo.LessonInfo WHERE LessonNo='{item.courseCode}'")
  357. .Count() == 0)
  358. {
  359. conn.Execute(
  360. $"INSERT dbo.LessonInfo ( LessonId, LessonNo, LessonName, TeachDeptNo,LessonSortNo ) VALUES ( NEWID(),'{item.courseCode}','{item.courseName}','{item.deptCode}','1')"
  361. );
  362. }
  363. }
  364. }
  365. }
  366. //专业
  367. string majorJsonString = httpClient.GetStringAsync(majorurl).Result;
  368. var majorJsonObj = JsonConvert.DeserializeObject<List<major>>(majorJsonString);
  369. if (majorJsonObj != null && majorJsonObj.Count > 0)
  370. {
  371. foreach (var item in majorJsonObj)
  372. {
  373. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  374. {
  375. if (conn.Query<dynamic>(
  376. $"SELECT * FROM dbo.CdMajor WHERE MajorNo='{item.majorCode}'")
  377. .Count() == 0)
  378. {
  379. conn.Execute(
  380. $"INSERT dbo.CdMajor ( ID, MajorNo, MajorName, LengthOfSchooling, DeptNo,CheckMark ) VALUES (NEWID(), '{item.majorCode}', '{item.majorName}', {item.eduTypeCode}, '{item.deptCode}',1 )"
  381. );
  382. }
  383. }
  384. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  385. {
  386. if (conn.Query<dynamic>(
  387. $"SELECT * FROM dbo.CdMajor WHERE MajorNo='{item.majorCode}'")
  388. .Count() == 0)
  389. {
  390. conn.Execute(
  391. $"INSERT dbo.CdMajor ( ID, MajorNo, MajorName, LengthOfSchooling, DeptNo,CheckMark ) VALUES (NEWID(), '{item.majorCode}', '{item.majorName}', {item.eduTypeCode}, '{item.deptCode}',1 )"
  392. );
  393. }
  394. }
  395. }
  396. }
  397. //班级
  398. string classJsonString = httpClient.GetStringAsync(classurl).Result;
  399. var classJsonObj = JsonConvert.DeserializeObject<List<classInfo>>(classJsonString);
  400. if (classJsonObj != null && classJsonObj.Count > 0)
  401. {
  402. foreach (var item in classJsonObj)
  403. {
  404. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  405. {
  406. if (conn.Query<dynamic>(
  407. $"SELECT * FROM dbo.ClassInfo WHERE ClassNo='{item.classCode}'")
  408. .Count() == 0)
  409. {
  410. conn.Execute(
  411. $"INSERT dbo.ClassInfo ( ClassId, ClassNo, ClassName, MajorNo, Grade, ClassDiredctorNo,CheckMark) VALUES (NEWID(), '{item.classCode}', '{item.className}', '{item.majorCode}', '{item.gradeCode}', '{item.headTeacherNum}',1 )"
  412. );
  413. }
  414. }
  415. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  416. {
  417. if (conn.Query<dynamic>(
  418. $"SELECT * FROM dbo.ClassInfo WHERE ClassNo='{item.classCode}'")
  419. .Count() == 0)
  420. {
  421. conn.Execute(
  422. $"INSERT dbo.ClassInfo ( ClassId, ClassNo, ClassName, MajorNo, Grade, ClassDiredctorNo,CheckMark) VALUES (NEWID(), '{item.classCode}', '{item.className}', '{item.majorCode}', '{item.gradeCode}', '{item.headTeacherNum}',1 )"
  423. );
  424. }
  425. }
  426. }
  427. }
  428. bool hasdata = true;
  429. int pagenum = 1;
  430. while (hasdata)
  431. {
  432. //学生数据
  433. string studentJsonString = httpClient.GetStringAsync(studenturl + "&currentPage=" + pagenum.ToString()).Result;
  434. var studentJsonObj = JsonConvert.DeserializeObject<List<studentInfo>>(studentJsonString);
  435. if (studentJsonObj != null && studentJsonObj.Count > 0)
  436. {
  437. pagenum++;
  438. foreach (var item in studentJsonObj)
  439. {
  440. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  441. {
  442. if (conn.Query<dynamic>(
  443. $"SELECT * FROM dbo.StuInfoBasic WHERE StuNo='{item.studentNumber}'")
  444. .Count() == 0)
  445. {
  446. try
  447. {
  448. conn.Execute(
  449. $"INSERT dbo.StuInfoBasic ( StuId, StuNo, StuName,DeptNo, MajorNo, ClassNo,Grade, IdentityCardNo,NationalityNo,MailAddress,CheckMark) " +
  450. $"VALUES (NEWID(), '{item.studentNumber}', '{item.name}', (select top 1 DeptNo from CdDept where DeptName='{item.facultyName}'), " +
  451. $"(select top 1 MajorNo from CdMajor where MajorName='{item.majorName}'), (select top 1 ClassNo from ClassInfo where ClassName='{item.className}')," +
  452. $"'{item.gradeName?.Replace("级", "")?.Substring(2)}','{item.idCard}',(select top 1 NationalityNo from BCdNationality where Nationality='{item.nationName}'),'{item.nativeplace}','1')"
  453. );
  454. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  455. {
  456. conncore.Execute(
  457. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条学生学籍数据,总计:" + studentJsonObj.Count + "',getdate())");
  458. }
  459. }
  460. catch (Exception e)
  461. {
  462. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  463. {
  464. conncore.Execute(
  465. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'河南新安获取数据报错','" +
  466. e.Message + "',getdate())");
  467. }
  468. }
  469. }
  470. }
  471. using (IDbConnection conn = new SqlConnection(_sqlConnection2))
  472. {
  473. if (conn.Query<dynamic>(
  474. $"SELECT * FROM dbo.StuInfoBasic WHERE StuNo='{item.studentNumber}'")
  475. .Count() == 0)
  476. {
  477. try
  478. {
  479. conn.Execute(
  480. $"INSERT dbo.StuInfoBasic ( StuId, StuNo, StuName,DeptNo, MajorNo, ClassNo,Grade, IdentityCardNo,NationalityNo,MailAddress,CheckMark) " +
  481. $"VALUES (NEWID(), '{item.studentNumber}', '{item.name}', (select top 1 DeptNo from CdDept where DeptName='{item.facultyName}'), " +
  482. $"(select top 1 MajorNo from CdMajor where MajorName='{item.majorName}'), (select top 1 ClassNo from ClassInfo where ClassName='{item.className}')," +
  483. $"'{item.gradeName?.Replace("级", "")?.Substring(2)}','{item.idCard}',(select top 1 NationalityNo from BCdNationality where Nationality='{item.nationName}'),'{item.nativeplace}','1')"
  484. );
  485. using (IDbConnection conncore = new SqlConnection(_coresqlConnection2))
  486. {
  487. conncore.Execute(
  488. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'定时同步操作','插入了一条学生学籍数据,总计:" + studentJsonObj.Count + "',getdate())");
  489. }
  490. }
  491. catch (Exception e)
  492. {
  493. using (IDbConnection conncore = new SqlConnection(_coresqlConnection2))
  494. {
  495. conncore.Execute(
  496. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'河南新安获取学生数据报错','" +
  497. e.Message + "',getdate())");
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. else
  505. {
  506. hasdata = false;
  507. pagenum = 1;
  508. }
  509. }
  510. }
  511. catch (Exception e)
  512. {
  513. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  514. {
  515. conncore.Execute(
  516. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),888,'河南新安获取数据报错','" +
  517. e.Message + "',getdate())");
  518. }
  519. }
  520. }
  521. /// <summary>
  522. /// 西昌新生缴费状态查询
  523. /// </summary>
  524. public static void QueryPayData()
  525. {
  526. string param = "beginDate=" + DateTime.Now.ToString("yyyy-MM-dd") + "&endDate=" + DateTime.Now.ToString("yyyy-MM-dd");
  527. byte[] byteData = Encoding.ASCII.GetBytes(param);
  528. string strURL = "http://onlinepay.xcmzyz.com:58081/xcm/already";
  529. HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
  530. request.Method = "POST";
  531. request.ContentLength = byteData.Length;
  532. request.ContentType = "application/x-www-form-urlencoded";
  533. Stream stream = null;
  534. try
  535. {
  536. stream = request.GetRequestStream();
  537. stream.Flush();
  538. stream.Write(byteData, 0, byteData.Length);
  539. stream.Close();
  540. }
  541. catch (Exception)
  542. {
  543. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  544. {
  545. conn.Execute(
  546. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'缴费状态更新','连接服务器失败',getdate())");
  547. }
  548. }
  549. finally
  550. {
  551. if (stream != null)
  552. {
  553. stream.Close();
  554. stream.Dispose();
  555. }
  556. }
  557. HttpWebResponse response = null;
  558. try
  559. {
  560. response = (HttpWebResponse)request.GetResponse();
  561. StreamReader streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  562. string responseText = streamReader.ReadToEnd();
  563. streamReader.Close();
  564. PayResult paystudentsList = JsonConvert.DeserializeObject<PayResult>(responseText);
  565. if (paystudentsList != null && paystudentsList.result.Count > 0)
  566. {
  567. foreach (var studentitem in paystudentsList.result.DistinctBy(m => m.xjdm))
  568. {
  569. using (IDbConnection connmis = new SqlConnection(_sqlConnection))
  570. {
  571. DateTime dtout = new DateTime();
  572. connmis.Execute("update StuInfoFresh set PayFeeStatus=1,PayFeeDate='" + (DateTime.TryParse(studentitem.createTime, out dtout) ? studentitem.createTime : DateTime.Now.ToString()) + "' where StuNo='" + studentitem.xjdm + "' and (PayFeeStatus=0 or PayFeeStatus is null)");
  573. }
  574. }
  575. }
  576. }
  577. catch (WebException ex)
  578. {
  579. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  580. {
  581. conn.Execute(
  582. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'缴费状态更新','返回数据错误" +
  583. ex.Message + "',getdate())");
  584. }
  585. }
  586. finally
  587. {
  588. if (response != null)
  589. {
  590. response.Close();
  591. response.Dispose();
  592. }
  593. }
  594. }
  595. /// <summary>
  596. /// 批量开具发票
  597. /// </summary>
  598. public static void BatchInvoiceMethod()
  599. {
  600. try
  601. {
  602. Encoding encoding = Encoding.UTF8;
  603. string batchInvoiceUrl = "http://192.168.53.135:5000/colleges-proxy/api/college/batchInvoiceEBill";
  604. HttpWebRequest biRequest = (System.Net.HttpWebRequest)WebRequest.Create(batchInvoiceUrl);
  605. biRequest.Method = "POST";
  606. biRequest.ContentType = "application/json";
  607. Random ran = new Random();
  608. BatchInvoiceParam biParam = new BatchInvoiceParam();
  609. var key = "05a754b0b1897aa8ac07c3d951";
  610. var appid = "XCMZYESFGDZKXX0071670";
  611. biParam.busType = appid;
  612. biParam.batchNo = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  613. biParam.date = DateTime.Now.ToString("yyyy-MM-dd");
  614. List<eBillListClass> eBillList = new List<eBillListClass>();
  615. eBillListClass eBillListitem = new eBillListClass();
  616. eBillListitem.busNo = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  617. eBillListitem.ivcDate = DateTime.Now.ToString("yyyy-MM-dd");
  618. eBillListitem.placeCode = "001";
  619. eBillListitem.billCode = "4004";
  620. eBillListitem.channel = "23";
  621. eBillListitem.payerType = "1";
  622. eBillListitem.recer = "财务部刘亦菲";
  623. eBillListitem.stuName = "曾巧玲";
  624. eBillListitem.@operator = "曾巧玲";
  625. eBillListitem.totalAmt = 688.00;
  626. List<itemDetailClass> itemdetailList = new List<itemDetailClass>();
  627. itemDetailClass itemdetail = new itemDetailClass();
  628. itemdetail.itemCode = "0301002";
  629. itemdetail.itemName = "代收伙食费";
  630. itemdetail.count = 1;
  631. itemdetail.standard = 600;
  632. itemdetail.amt = 600.00;
  633. itemdetailList.Add(itemdetail);
  634. itemDetailClass itemdetail1 = new itemDetailClass();
  635. itemdetail1.itemCode = "0301003";
  636. itemdetail1.itemName = "代收水电气费";
  637. itemdetail1.count = 1;
  638. itemdetail1.standard = 88;
  639. itemdetail1.amt = 88.00;
  640. itemdetailList.Add(itemdetail1);
  641. eBillListitem.itemDetail = itemdetailList;
  642. eBillList.Add(eBillListitem);
  643. biParam.eBillList = eBillList;
  644. biParam.totalCount = eBillList.Count();
  645. var data = Convert.ToBase64String(encoding.GetBytes(JsonConvert.SerializeObject(biParam)));
  646. var noise = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  647. var biparams = "{\"appid\":" + appid + ",\"data\":" + data + ",\"noise\":" + noise + "}";
  648. string A = "appid=" + appid + "&data=" + data + "&noise=" + noise;
  649. string SignTemp = A + "&key=" + key + "&version=1.0";
  650. var sign = Md5Helper.Hash(SignTemp).ToUpper();
  651. biparams = "{\"appid\":\"" + appid + "\",\"data\":\"" + data + "\",\"noise\":\"" + noise + "\",\"version\":\"1.0\",\"sign\":\"" + sign + "\"}";
  652. //var aa = "{\"busType\":\"XCMZYESFGDZKXX0071670\"}";
  653. //var bb = Convert.ToBase64String(encoding.GetBytes(aa));
  654. //string A1 = "appid=" + appid + "&data=" + bb + "&noise=" + noise;
  655. //string SignTemp1 = A1 + "&key=" + key + "&version=1.0";
  656. //var sign1 = Md5Helper.Hash(SignTemp1.ToUpper());
  657. //var str = "{\"appid\":\"" + appid + "\",\"data\":" + aa + ",\"noise\":\"" + noise + "\",\"version\":\"1.0\"" +
  658. // ",\"sign\":\"" + sign1 + "\"}";
  659. byte[] buffer = encoding.GetBytes(biparams);
  660. biRequest.ContentLength = buffer.Length;
  661. biRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
  662. HttpWebResponse biresponse = (HttpWebResponse)biRequest.GetResponse();
  663. using (StreamReader reader = new StreamReader(biresponse.GetResponseStream(), Encoding.UTF8))
  664. {
  665. dynamic res = JsonConvert.DeserializeObject(reader.ReadToEnd());
  666. File.AppendAllText("d:\\test.txt", "返回结果:" + res);
  667. File.AppendAllText("d:\\test.txt", "返回result:" + res.result);
  668. File.AppendAllText("d:\\test.txt", "返回message:" + res.message);
  669. }
  670. }
  671. catch (Exception ex)
  672. {
  673. File.AppendAllText("d:\\test.txt", "出现异常:" + ex.Message);
  674. }
  675. }
  676. /// <summary>
  677. /// 单张票据开具接口
  678. /// </summary>
  679. public static void InvoiceEBillMethod(string OrderId, bool IsNewOrOld)
  680. {
  681. try
  682. {
  683. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  684. {
  685. StuEnrollFeeOrderEntity orderEntity = conn.QuerySingle<StuEnrollFeeOrderEntity>("select * from StuEnrollFeeOrder where orderid='" + OrderId + "'");
  686. if (orderEntity.Status == 1 || orderEntity.Status == 999)
  687. {
  688. List<StuEnrollFeeOrderDetailEntity> stuEnrollFeeOrderDetailList =
  689. conn.Query<StuEnrollFeeOrderDetailEntity>(@"select a.*, b.InvoiceTypeCode from StuEnrollFeeOrderDetail a
  690. join StuEnrollInvoiceTypeCode b on a.chargeItemId = b.ProjectCode
  691. where a.OrderId = '" + orderEntity.Id + "'").ToList();
  692. var groupDetail = stuEnrollFeeOrderDetailList.GroupBy(x => x.InvoiceTypeCode);
  693. foreach (IGrouping<string, StuEnrollFeeOrderDetailEntity> item in groupDetail)
  694. {
  695. try
  696. {
  697. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  698. {
  699. conncore.Execute(
  700. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'typecode','开票typecode:" + item.Key + "',getdate())");
  701. }
  702. InvoiceEBillByType(conn, OrderId, IsNewOrOld, orderEntity, item.Key, item);
  703. }
  704. catch (Exception ex)
  705. {
  706. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  707. {
  708. conncore.Execute(
  709. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票异常:" + ex.Message + "',getdate())");
  710. }
  711. }
  712. }
  713. }
  714. }
  715. }
  716. catch (Exception ex)
  717. {
  718. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  719. {
  720. conncore.Execute(
  721. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票异常:" + ex.Message + "',getdate())");
  722. }
  723. }
  724. }
  725. /// <summary>
  726. /// 单张票据开具接口
  727. /// </summary>
  728. public static void InvoiceEBillMethodTwo(FinaChargeStuOrderEntity orderEntity)
  729. {
  730. try
  731. {
  732. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  733. {
  734. List<FinaChargeStuYearItemEntity> stuEnrollFeeOrderDetailList =
  735. conn.Query<FinaChargeStuYearItemEntity>(@"select a.*, b.InvoiceTypeCode from FinaChargeStuYearItem a
  736. join StuEnrollInvoiceTypeCode b on a.chargeItemcode = b.ProjectCode
  737. where a.FSYId = '" + orderEntity.FSYId + "'").ToList();
  738. var groupDetail = stuEnrollFeeOrderDetailList.GroupBy(x => x.InvoiceTypeCode);
  739. foreach (IGrouping<string, FinaChargeStuYearItemEntity> item in groupDetail)
  740. {
  741. try
  742. {
  743. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  744. {
  745. conncore.Execute(
  746. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'typecode','开票typecode:" + item.Key + "',getdate())");
  747. }
  748. InvoiceEBillByTypeTwo(conn, orderEntity, item.Key, item);
  749. }
  750. catch (Exception ex)
  751. {
  752. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  753. {
  754. conncore.Execute(
  755. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票异常:" + ex.Message + "',getdate())");
  756. }
  757. }
  758. }
  759. }
  760. }
  761. catch (Exception ex)
  762. {
  763. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  764. {
  765. conncore.Execute(
  766. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票异常:" + ex.Message + "',getdate())");
  767. }
  768. }
  769. }
  770. private static void InvoiceEBillByType(IDbConnection conn, string OrderId, bool IsNewOrOld, StuEnrollFeeOrderEntity orderEntity, string billCode, IGrouping<string, StuEnrollFeeOrderDetailEntity> stuEnrollFeeOrderDetailList)
  771. {
  772. Encoding encoding = Encoding.UTF8;
  773. string StuName = conn.QuerySingle("select StuName from Stuinfobasic where stuno='" + orderEntity.StuNo + "'").StuName;
  774. Random ran = new Random();
  775. InvoiceEBillParam biParam = new InvoiceEBillParam();
  776. var key = "6b50096e01a3af32b62c1d3ab0";
  777. var appid = "XCMZYESFGDZKXX8371735";
  778. biParam.busType = appid;
  779. biParam.busNo = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  780. biParam.ivcDate = DateTime.Now.ToString("yyyy-MM-dd");
  781. biParam.placeCode = "001";
  782. biParam.billCode = billCode;//"4004";
  783. biParam.channel = "28";
  784. if (orderEntity.PayMode == "BHK" || orderEntity.PayMode == "THK")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  785. {
  786. biParam.channel = "28";
  787. }
  788. if (orderEntity.PayMode == "CFT")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  789. {
  790. biParam.channel = "23";
  791. }
  792. if (orderEntity.PayMode == "ZFB")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  793. {
  794. biParam.channel = "24";
  795. }
  796. if (orderEntity.PayMode == "ExcelOffLine")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  797. {
  798. biParam.channel = "26";
  799. }
  800. biParam.payerType = "1";
  801. biParam.recer = "林智慧";
  802. biParam.stuName = StuName;
  803. //biParam.stuNo = orderEntity.StuNo;
  804. biParam.memo = "缴费年度:" + orderEntity.YearNo + ",学号:" + orderEntity.StuNo;
  805. biParam.@operator = "林智慧";
  806. biParam.reViewer = "陈劲华";
  807. biParam.totalAmt = Convert.ToDouble(stuEnrollFeeOrderDetailList.Sum(x => x.YJAmount));// Convert.ToDouble(orderEntity.YJAmount);
  808. biParam.noticeMode = "0";
  809. List<InvoiceEBillItem> itemdetailList = new List<InvoiceEBillItem>();
  810. foreach (var itemEntity in stuEnrollFeeOrderDetailList)
  811. {
  812. InvoiceEBillItem itemdetail = new InvoiceEBillItem();
  813. itemdetail.itemCode = itemEntity.ChargeItemID;
  814. itemdetail.itemName = itemEntity.ChargeItemName;
  815. itemdetail.count = 1;
  816. itemdetail.standard = Convert.ToDouble(itemEntity.YJAmount);
  817. itemdetail.amt = Convert.ToDouble(itemEntity.YJAmount);
  818. itemdetailList.Add(itemdetail);
  819. }
  820. biParam.itemDetail = itemdetailList;
  821. //JsonConvert.SerializeObject(biParam)
  822. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  823. {
  824. conncore.Execute(
  825. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','发送给开票系统原始数据:" + JsonConvert.SerializeObject(biParam) + "',getdate())");
  826. }
  827. var data = Convert.ToBase64String(encoding.GetBytes(JsonConvert.SerializeObject(biParam)));
  828. var noise = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  829. var biparams = "{\"appid\":" + appid + ",\"data\":" + data + ",\"noise\":" + noise + "}";
  830. string A = "appid=" + appid + "&data=" + data + "&noise=" + noise;
  831. string SignTemp = A + "&key=" + key + "&version=1.0";
  832. var sign = Md5Helper.Hash(SignTemp).ToUpper();
  833. biparams = "{\"appid\":\"" + appid + "\",\"data\":\"" + data + "\",\"noise\":\"" + noise + "\",\"version\":\"1.0\",\"sign\":\"" + sign + "\"}";
  834. byte[] buffer = encoding.GetBytes(biparams);
  835. string batchInvoiceUrl = ConfigurationManager.AppSettings["Invoiceurl"];
  836. try
  837. {
  838. HttpWebRequest biRequest = (HttpWebRequest)WebRequest.Create(batchInvoiceUrl);
  839. biRequest.Method = "POST";
  840. biRequest.ContentType = "application/json";
  841. biRequest.ContentLength = buffer.Length;
  842. biRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
  843. HttpWebResponse biresponse = (HttpWebResponse)biRequest.GetResponse();
  844. using (StreamReader reader = new StreamReader(biresponse.GetResponseStream(), Encoding.UTF8))
  845. {
  846. dynamic res = JsonConvert.DeserializeObject(reader.ReadToEnd());
  847. string datain = res.data.ToString();
  848. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  849. {
  850. conncore.Execute(
  851. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统返回:" + datain + "',getdate())");
  852. }
  853. string returnresult = encoding.GetString(Convert.FromBase64String(datain));
  854. if (returnresult != "")
  855. {
  856. dynamic resultobj = JsonConvert.DeserializeObject(returnresult);
  857. string message = resultobj.message;
  858. string messagedecode = encoding.GetString(Convert.FromBase64String(message));
  859. if (resultobj.result == "S0000")
  860. {
  861. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  862. {
  863. conncore.Execute(
  864. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统成功返回:" + messagedecode + "',getdate())");
  865. }
  866. dynamic billInfo = JsonConvert.DeserializeObject(messagedecode);
  867. string eBillCode = billInfo.eBillCode;
  868. string eBillNo = billInfo.eBillNo;
  869. string checkCode = billInfo.checkCode;
  870. //记录票号
  871. var recordId = Guid.NewGuid();
  872. conn.Execute($"insert into StuEnrollInvoiceRecord(Id,YearNo,StuNo,billNo,random,billStatus) values('{recordId}','{orderEntity.YearNo}','{orderEntity.StuNo}','{eBillNo}','{checkCode}','1')");
  873. //conn.Execute("update StuEnrollFeeOrder set billBatchCode='" + eBillCode + "',billNo='" + eBillNo + "',random='" + checkCode + "',billStatus=1 where orderid='" + OrderId + "'");
  874. if (IsNewOrOld)
  875. {
  876. //记录开票状态
  877. conn.Execute("update StuInfoFresh set IsInvoice=1 where stuno='" + orderEntity.StuNo + "'");
  878. }
  879. else
  880. {
  881. conn.Execute("update StuInfoBasic_PayFee set InvoiceStatus=1 where stuno='" + orderEntity.StuNo + "' and payyear='" + orderEntity.YearNo + "'");
  882. }
  883. //查询票据url
  884. var invoiceobj = new { billBatchCode = eBillCode, billNo = eBillNo, random = checkCode, channelMode = "1" };
  885. var datainvoice = Convert.ToBase64String(encoding.GetBytes(JsonConvert.SerializeObject(invoiceobj)));
  886. var noiseinvoice = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  887. var paramsinvoice = "{\"appid\":" + appid + ",\"data\":" + datainvoice + ",\"noise\":" + noiseinvoice + "}";
  888. string Ainvoice = "appid=" + appid + "&data=" + datainvoice + "&noise=" + noiseinvoice;
  889. string SignTempinvoice = Ainvoice + "&key=" + key + "&version=1.0";
  890. var signinvoice = Md5Helper.Hash(SignTempinvoice).ToUpper();
  891. paramsinvoice = "{\"appid\":\"" + appid + "\",\"data\":\"" + datainvoice + "\",\"noise\":\"" + noiseinvoice + "\",\"version\":\"1.0\",\"sign\":\"" + signinvoice + "\"}";
  892. byte[] bufferinvoice = encoding.GetBytes(paramsinvoice);
  893. string getEBillPicUrl = ConfigurationManager.AppSettings["EBillPicUrl"];
  894. HttpWebRequest invoiceRequest = (HttpWebRequest)WebRequest.Create(getEBillPicUrl);
  895. invoiceRequest.Method = "POST";
  896. invoiceRequest.ContentType = "application/json";
  897. invoiceRequest.ContentLength = bufferinvoice.Length;
  898. invoiceRequest.GetRequestStream().Write(bufferinvoice, 0, bufferinvoice.Length);
  899. HttpWebResponse invoiceresponse = (HttpWebResponse)invoiceRequest.GetResponse();
  900. using (StreamReader readerinvoice = new StreamReader(invoiceresponse.GetResponseStream(), Encoding.UTF8))
  901. {
  902. dynamic resinvoice = JsonConvert.DeserializeObject(readerinvoice.ReadToEnd());
  903. datainvoice = resinvoice.data.ToString();
  904. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  905. {
  906. conncore.Execute(
  907. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url返回:" + datainvoice + "',getdate())");
  908. }
  909. string returnresultinvoice = encoding.GetString(Convert.FromBase64String(datainvoice));
  910. resultobj = JsonConvert.DeserializeObject(returnresultinvoice);
  911. message = resultobj.message;
  912. messagedecode = encoding.GetString(Convert.FromBase64String(message));
  913. if (resultobj.result == "S0000")
  914. {
  915. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  916. {
  917. conncore.Execute(
  918. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url成功返回:" + messagedecode + "',getdate())");
  919. }
  920. dynamic InvoiceUrlInfo = JsonConvert.DeserializeObject(messagedecode);
  921. string pictureUrl = InvoiceUrlInfo.pictureUrl;
  922. //pictureUrl = pictureUrl.Replace("[ip]:[port]", ConfigurationManager.AppSettings["InvoiceWebUrl"]);
  923. //记录发票url
  924. //conn.Execute("update StuEnrollFeeOrder set billUrl='" + pictureUrl + "' where orderid='" + OrderId + "'");
  925. conn.Execute("update StuEnrollInvoiceRecord set billUrl='" + pictureUrl + "' where Id='" + recordId + "'");
  926. }
  927. else
  928. {
  929. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  930. {
  931. conncore.Execute(
  932. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url错误:" + messagedecode + "',getdate())");
  933. }
  934. }
  935. }
  936. }
  937. else
  938. {
  939. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  940. {
  941. conncore.Execute(
  942. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统错误:" + messagedecode + "',getdate())");
  943. }
  944. }
  945. }
  946. }
  947. }
  948. catch (Exception e)
  949. {
  950. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  951. {
  952. conncore.Execute(
  953. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统报错:" + e.Message + "',getdate())");
  954. }
  955. }
  956. }
  957. private static void InvoiceEBillByTypeTwo(IDbConnection conn, FinaChargeStuOrderEntity orderEntity, string billCode, IGrouping<string, FinaChargeStuYearItemEntity> stuEnrollFeeOrderDetailList)
  958. {
  959. Encoding encoding = Encoding.UTF8;
  960. string StuName = conn.QuerySingle("select StuName from FinaChargeStudent where stuno='" + orderEntity.StuNo + "'").StuName;
  961. Random ran = new Random();
  962. InvoiceEBillParam biParam = new InvoiceEBillParam();
  963. var key = "6b50096e01a3af32b62c1d3ab0";
  964. var appid = "XCMZYESFGDZKXX8371735";
  965. biParam.busType = appid;
  966. biParam.busNo = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  967. biParam.ivcDate = DateTime.Now.ToString("yyyy-MM-dd");
  968. biParam.placeCode = "001";
  969. biParam.billCode = billCode;//"4004";
  970. biParam.channel = "28";
  971. if (orderEntity.PayMode == "BHK" || orderEntity.PayMode == "THK")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  972. {
  973. biParam.channel = "28";
  974. }
  975. if (orderEntity.PayMode == "CFT")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  976. {
  977. biParam.channel = "23";
  978. }
  979. if (orderEntity.PayMode == "ZFB")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  980. {
  981. biParam.channel = "24";
  982. }
  983. if (orderEntity.PayMode == "ExcelOffLine")//BHK:建行;THK:他行;ZFB:支付宝;CFT:微信
  984. {
  985. biParam.channel = "11";
  986. }
  987. biParam.payerType = "1";
  988. biParam.recer = "林智慧";
  989. biParam.stuName = StuName;
  990. //biParam.stuNo = orderEntity.StuNo;
  991. biParam.memo = "缴费年度:" + orderEntity.YearNo + ",学号:" + orderEntity.StuNo;
  992. biParam.@operator = "林智慧";
  993. biParam.reViewer = "陈劲华";
  994. biParam.noticeMode = "0";
  995. List<InvoiceEBillItem> itemdetailList = new List<InvoiceEBillItem>();
  996. foreach (var itemEntity in stuEnrollFeeOrderDetailList)
  997. {
  998. InvoiceEBillItem itemdetail = new InvoiceEBillItem();
  999. itemdetail.itemCode = itemEntity.ChargeItemCode;
  1000. itemdetail.itemName = itemEntity.ChargeItemName;
  1001. itemdetail.count = 1;
  1002. itemdetail.standard = Convert.ToDouble(itemEntity.Standard);
  1003. itemdetail.amt = Convert.ToDouble((itemEntity.SJAmount > itemEntity.Standard ? itemEntity.Standard : itemEntity.SJAmount));
  1004. itemdetailList.Add(itemdetail);
  1005. }
  1006. biParam.totalAmt = Convert.ToDouble(itemdetailList.Sum(m => m.amt));
  1007. biParam.itemDetail = itemdetailList;
  1008. //JsonConvert.SerializeObject(biParam)
  1009. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1010. {
  1011. conncore.Execute(
  1012. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','发送给开票系统原始数据:" + JsonConvert.SerializeObject(biParam) + "',getdate())");
  1013. }
  1014. var data = Convert.ToBase64String(encoding.GetBytes(JsonConvert.SerializeObject(biParam)));
  1015. var noise = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  1016. var biparams = "{\"appid\":" + appid + ",\"data\":" + data + ",\"noise\":" + noise + "}";
  1017. string A = "appid=" + appid + "&data=" + data + "&noise=" + noise;
  1018. string SignTemp = A + "&key=" + key + "&version=1.0";
  1019. var sign = Md5Helper.Hash(SignTemp).ToUpper();
  1020. biparams = "{\"appid\":\"" + appid + "\",\"data\":\"" + data + "\",\"noise\":\"" + noise + "\",\"version\":\"1.0\",\"sign\":\"" + sign + "\"}";
  1021. byte[] buffer = encoding.GetBytes(biparams);
  1022. string batchInvoiceUrl = ConfigurationManager.AppSettings["Invoiceurl"];
  1023. try
  1024. {
  1025. HttpWebRequest biRequest = (HttpWebRequest)WebRequest.Create(batchInvoiceUrl);
  1026. biRequest.Method = "POST";
  1027. biRequest.ContentType = "application/json";
  1028. biRequest.ContentLength = buffer.Length;
  1029. biRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
  1030. HttpWebResponse biresponse = (HttpWebResponse)biRequest.GetResponse();
  1031. using (StreamReader reader = new StreamReader(biresponse.GetResponseStream(), Encoding.UTF8))
  1032. {
  1033. dynamic res = JsonConvert.DeserializeObject(reader.ReadToEnd());
  1034. string datain = res.data.ToString();
  1035. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1036. {
  1037. conncore.Execute(
  1038. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统返回:" + datain + "',getdate())");
  1039. }
  1040. string returnresult = encoding.GetString(Convert.FromBase64String(datain));
  1041. if (returnresult != "")
  1042. {
  1043. dynamic resultobj = JsonConvert.DeserializeObject(returnresult);
  1044. string message = resultobj.message;
  1045. string messagedecode = encoding.GetString(Convert.FromBase64String(message));
  1046. if (resultobj.result == "S0000")
  1047. {
  1048. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1049. {
  1050. conncore.Execute(
  1051. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统成功返回:" + messagedecode + "',getdate())");
  1052. }
  1053. dynamic billInfo = JsonConvert.DeserializeObject(messagedecode);
  1054. string eBillCode = billInfo.eBillCode;
  1055. string eBillNo = billInfo.eBillNo;
  1056. string checkCode = billInfo.checkCode;
  1057. //记录票号
  1058. var recordId = Guid.NewGuid();
  1059. conn.Execute($"insert into StuEnrollInvoiceRecord(Id,YearNo,StuNo,billNo,random,billStatus) values('{recordId}','{orderEntity.YearNo}','{orderEntity.StuNo}','{eBillNo}','{checkCode}','1')");
  1060. //查询票据url
  1061. var invoiceobj = new { billBatchCode = eBillCode, billNo = eBillNo, random = checkCode, channelMode = "1" };
  1062. var datainvoice = Convert.ToBase64String(encoding.GetBytes(JsonConvert.SerializeObject(invoiceobj)));
  1063. var noiseinvoice = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(0, 100000);
  1064. var paramsinvoice = "{\"appid\":" + appid + ",\"data\":" + datainvoice + ",\"noise\":" + noiseinvoice + "}";
  1065. string Ainvoice = "appid=" + appid + "&data=" + datainvoice + "&noise=" + noiseinvoice;
  1066. string SignTempinvoice = Ainvoice + "&key=" + key + "&version=1.0";
  1067. var signinvoice = Md5Helper.Hash(SignTempinvoice).ToUpper();
  1068. paramsinvoice = "{\"appid\":\"" + appid + "\",\"data\":\"" + datainvoice + "\",\"noise\":\"" + noiseinvoice + "\",\"version\":\"1.0\",\"sign\":\"" + signinvoice + "\"}";
  1069. byte[] bufferinvoice = encoding.GetBytes(paramsinvoice);
  1070. string getEBillPicUrl = ConfigurationManager.AppSettings["EBillPicUrl"];
  1071. HttpWebRequest invoiceRequest = (HttpWebRequest)WebRequest.Create(getEBillPicUrl);
  1072. invoiceRequest.Method = "POST";
  1073. invoiceRequest.ContentType = "application/json";
  1074. invoiceRequest.ContentLength = bufferinvoice.Length;
  1075. invoiceRequest.GetRequestStream().Write(bufferinvoice, 0, bufferinvoice.Length);
  1076. HttpWebResponse invoiceresponse = (HttpWebResponse)invoiceRequest.GetResponse();
  1077. using (StreamReader readerinvoice = new StreamReader(invoiceresponse.GetResponseStream(), Encoding.UTF8))
  1078. {
  1079. dynamic resinvoice = JsonConvert.DeserializeObject(readerinvoice.ReadToEnd());
  1080. datainvoice = resinvoice.data.ToString();
  1081. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1082. {
  1083. conncore.Execute(
  1084. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url返回:" + datainvoice + "',getdate())");
  1085. }
  1086. string returnresultinvoice = encoding.GetString(Convert.FromBase64String(datainvoice));
  1087. resultobj = JsonConvert.DeserializeObject(returnresultinvoice);
  1088. message = resultobj.message;
  1089. messagedecode = encoding.GetString(Convert.FromBase64String(message));
  1090. if (resultobj.result == "S0000")
  1091. {
  1092. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1093. {
  1094. conncore.Execute(
  1095. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url成功返回:" + messagedecode + "',getdate())");
  1096. }
  1097. dynamic InvoiceUrlInfo = JsonConvert.DeserializeObject(messagedecode);
  1098. string pictureUrl = InvoiceUrlInfo.pictureUrl;
  1099. //pictureUrl = pictureUrl.Replace("[ip]:[port]", ConfigurationManager.AppSettings["InvoiceWebUrl"]);
  1100. //记录发票url
  1101. //conn.Execute("update StuEnrollFeeOrder set billUrl='" + pictureUrl + "' where orderid='" + OrderId + "'");
  1102. conn.Execute("update StuEnrollInvoiceRecord set billUrl='" + pictureUrl + "' where Id='" + recordId + "'");
  1103. }
  1104. else
  1105. {
  1106. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1107. {
  1108. conncore.Execute(
  1109. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','查询开票url错误:" + messagedecode + "',getdate())");
  1110. }
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1117. {
  1118. conncore.Execute(
  1119. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统错误:" + messagedecode + "',getdate())");
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. catch (Exception e)
  1126. {
  1127. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1128. {
  1129. conncore.Execute(
  1130. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),121,'piaoju','开票系统报错:" + e.Message + "',getdate())");
  1131. }
  1132. }
  1133. }
  1134. /// <summary>
  1135. /// 新疆巴楚教育局与java项目帐号同步
  1136. /// </summary>
  1137. public static void BeginBachuAccount()
  1138. {
  1139. try
  1140. {
  1141. IEnumerable<BachuJavaUserEntity> javalist = null;
  1142. IEnumerable<UserEntity> baseuserlist = null;
  1143. using (IDbConnection conn = new MySqlConnection(_bachujavaConnection))
  1144. {
  1145. javalist = conn.Query<BachuJavaUserEntity>(
  1146. "select login_name,name,mobile from sys_user where del_flag=0 and login_name<>'system' and login_name<>'admin'");
  1147. }
  1148. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1149. {
  1150. baseuserlist =
  1151. conn.Query<UserEntity>(
  1152. "select F_Account from LR_Base_User where F_DeleteMark = 0");
  1153. conn.Execute(
  1154. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','java系统获取用户数:" +
  1155. javalist.Count() + "条',getdate())");
  1156. foreach (var oauser in javalist)
  1157. {
  1158. if (baseuserlist.Where(m => m.F_Account == oauser.login_name).Count() == 0)
  1159. {
  1160. string guid = Guid.NewGuid().ToString();
  1161. string key = Md5Helper.Encrypt(Common.CreateNo(), 16).ToLower();
  1162. string pwd = Md5Helper.Encrypt(DESEncrypt.Encrypt(Md5Helper.Encrypt("123456", 32).ToLower(), key).ToLower(), 32).ToLower();
  1163. conn.Execute("insert into LR_Base_User(F_UserId,F_Account,F_RealName,F_EnCode,F_Password,F_Secretkey,F_HeadIcon,F_Gender,F_DeleteMark,F_EnabledMark,F_Mobile,F_Description) " +
  1164. "values('" + guid + "','" + oauser.login_name + "','" + oauser.name + "','" + oauser.login_name + "','" + pwd + "','" + key + "','/Content/images/head/on-boy.jpg',1,0,1,'" + oauser.mobile + "','教师')");
  1165. conn.Execute("insert into LR_Base_UserRelation(F_UserRelationId,F_UserId,F_Category,F_ObjectId) values(newid(),'" + guid + "',1,'bc624869-b258-4f8b-af34-5c59c7ee69cb')");
  1166. conn.Execute("insert into LR_Base_UserRelation(F_UserRelationId,F_UserId,F_Category,F_ObjectId) values(newid(),'" + guid + "',1,'d61e1853-cdee-4d49-a5e1-e230f1098e52')");
  1167. }
  1168. }
  1169. conn.Execute(
  1170. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','从java系统获取新增用户插入完毕',getdate())");
  1171. }
  1172. }
  1173. catch (Exception e)
  1174. {
  1175. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1176. {
  1177. conn.Execute(
  1178. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','错误信息:" +
  1179. e.Message + "',getdate())");
  1180. }
  1181. }
  1182. }
  1183. /// <summary>
  1184. /// 西昌一卡通
  1185. /// </summary>
  1186. public static void BeginTrans()
  1187. {
  1188. try
  1189. {
  1190. IEnumerable<YKTEntity> yktlist = null;
  1191. IEnumerable<UserEntity> baseuserlist = null;
  1192. using (IDbConnection conn = new OracleConnection(_yktConnection))
  1193. {
  1194. yktlist = conn.Query<YKTEntity>(
  1195. "select * from YKTV_ACCOUNT where zjh is not null and kh is not null and zhyxrq is not null");
  1196. }
  1197. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1198. {
  1199. baseuserlist =
  1200. conn.Query<UserEntity>(
  1201. "select a.*,b.F_FullName as DeptName from LR_Base_User a left join LR_Base_Department b on a.F_DepartmentId=b.F_DepartmentId where a.F_DeleteMark = 0");
  1202. conn.Execute(
  1203. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','一卡通获取记录数:" +
  1204. yktlist.Count() + "条',getdate())");
  1205. }
  1206. var fulllist = (
  1207. from a in yktlist
  1208. join b in baseuserlist on a.zjh.TrimEnd() equals b.F_IdentityCardNo into b_join
  1209. from x in b_join.DefaultIfEmpty()
  1210. select new
  1211. {
  1212. zjh = a?.zjh,
  1213. Mobile = x?.F_Mobile,
  1214. zhyxrq = a?.zhyxrq,
  1215. Period = x?.F_Account,
  1216. UserType = x?.F_Description,
  1217. PerName = x?.F_RealName,
  1218. PerSex = x?.F_Gender == 1 ? "男" : "女",
  1219. Sex = x?.F_Gender,
  1220. PerType = 1,
  1221. Positions = "",
  1222. State = a?.zhzt[1] == '0' ? 0 : 1,
  1223. CardID2 = a?.zhzt[1] == '0' ? a?.kh.PadLeft(10, '0') : "",
  1224. UserDept = x?.DeptName,
  1225. UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  1226. }
  1227. ).ToList().Where(a => !string.IsNullOrEmpty(a.PerName) && !string.IsNullOrEmpty(a.zjh))
  1228. .DistinctBy(a => a.CardID2);
  1229. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1230. {
  1231. conn.Execute(
  1232. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','一卡通和系统关联数量:" +
  1233. fulllist.Count() + "条',getdate())");
  1234. }
  1235. using (IDbConnection conn = new SqlConnection(_mjConnection))
  1236. {
  1237. try
  1238. {
  1239. conn.Execute("truncate table doormiddle");
  1240. foreach (var userdata in fulllist)
  1241. {
  1242. string sql = @"insert into doormiddle ([Perid]
  1243. ,[PerName]
  1244. ,[PerSex]
  1245. ,[PerType]
  1246. ,[Positions]
  1247. ,[CardID2]
  1248. ,[State]
  1249. ,[UpdateTime])
  1250. VALUES ('" + userdata.Period + "','" + userdata.PerName + "','" + userdata.PerSex + "'," +
  1251. userdata.PerType + ",'" + userdata.Positions + "','" + userdata.CardID2 +
  1252. "'," +
  1253. userdata.State + ",'" + userdata.UpdateTime + "')";
  1254. conn.Execute(sql);
  1255. }
  1256. }
  1257. catch (Exception e)
  1258. {
  1259. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1260. {
  1261. conncore.Execute(
  1262. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'门禁系统同步报错','" +
  1263. e.Message + "',getdate())");
  1264. }
  1265. }
  1266. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1267. {
  1268. conncore.Execute(
  1269. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'门禁系统同步完成','门禁系统同步数量:" +
  1270. fulllist.Count() + "条',getdate())");
  1271. }
  1272. }
  1273. using (IDbConnection conn = new SqlConnection(_tsConnection))
  1274. {
  1275. try
  1276. {
  1277. conn.Execute("truncate table bookmiddle");
  1278. foreach (var userdata in fulllist)
  1279. {
  1280. string sql = @"insert into bookmiddle ([Action]
  1281. ,[Userno]
  1282. ,[User_name]
  1283. ,[Sex]
  1284. ,[Usertype]
  1285. ,[Member_id]
  1286. ,[dep]
  1287. ,[Idcard]
  1288. ,[Tel]
  1289. ,[State]
  1290. ,[Duetime]
  1291. ,[updatetime])
  1292. VALUES (1,'" + userdata.Period + "','" + userdata.PerName + "'," + userdata.Sex + ",'" +
  1293. userdata.UserType + "','" + userdata.CardID2.PadLeft(10, '0') + "','" +
  1294. userdata.UserDept + "','" + userdata.zjh + "','" + userdata.Mobile + "'," +
  1295. userdata.State + ",'" + userdata.zhyxrq + "','" + userdata.UpdateTime + "')";
  1296. conn.Execute(sql);
  1297. }
  1298. }
  1299. catch (Exception e)
  1300. {
  1301. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1302. {
  1303. conncore.Execute(
  1304. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'图书系统同步报错','" +
  1305. e.Message + "',getdate())");
  1306. }
  1307. }
  1308. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1309. {
  1310. conncore.Execute(
  1311. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'图书系统同步完成','图书系统同步数量:" +
  1312. fulllist.Count() + "条',getdate())");
  1313. }
  1314. }
  1315. }
  1316. catch (Exception e)
  1317. {
  1318. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1319. {
  1320. conn.Execute(
  1321. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'定时同步操作','错误信息:" +
  1322. e.Message + "',getdate())");
  1323. }
  1324. }
  1325. }
  1326. /// <summary>
  1327. /// 西昌中间库更新学生数据
  1328. /// </summary>
  1329. public static void MiddleDBUpdStuData()
  1330. {
  1331. try
  1332. {
  1333. using (IDbConnection conn_oracle = new OracleConnection(_xzMiddleConnection))
  1334. {
  1335. try
  1336. {
  1337. #region 记录获取数据条数
  1338. //专业
  1339. List<V_ZYXX> zyxx = conn_oracle.Query<V_ZYXX>("select * from V_ZYXX").ToList();
  1340. //课程信息
  1341. List<V_KCXX> kcxx = conn_oracle.Query<V_KCXX>("select * from V_KCXX").ToList();
  1342. //部门
  1343. List<V_Dept> depts = conn_oracle.Query<V_Dept>("select * from V_DEPT").ToList();
  1344. //教师
  1345. List<V_JSXX> jsxx = conn_oracle.Query<V_JSXX>("select * from V_JSXX").ToList();
  1346. //行政班级表
  1347. List<V_BJXX> bjxx = conn_oracle.Query<V_BJXX>("select * from V_BJXX").ToList();
  1348. //教室组织机构
  1349. List<V_JS_ZZJG> zzjg = conn_oracle.Query<V_JS_ZZJG>("select * from V_JS_ZZJG where ID!='0'").ToList();
  1350. //学生信息
  1351. List<V_XSXX> xsxx = conn_oracle.Query<V_XSXX>("select * from V_XSXX where MAJOR_CODE is not null ").ToList();
  1352. //记录获取数据条数
  1353. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1354. {
  1355. conncore.Execute(
  1356. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库专业数据','获取oracle专业数据共{zyxx.Count()}条',getdate())");
  1357. conncore.Execute(
  1358. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库课程数据','获取oracle课程数据共{kcxx.Count()}条',getdate())");
  1359. conncore.Execute(
  1360. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库部门数据','获取oracle部门数据共{depts.Count()}条',getdate())");
  1361. conncore.Execute(
  1362. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库教师数据','获取oracle教师数据共{jsxx.Count()}条',getdate())");
  1363. conncore.Execute(
  1364. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库班级数据','获取oracle班级数据共{bjxx.Count()}条',getdate())");
  1365. conncore.Execute(
  1366. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库教室数据','获取oracle教室数据共{jsxx.Count()}条',getdate())");
  1367. conncore.Execute(
  1368. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'中间库学生数据','获取oracle学生数据共{xsxx.Count()}条',getdate())");
  1369. }
  1370. #endregion
  1371. var teachinfo = new List<TeachModel>();
  1372. using (IDbConnection conncores = new SqlConnection(_sqlConnection))
  1373. {
  1374. #region 专业
  1375. //获取中间库数据
  1376. List<CdMajorModel> cdMajors = conncores.Query<CdMajorModel>("select * from CdMajor").ToList();
  1377. int anumMajor = 0;
  1378. int unumMajor = 0;
  1379. if (zyxx.Count() > 0)
  1380. {
  1381. foreach (var item in zyxx)
  1382. {
  1383. try
  1384. {
  1385. if (cdMajors.Exists(x => x.MajorNo == item.CODE_ && x.MajorName == item.NAME_ && x.DeptNo == item.PID))
  1386. {
  1387. StringBuilder sb = new StringBuilder("update CdMajor set ");
  1388. if (!string.IsNullOrEmpty(item.PID))
  1389. {
  1390. sb.Append($" DeptNo='{item.PID}',");
  1391. }
  1392. if (!string.IsNullOrEmpty(item.ORDER_))
  1393. {
  1394. sb.Append($" F_ORDER='{item.ORDER_}',");
  1395. }
  1396. if (!string.IsNullOrEmpty(item.ZYFL_CODE))
  1397. {
  1398. sb.Append($" ZYFL_CODE='{item.ZYFL_CODE}',");
  1399. }
  1400. sb.Append(@" CheckMark='" + (item.ISTRUE == true ? 1 : 0) + "',");
  1401. //去掉最后一个逗号
  1402. if (sb.ToString().Contains(","))
  1403. {
  1404. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1405. }
  1406. //修改条件
  1407. sb.Append($" where MajorNo='{item.CODE_}' and MajorName='{item.NAME_}'");
  1408. unumMajor += conncores.Execute(sb.ToString());
  1409. }
  1410. else
  1411. {
  1412. int mysql = conncores.Execute($"insert into CdMajor(ID,MajorNo,MajorName,DeptNo,CheckMark,F_SchoolId,ZYFL_CODE,F_ORDER) values(newid(),'{item.CODE_}','{item.NAME_}','{item.PID}','{item.ISTRUE}','207fa1a9-160c-4943-a89b-8fa4db0547ce','{item.ZYFL_CODE}','{item.ORDER_}')");
  1413. anumMajor += mysql;
  1414. }
  1415. }
  1416. catch (Exception e)
  1417. {
  1418. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1419. {
  1420. conncore.Execute(
  1421. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新专业数据','编号({item.CODE_}),姓名({item.NAME_})更新时出现异常:{e.Message}',getdate())");
  1422. }
  1423. }
  1424. }
  1425. }
  1426. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1427. {
  1428. //记录修改数据总数
  1429. conncore.Execute(
  1430. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新专业数据','新增数据{anumMajor}条,修改数据{unumMajor}条,共计{anumMajor + unumMajor}条,获取数据{zyxx.Count()}',getdate())");
  1431. }
  1432. #endregion
  1433. #region 课程
  1434. List<LessonInfoModel> LessonInfos = conncores.Query<LessonInfoModel>("select * from lessoninfo").ToList();
  1435. int anumLesson = 0;
  1436. int unumlesson = 0;
  1437. foreach (var item in kcxx)
  1438. {
  1439. try
  1440. {
  1441. if (LessonInfos.Exists(x => x.LessonNo == item.CODE_ && x.LessonName == item.NAME_))
  1442. {
  1443. StringBuilder sb = new StringBuilder("update lessoninfo set ");
  1444. if (!string.IsNullOrEmpty(item.COURSE_TYPE_CODE))
  1445. {
  1446. sb.Append($" LessonTypeId='{item.COURSE_TYPE_CODE}',");
  1447. }
  1448. if (!string.IsNullOrEmpty(item.COURSE_ATTR_CODE))
  1449. {
  1450. sb.Append($" LessonSortDetailNo='{item.COURSE_ATTR_CODE}',");
  1451. }
  1452. if (!string.IsNullOrEmpty(item.COURSE_NATURE_CODE))
  1453. {
  1454. sb.Append($" LessonSortNo='{item.COURSE_NATURE_CODE}',");
  1455. }
  1456. sb.Append(@" CheckMark='" + (item.ISTRUE == true ? 1 : 0) + "',");
  1457. //去掉最后一个逗号
  1458. if (sb.ToString().Contains(","))
  1459. {
  1460. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1461. }
  1462. //修改条件
  1463. sb.Append($" where lessonno='{item.CODE_}' and lessonName='{item.NAME_}'");
  1464. unumlesson += conncores.Execute(sb.ToString());
  1465. }
  1466. else
  1467. {
  1468. int mysql = conncores.Execute($"insert into LessonInfo(LessonId,LessonNo,LessonName,CheckMark,F_SchoolId,LessonSortNo,LessonSortDetailNo,LessonTypeId) values(newid(), '{item.CODE_}', '{item.NAME_}', '{item.ISTRUE}', '207fa1a9-160c-4943-a89b-8fa4db0547ce', '{item.COURSE_NATURE_CODE}', '{item.COURSE_ATTR_CODE}', '{item.COURSE_TYPE_CODE}')");
  1469. anumLesson += mysql;
  1470. }
  1471. }
  1472. catch (Exception e)
  1473. {
  1474. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1475. {
  1476. conncore.Execute(
  1477. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新课程数据','编号({item.CODE_}),姓名({item.NAME_})更新时出现异常:{e.Message}',getdate())");
  1478. }
  1479. }
  1480. }
  1481. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1482. {
  1483. //记录修改数据总数
  1484. conncore.Execute(
  1485. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新课程数据','新增数据{anumLesson}条,修改数据{unumlesson}条,共计{unumlesson + anumLesson}条,获取数据{kcxx.Count()}',getdate())");
  1486. }
  1487. #endregion
  1488. #region 教师信息
  1489. teachinfo = conncores.Query<TeachModel>("select * from empinfo").ToList();
  1490. int anumTeach = 0;
  1491. int unumTeach = 0;
  1492. foreach (var item in jsxx)
  1493. {
  1494. try
  1495. {
  1496. if (teachinfo.Exists(x => x.EmpNo == item.TEA_NO))
  1497. {
  1498. StringBuilder sb = new StringBuilder("update empinfo set ");
  1499. sb.Append($" EmpName='{item.NAME_}',");
  1500. sb.Append($" UpdateTime='{DateTime.Now}', ");
  1501. if (!string.IsNullOrEmpty(item.ZZJG_ID))
  1502. {
  1503. sb.Append($" ZZJG_ID='{item.ZZJG_ID}',");
  1504. }
  1505. if (!string.IsNullOrEmpty(item.DEPT_ID))
  1506. {
  1507. sb.Append($" F_DepartmentId='{item.DEPT_ID}',");
  1508. }
  1509. if (!string.IsNullOrEmpty(item.BZLX_CODE))
  1510. {
  1511. sb.Append($" BZLX_CODE='{item.BZLX_CODE}',");
  1512. }
  1513. if (!string.IsNullOrEmpty(item.TEA_STATUS_CODE))
  1514. {
  1515. sb.Append($" IsInActiveStatus='{item.TEA_STATUS_CODE}',");
  1516. }
  1517. if (!string.IsNullOrEmpty(item.BZLB_CODE))
  1518. {
  1519. sb.Append($" BZLB_CODE='{item.BZLB_CODE}',");
  1520. }
  1521. if (!string.IsNullOrEmpty(item.IDNO))
  1522. {
  1523. sb.Append($" IdentityCardNo='{item.IDNO}',");
  1524. }
  1525. if (!string.IsNullOrEmpty(item.BIRTH_DATE))
  1526. {
  1527. sb.Append($" Birthday='{item.BIRTH_DATE}',");
  1528. }
  1529. if (!string.IsNullOrEmpty(item.PHONE))
  1530. {
  1531. sb.Append($" mobile='{item.PHONE}',");
  1532. }
  1533. if (!string.IsNullOrEmpty(item.EDU_ID))
  1534. {
  1535. sb.Append($" HighestRecord='{item.EDU_ID}',");
  1536. }
  1537. if (!string.IsNullOrEmpty(item.DEGREE_ID))
  1538. {
  1539. sb.Append($" DegreeNo='{item.DEGREE_ID}',");
  1540. }
  1541. sb.Append(@" CheckMark='" + (item.IS_NORMAL == true ? 1 : 0) + "',");
  1542. //去掉最后一个逗号
  1543. if (sb.ToString().Contains(","))
  1544. {
  1545. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1546. }
  1547. //修改条件
  1548. sb.Append($" where empno='{item.TEA_NO}'");
  1549. unumTeach += conncores.Execute(sb.ToString());
  1550. }
  1551. else
  1552. {
  1553. int mysql = conncores.Execute($"insert into empinfo (empid,ZZJG_ID,F_DepartmentId,empNo,empName,Birthday,IdentityCardNo,mobile,DegreeNo,HighestRecord,CheckMark,F_CompanyId,BZLB_CODE,BZLX_CODE,IsInActiveStatus,UpdateTime) values (newid(), '{item.ZZJG_ID}', '{item.DEPT_ID}', '{item.TEA_NO}', '{item.NAME_}', '{item.BIRTH_DATE}', '{item.IDNO}', '{item.PHONE}', '{item.EDU_ID}', '{item.DEGREE_ID}', '{item.IS_NORMAL}', '207fa1a9-160c-4943-a89b-8fa4db0547ce', '{item.BZLB_CODE}', '{item.BZLX_CODE}', '{item.TEA_STATUS_CODE}','{DateTime.Now}')");
  1554. anumTeach += mysql;
  1555. }
  1556. }
  1557. catch (Exception e)
  1558. {
  1559. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1560. {
  1561. conncore.Execute(
  1562. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新教师数据','编号({item.TEA_NO}),姓名({item.NAME_})更新时出现异常:{e.Message}',getdate())");
  1563. }
  1564. }
  1565. }
  1566. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1567. {
  1568. //记录修改数据总数
  1569. conncore.Execute(
  1570. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新教师数据','新增数据{anumTeach}条,修改数据{unumTeach}条,共计{unumTeach + anumTeach}条,获取数据{jsxx.Count()}',getdate())");
  1571. }
  1572. #endregion
  1573. #region 班级信息
  1574. List<ClassModel> classModels = conncores.Query<ClassModel>("select * from classinfo").ToList();
  1575. int anumClass = 0;
  1576. int unumClass = 0;
  1577. foreach (var item in bjxx)
  1578. {
  1579. try
  1580. {
  1581. if (classModels.Exists(x => x.ClassName == item.NAME_ && x.ClassNo == item.NO_))
  1582. {
  1583. StringBuilder sb = new StringBuilder("update classinfo set ");
  1584. if (!string.IsNullOrEmpty(item.MAJOR_CODE))
  1585. {
  1586. sb.Append($" MajorNo='{item.MAJOR_CODE}',");
  1587. }
  1588. if (!string.IsNullOrEmpty(item.LENGTH_SCHOOLING))
  1589. {
  1590. sb.Append($" Educational='{item.LENGTH_SCHOOLING}',");
  1591. }
  1592. if (!string.IsNullOrEmpty(item.PYCC_CODE))
  1593. {
  1594. sb.Append($" PYCC_CODE='{item.PYCC_CODE}',");
  1595. }
  1596. if (!string.IsNullOrEmpty(item.GRADE))
  1597. {
  1598. sb.Append($" Grade='{item.GRADE.Substring(2)}',");
  1599. }
  1600. if (!string.IsNullOrEmpty(item.GRADUATE_YEAR))
  1601. {
  1602. sb.Append($" GRADUATE_YEAR='{item.GRADUATE_YEAR}',");
  1603. }
  1604. if (!string.IsNullOrEmpty(item.GRADUATE_SCHOOLYEAR))
  1605. {
  1606. sb.Append($" GRADUATE_SCHOOLYEAR='{item.GRADUATE_SCHOOLYEAR}',");
  1607. }
  1608. if (!string.IsNullOrEmpty(item.GRADUATE_DATE))
  1609. {
  1610. sb.Append($" GRADUATE_DATE='{item.GRADUATE_DATE}',");
  1611. }
  1612. if (!string.IsNullOrEmpty(item.PINYIN))
  1613. {
  1614. sb.Append($" PINYIN='{item.PINYIN}',");
  1615. }
  1616. if (!string.IsNullOrEmpty(item.NAME_SHORT))
  1617. {
  1618. sb.Append($" NAME_SHORT='{item.NAME_SHORT}',");
  1619. }
  1620. if (!string.IsNullOrEmpty(item.PINYIN_SHORT))
  1621. {
  1622. sb.Append($" PINYIN_SHORT='{item.PINYIN_SHORT}',");
  1623. }
  1624. sb.Append(@" CheckMark='" + (item.ISTRUE == true ? 1 : 0) + "',");
  1625. //去掉最后一个逗号
  1626. if (sb.ToString().Contains(","))
  1627. {
  1628. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1629. }
  1630. //修改条件
  1631. sb.Append($" where classno='{item.NO_}' and className='{item.NAME_}'");
  1632. unumClass += conncores.Execute(sb.ToString());
  1633. }
  1634. else
  1635. {
  1636. int mysql = conncores.Execute($"insert into classinfo (ClassId, ClassNo, ClassName, MajorNo, Educational, PYCC_CODE, Grade, GRADUATE_YEAR, GRADUATE_SCHOOLYEAR, GRADUATE_DATE, PINYIN, NAME_SHORT, PINYIN_SHORT, CheckMark) values (newid(), '{item.NO_}', '{item.NAME_}', '{item.MAJOR_CODE}', '{item.LENGTH_SCHOOLING}', '{item.PYCC_CODE}', '{item.GRADE.Substring(2)}', '{item.GRADUATE_YEAR}', '{item.GRADUATE_SCHOOLYEAR}', '{item.GRADUATE_DATE}', '{item.PINYIN}', '{item.NAME_SHORT}', '{item.PINYIN_SHORT}', '{item.ISTRUE}')");
  1637. anumClass += mysql;
  1638. }
  1639. }
  1640. catch (Exception e)
  1641. {
  1642. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1643. {
  1644. conncore.Execute(
  1645. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新班级数据','编号({item.NO_}),姓名({item.NAME_})更新时出现异常:{e.Message}',getdate())");
  1646. }
  1647. }
  1648. }
  1649. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1650. {
  1651. //记录修改数据总数
  1652. conncore.Execute(
  1653. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新班级数据','新增数据{anumClass}条,修改数据{unumClass}条,共计{unumClass + anumClass}条,获取数据{bjxx.Count()}',getdate())");
  1654. }
  1655. #endregion
  1656. #region 教室信息
  1657. List<ClassRoomModel> classRoomModels = conncores.Query<ClassRoomModel>("select * from classroominfo").ToList();
  1658. int anumCroom = 0;
  1659. int unumCroom = 0;
  1660. foreach (var item in zzjg)
  1661. {
  1662. try
  1663. {
  1664. if (classRoomModels.Exists(x => x.ClassroomNo == item.CODE_ && x.ClassroomName == item.NAME_))
  1665. {
  1666. StringBuilder sb = new StringBuilder("update classroominfo set ");
  1667. if (!string.IsNullOrEmpty(item.PID))
  1668. {
  1669. sb.Append($" PID='{item.PID}',");
  1670. }
  1671. if (!string.IsNullOrEmpty(item.PATH_))
  1672. {
  1673. sb.Append($" PATH_='{item.PATH_}',");
  1674. }
  1675. if (!string.IsNullOrEmpty(item.LEVEL_))
  1676. {
  1677. sb.Append($" ClassroomFloor='{item.LEVEL_}',");
  1678. }
  1679. if (!string.IsNullOrEmpty(item.LEVEL_TYPE))
  1680. {
  1681. sb.Append($" LEVEL_TYPE='{item.LEVEL_TYPE}',");
  1682. }
  1683. if (!string.IsNullOrEmpty(item.ORDER_))
  1684. {
  1685. sb.Append($" ORDER_='{item.ORDER_}',");
  1686. }
  1687. if (!string.IsNullOrEmpty(item.JSLX_CODE))
  1688. {
  1689. sb.Append($" ClassroomTypeNo='{item.JSLX_CODE}',");
  1690. }
  1691. if (!string.IsNullOrEmpty(item.ZW_COUNT))
  1692. {
  1693. sb.Append($" ContainStuNum='{item.ZW_COUNT}',");
  1694. }
  1695. if (!string.IsNullOrEmpty(item.JXL_ID))
  1696. {
  1697. sb.Append($" ClassroomBuildingNo='{item.JXL_ID}',");
  1698. }
  1699. if (!string.IsNullOrEmpty(item.XQ_ID))
  1700. {
  1701. sb.Append($" F_SchoolId='{item.XQ_ID}',");
  1702. }
  1703. sb.Append(@" CheckMark='" + (item.ISTRUE == true ? 1 : 0) + "',");
  1704. //去掉最后一个逗号
  1705. if (sb.ToString().Contains(","))
  1706. {
  1707. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1708. }
  1709. //修改条件
  1710. sb.Append($" where classroomno='{item.CODE_}' and classroomName='{item.NAME_}'");
  1711. unumCroom += conncores.Execute(sb.ToString());
  1712. }
  1713. else
  1714. {
  1715. int mysql = conncores.Execute($"insert into classroominfo (ClassroomId, ClassroomNo, ClassroomName, PID, PATH_, ClassroomFloor, LEVEL_TYPE, ORDER_, ClassroomTypeNo, ContainStuNum, ClassroomBuildingNo, F_SchoolId, CheckMark) values (newid(), '{item.CODE_}', '{item.NAME_}', '{item.PID}', '{item.PATH_}', '{item.LEVEL_}', '{item.LEVEL_TYPE}', '{item.ORDER_}', '{item.JSLX_CODE}', '{item.ZW_COUNT}', '{item.JXL_ID}', '{item.XQ_ID}', '{item.ISTRUE}')");
  1716. anumCroom += mysql;
  1717. }
  1718. }
  1719. catch (Exception e)
  1720. {
  1721. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1722. {
  1723. conncore.Execute(
  1724. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新教室数据','编号({item.CODE_}),姓名({item.NAME_})更新时出现异常:{e.Message}',getdate())");
  1725. }
  1726. }
  1727. }
  1728. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1729. {
  1730. //记录修改数据总数
  1731. conncore.Execute(
  1732. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新教室数据','新增数据{anumCroom}条,修改数据{unumCroom}条,共计{unumCroom + anumCroom}条,获取数据{zzjg.Count()}',getdate())");
  1733. }
  1734. #endregion
  1735. }
  1736. using (IDbConnection db = new SqlConnection(_coresqlConnection))
  1737. {
  1738. #region 部门
  1739. List<DepartmentEntity> departments = db.Query<DepartmentEntity>("select * from LR_Base_Department").ToList();
  1740. int anumDept = 0;
  1741. int unumDept = 0;
  1742. foreach (var item in depts)
  1743. {
  1744. try
  1745. {
  1746. if (item.LEVEL_TYPE.ToLower() != "xx" && item.LEVEL_TYPE.ToLower() != "zy")
  1747. {
  1748. var manager = string.Empty;
  1749. if (!string.IsNullOrWhiteSpace(item.ADMIN_MANAGE_TEA_NO))
  1750. {
  1751. manager = teachinfo.FirstOrDefault(x => x.EmpNo == item.ADMIN_MANAGE_TEA_NO)?.EmpId ?? "";
  1752. }
  1753. if (departments.Any(x => x.F_DepartmentId == item.ID))
  1754. {
  1755. var sql = $"update LR_Base_Department set F_FullName='{item.NAME_}',F_ParentId='{item.PID}',F_EnCode='{item.CODE_}',F_ShortName='{item.NAME_SHORT}',F_Manager='{manager}',F_Description='{item.LEVEL_TYPE}',F_ModifyDate='{DateTime.Now}' where F_DepartmentId='{item.ID}'";
  1756. anumDept += db.Execute(sql);
  1757. }
  1758. else
  1759. {
  1760. var sql = $"insert into LR_Base_Department (F_DepartmentId,F_CompanyId,F_ParentId,F_EnCode,F_FullName,F_ShortName,F_Manager,F_Description,F_SortCode,F_DeleteMark,F_EnabledMark,F_CreateDate,F_Order) values ('{item.ID}','207fa1a9-160c-4943-a89b-8fa4db0547ce','{item.PID}','{item.CODE_}','{item.NAME_}','{item.NAME_SHORT}','{manager}','{item.LEVEL_TYPE}',0,0,1,'{DateTime.Now}',0)";
  1761. anumDept += db.Execute(sql);
  1762. }
  1763. }
  1764. }
  1765. catch (Exception ex)
  1766. {
  1767. db.Execute(
  1768. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'更新部门数据','编号({item.ID}),姓名({item.NAME_})更新时出现异常:{ex.Message}',getdate())");
  1769. }
  1770. }
  1771. #endregion
  1772. }
  1773. //获取oracle学生数据
  1774. //List<XCStudentEntity> xcStudentList = conn_oracle.Query<XCStudentEntity>(@"select ID,stu_no,name_,
  1775. //(case when dept_id in ('01','02','03') then dept_id when dept_id='00' then '06' when dept_id='23' then '04' when dept_id='06' then '07' else '' end )as dept_id,
  1776. //MAJOR_CODE,class_id,birthday,(case sex_code when '2' then '0' else '1' end) as sex_code,NATION_CODE,POLITICS_CODE,LENGTH_SCHOOLING,ENROLL_DATE,substr(ENROLL_GRADE,3,2) as ENROLL_GRADE from v_lq_xs_stu").ToList();
  1777. // List<XCStudentEntity> xcStudentList = conn_oracle.Query<XCStudentEntity>(@"select ID,stu_no,name_,
  1778. //(case when dept_id in ('01','02','03') then dept_id when dept_id='00' then '06' when dept_id='23' then '04' when dept_id='06' then '07' else '' end )as dept_id,
  1779. //MAJOR_CODE,class_id,birthday,(case sex_code when '2' then '0' else '1' end) as sex_code,NATION_CODE,POLITICS_CODE,LENGTH_SCHOOLING,ENROLL_DATE,substr(ENROLL_GRADE,3,2) as ENROLL_GRADE from v_lq_xs_stu
  1780. //where class_id like '21010130%'").ToList();
  1781. //using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1782. //{
  1783. // conncore.Execute(
  1784. // $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),578,'从西昌中间库更新学生数据','获取oracle学生数据{xsxx.Count()}条',getdate())");
  1785. //}
  1786. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  1787. {
  1788. //西昌学生信息表
  1789. List<StuInfoBasicModel> stuInfoBasicList = conn.Query<StuInfoBasicModel>(@"select * from StuInfoBasic ").ToList();
  1790. ////数据字典表
  1791. List<MiddleDicEntity> dicList = conn.Query<MiddleDicEntity>(@"select * from MiddleDictionary ").ToList();
  1792. int anum = 0;
  1793. int unum = 0;
  1794. foreach (var item in xsxx)
  1795. {
  1796. try
  1797. {
  1798. if (stuInfoBasicList.Exists(x => x.StuNo == item.STU_NO))
  1799. {
  1800. //学生存在,修改
  1801. #region 拼接SQL
  1802. StringBuilder sb = new StringBuilder("update StuInfoBasic set ");
  1803. sb.Append($" StuName='{item.NAME_}',");
  1804. sb.Append($" UpdateTime='{DateTime.Now}', ");
  1805. if (!string.IsNullOrEmpty(item.DEPT_ID))
  1806. {
  1807. sb.Append($" DeptNo='{item.DEPT_ID}',");
  1808. }
  1809. //专业
  1810. if (!string.IsNullOrEmpty(item.MAJOR_CODE))
  1811. {
  1812. sb.Append($" MajorNo='{item.MAJOR_CODE}',");
  1813. }
  1814. //班级
  1815. if (!string.IsNullOrEmpty(item.CLASS_ID))
  1816. {
  1817. sb.Append($" ClassNo='{item.CLASS_ID}',");
  1818. }
  1819. if (!string.IsNullOrEmpty(item.FORMER_NAME))
  1820. {
  1821. sb.Append($" FORMER_NAME='{item.FORMER_NAME}',");
  1822. }
  1823. if (!string.IsNullOrEmpty(item.PINYIN))
  1824. {
  1825. sb.Append($" SpellFull='{item.PINYIN}',");
  1826. }
  1827. if (!string.IsNullOrEmpty(item.BIRTHDAY))
  1828. {
  1829. var date = Convert.ToDateTime(item.BIRTHDAY);
  1830. sb.Append($" Birthday='{date}',");
  1831. }
  1832. if (!string.IsNullOrEmpty(item.IDNO))
  1833. {
  1834. sb.Append($" IdentityCardNo='{item.IDNO}',");
  1835. }
  1836. if (!string.IsNullOrEmpty(item.SEX_CODE))
  1837. {
  1838. sb.Append(" GenderNo='" + (item.SEX_CODE == "1" ? "1" : "0") + "',");
  1839. }
  1840. //民族
  1841. if (!string.IsNullOrEmpty(item.NATION_CODE))
  1842. {
  1843. var NationalityNo = dicList.Where(x =>
  1844. x.TName == "National" && x.Mcode == item.NATION_CODE).Select(x => x.Code).FirstOrDefault();
  1845. if (!string.IsNullOrEmpty(NationalityNo))
  1846. {
  1847. sb.Append($" NationalityNo='{NationalityNo}',");
  1848. }
  1849. }
  1850. //政治面貌
  1851. if (!string.IsNullOrEmpty(item.POLITICS_CODE))
  1852. {
  1853. sb.Append($" PartyFaceNo='{item.POLITICS_CODE}',");
  1854. }
  1855. //学制
  1856. if (!string.IsNullOrEmpty(item.LENGTH_SCHOOLING))
  1857. {
  1858. sb.Append($" EduSystem='{item.LENGTH_SCHOOLING}',");
  1859. }
  1860. if (!string.IsNullOrEmpty(item.PYCC_CODE))
  1861. {
  1862. sb.Append($" PYCC_CODE='{item.PYCC_CODE}',");
  1863. }
  1864. ////入学日期 oracle中格式有误,先不更新
  1865. //if (!string.IsNullOrEmpty(item.ENROLL_DATE))
  1866. //{
  1867. // var date = Convert.ToDateTime(item.ENROLL_DATE);
  1868. // sb.Append($" RegisterDate='{date}',");
  1869. //}
  1870. //入学年级
  1871. if (!string.IsNullOrEmpty(item.ENROLL_GRADE))
  1872. {
  1873. sb.Append($" Grade='{item.ENROLL_GRADE.Substring(2)}',");
  1874. }
  1875. if (!string.IsNullOrEmpty(item.STU_STATE_CODE))
  1876. {
  1877. sb.Append($" STU_STATE_CODE='{item.STU_STATE_CODE}',");
  1878. }
  1879. if (!string.IsNullOrEmpty(item.STU_ROLL_CODE))
  1880. {
  1881. sb.Append($" STU_ROLL_CODE='{item.STU_ROLL_CODE}',");
  1882. }
  1883. sb.Append(@" InSchoolStatus='" + (item.IS_NORMAL) + "',");
  1884. //去掉最后一个逗号
  1885. if (sb.ToString().Contains(","))
  1886. {
  1887. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  1888. }
  1889. sb.Append($" where StuNo='{item.STU_NO}'");
  1890. //System.IO.File.AppendAllText(@"c:\test.txt", sb.ToString() + "\r\n");
  1891. #endregion
  1892. unum += conn.Execute(sb.ToString());
  1893. }
  1894. else
  1895. {
  1896. //新增学生
  1897. //拼接SQL
  1898. string mysql = GetAddSql(dicList, item);
  1899. anum += conn.Execute(mysql);
  1900. }
  1901. }
  1902. catch (Exception e)
  1903. {
  1904. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1905. {
  1906. conncore.Execute(
  1907. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),578,'从西昌中间库更新学生数据','学生学号({item.STU_NO}),姓名({item.NAME_})更新时出现异常:{e.Message}.',getdate())");
  1908. }
  1909. }
  1910. }
  1911. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1912. {
  1913. conncore.Execute(
  1914. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),578,'从西昌中间库更新学生数据','新增学生数据{anum}条,修改学生数据{unum}条',getdate())");
  1915. }
  1916. }
  1917. }
  1918. catch (Exception e)
  1919. {
  1920. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  1921. {
  1922. conncore.Execute(
  1923. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),578,'从西昌中间库获取数据','异常信息:" +
  1924. e.Message + "',getdate())");
  1925. }
  1926. }
  1927. }
  1928. }
  1929. catch (Exception e)
  1930. {
  1931. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  1932. {
  1933. conn.Execute(
  1934. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),578,'从西昌中间库更新基础数据','错误信息:" +
  1935. e.Message + "',getdate())");
  1936. }
  1937. }
  1938. }
  1939. private static string GetAddSql(List<MiddleDicEntity> dicList, V_XSXX xsxx)
  1940. {
  1941. string mysql = "insert into StuInfoBasic(";
  1942. StringBuilder fieleSb = new StringBuilder();
  1943. StringBuilder sb = new StringBuilder();
  1944. fieleSb.Append("StuId,stuno,stuname,CheckMark,F_SchoolId,UpdateTime,");
  1945. sb.Append($" NEWID(),'{xsxx.STU_NO}','{xsxx.NAME_}','1','207fa1a9-160c-4943-a89b-8fa4db0547ce','{DateTime.Now}',");
  1946. if (!string.IsNullOrEmpty(xsxx.DEPT_ID))
  1947. {
  1948. fieleSb.Append("DeptNo,");
  1949. sb.Append($" '{xsxx.DEPT_ID}',");
  1950. }
  1951. //专业
  1952. if (!string.IsNullOrEmpty(xsxx.MAJOR_CODE))
  1953. {
  1954. fieleSb.Append("MajorNo,");
  1955. sb.Append($" '{xsxx.MAJOR_CODE}',");
  1956. }
  1957. if (!string.IsNullOrEmpty(xsxx.CLASS_ID))
  1958. {
  1959. fieleSb.Append("ClassNo,");
  1960. sb.Append($" '{xsxx.CLASS_ID}',");
  1961. }
  1962. if (!string.IsNullOrEmpty(xsxx.PINYIN))
  1963. {
  1964. fieleSb.Append("SpellFull,");
  1965. sb.Append($" '{xsxx.PINYIN}',");
  1966. }
  1967. if (!string.IsNullOrEmpty(xsxx.BIRTHDAY))
  1968. {
  1969. var date = Convert.ToDateTime(xsxx.BIRTHDAY);
  1970. fieleSb.Append("Birthday,");
  1971. sb.Append($" '{date}',");
  1972. }
  1973. if (!string.IsNullOrEmpty(xsxx.IDNO))
  1974. {
  1975. fieleSb.Append("IdentityCardNo,");
  1976. sb.Append($" '{xsxx.IDNO}',");
  1977. }
  1978. if (!string.IsNullOrEmpty(xsxx.SEX_CODE))
  1979. {
  1980. fieleSb.Append("GenderNo,");
  1981. sb.Append(" '" + (xsxx.SEX_CODE == "1" ? "1" : "0") + "',");
  1982. }
  1983. //民族
  1984. if (!string.IsNullOrEmpty(xsxx.NATION_CODE))
  1985. {
  1986. var NationalityNo = dicList.Where(x =>
  1987. x.TName == "National" && x.Mcode == xsxx.NATION_CODE).Select(x => x.Code).FirstOrDefault();
  1988. if (!string.IsNullOrEmpty(NationalityNo))
  1989. {
  1990. fieleSb.Append("NationalityNo,");
  1991. sb.Append($" '{NationalityNo}',");
  1992. }
  1993. }
  1994. //政治面貌
  1995. if (!string.IsNullOrEmpty(xsxx.POLITICS_CODE))
  1996. {
  1997. fieleSb.Append("PartyFaceNo,");
  1998. sb.Append($" '{xsxx.POLITICS_CODE}',");
  1999. }
  2000. //学制
  2001. if (!string.IsNullOrEmpty(xsxx.LENGTH_SCHOOLING))
  2002. {
  2003. fieleSb.Append("EduSystem,");
  2004. sb.Append($" '{xsxx.LENGTH_SCHOOLING}',");
  2005. }
  2006. if (!string.IsNullOrEmpty(xsxx.PYCC_CODE))
  2007. {
  2008. fieleSb.Append("PYCC_CODE,");
  2009. sb.Append($" '{xsxx.PYCC_CODE}',");
  2010. }
  2011. //入学日期
  2012. //if (!string.IsNullOrEmpty(xsxx.ENROLL_DATE))
  2013. //{
  2014. // var date = Convert.ToDateTime(xsxx.ENROLL_DATE);
  2015. // fieleSb.Append("RegisterDate,");
  2016. // sb.Append($" '{date}',");
  2017. //}
  2018. //入学年级
  2019. if (xsxx.ENROLL_GRADE != null)
  2020. {
  2021. fieleSb.Append("Grade,");
  2022. sb.Append($" '{xsxx.ENROLL_GRADE.ToString().Substring(2)}',");
  2023. }
  2024. if (xsxx.IS_NORMAL != null)
  2025. {
  2026. fieleSb.Append("InSchoolStatus,");
  2027. sb.Append(" '" + (xsxx.IS_NORMAL) + "',");
  2028. }
  2029. //去掉最后一个逗号
  2030. if (fieleSb.ToString().Contains(",") && sb.ToString().Contains(","))
  2031. {
  2032. fieleSb.Remove(fieleSb.ToString().LastIndexOf(","), 1);
  2033. sb.Remove(sb.ToString().LastIndexOf(","), 1);
  2034. }
  2035. mysql += fieleSb.ToString() + ") values (" + sb.ToString() + ")";
  2036. return mysql;
  2037. }
  2038. public static System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer();
  2039. static WebReference.SynService synService = new SynService() { Timeout = 300000, CookieContainer = cookieContainer };
  2040. static string Loginkey = "123456789";
  2041. static string enCode = "00000000";
  2042. public static void GetConsumeInfo()
  2043. {
  2044. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  2045. {
  2046. conn.Execute(
  2047. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'一卡通同步操作','开始同步消费记录',getdate())");
  2048. }
  2049. var tokenResult = synService.GetToken("1");
  2050. if (tokenResult.code == 100)
  2051. {
  2052. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  2053. {
  2054. conn.Execute(
  2055. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'一卡通同步操作','获取Token成功',getdate())");
  2056. }
  2057. var pwd = Md5Helper.Encrypt(tokenResult.msg + Loginkey, 32).ToUpper();
  2058. var loginInfo = synService.Logon("1", pwd);
  2059. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  2060. {
  2061. var beginKey = -1;
  2062. var result1 = conn.Query<string>("SELECT TOP 1 ID FROM dbo.StuConsumption ORDER BY ID DESC");
  2063. if (result1.Count() > 0)
  2064. {
  2065. beginKey = Convert.ToInt32(result1.FirstOrDefault());
  2066. }
  2067. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2068. {
  2069. conncore.Execute(
  2070. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'一卡通同步操作','同步开始:本次从+" + beginKey + "开始同步500条记录',getdate())");
  2071. }
  2072. var result = synService.GetEcardConsumeRecord(enCode, 0, beginKey, 500);
  2073. if (result.Record != null && result.Record.Length > 0)
  2074. {
  2075. foreach (var item in result.Record)
  2076. {
  2077. var entity = new StuConsumptionEntity();
  2078. entity.ACCCODE = item.ACCCODE.ToString();
  2079. entity.ASN = item.ASN.ToString();
  2080. entity.CARDSN = item.CARDSN.ToString();
  2081. entity.CUSTOMERID = item.CUSTOMERID.ToString();
  2082. entity.DSCRP = item.DSCRP.ToString();
  2083. entity.ECODE = item.ECODE.ToString();
  2084. entity.ID = item.ID.ToString();
  2085. entity.MNGFARE = item.MNGFARE.ToString();
  2086. entity.NOTECASE = item.NOTECASE.ToString();
  2087. entity.ODDFARE = item.ODDFARE.ToString();
  2088. entity.OPCOUNT = item.OPCOUNT.ToString();
  2089. entity.OPDT = item.OPDT;
  2090. entity.OPFARE = item.OPFARE.ToString();
  2091. entity.OUTID = item.OUTID.ToString();
  2092. entity.RECNO = item.RECNO.ToString();
  2093. entity.SAMCARDNO = item.ACCCODE.ToString();
  2094. entity.SAMTRADENO = item.SAMTRADENO.ToString();
  2095. entity.SOURCETABLE = item.SOURCETABLE.ToString();
  2096. entity.TAC = item.TAC.ToString();
  2097. entity.TERMID = item.TERMID.ToString();
  2098. entity.TRADECARDTYPE = item.TRADECARDTYPE.ToString();
  2099. entity.UPLOADDATE = item.UPLOADDATE;
  2100. entity.Create();
  2101. conn.Execute(
  2102. $"INSERT dbo.StuConsumption ( SID, SOURCETABLE, ID, ECODE, NOTECASE, CUSTOMERID, OUTID, CARDSN, OPCOUNT, OPDT, ODDFARE, OPFARE, MNGFARE, ACCCODE, DSCRP, TERMID, RECNO, UPLOADDATE, SAMCARDNO, SAMTRADENO, TRADECARDTYPE, TAC, ASN) VALUES (NEWID(), N'{entity.SOURCETABLE}',N'{entity.ID}',N'{entity.ECODE}',N'{entity.NOTECASE}',N'{entity.CUSTOMERID}',N'{entity.OUTID}',N'{entity.CARDSN}',N'{entity.OPCOUNT}','{entity.OPDT}', N'{entity.ODDFARE}',N'{entity.OPFARE}',N'{entity.MNGFARE}',N'{entity.ACCCODE}',N'{entity.DSCRP}',N'{entity.TERMID}',N'{entity.RECNO}','{entity.UPLOADDATE}',N'{entity.SAMCARDNO}',N'{entity.SAMTRADENO}',N'{entity.TRADECARDTYPE}',N'{entity.TAC}',N'{entity.ASN}')");
  2103. }
  2104. GetConsumeInfo();
  2105. }
  2106. else
  2107. {
  2108. var stuData = conn.Query("SELECT StuNo FROM dbo.StuInfoBasic");
  2109. foreach (var stu in stuData)
  2110. {
  2111. var StuNo = stu.StuNo.ToString();
  2112. conn.Execute(
  2113. $"UPDATE dbo.StuInfoBasic SET Balance=(SELECT TOP 1 ODDFARE FROM dbo.StuConsumption WHERE OUTID='{StuNo}' ORDER BY ID DESC) WHERE StuNo='{StuNo}'");
  2114. }
  2115. }
  2116. }
  2117. }
  2118. else
  2119. {
  2120. using (IDbConnection conn = new SqlConnection(_coresqlConnection))
  2121. {
  2122. conn.Execute(
  2123. "insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),999,'一卡通同步操作','获取Token失败',getdate())");
  2124. }
  2125. }
  2126. }
  2127. /// <summary>
  2128. /// 获取充值记录
  2129. /// </summary>
  2130. public static void GetSaveRecordInfo()
  2131. {
  2132. var tokenResult = synService.GetToken("1");
  2133. if (tokenResult.code == 100)
  2134. {
  2135. var pwd = Md5Helper.Encrypt(tokenResult.msg + Loginkey, 32).ToUpper();
  2136. var loginInfo = synService.Logon("1", pwd);
  2137. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  2138. {
  2139. var beginKey = -1;
  2140. var result1 = conn.Query<string>("SELECT TOP 1 ID FROM dbo.StuSaveRecord ORDER BY ID DESC");
  2141. if (result1.Count() > 0)
  2142. {
  2143. beginKey = Convert.ToInt32(result1.FirstOrDefault());
  2144. }
  2145. var result = synService.GetEcardSaveRecord(enCode, 0, beginKey, 500);
  2146. if (result.Record.Length > 0)
  2147. {
  2148. foreach (var item in result.Record)
  2149. {
  2150. var entity = new StuSaveRecordEntity();
  2151. entity.ACCCODE = item.ACCCODE.ToString();
  2152. entity.ASN = item.ASN.ToString();
  2153. entity.CARDSN = item.CARDSN.ToString();
  2154. entity.CUSTOMERID = item.CUSTOMERID.ToString();
  2155. entity.DSCRP = item.DSCRP.ToString();
  2156. entity.ECODE = item.ECODE.ToString();
  2157. entity.ID = item.ID.ToString();
  2158. entity.MNGFARE = item.MNGFARE.ToString();
  2159. entity.NOTECASE = item.NOTECASE.ToString();
  2160. entity.ODDFARE = item.ODDFARE.ToString();
  2161. entity.SAVEOPCOUNT = item.SAVEOPCOUNT.ToString();
  2162. entity.OPCOUNT = item.OPCOUNT.ToString();
  2163. entity.OPDT = item.OPDT;
  2164. entity.OPFARE = item.OPFARE.ToString();
  2165. entity.OUTID = item.OUTID.ToString();
  2166. entity.RECNO = item.RECNO.ToString();
  2167. entity.SAMCARDNO = item.ACCCODE.ToString();
  2168. entity.SAMTRADENO = item.SAMTRADENO.ToString();
  2169. entity.SOURCETABLE = item.SOURCETABLE.ToString();
  2170. entity.TAC = item.TAC.ToString();
  2171. entity.TERMID = item.TERMID.ToString();
  2172. entity.TRADECARDTYPE = item.TRADECARDTYPE.ToString();
  2173. entity.UPLOADDATE = item.UPLOADDATE;
  2174. entity.Create();
  2175. conn.Execute(
  2176. $"INSERT dbo.StuSaveRecord ( SID, SOURCETABLE, ID, ECODE, NOTECASE, CUSTOMERID, OUTID, CARDSN,SAVEOPCOUNT, OPCOUNT, OPDT, ODDFARE, OPFARE, MNGFARE, ACCCODE, DSCRP, TERMID, RECNO, UPLOADDATE, SAMCARDNO, SAMTRADENO, TRADECARDTYPE, TAC, ASN) VALUES (NEWID(), N'{entity.SOURCETABLE}',N'{entity.ID}',N'{entity.ECODE}',N'{entity.NOTECASE}',N'{entity.CUSTOMERID}',N'{entity.OUTID}',N'{entity.CARDSN}',N'{entity.SAVEOPCOUNT}',N'{entity.OPCOUNT}','{entity.OPDT}', N'{entity.ODDFARE}',N'{entity.OPFARE}',N'{entity.MNGFARE}',N'{entity.ACCCODE}',N'{entity.DSCRP}',N'{entity.TERMID}',N'{entity.RECNO}','{entity.UPLOADDATE}',N'{entity.SAMCARDNO}',N'{entity.SAMTRADENO}',N'{entity.TRADECARDTYPE}',N'{entity.TAC}',N'{entity.ASN}')");
  2177. }
  2178. GetSaveRecordInfo();
  2179. }
  2180. }
  2181. }
  2182. }
  2183. public static void PushWeixin()
  2184. {
  2185. Uri uri = new Uri(ConfigurationManager.AppSettings["apiUrl"] + "/mpManagement/pushWeixin?data=ceshimpid");
  2186. using (WebClient client = new WebClient())
  2187. {
  2188. client.Headers["Type"] = "GET";
  2189. client.Headers["Accept"] = "application/json";
  2190. client.Encoding = Encoding.UTF8;
  2191. client.DownloadStringCompleted += (senderobj, es) =>
  2192. {
  2193. var obj = es.Result;
  2194. };
  2195. client.DownloadStringAsync(uri);
  2196. }
  2197. }
  2198. /// <summary>
  2199. /// 长阳一卡通交易流水
  2200. /// </summary>
  2201. public static void GetChangeYangYKT()
  2202. {
  2203. try
  2204. {
  2205. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2206. {
  2207. conncore.Execute(
  2208. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水1','开始执行',getdate())");
  2209. }
  2210. string Token = "";
  2211. #region 登陆获取token
  2212. //获取配置文件
  2213. string CYLoginUrl = ConfigurationManager.AppSettings["CYLoginUrl"];
  2214. string UserName = ConfigurationManager.AppSettings["UserName"];
  2215. string PassWord = ConfigurationManager.AppSettings["PassWord"];
  2216. HttpContent httpContent = new StringContent("{\"username\":\"" + UserName + "\",\"password\":\"" + PassWord + "\"}");
  2217. httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
  2218. string Results = Client.PostAsync(CYLoginUrl, httpContent).Result.Content.ReadAsStringAsync().Result;
  2219. var Result = JsonConvert.DeserializeObject<LoginResult>(Results);
  2220. if (Results != null && Result.code == 0)
  2221. {
  2222. Token = Result.token;
  2223. }
  2224. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2225. {
  2226. conncore.Execute(
  2227. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水2','Token秘钥获取成功',getdate())");
  2228. }
  2229. #endregion
  2230. #region 插入数据
  2231. using (IDbConnection conn = new SqlConnection(_sqlConnection))
  2232. {
  2233. string JylsUrl = ConfigurationManager.AppSettings["JylsUrl"];
  2234. var Historylist = Convert.ToInt64(conn.ExecuteScalar("select isnull(Max(centralNo),0) from MealCardRunTab "));
  2235. string data = "{ \"pageNo\":\"1\",\"PageSize\":\"1000\",\"Date\":\"" + DateTime.Now.ToShortDateString() + "\",\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\"}";
  2236. var responses = HttpMethods.sendHttpPost(JylsUrl, Token, data);
  2237. var RequsetList = JsonConvert.DeserializeObject<JSONList>(responses);
  2238. if (RequsetList.pageTotal > 0)
  2239. {
  2240. for (int i = 1; i <= RequsetList.pageTotal; i++)
  2241. {
  2242. data = "{ \"pageNo\":\"" + i + " \",\"PageSize\":\"1000\",\"Date\":\"" + DateTime.Now.ToShortDateString() + "\",\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\"}";
  2243. var responses1 = HttpMethods.sendHttpPost(JylsUrl, Token, data);
  2244. var RequsetList1 = JsonConvert.DeserializeObject<JSONList>(responses1);
  2245. var NowCen = RequsetList1.data.flowlist.Max(x => x.centralNo);
  2246. if (NowCen > Historylist)
  2247. {
  2248. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2249. {
  2250. conncore.Execute(
  2251. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水3','准备开始插入数据',getdate())");
  2252. }
  2253. for (int j = 0; j < RequsetList1.data.flowlist.Count; j++)
  2254. {
  2255. var nowCen = Convert.ToInt32(conn.ExecuteScalar("select Count(*) from MealCardRunTab where centralNo='" + RequsetList1.data.flowlist[j].centralNo + "' "));
  2256. if (nowCen <= 0)
  2257. {
  2258. conn.Execute(
  2259. "insert into MealCardRunTab(Id,accountNo,accountName,depName,personId,identiName,flowtype,flowamount,balance,cardNo,centralTm,centralNo,occurTime,node,bigGroup,smallGroup,seg,pos) " +
  2260. "values(newid(), '" + RequsetList1.data.flowlist[j].accountNo + "', '" + RequsetList1.data.flowlist[j].accountName + "', '" + RequsetList1.data.flowlist[j].depName + "','" + RequsetList1.data.flowlist[j].personId + "','" + RequsetList1.data.flowlist[j].identiName + "','" + RequsetList1.data.flowlist[j].flowType + "','" + RequsetList1.data.flowlist[j].flowAmount +
  2261. "','" + RequsetList1.data.flowlist[j].balance + "','" + RequsetList1.data.flowlist[j].cardNo + "','" + RequsetList1.data.flowlist[j].centralTm + "','" + RequsetList1.data.flowlist[j].centralNo + "','" + RequsetList1.data.flowlist[j].occurTime + "','" + RequsetList1.data.flowlist[j].node + "','" + RequsetList1.data.flowlist[j].bigGroup + "','" + RequsetList1.data.flowlist[j].group + "','" + RequsetList1.data.flowlist[j].seg + "','" + RequsetList1.data.flowlist[j].pos + "')");
  2262. }
  2263. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2264. {
  2265. conncore.Execute(
  2266. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水4','第" + j + "次插入数据完成',getdate())");
  2267. }
  2268. }
  2269. }
  2270. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2271. {
  2272. conncore.Execute(
  2273. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'一卡通交易流水5','插入数据',getdate())");
  2274. }
  2275. }
  2276. }
  2277. }
  2278. #endregion
  2279. }
  2280. catch (Exception e)
  2281. {
  2282. using (IDbConnection conncore = new SqlConnection(_coresqlConnection))
  2283. {
  2284. conncore.Execute(
  2285. $"insert into LR_Base_Log(F_LogId,F_CategoryId,F_SourceObjectId,F_SourceContentJson,F_OperateTime) values(newid(),55555,'交易流水插入数据失败','" + e + "',getdate())");
  2286. }
  2287. Console.WriteLine(e);
  2288. throw;
  2289. }
  2290. }
  2291. /// <summary>
  2292. /// 长阳登录返回
  2293. /// </summary>
  2294. public class LoginResult
  2295. {
  2296. public int code { get; set; }
  2297. public string token { get; set; }
  2298. }
  2299. public class JSONList
  2300. {
  2301. public int code { get; set; }
  2302. public string msg { get; set; }
  2303. public int total { get; set; }
  2304. public int pageTotal { get; set; }
  2305. public int pageNo { get; set; }
  2306. public int pageSize { get; set; }
  2307. public dataobj data { get; set; }
  2308. }
  2309. public class dataobj
  2310. {
  2311. public List<flowlistobj> flowlist { get; set; }
  2312. }
  2313. public class flowlistobj
  2314. {
  2315. /// <summary>
  2316. /// 中心序号
  2317. /// </summary>
  2318. public int centralNo { get; set; }
  2319. /// <summary>
  2320. /// 中心时间
  2321. /// </summary>
  2322. public DateTime centralTm { get; set; }
  2323. /// <summary>
  2324. /// 发生时间
  2325. /// </summary>
  2326. public DateTime occurTime { get; set; }
  2327. /// <summary>
  2328. /// 节点名称
  2329. /// </summary>
  2330. public string node { get; set; }
  2331. /// <summary>
  2332. /// 学生卡账号
  2333. /// </summary>
  2334. public int accountNo { get; set; }
  2335. /// <summary>
  2336. /// 学生卡名称
  2337. /// </summary>
  2338. public string accountName { get; set; }
  2339. /// <summary>
  2340. /// 身份证号
  2341. /// </summary>
  2342. public string personId { get; set; }
  2343. /// <summary>
  2344. /// 部门名称
  2345. /// </summary>
  2346. public string depName { get; set; }
  2347. /// <summary>
  2348. /// 部门编码
  2349. /// </summary>
  2350. public string deptCode { get; set; }
  2351. /// <summary>
  2352. /// 身份名称
  2353. /// </summary>
  2354. public string identiName { get; set; }
  2355. /// <summary>
  2356. /// 流水类型
  2357. /// </summary>
  2358. public string flowType { get; set; }
  2359. /// <summary>
  2360. /// 余额变化
  2361. /// </summary>
  2362. public string flowAmount { get; set; }
  2363. /// <summary>
  2364. /// 余额
  2365. /// </summary>
  2366. public string balance { get; set; }
  2367. /// <summary>
  2368. /// 卡号
  2369. /// </summary>
  2370. public string cardNo { get; set; }
  2371. /// <summary>
  2372. /// 营业大组名称
  2373. /// </summary>
  2374. public string bigGroup { get; set; }
  2375. /// <summary>
  2376. /// 营业小组名称
  2377. /// </summary>
  2378. public string group { get; set; }
  2379. /// <summary>
  2380. /// 营业餐次
  2381. /// </summary>
  2382. public string seg { get; set; }
  2383. /// <summary>
  2384. /// pos机序号
  2385. /// </summary>
  2386. public string pos { get; set; }
  2387. }
  2388. }
  2389. }