contract_api.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * @description: 合同管理 相关API
  3. * @Author: CP
  4. * @Date: 2020-10-26 15:27:04
  5. * @FilePath: \construction_management\web\api\contract_api.go
  6. */
  7. package api
  8. import (
  9. "github.com/kataras/iris/v12"
  10. "go.mod/lib"
  11. "go.mod/services"
  12. "go.mod/web/utils"
  13. "go.mod/web/viewmodels"
  14. )
  15. type ContractApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // // 需要用的service
  19. ServiceTree services.TreeService
  20. ServiceContract services.ContractService
  21. // ServiceLogin services.LoginService
  22. // ServiceProject services.ProjectService
  23. }
  24. // @Summary 获得合同目录和标段
  25. // @Tags 合同管理
  26. // @Description 获得合同目录和标段
  27. // @Accept json
  28. // @Produce json
  29. // @Security ApiKeyAuth
  30. // @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  31. // @Router /api/contract/folder [get]
  32. func (c *ContractApi) GetFolder() {
  33. // 获得项目ID
  34. projectIdInt, err := utils.GetProjectId(c.Ctx)
  35. if err != nil {
  36. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  37. return
  38. }
  39. // 获得层级文件夹
  40. FolderData := c.ServiceTree.GetAllContract(projectIdInt)
  41. c.Ctx.JSON(iris.Map{
  42. "code": 0,
  43. "msg": "",
  44. "data": FolderData,
  45. })
  46. }
  47. // @Summary 获得合同信息
  48. // @Tags 合同管理
  49. // @Description 未设置合同项目节 返回项目节模板信息
  50. // @Accept json
  51. // @Produce json
  52. // @Security ApiKeyAuth
  53. // @Param bidsectionId path string true "标段ID"
  54. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
  55. // @Router /api/contract/income [get]
  56. func (c *ContractApi) GetIncome() {
  57. sectionData := viewmodels.TreeSectionContract{}
  58. err := c.Ctx.ReadForm(&sectionData)
  59. if err != nil {
  60. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  61. return
  62. }
  63. if sectionData.BidsectionId == "" {
  64. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  65. return
  66. }
  67. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  68. if err != nil {
  69. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  70. return
  71. }
  72. // 项目ID
  73. projectIdInt, err := utils.GetProjectId(c.Ctx)
  74. if err != nil {
  75. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  76. return
  77. }
  78. //获得合同项目节
  79. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
  80. // 1.未设置了项目节
  81. if len(sectionTree.Children) == 0 {
  82. // 返回项目节2个基础模板
  83. templateTree1 := lib.NewItemSection().TemplateTree1
  84. templateTree2 := lib.NewItemSection().TemplateTree2
  85. c.Ctx.JSON(iris.Map{
  86. "code": 0,
  87. "msg": "",
  88. "isTemplate": 1,
  89. "sectionTemplate1": templateTree1,
  90. "sectionTemplate2": templateTree2,
  91. })
  92. return
  93. //2.项目节已设置
  94. } else {
  95. // 2.已设置项目节
  96. c.Ctx.JSON(iris.Map{
  97. "code": 0,
  98. "msg": "",
  99. "isTemplate": 0,
  100. "sectionTree": sectionTree,
  101. })
  102. return
  103. // 返回项目相关所有信息
  104. }
  105. }
  106. // @Summary 获得合同详情和项目节详情
  107. // @Tags 合同管理
  108. // @Description 获得合同详情和项目节详情
  109. // @Accept json
  110. // @Produce json
  111. // @Security ApiKeyAuth
  112. // @Param id path string true "项目节ID"
  113. // @Param bidsectionId path string true "标段ID"
  114. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}"
  115. // @Router /api/contract [get]
  116. func (c *ContractApi) Get() {
  117. // 1.规则验证
  118. sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
  119. if err != nil {
  120. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  121. return
  122. }
  123. // 2.项目ID
  124. projectId, err := utils.GetProjectId(c.Ctx)
  125. if err != nil {
  126. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  127. return
  128. }
  129. // 3.标段ID
  130. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  131. if err != nil {
  132. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  133. return
  134. }
  135. // 4.树ID
  136. treeId, err := utils.GetDecryptId(sectionData.Id)
  137. if err != nil {
  138. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  139. return
  140. }
  141. // 获得项目节详情
  142. section := c.ServiceContract.Get(treeId, bidsectionId, projectId)
  143. // 该项目节 子树下是否有合同
  144. isContract := true
  145. contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId)
  146. if len(contractList) == 0 {
  147. isContract = false
  148. }
  149. // // 获得合同详情
  150. // contractId, err := utils.GetDecryptId(section.ContractId)
  151. // if err != nil {
  152. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  153. // return
  154. // }
  155. // contract := c.ServiceContract.GetContract(contractId)
  156. c.Ctx.JSON(iris.Map{
  157. "code": 0,
  158. "msg": "",
  159. "section": section,
  160. "isContract": isContract,
  161. // "contract": contract,
  162. })
  163. }
  164. // 新增合同
  165. func (c *ContractApi) PostCreate() {
  166. // // 获得模板号
  167. // sectionData, err := c.ServiceContract.ValidRuleAdd(c.Ctx)
  168. // if err != nil {
  169. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  170. // return
  171. // }
  172. // // 项目ID
  173. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  174. // if err != nil {
  175. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  176. // return
  177. // }
  178. // // 标段ID
  179. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  180. // if err != nil {
  181. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  182. // return
  183. // }
  184. // err = c.ServiceContract.Add(sectionData, bidsectionId, projectIdInt)
  185. // if err != nil {
  186. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  187. // return
  188. // }
  189. // c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  190. }