作者 yangfu

fix:1.时段产能修改

... ... @@ -32,4 +32,8 @@ type DeviceRunningData struct {
ProductType string `json:"productType"`
// 日期
Date string `json:"date"`
// 额外数据
// 单位数据 比如:1串/0.1kg weight = count * unitQuantity
UnitQuantity float64 `json:"unitQuantity"`
}
... ...
... ... @@ -86,7 +86,7 @@ func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh flo
if productRecordType == RecordTypeReturnMaterial {
employeeProductRecord.ProductWeigh -= weigh
}
employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0)
employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, yesterdayWeight, bestWeight)
employeeProductRecord.UpdatedAt = time.Now()
employeeProductRecord.Version += 1
}
... ...
... ... @@ -58,8 +58,10 @@ func (info *ProductRecordStaticInfo) PreStatistics(productWeight float64, second
info.InputWeight = productWeight - totalOtherSecondLevelWeigh
info.OutputWeight = info.InputWeight - secondWeight
info.SecondLevelWeight = secondWeight
info.YesterdayOutputWeight = yesterdayWeight
info.BestOutputWeight = bestWeight
if info.YesterdayOutputWeight == 0 && info.BestOutputWeight == 0 {
info.YesterdayOutputWeight = yesterdayWeight
info.BestOutputWeight = bestWeight
}
if bestWeight <= info.InputWeight {
info.BestOutputWeight = info.OutputWeight
}
... ...
... ... @@ -83,3 +83,47 @@ select round(avg(oee),1) oee,round(avg(tu),1) tu,round(avg(pu),1)pu, round(avg(q
}
return nil
}
// 时段产能
func (dao *DeviceDailyRunningRecordDao) TimeSectionProductRecord(companyId, orgId, workshopId int, lineId int, sectionName string, beginTime time.Time, result interface{}) error {
tx := dao.transactionContext.PgTx
sql := fmt.Sprintf(`
WITH ts_product as(
select sum(a.weight) total,a.ts from (
select
cast(device_running_record_info->>'count' as DECIMAL) weight,
"replace"(to_char(created_at at time ZONE 'Asia/shanghai', 'HH24:') || cast(date_part('minute',created_at) as integer)/30*30, ':0', ':00') ts
from manufacture.device_running_record
where
company_id = ?
and org_id = ?
and work_station->>'workshopId'='?'
and work_station->>'lineId'='?'
and work_station->>'sectionName'=?
and device_running_record_info->>'deviceType'='CCJ'
and created_at >?
) a
group by a.ts
order by ts
)
-- select * from ts_product
, ts_product_list as (
select d.ts,ts_product.total from (
select to_char(c.ts::timestamp,'HH24:MI') ts from (
select generate_series(a.end - interval '5 hour',
"replace"(to_char(a.end, 'yyyy-mm-dd HH24:') || cast(date_part('minute',a.end) as integer)/30*30+30, ':0', ':00')::timestamp,
'30 minute') ts from (
select to_timestamp(to_char(now() at time ZONE 'Asia/shanghai','yyyy-mm-dd HH24'),'yyyy-mm-dd HH24') as end
) a
) c
) d left join ts_product on d.ts = ts_product.ts
)
SELECT ts, coalesce(total,0) total
from ts_product_list
`)
if _, err := tx.Query(result, sql, companyId, orgId, workshopId, lineId, sectionName, beginTime); err != nil {
return err
}
return nil
}
... ...
... ... @@ -72,7 +72,7 @@ func (ptr *PGCommonStatisticsService) HourProductiveStatistics(queryOptions map[
if err != nil || workshop == nil {
return nil, nil
}
productRecordDao, _ := dao.NewProductRecordDao(ptr.transactionContext)
productRecordDao, _ := dao.NewDeviceDailyRunningRecordDao(ptr.transactionContext)
var response = make([]interface{}, 0)
var tmpXData = make([]string, 0)
... ... @@ -243,7 +243,7 @@ func (ptr *PGCommonStatisticsService) WorkshopProductionEfficiencyStatistics(que
var response = make(map[string]interface{})
for _, v := range input {
var result = make([]*record, 0)
var result = record{}
if err := productRecordDao.WorkshopProductionEfficiencyStatistics(request.CompanyId, request.OrgId, request.WorkshopId, v.t, &result); err != nil {
log.Logger.Error(err.Error())
return nil, err
... ... @@ -261,14 +261,14 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
return nil, err
}
workshopRepository, _ := repository.NewWorkshopRepository(ptr.transactionContext)
//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
}
//workshop, err := workshopRepository.FindOne(map[string]interface{}{"workshopId": request.WorkshopId})
//if err != nil || workshop == nil {
// return nil, nil
//}
_, devices, err := deviceRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "workshopId": request.WorkshopId, "lineId": request.LineId})
if err != nil {
... ... @@ -312,7 +312,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
type DeviceRunningStatisticRequest struct {
CompanyId int `json:"companyId" valid:"Required"`
OrgId int `json:"orgId" valid:"Required"`
WorkshopId int `json:"workshopId" valid:"Required"`
WorkshopId int `json:"workshopId"`
LineId int `json:"lineId""`
Date string `json:"date"`
}
... ...
... ... @@ -236,15 +236,21 @@ func (ptr *PGProductRecordService) personalProductStatics(productRecord *domain.
yesterdayOutputWeight float64 = 0
bestOutputWeight float64 = 0
)
if record, e := employeeProductRecordDao.WorkerProductRecord(cid, oid, planId, productRecord.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, productRecord.ProductWorker.UserId); e == nil && record != nil {
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 {
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
bestOutputWeight = record.ProductRecordInfo.BestOutputWeight
} else {
if record, e := employeeProductRecordDao.WorkerBestOutputRecord(cid, oid, planId, productRecord.ProductWorker.UserId); e == nil && record != nil {
yesterdayOutputWeight = record.ProductRecordInfo.OutputWeight
}
}
}
// 更新批次的产能 (只有包装要更新批次产能)
//if productPlan.WorkStation.SectionName==ProductSection4{
//
//}
employeeProductRecord.UpdateProductWeigh(productRecord.ProductRecordInfo.Weigh, productRecord.ProductRecordType, productRecord.WorkStation.SectionName, yesterdayOutputWeight, bestOutputWeight)
... ...
... ... @@ -73,14 +73,14 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
r := records[i]
// 操作时间 < 签到时间
if utils.TimeAfterEqual(r.SignIn, report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 考勤记录不合法,操作时间小于签到时间 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
// 存在完整打卡记录
// 1. 如果在区间内,退出
if !utils.TimeIsZero(r.SignIn) && !utils.TimeIsZero(r.SignOut) {
if utils.TimeBeforeEqual(r.SignIn, report.ActionTime) && utils.TimeAfterEqual(r.SignOut, report.ActionTime) {
log.Logger.Info(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 已存在同一时间段的考勤记录 考勤ID:%v 用户:%v 打卡时间:%v", r.ProductAttendanceId, worker.UserId, report.ActionTime))
return struct{}{}, nil
}
continue
... ... @@ -115,11 +115,11 @@ func (ptr *PGWorkerAttendanceReportService) Report(cid, oid int, report *domain.
ProductGroupId: groupId,
}),
}
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report))
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签到 %v", worker.UserName, worker.UserId, report))
} else {
record.SignOut = report.ActionTime
record.WorkTimeBefore = record.ComputeWorkTimeBefore()
log.Logger.Info(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report))
log.Logger.Debug(fmt.Sprintf("【考勤汇报】 用户:%v(%v) 签退 %v", worker.UserName, worker.UserId, report))
}
if _, err = attendanceRecordRepository.Save(record); err != nil {
... ...
... ... @@ -101,6 +101,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 data = &domain.DeviceRunningData{
DeviceCollectionId: record.DeviceCollectionId,
WorkShopName: record.WorkShopName,
... ... @@ -109,6 +110,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
DeviceType: record.DeviceType,
StartupStatus: int(record.StartupStatus),
ComStatus: int(record.ComStatus),
//UnitQuantity: unitQuantity,
}
var mBytes []byte
if mBytes, err = json.Marshal(record.Values); err != nil {
... ... @@ -152,6 +154,7 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
if data.Date, err = formatDate(deviceChuanChuanJi.Year, deviceChuanChuanJi.Month, deviceChuanChuanJi.Day); err != nil {
return nil, err
}
data.UnitQuantity = unitQuantity
break
//速冻线
case domain.DeviceTypeSuDongXian:
... ...
... ... @@ -174,6 +174,12 @@ func (repository *DeviceRepository) Find(queryOptions map[string]interface{}) (i
if v, ok := queryOptions["inDeviceId"]; ok && len(v.([]int)) > 0 {
query.Where(`device_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["workshopId"]; ok && (v.(int)) > 0 {
query.Where(`work_station->>'workshopId'='?'`, v)
}
if v, ok := queryOptions["lineId"]; ok && (v.(int)) > 0 {
query.Where(`work_station->>'lineId'='?'`, v)
}
query.SetWhereByQueryOption("device_code = ?", "deviceCode")
query.SetWhereByQueryOption("device_status = ?", "deviceStatus")
if v, ok := queryOptions["deviceName"]; ok && len(v.(string)) > 0 {
... ...