正在显示
5 个修改的文件
包含
32 行增加
和
16 行删除
@@ -2,14 +2,14 @@ package main | @@ -2,14 +2,14 @@ package main | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt" | ||
6 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" | ||
7 | - | ||
8 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
9 | "github.com/linmadan/egglib-go/log/logrus" | 6 | "github.com/linmadan/egglib-go/log/logrus" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" |
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task" | ||
12 | + "time" | ||
13 | 13 | ||
14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab" |
15 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 15 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
@@ -44,6 +44,7 @@ func main() { | @@ -44,6 +44,7 @@ func main() { | ||
44 | cron := crontab.NewCrontabService(nil) | 44 | cron := crontab.NewCrontabService(nil) |
45 | cron.StartCrontabTask() | 45 | cron.StartCrontabTask() |
46 | defer cron.StopCrontabTask() | 46 | defer cron.StopCrontabTask() |
47 | + time.Sleep(time.Second) | ||
47 | log.Logger.Info("server start!") | 48 | log.Logger.Info("server start!") |
48 | web.Run() | 49 | web.Run() |
49 | log.Logger.Info("server stop!") | 50 | log.Logger.Info("server stop!") |
@@ -436,8 +436,15 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { | @@ -436,8 +436,15 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { | ||
436 | if err != nil { | 436 | if err != nil { |
437 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 437 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
438 | } | 438 | } |
439 | + | ||
440 | + var userService = domainService.NewUserService() | ||
441 | + org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID) | ||
442 | + if err != nil { | ||
443 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
444 | + } | ||
445 | + | ||
439 | //同步ProductPlan 表数据 | 446 | //同步ProductPlan 表数据 |
440 | - err = prdMoDao.SyncDataProductPlan(version) | 447 | + err = prdMoDao.SyncDataProductPlan(version, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, org.OrgName) |
441 | if err != nil { | 448 | if err != nil { |
442 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 449 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
443 | } | 450 | } |
@@ -115,24 +115,26 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) { | @@ -115,24 +115,26 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) { | ||
115 | } | 115 | } |
116 | 116 | ||
117 | //SyncDataProductPlan 同步数据到 | 117 | //SyncDataProductPlan 同步数据到 |
118 | -func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64) error { | ||
119 | - sql := ` | 118 | +func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64, companyId, orgId int, orgName string) error { |
119 | + sql := fmt.Sprintf(` | ||
120 | INSERT INTO "manufacture"."product_plan"( | 120 | INSERT INTO "manufacture"."product_plan"( |
121 | + "company_id","org_id", | ||
121 | "product_plan_id","batch_number","product_date","workshop", | 122 | "product_plan_id","batch_number","product_date","workshop", |
122 | "plan_product_name","plan_devoted","plan_status","remark", | 123 | "plan_product_name","plan_devoted","plan_status","remark", |
123 | "ext","created_at","updated_at" | 124 | "ext","created_at","updated_at" |
124 | ) | 125 | ) |
125 | - SELECT prd_mo_k3cloud."join_product_plan_id",prd_mo_k3cloud."bill_no", | 126 | + SELECT ?,?, |
127 | + prd_mo_k3cloud."join_product_plan_id",prd_mo_k3cloud."bill_no", | ||
126 | prd_mo_k3cloud."plan_start_date", | 128 | prd_mo_k3cloud."plan_start_date", |
127 | json_build_object('workshopId',COALESCE("workshop"."workshop_id",0),'workshopName',prd_mo_k3cloud."work_shop_name"), | 129 | json_build_object('workshopId',COALESCE("workshop"."workshop_id",0),'workshopName',prd_mo_k3cloud."work_shop_name"), |
128 | prd_mo_k3cloud."material_name", json_build_object('unit',prd_mo_k3cloud."unit_name",'quantity',prd_mo_k3cloud."qty"), | 130 | prd_mo_k3cloud."material_name", json_build_object('unit',prd_mo_k3cloud."unit_name",'quantity',prd_mo_k3cloud."qty"), |
129 | 2,prd_mo_k3cloud."description", | 131 | 2,prd_mo_k3cloud."description", |
130 | - json_build_object('productPlanExt',json_build_object('productId',prd_mo_k3cloud."join_product_plan_id",'productCode',prd_mo_k3cloud."material_number",'productName',prd_mo_k3cloud."material_name")), | 132 | + json_build_object('orgName','%v','productPlanExt',json_build_object('productId',prd_mo_k3cloud."join_product_plan_id",'productCode',prd_mo_k3cloud."material_number",'productName',prd_mo_k3cloud."material_name")), |
131 | now(),now() | 133 | now(),now() |
132 | FROM "manufacture"."prd_mo_k3cloud" | 134 | FROM "manufacture"."prd_mo_k3cloud" |
133 | - LEFT JOIN "manufacture"."material_k3cloud" ON "prd_mo_k3cloud"."material_id"="material_k3cloud"."material_id" | ||
134 | - LEFT JOIN "manufacture"."workshop" ON "workshop"."workshop_name" = "prd_mo_k3cloud"."work_shop_name" | ||
135 | - WHERE prd_mo_k3cloud."data_version">=? | 135 | + -- LEFT JOIN "manufacture"."material_k3cloud" ON "prd_mo_k3cloud"."material_id"="material_k3cloud"."material_id" |
136 | + INNER JOIN "manufacture"."workshop" ON "workshop"."workshop_name" = "prd_mo_k3cloud"."work_shop_name" | ||
137 | + WHERE prd_mo_k3cloud."data_version">=? | ||
136 | ON conflict ("product_plan_id") DO | 138 | ON conflict ("product_plan_id") DO |
137 | UPDATE | 139 | UPDATE |
138 | SET ( | 140 | SET ( |
@@ -150,7 +152,7 @@ func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64) error { | @@ -150,7 +152,7 @@ func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64) error { | ||
150 | "product_plan"."ext"||EXCLUDED."ext", | 152 | "product_plan"."ext"||EXCLUDED."ext", |
151 | EXCLUDED."updated_at" | 153 | EXCLUDED."updated_at" |
152 | ) | 154 | ) |
153 | - ` | ||
154 | - _, err := d.transactionContext.PgTx.Exec(sql, version) | 155 | + `, orgName) |
156 | + _, err := d.transactionContext.PgTx.Exec(sql, companyId, orgId, version) | ||
155 | return err | 157 | return err |
156 | } | 158 | } |
@@ -31,8 +31,8 @@ func init() { | @@ -31,8 +31,8 @@ func init() { | ||
31 | web.BConfig.Listen.HTTPSPort = 443 | 31 | web.BConfig.Listen.HTTPSPort = 443 |
32 | 32 | ||
33 | //进程内监控 | 33 | //进程内监控 |
34 | - web.BConfig.Listen.EnableAdmin = true | ||
35 | - web.BConfig.Listen.AdminPort = 8088 | 34 | + //web.BConfig.Listen.EnableAdmin = true |
35 | + //web.BConfig.Listen.AdminPort = 8088 | ||
36 | if os.Getenv("HTTPS_PORT") != "" { | 36 | if os.Getenv("HTTPS_PORT") != "" { |
37 | portStr := os.Getenv("HTTPS_PORT") | 37 | portStr := os.Getenv("HTTPS_PORT") |
38 | if port, err := strconv.Atoi(portStr); err == nil { | 38 | if port, err := strconv.Atoi(portStr); err == nil { |
1 | package task | 1 | package task |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "github.com/hibiken/asynq" | 5 | "github.com/hibiken/asynq" |
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" |
@@ -11,6 +12,11 @@ import ( | @@ -11,6 +12,11 @@ import ( | ||
11 | ) | 12 | ) |
12 | 13 | ||
13 | func Run() { | 14 | func Run() { |
15 | + defer func() { | ||
16 | + if err := recover(); err != nil { | ||
17 | + fmt.Println(err) | ||
18 | + } | ||
19 | + }() | ||
14 | srv := asynq.NewServer( | 20 | srv := asynq.NewServer( |
15 | asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}, | 21 | asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS}, |
16 | asynq.Config{Concurrency: 1}, | 22 | asynq.Config{Concurrency: 1}, |
@@ -22,7 +28,7 @@ func Run() { | @@ -22,7 +28,7 @@ func Run() { | ||
22 | h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics) | 28 | h.HandleFunc(domain.TaskKeyWorkshopWorkTimeRecordStatics(), WorkshopWorkTimeRecordStatics) |
23 | h.HandleFunc(domain.TaskDeviceZkTecoReport(), WorkerAttendanceReport) | 29 | h.HandleFunc(domain.TaskDeviceZkTecoReport(), WorkerAttendanceReport) |
24 | h.HandleFunc(domain.TaskDeviceCollection(), WorkshopDataConsumer) | 30 | h.HandleFunc(domain.TaskDeviceCollection(), WorkshopDataConsumer) |
25 | - log.Logger.Info("aysnq task running ...") | 31 | + log.Logger.Info("aysnq task start!") |
26 | // Run blocks and waits for os signal to terminate the program. | 32 | // Run blocks and waits for os signal to terminate the program. |
27 | if err := srv.Run(h); err != nil { | 33 | if err := srv.Run(h); err != nil { |
28 | log.Logger.Error(err.Error()) | 34 | log.Logger.Error(err.Error()) |
-
请 注册 或 登录 后发表评论