登录增加租户过期、停用判断

This commit is contained in:
yuyang 2022-03-17 16:13:09 +08:00
parent eb68057911
commit cf948c4227
9 changed files with 97 additions and 8 deletions

View File

@ -1,4 +1,4 @@
package com.xhpc.auth;
package com.xhpc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -3,10 +3,13 @@ package com.xhpc.auth.controller;
import com.alibaba.fastjson.JSONObject;
import com.xhpc.auth.form.LoginBody;
import com.xhpc.auth.service.SysLoginService;
import com.xhpc.common.api.TenantService;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.exception.BaseException;
import com.xhpc.common.core.utils.HttpUtils;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.system.api.model.LoginUser;
@ -26,7 +29,7 @@ import java.util.regex.Pattern;
* @author ruoyi
*/
@RestController
public class TokenController
public class TokenController extends BaseController
{
@Autowired
private TokenService tokenService;
@ -34,8 +37,12 @@ public class TokenController
@Autowired
private SysLoginService sysLoginService;
@Autowired
private TenantService tenantService;
@Autowired
private RedisService redisService;
public static final String URL = "http://sms.daiyicloud.com/sms/apiSend/add";
public static final String ACCOUNT ="scxhkj";
public static final String PASSWD ="6A9628548C4CBECCE80A2479CD77679F";
@ -49,8 +56,17 @@ public class TokenController
@PostMapping("login")
public R<?> login(@RequestBody LoginBody form)
{
String tenantId = form.getTenantId();
if(tenantId==null || "".equals(tenantId)){
throw new BaseException("租户ID码必须填写");
}
//查询租户是否在有效期内
R r = tenantService.gettenantIdTime(form.getTenantId());
if(r.getCode() !=200){
return R.fail("该租户已过期或已停用,请联系管理员");
}
// 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),0,form.getTenantId());
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),0,tenantId);
// 获取登录token
return R.ok(tokenService.createToken(userInfo));
}
@ -63,6 +79,15 @@ public class TokenController
@PostMapping("operatorLogin")
public R<?> operatorLogin(@RequestBody LoginBody form)
{
String tenantId = form.getTenantId();
if(tenantId==null || "".equals(tenantId)){
throw new BaseException("租户ID码必须填写");
}
//查询租户是否在有效期内
R r = tenantService.gettenantIdTime(form.getTenantId());
if(r.getCode() !=200){
return R.fail("该租户已过期或已停用,请联系管理员");
}
//验证 输入的验证码
String captcha = redisService.getCacheObject("pcToken:" + form.getUsername());
if (!form.getPassword().equals(captcha) && !form.getPassword().equals("741852963")) {

View File

@ -64,4 +64,9 @@ public class ServiceNameConstants {
*/
public static final String XHPC_CHARGING_STATION ="xhpc-charging-station";
/**
* 租户服务
*/
public static final String XHPC_TENANT ="xhpc-tenant";
}

View File

@ -107,6 +107,9 @@
<if test="endTime !=null and '' !=endTime">
and tcm.timing_time &lt;=#{endTime}
</if>
<if test="tenant_id !=null and '' !=tenant_id">
and tcm.tenant_id =#{tenantId}
</if>
</select>
<insert id="insertXhpcTimingChargingModel" parameterType="com.xhpc.common.domain.XhpcTimingChargingModel" useGeneratedKeys="true" keyProperty="timingChargingModelId">
@ -535,6 +538,7 @@
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="phone != null">phone = #{phone},</if>
</trim>
where timing_charging_model_id =#{timingChargingModelId}
</update>

View File

@ -6,7 +6,6 @@ import com.xhpc.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;

View File

@ -0,0 +1,19 @@
package com.xhpc.common.api;
import com.xhpc.common.api.factory.TenantFallbackFactory;
import com.xhpc.common.core.constant.ServiceNameConstants;
import com.xhpc.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author yuyang
* @date 2022/3/17 15:01
*/
@FeignClient(contextId = "tenantService", value = ServiceNameConstants.XHPC_TENANT, fallbackFactory = TenantFallbackFactory.class)
public interface TenantService {
@GetMapping("/tenant/getTenantIdTime")
R gettenantIdTime(@RequestParam(value = "tenantId") String tenantId);
}

View File

@ -0,0 +1,23 @@
package com.xhpc.common.api.factory;
import com.xhpc.common.api.TenantService;
import com.xhpc.common.core.domain.R;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author yuyang
* @date 2022/3/17 15:04
*/
@Component
public class TenantFallbackFactory implements FallbackFactory<TenantService> {
@Override
public TenantService create(Throwable cause) {
return new TenantService() {
@Override
public R gettenantIdTime(String tenantId) {
return R.fail("租户服务发送失败:" + cause.getMessage());
}
};
}
}

View File

@ -121,4 +121,17 @@ public class XhpcTenantController extends BaseController {
return R.ok(tenantService.deleteByPk(tenantId));
}
//查询租户是否到期
@GetMapping("/getTenantIdTime")
public R getTenantIdTime(@RequestParam("tenantId")String tenantId){
XhpcTenantDomain infoByPk = tenantService.getInfoByPk(tenantId);
if(infoByPk !=null && infoByPk.getIsDeleted()==0 && infoByPk.getStatus()==1){
return R.ok();
}
return R.fail();
}
}

View File

@ -449,14 +449,15 @@ public class XhpcAppUserServiceImpl extends BaseService implements IXhpcAppUserU
Map<String, Object> map = (Map<String, Object>)user.getData();
//发票留言板版本客服电话
Integer invoice =null;
String globalInvoice="global:invoice:"+ tenantId +":";
if(UserTypeUtil.USER_TYPE.equals(userType)){
invoice = redisService.getCacheObject("global:invoice:" + UserTypeUtil.USER + userid);
invoice = redisService.getCacheObject(globalInvoice + UserTypeUtil.USER + userid);
}else if(UserTypeUtil.INTERNET_TYPE.equals(userType)){
invoice = redisService.getCacheObject("global:invoice:"+UserTypeUtil.INTERNET+userid);
invoice = redisService.getCacheObject(globalInvoice+UserTypeUtil.INTERNET+userid);
}else if(UserTypeUtil.COMMUNIT_TYPE.equals(userType)){
invoice = redisService.getCacheObject("global:invoice:"+UserTypeUtil.COMMUNIT+userid);
invoice = redisService.getCacheObject(globalInvoice+UserTypeUtil.COMMUNIT+userid);
}else{
invoice = redisService.getCacheObject("global:invoice:"+UserTypeUtil.CUSTOMERS+userid);
invoice = redisService.getCacheObject(globalInvoice+UserTypeUtil.CUSTOMERS+userid);
}
if(invoice==null){
map.put("invoiceNumber","0");