新增客户端登录接口
parent
01ecbcd504
commit
63372ffb3e
@ -0,0 +1,83 @@
|
||||
package com.glxp.api.controller.sup;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.glxp.api.common.enums.ResultEnum;
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import com.glxp.api.constant.Constant;
|
||||
import com.glxp.api.entity.auth.AuthAdmin;
|
||||
import com.glxp.api.entity.sup.UserPersonEntity;
|
||||
import com.glxp.api.entity.system.SysPdaKeyEntity;
|
||||
import com.glxp.api.exception.JsonException;
|
||||
import com.glxp.api.req.auth.LoginRequest;
|
||||
import com.glxp.api.res.auth.LoginResponse;
|
||||
import com.glxp.api.res.sup.PcLoginResponse;
|
||||
import com.glxp.api.service.sup.UserPersonService;
|
||||
import com.glxp.api.util.DateUtil;
|
||||
import com.glxp.api.util.IpUtils;
|
||||
import com.glxp.api.util.JwtUtils;
|
||||
import com.glxp.api.util.PasswordUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "注册企业用户登录接口")
|
||||
@RestController
|
||||
public class CompanyLoginController {
|
||||
|
||||
@Resource
|
||||
private UserPersonService userPersonService;
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "企业用户登录", response = LoginResponse.class)
|
||||
@PostMapping(value = "/company/login")
|
||||
public BaseResponse index(@RequestBody @Valid LoginRequest loginRequest,
|
||||
BindingResult bindingResult,
|
||||
HttpServletRequest request) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
UserPersonEntity userPersonEntity = userPersonService.getOne(new QueryWrapper<UserPersonEntity>().eq("userName", loginRequest.getUsername()));
|
||||
if (userPersonEntity == null) {
|
||||
throw new JsonException(ResultEnum.DATA_NOT, "用户不存在");
|
||||
}
|
||||
|
||||
if (!PasswordUtils.authAdminPwd(loginRequest.getPassword()).equals(userPersonEntity.getPassword())) {
|
||||
throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误");
|
||||
}
|
||||
|
||||
// 更新登录状态
|
||||
userPersonEntity.setLastLoginTime(new Date());
|
||||
userPersonEntity.setLastLoginIp(IpUtils.getIpAddr(request));
|
||||
userPersonService.update(userPersonEntity);
|
||||
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("pc_user_id", userPersonEntity.getId());
|
||||
String token = JwtUtils.createToken(claims, 3 * 86400L); // 三天后过期
|
||||
PcLoginResponse pcLoginResponse = new PcLoginResponse();
|
||||
pcLoginResponse.setUserId(userPersonEntity.getId());
|
||||
pcLoginResponse.setToken(token);
|
||||
pcLoginResponse.setCompanyId(userPersonEntity.getCompanyId());
|
||||
return ResultVOUtils.success(pcLoginResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.glxp.api.res.sup;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
@ApiModel("系统用户登录响应类")
|
||||
public class PcLoginResponse {
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "令牌")
|
||||
private String token;
|
||||
|
||||
@ApiModelProperty(value = "企业ID")
|
||||
private Long companyId;
|
||||
|
||||
}
|
@ -1,13 +1,27 @@
|
||||
package com.glxp.api.service.sup;
|
||||
|
||||
import com.glxp.api.entity.sup.UserCompanyEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.glxp.api.entity.sup.UserPersonEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface UserPersonService extends IService<UserPersonEntity>{
|
||||
int insert(UserPersonEntity userPerson);
|
||||
import com.glxp.api.dao.sup.UserPersonMapper;
|
||||
|
||||
boolean update(UserPersonEntity userPerson);
|
||||
import javax.annotation.Resource;
|
||||
|
||||
boolean delete(UserPersonEntity userPerson);
|
||||
@Service
|
||||
public class UserPersonService extends ServiceImpl<UserPersonMapper, UserPersonEntity> {
|
||||
|
||||
@Resource
|
||||
UserPersonMapper userPersonMapper;
|
||||
|
||||
public int insert(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.insert(userPerson);
|
||||
}
|
||||
|
||||
public boolean update(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.updateById(userPerson) > 0;
|
||||
}
|
||||
|
||||
public boolean delete(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.deleteById(userPerson) > 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
package com.glxp.api.service.sup.impl;
|
||||
|
||||
import com.glxp.api.service.sup.UserPersonService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.glxp.api.entity.sup.UserPersonEntity;
|
||||
import com.glxp.api.dao.sup.UserPersonMapper;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class UserPersonServiceImpl extends ServiceImpl<UserPersonMapper, UserPersonEntity> implements UserPersonService {
|
||||
|
||||
@Resource
|
||||
UserPersonMapper userPersonMapper;
|
||||
|
||||
@Override
|
||||
public int insert(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.insert(userPerson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.updateById(userPerson)>0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(UserPersonEntity userPerson) {
|
||||
return userPersonMapper.deleteById(userPerson)>0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue