You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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