作者 tangxuhui

更新 拉取 生产订单数据

... ... @@ -328,9 +328,9 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
fieldKeys := []string{
"FID", "FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
"FMaterialId.FNumber", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
"FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName",
"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",
}
var (
startRow int
... ... @@ -368,21 +368,18 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
)
nowTime := time.Now()
for _, item := range allResult {
id, err := strconv.Atoi(item["FID"])
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
workShopID, _ := strconv.Atoi(item["WorkShopID"])
materialId, _ := strconv.Atoi(item["MaterialId"])
qty, _ := strconv.ParseFloat(item["Qty"], 64)
workShopID, _ := strconv.Atoi(item["FWorkShopID"])
materialId, _ := strconv.Atoi(item["FMaterialId"])
qty, _ := strconv.ParseFloat(item["FQty"], 64)
fPrdOrgId, _ := strconv.Atoi(item["FPrdOrgId"])
planStartDate, _ := time.Parse("2006-01-02T15:04:05", item["FPlanStartDate"])
planFinishDate, _ := time.Parse("2006-01-02T15:04:05", item["FPlanFinishDate"])
fDate, _ := time.Parse("2006-01-02T15:04:05", item["FDate"])
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"])
prdMoTemp = models.PrdMoK3cloud{
Id: id,
RowId: item["FRowId"],
WorkShopID: workShopID,
MaterialId: materialId,
Qty: qty,
... ... @@ -398,6 +395,10 @@ func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
DataVersion: nowTime.Unix(),
PrdOrgId: fPrdOrgId,
PrdOrgName: item["FPrdOrgId.FName"],
Specification: item["FMaterialId.FSpecification"],
UnitName: item["FUnitId.FName"],
UnitId: fUnitId,
Description: item["FDescription"],
}
prdMoModels = append(prdMoModels, prdMoTemp)
}
... ...
... ... @@ -30,8 +30,8 @@ func (d *PrdMoK3cloudDao) SyncDataPrdMoK3cloud(data []models.PrdMoK3cloud) error
sqlValues := []string{}
var strTemp []string
for i := range data {
strTemp = make([]string, 0, 5)
strTemp = append(strTemp, strconv.Itoa(data[i].Id))
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+`'`)
... ... @@ -47,6 +47,12 @@ func (d *PrdMoK3cloudDao) SyncDataPrdMoK3cloud(data []models.PrdMoK3cloud) error
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
... ... @@ -57,28 +63,32 @@ func (d *PrdMoK3cloudDao) SyncDataPrdMoK3cloud(data []models.PrdMoK3cloud) error
valueTemp = sqlValues[i:]
}
sql := `INSERT INTO "manufacture"."prd_mo_k3cloud" (
"id","bill_no","work_shop_id","work_shop_name",
"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")
"prd_org_id","prd_org_name","unit_name","unit_id",
"specification","description","join_product_plan_id")
VALUES ` +
strings.Join(valueTemp, ",") +
` ON conflict ( "id" ) DO
` 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") = (
"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."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 {
... ... @@ -103,3 +113,8 @@ func (d *PrdMoK3cloudDao) GetLastVersion() (int64, error) {
}
return prdMoData[0].DataVersion, nil
}
//SyncDataProductPlan 同步数据到
func (d *PrdMoK3cloudDao) SyncDataProductPlan() {
}
... ...
... ... @@ -9,7 +9,7 @@ type MaterialK3cloud struct {
Name string `comment:"物料名称" pg:"name"`
Number string `comment:"物料编码" pg:"number"`
Specification string `comment:"规格型号" pg:"specification"`
ForbidStatus string `comment:"禁用状态,"A":否,"B":是" pg:"forbid_status"`
ForbidStatus string `comment:"禁用状态,A:否,B:是" pg:"forbid_status"`
ErpClsId int `comment:"物料属性" pg:"erp_cls_id"`
BaseUnitId int `comment:"基本单位" pg:"base_unit_id"`
BaseUnitName string `comment:"基本单位名称" pg:"base_unit_name"`
... ...
... ... @@ -5,21 +5,26 @@ import "time"
//计划订单
//PrdMoK3cloud ..
type PrdMoK3cloud struct {
tableName string `comment:"采集自金蝶k3cloud计划订单" pg:"manufacture.prd_mo_k3cloud,alias:prd_mo_k3cloud"`
Id int `pg:",pk"`
BillNo string `comment:"订单编号" pg:"bill_no"`
WorkShopID int `comment:"生产车间" pg:"work_shop_id"`
WorkShopName string `comment:"生产车间名称" pg:"work_shop_name"`
MaterialId int `comment:"物料" pg:"material_id"`
MaterialName string `comment:"物料名称" pg:"material_name"`
MaterialNumber string `comment:"物料名称" pg:"material_number"`
PlanStartDate time.Time `comment:"计划开工时间" pg:"plan_start_date"`
PlanFinishDate time.Time `comment:"计划完工时间" pg:"plan_finish_date"`
FDate time.Time `comment:"单据日期" pg:"f_date"`
Qty float64 `comment:"数量" pg:"qty"`
CreateDate time.Time `comment:"创建时间" pg:"create_date"`
ModifyDate time.Time `comment:"修改时间" pg:"modify_date"`
DataVersion int64 `comment:"数据版本" pg:"data_version"`
PrdOrgId int `comment:"生产组织" pg:"prd_org_id"`
PrdOrgName string `comment:"生产组织名称" pg:"prd_org_name"`
tableName string `comment:"采集自金蝶k3cloud计划订单" pg:"manufacture.prd_mo_k3cloud,alias:prd_mo_k3cloud"`
RowId string `pg:",pk"`
BillNo string `comment:"订单编号" pg:"bill_no"`
WorkShopID int `comment:"生产车间" pg:"work_shop_id"`
WorkShopName string `comment:"生产车间名称" pg:"work_shop_name"`
MaterialId int `comment:"物料" pg:"material_id"`
MaterialName string `comment:"物料名称" pg:"material_name"`
MaterialNumber string `comment:"物料名称" pg:"material_number"`
PlanStartDate time.Time `comment:"计划开工时间" pg:"plan_start_date"`
PlanFinishDate time.Time `comment:"计划完工时间" pg:"plan_finish_date"`
FDate time.Time `comment:"单据日期" pg:"f_date"`
Qty float64 `comment:"数量" pg:"qty"`
CreateDate time.Time `comment:"创建时间" pg:"create_date"`
ModifyDate time.Time `comment:"修改时间" pg:"modify_date"`
DataVersion int64 `comment:"数据版本" pg:"data_version"`
PrdOrgId int `comment:"生产组织" pg:"prd_org_id"`
PrdOrgName string `comment:"生产组织名称" pg:"prd_org_name"`
UnitName string `comment:"单位名称" pg:"unit_name"`
UnitId int `comment:"单位id" pg:"unit_id"`
Specification string `comment:"规格型号" pg:"specification"`
Description string `comment:"备注" pg:"description"`
JoinProductPlanId int `comment:"计划管理表的id" pg:"join_product_plan_id"`
}
... ...
... ... @@ -65,16 +65,17 @@ func TestExecuteBillQuery2(t *testing.T) {
return
}
fieldKeys := []string{
"FID", "FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
"FMaterialId.FNumber", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
"FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName",
"FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
"FMaterialId.FNumber", "FMaterialId.FSpecification", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
"FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName", "FRowId", "FUnitId", "FUnitId.FName", "FDescription",
}
result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
FormId: "PRD_MO",
Data: ExecuteBillQueryData{
FormId: "PRD_MO",
FieldKeys: strings.Join(fieldKeys, ","), //查询的字段
TopRowCount: 2,
FormId: "PRD_MO",
FieldKeys: strings.Join(fieldKeys, ","), //查询的字段
TopRowCount: 4,
FilterString: "",
},
})
... ...