/* * @description: 合同支出相关控制 * @Author: CP * @Date: 2020-12-18 16:44:13 * @FilePath: \construction_management\web\api\contract_expenditure_api.go */ package api import ( "fmt" "github.com/kataras/iris/v12" "go.mod/lib" "go.mod/web/utils" "go.mod/web/viewmodels" ) // @Summary 获得标段支出-项目节信息 // @Tags 合同管理-支出合同 // @Description 未设置合同项目节 返回项目节模板信息 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param bidsectionId path string true "标段ID" // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}" // @Router /api/contract/expenditure/section/all [get] func (c *ContractApi) GetExpenditureSectionAll() { sectionData := viewmodels.TreeSectionContract{} err := c.Ctx.ReadForm(§ionData) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"}) return } if sectionData.BidsectionId == "" { c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"}) return } bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"}) return } // 项目ID projectIdInt, err := utils.GetProjectId(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } //获得合同项目节 sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, 1) // 1.未设置了项目节 if len(sectionTree.Children) == 0 { // 返回项目节2个基础模板 templateTree1 := lib.NewItemSection().TemplateTree1 templateTree2 := lib.NewItemSection().TemplateTree2 c.Ctx.JSON(iris.Map{ "code": 0, "msg": "", "isTemplate": 1, "sectionTemplate1": templateTree1, "sectionTemplate2": templateTree2, }) return //2.项目节已设置 } else { // 2.已设置项目节 c.Ctx.JSON(iris.Map{ "code": 0, "msg": "", "isTemplate": 0, "sectionTree": sectionTree, }) return // 返回项目相关所有信息 } } // @Summary 单个合同和项目节 // @Tags 合同管理-支出合同 // @Description 获得合同详情和项目节详情 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param id path string true "项目节ID" // @Param bidsectionId path string true "标段ID" // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}" // @Router /api/contract/expenditure [get] func (c *ContractApi) GetExpenditure() { // 1.规则验证 sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } // 2.项目ID projectId, err := utils.GetProjectId(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } // 3.标段ID bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } // 4.树ID treeId, err := utils.GetDecryptId(sectionData.Id) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": err}) return } // 获得项目节详情 section := c.ServiceContract.Get(treeId, bidsectionId, projectId, 1) // 该项目节 子树下是否有合同 isContract := true contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 1) if len(contractList) == 0 { isContract = false } // 获得合同详情 contractId, _ := utils.GetDecryptId(section.ContractId) contract := &viewmodels.Contracts{} if contractId != 0 { contract = c.ServiceContract.GetContract(contractId) } c.Ctx.JSON(iris.Map{ "code": 0, "msg": "", "section": section, "isContract": isContract, //该项目节(包含子孙)下是否有合同 "contract": contract, }) } // @Summary 新增合同 // @Tags 合同管理-支出合同 // @Description 新增合同 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param treeId path string true "项目节ID" // @Param bidsectionId path string true "标段ID" // @Param code path string true "合同编号" // @Param name path string true "合同名称" // @Param contractsType path int true "合同类型(1)" // @Param price path string true "合同金额" // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}" // @Router /api/contract/expenditure/create [post] func (c *ContractApi) PostExpenditureCreate() { // 验证参数 contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目ID projectIdInt, err := utils.GetProjectId(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 标段ID bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目节ID treeId, err := utils.GetDecryptId(contractData.TreeId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } if !(contractData.ContractsType == 0 || contractData.ContractsType == 1) { c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同类型只能是0或者1"}) return } sectionData := &viewmodels.TreeSectionContract{} sectionData.Id = contractData.TreeId sectionData.Name = " " sectionResult, err := c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 1) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, sectionResult.Id) if err != nil { // 需要删除项目节 c.ServiceContract.SectionDelete(sectionResult.Id, bidsectionId, projectIdInt, 1) c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 获得项目节 sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1) // 合同ID contractId, _ := utils.GetDecryptId(sectionDetail.ContractId) contractDetail := c.ServiceContract.GetContract(contractId) c.Ctx.JSON(iris.Map{ "code": 0, "msg": "新增成功", "contract": contractDetail, }) } // @Summary 编辑合同 // @Tags 合同管理-支出合同 // @Description 编辑合同 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param id path string true "合同ID" // @Param treeId path string true "项目节ID" // @Param bidsectionId path string true "标段ID" // @Param content path string true "合同内容" // @Param name path string true "合同名称" // @Param price path string true "合同金额" // @Param partyA path string true "甲方" // @Param partyASigner path string true "甲方签约人" // @Param partyB path string true "已方" // @Param partyBSigner path string true "已方签约人" // @Param signerTime path string true "签约时间" // @Param remarks path string true "备注" // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}" // @Router /api/contract/expenditure/update [post] func (c *ContractApi) PostExpenditureUpdate() { // 验证参数 contractData, err := c.ServiceContract.ValidRuleContractEdi(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目ID projectIdInt, err := utils.GetProjectId(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 标段ID bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目节ID treeId, err := utils.GetDecryptId(contractData.TreeId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } err = c.ServiceContract.UpdateExpenditure(contractData, projectIdInt, bidsectionId, treeId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } //2.请求当前项目信息 // 1.验证项目节ID sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1) // 合同ID contractId, _ := utils.GetDecryptId(sectionDetail.ContractId) contractDetail := c.ServiceContract.GetContract(contractId) c.Ctx.JSON(iris.Map{ "code": 0, "msg": "编辑成功", "section": sectionDetail, "contract": contractDetail, }) } // @Summary 删除合同 // @Tags 合同管理-支出合同 // @Description 删除合同 // @Accept json // @Produce json // @Security ApiKeyAuth // @Param id path string true "合同ID" // @Param treeId path string true "项目节ID" // @Param bidsectionId path string true "标段ID" // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}" // @Router /api/contract/expenditure [delete] func (c *ContractApi) DeleteExpenditure() { // 验证参数 contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目ID projectIdInt, err := utils.GetProjectId(c.Ctx) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 标段ID bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 项目节ID treeId, err := utils.GetDecryptId(contractData.TreeId) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } // 合同ID id, err := utils.GetDecryptId(contractData.Id) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } err = c.ServiceContract.DeleteExpenditure(projectIdInt, bidsectionId, treeId, id) if err != nil { c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)}) return } //2.请求当前项目信息 // 1.验证项目节ID // sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1) c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": ""}) }