作者 yangfu

fix: 1.增加队列级别 2.二级品保留一位精度

... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
... ... @@ -43,7 +44,7 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro
d.ProductRecordId = m.ProductRecordId
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
d.WeighBefore = m.ProductRecordInfo.WeighBefore
d.WeighBefore = utils.Round(m.ProductRecordInfo.WeighBefore, 1)
d.WeighAfter = m.ProductRecordInfo.WeighAfter
d.ApproveStatus = m.ProductRecordInfo.ApproveStatus
d.WorkOn = m.ProductRecordInfo.WorkOn
... ...
... ... @@ -75,7 +75,7 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second
} else if info.OutputWeight == info.InputWeight {
info.QualificationRate = 100
} else {
info.QualificationRate = utils.Round(info.OutputWeight*100.0/info.InputWeight, 0)
info.QualificationRate = utils.Truncate(info.OutputWeight*100.0/info.InputWeight, 2)
}
}
... ...
... ... @@ -24,12 +24,12 @@ func SendDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error {
}
func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error {
return SendAsyncJob(domain.TaskDeviceCollection(), productRecord)
return SendAsyncJob(domain.TaskDeviceCollection(), productRecord, asynq.Queue("device"))
}
func SendAsyncJob(queueName string, job interface{}) error {
func SendAsyncJob(queueName string, job interface{}, opts ...asynq.Option) error {
task := asynq.NewTask(queueName, []byte(json.MarshalToString(job)))
client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
_, err := client.Enqueue(task)
_, err := client.Enqueue(task, opts...)
return err
}
... ...
... ... @@ -60,7 +60,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
workstation *domain.WorkStation
uc *domain.UnitConversion
err error
weight float64 = request.Weigh
weight float64 = utils.Round(request.Weigh, 1)
)
if plan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": request.ProductPlanId}); err != nil {
return nil, err
... ...
... ... @@ -408,9 +408,17 @@ func NewSnowflakeId() (int64, error) {
return id.Int64(), nil
}
// Round 保留数值的精度位 四舍五入
func Round(value float64, places int32) float64 {
quantity := decimal.NewFromFloat(value)
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
// Truncate 截取数值固定长度的 eg:Truncate(99.99,1) Result: 99.9
func Truncate(value float64, places int32) float64 {
quantity := decimal.NewFromFloat(value).Truncate(places)
rsp, _ := quantity.Float64()
return rsp
}
... ...
... ... @@ -3,6 +3,7 @@ package utils
import (
"fmt"
"github.com/stretchr/testify/assert"
"math"
"testing"
"time"
)
... ... @@ -102,3 +103,14 @@ func parseWithLocation(name string, timeStr string) (time.Time, error) {
return lt, nil
}
}
func TestRound(t *testing.T) {
t.Logf("%v", Round(99.999, 1))
t.Logf("%v", Round(99.999, 2))
t.Logf("%.1f", math.Floor(99.99))
t.Logf("%v", math.Ceil(99.99))
t.Logf("%.1f", Truncate(99.99, 1))
t.Logf("%v", Truncate(99, 0))
}
... ...
... ... @@ -19,7 +19,14 @@ func Run() {
}()
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS},
asynq.Config{Concurrency: 1},
asynq.Config{
Concurrency: 2,
Queues: map[string]int{
//"critical": 1,
"default": 1,
"device": 1,
},
},
)
h := asynq.NewServeMux()
... ...