| @@ -33,4 +33,7 @@ public interface RemoteLoginService { | |||||
| @GetMapping("/login/inner/loginByPhone/{phone}") | @GetMapping("/login/inner/loginByPhone/{phone}") | ||||
| R<LoginUser> getLoginInfoInnerByPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | R<LoginUser> getLoginInfoInnerByPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | ||||
| @GetMapping("/login/inner/loginByTenant/{tenantId}") | |||||
| R<LoginUser> getLoginInfoInnerByTenant(@PathVariable("tenantId") Long tenantId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | |||||
| } | } | ||||
| @@ -29,6 +29,11 @@ public class RemoteLoginFallbackFactory implements FallbackFactory<RemoteLoginSe | |||||
| public R<LoginUser> getLoginInfoInnerByPhone(String phone, String source) { | public R<LoginUser> getLoginInfoInnerByPhone(String phone, String source) { | ||||
| return R.fail("获取登录信息失败:" + throwable.getMessage()); | return R.fail("获取登录信息失败:" + throwable.getMessage()); | ||||
| } | } | ||||
| @Override | |||||
| public R<LoginUser> getLoginInfoInnerByTenant(Long tenantId, String source) { | |||||
| return R.fail("获取登录信息失败:" + throwable.getMessage()); | |||||
| } | |||||
| }; | }; | ||||
| } | } | ||||
| } | } | ||||
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject; | |||||
| import com.xueyi.common.core.constant.basic.SecurityConstants; | import com.xueyi.common.core.constant.basic.SecurityConstants; | ||||
| import com.xueyi.common.core.constant.basic.ServiceConstants; | import com.xueyi.common.core.constant.basic.ServiceConstants; | ||||
| import com.xueyi.common.core.web.result.R; | import com.xueyi.common.core.web.result.R; | ||||
| import com.xueyi.common.core.web.vo.DeviceTenantSourceMergeVo; | |||||
| import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | ||||
| @@ -41,6 +42,12 @@ public interface RemoteTenantService { | |||||
| @GetMapping("/tenant/one") | @GetMapping("/tenant/one") | ||||
| R<TeTenantPo> tenant(@RequestParam ("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | R<TeTenantPo> tenant(@RequestParam ("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | ||||
| @GetMapping("/tenant/query-tenant-by-id") | |||||
| R<TeTenantPo> selectById(@RequestParam ("tenantId") Long tenantId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | |||||
| @GetMapping("/tenant/query-tenant-source") | |||||
| DeviceTenantSourceMergeVo selectTenantSourceMerge(@RequestParam ("deviceId") String deviceId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | |||||
| @GetMapping("/tenant/query-tenant-by-staff-phone") | @GetMapping("/tenant/query-tenant-by-staff-phone") | ||||
| R<TeTenantPo> queryTenantByStaffPhone(@RequestParam ("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | R<TeTenantPo> queryTenantByStaffPhone(@RequestParam ("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); | ||||
| @@ -2,6 +2,7 @@ package com.xueyi.tenant.api.tenant.feign.factory; | |||||
| import com.alibaba.fastjson2.JSONObject; | import com.alibaba.fastjson2.JSONObject; | ||||
| import com.xueyi.common.core.web.result.R; | import com.xueyi.common.core.web.result.R; | ||||
| import com.xueyi.common.core.web.vo.DeviceTenantSourceMergeVo; | |||||
| import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | ||||
| @@ -43,6 +44,16 @@ public class RemoteTenantFallbackFactory implements FallbackFactory<RemoteTenant | |||||
| return R.fail("获取租户失败:" + throwable.getMessage()); | return R.fail("获取租户失败:" + throwable.getMessage()); | ||||
| } | } | ||||
| @Override | |||||
| public R<TeTenantPo> selectById(Long tenantId, String source) { | |||||
| return R.fail("获取租户失败:" + throwable.getMessage()); | |||||
| } | |||||
| @Override | |||||
| public DeviceTenantSourceMergeVo selectTenantSourceMerge(String deviceId, String source) { | |||||
| return null; | |||||
| } | |||||
| @Override | @Override | ||||
| public R<TeTenantPo> queryTenantByStaffPhone(String phone, String source) { | public R<TeTenantPo> queryTenantByStaffPhone(String phone, String source) { | ||||
| return null; | return null; | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.xueyi.auth.controller; | package com.xueyi.auth.controller; | ||||
| import com.alibaba.csp.sentinel.util.StringUtil; | |||||
| import com.alibaba.fastjson2.JSONObject; | import com.alibaba.fastjson2.JSONObject; | ||||
| import com.baomidou.mybatisplus.core.toolkit.StringUtils; | import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||||
| import com.xueyi.auth.form.LoginBody; | import com.xueyi.auth.form.LoginBody; | ||||
| @@ -13,6 +14,7 @@ import com.xueyi.common.core.utils.core.ObjectUtil; | |||||
| import com.xueyi.common.core.utils.core.StrUtil; | import com.xueyi.common.core.utils.core.StrUtil; | ||||
| import com.xueyi.common.core.web.result.AjaxResult; | import com.xueyi.common.core.web.result.AjaxResult; | ||||
| import com.xueyi.common.core.web.result.R; | import com.xueyi.common.core.web.result.R; | ||||
| import com.xueyi.common.core.web.vo.DeviceTenantSourceMergeVo; | |||||
| import com.xueyi.common.redis.service.RedisService; | import com.xueyi.common.redis.service.RedisService; | ||||
| import com.xueyi.common.security.auth.AuthUtil; | import com.xueyi.common.security.auth.AuthUtil; | ||||
| import com.xueyi.common.security.service.TokenService; | import com.xueyi.common.security.service.TokenService; | ||||
| @@ -99,6 +101,29 @@ public class TokenController { | |||||
| return AjaxResult.success(map); | return AjaxResult.success(map); | ||||
| } | } | ||||
| @PostMapping("deviceLogin") | |||||
| public AjaxResult loginByDevice(@RequestBody Map<String, String> params) { | |||||
| String deviceId = params.get("deviceId"); | |||||
| if (StringUtil.isNotBlank(deviceId)) { | |||||
| DeviceTenantSourceMergeVo vo = tenantService.selectTenantSourceMerge(deviceId, SecurityConstants.INNER);// 查询设备与租户、来源的关联关系 | |||||
| if (null == vo || null == vo.getTenantId()) { | |||||
| return AjaxResult.error("设备不正确,清查验"); | |||||
| } | |||||
| LoginUser userInfo = sysLoginService.loginByTenant(vo.getTenantId()); | |||||
| if (null == userInfo) { | |||||
| return AjaxResult.error("手机号不正确,清查验"); | |||||
| } | |||||
| // 获取登录token | |||||
| Map<String, Object> map = tokenService.createToken(userInfo); | |||||
| map.put("deviceId", deviceId);//塞入对应staffId | |||||
| return AjaxResult.success(map); | |||||
| } | |||||
| return AjaxResult.error("设备号不正确,清查验"); | |||||
| } | |||||
| @DeleteMapping("logout") | @DeleteMapping("logout") | ||||
| public AjaxResult logout(HttpServletRequest request) { | public AjaxResult logout(HttpServletRequest request) { | ||||
| String token = SecurityUtils.getToken(request); | String token = SecurityUtils.getToken(request); | ||||
| @@ -170,16 +170,28 @@ public class SysLoginService { | |||||
| remoteLogService.saveLoginInfo(loginInfo, enterpriseId, sourceName, SecurityConstants.INNER); | remoteLogService.saveLoginInfo(loginInfo, enterpriseId, sourceName, SecurityConstants.INNER); | ||||
| } | } | ||||
| public LoginUser loginByPhone(String phone) { | public LoginUser loginByPhone(String phone) { | ||||
| logger.info("phone:{}", phone); | logger.info("phone:{}", phone); | ||||
| R<LoginUser> loginInfoResult = remoteLoginService.getLoginInfoInnerByPhone(phone, SecurityConstants.INNER); | R<LoginUser> loginInfoResult = remoteLoginService.getLoginInfoInnerByPhone(phone, SecurityConstants.INNER); | ||||
| if (ObjectUtil.isNull(loginInfoResult.getData())) { | if (ObjectUtil.isNull(loginInfoResult.getData())) { | ||||
| AjaxResult.warn("手机号可能输错,请查证后重试!"); | AjaxResult.warn("手机号可能输错,请查证后重试!"); | ||||
| } | } | ||||
| return loginInfoResult.getData(); | return loginInfoResult.getData(); | ||||
| } | } | ||||
| public LoginUser loginByTenant(Long tenantId) { | |||||
| logger.info("tenantId:{}", tenantId); | |||||
| R<LoginUser> loginInfoResult = remoteLoginService.getLoginInfoInnerByTenant(tenantId, SecurityConstants.INNER); | |||||
| if (ObjectUtil.isNull(loginInfoResult.getData())) { | |||||
| AjaxResult.warn("租户号错误,请查证后重试!"); | |||||
| } | |||||
| return loginInfoResult.getData(); | |||||
| } | |||||
| } | } | ||||
| @@ -21,10 +21,10 @@ public class WebApiMvcConfig implements WebMvcConfigurer { | |||||
| @Override | @Override | ||||
| public void addInterceptors(InterceptorRegistry registry) { | public void addInterceptors(InterceptorRegistry registry) { | ||||
| System.err.println("WebMvcConfig.addInterceptors======================hshshkbb"); | |||||
| System.err.println("===graphql======================addInterceptors==="); | |||||
| registry.addInterceptor(getApiInterceptor()) | registry.addInterceptor(getApiInterceptor()) | ||||
| .addPathPatterns("/**/graphql/**") | |||||
| .addPathPatterns("/**/api/**") | |||||
| // .addPathPatterns("/**") | // .addPathPatterns("/**") | ||||
| .excludePathPatterns(excludeUrls) | .excludePathPatterns(excludeUrls) | ||||
| .order(1); | .order(1); | ||||
| @@ -1,6 +1,6 @@ | |||||
| package com.xueyi.common.web.entity.domain.provider; | package com.xueyi.common.web.entity.domain.provider; | ||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * @author yk | * @author yk | ||||
| @@ -8,7 +8,8 @@ import org.apache.ibatis.annotations.Param; | |||||
| * @date 2023-11-25 11:15 | * @date 2023-11-25 11:15 | ||||
| */ | */ | ||||
| public class DeviceTenantSqlProvider { | public class DeviceTenantSqlProvider { | ||||
| public String selectDeviceTenant(@Param("deviceId") String deviceId) { | |||||
| return "SELECT ddtm.dev_id, ddtm.tenant_id, s.source_slave FROM dm_device_tenant_merge ddtm JOIN te_tenant t ON t.id=ddtm.tenant_id JOIN te_strategy s ON s.id=t.strategy_id AND dev_id= #{deviceId}"; | |||||
| public String selectDeviceTenant(Map<String, Object> param) { | |||||
| String deviceId = (String) param.get("deviceId"); | |||||
| return "SELECT ddtm.dev_id, ddtm.tenant_id, s.source_slave FROM dm_device_tenant_merge ddtm JOIN te_tenant t ON t.id=ddtm.tenant_id JOIN te_strategy s ON s.id=t.strategy_id AND dev_id= '"+deviceId+"'"; | |||||
| } | } | ||||
| } | } | ||||
| @@ -103,18 +103,8 @@ public class SysLoginController extends BasisController { | |||||
| @Autowired | @Autowired | ||||
| RemoteTenantService tenantService; | RemoteTenantService tenantService; | ||||
| /** | |||||
| * 获取登录信息 | 内部调用, 手机号登录 | |||||
| */ | |||||
| @InnerAuth | |||||
| @GetMapping("/inner/loginByPhone/{phone}") | |||||
| public R<LoginUser> getLoginInfoByMobile(@PathVariable("phone") String phone) { | |||||
| log.info("获取登录信息 | 内部调用, 手机号登录 | phone: {}", phone); | |||||
| R<TeTenantPo> po = tenantService.tenant(phone, SecurityConstants.INNER); | |||||
| log.info("获取登录信息 | 内部调用, 手机号登录 | po:{}, {}, {}", po.getMsg(),po.getCode(),po.isFail()); | |||||
| if (po.getData() == null) | |||||
| return R.fail("指定手机号不存在记录"); | |||||
| SysEnterpriseDto enterprise = loginService.loginByEnterpriseName(po.getData().getName()); | |||||
| public R<LoginUser> getLoginInfo(String enterpriseName) { | |||||
| SysEnterpriseDto enterprise = loginService.loginByEnterpriseName(enterpriseName); | |||||
| // 不存在直接返回空数据 | 与网络调用错误区分 | // 不存在直接返回空数据 | 与网络调用错误区分 | ||||
| if (ObjectUtil.isNull(enterprise)) | if (ObjectUtil.isNull(enterprise)) | ||||
| return R.ok(null, "企业账号不存在"); | return R.ok(null, "企业账号不存在"); | ||||
| @@ -133,7 +123,7 @@ public class SysLoginController extends BasisController { | |||||
| loginUser.setIsLessor(enterprise.getIsLessor()); | loginUser.setIsLessor(enterprise.getIsLessor()); | ||||
| loginUser.setSource(source); | loginUser.setSource(source); | ||||
| loginUser.setSourceName(source.getMaster()); | loginUser.setSourceName(source.getMaster()); | ||||
| SysUserDto user = loginService.loginByStaff(phone); | |||||
| SysUserDto user = loginService.loginByTenantId(enterprise.getId()); | |||||
| if (ObjectUtil.isNull(user)) | if (ObjectUtil.isNull(user)) | ||||
| return R.ok(null, "用户账号不存在"); | return R.ok(null, "用户账号不存在"); | ||||
| @@ -165,4 +155,28 @@ public class SysLoginController extends BasisController { | |||||
| loginUser.setRouteURL(routeMap); | loginUser.setRouteURL(routeMap); | ||||
| return R.ok(loginUser); | return R.ok(loginUser); | ||||
| } | } | ||||
| /** | |||||
| * 获取登录信息 | 内部调用, 手机号登录 | |||||
| */ | |||||
| @InnerAuth | |||||
| @GetMapping("/inner/loginByPhone/{phone}") | |||||
| public R<LoginUser> getLoginInfoByMobile(@PathVariable("phone") String phone) { | |||||
| log.info("获取登录信息 | 内部调用, 手机号登录 | phone: {}", phone); | |||||
| R<TeTenantPo> po = tenantService.tenant(phone, SecurityConstants.INNER); | |||||
| log.info("获取登录信息 | 内部调用, 手机号登录 | po:{}, {}, {}", po.getMsg(),po.getCode(),po.isFail()); | |||||
| if (po.getData() == null) | |||||
| return R.fail("指定手机号不存在记录"); | |||||
| return this.getLoginInfo(po.getData().getName()); | |||||
| } | |||||
| @GetMapping("/inner/loginByTenant/{tenantId}") | |||||
| public R<LoginUser> getLoginInfoByTenant(@PathVariable("tenantId") Long tenantId) { | |||||
| R<TeTenantPo> po = tenantService.selectById(tenantId, SecurityConstants.INNER); | |||||
| log.info("获取登录信息 | 内部调用, 租户号登录 | po:{}, {}, {}", po.getMsg(),po.getCode(),po.isFail()); | |||||
| if (po.getData() == null) | |||||
| return R.fail("指定租户号不存在记录"); | |||||
| return this.getLoginInfo(po.getData().getName()); | |||||
| } | |||||
| } | } | ||||
| @@ -70,4 +70,6 @@ public interface ISysLoginService { | |||||
| Map<String, String> getMenuRouteMap(Set<Long> roleIds, String userType); | Map<String, String> getMenuRouteMap(Set<Long> roleIds, String userType); | ||||
| SysUserDto loginByStaff(String phone); | SysUserDto loginByStaff(String phone); | ||||
| SysUserDto loginByTenantId(Long tenantId); | |||||
| } | } | ||||
| @@ -247,8 +247,13 @@ public class SysLoginServiceImpl implements ISysLoginService { | |||||
| if (po == null) { | if (po == null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| SqlField field = new SqlField(SqlConstants.OperateType.EQ, "tenant_id", po.getTenantId()); | |||||
| SysUserDto dto = sysUserConverter.mapperDto(userMapper.selectByField(field)) ; | |||||
| return dto; | |||||
| return loginByTenantId(po.getTenantId()); | |||||
| } | |||||
| @Override | |||||
| public SysUserDto loginByTenantId(Long tenantId) { | |||||
| SqlField field = new SqlField(SqlConstants.OperateType.EQ, "tenant_id", tenantId); | |||||
| return sysUserConverter.mapperDto(userMapper.selectByField(field)) ; | |||||
| } | } | ||||
| } | } | ||||
| @@ -146,7 +146,8 @@ public class DmRecognizedRecordsInnerApiController extends MyBaseApiController { | |||||
| String deviceId = recognizedMultiRecordsDto.getDevId(); | String deviceId = recognizedMultiRecordsDto.getDevId(); | ||||
| BigDecimal timestamp = recognizedMultiRecordsDto.getTimestamp(); | BigDecimal timestamp = recognizedMultiRecordsDto.getTimestamp(); | ||||
| String sign = recognizedMultiRecordsDto.getSign(); | String sign = recognizedMultiRecordsDto.getSign(); | ||||
| logger.info("recognizedMultiRecordsDto :{}",recognizedMultiRecordsDto); | |||||
| //去掉recognizedMultiRecordsDto输出日志 | |||||
| // logger.info("recognizedMultiRecordsDto :{}",recognizedMultiRecordsDto); | |||||
| MyResponse myResponse = commonCheck(deviceId, timestamp.doubleValue(), sign); | MyResponse myResponse = commonCheck(deviceId, timestamp.doubleValue(), sign); | ||||
| if (myResponse.getStatus() != 0) { | if (myResponse.getStatus() != 0) { | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.xueyi.tenant.tenant.controller; | package com.xueyi.tenant.tenant.controller; | ||||
| import cn.hutool.core.text.CharSequenceUtil; | import cn.hutool.core.text.CharSequenceUtil; | ||||
| import com.alibaba.fastjson2.JSON; | |||||
| import com.xueyi.common.core.constant.basic.BaseConstants; | import com.xueyi.common.core.constant.basic.BaseConstants; | ||||
| import com.xueyi.common.core.constant.system.OrganizeConstants; | import com.xueyi.common.core.constant.system.OrganizeConstants; | ||||
| import com.xueyi.common.core.utils.core.CollUtil; | import com.xueyi.common.core.utils.core.CollUtil; | ||||
| @@ -9,6 +10,7 @@ import com.xueyi.common.core.web.result.AjaxResult; | |||||
| import com.xueyi.common.core.web.result.R; | import com.xueyi.common.core.web.result.R; | ||||
| import com.xueyi.common.core.web.validate.V_A; | import com.xueyi.common.core.web.validate.V_A; | ||||
| import com.xueyi.common.core.web.validate.V_E; | import com.xueyi.common.core.web.validate.V_E; | ||||
| import com.xueyi.common.core.web.vo.DeviceTenantSourceMergeVo; | |||||
| import com.xueyi.common.log.annotation.Log; | import com.xueyi.common.log.annotation.Log; | ||||
| import com.xueyi.common.log.enums.BusinessType; | import com.xueyi.common.log.enums.BusinessType; | ||||
| import com.xueyi.common.security.annotation.InnerAuth; | import com.xueyi.common.security.annotation.InnerAuth; | ||||
| @@ -17,6 +19,7 @@ import com.xueyi.common.security.annotation.RequiresPermissions; | |||||
| import com.xueyi.common.security.auth.Auth; | import com.xueyi.common.security.auth.Auth; | ||||
| import com.xueyi.common.web.annotation.TenantIgnore; | import com.xueyi.common.web.annotation.TenantIgnore; | ||||
| import com.xueyi.common.web.entity.controller.BaseController; | import com.xueyi.common.web.entity.controller.BaseController; | ||||
| import com.xueyi.common.web.entity.domain.mapper.DeviceTenantMergeMapper; | |||||
| import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | import com.xueyi.tenant.api.tenant.domain.po.SysEnterpriseStaff; | ||||
| import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | import com.xueyi.tenant.api.tenant.domain.po.TeTenantPo; | ||||
| @@ -83,11 +86,30 @@ public class TeTenantController extends BaseController<TeTenantQuery, TeTenantDt | |||||
| @InnerAuth | @InnerAuth | ||||
| @GetMapping("/one") | @GetMapping("/one") | ||||
| R<TeTenantPo> tenant(@RequestParam("phone") String phone) { | R<TeTenantPo> tenant(@RequestParam("phone") String phone) { | ||||
| log.info("tenant one方法,手机号查询SysEnterpriseStaff:{}", phone); | |||||
| log.info("tenant one方法,tenant phone:{}", phone); | |||||
| TeTenantPo po = enterpriseStaffMapper.selectTenantByPhone(phone); | TeTenantPo po = enterpriseStaffMapper.selectTenantByPhone(phone); | ||||
| log.info("tenant one方法,手机号查询SysEnterpriseStaff:{}", JSON.toJSONString(po)); | |||||
| return R.ok(po); | return R.ok(po); | ||||
| } | } | ||||
| @InnerAuth | |||||
| @GetMapping("/query-tenant-by-id") | |||||
| R<TeTenantPo> selectById(@RequestParam ("tenantId") Long tenantId) { | |||||
| log.info("selectById方法,查询TeTenantPo:{}", tenantId); | |||||
| TeTenantPo po = super.baseService.selectById(tenantId); | |||||
| return R.ok(po); | |||||
| } | |||||
| @Autowired | |||||
| private DeviceTenantMergeMapper mergeMapper; | |||||
| @InnerAuth | |||||
| @GetMapping("/query-tenant-source") | |||||
| DeviceTenantSourceMergeVo selectTenantSourceMerge(@RequestParam ("deviceId") String deviceId) { | |||||
| log.info("selectTenantSourceMerge方法,deviceId:{}", deviceId); | |||||
| return mergeMapper.selectByDeviceId(deviceId); | |||||
| } | |||||
| @InnerAuth | @InnerAuth | ||||
| @GetMapping("/query-tenant-by-staff-phone") | @GetMapping("/query-tenant-by-staff-phone") | ||||
| R<TeTenantPo> queryTenantByStaffPhone(@RequestParam("phone") String phone) { | R<TeTenantPo> queryTenantByStaffPhone(@RequestParam("phone") String phone) { | ||||