2bec257289
iotlcm-worker-svr:异步执行中枢(RabbitMQ 消费者 + 全量同步编排)。 - Go module:iotlcm-worker-svr → git.5iot.com/iotlcm-public/iotlcm-worker-svr(214 文件) - 凭据与内部标识脱敏:MySQL/Redis 凭据、私网与生产 IP、内网域名、 库名 xiujie_admin → iotlcm、哨兵名占位 - 159 处真实手机号 → 合法 11 位编造号(保留号段与后 4 位,维持互异, 不破坏「校验 MSISDN 格式」等测试断言) - 移除内部资产:CI 触发器、Jenkins 触发测试文档、预演门禁与镜像 digest 记录 - Dockerfile 改用公共基础镜像(golang:1.25-alpine → alpine:3.23), 移除写死的 git 凭据 - README 重写(架构/全量同步模型/配置/已知失败),补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 已知:3 个测试包在源仓同一提交上同样失败(client/upstream、 service/allocate、service/inbound),属既有缺陷,本仓未引入亦未修复。
106 lines
3.4 KiB
Go
106 lines
3.4 KiB
Go
package workorder
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/dao"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model/do"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model/entity"
|
|
)
|
|
|
|
const (
|
|
statusResolved = 3
|
|
statusClosed = 4
|
|
operationClose = 4
|
|
)
|
|
|
|
type Service struct{}
|
|
|
|
func New() *Service {
|
|
return &Service{}
|
|
}
|
|
|
|
func (s *Service) AutoCloseResolved(ctx context.Context, message model.WorkOrderAutoCloseMessage) error {
|
|
if message.WoNo == "" {
|
|
return nil
|
|
}
|
|
g.Log().Infof(ctx, "work order auto close received, woNo:%s", message.WoNo)
|
|
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
current := entity.TWoMain{}
|
|
if err := tx.Ctx(ctx).Model(dao.TWoMain.Table()).
|
|
Where(dao.TWoMain.Columns().WoNo, message.WoNo).
|
|
Scan(¤t); err != nil {
|
|
return gerror.Wrap(err, "query work order failed")
|
|
}
|
|
if current.WoNo == "" || current.CurrentStatus != statusResolved {
|
|
return nil
|
|
}
|
|
if current.ResolveTime == nil || current.ResolveTime.Add(72*time.Hour).After(gtime.Now()) {
|
|
return nil
|
|
}
|
|
if message.ResolveTimeTs > 0 && (current.ResolveTime == nil || current.ResolveTime.Timestamp() != message.ResolveTimeTs) {
|
|
g.Log().Infof(ctx, "work order auto close skipped, resolve time changed, woNo:%s, messageResolveTime:%d", message.WoNo, message.ResolveTimeTs)
|
|
return nil
|
|
}
|
|
|
|
operatorID := int64(0)
|
|
now := gtime.Now()
|
|
result, err := tx.Ctx(ctx).Model(dao.TWoMain.Table()).
|
|
Where(dao.TWoMain.Columns().Id, current.Id).
|
|
Where(dao.TWoMain.Columns().TenantId, current.TenantId).
|
|
Where(dao.TWoMain.Columns().ResolveTime, current.ResolveTime).
|
|
Where(dao.TWoMain.Columns().CurrentStatus, statusResolved).
|
|
Data(do.TWoMain{
|
|
CurrentStatus: statusClosed,
|
|
CloseTime: now,
|
|
UpdatedBy: operatorID,
|
|
}).Update()
|
|
if err != nil {
|
|
return gerror.Wrap(err, "auto close work order failed")
|
|
}
|
|
affected, err := result.RowsAffected()
|
|
if err != nil || affected == 0 {
|
|
return err
|
|
}
|
|
|
|
_, err = tx.Ctx(ctx).Model(dao.TWoRecord.Table()).Data(do.TWoRecord{
|
|
WoNo: message.WoNo,
|
|
OperationType: operationClose,
|
|
OperationDeptId: current.HandlerDeptId,
|
|
OperationUserId: operatorID,
|
|
BeforeStatus: statusResolved,
|
|
AfterStatus: statusClosed,
|
|
TenantId: current.TenantId,
|
|
CreatedDept: current.CreatedDept,
|
|
CreatedBy: operatorID,
|
|
}).Insert()
|
|
if err != nil {
|
|
return gerror.Wrap(err, "保存自动完结记录失败")
|
|
}
|
|
return saveAutoCloseNotice(ctx, tx, ¤t)
|
|
})
|
|
}
|
|
|
|
func (s *Service) CloseOverdue(ctx context.Context) error {
|
|
var rows []*entity.TWoMain
|
|
if err := dao.TWoMain.Ctx(ctx).Where(dao.TWoMain.Columns().CurrentStatus, statusResolved).WhereLTE(dao.TWoMain.Columns().ResolveTime, gtime.Now().Add(-72*time.Hour)).OrderAsc(dao.TWoMain.Columns().ResolveTime).Limit(100).Scan(&rows); err != nil {
|
|
return gerror.Wrap(err, "查询到期工单失败")
|
|
}
|
|
for _, row := range rows {
|
|
if row == nil || row.ResolveTime == nil {
|
|
continue
|
|
}
|
|
if err := s.AutoCloseResolved(ctx, model.WorkOrderAutoCloseMessage{WoNo: row.WoNo, ResolveTimeTs: row.ResolveTime.Timestamp()}); err != nil {
|
|
g.Log().Errorf(ctx, "工单补偿关闭失败 woNo:%s err:%v", row.WoNo, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|