...
|
...
|
@@ -64,22 +64,22 @@ func (d *MaterialK3cloudDao) SyncDataMaterialK3cloud(data []models.MaterialK3clo |
|
|
if data[i].CreateDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].CreateDate.String()+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].CreateDate.Format("2006-01-02 15:04:05.999")+`'`)
|
|
|
}
|
|
|
if data[i].ModifyDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ModifyDate.String()+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].ModifyDate.Format("2006-01-02 15:04:05.999")+`'`)
|
|
|
}
|
|
|
if data[i].ForbidDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ForbidDate.String()+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].ForbidDate.Format("2006-01-02 15:04:05.999")+`'`)
|
|
|
}
|
|
|
if data[i].ApproveDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ApproveDate.String()+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].ApproveDate.Format("2006-01-02 15:04:05.999")+`'`)
|
|
|
}
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].MaterialGroup))
|
|
|
strTemp = append(strTemp, `'`+data[i].MaterialGroupNumber+`'`)
|
...
|
...
|
@@ -89,22 +89,24 @@ func (d *MaterialK3cloudDao) SyncDataMaterialK3cloud(data []models.MaterialK3clo |
|
|
strTemp = append(strTemp, "nextval('manufacture.product_product_id_seq'::regclass)")
|
|
|
strTemp = append(strTemp, strconv.Itoa(int(data[i].DataVersion)))
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].UseOrgId))
|
|
|
strTemp = append(strTemp, `'`+data[i].UseOrgName+`'`)
|
|
|
sqlValues = append(sqlValues, "("+strings.Join(strTemp, ",")+")")
|
|
|
|
|
|
}
|
|
|
var valueTemp []string
|
|
|
fmt.Println("总数", len(data))
|
|
|
for i := 0; i < len(sqlValues); i += 100 {
|
|
|
if i < len(sqlValues)-100 {
|
|
|
valueTemp = sqlValues[i:100]
|
|
|
if i <= len(sqlValues)-100 {
|
|
|
valueTemp = sqlValues[i : i+100]
|
|
|
} else {
|
|
|
valueTemp = sqlValues[i:]
|
|
|
valueTemp = sqlValues[i-100:]
|
|
|
}
|
|
|
sql := `INSERT INTO "manufacture"."material_k3cloud" (
|
|
|
"material_id","name","number","specification","forbid_status",
|
|
|
"erp_cls_id","base_unit_id","base_unit_name","create_date",
|
|
|
"modify_date","forbid_date","approve_date","material_group",
|
|
|
"material_group_number","material_group_name","ref_status ",
|
|
|
"join_product_id","data_version","use_org_id" )
|
|
|
"material_group_number","material_group_name","ref_status",
|
|
|
"join_product_id","data_version","use_org_id","use_org_name" )
|
|
|
VALUES ` + strings.Join(valueTemp, ",") +
|
|
|
` ON conflict ( material_id ) DO
|
|
|
UPDATE
|
...
|
...
|
@@ -112,13 +114,13 @@ func (d *MaterialK3cloudDao) SyncDataMaterialK3cloud(data []models.MaterialK3clo |
|
|
"name","number","specification","forbid_status","erp_cls_id",
|
|
|
"base_unit_id","base_unit_name","create_date","modify_date",
|
|
|
"forbid_date","approve_date","material_group","material_group_number",
|
|
|
"material_group_name","ref_status ","data_version" ) = (
|
|
|
"material_group_name","ref_status","data_version","use_org_id","use_org_name" ) = (
|
|
|
EXCLUDED."name",EXCLUDED."number",EXCLUDED."specification",
|
|
|
EXCLUDED."forbid_status",EXCLUDED."erp_cls_id",EXCLUDED."base_unit_id",
|
|
|
EXCLUDED."base_unit_name",EXCLUDED."create_date",EXCLUDED."modify_date",
|
|
|
EXCLUDED."forbid_date",EXCLUDED."approve_date",EXCLUDED."material_group",
|
|
|
EXCLUDED."material_group_number",EXCLUDED."material_group_name",
|
|
|
EXCLUDED."ref_status ",EXCLUDED."data_version" )`
|
|
|
EXCLUDED."ref_status",EXCLUDED."data_version",EXCLUDED."use_org_id",EXCLUDED."use_org_name")`
|
|
|
_, err := d.transactionContext.PgTx.Exec(sql)
|
|
|
if err != nil {
|
|
|
return err
|
...
|
...
|
@@ -137,12 +139,12 @@ func (d *MaterialK3cloudDao) SyncDataProudct(version int64) error { |
|
|
)
|
|
|
SELECT 0,use_org_id,"join_product_id","number","name","material_group_name",
|
|
|
json_build_object('unit',specification),now(),now()
|
|
|
FROM "manufacture"."material_k3cloud" WHERE "data_version"=?
|
|
|
FROM "manufacture"."material_k3cloud" WHERE "data_version"=? AND "material_group_number" LIKE '05%'
|
|
|
ON conflict ( product_id ) DO
|
|
|
UPDATE
|
|
|
SET (
|
|
|
"company_id", "org_id", "product_id", "product_code", "product_name",
|
|
|
"product_category", "product_spec", "created_at", "updated_at")=(
|
|
|
"product_category", "product_spec", "updated_at")=(
|
|
|
EXCLUDED."company_id", EXCLUDED."org_id",EXCLUDED."product_id",
|
|
|
EXCLUDED."product_code",EXCLUDED."product_name",EXCLUDED."product_category",
|
|
|
EXCLUDED."product_spec", EXCLUDED."updated_at") `
|
...
|
...
|
|