作者 tangxuhui

更新 同步数据需要的sql

@@ -331,6 +331,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { @@ -331,6 +331,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
331 "FRowId", "FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName", 331 "FRowId", "FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
332 "FMaterialId.FNumber", "FMaterialId.FSpecification", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty", 332 "FMaterialId.FNumber", "FMaterialId.FSpecification", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
333 "FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName", "FUnitId", "FUnitId.FName", "FDescription", 333 "FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName", "FUnitId", "FUnitId.FName", "FDescription",
  334 + "FStatus",
334 } 335 }
335 var ( 336 var (
336 startRow int 337 startRow int
@@ -366,7 +367,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { @@ -366,7 +367,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
366 prdMoModels []models.PrdMoK3cloud 367 prdMoModels []models.PrdMoK3cloud
367 prdMoTemp models.PrdMoK3cloud 368 prdMoTemp models.PrdMoK3cloud
368 ) 369 )
369 - nowTime := time.Now() 370 + version := time.Now().Unix()
370 for _, item := range allResult { 371 for _, item := range allResult {
371 workShopID, _ := strconv.Atoi(item["FWorkShopID"]) 372 workShopID, _ := strconv.Atoi(item["FWorkShopID"])
372 materialId, _ := strconv.Atoi(item["FMaterialId"]) 373 materialId, _ := strconv.Atoi(item["FMaterialId"])
@@ -378,6 +379,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { @@ -378,6 +379,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
378 fCreateDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FCreateDate"]) 379 fCreateDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FCreateDate"])
379 fModifyDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FModifyDate"]) 380 fModifyDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FModifyDate"])
380 fUnitId, _ := strconv.Atoi(item["FUnitId"]) 381 fUnitId, _ := strconv.Atoi(item["FUnitId"])
  382 + status, _ := strconv.Atoi(item["FStatus"])
381 prdMoTemp = models.PrdMoK3cloud{ 383 prdMoTemp = models.PrdMoK3cloud{
382 RowId: item["FRowId"], 384 RowId: item["FRowId"],
383 WorkShopID: workShopID, 385 WorkShopID: workShopID,
@@ -392,13 +394,14 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { @@ -392,13 +394,14 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
392 WorkShopName: item["FWorkShopID.FName"], 394 WorkShopName: item["FWorkShopID.FName"],
393 MaterialName: item["FMaterialId.FName"], 395 MaterialName: item["FMaterialId.FName"],
394 MaterialNumber: item["FMaterialId.FNumber"], 396 MaterialNumber: item["FMaterialId.FNumber"],
395 - DataVersion: nowTime.Unix(), 397 + DataVersion: version,
396 PrdOrgId: fPrdOrgId, 398 PrdOrgId: fPrdOrgId,
397 PrdOrgName: item["FPrdOrgId.FName"], 399 PrdOrgName: item["FPrdOrgId.FName"],
398 Specification: item["FMaterialId.FSpecification"], 400 Specification: item["FMaterialId.FSpecification"],
399 UnitName: item["FUnitId.FName"], 401 UnitName: item["FUnitId.FName"],
400 UnitId: fUnitId, 402 UnitId: fUnitId,
401 Description: item["FDescription"], 403 Description: item["FDescription"],
  404 + Status: status,
402 } 405 }
403 prdMoModels = append(prdMoModels, prdMoTemp) 406 prdMoModels = append(prdMoModels, prdMoTemp)
404 } 407 }
@@ -424,7 +427,11 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error { @@ -424,7 +427,11 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
424 if err != nil { 427 if err != nil {
425 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 428 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
426 } 429 }
427 - 430 + //同步ProductPlan 表数据
  431 + err = prdMoDao.SyncDataProductPlan(version)
  432 + if err != nil {
  433 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  434 + }
428 if err = transactionContext.CommitTransaction(); err != nil { 435 if err = transactionContext.CommitTransaction(); err != nil {
429 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 436 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
430 } 437 }
@@ -115,6 +115,42 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) { @@ -115,6 +115,42 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) {
115 } 115 }
116 116
117 //SyncDataProductPlan 同步数据到 117 //SyncDataProductPlan 同步数据到
118 -func (d *PrdMoK3cloudDao) SyncDataProductPlan() {  
119 - 118 +func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64) error {
  119 + sql := `
  120 + INSERT INTO "manufacture"."product_plan"(
  121 + "product_plan_id","batch_number","product_date","workshop",
  122 + "plan_product_name","plan_devoted","plan_status","remark",
  123 + "ext","created_at","updated_at"
  124 + )
  125 + SELECT prd_mo_k3cloud."join_product_plan_id",prd_mo_k3cloud."bill_no",
  126 + prd_mo_k3cloud."plan_start_date",
  127 + json_build_object('workshopId',"workshop"."workshop_id",'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"),
  129 + 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")),
  131 + now(),now()
  132 + FROM "manufacture"."prd_mo_k3cloud"
  133 + LEFT JOIN "material_k3cloud" ON "prd_mo_k3cloud"."material_number"="material_k3cloud"."number"
  134 + LEFT JOIN "workshop" ON "workshop"."workshop_name" = "prd_mo_k3cloud"."work_shop_name"
  135 + WHERE prd_mo_k3cloud."data_version"=?
  136 + ON conflict ("product_plan_id") DO
  137 + UPDATE
  138 + SET (
  139 + "batch_number","product_date","workshop",
  140 + "plan_product_name","plan_devoted","plan_status","remark",
  141 + "ext","updated_at"
  142 + )=(
  143 + EXCLUDED."batch_number",
  144 + EXCLUDED."product_date",
  145 + "product_plan"."workshop"||EXCLUDED."workshop",
  146 + EXCLUDED."plan_product_name",
  147 + EXCLUDED."plan_devoted",
  148 + EXCLUDED."plan_status",
  149 + EXCLUDED."remark",
  150 + "product_plan"."ext"||EXCLUDED."ext",
  151 + EXCLUDED."updated_at"
  152 + )
  153 + `
  154 + _, err := d.transactionContext.PgTx.Exec(sql, version)
  155 + return err
120 } 156 }
@@ -26,5 +26,6 @@ type PrdMoK3cloud struct { @@ -26,5 +26,6 @@ type PrdMoK3cloud struct {
26 UnitId int `comment:"单位id" pg:"unit_id"` 26 UnitId int `comment:"单位id" pg:"unit_id"`
27 Specification string `comment:"规格型号" pg:"specification"` 27 Specification string `comment:"规格型号" pg:"specification"`
28 Description string `comment:"备注" pg:"description"` 28 Description string `comment:"备注" pg:"description"`
  29 + Status int `comment:"业务状态" pg:"status"`
29 JoinProductPlanId int `comment:"计划管理表的id" pg:"join_product_plan_id"` 30 JoinProductPlanId int `comment:"计划管理表的id" pg:"join_product_plan_id"`
30 } 31 }
@@ -51,7 +51,7 @@ @@ -51,7 +51,7 @@
51 ### 生产订单字段描述(部分) 51 ### 生产订单字段描述(部分)
52 52
53 | 字段名 | 备注 | 类型 | 53 | 字段名 | 备注 | 类型 |
54 -| ------------------- | ------------------------------------- | ------ | 54 +| ------------------- | ----------------------------------------------------------- | ------ |
55 | FBillNo | 订单编号 | 字符串 | 55 | FBillNo | 订单编号 | 字符串 |
56 | FWorkShopID | 生产车间 | 数字 | 56 | FWorkShopID | 生产车间 | 数字 |
57 | FWorkShopID.FName | 生产车间 | 字符串 | 57 | FWorkShopID.FName | 生产车间 | 字符串 |
@@ -64,3 +64,4 @@ @@ -64,3 +64,4 @@
64 | FQty | 数量,如 15.5000000000 | 小数 | 64 | FQty | 数量,如 15.5000000000 | 小数 |
65 | FID | id | 数字 | 65 | FID | id | 数字 |
66 | FPrdOrgId | 生产组织 | 数字 | 66 | FPrdOrgId | 生产组织 | 数字 |
  67 +| FStatus | 业务状态,1 计划,2 计划确认,3 下达,4 开工,5 完工,6 结案,结算 | 数字 |