123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- /*
- * @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/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
- // @Security ApiKeyAuth
- // @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
- // @Router /api/contract [get]
- func (c *ContractApi) Get() {
- // 获得项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 获得层级文件夹
- FolderData := c.ServiceTree.GetAllContract(projectIdInt)
- 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 [get]
- func (c *ContractApi) GetIncome() {
- 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.GetSeciontTree(bidsectionId, projectIdInt)
- // 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 operation{upDepth,downDepth}
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "项目节ID"
- // @Param bidsectionId body string true "标段ID"
- // @Param operation body string true "操作名称" default(upDepth)
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/contract/section/depth [post]
- func (c *ContractApi) PostSectionDepth() {
- // 验证字段-项目节ID 操作类型
- sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "操作成功",
- })
- }
- // @Summary 上移下移合同项目节
- // @Tags 合同管理
- // @Description operation{upSerial,downSerial}
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "项目节ID"
- // @Param bidsectionId body string true "标段ID"
- // @Param operation body string true "操作名称" default(upSerial)
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/contract/section/serial [post]
- func (c *ContractApi) PostSectionSerial() {
- // 验证字段-项目节ID 操作类型
- sectionData, err := c.ServiceContract.ValidRuleDepth(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- // 项目ID
- projectIdInt, err := utils.GetProjectId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
- return
- }
- err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "操作成功",
- })
- }
- // 修改合同项目节号
- func (c *ContractApi) PostSectionSave() {
- }
- // @Summary 设置合同项目节模板
- // @Tags 合同管理
- // @Description 设置合同项目节模板
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param templateNumber body int true "模板号" default(1)
- // @Param bidsectionId body string true "标段ID"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/contract/section/template [post]
- func (c *ContractApi) PostSectionTemplate() {
- // 获得模板号
- sectionData, err := c.ServiceContract.ValidRuleTemplate(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
- 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(sectionData.BidsectionId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- //获得合同项目节
- sectionTree := c.ServiceContract.GetSeciontTree(bidsectionId, projectIdInt)
- // 1.未设置了项目节
- if len(sectionTree.Children) == 0 {
- err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{"code": 0, "msg": "设置成功"})
- } else {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目节已经设置"})
- return
- }
- }
|