...
|
...
|
@@ -276,3 +276,156 @@ func (srv *PullDataK3CloudService) PullMaterialGroup() error { |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PullPrdMoNewest 拉取生产订单数据
|
|
|
func (srv *PullDataK3CloudService) PullPrdMoNewest() error {
|
|
|
var (
|
|
|
err error
|
|
|
prdMoDao *dao.PrdMoK3cloudDao
|
|
|
)
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
prdMoDao, err = dao.NewPrdMoK3cloudDao(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
version, err := prdMoDao.GetLastVersion()
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
var timeFilter time.Time
|
|
|
if version > 0 {
|
|
|
timeFilter = time.Unix(version, 0)
|
|
|
}
|
|
|
err = srv.PullPrdMo(timeFilter)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
//PullPrdMo 拉取生产订单数据
|
|
|
func (srv *PullDataK3CloudService) PullPrdMo(timeFilter time.Time) error {
|
|
|
//拉取数据
|
|
|
var filterString []string
|
|
|
if !timeFilter.IsZero() {
|
|
|
str := timeFilter.Format("2006-01-02T15:04:05")
|
|
|
filterString = append(filterString, "FModifyDate>='"+str+"'")
|
|
|
}
|
|
|
client, err := newK3cloudClient()
|
|
|
if err != nil {
|
|
|
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",
|
|
|
}
|
|
|
var (
|
|
|
startRow int
|
|
|
allResult []map[string]string
|
|
|
queryErr error
|
|
|
)
|
|
|
for {
|
|
|
result, err := client.ExecuteBillQuery(k3cloud.RequestExecuteBillQuery{
|
|
|
FormId: "PRD_MO",
|
|
|
Data: k3cloud.ExecuteBillQueryData{
|
|
|
FormId: "PRD_MO",
|
|
|
FieldKeys: strings.Join(fieldKeys, ","), //查询的字段
|
|
|
StartRow: startRow,
|
|
|
Limit: 1000,
|
|
|
FilterString: strings.Join(filterString, " and "),
|
|
|
},
|
|
|
})
|
|
|
if err != nil {
|
|
|
queryErr = err
|
|
|
break
|
|
|
}
|
|
|
mp := result.ToMapString()
|
|
|
if len(mp) == 0 {
|
|
|
break
|
|
|
}
|
|
|
allResult = append(allResult, mp...)
|
|
|
startRow += 1000
|
|
|
}
|
|
|
if queryErr != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
prdMoModels []models.PrdMoK3cloud
|
|
|
prdMoTemp models.PrdMoK3cloud
|
|
|
)
|
|
|
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)
|
|
|
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"])
|
|
|
prdMoTemp = models.PrdMoK3cloud{
|
|
|
Id: id,
|
|
|
WorkShopID: workShopID,
|
|
|
MaterialId: materialId,
|
|
|
Qty: qty,
|
|
|
PlanStartDate: planStartDate,
|
|
|
PlanFinishDate: planFinishDate,
|
|
|
FDate: fDate,
|
|
|
CreateDate: fCreateDate,
|
|
|
ModifyDate: fModifyDate,
|
|
|
BillNo: item["FBillNo"],
|
|
|
WorkShopName: item["FWorkShopID.FName"],
|
|
|
MaterialName: item["FMaterialId.FName"],
|
|
|
MaterialNumber: item["FMaterialId.FNumber"],
|
|
|
DataVersion: nowTime.Unix(),
|
|
|
PrdOrgId: fPrdOrgId,
|
|
|
PrdOrgName: item["FPrdOrgId.FName"],
|
|
|
}
|
|
|
prdMoModels = append(prdMoModels, prdMoTemp)
|
|
|
}
|
|
|
var (
|
|
|
prdMoDao *dao.PrdMoK3cloudDao
|
|
|
)
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
prdMoDao, err = dao.NewPrdMoK3cloudDao(transactionContext.(*pgTransaction.TransactionContext))
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//同步PrdMoK3cloud表数据
|
|
|
err = prdMoDao.SyncDataPrdMoK3cloud(prdMoModels)
|
|
|
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())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|