|  | @@ -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
 | 
	
		
			
				|  |  |  }
 |