12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package dashboard
- import (
- "context"
- "fmt"
- "time"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GetChartsLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewGetChartsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChartsLogic {
- return &GetChartsLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp, err error) {
-
- var organizationId uint64 = 0
- isAdmin := l.ctx.Value("isAdmin").(bool)
- if isAdmin && req.OrganizationId != nil && *req.OrganizationId != 0 {
- organizationId = *req.OrganizationId
- } else {
- organizationId = l.ctx.Value("organizationId").(uint64)
- }
-
- layouts := []string{
- "2006-01",
- "2006-01-02",
- }
- var startTime time.Time
- for _, layout := range layouts {
- startTime, err = time.Parse(layout, *req.StartDate)
- if err == nil {
- break
- }
- }
- if err != nil {
- fmt.Println("解析开始时间失败:", err)
- return
- }
- var endTime time.Time
- for _, layout := range layouts {
- endTime, err = time.Parse(layout, *req.EndDate)
- if err == nil {
- break
- }
- }
- if err != nil {
- fmt.Println("解析结束时间失败:", err)
- return
- }
- return
- }
|