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.
 
 
 
 
 
 

204 lines
7.6 KiB

  1. using Learun.Application.Base.AuthorizeModule;
  2. using Learun.Application.Base.SystemModule;
  3. using Learun.Application.Organization;
  4. using Learun.Application.TwoDevelopment.LogisticsManagement;
  5. using Learun.Application.TwoDevelopment.LR_Desktop;
  6. using Learun.Util;
  7. using Nancy;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Web;
  12. namespace Learun.Application.WebApi
  13. {
  14. /// <summary>
  15. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  16. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  17. /// 创 建:超级管理员
  18. /// 日 期:2020-06-03 14:29
  19. /// 描 述:系部数据
  20. /// </summary>
  21. public class RepairReportStudentApi : BaseApi
  22. {
  23. private RepairReportStudentIBLL repairreportStudentIBLL = new RepairReportStudentBLL();
  24. private MessageRindIBLL messageRindIBLL = new MessageRindBLL();
  25. private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  26. private DataItemIBLL dataItemIBLL = new DataItemBLL();
  27. private UserIBLL userIbll = new UserBLL();
  28. private RoleIBLL roleIBLL = new RoleBLL();
  29. /// <summary>
  30. /// 注册接口
  31. /// <summary>
  32. public RepairReportStudentApi()
  33. : base("/learun/adms/repairreportStudent")
  34. {
  35. Get["/pagelist"] = GetPageList;
  36. Get["/form"] = GetForm;
  37. Post["/delete"] = DeleteForm;
  38. Post["/save"] = SaveForm;
  39. Post["/submit"] = Submit;
  40. }
  41. #region 获取数据
  42. /// <summary>
  43. /// 获取页面显示列表分页数据
  44. /// <summary>
  45. /// <param name="_"></param>
  46. /// <returns></returns>
  47. public Response GetPageList(dynamic _)
  48. {
  49. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  50. var data = repairreportStudentIBLL.GetPageList(parameter.pagination, parameter.queryJson);
  51. var jsonData = new
  52. {
  53. rows = data,
  54. total = parameter.pagination.total,
  55. page = parameter.pagination.page,
  56. records = parameter.pagination.records
  57. };
  58. return Success(jsonData);
  59. }
  60. /// <summary>
  61. /// 获取表单数据
  62. /// <summary>
  63. /// <param name="_"></param>
  64. /// <returns></returns>
  65. public Response GetForm(dynamic _)
  66. {
  67. string keyValue = this.GetReqData();
  68. var RepairReport_StudentData = repairreportStudentIBLL.GetRepairReport_StudentEntity(keyValue);
  69. var jsonData = new
  70. {
  71. RepairReport_Student = RepairReport_StudentData,
  72. };
  73. return Success(jsonData);
  74. }
  75. #endregion
  76. #region 提交数据
  77. /// <summary>
  78. /// 删除实体数据
  79. /// <param name="_"></param>
  80. /// <summary>
  81. /// <returns></returns>
  82. public Response DeleteForm(dynamic _)
  83. {
  84. string keyValue = this.GetReqData();
  85. repairreportStudentIBLL.DeleteEntity(keyValue);
  86. return Success("删除成功!");
  87. }
  88. /// <summary>
  89. /// 保存实体数据(新增、修改)
  90. /// <param name="_"></param>
  91. /// <summary>
  92. /// <returns></returns>
  93. public Response SaveForm(dynamic _)
  94. {
  95. ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
  96. RepairReport_StudentEntity entity = parameter.strEntity.ToObject<RepairReport_StudentEntity>();
  97. if (string.IsNullOrWhiteSpace(entity.Contact)) return Fail("联系电话不能为空!");
  98. if(entity.Status==2 && string.IsNullOrWhiteSpace(entity.Repairname)) return Fail("维修人不能为空!");
  99. repairreportStudentIBLL.SaveEntity(parameter.keyValue, entity);
  100. //entity.Status = 2;
  101. if (entity.Status == 2)
  102. {
  103. var model = repairreportStudentIBLL.GetRepairReport_StudentEntity(parameter.keyValue);
  104. //获取所有的维修员账号并添加
  105. var userList = userIbll.GetListByUserIds(model.Creator);
  106. List<DataItemDetailEntity> datalist = dataItemIBLL.GetDetailList("repairtype", "");
  107. string servicevalue = datalist.Where(c => c.F_ItemValue == model.ServiceType).FirstOrDefault().F_ItemName;
  108. string content = "您发起" + model.Address + "-" + servicevalue + "维修请求已处理,请评价。";
  109. addmessagerind(userList, model, content, "评价通知");
  110. }
  111. return Success("保存成功!");
  112. }
  113. /// <summary>
  114. /// 提交
  115. /// <param name="_"></param>
  116. /// <summary>
  117. /// <returns></returns>
  118. public Response Submit(dynamic _)
  119. {
  120. string keyValue = this.GetReqData();
  121. //repairreportStudentIBLL.ModifyStatus(keyValue, 1,"");
  122. int existcount = repairreportStudentIBLL.Waitevaluatecount();
  123. if (existcount > 0)
  124. {
  125. return Fail("您有待评价的保修单,请评价后在提交!");
  126. }
  127. //修改状态
  128. repairreportStudentIBLL.ModifyStatus(keyValue, 1, "");
  129. var model = repairreportStudentIBLL.GetRepairReport_StudentEntity(keyValue);
  130. //向所有维修员发消息
  131. var MaintainRoleId = Config.GetValue("MaintainRoleId");
  132. var data = userRelationIBLL.GetUserIdList(MaintainRoleId);
  133. string userIds = "";
  134. foreach (var item in data)
  135. {
  136. if (userIds != "")
  137. {
  138. userIds += ",";
  139. }
  140. userIds += item.F_UserId;
  141. }
  142. //获取所有的维修员账号并添加
  143. var userList = userIbll.GetListByUserIds(userIds);
  144. List<DataItemDetailEntity> datalist = dataItemIBLL.GetDetailList("repairtype", "");
  145. string servicevalue = datalist.Where(c => c.F_ItemValue == model.ServiceType).FirstOrDefault().F_ItemName;
  146. string content = model.DeptName + model.CreatorName + "发起" + model.Address + "-" + servicevalue + "维修请求。";
  147. addmessagerind(userList, model, content);
  148. return Success("提交成功!");
  149. }
  150. #endregion
  151. #region 私有类
  152. /// <summary>
  153. /// 表单实体类
  154. /// <summary>
  155. private class ReqFormEntity
  156. {
  157. public string keyValue { get; set; }
  158. public string strEntity { get; set; }
  159. public string DetailList { get; set; }
  160. }
  161. #endregion
  162. #region 插入提醒公告
  163. private void addmessagerind(List<UserEntity> userList, RepairReport_StudentEntity model, string content, string title = "维修通知")
  164. {
  165. foreach (var userinfo in userList)
  166. {
  167. //站内通知逻辑
  168. MessageRemindEntity entity = new MessageRemindEntity();
  169. entity.ReceiptId = userinfo.F_UserId;
  170. entity.ReceiptName = userinfo.F_RealName;
  171. entity.SenderId = model.Creator;
  172. entity.SenderName = model.CreatorName;
  173. entity.TheTitle = title;
  174. entity.TheContent = content;
  175. entity.InstanceId = model.ID;
  176. entity.ConnectionUrl = "/LogisticsManagement/RepairReportStudent/FormView?keyValue=";
  177. entity.SendTime = DateTime.Now;
  178. entity.ReadSigns = false;
  179. messageRindIBLL.SaveEntity("", entity);
  180. }
  181. }
  182. #endregion
  183. }
  184. }