Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

1885 linhas
72 KiB

  1. using Dapper;
  2. using Learun.Application.Base.AuthorizeModule;
  3. using Learun.Application.Base.SystemModule;
  4. using Learun.Application.Organization;
  5. using Learun.Application.TwoDevelopment.LogisticsManagement;
  6. using Learun.DataBase.Repository;
  7. using Learun.Util;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  15. {
  16. /// <summary>
  17. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  18. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  19. /// 创 建:超级管理员
  20. /// 日 期:2019-08-08 17:21
  21. /// 描 述:新生信息管理
  22. /// </summary>
  23. public class StuInfoFreshService : RepositoryFactory
  24. {
  25. #region 构造函数和属性
  26. private string fieldSql;
  27. public StuInfoFreshService()
  28. {
  29. fieldSql = @"
  30. t.ID,
  31. t.NoticeNo,
  32. t.ksh,
  33. t.zkzh,
  34. t.StuNo,
  35. t.StuName,
  36. t.DeptNo,
  37. t.GenderNo,
  38. t.MajorNo,
  39. t.MajorDetailNok,
  40. t.MajorDetailName,
  41. t.Birthday,
  42. t.PartyFaceNo,
  43. t.FamilyOriginNo,
  44. t.NationalityNo,
  45. t.ResidenceNo,
  46. t.TestStuSortNo,
  47. t.HealthStatusNo,
  48. t.WillNo,
  49. t.TestStuSubjectNo,
  50. t.GraduateNo,
  51. t.PlanFormNo,
  52. t.HighTestSortNo,
  53. t.HighAmountScore,
  54. t.PoliticsScore,
  55. t.ChineseScore,
  56. t.MathScore,
  57. t.PhysicsScore,
  58. t.ChemScore,
  59. t.BiologyScore,
  60. t.ForeignLangScore,
  61. t.ForeignLangOralScore,
  62. t.ComprehensiveScore,
  63. t.ForeignLangSpecies,
  64. t.IsThreeGood,
  65. t.IsExcellent,
  66. t.IsNormalCadre,
  67. t.IsProvinceFirstThree,
  68. t.OverseasChineseNo,
  69. t.MatriculateSort,
  70. t.ProvinceNo,
  71. t.HighSchoolNo,
  72. t.RegionNo,
  73. t.Remark,
  74. t.RecruitYearDate,
  75. t.ClassNo,
  76. t.IdentityCardNo,
  77. t.HighSchoolName,
  78. t.GoodAt,
  79. t.ArriveDate,
  80. t.ArchivesNo,
  81. t.telephone,
  82. t.FamilyAddress,
  83. t.RegisterStatus,
  84. t.MailAddress,
  85. t.PostalCode,
  86. t.TransMark,
  87. t.LogIp,
  88. t.LogNum,
  89. t.Logtime,
  90. t.RecruitDeptNo,
  91. t.RecruitMajorNo,
  92. t.RegisterEmpNo,
  93. t.RegisterEmpName,
  94. t.ApprovedLeader,
  95. t.ChangeReason,
  96. t.ChangeDate,
  97. t.TextNo,
  98. t.SignUpTime,
  99. t.OriginAddress,
  100. t.IsAccommodate,
  101. t.HeightWeight,
  102. t.CreateUserId,
  103. t.UpdateUserId,
  104. t.IsPayUniform,
  105. t.IsGetUniform,
  106. t.Grade
  107. ";
  108. }
  109. #endregion
  110. #region 获取数据
  111. /// <summary>
  112. /// 获取列表数据
  113. /// <summary>
  114. /// <returns></returns>
  115. public IEnumerable<StuInfoFreshEntity> GetList(string queryJson)
  116. {
  117. try
  118. {
  119. //参考写法
  120. var queryParam = queryJson.ToJObject();
  121. //虚拟参数
  122. var dp = new DynamicParameters(new { });
  123. var strSql = new StringBuilder();
  124. strSql.Append("SELECT t.*,d.DeptName,m.MajorName,c.ClassName,b.Name as Bed,r.Name as Room,f.Name as floor,u.Name as Unit,build.Name as Build ");
  125. strSql.Append(" FROM StuInfoFresh t ");
  126. strSql.Append(" left join CdDept d on t.DeptNo=d.DeptNo ");
  127. strSql.Append(" left join CdMajor m on t.MajorNo=m.MajorNo ");
  128. strSql.Append(" left join ClassInfo c on t.ClassNo=c.ClassNo ");
  129. strSql.Append(" left join Acc_DormitoryBuild b on t.DormitoryNo=b.ID ");
  130. strSql.Append(" left join Acc_DormitoryBuild r on b.ParentID=r.ID ");
  131. strSql.Append(" left join Acc_DormitoryBuild f on r.ParentID=f.ID ");
  132. strSql.Append(" left join Acc_DormitoryBuild u on f.ParentID=u.ID ");
  133. strSql.Append(" left join Acc_DormitoryBuild build on u.ParentID=build.ID ");
  134. strSql.Append(" where 1=1 ");
  135. if (!queryParam["DeptNo"].IsEmpty())
  136. {
  137. strSql.Append(" and t.DeptNo = @DeptNo ");
  138. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  139. }
  140. if (!queryParam["MajorNo"].IsEmpty())
  141. {
  142. strSql.Append(" and t.MajorNo = @MajorNo ");
  143. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  144. }
  145. if (!queryParam["ClassNo"].IsEmpty())
  146. {
  147. strSql.Append(" and t.ClassNo = @ClassNo ");
  148. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  149. }
  150. if (!queryParam["Grade"].IsEmpty())
  151. {
  152. strSql.Append(" and t.Grade = @Grade ");
  153. dp.Add("Grade", queryParam["Grade"].ToString(), DbType.String);
  154. }
  155. var data = this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>(strSql.ToString(), dp);
  156. return data;
  157. }
  158. catch (Exception ex)
  159. {
  160. if (ex is ExceptionEx)
  161. {
  162. throw;
  163. }
  164. else
  165. {
  166. throw ExceptionEx.ThrowServiceException(ex);
  167. }
  168. }
  169. }
  170. /// <summary>
  171. /// 获取列表数据
  172. /// <summary>
  173. /// <returns></returns>
  174. public IEnumerable<StuInfoFreshEntity> GetList2(string queryJson)
  175. {
  176. try
  177. {
  178. //参考写法
  179. var queryParam = queryJson.ToJObject();
  180. //虚拟参数
  181. var dp = new DynamicParameters(new { });
  182. var strSql = new StringBuilder();
  183. strSql.Append("SELECT t.*,d.DeptName,m.MajorName,c.ClassName ");
  184. strSql.Append(" FROM StuInfoFresh t ");
  185. strSql.Append(" left join CdDept d on t.DeptNo=d.DeptNo ");
  186. strSql.Append(" left join CdMajor m on t.MajorNo=m.MajorNo ");
  187. strSql.Append(" left join ClassInfo c on t.ClassNo=c.ClassNo ");
  188. strSql.Append(" where 1=1 ");
  189. if (!queryParam["DeptNo"].IsEmpty())
  190. {
  191. strSql.Append(" and t.DeptNo = @DeptNo ");
  192. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  193. }
  194. if (!queryParam["MajorNo"].IsEmpty())
  195. {
  196. strSql.Append(" and t.MajorNo = @MajorNo ");
  197. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  198. }
  199. if (!queryParam["ClassNo"].IsEmpty())
  200. {
  201. strSql.Append(" and t.ClassNo = @ClassNo ");
  202. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  203. }
  204. if (!queryParam["Grade"].IsEmpty())
  205. {
  206. strSql.Append(" and t.Grade = @Grade ");
  207. dp.Add("Grade", queryParam["Grade"].ToString(), DbType.String);
  208. }
  209. var data = this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>(strSql.ToString(), dp);
  210. foreach (var item in data)
  211. {
  212. var familyList = this.BaseRepository("CollegeMIS").FindList<StuInfoFreshFamilyEntity>(x => x.StuInfoFreshId == item.ID);
  213. if (familyList.Any())
  214. {
  215. item.IsStudentEdit = true;
  216. }
  217. else
  218. {
  219. item.IsStudentEdit = false;
  220. }
  221. }
  222. return data;
  223. }
  224. catch (Exception ex)
  225. {
  226. if (ex is ExceptionEx)
  227. {
  228. throw;
  229. }
  230. else
  231. {
  232. throw ExceptionEx.ThrowServiceException(ex);
  233. }
  234. }
  235. }
  236. /// <summary>
  237. /// 获取列表分页数据
  238. /// <param name="pagination">分页参数</param>
  239. /// <summary>
  240. /// <returns></returns>
  241. public IEnumerable<StuInfoFreshEntity> GetPageList(Pagination pagination, string queryJson)
  242. {
  243. try
  244. {
  245. var strSql = new StringBuilder();
  246. strSql.Append("SELECT t.*,c.ClassName,c.ClassDiredctorNo,c.ClassTutorNo,b.Name as Bed,r.Name as Room,f.Name as floor,u.Name as Unit,build.Name as Build FROM StuInfoFresh t left join ClassInfo c on t.ClassNo=c.ClassNo ");
  247. strSql.Append(" left join Acc_DormitoryBuild b on t.DormitoryNo=b.ID ");
  248. strSql.Append(" left join Acc_DormitoryBuild r on b.ParentID=r.ID ");
  249. strSql.Append(" left join Acc_DormitoryBuild f on r.ParentID=f.ID ");
  250. strSql.Append(" left join Acc_DormitoryBuild u on f.ParentID=u.ID ");
  251. strSql.Append(" left join Acc_DormitoryBuild build on u.ParentID=build.ID ");
  252. strSql.Append(" where 1=1 ");
  253. var queryParam = queryJson.ToJObject();
  254. var dp = new DynamicParameters(new { });
  255. if (!queryParam["keyword"].IsEmpty())
  256. {
  257. strSql.Append(" and (t.ksh like @keyword or t.zkzh like @keyword or t.StuName like @keyword or t.IdentityCardNo like @keyword )");
  258. dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
  259. }
  260. if (!queryParam["StuNo"].IsEmpty())
  261. {
  262. strSql.Append(" and t.StuNo = @StuNo ");
  263. dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
  264. }
  265. if (!queryParam["StuName"].IsEmpty())
  266. {
  267. strSql.Append(" and t.StuName like @StuName ");
  268. dp.Add("StuName", '%' + queryParam["StuName"].ToString() + '%', DbType.String);
  269. }
  270. if (!queryParam["Grade"].IsEmpty())
  271. {
  272. strSql.Append(" and t.Grade like @Grade ");
  273. dp.Add("Grade", '%' + queryParam["Grade"].ToString() + '%', DbType.String);
  274. }
  275. //分配班级
  276. if (!queryParam["DeptNo"].IsEmpty())
  277. {
  278. strSql.Append(" and t.DeptNo = @DeptNo ");
  279. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  280. }
  281. if (!queryParam["MajorNo"].IsEmpty())
  282. {
  283. strSql.Append(" and t.MajorNo = @MajorNo ");
  284. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  285. }
  286. if (!queryParam["EducationalSystem"].IsEmpty())
  287. {
  288. strSql.Append(" and t.EducationalSystem = @EducationalSystem ");
  289. dp.Add("EducationalSystem", queryParam["EducationalSystem"].ToString(), DbType.String);
  290. }
  291. if (!queryParam["IDCard"].IsEmpty())
  292. {
  293. strSql.Append(" and t.IdentityCardNo like @IDCard ");
  294. dp.Add("IDCard", '%' + queryParam["IDCard"].ToString() + '%', DbType.String);
  295. }
  296. if (!queryParam["IsAllocation"].IsEmpty())
  297. {
  298. var IsAllocation = Convert.ToBoolean(queryParam["IsAllocation"].ToString());
  299. if (IsAllocation)//未分配
  300. {
  301. strSql.Append(" AND (t.ClassNo IS NULL OR t.ClassNo='') ");
  302. }
  303. else
  304. {
  305. strSql.Append(" AND (t.ClassNo IS NOT NULL AND t.ClassNo<>'') ");
  306. }
  307. }
  308. //分配床位
  309. if (!queryParam["ClassNo"].IsEmpty())
  310. {
  311. strSql.Append(" and t.ClassNo = @ClassNo ");
  312. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  313. }
  314. //完善信息
  315. if (!queryParam["PerfectStatus"].IsEmpty())
  316. {
  317. if (queryParam["PerfectStatus"].ToString() == "1")
  318. {
  319. strSql.Append(" AND t.ID in (select StuInfoFreshId from StuInfoFreshFamily) ");
  320. }
  321. else
  322. {
  323. strSql.Append(" AND t.ID not in (select StuInfoFreshId from StuInfoFreshFamily) ");
  324. }
  325. }
  326. //报到状态
  327. if (!queryParam["RegisterStatus"].IsEmpty())
  328. {
  329. if (queryParam["RegisterStatus"].ToString() == "1")
  330. {
  331. strSql.Append(" AND t.RegisterStatus = @RegisterStatus ");
  332. }
  333. else
  334. {
  335. strSql.Append(" AND (t.RegisterStatus <> 1 or t.RegisterStatus is null)");
  336. }
  337. dp.Add("RegisterStatus", queryParam["RegisterStatus"].ToString(), DbType.String);
  338. }
  339. //缴费状态
  340. if (!queryParam["PayStatus"].IsEmpty())
  341. {
  342. if (queryParam["PayStatus"].ToString() == "1")
  343. {
  344. strSql.Append(" AND t.PayFeeStatus = @PayFeeStatus ");
  345. }
  346. else
  347. {
  348. strSql.Append(" AND (t.PayFeeStatus <> 1 or t.PayFeeStatus is null)");
  349. }
  350. dp.Add("PayFeeStatus", queryParam["PayStatus"].ToString(), DbType.String);
  351. }
  352. //领取状态
  353. if (!queryParam["GetKeyStatus"].IsEmpty())
  354. {
  355. if (queryParam["GetKeyStatus"].ToString() == "1")
  356. {
  357. strSql.Append(" AND t.GetKeyStatus = @GetKeyStatus ");
  358. }
  359. else
  360. {
  361. strSql.Append(" AND (t.GetKeyStatus <> 1 or t.GetKeyStatus is null)");
  362. }
  363. dp.Add("GetKeyStatus", queryParam["GetKeyStatus"].ToString(), DbType.String);
  364. }
  365. if (!queryParam["Gender"].IsEmpty())
  366. {
  367. if (queryParam["Gender"].ToString() == "1")
  368. {
  369. strSql.Append(" AND t.GenderNo = @Gender ");
  370. }
  371. else
  372. {
  373. strSql.Append(" AND t.GenderNo <> 1 ");
  374. }
  375. dp.Add("Gender", queryParam["Gender"].ToString(), DbType.String);
  376. }
  377. if (!queryParam["IsAllocationDormitory"].IsEmpty())
  378. {
  379. var IsAllocation = Convert.ToBoolean(queryParam["IsAllocationDormitory"].ToString());
  380. if (IsAllocation)
  381. {
  382. strSql.Append(" AND (t.DormitoryNo IS NULL OR t.DormitoryNo='')");
  383. }
  384. else
  385. {
  386. strSql.Append(" AND (t.DormitoryNo IS NOT NULL AND t.DormitoryNo<>'')");
  387. }
  388. }
  389. //班主任/辅导员
  390. if (!queryParam["EmpNo"].IsEmpty())
  391. {
  392. strSql.Append(" and (c.ClassDiredctorNo = @EmpNo or c.ClassTutorNo = @EmpNo) ");
  393. dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
  394. }
  395. return this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>(strSql.ToString(), dp, pagination);
  396. }
  397. catch (Exception ex)
  398. {
  399. if (ex is ExceptionEx)
  400. {
  401. throw;
  402. }
  403. else
  404. {
  405. throw ExceptionEx.ThrowServiceException(ex);
  406. }
  407. }
  408. }
  409. /// <summary>
  410. /// 获取StuInfoFreshFamily表数据
  411. /// <summary>
  412. /// <returns></returns>
  413. public IEnumerable<StuInfoFreshFamilyEntity> GetStuInfoFreshFamilyList(string keyValue)
  414. {
  415. try
  416. {
  417. return this.BaseRepository("CollegeMIS").FindList<StuInfoFreshFamilyEntity>(t => t.StuInfoFreshId == keyValue);
  418. }
  419. catch (Exception ex)
  420. {
  421. if (ex is ExceptionEx)
  422. {
  423. throw;
  424. }
  425. else
  426. {
  427. throw ExceptionEx.ThrowServiceException(ex);
  428. }
  429. }
  430. }
  431. /// <summary>
  432. /// 获取StuInfoFreshEmergePeople表数据
  433. /// <summary>
  434. /// <returns></returns>
  435. public IEnumerable<StuInfoFreshEmergePeopleEntity> GetStuInfoFreshEmergePeopleList(string keyValue)
  436. {
  437. try
  438. {
  439. return this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEmergePeopleEntity>(t => t.StuInfoFreshId == keyValue);
  440. }
  441. catch (Exception ex)
  442. {
  443. if (ex is ExceptionEx)
  444. {
  445. throw;
  446. }
  447. else
  448. {
  449. throw ExceptionEx.ThrowServiceException(ex);
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 获取StuInfoFresh表实体数据
  455. /// <param name="keyValue">主键</param>
  456. /// <summary>
  457. /// <returns></returns>
  458. public StuInfoFreshEntity GetStuInfoFreshEntity(string keyValue)
  459. {
  460. try
  461. {
  462. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshEntity>(keyValue);
  463. }
  464. catch (Exception ex)
  465. {
  466. if (ex is ExceptionEx)
  467. {
  468. throw;
  469. }
  470. else
  471. {
  472. throw ExceptionEx.ThrowServiceException(ex);
  473. }
  474. }
  475. }
  476. /// <summary>
  477. /// 获取StuInfoFresh表实体数据
  478. /// <param name="keyValue">主键</param>
  479. /// <summary>
  480. /// <returns></returns>
  481. public StuInfoFreshEntity GetStuInfoFreshEntityByStuNo(string stuNo)
  482. {
  483. try
  484. {
  485. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshEntity>(x => x.StuNo == stuNo);
  486. }
  487. catch (Exception ex)
  488. {
  489. if (ex is ExceptionEx)
  490. {
  491. throw;
  492. }
  493. else
  494. {
  495. throw ExceptionEx.ThrowServiceException(ex);
  496. }
  497. }
  498. }
  499. /// <summary>
  500. /// 获取StuInfoFreshEmergePeople表实体数据
  501. /// <param name="keyValue">主键</param>
  502. /// <summary>
  503. /// <returns></returns>
  504. public StuInfoFreshEmergePeopleEntity GetStuInfoFreshEmergePeopleEntity(string keyValue)
  505. {
  506. try
  507. {
  508. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshEmergePeopleEntity>(t => t.StuInfoFreshId == keyValue);
  509. }
  510. catch (Exception ex)
  511. {
  512. if (ex is ExceptionEx)
  513. {
  514. throw;
  515. }
  516. else
  517. {
  518. throw ExceptionEx.ThrowServiceException(ex);
  519. }
  520. }
  521. }
  522. /// <summary>
  523. /// 获取StuInfoFreshFamily表实体数据
  524. /// <param name="keyValue">主键</param>
  525. /// <summary>
  526. /// <returns></returns>
  527. public StuInfoFreshFamilyEntity GetStuInfoFreshFamilyEntity(string keyValue)
  528. {
  529. try
  530. {
  531. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshFamilyEntity>(t => t.StuInfoFreshId == keyValue);
  532. }
  533. catch (Exception ex)
  534. {
  535. if (ex is ExceptionEx)
  536. {
  537. throw;
  538. }
  539. else
  540. {
  541. throw ExceptionEx.ThrowServiceException(ex);
  542. }
  543. }
  544. }
  545. /// <summary>
  546. /// 获取列表分页数据
  547. /// <param name="pagination">分页参数</param>
  548. /// <summary>
  549. /// <returns></returns>
  550. public IEnumerable<StuInfoFreshEntity> GetStuInfoFreshListByClassNo(string classNo)
  551. {
  552. try
  553. {
  554. var strSql = new StringBuilder();
  555. strSql.Append("SELECT t.* FROM StuInfoFresh t where 1=1 and t.ClassNo='" + classNo + "' ");
  556. return this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>(strSql.ToString());
  557. }
  558. catch (Exception ex)
  559. {
  560. if (ex is ExceptionEx)
  561. {
  562. throw;
  563. }
  564. else
  565. {
  566. throw ExceptionEx.ThrowServiceException(ex);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 获取列表分页数据
  572. /// <param name="pagination">分页参数</param>
  573. /// <summary>
  574. /// <returns></returns>
  575. public StuInfoFreshEntity Getksh(string ksh)
  576. {
  577. try
  578. {
  579. return this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshEntity>(x => x.ksh == ksh);
  580. }
  581. catch (Exception ex)
  582. {
  583. if (ex is ExceptionEx)
  584. {
  585. throw;
  586. }
  587. else
  588. {
  589. throw ExceptionEx.ThrowServiceException(ex);
  590. }
  591. }
  592. }
  593. /// <summary>
  594. /// 获取分配宿舍列表
  595. /// </summary>
  596. /// <param name="pagination"></param>
  597. /// <param name="queryJson"></param>
  598. /// <returns></returns>
  599. public IEnumerable<Acc_DormitoryBuildEntity> GetDormitorys(Pagination pagination, string queryJson)
  600. {
  601. try
  602. {
  603. var strSql = new StringBuilder();
  604. strSql.Append("SELECT t.* FROM Acc_DormitoryBuild t ");
  605. strSql.Append(" WHERE 1=1 ");
  606. var queryParam = queryJson.ToJObject();
  607. // 虚拟参数
  608. var dp = new DynamicParameters(new { });
  609. if (!queryParam["BuildType"].IsEmpty())
  610. {
  611. dp.Add("BuildType", queryParam["BuildType"].ToString(), DbType.String);
  612. strSql.Append(" AND t.BuildType =@BuildType ");
  613. }
  614. if (!queryParam["ParentID"].IsEmpty())
  615. {
  616. dp.Add("ParentID", queryParam["ParentID"].ToString(), DbType.String);
  617. strSql.Append(" AND t.ParentID =@ParentID ");
  618. }
  619. if (!queryParam["Sex"].IsEmpty())
  620. {
  621. dp.Add("Sex", queryParam["Sex"].ToString(), DbType.String);
  622. strSql.Append(" AND t.Sex = @Sex ");
  623. }
  624. //if (!queryParam["IsAllocationDormitory"].IsEmpty())
  625. //{
  626. // if (queryParam["IsAllocationDormitory"].ToString() == "false")
  627. // {
  628. // strSql.Append(" AND t.PlanClassNo is not null ");
  629. // }
  630. // else
  631. // {
  632. // strSql.Append(" AND t.PlanClassNo is null ");
  633. // }
  634. //}
  635. if (!queryParam["PlanClassNo"].IsEmpty())
  636. {
  637. //dp.Add("PlanClassNo", queryParam["PlanClassNo"].ToString(), DbType.String);
  638. //strSql.Append(" AND t.PlanClassNo =@PlanClassNo ");
  639. dp.Add("PlanClassNo", "%" + queryParam["PlanClassNo"].ToString() + "%", DbType.String);
  640. strSql.Append(" AND t.PlanClassNo like @PlanClassNo ");
  641. }
  642. var data = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(strSql.ToString(), dp, pagination).OrderBy(a => a.Name).ToList();
  643. foreach (var item in data)
  644. {
  645. //总床位
  646. item.ChildCount = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(a => a.ParentID == item.ID).Count();
  647. //可分配床位=总床位-预分床位
  648. int remainBedNum = item.ChildCount - (item.PlanBedNum.HasValue ? item.PlanBedNum.Value : 0);
  649. item.PlanBedNum = remainBedNum;
  650. item.RemainBedNum = remainBedNum;
  651. }
  652. if (!queryParam["IsAllocationDormitory"].IsEmpty())
  653. {
  654. if (queryParam["IsAllocationDormitory"].ToString() == "false")//不可分配
  655. {
  656. data = data.Where(x => x.RemainBedNum == 0).ToList();
  657. }
  658. else//可分配
  659. {
  660. data = data.Where(x => x.RemainBedNum > 0).ToList();
  661. }
  662. }
  663. return data;
  664. }
  665. catch (Exception ex)
  666. {
  667. if (ex is ExceptionEx)
  668. {
  669. throw;
  670. }
  671. else
  672. {
  673. throw ExceptionEx.ThrowServiceException(ex);
  674. }
  675. }
  676. }
  677. /// <summary>
  678. /// 获取分配宿舍列表
  679. /// </summary>
  680. /// <param name="pagination"></param>
  681. /// <param name="queryJson"></param>
  682. /// <returns></returns>
  683. public IEnumerable<Acc_DormitoryBuildEntity> GetDormitorys2(Pagination pagination, string queryJson)
  684. {
  685. try
  686. {
  687. var strSql = new StringBuilder();
  688. strSql.Append("SELECT t.* FROM Acc_DormitoryBuild t ");
  689. strSql.Append(" WHERE 1=1 ");
  690. var queryParam = queryJson.ToJObject();
  691. // 虚拟参数
  692. var dp = new DynamicParameters(new { });
  693. if (!queryParam["BuildType"].IsEmpty())
  694. {
  695. dp.Add("BuildType", queryParam["BuildType"].ToString(), DbType.String);
  696. strSql.Append(" AND t.BuildType =@BuildType ");
  697. }
  698. if (!queryParam["PlanClassNo"].IsEmpty())
  699. {
  700. dp.Add("PlanClassNo", "%" + queryParam["PlanClassNo"].ToString() + "%", DbType.String);
  701. strSql.Append(" AND t.PlanClassNo like @PlanClassNo ");
  702. }
  703. var data = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(strSql.ToString(), dp, pagination).OrderBy(a => a.Name).ToList();
  704. foreach (var item in data)
  705. {
  706. var bedList = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(a => a.ParentID == item.ID);
  707. //总床位
  708. item.ChildCount = bedList.Count();
  709. //已分配床位
  710. item.UseBedNum = bedList.Where(x => x.PlanClassNo == queryParam["PlanClassNo"].ToString()).Count();
  711. item.CancelUseBedNum = item.UseBedNum;
  712. }
  713. return data;
  714. }
  715. catch (Exception ex)
  716. {
  717. if (ex is ExceptionEx)
  718. {
  719. throw;
  720. }
  721. else
  722. {
  723. throw ExceptionEx.ThrowServiceException(ex);
  724. }
  725. }
  726. }
  727. /// <summary>
  728. /// 获取分配宿舍树
  729. /// </summary>
  730. /// <returns></returns>
  731. internal List<Tuple<int, int, string, string>> GetTree()
  732. {
  733. try
  734. {
  735. var data = this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>(a => !string.IsNullOrEmpty(a.ClassNo)).ToList();
  736. var classInfos = this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>().ToList();
  737. var classes = data.GroupBy(a => a.ClassNo).Select(a => a.Key).ToList();
  738. List<Tuple<int, int, string, string>> list = new List<Tuple<int, int, string, string>>();
  739. foreach (var classNo in classes)
  740. {
  741. var boy = data.Count(a => a.ClassNo == classNo && a.GenderNo == "1");
  742. var girl = data.Count(a => a.ClassNo == classNo && a.GenderNo != "1");
  743. var className = classInfos.FirstOrDefault(a => a.ClassNo == classNo)?.ClassName;
  744. Tuple<int, int, string, string> tuple = new Tuple<int, int, string, string>(boy, girl, classNo, className);
  745. list.Add(tuple);
  746. }
  747. return list;
  748. }
  749. catch (Exception ex)
  750. {
  751. if (ex is ExceptionEx)
  752. {
  753. throw;
  754. }
  755. else
  756. {
  757. throw ExceptionEx.ThrowServiceException(ex);
  758. }
  759. }
  760. }
  761. /// <summary>
  762. /// 获取分配床位树
  763. /// </summary>
  764. /// <param name="classNo"></param>
  765. /// <param name="gender"></param>
  766. /// <returns></returns>
  767. internal List<Acc_DormitoryBuildEntity> GetBedTree(string classNo, string gender)
  768. {
  769. try
  770. {
  771. List<Acc_DormitoryBuildEntity> list = new List<Acc_DormitoryBuildEntity>();
  772. var data = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(a => a.PlanClassNo.Contains(classNo) && a.Sex == gender && a.BuildType == "4").ToList();
  773. var bb = this.BaseRepository("CollegeMIS").FindList<StuInfoFreshEntity>().ToList();
  774. foreach (var item in data)
  775. {
  776. list.Add(item);
  777. var beds = this.BaseRepository("CollegeMIS").FindList<Acc_DormitoryBuildEntity>(a => a.ParentID == item.ID && a.PlanClassNo == classNo).ToList();
  778. foreach (var bed in beds)
  779. {
  780. var stuName = bb.FirstOrDefault(a => a.DormitoryNo == bed.ID)?.StuName;
  781. if (!string.IsNullOrEmpty(stuName))
  782. {
  783. bed.Name = $"{bed.Name}({stuName})";
  784. }
  785. list.Add(bed);
  786. }
  787. }
  788. return list;
  789. }
  790. catch (Exception ex)
  791. {
  792. if (ex is ExceptionEx)
  793. {
  794. throw;
  795. }
  796. else
  797. {
  798. throw ExceptionEx.ThrowServiceException(ex);
  799. }
  800. }
  801. }
  802. #endregion
  803. #region 提交数据
  804. /// <summary>
  805. /// 删除实体数据
  806. /// <param name="keyValue">主键</param>
  807. /// <summary>
  808. /// <returns></returns>
  809. public void DeleteEntity(string keyValue)
  810. {
  811. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  812. try
  813. {
  814. var stuInfoFreshEntity = GetStuInfoFreshEntity(keyValue);
  815. db.Delete<StuInfoFreshEntity>(t => t.ID == keyValue);
  816. db.Delete<StuInfoFreshEmergePeopleEntity>(t => t.StuInfoFreshId == stuInfoFreshEntity.ID);
  817. db.Delete<StuInfoFreshFamilyEntity>(t => t.StuInfoFreshId == stuInfoFreshEntity.ID);
  818. db.Commit();
  819. }
  820. catch (Exception ex)
  821. {
  822. db.Rollback();
  823. if (ex is ExceptionEx)
  824. {
  825. throw;
  826. }
  827. else
  828. {
  829. throw ExceptionEx.ThrowServiceException(ex);
  830. }
  831. }
  832. }
  833. /// <summary>
  834. /// 保存实体数据(新增、修改)
  835. /// <param name="keyValue">主键</param>
  836. /// <summary>
  837. /// <returns></returns>
  838. public void SaveEntity(string keyValue, StuInfoFreshEntity entity, List<StuInfoFreshEmergePeopleEntity> stuInfoFreshEmergePeopleList, List<StuInfoFreshFamilyEntity> stuInfoFreshFamilyList)
  839. {
  840. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  841. try
  842. {
  843. if (!string.IsNullOrEmpty(keyValue))
  844. {
  845. var stuInfoFreshEntityTmp = GetStuInfoFreshEntity(keyValue);
  846. entity.Modify(keyValue);
  847. db.Update(entity);
  848. db.Delete<StuInfoFreshEmergePeopleEntity>(t => t.StuInfoFreshId == stuInfoFreshEntityTmp.ID);
  849. if (null != stuInfoFreshEmergePeopleList && null != stuInfoFreshFamilyList)
  850. {
  851. foreach (StuInfoFreshEmergePeopleEntity item in stuInfoFreshEmergePeopleList)
  852. {
  853. item.Create();
  854. item.StuInfoFreshId = stuInfoFreshEntityTmp.ID;
  855. db.Insert(item);
  856. }
  857. db.Delete<StuInfoFreshFamilyEntity>(t => t.StuInfoFreshId == stuInfoFreshEntityTmp.ID);
  858. foreach (StuInfoFreshFamilyEntity item in stuInfoFreshFamilyList)
  859. {
  860. item.Create();
  861. item.StuInfoFreshId = stuInfoFreshEntityTmp.ID;
  862. db.Insert(item);
  863. }
  864. }
  865. }
  866. else
  867. {
  868. entity.Create();
  869. db.Insert(entity);
  870. if (null != stuInfoFreshEmergePeopleList && null != stuInfoFreshFamilyList)
  871. {
  872. foreach (StuInfoFreshEmergePeopleEntity item in stuInfoFreshEmergePeopleList)
  873. {
  874. item.Create();
  875. item.StuInfoFreshId = entity.ID;
  876. db.Insert(item);
  877. }
  878. foreach (StuInfoFreshFamilyEntity item in stuInfoFreshFamilyList)
  879. {
  880. item.Create();
  881. item.StuInfoFreshId = entity.ID;
  882. db.Insert(item);
  883. }
  884. }
  885. }
  886. db.Commit();
  887. }
  888. catch (Exception ex)
  889. {
  890. db.Rollback();
  891. if (ex is ExceptionEx)
  892. {
  893. throw;
  894. }
  895. else
  896. {
  897. throw ExceptionEx.ThrowServiceException(ex);
  898. }
  899. }
  900. }
  901. /// <summary>
  902. /// 保存实体数据(新增、修改)
  903. /// <param name="keyValue">主键</param>
  904. /// <summary>
  905. /// <returns></returns>
  906. public void SaveEntity(string keyValue, StuInfoFreshEntity entity)
  907. {
  908. try
  909. {
  910. if (!string.IsNullOrEmpty(keyValue))
  911. {
  912. entity.Modify(keyValue);
  913. this.BaseRepository("CollegeMIS").Update(entity);
  914. }
  915. else
  916. {
  917. entity.Create();
  918. this.BaseRepository("CollegeMIS").Insert(entity);
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. if (ex is ExceptionEx)
  924. {
  925. throw;
  926. }
  927. else
  928. {
  929. throw ExceptionEx.ThrowServiceException(ex);
  930. }
  931. }
  932. }
  933. #endregion
  934. #region 扩展数据
  935. /// <summary>
  936. /// 确认报到、取消报到
  937. /// <param name="keyValue">主键</param>
  938. /// <summary>
  939. /// <returns></returns>
  940. public void IsRegister(string keyValue, string status)
  941. {
  942. try
  943. {
  944. if (status == "1")//报到
  945. {
  946. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set RegisterStatus='1',ArriveDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  947. }
  948. else
  949. {
  950. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set RegisterStatus='0',ArriveDate=null where ID='" + keyValue + "' ");
  951. }
  952. }
  953. catch (Exception ex)
  954. {
  955. if (ex is ExceptionEx)
  956. {
  957. throw;
  958. }
  959. else
  960. {
  961. throw ExceptionEx.ThrowServiceException(ex);
  962. }
  963. }
  964. }
  965. /// <summary>
  966. /// 收取学生档案
  967. /// <param name="keyValue">主键</param>
  968. /// <summary>
  969. /// <returns></returns>
  970. public void IsCollectFile(string keyValue, string status)
  971. {
  972. try
  973. {
  974. if (status == "1")//收取
  975. {
  976. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set CollectFileStatus='1',CollectFileDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  977. }
  978. else
  979. {
  980. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set CollectFileStatus='0',CollectFileDate=null where ID='" + keyValue + "' ");
  981. }
  982. }
  983. catch (Exception ex)
  984. {
  985. if (ex is ExceptionEx)
  986. {
  987. throw;
  988. }
  989. else
  990. {
  991. throw ExceptionEx.ThrowServiceException(ex);
  992. }
  993. }
  994. }
  995. /// <summary>
  996. /// 领取钥匙
  997. /// <param name="keyValue">主键</param>
  998. /// <summary>
  999. /// <returns></returns>
  1000. public void IsGetKey(string keyValue, string status)
  1001. {
  1002. try
  1003. {
  1004. if (status == "1")//领取
  1005. {
  1006. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set GetKeyStatus='1',GetKeyDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  1007. }
  1008. else
  1009. {
  1010. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set GetKeyStatus='0',GetKeyDate=null where ID='" + keyValue + "' ");
  1011. }
  1012. }
  1013. catch (Exception ex)
  1014. {
  1015. if (ex is ExceptionEx)
  1016. {
  1017. throw;
  1018. }
  1019. else
  1020. {
  1021. throw ExceptionEx.ThrowServiceException(ex);
  1022. }
  1023. }
  1024. }
  1025. /// <summary>
  1026. /// 领取校园卡
  1027. /// <param name="keyValue">主键</param>
  1028. /// <summary>
  1029. /// <returns></returns>
  1030. public void IsGetCard(string keyValue, string status)
  1031. {
  1032. try
  1033. {
  1034. if (status == "1")//领取
  1035. {
  1036. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set GetCardStatus='1',GetCardDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  1037. }
  1038. else
  1039. {
  1040. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set GetCardStatus='0',GetCardDate=null where ID='" + keyValue + "' ");
  1041. }
  1042. }
  1043. catch (Exception ex)
  1044. {
  1045. if (ex is ExceptionEx)
  1046. {
  1047. throw;
  1048. }
  1049. else
  1050. {
  1051. throw ExceptionEx.ThrowServiceException(ex);
  1052. }
  1053. }
  1054. }
  1055. /// <summary>
  1056. /// 缴费
  1057. /// <param name="keyValue">主键</param>
  1058. /// <summary>
  1059. /// <returns></returns>
  1060. public void IsPayFee(string keyValue, string status)
  1061. {
  1062. try
  1063. {
  1064. if (status == "1")//缴费
  1065. {
  1066. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set PayFeeStatus='1',PayFeeDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  1067. }
  1068. else
  1069. {
  1070. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set PayFeeStatus='0',PayFeeDate=null where ID='" + keyValue + "' ");
  1071. }
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. if (ex is ExceptionEx)
  1076. {
  1077. throw;
  1078. }
  1079. else
  1080. {
  1081. throw ExceptionEx.ThrowServiceException(ex);
  1082. }
  1083. }
  1084. }
  1085. /// <summary>
  1086. /// 其他费用缴费
  1087. /// <param name="keyValue">主键</param>
  1088. /// <summary>
  1089. /// <returns></returns>
  1090. public void IsOtherPayFee(string keyValue, string status)
  1091. {
  1092. try
  1093. {
  1094. if (status == "1")//缴费
  1095. {
  1096. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set OtherPayFeeStatus='1',OtherPayFeeDate='" + DateTime.Now + "' where ID='" + keyValue + "' ");
  1097. }
  1098. else
  1099. {
  1100. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set OtherPayFeeStatus='0',OtherPayFeeDate=null where ID='" + keyValue + "' ");
  1101. }
  1102. }
  1103. catch (Exception ex)
  1104. {
  1105. if (ex is ExceptionEx)
  1106. {
  1107. throw;
  1108. }
  1109. else
  1110. {
  1111. throw ExceptionEx.ThrowServiceException(ex);
  1112. }
  1113. }
  1114. }
  1115. /// <summary>
  1116. /// 审核助学贷款
  1117. /// <param name="keyValue">主键</param>
  1118. /// <summary>
  1119. /// <returns></returns>
  1120. public void DoCheckLoan(string keyValue, string status)
  1121. {
  1122. try
  1123. {
  1124. if (status == "1")//通过
  1125. {
  1126. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set StudentLoanStatus='1' where ID='" + keyValue + "' ");
  1127. }
  1128. else
  1129. {
  1130. this.BaseRepository("CollegeMIS").ExecuteBySql("update StuInfoFresh set StudentLoanStatus='0' where ID='" + keyValue + "' ");
  1131. }
  1132. }
  1133. catch (Exception ex)
  1134. {
  1135. if (ex is ExceptionEx)
  1136. {
  1137. throw;
  1138. }
  1139. else
  1140. {
  1141. throw ExceptionEx.ThrowServiceException(ex);
  1142. }
  1143. }
  1144. }
  1145. /// <summary>
  1146. /// 分配班级
  1147. /// <param name="keyValue">主键</param>
  1148. /// <summary>
  1149. /// <returns></returns>
  1150. public void DoAllocationClass(List<StuInfoFreshEntity> stuInfoFreshEntities)
  1151. {
  1152. UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  1153. UserIBLL userIBLL = new UserBLL();
  1154. var defaultpwd = Config.GetValue("defaultpwd");
  1155. //读取默认密码配置中已启用的密码
  1156. var Sys_DefaultPwdConfigEntity = this.BaseRepository().FindEntity<Sys_DefaultPwdConfigEntity>(x => x.IsEnabled == true);
  1157. if (Sys_DefaultPwdConfigEntity != null)
  1158. {
  1159. defaultpwd = Sys_DefaultPwdConfigEntity.Pwd;
  1160. }
  1161. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1162. try
  1163. {
  1164. foreach (var entity in stuInfoFreshEntities)
  1165. {
  1166. //新生信息
  1167. entity.Modify(entity.ID);
  1168. db.Update(entity);
  1169. //自动生成学生账号默认为学生角色,方便登录移动端
  1170. //判断User是否存在
  1171. var userModel = userIBLL.GetEntityByAccount(entity.StuNo);
  1172. if (userModel == null)
  1173. {
  1174. //User
  1175. var annexesFileEntity = this.BaseRepository().FindEntity<AnnexesFileEntity>(a => a.F_Id == entity.Photo);
  1176. var url = "";
  1177. if (annexesFileEntity != null)
  1178. {
  1179. url = annexesFileEntity.F_FilePath;
  1180. url = "/" + url.Substring(url.IndexOf("Resource"));
  1181. }
  1182. var userEntity = new UserEntity()
  1183. {
  1184. F_Account = entity.StuNo,
  1185. F_RealName = entity.StuName,
  1186. F_EnCode = entity.StuNo,
  1187. F_Password = Md5Helper.Encrypt(defaultpwd, 32).ToLower(),
  1188. F_HeadIcon = string.IsNullOrEmpty(url) ? Config.GetValue("defaultheadimg") : url,
  1189. F_Gender = entity.GenderNo == "1" ? 1 : 0,
  1190. F_DeleteMark = 0,
  1191. F_EnabledMark = 1,
  1192. F_Mobile = entity.telephone,
  1193. F_Description = "学生",
  1194. F_CompanyId = this.BaseRepository("CollegeMIS").FindEntity<CdMajorEntity>(x => x.MajorNo == entity.MajorNo)?.F_SchoolId,
  1195. F_DepartmentId = entity.DeptNo
  1196. };
  1197. userIBLL.SaveEntity(null, userEntity);
  1198. //UserRelation
  1199. var roleId = Config.GetValue("GenerateStudentsRoleId");
  1200. //判断User是否添加成功
  1201. var user = userIBLL.GetEntityByAccount(entity.StuNo);
  1202. if (user != null)
  1203. {
  1204. var userRelationEntity = new UserRelationEntity();
  1205. userRelationEntity.Create();
  1206. userRelationEntity.F_UserId = user.F_UserId;
  1207. userRelationEntity.F_Category = 1;
  1208. userRelationEntity.F_ObjectId = roleId;
  1209. this.BaseRepository().Insert(userRelationEntity);
  1210. }
  1211. }
  1212. }
  1213. db.Commit();
  1214. }
  1215. catch (Exception ex)
  1216. {
  1217. db.Rollback();
  1218. if (ex is ExceptionEx)
  1219. {
  1220. throw;
  1221. }
  1222. else
  1223. {
  1224. throw ExceptionEx.ThrowServiceException(ex);
  1225. }
  1226. }
  1227. }
  1228. /// <summary>
  1229. /// 分配宿舍
  1230. /// <param name="keyValue">主键</param>
  1231. /// <summary>
  1232. /// <returns></returns>
  1233. public void DoAllocationDormitory(List<Acc_DormitoryBuildEntity> acc_DormitoryBuildEntities)
  1234. {
  1235. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1236. try
  1237. {
  1238. foreach (var entity in acc_DormitoryBuildEntities)
  1239. {
  1240. //修改房间:预分床位数量增加;预分班级判断是否需要增加;
  1241. var model = db.FindEntity<Acc_DormitoryBuildEntity>(entity.ID);
  1242. model.PlanBedNum = (model.PlanBedNum.HasValue ? model.PlanBedNum.Value : 0) + entity.PlanBedNum;
  1243. if (!string.IsNullOrEmpty(model.PlanClassNo) && model.PlanClassNo.Contains(entity.PlanClassNo))
  1244. {
  1245. }
  1246. else
  1247. {
  1248. model.PlanClassNo = model.PlanClassNo + entity.PlanClassNo + ',';
  1249. }
  1250. db.Update(model);
  1251. //修改房间下的床位:预分班级增加;
  1252. var redList = db.FindList<Acc_DormitoryBuildEntity>(x => x.ParentID == entity.ID && string.IsNullOrEmpty(x.PlanClassNo)).OrderBy(x => x.Name).ToList();
  1253. foreach (var redItem in redList)
  1254. {
  1255. var index = redList.IndexOf(redItem);
  1256. if (index == entity.PlanBedNum)
  1257. {
  1258. break;
  1259. }
  1260. redItem.PlanClassNo = entity.PlanClassNo;
  1261. db.Update(redItem);
  1262. }
  1263. }
  1264. db.Commit();
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. db.Rollback();
  1269. if (ex is ExceptionEx)
  1270. {
  1271. throw;
  1272. }
  1273. else
  1274. {
  1275. throw ExceptionEx.ThrowServiceException(ex);
  1276. }
  1277. }
  1278. }
  1279. /// <summary>
  1280. /// 导入宿舍
  1281. /// <param name="keyValue">主键</param>
  1282. /// <summary>
  1283. /// <returns></returns>
  1284. public void ImportDormitory(List<Acc_DormitoryBuildEntity> acc_DormitoryBuildEntities)
  1285. {
  1286. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1287. try
  1288. {
  1289. foreach (var entity in acc_DormitoryBuildEntities)
  1290. {
  1291. //修改房间:预分床位数量增加;预分班级判断是否需要增加;
  1292. var model = db.FindEntity<Acc_DormitoryBuildEntity>(entity.ID);
  1293. model.PlanBedNum = (model.PlanBedNum.HasValue ? model.PlanBedNum.Value : 0) + entity.PlanBedNum;
  1294. if (!string.IsNullOrEmpty(model.PlanClassNo) && model.PlanClassNo.Contains(entity.PlanClassNo))
  1295. {
  1296. }
  1297. else
  1298. {
  1299. model.PlanClassNo = model.PlanClassNo + entity.PlanClassNo + ',';
  1300. }
  1301. db.Update(model);
  1302. //修改房间下的床位:预分班级增加;
  1303. var redList = db.FindList<Acc_DormitoryBuildEntity>(x => x.ID == entity.bedId).ToList();
  1304. foreach (var redItem in redList)
  1305. {
  1306. var index = redList.IndexOf(redItem);
  1307. if (index == entity.PlanBedNum)
  1308. {
  1309. break;
  1310. }
  1311. redItem.PlanClassNo = entity.PlanClassNo;
  1312. db.Update(redItem);
  1313. }
  1314. }
  1315. db.Commit();
  1316. }
  1317. catch (Exception ex)
  1318. {
  1319. db.Rollback();
  1320. if (ex is ExceptionEx)
  1321. {
  1322. throw;
  1323. }
  1324. else
  1325. {
  1326. throw ExceptionEx.ThrowServiceException(ex);
  1327. }
  1328. }
  1329. }
  1330. /// <summary>
  1331. /// 取消分配宿舍
  1332. /// <param name="keyValue">主键</param>
  1333. /// <summary>
  1334. /// <returns></returns>
  1335. public void CancelAllocationDormitory(List<Acc_DormitoryBuildEntity> acc_DormitoryBuildEntities)
  1336. {
  1337. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1338. try
  1339. {
  1340. foreach (var entity in acc_DormitoryBuildEntities)
  1341. {
  1342. //修改房间:预分床位数量减少;预分班级判断是否需要清除;
  1343. var model = db.FindEntity<Acc_DormitoryBuildEntity>(entity.ID);
  1344. model.PlanBedNum = model.PlanBedNum - entity.CancelUseBedNum;
  1345. if (!string.IsNullOrEmpty(model.PlanClassNo))
  1346. {
  1347. var planclassnotemp = entity.PlanClassNo + ',';
  1348. if (model.PlanClassNo == planclassnotemp) //一个班
  1349. {
  1350. if (model.PlanBedNum <= 0)
  1351. {
  1352. model.PlanClassNo = "";
  1353. }
  1354. }
  1355. else //多个班
  1356. {
  1357. var bedNumSelf = db.FindList<Acc_DormitoryBuildEntity>(x => x.ParentID == entity.ID && x.PlanClassNo == entity.PlanClassNo).Count();
  1358. if (bedNumSelf == entity.CancelUseBedNum)
  1359. {
  1360. model.PlanClassNo = model.PlanClassNo.Replace(planclassnotemp, "");
  1361. }
  1362. }
  1363. }
  1364. db.Update(model);
  1365. //修改房间下的床位:预分班级清除;
  1366. var redList = db.FindList<Acc_DormitoryBuildEntity>(x => x.ParentID == entity.ID && x.PlanClassNo == entity.PlanClassNo).OrderBy(x => x.PlanStudentID).ThenBy(x => x.Name).ToList();
  1367. foreach (var redItem in redList)
  1368. {
  1369. var index = redList.IndexOf(redItem);
  1370. if (index == entity.CancelUseBedNum)
  1371. {
  1372. break;
  1373. }
  1374. redItem.PlanClassNo = "";
  1375. //判断床位是否被占用;
  1376. if (!string.IsNullOrEmpty(redItem.PlanStudentID))
  1377. {
  1378. redItem.PlanStudentID = "";
  1379. var stuInfoFreshEntity = db.FindEntity<StuInfoFreshEntity>(x => x.DormitoryNo == redItem.ID);
  1380. if (stuInfoFreshEntity != null)
  1381. {
  1382. stuInfoFreshEntity.DormitoryNo = "";
  1383. stuInfoFreshEntity.DormitoryName = "";
  1384. }
  1385. db.Update(stuInfoFreshEntity);
  1386. }
  1387. db.Update(redItem);
  1388. }
  1389. }
  1390. db.Commit();
  1391. }
  1392. catch (Exception ex)
  1393. {
  1394. db.Rollback();
  1395. if (ex is ExceptionEx)
  1396. {
  1397. throw;
  1398. }
  1399. else
  1400. {
  1401. throw ExceptionEx.ThrowServiceException(ex);
  1402. }
  1403. }
  1404. }
  1405. /// <summary>
  1406. /// 分配床位
  1407. /// </summary>
  1408. /// <param name="dormitoryNo"></param>
  1409. /// <param name="stuId"></param>
  1410. /// <param name="dormitoryName"></param>
  1411. public void DoAllocationBed(string dormitoryNo, string keyValue)
  1412. {
  1413. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1414. try
  1415. {
  1416. //清除StuInfoFresh
  1417. db.ExecuteBySql("update StuInfoFresh set DormitoryNo=null,DormitoryName=null where DormitoryNo='" + dormitoryNo + "' ");
  1418. //清除Acc_DormitoryBuild
  1419. db.ExecuteBySql("update Acc_DormitoryBuild set PlanStudentID=null where PlanStudentID='" + keyValue + "' ");
  1420. //更新Acc_DormitoryBuild
  1421. var newAcc_DormitoryBuildEntity = db.FindEntity<Acc_DormitoryBuildEntity>(x => x.ID == dormitoryNo);
  1422. if (newAcc_DormitoryBuildEntity != null)
  1423. {
  1424. newAcc_DormitoryBuildEntity.PlanStudentID = keyValue;
  1425. db.Update(newAcc_DormitoryBuildEntity);
  1426. //更新StuInfoFresh
  1427. var newStuInfoFreshEntity = db.FindEntity<StuInfoFreshEntity>(x => x.ID == keyValue);
  1428. if (newStuInfoFreshEntity != null)
  1429. {
  1430. newStuInfoFreshEntity.DormitoryNo = dormitoryNo;
  1431. newStuInfoFreshEntity.DormitoryName = db.FindEntity<Acc_DormitoryBuildEntity>(x => x.ID == newAcc_DormitoryBuildEntity.ParentID)?.Name + newAcc_DormitoryBuildEntity.Name;
  1432. db.Update(newStuInfoFreshEntity);
  1433. }
  1434. }
  1435. db.Commit();
  1436. }
  1437. catch (Exception ex)
  1438. {
  1439. db.Rollback();
  1440. if (ex is ExceptionEx)
  1441. {
  1442. throw;
  1443. }
  1444. else
  1445. {
  1446. throw ExceptionEx.ThrowServiceException(ex);
  1447. }
  1448. }
  1449. }
  1450. /// <summary>
  1451. /// 自动分配床位
  1452. /// </summary>
  1453. /// <param name="classNo">班级编号</param>
  1454. /// <param name="stuId"></param>
  1455. /// <param name="dormitoryName"></param>
  1456. public void DoAllocationBedOfAuto(string classNo)
  1457. {
  1458. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1459. try
  1460. {
  1461. //区分性别:男1,女0;
  1462. //班级里未分配床位的学生;班级里的空床位;
  1463. //修改StuInfoFresh;修改Acc_DormitoryBuild;
  1464. #region 随机分配
  1465. for (int i = 0; i <= 1; i++)
  1466. {
  1467. var studentList = new List<StuInfoFreshEntity>();
  1468. var bedList = new List<Acc_DormitoryBuildEntity>();
  1469. string sexTemp = "1";
  1470. if (i == 0)
  1471. {
  1472. studentList = db.FindList<StuInfoFreshEntity>(x => x.ClassNo == classNo && x.GenderNo != sexTemp && string.IsNullOrEmpty(x.DormitoryNo)).ToList();
  1473. bedList = db.FindList<Acc_DormitoryBuildEntity>(x => x.PlanClassNo == classNo && x.Sex != sexTemp && string.IsNullOrEmpty(x.PlanStudentID)).ToList();
  1474. }
  1475. else
  1476. {
  1477. studentList = db.FindList<StuInfoFreshEntity>(x => x.ClassNo == classNo && x.GenderNo == sexTemp && string.IsNullOrEmpty(x.DormitoryNo)).ToList();
  1478. bedList = db.FindList<Acc_DormitoryBuildEntity>(x => x.PlanClassNo == classNo && x.Sex == sexTemp && string.IsNullOrEmpty(x.PlanStudentID)).ToList();
  1479. }
  1480. var studentTempList = new List<StuInfoFreshEntity>();
  1481. var bedTempList = new List<Acc_DormitoryBuildEntity>();
  1482. foreach (var bedItem in bedList)
  1483. {
  1484. if (studentList.Count() == studentTempList.Count())
  1485. {
  1486. break;
  1487. }
  1488. var index = bedList.IndexOf(bedItem);
  1489. var studentItem = studentList[index];
  1490. bedItem.PlanStudentID = studentItem.ID;
  1491. bedTempList.Add(bedItem);
  1492. studentItem.DormitoryNo = bedItem.ID;
  1493. studentItem.DormitoryName = db.FindEntity<Acc_DormitoryBuildEntity>(x => x.ID == bedItem.ParentID)?.Name + bedItem.Name;
  1494. studentTempList.Add(studentItem);
  1495. }
  1496. db.Update(bedTempList);
  1497. db.Update(studentTempList);
  1498. }
  1499. #endregion
  1500. db.Commit();
  1501. }
  1502. catch (Exception ex)
  1503. {
  1504. db.Rollback();
  1505. if (ex is ExceptionEx)
  1506. {
  1507. throw;
  1508. }
  1509. else
  1510. {
  1511. throw ExceptionEx.ThrowServiceException(ex);
  1512. }
  1513. }
  1514. }
  1515. public void ConfirmDormitory()
  1516. {
  1517. try
  1518. {
  1519. var nostuBed = this.BaseRepository("CollegeMIS")
  1520. .FindList<Acc_DormitoryBuildEntity>(a => a.StudentID == null || a.StudentID == "").Where(a => a.PlanStudentID != null);
  1521. foreach (var bed in nostuBed)
  1522. {
  1523. var stuFreshInfo = this.BaseRepository("CollegeMIS")
  1524. .FindEntity<StuInfoFreshEntity>(a => a.ID == bed.PlanStudentID);
  1525. if (stuFreshInfo != null)
  1526. {
  1527. var stuInfo = this.BaseRepository("CollegeMIS")
  1528. .FindEntity<StuInfoBasicEntity>(a => a.StuNo == stuFreshInfo.StuNo);
  1529. if (stuInfo != null)
  1530. {
  1531. bed.Dept = stuInfo.DeptNo;
  1532. bed.Major = stuInfo.MajorNo;
  1533. bed.Class = stuInfo.ClassNo;
  1534. bed.StudentID = stuInfo.StuId;
  1535. this.BaseRepository("CollegeMIS").Update(bed);
  1536. }
  1537. }
  1538. }
  1539. }
  1540. catch (Exception ex)
  1541. {
  1542. if (ex is ExceptionEx)
  1543. {
  1544. throw;
  1545. }
  1546. else
  1547. {
  1548. throw ExceptionEx.ThrowServiceException(ex);
  1549. }
  1550. }
  1551. }
  1552. public void ConfirmDormitoryTwo()
  1553. {
  1554. try
  1555. {
  1556. var nostuBed = this.BaseRepository("CollegeMIS")
  1557. .FindList<Acc_DormitoryBuildEntity>(a => a.StudentID == null || a.StudentID == "").Where(a => a.PlanStudentID != null);
  1558. foreach (var bed in nostuBed)
  1559. {
  1560. var stuFreshInfo = this.BaseRepository("CollegeMIS")
  1561. .FindEntity<StuEnrollEntity>(a => a.StuId == bed.PlanStudentID);
  1562. if (stuFreshInfo != null)
  1563. {
  1564. var stuInfo = this.BaseRepository("CollegeMIS")
  1565. .FindEntity<StuInfoBasicEntity>(a => a.StuNo == stuFreshInfo.StuNo);
  1566. if (stuInfo != null)
  1567. {
  1568. bed.Dept = stuInfo.DeptNo;
  1569. bed.Major = stuInfo.MajorNo;
  1570. bed.Class = stuInfo.ClassNo;
  1571. bed.StudentID = stuInfo.StuId;
  1572. this.BaseRepository("CollegeMIS").Update(bed);
  1573. }
  1574. }
  1575. }
  1576. }
  1577. catch (Exception ex)
  1578. {
  1579. if (ex is ExceptionEx)
  1580. {
  1581. throw;
  1582. }
  1583. else
  1584. {
  1585. throw ExceptionEx.ThrowServiceException(ex);
  1586. }
  1587. }
  1588. }
  1589. public void GetUniform(string keyValue, bool Status)
  1590. {
  1591. try
  1592. {
  1593. var sql = "";
  1594. if (Status)
  1595. {
  1596. sql = $"UPDATE dbo.StuInfoFresh SET IsGetUniform =1 WHERE ID='{keyValue}'";
  1597. }
  1598. else
  1599. {
  1600. sql = $"UPDATE dbo.StuInfoFresh SET IsGetUniform =0 WHERE ID='{keyValue}'";
  1601. }
  1602. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  1603. }
  1604. catch (Exception ex)
  1605. {
  1606. if (ex is ExceptionEx)
  1607. {
  1608. throw;
  1609. }
  1610. else
  1611. {
  1612. throw ExceptionEx.ThrowServiceException(ex);
  1613. }
  1614. }
  1615. }
  1616. public void PayUniform(string keyValue, bool Status)
  1617. {
  1618. try
  1619. {
  1620. var sql = "";
  1621. if (Status)
  1622. {
  1623. sql = $"UPDATE dbo.StuInfoFresh SET IsPayUniform =1 WHERE ID='{keyValue}'";
  1624. }
  1625. else
  1626. {
  1627. sql = $"UPDATE dbo.StuInfoFresh SET IsPayUniform =0 WHERE ID='{keyValue}'";
  1628. }
  1629. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  1630. }
  1631. catch (Exception ex)
  1632. {
  1633. if (ex is ExceptionEx)
  1634. {
  1635. throw;
  1636. }
  1637. else
  1638. {
  1639. throw ExceptionEx.ThrowServiceException(ex);
  1640. }
  1641. }
  1642. }
  1643. /// <summary>
  1644. /// 导入学籍信息
  1645. /// </summary>
  1646. public void ImportStuInfoBasic()
  1647. {
  1648. try
  1649. {
  1650. //学籍表增加数据
  1651. var strSql = new StringBuilder();
  1652. strSql.Append(@"insert into StuInfoBasic
  1653. (StuId, StuNo, StuCode, NoticeNo, GraduateYear, ksh, DeptNo, MajorNo, MajorDetailNo, MajorDetailName,
  1654. Grade, ClassNo, StuName, SpellFull, SpellBrief, GenderNo, Birthday, PartyFaceNo, FamilyOriginNo, NationalityNo,
  1655. ProvinceNo, RegionNo, ResidenceNo, TestStuSortNo, HealthStatusNo, WillNo, TestStuSubjectNo, GraduateNo,
  1656. PlanFormNo, IsThreeGood, IsExcellent, IsNormalCadre, IsProvinceFirstThree, OverseasChineseNo, MatriculateSort,
  1657. ComeProvinceNo, HighSchoolNo, HighSchoolName, EntranceDate, Religion, GoodAt, IdentityCardNo, JoinPartyDate,
  1658. JoinLeagueDate, InSchoolAddress, InSchoolTelephone, AbmormityMoveMark, AwardMark, PunishMark, LinkmanMark,
  1659. StuNoChangeMark, FinishSchoolMark, CurrentRegisterMark, FinishSchoolDate, DiplomaNo, DiplomaRemark, Remark,
  1660. RegisterDate, Photo, TeachPlanNo, CheckMark, mobile, EMail, QQ, FatherUnit, FatherName, FatherPhone, MatherName,
  1661. MatherUnit, MatherPhone, username, password, MailAddress, PostalCode, InSchoolStatus, TransMark, ClassTutorNo,
  1662. ResumeCheck, PracStatus, RegisterStatus, PunishmentDate, F_CityId, F_CountyId, F_ProvinceId, F_SchoolId,
  1663. EduSystem, StudyModality, SyncFlag)
  1664. select NEWID(),StuNo,null,NoticeNo,null,ksh,DeptNo,MajorNo,MajorDetailNok as MajorDetailNo,MajorDetailName,Grade,ClassNo,StuName,null,null,case when GenderNo ='1' then 1 else 0 end,Birthday,PartyFaceNo,FamilyOriginNo,NationalityNo,ProvinceNo,RegionNo,ResidenceNo,TestStuSortNo,HealthStatusNo,WillNo,TestStuSubjectNo,GraduateNo,PlanFormNo,IsThreeGood,IsExcellent,IsNormalCadre,IsProvinceFirstThree,OverseasChineseNo,MatriculateSort,null,HighSchoolNo,HighSchoolName,null,null,GoodAt,IdentityCardNo,null,null,null,null,null,null,null,null,null,null,null,null,null,null,Remark,ArriveDate as RegisterDate,Photo,null,null,telephone as mobile,null,null,null,null,null,null,null,null,StuNo as username,null,MailAddress,PostalCode,null,TransMark,null,null,null,RegisterStatus,null,null,null,null,F_SchoolId,null,null,0 from
  1665. (select f.*,m.F_SchoolId from StuInfoFresh f left join CdMajor m on f.MajorNo=m.MajorNo where f.StuNo is not null ) as bb
  1666. where bb.StuNo not in (select b.StuNo from StuInfoBasic b where b.StuNo=bb.StuNo) ");
  1667. this.BaseRepository("CollegeMIS").ExecuteBySql(strSql.ToString());
  1668. //新生表修改“是否生成学籍”的状态
  1669. var strSql2 = new StringBuilder();
  1670. strSql2.Append("update StuInfoFresh set IsInBasic=1 where StuNo is not null and (IsInBasic is null or IsInBasic=0) and StuNo in (select t.StuNo from StuInfoBasic t where t.StuNo=StuNo)");
  1671. this.BaseRepository("CollegeMIS").ExecuteBySql(strSql2.ToString());
  1672. }
  1673. catch (Exception ex)
  1674. {
  1675. if (ex is ExceptionEx)
  1676. {
  1677. throw;
  1678. }
  1679. else
  1680. {
  1681. throw ExceptionEx.ThrowServiceException(ex);
  1682. }
  1683. }
  1684. }
  1685. /// <summary>
  1686. /// 删除宿舍信息
  1687. /// </summary>
  1688. public void DeleteBed(string keyValue)
  1689. {
  1690. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  1691. try
  1692. {
  1693. var stuInfoFreshEntity = db.FindEntity<StuInfoFreshEntity>(x => x.ID == keyValue);
  1694. if (stuInfoFreshEntity != null && !string.IsNullOrEmpty(stuInfoFreshEntity.DormitoryNo))
  1695. {
  1696. var dormitoryBuildEntity = db.FindEntity<Acc_DormitoryBuildEntity>(x => x.ID == stuInfoFreshEntity.DormitoryNo);
  1697. if (dormitoryBuildEntity != null)
  1698. {
  1699. //判断是否清除宿舍中预分班级
  1700. var roomEntity = db.FindEntity<Acc_DormitoryBuildEntity>(x => x.ID == dormitoryBuildEntity.ParentID);
  1701. if (roomEntity != null)
  1702. {
  1703. roomEntity.PlanBedNum = roomEntity.PlanBedNum - 1;
  1704. var aa = db.FindList<Acc_DormitoryBuildEntity>(x => x.ParentID == roomEntity.ID && x.PlanClassNo == dormitoryBuildEntity.PlanClassNo && x.ID != dormitoryBuildEntity.ID);
  1705. if (!aa.Any()) //宿舍不存在同班学生
  1706. {
  1707. var tempClass = dormitoryBuildEntity.PlanClassNo + ",";
  1708. roomEntity.PlanClassNo = roomEntity.PlanClassNo.Replace(tempClass, "");
  1709. }
  1710. db.Update(roomEntity);
  1711. }
  1712. //清除Acc_DormitoryBuild
  1713. db.ExecuteBySql("update Acc_DormitoryBuild set PlanStudentID=null,PlanClassNo=null where ID='" + dormitoryBuildEntity.ID + "' ");
  1714. }
  1715. //清除StuInfoFresh
  1716. db.ExecuteBySql("update StuInfoFresh set DormitoryNo=null,DormitoryName=null where ID='" + stuInfoFreshEntity.ID + "' ");
  1717. }
  1718. db.Commit();
  1719. }
  1720. catch (Exception ex)
  1721. {
  1722. db.Rollback();
  1723. if (ex is ExceptionEx)
  1724. {
  1725. throw;
  1726. }
  1727. else
  1728. {
  1729. throw ExceptionEx.ThrowServiceException(ex);
  1730. }
  1731. }
  1732. }
  1733. #endregion
  1734. #region 上传图片
  1735. internal (bool, string) IsPhoto(string stuId, bool status, string fileGuid)
  1736. {
  1737. try
  1738. {
  1739. string result = "";
  1740. bool resultBool = false;
  1741. var model = this.BaseRepository("CollegeMIS").FindEntity<StuInfoFreshEntity>(a => a.ID == stuId);
  1742. if (model != null)
  1743. {
  1744. model.Photo = fileGuid;
  1745. resultBool = true;
  1746. result = "操作成功!";
  1747. this.BaseRepository("CollegeMIS").Update(model);
  1748. }
  1749. else
  1750. {
  1751. result = "错误";
  1752. }
  1753. return (resultBool, result);
  1754. }
  1755. catch (Exception ex)
  1756. {
  1757. if (ex is ExceptionEx)
  1758. {
  1759. throw;
  1760. }
  1761. else
  1762. {
  1763. throw ExceptionEx.ThrowServiceException(ex);
  1764. }
  1765. }
  1766. }
  1767. #endregion
  1768. }
  1769. }