作者 yangfu

Merge remote-tracking branch 'origin/test'

package syncdata
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"strconv"
"strings"
"time"
... ... @@ -526,18 +526,13 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
// 计划信息
plan, err = productPlanRepository.FindOne(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
if err == nil && plan != nil {
//plan.UpdatedAt = time.Now()
continue
}
count, _, errFindPlan := productPlanRepository.Find(map[string]interface{}{"companyId": cid, "orgId": oid, "erpBillNo": v.BillNo, "productCode": v.MaterialNumber})
if errFindPlan != nil {
batchNumber, genBatchNumberErr := redis.GenCode(redis.NewBillNoCodeCache(cid, v.BillNo))
if genBatchNumberErr != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"id": v.RowId, "err": "gen batch number error"})
continue
}
/* ERP系统BillNO + MaterialNumber 唯一 会重复,需要做自增格式化处理*/
batchNumber := fmt.Sprintf("%v-1", v.BillNo)
if count >= 1 {
batchNumber = fmt.Sprintf("%v-%v", v.BillNo, count)
}
if err == domain.ErrorNotFound {
plan = &domain.ProductPlan{
CompanyId: cid,
... ... @@ -556,7 +551,7 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa
// 更新数据
plan.PlanDevoted = &domain.UnitQuantity{
Unit: product.ProductSpec.Unit,
Quantity: 0,
Quantity: v.Qty,
Weight: product.ProductWeigh(0),
UnitWeight: product.ProductSpec.UnitWeight,
}
... ...
... ... @@ -86,3 +86,25 @@ func NewPlanBatchCodeCache(id int) PlanBatchCodeCache {
Time: time.Now(),
}
}
type BillNoCodeCache struct {
CompanyId int
BillNo string
}
func (ca BillNoCodeCache) CacheKey() string {
str := fmt.Sprintf("%v:bill-no:%v:%v", constant.CACHE_PREFIX, ca.CompanyId, ca.BillNo)
return str
}
func (ca BillNoCodeCache) Format(index int) string {
return fmt.Sprintf("%v-%v", ca.BillNo, index)
}
func (ca BillNoCodeCache) Expire() time.Duration {
return time.Hour * 24 * 5
}
func NewBillNoCodeCache(id int, billNo string) BillNoCodeCache {
return BillNoCodeCache{
CompanyId: id,
BillNo: billNo,
}
}
... ...