| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 | /* * @description: 合同管理 -项目节相关API * @Author: CP * @Date: 2020-10-26 15:27:04 * @FilePath: \construction_management\web\api\contract_section_tree_api.go */package apiimport (	"fmt"	"github.com/kataras/iris/v12"	"go.mod/web/utils")// @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   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @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	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	//2.请求当前项目信息	// 1.验证项目节ID	treeId, _ := utils.GetDecryptId(sectionData.Id)	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)	c.Ctx.JSON(iris.Map{		"code":    0,		"msg":     "操作成功",		"section": sectionDetail,	})}// @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   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @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	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	//2.请求当前项目信息	// 1.验证项目节ID	treeId, _ := utils.GetDecryptId(sectionData.Id)	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)	c.Ctx.JSON(iris.Map{		"code":    0,		"msg":     "操作成功",		"section": sectionDetail,	})}// @Summary 更新合同节序号// @Tags 合同管理-项目节// @Description// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   id     body    string     true        "项目节ID"// @Param   bidsectionId     body    string     true        "标段ID"// @Param   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @Param   serial     body    int     true        "操作名称"// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"// @Router /api/contract/section/serial/update [post]func (c *ContractApi) PostSectionSerialUpdate() {	// 验证字段-项目节ID 操作类型	sectionData, err := c.ServiceContract.ValidRuleSerial(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	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	err = c.ServiceContract.UpdateSerial(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	//2.请求当前项目信息	// 1.验证项目节ID	treeId, _ := utils.GetDecryptId(sectionData.Id)	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)	c.Ctx.JSON(iris.Map{		"code":    0,		"msg":     "操作成功",		"section": sectionDetail,	})}// @Summary 设置合同项目节模板// @Tags 合同管理-项目节// @Description 设置合同项目节模板// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   templateNumber     body    int     true        "模板号" default(1)// @Param   bidsectionId     body    string     true        "标段ID"// @Param   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @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	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	//获得合同项目节	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, sectionData.TreeType)	// 1.未设置了项目节	if len(sectionTree.Children) == 0 {		err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt, sectionData.TreeType)		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	}}// @Summary 新增 合同项目节// @Tags 合同管理-项目节// @Description 新增 合同项目节// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   id     body    string     true        "项目节ID"// @Param   bidsectionId     body    string     true        "标段ID"// @Param   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @Param   name     body    string     true        "项目节名称"// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"// @Router /api/contract/section/add [post]func (c *ContractApi) PostSectionAdd() {	// 获得模板号	sectionData, err := c.ServiceContract.ValidRuleSectionAdd(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(sectionData.BidsectionId)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	_, err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)	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 修改合同项目节 名称// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   id     body    string     true        "项目节ID"// @Param   bidsectionId     body    string     true        "标段ID"// @Param   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @Param   name     body    string     true        "项目节名称"// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"// @Router /api/contract/section/save [post]func (c *ContractApi) PostSectionSave() {	// 获得模板号	sectionData, err := c.ServiceContract.ValidRuleSectionAdd(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	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	//2.请求当前项目信息	// 1.验证项目节ID	treeId, _ := utils.GetDecryptId(sectionData.Id)	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, sectionData.TreeType)	c.Ctx.JSON(iris.Map{"code": 0, "msg": "修改成功", "section": sectionDetail})}// @Summary 删除 合同项目节// @Tags 合同管理-项目节// @Description 删除 合同项目节// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   id     body    string     true        "项目节ID"// @Param   bidsectionId     body    string     true        "标段ID"// @Param   treeType     body    string     true        "项目节类型(0收入1支出) 不传为0" default(0)// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"// @Router /api/contract/section [delete]func (c *ContractApi) DeleteSection() {	// 获得模板号-=1	sectionData, err := c.ServiceContract.ValidRuleSectionDelete(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	}	// 项目节ID	treeId, err := utils.GetDecryptId(sectionData.Id)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		return	}	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})		return	}	err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt, sectionData.TreeType)	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 获得项目节(不含合同)// @Accept  json// @Produce  json// @Security ApiKeyAuth// @Param   bidsectionId     path    string     true        "标段ID"// @Param   treeType     path    int     true        "项目节类型(0收入,1支出)"// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"// @Router /api/contract/section/not [get]func (c *ContractApi) GetSectionNot() {	// 验证规则	sectionData, err := c.ServiceContract.ValidRuleSectionNot(c.Ctx)	if err != nil {		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})		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": fmt.Sprintf("%s", err)})		return	}	//获得合同项目节	sectionTree := c.ServiceContract.GetSecionTreeNotContract(bidsectionId, projectIdInt, sectionData.TreeType)	// 2.已设置项目节	c.Ctx.JSON(iris.Map{		"code":        0,		"msg":         "",		"sectionTree": sectionTree,	})}
 |