contract_section_tree_api.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * @description: 合同管理 -项目节相关API
  3. * @Author: CP
  4. * @Date: 2020-10-26 15:27:04
  5. * @FilePath: \construction_management\web\api\contract_section_tree_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/web/utils"
  12. )
  13. // @Summary 升级降级合同项目节
  14. // @Tags 合同管理
  15. // @Description operation{upDepth,downDepth}
  16. // @Accept json
  17. // @Produce json
  18. // @Security ApiKeyAuth
  19. // @Param id body string true "项目节ID"
  20. // @Param bidsectionId body string true "标段ID"
  21. // @Param operation body string true "操作名称" default(upDepth)
  22. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  23. // @Router /api/contract/section/depth [post]
  24. func (c *ContractApi) PostSectionDepth() {
  25. // 验证字段-项目节ID 操作类型
  26. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  27. if err != nil {
  28. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  29. return
  30. }
  31. // 项目ID
  32. projectIdInt, err := utils.GetProjectId(c.Ctx)
  33. if err != nil {
  34. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  35. return
  36. }
  37. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  38. if err != nil {
  39. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  40. return
  41. }
  42. err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt)
  43. if err != nil {
  44. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  45. return
  46. }
  47. c.Ctx.JSON(iris.Map{
  48. "code": 0,
  49. "msg": "操作成功",
  50. })
  51. }
  52. // @Summary 上移下移合同项目节
  53. // @Tags 合同管理
  54. // @Description operation{upSerial,downSerial}
  55. // @Accept json
  56. // @Produce json
  57. // @Security ApiKeyAuth
  58. // @Param id body string true "项目节ID"
  59. // @Param bidsectionId body string true "标段ID"
  60. // @Param operation body string true "操作名称" default(upSerial)
  61. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  62. // @Router /api/contract/section/serial [post]
  63. func (c *ContractApi) PostSectionSerial() {
  64. // 验证字段-项目节ID 操作类型
  65. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  66. if err != nil {
  67. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  68. return
  69. }
  70. // 项目ID
  71. projectIdInt, err := utils.GetProjectId(c.Ctx)
  72. if err != nil {
  73. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  74. return
  75. }
  76. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  77. if err != nil {
  78. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  79. return
  80. }
  81. err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
  82. if err != nil {
  83. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  84. return
  85. }
  86. c.Ctx.JSON(iris.Map{
  87. "code": 0,
  88. "msg": "操作成功",
  89. })
  90. }
  91. // @Summary 设置合同项目节模板
  92. // @Tags 合同管理
  93. // @Description 设置合同项目节模板
  94. // @Accept json
  95. // @Produce json
  96. // @Security ApiKeyAuth
  97. // @Param templateNumber body int true "模板号" default(1)
  98. // @Param bidsectionId body string true "标段ID"
  99. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  100. // @Router /api/contract/section/template [post]
  101. func (c *ContractApi) PostSectionTemplate() {
  102. // 获得模板号
  103. sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  104. if err != nil {
  105. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  106. return
  107. }
  108. // 项目ID
  109. projectIdInt, err := utils.GetProjectId(c.Ctx)
  110. if err != nil {
  111. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  112. return
  113. }
  114. // 标段ID
  115. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  116. if err != nil {
  117. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  118. return
  119. }
  120. //获得合同项目节
  121. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
  122. // 1.未设置了项目节
  123. if len(sectionTree.Children) == 0 {
  124. err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
  125. if err != nil {
  126. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  127. return
  128. }
  129. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  130. } else {
  131. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  132. return
  133. }
  134. }
  135. // @Summary 新增 合同项目节
  136. // @Tags 合同管理
  137. // @Description 新增 合同项目节
  138. // @Accept json
  139. // @Produce json
  140. // @Security ApiKeyAuth
  141. // @Param id body string true "项目节ID"
  142. // @Param bidsectionId body string true "标段ID"
  143. // @Param name body string true "项目节名称"
  144. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  145. // @Router /api/contract/section/add [post]
  146. func (c *ContractApi) PostSectionAdd() {
  147. // 获得模板号
  148. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  149. if err != nil {
  150. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  151. return
  152. }
  153. // 项目ID
  154. projectIdInt, err := utils.GetProjectId(c.Ctx)
  155. if err != nil {
  156. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  157. return
  158. }
  159. // 标段ID
  160. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  161. if err != nil {
  162. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  163. return
  164. }
  165. err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt)
  166. if err != nil {
  167. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  168. return
  169. }
  170. c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  171. }
  172. // @Summary 修改合同项目节 名称
  173. // @Tags 合同管理
  174. // @Description 修改合同项目节 名称
  175. // @Accept json
  176. // @Produce json
  177. // @Security ApiKeyAuth
  178. // @Param id body string true "项目节ID"
  179. // @Param bidsectionId body string true "标段ID"
  180. // @Param name body string true "项目节名称"
  181. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  182. // @Router /api/contract/section/save [post]
  183. func (c *ContractApi) PostSectionSave() {
  184. // 获得模板号
  185. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  186. if err != nil {
  187. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  188. return
  189. }
  190. // 项目ID
  191. projectIdInt, err := utils.GetProjectId(c.Ctx)
  192. if err != nil {
  193. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  194. return
  195. }
  196. // 标段ID
  197. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  198. if err != nil {
  199. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  200. return
  201. }
  202. err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt)
  203. if err != nil {
  204. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  205. return
  206. }
  207. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  208. }
  209. // @Summary 删除 合同项目节
  210. // @Tags 合同管理
  211. // @Description 删除 合同项目节
  212. // @Accept json
  213. // @Produce json
  214. // @Security ApiKeyAuth
  215. // @Param id body string true "项目节ID"
  216. // @Param bidsectionId body string true "标段ID"
  217. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  218. // @Router /api/contract/section [delete]
  219. func (c *ContractApi) DeleteSection() {
  220. // 获得模板号
  221. sectionData, err := c.ServiceContract.ValidRuleSectionDelete(c.Ctx)
  222. if err != nil {
  223. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  224. return
  225. }
  226. // 项目ID
  227. projectIdInt, err := utils.GetProjectId(c.Ctx)
  228. if err != nil {
  229. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  230. return
  231. }
  232. // 标段ID
  233. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  234. if err != nil {
  235. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  236. return
  237. }
  238. // 项目节ID
  239. treeId, err := utils.GetDecryptId(sectionData.Id)
  240. if err != nil {
  241. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  242. return
  243. }
  244. err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt)
  245. if err != nil {
  246. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  247. return
  248. }
  249. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
  250. }