package com.ytpm.calculator.controller;


import com.ytpm.app.enums.LoginType;
import com.ytpm.app.model.YtDyzUser;
import com.ytpm.app.param.VisitorLoginParam;
import com.ytpm.app.param.WxLoginParam;
import com.ytpm.calculator.dao.AppUserMapper;
import com.ytpm.general.Result;
import com.ytpm.handle.LoginServiceFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Marx
 * @date 2025/9/2 15:02
 */
@Api(tags = "游客管理")
@RefreshScope
@RestController
@RequestMapping("/visitor")
public class VisitorController {

    @Resource
    private AppUserMapper appUserMapper;

    @Resource
    private LoginServiceFactory loginServiceFactory;

    @PostMapping("/login")
    @ApiOperation("游客登录")
    @Transactional(rollbackFor = Exception.class)
    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
        return loginServiceFactory.login(LoginType.VISITOR, param, request);
    }

    @ApiOperation("设备在指定时间内注册的渠道")
    @GetMapping("/getDitchCount")
    public int getDitchCount(@RequestParam("deviceId") String deviceId, @RequestParam("hours") Integer hours) {
        return appUserMapper.countDitch(deviceId, hours);
    }

    @ApiOperation("设备在指定时间内注册的渠道")
    @GetMapping("/getLoginDitchCount")
    public int getLoginDitchCount(@RequestParam("deviceId") String deviceId, @RequestParam("hours") Integer hours) {
        return appUserMapper.countLoginDitch(deviceId, hours);
    }


}
