正在显示
4 个修改的文件
包含
33 行增加
和
5 行删除
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
7 | "oppmg/common/log" | 7 | "oppmg/common/log" |
8 | "oppmg/models" | 8 | "oppmg/models" |
9 | "oppmg/protocol" | 9 | "oppmg/protocol" |
10 | + "oppmg/services/ucenter" | ||
10 | "oppmg/utils" | 11 | "oppmg/utils" |
11 | "time" | 12 | "time" |
12 | 13 | ||
@@ -185,6 +186,13 @@ func AddCompanyData(data ModuleCompanytData) error { | @@ -185,6 +186,13 @@ func AddCompanyData(data ModuleCompanytData) error { | ||
185 | newUserCompany *models.UserCompany | 186 | newUserCompany *models.UserCompany |
186 | err error | 187 | err error |
187 | ) | 188 | ) |
189 | + log.Info("获取统一户中心的数据") | ||
190 | + ucenterReturn, err := ucenter.RequestUCenterAddUser(data.User.Phone, data.User.Name, "") | ||
191 | + if err != nil { | ||
192 | + log.Error("请求统一用户中心数据失败:%s", err) | ||
193 | + return errors.New("获取统一用户中心数据失败") | ||
194 | + } | ||
195 | + data.User.OpenId = ucenterReturn.Data.Id | ||
188 | o := orm.NewOrm() | 196 | o := orm.NewOrm() |
189 | o.Begin() | 197 | o.Begin() |
190 | //处理用户数据 | 198 | //处理用户数据 |
@@ -382,6 +390,7 @@ func AddFirstDepartment(newCompany *models.Company, newusercompany *models.UserC | @@ -382,6 +390,7 @@ func AddFirstDepartment(newCompany *models.Company, newusercompany *models.UserC | ||
382 | IsTop: 1, | 390 | IsTop: 1, |
383 | ParentId: 0, | 391 | ParentId: 0, |
384 | Relation: fmt.Sprint(utils.GenerateIDBySonyflake()), | 392 | Relation: fmt.Sprint(utils.GenerateIDBySonyflake()), |
393 | + Id: utils.GenerateID14(), | ||
385 | } | 394 | } |
386 | _, err = models.AddDepartment(newDepartment, o) | 395 | _, err = models.AddDepartment(newDepartment, o) |
387 | if err != nil { | 396 | if err != nil { |
@@ -190,8 +190,7 @@ func departmentRelationUpdate(departmentUpdate models.Department, newparent mode | @@ -190,8 +190,7 @@ func departmentRelationUpdate(departmentUpdate models.Department, newparent mode | ||
190 | //重建关系树 | 190 | //重建关系树 |
191 | s := strings.TrimLeft(departmentSubset[i].Relation, oldRelation) | 191 | s := strings.TrimLeft(departmentSubset[i].Relation, oldRelation) |
192 | departmentSubset[i].Relation = fmt.Sprintf("%s%s", newRelation, s) | 192 | departmentSubset[i].Relation = fmt.Sprintf("%s%s", newRelation, s) |
193 | - s1 := strings.Split(departmentSubset[i].Relation, ",") | ||
194 | - departmentSubset[i].Level = len(s1) - 2 | 193 | + departmentSubset[i].Level = setDepartmentLevel(departmentSubset[i].Relation) |
195 | } | 194 | } |
196 | 195 | ||
197 | //修改部门及子级部门的relation | 196 | //修改部门及子级部门的relation |
@@ -257,8 +256,8 @@ func AddDepartmentData(data []ModuleDeparmentData) error { | @@ -257,8 +256,8 @@ func AddDepartmentData(data []ModuleDeparmentData) error { | ||
257 | departmentData.ParentId = topDepartment.Id | 256 | departmentData.ParentId = topDepartment.Id |
258 | departmentData.SetRelation(topDepartment) | 257 | departmentData.SetRelation(topDepartment) |
259 | } | 258 | } |
260 | - s := strings.Split(departmentData.Relation, ",") | ||
261 | - departmentData.Level = len(s) - 2 | 259 | + |
260 | + departmentData.Level = setDepartmentLevel(departmentData.Relation) | ||
262 | _, err = models.AddDepartment(departmentData, o) | 261 | _, err = models.AddDepartment(departmentData, o) |
263 | if err != nil { | 262 | if err != nil { |
264 | e := fmt.Errorf("存储部门数据失败,err:%s", err) | 263 | e := fmt.Errorf("存储部门数据失败,err:%s", err) |
@@ -271,6 +270,11 @@ func AddDepartmentData(data []ModuleDeparmentData) error { | @@ -271,6 +270,11 @@ func AddDepartmentData(data []ModuleDeparmentData) error { | ||
271 | return nil | 270 | return nil |
272 | } | 271 | } |
273 | 272 | ||
273 | +func setDepartmentLevel(relation string) int { | ||
274 | + s := strings.Split(relation, ",") | ||
275 | + return len(s) - 3 | ||
276 | +} | ||
277 | + | ||
274 | //DeleteDepartmentData ... | 278 | //DeleteDepartmentData ... |
275 | func DeleteDepartmentData(ids []int64) error { | 279 | func DeleteDepartmentData(ids []int64) error { |
276 | o := orm.NewOrm() | 280 | o := orm.NewOrm() |
@@ -320,7 +320,7 @@ func getRangeDataRelationLsit(rankRangeId int64, rangeType int8) []protocol.Rank | @@ -320,7 +320,7 @@ func getRangeDataRelationLsit(rankRangeId int64, rangeType int8) []protocol.Rank | ||
320 | } | 320 | } |
321 | 321 | ||
322 | func RankRangeNameOnlyOne(rankTypeId int64, rankRangeId int64, name string) bool { | 322 | func RankRangeNameOnlyOne(rankTypeId int64, rankRangeId int64, name string) bool { |
323 | - sql := `SELECT 1 FROM rank_range WHERE rank_type_id=? AND name=? AND id<>? LIMIT 1` | 323 | + sql := `SELECT count(*) FROM rank_range WHERE rank_type_id=? AND name=? AND id<>?` |
324 | var ( | 324 | var ( |
325 | err error | 325 | err error |
326 | cnt int | 326 | cnt int |
@@ -2,6 +2,8 @@ package utils | @@ -2,6 +2,8 @@ package utils | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/hex" | 4 | "encoding/hex" |
5 | + "fmt" | ||
6 | + "strconv" | ||
5 | 7 | ||
6 | uuid "github.com/satori/go.uuid" | 8 | uuid "github.com/satori/go.uuid" |
7 | "github.com/sony/sonyflake" | 9 | "github.com/sony/sonyflake" |
@@ -9,13 +11,26 @@ import ( | @@ -9,13 +11,26 @@ import ( | ||
9 | 11 | ||
10 | var sf = sonyflake.NewSonyflake(sonyflake.Settings{}) | 12 | var sf = sonyflake.NewSonyflake(sonyflake.Settings{}) |
11 | 13 | ||
14 | +//GenerateIDBySonyflake 18位雪花id | ||
12 | func GenerateIDBySonyflake() int64 { | 15 | func GenerateIDBySonyflake() int64 { |
13 | num, _ := sf.NextID() | 16 | num, _ := sf.NextID() |
17 | + | ||
14 | return int64(num) | 18 | return int64(num) |
15 | } | 19 | } |
16 | 20 | ||
17 | func GenerateIDByUUID() string { | 21 | func GenerateIDByUUID() string { |
18 | ubyte := uuid.NewV4().Bytes() | 22 | ubyte := uuid.NewV4().Bytes() |
19 | s := hex.EncodeToString(ubyte) | 23 | s := hex.EncodeToString(ubyte) |
24 | + | ||
20 | return s | 25 | return s |
21 | } | 26 | } |
27 | + | ||
28 | +func GenerateID14() int64 { | ||
29 | + num := GenerateIDBySonyflake() | ||
30 | + s := fmt.Sprintf("%d", num) | ||
31 | + if len(s) < 4 { | ||
32 | + return 0 | ||
33 | + } | ||
34 | + i, _ := strconv.ParseInt(s[4:], 10, 64) | ||
35 | + return i | ||
36 | +} |
-
请 注册 或 登录 后发表评论