contract_api.go 5.9 KB

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