...
|
...
|
@@ -2,6 +2,7 @@ package domainService |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/mohae/deepcopy"
|
|
|
"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/repository"
|
...
|
...
|
@@ -24,10 +25,10 @@ const ( |
|
|
func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
|
|
|
|
|
|
var (
|
|
|
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
|
|
|
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
|
|
|
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
|
|
|
employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
|
|
|
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
|
|
|
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
|
|
|
productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
|
|
|
//employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
|
|
|
)
|
|
|
|
|
|
var (
|
...
|
...
|
@@ -44,10 +45,13 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. |
|
|
//查询生产记录 批次、生产日期、下(成型)所有二级品
|
|
|
// 更新打料的二级品需要再一次更新成型的二级品
|
|
|
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.EmployeeProductStatics(&nextProductRecord)
|
|
|
if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok {
|
|
|
nextProductRecord.WorkStation.SectionName = ProductSection2
|
|
|
nextProductRecord.WorkStation.SectionId = section.SectionId
|
|
|
nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId)
|
|
|
nextProductRecord.PreRecord = productRecord
|
|
|
ptr.EmployeeProductStatics(nextProductRecord)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
break
|
...
|
...
|
@@ -56,7 +60,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. |
|
|
case ProductSection3:
|
|
|
break
|
|
|
case ProductSection4: //个人特殊处理
|
|
|
return ptr.personalProductStatics(productRecord)
|
|
|
return ptr.personalProductStatics(nil, nil, nil, productRecord)
|
|
|
default:
|
|
|
return nil, nil //ptr.personalProductStatics(productRecord)
|
|
|
}
|
...
|
...
|
@@ -64,72 +68,34 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain. |
|
|
log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId))
|
|
|
return nil, nil
|
|
|
}
|
|
|
// 2.0 查找批次
|
|
|
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
|
|
|
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
|
|
|
|
|
|
// 集体
|
|
|
// 1.查询员工 -》 员工打卡记录 工位+打卡日期
|
|
|
// 2.打卡记录的时间区间 在生产记录上报的时间范围内
|
|
|
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext)
|
|
|
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, time.Now()) //, productRecord.CreatedAt
|
|
|
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, productRecord.CreatedAt) //, productRecord.CreatedAt
|
|
|
if err != nil || len(attendanceRecords) == 0 {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
|
|
|
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
|
|
|
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
|
|
|
for i := 0; i < len(attendanceRecords); i++ {
|
|
|
r := attendanceRecords[i]
|
|
|
participateType := domain.ParticipateNormal
|
|
|
if _, ok := groupMembers[groupMembersKeyFunc(r.ProductWorker.UserId)]; !ok {
|
|
|
participateType = domain.ParticipateSupport
|
|
|
}
|
|
|
|
|
|
var employeeProductRecord *domain.EmployeeProductRecord
|
|
|
employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, r.ProductWorker.UserId, productRecord.CreatedAt)
|
|
|
if err == domain.ErrorNotFound {
|
|
|
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, r.ProductWorker)
|
|
|
} else {
|
|
|
if err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询当前员工 昨日产能 、历史最好产能
|
|
|
var (
|
|
|
yesterdayOutputWeight float64 = 0
|
|
|
bestOutputWeight float64 = 0
|
|
|
)
|
|
|
if employeeProductRecord.ProductRecordInfo.BestOutputWeight > 0 {
|
|
|
if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, r.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
|
|
|
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
|
|
|
bestOutputWeight = record.ProductRecordInfo.BestOutputWeight
|
|
|
|
|
|
} else {
|
|
|
if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, r.ProductWorker.UserId); e == nil && record != nil {
|
|
|
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
|
|
|
|
|
|
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
|
|
|
// TODO:异常处理
|
|
|
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 员工:[%v] 处理异常:%v", productRecord.ProductRecordId, r.ProductWorker.UserId, err.Error()))
|
|
|
continue
|
|
|
productRecord.ProductWorker = r.ProductWorker
|
|
|
// 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据)
|
|
|
// 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
|
|
|
// 个人
|
|
|
if _, err := ptr.personalProductStatics(productPlan, groupMembers, groupMembersKeyFunc, productRecord); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
// 3.查询员工产能记录 -》员工 批次+工位+批次生产日期 (有 更新产能数据、没有插入一条产能数据)
|
|
|
|
|
|
// 4.更新产能 (产能、二级品) (特殊工段处理 打料、成型)
|
|
|
|
|
|
// 个人
|
|
|
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -208,7 +174,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp |
|
|
}
|
|
|
|
|
|
// 个人生产记录统计
|
|
|
func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
|
|
|
func (ptr *PGProductRecordService) personalProductStatics(productPlan *domain.ProductPlan, groupMembers map[string]*domain.User, groupMembersKeyFunc func(int) string, productRecord *domain.ProductRecord) (interface{}, error) {
|
|
|
var (
|
|
|
//workshopRepository,_=repository.NewWorkshopRepository(ptr.transactionContext)
|
|
|
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
|
...
|
...
|
@@ -216,29 +182,37 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. |
|
|
employeeProductRecordRepository, _ = repository.NewEmployeeProductRecordRepository(ptr.transactionContext)
|
|
|
)
|
|
|
var (
|
|
|
cid = productRecord.CompanyId
|
|
|
oid = productRecord.OrgId
|
|
|
planId = productRecord.ProductRecordInfo.ProductPlanId
|
|
|
productPlan *domain.ProductPlan
|
|
|
err error
|
|
|
cid = productRecord.CompanyId
|
|
|
oid = productRecord.OrgId
|
|
|
planId = productRecord.ProductRecordInfo.ProductPlanId
|
|
|
//productPlan *domain.ProductPlan
|
|
|
err error
|
|
|
)
|
|
|
// 2.1 判断是否是支援类型 有打卡记录,员工是否是属于该工段的员工
|
|
|
groupMembers, groupMembersKeyFunc := FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
|
|
|
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
|
|
|
|
|
|
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
if groupMembers == nil {
|
|
|
groupMembers, groupMembersKeyFunc = FindGroupMembers(productGroupRepository, cid, oid, productRecord.WorkStation.WorkStationId)
|
|
|
}
|
|
|
if productPlan == nil {
|
|
|
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
workStationId := productRecord.WorkStation.WorkStationId
|
|
|
|
|
|
employeeProductRecordDao, _ := dao.NewEmployeeProductRecordDao(ptr.transactionContext)
|
|
|
|
|
|
participateType := domain.ParticipateNormal
|
|
|
if _, ok := groupMembers[groupMembersKeyFunc(productRecord.ProductWorker.UserId)]; !ok {
|
|
|
participateType = domain.ParticipateSupport
|
|
|
}
|
|
|
var employeeProductRecord *domain.EmployeeProductRecord
|
|
|
employeeProductRecord, err = employeeProductRecordDao.WorkerProductRecord(cid, oid, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt)
|
|
|
employeeProductRecord, err = employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, productRecord.ProductRecordInfo.ProductPlanId, productRecord.ProductWorker.UserId, productRecord.CreatedAt)
|
|
|
if err == domain.ErrorNotFound {
|
|
|
employeeProductRecord = newEmployeeProductRecord(productRecord, participateType, productPlan, productRecord.ProductWorker)
|
|
|
err = nil
|
|
|
} else if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 查询当前员工 昨日产能 、历史最好产能
|
...
|
...
|
@@ -247,9 +221,9 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. |
|
|
bestOutputWeight float64 = 0
|
|
|
)
|
|
|
if employeeProductRecord.ProductRecordInfo.BestOutputWeight == 0 {
|
|
|
if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
|
|
|
if record, e := employeeProductRecordDao.WorkerWorkStationProductRecord(cid, oid, workStationId, planId, productRecord.ProductWorker.UserId, productRecord.CreatedAt.AddDate(0, 0, -1)); e == nil && record != nil {
|
|
|
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
|
|
|
bestOutputWeight = record.ProductRecordInfo.BestOutputWeight
|
|
|
bestOutputWeight = record.ProductRecordInfo.GetBestOutputWeight()
|
|
|
|
|
|
} else {
|
|
|
if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil {
|
...
|
...
|
@@ -258,7 +232,7 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain. |
|
|
}
|
|
|
}
|
|
|
|
|
|
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
|
|
|
employeeProductRecord.UpdateProductWeigh(productRecord, yesterdayOutputWeight, bestOutputWeight)
|
|
|
|
|
|
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
|
|
|
// TODO:异常处理
|
...
|
...
|
@@ -273,7 +247,7 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. |
|
|
workshopRepository, _ = repository.NewWorkshopRepository(ptr.transactionContext)
|
|
|
productPlanRepository, _ = repository.NewProductPlanRepository(ptr.transactionContext)
|
|
|
//productGroupRepository, _ = repository.NewProductGroupRepository(ptr.transactionContext)
|
|
|
employeeProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
|
|
|
workshopProductRecordRepository, _ = repository.NewWorkshopProductRecordRepository(ptr.transactionContext)
|
|
|
)
|
|
|
|
|
|
var (
|
...
|
...
|
@@ -298,29 +272,36 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain. |
|
|
//查询生产记录 批次、生产日期、下(成型)所有二级品
|
|
|
// 更新打料的二级品需要再一次更新成型的二级品
|
|
|
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)
|
|
|
if nextProductRecord, ok := deepcopy.Copy(productRecord).(*domain.ProductRecord); ok {
|
|
|
nextProductRecord.WorkStation.SectionName = ProductSection2
|
|
|
nextProductRecord.WorkStation.SectionId = section.SectionId
|
|
|
nextProductRecord.WorkStation.WorkStationId = domain.WorkstationKey(productRecord.WorkStation.WorkshopId, productRecord.WorkStation.LineId, section.SectionId)
|
|
|
nextProductRecord.PreRecord = productRecord
|
|
|
ptr.WorkshopProductStatics(nextProductRecord)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
|
|
|
var employeeProductRecord *domain.WorkshopProductRecord
|
|
|
employeeProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
|
|
|
employeeProductRecord, err = employeeProductRecordDao.WorkshopProductRecord(cid, oid, planId, productRecord.CreatedAt)
|
|
|
var workshopProductRecord *domain.WorkshopProductRecord
|
|
|
workshopProductRecordDao, _ := dao.NewWorkshopProductRecordDao(ptr.transactionContext)
|
|
|
workshopProductRecord, err = workshopProductRecordDao.WorkshopProductRecord(cid, oid, productRecord.WorkStation.WorkStationId, planId, productRecord.CreatedAt)
|
|
|
if err == domain.ErrorNotFound {
|
|
|
employeeProductRecord = newWorkshopProductRecord(productRecord, productPlan)
|
|
|
workshopProductRecord = 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)
|
|
|
workshopProductRecord.UpdateProductWeigh(productRecord)
|
|
|
// 打料 跟 成型工段的初始产能是批次的产能
|
|
|
if productRecord.WorkStation.SectionName == ProductSection1 && productRecord.WorkStation.SectionName == ProductSection2 {
|
|
|
workshopProductRecord.AddPlanProductWeight(productPlan.PlanDevoted.Weight, productPlan.ProductPlanId)
|
|
|
}
|
|
|
|
|
|
if employeeProductRecord, err = employeeProductRecordRepository.Save(employeeProductRecord); err != nil {
|
|
|
if workshopProductRecord, err = workshopProductRecordRepository.Save(workshopProductRecord); err != nil {
|
|
|
// TODO:异常处理
|
|
|
log.Logger.Error(fmt.Sprintf("生产记录:[%v] 处理异常:%v", productRecord.ProductRecordId, err.Error()))
|
|
|
}
|
...
|
...
|
|