|  | @@ -29,11 +29,11 @@ func NewTreeContractDao(engine *xorm.Engine) *TreeContractDao {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得本项目的合同项目节
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) Get(treeId int, bidsectionId int, projectId int) *models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) Get(treeId int, bidsectionId int, projectId int, treeType int) *models.CmTreeContracts {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	data := &models.CmTreeContracts{}
 | 
	
		
			
				|  |  |  	_, err := d.engine.
 | 
	
		
			
				|  |  | -		Where("tree_id=? and bidsection_id =? and project_id=? ", treeId, bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("tree_id=? and bidsection_id =? and project_id=? and  tree_type=?", treeId, bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Get(data)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		data.Id = 0
 | 
	
	
		
			
				|  | @@ -43,11 +43,11 @@ func (d *TreeContractDao) Get(treeId int, bidsectionId int, projectId int) *mode
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得项目下的项目节
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetAll(bidsectionId int, projectId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetAll(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 0)
 | 
	
		
			
				|  |  |  	err := d.engine.
 | 
	
		
			
				|  |  |  		Asc("id").
 | 
	
		
			
				|  |  | -		Where("bidsection_id =? and project_id=?", bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("bidsection_id =? and project_id=? and tree_type=?", bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -57,11 +57,11 @@ func (d *TreeContractDao) GetAll(bidsectionId int, projectId int) []models.CmTre
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得标段 项目节中已有的合同
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetContract(bidsectionId int, projectId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 0)
 | 
	
		
			
				|  |  |  	err := d.engine.
 | 
	
		
			
				|  |  |  		Asc("id").
 | 
	
		
			
				|  |  | -		Where("bidsection_id =? and project_id=? and contract_id!=0", bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("bidsection_id =? and project_id=? and contract_id!=0 and tree_type=?", bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -71,11 +71,11 @@ func (d *TreeContractDao) GetContract(bidsectionId int, projectId int) []models.
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得节点的孩子
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetChildren(parentId int, bidsectionId int, projectId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetChildren(parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 0)
 | 
	
		
			
				|  |  |  	err := d.engine.
 | 
	
		
			
				|  |  |  		Asc("serial").
 | 
	
		
			
				|  |  | -		Where("parent_id=?  and bidsection_id=? and project_id=?", parentId, bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("parent_id=?  and bidsection_id=? and project_id=? and tree_type=?", parentId, bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -85,11 +85,11 @@ func (d *TreeContractDao) GetChildren(parentId int, bidsectionId int, projectId
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //根据序号和深度获得前一个兄弟节点
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetElderBrother(serial int, depth int, parentId int, bidsectionId int, projectId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetElderBrother(serial int, depth int, parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 0)
 | 
	
		
			
				|  |  |  	err := d.engine.
 | 
	
		
			
				|  |  |  		Desc("serial").
 | 
	
		
			
				|  |  | -		Where("serial < ? and depth = ? and  parent_id =? and bidsection_id=?  and project_id=?", serial, depth, parentId, bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("serial < ? and depth = ? and  parent_id =? and bidsection_id=?  and project_id=? and tree_type=?", serial, depth, parentId, bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -99,11 +99,11 @@ func (d *TreeContractDao) GetElderBrother(serial int, depth int, parentId int, b
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //根据序号和深度获得后一个兄弟节点
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetYoungerBrother(serial int, depth int, parentId int, bidsectionId int, projectId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetYoungerBrother(serial int, depth int, parentId int, bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 0)
 | 
	
		
			
				|  |  |  	err := d.engine.
 | 
	
		
			
				|  |  |  		Asc("serial").
 | 
	
		
			
				|  |  | -		Where("serial > ? and depth = ? and  parent_id =? and bidsection_id=?   and project_id=?", serial, depth, parentId, bidsectionId, projectId).
 | 
	
		
			
				|  |  | +		Where("serial > ? and depth = ? and  parent_id =? and bidsection_id=?   and project_id=? and tree_type=?", serial, depth, parentId, bidsectionId, projectId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -113,11 +113,11 @@ func (d *TreeContractDao) GetYoungerBrother(serial int, depth int, parentId int,
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得最后一条项目节
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetLast(projectId int) *models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetLast(projectId int, treeType int) *models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	data := &models.CmTreeContracts{}
 | 
	
		
			
				|  |  |  	_, err := d.engine.
 | 
	
		
			
				|  |  |  		Desc("id").
 | 
	
		
			
				|  |  | -		Where("project_id=?", projectId).
 | 
	
		
			
				|  |  | +		Where("project_id=? and tree_type=?", projectId, treeType).
 | 
	
		
			
				|  |  |  		Get(data)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		data.Id = 0
 | 
	
	
		
			
				|  | @@ -127,11 +127,11 @@ func (d *TreeContractDao) GetLast(projectId int) *models.CmTreeContracts {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 获得谋归属下的项目节
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) GetAttribution(attribution string, projectId int, bidsectionId int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) GetAttribution(attribution string, projectId int, bidsectionId int, treeType int) []models.CmTreeContracts {
 | 
	
		
			
				|  |  |  	datalist := make([]models.CmTreeContracts, 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 bidsection_id=? and tree_type=?", attribution+"%", projectId, bidsectionId, treeType).
 | 
	
		
			
				|  |  |  		Find(&datalist)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		return datalist
 | 
	
	
		
			
				|  | @@ -141,7 +141,7 @@ func (d *TreeContractDao) GetAttribution(attribution string, projectId int, bids
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 项目节升降级
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrother *models.CmTreeContracts, operation string, bidsectionId int, projectId int) error {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrother *models.CmTreeContracts, operation string, bidsectionId int, projectId int, treeType int) error {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	session := d.engine.NewSession()
 | 
	
		
			
				|  |  |  	defer session.Close()
 | 
	
	
		
			
				|  | @@ -160,7 +160,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		attribution := fmt.Sprintf("%s%d-", elderBrother.Attribution, elderBrother.Serial)
 | 
	
		
			
				|  |  |  		// 2-4 序号 没有孩子序号为1,有孩子 最大孩子序号+1
 | 
	
		
			
				|  |  |  		// 2-4-1 获得上一位哥的孩子们
 | 
	
		
			
				|  |  | -		elderBrotherChildren := d.GetChildren(elderBrother.TreeId, bidsectionId, projectId)
 | 
	
		
			
				|  |  | +		elderBrotherChildren := d.GetChildren(elderBrother.TreeId, bidsectionId, projectId, treeType)
 | 
	
		
			
				|  |  |  		serial := 1
 | 
	
		
			
				|  |  |  		if len(elderBrotherChildren) != 0 {
 | 
	
		
			
				|  |  |  			serial = elderBrotherChildren[len(elderBrotherChildren)-1].Serial + 1
 | 
	
	
		
			
				|  | @@ -171,7 +171,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		// 移动后编号
 | 
	
		
			
				|  |  |  		moveCode := fmt.Sprintf("%s%d", attribution, serial)
 | 
	
		
			
				|  |  |  		_, err = session.Exec("UPDATE  cm_tree_contracts SET `parent_id` = ?,attribution= ? , serial = ? ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"')"+
 | 
	
		
			
				|  |  | -			",`depth` =`depth` + ? where id = ? ", elderBrother.TreeId, attribution, serial, 1, section.Id)
 | 
	
		
			
				|  |  | +			",`depth` =`depth` + ? where id = ? and tree_type=? ", elderBrother.TreeId, attribution, serial, 1, section.Id, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("降级失败")
 | 
	
	
		
			
				|  | @@ -184,14 +184,14 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		moveAttributionChildren := fmt.Sprintf("%s%d-", attribution, serial)
 | 
	
		
			
				|  |  |  		// 3-2 降级 深度+1
 | 
	
		
			
				|  |  |  		_, err = session.Exec("UPDATE  cm_tree_contracts SET  "+
 | 
	
		
			
				|  |  | -			"`depth` =`depth` + ? where attribution like ? and project_id=? and bidsection_id=? ", 1, attributionChildren+"%", projectId, bidsectionId)
 | 
	
		
			
				|  |  | +			"`depth` =`depth` + ? where attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", 1, attributionChildren+"%", projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("降级失败")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		// 3-3--替换 归属和编号
 | 
	
		
			
				|  |  |  		// "`attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"'),"
 | 
	
		
			
				|  |  | -		err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId)
 | 
	
		
			
				|  |  | +		err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("降级失败")
 | 
	
	
		
			
				|  | @@ -199,7 +199,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  	} else if operation == "upDepth" {
 | 
	
		
			
				|  |  |  		// 升级
 | 
	
		
			
				|  |  |  		// 1.父亲节点
 | 
	
		
			
				|  |  | -		sectionFather := d.Get(section.ParentId, bidsectionId, projectId)
 | 
	
		
			
				|  |  | +		sectionFather := d.Get(section.ParentId, bidsectionId, projectId, treeType)
 | 
	
		
			
				|  |  |  		if sectionFather.Id == 0 {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("升级-未找到上级项目节")
 | 
	
	
		
			
				|  | @@ -207,7 +207,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		// 2.原节点的父亲ID字段升级为爷爷ID
 | 
	
		
			
				|  |  |  		// 2-1 升级 深度-1
 | 
	
		
			
				|  |  |  		// 2-2 序号 爷爷的孩子们的 序号+1
 | 
	
		
			
				|  |  | -		grandpaChildren := d.GetChildren(sectionFather.ParentId, bidsectionId, projectId)
 | 
	
		
			
				|  |  | +		grandpaChildren := d.GetChildren(sectionFather.ParentId, bidsectionId, projectId, treeType)
 | 
	
		
			
				|  |  |  		serial := 1
 | 
	
		
			
				|  |  |  		if len(grandpaChildren) != 0 {
 | 
	
		
			
				|  |  |  			serial = grandpaChildren[len(grandpaChildren)-1].Serial + 1
 | 
	
	
		
			
				|  | @@ -217,7 +217,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		moveCode := fmt.Sprintf("%s%d", sectionFather.Attribution, serial)
 | 
	
		
			
				|  |  |  		// 升级的项目节
 | 
	
		
			
				|  |  |  		_, err = session.Exec("UPDATE  cm_tree_contracts SET `parent_id` = ?,attribution= ? , serial = ? ,`code` = replace(`code`, '"+section.Code+"', '"+moveCode+"')"+
 | 
	
		
			
				|  |  | -			",`depth` =`depth` - ? where id = ? ", sectionFather.ParentId, sectionFather.Attribution, serial, 1, section.Id)
 | 
	
		
			
				|  |  | +			",`depth` =`depth` - ? where id = ? and tree_type=? ", sectionFather.ParentId, sectionFather.Attribution, serial, 1, section.Id, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("升级失败")
 | 
	
	
		
			
				|  | @@ -229,13 +229,13 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  		moveAttributionChildren := fmt.Sprintf("%s%d-", sectionFather.Attribution, serial)
 | 
	
		
			
				|  |  |  		// 深度 -1
 | 
	
		
			
				|  |  |  		_, err = session.Exec("UPDATE  cm_tree_contracts SET `attribution` = replace(`attribution`, '"+attributionChildren+"', '"+moveAttributionChildren+"') "+
 | 
	
		
			
				|  |  | -			",`depth` =`depth` - ? where attribution like ? and project_id=? and bidsection_id=? ", 1, attributionChildren+"%", projectId, bidsectionId)
 | 
	
		
			
				|  |  | +			",`depth` =`depth` - ? where attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", 1, attributionChildren+"%", projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("升级失败")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		// 3-1
 | 
	
		
			
				|  |  | -		err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId)
 | 
	
		
			
				|  |  | +		err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, moveCode, projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  		if err != nil {
 | 
	
		
			
				|  |  |  			session.Rollback()
 | 
	
		
			
				|  |  |  			return errors.New("升级失败")
 | 
	
	
		
			
				|  | @@ -254,7 +254,7 @@ func (d *TreeContractDao) MoveDepth(section *models.CmTreeContracts, elderBrothe
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 合同项目节上下移动
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *models.CmTreeContracts, operation string, bidsectionId int, projectId int) error {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *models.CmTreeContracts, operation string, bidsectionId int, projectId int, treeType int) error {
 | 
	
		
			
				|  |  |  	session := d.engine.NewSession()
 | 
	
		
			
				|  |  |  	defer session.Close()
 | 
	
		
			
				|  |  |  	err := session.Begin()
 | 
	
	
		
			
				|  | @@ -264,13 +264,13 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	//1.上下移
 | 
	
		
			
				|  |  |  	// 1.项目节序号替换为兄弟序号
 | 
	
		
			
				|  |  | -	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = replace(`code`, '"+section.Code+"', '"+brother.Code+"')  where id = ? ", brother.Serial, section.Id)
 | 
	
		
			
				|  |  | +	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = replace(`code`, '"+section.Code+"', '"+brother.Code+"')  where id = ? and tree_type=? ", brother.Serial, section.Id, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		return errors.New("移动失败")
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	// 兄弟序号替换为项目节序号
 | 
	
		
			
				|  |  | -	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = replace(`code`, '"+brother.Code+"', '"+section.Code+"')  where id = ? ", section.Serial, brother.Id)
 | 
	
		
			
				|  |  | +	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = replace(`code`, '"+brother.Code+"', '"+section.Code+"')  where id = ? and tree_type=? ", section.Serial, brother.Id, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		return errors.New("移动失败")
 | 
	
	
		
			
				|  | @@ -281,7 +281,7 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 | 
	
		
			
				|  |  |  	// 移动后的 孩子归属和编号
 | 
	
		
			
				|  |  |  	moveAttributionChildren := fmt.Sprintf("%s%d-", brother.Attribution, brother.Serial)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, brother.Code, projectId, bidsectionId)
 | 
	
		
			
				|  |  | +	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, section.Code, brother.Code, projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		return errors.New("移动失败")
 | 
	
	
		
			
				|  | @@ -299,7 +299,7 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 | 
	
		
			
				|  |  |  	attributionChildren = fmt.Sprintf("%s%d-", brother.Attribution, brother.Serial)
 | 
	
		
			
				|  |  |  	// 移动后的 孩子归属
 | 
	
		
			
				|  |  |  	moveAttributionChildren = fmt.Sprintf("%s%d-", section.Attribution, section.Serial)
 | 
	
		
			
				|  |  | -	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, brother.Code, section.Code, projectId, bidsectionId)
 | 
	
		
			
				|  |  | +	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, brother.Code, section.Code, projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		return errors.New("移动失败")
 | 
	
	
		
			
				|  | @@ -314,7 +314,7 @@ func (d *TreeContractDao) MoveSerial(section *models.CmTreeContracts, brother *m
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 修改项目节序号
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) UpdateSerial(section *models.CmTreeContracts, serial int) error {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) UpdateSerial(section *models.CmTreeContracts, serial int, treeType int) error {
 | 
	
		
			
				|  |  |  	session := d.engine.NewSession()
 | 
	
		
			
				|  |  |  	defer session.Close()
 | 
	
		
			
				|  |  |  	err := session.Begin()
 | 
	
	
		
			
				|  | @@ -324,7 +324,7 @@ func (d *TreeContractDao) UpdateSerial(section *models.CmTreeContracts, serial i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	// 1.更新项目节序号和项目节编号
 | 
	
		
			
				|  |  |  	moveCode := fmt.Sprintf("%s%d", section.Attribution, serial)
 | 
	
		
			
				|  |  | -	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = ?  where id = ? ", serial, moveCode, section.Id)
 | 
	
		
			
				|  |  | +	_, err = session.Exec("UPDATE  cm_tree_contracts SET  serial = ? , `code` = ?  where id = ? and tree_type=? ", serial, moveCode, section.Id, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		log.Println("合同项目节序号更新 error=", err)
 | 
	
	
		
			
				|  | @@ -337,7 +337,7 @@ func (d *TreeContractDao) UpdateSerial(section *models.CmTreeContracts, serial i
 | 
	
		
			
				|  |  |  	moveAttributionChildren := fmt.Sprintf("%s%d-", section.Attribution, serial)
 | 
	
		
			
				|  |  |  	// 2-3 项目节 孩子的编号
 | 
	
		
			
				|  |  |  	code := fmt.Sprintf("%s%d", section.Attribution, section.Serial)
 | 
	
		
			
				|  |  | -	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, code, moveCode, section.ProjectId, section.BidsectionId)
 | 
	
		
			
				|  |  | +	err = d.replaceContractAttribution(session, attributionChildren, moveAttributionChildren, code, moveCode, section.ProjectId, section.BidsectionId, treeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		log.Println("合同项目节序号更新 error=", err)
 | 
	
	
		
			
				|  | @@ -417,7 +417,7 @@ func (d *TreeContractDao) Delete(section *models.CmTreeContracts) error {
 | 
	
		
			
				|  |  |  	// 孩子们的归属
 | 
	
		
			
				|  |  |  	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)
 | 
	
		
			
				|  |  | +	_, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE attribution like ? and project_id=? and bidsection_id=? and tree_type=? ", attribution+"%", section.ProjectId, section.BidsectionId, section.TreeType)
 | 
	
		
			
				|  |  |  	if err != nil {
 | 
	
		
			
				|  |  |  		session.Rollback()
 | 
	
		
			
				|  |  |  		return errors.New("删除失败")
 | 
	
	
		
			
				|  | @@ -432,9 +432,9 @@ func (d *TreeContractDao) Delete(section *models.CmTreeContracts) error {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //替换项目节归属
 | 
	
		
			
				|  |  | -func (d *TreeContractDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, code string, moveCode string, projectId int, bidsectionId int) error {
 | 
	
		
			
				|  |  | +func (d *TreeContractDao) replaceContractAttribution(session *xorm.Session, attributionChildren string, moveAttributionChildren string, code string, moveCode string, projectId int, bidsectionId int, treeType int) error {
 | 
	
		
			
				|  |  |  	// 1.获得需要替换的数据
 | 
	
		
			
				|  |  | -	sectionData := d.GetAttribution(attributionChildren, projectId, bidsectionId)
 | 
	
		
			
				|  |  | +	sectionData := d.GetAttribution(attributionChildren, projectId, bidsectionId, treeType)
 | 
	
		
			
				|  |  |  	if len(sectionData) == 0 {
 | 
	
		
			
				|  |  |  		return nil
 | 
	
		
			
				|  |  |  	}
 |