作者 tangxuhui

更新 同步数据需要的sql

... ... @@ -331,6 +331,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
"FRowId", "FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
"FMaterialId.FNumber", "FMaterialId.FSpecification", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
"FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName", "FUnitId", "FUnitId.FName", "FDescription",
"FStatus",
}
var (
startRow int
... ... @@ -366,7 +367,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
prdMoModels []models.PrdMoK3cloud
prdMoTemp models.PrdMoK3cloud
)
nowTime := time.Now()
version := time.Now().Unix()
for _, item := range allResult {
workShopID, _ := strconv.Atoi(item["FWorkShopID"])
materialId, _ := strconv.Atoi(item["FMaterialId"])
... ... @@ -378,6 +379,7 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
fCreateDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FCreateDate"])
fModifyDate, _ := time.Parse("2006-01-02T15:04:05.999", item["FModifyDate"])
fUnitId, _ := strconv.Atoi(item["FUnitId"])
status, _ := strconv.Atoi(item["FStatus"])
prdMoTemp = models.PrdMoK3cloud{
RowId: item["FRowId"],
WorkShopID: workShopID,
... ... @@ -392,13 +394,14 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
WorkShopName: item["FWorkShopID.FName"],
MaterialName: item["FMaterialId.FName"],
MaterialNumber: item["FMaterialId.FNumber"],
DataVersion: nowTime.Unix(),
DataVersion: version,
PrdOrgId: fPrdOrgId,
PrdOrgName: item["FPrdOrgId.FName"],
Specification: item["FMaterialId.FSpecification"],
UnitName: item["FUnitId.FName"],
UnitId: fUnitId,
Description: item["FDescription"],
Status: status,
}
prdMoModels = append(prdMoModels, prdMoTemp)
}
... ... @@ -424,7 +427,11 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//同步ProductPlan 表数据
err = prdMoDao.SyncDataProductPlan(version)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err = transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -115,6 +115,42 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) {
}
//SyncDataProductPlan 同步数据到
func (d *PrdMoK3cloudDao) SyncDataProductPlan() {
func (d *PrdMoK3cloudDao) SyncDataProductPlan(version int64) error {
sql := `
INSERT INTO "manufacture"."product_plan"(
"product_plan_id","batch_number","product_date","workshop",
"plan_product_name","plan_devoted","plan_status","remark",
"ext","created_at","updated_at"
)
SELECT prd_mo_k3cloud."join_product_plan_id",prd_mo_k3cloud."bill_no",
prd_mo_k3cloud."plan_start_date",
json_build_object('workshopId',"workshop"."workshop_id",'workshopName',prd_mo_k3cloud."work_shop_name"),
prd_mo_k3cloud."material_name", json_build_object('unit',prd_mo_k3cloud."unit_name",'quantity',prd_mo_k3cloud."qty"),
2,prd_mo_k3cloud."description",
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")),
now(),now()
FROM "manufacture"."prd_mo_k3cloud"
LEFT JOIN "material_k3cloud" ON "prd_mo_k3cloud"."material_number"="material_k3cloud"."number"
LEFT JOIN "workshop" ON "workshop"."workshop_name" = "prd_mo_k3cloud"."work_shop_name"
WHERE prd_mo_k3cloud."data_version"=?
ON conflict ("product_plan_id") DO
UPDATE
SET (
"batch_number","product_date","workshop",
"plan_product_name","plan_devoted","plan_status","remark",
"ext","updated_at"
)=(
EXCLUDED."batch_number",
EXCLUDED."product_date",
"product_plan"."workshop"||EXCLUDED."workshop",
EXCLUDED."plan_product_name",
EXCLUDED."plan_devoted",
EXCLUDED."plan_status",
EXCLUDED."remark",
"product_plan"."ext"||EXCLUDED."ext",
EXCLUDED."updated_at"
)
`
_, err := d.transactionContext.PgTx.Exec(sql, version)
return err
}
... ...
... ... @@ -26,5 +26,6 @@ type PrdMoK3cloud struct {
UnitId int `comment:"单位id" pg:"unit_id"`
Specification string `comment:"规格型号" pg:"specification"`
Description string `comment:"备注" pg:"description"`
Status int `comment:"业务状态" pg:"status"`
JoinProductPlanId int `comment:"计划管理表的id" pg:"join_product_plan_id"`
}
... ...
... ... @@ -50,17 +50,18 @@
### 生产订单字段描述(部分)
| 字段名 | 备注 | 类型 |
| ------------------- | ------------------------------------- | ------ |
| FBillNo | 订单编号 | 字符串 |
| FWorkShopID | 生产车间 | 数字 |
| FWorkShopID.FName | 生产车间 | 字符串 |
| FMaterialId | 物料 | 数字 |
| FPlanStartDate | 计划开工时间,如"2021-12-20T00:00:00" | 字符串 |
| FPlanFinishDate | 计划完工时间,如"2021-12-20T00:00:00" | 字符串 |
| FMaterialId.FName | 物料名称 | 字符串 |
| FMaterialId.FNumber | 物料编码 | 字符串 |
| FDate | 单据日期,如"2021-12-20T00:00:00" | 字符串 |
| FQty | 数量,如 15.5000000000 | 小数 |
| FID | id | 数字 |
| FPrdOrgId | 生产组织 | 数字 |
| 字段名 | 备注 | 类型 |
| ------------------- | ----------------------------------------------------------- | ------ |
| FBillNo | 订单编号 | 字符串 |
| FWorkShopID | 生产车间 | 数字 |
| FWorkShopID.FName | 生产车间 | 字符串 |
| FMaterialId | 物料 | 数字 |
| FPlanStartDate | 计划开工时间,如"2021-12-20T00:00:00" | 字符串 |
| FPlanFinishDate | 计划完工时间,如"2021-12-20T00:00:00" | 字符串 |
| FMaterialId.FName | 物料名称 | 字符串 |
| FMaterialId.FNumber | 物料编码 | 字符串 |
| FDate | 单据日期,如"2021-12-20T00:00:00" | 字符串 |
| FQty | 数量,如 15.5000000000 | 小数 |
| FID | id | 数字 |
| FPrdOrgId | 生产组织 | 数字 |
| FStatus | 业务状态,1 计划,2 计划确认,3 下达,4 开工,5 完工,6 结案,结算 | 数字 |
... ...