package com.shkj.web.controller.system.pda;

import com.shkj.common.constant.Constants;
import com.shkj.common.core.domain.AjaxResult;
import com.shkj.common.core.domain.model.LoginBody;
import com.shkj.framework.web.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lch
 * @menu 登录验证
 */
@RestController
@RequestMapping("/pda")
public class PdaSysLoginController {
    @Autowired
    private SysLoginService loginService;

    /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody) {
        if (loginBody.getBranchId() == null || loginBody.getBranchId().equals(0L)) {
            return AjaxResult.error("请选择仓库");
        }
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid(), loginBody.getBranchId(), true);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }


}
