refactor(serial):唯一序列号生成器改进。

This commit is contained in:
徐涛
2023-06-07 21:25:28 +08:00
parent bfb59a3626
commit 6bf4009338
3 changed files with 72 additions and 59 deletions

View File

@@ -100,6 +100,8 @@ func (pr _ParkRepository) CreatePark(ownerId string, park *model.Park) (bool, er
defer cancel()
timeNow := types.Now()
serial.StringSerialRequestChan <- 1
code := serial.Prefix("P", <-serial.StringSerialResponseChan)
createSql, createArgs, _ := pr.ds.
Insert("park").
Cols(
@@ -108,7 +110,7 @@ func (pr _ParkRepository) CreatePark(ownerId string, park *model.Park) (bool, er
"basic_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at", "last_modified_at",
).
Vals(goqu.Vals{
serial.GeneratePrefixedUniqueSerialString("P"),
code,
ownerId, park.Name, tools.PinyinAbbr(park.Name),
park.Area, park.TenementQuantity, park.Capacity, park.Category,
park.MeterType, park.Region, park.Address, park.Contact, park.Phone, park.Enabled, park.PricePolicy, park.TaxRate,
@@ -347,13 +349,15 @@ func (pr _ParkRepository) CreateParkBuilding(pid, name string, floor *string) (b
defer cancel()
timeNow := types.Now()
serial.StringSerialRequestChan <- 1
code := serial.Prefix("B", <-serial.StringSerialResponseChan)
createSql, createArgs, _ := pr.ds.
Insert("park_building").
Cols(
"id", "park_id", "name", "floors", "enabled", "created_at", "last_modified_at",
).
Vals(goqu.Vals{
serial.GeneratePrefixedUniqueSerialString("B"),
code,
pid, name, floor, true, timeNow, timeNow,
}).
Prepared(true).ToSQL()