contract_section_tree_api.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. // @Param code2 body string true "编号名称"
  255. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  256. // @Router /api/contract/section/save [post]
  257. func (c *ContractApi) PostSectionSave() {
  258. // 获得模板号
  259. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  260. if err != nil {
  261. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  262. return
  263. }
  264. // 项目ID
  265. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  266. // if err != nil {
  267. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  268. // return
  269. // }
  270. // // 标段ID
  271. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  272. // if err != nil {
  273. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  274. // return
  275. // }
  276. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  277. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  278. // return
  279. // }
  280. err = c.ServiceContract.SectionSave(sectionData)
  281. if err != nil {
  282. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  283. return
  284. }
  285. //2.请求当前项目信息
  286. // 1.验证项目节ID
  287. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  288. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
  289. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  290. }
  291. // @Summary 修改合同项目节 编号
  292. // @Tags 合同管理-项目节
  293. // @Description 修改合同项目节 编号
  294. // @Accept json
  295. // @Produce json
  296. // @Security ApiKeyAuth
  297. // @Param id body string true "项目节ID"
  298. // @Param bidsectionId body string true "标段ID"
  299. // @Param treeType body string true "项目节类型(0收入1支出) 不传为0" default(0)
  300. // @Param code body string true "项目节名称"
  301. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  302. // @Router /api/contract/section/code [post]
  303. func (c *ContractApi) PostSectionCode() {
  304. // 获得模板号
  305. sectionData, err := c.ServiceContract.ValidRuleSectionAdd(c.Ctx)
  306. if err != nil {
  307. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  308. return
  309. }
  310. // 项目ID
  311. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  312. // if err != nil {
  313. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  314. // return
  315. // }
  316. // 标段ID
  317. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  318. // if err != nil {
  319. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  320. // return
  321. // }
  322. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  323. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  324. // return
  325. // }
  326. err = c.ServiceContract.SectionSave(sectionData)
  327. if err != nil {
  328. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  329. return
  330. }
  331. //2.请求当前项目信息
  332. // 1.验证项目节ID
  333. // treeId, _ := utils.GetDecryptId(sectionData.Id)
  334. // sectionDetail := c.ServiceContract.Get(treeId)
  335. c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功"})
  336. }
  337. // @Summary 删除 合同项目节
  338. // @Tags 合同管理-项目节
  339. // @Description 删除 合同项目节
  340. // @Accept json
  341. // @Produce json
  342. // @Security ApiKeyAuth
  343. // @Param id body string true "项目节ID"
  344. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  345. // @Router /api/contract/section [delete]
  346. func (c *ContractApi) DeleteSection() {
  347. // 获得模板号-=1
  348. sectionData, err := c.ServiceContract.ValidRuleSectionDelete(c.Ctx)
  349. if err != nil {
  350. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  351. return
  352. }
  353. // 项目ID
  354. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  355. // if err != nil {
  356. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  357. // return
  358. // }
  359. // // 标段ID
  360. // bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  361. // if err != nil {
  362. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  363. // return
  364. // }
  365. // 项目节ID
  366. treeId, err := utils.GetDecryptId(sectionData.Id)
  367. if err != nil {
  368. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  369. return
  370. }
  371. // if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
  372. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
  373. // return
  374. // }
  375. err = c.ServiceContract.SectionDelete(treeId)
  376. if err != nil {
  377. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  378. return
  379. }
  380. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功"})
  381. }
  382. // @Summary 保存 项目节附件
  383. // @Tags 合同管理-项目节
  384. // @Description 附件 合同项目节
  385. // @Accept json
  386. // @Produce json
  387. // @Security ApiKeyAuth
  388. // @Param id body string true "项目节ID"
  389. // @Param fid body string true "附件id"
  390. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  391. // @Router /api/contract/file [post]
  392. func (c *ContractApi) PostFile() {
  393. sectionData, err := c.ServiceContract.ValidRuleUpdateFile(c.Ctx)
  394. if err != nil {
  395. c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
  396. return
  397. }
  398. // 项目节ID
  399. treeId, err := utils.GetDecryptId(sectionData.Id)
  400. if err != nil {
  401. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  402. return
  403. }
  404. // 项目节ID
  405. contractId, err := utils.GetDecryptId(sectionData.ContractId)
  406. if err != nil {
  407. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  408. return
  409. }
  410. err = c.ServiceContract.UpdateContractId(treeId, contractId)
  411. if err != nil {
  412. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  413. return
  414. }
  415. c.Ctx.JSON(iris.Map{"code": 0, "msg": "保存成功"})
  416. }