123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- /*
- * @description: 合同管理 相关API
- * @Author: CP
- * @Date: 2020-10-26 15:27:04
- * @FilePath: \construction_management\web\api\contract_api.go
- */
- package api
- import (
- "fmt"
- "github.com/kataras/iris/v12"
- "go.mod/lib"
- "go.mod/models"
- "go.mod/services"
- "go.mod/web/utils"
- "go.mod/web/viewmodels"
- )
- type ContractApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // // 需要用的service
- ServiceTree services.TreeService
- ServiceContract services.ContractService
- // ServiceLogin services.LoginService
- // ServiceProject services.ProjectService
- }
- // @Summary 获得合同目录和标段
- // @Tags 合同管理
- // @Description 获得合同目录和标段
- // @Accept json
- // @Produce json
- // @Param bidsectionType path string true "标段类型0合同1安全2质量"
- // @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/contract/folder [get]
- func (c *ContractApi) GetFolder() {
- bidTypeData, err := c.ServiceTree.ValidRuleBidsectionType(c.Ctx)
- if err != nil {
- ErrMsg := utils.FormValidError(err)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
- return
- }
- // 获得项目ID
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 获得项目账号ID
- // projectAccountId, err := utils.GetProjectAccountId(c.Ctx)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- // return
- // }
- account := c.Ctx.Values().Get("account").(*models.CmProjectAccount)
- // 获得层级文件夹
- FolderData := c.ServiceTree.GetAllContract(projectId, account, bidTypeData.BidsectionType)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": FolderData,
- })
- }
- // @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/income/section/all [get]
- func (c *ContractApi) GetIncomeSectionAll() {
- 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, 0)
- // 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/income [get]
- func (c *ContractApi) GetIncome() {
- // 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, 0)
- // 该项目节 子树下是否有合同
- isContract := true
- contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 0)
- 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/income/create [post]
- func (c *ContractApi) PostIncomeCreate() {
- // 验证参数
- 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
- }
- // 可优化-事务问题
- // 先添加项目节
- // 1.新建合同,项目层级必须在第二层以下,当第一层没有孩子可以添加合同
- sectionData := &viewmodels.TreeSectionContract{}
- sectionData.Id = contractData.TreeId
- sectionData.Name = " "
- sectionResult, err := c.ServiceContract.ContractSectionAdd(sectionData, bidsectionId, projectIdInt, 0)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 在添加合同
- err = c.ServiceContract.Add(contractData, projectIdInt, bidsectionId, sectionResult.Id)
- if err != nil {
- // 需要删除项目节-有问题
- c.ServiceContract.SectionDelete(sectionResult.Id, bidsectionId, projectIdInt, 0)
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 获得项目节
- sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
- // 合同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/income/update [post]
- func (c *ContractApi) PostIncomeUpdate() {
- // 验证参数
- 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.Update(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, 0)
- // 合同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 [delete]
- func (c *ContractApi) Delete() {
- // 验证参数
- 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.Delete(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, 0)
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": ""})
- }
- // @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/close [post]
- func (c *ContractApi) PostClose() {
- // 验证参数
- contractData, err := c.ServiceContract.ValidRuleContractClose(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.Close(projectIdInt, bidsectionId, treeId, id, contractData.TreeType, contractData.SettlementCode)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 1.项目节信息
- sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
- contractDetail := c.ServiceContract.GetContract(id)
- 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/unlock [post]
- func (c *ContractApi) PostUnlock() {
- // 验证参数
- contractData, err := c.ServiceContract.ValidRuleContractClose(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.Unlock(projectIdInt, bidsectionId, treeId, id, contractData.TreeType)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 1.项目节信息
- sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 0)
- contractDetail := c.ServiceContract.GetContract(id)
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "解锁成功", "section": sectionDetail, "contract": contractDetail})
- }
- // @Summary 合同概述
- // @Tags 合同管理
- // @Description 合同概述
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param bidsectionId path string true "标段ID"
- // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
- // @Router /api/contract/survey [get]
- func (c *ContractApi) GetSurvey() {
- sectionData := viewmodels.Contracts{}
- err := c.Ctx.ReadForm(§ionData)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- err = sectionData.ValidateBidsectionId()
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- // 标段ID
- bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
- return
- }
- // 项目ID
- projectId, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 账号ID
- // accountId, err := utils.GetProjectAccountId(c.Ctx)
- // if err != nil {
- // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- // return
- // }
- // 缓存标段ID-用于权限
- // key := fmt.Sprintf("pm_%d_%d", projectId, accountId)
- // lib.NewRedis().SetBidsectionIdByCache(key, bidsectionId)
- incomeData := c.ServiceContract.GetSurvey(bidsectionId, projectId, 1)
- expenditureData := c.ServiceContract.GetSurvey(bidsectionId, projectId, 2)
- data := map[string]interface{}{
- "incomeData": incomeData,
- "expenditureData": expenditureData,
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "",
- "data": data,
- })
- }
|