作者 yangfu

fix:1.设备运行状态修改

... ... @@ -26,6 +26,7 @@ func (d *WorkshopWorkTimeRecordDto) LoadDto(m *domain.WorkshopWorkTimeRecord, or
d.WorkshopWorkTimeRecordId = m.WorkshopWorkTimeRecordId
d.WorkStation = m.WorkStation
if m.WorkshopWorkTimeRecordInfo != nil {
d.WorkshopWorkTimeRecordInfo = &domain.WorkshopWorkTimeRecordInfo{}
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)
... ...
... ... @@ -15,9 +15,9 @@ type ProductLevelTwoRecord struct {
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn"`
// 产能 - 审核前
WeighBefore float64 `json:"weighBefore"`
WeighBefore float64 `json:"weightBefore"`
// 产能-审核后
WeighAfter float64 `json:"weighAfter"`
WeighAfter float64 `json:"weightAfter"`
// 审核状态 1:未审核 2:已审核
ApproveStatus int `json:"approveStatus"`
// 审核人
... ...
... ... @@ -86,6 +86,9 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
if productRecordType == RecordTypeReturnMaterial {
employeeProductRecord.ProductWeigh -= weigh
}
if productRecordType == RecordTypeWeigh {
employeeProductRecord.ProductWeigh += weigh
}
employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, yesterdayWeight, bestWeight)
employeeProductRecord.UpdatedAt = time.Now()
employeeProductRecord.Version += 1
... ...
... ... @@ -68,6 +68,9 @@ func (employeeProductRecord *WorkshopProductRecord) UpdateProductWeigh(weigh flo
if productRecordType == RecordTypeReturnMaterial {
employeeProductRecord.ProductWeigh -= weigh
}
if productRecordType == RecordTypeWeigh {
employeeProductRecord.ProductWeigh += weigh
}
employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0)
employeeProductRecord.UpdatedAt = time.Now()
employeeProductRecord.Version += 1
... ...
... ... @@ -261,22 +261,24 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
return nil, err
}
//workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext)
deviceRepository, _ := repository.NewDeviceRepository(ptr.transactionContext)
deviceRunningRecordRepository, _ := repository.NewDeviceDailyRunningRecordRepository(ptr.transactionContext)
//workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId})
//if err != nil || workshop == nil {
// return nil, nil
//}
var t time.Time
var err error
if len(request.Date) > 0 {
t, err = time.ParseInLocation("2006-01-02", request.Date, time.Local)
if err != nil {
log.Logger.Error(err.Error())
}
}
_, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId})
if err != nil {
return nil, err
}
var response = make([]interface{}, 0)
_, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": request.Date})
_, dailyRecords, err := deviceRunningRecordRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "productDate": t})
for i := 0; i < len(devices); i++ {
d := devices[i]
if d.Ext == nil || d.Ext.DeviceExt == nil || d.Ext.DeviceExt.IsProductDevice == 0 {
... ... @@ -301,7 +303,10 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
}
}
if r != nil {
m := r.UpdatedAt.Hour()*60 + r.UpdatedAt.Minute()
m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Minute()
if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) {
m = 60 * 24
}
item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m)
item["status_info"] = r.DeviceRunningRecordInfo.TimeLineDeviceStatus
}
... ...
... ... @@ -48,6 +48,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
if err != nil {
return nil, err
}
if deviceDailyRecord != nil {
workStation = deviceDailyRecord.WorkStation
planId = deviceDailyRecord.DeviceRunningRecordInfo.ProductPlanId
... ... @@ -64,15 +65,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
return nil, nil
}
workStation = device.WorkStation
// 封箱机、串串机需要定位到批次
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.ProductType); err != nil {
log.Logger.Error(err.Error())
} else {
planId = plan.PlanDispatchRecordExt.ProductPlanId
}
}
var saveErr error
if deviceDailyRecord, saveErr = ptr.saveDeviceDailyRunningRecord(companyId, orgId, workStation, device, planId, deviceRunningData); err != nil {
return nil, err
... ... @@ -84,14 +77,25 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
}()
}
// 封箱机、串串机需要定位到批次
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.ProductType); err != nil {
log.Logger.Error(err.Error())
} else {
planId = plan.PlanDispatchRecordExt.ProductPlanId
}
}
// 1.保存设备运行记录
deviceRunningRecord, _ = ptr.newDeviceRunningRecord(companyId, orgId, workStation, device, deviceRunningData)
if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil {
return nil, err
}
// 2.保存设备生产记录
if record.DeviceType == domain.DeviceTypeChuanChuanJi {
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, planId)
if record.DeviceType == domain.DeviceTypeChuanChuanJi && plan != nil {
productRecord, _ := ptr.newProductRecord(companyId, orgId, workStation, device, deviceRunningData, plan)
//if _, err = deviceRunningRecordRepository.Save(deviceRunningRecord); err != nil {
// return nil, err
//}
... ... @@ -217,7 +221,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningRecord(companyId, orgId
}, nil
}
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, planId int) (*domain.ProductRecord, error) {
func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId int, workStation *domain.WorkStation, device *domain.Device, data *domain.DeviceRunningData, plan *domain.ProductPlanDispatchRecord) (*domain.ProductRecord, error) {
result := &domain.ProductRecord{
CompanyId: companyId,
OrgId: orgId,
... ... @@ -227,12 +231,14 @@ func (ptr *PGWorkshopDataConsumeService) newProductRecord(companyId int, orgId i
CreatedAt: data.CollectionTime,
UpdatedAt: time.Now(),
ProductRecordInfo: &domain.ProductRecordInfo{
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
Original: float64(data.Count),
Weigh: float64(data.Count) * DefaultCCJUnitQuantity,
WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity,
ApproveStatus: domain.AttendanceNotApprove,
ProductPlanId: planId,
ProductDate: data.CollectionTime.Local().Format("2006-01-02"),
Original: float64(data.Count),
Weigh: float64(data.Count) * DefaultCCJUnitQuantity,
WeighBefore: float64(data.Count) * DefaultCCJUnitQuantity,
ApproveStatus: domain.AttendanceNotApprove,
ProductPlanId: plan.PlanDispatchRecordExt.ProductPlanId,
PlanProductName: plan.PlanDispatchRecordExt.PlanProductName,
BatchNumber: plan.BatchNumber,
},
Ext: domain.NewExt(""),
}
... ...
... ... @@ -3,6 +3,7 @@ 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"
... ... @@ -145,7 +146,7 @@ func (repository *DeviceDailyRunningRecordRepository) Find(queryOptions map[stri
query := sqlbuilder.BuildQuery(tx.Model(&deviceDailyRunningRecordModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["productDate"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["productDate"]; ok && !(v.(time.Time)).IsZero() {
query.Where(`product_date = ?`, v)
}
query.SetOffsetAndLimit(20)
... ...
... ... @@ -107,6 +107,14 @@ func (repository *WorkshopWorkTimeRecordRepository) FindOne(queryOptions map[str
tx := repository.transactionContext.PgTx
workshopWorkTimeRecordModel := new(models.WorkshopWorkTimeRecord)
query := sqlbuilder.BuildQuery(tx.Model(workshopWorkTimeRecordModel), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
if v, ok := queryOptions["workStationId"]; ok && len(v.(string)) > 0 {
query.Where(`work_station->>'workStationId' = ?`, v)
}
if v, ok := queryOptions["recordDate"]; ok {
query.Where("record_date=?", v)
}
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" {
... ...