作者 yangfu

fix:1.车间数据消费修改

... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
... ... @@ -46,13 +47,13 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
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.SignIn = m.SignIn.Local().Format("15:04:05")
d.SignDate = m.SignIn.Local().Format("2006-01-02")
}
if !m.SignOut.IsZero() {
d.SignOut = m.SignOut.Format("15:04:05")
d.SignOut = m.SignOut.Local().Format("15:04:05")
}
d.WorkTimeBefore = m.WorkTimeBefore
d.WorkTimeBefore = utils.Round(m.WorkTimeBefore, 1)
d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
... ... @@ -69,7 +70,7 @@ func (d *AttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord, orgId i
}
if m.Ext.AttendanceExt.ApproveAt > 0 {
t := time.Unix(m.Ext.AttendanceExt.ApproveAt, 0)
d.ApproveAt = t.Format("2006-01-02 15:04:05")
d.ApproveAt = t.Local().Format("2006-01-02 15:04:05")
}
}
}
... ...
... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type EmployeeAttendanceRecordDto struct {
... ... @@ -39,9 +40,9 @@ func (d *EmployeeAttendanceRecordDto) LoadDto(m *domain.ProductAttendanceRecord,
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.SignDate = m.SignIn.Local().Format("2006-01-02")
}
d.WorkTime = m.WorkTimeAfter
d.WorkTime = utils.Round(m.WorkTimeAfter, 1)
//d.WorkTimeAfter = m.WorkTimeAfter
d.AttendanceStatus = m.AttendanceStatus
d.AttendanceTypeDescription = domain.ParticipateTypeDescription(m.AttendanceType)
... ...
... ... @@ -2,6 +2,7 @@ package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type WorkshopWorkTimeRecordDto struct {
... ... @@ -24,9 +25,13 @@ type WorkshopWorkTimeRecordDto struct {
func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, orgId int) *WorkshopWorkTimeRecordDto {
d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId
d.WorkStation = m.WorkStation
d.WorkshopWorkTimeRecordInfo = m.WorkshopWorkTimeRecordInfo
if m.WorkshopWorkTimeRecordInfo != nil {
d.WorkshopWorkTimeRecordInfo.EPTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EPTWorkTime, 1)
d.WorkshopWorkTimeRecordInfo.EDWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EDWorkTime, 1)
d.WorkshopWorkTimeRecordInfo.EFTWorkTime = utils.Round(m.WorkshopWorkTimeRecordInfo.EFTWorkTime, 1)
}
d.WorkStation = m.WorkStation
d.RecordDate = m.RecordDate.Format("2006-01-02")
d.RecordDate = m.RecordDate.Local().Format("2006-01-02")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -71,7 +71,7 @@ func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
}
}
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceRecord) {
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) {
var mapUser = make(map[int]int)
for _, v := range list {
item := &ProductGroupEmployeesDto{}
... ... @@ -79,6 +79,11 @@ func (d *ProductGroupEmployeesDtos) LoadDtoV2(list ...*domain.ProductAttendanceR
item.UserName = v.ProductWorker.UserName
item.ProductGroupId = 0
item.GroupName = ""
if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok {
item.GroupName = v.GroupName
item.ProductGroupId = v.GroupId
item.WorkOnDescription = domain.WorkOnDescriptions(v.WorkOn)
}
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
... ...
... ... @@ -444,8 +444,11 @@ func (productGroupService *ProductGroupService) SearchProductGroupEmployeesV2(op
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0)
mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, domain.WorkstationKey(cmd.WorkshopId, cmd.LineId, cmd.SectionId))
var results = dto.NewProductGroupEmployeesDtos()
results.LoadDtoV2(productGroups...)
results.LoadDtoV2(productGroups, mapUser, keyFunc)
sort.Stable(results)
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -477,12 +480,23 @@ func (productGroupService *ProductGroupService) GetSignEmployee(cmd *query.GetSi
if err != nil || worker == nil || worker.UserId == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户不存在")
}
result := map[string]interface{}{
"userId": worker.UserId,
"userName": worker.UserName,
}
productGroupRepository, _, _ := factory.FastPgProductGroup(transactionContext, 0)
mapUser, keyFunc := domainService.FindGroupMembers(productGroupRepository, cmd.CompanyId, cmd.OrgId, "")
if v, ok := mapUser[keyFunc(worker.UserId)]; ok {
result["productGroupId"] = v.GroupId
result["groupName"] = v.GroupName
result["workOn"] = domain.WorkOnDescriptions(v.WorkOn)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"employee": worker,
"employee": result,
}, nil
}
... ...
... ... @@ -42,7 +42,7 @@ type ProductPlanDispatchRecordDto struct {
func (d *ProductPlanDispatchRecordDto) LoadDto(m *domain.ProductPlanDispatchRecord, orgId int) *ProductPlanDispatchRecordDto {
d.ProductPlanId = m.ProductPlanDispatchRecordId
d.BatchNumber = m.BatchNumber
d.ProductDate = m.ProductDate.Format("2006/01/02")
d.ProductDate = m.ProductDate.Local().Format("2006-01-02")
d.WorkStation = m.WorkStation
d.WorkOn = m.PlanDispatchRecordExt.WorkOn
d.PlanProductName = m.PlanDispatchRecordExt.PlanProductName
... ...
... ... @@ -47,13 +47,13 @@ func (d *ProductLevelTwoRecord) LoadDto(m *domain.ProductRecord, orgId int) *Pro
d.WeighAfter = m.ProductRecordInfo.WeighAfter
d.ApproveStatus = m.ProductRecordInfo.ApproveStatus
if m.ProductRecordInfo.ApproveAt > 0 {
d.ApproveAt = time.Unix(m.ProductRecordInfo.ApproveAt, 0).Format("2006-01-02 15:04:05")
d.ApproveAt = time.Unix(m.ProductRecordInfo.ApproveAt, 0).Local().Format("2006-01-02 15:04:05")
d.ApproveUser = m.ProductRecordInfo.ApproveUser
}
d.PlanProductName = m.ProductRecordInfo.PlanProductName
d.BatchNumber = m.ProductRecordInfo.BatchNumber
d.CreatedDate = m.CreatedAt.Format("2006-01-02")
d.CreatedAt = m.CreatedAt.Format("2006-01-02 15:04:05")
d.CreatedDate = m.CreatedAt.Local().Format("2006-01-02")
d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05")
d.AuthFlag = domain.CheckOrgAuth(orgId, m.OrgId)
if m.Ext != nil {
d.OrgName = m.Ext.OrgName
... ...
... ... @@ -171,7 +171,13 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
off := make([][]int, 0)
err := make([][]int, 0)
var begin, end int = 0, 0
var status = 1 // 1.故障:1 0 \ 0 0 2.正常:1 1 3.停机:0 1
/*
1.故障: 1 0 \ 0 0
2.正常: 1 1
3.停机:0 1
*/
var status = 1
// 添加数据
addToStatus := func(s []int, status int) {
switch status {
case 1:
... ... @@ -185,6 +191,7 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
break
}
}
// 计算当前状态
computeStatus := func(up, com int, index int) int {
var val = 0
if up&index > 0 {
... ... @@ -199,6 +206,9 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
if val == 3 {
return 2 //正常
}
if val == 2 {
return 3 //停机
}
return 3 // 停机
}
... ... @@ -223,7 +233,6 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
curStatus := computeStatus(hds.Up, hds.Com, index)
if curStatus == status {
end += 1
//continue
} else {
addToStatus([]int{begin, end}, status)
status = curStatus
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"errors"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"time"
)
... ... @@ -74,7 +75,7 @@ func (productAttendanceRecord *ProductAttendanceRecord) ComputeWorkTimeBefore()
if !productAttendanceRecord.SignOut.After(productAttendanceRecord.SignIn) {
return 0
}
return productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours()
return utils.Round(productAttendanceRecord.SignOut.Sub(productAttendanceRecord.SignIn).Hours(), 1)
}
func (productAttendanceRecord *ProductAttendanceRecord) Approve(approveUser *User, workTimeAfter float64, status int) error {
... ...
... ... @@ -24,4 +24,5 @@ type User struct {
// 额外扩展的参数
GroupId int `json:"-"`
GroupName string `json:"-"`
WorkOn int `json:"-"`
}
... ...
... ... @@ -33,7 +33,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation
//Principal: w.Principal,
}
if w != nil && l != nil && s != nil {
item.WorkStationId = fmt.Sprintf("%v.%v.%v", w.WorkshopId, l.LineId, s.SectionId)
item.WorkStationId = WorkstationKey(w.WorkshopId, l.LineId, s.SectionId)
}
if w != nil {
item.WorkshopId = w.WorkshopId
... ... @@ -49,3 +49,7 @@ func NewWorkStation(w *Workshop, l *ProductLine, s *ProductSection) *WorkStation
}
return item
}
func WorkstationKey(workshopId, lineId, sectionId int) string {
return fmt.Sprintf("%v.%v.%v", workshopId, lineId, sectionId)
}
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10/orm"
"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"
... ... @@ -34,9 +35,15 @@ func (dao *AttendanceRecordDao) ProductWorkStationAttendanceRecord(companyId, or
query.Where("org_id = ?", orgId)
query.Where("work_station->>'workStationId' = ?", workStationId)
query.Where("sign_in <= ?", productTime)
query.Where("sign_out >= ?", productTime)
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
query.WhereOr("sign_out >= ?", productTime)
query.WhereOr("sign_out=?", time.Time{})
return q, nil
})
query.DistinctOn("product_worker->>'userId',work_station->>'workStationId'")
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
query.OrderExpr("product_worker->>'userId' asc ,work_station->>'workStationId' asc")
if count, err := query.SelectAndCount(); err != nil {
return 0, productAttendanceRecords, err
} else {
... ... @@ -94,6 +101,9 @@ func (dao *AttendanceRecordDao) WorkerAttendanceRecords(companyId, orgId, worker
query.Where("sign_in >= ?", beginTime)
query.Where("sign_in <= ?", endTime)
query.Where("attendance_status = ?", domain.AttendanceNotApprove)
if len(workStationId) > 0 {
query.Where("work_station ->>'workStationId' = ?", workStationId)
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_attendance_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -58,7 +58,8 @@ func (dao *EmployeeProductRecordDao) WorkerBestOutputRecord(companyId, orgId, pl
query.Where("org_id = ?", orgId)
query.Where("product_worker ->>'userId' = '?'", workerId)
query.Where("product_record_info ->>'productPlanId' = '?'", planId)
query.Order("product_record_info ->>'outputWeight' DESC")
query.OrderExpr("product_record_info ->>'outputWeight' DESC")
query.Limit(1)
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, domain.ErrorNotFound
... ...
... ... @@ -32,7 +32,7 @@ func (dao *WorkshopProductRecordDao) WorkshopProductRecord(companyId, orgId, pla
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_date = ?", productTime.Local().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" {
... ...
package domainService
import (
"errors"
"fmt"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -96,6 +97,12 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
if productRecordType == domain.RecordTypeReceiveMaterial || productRecordType == domain.RecordTypeReturnMaterial {
weight = (weight / uc.FromUnitQuantity.Quantity) * uc.ToUnitQuantity.Quantity
}
// 退料、需要判断用户是否有领过料
if productRecordType == domain.RecordTypeReturnMaterial {
if _, records, err := productRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "employeeId": user.UserId, "productPlanId": plan.ProductPlanId, "productRecordType": domain.RecordTypeReceiveMaterial, "limit": 1}); err == nil && len(records) == 0 {
return nil, errors.New("当前批次未进行领料,无法退料")
}
}
record := &domain.ProductRecord{
CompanyId: request.CompanyId,
... ... @@ -106,7 +113,7 @@ func (ptr *PGProductRecordService) SubmitProductRecord(productRecordType int, qu
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: plan.ProductDate.Format("2006-01-02"),
ProductDate: plan.ProductDate.Local().Format("2006-01-02"),
Original: request.Weigh,
Weigh: weight,
WeighBefore: weight,
... ...
... ... @@ -16,6 +16,10 @@ const (
ProductSection4 = "包装"
)
const (
DefaultCCJUnitQuantity = 0.2 //kg 穿串机默认的换算数量 1串/0.1千克
)
//EmployeeProductStatics 员工产能统计
func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.ProductRecord) (interface{}, error) {
... ... @@ -56,7 +60,10 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
default:
return nil, nil //ptr.personalProductStatics(productRecord)
}
if planId == 0 {
log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId))
return nil, nil
}
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
... ... @@ -66,7 +73,7 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
// 1.查询员工 -》 员工打卡记录 工位+打卡日期
// 2.打卡记录的时间区间 在生产记录上报的时间范围内
attendanceRecordDao, _ := dao.NewAttendanceRecordDao(ptr.transactionContext)
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, productRecord.CreatedAt)
_, attendanceRecords, err := attendanceRecordDao.ProductWorkStationAttendanceRecord(cid, oid, productRecord.WorkStation.WorkStationId, time.Now()) //, productRecord.CreatedAt
if err != nil || len(attendanceRecords) == 0 {
return nil, err
}
... ... @@ -97,13 +104,15 @@ func (ptr *PGProductRecordService) EmployeeProductStatics(productRecord *domain.
yesterdayOutputWeight float64 = 0
bestOutputWeight float64 = 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 {
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
}
}
}
... ... @@ -139,7 +148,7 @@ func newEmployeeProductRecord(productRecord *domain.ProductRecord, participateTy
Ext: productPlan.Ext,
Version: 1,
ProductRecordInfo: &domain.ProductRecordStaticInfo{
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"),
ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
... ... @@ -191,6 +200,7 @@ func FindGroupMembers(productGroupRepository domain.ProductGroupRepository, comp
u := groups[i].GroupMembers[j]
u.GroupId = groups[i].ProductGroupId
u.GroupName = groups[i].GroupName
u.WorkOn = groups[i].WorkOn
result[keyFunc(u.UserId)] = u
}
}
... ... @@ -247,10 +257,6 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
}
}
}
// 更新批次的产能 (只有包装要更新批次产能)
//if productPlan.WorkStation.SectionName==ProductSection4{
//
//}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
... ... @@ -277,7 +283,10 @@ func (ptr *PGProductRecordService) WorkshopProductStatics(productRecord *domain.
productPlan *domain.ProductPlan
err error
)
if planId == 0 {
log.Logger.Debug(fmt.Sprintf("工段:%v product_record 编号:%v 批次为0", productRecord.WorkStation.WorkStationId, productRecord.ProductRecordId))
return nil, nil
}
productPlan, err = productPlanRepository.FindOne(map[string]interface{}{"productPlanId": planId})
if err != nil {
return nil, err
... ... @@ -326,7 +335,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *
WorkStation: productRecord.WorkStation,
//WorkOn: productPlan.WorkOn,
//ParticipateType: participateType,
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"),
ProductWeigh: 0,
SecondLevelWeigh: 0,
CreatedAt: time.Now(),
... ... @@ -334,7 +343,7 @@ func newWorkshopProductRecord(productRecord *domain.ProductRecord, productPlan *
Ext: productPlan.Ext,
Version: 1,
ProductRecordInfo: &domain.ProductRecordStaticInfo{
ProductDate: productRecord.CreatedAt.Format("2006-01-02"),
ProductDate: productRecord.CreatedAt.Local().Format("2006-01-02"),
ProductPlanId: productRecord.ProductRecordInfo.ProductPlanId,
PlanProductName: productRecord.ProductRecordInfo.PlanProductName,
BatchNumber: productRecord.ProductRecordInfo.BatchNumber,
... ...
... ... @@ -23,11 +23,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
attendanceRecordRepository, _ = repository.NewProductAttendanceRecordRepository(ptr.transactionContext)
isSignIn = true
record *domain.ProductAttendanceRecord
workStationId string //具体工位
workStation *domain.WorkStation
attendanceType int = domain.ParticipateNormal
worker *domain.User
org *domain.Org
//workStationId string //具体工位
workStation *domain.WorkStation
attendanceType int = domain.ParticipateNormal
worker *domain.User
org *domain.Org
)
if err := report.Valid(); err != nil {
... ... @@ -68,9 +68,32 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
beginTime := utils.GetZeroTime(report.ActionTime)
endTime := report.ActionTime
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, workStationId, beginTime, endTime)
_, records, _ := attendanceRecordDao.WorkerAttendanceRecords(cid, oid, worker.UserId, "", beginTime, endTime)
for i := 0; i < len(records); i++ {
r := records[i]
if workStation.WorkStationId == r.WorkStation.WorkStationId {
continue
}
if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) {
if utils.TimeAfterEqual(report.ActionTime, r.SignIn) {
r.SignOut = report.ActionTime
r.WorkTimeBefore = r.ComputeWorkTimeBefore()
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 在其他工段打卡 下线当前工段:%v 签退 %v", worker.UserName, worker.UserId, r.WorkStation.SectionName, report))
if _, err = attendanceRecordRepository.Save(r); err != nil {
return nil, err
}
} else {
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
break
}
}
for i := 0; i < len(records); i++ {
r := records[i]
if workStation.WorkStationId != r.WorkStation.WorkStationId {
continue
}
// 操作时间 < 签到时间
if utils.TimeAfterEqual(r.SignIn, report.ActionTime) {
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
... ... @@ -88,6 +111,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
// 存在未结束的打卡记录
// 1.满足条件-签退
if !utils.TimeIsZero(r.SignIn) && utils.TimeIsZero(r.SignOut) {
// 五分钟内重复打卡不算数
if r.SignIn.Add(time.Minute * 5).After(report.ActionTime) {
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 打卡未满五分钟 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) {
isSignIn = false
record = r
... ...
... ... @@ -65,9 +65,9 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
}
workStation = device.WorkStation
// 封箱机、串串机需要定位到批次
if record.DeviceType == domain.DeviceTypeFengXiangJi && record.DeviceType == domain.DeviceTypeChuanChuanJi {
if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi {
datetime, _ = time.Parse("2006-01-02", deviceRunningData.Date)
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.DeviceCode); err != nil {
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, datetime, deviceRunningData.ProductType); err != nil {
log.Logger.Error(err.Error())
} else {
planId = plan.PlanDispatchRecordExt.ProductPlanId
... ... @@ -90,6 +90,13 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
return nil, err
}
// 2.保存设备生产记录
if record.DeviceType == domain.DeviceTypeChuanChuanJi {
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, planId)
//if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil {
// return nil, err
//}
SendProductRecordStaticsJob(productRecord)
}
// 3.更新 设备每日运行记录(汇总) - redis更新 十分钟异步刷库
deviceDailyRecord.AddDeviceRunningData(deviceRunningData.CollectionTime, deviceRunningData)
... ... @@ -101,7 +108,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.DeviceCollection) (*domain.DeviceRunningData, error) {
var err error
var unitQuantity float64 = 1 // 单位数量
var unitQuantity float64 = DefaultCCJUnitQuantity // 单位数量
var data = &domain.DeviceRunningData{
DeviceCollectionId: record.DeviceCollectionId,
WorkShopName: record.WorkShopName,
... ... @@ -121,7 +128,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
md, _ := strconv.Atoi(m)
dd, _ := strconv.Atoi(d)
t := time.Date(yd, time.Month(md), dd, 0, 0, 0, 0, time.Local)
return t.Format("2006-01-02"), nil
return t.Local().Format("2006-01-02"), nil
}
switch record.DeviceType {
//包馅机
... ... @@ -210,25 +217,29 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId
}, nil
}
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, org *domain.Org, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) {
return &domain.ProductRecord{
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) {
result := &domain.ProductRecord{
CompanyId: companyId,
OrgId: org.OrgId,
OrgId: orgId,
WorkStation: workStation,
ProductRecordType: domain.RecordTypeWeigh,
ProductWorker: &domain.User{},
CreatedAt: time.Now(),
CreatedAt: data.CollectionTime,
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: data.CollectionTime.Format("2006-01-02"),
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
Original: float64(data.Count),
Weigh: float64(data.Count),
WeighBefore: float64(data.Count),
Weigh: float64(data.Count) * DefaultCCJUnitQuantity,
WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity,
ApproveStatus: domain.AttendanceNotApprove,
ProductPlanId: planId,
},
Ext: domain.NewExt(org.OrgName),
}, nil
Ext: domain.NewExt(""),
}
if device.Ext != nil {
result.Ext = domain.NewExt(device.Ext.OrgName)
}
return result, nil
}
func (ptr *PGWorkshopDataConsumeService) saveDeviceDailyRunningRecord(companyId, orgId int, workStation *domain.WorkStation, device *domain.Device, planId int, data *domain.DeviceRunningData) (*domain.DeviceDailyRunningRecord, error) {
... ...
... ... @@ -174,6 +174,12 @@ func (repository *ProductRecordRepository) Find(queryOptions map[string]interfac
if v, ok := queryOptions["batchNumber"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_record_info->>'batchNumber' like '%%%v%%'`, v))
}
if v, ok := queryOptions["employeeId"]; ok && v.(int) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'userId' = '%v'`, v))
}
if v, ok := queryOptions["productPlanId"]; ok && v.(int) > 0 {
query.Where(fmt.Sprintf(`product_record_info->>'productPlanId' = '%v'`, v))
}
query.SetOffsetAndLimit(domain.MaxQueryRow)
query.SetOrderDirect("product_record_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...