contract_api.go 17 KB

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