12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package query
- import (
- "context"
- "encoding/json"
- "fmt"
- "time"
- "adm-data/errors"
- "adm-data/model"
- v1 "adm-data/pb/v1"
- jsoniter "github.com/json-iterator/go"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- type p06Request struct {
- ExportId string `json:"export_id"`
- }
- type p06Response struct {
- State int8 `json:"state"`
- Addr string `json:"addr"`
- }
- func p06(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
- reply = &v1.QueryResponse{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- var req p06Request
- err = jsoniter.UnmarshalFromString(params, &req)
- if err != nil && req.ExportId == "" {
- return nil, errors.ParamsError
- }
- info, err := model.NewExportStyleTaskModel().Get(database.DB().Where("export_id = ?", req.ExportId))
- if err != nil {
- return nil, errors.DataNotExistError
- }
- res := p06Response{
- State: info.Status,
- Addr: info.Path,
- }
- if info.Status == 0 && time.Now().Unix()-info.CreatedAt.Unix() >= 3600 {
- res.State = 2
- }
- reply.Data, _ = jsoniter.MarshalToString(res)
- return reply, nil
- }
|