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.
 
 
 
 
 
 

401 lines
16 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. using Learun.Application.Base.SystemModule;
  7. using Learun.Application.TwoDevelopment.EducationalAdministration;
  8. using Learun.Application.TwoDevelopment.LogisticsManagement;
  9. using Learun.Application.TwoDevelopment.ReceiveSendFeeManagement;
  10. using Learun.Util;
  11. using Nancy;
  12. namespace Learun.Application.WebApi.Modules
  13. {
  14. public class StuInfoFreshApi : BaseApi
  15. {
  16. public StuInfoFreshApi()
  17. : base("/StuInfoFresh")
  18. {
  19. Get["/stuInfoFreshEntity"] = GetStuInfoFreshEntity;
  20. Get["/stuInfoFresh"] = GetStuInfoFresh;
  21. Get["/saveStuInfoFresh"] = GetSaveStuInfoFresh;
  22. Get["/saveLoan"] = GetSaveLoan;
  23. Post["/savePhoto"] = GetSavePhoto;
  24. Get["/payFeeDetail"] = GetPayFeeDetail;
  25. Get["/pageList"] = GetPageList;
  26. Get["/form"] = GetForm;
  27. Post["/save"] = SaveForm;
  28. }
  29. private StuInfoFreshIBLL stuInfoFreshIBLL = new StuInfoFreshBLL();
  30. private CdMajorIBLL cdMajorIBLL = new CdMajorBLL();
  31. private CdDeptIBLL cdDeptIBLL = new CdDeptBLL();
  32. private ClassInfoIBLL classInfoIBLL = new ClassInfoBLL();
  33. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  34. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  35. private AccommodationIBLL accdormitoryIBLL = new AccommodationBLL();
  36. private FinaChargesStandardIBLL finaChargesStandardIBLL = new FinaChargesStandardBLL();
  37. private ClassroomInfoIBLL classroomInfoIBLL = new ClassroomInfoBLL();
  38. /// <summary>
  39. /// 获取个人信息
  40. /// </summary>
  41. /// <param name="_"></param>
  42. /// <returns></returns>
  43. private Response GetStuInfoFreshEntity(dynamic _)
  44. {
  45. var url = Config.GetValue("defaultheadimg");
  46. var StuInfoFreshFamilyList = new List<StuInfoFreshFamilyEntity>();
  47. var StuInfoFreshEmergePeopleList = new List<StuInfoFreshEmergePeopleEntity>();
  48. var StuInfoFreshEntity = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(GetReqData());
  49. if (StuInfoFreshEntity != null)
  50. {
  51. //处理数据源
  52. StuInfoFreshEntity.MajorNo = cdMajorIBLL.GetCdMajorEntityByMajorNo(StuInfoFreshEntity.MajorNo)?.MajorName;
  53. StuInfoFreshEntity.DeptNo = cdDeptIBLL.GetCdDeptEntityByNo(StuInfoFreshEntity.DeptNo)?.DeptName;
  54. var classInfoEntity = classInfoIBLL.GetClassInfoEntityByClassNo(StuInfoFreshEntity.ClassNo);
  55. if (classInfoEntity != null)
  56. {
  57. StuInfoFreshEntity.ClassNo = classInfoEntity.ClassName;
  58. if (classInfoEntity.ClassTutorNo != null)
  59. {
  60. StuInfoFreshEntity.ClassTutorNo = classInfoEntity.ClassTutorNo;
  61. var empInfoEntity = empInfoIBLL.GetEmpInfoEntityByEmpNo(classInfoEntity.ClassTutorNo);
  62. if (empInfoEntity != null)
  63. {
  64. StuInfoFreshEntity.ClassTutorName = empInfoEntity.EmpName;
  65. StuInfoFreshEntity.ClassTutorMobile = empInfoEntity.mobile;
  66. }
  67. }
  68. if (classInfoEntity.ClassDiredctorNo != null)
  69. {
  70. StuInfoFreshEntity.ClassDiredctorNo = classInfoEntity.ClassDiredctorNo;
  71. var empInfoEntity2 = empInfoIBLL.GetEmpInfoEntityByEmpNo(classInfoEntity.ClassDiredctorNo);
  72. if (empInfoEntity2 != null)
  73. {
  74. StuInfoFreshEntity.ClassDiredctorName = empInfoEntity2.EmpName;
  75. StuInfoFreshEntity.ClassDiredctorMobile = empInfoEntity2.mobile;
  76. }
  77. }
  78. if (classInfoEntity.SerialNum != null)
  79. {
  80. StuInfoFreshEntity.DefaultClassRoomNo = classInfoEntity.SerialNum;
  81. var classroomEntity = classroomInfoIBLL.GetClassroomInfoEntityByNo(classInfoEntity.SerialNum);
  82. if (classroomEntity != null)
  83. {
  84. StuInfoFreshEntity.DefaultClassRoomName = classroomEntity.ClassroomName;
  85. }
  86. }
  87. }
  88. //获取头像地址
  89. if (StuInfoFreshEntity.IsPhoto == true && !string.IsNullOrEmpty(StuInfoFreshEntity.Photo))
  90. {
  91. var annexesFileEntity = annexesFileIBLL.GetEntity(StuInfoFreshEntity.Photo);
  92. if (annexesFileEntity != null)
  93. {
  94. url = annexesFileEntity.F_FilePath.Substring(annexesFileEntity.F_FilePath.IndexOf("Resource"));
  95. }
  96. }
  97. StuInfoFreshEntity.DormitoryName = accdormitoryIBLL.GetDormitoryInfoByPlanStuNo(StuInfoFreshEntity.ID);
  98. if (StuInfoFreshEntity.IsPoor != "1")
  99. {
  100. StuInfoFreshEntity.IsPoor = "0";
  101. }
  102. if (StuInfoFreshEntity.GetKeyStatus != "1")
  103. {
  104. StuInfoFreshEntity.GetKeyStatus = "0";
  105. }
  106. if (StuInfoFreshEntity.GetCardStatus != "1")
  107. {
  108. StuInfoFreshEntity.GetCardStatus = "0";
  109. }
  110. if (StuInfoFreshEntity.OtherPayFeeStatus != "1")
  111. {
  112. StuInfoFreshEntity.OtherPayFeeStatus = "0";
  113. }
  114. if (StuInfoFreshEntity.CollectFileStatus != "1")
  115. {
  116. StuInfoFreshEntity.CollectFileStatus = "0";
  117. }
  118. //是否完善信息
  119. StuInfoFreshFamilyList = stuInfoFreshIBLL.GetStuInfoFreshFamilyList(StuInfoFreshEntity.ID).ToList();
  120. StuInfoFreshEmergePeopleList = stuInfoFreshIBLL.GetStuInfoFreshEmergePeopleList(StuInfoFreshEntity.ID).ToList();
  121. StuInfoFreshEntity.IsCompleteInfo = StuInfoFreshFamilyList.Any() ? "已完善" : "未完善";
  122. }
  123. var result = new
  124. {
  125. StuInfoFreshEntity = StuInfoFreshEntity,
  126. StuInfoFreshFamilyList = StuInfoFreshFamilyList,
  127. StuInfoFreshEmergePeopleList = StuInfoFreshEmergePeopleList,
  128. Url = url
  129. };
  130. return Success(result);
  131. }
  132. /// <summary>
  133. /// 获取个人信息
  134. /// </summary>
  135. /// <param name="_"></param>
  136. /// <returns></returns>
  137. private Response GetStuInfoFresh(dynamic _)
  138. {
  139. var StuInfoFreshEntity = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(userInfo.account);
  140. var result = new
  141. {
  142. StuInfoFreshEntity = StuInfoFreshEntity
  143. };
  144. return Success(result);
  145. }
  146. /// <summary>
  147. /// 保存完善个人信息
  148. /// </summary>
  149. /// <param name="_"></param>
  150. /// <returns></returns>
  151. private Response GetSaveStuInfoFresh(dynamic _)
  152. {
  153. var model = this.GetReqData<StuInfoFreshModel>();
  154. var entity = stuInfoFreshIBLL.GetStuInfoFreshEntity(model.ID);
  155. entity.RegionNo = model.RegionNo;
  156. entity.FamilyAddress = model.FamilyAddress;
  157. entity.telephone = model.telephone;
  158. if (!string.IsNullOrEmpty(model.Photo))
  159. {
  160. entity.IsPhoto = true;
  161. entity.Photo = model.Photo;
  162. }
  163. else
  164. {
  165. entity.IsPhoto = false;
  166. entity.Photo = "";
  167. }
  168. stuInfoFreshIBLL.SaveEntity(entity.ID, entity, model.StuInfoFreshEmergePeopleEntities, model.StuInfoFreshFamilyEntities);
  169. return Success("保存成功");
  170. }
  171. /// <summary>
  172. /// 保存贷款回执码
  173. /// </summary>
  174. /// <param name="_"></param>
  175. /// <returns></returns>
  176. private Response GetSaveLoan(dynamic _)
  177. {
  178. var model = this.GetReqData<StuInfoFreshModel>();
  179. var entity = stuInfoFreshIBLL.GetStuInfoFreshEntity(model.ID);
  180. entity.StudentLoan = model.StudentLoan;
  181. entity.StudentLoanStatus = model.StudentLoanStatus;
  182. stuInfoFreshIBLL.SaveEntity(entity.ID, entity);
  183. return Success("保存成功");
  184. }
  185. /// <summary>
  186. /// 头像
  187. /// </summary>
  188. /// <param name="_"></param>
  189. /// <returns></returns>
  190. private Response GetSavePhoto(dynamic _)
  191. {
  192. var model = this.GetReqData<PhotoModel>();
  193. var folderId = Guid.NewGuid().ToString();
  194. string filePath = Config.GetValue("AnnexesFile");
  195. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  196. string FileEextension = ".png";
  197. string fileGuid = Guid.NewGuid().ToString();
  198. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.account, uploadDate, fileGuid, FileEextension);
  199. //创建文件夹
  200. string path = Path.GetDirectoryName(virtualPath);
  201. Directory.CreateDirectory(path);
  202. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  203. if (!System.IO.File.Exists(virtualPath))
  204. {
  205. //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
  206. byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
  207. FileInfo file = new FileInfo(virtualPath);
  208. FileStream fs = file.Create();
  209. fs.Write(bytes, 0, bytes.Length);
  210. fs.Close();
  211. //文件信息写入数据库
  212. fileAnnexesEntity.F_Id = fileGuid;
  213. fileAnnexesEntity.F_FileName = "userphoto.png";
  214. fileAnnexesEntity.F_FilePath = virtualPath;
  215. fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
  216. fileAnnexesEntity.F_FileExtensions = FileEextension;
  217. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  218. fileAnnexesEntity.F_CreateUserId = userInfo.userId;
  219. fileAnnexesEntity.F_CreateUserName = userInfo.realName;
  220. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  221. }
  222. var data = new
  223. {
  224. Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
  225. AnnexesFileId = fileGuid
  226. };
  227. return Success(data);
  228. }
  229. /// <summary>
  230. /// 学费查询
  231. /// </summary>
  232. /// <param name="_"></param>
  233. /// <returns></returns>
  234. private Response GetPayFeeDetail(dynamic _)
  235. {
  236. var academicAndYear = Common.GetSemesterAndYear();
  237. var FinaChargesStandardList = new List<FinaChargesStandardEntity>();
  238. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(userInfo.account);
  239. if (StuInfoFreshData != null)
  240. {
  241. if (!string.IsNullOrEmpty(StuInfoFreshData.ClassNo) && !string.IsNullOrEmpty(StuInfoFreshData.MajorNo))
  242. {
  243. var ClassInfoEntity = classInfoIBLL.GetClassInfoEntityByClassNo(StuInfoFreshData.ClassNo);
  244. if (ClassInfoEntity != null)
  245. {
  246. FinaChargesStandardList = finaChargesStandardIBLL.GetFinaChargesStandardListByMajorNoOfNotAll(StuInfoFreshData.MajorNo, academicAndYear.AcademicYearShort, academicAndYear.Semester, ClassInfoEntity.Grade).ToList();
  247. }
  248. }
  249. }
  250. var PayFeeTotal = FinaChargesStandardList.Select(x => x.Standard).Sum();
  251. var result = new
  252. {
  253. FinaChargesStandardList = FinaChargesStandardList,
  254. PayFeeTotal = PayFeeTotal,
  255. AcademicYearNo = academicAndYear.AcademicYearShort,
  256. Semester = academicAndYear.Semester,
  257. };
  258. return Success(result);
  259. }
  260. /// <summary>
  261. /// 根据班级查询新生列表
  262. /// <summary>
  263. /// <param name="_"></param>
  264. /// <returns></returns>
  265. public Response GetPageList(dynamic _)
  266. {
  267. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  268. var data = stuInfoFreshIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  269. var jsonData = new
  270. {
  271. rows = data,
  272. total = parameter.pagination.total,
  273. page = parameter.pagination.page,
  274. records = parameter.pagination.records
  275. };
  276. return Success(jsonData);
  277. }
  278. /// <summary>
  279. /// 获取表单数据
  280. /// <summary>
  281. /// <param name="_"></param>
  282. /// <returns></returns>
  283. public Response GetForm(dynamic _)
  284. {
  285. string keyValue = this.GetReqData();
  286. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue);
  287. var jsonData = new
  288. {
  289. StuInfoFresh = StuInfoFreshData,
  290. };
  291. return Success(jsonData);
  292. }
  293. /// <summary>
  294. /// 保存实体数据(新增、修改)
  295. /// <param name="_"></param>
  296. /// <summary>
  297. /// <returns></returns>
  298. public Response SaveForm(dynamic _)
  299. {
  300. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  301. StuInfoFreshEntity entity = parameter.strEntity.ToObject<StuInfoFreshEntity>();
  302. stuInfoFreshIBLL.SaveEntity(parameter.keyValue, entity);
  303. return Success("保存成功!");
  304. }
  305. #region 私有类
  306. /// <summary>
  307. /// 表单实体类
  308. /// <summary>
  309. private class ReqFormEntity
  310. {
  311. public string keyValue { get; set; }
  312. public string strEntity { get; set; }
  313. }
  314. #endregion
  315. /// <summary>
  316. /// 个人信息
  317. /// </summary>
  318. public class StuInfoFreshModel
  319. {
  320. /// <summary>
  321. /// 主键
  322. /// </summary>
  323. public string ID { get; set; }
  324. /// <summary>
  325. /// 籍贯
  326. /// </summary>
  327. public string RegionNo { get; set; }
  328. /// <summary>
  329. /// 家庭住址
  330. /// </summary>
  331. public string FamilyAddress { get; set; }
  332. /// <summary>
  333. /// 联系电话
  334. /// </summary>
  335. public string telephone { get; set; }
  336. /// <summary>
  337. /// 头像地址
  338. /// </summary>
  339. public string Photo { get; set; }
  340. /// <summary>
  341. /// 贷款回执码
  342. /// </summary>
  343. public string StudentLoan { get; set; }
  344. /// <summary>
  345. /// 贷款回执码状态
  346. /// </summary>
  347. public string StudentLoanStatus { get; set; }
  348. /// <summary>
  349. /// 家庭成员
  350. /// </summary>
  351. public List<StuInfoFreshFamilyEntity> StuInfoFreshFamilyEntities { get; set; }
  352. /// <summary>
  353. /// 紧急联系人
  354. /// </summary>
  355. public List<StuInfoFreshEmergePeopleEntity> StuInfoFreshEmergePeopleEntities { get; set; }
  356. }
  357. public class PhotoModel
  358. {
  359. public string Base64Url { get; set; }
  360. public string account { get; set; }
  361. }
  362. }
  363. }