contract_api.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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/folder [get]
  33. func (c *ContractApi) GetFolder() {
  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/section/all [get]
  57. func (c *ContractApi) GetIncomeSectionAll() {
  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.GetSecionTree(bidsectionId, projectIdInt, 0)
  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 获得合同详情和项目节详情
  110. // @Accept json
  111. // @Produce json
  112. // @Security ApiKeyAuth
  113. // @Param id path string true "项目节ID"
  114. // @Param bidsectionId path string true "标段ID"
  115. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}"
  116. // @Router /api/contract/income [get]
  117. func (c *ContractApi) GetIncome() {
  118. // 1.规则验证
  119. sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
  120. if err != nil {
  121. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  122. return
  123. }
  124. // 2.项目ID
  125. projectId, err := utils.GetProjectId(c.Ctx)
  126. if err != nil {
  127. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  128. return
  129. }
  130. // 3.标段ID
  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. // 4.树ID
  137. treeId, err := utils.GetDecryptId(sectionData.Id)
  138. if err != nil {
  139. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  140. return
  141. }
  142. // 获得项目节详情
  143. section := c.ServiceContract.Get(treeId, bidsectionId, projectId)
  144. // 该项目节 子树下是否有合同
  145. isContract := true
  146. contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 0)
  147. if len(contractList) == 0 {
  148. isContract = false
  149. }
  150. // 获得合同详情
  151. contractId, _ := utils.GetDecryptId(section.ContractId)
  152. contract := &viewmodels.Contracts{}
  153. if contractId != 0 {
  154. contract = c.ServiceContract.GetContract(contractId)
  155. }
  156. c.Ctx.JSON(iris.Map{
  157. "code": 0,
  158. "msg": "",
  159. "section": section,
  160. "isContract": isContract, //该项目节(包含子孙)下是否有合同
  161. "contract": contract,
  162. })
  163. }
  164. // @Summary 新增合同
  165. // @Tags 合同管理-收入合同
  166. // @Description 新增合同
  167. // @Accept json
  168. // @Produce json
  169. // @Security ApiKeyAuth
  170. // @Param treeId path string true "项目节ID"
  171. // @Param bidsectionId path string true "标段ID"
  172. // @Param code path string true "合同编号"
  173. // @Param name path string true "合同名称"
  174. // @Param contractsType path int true "合同类型(1)"
  175. // @Param price path string true "合同金额"
  176. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  177. // @Router /api/contract/income/create [post]
  178. func (c *ContractApi) PostIncomeCreate() {
  179. // 验证参数
  180. contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx)
  181. if err != nil {
  182. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  183. return
  184. }
  185. // 项目ID
  186. projectIdInt, err := utils.GetProjectId(c.Ctx)
  187. if err != nil {
  188. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  189. return
  190. }
  191. // 标段ID
  192. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  193. if err != nil {
  194. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  195. return
  196. }
  197. // 项目节ID
  198. treeId, err := utils.GetDecryptId(contractData.TreeId)
  199. if err != nil {
  200. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  201. return
  202. }
  203. err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, treeId)
  204. if err != nil {
  205. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  206. return
  207. }
  208. // 获得项目节
  209. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  210. // 合同ID
  211. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  212. contractDetail := c.ServiceContract.GetContract(contractId)
  213. c.Ctx.JSON(iris.Map{
  214. "code": 0,
  215. "msg": "新增成功",
  216. "contract": contractDetail,
  217. })
  218. }
  219. // @Summary 编辑合同
  220. // @Tags 合同管理-收入合同
  221. // @Description 编辑合同
  222. // @Accept json
  223. // @Produce json
  224. // @Security ApiKeyAuth
  225. // @Param id path string true "合同ID"
  226. // @Param treeId path string true "项目节ID"
  227. // @Param bidsectionId path string true "标段ID"
  228. // @Param content path string true "合同内容"
  229. // @Param name path string true "合同名称"
  230. // @Param price path string true "合同金额"
  231. // @Param partyA path string true "甲方"
  232. // @Param partyASigner path string true "甲方签约人"
  233. // @Param partyB path string true "已方"
  234. // @Param partyBSigner path string true "已方签约人"
  235. // @Param signerTime path string true "签约时间"
  236. // @Param remarks path string true "备注"
  237. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  238. // @Router /api/contract/income/update [post]
  239. func (c *ContractApi) PostIncomeUpdate() {
  240. // 验证参数
  241. contractData, err := c.ServiceContract.ValidRuleContractEdi(c.Ctx)
  242. if err != nil {
  243. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  244. return
  245. }
  246. // 项目ID
  247. projectIdInt, err := utils.GetProjectId(c.Ctx)
  248. if err != nil {
  249. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  250. return
  251. }
  252. // 标段ID
  253. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  254. if err != nil {
  255. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  256. return
  257. }
  258. // 项目节ID
  259. treeId, err := utils.GetDecryptId(contractData.TreeId)
  260. if err != nil {
  261. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  262. return
  263. }
  264. err = c.ServiceContract.Update(contractData, projectIdInt, bidsectionId, treeId)
  265. if err != nil {
  266. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  267. return
  268. }
  269. //2.请求当前项目信息
  270. // 1.验证项目节ID
  271. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  272. // 合同ID
  273. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  274. contractDetail := c.ServiceContract.GetContract(contractId)
  275. c.Ctx.JSON(iris.Map{
  276. "code": 0,
  277. "msg": "编辑成功",
  278. "section": sectionDetail,
  279. "contract": contractDetail,
  280. })
  281. }
  282. // @Summary 删除合同
  283. // @Tags 合同管理-收入合同
  284. // @Description 删除合同
  285. // @Accept json
  286. // @Produce json
  287. // @Security ApiKeyAuth
  288. // @Param id path string true "合同ID"
  289. // @Param treeId path string true "项目节ID"
  290. // @Param bidsectionId path string true "标段ID"
  291. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  292. // @Router /api/contract [delete]
  293. func (c *ContractApi) Delete() {
  294. // 验证参数
  295. contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
  296. if err != nil {
  297. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  298. return
  299. }
  300. // 项目ID
  301. projectIdInt, err := utils.GetProjectId(c.Ctx)
  302. if err != nil {
  303. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  304. return
  305. }
  306. // 标段ID
  307. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  308. if err != nil {
  309. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  310. return
  311. }
  312. // 项目节ID
  313. treeId, err := utils.GetDecryptId(contractData.TreeId)
  314. if err != nil {
  315. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  316. return
  317. }
  318. // 合同ID
  319. id, err := utils.GetDecryptId(contractData.Id)
  320. if err != nil {
  321. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  322. return
  323. }
  324. err = c.ServiceContract.Delete(projectIdInt, bidsectionId, treeId, id)
  325. if err != nil {
  326. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  327. return
  328. }
  329. //2.请求当前项目信息
  330. // 1.验证项目节ID
  331. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  332. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": sectionDetail})
  333. }
  334. // @Summary 关闭合同
  335. // @Tags 合同管理
  336. // @Description 关闭合同
  337. // @Accept json
  338. // @Produce json
  339. // @Security ApiKeyAuth
  340. // @Param id path string true "合同ID"
  341. // @Param treeId path string true "项目节ID"
  342. // @Param bidsectionId path string true "标段ID"
  343. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  344. // @Router /api/contract/close [post]
  345. func (c *ContractApi) PostClose() {
  346. // 验证参数
  347. contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
  348. if err != nil {
  349. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  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(contractData.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(contractData.TreeId)
  366. if err != nil {
  367. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  368. return
  369. }
  370. // 合同ID
  371. id, err := utils.GetDecryptId(contractData.Id)
  372. if err != nil {
  373. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  374. return
  375. }
  376. err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id)
  377. if err != nil {
  378. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  379. return
  380. }
  381. // 1.项目节信息
  382. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  383. c.Ctx.JSON(iris.Map{"code": 0, "msg": "关闭成功", "section": sectionDetail})
  384. }
  385. // @Summary 解锁合同
  386. // @Tags 合同管理
  387. // @Description 解锁合同
  388. // @Accept json
  389. // @Produce json
  390. // @Security ApiKeyAuth
  391. // @Param id path string true "合同ID"
  392. // @Param treeId path string true "项目节ID"
  393. // @Param bidsectionId path string true "标段ID"
  394. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  395. // @Router /api/contract/unlock [post]
  396. func (c *ContractApi) PostUnlock() {
  397. // 验证参数
  398. contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
  399. if err != nil {
  400. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  401. return
  402. }
  403. // 项目ID
  404. projectIdInt, err := utils.GetProjectId(c.Ctx)
  405. if err != nil {
  406. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  407. return
  408. }
  409. // 标段ID
  410. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  411. if err != nil {
  412. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  413. return
  414. }
  415. // 项目节ID
  416. treeId, err := utils.GetDecryptId(contractData.TreeId)
  417. if err != nil {
  418. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  419. return
  420. }
  421. // 合同ID
  422. id, err := utils.GetDecryptId(contractData.Id)
  423. if err != nil {
  424. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  425. return
  426. }
  427. err = c.ServiceContract.Unlock(projectIdInt, bidsectionId, treeId, id)
  428. if err != nil {
  429. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  430. return
  431. }
  432. // 1.项目节信息
  433. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  434. c.Ctx.JSON(iris.Map{"code": 0, "msg": "解锁成功", "section": sectionDetail})
  435. }