surplusdetaillogic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
  6. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
  7. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
  8. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type SurplusDetailLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewSurplusDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SurplusDetailLogic {
  17. return &SurplusDetailLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. //资源剩余详情
  24. func (l *SurplusDetailLogic) SurplusDetail(req *types.Req) (resp *types.Reply, err error) {
  25. resp = &types.Reply{}
  26. if req.AppId == "" {
  27. resp.Error_msg = "无效的参数appid"
  28. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  29. return resp, nil
  30. } else if req.Function_code == "" {
  31. resp.Error_msg = "无效的参数function_code"
  32. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  33. return resp, nil
  34. } else if req.User_id == 0 && req.Ent_id == 0 && req.Ent_user_id == 0 {
  35. resp.Error_msg = "无效的参数user_id、ent_id、ent_user_id"
  36. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  37. return resp, nil
  38. }
  39. status, total, surplus, err := Surplus(req.AppId, req.Function_code, req.User_id, req.Ent_id, req.Ent_user_id)
  40. if err != nil {
  41. resp.Error_msg = err.Error()
  42. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  43. }
  44. resp.Error_code = status
  45. resp.Data = &SurplusData{
  46. Total: total,
  47. Surplus: surplus,
  48. }
  49. return
  50. }