作者 yangfu

Merge branch 'test'

  1 +
  2 +/*
  3 +1.设备信息查询函数
  4 + code 设备编码,设备编码为空时返回所有设备信息数据
  5 + cid 公司ID
  6 + oid 组织ID
  7 +*/
  8 + */
  9 +CREATE OR REPLACE FUNCTION "manufacture"."device_running_info"("code" varchar, "cid" int4, "oid" int4)
  10 + RETURNS TABLE("t_device_name" text, "t_device_code" text, "t_status" text, "t_temperature" numeric, "t_temperature1" numeric, "t_device_type" text, "t_total" int4, "t_uptime" numeric) AS $BODY$
  11 +begin
  12 +
  13 + return query
  14 +
  15 + with product_device as (
  16 + select device_code,device_name,device_id,device_type from manufacture.device
  17 + where
  18 + company_id = 1
  19 + and org_id = 1
  20 + and ext #>'{deviceExt,isProductDevice}'='1'
  21 + )
  22 + ,device_status as(
  23 + select c.*,a.device_name,a.device_type,a.device_code device_code
  24 + from (
  25 + select cast(b.device_running_record_info->>'currentStatus' as INTEGER)status,
  26 + cast(b.device_running_record_info->>'temp' as DECIMAL) as t,
  27 + cast(b.device_running_record_info->>'count' as INTEGER) as total,
  28 + cast(b.device_running_record_info->>'upTime' as INTEGER) as uptime,
  29 + cast(b.device_running_record_info->>'temp1'as DECIMAL) as t1,
  30 + extract (min from now()-b.updated_at) span,
  31 + b.device_id
  32 + from
  33 + manufacture.device_daily_running_record b
  34 + where
  35 + company_id = 1
  36 + and org_id = 1
  37 + and b.created_at> (to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') - interval '8 hours')
  38 + )c right join product_device a on c.device_id = a.device_id
  39 + )
  40 + select cast(device_name as text) device_name,
  41 + cast(device_code as text) device_code,
  42 + cast(
  43 + (case when (status=3 or status=1) and span<10 then '运行中'
  44 + when (status=2 or status=0 )and span<10 then '待机中'
  45 + ELSE '故障中' end) as text
  46 + ) status,
  47 + cast(COALESCE(t,0) as DECIMAL) temperature,
  48 + cast(COALESCE(t1,0) as DECIMAL) temperature1,
  49 + cast(COALESCE(device_type,'') as TEXT) device_type,
  50 + cast(COALESCE(total,0) as INTEGER) total,
  51 + cast(COALESCE(uptime,0) as DECIMAL) uptime
  52 + from device_status
  53 + where device_code = code;
  54 +
  55 +end;
  56 +$BODY$
  57 + LANGUAGE plpgsql VOLATILE
  1 +
  2 +-- 表 product_plan
  3 +-- 唯一索引 company_id,org_id,batch_number
  4 +create unique index idx_product_plan_company_id_org_id_batch_number on manufacture.product_plan using btree (company_id,org_id,batch_number);
  5 +
  6 +
@@ -55,11 +55,11 @@ func (crontabService *CrontabService) initTask() { @@ -55,11 +55,11 @@ func (crontabService *CrontabService) initTask() {
55 autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次 55 autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次
56 task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord) 56 task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord)
57 57
58 - syncProductPlan := task.NewTask("定时同步车间计划", "0 */5 * * * *", SyncProductPlan)  
59 - task.AddTask("SyncProductPlan", syncProductPlan)  
60 -  
61 - syncProduct := task.NewTask("定时同步产品信息", "0 */30 * * * *", SyncProduct) 58 + syncProduct := task.NewTask("定时同步产品信息", "0 0 * * * *", SyncProduct)
62 task.AddTask("syncProduct", syncProduct) 59 task.AddTask("syncProduct", syncProduct)
  60 +
  61 + syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan)
  62 + task.AddTask("SyncProductPlan", syncProductPlan)
63 } 63 }
64 64
65 func (crontabService *CrontabService) StartCrontabTask() { 65 func (crontabService *CrontabService) StartCrontabTask() {
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 "github.com/linmadan/egglib-go/transaction/pg" 6 "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
9 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" 9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
11 "runtime/debug" 11 "runtime/debug"
12 "time" 12 "time"
@@ -45,7 +45,8 @@ func SyncProduct(ctx context.Context) error { @@ -45,7 +45,8 @@ func SyncProduct(ctx context.Context) error {
45 } 45 }
46 } 46 }
47 if fromTime.IsZero() { 47 if fromTime.IsZero() {
48 - fromTime, err = redis.GetLastFetchTime(redis.MaterialK3cloudFetchTimeKey()) 48 + // fromTime, err = redis.GetLastFetchTime(redis.MaterialK3cloudFetchTimeKey())
  49 + fromTime = utils.GetZeroTime(time.Now()).Add(-time.Hour * 24) //前一天有修改的记录
49 if err != nil { 50 if err != nil {
50 log.Logger.Error(err.Error()) 51 log.Logger.Error(err.Error())
51 return nil 52 return nil
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
9 "strconv" 10 "strconv"
10 "strings" 11 "strings"
@@ -483,10 +484,11 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa @@ -483,10 +484,11 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
483 3.查询是否有重复的批次号 484 3.查询是否有重复的批次号
484 4.有进行更新,其他的插入 485 4.有进行更新,其他的插入
485 */ 486 */
486 - lastTime, err := redis.GetLastFetchTime()  
487 - if err != nil {  
488 - return err  
489 - } 487 + //lastTime, err := redis.GetLastFetchTime()
  488 + //if err != nil {
  489 + // return err
  490 + //}
  491 + var lastTime = utils.GetZeroTime(time.Now()).Add(-time.Hour * 24) //前一天有修改的记录
490 if !fromTime.IsZero() { 492 if !fromTime.IsZero() {
491 lastTime = fromTime 493 lastTime = fromTime
492 } 494 }
@@ -552,7 +554,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa @@ -552,7 +554,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
552 plan.PlanDevoted = &domain.UnitQuantity{ 554 plan.PlanDevoted = &domain.UnitQuantity{
553 Unit: product.ProductSpec.Unit, 555 Unit: product.ProductSpec.Unit,
554 Quantity: v.Qty, 556 Quantity: v.Qty,
555 - Weight: product.ProductWeigh(0), 557 + Weight: product.ProductWeigh(v.Qty),
556 UnitWeight: product.ProductSpec.UnitWeight, 558 UnitWeight: product.ProductSpec.UnitWeight,
557 } 559 }
558 plan.Workshop = workshop.CloneSample() 560 plan.Workshop = workshop.CloneSample()
@@ -330,7 +330,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s @@ -330,7 +330,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
330 if r != nil { 330 if r != nil {
331 //log.Logger.Debug(fmt.Sprintf("%v %v",r.UpdatedAt.Local().Hour(),r.UpdatedAt.Local().Minute())) 331 //log.Logger.Debug(fmt.Sprintf("%v %v",r.UpdatedAt.Local().Hour(),r.UpdatedAt.Local().Minute()))
332 m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Local().Minute() 332 m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Local().Minute()
333 - if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) { 333 + if r.UpdatedAt.After(r.ProductDate.Add(time.Hour * 24)) {
334 m = 60 * 24 334 m = 60 * 24
335 } 335 }
336 item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m) 336 item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m)