作者 yangfu

refactor: 功能优化

* 禁用的用户不在车间面板上展示
* 二级品自动审核修改
@@ -41,7 +41,7 @@ func AutoApproveProductRecord(ctx context.Context) error { @@ -41,7 +41,7 @@ func AutoApproveProductRecord(ctx context.Context) error {
41 41
42 approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext)) 42 approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
43 43
44 - if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.AttendanceAutoApproved); err != nil { 44 + if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.ProductRecordAutoApproved); err != nil {
45 log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"}) 45 log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"})
46 return err 46 return err
47 } 47 }
@@ -73,7 +73,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) { @@ -73,7 +73,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
73 } 73 }
74 } 74 }
75 75
76 -func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) { 76 +func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string, checkUserEnableFunc func(int) bool) {
77 var mapUser = make(map[int]int) 77 var mapUser = make(map[int]int)
78 // 打卡的用户 78 // 打卡的用户
79 for _, v := range list { 79 for _, v := range list {
@@ -83,6 +83,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe @@ -83,6 +83,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe
83 item.ProductGroupId = 0 83 item.ProductGroupId = 0
84 item.GroupName = "" 84 item.GroupName = ""
85 item.Online = true 85 item.Online = true
  86 + if enable := checkUserEnableFunc(item.UserId); !enable {
  87 + continue
  88 + }
86 if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok { 89 if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok {
87 item.GroupName = v.GroupName 90 item.GroupName = v.GroupName
88 item.ProductGroupId = v.GroupId 91 item.ProductGroupId = v.GroupId
@@ -107,6 +110,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe @@ -107,6 +110,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe
107 item.UserName = v.UserName 110 item.UserName = v.UserName
108 item.ProductGroupId = v.GroupId 111 item.ProductGroupId = v.GroupId
109 item.GroupName = v.GroupName 112 item.GroupName = v.GroupName
  113 + if enable := checkUserEnableFunc(item.UserId); !enable {
  114 + continue
  115 + }
110 mapUser[item.UserId] = item.UserId 116 mapUser[item.UserId] = item.UserId
111 d.Append(item) 117 d.Append(item)
112 } 118 }
@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
  14 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
14 "sort" 15 "sort"
15 "strings" 16 "strings"
16 "time" 17 "time"
@@ -491,7 +492,20 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op @@ -491,7 +492,20 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op
491 productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0) 492 productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0)
492 mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId)) 493 mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId))
493 var results = dto.NewProductGroupEmployeesDtos() 494 var results = dto.NewProductGroupEmployeesDtos()
494 - results.LoadDtoV2(productGroups, mapUser, keyFunc) 495 +
  496 + userService := domainService.NewUserService()
  497 + checkUserEnableFunc := func(userId int) bool {
  498 + user, err := userService.User(userId)
  499 + if err != nil {
  500 + return false
  501 + }
  502 + if user.EnableStatus == int(domain.UserStatusEnable) {
  503 + return true
  504 + }
  505 + log.Logger.Debug(fmt.Sprintf("ID:%d 用户:%s 状态:%d 已被禁用,过滤", user.UserId, user.UserName, user.EnableStatus))
  506 + return false
  507 + }
  508 + results.LoadDtoV2(productGroups, mapUser, keyFunc, checkUserEnableFunc)
495 sort.Stable(results) 509 sort.Stable(results)
496 if err := transactionContext.CommitTransaction(); err != nil { 510 if err := transactionContext.CommitTransaction(); err != nil {
497 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 511 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -15,10 +15,11 @@ const ( @@ -15,10 +15,11 @@ const (
15 ) 15 )
16 16
17 const ( 17 const (
18 - ProductRecordNotApprove = 1 // 未审核  
19 - ProductRecordApproved = 2 // 已审核  
20 - ProductRecordWithdraw = 3 // 已撤回  
21 - ProductRecordLogged = 4 // 已记录 18 + ProductRecordNotApprove = 1 // 未审核
  19 + ProductRecordApproved = 2 // 已审核
  20 + ProductRecordWithdraw = 3 // 已撤回
  21 + ProductRecordLogged = 4 // 已记录
  22 + ProductRecordAutoApproved = 5 // 自动审核
22 ) 23 )
23 24
24 // 生产记录 25 // 生产记录
@@ -12,7 +12,7 @@ type ProductRecordInfo struct { @@ -12,7 +12,7 @@ type ProductRecordInfo struct {
12 WeighBefore float64 `json:"weighBefore"` 12 WeighBefore float64 `json:"weighBefore"`
13 // 产能-审核后 13 // 产能-审核后
14 WeighAfter float64 `json:"weighAfter"` 14 WeighAfter float64 `json:"weighAfter"`
15 - // 审核状态 1:未审核 2:已审核 15 + // 审核状态 1:未审核 2:已审核 3.已撤回 4.已记录 5.自动审核
16 ApproveStatus int `json:"approveStatus"` 16 ApproveStatus int `json:"approveStatus"`
17 // 审核时间 17 // 审核时间
18 ApproveAt int64 `json:"approveAt"` 18 ApproveAt int64 `json:"approveAt"`
@@ -6,6 +6,15 @@ const ( @@ -6,6 +6,15 @@ const (
6 EmployeePartTime = 3 // 临时 6 EmployeePartTime = 3 // 临时
7 ) 7 )
8 8
  9 +// 用户状态
  10 +const (
  11 + UserStatusEnable UserStatus = 1
  12 + UserStatusDisable UserStatus = 2
  13 + UserStatusDestroy UserStatus = 3
  14 +)
  15 +
  16 +type UserStatus int
  17 +
9 // 用户对象 18 // 用户对象
10 type User struct { 19 type User struct {
11 // 用户Id 用户唯一标识 20 // 用户Id 用户唯一标识
@@ -21,6 +30,8 @@ type User struct { @@ -21,6 +30,8 @@ type User struct {
21 // 手机号码 30 // 手机号码
22 Phone string `json:"phone,omitempty"` 31 Phone string `json:"phone,omitempty"`
23 32
  33 + // 启用状态
  34 + EnableStatus int `json:"-"`
24 // 额外扩展的参数 35 // 额外扩展的参数
25 GroupId int `json:"-"` 36 GroupId int `json:"-"`
26 GroupName string `json:"-"` 37 GroupName string `json:"-"`
@@ -63,6 +63,7 @@ func (svr *UserService) ToUser(from *models.User) *domain.User { @@ -63,6 +63,7 @@ func (svr *UserService) ToUser(from *models.User) *domain.User {
63 IcCardNumber: from.IcCardNumber, 63 IcCardNumber: from.IcCardNumber,
64 Avatar: from.UserInfo.Avatar, 64 Avatar: from.UserInfo.Avatar,
65 Phone: from.UserInfo.Phone, 65 Phone: from.UserInfo.Phone,
  66 + EnableStatus: from.EnableStatus,
66 } 67 }
67 if user.EmployeeType == 0 { 68 if user.EmployeeType == 0 {
68 user.EmployeeType = 1 //默认正式员工 69 user.EmployeeType = 1 //默认正式员工
@@ -204,7 +204,7 @@ func (ptr *PGProductRecordService) Cancel(productRecordId int) (interface{}, err @@ -204,7 +204,7 @@ func (ptr *PGProductRecordService) Cancel(productRecordId int) (interface{}, err
204 return struct{}{}, nil 204 return struct{}{}, nil
205 } 205 }
206 206
207 -func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weight float64, status int) (interface{}, error) { 207 +func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weightAfter float64, status int) (interface{}, error) {
208 var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext) 208 var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext)
209 var record *domain.ProductRecord 209 var record *domain.ProductRecord
210 var err error 210 var err error
@@ -220,26 +220,19 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap @@ -220,26 +220,19 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap
220 220
221 for i := range list { 221 for i := range list {
222 record = list[i] 222 record = list[i]
223 - t := record.ProductRecordInfo.WeighBefore  
224 - if weight > 0 {  
225 - t = weight 223 + weighBefore := record.ProductRecordInfo.WeighBefore
  224 + if weightAfter > 0 {
  225 + weighBefore = weightAfter
226 } 226 }
227 - if t <= 0 && status == domain.AttendanceAutoApproved { 227 + if weighBefore <= 0 || record.ProductRecordInfo.ApproveStatus != domain.ProductRecordNotApprove {
228 continue 228 continue
229 } 229 }
230 - if err = record.Approve(user, t, time.Now(), status); err != nil { 230 + if err = record.Approve(user, weighBefore, time.Now(), status); err != nil {
231 return nil, err 231 return nil, err
232 } 232 }
233 if _, err := productRecordRepository.Save(record); err != nil { 233 if _, err := productRecordRepository.Save(record); err != nil {
234 return nil, err 234 return nil, err
235 } 235 }
236 - }  
237 -  
238 - for i := range list {  
239 - record = list[i]  
240 - if record.ProductRecordInfo.WeighBefore <= 0 && status == domain.AttendanceAutoApproved {  
241 - continue  
242 - }  
243 if e := SendProductRecordStaticsJob(record); e != nil { 236 if e := SendProductRecordStaticsJob(record); e != nil {
244 log.Logger.Error("【发送产量统计任务失败】" + e.Error()) 237 log.Logger.Error("【发送产量统计任务失败】" + e.Error())
245 } 238 }