正在显示
7 个修改的文件
包含
35 行增加
和
7 行删除
@@ -2,6 +2,7 @@ package dto | @@ -2,6 +2,7 @@ package dto | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
5 | "time" | 6 | "time" |
6 | ) | 7 | ) |
7 | 8 | ||
@@ -43,7 +44,7 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro | @@ -43,7 +44,7 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro | ||
43 | d.ProductRecordId = m.ProductRecordId | 44 | d.ProductRecordId = m.ProductRecordId |
44 | d.ProductWorker = m.ProductWorker | 45 | d.ProductWorker = m.ProductWorker |
45 | d.WorkStation = m.WorkStation | 46 | d.WorkStation = m.WorkStation |
46 | - d.WeighBefore = m.ProductRecordInfo.WeighBefore | 47 | + d.WeighBefore = utils.Round(m.ProductRecordInfo.WeighBefore, 1) |
47 | d.WeighAfter = m.ProductRecordInfo.WeighAfter | 48 | d.WeighAfter = m.ProductRecordInfo.WeighAfter |
48 | d.ApproveStatus = m.ProductRecordInfo.ApproveStatus | 49 | d.ApproveStatus = m.ProductRecordInfo.ApproveStatus |
49 | d.WorkOn = m.ProductRecordInfo.WorkOn | 50 | d.WorkOn = m.ProductRecordInfo.WorkOn |
@@ -75,7 +75,7 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | @@ -75,7 +75,7 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second | ||
75 | } else if info.OutputWeight == info.InputWeight { | 75 | } else if info.OutputWeight == info.InputWeight { |
76 | info.QualificationRate = 100 | 76 | info.QualificationRate = 100 |
77 | } else { | 77 | } else { |
78 | - info.QualificationRate = utils.Round(info.OutputWeight*100.0/info.InputWeight, 0) | 78 | + info.QualificationRate = utils.Truncate(info.OutputWeight*100.0/info.InputWeight, 2) |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 |
@@ -24,12 +24,12 @@ func SendDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error { | @@ -24,12 +24,12 @@ func SendDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error { | ||
24 | } | 24 | } |
25 | 25 | ||
26 | func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error { | 26 | func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error { |
27 | - return SendAsyncJob(domain.TaskDeviceCollection(), productRecord) | 27 | + return SendAsyncJob(domain.TaskDeviceCollection(), productRecord, asynq.Queue("device")) |
28 | } | 28 | } |
29 | 29 | ||
30 | -func SendAsyncJob(queueName string, job interface{}) error { | 30 | +func SendAsyncJob(queueName string, job interface{}, opts ...asynq.Option) error { |
31 | task := asynq.NewTask(queueName, []byte(json.MarshalToString(job))) | 31 | task := asynq.NewTask(queueName, []byte(json.MarshalToString(job))) |
32 | client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}) | 32 | client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}) |
33 | - _, err := client.Enqueue(task) | 33 | + _, err := client.Enqueue(task, opts...) |
34 | return err | 34 | return err |
35 | } | 35 | } |
@@ -60,7 +60,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | @@ -60,7 +60,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu | ||
60 | workstation *domain.WorkStation | 60 | workstation *domain.WorkStation |
61 | uc *domain.UnitConversion | 61 | uc *domain.UnitConversion |
62 | err error | 62 | err error |
63 | - weight float64 = request.Weigh | 63 | + weight float64 = utils.Round(request.Weigh, 1) |
64 | ) | 64 | ) |
65 | if plan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": request.ProductPlanId}); err != nil { | 65 | if plan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": request.ProductPlanId}); err != nil { |
66 | return nil, err | 66 | return nil, err |
@@ -408,9 +408,17 @@ func NewSnowflakeId() (int64, error) { | @@ -408,9 +408,17 @@ func NewSnowflakeId() (int64, error) { | ||
408 | return id.Int64(), nil | 408 | return id.Int64(), nil |
409 | } | 409 | } |
410 | 410 | ||
411 | +// Round 保留数值的精度位 四舍五入 | ||
411 | func Round(value float64, places int32) float64 { | 412 | func Round(value float64, places int32) float64 { |
412 | quantity := decimal.NewFromFloat(value) | 413 | quantity := decimal.NewFromFloat(value) |
413 | d := quantity.Round(places) | 414 | d := quantity.Round(places) |
414 | rsp, _ := d.Float64() | 415 | rsp, _ := d.Float64() |
415 | return rsp | 416 | return rsp |
416 | } | 417 | } |
418 | + | ||
419 | +// Truncate 截取数值固定长度的 eg:Truncate(99.99,1) Result: 99.9 | ||
420 | +func Truncate(value float64, places int32) float64 { | ||
421 | + quantity := decimal.NewFromFloat(value).Truncate(places) | ||
422 | + rsp, _ := quantity.Float64() | ||
423 | + return rsp | ||
424 | +} |
@@ -3,6 +3,7 @@ package utils | @@ -3,6 +3,7 @@ package utils | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/stretchr/testify/assert" | 5 | "github.com/stretchr/testify/assert" |
6 | + "math" | ||
6 | "testing" | 7 | "testing" |
7 | "time" | 8 | "time" |
8 | ) | 9 | ) |
@@ -102,3 +103,14 @@ func parseWithLocation(name string, timeStr string) (time.Time, error) { | @@ -102,3 +103,14 @@ func parseWithLocation(name string, timeStr string) (time.Time, error) { | ||
102 | return lt, nil | 103 | return lt, nil |
103 | } | 104 | } |
104 | } | 105 | } |
106 | + | ||
107 | +func TestRound(t *testing.T) { | ||
108 | + t.Logf("%v", Round(99.999, 1)) | ||
109 | + t.Logf("%v", Round(99.999, 2)) | ||
110 | + | ||
111 | + t.Logf("%.1f", math.Floor(99.99)) | ||
112 | + t.Logf("%v", math.Ceil(99.99)) | ||
113 | + | ||
114 | + t.Logf("%.1f", Truncate(99.99, 1)) | ||
115 | + t.Logf("%v", Truncate(99, 0)) | ||
116 | +} |
@@ -19,7 +19,14 @@ func Run() { | @@ -19,7 +19,14 @@ func Run() { | ||
19 | }() | 19 | }() |
20 | srv := asynq.NewServer( | 20 | srv := asynq.NewServer( |
21 | asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}, | 21 | asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}, |
22 | - asynq.Config{Concurrency: 1}, | 22 | + asynq.Config{ |
23 | + Concurrency: 2, | ||
24 | + Queues: map[string]int{ | ||
25 | + //"critical": 1, | ||
26 | + "default": 1, | ||
27 | + "device": 1, | ||
28 | + }, | ||
29 | + }, | ||
23 | ) | 30 | ) |
24 | 31 | ||
25 | h := asynq.NewServeMux() | 32 | h := asynq.NewServeMux() |
-
请 注册 或 登录 后发表评论