...
|
...
|
@@ -23,93 +23,35 @@ func NewMaterialGroupK3cloudDao(transactionContext *pgTransaction.TransactionCon |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (d *MaterialGroupK3cloudDao) GetLastVersion() (int64, error) {
|
|
|
var materialData []models.MaterialK3cloud
|
|
|
err := d.transactionContext.PgTx.Model(&materialData).
|
|
|
Order("data_version DESC").
|
|
|
Limit(1).
|
|
|
Select()
|
|
|
if err != nil {
|
|
|
return 0, err
|
|
|
}
|
|
|
if len(materialData) == 0 {
|
|
|
return 0, nil
|
|
|
}
|
|
|
return materialData[0].DataVersion, nil
|
|
|
}
|
|
|
|
|
|
//SyncDataMaterialK3cloud 同步MaterialK3cloud表数据
|
|
|
func (d *MaterialGroupK3cloudDao) SyncDataMaterialK3cloud(data []models.MaterialK3cloud) error {
|
|
|
//SyncDataMaterialGroupK3cloud 同步MaterialGroupK3cloud表 物料分组数据
|
|
|
func (d *MaterialGroupK3cloudDao) SyncDataMaterialGroupK3cloud(data []models.MaterialGroupK3cloud) error {
|
|
|
sqlValues := []string{}
|
|
|
var strTemp []string
|
|
|
for i := range data {
|
|
|
strTemp = make([]string, 0, 18)
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].MaterialId))
|
|
|
strTemp = append(strTemp, `'`+data[i].Name+`'`)
|
|
|
strTemp = make([]string, 0, 5)
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].Id))
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].ParentId))
|
|
|
strTemp = append(strTemp, `'`+data[i].Number+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].Specification+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].ForbidStatus+`'`)
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].ErpClsId))
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].BaseUnitId))
|
|
|
strTemp = append(strTemp, `'`+data[i].BaseUnitName+`'`)
|
|
|
if data[i].CreateDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].CreateDate.String()+`'`)
|
|
|
}
|
|
|
if data[i].ModifyDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ModifyDate.String()+`'`)
|
|
|
}
|
|
|
if data[i].ForbidDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ForbidDate.String()+`'`)
|
|
|
}
|
|
|
if data[i].ApproveDate.IsZero() {
|
|
|
strTemp = append(strTemp, `NULL`)
|
|
|
} else {
|
|
|
strTemp = append(strTemp, `'`+data[i].ApproveDate.String()+`'`)
|
|
|
}
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].MaterialGroup))
|
|
|
strTemp = append(strTemp, `'`+data[i].MaterialGroupNumber+`'`)
|
|
|
strTemp = append(strTemp, `'`+data[i].MaterialGroupName+`'`)
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].RefStatus))
|
|
|
//关联的产品表id ,使用 product 产品表的自增序列表
|
|
|
strTemp = append(strTemp, "nextval('manufacture.product_product_id_seq'::regclass)")
|
|
|
strTemp = append(strTemp, `'`+data[i].Name+`'`)
|
|
|
strTemp = append(strTemp, strconv.Itoa(int(data[i].DataVersion)))
|
|
|
strTemp = append(strTemp, strconv.Itoa(data[i].UseOrgId))
|
|
|
sqlValues = append(sqlValues, "("+strings.Join(strTemp, ",")+")")
|
|
|
|
|
|
}
|
|
|
var valueTemp []string
|
|
|
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:]
|
|
|
}
|
|
|
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" )
|
|
|
VALUES ` + strings.Join(valueTemp, ",") +
|
|
|
` ON conflict ( material_id ) DO
|
|
|
sql := `INSERT INTO "manufacture"."material_group_k3cloud" (
|
|
|
"id","parent_id","number","name","data_version")
|
|
|
VALUES ` + strings.Join(valueTemp, ",") + `
|
|
|
ON conflict ( "id" ) DO
|
|
|
UPDATE
|
|
|
SET (
|
|
|
"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" ) = (
|
|
|
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" )`
|
|
|
"parent_id","number","name","data_version") = (
|
|
|
EXCLUDED."parent_id",EXCLUDED."number",
|
|
|
EXCLUDED."name",EXCLUDED."data_version" )`
|
|
|
_, err := d.transactionContext.PgTx.Exec(sql)
|
|
|
if err != nil {
|
|
|
return err
|
...
|
...
|
|