作者 yangfu

feat: 增加物料定时同步功能

-- 表product_material_group 增加唯一索引 idx_unq_product_material_group_company_id_org_id_material_group_number
create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number);
create UNIQUE INDEX idx_unq_product_material_group_company_id_org_id_material_group_number on manufacture.product_material_group using btree(company_id,org_id,material_group_number,deleted_at);
-- 表product_material 增加唯一索引 idx_unq_product_material_company_id_material_number
create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number);
\ No newline at end of file
create UNIQUE INDEX idx_unq_product_material_company_id_material_number on manufacture.product_material using btree(company_id,material_number,deleted_at);
\ No newline at end of file
... ...
... ... @@ -6,11 +6,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
... ... @@ -30,11 +27,11 @@ func main() {
log.Logger.Info("server start ....")
log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
go mqtt.Start(log.Logger)
go task.Run()
cron := crontab.NewCrontabService(nil)
cron.StartCrontabTask()
defer cron.StopCrontabTask()
//go mqtt.Start(log.Logger)
//go task.Run()
//cron := crontab.NewCrontabService(nil)
//cron.StartCrontabTask()
//defer cron.StopCrontabTask()
time.Sleep(time.Second)
log.Logger.Info("server start!")
web.Run()
... ...
... ... @@ -846,6 +846,8 @@ func (srv *PullDataK3CloudService) SyncDataMaterial(ptr *pgTransaction.Transacti
return err
}
log.Logger.Debug(fmt.Sprintf("【同步物料数据】查询数据条数:%v", len(records)))
_, materialsFromDb, _ := productMaterialRepository.Find(map[string]interface{}{"companyId": cid, "limit": 20000})
mapMaterialsFromDb := domain.ProductMaterials(materialsFromDb).ToMapByNumber()
for index, item := range records {
var (
material *domain.ProductMaterial
... ... @@ -854,14 +856,13 @@ func (srv *PullDataK3CloudService) SyncDataMaterial(ptr *pgTransaction.Transacti
attribute string //物料属性
category string //物料类别
)
if materialGroup, ok = mapMaterialGroup[item.MaterialGroupNumber]; !ok {
if item.UseOrgName != "素天下" {
continue
}
material, err = productMaterialRepository.FindOne(map[string]interface{}{"companyId": cid, "materialNumber": item.Number})
if err == nil && material != nil {
if materialGroup, ok = mapMaterialGroup[item.MaterialGroupNumber]; !ok {
continue
}
if err != domain.ErrorNotFound {
if _, ok := mapMaterialsFromDb[item.Number]; ok {
continue
}
if v, ok := mapMaterialCategory[item.FCategoryID]; ok {
... ... @@ -889,7 +890,8 @@ func (srv *PullDataK3CloudService) SyncDataMaterial(ptr *pgTransaction.Transacti
Ext: domain.NewExt(org.OrgName),
}
if material, err = productMaterialRepository.Save(material); err != nil {
return err
log.Logger.Debug(fmt.Sprintf("同步失败 序号:%v 物料数据 id:%v number:%v name:%v 错误:%v", index, material.ProductMaterialId, material.MaterialNumber, material.MaterialName, err.Error()))
continue
}
log.Logger.Debug(fmt.Sprintf("同步 序号:%v 物料数据 id:%v number:%v name:%v", index, material.ProductMaterialId, material.MaterialNumber, material.MaterialName))
}
... ...