Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

148 linhas
4.8 KiB

  1. using Learun.Application.Form;
  2. using Nancy;
  3. using System.Collections.Generic;
  4. namespace Learun.Application.WebApi.Modules
  5. {
  6. /// <summary>
  7. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  8. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  9. /// 创建人:数字化智慧校园-框架开发组
  10. /// 日 期:2018.01.03
  11. /// 描 述:自定义表单处理接口
  12. /// </summary>
  13. public class FormApi: BaseApi
  14. {
  15. /// <summary>
  16. /// 注册接口
  17. /// </summary>
  18. public FormApi()
  19. : base("/learun/adms/form")
  20. {
  21. Get["/scheme"] = GetScheme;
  22. Get["/data"] = GetData;
  23. Post["/save"] = Save;
  24. Post["/delete"] = DeleteForm;
  25. }
  26. private FormSchemeIBLL formSchemeIBLL = new FormSchemeBLL();
  27. /// <summary>
  28. /// 获取表单模板数据
  29. /// </summary>
  30. /// <param name="_"></param>
  31. /// <returns></returns>
  32. private Response GetScheme(dynamic _)
  33. {
  34. List<SchemeReq> req = this.GetReqData<List<SchemeReq>>();// 获取模板请求数据
  35. Dictionary<string,FormSchemeEntity> schemeList = new Dictionary<string,FormSchemeEntity>();
  36. foreach (var item in req) {
  37. FormSchemeInfoEntity schemeInfoEntity = formSchemeIBLL.GetSchemeInfoEntity(item.id);
  38. if (schemeInfoEntity != null) {
  39. FormSchemeEntity schemeEntity = formSchemeIBLL.GetSchemeEntity(schemeInfoEntity.F_SchemeId);
  40. if (schemeEntity != null) {
  41. if (schemeInfoEntity.F_SchemeId != item.ver)
  42. {
  43. schemeList.Add(item.id, schemeEntity);
  44. }
  45. }
  46. }
  47. }
  48. return Success(schemeList);
  49. }
  50. /// <summary>
  51. /// 获取自定义表单数据
  52. /// </summary>
  53. /// <param name="_"></param>
  54. /// <returns></returns>
  55. public Response GetData(dynamic _)
  56. {
  57. List<FormParam> req = this.GetReqData<List<FormParam>>();// 获取模板请求数据
  58. Dictionary<string, object> dic = new Dictionary<string, object>();
  59. foreach (var item in req)
  60. {
  61. if (string.IsNullOrEmpty(item.processIdName))
  62. {
  63. var data = formSchemeIBLL.GetInstanceForm(item.schemeInfoId, item.keyValue);
  64. dic.Add(item.schemeInfoId, data);
  65. }
  66. else
  67. {
  68. var data = formSchemeIBLL.GetInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue);//
  69. dic.Add(item.schemeInfoId, data);
  70. }
  71. }
  72. return Success(dic);
  73. }
  74. /// <summary>
  75. /// 保存表单数据
  76. /// </summary>
  77. /// <param name="_"></param>
  78. /// <returns></returns>
  79. private Response Save(dynamic _)
  80. {
  81. List<FormParam> req = this.GetReqData<List<FormParam>>();// 获取模板请求数据
  82. foreach (var item in req)
  83. {
  84. formSchemeIBLL.SaveInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue, item.formData);
  85. }
  86. return Success("保存成功");
  87. }
  88. /// <summary>
  89. /// 删除表单数据
  90. /// </summary>
  91. /// <param name="_"></param>
  92. /// <returns></returns>
  93. private Response DeleteForm(dynamic _)
  94. {
  95. FormParam req = this.GetReqData<FormParam>();// 获取模板请求数据
  96. formSchemeIBLL.DeleteInstanceForm(req.schemeInfoId, req.keyValue);
  97. return Success("删除成功");
  98. }
  99. #region 请求参数
  100. private class SchemeReq {
  101. /// <summary>
  102. /// 表单请求Id
  103. /// </summary>
  104. public string id { get; set; }
  105. /// <summary>
  106. /// 当前自定义表单版本号
  107. /// </summary>
  108. public string ver { get; set; }
  109. }
  110. /// <summary>
  111. /// 自定义表单提交参数
  112. /// </summary>
  113. private class FormParam
  114. {
  115. /// <summary>
  116. /// 流程模板id
  117. /// </summary>
  118. public string schemeInfoId { get; set; }
  119. /// <summary>
  120. /// 关联字段名称
  121. /// </summary>
  122. public string processIdName { get; set; }
  123. /// <summary>
  124. /// 数据主键值
  125. /// </summary>
  126. public string keyValue { get; set; }
  127. /// <summary>
  128. /// 表单数据
  129. /// </summary>
  130. public string formData { get; set; }
  131. }
  132. #endregion
  133. }
  134. }