...
|
...
|
@@ -162,9 +162,6 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio |
|
|
|
|
|
//positionRelationUpdate 处理部门上级发生变化的情况
|
|
|
func positionRelationUpdate(positionUpdate *models.Position, newparent *models.Position) error {
|
|
|
if newparent == nil {
|
|
|
return nil
|
|
|
}
|
|
|
const (
|
|
|
//获取某个部门的下级部门 锁数据 select ... for update
|
|
|
dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
|
...
|
...
|
@@ -178,8 +175,15 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P |
|
|
err error
|
|
|
oldRelation string = positionUpdate.Relation
|
|
|
relationLike string = oldRelation + "%"
|
|
|
newRelation string = fmt.Sprintf("%s/%d", newparent.Relation, positionUpdate.Id)
|
|
|
newRelation string
|
|
|
)
|
|
|
if newparent == nil {
|
|
|
//修改节点为顶层节点的情况
|
|
|
newparent = &models.Position{}
|
|
|
newRelation = fmt.Sprintf("%d", positionUpdate.Id)
|
|
|
} else {
|
|
|
newRelation = fmt.Sprintf("%s/%d", newparent.Relation, positionUpdate.Id)
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//修改部门的parent_id
|
...
|
...
|
@@ -209,6 +213,11 @@ func positionRelationUpdate(positionUpdate *models.Position, newparent *models.P |
|
|
}
|
|
|
//重建关系树
|
|
|
s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation)
|
|
|
rs := strings.Split(s, "/")
|
|
|
if len(rs) >= 10 { //层级不能超过10级
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("10012")
|
|
|
}
|
|
|
positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
|
|
|
err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id)
|
|
|
if err != nil {
|
...
|
...
|
|