作者 yangfu

feat: 工时、二级品自动nan'x审核

正在显示 29 个修改的文件 包含 463 行增加92 行删除
... ... @@ -18,6 +18,12 @@ type EmployeeAttendanceRecordDto struct {
//*domain.ProductAttendanceRecordExt
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 考勤类型 1.正常 2.支援
AttendanceTypeDescription string `json:"attendanceTypeDescription,omitempty"`
// 员工类型描述 1:固定 2:派遣 3.临时
EmployeeTypeDescription string `json:"employeeTypeDescription,omitempty"`
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatusDescription string `json:"attendanceStatusDescription"`
// 工时
WorkTime float64 `json:"workTime"`
// 组织名称
... ... @@ -38,6 +44,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord,
d.WorkTime = m.WorkTimeAfter
//d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AttendanceTypeDescription = domain.ParticipateTypeDescription(m.AttendanceType)
d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType)
d.AttendanceStatusDescription = domain.AttendanceStatusDescription(m.AttendanceStatus)
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -44,7 +44,7 @@ func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.Appro
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = attendance.Approve(user, cmd.WorkTimeAfter); err != nil {
if err = attendance.Approve(user, cmd.WorkTimeAfter, domain.AttendanceApproved); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -119,6 +119,7 @@ func (attendanceService *AttendanceService) CreateAttendance(operateInfo *domain
ProductGroupId: productGroup.ProductGroupId,
}),
}
newAttendance.WorkTimeBefore = newAttendance.ComputeWorkTimeBefore()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
... ...
... ... @@ -36,6 +36,9 @@ func (crontabService *CrontabService) initTask() {
return srv.PullPrdMoNewest()
})
task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */1 * * * *", AutoApproveProductAttendanceRecord)
task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)
}
func (crontabService *CrontabService) StartCrontabTask() {
... ...
package crontab
import (
"context"
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 定时审核生产考勤记录
func AutoApproveProductAttendanceRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时审核生产考勤记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(transactionContext.(*pgTransaction.TransactionContext))
var records []*domain.ProductAttendanceRecord
_, records, err = attendanceRecordDao.RecentUnApprovedAttendanceRecord(24, 2)
if err != nil {
return err
}
approveAttendanceRecordsService, _ := domainService.NewPGApproveAttendanceRecordsService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApproveAttendanceRecords(nil, records, 0, 0, domain.AttendanceAutoApproved); err != nil {
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
package crontab
import (
"context"
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 定时审核生产记录
func AutoApproveProductRecord(ctx context.Context) error {
defer func() {
if r := recover(); r != nil {
log.Logger.Error(fmt.Sprintf("%v", r))
}
}()
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
if err != nil {
log.Logger.Error("【定时审核生产考勤记录】 失败:" + err.Error())
}
transactionContext.RollbackTransaction()
}()
attendanceRecordDao, _ := dao.NewProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
var records []*domain.ProductRecord
_, records, err = attendanceRecordDao.RecentUnApprovedProductRecord(24, 2, domain.RecordTypeSecondLevelWeigh)
if err != nil {
return err
}
approveAttendanceRecordsService, _ := domainService.NewPGProductRecordService(transactionContext.(*pgTransaction.TransactionContext))
if _, err = approveAttendanceRecordsService.BatchApprove(records, 0, 0, domain.AttendanceAutoApproved); err != nil {
return err
}
if err = transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
... ... @@ -23,7 +23,7 @@ type CreateProductCalendarCommand struct {
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `cname:"上班班次 1:全天 2:白班 4:中班 8:夜班" json:"workOn" valid:"Required"`
// 日历选择
CalendarSelected []string `cname:"日历选择" json:"calendarSelected" valid:"Required"`
CalendarSelected []int `cname:"日历选择" json:"calendarSelected" valid:"Required"`
// 上岗时间
InWorkAt string `cname:"上岗时间" json:"inWorkAt" valid:"Required"`
// 下岗时间
... ...
... ... @@ -2,7 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type ProductCalendarDto struct {
... ... @@ -17,7 +17,7 @@ type ProductCalendarDto struct {
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 日历选择
CalendarSelected []string `json:"calendarSelected,omitempty"`
CalendarSelected []int `json:"calendarSelected,omitempty"`
// 上岗时间
InWorkAt string `json:"inWorkAt,omitempty"`
// 下岗时间
... ... @@ -27,7 +27,7 @@ type ProductCalendarDto struct {
// 工时 (单位 h)
WorkTime float64 `json:"workTime,omitempty"`
// 已选择日历
CalendarSelectedString string `json:"calendarSelectedString,omitempty"`
//CalendarSelectedString string `json:"calendarSelectedString,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
... ... @@ -38,12 +38,12 @@ func (d *ProductCalendarDto) LoadDto(m *domain.ProductCalendar, orgId int) *Prod
d.ProductCalendarId = m.ProductCalendarId
d.WorkStation = m.WorkStation
d.WorkOn = m.WorkOn
d.CalendarSelected = m.CalendarSelected
d.CalendarSelected = utils.ToArrayInt(m.CalendarSelected)
d.InWorkAt = m.InWorkAt
d.OutWorkAt = m.OutWorkAt
d.BreakTime = m.BreakTime
d.WorkTime = m.WorkTime
d.CalendarSelectedString = strings.Join(m.CalendarSelected, "/")
//d.CalendarSelectedString = strings.Join(m.CalendarSelected, "/")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -66,7 +66,7 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper
OrgId: cmd.OrgId,
WorkStation: workStation,
WorkOn: cmd.WorkOn,
CalendarSelected: cmd.CalendarSelected,
CalendarSelected: utils.ToArrayString(cmd.CalendarSelected),
InWorkAt: cmd.InWorkAt,
OutWorkAt: cmd.OutWorkAt,
BreakTime: cmd.BreakTime,
... ... @@ -85,7 +85,10 @@ func (productCalendarService *ProductCalendarService) CreateProductCalendar(oper
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productCalendar, nil
result := &dto.ProductCalendarDto{}
result.LoadDto(productCalendar, 0)
return result, nil
}
}
... ... @@ -317,7 +320,10 @@ func (productCalendarService *ProductCalendarService) UpdateProductCalendar(cmd
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productCalendar, nil
result := &dto.ProductCalendarDto{}
result.LoadDto(productCalendar, 0)
return result, nil
}
}
... ...
... ... @@ -28,6 +28,10 @@ type EmployeeProductRecordDto struct {
AuthFlag bool `json:"authFlag"`
// 合格率 百分比
QualificationRate int `json:"qualificationRate"`
// 考勤类型 1.正常 2.支援
ParticipateTypeDescription string `json:"participateTypeDescription,omitempty"`
// 员工类型描述 1:固定 2:派遣 3.临时
EmployeeTypeDescription string `json:"employeeTypeDescription,omitempty"`
}
func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgId int) *EmployeeProductRecordDto {
... ... @@ -41,6 +45,8 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI
d.SecondLevelWeigh = m.SecondLevelWeigh
d.QualificationRate = m.QualificationRate()
d.CreatedAt = m.CreatedAt.Format("2006-01-02")
d.ParticipateTypeDescription = domain.ParticipateTypeDescription(m.ParticipateType)
d.EmployeeTypeDescription = domain.EmployeeTypeDescription(m.ProductWorker.EmployeeType)
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -19,7 +19,7 @@ type ProductLevelTwoRecord struct {
// 产能-审核后
WeighAfter float64 `json:"weighAfter"`
// 审核状态 1:未审核 2:已审核
ApproveStatus int64 `json:"approveStatus"`
ApproveStatus int `json:"approveStatus"`
// 审核时间
ApproveAt string `json:"approveAt"`
// 计划的产品名称
... ... @@ -27,6 +27,8 @@ type ProductLevelTwoRecord struct {
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 创建日期
CreatedDate string `json:"createdDate,omitempty"`
// 创建时间
CreatedAt string `json:"createdAt,omitempty"`
// 组织名称
... ... @@ -47,8 +49,8 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro
}
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
d.CreatedAt = m.CreatedAt.Format("2006-01-02")
d.CreatedDate = m.CreatedAt.Format("2006-01-02")
d.CreatedAt = m.CreatedAt.Format("2006-01-02 15:04:05")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -35,7 +35,7 @@ type SearchEmployeeProductRecordQuery struct {
// 姓名
UserName string `cname:"姓名" json:"userName"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType string `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
... ...
... ... @@ -3,8 +3,10 @@ package query
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
... ... @@ -30,10 +32,43 @@ type SearchProductRecordQuery struct {
BatchNumber string `cname:"批号" json:"batchNumber"`
// 姓名
UserName string `cname:"姓名" json:"userName"`
// 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重
ProductRecordType int `cname:"生产记录类型:1:领料 2:退料 4:称重 8:二级品称重"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 员工类型 1:固定 2:派遣 3.临时
EmployeeType int `cname:"员工类型 1:固定 2:派遣 3.临时" json:"employeeType"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
ProductBeginTime time.Time `cname:"开始时间" json:"productBeginTime"`
// 结束时间
ProductEndTime time.Time `cname:"结束时间" json:"productEndTime"`
}
func (cmd *SearchProductRecordQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.ProductBeginTime, err = time.Parse("2006-01-02 15:04:05", cmd.BeginTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("开始时间有误")
return
}
}
if len(cmd.EndTime) > 0 {
if cmd.ProductEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
}
func (cmd *SearchProductRecordQuery) ValidateQuery() error {
... ...
... ... @@ -120,3 +120,39 @@ func WorkOnDescription(workOn int) []string {
}
return result
}
func EmployeeTypeDescription(employeeType int) string {
if employeeType == 1 {
return "固定"
}
if employeeType == 2 {
return "派遣"
}
if employeeType == 3 {
return "临时"
}
return "固定"
}
func ParticipateTypeDescription(participateType int) string {
if participateType == 1 {
return "正常"
}
if participateType == 2 {
return "支援"
}
return "正常"
}
func AttendanceStatusDescription(status int) string {
if status == 1 {
return "未审核"
}
if status == 2 {
return "已审核"
}
if status == 4 {
return "自动审核"
}
return "已审核"
}
... ...
... ... @@ -8,6 +8,7 @@ import (
const (
AttendanceNotApprove = 1 // 未审核
AttendanceApproved = 2 // 已审核
AttendanceAutoApproved = 3 // 自动审核
)
// 生产考勤记录
... ... @@ -59,86 +60,28 @@ func (productAttendanceRecord *ProductAttendanceRecord) Identify() interface{} {
}
func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]interface{}) error {
if productAttendanceId, ok := data["productAttendanceId"]; ok {
productAttendanceRecord.ProductAttendanceId = productAttendanceId.(int)
}
if orgId, ok := data["orgId"]; ok {
productAttendanceRecord.OrgId = orgId.(int)
}
if attendanceType, ok := data["attendanceType"]; ok {
productAttendanceRecord.AttendanceType = attendanceType.(int)
}
if userId, ok := data["userId"]; ok {
productAttendanceRecord.ProductWorker.UserId = userId.(int)
}
if userName, ok := data["userName"]; ok {
productAttendanceRecord.ProductWorker.UserName = userName.(string)
}
if employeeType, ok := data["employeeType"]; ok {
productAttendanceRecord.ProductWorker.EmployeeType = employeeType.(int)
}
if icCardNumber, ok := data["icCardNumber"]; ok {
productAttendanceRecord.ProductWorker.IcCardNumber = icCardNumber.(string)
}
if avatar, ok := data["avatar"]; ok {
productAttendanceRecord.ProductWorker.Avatar = avatar.(string)
}
if phone, ok := data["phone"]; ok {
productAttendanceRecord.ProductWorker.Phone = phone.(string)
}
if workStationId, ok := data["workStationId"]; ok {
productAttendanceRecord.WorkStation.WorkStationId = workStationId.(string)
}
if workshopId, ok := data["workshopId"]; ok {
productAttendanceRecord.WorkStation.WorkshopId = workshopId.(int)
}
if workshopName, ok := data["workshopName"]; ok {
productAttendanceRecord.WorkStation.WorkshopName = workshopName.(string)
}
if lineId, ok := data["lineId"]; ok {
productAttendanceRecord.WorkStation.LineId = lineId.(int)
}
if lineName, ok := data["lineName"]; ok {
productAttendanceRecord.WorkStation.LineName = lineName.(string)
}
if sectionId, ok := data["sectionId"]; ok {
productAttendanceRecord.WorkStation.SectionId = sectionId.(int)
}
if sectionName, ok := data["sectionName"]; ok {
productAttendanceRecord.WorkStation.SectionName = sectionName.(string)
}
if signIn, ok := data["signIn"]; ok {
productAttendanceRecord.SignIn = signIn.(time.Time)
}
if signOut, ok := data["signOut"]; ok {
productAttendanceRecord.SignOut = signOut.(time.Time)
}
if attendanceStatus, ok := data["attendanceStatus"]; ok {
productAttendanceRecord.AttendanceStatus = attendanceStatus.(int)
}
if workTimeBefore, ok := data["workTimeBefore"]; ok {
productAttendanceRecord.WorkTimeBefore = workTimeBefore.(float64)
}
if workTimeAfter, ok := data["workTimeAfter"]; ok {
productAttendanceRecord.WorkTimeAfter = workTimeAfter.(float64)
}
if createdAt, ok := data["createdAt"]; ok {
productAttendanceRecord.CreatedAt = createdAt.(time.Time)
return nil
}
// 计算审核前工时
func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore() float64 {
if productAttendanceRecord.SignIn.IsZero() {
return 0
}
if updatedAt, ok := data["updatedAt"]; ok {
productAttendanceRecord.UpdatedAt = updatedAt.(time.Time)
if productAttendanceRecord.SignOut.IsZero() {
return 0
}
if deletedAt, ok := data["deletedAt"]; ok {
productAttendanceRecord.DeletedAt = deletedAt.(time.Time)
if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) {
return 0
}
return nil
return productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours()
}
func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64) error {
if productAttendanceRecord.AttendanceStatus == AttendanceApproved {
func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error {
if productAttendanceRecord.AttendanceStatus == AttendanceApproved || productAttendanceRecord.AttendanceStatus == AttendanceAutoApproved {
return errors.New("已审核")
}
productAttendanceRecord.AttendanceStatus = AttendanceApproved
productAttendanceRecord.AttendanceStatus = status
productAttendanceRecord.WorkTimeAfter = workTimeAfter
if productAttendanceRecord.Ext != nil && productAttendanceRecord.Ext.AttendanceExt != nil {
productAttendanceRecord.Ext.AttendanceExt.ApproveUserId = approveUser.UserId
... ...
... ... @@ -63,7 +63,7 @@ func (productRecord *ProductRecord) Update(data map[string]interface{}) error {
return nil
}
func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float64, approveAt time.Time) error {
func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float64, approveAt time.Time, status int) error {
if productRecord.ProductRecordInfo.ApproveAt > 0 {
return errors.New("已审核")
}
... ... @@ -71,7 +71,7 @@ func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float6
return errors.New("审核后重量必须大于0")
}
productRecord.ProductRecordInfo.ApproveAt = approveAt.Unix()
productRecord.ProductRecordInfo.ApproveStatus = ProductRecordApproved
productRecord.ProductRecordInfo.ApproveStatus = status
productRecord.ProductRecordInfo.ApproveUser = approveUser
productRecord.ProductRecordInfo.WeighAfter = weighAfter
productRecord.ProductRecordInfo.Weigh = weighAfter
... ...
... ... @@ -81,6 +81,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
}
}
employeeProductRecord.ProductRecordInfo.TotalOtherSecondLevelWeigh = employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() // 预先统计其他二级品占比
}
if productRecordType == RecordTypeReceiveMaterial {
employeeProductRecord.ProductWeigh += weigh
... ...
... ... @@ -13,7 +13,7 @@ type ProductRecordInfo struct {
// 产能-审核后
WeighAfter float64 `json:"weighAfter"`
// 审核状态 1:未审核 2:已审核
ApproveStatus int64 `json:"approveStatus"`
ApproveStatus int `json:"approveStatus"`
// 审核时间
ApproveAt int64 `json:"approveAt"`
// 审核人
... ...
... ... @@ -13,6 +13,7 @@ type ProductRecordStaticInfo struct {
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
TotalOtherSecondLevelWeigh float64 `json:"otherSecondLevelWeigh"`
// 保存其他工段二级品的重量
OtherSectionSecondLevelWeigh map[string]float64 `json:"sectionSecondLevelWeigh"`
}
... ...
... ... @@ -63,6 +63,7 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo
} else {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
}
employeeProductRecord.ProductRecordInfo.TotalOtherSecondLevelWeigh = employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh() // 预先统计其他二级品占比
}
}
if productRecordType == RecordTypeReceiveMaterial {
... ...
... ... @@ -50,3 +50,33 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or
return int64(count), productAttendanceRecords, nil
}
}
// 近n天未审核的考勤记录
// fromLastHour 从前 n小时开始
// recentDay 近 n天未审核的数据
func (dao *AttendanceRecordDao) RecentUnApprovedAttendanceRecord(fromLastHour int, recentDay int) (int64, []*domain.ProductAttendanceRecord, error) {
tx := dao.transactionContext.PgTx
endTime := time.Now().Add(-(time.Hour * time.Duration(fromLastHour)))
beginTime := endTime.Add(-(time.Hour * time.Duration(recentDay*24)))
var productAttendanceRecordModels []*models.ProductAttendanceRecord
productAttendanceRecords := make([]*domain.ProductAttendanceRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), map[string]interface{}{})
query.Where("sign_in <= ?", endTime)
query.Where("sign_in >= ?", beginTime)
query.Where("attendance_status = ?", domain.AttendanceNotApprove)
query.Where("work_time_before>0")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productAttendanceRecords, err
} else {
for _, productAttendanceRecordModel := range productAttendanceRecordModels {
if productAttendanceRecord, err := transform.TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendanceRecordModel); err != nil {
return 0, productAttendanceRecords, err
} else {
productAttendanceRecords = append(productAttendanceRecords, productAttendanceRecord)
}
}
return int64(count), productAttendanceRecords, nil
}
}
... ...
... ... @@ -71,7 +71,7 @@ func (dao *EmployeeProductRecordDao) SearchEmployeeProductRecord(queryOptions ma
if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["employeeType"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["employeeType"]; ok && v.(int) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'employeeType' = '%v'`, v))
}
if v, ok := queryOptions["productBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
... ...
package dao
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"time"
)
type ProductRecordDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewProductRecordDao(transactionContext *pgTransaction.TransactionContext) (*ProductRecordDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProductRecordDao{
transactionContext: transactionContext,
}, nil
}
}
// 近n天未审核的考勤记录
// fromLastHour 从前 n小时开始
// recentDay 近 n天未审核的数据
func (dao *ProductRecordDao) RecentUnApprovedProductRecord(fromLastHour int, recentDay int, recordType int) (int64, []*domain.ProductRecord, error) {
tx := dao.transactionContext.PgTx
endTime := time.Now().Add(-(time.Hour * time.Duration(fromLastHour)))
beginTime := endTime.Add(-(time.Hour * time.Duration(recentDay*24)))
var productAttendanceRecordModels []*models.ProductRecord
productAttendanceRecords := make([]*domain.ProductRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), map[string]interface{}{})
query.Where("created_at <= ?", endTime)
query.Where("created_at >= ?", beginTime)
query.Where("product_record_type & ? >0", recordType)
query.Where("product_record_info->>approveStatus = '?'", domain.AttendanceNotApprove)
query.Where("product_record_info->>'weighBefore'<>'0'")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, productAttendanceRecords, err
} else {
for _, productAttendanceRecordModel := range productAttendanceRecordModels {
if productAttendanceRecord, err := transform.TransformToProductRecordDomainModelFromPgModels(productAttendanceRecordModel); err != nil {
return 0, productAttendanceRecords, err
} else {
productAttendanceRecords = append(productAttendanceRecords, productAttendanceRecord)
}
}
return int64(count), productAttendanceRecords, nil
}
}
... ...
package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
type PGApproveAttendanceRecordsService struct {
transactionContext *pgTransaction.TransactionContext
}
func (ptr *PGApproveAttendanceRecordsService) BatchApproveAttendanceRecords(opt *domain.OperateInfo, list []*domain.ProductAttendanceRecord, approveUserId int, workTime float64, status int) (interface{}, error) {
var productAttendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext)
var attendance *domain.ProductAttendanceRecord
var err error
log.Logger.Info("【自动审核考勤记录任务】 启动")
var user *domain.User = &domain.User{}
userService := NewUserService()
if approveUserId > 0 {
user, err = userService.User(approveUserId)
if err != nil {
return nil, err
}
}
for i := range list {
attendance = list[i]
t := attendance.WorkTimeBefore
if workTime > 0 {
t = workTime
}
if t <= 0 && status == domain.AttendanceAutoApproved {
continue
}
if err = attendance.Approve(user, t, status); err != nil {
return nil, err
}
if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
return nil, err
}
}
for i := range list {
attendance = list[i]
if e := SendWorkshopWorkTimeStaticJob(attendance); e != nil {
log.Logger.Error("【发送工时统计任务失败】" + e.Error())
}
}
return struct{}{}, nil
}
func NewPGApproveAttendanceRecordsService(transactionContext *pgTransaction.TransactionContext) (*PGApproveAttendanceRecordsService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PGApproveAttendanceRecordsService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
... ... @@ -150,7 +151,7 @@ func (ptr *PGProductRecordService) Approve(productRecordId int, approveUserId in
return nil, err
}
if err = productRecord.Approve(user, weighAfter, approveAt); err != nil {
if err = productRecord.Approve(user, weighAfter, approveAt, domain.ProductRecordApproved); err != nil {
return nil, err
}
if _, err = productRecordRepository.Save(productRecord); err != nil {
... ... @@ -163,6 +164,49 @@ func (ptr *PGProductRecordService) Approve(productRecordId int, approveUserId in
return struct{}{}, nil
}
func (ptr *PGProductRecordService) BatchApprove(list []*domain.ProductRecord, approveUserId int, weight float64, status int) (interface{}, error) {
var productRecordRepository, _ = repository.NewProductRecordRepository(ptr.transactionContext)
var record *domain.ProductRecord
var err error
log.Logger.Info("【自动审核二级品记录任务】 启动")
var user *domain.User = &domain.User{}
userService := NewUserService()
if approveUserId > 0 {
user, err = userService.User(approveUserId)
if err != nil {
return nil, err
}
}
for i := range list {
record = list[i]
t := record.ProductRecordInfo.WeighBefore
if weight > 0 {
t = weight
}
if t <= 0 && status == domain.AttendanceAutoApproved {
continue
}
if err = record.Approve(user, t, 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())
}
}
return struct{}{}, nil
}
func SendProductRecordStaticsJob(productRecord *domain.ProductRecord) error {
task := asynq.NewTask(domain.TaskKeyPatternProductRecordStatics(), []byte(json.MarshalToString(productRecord)))
... ...
... ... @@ -85,9 +85,11 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
if err == domain.ErrorNotFound {
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, r.ProductWorker)
} else {
if err != nil {
log.Logger.Error(err.Error())
continue
}
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
... ... @@ -261,9 +263,11 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
if err == domain.ErrorNotFound {
employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan)
} else {
if err != nil {
log.Logger.Error(err.Error())
return nil, nil
}
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -145,6 +146,7 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
query := sqlbuilder.BuildQuery(tx.Model(&productRecordModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("product_record_type & ? >0", "productRecordType")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
... ... @@ -154,6 +156,21 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'workshopName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'lineName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`work_station->>'sectionName' like '%%%v%%'`, v))
}
if v, ok := queryOptions["employeeType"]; ok && v.(int) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'employeeType' = '%v'`, v))
}
if v, ok := queryOptions["productBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("created_at>=?", v.(time.Time))
}
if v, ok := queryOptions["productEndTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("created_at<?", v.(time.Time))
}
if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v))
}
... ...
... ... @@ -334,6 +334,15 @@ func ToArrayString(inputs []int) []string {
return result
}
func ToArrayInt(inputs []string) []int {
result := make([]int, 0)
for i := range inputs {
v, _ := strconv.Atoi(inputs[i])
result = append(result, v)
}
return result
}
func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
jsonlib.UnmarshalFromString(jsonlib.MarshalToString(queryOption), obj)
validation := validation.Validation{}
... ...
... ... @@ -75,6 +75,7 @@ func (controller *ProductRecordController) SearchProductRecord() {
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
cmd.ProductRecordType = 8
total, data, err := productPlanService.SearchProductRecord(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -13,6 +13,7 @@ func init() {
web.Router("/product-records/", &controllers.ProductRecordController{}, "Get:ListProductRecord")
web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord")
web.Router("/product-records/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord")
web.Router("/product-records/second-level-record/search", &controllers.ProductRecordController{}, "Post:SearchProductRecord")
web.Router("/product-records/employee-productive/search", &controllers.ProductRecordController{}, "Post:SearchEmployeeProductRecord")
web.Router("/product-records/workshop-productive/search", &controllers.ProductRecordController{}, "Post:SearchWorkshopProductRecord")
}
... ...