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.
 
 
 
 
 
 

416 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. entity.BankCard = model.BankCard;
  159. entity.BankLocation = model.BankLocation;
  160. entity.DepositBank = model.DepositBank;
  161. if (!string.IsNullOrEmpty(model.Photo))
  162. {
  163. entity.IsPhoto = true;
  164. entity.Photo = model.Photo;
  165. }
  166. else
  167. {
  168. entity.IsPhoto = false;
  169. entity.Photo = "";
  170. }
  171. stuInfoFreshIBLL.SaveEntity(entity.ID, entity, model.StuInfoFreshEmergePeopleEntities, model.StuInfoFreshFamilyEntities);
  172. return Success("保存成功");
  173. }
  174. /// <summary>
  175. /// 保存贷款回执码
  176. /// </summary>
  177. /// <param name="_"></param>
  178. /// <returns></returns>
  179. private Response GetSaveLoan(dynamic _)
  180. {
  181. var model = this.GetReqData<StuInfoFreshModel>();
  182. var entity = stuInfoFreshIBLL.GetStuInfoFreshEntity(model.ID);
  183. entity.StudentLoan = model.StudentLoan;
  184. entity.StudentLoanStatus = model.StudentLoanStatus;
  185. stuInfoFreshIBLL.SaveEntity(entity.ID, entity);
  186. return Success("保存成功");
  187. }
  188. /// <summary>
  189. /// 头像
  190. /// </summary>
  191. /// <param name="_"></param>
  192. /// <returns></returns>
  193. private Response GetSavePhoto(dynamic _)
  194. {
  195. var model = this.GetReqData<PhotoModel>();
  196. var folderId = Guid.NewGuid().ToString();
  197. string filePath = Config.GetValue("AnnexesFile");
  198. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  199. string FileEextension = ".png";
  200. string fileGuid = Guid.NewGuid().ToString();
  201. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.account, uploadDate, fileGuid, FileEextension);
  202. //创建文件夹
  203. string path = Path.GetDirectoryName(virtualPath);
  204. Directory.CreateDirectory(path);
  205. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  206. if (!System.IO.File.Exists(virtualPath))
  207. {
  208. //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
  209. byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
  210. FileInfo file = new FileInfo(virtualPath);
  211. FileStream fs = file.Create();
  212. fs.Write(bytes, 0, bytes.Length);
  213. fs.Close();
  214. //文件信息写入数据库
  215. fileAnnexesEntity.F_Id = fileGuid;
  216. fileAnnexesEntity.F_FileName = "userphoto.png";
  217. fileAnnexesEntity.F_FilePath = virtualPath;
  218. fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
  219. fileAnnexesEntity.F_FileExtensions = FileEextension;
  220. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  221. fileAnnexesEntity.F_CreateUserId = userInfo.userId;
  222. fileAnnexesEntity.F_CreateUserName = userInfo.realName;
  223. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  224. }
  225. var data = new
  226. {
  227. Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
  228. AnnexesFileId = fileGuid
  229. };
  230. return Success(data);
  231. }
  232. /// <summary>
  233. /// 学费查询
  234. /// </summary>
  235. /// <param name="_"></param>
  236. /// <returns></returns>
  237. private Response GetPayFeeDetail(dynamic _)
  238. {
  239. var academicAndYear = Common.GetSemesterAndYear();
  240. var FinaChargesStandardList = new List<FinaChargesStandardEntity>();
  241. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(userInfo.account);
  242. if (StuInfoFreshData != null)
  243. {
  244. if (!string.IsNullOrEmpty(StuInfoFreshData.ClassNo) && !string.IsNullOrEmpty(StuInfoFreshData.MajorNo))
  245. {
  246. var ClassInfoEntity = classInfoIBLL.GetClassInfoEntityByClassNo(StuInfoFreshData.ClassNo);
  247. if (ClassInfoEntity != null)
  248. {
  249. FinaChargesStandardList = finaChargesStandardIBLL.GetFinaChargesStandardListByMajorNoOfNotAll(StuInfoFreshData.MajorNo, academicAndYear.AcademicYearShort, academicAndYear.Semester, ClassInfoEntity.Grade).ToList();
  250. }
  251. }
  252. }
  253. var PayFeeTotal = FinaChargesStandardList.Select(x => x.Standard).Sum();
  254. var result = new
  255. {
  256. FinaChargesStandardList = FinaChargesStandardList,
  257. PayFeeTotal = PayFeeTotal,
  258. AcademicYearNo = academicAndYear.AcademicYearShort,
  259. Semester = academicAndYear.Semester,
  260. };
  261. return Success(result);
  262. }
  263. /// <summary>
  264. /// 根据班级查询新生列表
  265. /// <summary>
  266. /// <param name="_"></param>
  267. /// <returns></returns>
  268. public Response GetPageList(dynamic _)
  269. {
  270. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  271. var data = stuInfoFreshIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  272. var jsonData = new
  273. {
  274. rows = data,
  275. total = parameter.pagination.total,
  276. page = parameter.pagination.page,
  277. records = parameter.pagination.records
  278. };
  279. return Success(jsonData);
  280. }
  281. /// <summary>
  282. /// 获取表单数据
  283. /// <summary>
  284. /// <param name="_"></param>
  285. /// <returns></returns>
  286. public Response GetForm(dynamic _)
  287. {
  288. string keyValue = this.GetReqData();
  289. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue);
  290. var jsonData = new
  291. {
  292. StuInfoFresh = StuInfoFreshData,
  293. };
  294. return Success(jsonData);
  295. }
  296. /// <summary>
  297. /// 保存实体数据(新增、修改)
  298. /// <param name="_"></param>
  299. /// <summary>
  300. /// <returns></returns>
  301. public Response SaveForm(dynamic _)
  302. {
  303. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  304. StuInfoFreshEntity entity = parameter.strEntity.ToObject<StuInfoFreshEntity>();
  305. stuInfoFreshIBLL.SaveEntity(parameter.keyValue, entity);
  306. return Success("保存成功!");
  307. }
  308. #region 私有类
  309. /// <summary>
  310. /// 表单实体类
  311. /// <summary>
  312. private class ReqFormEntity
  313. {
  314. public string keyValue { get; set; }
  315. public string strEntity { get; set; }
  316. }
  317. #endregion
  318. /// <summary>
  319. /// 个人信息
  320. /// </summary>
  321. public class StuInfoFreshModel
  322. {
  323. /// <summary>
  324. /// 主键
  325. /// </summary>
  326. public string ID { get; set; }
  327. /// <summary>
  328. /// 籍贯
  329. /// </summary>
  330. public string RegionNo { get; set; }
  331. /// <summary>
  332. /// 家庭住址
  333. /// </summary>
  334. public string FamilyAddress { get; set; }
  335. /// <summary>
  336. /// 联系电话
  337. /// </summary>
  338. public string telephone { get; set; }
  339. /// <summary>
  340. /// 头像地址
  341. /// </summary>
  342. public string Photo { get; set; }
  343. /// <summary>
  344. /// 贷款回执码
  345. /// </summary>
  346. public string StudentLoan { get; set; }
  347. /// <summary>
  348. /// 贷款回执码状态
  349. /// </summary>
  350. public string StudentLoanStatus { get; set; }
  351. /// <summary>
  352. /// 家庭成员
  353. /// </summary>
  354. public List<StuInfoFreshFamilyEntity> StuInfoFreshFamilyEntities { get; set; }
  355. /// <summary>
  356. /// 紧急联系人
  357. /// </summary>
  358. public List<StuInfoFreshEmergePeopleEntity> StuInfoFreshEmergePeopleEntities { get; set; }
  359. /// <summary>
  360. /// 开户行
  361. /// </summary>
  362. public string DepositBank { get; set; }
  363. /// <summary>
  364. /// 银行卡号
  365. /// </summary>
  366. public string BankCard { get; set; }
  367. /// <summary>
  368. /// 开户行位置
  369. /// </summary>
  370. public string BankLocation { get; set; }
  371. }
  372. public class PhotoModel
  373. {
  374. public string Base64Url { get; set; }
  375. public string account { get; set; }
  376. }
  377. }
  378. }