check_logistic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package handler
  2. import (
  3. "context"
  4. "github.com/caixw/lib.go/conv"
  5. "github.com/gin-gonic/gin"
  6. "github.com/sirupsen/logrus"
  7. "youngee_m_api/consts"
  8. "youngee_m_api/db"
  9. "youngee_m_api/model/http_model"
  10. "youngee_m_api/service"
  11. )
  12. func WrapCheckLogisticHandler(ctx *gin.Context) {
  13. handler := newCheckLogisticHandler(ctx)
  14. BaseRun(handler)
  15. }
  16. type CheckLogisticHandler struct {
  17. ctx *gin.Context
  18. req *http_model.CheckLogisticRequest
  19. resp *http_model.CommonResponse
  20. }
  21. func newCheckLogisticHandler(ctx *gin.Context) *CheckLogisticHandler {
  22. return &CheckLogisticHandler{
  23. ctx: ctx,
  24. req: http_model.NewCheckLogisticRequest(),
  25. resp: http_model.NewCheckLogisticResponse(),
  26. }
  27. }
  28. func (c CheckLogisticHandler) getContext() *gin.Context { return c.ctx }
  29. func (c CheckLogisticHandler) getResponse() interface{} { return c.resp }
  30. func (c CheckLogisticHandler) getRequest() interface{} {
  31. return c.req
  32. }
  33. func (c CheckLogisticHandler) run() {
  34. logisticNums := db.GetLogisticsNum()
  35. for i := 0; i < len(logisticNums); i++ {
  36. logisticNum := logisticNums[i]
  37. status := service.GetKDStatus(consts.GetKD(logisticNum[0]), logisticNum[1])
  38. if status == "1" {
  39. taskId := db.SignLogistic(conv.MustInt64(logisticNum[2], 0))
  40. err := db.CreateTaskLog(context.Background(), taskId, "签收时间")
  41. if err != nil {
  42. logrus.WithContext(context.Background()).Errorf("[logistics service] call CreateTaskLog error,err:%+v", err)
  43. c.resp.Status = 40000
  44. c.resp.Message = err.Error()
  45. return
  46. }
  47. }
  48. }
  49. c.resp.Status = 20000
  50. c.resp.Message = "ok"
  51. }
  52. func (c CheckLogisticHandler) checkParam() error {
  53. return nil
  54. }