作者 yangfu

refactor: 功能优化

* 禁用的用户不在车间面板上展示
* 二级品自动审核修改
... ... @@ -41,7 +41,7 @@ func AutoApproveProductRecord(ctx context.Context) error {
approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.AttendanceAutoApproved); err != nil {
if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.ProductRecordAutoApproved); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"task": "定时审核生产记录"})
return err
}
... ...
... ... @@ -73,7 +73,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
}
}
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) {
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string, checkUserEnableFunc func(int) bool) {
var mapUser = make(map[int]int)
// 打卡的用户
for _, v := range list {
... ... @@ -83,6 +83,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe
item.ProductGroupId = 0
item.GroupName = ""
item.Online = true
if enable := checkUserEnableFunc(item.UserId); !enable {
continue
}
if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok {
item.GroupName = v.GroupName
item.ProductGroupId = v.GroupId
... ... @@ -107,6 +110,9 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRe
item.UserName = v.UserName
item.ProductGroupId = v.GroupId
item.GroupName = v.GroupName
if enable := checkUserEnableFunc(item.UserId); !enable {
continue
}
mapUser[item.UserId] = item.UserId
d.Append(item)
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"sort"
"strings"
"time"
... ... @@ -491,7 +492,20 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op
productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0)
mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId))
var results = dto.NewProductGroupEmployeesDtos()
results.LoadDtoV2(productGroups, mapUser, keyFunc)
userService := domainService.NewUserService()
checkUserEnableFunc := func(userId int) bool {
user, err := userService.User(userId)
if err != nil {
return false
}
if user.EnableStatus == int(domain.UserStatusEnable) {
return true
}
log.Logger.Debug(fmt.Sprintf("ID:%d 用户:%s 状态:%d 已被禁用,过滤", user.UserId, user.UserName, user.EnableStatus))
return false
}
results.LoadDtoV2(productGroups, mapUser, keyFunc, checkUserEnableFunc)
sort.Stable(results)
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -19,6 +19,7 @@ const (
ProductRecordApproved = 2 // 已审核
ProductRecordWithdraw = 3 // 已撤回
ProductRecordLogged = 4 // 已记录
ProductRecordAutoApproved = 5 // 自动审核
)
// 生产记录
... ...
... ... @@ -12,7 +12,7 @@ type ProductRecordInfo struct {
WeighBefore float64 `json:"weighBefore"`
// 产能-审核后
WeighAfter float64 `json:"weighAfter"`
// 审核状态 1:未审核 2:已审核
// 审核状态 1:未审核 2:已审核 3.已撤回 4.已记录 5.自动审核
ApproveStatus int `json:"approveStatus"`
// 审核时间
ApproveAt int64 `json:"approveAt"`
... ...
... ... @@ -6,6 +6,15 @@ const (
EmployeePartTime = 3 // 临时
)
// 用户状态
const (
UserStatusEnable UserStatus = 1
UserStatusDisable UserStatus = 2
UserStatusDestroy UserStatus = 3
)
type UserStatus int
// 用户对象
type User struct {
// 用户Id 用户唯一标识
... ... @@ -21,6 +30,8 @@ type User struct {
// 手机号码
Phone string `json:"phone,omitempty"`
// 启用状态
EnableStatus int `json:"-"`
// 额外扩展的参数
GroupId int `json:"-"`
GroupName string `json:"-"`
... ...
... ... @@ -63,6 +63,7 @@ func (svr *UserService) ToUser(from *models.User) *domain.User {
IcCardNumber: from.IcCardNumber,
Avatar: from.UserInfo.Avatar,
Phone: from.UserInfo.Phone,
EnableStatus: from.EnableStatus,
}
if user.EmployeeType == 0 {
user.EmployeeType = 1 //默认正式员工
... ...
... ... @@ -204,7 +204,7 @@ func (ptr *PGProductRecordService) Cancel(productRecordId int) (interface{}, err
return struct{}{}, nil
}
func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weight float64, status int) (interface{}, error) {
func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weightAfter float64, status int) (interface{}, error) {
var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext)
var record *domain.ProductRecord
var err error
... ... @@ -220,26 +220,19 @@ func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, ap
for i := range list {
record = list[i]
t := record.ProductRecordInfo.WeighBefore
if weight > 0 {
t = weight
weighBefore := record.ProductRecordInfo.WeighBefore
if weightAfter > 0 {
weighBefore = weightAfter
}
if t <= 0 && status == domain.AttendanceAutoApproved {
if weighBefore <= 0 || record.ProductRecordInfo.ApproveStatus != domain.ProductRecordNotApprove {
continue
}
if err = record.Approve(user, t, time.Now(), status); err != nil {
if err = record.Approve(user, weighBefore, time.Now(), status); err != nil {
return nil, err
}
if _, err := productRecordRepository.Save(record); err != nil {
return nil, err
}
}
for i := range list {
record = list[i]
if record.ProductRecordInfo.WeighBefore <= 0 && status == domain.AttendanceAutoApproved {
continue
}
if e := SendProductRecordStaticsJob(record); e != nil {
log.Logger.Error("【发送产量统计任务失败】" + e.Error())
}
... ...