作者 yangfu

feat: 工时审核

正在显示 44 个修改的文件 包含 1533 行增加77 行删除
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"reflect"
"strings"
)
type WorkshopWorkTimeRecordStaticsCommand struct {
*domain.ProductAttendanceRecord
}
// Type is a string value that indicates the type of the task.
//func (t *ProductRecordStaticsCommand) Type() string
// Payload is the data needed for task execution.
//func (t *ProductRecordStaticsCommand) Payload() []byte
func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProductRecordCommand *WorkshopWorkTimeRecordStaticsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProductRecordCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeProductRecordCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type EmployeeAttendanceRecordDto struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId"`
// 签到日期
SignDate string `json:"signDate"`
// 工作位置
*domain.WorkStation
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
//*domain.ProductAttendanceRecordExt
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatus int `json:"attendanceStatus"`
// 工时
WorkTime float64 `json:"workTime"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId int) *EmployeeAttendanceRecordDto {
d.ProductAttendanceId = m.ProductAttendanceId
d.AttendanceType = m.AttendanceType
d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
if !m.SignIn.IsZero() {
//d.SignIn = m.SignIn.Format("15:04:05")
d.SignDate = m.SignIn.Format("2006-01-02")
}
d.WorkTime = m.WorkTimeAfter
//d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
}
return d
}
... ...
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type WorkshopWorkTimeRecordDto struct {
// 车间工时记录ID
WorkshopWorkTimeRecordId int `json:"workshopWorkTimeRecordId"`
// 工作位置
*domain.WorkStation
// 签到日期
//SignDate string `json:"signDate"`
// 记录信息
*domain.WorkshopWorkTimeRecordInfo
// 记录日期
RecordDate string `json:"recordDate"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
}
func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto {
d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId
d.WorkStation = m.WorkStation
d.WorkshopWorkTimeRecordInfo = m.WorkshopWorkTimeRecordInfo
d.WorkStation = m.WorkStation
d.RecordDate = m.RecordDate.Format("2006-01-02")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
//d.ProductAttendanceRecordExt = m.Ext.AttendanceExt
}
return d
}
... ...
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"
)
type SearchEmployeeAttendanceQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset"`
// 查询限制
Limit int `cname:"查询限制" json:"limit"`
// 当前公司
CompanyId int `cname:"当前公司" json:"companyId,omitempty" valid:"Required"`
// 当前登录的组织
OrgId int `cname:"当前登录的组织" json:"orgId,omitempty" `
// 匹配多个组织
InOrgIds []int `cname:"匹配多个组织" json:"inOrgIds,omitempty" `
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 车间名称
WorkshopName string `cname:"车间名称" json:"workshopName,omitempty"`
// 生产线名称
LineName string `cname:"生产线名称" json:"lineName,omitempty"`
// 工段名称
SectionName string `cname:"工段名称" json:"sectionName,omitempty"`
// 姓名
UserName string `cname:"姓名" json:"userName,omitempty"`
// 考勤状态 1.未审核 2:已审核 4.自动审核
AttendanceStatus int `cname:"考勤状态 1.未审核 2:已审核 4.自动审核" json:"attendanceStatus,omitempty"`
// 开始时间
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 开始时间
SignBeginTime time.Time `cname:"开始时间" json:"signBeginTime"`
// 结束时间
SignEndTime time.Time `cname:"结束时间" json:"signEndTime"`
}
func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validation) {
cmd.Offset, cmd.Limit = domain.Pagination(cmd.PageNumber, cmd.PageSize)
var err error
if len(cmd.BeginTime) > 0 {
if cmd.SignBeginTime, 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.SignEndTime, err = time.Parse("2006-01-02 15:04:05", cmd.EndTime); err != nil {
log.Logger.Error(err.Error())
validation.Error("结束时间有误")
return
}
}
cmd.AttendanceStatus = 6 // 审核 + 自动审核
}
func (cmd *SearchEmployeeAttendanceQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -51,7 +51,9 @@ func (attendanceService *AttendanceService) ApproveAttendance(cmd *command.Appro
if _, err := productAttendanceRecordRepository.Save(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := domainService.SendWorkshopWorkTimeStaticJob(attendance); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -310,6 +312,74 @@ func (attendanceService *AttendanceService) SearchAttendance(operateInfo *domain
return count, result, nil
}
// 员工工时统计
func (attendanceService *AttendanceService) SearchEmployeeAttendanceStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.ProductAttendanceRecordRepository
attendanceRepository, _, _ = factory.FastPgAttendance(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, attendances, err := attendanceRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.EmployeeAttendanceRecordDto, 0)
for i := range attendances {
newItem := &dto.EmployeeAttendanceRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
return count, result, nil
}
// 车间工时统计
func (attendanceService *AttendanceService) SearchWorkshopWorkTimeStatics(operateInfo *domain.OperateInfo, cmd *query.SearchEmployeeAttendanceQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var attendanceRepository domain.WorkshopWorkTimeRecordRepository
attendanceRepository, _, _ = factory.FastPgWorkshopWorkTimeRecord(transactionContext, 0)
queryOptions := utils.ObjectToMap(cmd)
count, attendances, err := attendanceRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.WorkshopWorkTimeRecordDto, 0)
for i := range attendances {
newItem := &dto.WorkshopWorkTimeRecordDto{}
result = append(result, newItem.LoadDto(attendances[i], operateInfo.OrgId))
}
return count, result, nil
}
func NewAttendanceService(options map[string]interface{}) *AttendanceService {
newAttendanceService := &AttendanceService{}
return newAttendanceService
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 审核工时
func (attendanceService *AttendanceService) WorkshopWorkTimeRecordStatics(cmd *command.WorkshopWorkTimeRecordStaticsCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
svr, _ := domainService.NewPGWorkshopWorkTimeStaticService(transactionContext.(*pgTransaction.TransactionContext))
if _, err := svr.WorkshopWorkTimeStatic(cmd.ProductAttendanceRecord); err != nil {
log.Logger.Error(err.Error())
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return struct{}{}, nil
}
... ...
... ... @@ -22,11 +22,11 @@ type CreateDeviceCommand struct {
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
WorkshopId int `cname:"车间ID" json:"workshopId"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
LineId int `cname:"生产线ID" json:"lineId"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
SectionId int `cname:"工段ID" json:"sectionId"`
// 品牌
Brand string `cname:"品牌" json:"brand"`
// 设备状态 1:正常 2:封存 3:报废
... ...
... ... @@ -20,11 +20,11 @@ type UpdateDeviceCommand struct {
// 设备类型
DeviceType string `cname:"设备类型" json:"deviceType" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
WorkshopId int `cname:"车间ID" json:"workshopId"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
LineId int `cname:"生产线ID" json:"lineId" `
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
SectionId int `cname:"工段ID" json:"sectionId"`
// 品牌
Brand string `cname:"品牌" json:"brand" valid:"Required"`
// 设备状态 1:正常 2:封存 3:报废
... ...
... ... @@ -36,6 +36,7 @@ func (d *DeviceDto) LoadDto(m *domain.Device, orgId int) *DeviceDto {
d.DeviceId = m.DeviceId
d.DeviceCode = m.DeviceCode
d.DeviceName = m.DeviceName
d.DeviceModel = m.DeviceModel
d.DeviceType = m.DeviceType
d.Brand = m.Brand
d.DeviceStatus = m.DeviceStatus
... ...
... ... @@ -38,9 +38,12 @@ func (deviceService *DeviceService) CreateDevice(operateInfo *domain.OperateInfo
}()
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if cmd.WorkshopId != 0 {
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
}
var userService = domainService.NewUserService()
... ... @@ -272,9 +275,16 @@ func (deviceService *DeviceService) UpdateDevice(cmd *command.UpdateDeviceComman
}
var workStation *domain.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
if cmd.WorkshopId != 0 {
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId) //, cmd.LineId, cmd.SectionId
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workStation, _ = workshop.FindWorkStationOrNil(cmd.WorkshopId, cmd.LineId, cmd.SectionId)
}
device.WorkStation = workStation
... ...
... ... @@ -335,6 +335,32 @@ func FastPgProductRecord(transactionContext application.TransactionContext, id i
return rep, mod, err
}
// FastPgWorkshopWorkTimeRecord 快速返回生产记录
//
// transactionContext 事务
// id 对象唯一标识
func FastPgWorkshopWorkTimeRecord(transactionContext application.TransactionContext, id int, options ...option) (domain.WorkshopWorkTimeRecordRepository, *domain.WorkshopWorkTimeRecord, error) {
var rep domain.WorkshopWorkTimeRecordRepository
var mod *domain.WorkshopWorkTimeRecord
var err error
if value, err := CreateWorkshopWorkTimeRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"workshopWorkTimeRecordId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该记录不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
return rep, mod, err
}
/***** 2.配置 *****/
type FastOptions struct {
... ...
... ... @@ -93,3 +93,19 @@ func CreateEmployeeProductRecordRepository(options map[string]interface{}) (doma
}
return repository.NewEmployeeProductRecordRepository(transactionContext)
}
func CreateWorkshopProductRecordRepository(options map[string]interface{}) (domain.WorkshopProductRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewWorkshopProductRecordRepository(transactionContext)
}
func CreateWorkshopWorkTimeRecordRepository(options map[string]interface{}) (domain.WorkshopWorkTimeRecordRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewWorkshopWorkTimeRecordRepository(transactionContext)
}
... ...
... ... @@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/d
type EmployeeProductRecordDto struct {
// 员工产能记录ID
EmployeeProductRecordId int `json:"employeeProductRecordId"`
EmployeeProductRecordId int `json:"productRecordId"`
// 生产工人
ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.WorkStation
... ... @@ -40,7 +40,7 @@ func (d *EmployeeProductRecordDto) LoadDto(m *domain.EmployeeProductRecord, orgI
d.ProductWeigh = m.RealProductWeigh()
d.SecondLevelWeigh = m.SecondLevelWeigh
d.QualificationRate = m.QualificationRate()
d.CreatedAt = m.CreatedAt.Format("06-01-02")
d.CreatedAt = m.CreatedAt.Format("2006-01-02")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
type WorkshopProductRecordDto struct {
// 员工产能记录ID
WorkshopProductRecordId int `json:"productRecordId"`
// 生产工人
//ProductWorker *domain.User `json:"productWorker,omitempty"`
*domain.WorkStation
// 生产日期
//ProductDate string `json:"productDate"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 参与类型 1:正常 2:支援
//ParticipateType int `json:"participateType"`
// 投入量
DevotedProductWeigh float64 `json:"devotedProductWeigh"`
// 产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
// 创建时间
CreatedAt string `json:"createdAt,omitempty"`
// 组织名称
OrgName string `json:"orgName"`
// 权限标识 (当前登录组织匹配为true,否则false)
AuthFlag bool `json:"authFlag"`
// 合格率 百分比
QualificationRate int `json:"qualificationRate"`
}
func (d *WorkshopProductRecordDto) LoadDto(m *domain.WorkshopProductRecord, orgId int) *WorkshopProductRecordDto {
d.WorkshopProductRecordId = m.WorkshopProductRecordId
//d.ProductWorker = m.ProductWorker
d.WorkStation = m.WorkStation
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
//d.ParticipateType = m.ParticipateType
d.DevotedProductWeigh = m.DevotedProductWeigh()
d.ProductWeigh = m.RealProductWeigh()
d.SecondLevelWeigh = m.SecondLevelWeigh
d.QualificationRate = m.QualificationRate()
d.CreatedAt = m.ProductDate
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
}
return d
}
... ...
... ... @@ -304,6 +304,9 @@ func (productRecordService *ProductRecordService) ProductRecordStatics(cmd *comm
if _, err = svr.EmployeeProductStatics(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = svr.WorkshopProductStatics(productRecord); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -29,19 +29,19 @@ func (productRecordService *ProductRecordService) SearchWorkshopProductRecord(op
//var productRecordRepository domain.ProductRecordRepository
//productRecordRepository,_,_ = factory.FastPgProductRecord(transactionContext,0)
productRecordRepository, _ := dao.NewEmployeeProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
productRecordRepository, _ := dao.NewWorkshopProductRecordDao(transactionContext.(*pgTransaction.TransactionContext))
options := utils.ObjectToMap(listProductRecordQuery)
count, productRecords, err := productRecordRepository.SearchEmployeeProductRecord(options)
count, productRecords, err := productRecordRepository.SearchWorkshopProductRecord(options)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.EmployeeProductRecordDto, 0)
var result = make([]*dto.WorkshopProductRecordDto, 0)
for i := range productRecords {
item := productRecords[i]
newItem := &dto.EmployeeProductRecordDto{}
newItem := &dto.WorkshopProductRecordDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
... ...
... ... @@ -103,9 +103,9 @@ func (device *Device) Update(data map[string]interface{}) error {
}
if device.Ext == nil {
device.Ext = &Ext{}
if device.Ext.DeviceExt == nil {
device.Ext.DeviceExt = &DeviceExt{}
}
}
if device.Ext != nil && device.Ext.DeviceExt == nil {
device.Ext.DeviceExt = &DeviceExt{}
}
if orgName, ok := data["orgName"]; ok {
device.Ext.OrgName = orgName.(string)
... ...
package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
// 车间工时记录
type WorkshopWorkTimeRecord struct {
// 车间工时记录ID
WorkshopWorkTimeRecordId int `json:"workshopWorkTimeRecordId"`
// 工作位置
WorkStation *WorkStation `json:"workStation"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 企业id
CompanyId int `json:"companyId"`
// 组织ID
OrgId int `json:"orgId"`
// 记录信息
WorkshopWorkTimeRecordInfo *WorkshopWorkTimeRecordInfo `json:"workshopWorkTimeRecordInfo"`
// 扩展数据
Ext *Ext `json:"ext"`
// 记录日期
RecordDate time.Time `json:"recordDate"`
}
type WorkshopWorkTimeRecordInfo struct {
// 固定工时
EFTWorkTime float64 `json:"eft_work_time"`
// 临时工时
EDWorkTime float64 `json:"ed_work_time"`
// 派遣工时
EPTWorkTime float64 `json:"ept_work_time"`
}
type WorkshopWorkTimeRecordRepository interface {
Save(workshopWorkTimeRecord *WorkshopWorkTimeRecord) (*WorkshopWorkTimeRecord, error)
Remove(workshopWorkTimeRecord *WorkshopWorkTimeRecord) (*WorkshopWorkTimeRecord, error)
FindOne(queryOptions map[string]interface{}) (*WorkshopWorkTimeRecord, error)
Find(queryOptions map[string]interface{}) (int64, []*WorkshopWorkTimeRecord, error)
}
func (workshopWorkTimeRecord *WorkshopWorkTimeRecord) Identify() interface{} {
if workshopWorkTimeRecord.WorkshopWorkTimeRecordId == 0 {
return nil
}
return workshopWorkTimeRecord.WorkshopWorkTimeRecordId
}
func (workshopWorkTimeRecord *WorkshopWorkTimeRecord) Update(data map[string]interface{}) error {
return nil
}
func TaskKeyWorkshopWorkTimeRecordStatics() string {
return fmt.Sprintf("%v:task:workshop-work-time-record:statics", constant.CACHE_PREFIX)
}
... ...
... ... @@ -7,6 +7,13 @@ const (
ParticipateSupport = 2
)
const (
ProductSection1 = "打料"
ProductSection2 = "成型"
ProductSection3 = "穿串"
ProductSection4 = "包装"
)
// 员工生产记录
type EmployeeProductRecord struct {
// 企业id
... ... @@ -35,47 +42,12 @@ type EmployeeProductRecord struct {
Ext *Ext `json:"ext"`
// 版本号
Version int `json:"version"`
// 生产记录信息
ProductRecordInfo *EmployeeProductRecordInfo `json:"productRecordInfo"`
// 生产记录统计信息
ProductRecordInfo *ProductRecordStaticInfo `json:"productRecordInfo"`
// 生产工人
ProductWorker *User `comment:"生产工人"`
}
type EmployeeProductRecordInfo struct {
// 生产日期
ProductDate string `json:"productDate"`
// 原始上报数据
//OriginalWeigh float64 `json:"originalWeigh,omitempty"`
// 换算后的产能
//Weigh float64 `json:"weigh"`
// 产能 - 审核前
//WeighBefore float64 `json:"weighBefore"`
// 产能-审核后
//WeighAfter float64 `json:"weighAfter"`
// 审核状态 1:未审核 2:已审核
//ApproveStatus int64 `json:"approveStatus"`
// 审核时间
//ApproveAt int64 `json:"approveAt"`
// 审核人
//ApproveUser *User `json:"approveUser"`
// 物料信息
//Material *UnitConversion `json:"material,omitempty"`
// 生产计划信息(批次)
//ProductPlan *ProductPlan `json:"productPlan,omitempty"`
// 单位换算ID
//UnitConversionId int `json:"unitConversionId,omitempty"`
// 生产计划ID
ProductPlanId int `json:"productPlanId,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
}
type EmployeeProductRecordRepository interface {
Save(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
Remove(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
... ... @@ -94,9 +66,21 @@ func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]inter
return nil
}
func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int) {
// 更新生产量
func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) {
if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
employeeProductRecord.SecondLevelWeigh += weigh
if employeeProductRecord.WorkStation.SectionName == sectionName {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品
} else {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
}
}
}
if productRecordType == RecordTypeReceiveMaterial {
employeeProductRecord.ProductWeigh += weigh
... ... @@ -108,14 +92,18 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
employeeProductRecord.Version += 1
}
// 产能
func (employeeProductRecord *EmployeeProductRecord) RealProductWeigh() float64 {
return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh
// 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
}
// 合格率
func (employeeProductRecord *EmployeeProductRecord) QualificationRate() int {
if employeeProductRecord.ProductWeigh == employeeProductRecord.SecondLevelWeigh {
realProductWeigh := employeeProductRecord.RealProductWeigh()
if realProductWeigh == 0 {
return 0
}
result := int((employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh) * 100 / employeeProductRecord.ProductWeigh)
result := int(realProductWeigh * 100 / employeeProductRecord.ProductWeigh)
return result
}
... ...
package domain
type ProductRecordStaticInfo struct {
// 生产日期
ProductDate string `json:"productDate"`
// 生产计划ID
ProductPlanId int `json:"productPlanId,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 保存其他工段二级品的重量
OtherSectionSecondLevelWeigh map[string]float64 `json:"sectionSecondLevelWeigh"`
}
func (info *ProductRecordStaticInfo) OtherSecondLevelWeigh() float64 {
var result float64
for _, v := range info.OtherSectionSecondLevelWeigh {
result += v
}
return result
}
... ...
package domain
import "time"
// 员工生产记录
type WorkshopProductRecord struct {
// 车间生产记录ID
WorkshopProductRecordId int `json:"workshopProductRecordId"`
// 企业id
CompanyId int `json:"companyId"`
// 组织ID
OrgId int `json:"orgId"`
// 工作位置
WorkStation *WorkStation `json:"workStation"`
// 生产日期
ProductDate string `json:"productDate"`
// 产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 扩展
Ext *Ext `json:"ext"`
// 版本号
Version int `json:"version"`
// 生产记录信息
ProductRecordInfo *ProductRecordStaticInfo `json:"productRecordInfo"`
}
type WorkshopProductRecordRepository interface {
Save(workshopProductRecord *WorkshopProductRecord) (*WorkshopProductRecord, error)
Remove(workshopProductRecord *WorkshopProductRecord) (*WorkshopProductRecord, error)
FindOne(queryOptions map[string]interface{}) (*WorkshopProductRecord, error)
Find(queryOptions map[string]interface{}) (int64, []*WorkshopProductRecord, error)
}
func (workshopProductRecord *WorkshopProductRecord) Identify() interface{} {
if workshopProductRecord.WorkshopProductRecordId == 0 {
return nil
}
return workshopProductRecord.WorkshopProductRecordId
}
func (workshopProductRecord *WorkshopProductRecord) Update(data map[string]interface{}) error {
return nil
}
func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string) {
if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
if employeeProductRecord.WorkStation.SectionName == sectionName {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
if _, ok := employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName]; ok {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] += weigh //存关联级的二级品
} else {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh[sectionName] = weigh
}
}
}
if productRecordType == RecordTypeReceiveMaterial {
employeeProductRecord.ProductWeigh += weigh
}
if productRecordType == RecordTypeReturnMaterial {
employeeProductRecord.ProductWeigh -= weigh
}
employeeProductRecord.UpdatedAt = time.Now()
employeeProductRecord.Version += 1
}
// 产能
func (employeeProductRecord *WorkshopProductRecord) RealProductWeigh() float64 {
// 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
result := employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
return result
}
// 合格率
func (employeeProductRecord *WorkshopProductRecord) QualificationRate() int {
realProductWeigh := employeeProductRecord.RealProductWeigh()
if realProductWeigh == 0 {
return 0
}
// 合格率 = 产能重量 / (总投入重量 - 上级损耗重量)
result := int(realProductWeigh * 100 / (employeeProductRecord.ProductWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()))
return result
}
func (employeeProductRecord *WorkshopProductRecord) DevotedProductWeigh() float64 {
result := employeeProductRecord.ProductWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
return result
}
... ...
package domain
const (
EmployeeFullTime = 1 // 固定
EmployeeDispatch = 2 // 派遣
EmployeePartTime = 3 // 临时
)
// 用户对象
type User struct {
// 用户Id 用户唯一标识
... ...
... ... @@ -209,6 +209,21 @@ func (workshop *Workshop) FindWorkStation(workshopId, lineId, sectionId int) (*W
return NewWorkStation(workshop, line, section), nil
}
func (workshop *Workshop) FindWorkStationOrNil(workshopId, lineId, sectionId int) (*WorkStation, error) {
if workshop.WorkshopId != workshopId {
return nil, fmt.Errorf("不存在")
}
line, _ := workshop.FindLine(lineId)
//if err != nil {
// return nil, err
//}
section, _ := workshop.FindSection(lineId, sectionId)
//if err != nil {
// return nil, err
//}
return NewWorkStation(workshop, line, section), nil
}
func (workshop *Workshop) GetProductLines(removed int) []*ProductLine {
var result = make([]*ProductLine, 0)
for i := range workshop.ProductLines {
... ...
package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"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 WorkshopProductRecordDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewWorkshopProductRecordDao(transactionContext *pgTransaction.TransactionContext) (*WorkshopProductRecordDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &WorkshopProductRecordDao{
transactionContext: transactionContext,
}, nil
}
}
// 员工对应批次的生产记录 (生产日期)
func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, planId int, productTime time.Time) (*domain.WorkshopProductRecord, error) {
tx := dao.transactionContext.PgTx
employeeProductRecordModel := new(models.WorkshopProductRecord)
query := sqlbuilder.BuildQuery(tx.Model(employeeProductRecordModel), map[string]interface{}{})
query.Where("company_id = ?", companyId)
query.Where("org_id = ?", orgId)
query.Where("product_date = ?", productTime.Format("2006-01-02"))
query.Where("product_record_info ->>'productPlanId' = '?'", planId)
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if employeeProductRecordModel.WorkshopProductRecordId == 0 {
return nil, domain.ErrorNotFound
} else {
return transform.TransformToWorkshopProductRecordDomainModelFromPgModels(employeeProductRecordModel)
}
}
func (dao *WorkshopProductRecordDao) SearchWorkshopProductRecord(queryOptions map[string]interface{}) (int64, []*domain.WorkshopProductRecord, error) {
tx := dao.transactionContext.PgTx
var employeeProductRecordModels []*models.WorkshopProductRecord
employeeProductRecords := make([]*domain.WorkshopProductRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&employeeProductRecordModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(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["planProductName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_record_info->>'planProductName' like '%%%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))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("workshop_product_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, employeeProductRecords, err
} else {
for _, employeeProductRecordModel := range employeeProductRecordModels {
if employeeProductRecord, err := transform.TransformToWorkshopProductRecordDomainModelFromPgModels(employeeProductRecordModel); err != nil {
return 0, employeeProductRecords, err
} else {
employeeProductRecords = append(employeeProductRecords, employeeProductRecord)
}
}
return int64(count), employeeProductRecords, nil
}
}
... ...
... ... @@ -40,7 +40,7 @@ func (svr *UserService) Organization(id int) (*domain.Org, error) {
}
func (svr *UserService) ToUser(from *models.User) *domain.User {
return &domain.User{
user := &domain.User{
UserId: from.UserId,
UserName: from.UserInfo.UserName,
EmployeeType: from.EmployeeType,
... ... @@ -48,6 +48,10 @@ func (svr *UserService) ToUser(from *models.User) *domain.User {
Avatar: from.UserInfo.Avatar,
Phone: from.UserInfo.Phone,
}
if user.EmployeeType == 0 {
user.EmployeeType = 1 //默认正式员工
}
return user
}
func (svr *UserService) ToOrg(from *models.Organization) *domain.Org {
... ...
... ... @@ -88,7 +88,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
log.Logger.Error(err.Error())
continue
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType)
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
// TODO:异常处理
... ... @@ -101,6 +101,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
// 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
// 个人
return nil, nil
}
... ... @@ -118,12 +119,13 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy
UpdatedAt: time.Now(),
Ext: productPlan.Ext,
Version: 1,
ProductRecordInfo: &domain.EmployeeProductRecordInfo{
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId,
ProductRecordInfo: &domain.ProductRecordStaticInfo{
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId,
OtherSectionSecondLevelWeigh: make(map[string]float64),
},
ProductWorker: worker,
}
... ... @@ -207,7 +209,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
if err == domain.ErrorNotFound {
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker)
}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType)
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName)
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
// TODO:异常处理
... ... @@ -217,6 +219,87 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
}
//WorkshopProductStatics 车间产能统计
func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) (interface{}, error) {
func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
var (
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
//productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
employeeProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
)
var (
cid = productRecord.CompanyId
oid = productRecord.OrgId
planId = productRecord.ProductRecordInfo.ProductPlanId
productPlan *domain.ProductPlan
err error
)
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
}
switch productRecord.WorkStation.SectionName {
case ProductSection1:
if productRecord.ProductRecordType == domain.RecordTypeSecondLevelWeigh {
//查询生产记录 批次、生产日期、下(成型)所有二级品
// 更新打料的二级品需要再一次更新成型的二级品
if section, err := FindSectionByName(workshopRepository, productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, ProductSection2); err == nil && section != nil {
nextProductRecord := *productRecord
nextProductRecord.WorkStation.SectionName = ProductSection2
nextProductRecord.WorkStation.SectionId = section.SectionId
ptr.WorkshopProductStatics(&nextProductRecord)
}
}
break
}
var employeeProductRecord *domain.WorkshopProductRecord
employeeProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
employeeProductRecord, err = employeeProductRecordDao.WorkshopProductRecord(cid, oid, planId, productRecord.CreatedAt)
if err == domain.ErrorNotFound {
employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan)
} else {
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 {
// TODO:异常处理
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error()))
}
return nil, nil
}
// newEmployeeProductRecord 员工生产记录
func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *domain.ProductPlan) *domain.WorkshopProductRecord {
record := &domain.WorkshopProductRecord{
CompanyId: productRecord.CompanyId,
OrgId: productRecord.OrgId,
WorkStation: productRecord.WorkStation,
//WorkOn: productPlan.WorkOn,
//ParticipateType: participateType,
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductWeigh: 0,
SecondLevelWeigh: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Ext: productPlan.Ext,
Version: 1,
ProductRecordInfo: &domain.ProductRecordStaticInfo{
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
ProductGroupId: productRecord.ProductRecordInfo.ProductGroupId,
OtherSectionSecondLevelWeigh: make(map[string]float64),
},
}
// 打料、成型有初始值
if productRecord.WorkStation.SectionName == ProductSection1 || productRecord.WorkStation.SectionName == ProductSection2 {
record.ProductWeigh = productPlan.PlanDevoted.Weight
}
return record
}
... ...
package domainService
import (
"errors"
"fmt"
"github.com/hibiken/asynq"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"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"
"time"
)
type PGWorkshopWorkTimeStaticService struct {
transactionContext *pgTransaction.TransactionContext
}
//WorkshopWorkTimeStatic 车间工时统计
func (ptr *PGWorkshopWorkTimeStaticService) WorkshopWorkTimeStatic(productRecord *domain.ProductAttendanceRecord) (interface{}, error) {
workshopWorkTimeRecordRepository, _ := repository.NewWorkshopWorkTimeRecordRepository(ptr.transactionContext)
record, err := workshopWorkTimeRecordRepository.FindOne(map[string]interface{}{
"companyId": productRecord.CompanyId,
"orgId": productRecord.OrgId,
"workStationId": productRecord.WorkStation.WorkStationId,
"recordDate": utils.GetZeroTime(productRecord.SignIn),
})
if err != nil && errors.Is(err, domain.ErrorNotFound) {
err = nil
record = &domain.WorkshopWorkTimeRecord{
WorkStation: productRecord.WorkStation,
CreatedAt: time.Now(),
CompanyId: productRecord.CompanyId,
OrgId: productRecord.OrgId,
Ext: productRecord.Ext,
RecordDate: utils.GetZeroTime(productRecord.SignIn),
WorkshopWorkTimeRecordInfo: &domain.WorkshopWorkTimeRecordInfo{},
}
}
if err != nil {
return nil, err
}
employeeType := productRecord.ProductWorker.EmployeeType
switch employeeType {
case domain.EmployeeFullTime:
record.WorkshopWorkTimeRecordInfo.EFTWorkTime += productRecord.WorkTimeAfter
case domain.EmployeeDispatch:
record.WorkshopWorkTimeRecordInfo.EDWorkTime += productRecord.WorkTimeAfter
case domain.EmployeePartTime:
record.WorkshopWorkTimeRecordInfo.EPTWorkTime += productRecord.WorkTimeAfter
}
if record, err = workshopWorkTimeRecordRepository.Save(record); err != nil {
return nil, err
}
return record, nil
}
func SendWorkshopWorkTimeStaticJob(productRecord *domain.ProductAttendanceRecord) error {
task := asynq.NewTask(domain.TaskKeyWorkshopWorkTimeRecordStatics(), []byte(json.MarshalToString(productRecord)))
client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
_, err := client.Enqueue(task)
return err
}
func NewPGWorkshopWorkTimeStaticService(transactionContext *pgTransaction.TransactionContext) (*PGWorkshopWorkTimeStaticService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PGWorkshopWorkTimeStaticService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -40,6 +40,8 @@ func init() {
(*models.MaterialGroupK3cloud)(nil),
(*models.PrdMoK3cloud)(nil),
(*models.EmployeeProductRecord)(nil),
(*models.WorkshopProductRecord)(nil),
(*models.WorkshopWorkTimeRecord)(nil),
} {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -34,7 +34,7 @@ type EmployeeProductRecord struct {
// 版本号
Version int `comment:"版本号"`
// 生产记录信息
ProductRecordInfo *domain.EmployeeProductRecordInfo `comment:"生产记录信息"`
ProductRecordInfo *domain.ProductRecordStaticInfo `comment:"生产记录信息"`
// 生产工人
ProductWorker *domain.User `comment:"生产工人"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"time"
)
type WorkshopProductRecord struct {
tableName string `comment:"员工生产记录" pg:"manufacture.workshop_product_record"`
// 车间生产记录ID
WorkshopProductRecordId int `comment:"车间生产记录ID" pg:"pk:workshop_product_record_id"`
// 企业id
CompanyId int `comment:"企业id"`
// 组织ID
OrgId int `comment:"组织ID"`
// 工作位置
WorkStation *domain.WorkStation `comment:"工作位置"`
// 生产日期
ProductDate string `comment:"生产日期"`
// 产能
ProductWeigh float64 `comment:"产能"`
// 二级品产能
SecondLevelWeigh float64 `comment:"二级品产能"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 扩展
Ext *domain.Ext `comment:"扩展"`
// 版本号
Version int `comment:"版本号"`
// 生产记录信息
ProductRecordInfo *domain.ProductRecordStaticInfo `comment:"生产记录信息"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"time"
)
type WorkshopWorkTimeRecord struct {
tableName string `comment:"车间工时记录" pg:"manufacture.workshop_work_time_record"`
// 车间工时记录ID
WorkshopWorkTimeRecordId int `comment:"车间工时记录ID" pg:"pk:workshop_work_time_record_id"`
// 工作位置
WorkStation *domain.WorkStation `comment:"工作位置"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 企业id
CompanyId int `comment:"企业id"`
// 组织ID
OrgId int `comment:"组织ID"`
// 记录信息
WorkshopWorkTimeRecordInfo *domain.WorkshopWorkTimeRecordInfo `comment:"记录信息"`
// 扩展数据
Ext *domain.Ext `comment:"扩展数据"`
// 记录日期
RecordDate time.Time `comment:"记录日期"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
)
func TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel *models.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
return &domain.WorkshopProductRecord{
WorkshopProductRecordId: workshopProductRecordModel.WorkshopProductRecordId,
CompanyId: workshopProductRecordModel.CompanyId,
OrgId: workshopProductRecordModel.OrgId,
WorkStation: workshopProductRecordModel.WorkStation,
ProductDate: workshopProductRecordModel.ProductDate,
ProductWeigh: workshopProductRecordModel.ProductWeigh,
SecondLevelWeigh: workshopProductRecordModel.SecondLevelWeigh,
CreatedAt: workshopProductRecordModel.CreatedAt,
UpdatedAt: workshopProductRecordModel.UpdatedAt,
DeletedAt: workshopProductRecordModel.DeletedAt,
Ext: workshopProductRecordModel.Ext,
Version: workshopProductRecordModel.Version,
ProductRecordInfo: workshopProductRecordModel.ProductRecordInfo,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
)
func TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel *models.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
return &domain.WorkshopWorkTimeRecord{
WorkshopWorkTimeRecordId: workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId,
WorkStation: workshopWorkTimeRecordModel.WorkStation,
CreatedAt: workshopWorkTimeRecordModel.CreatedAt,
CompanyId: workshopWorkTimeRecordModel.CompanyId,
OrgId: workshopWorkTimeRecordModel.OrgId,
WorkshopWorkTimeRecordInfo: workshopWorkTimeRecordModel.WorkshopWorkTimeRecordInfo,
Ext: workshopWorkTimeRecordModel.Ext,
RecordDate: workshopWorkTimeRecordModel.RecordDate,
}, 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"
... ... @@ -165,7 +166,7 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
query := sqlbuilder.BuildQuery(tx.Model(&productAttendanceRecordModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("attendance_status = ?", "attendanceStatus")
query.SetWhereByQueryOption("attendance_status & ? >0", "attendanceStatus")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
... ... @@ -175,6 +176,18 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
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["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("created_at>=?", v.(time.Time))
}
if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("created_at<?", v.(time.Time))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"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"
)
type WorkshopProductRecordRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *WorkshopProductRecordRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *WorkshopProductRecordRepository) Save(workshopProductRecord *domain.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
sqlBuildFields := []string{
"workshop_product_record_id",
"company_id",
"org_id",
"work_station",
"product_date",
"product_weigh",
"second_level_weigh",
"created_at",
"updated_at",
"deleted_at",
"ext",
"version",
"product_record_info",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_product_record_id", "deleted_at")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if workshopProductRecord.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(
&workshopProductRecord.WorkshopProductRecordId,
&workshopProductRecord.CompanyId,
&workshopProductRecord.OrgId,
&workshopProductRecord.WorkStation,
&workshopProductRecord.ProductDate,
&workshopProductRecord.ProductWeigh,
&workshopProductRecord.SecondLevelWeigh,
&workshopProductRecord.CreatedAt,
&workshopProductRecord.UpdatedAt,
&workshopProductRecord.DeletedAt,
&workshopProductRecord.Ext,
&workshopProductRecord.Version,
&workshopProductRecord.ProductRecordInfo,
),
fmt.Sprintf("INSERT INTO manufacture.workshop_product_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
workshopProductRecord.CompanyId,
workshopProductRecord.OrgId,
workshopProductRecord.WorkStation,
workshopProductRecord.ProductDate,
workshopProductRecord.ProductWeigh,
workshopProductRecord.SecondLevelWeigh,
workshopProductRecord.CreatedAt,
workshopProductRecord.UpdatedAt,
workshopProductRecord.Ext,
workshopProductRecord.Version,
workshopProductRecord.ProductRecordInfo,
); err != nil {
return workshopProductRecord, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&workshopProductRecord.WorkshopProductRecordId,
&workshopProductRecord.CompanyId,
&workshopProductRecord.OrgId,
&workshopProductRecord.WorkStation,
&workshopProductRecord.ProductDate,
&workshopProductRecord.ProductWeigh,
&workshopProductRecord.SecondLevelWeigh,
&workshopProductRecord.CreatedAt,
&workshopProductRecord.UpdatedAt,
&workshopProductRecord.DeletedAt,
&workshopProductRecord.Ext,
&workshopProductRecord.Version,
&workshopProductRecord.ProductRecordInfo,
),
fmt.Sprintf("UPDATE manufacture.workshop_product_record SET %s WHERE workshop_product_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
workshopProductRecord.CompanyId,
workshopProductRecord.OrgId,
workshopProductRecord.WorkStation,
workshopProductRecord.ProductDate,
workshopProductRecord.ProductWeigh,
workshopProductRecord.SecondLevelWeigh,
workshopProductRecord.CreatedAt,
workshopProductRecord.UpdatedAt,
workshopProductRecord.Ext,
workshopProductRecord.Version,
workshopProductRecord.ProductRecordInfo,
workshopProductRecord.Identify(),
); err != nil {
return workshopProductRecord, err
}
}
return workshopProductRecord, nil
}
func (repository *WorkshopProductRecordRepository) Remove(workshopProductRecord *domain.WorkshopProductRecord) (*domain.WorkshopProductRecord, error) {
tx := repository.transactionContext.PgTx
workshopProductRecordModel := new(models.WorkshopProductRecord)
workshopProductRecordModel.WorkshopProductRecordId = workshopProductRecord.Identify().(int)
if _, err := tx.Model(workshopProductRecordModel).WherePK().Delete(); err != nil {
return workshopProductRecord, err
}
return workshopProductRecord, nil
}
func (repository *WorkshopProductRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.WorkshopProductRecord, error) {
tx := repository.transactionContext.PgTx
workshopProductRecordModel := new(models.WorkshopProductRecord)
query := sqlbuilder.BuildQuery(tx.Model(workshopProductRecordModel), queryOptions)
query.SetWhereByQueryOption("workshop_product_record.workshop_product_record_id = ?", "workshopProductRecordId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if workshopProductRecordModel.WorkshopProductRecordId == 0 {
return nil, nil
} else {
return transform.TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel)
}
}
func (repository *WorkshopProductRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.WorkshopProductRecord, error) {
tx := repository.transactionContext.PgTx
var workshopProductRecordModels []*models.WorkshopProductRecord
workshopProductRecords := make([]*domain.WorkshopProductRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&workshopProductRecordModels), queryOptions)
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("workshop_product_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, workshopProductRecords, err
} else {
for _, workshopProductRecordModel := range workshopProductRecordModels {
if workshopProductRecord, err := transform.TransformToWorkshopProductRecordDomainModelFromPgModels(workshopProductRecordModel); err != nil {
return 0, workshopProductRecords, err
} else {
workshopProductRecords = append(workshopProductRecords, workshopProductRecord)
}
}
return int64(count), workshopProductRecords, nil
}
}
func NewWorkshopProductRecordRepository(transactionContext *pgTransaction.TransactionContext) (*WorkshopProductRecordRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &WorkshopProductRecordRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"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"
)
type WorkshopWorkTimeRecordRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *WorkshopWorkTimeRecordRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *WorkshopWorkTimeRecordRepository) Save(workshopWorkTimeRecord *domain.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
sqlBuildFields := []string{
"workshop_work_time_record_id",
"work_station",
"created_at",
"company_id",
"org_id",
"workshop_work_time_record_info",
"ext",
"record_date",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id"))
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id"))
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "workshop_work_time_record_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if workshopWorkTimeRecord.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(
&workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
&workshopWorkTimeRecord.WorkStation,
&workshopWorkTimeRecord.CreatedAt,
&workshopWorkTimeRecord.CompanyId,
&workshopWorkTimeRecord.OrgId,
&workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
&workshopWorkTimeRecord.Ext,
&workshopWorkTimeRecord.RecordDate,
),
fmt.Sprintf("INSERT INTO manufacture.workshop_work_time_record (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
//workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
workshopWorkTimeRecord.WorkStation,
workshopWorkTimeRecord.CreatedAt,
workshopWorkTimeRecord.CompanyId,
workshopWorkTimeRecord.OrgId,
workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
workshopWorkTimeRecord.Ext,
workshopWorkTimeRecord.RecordDate,
); err != nil {
return workshopWorkTimeRecord, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
&workshopWorkTimeRecord.WorkStation,
&workshopWorkTimeRecord.CreatedAt,
&workshopWorkTimeRecord.CompanyId,
&workshopWorkTimeRecord.OrgId,
&workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
&workshopWorkTimeRecord.Ext,
&workshopWorkTimeRecord.RecordDate,
),
fmt.Sprintf("UPDATE manufacture.workshop_work_time_record SET %s WHERE workshop_work_time_record_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
//workshopWorkTimeRecord.WorkshopWorkTimeRecordId,
workshopWorkTimeRecord.WorkStation,
workshopWorkTimeRecord.CreatedAt,
workshopWorkTimeRecord.CompanyId,
workshopWorkTimeRecord.OrgId,
workshopWorkTimeRecord.WorkshopWorkTimeRecordInfo,
workshopWorkTimeRecord.Ext,
workshopWorkTimeRecord.RecordDate,
workshopWorkTimeRecord.Identify(),
); err != nil {
return workshopWorkTimeRecord, err
}
}
return workshopWorkTimeRecord, nil
}
func (repository *WorkshopWorkTimeRecordRepository) Remove(workshopWorkTimeRecord *domain.WorkshopWorkTimeRecord) (*domain.WorkshopWorkTimeRecord, error) {
tx := repository.transactionContext.PgTx
workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord)
workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId = workshopWorkTimeRecord.Identify().(int)
if _, err := tx.Model(workshopWorkTimeRecordModel).WherePK().Delete(); err != nil {
return workshopWorkTimeRecord, err
}
return workshopWorkTimeRecord, nil
}
func (repository *WorkshopWorkTimeRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.WorkshopWorkTimeRecord, error) {
tx := repository.transactionContext.PgTx
workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord)
query := sqlbuilder.BuildQuery(tx.Model(workshopWorkTimeRecordModel), queryOptions)
query.SetWhereByQueryOption("workshop_work_time_record.workshop_work_time_record_id = ?", "workshopWorkTimeRecordId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
} else {
return nil, err
}
}
if workshopWorkTimeRecordModel.WorkshopWorkTimeRecordId == 0 {
return nil, nil
} else {
return transform.TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel)
}
}
func (repository *WorkshopWorkTimeRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.WorkshopWorkTimeRecord, error) {
tx := repository.transactionContext.PgTx
var workshopWorkTimeRecordModels []*models.WorkshopWorkTimeRecord
workshopWorkTimeRecords := make([]*domain.WorkshopWorkTimeRecord, 0)
query := sqlbuilder.BuildQuery(tx.Model(&workshopWorkTimeRecordModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
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["signBeginTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("record_date>=?", v.(time.Time))
}
if v, ok := queryOptions["signEndTime"]; ok && !((v.(time.Time)).IsZero()) {
query.Where("record_date<?", v.(time.Time))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("record_date", "DESC")
query.SetOrderDirect("workshop_work_time_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, workshopWorkTimeRecords, err
} else {
for _, workshopWorkTimeRecordModel := range workshopWorkTimeRecordModels {
if workshopWorkTimeRecord, err := transform.TransformToWorkshopWorkTimeRecordDomainModelFromPgModels(workshopWorkTimeRecordModel); err != nil {
return 0, workshopWorkTimeRecords, err
} else {
workshopWorkTimeRecords = append(workshopWorkTimeRecords, workshopWorkTimeRecord)
}
}
return int64(count), workshopWorkTimeRecords, nil
}
}
func NewWorkshopWorkTimeRecordRepository(transactionContext *pgTransaction.TransactionContext) (*WorkshopWorkTimeRecordRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &WorkshopWorkTimeRecordRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package utils
import (
"strconv"
"time"
)
func GetDayBegin() time.Time {
t := time.Now()
today, _ := time.Parse("2006-01-02", t.Format("2006-01-02"))
return today
}
func GetDayEnd() time.Time {
t := GetDayBegin()
nextDay := t.AddDate(0, 0, 1)
return nextDay
}
// GetFirstDateOfMonth 获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
func GetFirstDateOfMonth(d time.Time) time.Time {
d = d.AddDate(0, 0, -d.Day()+1)
return GetZeroTime(d)
}
// GetNextMonthFirstDay 获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
func GetNextMonthFirstDay(d time.Time) time.Time {
d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
return GetZeroTime(d)
}
// GetZeroTime 获取某一天的0点时间
func GetZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
}
// GetNextDayZeroTime 获取某一天的23点59分59秒
func GetNextDayZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
}
// TransformTimestampToTime 根据13位时间戳返回日期时间格式时间
func TransformTimestampToTime(timeStamp int64) time.Time {
t := strconv.FormatInt(timeStamp, 10)
tIpartStr := t[0:10]
//tDecpartStr := t[10:13]
ipart, _ := strconv.ParseInt(tIpartStr, 10, 64)
//decpart, _ := strconv.ParseInt(tDecpartStr, 10, 64)
myTime := time.Unix(ipart, 0)
//(myTime)
return time.Date(myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second(), 0, time.Local)
}
... ...
... ... @@ -78,3 +78,27 @@ func (controller *AttendanceController) SearchAttendance() {
total, data, err := attendanceService.SearchAttendance(operateInfo, cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *AttendanceController) SearchEmployeeAttendanceStatics() {
attendanceService := service.NewAttendanceService(nil)
cmd := &query.SearchEmployeeAttendanceQuery{}
controller.Unmarshal(cmd)
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := attendanceService.SearchEmployeeAttendanceStatics(operateInfo, cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *AttendanceController) SearchWorkshopWorkTimeStatics() {
attendanceService := service.NewAttendanceService(nil)
cmd := &query.SearchEmployeeAttendanceQuery{}
controller.Unmarshal(cmd)
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := attendanceService.SearchWorkshopWorkTimeStatics(operateInfo, cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -90,3 +90,15 @@ func (controller *ProductRecordController) SearchEmployeeProductRecord() {
total, data, err := productPlanService.SearchEmployeeProductRecord(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *ProductRecordController) SearchWorkshopProductRecord() {
productPlanService := service.NewProductRecordService(nil)
cmd := &query.SearchWorkshopProductRecordQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := productPlanService.SearchWorkshopProductRecord(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
... ...
... ... @@ -13,4 +13,6 @@ func init() {
web.Router("/attendances/", &controllers.AttendanceController{}, "Get:ListAttendance")
web.Router("/attendances/approve", &controllers.AttendanceController{}, "Post:ApproveAttendance")
web.Router("/attendances/search", &controllers.AttendanceController{}, "Post:SearchAttendance")
web.Router("/attendances/employee-attendance-statics/search", &controllers.AttendanceController{}, "Post:SearchEmployeeAttendanceStatics")
web.Router("/attendances/workshop-attendance-statics/search", &controllers.AttendanceController{}, "Post:SearchWorkshopWorkTimeStatics")
}
... ...
... ... @@ -14,4 +14,5 @@ func init() {
web.Router("/product-records/approve", &controllers.ProductRecordController{}, "Post:ApproveProductRecord")
web.Router("/product-records/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")
}
... ...
... ... @@ -23,7 +23,7 @@ func Run() {
h := asynq.NewServeMux()
// ... Register handlers
h.HandleFunc(domain.TaskKeyPatternProductRecordStatics(), HandlerProductRecordStatics)
h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics)
log.Logger.Info("aysnq task running ...")
// Run blocks and waits for os signal to terminate the program.
if err := srv.Run(h); err != nil {
... ...
package task
import (
"context"
"encoding/json"
"fmt"
"github.com/hibiken/asynq"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/attendance/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
)
// 生产工时记录统计
func WorkshopWorkTimeRecordStatics(c context.Context, t *asynq.Task) error {
svr := service.NewAttendanceService(nil)
cmd := &command.WorkshopWorkTimeRecordStaticsCommand{}
if err := json.Unmarshal(t.Payload(), cmd); err != nil {
return err
}
log.Logger.Debug(fmt.Sprintf("【考勤记录统计】 消费 记录ID:%v 时间:%v", cmd.ProductAttendanceId, cmd.WorkTimeBefore))
_, err := svr.WorkshopWorkTimeRecordStatics(cmd)
if err != nil {
log.Logger.Error(err.Error())
}
return nil
}
... ...