caipin 4 năm trước cách đây
mục cha
commit
23aa4da72f

+ 5 - 1
comm/functions.go

@@ -91,7 +91,11 @@ func MakeSectionContract(Data []*viewmodels.TreeSectionContract, node *viewmodel
 	if childs != nil {
 		// 往父节点添加子节点
 		// 孩子们从小到大排序
-		sectionSelectionSort(childs)
+		if len(childs) != 0 {
+			sectionSelectionSort(childs)
+			childs[0].ElderBrother = false
+			childs[len(childs)-1].IsEnd = true
+		}
 		node.Children = append(node.Children, childs[0:]...) //添加子节点
 		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
 			_, has := haveChildSectionContract(Data, v)

+ 71 - 36
dao/tree_contract_dao.go

@@ -278,42 +278,6 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 		session.Rollback()
 		return errors.New("移动失败")
 	}
-	// _, err = session.Exec("UPDATE  cm_tree_contracts SET `attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') "+
-	// 	"`code` = replace(`code`, '"+attributionChildren+"', '"+moveAttributionChildren+"') where attribution like ? and project_id=? and bidsection_id=? ", attributionChildren+"%", projectId, bidsectionId)
-	// if err != nil {
-	// 	session.Rollback()
-	// 	return errors.New("移动失败")
-	// }
-	//
-
-	// 上移
-	// if operation == "upSerial" {
-	// 	// 1.上一个大兄弟
-	// 	// fmt.Println(brother)
-	// 	// 2.项目节 序号 兄弟的序号
-	// 	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? "+
-	// 		" where id = ? ", brother.Serial, section.Id)
-	// 	if err != nil {
-	// 		session.Rollback()
-	// 		return errors.New("上移失败")
-	// 	}
-	// 	// 3.兄弟的序号为 项目节序号
-	// 	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? "+
-	// 		" where id = ? ", section.Serial, brother.Id)
-	// 	if err != nil {
-	// 		session.Rollback()
-	// 		return errors.New("上移失败")
-	// 	}
-
-	// } else if operation == "downSerial" {
-	// 	// 下移
-	// 	// 1.下一个兄弟
-	// 	// fmt.Println(brother)
-	// 	// 2.项目节 序号 兄弟的序号
-
-	// } else {
-	// 	return errors.New("参数错误")
-	// }
 
 	err = session.Commit()
 	if err != nil {
@@ -329,6 +293,77 @@ func (d *TreeContractDao) CreateAll(data []*models.CmTreeContracts) error {
 	return err
 }
 
+// 新增项目节
+func (d *TreeContractDao) Create(data *models.CmTreeContracts) error {
+
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("新增失败-db")
+	}
+
+	_, err = session.Insert(data)
+	if err != nil {
+		return errors.New("新增失败")
+	}
+	fmt.Println(data.Id)
+	// 更新合同节树ID
+	data.TreeId = data.Id
+	_, err = session.Id(data.Id).Update(data)
+	if err != nil {
+		return errors.New("新增失败")
+	}
+
+	err = session.Commit()
+	if err != nil {
+		session.Rollback()
+		return errors.New("新增失败-db")
+	}
+	return nil
+}
+
+// 保存项目节
+func (d *TreeContractDao) Save(section *models.CmTreeContracts, columns []string) error {
+	_, err := d.engine.Id(section.Id).MustCols(columns...).Update(section)
+	if err != nil {
+		return errors.New("保存失败")
+	}
+	return nil
+}
+
+// 删除项目节
+func (d *TreeContractDao) Delete(section *models.CmTreeContracts) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("删除失败-db")
+	}
+	// 1. 删除项目节
+	_, err = session.Where("id = ? ", section.Id).Delete(section)
+	if err != nil {
+		session.Rollback()
+		return errors.New("删除失败")
+	}
+
+	// 孩子们的归属
+	attribution := fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
+	// 2. 删除项目节孩子们
+	_, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE attribution like ? and project_id=? and bidsection_id=? ", attribution+"%", section.ProjectId, section.BidsectionId)
+	if err != nil {
+		session.Rollback()
+		return errors.New("删除失败")
+	}
+
+	err = session.Commit()
+	if err != nil {
+		session.Rollback()
+		return errors.New("删除失败-db")
+	}
+	return nil
+}
+
 //替换项目节归属
 func (d *TreeContractDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, code string, moveCode string, projectId int, bidsectionId int) error {
 	// 1.获得需要替换的数据

+ 14 - 12
dao/tree_dao.go

@@ -145,11 +145,11 @@ func (d *TreeDao) GetBidParentId(bidsectionId int, projectId int) *models.CmTree
 }
 
 // 获得谋归属下的项目节
-func (d *TreeDao) GetAttribution(attribution string, projectId int, bidsectionId int) []models.CmTree {
+func (d *TreeDao) GetAttribution(attribution string, projectId int) []models.CmTree {
 	datalist := make([]models.CmTree, 0)
 	err := d.engine.
 		Asc("serial").
-		Where("attribution like ? and project_id=? and bidsection_id=?", attribution+"%", projectId, bidsectionId).
+		Where("attribution like ? and project_id=? and isdelete=0", attribution+"%", projectId).
 		Find(&datalist)
 	if err != nil {
 		return datalist
@@ -263,18 +263,20 @@ func (d *TreeDao) Move(treeNode *models.CmTree, moveFolder *models.CmTree) error
 
 	// 5-移动原目录下所有子目录和标段-项目下
 	movrAttribution = fmt.Sprintf("%s%d-", movrAttribution, serial)
-	_, err = session.Exec("UPDATE  cm_tree SET `attribution` = replace(`attribution`, '"+attribution+"', '"+movrAttribution+"') "+
+	//`attribution` = replace(`attribution`, '"+attribution+"', '"+movrAttribution+"')
+	_, err = session.Exec("UPDATE  cm_tree SET  "+
 		",`depth` =`depth` - ? where attribution like ? and project_id=? and isdelete=0", difference, attribution+"%", treeNode.ProjectId)
 	//_, err = session.Exec("UPDATE from cm_tree SET `attribution` = replace(`attribution`, ?, ?) where attribution like ?", attribution,movrAttribution,attribution+"%")
 	if err != nil {
 		session.Rollback()
 		return errors.New("移动目录或标段出错")
 	}
-
-	// 6-更新depth
-	// 6-1原目录深度差
-	//difference := treeNode.Depth - moveFolder.Depth
-	// 原目录depth-差,移动后的depth
+	// 6-目录孩子们的归属设置
+	err = d.replaceContractAttribution(session, attribution, movrAttribution, treeNode.ProjectId)
+	if err != nil {
+		session.Rollback()
+		return errors.New("移动失败")
+	}
 
 	err = session.Commit()
 	if err != nil {
@@ -310,7 +312,7 @@ func (d *TreeDao) Rename(data *models.CmTree, columns []string) error {
 	}
 
 	// 重命名treeNode
-	_, err = d.engine.Id(data.Id).MustCols(columns...).Update(data)
+	_, err = session.Id(data.Id).MustCols(columns...).Update(data)
 	if err != nil {
 		session.Rollback()
 		return errors.New("标段重命名失败")
@@ -319,7 +321,7 @@ func (d *TreeDao) Rename(data *models.CmTree, columns []string) error {
 	bidsection := models.CmBidsection{}
 	bidsection.Id = data.BidsectionId
 	bidsection.Name = data.Name
-	_, err = d.engine.Id(bidsection.Id).MustCols(columns...).Update(bidsection)
+	_, err = session.Id(bidsection.Id).MustCols(columns...).Update(bidsection)
 	if err != nil {
 		session.Rollback()
 		return errors.New("标段重命名失败-bid")
@@ -347,9 +349,9 @@ func (d *TreeDao) Update(data *models.CmTree, columns []string) error {
 }
 
 //替换项目节归属
-func (d *TreeDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, projectId int, bidsectionId int) error {
+func (d *TreeDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, projectId int) error {
 	// 1.获得需要替换的数据
-	sectionData := d.GetAttribution(attributionChildren, projectId, bidsectionId)
+	sectionData := d.GetAttribution(attributionChildren, projectId)
 	if len(sectionData) == 0 {
 		return nil
 	}

+ 270 - 0
services/contract_section_tree_service.go

@@ -0,0 +1,270 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"log"
+	"strconv"
+	"time"
+
+	"go.mod/comm"
+	"go.mod/conf"
+	"go.mod/lib"
+	"go.mod/models"
+	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
+)
+
+// 获得合同项目节
+func (s *contractService) GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
+	sectionList := make([]*viewmodels.TreeSectionContract, 0)
+	dataList := s.treeContractDao.GetAll(bidsectionId, projectId)
+	// 生成根
+	sectionRoot := &viewmodels.TreeSectionContract{}
+	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
+	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
+	sectionRoot.Id = id
+	sectionRoot.Name = "root"
+	sectionRoot.ParentId = parentId
+	sectionList = append(sectionList, sectionRoot)
+	for _, data := range dataList {
+		section := &viewmodels.TreeSectionContract{}
+		id, _ := comm.AesEncrypt(strconv.Itoa(data.TreeId), conf.SignSecret)
+		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
+		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
+		contractId, _ := comm.AesEncrypt(strconv.Itoa(data.ContractId), conf.SignSecret)
+		bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(data.BidsectionId), conf.SignSecret)
+		section.Id = id
+		section.Name = data.Name
+		section.ParentId = parentId
+		section.Depth = data.Depth + 1
+		section.Serial = data.Serial
+		section.Attribution = data.Attribution
+		section.Code = data.Code
+		section.ProjectId = projectId
+		section.BidsectionId = bidsectionId
+		section.ContractId = contractId
+
+		section.ElderBrother = true
+		section.IsEnd = false
+
+		section.Name = data.Name
+		section.ContractCode = data.ContractCode
+		section.ContractPrice = data.ContractPrice
+		section.ContractReturned = data.ContractReturned
+		section.ContractsPaid = data.ContractsPaid
+		section.ContractStatus = data.ContractStatus
+
+		section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
+		sectionList = append(sectionList, section)
+	}
+
+	Node := sectionRoot //父节点
+	comm.MakeSectionContract(sectionList, Node)
+	return Node
+}
+
+// 设置合同项目节初始数据-根据模板导入
+func (s *contractService) SetSection(templateNumber int, bidsectionId int, projectId int) error {
+	// 获得模板数据
+	templateTree := make([]*lib.ItemSectionTemplateTree, 0)
+	if templateNumber == 1 {
+		templateTree = lib.NewItemSectionData().TemplateList1
+	} else if templateNumber == 2 {
+		templateTree = lib.NewItemSectionData().TemplateList2
+	} else {
+		return errors.New("找不到合同项目节模板")
+	}
+
+	// 1.组合数据-写入库中
+	sectionTreeList := make([]*models.CmTreeContracts, 0)
+	for _, item := range templateTree {
+		section := &models.CmTreeContracts{}
+		section.TreeId = item.Id
+		section.ParentId = item.ParentId
+		section.ProjectId = projectId
+		section.BidsectionId = bidsectionId
+		section.Name = item.Name
+		section.Depth = item.Depth
+		section.Serial = item.Serial
+		section.Attribution = item.Attribution
+		section.Code = fmt.Sprintf("%s%d", item.Attribution, item.Serial)
+		section.CreateTime = time.Now()
+
+		section.ContractPrice = "0"
+		section.ContractReturned = "0"
+		section.ContractsPaid = "0"
+
+		sectionTreeList = append(sectionTreeList, section)
+	}
+
+	err := s.treeContractDao.CreateAll(sectionTreeList)
+	if err != nil {
+		log.Println("设置合同项目节模板错误 err=", err)
+		return errors.New("设置合同项目节模板错误")
+	}
+	return nil
+}
+
+// 新增项目节
+func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+	// 1.验证项目节ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		return err
+	}
+	sectionFather := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	if sectionFather.Id == 0 {
+		return errors.New("未找到合同项目节")
+	}
+
+	// 2 获得最大序号
+	// 2-1 孩子节点
+	childrenList := s.treeContractDao.GetChildren(treeId, bidsectionId, projectId)
+	// 2-1 最大序号
+	serial := 1
+	if len(childrenList) != 0 {
+		serial = childrenList[len(childrenList)-1].Serial + 1
+	}
+	// 2-2 归属
+	attribution := fmt.Sprintf("%s%d-", sectionFather.Attribution, sectionFather.Serial)
+	code := fmt.Sprintf("%s%d", attribution, serial)
+	// 新增项目节
+	sectionCM := &models.CmTreeContracts{}
+	sectionCM.ParentId = sectionFather.TreeId
+	sectionCM.Name = sectionData.Name
+	sectionCM.Depth = sectionFather.Depth + 1
+	sectionCM.Serial = serial
+	sectionCM.Attribution = attribution
+	sectionCM.Code = code
+
+	sectionCM.ProjectId = projectId
+	sectionCM.BidsectionId = bidsectionId
+	sectionCM.ContractPrice = "0"
+	sectionCM.ContractReturned = "0"
+	sectionCM.ContractsPaid = "0"
+
+	err = s.treeContractDao.Create(sectionCM)
+	if err != nil {
+		return errors.New("新增失败")
+	}
+	return nil
+}
+
+// 保存名称或者编号
+func (s *contractService) SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+	// 1.验证项目节ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		return err
+	}
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	if section.Id == 0 {
+		return errors.New("未找到合同项目节")
+	}
+
+	// 2.保存
+	sectionCM := &models.CmTreeContracts{}
+	sectionCM.Name = sectionData.Name
+	sectionCM.Id = section.Id
+
+	err = s.treeContractDao.Save(sectionCM, []string{"Name"})
+	if err != nil {
+		return errors.New("保存失败")
+	}
+	return nil
+}
+
+// 项目节删除
+func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId int) error {
+	// 1.验证项目节ID
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	if section.Id == 0 {
+		return errors.New("未找到合同项目节")
+	}
+
+	err := s.treeContractDao.Delete(section)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// 项目节的层级移动
+func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+	// 1.验证项目节ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		return err
+	}
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	if section.Id == 0 {
+		return errors.New("未找到合同项目节")
+	}
+	// 2.层级降级-同级有前一个兄弟节点
+	elderBrother := &models.CmTreeContracts{}
+	if sectionData.Operation == "downDepth" {
+		// 获得前一个兄弟节点
+		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
+		if len(elderBrotherList) == 0 {
+			return errors.New("项目节不能降级")
+		}
+		elderBrother = &elderBrotherList[0]
+	} else if sectionData.Operation == "upDepth" { // 3.层级升级-只要有父亲都能升级
+
+		// 获得父亲节点
+		if section.ParentId == 0 {
+			return errors.New("项目节不能升级")
+		}
+	} else {
+		return errors.New("参数错误")
+	}
+
+	// 4.执行升降级
+	err = s.treeContractDao.MoveDepth(section, elderBrother, sectionData.Operation, bidsectionId, projectId)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// 项目节的排序移动
+func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+	// 1.验证项目节ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		return err
+	}
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
+	if section.Id == 0 {
+		return errors.New("未找到合同项目节")
+	}
+
+	// 2.下移
+	brother := &models.CmTreeContracts{}
+	if sectionData.Operation == "downSerial" {
+		// 获得下一个兄弟
+		youngerBrotherList := s.treeContractDao.GetYoungerBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
+		if len(youngerBrotherList) == 0 {
+			return errors.New("项目节不能下移")
+		}
+		brother = &youngerBrotherList[0]
+	} else if sectionData.Operation == "upSerial" {
+		// 获得上一个兄弟
+		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
+		if len(elderBrotherList) == 0 {
+			return errors.New("项目节不能上移")
+		}
+		brother = &elderBrotherList[0]
+	} else {
+		return errors.New("参数错误")
+	}
+
+	// 4.执行升降级
+	err = s.treeContractDao.MoveSerial(section, brother, sectionData.Operation, bidsectionId, projectId)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 49 - 159
services/contract_service.go

@@ -7,20 +7,11 @@
 package services
 
 import (
-	"errors"
-	"fmt"
 	"log"
-	"strconv"
-	"time"
 
 	"github.com/kataras/iris/v12"
-	"go.mod/comm"
-	"go.mod/conf"
 	"go.mod/dao"
 	"go.mod/datasource"
-	"go.mod/lib"
-	"go.mod/models"
-	"go.mod/web/utils"
 	"go.mod/web/viewmodels"
 )
 
@@ -28,11 +19,17 @@ import (
 type ContractService interface {
 	ValidRuleDepth(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
-	// Create(viewBidAccount viewmodels.BidAccount, projectId int) error
-	// Delete(viewBidAccount viewmodels.BidAccount, projectId int) error
+	ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
+	ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
+	ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
+
+	Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract
 	GetAll()
-	GetSeciontTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract
+	GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract
 	SetSection(templateNumber int, bidsectionId int, projectIdInt int) error
+	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
+	SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
+	SectionDelete(treeId int, bidsectionId int, projectId int) error
 	MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
 	MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
 }
@@ -95,172 +92,65 @@ func (s *contractService) ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeS
 	return treeSectionVaild, nil
 }
 
-// 获得合同标段内容
-func (s *contractService) GetAll() {
-
-}
-
-// 获得合同项目节
-func (s *contractService) GetSeciontTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
-	sectionList := make([]*viewmodels.TreeSectionContract, 0)
-	dataList := s.treeContractDao.GetAll(bidsectionId, projectId)
-	// 生成根
-	sectionRoot := &viewmodels.TreeSectionContract{}
-	id, _ := comm.AesEncrypt(strconv.Itoa(0), conf.SignSecret)
-	parentId, _ := comm.AesEncrypt(strconv.Itoa(-1), conf.SignSecret)
-	sectionRoot.Id = id
-	sectionRoot.Name = "root"
-	sectionRoot.ParentId = parentId
-	sectionList = append(sectionList, sectionRoot)
-	for _, data := range dataList {
-		section := &viewmodels.TreeSectionContract{}
-		id, _ := comm.AesEncrypt(strconv.Itoa(data.TreeId), conf.SignSecret)
-		parentId, _ := comm.AesEncrypt(strconv.Itoa(data.ParentId), conf.SignSecret)
-		projectId, _ := comm.AesEncrypt(strconv.Itoa(data.ProjectId), conf.SignSecret)
-		contractId, _ := comm.AesEncrypt(strconv.Itoa(data.ContractId), conf.SignSecret)
-		section.Id = id
-		section.Name = data.Name
-		section.ParentId = parentId
-		section.Depth = data.Depth + 1
-		section.Serial = data.Serial
-		section.Attribution = data.Attribution
-		section.Code = data.Code
-		section.ProjectId = projectId
-		section.ContractId = contractId
-
-		section.Name = data.Name
-		section.ContractCode = data.ContractCode
-		section.ContractPrice = data.ContractPrice
-		section.ContractReturned = data.ContractReturned
-		section.ContractsPaid = data.ContractsPaid
-		section.ContractStatus = data.ContractStatus
-
-		section.CreateTime = data.CreateTime.Format(conf.SysTimeform)
-		sectionList = append(sectionList, section)
+// 模板规则新增项目节
+func (s *contractService) ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadJSON(treeSectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
 	}
 
-	Node := sectionRoot //父节点
-	comm.MakeSectionContract(sectionList, Node)
-	return Node
-}
-
-// 设置合同项目节初始数据-根据模板导入
-func (s *contractService) SetSection(templateNumber int, bidsectionId int, projectId int) error {
-	// 获得模板数据
-	templateTree := make([]*lib.ItemSectionTemplateTree, 0)
-	if templateNumber == 1 {
-		templateTree = lib.NewItemSectionData().TemplateList1
-	} else if templateNumber == 2 {
-		templateTree = lib.NewItemSectionData().TemplateList2
-	} else {
-		return errors.New("找不到合同项目节模板")
+	err = treeSectionVaild.ValidateSectionAdd()
+	if err != nil {
+		log.Println("参数验证错误, error=", err)
+		return treeSectionVaild, err
 	}
 
-	// 1.组合数据-写入库中
-	sectionTreeList := make([]*models.CmTreeContracts, 0)
-	for _, item := range templateTree {
-		section := &models.CmTreeContracts{}
-		section.TreeId = item.Id
-		section.ParentId = item.ParentId
-		section.ProjectId = projectId
-		section.BidsectionId = bidsectionId
-		section.Name = item.Name
-		section.Depth = item.Depth
-		section.Serial = item.Serial
-		section.Attribution = item.Attribution
-		section.Code = fmt.Sprintf("%s%d", item.Attribution, item.Serial)
-		section.CreateTime = time.Now()
-
-		section.ContractPrice = "0"
-		section.ContractReturned = "0"
-		section.ContractsPaid = "0"
+	return treeSectionVaild, nil
+}
 
-		sectionTreeList = append(sectionTreeList, section)
+// 模板规则新增项目节
+func (s *contractService) ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadJSON(treeSectionVaild)
+	if err != nil {
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
 	}
 
-	err := s.treeContractDao.CreateAll(sectionTreeList)
+	err = treeSectionVaild.ValidateSectionDelete()
 	if err != nil {
-		log.Println("设置合同项目节模板错误 err=", err)
-		return errors.New("设置合同项目节模板错误")
+		log.Println("参数验证错误, error=", err)
+		return treeSectionVaild, err
 	}
-	return nil
+
+	return treeSectionVaild, nil
 }
 
-// 项目节的层级移动
-func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
-	// 1.验证项目节ID
-	treeId, err := utils.GetDecryptId(sectionData.Id)
+func (s *contractService) ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
+	treeSectionVaild := &viewmodels.TreeSectionContract{}
+	err := ctx.ReadForm(treeSectionVaild)
 	if err != nil {
-		return err
-	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
-	if section.Id == 0 {
-		return errors.New("未找到合同项目节")
-	}
-	// 2.层级降级-同级有前一个兄弟节点
-	elderBrother := &models.CmTreeContracts{}
-	if sectionData.Operation == "downDepth" {
-		// 获得前一个兄弟节点
-		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
-		if len(elderBrotherList) == 0 {
-			return errors.New("项目节不能降级")
-		}
-		elderBrother = &elderBrotherList[0]
-	} else if sectionData.Operation == "upDepth" { // 3.层级升级-只要有父亲都能升级
-
-		// 获得父亲节点
-		if section.ParentId == 0 {
-			return errors.New("项目节不能升级")
-		}
-	} else {
-		return errors.New("参数错误")
+		log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
+		return treeSectionVaild, err
 	}
 
-	// 4.执行升降级
-	err = s.treeContractDao.MoveDepth(section, elderBrother, sectionData.Operation, bidsectionId, projectId)
+	err = treeSectionVaild.ValidateSectionDelete()
 	if err != nil {
-		return err
+		log.Println("参数验证错误, error=", err)
+		return treeSectionVaild, err
 	}
+	return treeSectionVaild, nil
+}
+
+// 获得项目节
+func (s *contractService) Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
 
 	return nil
 }
 
-// 项目节的排序移动
-func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
-	// 1.验证项目节ID
-	treeId, err := utils.GetDecryptId(sectionData.Id)
-	if err != nil {
-		return err
-	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId)
-	if section.Id == 0 {
-		return errors.New("未找到合同项目节")
-	}
-
-	// 2.下移
-	brother := &models.CmTreeContracts{}
-	if sectionData.Operation == "downSerial" {
-		// 获得下一个兄弟
-		youngerBrotherList := s.treeContractDao.GetYoungerBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
-		if len(youngerBrotherList) == 0 {
-			return errors.New("项目节不能下移")
-		}
-		brother = &youngerBrotherList[0]
-	} else if sectionData.Operation == "upSerial" {
-		// 获得上一个兄弟
-		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId)
-		if len(elderBrotherList) == 0 {
-			return errors.New("项目节不能上移")
-		}
-		brother = &elderBrotherList[0]
-	} else {
-		return errors.New("参数错误")
-	}
+// 获得合同标段内容
+func (s *contractService) GetAll() {
 
-	// 4.执行升降级
-	err = s.treeContractDao.MoveSerial(section, brother, sectionData.Operation, bidsectionId, projectId)
-	if err != nil {
-		return err
-	}
-	return nil
 }

+ 51 - 124
web/api/contract_api.go

@@ -1,5 +1,5 @@
 /*
- * @description: 合同管理相关API
+ * @description: 合同管理 相关API
  * @Author: CP
  * @Date: 2020-10-26 15:27:04
  * @FilePath: \construction_management\web\api\contract_api.go
@@ -33,8 +33,8 @@ type ContractApi struct {
 // @Produce  json
 // @Security ApiKeyAuth
 // @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
-// @Router /api/contract [get]
-func (c *ContractApi) Get() {
+// @Router /api/contract/folder [get]
+func (c *ContractApi) GetFolder() {
 	// 获得项目ID
 	projectIdInt, err := utils.GetProjectId(c.Ctx)
 	if err != nil {
@@ -87,7 +87,7 @@ func (c *ContractApi) GetIncome() {
 	}
 
 	//获得合同项目节
-	sectionTree := c.ServiceContract.GetSeciontTree(bidsectionId, projectIdInt)
+	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
 
 	// 1.未设置了项目节
 	if len(sectionTree.Children) == 0 {
@@ -117,141 +117,68 @@ func (c *ContractApi) GetIncome() {
 	}
 }
 
-// @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)
+// 获得合同详情和项目节详情
+func (c *ContractApi) Get() {
+	// 1.规则验证
+	sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "解析参数出错"})
 		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)
+	// 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})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
 		return
 	}
-	err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
+	// 4.树ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
 		return
 	}
-	c.Ctx.JSON(iris.Map{
-		"code": 0,
-		"msg":  "操作成功",
-	})
-}
-
-// 修改合同项目节号
-func (c *ContractApi) PostSectionSave() {
-
+	fmt.Println(projectId)
+	fmt.Println(bidsectionId)
+	fmt.Println(treeId)
+	// 获得项目节详情
+	c.ServiceContract.GetAll()
+	// 获得合同详情
 }
 
-// @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
-	}
-
+// 新增合同
+func (c *ContractApi) PostCreate() {
+
+	// // 获得模板号
+	// sectionData, err := c.ServiceContract.ValidRuleAdd(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
+	// }
+
+	// err = c.ServiceContract.Add(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": "新增成功"})
 }

+ 264 - 0
web/api/contract_section_tree_api.go

@@ -0,0 +1,264 @@
+/*
+ * @description: 合同管理 -项目节相关API
+ * @Author: CP
+ * @Date: 2020-10-26 15:27:04
+ * @FilePath: \construction_management\web\api\contract_section_tree_api.go
+ */
+package api
+
+import (
+	"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   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":  "操作成功",
+	})
+}
+
+// @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.GetSecionTree(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
+	}
+
+}
+
+// @Summary 新增 合同项目节
+// @Tags 合同管理
+// @Description 新增 合同项目节
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     body    int     true        "项目节ID"
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @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": "解析参数出错"})
+		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
+	}
+
+	err = c.ServiceContract.SectionAdd(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() {
+	// 获得模板号
+	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
+	}
+
+	err = c.ServiceContract.SectionSave(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 删除 合同项目节
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     body    int     true        "项目节ID"
+// @Param   bidsectionId     body    string     true        "标段ID"
+// @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
+// @Router /api/contract/section [delete]
+func (c *ContractApi) DeleteSection() {
+	// 获得模板号
+	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
+	}
+
+	err = c.ServiceContract.SectionDelete(treeId, 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": "删除成功"})
+}

+ 20 - 0
web/viewmodels/tree_section_contract.go

@@ -8,6 +8,9 @@ package viewmodels
 
 import validation "github.com/go-ozzo/ozzo-validation/v3"
 
+// ElderBrother 为true 有前一个兄弟节点,可上移和下降
+// IsEnd 为true 不能下移
+
 type TreeSectionContract struct {
 	Id           string `form:"id" json:"id" `
 	ParentId     string `form:"parentId" json:"parentId"`
@@ -33,6 +36,8 @@ type TreeSectionContract struct {
 
 	TemplateNumber int    `form:"templateNumber" json:"templateNumber"`
 	Operation      string `form:"operation" json:"operation"`
+	ElderBrother   bool   `form:"elderBrother" json:"elderBrother"`
+	IsEnd          bool   `form:"isEnd" json:"isEnd"`
 }
 
 func (l TreeSectionContract) ValidateDepth() error {
@@ -50,6 +55,21 @@ func (l TreeSectionContract) ValidateTemplate() error {
 	)
 }
 
+func (l TreeSectionContract) ValidateSectionAdd() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+		validation.Field(&l.Name, validation.Required.Error("项目节名称不能为空")),
+	)
+}
+
+func (l TreeSectionContract) ValidateSectionDelete() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+	)
+}
+
 // Isfolder int `form:"isfolder" json:"isfolder"`
 
 // 	UpdateTime     string `form:"updateTime" json:"updateTime"`