2024-09-03 10:51:15 +08:00
|
|
|
package com.changhu.enums.handler;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2024-09-04 17:13:01 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
2024-09-06 14:54:14 +08:00
|
|
|
import com.changhu.common.annotation.UserType;
|
2024-09-03 10:51:15 +08:00
|
|
|
import com.changhu.common.db.enums.IsEnable;
|
|
|
|
import com.changhu.common.enums.ResultCode;
|
|
|
|
import com.changhu.common.exception.MessageException;
|
|
|
|
import com.changhu.common.pojo.vo.TokenInfo;
|
|
|
|
import com.changhu.common.utils.RsaUtil;
|
|
|
|
import com.changhu.common.utils.UserUtil;
|
|
|
|
import com.changhu.common.utils.ValidatorUtil;
|
|
|
|
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
|
|
|
|
import com.changhu.module.management.pojo.entity.PoliceUnit;
|
|
|
|
import com.changhu.pojo.params.ManagementPoliceUnitLoginParams;
|
|
|
|
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author 20252
|
|
|
|
* @createTime 2024/9/2 下午4:52
|
|
|
|
* @desc ManagementPoliceUnitLogin...
|
|
|
|
*/
|
|
|
|
public class ManagementPoliceUnitLogin extends AbstractLoginHandler {
|
|
|
|
|
|
|
|
public static final ManagementPoliceUnitLogin instance = new ManagementPoliceUnitLogin();
|
|
|
|
|
|
|
|
private ManagementPoliceUnitLogin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TokenInfo login(JSONObject jsonObject) {
|
|
|
|
ManagementPoliceUnitLoginParams managementPoliceUnitLoginParams = jsonObject.to(ManagementPoliceUnitLoginParams.class);
|
|
|
|
ValidatorUtil.manual(managementPoliceUnitLoginParams);
|
|
|
|
|
|
|
|
String accountOrTelephone = managementPoliceUnitLoginParams.getAccountOrTelephone();
|
|
|
|
String password = RsaUtil.decrypt(managementPoliceUnitLoginParams.getPassword());
|
|
|
|
|
|
|
|
//查看 账号/手机号 是否存在
|
2024-09-04 17:13:01 +08:00
|
|
|
ManagementPoliceUnitUser managementPoliceUnitUser = Db.lambdaQuery(ManagementPoliceUnitUser.class)
|
2024-09-03 10:51:15 +08:00
|
|
|
.eq(ManagementPoliceUnitUser::getAccount, accountOrTelephone)
|
|
|
|
.or()
|
|
|
|
.eq(ManagementPoliceUnitUser::getTelephone, accountOrTelephone)
|
|
|
|
.oneOpt()
|
|
|
|
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
|
|
|
|
|
|
|
|
//判断用户是否禁用
|
|
|
|
if (managementPoliceUnitUser.getIsEnable().equals(IsEnable.FALSE)) {
|
|
|
|
throw new MessageException(ResultCode.USER_IS_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断单位是否禁用
|
2024-09-04 17:13:01 +08:00
|
|
|
IsEnable unitEnable = Db.lambdaQuery(PoliceUnit.class)
|
2024-09-03 10:51:15 +08:00
|
|
|
.eq(BaseEntity::getSnowFlakeId, managementPoliceUnitUser.getPoliceUnitId())
|
|
|
|
.oneOpt()
|
|
|
|
.map(PoliceUnit::getIsEnable)
|
|
|
|
.orElseThrow(() -> new MessageException("单位不存在"));
|
|
|
|
if (unitEnable.equals(IsEnable.FALSE)) {
|
|
|
|
throw new MessageException("单位被禁用");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断密码是否正确
|
|
|
|
if (!UserUtil.verifyPassWord(password, managementPoliceUnitUser.getSalt(), managementPoliceUnitUser.getPassword())) {
|
|
|
|
throw new MessageException(ResultCode.PASSWORD_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
//登录
|
2024-09-04 17:13:01 +08:00
|
|
|
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(
|
|
|
|
managementPoliceUnitUser.getSnowFlakeId(),
|
2024-09-06 14:54:14 +08:00
|
|
|
UserType.MANAGEMENT_POLICE,
|
2024-09-04 17:13:01 +08:00
|
|
|
managementPoliceUnitUser.getPoliceUnitId()
|
|
|
|
);
|
2024-09-03 10:51:15 +08:00
|
|
|
//返回token
|
|
|
|
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
|
|
|
|
}
|
|
|
|
}
|