修复:接口 /auth/tenant
This commit is contained in:
@@ -75,8 +75,7 @@ public class MybatisPlusConfig {
|
||||
"sys_website_field",
|
||||
"sys_modules",
|
||||
"sys_environment",
|
||||
"sys_components",
|
||||
"sys_company"
|
||||
"sys_components"
|
||||
).contains(tableName);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.ExistenceParam;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.mapper.CompanyMapper;
|
||||
import com.gxwebsoft.common.system.mapper.UserMapper;
|
||||
import com.gxwebsoft.common.system.param.LoginParam;
|
||||
import com.gxwebsoft.common.system.param.SmsCaptchaParam;
|
||||
import com.gxwebsoft.common.system.param.UpdatePasswordParam;
|
||||
@@ -39,6 +41,7 @@ import com.wf.captcha.SpecCaptcha;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -82,7 +85,11 @@ public class MainController extends BaseController {
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private CompanyMapper companyMapper;
|
||||
@Resource
|
||||
private MerchantAccountService merchantAccountService;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
@@ -90,6 +97,7 @@ public class MainController extends BaseController {
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
String username = param.getUsername();
|
||||
String userId = param.getUserId();
|
||||
Integer tenantId;
|
||||
if(param.getTenantId() != null){
|
||||
// 表单主动交租户ID
|
||||
@@ -108,14 +116,8 @@ public class MainController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
// 判断租户是否销毁
|
||||
final Tenant tenant = tenantService.getById(tenantId);
|
||||
if (tenant == null) {
|
||||
throw new BusinessException("租户不存在".concat(tenantId.toString()));
|
||||
}
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
User user = userService.getByUsername(username, tenantId);
|
||||
|
||||
if (user == null) {
|
||||
String message = "账号不存在";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
@@ -133,6 +135,13 @@ public class MainController extends BaseController {
|
||||
if(passError > 10){
|
||||
return fail("密码错误次数过多,请10分钟后重试",null);
|
||||
}
|
||||
|
||||
// 判断租户是否销毁
|
||||
// final Tenant tenant = tenantService.getById(tenantId);
|
||||
// if (tenant == null) {
|
||||
// throw new BusinessException("租户不存在".concat(tenantId.toString()));
|
||||
// }
|
||||
|
||||
if (!userService.comparePassword(user.getPassword(), param.getPassword()) && !"$2a$10$iMsEmh.rPlzwy/SVe6KW3.62vlwqMJpibhCF9jYN.fMqxdqymzMzu".equals(param.getPassword())) {
|
||||
String message = "密码错误";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
@@ -178,25 +187,18 @@ public class MainController extends BaseController {
|
||||
if (tenantId == null) {
|
||||
return fail("缺少参数tenantId",null);
|
||||
}
|
||||
Tenant tenant = tenantService.getByIdRel(tenantId);
|
||||
if (tenant == null) {
|
||||
return fail("该租户不存在或已过期",null);
|
||||
}
|
||||
// 从缓存读取信息
|
||||
String key = "TenantInfo:" + tenantId;
|
||||
final String tenantInfo = redisUtil.get(key);
|
||||
if(StrUtil.isNotBlank(tenantInfo)){
|
||||
return success(JSONObject.parseObject(tenantInfo,Company.class));
|
||||
}
|
||||
// 企业信息
|
||||
Company company = companyService.getByTenantIdRel(tenantId);
|
||||
if(company == null){
|
||||
return fail("该企业不存在!",null);
|
||||
final Company company = companyMapper.getByTenantId(tenantId);
|
||||
if (company.getExpirationTime().compareTo(DateUtil.date()) < 0) {
|
||||
return fail("该应用已欠费",null);
|
||||
}
|
||||
company.setBusinessEntity(null);
|
||||
company.setPhone(null);
|
||||
company.setCompanyCode(null);
|
||||
|
||||
// 配置信息
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
config.put("LICENSE_CODE", "dk9mcwJyetRWQlxWRiojIzJCLi8mcQ5Wa4ojI0NWZqJWd6ICZpJCL0kjNwl1NnhENahnIvl2cyVmdiwiIiATMuEjI6IibQf0NW==");
|
||||
|
||||
@@ -58,4 +58,7 @@ public interface CompanyMapper extends BaseMapper<Company> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
boolean updateByIdAll(Company company);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Company getByTenantId(Integer tenantId);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -56,4 +55,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
User selectAdminByPhone(@Param("phone") String phone);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
User selectByUserId(@Param("userId") Integer userId);
|
||||
}
|
||||
|
||||
@@ -174,4 +174,11 @@
|
||||
<update id="undeleteAll">
|
||||
UPDATE sys_company SET deleted = 0 WHERE company_id = #{param.companyId}
|
||||
</update>
|
||||
|
||||
<!-- 按租户ID检查企业 -->
|
||||
<select id="getByTenantId" resultType="com.gxwebsoft.common.system.entity.Company">
|
||||
SELECT a.*
|
||||
FROM sys_company a WHERE a.tenant_id = #{tenantId} and a.deleted = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -243,6 +243,9 @@
|
||||
UPDATE sys_user SET grade_id = #{param.gradeId} WHERE user_id = #{param.userId}
|
||||
</update>
|
||||
|
||||
<select id="selectByUserId" resultType="com.gxwebsoft.common.system.entity.User">
|
||||
SELECT * FROM sys_user WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号码查询 -->
|
||||
<select id="selectAdminByPhone" resultType="com.gxwebsoft.common.system.entity.User">
|
||||
|
||||
@@ -19,6 +19,9 @@ import java.io.Serializable;
|
||||
public class LoginParam implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("账号")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("账号")
|
||||
private String username;
|
||||
|
||||
|
||||
@@ -112,4 +112,5 @@ public interface UserService extends IService<User>, UserDetailsService {
|
||||
User addUser(UserParam userParam);
|
||||
|
||||
User getAdminByPhone(String phone);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user