作者 yangfu

feat: 工时审核

正在显示 44 个修改的文件 包含 1533 行增加77 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/beego/beego/v2/core/validation"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  7 + "reflect"
  8 + "strings"
  9 +)
  10 +
  11 +type WorkshopWorkTimeRecordStaticsCommand struct {
  12 + *domain.ProductAttendanceRecord
  13 +}
  14 +
  15 +// Type is a string value that indicates the type of the task.
  16 +//func (t *ProductRecordStaticsCommand) Type() string
  17 +
  18 +// Payload is the data needed for task execution.
  19 +//func (t *ProductRecordStaticsCommand) Payload() []byte
  20 +
  21 +func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) Valid(validation *validation.Validation) {
  22 + //validation.SetError("CustomValid", "未实现的自定义认证")
  23 +}
  24 +
  25 +func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) ValidateCommand() error {
  26 + valid := validation.Validation{}
  27 + b, err := valid.Valid(removeProductRecordCommand)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if !b {
  32 + elem := reflect.TypeOf(removeProductRecordCommand).Elem()
  33 + for _, validErr := range valid.Errors {
  34 + field, isExist := elem.FieldByName(validErr.Field)
  35 + if isExist {
  36 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  37 + } else {
  38 + return fmt.Errorf(validErr.Message)
  39 + }
  40 + }
  41 + }
  42 + return nil
  43 +}
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +type EmployeeAttendanceRecordDto struct {
  8 + // 考勤记录ID
  9 + ProductAttendanceId int `json:"productAttendanceId"`
  10 + // 签到日期
  11 + SignDate string `json:"signDate"`
  12 + // 工作位置
  13 + *domain.WorkStation
  14 + // 生产工人
  15 + ProductWorker *domain.User `json:"productWorker,omitempty"`
  16 + // 考勤类型 1.正常 2.支援
  17 + AttendanceType int `json:"attendanceType,omitempty"`
  18 + //*domain.ProductAttendanceRecordExt
  19 + // 考勤状态 1.未审核 2:已审核 4.自动审核
  20 + AttendanceStatus int `json:"attendanceStatus"`
  21 + // 工时
  22 + WorkTime float64 `json:"workTime"`
  23 + // 组织名称
  24 + OrgName string `json:"orgName"`
  25 + // 权限标识 (当前登录组织匹配为true,否则false)
  26 + AuthFlag bool `json:"authFlag"`
  27 +}
  28 +
  29 +func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *EmployeeAttendanceRecordDto {
  30 + d.ProductAttendanceId = m.ProductAttendanceId
  31 + d.AttendanceType = m.AttendanceType
  32 + d.ProductWorker = m.ProductWorker
  33 + d.WorkStation = m.WorkStation
  34 + if !m.SignIn.IsZero() {
  35 + //d.SignIn = m.SignIn.Format("15:04:05")
  36 + d.SignDate = m.SignIn.Format("2006-01-02")
  37 + }
  38 + d.WorkTime = m.WorkTimeAfter
  39 + //d.WorkTimeAfter = m.WorkTimeAfter
  40 + d.AttendanceStatus = m.AttendanceStatus
  41 + d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
  42 + if m.Ext != nil {
  43 + d.OrgName = m.Ext.OrgName
  44 + //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
  45 + }
  46 + return d
  47 +}
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +type WorkshopWorkTimeRecordDto struct {
  8 + // 车间工时记录ID
  9 + WorkshopWorkTimeRecordId int `json:"workshopWorkTimeRecordId"`
  10 + // 工作位置
  11 + *domain.WorkStation
  12 + // 签到日期
  13 + //SignDate string `json:"signDate"`
  14 + // 记录信息
  15 + *domain.WorkshopWorkTimeRecordInfo
  16 + // 记录日期
  17 + RecordDate string `json:"recordDate"`
  18 + // 组织名称
  19 + OrgName string `json:"orgName"`
  20 + // 权限标识 (当前登录组织匹配为true,否则false)
  21 + AuthFlag bool `json:"authFlag"`
  22 +}
  23 +
  24 +func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto {
  25 + d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId
  26 + d.WorkStation = m.WorkStation
  27 + d.WorkshopWorkTimeRecordInfo = m.WorkshopWorkTimeRecordInfo
  28 + d.WorkStation = m.WorkStation
  29 + d.RecordDate = m.RecordDate.Format("2006-01-02")
  30 + d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
  31 + if m.Ext != nil {
  32 + d.OrgName = m.Ext.OrgName
  33 + //d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
  34 + }
  35 + return d
  36 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
  7 + "reflect"
  8 + "strings"
  9 + "time"
  10 +
  11 + "github.com/beego/beego/v2/core/validation"
  12 +)
  13 +
  14 +type SearchEmployeeAttendanceQuery struct {
  15 + // 查询偏离量
  16 + Offset int `cname:"查询偏离量" json:"offset"`
  17 + // 查询限制
  18 + Limit int `cname:"查询限制" json:"limit"`
  19 + // 当前公司
  20 + CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
  21 + // 当前登录的组织
  22 + OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" `
  23 + // 匹配多个组织
  24 + InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" `
  25 + // 页码
  26 + PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
  27 + // 页数
  28 + PageSize int `cname:"页数" json:"pageSize,omitempty"`
  29 + // 车间名称
  30 + WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
  31 + // 生产线名称
  32 + LineName string `cname:"生产线名称" json:"lineName,omitempty"`
  33 + // 工段名称
  34 + SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
  35 + // 姓名
  36 + UserName string `cname:"姓名" json:"userName,omitempty"`
  37 + // 考勤状态 1.未审核 2:已审核 4.自动审核
  38 + AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 4.自动审核" json:"attendanceStatus,omitempty"`
  39 + // 开始时间
  40 + BeginTime string `cname:"开始时间" json:"beginTime"`
  41 + // 结束时间
  42 + EndTime string `cname:"结束时间" json:"endTime"`
  43 +
  44 + // 开始时间
  45 + SignBeginTime time.Time `cname:"开始时间" json:"signBeginTime"`
  46 + // 结束时间
  47 + SignEndTime time.Time `cname:"结束时间" json:"signEndTime"`
  48 +}
  49 +
  50 +func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validation) {
  51 + cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
  52 + var err error
  53 + if len(cmd.BeginTime) > 0 {
  54 + if cmd.SignBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
  55 + log.Logger.Error(err.Error())
  56 + validation.Error("开始时间有误")
  57 + return
  58 + }
  59 + }
  60 + if len(cmd.EndTime) > 0 {
  61 + if cmd.SignEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
  62 + log.Logger.Error(err.Error())
  63 + validation.Error("结束时间有误")
  64 + return
  65 + }
  66 + }
  67 + cmd.AttendanceStatus = 6 // 审核 + 自动审核
  68 +}
  69 +
  70 +func (cmd *SearchEmployeeAttendanceQuery) ValidateQuery() error {
  71 + valid := validation.Validation{}
  72 + b, err := valid.Valid(cmd)
  73 + if err != nil {
  74 + return err
  75 + }
  76 + if !b {
  77 + elem := reflect.TypeOf(cmd).Elem()
  78 + for _, validErr := range valid.Errors {
  79 + field, isExist := elem.FieldByName(validErr.Field)
  80 + if isExist {
  81 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  82 + } else {
  83 + return fmt.Errorf(validErr.Message)
  84 + }
  85 + }
  86 + }
  87 + return nil
  88 +}
@@ -51,7 +51,9 @@ func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.Appro @@ -51,7 +51,9 @@ func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.Appro
51 if _, err := productAttendanceRecordRepository.Save(attendance); err != nil { 51 if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
53 } 53 }
54 - 54 + if err := domainService.SendWorkshopWorkTimeStaticJob(attendance); err != nil {
  55 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  56 + }
55 if err := transactionContext.CommitTransaction(); err != nil { 57 if err := transactionContext.CommitTransaction(); err != nil {
56 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 58 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
57 } 59 }
@@ -310,6 +312,74 @@ func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain @@ -310,6 +312,74 @@ func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain
310 return count, result, nil 312 return count, result, nil
311 } 313 }
312 314
  315 +// 员工工时统计
  316 +func (attendanceService *AttendanceService) SearchEmployeeAttendanceStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
  317 + if err := cmd.ValidateQuery(); err != nil {
  318 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  319 + }
  320 + transactionContext, err := factory.CreateTransactionContext(nil)
  321 + if err != nil {
  322 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  323 + }
  324 + if err := transactionContext.StartTransaction(); err != nil {
  325 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  326 + }
  327 + defer func() {
  328 + transactionContext.RollbackTransaction()
  329 + }()
  330 + var attendanceRepository domain.ProductAttendanceRecordRepository
  331 + attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
  332 +
  333 + queryOptions := utils.ObjectToMap(cmd)
  334 + count, attendances, err := attendanceRepository.Find(queryOptions)
  335 + if err != nil {
  336 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  337 + }
  338 + if err := transactionContext.CommitTransaction(); err != nil {
  339 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  340 + }
  341 + var result = make([]*dto.EmployeeAttendanceRecordDto, 0)
  342 + for i := range attendances {
  343 + newItem := &dto.EmployeeAttendanceRecordDto{}
  344 + result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
  345 + }
  346 + return count, result, nil
  347 +}
  348 +
  349 +// 车间工时统计
  350 +func (attendanceService *AttendanceService) SearchWorkshopWorkTimeStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
  351 + if err := cmd.ValidateQuery(); err != nil {
  352 + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
  353 + }
  354 + transactionContext, err := factory.CreateTransactionContext(nil)
  355 + if err != nil {
  356 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  357 + }
  358 + if err := transactionContext.StartTransaction(); err != nil {
  359 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  360 + }
  361 + defer func() {
  362 + transactionContext.RollbackTransaction()
  363 + }()
  364 + var attendanceRepository domain.WorkshopWorkTimeRecordRepository
  365 + attendanceRepository, _, _ = factory.FastPgWorkshopWorkTimeRecord(transactionContext, 0)
  366 +
  367 + queryOptions := utils.ObjectToMap(cmd)
  368 + count, attendances, err := attendanceRepository.Find(queryOptions)
  369 + if err != nil {
  370 + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  371 + }
  372 + if err := transactionContext.CommitTransaction(); err != nil {
  373 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  374 + }
  375 + var result = make([]*dto.WorkshopWorkTimeRecordDto, 0)
  376 + for i := range attendances {
  377 + newItem := &dto.WorkshopWorkTimeRecordDto{}
  378 + result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
  379 + }
  380 + return count, result, nil
  381 +}
  382 +
313 func NewAttendanceService(options map[string]interface{}) *AttendanceService { 383 func NewAttendanceService(options map[string]interface{}) *AttendanceService {
314 newAttendanceService := &AttendanceService{} 384 newAttendanceService := &AttendanceService{}
315 return newAttendanceService 385 return newAttendanceService
  1 +package service
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
  10 +)
  11 +
  12 +// 审核工时
  13 +func (attendanceService *AttendanceService) WorkshopWorkTimeRecordStatics(cmd *command.WorkshopWorkTimeRecordStaticsCommand) (interface{}, error) {
  14 + if err := cmd.ValidateCommand(); err != nil {
  15 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  16 + }
  17 + transactionContext, err := factory.CreateTransactionContext(nil)
  18 + if err != nil {
  19 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  20 + }
  21 + if err := transactionContext.StartTransaction(); err != nil {
  22 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  23 + }
  24 + defer func() {
  25 + transactionContext.RollbackTransaction()
  26 + }()
  27 +
  28 + svr, _ := domainService.NewPGWorkshopWorkTimeStaticService(transactionContext.(*pgTransaction.TransactionContext))
  29 + if _, err := svr.WorkshopWorkTimeStatic(cmd.ProductAttendanceRecord); err != nil {
  30 + log.Logger.Error(err.Error())
  31 + return nil, err
  32 + }
  33 +
  34 + if err := transactionContext.CommitTransaction(); err != nil {
  35 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  36 + }
  37 + return struct{}{}, nil
  38 +}
@@ -22,11 +22,11 @@ type CreateDeviceCommand struct { @@ -22,11 +22,11 @@ type CreateDeviceCommand struct {
22 // 设备类型 22 // 设备类型
23 DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"` 23 DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
24 // 车间ID 24 // 车间ID
25 - WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 25 + WorkshopId int `cname:"车间ID" json:"workshopId"`
26 // 生产线ID 26 // 生产线ID
27 - LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` 27 + LineId int `cname:"生产线ID" json:"lineId"`
28 // 工段ID 28 // 工段ID
29 - SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 29 + SectionId int `cname:"工段ID" json:"sectionId"`
30 // 品牌 30 // 品牌
31 Brand string `cname:"品牌" json:"brand"` 31 Brand string `cname:"品牌" json:"brand"`
32 // 设备状态 1:正常 2:封存 3:报废 32 // 设备状态 1:正常 2:封存 3:报废
@@ -20,11 +20,11 @@ type UpdateDeviceCommand struct { @@ -20,11 +20,11 @@ type UpdateDeviceCommand struct {
20 // 设备类型 20 // 设备类型
21 DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"` 21 DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
22 // 车间ID 22 // 车间ID
23 - WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 23 + WorkshopId int `cname:"车间ID" json:"workshopId"`
24 // 生产线ID 24 // 生产线ID
25 - LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` 25 + LineId int `cname:"生产线ID" json:"lineId" `
26 // 工段ID 26 // 工段ID
27 - SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 27 + SectionId int `cname:"工段ID" json:"sectionId"`
28 // 品牌 28 // 品牌
29 Brand string `cname:"品牌" json:"brand" valid:"Required"` 29 Brand string `cname:"品牌" json:"brand" valid:"Required"`
30 // 设备状态 1:正常 2:封存 3:报废 30 // 设备状态 1:正常 2:封存 3:报废
@@ -36,6 +36,7 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto { @@ -36,6 +36,7 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto {
36 d.DeviceId = m.DeviceId 36 d.DeviceId = m.DeviceId
37 d.DeviceCode = m.DeviceCode 37 d.DeviceCode = m.DeviceCode
38 d.DeviceName = m.DeviceName 38 d.DeviceName = m.DeviceName
  39 + d.DeviceModel = m.DeviceModel
39 d.DeviceType = m.DeviceType 40 d.DeviceType = m.DeviceType
40 d.Brand = m.Brand 41 d.Brand = m.Brand
41 d.DeviceStatus = m.DeviceStatus 42 d.DeviceStatus = m.DeviceStatus
@@ -38,9 +38,12 @@ func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo @@ -38,9 +38,12 @@ func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo
38 }() 38 }()
39 39
40 var workStation *domain.WorkStation 40 var workStation *domain.WorkStation
41 - _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)  
42 - if err != nil {  
43 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 41 + if cmd.WorkshopId != 0 {
  42 + _, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
  43 + if err != nil {
  44 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  45 + }
  46 + workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
44 } 47 }
45 48
46 var userService = domainService.NewUserService() 49 var userService = domainService.NewUserService()
@@ -272,9 +275,16 @@ func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceComman @@ -272,9 +275,16 @@ func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceComman
272 } 275 }
273 276
274 var workStation *domain.WorkStation 277 var workStation *domain.WorkStation
275 - _, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())  
276 - if err != nil {  
277 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 278 + //_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
  279 + //if err != nil {
  280 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  281 + //}
  282 + if cmd.WorkshopId != 0 {
  283 + _, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
  284 + if err != nil {
  285 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  286 + }
  287 + workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
278 } 288 }
279 device.WorkStation = workStation 289 device.WorkStation = workStation
280 290
@@ -335,6 +335,32 @@ func FastPgProductRecord(transactionContext application.TransactionContext, id i @@ -335,6 +335,32 @@ func FastPgProductRecord(transactionContext application.TransactionContext, id i
335 return rep, mod, err 335 return rep, mod, err
336 } 336 }
337 337
  338 +// FastPgWorkshopWorkTimeRecord 快速返回生产记录
  339 +//
  340 +// transactionContext 事务
  341 +// id 对象唯一标识
  342 +func FastPgWorkshopWorkTimeRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopWorkTimeRecordRepository, *domain.WorkshopWorkTimeRecord, error) {
  343 + var rep domain.WorkshopWorkTimeRecordRepository
  344 + var mod *domain.WorkshopWorkTimeRecord
  345 + var err error
  346 + if value, err := CreateWorkshopWorkTimeRecordRepository(map[string]interface{}{
  347 + "transactionContext": transactionContext,
  348 + }); err != nil {
  349 + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  350 + } else {
  351 + rep = value
  352 + }
  353 + if id > 0 {
  354 + if mod, err = rep.FindOne(map[string]interface{}{"workshopWorkTimeRecordId": id}); err != nil {
  355 + if err == domain.ErrorNotFound {
  356 + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该记录不存在")
  357 + }
  358 + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  359 + }
  360 + }
  361 + return rep, mod, err
  362 +}
  363 +
338 /***** 2.配置 *****/ 364 /***** 2.配置 *****/
339 365
340 type FastOptions struct { 366 type FastOptions struct {
@@ -93,3 +93,19 @@ func CreateEmployeeProductRecordRepository(options map[string]interface{}) (doma @@ -93,3 +93,19 @@ func CreateEmployeeProductRecordRepository(options map[string]interface{}) (doma
93 } 93 }
94 return repository.NewEmployeeProductRecordRepository(transactionContext) 94 return repository.NewEmployeeProductRecordRepository(transactionContext)
95 } 95 }
  96 +
  97 +func CreateWorkshopProductRecordRepository(options map[string]interface{}) (domain.WorkshopProductRecordRepository, error) {
  98 + var transactionContext *pg.TransactionContext
  99 + if value, ok := options["transactionContext"]; ok {
  100 + transactionContext = value.(*pg.TransactionContext)
  101 + }
  102 + return repository.NewWorkshopProductRecordRepository(transactionContext)
  103 +}
  104 +
  105 +func CreateWorkshopWorkTimeRecordRepository(options map[string]interface{}) (domain.WorkshopWorkTimeRecordRepository, error) {
  106 + var transactionContext *pg.TransactionContext
  107 + if value, ok := options["transactionContext"]; ok {
  108 + transactionContext = value.(*pg.TransactionContext)
  109 + }
  110 + return repository.NewWorkshopWorkTimeRecordRepository(transactionContext)
  111 +}
@@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/d @@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/d
4 4
5 type EmployeeProductRecordDto struct { 5 type EmployeeProductRecordDto struct {
6 // 员工产能记录ID 6 // 员工产能记录ID
7 - EmployeeProductRecordId int `json:"employeeProductRecordId"` 7 + EmployeeProductRecordId int `json:"productRecordId"`
8 // 生产工人 8 // 生产工人
9 ProductWorker *domain.User `json:"productWorker,omitempty"` 9 ProductWorker *domain.User `json:"productWorker,omitempty"`
10 *domain.WorkStation 10 *domain.WorkStation
@@ -40,7 +40,7 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI @@ -40,7 +40,7 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI
40 d.ProductWeigh = m.RealProductWeigh() 40 d.ProductWeigh = m.RealProductWeigh()
41 d.SecondLevelWeigh = m.SecondLevelWeigh 41 d.SecondLevelWeigh = m.SecondLevelWeigh
42 d.QualificationRate = m.QualificationRate() 42 d.QualificationRate = m.QualificationRate()
43 - d.CreatedAt = m.CreatedAt.Format("06-01-02") 43 + d.CreatedAt = m.CreatedAt.Format("2006-01-02")
44 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId) 44 d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
45 if m.Ext != nil { 45 if m.Ext != nil {
46 d.OrgName = m.Ext.OrgName 46 d.OrgName = m.Ext.OrgName
  1 +package dto
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  4 +
  5 +type WorkshopProductRecordDto struct {
  6 + // 员工产能记录ID
  7 + WorkshopProductRecordId int `json:"productRecordId"`
  8 + // 生产工人
  9 + //ProductWorker *domain.User `json:"productWorker,omitempty"`
  10 + *domain.WorkStation
  11 + // 生产日期
  12 + //ProductDate string `json:"productDate"`
  13 + // 计划的产品名称
  14 + PlanProductName string `json:"planProductName,omitempty"`
  15 + // 批号
  16 + BatchNumber string `json:"batchNumber,omitempty"`
  17 + // 参与类型 1:正常 2:支援
  18 + //ParticipateType int `json:"participateType"`
  19 + // 投入量
  20 + DevotedProductWeigh float64 `json:"devotedProductWeigh"`
  21 + // 产能
  22 + ProductWeigh float64 `json:"productWeigh"`
  23 + // 二级品产能
  24 + SecondLevelWeigh float64 `json:"secondLevelWeigh"`
  25 + // 创建时间
  26 + CreatedAt string `json:"createdAt,omitempty"`
  27 + // 组织名称
  28 + OrgName string `json:"orgName"`
  29 + // 权限标识 (当前登录组织匹配为true,否则false)
  30 + AuthFlag bool `json:"authFlag"`
  31 + // 合格率 百分比
  32 + QualificationRate int `json:"qualificationRate"`
  33 +}
  34 +
  35 +func (d *WorkshopProductRecordDto) LoadDto(m *domain.WorkshopProductRecord, orgId int) *WorkshopProductRecordDto {
  36 + d.WorkshopProductRecordId = m.WorkshopProductRecordId
  37 + //d.ProductWorker = m.ProductWorker
  38 + d.WorkStation = m.WorkStation
  39 + d.PlanProductName = m.ProductRecordInfo.PlanProductName
  40 + d.BatchNumber = m.ProductRecordInfo.BatchNumber
  41 + //d.ParticipateType = m.ParticipateType
  42 + d.DevotedProductWeigh = m.DevotedProductWeigh()
  43 + d.ProductWeigh = m.RealProductWeigh()
  44 + d.SecondLevelWeigh = m.SecondLevelWeigh
  45 + d.QualificationRate = m.QualificationRate()
  46 + d.CreatedAt = m.ProductDate
  47 + d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
  48 + if m.Ext != nil {
  49 + d.OrgName = m.Ext.OrgName
  50 + }
  51 + return d
  52 +}
@@ -304,6 +304,9 @@ func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *comm @@ -304,6 +304,9 @@ func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *comm
304 if _, err = svr.EmployeeProductStatics(productRecord); err != nil { 304 if _, err = svr.EmployeeProductStatics(productRecord); err != nil {
305 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 305 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
306 } 306 }
  307 + if _, err = svr.WorkshopProductStatics(productRecord); err != nil {
  308 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  309 + }
307 if err := transactionContext.CommitTransaction(); err != nil { 310 if err := transactionContext.CommitTransaction(); err != nil {
308 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 311 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
309 } 312 }
@@ -29,19 +29,19 @@ func (productRecordService *ProductRecordService) SearchWorkshopProductRecord(op @@ -29,19 +29,19 @@ func (productRecordService *ProductRecordService) SearchWorkshopProductRecord(op
29 //var productRecordRepository domain.ProductRecordRepository 29 //var productRecordRepository domain.ProductRecordRepository
30 //productRecordRepository,_,_ = factory.FastPgProductRecord(transactionContext,0) 30 //productRecordRepository,_,_ = factory.FastPgProductRecord(transactionContext,0)
31 31
32 - productRecordRepository, _ := dao.NewEmployeeProductRecordDao(transactionContext.(*pgTransaction.TransactionContext)) 32 + productRecordRepository, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
33 options := utils.ObjectToMap(listProductRecordQuery) 33 options := utils.ObjectToMap(listProductRecordQuery)
34 - count, productRecords, err := productRecordRepository.SearchEmployeeProductRecord(options) 34 + count, productRecords, err := productRecordRepository.SearchWorkshopProductRecord(options)
35 if err != nil { 35 if err != nil {
36 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 36 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
37 } 37 }
38 if err := transactionContext.CommitTransaction(); err != nil { 38 if err := transactionContext.CommitTransaction(); err != nil {
39 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 39 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
40 } 40 }
41 - var result = make([]*dto.EmployeeProductRecordDto, 0) 41 + var result = make([]*dto.WorkshopProductRecordDto, 0)
42 for i := range productRecords { 42 for i := range productRecords {
43 item := productRecords[i] 43 item := productRecords[i]
44 - newItem := &dto.EmployeeProductRecordDto{} 44 + newItem := &dto.WorkshopProductRecordDto{}
45 newItem.LoadDto(item, operateInfo.OrgId) 45 newItem.LoadDto(item, operateInfo.OrgId)
46 result = append(result, newItem) 46 result = append(result, newItem)
47 } 47 }
@@ -103,9 +103,9 @@ func (device *Device) Update(data map[string]interface{}) error { @@ -103,9 +103,9 @@ func (device *Device) Update(data map[string]interface{}) error {
103 } 103 }
104 if device.Ext == nil { 104 if device.Ext == nil {
105 device.Ext = &Ext{} 105 device.Ext = &Ext{}
106 - if device.Ext.DeviceExt == nil {  
107 - device.Ext.DeviceExt = &DeviceExt{}  
108 - } 106 + }
  107 + if device.Ext != nil && device.Ext.DeviceExt == nil {
  108 + device.Ext.DeviceExt = &DeviceExt{}
109 } 109 }
110 if orgName, ok := data["orgName"]; ok { 110 if orgName, ok := data["orgName"]; ok {
111 device.Ext.OrgName = orgName.(string) 111 device.Ext.OrgName = orgName.(string)
  1 +package domain
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  6 + "time"
  7 +)
  8 +
  9 +// 车间工时记录
  10 +type WorkshopWorkTimeRecord struct {
  11 + // 车间工时记录ID
  12 + WorkshopWorkTimeRecordId int `json:"workshopWorkTimeRecordId"`
  13 + // 工作位置
  14 + WorkStation *WorkStation `json:"workStation"`
  15 + // 创建时间
  16 + CreatedAt time.Time `json:"createdAt"`
  17 + // 企业id
  18 + CompanyId int `json:"companyId"`
  19 + // 组织ID
  20 + OrgId int `json:"orgId"`
  21 + // 记录信息
  22 + WorkshopWorkTimeRecordInfo *WorkshopWorkTimeRecordInfo `json:"workshopWorkTimeRecordInfo"`
  23 + // 扩展数据
  24 + Ext *Ext `json:"ext"`
  25 + // 记录日期
  26 + RecordDate time.Time `json:"recordDate"`
  27 +}
  28 +
  29 +type WorkshopWorkTimeRecordInfo struct {
  30 + // 固定工时
  31 + EFTWorkTime float64 `json:"eft_work_time"`
  32 + // 临时工时
  33 + EDWorkTime float64 `json:"ed_work_time"`
  34 + // 派遣工时
  35 + EPTWorkTime float64 `json:"ept_work_time"`
  36 +}
  37 +
  38 +type WorkshopWorkTimeRecordRepository interface {
  39 + Save(workshopWorkTimeRecord *WorkshopWorkTimeRecord) (*WorkshopWorkTimeRecord, error)
  40 + Remove(workshopWorkTimeRecord *WorkshopWorkTimeRecord) (*WorkshopWorkTimeRecord, error)
  41 + FindOne(queryOptions map[string]interface{}) (*WorkshopWorkTimeRecord, error)
  42 + Find(queryOptions map[string]interface{}) (int64, []*WorkshopWorkTimeRecord, error)
  43 +}
  44 +
  45 +func (workshopWorkTimeRecord *WorkshopWorkTimeRecord) Identify() interface{} {
  46 + if workshopWorkTimeRecord.WorkshopWorkTimeRecordId == 0 {
  47 + return nil
  48 + }
  49 + return workshopWorkTimeRecord.WorkshopWorkTimeRecordId
  50 +}
  51 +
  52 +func (workshopWorkTimeRecord *WorkshopWorkTimeRecord) Update(data map[string]interface{}) error {
  53 + return nil
  54 +}
  55 +
  56 +func TaskKeyWorkshopWorkTimeRecordStatics() string {
  57 + return fmt.Sprintf("%v:task:workshop-work-time-record:statics", constant.CACHE_PREFIX)
  58 +}
@@ -7,6 +7,13 @@ const ( @@ -7,6 +7,13 @@ const (
7 ParticipateSupport = 2 7 ParticipateSupport = 2
8 ) 8 )
9 9
  10 +const (
  11 + ProductSection1 = "打料"
  12 + ProductSection2 = "成型"
  13 + ProductSection3 = "穿串"
  14 + ProductSection4 = "包装"
  15 +)
  16 +
10 // 员工生产记录 17 // 员工生产记录
11 type EmployeeProductRecord struct { 18 type EmployeeProductRecord struct {
12 // 企业id 19 // 企业id
@@ -35,47 +42,12 @@ type EmployeeProductRecord struct { @@ -35,47 +42,12 @@ type EmployeeProductRecord struct {
35 Ext *Ext `json:"ext"` 42 Ext *Ext `json:"ext"`
36 // 版本号 43 // 版本号
37 Version int `json:"version"` 44 Version int `json:"version"`
38 - // 生产记录信息  
39 - ProductRecordInfo *EmployeeProductRecordInfo `json:"productRecordInfo"` 45 + // 生产记录统计信息
  46 + ProductRecordInfo *ProductRecordStaticInfo `json:"productRecordInfo"`
40 // 生产工人 47 // 生产工人
41 ProductWorker *User `comment:"生产工人"` 48 ProductWorker *User `comment:"生产工人"`
42 } 49 }
43 50
44 -type EmployeeProductRecordInfo struct {  
45 - // 生产日期  
46 - ProductDate string `json:"productDate"`  
47 - // 原始上报数据  
48 - //OriginalWeigh float64 `json:"originalWeigh,omitempty"`  
49 - // 换算后的产能  
50 - //Weigh float64 `json:"weigh"`  
51 - // 产能 - 审核前  
52 - //WeighBefore float64 `json:"weighBefore"`  
53 - // 产能-审核后  
54 - //WeighAfter float64 `json:"weighAfter"`  
55 - // 审核状态 1:未审核 2:已审核  
56 - //ApproveStatus int64 `json:"approveStatus"`  
57 - // 审核时间  
58 - //ApproveAt int64 `json:"approveAt"`  
59 - // 审核人  
60 - //ApproveUser *User `json:"approveUser"`  
61 - // 物料信息  
62 - //Material *UnitConversion `json:"material,omitempty"`  
63 - // 生产计划信息(批次)  
64 - //ProductPlan *ProductPlan `json:"productPlan,omitempty"`  
65 - // 单位换算ID  
66 - //UnitConversionId int `json:"unitConversionId,omitempty"`  
67 -  
68 - // 生产计划ID  
69 - ProductPlanId int `json:"productPlanId,omitempty"`  
70 - // 计划的产品名称  
71 - PlanProductName string `json:"planProductName,omitempty"`  
72 - // 批号  
73 - BatchNumber string `json:"batchNumber,omitempty"`  
74 -  
75 - // 生产小组ID  
76 - ProductGroupId int `json:"productGroupId,omitempty"`  
77 -}  
78 -  
79 type EmployeeProductRecordRepository interface { 51 type EmployeeProductRecordRepository interface {
80 Save(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error) 52 Save(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
81 Remove(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error) 53 Remove(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
@@ -94,9 +66,21 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter @@ -94,9 +66,21 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter
94 return nil 66 return nil
95 } 67 }
96 68
97 -func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int) { 69 +// 更新生产量
  70 +func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) {
  71 + if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
  72 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
  73 + }
98 if productRecordType == RecordTypeSecondLevelWeigh { 74 if productRecordType == RecordTypeSecondLevelWeigh {
99 - employeeProductRecord.SecondLevelWeigh += weigh 75 + if employeeProductRecord.WorkStation.SectionName == sectionName {
  76 + employeeProductRecord.SecondLevelWeigh += weigh
  77 + } else {
  78 + if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok {
  79 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品
  80 + } else {
  81 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
  82 + }
  83 + }
100 } 84 }
101 if productRecordType == RecordTypeReceiveMaterial { 85 if productRecordType == RecordTypeReceiveMaterial {
102 employeeProductRecord.ProductWeigh += weigh 86 employeeProductRecord.ProductWeigh += weigh
@@ -108,14 +92,18 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo @@ -108,14 +92,18 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
108 employeeProductRecord.Version += 1 92 employeeProductRecord.Version += 1
109 } 93 }
110 94
  95 +// 产能
111 func (employeeProductRecord *EmployeeProductRecord) RealProductWeigh() float64 { 96 func (employeeProductRecord *EmployeeProductRecord) RealProductWeigh() float64 {
112 - return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh 97 + // 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
  98 + return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
113 } 99 }
114 100
  101 +// 合格率
115 func (employeeProductRecord *EmployeeProductRecord) QualificationRate() int { 102 func (employeeProductRecord *EmployeeProductRecord) QualificationRate() int {
116 - if employeeProductRecord.ProductWeigh == employeeProductRecord.SecondLevelWeigh { 103 + realProductWeigh := employeeProductRecord.RealProductWeigh()
  104 + if realProductWeigh == 0 {
117 return 0 105 return 0
118 } 106 }
119 - result := int((employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh) * 100 / employeeProductRecord.ProductWeigh) 107 + result := int(realProductWeigh * 100 / employeeProductRecord.ProductWeigh)
120 return result 108 return result
121 } 109 }
  1 +package domain
  2 +
  3 +type ProductRecordStaticInfo struct {
  4 + // 生产日期
  5 + ProductDate string `json:"productDate"`
  6 + // 生产计划ID
  7 + ProductPlanId int `json:"productPlanId,omitempty"`
  8 + // 计划的产品名称
  9 + PlanProductName string `json:"planProductName,omitempty"`
  10 + // 批号
  11 + BatchNumber string `json:"batchNumber,omitempty"`
  12 +
  13 + // 生产小组ID
  14 + ProductGroupId int `json:"productGroupId,omitempty"`
  15 +
  16 + // 保存其他工段二级品的重量
  17 + OtherSectionSecondLevelWeigh map[string]float64 `json:"sectionSecondLevelWeigh"`
  18 +}
  19 +
  20 +func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 {
  21 + var result float64
  22 + for _, v := range info.OtherSectionSecondLevelWeigh {
  23 + result += v
  24 + }
  25 + return result
  26 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 员工生产记录
  6 +type WorkshopProductRecord struct {
  7 + // 车间生产记录ID
  8 + WorkshopProductRecordId int `json:"workshopProductRecordId"`
  9 + // 企业id
  10 + CompanyId int `json:"companyId"`
  11 + // 组织ID
  12 + OrgId int `json:"orgId"`
  13 + // 工作位置
  14 + WorkStation *WorkStation `json:"workStation"`
  15 + // 生产日期
  16 + ProductDate string `json:"productDate"`
  17 + // 产能
  18 + ProductWeigh float64 `json:"productWeigh"`
  19 + // 二级品产能
  20 + SecondLevelWeigh float64 `json:"secondLevelWeigh"`
  21 + // 创建时间
  22 + CreatedAt time.Time `json:"createdAt"`
  23 + // 更新时间
  24 + UpdatedAt time.Time `json:"updatedAt"`
  25 + // 删除时间
  26 + DeletedAt time.Time `json:"deletedAt"`
  27 + // 扩展
  28 + Ext *Ext `json:"ext"`
  29 + // 版本号
  30 + Version int `json:"version"`
  31 + // 生产记录信息
  32 + ProductRecordInfo *ProductRecordStaticInfo `json:"productRecordInfo"`
  33 +}
  34 +
  35 +type WorkshopProductRecordRepository interface {
  36 + Save(workshopProductRecord *WorkshopProductRecord) (*WorkshopProductRecord, error)
  37 + Remove(workshopProductRecord *WorkshopProductRecord) (*WorkshopProductRecord, error)
  38 + FindOne(queryOptions map[string]interface{}) (*WorkshopProductRecord, error)
  39 + Find(queryOptions map[string]interface{}) (int64, []*WorkshopProductRecord, error)
  40 +}
  41 +
  42 +func (workshopProductRecord *WorkshopProductRecord) Identify() interface{} {
  43 + if workshopProductRecord.WorkshopProductRecordId == 0 {
  44 + return nil
  45 + }
  46 + return workshopProductRecord.WorkshopProductRecordId
  47 +}
  48 +
  49 +func (workshopProductRecord *WorkshopProductRecord) Update(data map[string]interface{}) error {
  50 + return nil
  51 +}
  52 +
  53 +func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) {
  54 + if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
  55 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
  56 + }
  57 + if productRecordType == RecordTypeSecondLevelWeigh {
  58 + if employeeProductRecord.WorkStation.SectionName == sectionName {
  59 + employeeProductRecord.SecondLevelWeigh += weigh
  60 + } else {
  61 + if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok {
  62 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品
  63 + } else {
  64 + employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
  65 + }
  66 + }
  67 + }
  68 + if productRecordType == RecordTypeReceiveMaterial {
  69 + employeeProductRecord.ProductWeigh += weigh
  70 + }
  71 + if productRecordType == RecordTypeReturnMaterial {
  72 + employeeProductRecord.ProductWeigh -= weigh
  73 + }
  74 + employeeProductRecord.UpdatedAt = time.Now()
  75 + employeeProductRecord.Version += 1
  76 +}
  77 +
  78 +// 产能
  79 +func (employeeProductRecord *WorkshopProductRecord) RealProductWeigh() float64 {
  80 + // 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
  81 + result := employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
  82 + return result
  83 +}
  84 +
  85 +// 合格率
  86 +func (employeeProductRecord *WorkshopProductRecord) QualificationRate() int {
  87 + realProductWeigh := employeeProductRecord.RealProductWeigh()
  88 + if realProductWeigh == 0 {
  89 + return 0
  90 + }
  91 + // 合格率 = 产能重量 / (总投入重量 - 上级损耗重量)
  92 + result := int(realProductWeigh * 100 / (employeeProductRecord.ProductWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()))
  93 + return result
  94 +}
  95 +func (employeeProductRecord *WorkshopProductRecord) DevotedProductWeigh() float64 {
  96 + result := employeeProductRecord.ProductWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
  97 + return result
  98 +}
1 package domain 1 package domain
2 2
  3 +const (
  4 + EmployeeFullTime = 1 // 固定
  5 + EmployeeDispatch = 2 // 派遣
  6 + EmployeePartTime = 3 // 临时
  7 +)
  8 +
3 // 用户对象 9 // 用户对象
4 type User struct { 10 type User struct {
5 // 用户Id 用户唯一标识 11 // 用户Id 用户唯一标识
@@ -209,6 +209,21 @@ func (workshop *Workshop) FindWorkStation(workshopId, lineId, sectionId int) (*W @@ -209,6 +209,21 @@ func (workshop *Workshop) FindWorkStation(workshopId, lineId, sectionId int) (*W
209 return NewWorkStation(workshop, line, section), nil 209 return NewWorkStation(workshop, line, section), nil
210 } 210 }
211 211
  212 +func (workshop *Workshop) FindWorkStationOrNil(workshopId, lineId, sectionId int) (*WorkStation, error) {
  213 + if workshop.WorkshopId != workshopId {
  214 + return nil, fmt.Errorf("不存在")
  215 + }
  216 + line, _ := workshop.FindLine(lineId)
  217 + //if err != nil {
  218 + // return nil, err
  219 + //}
  220 + section, _ := workshop.FindSection(lineId, sectionId)
  221 + //if err != nil {
  222 + // return nil, err
  223 + //}
  224 + return NewWorkStation(workshop, line, section), nil
  225 +}
  226 +
212 func (workshop *Workshop) GetProductLines(removed int) []*ProductLine { 227 func (workshop *Workshop) GetProductLines(removed int) []*ProductLine {
213 var result = make([]*ProductLine, 0) 228 var result = make([]*ProductLine, 0)
214 for i := range workshop.ProductLines { 229 for i := range workshop.ProductLines {
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg/v10"
  6 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
  11 + "time"
  12 +)
  13 +
  14 +type WorkshopProductRecordDao struct {
  15 + transactionContext *pgTransaction.TransactionContext
  16 +}
  17 +
  18 +func NewWorkshopProductRecordDao(transactionContext *pgTransaction.TransactionContext) (*WorkshopProductRecordDao, error) {
  19 + if transactionContext == nil {
  20 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  21 + } else {
  22 + return &WorkshopProductRecordDao{
  23 + transactionContext: transactionContext,
  24 + }, nil
  25 + }
  26 +}
  27 +
  28 +// 员工对应批次的生产记录 (生产日期)
  29 +func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) {
  30 + tx := dao.transactionContext.PgTx
  31 + employeeProductRecordModel := new(models.WorkshopProductRecord)
  32 + query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{})
  33 + query.Where("company_id = ?", companyId)
  34 + query.Where("org_id = ?", orgId)
  35 + query.Where("product_date = ?", productTime.Format("2006-01-02"))
  36 + query.Where("product_record_info ->>'productPlanId' = '?'", planId)
  37 + if err := query.First(); err != nil {
  38 + if err.Error() == "pg: no rows in result set" {
  39 + return nil, domain.ErrorNotFound
  40 + } else {
  41 + return nil, err
  42 + }
  43 + }
  44 + if employeeProductRecordModel.WorkshopProductRecordId == 0 {
  45 + return nil, domain.ErrorNotFound
  46 + } else {
  47 + return transform.TransformToWorkshopProductRecordDomainModelFromPgModels(employeeProductRecordModel)
  48 + }
  49 +}
  50 +
  51 +func (dao *WorkshopProductRecordDao) SearchWorkshopProductRecord(queryOptions map[string]interface{}) (int64, []*domain.WorkshopProductRecord, error) {
  52 + tx := dao.transactionContext.PgTx
  53 + var employeeProductRecordModels []*models.WorkshopProductRecord
  54 + employeeProductRecords := make([]*domain.WorkshopProductRecord, 0)
  55 + query := sqlbuilder.BuildQuery(tx.Model(&employeeProductRecordModels), queryOptions)
  56 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  57 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  58 + if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
  59 + query.Where(`org_id in (?)`, pg.In(v))
  60 + }
  61 + if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
  62 + query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
  63 + }
  64 + if v, ok := queryOptions["planProductName"]; ok && len(v.(string)) > 0 {
  65 + query.Where(fmt.Sprintf(`product_record_info->>'planProductName' like '%%%v%%'`, v))
  66 + }
  67 + if v, ok := queryOptions["productBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
  68 + query.Where("created_at>=?", v.(time.Time))
  69 + }
  70 + if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
  71 + query.Where("created_at<?", v.(time.Time))
  72 + }
  73 + query.SetOffsetAndLimit(domain.MaxQueryRow)
  74 + query.SetOrderDirect("workshop_product_record_id", "DESC")
  75 + if count, err := query.SelectAndCount(); err != nil {
  76 + return 0, employeeProductRecords, err
  77 + } else {
  78 + for _, employeeProductRecordModel := range employeeProductRecordModels {
  79 + if employeeProductRecord, err := transform.TransformToWorkshopProductRecordDomainModelFromPgModels(employeeProductRecordModel); err != nil {
  80 + return 0, employeeProductRecords, err
  81 + } else {
  82 + employeeProductRecords = append(employeeProductRecords, employeeProductRecord)
  83 + }
  84 + }
  85 + return int64(count), employeeProductRecords, nil
  86 + }
  87 +}
@@ -40,7 +40,7 @@ func (svr *UserService) Organization(id int) (*domain.Org, error) { @@ -40,7 +40,7 @@ func (svr *UserService) Organization(id int) (*domain.Org, error) {
40 } 40 }
41 41
42 func (svr *UserService) ToUser(from *models.User) *domain.User { 42 func (svr *UserService) ToUser(from *models.User) *domain.User {
43 - return &domain.User{ 43 + user := &domain.User{
44 UserId: from.UserId, 44 UserId: from.UserId,
45 UserName: from.UserInfo.UserName, 45 UserName: from.UserInfo.UserName,
46 EmployeeType: from.EmployeeType, 46 EmployeeType: from.EmployeeType,
@@ -48,6 +48,10 @@ func (svr *UserService) ToUser(from *models.User) *domain.User { @@ -48,6 +48,10 @@ func (svr *UserService) ToUser(from *models.User) *domain.User {
48 Avatar: from.UserInfo.Avatar, 48 Avatar: from.UserInfo.Avatar,
49 Phone: from.UserInfo.Phone, 49 Phone: from.UserInfo.Phone,
50 } 50 }
  51 + if user.EmployeeType == 0 {
  52 + user.EmployeeType = 1 //默认正式员工
  53 + }
  54 + return user
51 } 55 }
52 56
53 func (svr *UserService) ToOrg(from *models.Organization) *domain.Org { 57 func (svr *UserService) ToOrg(from *models.Organization) *domain.Org {
@@ -88,7 +88,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. @@ -88,7 +88,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
88 log.Logger.Error(err.Error()) 88 log.Logger.Error(err.Error())
89 continue 89 continue
90 } 90 }
91 - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType) 91 + employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
92 92
93 if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { 93 if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
94 // TODO:异常处理 94 // TODO:异常处理
@@ -101,6 +101,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. @@ -101,6 +101,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
101 // 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型) 101 // 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
102 102
103 // 个人 103 // 个人
  104 +
104 return nil, nil 105 return nil, nil
105 } 106 }
106 107
@@ -118,12 +119,13 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy @@ -118,12 +119,13 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy
118 UpdatedAt: time.Now(), 119 UpdatedAt: time.Now(),
119 Ext: productPlan.Ext, 120 Ext: productPlan.Ext,
120 Version: 1, 121 Version: 1,
121 - ProductRecordInfo: &domain.EmployeeProductRecordInfo{  
122 - ProductDate: productRecord.CreatedAt.Format("2006-01-02"),  
123 - ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,  
124 - PlanProductName: productRecord.ProductRecordInfo.PlanProductName,  
125 - BatchNumber: productRecord.ProductRecordInfo.BatchNumber,  
126 - ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId, 122 + ProductRecordInfo: &domain.ProductRecordStaticInfo{
  123 + ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
  124 + ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
  125 + PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
  126 + BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
  127 + ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId,
  128 + OtherSectionSecondLevelWeigh: make(map[string]float64),
127 }, 129 },
128 ProductWorker: worker, 130 ProductWorker: worker,
129 } 131 }
@@ -207,7 +209,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. @@ -207,7 +209,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
207 if err == domain.ErrorNotFound { 209 if err == domain.ErrorNotFound {
208 employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker) 210 employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker)
209 } 211 }
210 - employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType) 212 + employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
211 213
212 if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil { 214 if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
213 // TODO:异常处理 215 // TODO:异常处理
@@ -217,6 +219,87 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. @@ -217,6 +219,87 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
217 } 219 }
218 220
219 //WorkshopProductStatics 车间产能统计 221 //WorkshopProductStatics 车间产能统计
220 -func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) (interface{}, error) { 222 +func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
  223 + var (
  224 + workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
  225 + productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
  226 + //productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
  227 + employeeProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
  228 + )
  229 +
  230 + var (
  231 + cid = productRecord.CompanyId
  232 + oid = productRecord.OrgId
  233 + planId = productRecord.ProductRecordInfo.ProductPlanId
  234 + productPlan *domain.ProductPlan
  235 + err error
  236 + )
  237 +
  238 + productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
  239 + if err != nil {
  240 + return nil, err
  241 + }
  242 +
  243 + switch productRecord.WorkStation.SectionName {
  244 + case ProductSection1:
  245 + if productRecord.ProductRecordType == domain.RecordTypeSecondLevelWeigh {
  246 + //查询生产记录 批次、生产日期、下(成型)所有二级品
  247 + // 更新打料的二级品需要再一次更新成型的二级品
  248 + if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil {
  249 + nextProductRecord := *productRecord
  250 + nextProductRecord.WorkStation.SectionName = ProductSection2
  251 + nextProductRecord.WorkStation.SectionId = section.SectionId
  252 + ptr.WorkshopProductStatics(&nextProductRecord)
  253 + }
  254 + }
  255 + break
  256 + }
  257 +
  258 + var employeeProductRecord *domain.WorkshopProductRecord
  259 + employeeProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
  260 + employeeProductRecord, err = employeeProductRecordDao.WorkshopProductRecord(cid, oid, planId, productRecord.CreatedAt)
  261 + if err == domain.ErrorNotFound {
  262 + employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan)
  263 + } else {
  264 + log.Logger.Error(err.Error())
  265 + return nil, nil
  266 + }
  267 + employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
  268 +
  269 + if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
  270 + // TODO:异常处理
  271 + log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error()))
  272 + }
221 return nil, nil 273 return nil, nil
222 } 274 }
  275 +
  276 +// newEmployeeProductRecord 员工生产记录
  277 +func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord {
  278 + record := &domain.WorkshopProductRecord{
  279 + CompanyId: productRecord.CompanyId,
  280 + OrgId: productRecord.OrgId,
  281 + WorkStation: productRecord.WorkStation,
  282 + //WorkOn: productPlan.WorkOn,
  283 + //ParticipateType: participateType,
  284 + ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
  285 + ProductWeigh: 0,
  286 + SecondLevelWeigh: 0,
  287 + CreatedAt: time.Now(),
  288 + UpdatedAt: time.Now(),
  289 + Ext: productPlan.Ext,
  290 + Version: 1,
  291 + ProductRecordInfo: &domain.ProductRecordStaticInfo{
  292 + ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
  293 + ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
  294 + PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
  295 + BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
  296 + ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId,
  297 + OtherSectionSecondLevelWeigh: make(map[string]float64),
  298 + },
  299 + }
  300 + // 打料、成型有初始值
  301 + if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 {
  302 + record.ProductWeigh = productPlan.PlanDevoted.Weight
  303 + }
  304 + return record
  305 +}
  1 +package domainService
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "github.com/hibiken/asynq"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/linmadan/egglib-go/utils/json"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  13 + "time"
  14 +)
  15 +
  16 +type PGWorkshopWorkTimeStaticService struct {
  17 + transactionContext *pgTransaction.TransactionContext
  18 +}
  19 +
  20 +//WorkshopWorkTimeStatic 车间工时统计
  21 +func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord *domain.ProductAttendanceRecord) (interface{}, error) {
  22 + workshopWorkTimeRecordRepository, _ := repository.NewWorkshopWorkTimeRecordRepository(ptr.transactionContext)
  23 + record, err := workshopWorkTimeRecordRepository.FindOne(map[string]interface{}{
  24 + "companyId": productRecord.CompanyId,
  25 + "orgId": productRecord.OrgId,
  26 + "workStationId": productRecord.WorkStation.WorkStationId,
  27 + "recordDate": utils.GetZeroTime(productRecord.SignIn),
  28 + })
  29 + if err != nil && errors.Is(err, domain.ErrorNotFound) {
  30 + err = nil
  31 + record = &domain.WorkshopWorkTimeRecord{
  32 + WorkStation: productRecord.WorkStation,
  33 + CreatedAt: time.Now(),
  34 + CompanyId: productRecord.CompanyId,
  35 + OrgId: productRecord.OrgId,
  36 + Ext: productRecord.Ext,
  37 + RecordDate: utils.GetZeroTime(productRecord.SignIn),
  38 + WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{},
  39 + }
  40 + }
  41 + if err != nil {
  42 + return nil, err
  43 + }
  44 +
  45 + employeeType := productRecord.ProductWorker.EmployeeType
  46 + switch employeeType {
  47 + case domain.EmployeeFullTime:
  48 + record.WorkshopWorkTimeRecordInfo.EFTWorkTime += productRecord.WorkTimeAfter
  49 + case domain.EmployeeDispatch:
  50 + record.WorkshopWorkTimeRecordInfo.EDWorkTime += productRecord.WorkTimeAfter
  51 + case domain.EmployeePartTime:
  52 + record.WorkshopWorkTimeRecordInfo.EPTWorkTime += productRecord.WorkTimeAfter
  53 + }
  54 +
  55 + if record, err = workshopWorkTimeRecordRepository.Save(record); err != nil {
  56 + return nil, err
  57 + }
  58 + return record, nil
  59 +}
  60 +
  61 +func SendWorkshopWorkTimeStaticJob(productRecord *domain.ProductAttendanceRecord) error {
  62 + task := asynq.NewTask(domain.TaskKeyWorkshopWorkTimeRecordStatics(), []byte(json.MarshalToString(productRecord)))
  63 +
  64 + client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
  65 + _, err := client.Enqueue(task)
  66 + return err
  67 +}
  68 +
  69 +func NewPGWorkshopWorkTimeStaticService(transactionContext *pgTransaction.TransactionContext) (*PGWorkshopWorkTimeStaticService, error) {
  70 + if transactionContext == nil {
  71 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  72 + } else {
  73 + return &PGWorkshopWorkTimeStaticService{
  74 + transactionContext: transactionContext,
  75 + }, nil
  76 + }
  77 +}
@@ -40,6 +40,8 @@ func init() { @@ -40,6 +40,8 @@ func init() {
40 (*models.MaterialGroupK3cloud)(nil), 40 (*models.MaterialGroupK3cloud)(nil),
41 (*models.PrdMoK3cloud)(nil), 41 (*models.PrdMoK3cloud)(nil),
42 (*models.EmployeeProductRecord)(nil), 42 (*models.EmployeeProductRecord)(nil),
  43 + (*models.WorkshopProductRecord)(nil),
  44 + (*models.WorkshopWorkTimeRecord)(nil),
43 } { 45 } {
44 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ 46 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
45 Temp: false, 47 Temp: false,
@@ -34,7 +34,7 @@ type EmployeeProductRecord struct { @@ -34,7 +34,7 @@ type EmployeeProductRecord struct {
34 // 版本号 34 // 版本号
35 Version int `comment:"版本号"` 35 Version int `comment:"版本号"`
36 // 生产记录信息 36 // 生产记录信息
37 - ProductRecordInfo *domain.EmployeeProductRecordInfo `comment:"生产记录信息"` 37 + ProductRecordInfo *domain.ProductRecordStaticInfo `comment:"生产记录信息"`
38 // 生产工人 38 // 生产工人
39 ProductWorker *domain.User `comment:"生产工人"` 39 ProductWorker *domain.User `comment:"生产工人"`
40 } 40 }
  1 +package models
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "time"
  6 +)
  7 +
  8 +type WorkshopProductRecord struct {
  9 + tableName string `comment:"员工生产记录" pg:"manufacture.workshop_product_record"`
  10 + // 车间生产记录ID
  11 + WorkshopProductRecordId int `comment:"车间生产记录ID" pg:"pk:workshop_product_record_id"`
  12 + // 企业id
  13 + CompanyId int `comment:"企业id"`
  14 + // 组织ID
  15 + OrgId int `comment:"组织ID"`
  16 + // 工作位置
  17 + WorkStation *domain.WorkStation `comment:"工作位置"`
  18 + // 生产日期
  19 + ProductDate string `comment:"生产日期"`
  20 + // 产能
  21 + ProductWeigh float64 `comment:"产能"`
  22 + // 二级品产能
  23 + SecondLevelWeigh float64 `comment:"二级品产能"`
  24 + // 创建时间
  25 + CreatedAt time.Time `comment:"创建时间"`
  26 + // 更新时间
  27 + UpdatedAt time.Time `comment:"更新时间"`
  28 + // 删除时间
  29 + DeletedAt time.Time `comment:"删除时间"`
  30 + // 扩展
  31 + Ext *domain.Ext `comment:"扩展"`
  32 + // 版本号
  33 + Version int `comment:"版本号"`
  34 + // 生产记录信息
  35 + ProductRecordInfo *domain.ProductRecordStaticInfo `comment:"生产记录信息"`
  36 +}
  1 +package models
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "time"
  6 +)
  7 +
  8 +type WorkshopWorkTimeRecord struct {
  9 + tableName string `comment:"车间工时记录" pg:"manufacture.workshop_work_time_record"`
  10 + // 车间工时记录ID
  11 + WorkshopWorkTimeRecordId int `comment:"车间工时记录ID" pg:"pk:workshop_work_time_record_id"`
  12 + // 工作位置
  13 + WorkStation *domain.WorkStation `comment:"工作位置"`
  14 + // 创建时间
  15 + CreatedAt time.Time `comment:"创建时间"`
  16 + // 企业id
  17 + CompanyId int `comment:"企业id"`
  18 + // 组织ID
  19 + OrgId int `comment:"组织ID"`
  20 + // 记录信息
  21 + WorkshopWorkTimeRecordInfo *domain.WorkshopWorkTimeRecordInfo `comment:"记录信息"`
  22 + // 扩展数据
  23 + Ext *domain.Ext `comment:"扩展数据"`
  24 + // 记录日期
  25 + RecordDate time.Time `comment:"记录日期"`
  26 +}
  1 +package transform
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  6 +)
  7 +
  8 +func TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel *models.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
  9 + return &domain.WorkshopProductRecord{
  10 + WorkshopProductRecordId: workshopProductRecordModel.WorkshopProductRecordId,
  11 + CompanyId: workshopProductRecordModel.CompanyId,
  12 + OrgId: workshopProductRecordModel.OrgId,
  13 + WorkStation: workshopProductRecordModel.WorkStation,
  14 + ProductDate: workshopProductRecordModel.ProductDate,
  15 + ProductWeigh: workshopProductRecordModel.ProductWeigh,
  16 + SecondLevelWeigh: workshopProductRecordModel.SecondLevelWeigh,
  17 + CreatedAt: workshopProductRecordModel.CreatedAt,
  18 + UpdatedAt: workshopProductRecordModel.UpdatedAt,
  19 + DeletedAt: workshopProductRecordModel.DeletedAt,
  20 + Ext: workshopProductRecordModel.Ext,
  21 + Version: workshopProductRecordModel.Version,
  22 + ProductRecordInfo: workshopProductRecordModel.ProductRecordInfo,
  23 + }, nil
  24 +}
  1 +package transform
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  6 +)
  7 +
  8 +func TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel *models.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
  9 + return &domain.WorkshopWorkTimeRecord{
  10 + WorkshopWorkTimeRecordId: workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId,
  11 + WorkStation: workshopWorkTimeRecordModel.WorkStation,
  12 + CreatedAt: workshopWorkTimeRecordModel.CreatedAt,
  13 + CompanyId: workshopWorkTimeRecordModel.CompanyId,
  14 + OrgId: workshopWorkTimeRecordModel.OrgId,
  15 + WorkshopWorkTimeRecordInfo: workshopWorkTimeRecordModel.WorkshopWorkTimeRecordInfo,
  16 + Ext: workshopWorkTimeRecordModel.Ext,
  17 + RecordDate: workshopWorkTimeRecordModel.RecordDate,
  18 + }, nil
  19 +}
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
  9 + "time"
9 10
10 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 11 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
11 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 12 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -165,7 +166,7 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin @@ -165,7 +166,7 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
165 query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions) 166 query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions)
166 query.SetWhereByQueryOption("company_id = ?", "companyId") 167 query.SetWhereByQueryOption("company_id = ?", "companyId")
167 query.SetWhereByQueryOption("org_id = ?", "orgId") 168 query.SetWhereByQueryOption("org_id = ?", "orgId")
168 - query.SetWhereByQueryOption("attendance_status = ?", "attendanceStatus") 169 + query.SetWhereByQueryOption("attendance_status & ? >0", "attendanceStatus")
169 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 { 170 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
170 query.Where(`org_id in (?)`, pg.In(v)) 171 query.Where(`org_id in (?)`, pg.In(v))
171 } 172 }
@@ -175,6 +176,18 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin @@ -175,6 +176,18 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
175 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { 176 if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
176 query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v)) 177 query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
177 } 178 }
  179 + if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
  180 + query.Where(fmt.Sprintf(`work_station->>'lineName' like '%%%v%%'`, v))
  181 + }
  182 + if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
  183 + query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
  184 + }
  185 + if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
  186 + query.Where("created_at>=?", v.(time.Time))
  187 + }
  188 + if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) {
  189 + query.Where("created_at<?", v.(time.Time))
  190 + }
178 query.SetOffsetAndLimit(domain.MaxQueryRow) 191 query.SetOffsetAndLimit(domain.MaxQueryRow)
179 query.SetOrderDirect("product_attendance_id", "DESC") 192 query.SetOrderDirect("product_attendance_id", "DESC")
180 if count, err := query.SelectAndCount(); err != nil { 193 if count, err := query.SelectAndCount(); err != nil {
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg/v10"
  6 +
  7 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 + "github.com/linmadan/egglib-go/utils/snowflake"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
  13 +)
  14 +
  15 +type WorkshopProductRecordRepository struct {
  16 + transactionContext *pgTransaction.TransactionContext
  17 +}
  18 +
  19 +func (repository *WorkshopProductRecordRepository) nextIdentify() (int64, error) {
  20 + IdWorker, err := snowflake.NewIdWorker(1)
  21 + if err != nil {
  22 + return 0, err
  23 + }
  24 + id, err := IdWorker.NextId()
  25 + return id, err
  26 +}
  27 +func (repository *WorkshopProductRecordRepository) Save(workshopProductRecord *domain.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
  28 + sqlBuildFields := []string{
  29 + "workshop_product_record_id",
  30 + "company_id",
  31 + "org_id",
  32 + "work_station",
  33 + "product_date",
  34 + "product_weigh",
  35 + "second_level_weigh",
  36 + "created_at",
  37 + "updated_at",
  38 + "deleted_at",
  39 + "ext",
  40 + "version",
  41 + "product_record_info",
  42 + }
  43 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at"))
  44 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at"))
  45 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  46 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at")
  47 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  48 + tx := repository.transactionContext.PgTx
  49 + if workshopProductRecord.Identify() == nil {
  50 + if _, err := tx.QueryOne(
  51 + pg.Scan(
  52 + &workshopProductRecord.WorkshopProductRecordId,
  53 + &workshopProductRecord.CompanyId,
  54 + &workshopProductRecord.OrgId,
  55 + &workshopProductRecord.WorkStation,
  56 + &workshopProductRecord.ProductDate,
  57 + &workshopProductRecord.ProductWeigh,
  58 + &workshopProductRecord.SecondLevelWeigh,
  59 + &workshopProductRecord.CreatedAt,
  60 + &workshopProductRecord.UpdatedAt,
  61 + &workshopProductRecord.DeletedAt,
  62 + &workshopProductRecord.Ext,
  63 + &workshopProductRecord.Version,
  64 + &workshopProductRecord.ProductRecordInfo,
  65 + ),
  66 + fmt.Sprintf("INSERT INTO manufacture.workshop_product_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  67 + workshopProductRecord.CompanyId,
  68 + workshopProductRecord.OrgId,
  69 + workshopProductRecord.WorkStation,
  70 + workshopProductRecord.ProductDate,
  71 + workshopProductRecord.ProductWeigh,
  72 + workshopProductRecord.SecondLevelWeigh,
  73 + workshopProductRecord.CreatedAt,
  74 + workshopProductRecord.UpdatedAt,
  75 + workshopProductRecord.Ext,
  76 + workshopProductRecord.Version,
  77 + workshopProductRecord.ProductRecordInfo,
  78 + ); err != nil {
  79 + return workshopProductRecord, err
  80 + }
  81 + } else {
  82 + if _, err := tx.QueryOne(
  83 + pg.Scan(
  84 + &workshopProductRecord.WorkshopProductRecordId,
  85 + &workshopProductRecord.CompanyId,
  86 + &workshopProductRecord.OrgId,
  87 + &workshopProductRecord.WorkStation,
  88 + &workshopProductRecord.ProductDate,
  89 + &workshopProductRecord.ProductWeigh,
  90 + &workshopProductRecord.SecondLevelWeigh,
  91 + &workshopProductRecord.CreatedAt,
  92 + &workshopProductRecord.UpdatedAt,
  93 + &workshopProductRecord.DeletedAt,
  94 + &workshopProductRecord.Ext,
  95 + &workshopProductRecord.Version,
  96 + &workshopProductRecord.ProductRecordInfo,
  97 + ),
  98 + fmt.Sprintf("UPDATE manufacture.workshop_product_record SET %s WHERE workshop_product_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  99 + workshopProductRecord.CompanyId,
  100 + workshopProductRecord.OrgId,
  101 + workshopProductRecord.WorkStation,
  102 + workshopProductRecord.ProductDate,
  103 + workshopProductRecord.ProductWeigh,
  104 + workshopProductRecord.SecondLevelWeigh,
  105 + workshopProductRecord.CreatedAt,
  106 + workshopProductRecord.UpdatedAt,
  107 + workshopProductRecord.Ext,
  108 + workshopProductRecord.Version,
  109 + workshopProductRecord.ProductRecordInfo,
  110 + workshopProductRecord.Identify(),
  111 + ); err != nil {
  112 + return workshopProductRecord, err
  113 + }
  114 + }
  115 + return workshopProductRecord, nil
  116 +}
  117 +func (repository *WorkshopProductRecordRepository) Remove(workshopProductRecord *domain.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
  118 + tx := repository.transactionContext.PgTx
  119 + workshopProductRecordModel := new(models.WorkshopProductRecord)
  120 + workshopProductRecordModel.WorkshopProductRecordId = workshopProductRecord.Identify().(int)
  121 + if _, err := tx.Model(workshopProductRecordModel).WherePK().Delete(); err != nil {
  122 + return workshopProductRecord, err
  123 + }
  124 + return workshopProductRecord, nil
  125 +}
  126 +func (repository *WorkshopProductRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.WorkshopProductRecord, error) {
  127 + tx := repository.transactionContext.PgTx
  128 + workshopProductRecordModel := new(models.WorkshopProductRecord)
  129 + query := sqlbuilder.BuildQuery(tx.Model(workshopProductRecordModel), queryOptions)
  130 + query.SetWhereByQueryOption("workshop_product_record.workshop_product_record_id = ?", "workshopProductRecordId")
  131 + if err := query.First(); err != nil {
  132 + if err.Error() == "pg: no rows in result set" {
  133 + return nil, fmt.Errorf("没有此资源")
  134 + } else {
  135 + return nil, err
  136 + }
  137 + }
  138 + if workshopProductRecordModel.WorkshopProductRecordId == 0 {
  139 + return nil, nil
  140 + } else {
  141 + return transform.TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel)
  142 + }
  143 +}
  144 +func (repository *WorkshopProductRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.WorkshopProductRecord, error) {
  145 + tx := repository.transactionContext.PgTx
  146 + var workshopProductRecordModels []*models.WorkshopProductRecord
  147 + workshopProductRecords := make([]*domain.WorkshopProductRecord, 0)
  148 + query := sqlbuilder.BuildQuery(tx.Model(&workshopProductRecordModels), queryOptions)
  149 + query.SetOffsetAndLimit(domain.MaxQueryRow)
  150 + query.SetOrderDirect("workshop_product_record_id", "DESC")
  151 + if count, err := query.SelectAndCount(); err != nil {
  152 + return 0, workshopProductRecords, err
  153 + } else {
  154 + for _, workshopProductRecordModel := range workshopProductRecordModels {
  155 + if workshopProductRecord, err := transform.TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel); err != nil {
  156 + return 0, workshopProductRecords, err
  157 + } else {
  158 + workshopProductRecords = append(workshopProductRecords, workshopProductRecord)
  159 + }
  160 + }
  161 + return int64(count), workshopProductRecords, nil
  162 + }
  163 +}
  164 +func NewWorkshopProductRecordRepository(transactionContext *pgTransaction.TransactionContext) (*WorkshopProductRecordRepository, error) {
  165 + if transactionContext == nil {
  166 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  167 + } else {
  168 + return &WorkshopProductRecordRepository{
  169 + transactionContext: transactionContext,
  170 + }, nil
  171 + }
  172 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg/v10"
  6 + "time"
  7 +
  8 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  9 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  10 + "github.com/linmadan/egglib-go/utils/snowflake"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
  14 +)
  15 +
  16 +type WorkshopWorkTimeRecordRepository struct {
  17 + transactionContext *pgTransaction.TransactionContext
  18 +}
  19 +
  20 +func (repository *WorkshopWorkTimeRecordRepository) nextIdentify() (int64, error) {
  21 + IdWorker, err := snowflake.NewIdWorker(1)
  22 + if err != nil {
  23 + return 0, err
  24 + }
  25 + id, err := IdWorker.NextId()
  26 + return id, err
  27 +}
  28 +func (repository *WorkshopWorkTimeRecordRepository) Save(workshopWorkTimeRecord *domain.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
  29 + sqlBuildFields := []string{
  30 + "workshop_work_time_record_id",
  31 + "work_station",
  32 + "created_at",
  33 + "company_id",
  34 + "org_id",
  35 + "workshop_work_time_record_info",
  36 + "ext",
  37 + "record_date",
  38 + }
  39 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id"))
  40 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id"))
  41 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  42 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id")
  43 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  44 + tx := repository.transactionContext.PgTx
  45 + if workshopWorkTimeRecord.Identify() == nil {
  46 + if _, err := tx.QueryOne(
  47 + pg.Scan(
  48 + &workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
  49 + &workshopWorkTimeRecord.WorkStation,
  50 + &workshopWorkTimeRecord.CreatedAt,
  51 + &workshopWorkTimeRecord.CompanyId,
  52 + &workshopWorkTimeRecord.OrgId,
  53 + &workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
  54 + &workshopWorkTimeRecord.Ext,
  55 + &workshopWorkTimeRecord.RecordDate,
  56 + ),
  57 + fmt.Sprintf("INSERT INTO manufacture.workshop_work_time_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  58 + //workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
  59 + workshopWorkTimeRecord.WorkStation,
  60 + workshopWorkTimeRecord.CreatedAt,
  61 + workshopWorkTimeRecord.CompanyId,
  62 + workshopWorkTimeRecord.OrgId,
  63 + workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
  64 + workshopWorkTimeRecord.Ext,
  65 + workshopWorkTimeRecord.RecordDate,
  66 + ); err != nil {
  67 + return workshopWorkTimeRecord, err
  68 + }
  69 + } else {
  70 + if _, err := tx.QueryOne(
  71 + pg.Scan(
  72 + &workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
  73 + &workshopWorkTimeRecord.WorkStation,
  74 + &workshopWorkTimeRecord.CreatedAt,
  75 + &workshopWorkTimeRecord.CompanyId,
  76 + &workshopWorkTimeRecord.OrgId,
  77 + &workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
  78 + &workshopWorkTimeRecord.Ext,
  79 + &workshopWorkTimeRecord.RecordDate,
  80 + ),
  81 + fmt.Sprintf("UPDATE manufacture.workshop_work_time_record SET %s WHERE workshop_work_time_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  82 + //workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
  83 + workshopWorkTimeRecord.WorkStation,
  84 + workshopWorkTimeRecord.CreatedAt,
  85 + workshopWorkTimeRecord.CompanyId,
  86 + workshopWorkTimeRecord.OrgId,
  87 + workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
  88 + workshopWorkTimeRecord.Ext,
  89 + workshopWorkTimeRecord.RecordDate,
  90 + workshopWorkTimeRecord.Identify(),
  91 + ); err != nil {
  92 + return workshopWorkTimeRecord, err
  93 + }
  94 + }
  95 + return workshopWorkTimeRecord, nil
  96 +}
  97 +func (repository *WorkshopWorkTimeRecordRepository) Remove(workshopWorkTimeRecord *domain.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
  98 + tx := repository.transactionContext.PgTx
  99 + workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord)
  100 + workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId = workshopWorkTimeRecord.Identify().(int)
  101 + if _, err := tx.Model(workshopWorkTimeRecordModel).WherePK().Delete(); err != nil {
  102 + return workshopWorkTimeRecord, err
  103 + }
  104 + return workshopWorkTimeRecord, nil
  105 +}
  106 +func (repository *WorkshopWorkTimeRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.WorkshopWorkTimeRecord, error) {
  107 + tx := repository.transactionContext.PgTx
  108 + workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord)
  109 + query := sqlbuilder.BuildQuery(tx.Model(workshopWorkTimeRecordModel), queryOptions)
  110 + query.SetWhereByQueryOption("workshop_work_time_record.workshop_work_time_record_id = ?", "workshopWorkTimeRecordId")
  111 + if err := query.First(); err != nil {
  112 + if err.Error() == "pg: no rows in result set" {
  113 + return nil, domain.ErrorNotFound
  114 + } else {
  115 + return nil, err
  116 + }
  117 + }
  118 + if workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId == 0 {
  119 + return nil, nil
  120 + } else {
  121 + return transform.TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel)
  122 + }
  123 +}
  124 +func (repository *WorkshopWorkTimeRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.WorkshopWorkTimeRecord, error) {
  125 + tx := repository.transactionContext.PgTx
  126 + var workshopWorkTimeRecordModels []*models.WorkshopWorkTimeRecord
  127 + workshopWorkTimeRecords := make([]*domain.WorkshopWorkTimeRecord, 0)
  128 + query := sqlbuilder.BuildQuery(tx.Model(&workshopWorkTimeRecordModels), queryOptions)
  129 +
  130 + query.SetWhereByQueryOption("company_id = ?", "companyId")
  131 + query.SetWhereByQueryOption("org_id = ?", "orgId")
  132 + if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
  133 + query.Where(`org_id in (?)`, pg.In(v))
  134 + }
  135 + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
  136 + query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
  137 + }
  138 + if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
  139 + query.Where(fmt.Sprintf(`work_station->>'lineName' like '%%%v%%'`, v))
  140 + }
  141 + //if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
  142 + // query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
  143 + //}
  144 + if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
  145 + query.Where("record_date>=?", v.(time.Time))
  146 + }
  147 + if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) {
  148 + query.Where("record_date<?", v.(time.Time))
  149 + }
  150 +
  151 + query.SetOffsetAndLimit(domain.MaxQueryRow)
  152 + query.SetOrderDirect("record_date", "DESC")
  153 + query.SetOrderDirect("workshop_work_time_record_id", "DESC")
  154 + if count, err := query.SelectAndCount(); err != nil {
  155 + return 0, workshopWorkTimeRecords, err
  156 + } else {
  157 + for _, workshopWorkTimeRecordModel := range workshopWorkTimeRecordModels {
  158 + if workshopWorkTimeRecord, err := transform.TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel); err != nil {
  159 + return 0, workshopWorkTimeRecords, err
  160 + } else {
  161 + workshopWorkTimeRecords = append(workshopWorkTimeRecords, workshopWorkTimeRecord)
  162 + }
  163 + }
  164 + return int64(count), workshopWorkTimeRecords, nil
  165 + }
  166 +}
  167 +func NewWorkshopWorkTimeRecordRepository(transactionContext *pgTransaction.TransactionContext) (*WorkshopWorkTimeRecordRepository, error) {
  168 + if transactionContext == nil {
  169 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  170 + } else {
  171 + return &WorkshopWorkTimeRecordRepository{
  172 + transactionContext: transactionContext,
  173 + }, nil
  174 + }
  175 +}
  1 +package utils
  2 +
  3 +import (
  4 + "strconv"
  5 + "time"
  6 +)
  7 +
  8 +func GetDayBegin() time.Time {
  9 + t := time.Now()
  10 + today, _ := time.Parse("2006-01-02", t.Format("2006-01-02"))
  11 + return today
  12 +}
  13 +
  14 +func GetDayEnd() time.Time {
  15 + t := GetDayBegin()
  16 + nextDay := t.AddDate(0, 0, 1)
  17 + return nextDay
  18 +}
  19 +
  20 +// GetFirstDateOfMonth 获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
  21 +func GetFirstDateOfMonth(d time.Time) time.Time {
  22 + d = d.AddDate(0, 0, -d.Day()+1)
  23 + return GetZeroTime(d)
  24 +}
  25 +
  26 +// GetNextMonthFirstDay 获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
  27 +func GetNextMonthFirstDay(d time.Time) time.Time {
  28 + d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
  29 + return GetZeroTime(d)
  30 +}
  31 +
  32 +// GetZeroTime 获取某一天的0点时间
  33 +func GetZeroTime(d time.Time) time.Time {
  34 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
  35 +}
  36 +
  37 +// GetNextDayZeroTime 获取某一天的23点59分59秒
  38 +func GetNextDayZeroTime(d time.Time) time.Time {
  39 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
  40 +}
  41 +
  42 +// TransformTimestampToTime 根据13位时间戳返回日期时间格式时间
  43 +func TransformTimestampToTime(timeStamp int64) time.Time {
  44 + t := strconv.FormatInt(timeStamp, 10)
  45 + tIpartStr := t[0:10]
  46 + //tDecpartStr := t[10:13]
  47 + ipart, _ := strconv.ParseInt(tIpartStr, 10, 64)
  48 + //decpart, _ := strconv.ParseInt(tDecpartStr, 10, 64)
  49 + myTime := time.Unix(ipart, 0)
  50 + //(myTime)
  51 + return time.Date(myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second(), 0, time.Local)
  52 +}
@@ -78,3 +78,27 @@ func (controller *AttendanceController) SearchAttendance() { @@ -78,3 +78,27 @@ func (controller *AttendanceController) SearchAttendance() {
78 total, data, err := attendanceService.SearchAttendance(operateInfo, cmd) 78 total, data, err := attendanceService.SearchAttendance(operateInfo, cmd)
79 ResponseGrid(controller.BaseController, total, data, err) 79 ResponseGrid(controller.BaseController, total, data, err)
80 } 80 }
  81 +
  82 +func (controller *AttendanceController) SearchEmployeeAttendanceStatics() {
  83 + attendanceService := service.NewAttendanceService(nil)
  84 + cmd := &query.SearchEmployeeAttendanceQuery{}
  85 + controller.Unmarshal(cmd)
  86 + operateInfo := ParseOperateInfo(controller.BaseController)
  87 + //cmd.OrgId = operateInfo.OrgId
  88 + cmd.CompanyId = operateInfo.CompanyId
  89 + cmd.InOrgIds = operateInfo.OrgIds
  90 + total, data, err := attendanceService.SearchEmployeeAttendanceStatics(operateInfo, cmd)
  91 + ResponseGrid(controller.BaseController, total, data, err)
  92 +}
  93 +
  94 +func (controller *AttendanceController) SearchWorkshopWorkTimeStatics() {
  95 + attendanceService := service.NewAttendanceService(nil)
  96 + cmd := &query.SearchEmployeeAttendanceQuery{}
  97 + controller.Unmarshal(cmd)
  98 + operateInfo := ParseOperateInfo(controller.BaseController)
  99 + //cmd.OrgId = operateInfo.OrgId
  100 + cmd.CompanyId = operateInfo.CompanyId
  101 + cmd.InOrgIds = operateInfo.OrgIds
  102 + total, data, err := attendanceService.SearchWorkshopWorkTimeStatics(operateInfo, cmd)
  103 + ResponseGrid(controller.BaseController, total, data, err)
  104 +}
@@ -90,3 +90,15 @@ func (controller *ProductRecordController) SearchEmployeeProductRecord() { @@ -90,3 +90,15 @@ func (controller *ProductRecordController) SearchEmployeeProductRecord() {
90 total, data, err := productPlanService.SearchEmployeeProductRecord(ParseOperateInfo(controller.BaseController), cmd) 90 total, data, err := productPlanService.SearchEmployeeProductRecord(ParseOperateInfo(controller.BaseController), cmd)
91 ResponseGrid(controller.BaseController, total, data, err) 91 ResponseGrid(controller.BaseController, total, data, err)
92 } 92 }
  93 +
  94 +func (controller *ProductRecordController) SearchWorkshopProductRecord() {
  95 + productPlanService := service.NewProductRecordService(nil)
  96 + cmd := &query.SearchWorkshopProductRecordQuery{}
  97 + Must(controller.Unmarshal(cmd))
  98 + operateInfo := ParseOperateInfo(controller.BaseController)
  99 + //cmd.OrgId = operateInfo.OrgId
  100 + cmd.CompanyId = operateInfo.CompanyId
  101 + cmd.InOrgIds = operateInfo.OrgIds
  102 + total, data, err := productPlanService.SearchWorkshopProductRecord(ParseOperateInfo(controller.BaseController), cmd)
  103 + ResponseGrid(controller.BaseController, total, data, err)
  104 +}
@@ -13,4 +13,6 @@ func init() { @@ -13,4 +13,6 @@ func init() {
13 web.Router("/attendances/", &controllers.AttendanceController{}, "Get:ListAttendance") 13 web.Router("/attendances/", &controllers.AttendanceController{}, "Get:ListAttendance")
14 web.Router("/attendances/approve", &controllers.AttendanceController{}, "Post:ApproveAttendance") 14 web.Router("/attendances/approve", &controllers.AttendanceController{}, "Post:ApproveAttendance")
15 web.Router("/attendances/search", &controllers.AttendanceController{}, "Post:SearchAttendance") 15 web.Router("/attendances/search", &controllers.AttendanceController{}, "Post:SearchAttendance")
  16 + web.Router("/attendances/employee-attendance-statics/search", &controllers.AttendanceController{}, "Post:SearchEmployeeAttendanceStatics")
  17 + web.Router("/attendances/workshop-attendance-statics/search", &controllers.AttendanceController{}, "Post:SearchWorkshopWorkTimeStatics")
16 } 18 }
@@ -14,4 +14,5 @@ func init() { @@ -14,4 +14,5 @@ func init() {
14 web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord") 14 web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord")
15 web.Router("/product-records/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord") 15 web.Router("/product-records/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord")
16 web.Router("/product-records/employee-productive/search", &controllers.ProductRecordController{}, "Post:SearchEmployeeProductRecord") 16 web.Router("/product-records/employee-productive/search", &controllers.ProductRecordController{}, "Post:SearchEmployeeProductRecord")
  17 + web.Router("/product-records/workshop-productive/search", &controllers.ProductRecordController{}, "Post:SearchWorkshopProductRecord")
17 } 18 }
@@ -23,7 +23,7 @@ func Run() { @@ -23,7 +23,7 @@ func Run() {
23 h := asynq.NewServeMux() 23 h := asynq.NewServeMux()
24 // ... Register handlers 24 // ... Register handlers
25 h.HandleFunc(domain.TaskKeyPatternProductRecordStatics(), HandlerProductRecordStatics) 25 h.HandleFunc(domain.TaskKeyPatternProductRecordStatics(), HandlerProductRecordStatics)
26 - 26 + h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics)
27 log.Logger.Info("aysnq task running ...") 27 log.Logger.Info("aysnq task running ...")
28 // Run blocks and waits for os signal to terminate the program. 28 // Run blocks and waits for os signal to terminate the program.
29 if err := srv.Run(h); err != nil { 29 if err := srv.Run(h); err != nil {
  1 +package task
  2 +
  3 +import (
  4 + "context"
  5 + "encoding/json"
  6 + "fmt"
  7 + "github.com/hibiken/asynq"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
  11 +)
  12 +
  13 +// 生产工时记录统计
  14 +func WorkshopWorkTimeRecordStatics(c context.Context, t *asynq.Task) error {
  15 + svr := service.NewAttendanceService(nil)
  16 + cmd := &command.WorkshopWorkTimeRecordStaticsCommand{}
  17 + if err := json.Unmarshal(t.Payload(), cmd); err != nil {
  18 + return err
  19 + }
  20 + log.Logger.Debug(fmt.Sprintf("【考勤记录统计】 消费 记录ID:%v 时间:%v", cmd.ProductAttendanceId, cmd.WorkTimeBefore))
  21 + _, err := svr.WorkshopWorkTimeRecordStatics(cmd)
  22 + if err != nil {
  23 + log.Logger.Error(err.Error())
  24 + }
  25 + return nil
  26 +}