作者 yangfu

feat: 考勤打卡记录上报

... ... @@ -2,8 +2,11 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
)
func (attendanceService *AttendanceService) WorkerAttendanceReport(cmd *command.WorkerAttendanceReportCommand) (interface{}, error) {
... ... @@ -26,7 +29,10 @@ func (attendanceService *AttendanceService) WorkerAttendanceReport(cmd *command.
// log.Logger.Error(err.Error())
// return nil, err
//}
attendanceReportService, _ := domainService.NewPGWorkerAttendanceReportService(transactionContext.(*pgTransaction.TransactionContext))
if _, err := attendanceReportService.Report(constant.MANUFACTURE_WEIGH_DEFAULT_COMPANYID, constant.MANUFACTURE_WEIGH_DEFAULT_COMPANYID, cmd.DeviceZkTeco); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -28,17 +28,14 @@ type CreateProductPlanCommand struct {
//PlanProductName string `cname:"计划的产品名称" json:"planProductName"`
// 产品ID
ProductId int `cname:"产品ID" json:"productId" valid:"Required"`
// 投入量规格 默认份
DevotedUnit string `cname:"投入量规格" json:"devotedUnit" `
// 数量(保留两位小数)
Quantity float64 `cname:"数量(保留两位小数)" json:"quantity" valid:"Required"`
// 单位
//Unit string `cname:"单位" json:"unit" `
// 单份重量(原材料)
//nitWeight float64 `cname:"单份重量(原材料)" json:"unitWeight" valid:"Required"`
// 重量
Weight float64 `cname:"重量" json:"weight" valid:"Required"`
// 备注
Remark string `cname:"备注" json:"remark"`
// 生产日期
ProductDateTime time.Time `cname:"生产日期" json:"-" `
}
... ... @@ -49,8 +46,8 @@ func (createProductPlanCommand *CreateProductPlanCommand) Valid(validation *vali
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", createProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
if t, err := time.Parse("2006-01-02", createProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误" + createProductPlanCommand.ProductDate)
return
} else {
createProductPlanCommand.ProductDateTime = t
... ...
... ... @@ -49,8 +49,8 @@ func (updateProductPlanCommand *UpdateProductPlanCommand) Valid(validation *vali
validation.Error(err.Error())
return
}
if t, err := time.Parse("2006/01/02", updateProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误 2006/01/02")
if t, err := time.Parse("2006-01-02", updateProductPlanCommand.ProductDate); err != nil {
validation.Error("时间格式有误")
return
} else {
updateProductPlanCommand.ProductDateTime = t
... ...
... ... @@ -23,9 +23,11 @@ type ProductPlanDto struct {
// 上班班次描述
WorkOnDescription string `json:"workOnDescription"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine,omitempty"`
Machine string `json:"machine"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 投入量规格 默认份
DevotedUnit string `json:"devotedUnit" `
// 计划投入
*domain.UnitQuantity
// 计划状态 (1:上线 2:下线 默认下线)
... ... @@ -45,12 +47,17 @@ type ProductPlanDto struct {
func (d *ProductPlanDto) LoadDto(m *domain.ProductPlan, orgId int) *ProductPlanDto {
d.ProductPlanId = m.ProductPlanId
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.ProductDate = m.ProductDate.Format("2006-01-02")
d.WorkshopId = m.Workshop.WorkshopId
d.WorkshopName = m.Workshop.WorkshopName
d.WorkOn = m.WorkOn
d.Machine = m.Machine
d.PlanProductName = m.PlanProductName
d.UnitQuantity = m.PlanDevoted
d.DevotedUnit = "份"
if m.Ext.ProductPlanExt != nil {
d.DevotedUnit = m.Ext.ProductPlanExt.DevotedUnit
}
d.PlanStatus = m.PlanStatus
d.TotalProduct = 0
d.Remark = m.Remark
... ...
... ... @@ -86,6 +86,7 @@ func (productPlanService *ProductPlanService) CreateProductPlan(cmd *command.Cre
ProductCode: product.ProductCode,
ProductName: product.ProductName,
//ProductSpec: product.ProductSpec,
DevotedUnit: cmd.DevotedUnit,
}),
}
if cmd.Weight > 0 {
... ...
package domain
import "time"
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
type DeviceZkTeco struct {
Sn string `json:"sn"` // 设备号
UserNo string `json:"userNo"` // 用户编码
ActionTime time.Time `json:"actionTime"` // 操作时间
}
func (m *DeviceZkTeco) Valid() error {
if len(m.Sn) == 0 {
return fmt.Errorf("设备号不能为空")
}
if len(m.UserNo) == 0 {
return fmt.Errorf("用户编码不能为空")
}
if m.ActionTime.IsZero() {
return fmt.Errorf("操作时间不能为空")
}
return nil
}
func (m *DeviceZkTeco) String() string {
return fmt.Sprintf("设备号:%v 用户编码:%v 操作时间:%v", m.Sn, m.UserNo, m.ActionTime)
}
func TaskDeviceZkTecoReport() string {
return fmt.Sprintf("%v:task:device-zk-teco:report", constant.CACHE_PREFIX)
}
... ...
... ... @@ -10,4 +10,6 @@ type ProductPlanExt struct {
ProductName string `json:"productName,omitempty"`
// 产品规格
//ProductSpec *UnitQuantity `json:"productSpec,omitempty"`
// 投入量规格 默认份
DevotedUnit string `json:"devotedUnit" `
}
... ...
... ... @@ -20,4 +20,8 @@ type User struct {
Avatar string `json:"avatar,omitempty"`
// 手机号码
Phone string `json:"phone,omitempty"`
// 额外扩展的参数
GroupId int `json:"-"`
GroupName string `json:"-"`
}
... ...
... ... @@ -29,6 +29,16 @@ func NewHttpLibAlliedCreationUser(host string) *HttpLibAlliedCreationUser {
func (gateway HttpLibAlliedCreationUser) User(userId int) (*models.User, error) {
return gateway.UserGet(ReqGetUser{UserId: userId})
}
func (gateway HttpLibAlliedCreationUser) UserByCode(companyId, orgId int, userCode string) (*models.User, error) {
_, users, err := gateway.UserSearch(ReqUserSearch{CompanyId: int64(companyId), OrganizationId: int64(orgId), UserCode: userCode, Limit: 1, PullRealTime: true})
if err != nil {
return nil, err
}
if len(users) == 0 {
return nil, fmt.Errorf("用户不存在")
}
return users[0], nil
}
func (gateway HttpLibAlliedCreationUser) Users(userIds []int) ([]*models.User, error) {
var list = make([]*models.User, 0)
for i := range userIds {
... ...
... ... @@ -40,6 +40,8 @@ type (
InEnableStatus []int `cname:"状态(1:启用 2:禁用 3:注销)" json:"inEnableStatus,omitempty"`
// 匹配多个公司
InCompanyIds []interface{} `json:"inCompanyIds,omitempty"`
// 用户编号 企业内标识
UserCode string `cname:"用户编号" json:"userCode,omitempty"`
// 自定义高级查询
AdvancedQuery string `json:"advancedQuery"`
... ...
... ... @@ -91,8 +91,8 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker
query.Where("company_id =?", companyId)
query.Where("org_id =?", orgId)
query.Where("product_worker ->>'userId' = '?'", workerId)
query.Where("sign_in <= ?", endTime)
query.Where("sign_in >= ?", beginTime)
query.Where("sign_in <= ?", endTime)
query.Where("attendance_status = ?", domain.AttendanceNotApprove)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
... ...
package dao
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
)
type DeviceDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewDeviceDao(transactionContext *pgTransaction.TransactionContext) (*DeviceDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DeviceDao{
transactionContext: transactionContext,
}, nil
}
}
func (d *DeviceDao) FindDeviceByDeviceCode(companyId, orgId int, deviceCode string) (*domain.Device, error) {
tx := d.transactionContext.PgTx
deviceModel := new(models.Device)
query := sqlbuilder.BuildQuery(tx.Model(deviceModel), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("device_code = ?", deviceCode)
//if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) {
// query.AllWithDeleted()
//}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if deviceModel.DeviceId == 0 {
return nil, nil
} else {
return transform.TransformToDeviceDomainModelFromPgModels(deviceModel)
}
return nil, nil
}
... ...
... ... @@ -19,6 +19,14 @@ func (svr *UserService) User(id int) (*domain.User, error) {
return svr.ToUser(rsp), nil
}
func (svr *UserService) UserByCode(companyId, orgId int, userCode string) (*domain.User, error) {
rsp, err := svr.internalUserService.UserByCode(companyId, orgId, userCode)
if err != nil {
return nil, err
}
return svr.ToUser(rsp), nil
}
func (svr *UserService) Users(id []int) ([]*domain.User, error) {
rsp, err := svr.internalUserService.Users(id)
if err != nil {
... ...
... ... @@ -189,6 +189,8 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp
//g:=groups[i]
for j := range groups[i].GroupMembers {
u := groups[i].GroupMembers[j]
u.GroupId = groups[i].ProductGroupId
u.GroupName = groups[i].GroupName
result[keyFunc(u.UserId)] = u
}
}
... ...
... ... @@ -2,9 +2,11 @@ package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
... ... @@ -17,42 +19,85 @@ type PGWorkerAttendanceReportService struct {
// 考勤汇报
func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.DeviceZkTeco) (interface{}, error) {
var (
attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext)
isSignIn = true
record *domain.ProductAttendanceRecord
workStationId string //具体工位
workStation *domain.WorkStation
attendanceType int
worker *domain.User
org *domain.Org
attendanceRecordDao, _ = dao.NewAttendanceRecordDao(ptr.transactionContext)
attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext)
isSignIn = true
record *domain.ProductAttendanceRecord
workStationId string //具体工位
workStation *domain.WorkStation
attendanceType int = domain.ParticipateNormal
worker *domain.User
org *domain.Org
)
beginTime := utils.GetZeroTime(time.Now())
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, time.Now())
if err := report.Valid(); err != nil {
return nil, err
}
var (
device *domain.Device
err error
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
groupId = 0
groupName = ""
)
deviceRepository, _ := dao.NewDeviceDao(ptr.transactionContext)
if device, err = deviceRepository.FindDeviceByDeviceCode(cid, oid, report.Sn); err != nil {
return nil, err
}
workStation = device.WorkStation
var userService = NewUserService()
org, err = userService.Organization(oid)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
worker, err = userService.UserByCode(cid, oid, report.UserNo)
if err != nil {
return nil, err
}
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, workStation.WorkStationId)
if v, ok := groupMembers[groupMembersKeyFunc(worker.UserId)]; !ok {
attendanceType = domain.ParticipateSupport
} else {
groupId = v.GroupId
groupName = v.GroupName
}
beginTime := utils.GetZeroTime(report.ActionTime)
endTime := report.ActionTime
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, endTime)
for i := 0; i < len(records); i++ {
r := records[i]
// 操作时间 < 签到时间 签退时间 < 操作时间
if (!r.SignIn.IsZero() && r.SignIn.After(report.ActionTime)) || (!r.SignOut.IsZero() && r.SignOut.Before(report.ActionTime)) {
continue
// 操作时间 < 签到时间
if utils.TimeAfterEqual(r.SignIn, report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
if !r.SignIn.IsZero() && !r.SignOut.IsZero() {
if r.SignIn.Before(report.ActionTime) && r.SignOut.After(report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
// 存在完整打卡记录
// 1. 如果在区间内,退出
if !utils.TimeIsZero(r.SignIn) && !utils.TimeIsZero(r.SignOut) {
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) && utils.TimeAfterEqual(r.SignOut, report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
continue
}
if !r.SignIn.IsZero() && r.SignOut.IsZero() && r.SignIn.Before(report.ActionTime) {
isSignIn = false
record = r
break
// 存在未结束的打卡记录
// 1.满足条件-签退
if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) {
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) {
isSignIn = false
record = r
break
}
}
}
if isSignIn {
if isSignIn || record == nil {
record = &domain.ProductAttendanceRecord{
//ProductAttendanceId: cmd.ProductAttendanceId,
CompanyId: cid,
OrgId: oid,
AttendanceType: attendanceType,
... ... @@ -65,13 +110,20 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
WorkTimeAfter: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
//GroupName: productGroup.GroupName,
//ProductGroupId: productGroup.ProductGroupId,
Ext: domain.NewExt(org.OrgName).WithAttendanceExt(&domain.ProductAttendanceRecordExt{
GroupName: groupName,
ProductGroupId: groupId,
}),
}
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report))
} else {
record.SignOut = report.ActionTime
record.WorkTimeBefore = record.ComputeWorkTimeBefore()
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report))
}
if _, err = attendanceRecordRepository.Save(record); err != nil {
return nil, err
}
return struct{}{}, nil
... ...
package domainService
//import (
// "fmt"
// pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
// "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
// "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
//)
//
//type PGWorkshopService struct {
// transactionContext *pgTransaction.TransactionContext
//}
//
//func(ptr *PGWorkshopService)CompanyWorkshops(companyId int)(domain.Workshops,error){
// workshopRepository,_:= repository.NewWorkshopRepository(ptr.transactionContext)
// _,workshops,err:= workshopRepository.Find(map[string]interface{}{"companyId":companyId})
// if err!=nil{
// return nil,err
// }
// if len(workshops)==0{
// workshops = make([]*domain.Workshop,0)
// }
// return workshops,nil
//}
//
//func NewPGWorkshopService(transactionContext *pgTransaction.TransactionContext) (*PGWorkshopService, error) {
// if transactionContext == nil {
// return nil, fmt.Errorf("transactionContext参数不能为nil")
// } else {
// return &PGWorkshopService{
// transactionContext: transactionContext,
// }, nil
// }
//}
... ... @@ -59,7 +59,15 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord
}
func SendWorkshopWorkTimeStaticJob(productRecord *domain.ProductAttendanceRecord) error {
task := asynq.NewTask(domain.TaskKeyWorkshopWorkTimeRecordStatics(), []byte(json.MarshalToString(productRecord)))
return SendAsyncJob(domain.TaskKeyWorkshopWorkTimeRecordStatics(), productRecord)
}
func SenDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error {
return SendAsyncJob(domain.TaskDeviceZkTecoReport(), productRecord)
}
func SendAsyncJob(queueName string, job interface{}) error {
task := asynq.NewTask(queueName, []byte(json.MarshalToString(job)))
client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
_, err := client.Enqueue(task)
... ...
... ... @@ -50,3 +50,33 @@ func TransformTimestampToTime(timeStamp int64) time.Time {
//(myTime)
return time.Date(myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second(), 0, time.Local)
}
func TimeIsZero(d time.Time) bool {
if d.IsZero() {
return true
}
if d.Equal(time.Date(1, 1, 1, 0, 0, 0, 0, time.Local)) {
return true
}
return false
}
func TimeAfterEqual(t1, t2 time.Time) bool {
if t1.After(t2) {
return true
}
if t1.Equal(t2) {
return true
}
return false
}
func TimeBeforeEqual(t1, t2 time.Time) bool {
if t1.Before(t2) {
return true
}
if t1.Equal(t2) {
return true
}
return false
}
... ...
package controllers
import (
"encoding/json"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"strings"
"time"
)
... ... @@ -28,8 +26,9 @@ func (controller *DeviceZKTecoController) PostCdata() {
mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
if err == nil {
data.ActionTime = mTime
mBytes, _ := json.Marshal(data)
redis.GetRedis().LPush(constant.REDIS_ZKTECO_KEY, mBytes)
//mBytes, _ := json.Marshal(data)
//redis.GetRedis().LPush(domain.TaskDeviceZkTecoReport(), mBytes)
domainService.SenDeviceZkTecoReportJob(data)
}
}
controller.Response(data, nil)
... ...
package task
import (
"context"
"encoding/json"
"fmt"
"github.com/hibiken/asynq"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
... ... @@ -25,6 +20,7 @@ func Run() {
// ... Register handlers
h.HandleFunc(domain.TaskKeyPatternProductRecordStatics(), HandlerProductRecordStatics)
h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics)
h.HandleFunc(domain.TaskDeviceZkTecoReport(), WorkerAttendanceReport)
log.Logger.Info("aysnq task running ...")
// Run blocks and waits for os signal to terminate the program.
if err := srv.Run(h); err != nil {
... ... @@ -36,19 +32,3 @@ func Run() {
log.Logger.Info("aysnq task stopping ...")
srv.Shutdown()
}
// 生产记录统计
func HandlerProductRecordStatics(c context.Context, t *asynq.Task) error {
productPlanService := service.NewProductRecordService(nil)
cmd := &command.ProductRecordStaticsCommand{}
if err := json.Unmarshal(t.Payload(), cmd); err != nil {
return err
}
log.Logger.Debug(fmt.Sprintf("【生产记录统计】 消费 生产记录ID:%v 类型:%v 工段:%v(%v) 重量:%v", cmd.ProductRecordId, cmd.ProductRecordType,
cmd.WorkStation.SectionName, cmd.WorkStation.WorkStationId, cmd.ProductRecordInfo.Weigh))
_, err := productPlanService.ProductRecordStatics(cmd)
if err != nil {
log.Logger.Error(err.Error())
}
return err
}
... ...
package task
import (
"context"
"encoding/json"
"fmt"
"github.com/hibiken/asynq"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 生产记录统计
func HandlerProductRecordStatics(c context.Context, t *asynq.Task) error {
productPlanService := service.NewProductRecordService(nil)
cmd := &command.ProductRecordStaticsCommand{}
if err := json.Unmarshal(t.Payload(), cmd); err != nil {
return err
}
log.Logger.Debug(fmt.Sprintf("【生产记录统计】 消费 生产记录ID:%v 类型:%v 工段:%v(%v) 重量:%v", cmd.ProductRecordId, cmd.ProductRecordType,
cmd.WorkStation.SectionName, cmd.WorkStation.WorkStationId, cmd.ProductRecordInfo.Weigh))
_, err := productPlanService.ProductRecordStatics(cmd)
if err != nil {
log.Logger.Error(err.Error())
}
return err
}
... ...