contract_expenditure_api.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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)
  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. err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, treeId)
  175. if err != nil {
  176. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  177. return
  178. }
  179. // 获得项目节
  180. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  181. // 合同ID
  182. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  183. contractDetail := c.ServiceContract.GetContract(contractId)
  184. c.Ctx.JSON(iris.Map{
  185. "code": 0,
  186. "msg": "新增成功",
  187. "contract": contractDetail,
  188. })
  189. }
  190. // @Summary 编辑合同
  191. // @Tags 合同管理-支出合同
  192. // @Description 编辑合同
  193. // @Accept json
  194. // @Produce json
  195. // @Security ApiKeyAuth
  196. // @Param id path string true "合同ID"
  197. // @Param treeId path string true "项目节ID"
  198. // @Param bidsectionId path string true "标段ID"
  199. // @Param content path string true "合同内容"
  200. // @Param name path string true "合同名称"
  201. // @Param price path string true "合同金额"
  202. // @Param partyA path string true "甲方"
  203. // @Param partyASigner path string true "甲方签约人"
  204. // @Param partyB path string true "已方"
  205. // @Param partyBSigner path string true "已方签约人"
  206. // @Param signerTime path string true "签约时间"
  207. // @Param remarks path string true "备注"
  208. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  209. // @Router /api/contract/expenditure/update [post]
  210. func (c *ContractApi) PostExpenditureUpdate() {
  211. // 验证参数
  212. contractData, err := c.ServiceContract.ValidRuleContractEdi(c.Ctx)
  213. if err != nil {
  214. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  215. return
  216. }
  217. // 项目ID
  218. projectIdInt, err := utils.GetProjectId(c.Ctx)
  219. if err != nil {
  220. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  221. return
  222. }
  223. // 标段ID
  224. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  225. if err != nil {
  226. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  227. return
  228. }
  229. // 项目节ID
  230. treeId, err := utils.GetDecryptId(contractData.TreeId)
  231. if err != nil {
  232. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  233. return
  234. }
  235. err = c.ServiceContract.UpdateExpenditure(contractData, projectIdInt, bidsectionId, treeId)
  236. if err != nil {
  237. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  238. return
  239. }
  240. //2.请求当前项目信息
  241. // 1.验证项目节ID
  242. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  243. // 合同ID
  244. contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
  245. contractDetail := c.ServiceContract.GetContract(contractId)
  246. c.Ctx.JSON(iris.Map{
  247. "code": 0,
  248. "msg": "编辑成功",
  249. "section": sectionDetail,
  250. "contract": contractDetail,
  251. })
  252. }
  253. // @Summary 删除合同
  254. // @Tags 合同管理-支出合同
  255. // @Description 删除合同
  256. // @Accept json
  257. // @Produce json
  258. // @Security ApiKeyAuth
  259. // @Param id path string true "合同ID"
  260. // @Param treeId path string true "项目节ID"
  261. // @Param bidsectionId path string true "标段ID"
  262. // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
  263. // @Router /api/contract/expenditure [delete]
  264. func (c *ContractApi) DeleteExpenditure() {
  265. // 验证参数
  266. contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
  267. if err != nil {
  268. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  269. return
  270. }
  271. // 项目ID
  272. projectIdInt, err := utils.GetProjectId(c.Ctx)
  273. if err != nil {
  274. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  275. return
  276. }
  277. // 标段ID
  278. bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
  279. if err != nil {
  280. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  281. return
  282. }
  283. // 项目节ID
  284. treeId, err := utils.GetDecryptId(contractData.TreeId)
  285. if err != nil {
  286. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  287. return
  288. }
  289. // 合同ID
  290. id, err := utils.GetDecryptId(contractData.Id)
  291. if err != nil {
  292. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  293. return
  294. }
  295. err = c.ServiceContract.DeleteExpenditure(projectIdInt, bidsectionId, treeId, id)
  296. if err != nil {
  297. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  298. return
  299. }
  300. //2.请求当前项目信息
  301. // 1.验证项目节ID
  302. sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
  303. c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": sectionDetail})
  304. }