prd_mo_k3cloud.go
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package dao
import (
"fmt"
"strconv"
"strings"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
)
//
type PrdMoK3cloudDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewPrdMoK3cloudDao(transactionContext *pgTransaction.TransactionContext) (*PrdMoK3cloudDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PrdMoK3cloudDao{
transactionContext: transactionContext,
}, nil
}
}
//SyncDataPrdMoK3cloud 同步PrdMoK3cloud表数据
func (d *PrdMoK3cloudDao) SyncDataPrdMoK3cloud(data []models.PrdMoK3cloud) error {
//插入或者更新
sqlValues := []string{}
var strTemp []string
for i := range data {
strTemp = make([]string, 0, 15)
strTemp = append(strTemp, `'`+data[i].RowId+`'`)
strTemp = append(strTemp, `'`+data[i].BillNo+`'`)
strTemp = append(strTemp, strconv.Itoa(data[i].WorkShopID))
strTemp = append(strTemp, `'`+data[i].WorkShopName+`'`)
strTemp = append(strTemp, strconv.Itoa(data[i].MaterialId))
strTemp = append(strTemp, `'`+data[i].MaterialName+`'`)
strTemp = append(strTemp, `'`+data[i].MaterialNumber+`'`)
strTemp = append(strTemp, `'`+data[i].PlanStartDate.Format("2006-01-02 15:04:05.999")+`'`)
strTemp = append(strTemp, `'`+data[i].PlanFinishDate.Format("2006-01-02 15:04:05.999")+`'`)
strTemp = append(strTemp, `'`+data[i].FDate.Format("2006-01-02 15:04:05.999")+`'`)
strTemp = append(strTemp, fmt.Sprintf("%.10f", data[i].Qty)) //15.5000000000
strTemp = append(strTemp, `'`+data[i].CreateDate.Format("2006-01-02 15:04:05.999")+`'`)
strTemp = append(strTemp, `'`+data[i].ModifyDate.Format("2006-01-02 15:04:05.999")+`'`)
strTemp = append(strTemp, strconv.Itoa(int(data[i].DataVersion)))
strTemp = append(strTemp, strconv.Itoa(data[i].PrdOrgId))
strTemp = append(strTemp, `'`+data[i].PrdOrgName+`'`)
strTemp = append(strTemp, `'`+data[i].UnitName+`'`)
strTemp = append(strTemp, strconv.Itoa(data[i].UnitId))
strTemp = append(strTemp, `'`+data[i].Specification+`'`)
strTemp = append(strTemp, `'`+data[i].Description+`'`)
//关联的计划管理表id ,使用 product_plan 产品表的自增序列表
strTemp = append(strTemp, "nextval('manufacture.product_plan_product_plan_id_seq'::regclass)")
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 : i+100]
} else {
valueTemp = sqlValues[i:]
}
sql := `INSERT INTO "manufacture"."prd_mo_k3cloud" (
"row_id","bill_no","work_shop_id","work_shop_name",
"material_id","material_name","material_number",
"plan_start_date","plan_finish_date","f_date",
"qty","create_date","modify_date","data_version",
"prd_org_id","prd_org_name","unit_name","unit_id",
"specification","description","join_product_plan_id")
VALUES ` +
strings.Join(valueTemp, ",") +
` ON conflict ( "row_id" ) DO
UPDATE
SET (
"bill_no","work_shop_id","work_shop_name",
"material_id","material_name","material_number",
"plan_start_date","plan_finish_date","f_date",
"qty","create_date","modify_date","data_version",
"prd_org_id","prd_org_name","unit_name","unit_id",
"specification","description") = (
EXCLUDED."bill_no",EXCLUDED."work_shop_id",
EXCLUDED."work_shop_name",EXCLUDED."material_id",
EXCLUDED."material_name",EXCLUDED."material_number",
EXCLUDED."plan_start_date",EXCLUDED."plan_finish_date",
EXCLUDED."f_date",EXCLUDED."qty",EXCLUDED."create_date",
EXCLUDED."modify_date",EXCLUDED."data_version",
EXCLUDED."prd_org_id",EXCLUDED."prd_org_name",
EXCLUDED."unit_name",EXCLUDED."unit_id",
EXCLUDED."specification",EXCLUDED."description"
)`
_, err := d.transactionContext.PgTx.Exec(sql)
if err != nil {
return err
}
}
return nil
}
func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) {
var prdMoData []models.PrdMoK3cloud
err := d.transactionContext.PgTx.Model(&prdMoData).
Order("data_version DESC").
Limit(1).
Select()
if err != nil {
return 0, err
}
if len(prdMoData) == 0 {
return 0, nil
}
return prdMoData[0].DataVersion, nil
}
//SyncDataProductPlan 同步数据到
func (d *PrdMoK3cloudDao) SyncDataProductPlan() {
}