package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.SysUserMapper;
import cn.wisenergy.model.app.SysUser;
import cn.wisenergy.model.dto.SysLoginDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 86187
 */
@Api(tags = "后台管理--用户登录")
@RestController
@RequestMapping("/sys")
@Slf4j
public class SysUserController {

    @Autowired
    private SysUserMapper sysUserMapper;

    @ApiOperation(value = "登录", notes = "登录", httpMethod = "POST")
    @ApiImplicitParam(name = "query", value = "登录信息", dataType = "SysLoginDto")
    @PostMapping("/login")
    public R<Boolean> login(@RequestBody SysLoginDto query) {
        log.info("shop-mall[]SysUserController[]login[]input.param.query:" + query);
        if (null == query || StringUtils.isBlank(query.getAccount()) || StringUtils.isBlank(query.getPassword())) {
            return R.error("入参为空!");
        }

        //获取账户信息
        SysUser sysUser = sysUserMapper.getByAccount(query.getAccount());
        if (null == sysUser) {
            return R.error("用户信息不存在!");
        }

        //判断账户密码是否正确
        if (!query.getPassword().equals(sysUser.getPassword())) {
            return R.error("密码输入错误，请从新输入!");
        }

        return R.ok(0, true);
    }
}
