作者 tangxvhui

bug 修复

... ... @@ -7,6 +7,7 @@ import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/services/ucenter"
"oppmg/utils"
"time"
... ... @@ -185,6 +186,13 @@ func AddCompanyData(data ModuleCompanytData) error {
newUserCompany *models.UserCompany
err error
)
log.Info("获取统一户中心的数据")
ucenterReturn, err := ucenter.RequestUCenterAddUser(data.User.Phone, data.User.Name, "")
if err != nil {
log.Error("请求统一用户中心数据失败:%s", err)
return errors.New("获取统一用户中心数据失败")
}
data.User.OpenId = ucenterReturn.Data.Id
o := orm.NewOrm()
o.Begin()
//处理用户数据
... ... @@ -382,6 +390,7 @@ func AddFirstDepartment(newCompany *models.Company, newusercompany *models.UserC
IsTop: 1,
ParentId: 0,
Relation: fmt.Sprint(utils.GenerateIDBySonyflake()),
Id: utils.GenerateID14(),
}
_, err = models.AddDepartment(newDepartment, o)
if err != nil {
... ...
... ... @@ -190,8 +190,7 @@ func departmentRelationUpdate(departmentUpdate models.Department, newparent mode
//重建关系树
s := strings.TrimLeft(departmentSubset[i].Relation, oldRelation)
departmentSubset[i].Relation = fmt.Sprintf("%s%s", newRelation, s)
s1 := strings.Split(departmentSubset[i].Relation, ",")
departmentSubset[i].Level = len(s1) - 2
departmentSubset[i].Level = setDepartmentLevel(departmentSubset[i].Relation)
}
//修改部门及子级部门的relation
... ... @@ -257,8 +256,8 @@ func AddDepartmentData(data []ModuleDeparmentData) error {
departmentData.ParentId = topDepartment.Id
departmentData.SetRelation(topDepartment)
}
s := strings.Split(departmentData.Relation, ",")
departmentData.Level = len(s) - 2
departmentData.Level = setDepartmentLevel(departmentData.Relation)
_, err = models.AddDepartment(departmentData, o)
if err != nil {
e := fmt.Errorf("存储部门数据失败,err:%s", err)
... ... @@ -271,6 +270,11 @@ func AddDepartmentData(data []ModuleDeparmentData) error {
return nil
}
func setDepartmentLevel(relation string) int {
s := strings.Split(relation, ",")
return len(s) - 3
}
//DeleteDepartmentData ...
func DeleteDepartmentData(ids []int64) error {
o := orm.NewOrm()
... ...
... ... @@ -320,7 +320,7 @@ func getRangeDataRelationLsit(rankRangeId int64, rangeType int8) []protocol.Rank
}
func RankRangeNameOnlyOne(rankTypeId int64, rankRangeId int64, name string) bool {
sql := `SELECT 1 FROM rank_range WHERE rank_type_id=? AND name=? AND id<>? LIMIT 1`
sql := `SELECT count(*) FROM rank_range WHERE rank_type_id=? AND name=? AND id<>?`
var (
err error
cnt int
... ...
... ... @@ -2,6 +2,8 @@ package utils
import (
"encoding/hex"
"fmt"
"strconv"
uuid "github.com/satori/go.uuid"
"github.com/sony/sonyflake"
... ... @@ -9,13 +11,26 @@ import (
var sf = sonyflake.NewSonyflake(sonyflake.Settings{})
//GenerateIDBySonyflake 18位雪花id
func GenerateIDBySonyflake() int64 {
num, _ := sf.NextID()
return int64(num)
}
func GenerateIDByUUID() string {
ubyte := uuid.NewV4().Bytes()
s := hex.EncodeToString(ubyte)
return s
}
func GenerateID14() int64 {
num := GenerateIDBySonyflake()
s := fmt.Sprintf("%d", num)
if len(s) < 4 {
return 0
}
i, _ := strconv.ParseInt(s[4:], 10, 64)
return i
}
... ...