contract_section_tree_api.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. //2.请求当前项目信息
  48. // 1.验证项目节ID
  49. treeId, _ := utils.GetDecryptId(sectionData.Id)
  50. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  51. c.Ctx.JSON(iris.Map{
  52. "code": 0,
  53. "msg": "操作成功",
  54. "section": sectionDetail,
  55. })
  56. }
  57. // @Summary 上移下移合同项目节
  58. // @Tags 合同管理
  59. // @Description operation{upSerial,downSerial}
  60. // @Accept json
  61. // @Produce json
  62. // @Security ApiKeyAuth
  63. // @Param id body string true "项目节ID"
  64. // @Param bidsectionId body string true "标段ID"
  65. // @Param operation body string true "操作名称" default(upSerial)
  66. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  67. // @Router /api/contract/section/serial [post]
  68. func (c *ContractApi) PostSectionSerial() {
  69. // 验证字段-项目节ID 操作类型
  70. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  71. if err != nil {
  72. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  73. return
  74. }
  75. // 项目ID
  76. projectIdInt, err := utils.GetProjectId(c.Ctx)
  77. if err != nil {
  78. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  79. return
  80. }
  81. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  82. if err != nil {
  83. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  84. return
  85. }
  86. err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
  87. if err != nil {
  88. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  89. return
  90. }
  91. //2.请求当前项目信息
  92. // 1.验证项目节ID
  93. treeId, _ := utils.GetDecryptId(sectionData.Id)
  94. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  95. c.Ctx.JSON(iris.Map{
  96. "code": 0,
  97. "msg": "操作成功",
  98. "section": sectionDetail,
  99. })
  100. }
  101. // @Summary 更新合同节序号
  102. // @Tags 合同管理
  103. // @Description
  104. // @Accept json
  105. // @Produce json
  106. // @Security ApiKeyAuth
  107. // @Param id body string true "项目节ID"
  108. // @Param bidsectionId body string true "标段ID"
  109. // @Param serial body int true "操作名称"
  110. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  111. // @Router /api/contract/section/serial/update [post]
  112. func (c *ContractApi) PostSectionSerialUpdate() {
  113. // 验证字段-项目节ID 操作类型
  114. sectionData, err := c.ServiceContract.ValidRuleSerial(c.Ctx)
  115. if err != nil {
  116. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  117. return
  118. }
  119. // 项目ID
  120. projectIdInt, err := utils.GetProjectId(c.Ctx)
  121. if err != nil {
  122. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  123. return
  124. }
  125. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  126. if err != nil {
  127. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  128. return
  129. }
  130. err = c.ServiceContract.UpdateSerial(sectionData, bidsectionId, projectIdInt)
  131. if err != nil {
  132. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  133. return
  134. }
  135. //2.请求当前项目信息
  136. // 1.验证项目节ID
  137. treeId, _ := utils.GetDecryptId(sectionData.Id)
  138. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  139. c.Ctx.JSON(iris.Map{
  140. "code": 0,
  141. "msg": "操作成功",
  142. "section": sectionDetail,
  143. })
  144. }
  145. // @Summary 设置合同项目节模板
  146. // @Tags 合同管理
  147. // @Description 设置合同项目节模板
  148. // @Accept json
  149. // @Produce json
  150. // @Security ApiKeyAuth
  151. // @Param templateNumber body int true "模板号" default(1)
  152. // @Param bidsectionId body string true "标段ID"
  153. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  154. // @Router /api/contract/section/template [post]
  155. func (c *ContractApi) PostSectionTemplate() {
  156. // 获得模板号
  157. sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  158. if err != nil {
  159. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  160. return
  161. }
  162. // 项目ID
  163. projectIdInt, err := utils.GetProjectId(c.Ctx)
  164. if err != nil {
  165. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  166. return
  167. }
  168. // 标段ID
  169. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  170. if err != nil {
  171. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  172. return
  173. }
  174. //获得合同项目节
  175. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
  176. // 1.未设置了项目节
  177. if len(sectionTree.Children) == 0 {
  178. err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
  179. if err != nil {
  180. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  181. return
  182. }
  183. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  184. } else {
  185. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  186. return
  187. }
  188. }
  189. // @Summary 新增 合同项目节
  190. // @Tags 合同管理
  191. // @Description 新增 合同项目节
  192. // @Accept json
  193. // @Produce json
  194. // @Security ApiKeyAuth
  195. // @Param id body string true "项目节ID"
  196. // @Param bidsectionId body string true "标段ID"
  197. // @Param name body string true "项目节名称"
  198. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  199. // @Router /api/contract/section/add [post]
  200. func (c *ContractApi) PostSectionAdd() {
  201. // 获得模板号
  202. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  203. if err != nil {
  204. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  205. return
  206. }
  207. // 项目ID
  208. projectIdInt, err := utils.GetProjectId(c.Ctx)
  209. if err != nil {
  210. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  211. return
  212. }
  213. // 标段ID
  214. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  215. if err != nil {
  216. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  217. return
  218. }
  219. err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt)
  220. if err != nil {
  221. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  222. return
  223. }
  224. c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  225. }
  226. // @Summary 修改合同项目节 名称
  227. // @Tags 合同管理
  228. // @Description 修改合同项目节 名称
  229. // @Accept json
  230. // @Produce json
  231. // @Security ApiKeyAuth
  232. // @Param id body string true "项目节ID"
  233. // @Param bidsectionId body string true "标段ID"
  234. // @Param name body string true "项目节名称"
  235. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  236. // @Router /api/contract/section/save [post]
  237. func (c *ContractApi) PostSectionSave() {
  238. // 获得模板号
  239. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  240. if err != nil {
  241. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  242. return
  243. }
  244. // 项目ID
  245. projectIdInt, err := utils.GetProjectId(c.Ctx)
  246. if err != nil {
  247. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  248. return
  249. }
  250. // 标段ID
  251. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  252. if err != nil {
  253. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  254. return
  255. }
  256. err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt)
  257. if err != nil {
  258. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  259. return
  260. }
  261. //2.请求当前项目信息
  262. // 1.验证项目节ID
  263. treeId, _ := utils.GetDecryptId(sectionData.Id)
  264. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  265. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功", "section": sectionDetail})
  266. }
  267. // @Summary 删除 合同项目节
  268. // @Tags 合同管理
  269. // @Description 删除 合同项目节
  270. // @Accept json
  271. // @Produce json
  272. // @Security ApiKeyAuth
  273. // @Param id body string true "项目节ID"
  274. // @Param bidsectionId body string true "标段ID"
  275. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  276. // @Router /api/contract/section [delete]
  277. func (c *ContractApi) DeleteSection() {
  278. // 获得模板号-=1
  279. sectionData, err := c.ServiceContract.ValidRuleSectionDelete(c.Ctx)
  280. if err != nil {
  281. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  282. return
  283. }
  284. // 项目ID
  285. projectIdInt, err := utils.GetProjectId(c.Ctx)
  286. if err != nil {
  287. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  288. return
  289. }
  290. // 标段ID
  291. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  292. if err != nil {
  293. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  294. return
  295. }
  296. // 项目节ID
  297. treeId, err := utils.GetDecryptId(sectionData.Id)
  298. if err != nil {
  299. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  300. return
  301. }
  302. err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt)
  303. if err != nil {
  304. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  305. return
  306. }
  307. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
  308. }