contract_section_tree_api.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 id body string true "项目节ID"
  98. // @Param bidsectionId body string true "标段ID"
  99. // @Param serial body int true "操作名称"
  100. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  101. // @Router /api/contract/section/serial/update [post]
  102. func (c *ContractApi) PostSectionSerialUpdate() {
  103. // 验证字段-项目节ID 操作类型
  104. sectionData, err := c.ServiceContract.ValidRuleSerial(c.Ctx)
  105. if err != nil {
  106. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  107. return
  108. }
  109. // 项目ID
  110. projectIdInt, err := utils.GetProjectId(c.Ctx)
  111. if err != nil {
  112. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  113. return
  114. }
  115. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  116. if err != nil {
  117. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  118. return
  119. }
  120. err = c.ServiceContract.UpdateSerial(sectionData, bidsectionId, projectIdInt)
  121. if err != nil {
  122. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  123. return
  124. }
  125. c.Ctx.JSON(iris.Map{
  126. "code": 0,
  127. "msg": "操作成功",
  128. })
  129. }
  130. // @Summary 设置合同项目节模板
  131. // @Tags 合同管理
  132. // @Description 设置合同项目节模板
  133. // @Accept json
  134. // @Produce json
  135. // @Security ApiKeyAuth
  136. // @Param templateNumber body int true "模板号" default(1)
  137. // @Param bidsectionId body string true "标段ID"
  138. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  139. // @Router /api/contract/section/template [post]
  140. func (c *ContractApi) PostSectionTemplate() {
  141. // 获得模板号
  142. sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  143. if err != nil {
  144. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  145. return
  146. }
  147. // 项目ID
  148. projectIdInt, err := utils.GetProjectId(c.Ctx)
  149. if err != nil {
  150. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  151. return
  152. }
  153. // 标段ID
  154. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  155. if err != nil {
  156. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  157. return
  158. }
  159. //获得合同项目节
  160. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
  161. // 1.未设置了项目节
  162. if len(sectionTree.Children) == 0 {
  163. err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
  164. if err != nil {
  165. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  166. return
  167. }
  168. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  169. } else {
  170. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  171. return
  172. }
  173. }
  174. // @Summary 新增 合同项目节
  175. // @Tags 合同管理
  176. // @Description 新增 合同项目节
  177. // @Accept json
  178. // @Produce json
  179. // @Security ApiKeyAuth
  180. // @Param id body string true "项目节ID"
  181. // @Param bidsectionId body string true "标段ID"
  182. // @Param name body string true "项目节名称"
  183. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  184. // @Router /api/contract/section/add [post]
  185. func (c *ContractApi) PostSectionAdd() {
  186. // 获得模板号
  187. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  188. if err != nil {
  189. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  190. return
  191. }
  192. // 项目ID
  193. projectIdInt, err := utils.GetProjectId(c.Ctx)
  194. if err != nil {
  195. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  196. return
  197. }
  198. // 标段ID
  199. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  200. if err != nil {
  201. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  202. return
  203. }
  204. err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt)
  205. if err != nil {
  206. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  207. return
  208. }
  209. c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  210. }
  211. // @Summary 修改合同项目节 名称
  212. // @Tags 合同管理
  213. // @Description 修改合同项目节 名称
  214. // @Accept json
  215. // @Produce json
  216. // @Security ApiKeyAuth
  217. // @Param id body string true "项目节ID"
  218. // @Param bidsectionId body string true "标段ID"
  219. // @Param name body string true "项目节名称"
  220. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  221. // @Router /api/contract/section/save [post]
  222. func (c *ContractApi) PostSectionSave() {
  223. // 获得模板号
  224. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  225. if err != nil {
  226. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  227. return
  228. }
  229. // 项目ID
  230. projectIdInt, err := utils.GetProjectId(c.Ctx)
  231. if err != nil {
  232. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  233. return
  234. }
  235. // 标段ID
  236. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  237. if err != nil {
  238. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  239. return
  240. }
  241. err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt)
  242. if err != nil {
  243. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  244. return
  245. }
  246. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  247. }
  248. // @Summary 删除 合同项目节
  249. // @Tags 合同管理
  250. // @Description 删除 合同项目节
  251. // @Accept json
  252. // @Produce json
  253. // @Security ApiKeyAuth
  254. // @Param id body string true "项目节ID"
  255. // @Param bidsectionId body string true "标段ID"
  256. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  257. // @Router /api/contract/section [delete]
  258. func (c *ContractApi) DeleteSection() {
  259. // 获得模板号
  260. sectionData, err := c.ServiceContract.ValidRuleSectionDelete(c.Ctx)
  261. if err != nil {
  262. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  263. return
  264. }
  265. // 项目ID
  266. projectIdInt, err := utils.GetProjectId(c.Ctx)
  267. if err != nil {
  268. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  269. return
  270. }
  271. // 标段ID
  272. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  273. if err != nil {
  274. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  275. return
  276. }
  277. // 项目节ID
  278. treeId, err := utils.GetDecryptId(sectionData.Id)
  279. if err != nil {
  280. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  281. return
  282. }
  283. err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt)
  284. if err != nil {
  285. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  286. return
  287. }
  288. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
  289. }