contract_section_tree_api.go 16 KB

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