作者 yangfu

feat: 创建工时、生产班组下拉选择、工时统计优化

1 1
2 --- 表product_calendar 增加列表 break_time_periods  
3 -ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb;  
  2 +-- 表product_calendar 增加字段 break_time_periods
  3 +ALTER TABLE manufacture.product_calendar ADD COLUMN break_time_periods jsonb;
  4 +
  5 +-- 表product_attendance_record 增加字段 product_date
  6 +alter table manufacture.product_attendance_record add COLUMN product_date timestamptz;
  7 +update manufacture.product_attendance_record set product_date = sign_in where product_date is null ;
@@ -13,27 +13,36 @@ type CreateAttendanceCommand struct { @@ -13,27 +13,36 @@ type CreateAttendanceCommand struct {
13 // 考勤记录ID 13 // 考勤记录ID
14 //ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"` 14 //ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
15 // 考勤类型 1.正常 2.支援 15 // 考勤类型 1.正常 2.支援
16 - AttendanceType int `json:"attendanceType,omitempty"` 16 + AttendanceType int `cname:"考勤类型" json:"attendanceType,omitempty"`
17 // 生产班组Id 17 // 生产班组Id
18 - ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"` 18 + ProductGroupId int `cname:"生产班组Id" json:"productGroupId,omitempty" valid:"Required"`
19 // 生产工人 19 // 生产工人
20 - ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"` 20 + ProductWorkerId int `cname:"生产工人" json:"productWorkerId,omitempty" valid:"Required"`
21 // 车间ID 21 // 车间ID
22 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"` 22 WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
23 // 生产线ID 23 // 生产线ID
24 LineId int `cname:"生产线ID" json:"lineId" valid:"Required"` 24 LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
25 // 工段ID 25 // 工段ID
26 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"` 26 SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
  27 + // 生产日期
  28 + ProductDate time.Time `cname:"生产日期" json:"productDate,omitempty" valid:"Required"`
27 // 签到 29 // 签到
28 - SignIn time.Time `json:"signIn,omitempty"` 30 + SignIn time.Time `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"`
29 // 签退 31 // 签退
30 - SignOut time.Time `json:"signOut,omitempty"`  
31 - // 考勤状态 1.未审核 2:已审核 3.自动审核  
32 - //AttendanceStatus int `json:"attendanceStatus,omitempty"` 32 + SignOut time.Time `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"`
  33 + // 考勤状态 1.未审核 2:审核
  34 + AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"`
  35 + // 休息时长
  36 + BreakTime float64 `cname:"休息时长" json:"breakTime"`
  37 + // 工时
  38 + WorkTime float64 `cname:"工时" json:"workTime"`
  39 + // 准备(true:准备完毕 false:进行预查)
  40 + Prepared bool `json:"prepared"`
33 } 41 }
34 42
35 func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) { 43 func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
36 //validation.SetError("CustomValid", "未实现的自定义认证") 44 //validation.SetError("CustomValid", "未实现的自定义认证")
  45 + validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus")
37 } 46 }
38 47
39 func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error { 48 func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error {
@@ -50,7 +50,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i @@ -50,7 +50,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
50 d.WorkStation = m.WorkStation 50 d.WorkStation = m.WorkStation
51 if !m.SignIn.IsZero() { 51 if !m.SignIn.IsZero() {
52 d.SignIn = m.SignIn.Local().Format("15:04:05") 52 d.SignIn = m.SignIn.Local().Format("15:04:05")
53 - d.SignDate = m.SignIn.Local().Format("2006-01-02") 53 + d.SignDate = m.ProductTime().Format("2006-01-02")
54 } 54 }
55 if !m.SignOut.IsZero() { 55 if !m.SignOut.IsZero() {
56 d.SignOut = m.SignOut.Local().Format("15:04:05") 56 d.SignOut = m.SignOut.Local().Format("15:04:05")
@@ -40,10 +40,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, @@ -40,10 +40,7 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord,
40 d.AttendanceType = m.AttendanceType 40 d.AttendanceType = m.AttendanceType
41 d.ProductWorker = m.ProductWorker 41 d.ProductWorker = m.ProductWorker
42 d.WorkStation = m.WorkStation 42 d.WorkStation = m.WorkStation
43 - if !m.SignIn.IsZero() {  
44 - //d.SignIn = m.SignIn.Format("15:04:05")  
45 - d.SignDate = m.SignIn.Local().Format("2006-01-02")  
46 - } 43 + d.SignDate = m.ProductTime().Local().Format("2006-01-02")
47 d.WorkTime = utils.Round(m.WorkTimeAfter, 1) 44 d.WorkTime = utils.Round(m.WorkTimeAfter, 1)
48 //d.WorkTimeAfter = m.WorkTimeAfter 45 //d.WorkTimeAfter = m.WorkTimeAfter
49 d.AttendanceStatus = m.AttendanceStatus 46 d.AttendanceStatus = m.AttendanceStatus
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/transaction/pg"
  7 + "github.com/linmadan/egglib-go/utils/xtime"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/dto"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/query"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
12 "time" 16 "time"
@@ -100,6 +104,11 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -100,6 +104,11 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
100 if err != nil { 104 if err != nil {
101 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 105 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
102 } 106 }
  107 +
  108 + var workTime float64 = 0
  109 + if cmd.WorkTime-cmd.BreakTime > 0 {
  110 + workTime = cmd.WorkTime - cmd.BreakTime
  111 + }
103 newAttendance := &domain.ProductAttendanceRecord{ 112 newAttendance := &domain.ProductAttendanceRecord{
104 //ProductAttendanceId: cmd.ProductAttendanceId, 113 //ProductAttendanceId: cmd.ProductAttendanceId,
105 CompanyId: operateInfo.CompanyId, 114 CompanyId: operateInfo.CompanyId,
@@ -109,8 +118,8 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -109,8 +118,8 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
109 WorkStation: workStation, 118 WorkStation: workStation,
110 SignIn: cmd.SignIn, 119 SignIn: cmd.SignIn,
111 SignOut: cmd.SignOut, 120 SignOut: cmd.SignOut,
112 - AttendanceStatus: domain.AttendanceNotApprove,  
113 - WorkTimeBefore: 0, 121 + AttendanceStatus: cmd.AttendanceStatus,
  122 + WorkTimeBefore: workTime,
114 WorkTimeAfter: 0, 123 WorkTimeAfter: 0,
115 CreatedAt: time.Now(), 124 CreatedAt: time.Now(),
116 UpdatedAt: time.Now(), 125 UpdatedAt: time.Now(),
@@ -118,15 +127,33 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain @@ -118,15 +127,33 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
118 GroupName: productGroup.GroupName, 127 GroupName: productGroup.GroupName,
119 ProductGroupId: productGroup.ProductGroupId, 128 ProductGroupId: productGroup.ProductGroupId,
120 }), 129 }),
  130 + ProductDate: xtime.New(cmd.ProductDate).BeginningOfDay(),
121 } 131 }
122 - newAttendance.WorkTimeBefore = newAttendance.ComputeWorkTimeBefore(nil)  
123 - var attendanceRepository domain.ProductAttendanceRecordRepository  
124 132
  133 + if cmd.AttendanceStatus == domain.AttendanceApproved {
  134 + newAttendance.WorkTimeAfter = domain.AttendanceApproved
  135 + newAttendance.WorkTimeAfter = workTime
  136 + }
  137 + var (
  138 + attendanceRepository domain.ProductAttendanceRecordRepository
  139 + attendanceRecordDao *dao.AttendanceRecordDao
  140 + )
  141 + attendanceRecordDao, _ = dao.NewAttendanceRecordDao(transactionContext.(*pg.TransactionContext))
125 attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0) 142 attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
126 - 143 + if !cmd.Prepared {
  144 + // 检查时间段内是否有重复的打卡记录
  145 + count, _, err := attendanceRecordDao.WorkerAttendanceRecordsByProductDate(operateInfo.CompanyId, operateInfo.OrgId, cmd.ProductWorkerId, newAttendance.ProductDate, cmd.SignIn, cmd.SignIn)
  146 + if err != nil {
  147 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  148 + }
  149 + if count > 0 {
  150 + return nil, &application.ServiceError{Code: 10040001, Message: fmt.Sprintf("已存在员工%v的工时记录,是否继续新增", user.UserName)}
  151 + }
  152 + }
127 if attendance, err := attendanceRepository.Save(newAttendance); err != nil { 153 if attendance, err := attendanceRepository.Save(newAttendance); err != nil {
128 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 154 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
129 } else { 155 } else {
  156 + domainService.SendWorkshopWorkTimeStaticJob(attendance)
130 if err := transactionContext.CommitTransaction(); err != nil { 157 if err := transactionContext.CommitTransaction(); err != nil {
131 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 158 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
132 } 159 }
  1 +package dto
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  5 +)
  6 +
  7 +// 生产班组
  8 +type ProductGroupSelectorDto struct {
  9 + // 生产小组ID
  10 + ProductGroupId int `json:"productGroupId,omitempty"`
  11 + // 班组名称
  12 + GroupName string `json:"groupName,omitempty"`
  13 + // 班组长
  14 + GroupLeader *domain.User `json:"groupLeader"`
  15 + // 帮组成员列表
  16 + GroupMembers []*domain.User `json:"groupMembers"`
  17 +}
  18 +
  19 +func (d *ProductGroupSelectorDto) LoadDto(m *domain.ProductGroup, orgId int) *ProductGroupSelectorDto {
  20 + d.ProductGroupId = m.ProductGroupId
  21 + d.GroupName = m.GroupName
  22 + d.GroupLeader = m.GroupLeader
  23 + d.GroupMembers = m.GroupMembers
  24 + return d
  25 +}
@@ -543,6 +543,46 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi @@ -543,6 +543,46 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi
543 }, nil 543 }, nil
544 } 544 }
545 545
  546 +// 返回生产班组服务列表
  547 +func (productGroupService *ProductGroupService) SelectorProductGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupQuery) (interface{}, error) {
  548 + if err := cmd.ValidateQuery(); err != nil {
  549 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  550 + }
  551 + transactionContext, err := factory.CreateTransactionContext(nil)
  552 + if err != nil {
  553 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  554 + }
  555 + if err := transactionContext.StartTransaction(); err != nil {
  556 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  557 + }
  558 + defer func() {
  559 + transactionContext.RollbackTransaction()
  560 + }()
  561 +
  562 + workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
  563 + queryOptions := utils.ObjectToMap(cmd)
  564 + queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "")
  565 +
  566 + var productGroupRepository domain.ProductGroupRepository
  567 + productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
  568 + _, productGroups, err := productGroupRepository.Find(queryOptions)
  569 + if err != nil {
  570 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  571 + }
  572 + var results = make([]*dto.ProductGroupSelectorDto, 0)
  573 + for i := range productGroups {
  574 + newItem := &dto.ProductGroupSelectorDto{}
  575 + newItem.LoadDto(productGroups[i], operateInfo.OrgId)
  576 + results = append(results, newItem)
  577 + }
  578 + if err := transactionContext.CommitTransaction(); err != nil {
  579 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  580 + }
  581 + return map[string]interface{}{
  582 + "groups": results,
  583 + }, nil
  584 +}
  585 +
546 func NewProductGroupService(options map[string]interface{}) *ProductGroupService { 586 func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
547 newProductGroupService := &ProductGroupService{} 587 newProductGroupService := &ProductGroupService{}
548 return newProductGroupService 588 return newProductGroupService
@@ -45,6 +45,8 @@ type ProductAttendanceRecord struct { @@ -45,6 +45,8 @@ type ProductAttendanceRecord struct {
45 DeletedAt time.Time `json:"deletedAt,omitempty"` 45 DeletedAt time.Time `json:"deletedAt,omitempty"`
46 // 扩展数据 46 // 扩展数据
47 Ext *Ext `json:"ext,omitempty"` 47 Ext *Ext `json:"ext,omitempty"`
  48 + // 生产日期
  49 + ProductDate time.Time `json:"productDate,omitempty"`
48 } 50 }
49 51
50 type ProductAttendanceRecordRepository interface { 52 type ProductAttendanceRecordRepository interface {
@@ -89,7 +91,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(pr @@ -89,7 +91,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore(pr
89 91
90 func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error { 92 func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductCalendar(productCalendar *ProductCalendar) error {
91 now := xtime.New(productAttendanceRecord.SignIn) 93 now := xtime.New(productAttendanceRecord.SignIn)
92 - productAttendanceRecord.Ext.AttendanceExt.ProductTime = now.BeginningOfDay().Unix() 94 + productAttendanceRecord.ProductDate = now.BeginningOfDay()
93 if productCalendar == nil { 95 if productCalendar == nil {
94 return nil 96 return nil
95 } 97 }
@@ -99,7 +101,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductC @@ -99,7 +101,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) SetProductTimeByProductC
99 } 101 }
100 newNow := now.BeginningOfDay().Add(-time.Hour * 24) 102 newNow := now.BeginningOfDay().Add(-time.Hour * 24)
101 if overDay && productCalendar.MatchCalendarSelected(newNow) { 103 if overDay && productCalendar.MatchCalendarSelected(newNow) {
102 - productAttendanceRecord.Ext.AttendanceExt.ProductTime = newNow.Unix() 104 + productAttendanceRecord.ProductDate = newNow
103 } 105 }
104 return nil 106 return nil
105 } 107 }
@@ -123,11 +125,8 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use @@ -123,11 +125,8 @@ func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *Use
123 125
124 func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time { 126 func (productAttendanceRecord *ProductAttendanceRecord) ProductTime() time.Time {
125 attendanceExt := productAttendanceRecord.Ext.AttendanceExt 127 attendanceExt := productAttendanceRecord.Ext.AttendanceExt
126 - if attendanceExt != nil && attendanceExt.ProductTime > 0 {  
127 - t := time.Unix(attendanceExt.ProductTime, 0)  
128 - if !t.IsZero() {  
129 - return t  
130 - } 128 + if attendanceExt != nil && !xtime.IsZero(productAttendanceRecord.ProductDate) {
  129 + return productAttendanceRecord.ProductDate
131 } 130 }
132 return productAttendanceRecord.SignIn 131 return productAttendanceRecord.SignIn
133 } 132 }
@@ -7,7 +7,7 @@ type ProductAttendanceRecordExt struct { @@ -7,7 +7,7 @@ type ProductAttendanceRecordExt struct {
7 // 班组名称 7 // 班组名称
8 GroupName string `json:"groupName,omitempty"` 8 GroupName string `json:"groupName,omitempty"`
9 // 生产日期 9 // 生产日期
10 - ProductTime int64 `json:"productTime,omitempty"` 10 + //ProductTime int64 `json:"productTime,omitempty"`
11 // 审核人Id 11 // 审核人Id
12 ApproveUserId int `json:"approveUserId,omitempty"` 12 ApproveUserId int `json:"approveUserId,omitempty"`
13 // 审核人名称 13 // 审核人名称
@@ -123,3 +123,35 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker @@ -123,3 +123,35 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker
123 return int64(count), productAttendanceRecords, nil 123 return int64(count), productAttendanceRecords, nil
124 } 124 }
125 } 125 }
  126 +
  127 +func (dao *AttendanceRecordDao) WorkerAttendanceRecordsByProductDate(companyId, orgId, workerId int, productDate, beginTime, endTime time.Time) (int64, []*domain.ProductAttendanceRecord, error) {
  128 + tx := dao.transactionContext.PgTx
  129 + //endTime := time.Now()
  130 + //beginTime := endTime.Add(-(time.Hour * time.Duration(recentDay*24)))
  131 + var productAttendanceRecordModels []*models.ProductAttendanceRecord
  132 + productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0)
  133 + query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), map[string]interface{}{})
  134 + query.Where("company_id =?", companyId)
  135 + query.Where("org_id =?", orgId)
  136 + query.Where("product_worker ->>'userId' = '?'", workerId)
  137 + query.Where("product_date = ?", productDate)
  138 + query.Where("sign_in >= ?", beginTime)
  139 + query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
  140 + query.Where("sign_out is null")
  141 + query.WhereOr("sign_out>?", endTime)
  142 + return query, nil
  143 + })
  144 + query.SetOrderDirect("product_attendance_id", "DESC")
  145 + if count, err := query.SelectAndCount(); err != nil {
  146 + return 0, productAttendanceRecords, err
  147 + } else {
  148 + for _, productAttendanceRecordModel := range productAttendanceRecordModels {
  149 + if productAttendanceRecord, err := transform.TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendanceRecordModel); err != nil {
  150 + return 0, productAttendanceRecords, err
  151 + } else {
  152 + productAttendanceRecords = append(productAttendanceRecords, productAttendanceRecord)
  153 + }
  154 + }
  155 + return int64(count), productAttendanceRecords, nil
  156 + }
  157 +}
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
9 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"  
10 "time" 9 "time"
11 ) 10 )
12 11
@@ -21,7 +20,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord @@ -21,7 +20,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord
21 "companyId": productRecord.CompanyId, 20 "companyId": productRecord.CompanyId,
22 "orgId": productRecord.OrgId, 21 "orgId": productRecord.OrgId,
23 "workStationId": productRecord.WorkStation.WorkStationId, 22 "workStationId": productRecord.WorkStation.WorkStationId,
24 - "recordDate": utils.GetZeroTime(productRecord.SignIn), 23 + "recordDate": productRecord.ProductDate,
25 }) 24 })
26 if err != nil && errors.Is(err, domain.ErrorNotFound) { 25 if err != nil && errors.Is(err, domain.ErrorNotFound) {
27 err = nil 26 err = nil
@@ -31,7 +30,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord @@ -31,7 +30,7 @@ func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord
31 CompanyId: productRecord.CompanyId, 30 CompanyId: productRecord.CompanyId,
32 OrgId: productRecord.OrgId, 31 OrgId: productRecord.OrgId,
33 Ext: productRecord.Ext, 32 Ext: productRecord.Ext,
34 - RecordDate: utils.GetZeroTime(productRecord.ProductTime()), // utils.GetZeroTime(productRecord.SignIn), 33 + RecordDate: productRecord.ProductDate, // utils.GetZeroTime(productRecord.SignIn),
35 WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{}, 34 WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{},
36 } 35 }
37 } 36 }
@@ -37,4 +37,6 @@ type ProductAttendanceRecord struct { @@ -37,4 +37,6 @@ type ProductAttendanceRecord struct {
37 DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"` 37 DeletedAt time.Time `pg:",soft_delete" comment:"删除时间"`
38 // 扩展数据 38 // 扩展数据
39 Ext *domain.Ext `comment:"扩展数据"` 39 Ext *domain.Ext `comment:"扩展数据"`
  40 + // 生产日期
  41 + ProductDate time.Time `comment:"生产日期"`
40 } 42 }
@@ -22,5 +22,6 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance @@ -22,5 +22,6 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance
22 UpdatedAt: productAttendanceRecordModel.UpdatedAt, 22 UpdatedAt: productAttendanceRecordModel.UpdatedAt,
23 DeletedAt: productAttendanceRecordModel.DeletedAt, 23 DeletedAt: productAttendanceRecordModel.DeletedAt,
24 Ext: productAttendanceRecordModel.Ext, 24 Ext: productAttendanceRecordModel.Ext,
  25 + ProductDate: productAttendanceRecordModel.ProductDate,
25 }, nil 26 }, nil
26 } 27 }
@@ -42,6 +42,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -42,6 +42,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
42 "updated_at", 42 "updated_at",
43 "deleted_at", 43 "deleted_at",
44 "ext", 44 "ext",
  45 + "product_date",
45 } 46 }
46 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) 47 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
47 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at")) 48 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "product_attendance_id", "deleted_at"))
@@ -67,6 +68,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -67,6 +68,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
67 &productAttendanceRecord.UpdatedAt, 68 &productAttendanceRecord.UpdatedAt,
68 &productAttendanceRecord.DeletedAt, 69 &productAttendanceRecord.DeletedAt,
69 &productAttendanceRecord.Ext, 70 &productAttendanceRecord.Ext,
  71 + &productAttendanceRecord.ProductDate,
70 ), 72 ),
71 fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 73 fmt.Sprintf("INSERT INTO manufacture.product_attendance_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
72 //productAttendanceRecord.ProductAttendanceId, 74 //productAttendanceRecord.ProductAttendanceId,
@@ -84,6 +86,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -84,6 +86,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
84 productAttendanceRecord.UpdatedAt, 86 productAttendanceRecord.UpdatedAt,
85 //productAttendanceRecord.DeletedAt, 87 //productAttendanceRecord.DeletedAt,
86 productAttendanceRecord.Ext, 88 productAttendanceRecord.Ext,
  89 + productAttendanceRecord.ProductDate,
87 ); err != nil { 90 ); err != nil {
88 return productAttendanceRecord, err 91 return productAttendanceRecord, err
89 } 92 }
@@ -105,6 +108,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -105,6 +108,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
105 &productAttendanceRecord.UpdatedAt, 108 &productAttendanceRecord.UpdatedAt,
106 &productAttendanceRecord.DeletedAt, 109 &productAttendanceRecord.DeletedAt,
107 &productAttendanceRecord.Ext, 110 &productAttendanceRecord.Ext,
  111 + &productAttendanceRecord.ProductDate,
108 ), 112 ),
109 fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 113 fmt.Sprintf("UPDATE manufacture.product_attendance_record SET %s WHERE product_attendance_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
110 //productAttendanceRecord.ProductAttendanceId, 114 //productAttendanceRecord.ProductAttendanceId,
@@ -122,6 +126,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor @@ -122,6 +126,7 @@ func (repository *ProductAttendanceRecordRepository) Save(productAttendanceRecor
122 productAttendanceRecord.UpdatedAt, 126 productAttendanceRecord.UpdatedAt,
123 //productAttendanceRecord.DeletedAt, 127 //productAttendanceRecord.DeletedAt,
124 productAttendanceRecord.Ext, 128 productAttendanceRecord.Ext,
  129 + productAttendanceRecord.ProductDate,
125 productAttendanceRecord.Identify(), 130 productAttendanceRecord.Identify(),
126 ); err != nil { 131 ); err != nil {
127 return productAttendanceRecord, err 132 return productAttendanceRecord, err
@@ -189,10 +194,10 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin @@ -189,10 +194,10 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
189 query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v)) 194 query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
190 } 195 }
191 if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) { 196 if v, ok := queryOptions["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
192 - query.Where("created_at>=?", v.(time.Time)) 197 + query.Where("product_date>=?", v.(time.Time))
193 } 198 }
194 if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) { 199 if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) {
195 - query.Where("created_at<?", v.(time.Time)) 200 + query.Where("product_date<?", v.(time.Time))
196 } 201 }
197 if v, ok := queryOptions["employeeType"]; ok && (v.(int)) > 0 { 202 if v, ok := queryOptions["employeeType"]; ok && (v.(int)) > 0 {
198 query.Where("product_worker->>'employeeType'='?'", v.(int)) 203 query.Where("product_worker->>'employeeType'='?'", v.(int))
@@ -100,3 +100,15 @@ func (controller *ProductGroupController) GetSignInEmployeeQuery() { @@ -100,3 +100,15 @@ func (controller *ProductGroupController) GetSignInEmployeeQuery() {
100 data, err := productGroupService.GetSignEmployee(cmd) 100 data, err := productGroupService.GetSignEmployee(cmd)
101 controller.Response(data, err) 101 controller.Response(data, err)
102 } 102 }
  103 +
  104 +func (controller *ProductGroupController) SelectorProductGroups() {
  105 + productGroupService := service.NewProductGroupService(nil)
  106 + cmd := &query.SearchProductGroupQuery{}
  107 + Must(controller.Unmarshal(cmd))
  108 + operateInfo := ParseOperateInfo(controller.BaseController)
  109 + //cmd.OrgId = operateInfo.OrgId
  110 + cmd.CompanyId = operateInfo.CompanyId
  111 + cmd.InOrgIds = operateInfo.OrgIds
  112 + data, err := productGroupService.SelectorProductGroup(ParseOperateInfo(controller.BaseController), cmd)
  113 + controller.Response(data, err)
  114 +}
@@ -15,4 +15,5 @@ func init() { @@ -15,4 +15,5 @@ func init() {
15 web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup") 15 web.Router("/product-groups/search", &controllers.ProductGroupController{}, "Post:SearchProductGroup")
16 web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees") 16 web.Router("/product-groups/employees", &controllers.ProductGroupController{}, "Post:SearchProductGroupEmployees")
17 web.Router("/product-groups/employee-signing", &controllers.ProductGroupController{}, "Post:GetSignInEmployeeQuery") 17 web.Router("/product-groups/employee-signing", &controllers.ProductGroupController{}, "Post:GetSignInEmployeeQuery")
  18 + web.Router("/product-groups/selector", &controllers.ProductGroupController{}, "Post:SelectorProductGroups")
18 } 19 }