25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

521 lines
21 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. Post["/upload"] = Upload;
  29. Post["/deleteFiles"] = DeleteFiles;
  30. }
  31. private StuInfoFreshIBLL stuInfoFreshIBLL = new StuInfoFreshBLL();
  32. private CdMajorIBLL cdMajorIBLL = new CdMajorBLL();
  33. private CdDeptIBLL cdDeptIBLL = new CdDeptBLL();
  34. private ClassInfoIBLL classInfoIBLL = new ClassInfoBLL();
  35. private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
  36. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  37. private AccommodationIBLL accdormitoryIBLL = new AccommodationBLL();
  38. private FinaChargesStandardIBLL finaChargesStandardIBLL = new FinaChargesStandardBLL();
  39. private ClassroomInfoIBLL classroomInfoIBLL = new ClassroomInfoBLL();
  40. /// <summary>
  41. /// 获取个人信息
  42. /// </summary>
  43. /// <param name="_"></param>
  44. /// <returns></returns>
  45. private Response GetStuInfoFreshEntity(dynamic _)
  46. {
  47. var url = Config.GetValue("defaultheadimg");
  48. var StuInfoFreshFamilyList = new List<StuInfoFreshFamilyEntity>();
  49. var StuInfoFreshEmergePeopleList = new List<StuInfoFreshEmergePeopleEntity>();
  50. var StuInfoFreshEntity = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(GetReqData());
  51. if (StuInfoFreshEntity != null)
  52. {
  53. //处理数据源
  54. StuInfoFreshEntity.MajorNo = cdMajorIBLL.GetCdMajorEntityByMajorNo(StuInfoFreshEntity.MajorNo)?.MajorName;
  55. StuInfoFreshEntity.DeptNo = cdDeptIBLL.GetCdDeptEntityByNo(StuInfoFreshEntity.DeptNo)?.DeptName;
  56. var classInfoEntity = classInfoIBLL.GetClassInfoEntityByClassNo(StuInfoFreshEntity.ClassNo);
  57. if (classInfoEntity != null)
  58. {
  59. StuInfoFreshEntity.ClassNo = classInfoEntity.ClassName;
  60. if (classInfoEntity.ClassTutorNo != null)
  61. {
  62. StuInfoFreshEntity.ClassTutorNo = classInfoEntity.ClassTutorNo;
  63. //单个辅导员修改为多个辅导员
  64. if (!string.IsNullOrEmpty(StuInfoFreshEntity.ClassTutorNo))
  65. {
  66. foreach (var item in StuInfoFreshEntity.ClassTutorNo.Split(','))
  67. {
  68. var empInfoEntity = empInfoIBLL.GetEmpInfoEntityByEmpNo(item);
  69. if (empInfoEntity != null)
  70. {
  71. StuInfoFreshEntity.ClassTutorName += (empInfoEntity.EmpName + ",");
  72. StuInfoFreshEntity.ClassTutorMobile += (empInfoEntity.mobile + ",");
  73. }
  74. }
  75. if (!string.IsNullOrEmpty(StuInfoFreshEntity.ClassTutorName))
  76. {
  77. StuInfoFreshEntity.ClassTutorName = StuInfoFreshEntity.ClassTutorName.TrimEnd(',');
  78. }
  79. if (!string.IsNullOrEmpty(StuInfoFreshEntity.ClassTutorMobile))
  80. {
  81. StuInfoFreshEntity.ClassTutorMobile = StuInfoFreshEntity.ClassTutorMobile.TrimEnd(',');
  82. }
  83. }
  84. }
  85. if (classInfoEntity.ClassDiredctorNo != null)
  86. {
  87. StuInfoFreshEntity.ClassDiredctorNo = classInfoEntity.ClassDiredctorNo;
  88. var empInfoEntity2 = empInfoIBLL.GetEmpInfoEntityByEmpNo(classInfoEntity.ClassDiredctorNo);
  89. if (empInfoEntity2 != null)
  90. {
  91. StuInfoFreshEntity.ClassDiredctorName = empInfoEntity2.EmpName;
  92. StuInfoFreshEntity.ClassDiredctorMobile = empInfoEntity2.mobile;
  93. }
  94. }
  95. if (classInfoEntity.SerialNum != null)
  96. {
  97. StuInfoFreshEntity.DefaultClassRoomNo = classInfoEntity.SerialNum;
  98. var classroomEntity = classroomInfoIBLL.GetClassroomInfoEntityByNo(classInfoEntity.SerialNum);
  99. if (classroomEntity != null)
  100. {
  101. StuInfoFreshEntity.DefaultClassRoomName = classroomEntity.ClassroomName;
  102. }
  103. }
  104. }
  105. //获取头像地址
  106. if (StuInfoFreshEntity.IsPhoto == true && !string.IsNullOrEmpty(StuInfoFreshEntity.Photo))
  107. {
  108. var annexesFileEntity = annexesFileIBLL.GetEntity(StuInfoFreshEntity.Photo);
  109. if (annexesFileEntity != null)
  110. {
  111. url = annexesFileEntity.F_FilePath.Substring(annexesFileEntity.F_FilePath.IndexOf("Resource"));
  112. StuInfoFreshEntity.Url = url;
  113. }
  114. }
  115. //获取附件列表
  116. var annexesFileList = annexesFileIBLL.GetList(StuInfoFreshEntity.ID);
  117. if (annexesFileList.Any())
  118. {
  119. foreach (var item in annexesFileList)
  120. {
  121. item.F_FilePath = item.F_FilePath.Substring(item.F_FilePath.IndexOf("Resource"));
  122. }
  123. StuInfoFreshEntity.FilesList = annexesFileList.ToList();
  124. }
  125. StuInfoFreshEntity.DormitoryName = accdormitoryIBLL.GetDormitoryInfoByPlanStuNo(StuInfoFreshEntity.ID);
  126. if (StuInfoFreshEntity.IsPoor != "1")
  127. {
  128. StuInfoFreshEntity.IsPoor = "0";
  129. }
  130. if (StuInfoFreshEntity.GetKeyStatus != "1")
  131. {
  132. StuInfoFreshEntity.GetKeyStatus = "0";
  133. }
  134. if (StuInfoFreshEntity.GetCardStatus != "1")
  135. {
  136. StuInfoFreshEntity.GetCardStatus = "0";
  137. }
  138. if (StuInfoFreshEntity.OtherPayFeeStatus != "1")
  139. {
  140. StuInfoFreshEntity.OtherPayFeeStatus = "0";
  141. }
  142. if (StuInfoFreshEntity.CollectFileStatus != "1")
  143. {
  144. StuInfoFreshEntity.CollectFileStatus = "0";
  145. }
  146. //是否完善信息
  147. StuInfoFreshFamilyList = stuInfoFreshIBLL.GetStuInfoFreshFamilyList(StuInfoFreshEntity.ID).ToList();
  148. StuInfoFreshEmergePeopleList = stuInfoFreshIBLL.GetStuInfoFreshEmergePeopleList(StuInfoFreshEntity.ID).ToList();
  149. StuInfoFreshEntity.IsCompleteInfo = StuInfoFreshFamilyList.Any() ? "已完善" : "未完善";
  150. }
  151. var result = new
  152. {
  153. StuInfoFreshEntity = StuInfoFreshEntity,
  154. StuInfoFreshFamilyList = StuInfoFreshFamilyList,
  155. StuInfoFreshEmergePeopleList = StuInfoFreshEmergePeopleList,
  156. Url = url
  157. };
  158. return Success(result);
  159. }
  160. /// <summary>
  161. /// 获取个人信息
  162. /// </summary>
  163. /// <param name="_"></param>
  164. /// <returns></returns>
  165. private Response GetStuInfoFresh(dynamic _)
  166. {
  167. var StuInfoFreshEntity = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(userInfo.account);
  168. var result = new
  169. {
  170. StuInfoFreshEntity = StuInfoFreshEntity
  171. };
  172. return Success(result);
  173. }
  174. /// <summary>
  175. /// 保存完善个人信息
  176. /// </summary>
  177. /// <param name="_"></param>
  178. /// <returns></returns>
  179. private Response GetSaveStuInfoFresh(dynamic _)
  180. {
  181. var model = this.GetReqData<StuInfoFreshModel>();
  182. var entity = stuInfoFreshIBLL.GetStuInfoFreshEntity(model.ID);
  183. entity.RegionNo = model.RegionNo;
  184. entity.FamilyAddress = model.FamilyAddress;
  185. entity.telephone = model.telephone;
  186. if (!string.IsNullOrEmpty(model.Photo))
  187. {
  188. entity.IsPhoto = true;
  189. entity.Photo = model.Photo;
  190. }
  191. else
  192. {
  193. entity.IsPhoto = false;
  194. entity.Photo = "";
  195. }
  196. stuInfoFreshIBLL.SaveEntity(entity.ID, entity, model.StuInfoFreshEmergePeopleEntities, model.StuInfoFreshFamilyEntities);
  197. return Success("保存成功");
  198. }
  199. /// <summary>
  200. /// 保存贷款回执码
  201. /// </summary>
  202. /// <param name="_"></param>
  203. /// <returns></returns>
  204. private Response GetSaveLoan(dynamic _)
  205. {
  206. var model = this.GetReqData<StuInfoFreshModel>();
  207. var entity = stuInfoFreshIBLL.GetStuInfoFreshEntity(model.ID);
  208. entity.StudentLoan = model.StudentLoan;
  209. entity.StudentLoanStatus = model.StudentLoanStatus;
  210. stuInfoFreshIBLL.SaveEntity(entity.ID, entity);
  211. return Success("保存成功");
  212. }
  213. /// <summary>
  214. /// 头像
  215. /// </summary>
  216. /// <param name="_"></param>
  217. /// <returns></returns>
  218. private Response GetSavePhoto(dynamic _)
  219. {
  220. var model = this.GetReqData<PhotoModel>();
  221. var folderId = Guid.NewGuid().ToString();
  222. string filePath = Config.GetValue("AnnexesFile");
  223. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  224. string FileEextension = ".png";
  225. string fileGuid = Guid.NewGuid().ToString();
  226. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.account, uploadDate, fileGuid, FileEextension);
  227. //创建文件夹
  228. string path = Path.GetDirectoryName(virtualPath);
  229. Directory.CreateDirectory(path);
  230. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  231. if (!System.IO.File.Exists(virtualPath))
  232. {
  233. //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
  234. byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
  235. FileInfo file = new FileInfo(virtualPath);
  236. FileStream fs = file.Create();
  237. fs.Write(bytes, 0, bytes.Length);
  238. fs.Close();
  239. //文件信息写入数据库
  240. fileAnnexesEntity.F_Id = fileGuid;
  241. fileAnnexesEntity.F_FileName = "userphoto.png";
  242. fileAnnexesEntity.F_FilePath = virtualPath;
  243. fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
  244. fileAnnexesEntity.F_FileExtensions = FileEextension;
  245. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  246. fileAnnexesEntity.F_CreateUserId = userInfo.userId;
  247. fileAnnexesEntity.F_CreateUserName = userInfo.realName;
  248. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  249. }
  250. var data = new
  251. {
  252. Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
  253. AnnexesFileId = fileGuid
  254. };
  255. return Success(data);
  256. }
  257. /// <summary>
  258. /// 学费查询
  259. /// </summary>
  260. /// <param name="_"></param>
  261. /// <returns></returns>
  262. private Response GetPayFeeDetail(dynamic _)
  263. {
  264. var academicAndYear = Common.GetSemesterAndYear();
  265. var finaChargesStandardList = new List<FinaChargesStandardEntity>();
  266. var stuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntityByStuNo(userInfo.account);
  267. if (stuInfoFreshData != null)
  268. {
  269. if (!string.IsNullOrEmpty(stuInfoFreshData.ClassNo) && !string.IsNullOrEmpty(stuInfoFreshData.MajorNo))
  270. {
  271. var classInfoEntity = classInfoIBLL.GetClassInfoEntityByClassNo(stuInfoFreshData.ClassNo);
  272. if (classInfoEntity != null)
  273. {
  274. finaChargesStandardList = finaChargesStandardIBLL.GetFinaChargesStandardListByMajorNoOfNotAll(stuInfoFreshData.MajorNo, academicAndYear.AcademicYearShort, academicAndYear.Semester, classInfoEntity.Grade).ToList();
  275. }
  276. }
  277. }
  278. var payFeeTotal = finaChargesStandardList.Select(x => x.Standard).Sum();
  279. var result = new
  280. {
  281. FinaChargesStandardList = finaChargesStandardList,
  282. PayFeeTotal = payFeeTotal,
  283. AcademicYearNo = academicAndYear.AcademicYearShort,
  284. Semester = academicAndYear.Semester,
  285. };
  286. return Success(result);
  287. }
  288. /// <summary>
  289. /// 根据班级查询新生列表
  290. /// <summary>
  291. /// <param name="_"></param>
  292. /// <returns></returns>
  293. public Response GetPageList(dynamic _)
  294. {
  295. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  296. var data = stuInfoFreshIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  297. var jsonData = new
  298. {
  299. rows = data,
  300. total = parameter.pagination.total,
  301. page = parameter.pagination.page,
  302. records = parameter.pagination.records
  303. };
  304. return Success(jsonData);
  305. }
  306. /// <summary>
  307. /// 获取表单数据
  308. /// <summary>
  309. /// <param name="_"></param>
  310. /// <returns></returns>
  311. public Response GetForm(dynamic _)
  312. {
  313. string keyValue = this.GetReqData();
  314. var StuInfoFreshData = stuInfoFreshIBLL.GetStuInfoFreshEntity(keyValue);
  315. var jsonData = new
  316. {
  317. StuInfoFresh = StuInfoFreshData,
  318. };
  319. return Success(jsonData);
  320. }
  321. /// <summary>
  322. /// 保存实体数据(新增、修改)
  323. /// <param name="_"></param>
  324. /// <summary>
  325. /// <returns></returns>
  326. public Response SaveForm(dynamic _)
  327. {
  328. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  329. StuInfoFreshEntity entity = parameter.strEntity.ToObject<StuInfoFreshEntity>();
  330. stuInfoFreshIBLL.SaveEntity(parameter.keyValue, entity);
  331. return Success("保存成功!");
  332. }
  333. /// <summary>
  334. /// 上传附件图片文件
  335. /// <summary>
  336. /// <returns></returns>
  337. public Response Upload(dynamic _)
  338. {
  339. var files = (List<HttpFile>)this.Context.Request.Files;
  340. var folderId = this.GetReq<FileModel>().folderId;//文件夹id=新生id
  341. var name = this.GetReq<FileModel>().name;//文件夹id=新生id
  342. string filePath = Config.GetValue("AnnexesFile");
  343. string uploadDate = DateTime.Now.ToString("yyyyMMdd");
  344. //string FileEextension = name;
  345. string FileEextension = Path.GetExtension(name);
  346. string fileGuid = Guid.NewGuid().ToString();
  347. string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension);
  348. //创建文件夹
  349. string path = Path.GetDirectoryName(virtualPath);
  350. Directory.CreateDirectory(path);
  351. AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
  352. if (!System.IO.File.Exists(virtualPath))
  353. {
  354. byte[] bytes = new byte[files[0].Value.Length];
  355. files[0].Value.Read(bytes, 0, bytes.Length);
  356. FileInfo file = new FileInfo(virtualPath);
  357. FileStream fs = file.Create();
  358. fs.Write(bytes, 0, bytes.Length);
  359. fs.Close();
  360. //文件信息写入数据库
  361. fileAnnexesEntity.F_Id = fileGuid;
  362. fileAnnexesEntity.F_FolderId = folderId;
  363. fileAnnexesEntity.F_FileName = name;
  364. fileAnnexesEntity.F_FilePath = virtualPath;
  365. fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
  366. fileAnnexesEntity.F_FileExtensions = FileEextension;
  367. fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
  368. fileAnnexesEntity.F_CreateUserId = userInfo.userId;
  369. fileAnnexesEntity.F_CreateUserName = userInfo.realName;
  370. annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
  371. }
  372. //文件地址截取到resource后
  373. //fileAnnexesEntity.F_FilePath = fileAnnexesEntity.F_FilePath.Substring(fileAnnexesEntity.F_FilePath.IndexOf("Resource"));
  374. return SuccessString(folderId);
  375. }
  376. /// <summary>
  377. /// 删除附件
  378. /// </summary>
  379. /// <param name="_"></param>
  380. /// <returns></returns>
  381. public Response DeleteFiles(dynamic _)
  382. {
  383. var fileId = this.GetReqData<FileModel>().id;
  384. AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
  385. if (fileInfoEntity != null)
  386. {
  387. //删除附件表
  388. annexesFileIBLL.DeleteEntity(fileId);
  389. //删除文件
  390. if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
  391. {
  392. System.IO.File.Delete(fileInfoEntity.F_FilePath);
  393. }
  394. //下载
  395. //if (FileDownHelper.FileExists(fileInfoEntity.F_FilePath))
  396. //{
  397. // FileDownHelper.DownLoadnew(fileInfoEntity.F_FilePath);
  398. //}
  399. }
  400. return Success("删除成功");
  401. }
  402. #region 私有类
  403. /// <summary>
  404. /// 表单实体类
  405. /// <summary>
  406. private class ReqFormEntity
  407. {
  408. public string keyValue { get; set; }
  409. public string strEntity { get; set; }
  410. }
  411. #endregion
  412. /// <summary>
  413. /// 个人信息
  414. /// </summary>
  415. public class StuInfoFreshModel
  416. {
  417. /// <summary>
  418. /// 主键
  419. /// </summary>
  420. public string ID { get; set; }
  421. /// <summary>
  422. /// 籍贯
  423. /// </summary>
  424. public string RegionNo { get; set; }
  425. /// <summary>
  426. /// 家庭住址
  427. /// </summary>
  428. public string FamilyAddress { get; set; }
  429. /// <summary>
  430. /// 联系电话
  431. /// </summary>
  432. public string telephone { get; set; }
  433. /// <summary>
  434. /// 头像地址
  435. /// </summary>
  436. public string Photo { get; set; }
  437. /// <summary>
  438. /// 贷款回执码
  439. /// </summary>
  440. public string StudentLoan { get; set; }
  441. /// <summary>
  442. /// 贷款回执码状态
  443. /// </summary>
  444. public string StudentLoanStatus { get; set; }
  445. /// <summary>
  446. /// 家庭成员
  447. /// </summary>
  448. public List<StuInfoFreshFamilyEntity> StuInfoFreshFamilyEntities { get; set; }
  449. /// <summary>
  450. /// 紧急联系人
  451. /// </summary>
  452. public List<StuInfoFreshEmergePeopleEntity> StuInfoFreshEmergePeopleEntities { get; set; }
  453. }
  454. public class PhotoModel
  455. {
  456. public string Base64Url { get; set; }
  457. public string account { get; set; }
  458. }
  459. public class FileModel
  460. {
  461. public string folderId { get; set; }
  462. public string name { get; set; }
  463. public string id { get; set; }
  464. }
  465. }
  466. }