chore: 并入 iotlcm-worker-svr 历史到 worker-svr/(原提交 96f0f4e)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:03 +08:00
422 changed files with 80993 additions and 0 deletions
@@ -0,0 +1,53 @@
package rabbitmq
import (
"context"
"errors"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/consts"
mq "git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/library/rabbitmq"
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model"
packagecustomerservice "git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/service/packagecustomer"
)
func (c *Consumers) initPackageCustomerSync(ctx context.Context) error {
if !mq.Enabled(ctx) {
g.Log().Info(ctx, "package customer sync consumer skipped, RabbitMQ disabled")
return nil
}
if c.packageCustomerSync == nil {
return gerror.New("package customer sync handler is not configured")
}
if err := mq.ConsumeJSON[model.PackageCustomerSyncMessage](
ctx,
consts.QueuePackageCustomerSync,
"iotlcm-package-customer-sync",
c.handlePackageCustomerSync,
); err != nil {
return err
}
g.Log().Infof(ctx, "package customer sync consumer started, queue:%s", consts.QueuePackageCustomerSync)
return nil
}
func (c *Consumers) handlePackageCustomerSync(ctx context.Context, message model.PackageCustomerSyncMessage) error {
if c.packageCustomerSync == nil {
return gerror.New("package customer sync handler is not configured")
}
if message.TenantId == "" || message.DeptId <= 0 {
g.Log().Errorf(ctx, "package customer sync message dropped, invalid message:%+v", message)
return nil
}
if err := c.packageCustomerSync.SyncDeptPackages(ctx, message); err != nil {
if errors.Is(err, packagecustomerservice.ErrDeptNotFound) {
g.Log().Warningf(ctx, "package customer sync message dropped, dept not found, tenantId:%s, deptId:%d, trigger:%s, sourceBatchNo:%s",
message.TenantId, message.DeptId, message.Trigger, message.SourceBatchNo)
return nil
}
return err
}
return nil
}