package ink.wgink.login.base.controller.api.log;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.base.pojo.dtos.log.LoginLogDTO;
import ink.wgink.login.base.service.log.ILoginLogService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.service.department.pojo.dtos.DepartmentAdjustmentDTO;
import ink.wgink.service.department.pojo.dtos.DepartmentUserAdjustmentDTO;
import ink.wgink.service.department.service.IDepartmentAdjustmentService;
import ink.wgink.service.department.service.IDepartmentUserAdjustmentService;
import ink.wgink.service.user.pojo.dtos.UserLogDTO;
import ink.wgink.service.user.service.IUserAdjustmentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: LoginLogController
 * @Description: 登录日志
 * @Author: wanggeng
 * @Date: 2021/2/28 11:11 上午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "日志")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/log")
public class LogController extends DefaultBaseController {

    @Autowired
    private IUserAdjustmentService userAdjustmentService;
    @Autowired
    private IDepartmentAdjustmentService departmentAdjustmentService;
    @Autowired
    private IDepartmentUserAdjustmentService departmentUserAdjustmentService;
    @Autowired
    private ILoginLogService loginLoggerService;

    @ApiOperation(value = "用户调整分页列表", notes = "用户调整分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/user-adjustment")
    public SuccessResultList<List<UserLogDTO>> listPageUserAdjustment(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return userAdjustmentService.listPage(page);
    }

    @ApiOperation(value = "用户部门调整分页列表", notes = "用户部门调整分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/department-user-adjustment")
    public SuccessResultList<List<DepartmentUserAdjustmentDTO>> listPageDepartmentUserAdjustment(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return departmentUserAdjustmentService.listPage(page);
    }

    @ApiOperation(value = "部门调整分页列表", notes = "部门调整分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/department-adjustment")
    public SuccessResultList<List<DepartmentAdjustmentDTO>> listPageDepartmentAdjustment(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return departmentAdjustmentService.listPage(page);
    }

    @ApiOperation(value = "登录日志分页列表", notes = "登录日志列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/login-log")
    public SuccessResultList<List<LoginLogDTO>> listPageLoginLogger(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return loginLoggerService.listPage(page);
    }

}
