作者 yangfu

Merge branch 'test'

/*
1.设备信息查询函数
code 设备编码,设备编码为空时返回所有设备信息数据
cid 公司ID
oid 组织ID
*/
*/
CREATE OR REPLACE FUNCTION "manufacture"."device_running_info"("code" varchar, "cid" int4, "oid" int4)
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$
begin
return query
with product_device as (
select device_code,device_name,device_id,device_type from manufacture.device
where
company_id = 1
and org_id = 1
and ext #>'{deviceExt,isProductDevice}'='1'
)
,device_status as(
select c.*,a.device_name,a.device_type,a.device_code device_code
from (
select cast(b.device_running_record_info->>'currentStatus' as INTEGER)status,
cast(b.device_running_record_info->>'temp' as DECIMAL) as t,
cast(b.device_running_record_info->>'count' as INTEGER) as total,
cast(b.device_running_record_info->>'upTime' as INTEGER) as uptime,
cast(b.device_running_record_info->>'temp1'as DECIMAL) as t1,
extract (min from now()-b.updated_at) span,
b.device_id
from
manufacture.device_daily_running_record b
where
company_id = 1
and org_id = 1
and b.created_at> (to_date(to_char(now(), 'YYYY-MM-DD'),'YYYY-MM-DD') - interval '8 hours')
)c right join product_device a on c.device_id = a.device_id
)
select cast(device_name as text) device_name,
cast(device_code as text) device_code,
cast(
(case when (status=3 or status=1) and span<10 then '运行中'
when (status=2 or status=0 )and span<10 then '待机中'
ELSE '故障中' end) as text
) status,
cast(COALESCE(t,0) as DECIMAL) temperature,
cast(COALESCE(t1,0) as DECIMAL) temperature1,
cast(COALESCE(device_type,'') as TEXT) device_type,
cast(COALESCE(total,0) as INTEGER) total,
cast(COALESCE(uptime,0) as DECIMAL) uptime
from device_status
where device_code = code;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
\ No newline at end of file
... ...
-- 表 product_plan
-- 唯一索引 company_id,org_id,batch_number
create unique index idx_product_plan_company_id_org_id_batch_number on manufacture.product_plan using btree (company_id,org_id,batch_number);
... ...
... ... @@ -55,11 +55,11 @@ func (crontabService *CrontabService) initTask() {
autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次
task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord)
syncProductPlan := task.NewTask("定时同步车间计划", "0 */5 * * * *", SyncProductPlan)
task.AddTask("SyncProductPlan", syncProductPlan)
syncProduct := task.NewTask("定时同步产品信息", "0 */30 * * * *", SyncProduct)
syncProduct := task.NewTask("定时同步产品信息", "0 0 * * * *", SyncProduct)
task.AddTask("syncProduct", syncProduct)
syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan)
task.AddTask("SyncProductPlan", syncProductPlan)
}
func (crontabService *CrontabService) StartCrontabTask() {
... ...
... ... @@ -6,7 +6,7 @@ import (
"github.com/linmadan/egglib-go/transaction/pg"
"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/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"runtime/debug"
"time"
... ... @@ -45,7 +45,8 @@ func SyncProduct(ctx context.Context) error {
}
}
if fromTime.IsZero() {
fromTime, err = redis.GetLastFetchTime(redis.MaterialK3cloudFetchTimeKey())
// fromTime, err = redis.GetLastFetchTime(redis.MaterialK3cloudFetchTimeKey())
fromTime = utils.GetZeroTime(time.Now()).Add(-time.Hour * 24) //前一天有修改的记录
if err != nil {
log.Logger.Error(err.Error())
return nil
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"strconv"
"strings"
... ... @@ -483,10 +484,11 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
3.查询是否有重复的批次号
4.有进行更新,其他的插入
*/
lastTime, err := redis.GetLastFetchTime()
if err != nil {
return err
}
//lastTime, err := redis.GetLastFetchTime()
//if err != nil {
// return err
//}
var lastTime = utils.GetZeroTime(time.Now()).Add(-time.Hour * 24) //前一天有修改的记录
if !fromTime.IsZero() {
lastTime = fromTime
}
... ... @@ -552,7 +554,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
plan.PlanDevoted = &domain.UnitQuantity{
Unit: product.ProductSpec.Unit,
Quantity: v.Qty,
Weight: product.ProductWeigh(0),
Weight: product.ProductWeigh(v.Qty),
UnitWeight: product.ProductSpec.UnitWeight,
}
plan.Workshop = workshop.CloneSample()
... ...
... ... @@ -330,7 +330,7 @@ func (ptr *PGCommonStatisticsService) DeviceRunningStatistics(queryOptions map[s
if r != nil {
//log.Logger.Debug(fmt.Sprintf("%v %v",r.UpdatedAt.Local().Hour(),r.UpdatedAt.Local().Minute()))
m := r.UpdatedAt.Local().Hour()*60 + r.UpdatedAt.Local().Minute()
if r.UpdatedAt.Before(utils.GetZeroTime(time.Now())) {
if r.UpdatedAt.After(r.ProductDate.Add(time.Hour * 24)) {
m = 60 * 24
}
item["status"] = r.DeviceRunningRecordInfo.HourDeviceStatusDetail(m)
... ...