contract_expenditure_api.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * @description: 合同支出相关控制
  3. * @Author: CP
  4. * @Date: 2020-12-18 16:44:13
  5. * @FilePath: \construction_management\web\api\contract_expenditure_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/lib"
  12. "go.mod/web/utils"
  13. "go.mod/web/viewmodels"
  14. )
  15. // @Summary 获得标段支出-项目节信息
  16. // @Tags 合同管理-支出合同
  17. // @Description 未设置合同项目节 返回项目节模板信息
  18. // @Accept json
  19. // @Produce json
  20. // @Security ApiKeyAuth
  21. // @Param bidsectionId path string true "标段ID"
  22. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
  23. // @Router /api/contract/expenditure/section/all [get]
  24. func (c *ContractApi) GetExpenditureSectionAll() {
  25. sectionData := viewmodels.TreeSectionContract{}
  26. err := c.Ctx.ReadForm(&sectionData)
  27. if err != nil {
  28. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  29. return
  30. }
  31. if sectionData.BidsectionId == "" {
  32. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  33. return
  34. }
  35. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  36. if err != nil {
  37. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  38. return
  39. }
  40. // 项目ID
  41. projectIdInt, err := utils.GetProjectId(c.Ctx)
  42. if err != nil {
  43. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  44. return
  45. }
  46. //获得合同项目节
  47. sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, 1)
  48. // 1.未设置了项目节
  49. if len(sectionTree.Children) == 0 {
  50. // 返回项目节2个基础模板
  51. templateTree1 := lib.NewItemSection().TemplateTree1
  52. templateTree2 := lib.NewItemSection().TemplateTree2
  53. c.Ctx.JSON(iris.Map{
  54. "code": 0,
  55. "msg": "",
  56. "isTemplate": 1,
  57. "sectionTemplate1": templateTree1,
  58. "sectionTemplate2": templateTree2,
  59. })
  60. return
  61. //2.项目节已设置
  62. } else {
  63. // 2.已设置项目节
  64. c.Ctx.JSON(iris.Map{
  65. "code": 0,
  66. "msg": "",
  67. "isTemplate": 0,
  68. "sectionTree": sectionTree,
  69. })
  70. return
  71. // 返回项目相关所有信息
  72. }
  73. }
  74. // @Summary 单个合同和项目节
  75. // @Tags 合同管理-支出合同
  76. // @Description 获得合同详情和项目节详情
  77. // @Accept json
  78. // @Produce json
  79. // @Security ApiKeyAuth
  80. // @Param id path string true "项目节ID"
  81. // @Param bidsectionId path string true "标段ID"
  82. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}"
  83. // @Router /api/contract/expenditure [get]
  84. func (c *ContractApi) GetExpenditure() {
  85. // 1.规则验证
  86. sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
  87. if err != nil {
  88. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  89. return
  90. }
  91. // 2.项目ID
  92. projectId, err := utils.GetProjectId(c.Ctx)
  93. if err != nil {
  94. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  95. return
  96. }
  97. // 3.标段ID
  98. bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
  99. if err != nil {
  100. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  101. return
  102. }
  103. // 4.树ID
  104. treeId, err := utils.GetDecryptId(sectionData.Id)
  105. if err != nil {
  106. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  107. return
  108. }
  109. // 获得项目节详情
  110. section := c.ServiceContract.Get(treeId, bidsectionId, projectId, 1)
  111. // 该项目节 子树下是否有合同
  112. isContract := true
  113. contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 1)
  114. if len(contractList) == 0 {
  115. isContract = false
  116. }
  117. // 获得合同详情
  118. contractId, _ := utils.GetDecryptId(section.ContractId)
  119. contract := &viewmodels.Contracts{}
  120. if contractId != 0 {
  121. contract = c.ServiceContract.GetContract(contractId)
  122. }
  123. c.Ctx.JSON(iris.Map{
  124. "code": 0,
  125. "msg": "",
  126. "section": section,
  127. "isContract": isContract, //该项目节(包含子孙)下是否有合同
  128. "contract": contract,
  129. })
  130. }
  131. // @Summary 新增合同
  132. // @Tags 合同管理-支出合同
  133. // @Description 新增合同
  134. // @Accept json
  135. // @Produce json
  136. // @Security ApiKeyAuth
  137. // @Param treeId path string true "项目节ID"
  138. // @Param bidsectionId path string true "标段ID"
  139. // @Param code path string true "合同编号"
  140. // @Param name path string true "合同名称"
  141. // @Param contractsType path int true "合同类型(1)"
  142. // @Param price path string true "合同金额"
  143. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  144. // @Router /api/contract/expenditure/create [post]
  145. func (c *ContractApi) PostExpenditureCreate() {
  146. // 验证参数
  147. contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx)
  148. if err != nil {
  149. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  150. return
  151. }
  152. // 项目ID
  153. projectIdInt, err := utils.GetProjectId(c.Ctx)
  154. if err != nil {
  155. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  156. return
  157. }
  158. // 标段ID
  159. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  160. if err != nil {
  161. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  162. return
  163. }
  164. // 项目节ID
  165. treeId, err := utils.GetDecryptId(contractData.TreeId)
  166. if err != nil {
  167. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  168. return
  169. }
  170. if !(contractData.ContractsType == 0 || contractData.ContractsType == 1) {
  171. c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同类型只能是0或者1"})
  172. return
  173. }
  174. sectionData := &viewmodels.TreeSectionContract{}
  175. sectionData.Id = contractData.TreeId
  176. sectionData.Name = " "
  177. sectionResult, err := c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 1)
  178. if err != nil {
  179. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  180. return
  181. }
  182. err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, sectionResult.Id)
  183. if err != nil {
  184. // 需要删除项目节
  185. c.ServiceContract.SectionDelete(sectionResult.Id, bidsectionId, projectIdInt, 1)
  186. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  187. return
  188. }
  189. // 获得项目节
  190. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
  191. // 合同ID
  192. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  193. contractDetail := c.ServiceContract.GetContract(contractId)
  194. c.Ctx.JSON(iris.Map{
  195. "code": 0,
  196. "msg": "新增成功",
  197. "contract": contractDetail,
  198. })
  199. }
  200. // @Summary 编辑合同
  201. // @Tags 合同管理-支出合同
  202. // @Description 编辑合同
  203. // @Accept json
  204. // @Produce json
  205. // @Security ApiKeyAuth
  206. // @Param id path string true "合同ID"
  207. // @Param treeId path string true "项目节ID"
  208. // @Param bidsectionId path string true "标段ID"
  209. // @Param content path string true "合同内容"
  210. // @Param name path string true "合同名称"
  211. // @Param price path string true "合同金额"
  212. // @Param partyA path string true "甲方"
  213. // @Param partyASigner path string true "甲方签约人"
  214. // @Param partyB path string true "已方"
  215. // @Param partyBSigner path string true "已方签约人"
  216. // @Param signerTime path string true "签约时间"
  217. // @Param remarks path string true "备注"
  218. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  219. // @Router /api/contract/expenditure/update [post]
  220. func (c *ContractApi) PostExpenditureUpdate() {
  221. // 验证参数
  222. contractData, err := c.ServiceContract.ValidRuleContractEdi(c.Ctx)
  223. if err != nil {
  224. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  225. return
  226. }
  227. // 项目ID
  228. projectIdInt, err := utils.GetProjectId(c.Ctx)
  229. if err != nil {
  230. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  231. return
  232. }
  233. // 标段ID
  234. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  235. if err != nil {
  236. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  237. return
  238. }
  239. // 项目节ID
  240. treeId, err := utils.GetDecryptId(contractData.TreeId)
  241. if err != nil {
  242. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  243. return
  244. }
  245. err = c.ServiceContract.UpdateExpenditure(contractData, projectIdInt, bidsectionId, treeId)
  246. if err != nil {
  247. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  248. return
  249. }
  250. //2.请求当前项目信息
  251. // 1.验证项目节ID
  252. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
  253. // 合同ID
  254. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  255. contractDetail := c.ServiceContract.GetContract(contractId)
  256. c.Ctx.JSON(iris.Map{
  257. "code": 0,
  258. "msg": "编辑成功",
  259. "section": sectionDetail,
  260. "contract": contractDetail,
  261. })
  262. }
  263. // @Summary 删除合同
  264. // @Tags 合同管理-支出合同
  265. // @Description 删除合同
  266. // @Accept json
  267. // @Produce json
  268. // @Security ApiKeyAuth
  269. // @Param id path string true "合同ID"
  270. // @Param treeId path string true "项目节ID"
  271. // @Param bidsectionId path string true "标段ID"
  272. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  273. // @Router /api/contract/expenditure [delete]
  274. func (c *ContractApi) DeleteExpenditure() {
  275. // 验证参数
  276. contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
  277. if err != nil {
  278. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  279. return
  280. }
  281. // 项目ID
  282. projectIdInt, err := utils.GetProjectId(c.Ctx)
  283. if err != nil {
  284. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  285. return
  286. }
  287. // 标段ID
  288. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  289. if err != nil {
  290. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  291. return
  292. }
  293. // 项目节ID
  294. treeId, err := utils.GetDecryptId(contractData.TreeId)
  295. if err != nil {
  296. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  297. return
  298. }
  299. // 合同ID
  300. id, err := utils.GetDecryptId(contractData.Id)
  301. if err != nil {
  302. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  303. return
  304. }
  305. err = c.ServiceContract.DeleteExpenditure(projectIdInt, bidsectionId, treeId, id)
  306. if err != nil {
  307. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  308. return
  309. }
  310. //2.请求当前项目信息
  311. // 1.验证项目节ID
  312. // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
  313. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": ""})
  314. }