package services

import (
	"errors"
	"fmt"
	"gin-vue-admin/common"
	"gin-vue-admin/repository"
	"time"
)

func BusinessTrendList(phone, t string) (interface{}, error) {

	fmt.Println(time.Now())
	// 1. 查询当前手机号是否有默认医院
	chainCode, employeeId, err := repository.QueryChainCodeAndLocalIDByPhone(phone)
	if err != nil {
		return nil, err
	}

	if chainCode == "" {
		return nil, errors.New("请设置默认医院")
	}

	// 2. 拿到db
	safeMap := common.NewSafeMap()
	db, err := safeMap.GetOrStore(chainCode)
	if err != nil {
		return nil, err
	}

	return repository.QueryBusinessTrendList(db, t, employeeId, chainCode)
}
