|
|
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"
|
...
|
...
|
@@ -612,3 +613,71 @@ func (srv *PullDataK3CloudService) SyncDataProductPlan(ptr *pgTransaction.Transa |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 同步产品
|
|
|
func (srv *PullDataK3CloudService) SyncDataMaterialGroup(ptr *pgTransaction.TransactionContext) error {
|
|
|
prdMoDao, err := dao.NewMaterialK3cloudDao(ptr)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
var userService = domainService.NewUserService()
|
|
|
org, err := userService.Organization(constant.MANUFACTURE_DEFAULT_ORGID)
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
fromMaterialGroups, err := prdMoDao.SearchMaterialGroup() // 默认企业名称素天下、或者使用组织ID
|
|
|
if err != nil {
|
|
|
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
cid = constant.MANUFACTURE_DEFAULT_COMPANYID
|
|
|
oid = constant.MANUFACTURE_DEFAULT_ORGID
|
|
|
)
|
|
|
productMaterialGroupRepository, _, _ := factory.FastProductMaterialGroup(ptr, 0)
|
|
|
_, materialGroups, err := productMaterialGroupRepository.Find(map[string]interface{}{"companyId": cid})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
mapMaterialGroups := domain.ProductMaterialGroups(materialGroups).ToMapByGroupNumber()
|
|
|
mapFromMaterialGroups := models.MaterialGroupK3clouds(fromMaterialGroups).ToMapId()
|
|
|
for _, from := range fromMaterialGroups {
|
|
|
to, ok := mapMaterialGroups[from.Number]
|
|
|
if ok {
|
|
|
// 更新
|
|
|
if to.MaterialGroupName != from.Name {
|
|
|
log.Logger.Info(fmt.Sprintf("更新物料分组 old:%v new:%v", to.MaterialGroupName, from.Name), map[string]interface{}{"material": to})
|
|
|
to.MaterialGroupName = from.Name
|
|
|
}
|
|
|
continue
|
|
|
}
|
|
|
var parentId int
|
|
|
if from.ParentId > 0 {
|
|
|
parent, ok := mapFromMaterialGroups[from.ParentId]
|
|
|
if !ok {
|
|
|
log.Logger.Warn("parent node not exits", map[string]interface{}{"material": to})
|
|
|
continue
|
|
|
}
|
|
|
toParent, ok := mapMaterialGroups[parent.Number]
|
|
|
if !ok {
|
|
|
log.Logger.Warn("to parent node not exits", map[string]interface{}{"material": to})
|
|
|
continue
|
|
|
}
|
|
|
parentId = toParent.ProductMaterialGroupId
|
|
|
}
|
|
|
productMaterialGroup := &domain.ProductMaterialGroup{
|
|
|
CompanyId: cid,
|
|
|
OrgId: oid,
|
|
|
Pid: parentId,
|
|
|
MaterialGroupName: from.Name,
|
|
|
MaterialGroupNumber: from.Number,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
Ext: domain.NewExt(org.OrgName),
|
|
|
}
|
|
|
if productMaterialGroup, err = productMaterialGroupRepository.Save(productMaterialGroup); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
mapMaterialGroups[productMaterialGroup.MaterialGroupNumber] = productMaterialGroup
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|