contract_section_tree_api.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*
  2. * @description: 合同管理 -项目节相关API
  3. * @Author: CP
  4. * @Date: 2020-10-26 15:27:04
  5. * @FilePath: \design_quantity\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 operation body string true "操作名称" default(upDepth)
  21. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  22. // @Router /api/contract/section/depth [post]
  23. func (c *ContractApi) PostSectionDepth() {
  24. // 验证字段-项目节ID 操作类型
  25. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  26. if err != nil {
  27. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  28. return
  29. }
  30. // 项目ID
  31. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  32. // if err != nil {
  33. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  34. // return
  35. // }
  36. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  37. // if err != nil {
  38. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  39. // return
  40. // }
  41. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  42. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  43. // return
  44. // }
  45. err = c.ServiceContract.MoveDepth(sectionData)
  46. if err != nil {
  47. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  48. return
  49. }
  50. //2.请求当前项目信息
  51. // 1.验证项目节ID
  52. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  53. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  54. c.Ctx.JSON(iris.Map{
  55. "code": 0,
  56. "msg": "操作成功",
  57. })
  58. }
  59. // @Summary 上移下移合同项目节
  60. // @Tags 合同管理-项目节
  61. // @Description operation{upSerial,downSerial}
  62. // @Accept json
  63. // @Produce json
  64. // @Security ApiKeyAuth
  65. // @Param id body string true "项目节ID"
  66. // @Param operation body string true "操作名称" default(upSerial)
  67. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  68. // @Router /api/contract/section/serial [post]
  69. func (c *ContractApi) PostSectionSerial() {
  70. // 验证字段-项目节ID 操作类型
  71. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  72. if err != nil {
  73. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  74. return
  75. }
  76. // 项目ID
  77. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  78. // if err != nil {
  79. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  80. // return
  81. // }
  82. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  83. // if err != nil {
  84. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  85. // return
  86. // }
  87. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  88. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  89. // return
  90. // }
  91. err = c.ServiceContract.MoveSerial(sectionData)
  92. if err != nil {
  93. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  94. return
  95. }
  96. //2.请求当前项目信息
  97. // 1.验证项目节ID
  98. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  99. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  100. c.Ctx.JSON(iris.Map{
  101. "code": 0,
  102. "msg": "操作成功",
  103. // "section": sectionDetail,
  104. })
  105. }
  106. // @Summary 更新合同节序号
  107. // @Tags 合同管理-项目节
  108. // @Description
  109. // @Accept json
  110. // @Produce json
  111. // @Security ApiKeyAuth
  112. // @Param id body string true "项目节ID"
  113. // @Param serial body int true "操作名称"
  114. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  115. // @Router /api/contract/section/serial/update [post]
  116. func (c *ContractApi) PostSectionSerialUpdate() {
  117. // 验证字段-项目节ID 操作类型
  118. sectionData, err := c.ServiceContract.ValidRuleSerial(c.Ctx)
  119. if err != nil {
  120. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  121. return
  122. }
  123. // 项目ID
  124. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  125. // if err != nil {
  126. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  127. // return
  128. // }
  129. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  130. // if err != nil {
  131. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  132. // return
  133. // }
  134. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  135. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  136. // return
  137. // }
  138. err = c.ServiceContract.UpdateSerial(sectionData)
  139. if err != nil {
  140. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  141. return
  142. }
  143. //2.请求当前项目信息
  144. // 1.验证项目节ID
  145. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  146. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  147. c.Ctx.JSON(iris.Map{
  148. "code": 0,
  149. "msg": "操作成功",
  150. // "section": sectionDetail,
  151. })
  152. }
  153. // @Summary 设置合同项目节模板
  154. // @Tags 合同管理-项目节
  155. // @Description 设置合同项目节模板
  156. // @Accept json
  157. // @Produce json
  158. // @Security ApiKeyAuth
  159. // @Param templateNumber body int true "模板号" default(1)
  160. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  161. // @Router /api/contract/section/template [post]
  162. func (c *ContractApi) PostSectionTemplate() {
  163. // 获得模板号
  164. // sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  165. // if err != nil {
  166. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  167. // return
  168. // }
  169. // 项目ID
  170. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  171. // if err != nil {
  172. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  173. // return
  174. // }
  175. // 标段ID
  176. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  177. // if err != nil {
  178. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  179. // return
  180. // }
  181. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  182. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  183. // return
  184. // }
  185. //获得合同项目节
  186. // sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, sectionData.TreeType)
  187. err := c.ServiceContract.SetSection()
  188. if err != nil {
  189. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  190. return
  191. }
  192. if err != nil {
  193. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  194. }
  195. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  196. // 1.未设置了项目节
  197. // if len(sectionTree.Children) == 0 {
  198. // } else {
  199. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  200. // return
  201. // }
  202. }
  203. // @Summary 新增 合同项目节
  204. // @Tags 合同管理-项目节
  205. // @Description 新增 合同项目节
  206. // @Accept json
  207. // @Produce json
  208. // @Security ApiKeyAuth
  209. // @Param id body string true "项目节ID"
  210. // @Param code2 body string true "图表编码"
  211. // @Param name body string true "项目节名称"
  212. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  213. // @Router /api/contract/section/add [post]
  214. func (c *ContractApi) PostSectionAdd() {
  215. // 获得模板号
  216. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  217. if err != nil {
  218. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  219. return
  220. }
  221. // userMsg := c.Ctx.Values().Get("jwt").(*jwt.Token).Claims.(jwt.MapClaims)
  222. // 项目ID
  223. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  224. // if err != nil {
  225. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  226. // return
  227. // }
  228. // // 标段ID
  229. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  230. // if err != nil {
  231. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  232. // return
  233. // }
  234. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  235. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  236. // return
  237. // }
  238. _, err = c.ServiceContract.SectionAdd(sectionData)
  239. if err != nil {
  240. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  241. return
  242. }
  243. c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  244. }
  245. // @Summary 修改合同项目节 名称
  246. // @Tags 合同管理-项目节
  247. // @Description 修改合同项目节 名称
  248. // @Accept json
  249. // @Produce json
  250. // @Security ApiKeyAuth
  251. // @Param id body string true "项目节ID"
  252. // @Param name body string true "项目节名称"
  253. // @Param code2 body string true "编号名称"
  254. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  255. // @Router /api/contract/section/save [post]
  256. func (c *ContractApi) PostSectionSave() {
  257. // 获得模板号
  258. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  259. if err != nil {
  260. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  261. return
  262. }
  263. // 项目ID
  264. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  265. // if err != nil {
  266. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  267. // return
  268. // }
  269. // // 标段ID
  270. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  271. // if err != nil {
  272. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  273. // return
  274. // }
  275. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  276. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  277. // return
  278. // }
  279. err = c.ServiceContract.SectionSave(sectionData)
  280. if err != nil {
  281. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  282. return
  283. }
  284. //2.请求当前项目信息
  285. // 1.验证项目节ID
  286. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  287. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  288. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  289. }
  290. // @Summary 修改合同项目节 编号
  291. // @Tags 合同管理-项目节
  292. // @Description 修改合同项目节 编号
  293. // @Accept json
  294. // @Produce json
  295. // @Security ApiKeyAuth
  296. // @Param id body string true "项目节ID"
  297. // @Param bidsectionId body string true "标段ID"
  298. // @Param treeType body string true "项目节类型(0收入1支出) 不传为0" default(0)
  299. // @Param code body string true "项目节名称"
  300. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  301. // @Router /api/contract/section/code [post]
  302. func (c *ContractApi) PostSectionCode() {
  303. // 获得模板号
  304. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  305. if err != nil {
  306. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  307. return
  308. }
  309. // 项目ID
  310. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  311. // if err != nil {
  312. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  313. // return
  314. // }
  315. // 标段ID
  316. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  317. // if err != nil {
  318. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  319. // return
  320. // }
  321. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  322. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  323. // return
  324. // }
  325. err = c.ServiceContract.SectionSave(sectionData)
  326. if err != nil {
  327. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  328. return
  329. }
  330. //2.请求当前项目信息
  331. // 1.验证项目节ID
  332. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  333. // sectionDetail := c.ServiceContract.Get(treeId)
  334. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  335. }
  336. // @Summary 删除 合同项目节
  337. // @Tags 合同管理-项目节
  338. // @Description 删除 合同项目节
  339. // @Accept json
  340. // @Produce json
  341. // @Security ApiKeyAuth
  342. // @Param id body string true "项目节ID"
  343. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  344. // @Router /api/contract/section [delete]
  345. func (c *ContractApi) DeleteSection() {
  346. // 获得模板号-=1
  347. sectionData, err := c.ServiceContract.ValidRuleSectionDelete(c.Ctx)
  348. if err != nil {
  349. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  350. return
  351. }
  352. // 项目ID
  353. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  354. // if err != nil {
  355. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  356. // return
  357. // }
  358. // // 标段ID
  359. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  360. // if err != nil {
  361. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  362. // return
  363. // }
  364. // 项目节ID
  365. treeId, err := utils.GetDecryptId(sectionData.Id)
  366. if err != nil {
  367. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  368. return
  369. }
  370. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  371. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  372. // return
  373. // }
  374. err = c.ServiceContract.SectionDelete(treeId)
  375. if err != nil {
  376. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  377. return
  378. }
  379. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
  380. }
  381. // @Summary 保存 项目节附件
  382. // @Tags 合同管理-项目节
  383. // @Description 附件 合同项目节
  384. // @Accept json
  385. // @Produce json
  386. // @Security ApiKeyAuth
  387. // @Param id body string true "项目节ID"
  388. // @Param fid body string true "附件id"
  389. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  390. // @Router /api/contract/file [post]
  391. func (c *ContractApi) PostFile() {
  392. sectionData, err := c.ServiceContract.ValidRuleUpdateFile(c.Ctx)
  393. if err != nil {
  394. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  395. return
  396. }
  397. // 项目节ID
  398. treeId, err := utils.GetDecryptId(sectionData.Id)
  399. if err != nil {
  400. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  401. return
  402. }
  403. // 项目节ID
  404. contractId, err := utils.GetDecryptId(sectionData.ContractId)
  405. if err != nil {
  406. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  407. return
  408. }
  409. err = c.ServiceContract.UpdateContractId(treeId, contractId)
  410. if err != nil {
  411. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  412. return
  413. }
  414. c.Ctx.JSON(iris.Map{"code": 0, "msg": "保存成功"})
  415. }