Commit 684daecf by YANGYANG

登录

parent 09a7ba34
package com.founder.asj.controller;
import com.founder.asj.service.SysUsersService;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.publicEntity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/")
@Api(tags = "登陆管理")
public class LoginController {
@Autowired
private SysUsersService userService;
@ApiOperation(value = "登陆")
@PostMapping("/login")
@ResponseBody
public MapRestResult login(
@RequestParam String username,
@RequestParam String password){
SysUser user = new SysUser();
user.setUsername(username);
user.setPassword(password);
if (user!=null) {
SysUser loginUser = userService.login(user);
if (loginUser == null) {
return MapRestResult.build(201,"用户名或密码错误","1");
} else {
return MapRestResult.build(200,"登陆成功","1",loginUser);
}
}
return MapRestResult.error();
}
}
......@@ -4,6 +4,7 @@ package com.founder.asj.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.founder.commonutils.publicEntity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
/**
* <p>
......@@ -14,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2021-03-11
*/
@Mapper
@Component
public interface SysUsersMapper extends BaseMapper<SysUser> {
}
......@@ -4,6 +4,9 @@ package com.founder.asj.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.founder.commonutils.publicEntity.SysUser;
import javax.servlet.http.HttpServletRequest;
public interface SysUsersService extends IService<SysUser> {
SysUser login(SysUser user);
}
package com.founder.asj.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.asj.mapper.SysUsersMapper;
import com.founder.asj.service.SysUsersService;
import com.founder.commonutils.publicEntity.SysUser;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Base64;
@Service
public class SysUsersServiceImpl extends ServiceImpl<SysUsersMapper, SysUser> implements SysUsersService {
@Autowired
private SysUsersMapper sysUsersMapper;
@Override
public SysUser login(SysUser user) {
//对password进行加密
String password = Base64.getEncoder().encodeToString(user.getPassword().getBytes());
QueryWrapper<SysUser> wrapper = new QueryWrapper<SysUser>();
// 数据库字段名 对应值
wrapper.eq("USERNAME", user.getUsername());
wrapper.eq("PASSWORD", password);
wrapper.eq("OPEN_FLAG", "1");
wrapper.eq("SCBZ", "0");
//设置需要查询的字段
wrapper.select("IDENTITYCARD","USERNAME", "UNITCODE", "TRUE_NAME", "TELEPHONE",
"UNITNAME", "GRADE", "POLICEMANID");
user = sysUsersMapper.selectOne(wrapper);
return user;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment