contract_api.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. projectId, err := utils.GetProjectId(c.Ctx)
  36. if err != nil {
  37. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  38. return
  39. }
  40. // 获得项目账号ID
  41. projectAccountId, err := utils.GetProjectAccountId(c.Ctx)
  42. if err != nil {
  43. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  44. return
  45. }
  46. // 获得层级文件夹
  47. FolderData := c.ServiceTree.GetAllContract(projectId, projectAccountId)
  48. c.Ctx.JSON(iris.Map{
  49. "code": 0,
  50. "msg": "",
  51. "data": FolderData,
  52. })
  53. }
  54. // @Summary 获得标段收入-项目节信息
  55. // @Tags 合同管理-收入合同
  56. // @Description 未设置合同项目节 返回项目节模板信息
  57. // @Accept json
  58. // @Produce json
  59. // @Security ApiKeyAuth
  60. // @Param bidsectionId path string true "标段ID"
  61. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
  62. // @Router /api/contract/income/section/all [get]
  63. func (c *ContractApi) GetIncomeSectionAll() {
  64. sectionData := viewmodels.TreeSectionContract{}
  65. err := c.Ctx.ReadForm(&sectionData)
  66. if err != nil {
  67. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  68. return
  69. }
  70. if sectionData.BidsectionId == "" {
  71. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  72. return
  73. }
  74. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  75. if err != nil {
  76. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  77. return
  78. }
  79. // 项目ID
  80. projectIdInt, err := utils.GetProjectId(c.Ctx)
  81. if err != nil {
  82. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  83. return
  84. }
  85. //获得合同项目节
  86. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, 0)
  87. // 1.未设置了项目节
  88. if len(sectionTree.Children) == 0 {
  89. // 返回项目节2个基础模板
  90. templateTree1 := lib.NewItemSection().TemplateTree1
  91. templateTree2 := lib.NewItemSection().TemplateTree2
  92. c.Ctx.JSON(iris.Map{
  93. "code": 0,
  94. "msg": "",
  95. "isTemplate": 1,
  96. "sectionTemplate1": templateTree1,
  97. "sectionTemplate2": templateTree2,
  98. })
  99. return
  100. //2.项目节已设置
  101. } else {
  102. // 2.已设置项目节
  103. c.Ctx.JSON(iris.Map{
  104. "code": 0,
  105. "msg": "",
  106. "isTemplate": 0,
  107. "sectionTree": sectionTree,
  108. })
  109. return
  110. // 返回项目相关所有信息
  111. }
  112. }
  113. // @Summary 单个合同和项目节
  114. // @Tags 合同管理-收入合同
  115. // @Description 获得合同详情和项目节详情
  116. // @Accept json
  117. // @Produce json
  118. // @Security ApiKeyAuth
  119. // @Param id path string true "项目节ID"
  120. // @Param bidsectionId path string true "标段ID"
  121. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}"
  122. // @Router /api/contract/income [get]
  123. func (c *ContractApi) GetIncome() {
  124. // 1.规则验证
  125. sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
  126. if err != nil {
  127. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  128. return
  129. }
  130. // 2.项目ID
  131. projectId, err := utils.GetProjectId(c.Ctx)
  132. if err != nil {
  133. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  134. return
  135. }
  136. // 3.标段ID
  137. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  138. if err != nil {
  139. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  140. return
  141. }
  142. // 4.树ID
  143. treeId, err := utils.GetDecryptId(sectionData.Id)
  144. if err != nil {
  145. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  146. return
  147. }
  148. // 获得项目节详情
  149. section := c.ServiceContract.Get(treeId, bidsectionId, projectId, 0)
  150. // 该项目节 子树下是否有合同
  151. isContract := true
  152. contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 0)
  153. if len(contractList) == 0 {
  154. isContract = false
  155. }
  156. // 获得合同详情
  157. contractId, _ := utils.GetDecryptId(section.ContractId)
  158. contract := &viewmodels.Contracts{}
  159. if contractId != 0 {
  160. contract = c.ServiceContract.GetContract(contractId)
  161. }
  162. c.Ctx.JSON(iris.Map{
  163. "code": 0,
  164. "msg": "",
  165. "section": section,
  166. "isContract": isContract, //该项目节(包含子孙)下是否有合同
  167. "contract": contract,
  168. })
  169. }
  170. // @Summary 新增合同
  171. // @Tags 合同管理-收入合同
  172. // @Description 新增合同
  173. // @Accept json
  174. // @Produce json
  175. // @Security ApiKeyAuth
  176. // @Param treeId path string true "项目节ID"
  177. // @Param bidsectionId path string true "标段ID"
  178. // @Param code path string true "合同编号"
  179. // @Param name path string true "合同名称"
  180. // @Param contractsType path int true "合同类型(1)"
  181. // @Param price path string true "合同金额"
  182. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  183. // @Router /api/contract/income/create [post]
  184. func (c *ContractApi) PostIncomeCreate() {
  185. // 验证参数
  186. contractData, err := c.ServiceContract.ValidRuleContractAdd(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. projectIdInt, err := utils.GetProjectId(c.Ctx)
  193. if err != nil {
  194. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  195. return
  196. }
  197. // 标段ID
  198. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  199. if err != nil {
  200. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  201. return
  202. }
  203. // 项目节ID
  204. treeId, err := utils.GetDecryptId(contractData.TreeId)
  205. if err != nil {
  206. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  207. return
  208. }
  209. err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, treeId)
  210. if err != nil {
  211. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  212. return
  213. }
  214. // 获得项目节
  215. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
  216. // 合同ID
  217. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  218. contractDetail := c.ServiceContract.GetContract(contractId)
  219. c.Ctx.JSON(iris.Map{
  220. "code": 0,
  221. "msg": "新增成功",
  222. "contract": contractDetail,
  223. })
  224. }
  225. // @Summary 编辑合同
  226. // @Tags 合同管理-收入合同
  227. // @Description 编辑合同
  228. // @Accept json
  229. // @Produce json
  230. // @Security ApiKeyAuth
  231. // @Param id path string true "合同ID"
  232. // @Param treeId path string true "项目节ID"
  233. // @Param bidsectionId path string true "标段ID"
  234. // @Param content path string true "合同内容"
  235. // @Param name path string true "合同名称"
  236. // @Param price path string true "合同金额"
  237. // @Param partyA path string true "甲方"
  238. // @Param partyASigner path string true "甲方签约人"
  239. // @Param partyB path string true "已方"
  240. // @Param partyBSigner path string true "已方签约人"
  241. // @Param signerTime path string true "签约时间"
  242. // @Param remarks path string true "备注"
  243. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  244. // @Router /api/contract/income/update [post]
  245. func (c *ContractApi) PostIncomeUpdate() {
  246. // 验证参数
  247. contractData, err := c.ServiceContract.ValidRuleContractEdi(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. projectIdInt, err := utils.GetProjectId(c.Ctx)
  254. if err != nil {
  255. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  256. return
  257. }
  258. // 标段ID
  259. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  260. if err != nil {
  261. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  262. return
  263. }
  264. // 项目节ID
  265. treeId, err := utils.GetDecryptId(contractData.TreeId)
  266. if err != nil {
  267. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  268. return
  269. }
  270. err = c.ServiceContract.Update(contractData, projectIdInt, bidsectionId, treeId)
  271. if err != nil {
  272. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  273. return
  274. }
  275. //2.请求当前项目信息
  276. // 1.验证项目节ID
  277. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
  278. // 合同ID
  279. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  280. contractDetail := c.ServiceContract.GetContract(contractId)
  281. c.Ctx.JSON(iris.Map{
  282. "code": 0,
  283. "msg": "编辑成功",
  284. "section": sectionDetail,
  285. "contract": contractDetail,
  286. })
  287. }
  288. // @Summary 删除合同
  289. // @Tags 合同管理-收入合同
  290. // @Description 删除合同
  291. // @Accept json
  292. // @Produce json
  293. // @Security ApiKeyAuth
  294. // @Param id path string true "合同ID"
  295. // @Param treeId path string true "项目节ID"
  296. // @Param bidsectionId path string true "标段ID"
  297. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  298. // @Router /api/contract [delete]
  299. func (c *ContractApi) Delete() {
  300. // 验证参数
  301. contractData, err := c.ServiceContract.ValidRuleContractDel(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. projectIdInt, err := utils.GetProjectId(c.Ctx)
  308. if err != nil {
  309. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  310. return
  311. }
  312. // 标段ID
  313. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  314. if err != nil {
  315. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  316. return
  317. }
  318. // 项目节ID
  319. treeId, err := utils.GetDecryptId(contractData.TreeId)
  320. if err != nil {
  321. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  322. return
  323. }
  324. // 合同ID
  325. id, err := utils.GetDecryptId(contractData.Id)
  326. if err != nil {
  327. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  328. return
  329. }
  330. err = c.ServiceContract.Delete(projectIdInt, bidsectionId, treeId, id)
  331. if err != nil {
  332. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  333. return
  334. }
  335. //2.请求当前项目信息
  336. // 1.验证项目节ID
  337. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
  338. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": sectionDetail})
  339. }
  340. // @Summary 关闭合同
  341. // @Tags 合同管理
  342. // @Description 关闭合同
  343. // @Accept json
  344. // @Produce json
  345. // @Security ApiKeyAuth
  346. // @Param id path string true "合同ID"
  347. // @Param treeId path string true "项目节ID"
  348. // @Param bidsectionId path string true "标段ID"
  349. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  350. // @Router /api/contract/close [post]
  351. func (c *ContractApi) PostClose() {
  352. // 验证参数
  353. contractData, err := c.ServiceContract.ValidRuleContractDel(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. projectIdInt, err := utils.GetProjectId(c.Ctx)
  360. if err != nil {
  361. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  362. return
  363. }
  364. // 标段ID
  365. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  366. if err != nil {
  367. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  368. return
  369. }
  370. // 项目节ID
  371. treeId, err := utils.GetDecryptId(contractData.TreeId)
  372. if err != nil {
  373. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  374. return
  375. }
  376. // 合同ID
  377. id, err := utils.GetDecryptId(contractData.Id)
  378. if err != nil {
  379. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  380. return
  381. }
  382. err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id)
  383. if err != nil {
  384. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  385. return
  386. }
  387. // 1.项目节信息
  388. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
  389. c.Ctx.JSON(iris.Map{"code": 0, "msg": "关闭成功", "section": sectionDetail})
  390. }
  391. // @Summary 解锁合同
  392. // @Tags 合同管理
  393. // @Description 解锁合同
  394. // @Accept json
  395. // @Produce json
  396. // @Security ApiKeyAuth
  397. // @Param id path string true "合同ID"
  398. // @Param treeId path string true "项目节ID"
  399. // @Param bidsectionId path string true "标段ID"
  400. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  401. // @Router /api/contract/unlock [post]
  402. func (c *ContractApi) PostUnlock() {
  403. // 验证参数
  404. contractData, err := c.ServiceContract.ValidRuleContractDel(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. projectIdInt, err := utils.GetProjectId(c.Ctx)
  411. if err != nil {
  412. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  413. return
  414. }
  415. // 标段ID
  416. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  417. if err != nil {
  418. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  419. return
  420. }
  421. // 项目节ID
  422. treeId, err := utils.GetDecryptId(contractData.TreeId)
  423. if err != nil {
  424. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  425. return
  426. }
  427. // 合同ID
  428. id, err := utils.GetDecryptId(contractData.Id)
  429. if err != nil {
  430. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  431. return
  432. }
  433. err = c.ServiceContract.Unlock(projectIdInt, bidsectionId, treeId, id)
  434. if err != nil {
  435. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  436. return
  437. }
  438. // 1.项目节信息
  439. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
  440. c.Ctx.JSON(iris.Map{"code": 0, "msg": "解锁成功", "section": sectionDetail})
  441. }
  442. // @Summary 合同概述
  443. // @Tags 合同管理
  444. // @Description 合同概述
  445. // @Accept json
  446. // @Produce json
  447. // @Security ApiKeyAuth
  448. // @Param bidsectionId path string true "标段ID"
  449. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  450. // @Router /api/contract/survey [get]
  451. func (c *ContractApi) GetSurvey() {
  452. sectionData := viewmodels.Contracts{}
  453. err := c.Ctx.ReadForm(&sectionData)
  454. if err != nil {
  455. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  456. return
  457. }
  458. err = sectionData.ValidateBidsectionId()
  459. if err != nil {
  460. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  461. return
  462. }
  463. // 标段ID
  464. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  465. if err != nil {
  466. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  467. return
  468. }
  469. // 项目ID
  470. projectId, err := utils.GetProjectId(c.Ctx)
  471. if err != nil {
  472. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  473. return
  474. }
  475. incomeData := c.ServiceContract.GetSurvey(bidsectionId, projectId, 1)
  476. expenditureData := c.ServiceContract.GetSurvey(bidsectionId, projectId, 2)
  477. data := map[string]interface{}{
  478. "incomeData": incomeData,
  479. "expenditureData": expenditureData,
  480. }
  481. c.Ctx.JSON(iris.Map{
  482. "code": 0,
  483. "msg": "",
  484. "data": data,
  485. })
  486. }