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/iris-contrib/middleware/jwt"
  11. "github.com/kataras/iris/v12"
  12. "go.mod/web/utils"
  13. )
  14. // @Summary 升级降级合同项目节
  15. // @Tags 合同管理-项目节
  16. // @Description operation{upDepth,downDepth}
  17. // @Accept json
  18. // @Produce json
  19. // @Security ApiKeyAuth
  20. // @Param id 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. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  43. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  44. // return
  45. // }
  46. err = c.ServiceContract.MoveDepth(sectionData)
  47. if err != nil {
  48. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  49. return
  50. }
  51. //2.请求当前项目信息
  52. // 1.验证项目节ID
  53. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  54. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  55. c.Ctx.JSON(iris.Map{
  56. "code": 0,
  57. "msg": "操作成功",
  58. })
  59. }
  60. // @Summary 上移下移合同项目节
  61. // @Tags 合同管理-项目节
  62. // @Description operation{upSerial,downSerial}
  63. // @Accept json
  64. // @Produce json
  65. // @Security ApiKeyAuth
  66. // @Param id body string true "项目节ID"
  67. // @Param operation body string true "操作名称" default(upSerial)
  68. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  69. // @Router /api/contract/section/serial [post]
  70. func (c *ContractApi) PostSectionSerial() {
  71. // 验证字段-项目节ID 操作类型
  72. sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
  73. if err != nil {
  74. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  75. return
  76. }
  77. // 项目ID
  78. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  79. // if err != nil {
  80. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  81. // return
  82. // }
  83. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  84. // if err != nil {
  85. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  86. // return
  87. // }
  88. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  89. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  90. // return
  91. // }
  92. err = c.ServiceContract.MoveSerial(sectionData)
  93. if err != nil {
  94. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  95. return
  96. }
  97. //2.请求当前项目信息
  98. // 1.验证项目节ID
  99. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  100. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  101. c.Ctx.JSON(iris.Map{
  102. "code": 0,
  103. "msg": "操作成功",
  104. // "section": sectionDetail,
  105. })
  106. }
  107. // @Summary 更新合同节序号
  108. // @Tags 合同管理-项目节
  109. // @Description
  110. // @Accept json
  111. // @Produce json
  112. // @Security ApiKeyAuth
  113. // @Param id body string true "项目节ID"
  114. // @Param serial body int true "操作名称"
  115. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  116. // @Router /api/contract/section/serial/update [post]
  117. func (c *ContractApi) PostSectionSerialUpdate() {
  118. // 验证字段-项目节ID 操作类型
  119. sectionData, err := c.ServiceContract.ValidRuleSerial(c.Ctx)
  120. if err != nil {
  121. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  122. return
  123. }
  124. // 项目ID
  125. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  126. // if err != nil {
  127. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  128. // return
  129. // }
  130. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  131. // if err != nil {
  132. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  133. // return
  134. // }
  135. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  136. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  137. // return
  138. // }
  139. err = c.ServiceContract.UpdateSerial(sectionData)
  140. if err != nil {
  141. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  142. return
  143. }
  144. //2.请求当前项目信息
  145. // 1.验证项目节ID
  146. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  147. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  148. c.Ctx.JSON(iris.Map{
  149. "code": 0,
  150. "msg": "操作成功",
  151. // "section": sectionDetail,
  152. })
  153. }
  154. // @Summary 设置合同项目节模板
  155. // @Tags 合同管理-项目节
  156. // @Description 设置合同项目节模板
  157. // @Accept json
  158. // @Produce json
  159. // @Security ApiKeyAuth
  160. // @Param templateNumber body int true "模板号" default(1)
  161. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  162. // @Router /api/contract/section/template [post]
  163. func (c *ContractApi) PostSectionTemplate() {
  164. // 获得模板号
  165. // sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
  166. // if err != nil {
  167. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  168. // return
  169. // }
  170. // 项目ID
  171. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  172. // if err != nil {
  173. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  174. // return
  175. // }
  176. // 标段ID
  177. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  178. // if err != nil {
  179. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  180. // return
  181. // }
  182. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  183. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  184. // return
  185. // }
  186. //获得合同项目节
  187. // sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, sectionData.TreeType)
  188. err := c.ServiceContract.SetSection()
  189. if err != nil {
  190. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  191. return
  192. }
  193. if err != nil {
  194. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  195. }
  196. c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
  197. // 1.未设置了项目节
  198. // if len(sectionTree.Children) == 0 {
  199. // } else {
  200. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
  201. // return
  202. // }
  203. }
  204. // @Summary 新增 合同项目节
  205. // @Tags 合同管理-项目节
  206. // @Description 新增 合同项目节
  207. // @Accept json
  208. // @Produce json
  209. // @Security ApiKeyAuth
  210. // @Param id body string true "项目节ID"
  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. fmt.Println(userMsg)
  223. // 项目ID
  224. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  225. // if err != nil {
  226. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  227. // return
  228. // }
  229. // // 标段ID
  230. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  231. // if err != nil {
  232. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  233. // return
  234. // }
  235. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  236. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  237. // return
  238. // }
  239. _, err = c.ServiceContract.SectionAdd(sectionData)
  240. if err != nil {
  241. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  242. return
  243. }
  244. c.Ctx.JSON(iris.Map{"code": 0, "msg": "新增成功"})
  245. }
  246. // @Summary 修改合同项目节 名称
  247. // @Tags 合同管理-项目节
  248. // @Description 修改合同项目节 名称
  249. // @Accept json
  250. // @Produce json
  251. // @Security ApiKeyAuth
  252. // @Param id body string true "项目节ID"
  253. // @Param name 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. }