contract_api.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/services"
  13. "go.mod/web/utils"
  14. "go.mod/web/viewmodels"
  15. )
  16. type ContractApi struct {
  17. //框架-web应用上下文环境
  18. Ctx iris.Context
  19. // // 需要用的service
  20. ServiceTree services.TreeService
  21. ServiceContract services.ContractService
  22. // ServiceLogin services.LoginService
  23. // ServiceProject services.ProjectService
  24. }
  25. // @Summary 获得合同目录和标段
  26. // @Tags 合同管理
  27. // @Description 获得合同目录和标段
  28. // @Accept json
  29. // @Produce json
  30. // @Security ApiKeyAuth
  31. // @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  32. // @Router /api/contract [get]
  33. func (c *ContractApi) Get() {
  34. // 获得项目ID
  35. projectIdInt, err := utils.GetProjectId(c.Ctx)
  36. if err != nil {
  37. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  38. return
  39. }
  40. // 获得层级文件夹
  41. FolderData := c.ServiceTree.GetAllContract(projectIdInt)
  42. c.Ctx.JSON(iris.Map{
  43. "code": 0,
  44. "msg": "",
  45. "data": FolderData,
  46. })
  47. }
  48. // @Summary 获得合同信息
  49. // @Tags 合同管理
  50. // @Description 未设置合同项目节 返回项目节模板信息
  51. // @Accept json
  52. // @Produce json
  53. // @Security ApiKeyAuth
  54. // @Param bidsectionId path string true "标段ID"
  55. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
  56. // @Router /api/contract/income [get]
  57. func (c *ContractApi) GetIncome() {
  58. sectionData := viewmodels.TreeSectionContract{}
  59. err := c.Ctx.ReadForm(&sectionData)
  60. if err != nil {
  61. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  62. return
  63. }
  64. if sectionData.BidsectionId == "" {
  65. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  66. return
  67. }
  68. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  69. if err != nil {
  70. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  71. return
  72. }
  73. // 项目ID
  74. projectIdInt, err := utils.GetProjectId(c.Ctx)
  75. if err != nil {
  76. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  77. return
  78. }
  79. //获得合同项目节
  80. sectionTree := c.ServiceContract.GetSeciontTree(bidsectionId, projectIdInt)
  81. // 1.未设置了项目节
  82. if len(sectionTree.Children) == 0 {
  83. // 返回项目节2个基础模板
  84. templateTree1 := lib.NewItemSection().TemplateTree1
  85. templateTree2 := lib.NewItemSection().TemplateTree2
  86. c.Ctx.JSON(iris.Map{
  87. "code": 0,
  88. "msg": "",
  89. "isTemplate": 1,
  90. "sectionTemplate1": templateTree1,
  91. "sectionTemplate2": templateTree2,
  92. })
  93. return
  94. //2.项目节已设置
  95. } else {
  96. // 2.已设置项目节
  97. c.Ctx.JSON(iris.Map{
  98. "code": 0,
  99. "msg": "",
  100. "isTemplate": 0,
  101. "sectionTree": sectionTree,
  102. })
  103. return
  104. // 返回项目相关所有信息
  105. }
  106. }
  107. // @Summary 升级降级合同项目节
  108. // @Tags 合同管理
  109. // @Description operation{upDepth,downDepth}
  110. // @Accept json
  111. // @Produce json
  112. // @Security ApiKeyAuth
  113. // @Param id body string true "项目节ID"
  114. // @Param bidsectionId body string true "标段ID"
  115. // @Param operation body string true "操作名称" default(upDepth)
  116. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  117. // @Router /api/contract/section/depth [post]
  118. func (c *ContractApi) PostSectionDepth() {
  119. // 验证字段-项目节ID 操作类型
  120. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  121. if err != nil {
  122. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  123. return
  124. }
  125. // 项目ID
  126. projectIdInt, err := utils.GetProjectId(c.Ctx)
  127. if err != nil {
  128. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  129. return
  130. }
  131. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  132. if err != nil {
  133. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  134. return
  135. }
  136. err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt)
  137. if err != nil {
  138. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  139. return
  140. }
  141. c.Ctx.JSON(iris.Map{
  142. "code": 0,
  143. "msg": "操作成功",
  144. })
  145. }
  146. // @Summary 上移下移合同项目节
  147. // @Tags 合同管理
  148. // @Description operation{upSerial,downSerial}
  149. // @Accept json
  150. // @Produce json
  151. // @Security ApiKeyAuth
  152. // @Param id body string true "项目节ID"
  153. // @Param bidsectionId body string true "标段ID"
  154. // @Param operation body string true "操作名称" default(upSerial)
  155. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  156. // @Router /api/contract/section/serial [post]
  157. func (c *ContractApi) PostSectionSerial() {
  158. // 验证字段-项目节ID 操作类型
  159. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  160. if err != nil {
  161. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  162. return
  163. }
  164. // 项目ID
  165. projectIdInt, err := utils.GetProjectId(c.Ctx)
  166. if err != nil {
  167. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  168. return
  169. }
  170. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  171. if err != nil {
  172. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  173. return
  174. }
  175. err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
  176. if err != nil {
  177. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  178. return
  179. }
  180. c.Ctx.JSON(iris.Map{
  181. "code": 0,
  182. "msg": "操作成功",
  183. })
  184. }
  185. // 修改合同项目节号
  186. func (c *ContractApi) PostSectionSave() {
  187. }
  188. // @Summary 设置合同项目节模板
  189. // @Tags 合同管理
  190. // @Description 设置合同项目节模板
  191. // @Accept json
  192. // @Produce json
  193. // @Security ApiKeyAuth
  194. // @Param templateNumber body int true "模板号" default(1)
  195. // @Param bidsectionId body string true "标段ID"
  196. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  197. // @Router /api/contract/section/template [post]
  198. func (c *ContractApi) PostSectionTemplate() {
  199. // 获得模板号
  200. sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  201. if err != nil {
  202. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  203. return
  204. }
  205. // 项目ID
  206. projectIdInt, err := utils.GetProjectId(c.Ctx)
  207. if err != nil {
  208. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  209. return
  210. }
  211. // 标段ID
  212. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  213. if err != nil {
  214. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  215. return
  216. }
  217. //获得合同项目节
  218. sectionTree := c.ServiceContract.GetSeciontTree(bidsectionId, projectIdInt)
  219. // 1.未设置了项目节
  220. if len(sectionTree.Children) == 0 {
  221. err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
  222. if err != nil {
  223. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  224. return
  225. }
  226. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  227. } else {
  228. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  229. return
  230. }
  231. }