作者 yangfu

fix: 1.数据同步修改

... ... @@ -42,6 +42,8 @@ type SearchEmployeeAttendanceQuery struct {
BeginTime string `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime string `cname:"结束时间" json:"endTime"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
InAttendanceStatus []int `cname:"考勤状态 1.未审核 2:已审核 3.自动审核" json:"inAttendanceStatus,omitempty"`
// 开始时间
SignBeginTime time.Time `cname:"开始时间" json:"signBeginTime"`
... ... @@ -69,7 +71,8 @@ func (cmd *SearchEmployeeAttendanceQuery) Valid(validation *validation.Validatio
cmd.SignEndTime = cmd.SignEndTime.Add(time.Hour * 24)
}
}
cmd.AttendanceStatus = 6 // 审核 + 自动审核
//cmd.AttendanceStatus = 6 // 审核 + 自动审核
cmd.InAttendanceStatus = []int{2, 3}
}
func (cmd *SearchEmployeeAttendanceQuery) ValidateQuery() error {
... ...
... ... @@ -47,7 +47,7 @@ func (crontabService *CrontabService) initTask() {
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)
autoFlushDeviceDailyRunningRecordOEE := task.NewTask("定时刷新设备每日运行记录-OEE", "0 */10 * * * *", AutoFlushDeviceDailyRunningRecordOEE)
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecordOEE)
task.AddTask("autoFlushDeviceDailyRunningRecordOEE", autoFlushDeviceDailyRunningRecordOEE)
autoWorkshopPlanCompletionRecord := task.NewTask("定时刷新昨日车间计划完成纪录", "0 5 1-17/1 * * *", AutoWorkshopPlanCompletionRecord)
task.AddTask("autoWorkshopPlanCompletionRecord", autoWorkshopPlanCompletionRecord)
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"time"
)
// 定时同步生产计划
... ... @@ -32,7 +33,14 @@ func SyncProductPlan(ctx context.Context) error {
log.Logger.Debug("【定时同步车间计划】 启动")
pullK3CloudService := syncdata.PullDataK3CloudService{}
if err := pullK3CloudService.SyncDataProductPlan(transactionContext.(*pg.TransactionContext)); err != nil {
t := ctx.Value("fromTime")
var fromTime time.Time
if t != nil {
if v, ok := t.(time.Time); ok {
fromTime = v
}
}
if err := pullK3CloudService.SyncDataProductPlan(transactionContext.(*pg.TransactionContext), fromTime); err != nil {
log.Logger.Error(err.Error())
return nil
}
... ...
... ... @@ -457,7 +457,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
}
// 同步生产计划
func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.TransactionContext) error {
func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.TransactionContext, fromTime time.Time) error {
/*
1.获取更新时间
2.获取prd_mo_k3cloud从更新时间开始的有变化的数据
... ... @@ -468,6 +468,9 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
if err != nil {
return err
}
if !fromTime.IsZero() {
lastTime = fromTime
}
prdMoK3cloudDao, _ := dao.NewPrdMoK3cloudDao(ptr)
records, err := prdMoK3cloudDao.GetLatestData(lastTime)
if err != nil {
... ...
... ... @@ -32,6 +32,8 @@ var (
// 打浆机
DeviceTypeDaJiangJi = "DJJ"
// 面包屑机
DeviceTypeMianBaoXie = "MBX"
// 面包屑机
DeviceTypeMianBaoXieJi = "MBXJ"
// 油炸机
DeviceTypeYouZhaJi = "YZJ"
... ...
... ... @@ -13,10 +13,10 @@ type DeviceBaoXianJi struct {
// 油炸机
type DeviceYouZhaJi struct {
FrontTemp float64 `json:"FontTemp"` // 炸机前段温度:炸机前段当前温度
BackTemp float64 `json:"BackTemp"` // 炸机后段温度:炸机后段当前温度
TankTemp float64 `json:"TankTemp"` // 储油罐温度 :储油罐当前温度
TubeTemp float64 `json:"TubeTemp"` // 管路温度:管路当前温度
FrontTemp float64 `json:"FrontTemp"` // 炸机前段温度:炸机前段当前温度
BackTemp float64 `json:"BackTemp"` // 炸机后段温度:炸机后段当前温度
TankTemp float64 `json:"TankTemp"` // 储油罐温度 :储油罐当前温度
TubeTemp float64 `json:"TubeTemp"` // 管路温度:管路当前温度
}
// 油炸机2
... ...
... ... @@ -239,10 +239,11 @@ func (d *DeviceRunningRecordInfo) HourDeviceStatusDetail(endTime int) map[string
if i == 0 {
status = computeStatus(hds.Up, hds.Com, index) // 状态初始化
}
if hds.Up == 0 && hds.Com == 0 {
if hds.Up == 0 && hds.Com == 0 && (end+60/hds.Window) < endTime {
end += 60 / hds.Window
continue
}
for j := 1; j < 60; j++ {
curStatus := computeStatus(hds.Up, hds.Com, index)
if curStatus == status {
... ...
... ... @@ -77,7 +77,7 @@ func (ptr *PGWorkshopDataConsumeService) Consume(companyId, orgId int, record *d
}
// 封箱机、串串机需要定位到批次
if record.DeviceType == domain.DeviceTypeFengXiangJi || record.DeviceType == domain.DeviceTypeChuanChuanJi {
if record.DeviceType == domain.DeviceTypeChuanChuanJi { //record.DeviceType == domain.DeviceTypeFengXiangJi ||
datetime, _ := time.ParseInLocation("2006-01-02", deviceRunningData.Date, time.Local)
if plan, err = ptr.findDeviceProductPlan(companyId, orgId, workStation.WorkStationId, utils.GetZeroTimeWithLocal(datetime, time.UTC), deviceRunningData.ProductType); err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"workstation": workStation, "product_code": deviceRunningData.ProductType})
... ... @@ -145,23 +145,23 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
break
//油炸机
case domain.DeviceTypeYouZhaJi:
deviceYouZhaJi := &domain.DeviceYouZhaJi{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
break
}
data.Temp1 = deviceYouZhaJi.FrontTemp
data.Temp2 = deviceYouZhaJi.BackTemp
break
//油炸机
case domain.DeviceTypeYouZhaJi2:
deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
break
if record.DeviceSn == domain.DeviceTypeYouZhaJi1 {
deviceYouZhaJi := &domain.DeviceYouZhaJi{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
break
}
data.Temp1 = deviceYouZhaJi.FrontTemp
data.Temp2 = deviceYouZhaJi.BackTemp
} else {
deviceYouZhaJi := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
break
}
data.Temp1 = deviceYouZhaJi.Temp1
data.Temp2 = deviceYouZhaJi.Temp2
}
data.Temp1 = deviceYouZhaJi.Temp1
data.Temp2 = deviceYouZhaJi.Temp2
break
//串串机
case domain.DeviceTypeChuanChuanJi:
... ... @@ -216,6 +216,8 @@ func (ptr *PGWorkshopDataConsumeService) newDeviceRunningData(record *domain.Dev
break
//打浆机
case domain.DeviceTypeDaJiangJi:
//面包屑机
case domain.DeviceTypeMianBaoXie:
default:
}
return data, nil
... ...
... ... @@ -173,6 +173,9 @@ func (repository *ProductAttendanceRecordRepository) Find(queryOptions map[strin
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["inAttendanceStatus"]; ok && len(v.([]int)) > 0 {
query.Where(`attendance_status in (?)`, pg.In(v))
}
if v, ok := queryOptions["userName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`product_worker->>'userName' like '%%%v%%'`, v))
}
... ...
... ... @@ -151,6 +151,7 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface
query := sqlbuilder.BuildQuery(tx.Model(&productGroupModels), queryOptions)
query.SetWhereByQueryOption("company_id = ?", "companyId")
query.SetWhereByQueryOption("org_id = ?", "orgId")
query.SetWhereByQueryOption("work_station->>'workStationId'=?", "workStationId")
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
... ...
package controllers
import (
c "context"
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/utils/json"
"github.com/linmadan/egglib-go/web/beego"
... ... @@ -14,6 +15,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
)
type StatisticsController struct {
... ... @@ -67,7 +69,14 @@ func (controller *StatisticsController) TaskHandler() func(ctx *context.Context)
crontab.AutoWorkshopPlanCompletionRecord(nil)
break
case "6":
crontab.SyncProductPlan(nil)
bc := c.Background()
t := ctx.Input.Query("t")
if len(t) != 0 {
if v, err := time.ParseInLocation("2006-01-02 15:04:05", t, time.Local); err == nil {
bc = c.WithValue(bc, "fromTime", v)
}
}
crontab.SyncProductPlan(bc)
break
}
Response(ctx, nil, nil)
... ...
... ... @@ -34,11 +34,12 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
if collectionTime.IsZero() {
return
}
var mBytes []byte
for key, item := range payload {
if key == "WorkShop" || key == "UpTime" {
continue
}
mBytes, err := json.Marshal(item)
mBytes, err = json.Marshal(item)
if err != nil {
continue
}
... ... @@ -49,106 +50,113 @@ func OnReceiveData(client pahomqtt.Client, message pahomqtt.Message) {
StartupStatus: gjson.Get(string(message.Payload()), key+".StartupState").Int(),
ComStatus: gjson.Get(string(message.Payload()), key+".ComStatus").Int(),
}
if utils.SubStr(key, 0, 4) == domain.DeviceTypeMianBaoXieJi {
deviceType4 := utils.SubStr(key, 0, 4)
deviceType := utils.SubStr(key, 0, 3)
deviceCollection.DeviceType = deviceType
if deviceType4 == domain.DeviceTypeMianBaoXieJi {
deviceCollection.DeviceType = domain.DeviceTypeMianBaoXieJi
} else {
deviceType := utils.SubStr(key, 0, 3)
deviceCollection.DeviceType = deviceType
switch deviceType {
//包馅机
case domain.DeviceTypeBaoXianJi:
deviceBaoXianJi := &domain.DeviceBaoXianJi{}
err = json.Unmarshal(mBytes, deviceBaoXianJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceBaoXianJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi1:
deviceYouZhaJi := &domain.DeviceYouZhaJi{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi2:
deviceYouZhaJi2 := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi2)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi2)
break
//串串机
case domain.DeviceTypeChuanChuanJi:
deviceChuanChuanJi := &domain.DeviceChuanChuanJi{}
err = json.Unmarshal(mBytes, deviceChuanChuanJi)
if err != nil {
log.Logger.Error(err.Error())
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceChuanChuanJi)
break
//速冻线
case domain.DeviceTypeSuDongXian:
deviceSuDongXian := &domain.DeviceSuDongXian{}
err = json.Unmarshal(mBytes, deviceSuDongXian)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceSuDongXian)
break
//封口机
case domain.DeviceTypeFengKouJi:
deviceFengKouJi := &domain.DeviceFengKouJi{}
err = json.Unmarshal(mBytes, deviceFengKouJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengKouJi)
break
//封箱机
case domain.DeviceTypeFengXiangJi:
deviceFengXiangJi := &domain.DeviceFengXiangJi{}
err = json.Unmarshal(mBytes, deviceFengXiangJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengXiangJi)
break
//打浆机 //面包屑机
case domain.DeviceTypeDaJiangJi:
case domain.DeviceTypeChuanChuanJi:
default:
}
if deviceType == domain.DeviceTypeYouZhaJi {
deviceType = deviceType4
}
switch deviceType {
//包馅机
case domain.DeviceTypeBaoXianJi:
deviceBaoXianJi := &domain.DeviceBaoXianJi{}
err = json.Unmarshal(mBytes, deviceBaoXianJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceBaoXianJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi1:
deviceYouZhaJi := &domain.DeviceYouZhaJi{}
err = json.Unmarshal(mBytes, deviceYouZhaJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi)
break
//油炸机
case domain.DeviceTypeYouZhaJi2:
deviceYouZhaJi2 := &domain.DeviceYouZhaJi2{}
err = json.Unmarshal(mBytes, deviceYouZhaJi2)
if err != nil {
continue
}
if deviceType != domain.DeviceTypeChuanChuanJi {
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceYouZhaJi2)
break
//串串机
case domain.DeviceTypeChuanChuanJi:
deviceChuanChuanJi := &domain.DeviceChuanChuanJi{}
err = json.Unmarshal(mBytes, deviceChuanChuanJi)
if err != nil {
log.Logger.Error(err.Error())
continue
}
// 发送数据
deviceCollectionService := service.NewDeviceCollectionService(nil)
_, err := deviceCollectionService.CreateDeviceCollection(&command.CreateDeviceCollectionCommand{
WorkShopName: deviceCollection.WorkShopName,
StartupStatus: deviceCollection.StartupStatus,
CollectionTime: deviceCollection.CollectionTime,
DeviceSn: deviceCollection.DeviceSn,
DeviceType: deviceCollection.DeviceType,
ComStatus: deviceCollection.ComStatus,
Values: deviceCollection.Values,
PreCheck: true,
})
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceChuanChuanJi)
break
//速冻线
case domain.DeviceTypeSuDongXian:
deviceSuDongXian := &domain.DeviceSuDongXian{}
err = json.Unmarshal(mBytes, deviceSuDongXian)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceSuDongXian)
break
//封口机
case domain.DeviceTypeFengKouJi:
deviceFengKouJi := &domain.DeviceFengKouJi{}
err = json.Unmarshal(mBytes, deviceFengKouJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengKouJi)
break
//封箱机
case domain.DeviceTypeFengXiangJi:
deviceFengXiangJi := &domain.DeviceFengXiangJi{}
err = json.Unmarshal(mBytes, deviceFengXiangJi)
if err != nil {
continue
}
deviceCollection.Values = tool_funs.SimpleStructToMap(deviceFengXiangJi)
break
//打浆机 //面包屑机
case domain.DeviceTypeDaJiangJi:
break
default:
}
//if deviceType != domain.DeviceTypeChuanChuanJi {
// continue
//}
// 发送数据
deviceCollectionService := service.NewDeviceCollectionService(nil)
_, err = deviceCollectionService.CreateDeviceCollection(&command.CreateDeviceCollectionCommand{
WorkShopName: deviceCollection.WorkShopName,
StartupStatus: deviceCollection.StartupStatus,
CollectionTime: deviceCollection.CollectionTime,
DeviceSn: deviceCollection.DeviceSn,
DeviceType: deviceCollection.DeviceType,
ComStatus: deviceCollection.ComStatus,
Values: deviceCollection.Values,
PreCheck: true,
})
if err != nil {
continue
}
}
//TODO:日志先注释
//log.Logger.Info("MQTT", map[string]interface{}{
// "Topic": message.Topic(),
// "MessageId": message.MessageID(),
// "Message": payload,
//})
if err == nil {
log.Logger.Info("MQTT", map[string]interface{}{
"Topic": message.Topic(),
"MessageId": message.MessageID(),
"Message": payload,
})
}
}
}
... ...