diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/RepairRoleEnum.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/RepairRoleEnum.java new file mode 100644 index 00000000..3c83e186 --- /dev/null +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/RepairRoleEnum.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.common; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 维修系统可用角色枚举 + * + * @author vinjor-m + */ +@AllArgsConstructor +@Getter +public enum RepairRoleEnum { + /** + * 维修业务管理员 + */ + ADMIN("weixiu","维修业务管理员"), + /** + * 维修服务顾问 + */ + ADVISOR("service_advisor","维修服务顾问"), + /** + * 维修总检 + */ + INSPECTION("general_inspection","维修总检"), + /** + * 维修工 + */ + REPAIR_STAFF("repair_staff","维修工"), + /** + * 维修仓库管理员 + */ + WAREHOUSE("repair_warehouse","维修仓库管理员"), + /** + * 维修财务 + */ + WXCW("wxcw","维修财务"); + + /** + * 角色code + */ + private String code; + /** + * 角色名称 + */ + private String name; + + /** + * 根据角色code返回对应的枚举 + * @author vinjor-M + * @date 14:23 2024/10/16 + * @param code 角色code + * @return cn.iocoder.yudao.common.SystemEnum + **/ + public static RepairRoleEnum getRepairRole(String code) { + for (RepairRoleEnum roleEnum : RepairRoleEnum.values()) { + if (roleEnum.getCode().equalsIgnoreCase(code)) { + // 找到对应的枚举 + return roleEnum; + } + } + throw new IllegalArgumentException("无效的角色code:" + code); + } + +} diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java index b8b198f1..899ee0ee 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java @@ -14,23 +14,23 @@ public enum SystemEnum { /** * 维修系统 */ - REPAIR("weixiu","04","维修系统"), + REPAIR("weixiu","04","维修系统","机动车管家小程序"), /** * 救援系统 */ - RESCUE("jiuyuan","02","救援系统"), + RESCUE("jiuyuan","02","救援系统","机动车管家小程序"), /** * 驾校系统 */ - SCHOOL("jiaxiao","03","驾校系统"), + SCHOOL("jiaxiao","03","驾校系统","机动车管家小程序"), /** * 检测系统 */ - INSPECTION("jiance","01","检测系统"), + INSPECTION("jiance","01","检测系统","机动车管家小程序"), /** * 保险系统 */ - INSURE("baoxian","06","保险系统"); + INSURE("baoxian","06","保险系统","机动车管家小程序"); /** * 系统标识 @@ -44,5 +44,26 @@ public enum SystemEnum { * 系统名称 */ private String name; + /** + * 系统别名 + */ + private String appName; + + /** + * 根据系统标识返回对应的枚举 + * @author vinjor-M + * @date 14:23 2024/10/16 + * @param sysCode 系统标识 + * @return cn.iocoder.yudao.common.SystemEnum + **/ + public static SystemEnum getSystem(String sysCode) { + for (SystemEnum systemEnum : SystemEnum.values()) { + if (systemEnum.getCode().equalsIgnoreCase(sysCode)) { + // 找到对应的枚举 + return systemEnum; + } + } + throw new IllegalArgumentException("无效的系统标识:" + sysCode); + } } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/app/ApiAppLoginController.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/app/ApiAppLoginController.java new file mode 100644 index 00000000..54aa1369 --- /dev/null +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/app/ApiAppLoginController.java @@ -0,0 +1,73 @@ +package cn.iocoder.yudao.module.staff.controller.app; + +import cn.iocoder.yudao.common.CommonErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.staff.service.ApiAppLoginService; +import cn.iocoder.yudao.module.staff.vo.StaffLoginBody; +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.auth.AdminAuthService; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 员工APP端登录通用接口 + * @author vinjor-M + * @date 14:04 2024/10/16 +**/ +@RestController +@RequestMapping("/company/staff") +@Tag(name = "员工APP端登录通用接口") +public class ApiAppLoginController { + @Autowired + private ApiAppLoginService apiAppLoginService; + @Resource + private AdminAuthService loginService; + + /** + * 登录获取验证码 + * @author vinjor-M + * @date 14:06 2024/10/16 + * @param phone 手机号 + * @param sysCode 系统标识 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ + @PostMapping("/loginSmsCode") + public CommonResult loginSmsCode(String phone,String sysCode) { + return apiAppLoginService.loginSmsCode(phone,sysCode); + } + + /** + * 员工登录方法 + * @author vinjor-M + * @date 15:17 2024/10/16 + * @param loginBody 登录请求体 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ + @PostMapping("/loginApp") + public CommonResult loginApp(@RequestBody StaffLoginBody loginBody) throws Exception { + try { + AdminUserDO user = apiAppLoginService.loginApp(loginBody); + AuthLoginReqVO authLoginReqVO = new AuthLoginReqVO(); + authLoginReqVO.setUsername(loginBody.getUsername()); + authLoginReqVO.setPassword(loginBody.getPassword()); + Map rtnMap = new HashMap<>(); + rtnMap.put("userinfo",user); + rtnMap.put("loginResult",loginService.login(authLoginReqVO)); + return success(rtnMap); + }catch (Exception e){ + return error(CommonErrorCodeConstants.LOGIN_ACCOUNT_NOT_EXIST); + } + } +} diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/ApiAppLoginService.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/ApiAppLoginService.java new file mode 100644 index 00000000..9385730d --- /dev/null +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/ApiAppLoginService.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.staff.service; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.staff.vo.StaffLoginBody; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; + +public interface ApiAppLoginService { + + /** + * 登录发送验证码 + * @author vinjor-M + * @date 14:06 2024/10/16 + * @param phone 手机号 + * @param systemCode 系统标识 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ + CommonResult loginSmsCode(String phone,String systemCode); + + /** + * 员工app登录通用方法 + * @author vinjor-M + * @date 15:23 2024/10/16 + * @param loginBody 请求体 + * @return cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO + **/ + AdminUserDO loginApp(StaffLoginBody loginBody); +} diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/ApiAppLoginServiceImpl.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/ApiAppLoginServiceImpl.java new file mode 100644 index 00000000..4427e9c8 --- /dev/null +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/ApiAppLoginServiceImpl.java @@ -0,0 +1,166 @@ +package cn.iocoder.yudao.module.staff.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.common.CommonErrorCodeConstants; +import cn.iocoder.yudao.common.RepairRoleEnum; +import cn.iocoder.yudao.common.SystemEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.staff.service.ApiAppLoginService; +import cn.iocoder.yudao.module.staff.vo.StaffLoginBody; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; +import cn.iocoder.yudao.module.system.api.permission.RoleApi; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import cn.iocoder.yudao.util.PhoneCodeUtil; +import cn.iocoder.yudao.util.RedisCache; +import cn.iocoder.yudao.util.SendSmsUtil; +import lombok.SneakyThrows; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Service +public class ApiAppLoginServiceImpl implements ApiAppLoginService { + @Resource + private AdminUserApi adminUserApi; + @Resource + @Lazy + private RedisCache redisCache2; + @Autowired + private PhoneCodeUtil phoneCodeUtil; + @Autowired + private AdminUserService userService; + @Resource + private PermissionApi permissionApi; + @Resource + private RoleApi roleApi; + /** + * 登录发送验证码 + * + * @param phone 手机号 + * @param systemCode 系统标识 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + * @author vinjor-M + * @date 14:06 2024/10/16 + **/ + @Override + public CommonResult loginSmsCode(String phone,String systemCode) { + String msg; + AdminUserDO userDO = new AdminUserDO(); + userDO.setMobile(phone); + if (ObjectUtil.isEmpty(adminUserApi.getUserByMobile(phone))){ + msg = "手机号'" + phone + "不存在请先注册"; + return error(500, msg); + } + String msgCode = phoneCodeUtil.generateVerificationCode(); + redisCache2.setCacheObject(phone+"-loginCode",msgCode,300, TimeUnit.SECONDS); + SendSmsUtil.sendMsg(msgCode,phone,"1400852709", SystemEnum.getSystem(systemCode).getAppName(),"1917285"); + return success("验证码成功生成"); + } + + /** + * 员工app登录通用方法 + * + * @param loginBody 请求体 + * @return cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO + * @author vinjor-M + * @date 15:23 2024/10/16 + **/ + @SneakyThrows + @Override + public AdminUserDO loginApp(StaffLoginBody loginBody) { + String userName = loginBody.getUsername(); + AdminUserDO user = new AdminUserDO(); + if(StringUtils.isNotEmpty(userName)){ + //手机号密码登录 + user = userService.getUserByUsername(userName); + if (ObjectUtil.isEmpty(user)) { + throw new Exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_NOT_EXIST.getMsg()); + } + // 获取登录用户的角色信息 + List roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId()); + if (ObjectUtil.isEmpty(roleIdsByUserId) || roleIdsByUserId.size() == 0) { + throw new Exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_NOT_EXIST.getMsg()); + } + List roleList = roleApi.getRoleList(); + //所拥有的角色code集和 + List roleCodeList = new ArrayList<>(); + //所拥有的角色名称集和 + List roleNames = new ArrayList<>(); + for (RoleReqDTO item:roleList){ + if(roleIdsByUserId.contains(item.getId())){ + roleCodeList.add(item.getCode()); + roleNames.add(item.getName()); + } + } + //默认无权限登录 + boolean flag = false; + if(SystemEnum.REPAIR.getCode().equals(loginBody.getSysCode())){ + //维修业务系统 + flag = this.checkRepairCanLogin(user,roleCodeList); + }else if(SystemEnum.INSPECTION.getCode().equals(loginBody.getSysCode())){ + //检测业务系统 + + }else if(SystemEnum.SCHOOL.getCode().equals(loginBody.getSysCode())){ + //驾校业务系统 + + }else if(SystemEnum.RESCUE.getCode().equals(loginBody.getSysCode())){ + //救援业务系统 + flag = (loginBody.getType().equals("0") && roleNames.contains("调度中心")) || (loginBody.getType().equals("0") && roleNames.contains("交警大队")); + }else if(SystemEnum.INSURE.getCode().equals(loginBody.getSysCode())){ + //保险业务系统 + + }else { + //错误的业务系统标识 + throw new Exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_NOT_EXIST.getMsg()); + } + // 角色是否可以登录 + if (!flag) { + throw new Exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_NOT_EXIST.getMsg()); + } + }else{ + //验证码登录--TODO 先不管 + } + return user; + } + + /** + * 检查是否可以登录维修系统 + * @author vinjor-M + * @date 15:34 2024/10/16 + * @param user 当前用户 + * @param roleCodeList 已有的角色code + * @return boolean + **/ + private boolean checkRepairCanLogin(AdminUserDO user,List roleCodeList){ + boolean flag = false; + if(roleCodeList.contains(RepairRoleEnum.ADMIN.getCode())){ + //维修业务管理员 + flag = true; + }else if(roleCodeList.contains(RepairRoleEnum.INSPECTION.getCode())){ + //总检 + flag = true; + }else if(roleCodeList.contains(RepairRoleEnum.ADVISOR.getCode())){ + //维修服务顾问 + flag = true; + }else if(roleCodeList.contains(RepairRoleEnum.WAREHOUSE.getCode())){ + //维修仓库管理员 + flag = true; + }else if(roleCodeList.contains(RepairRoleEnum.REPAIR_STAFF.getCode())){ + //维修工 + flag = true; + } + return flag; + } +} diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/StaffLoginBody.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/StaffLoginBody.java new file mode 100644 index 00000000..be629190 --- /dev/null +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/vo/StaffLoginBody.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.staff.vo; + +import lombok.Data; + +/** + * 员工移动端登录对象 + * + * @author ruoyi + */ +@Data +public class StaffLoginBody { + /** + * 用户名 + */ + private String username; + + /** + * 用户密码 + */ + private String password; + + /** + * 验证码 + */ + private String code; + + /** + * 唯一标识 + */ + private String uuid; + //0账号密码登录,1手机号登录 2:管理 3:教练 + private String type; + private String types; + private String phone; + private String realName; + + /** + * 系统标识 + */ + private String sysCode; +} diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/util/PhoneCodeUtil.java b/dl-module-company/src/main/java/cn/iocoder/yudao/util/PhoneCodeUtil.java new file mode 100644 index 00000000..e6839e46 --- /dev/null +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/util/PhoneCodeUtil.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.util; + +import org.springframework.stereotype.Component; + +import java.util.Random; + +/** + * 手机验证码通用util + * @author vinjor-M + * @date 14:08 2024/10/16 +**/ +@Component +public class PhoneCodeUtil { + /** + * 生成登录验证码 + * @author vinjor-M + * @date 14:09 2024/10/16 + * @return java.lang.String + **/ + public String generateVerificationCode() { + // 设置验证码长度 + int codeLength = 6; + // 设置验证码字符源 + String codeSource = "0123456789"; + // 生成随机数对象 + Random random = new Random(); + StringBuilder verificationCode = new StringBuilder(); + // 随机生成验证码 + for (int i = 0; i < codeLength; i++) { + int index = random.nextInt(codeSource.length()); + char codeChar = codeSource.charAt(index); + verificationCode.append(codeChar); + } + return verificationCode.toString(); + } +} diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/core/redis/RedisCache.java b/dl-module-company/src/main/java/cn/iocoder/yudao/util/RedisCache.java similarity index 99% rename from dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/core/redis/RedisCache.java rename to dl-module-company/src/main/java/cn/iocoder/yudao/util/RedisCache.java index d89b1fc4..63f0287b 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/core/redis/RedisCache.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/util/RedisCache.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.rescue.core.redis; +package cn.iocoder.yudao.util; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.BoundSetOperations; diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/SendSmsUtil.java b/dl-module-company/src/main/java/cn/iocoder/yudao/util/SendSmsUtil.java similarity index 98% rename from dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/SendSmsUtil.java rename to dl-module-company/src/main/java/cn/iocoder/yudao/util/SendSmsUtil.java index 57adf99e..3895eebf 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/SendSmsUtil.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/util/SendSmsUtil.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.rescue.utils; +package cn.iocoder.yudao.util; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/RescueDriverController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/RescueDriverController.java index 5066ef2b..addfbab2 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/RescueDriverController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/RescueDriverController.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.rescue.core.controller.BaseController; import cn.iocoder.yudao.module.rescue.core.page.TableDataInfo; -import cn.iocoder.yudao.module.rescue.core.redis.RedisCache; +import cn.iocoder.yudao.util.RedisCache; import cn.iocoder.yudao.module.rescue.core.text.HttpStatus; import cn.iocoder.yudao.module.rescue.domain.DriverInfo; import cn.iocoder.yudao.module.rescue.domain.RescueInfo; diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java index 566588c6..f9f33cbc 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java @@ -9,13 +9,13 @@ import cn.iocoder.yudao.framework.security.config.SecurityProperties; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.module.rescue.core.redis.RedisCache; +import cn.iocoder.yudao.util.RedisCache; import cn.iocoder.yudao.module.rescue.domain.DriverInfo; import cn.iocoder.yudao.module.rescue.domain.LoginBody; import cn.iocoder.yudao.module.rescue.domain.WxLoginBody; import cn.iocoder.yudao.module.rescue.service.IDriverInfoService; import cn.iocoder.yudao.module.rescue.utils.RescueSysLoginService; -import cn.iocoder.yudao.module.rescue.utils.SendSmsUtil; +import cn.iocoder.yudao.util.SendSmsUtil; import cn.iocoder.yudao.module.rescue.vo.RegisterVO; import cn.iocoder.yudao.module.shop.entity.ShopConfig; import cn.iocoder.yudao.module.shop.entity.UserBalance; diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/SysConfigServiceImpl.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/SysConfigServiceImpl.java index 33950773..5f4ab49a 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/SysConfigServiceImpl.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/SysConfigServiceImpl.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.rescue.service.impl; import cn.iocoder.yudao.common.CommonErrorCodeConstants; import cn.iocoder.yudao.module.constant.CacheConstants; import cn.iocoder.yudao.module.constant.UserConstants; -import cn.iocoder.yudao.module.rescue.core.redis.RedisCache; +import cn.iocoder.yudao.util.RedisCache; import cn.iocoder.yudao.module.rescue.core.text.Convert; import cn.iocoder.yudao.module.rescue.domain.SysConfig; import cn.iocoder.yudao.module.rescue.mapper.RescueSysConfigMapper; diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RescueSysLoginService.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RescueSysLoginService.java index a7c0f4a1..1120ac07 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RescueSysLoginService.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RescueSysLoginService.java @@ -2,13 +2,10 @@ package cn.iocoder.yudao.module.rescue.utils; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.rescue.core.redis.RedisCache; +import cn.iocoder.yudao.util.RedisCache; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; -import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; -import com.alibaba.fastjson.JSONObject; -import com.thoughtworks.xstream.core.SecurityUtils; +import cn.iocoder.yudao.util.SendSmsUtil; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/user/AppUserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/user/AppUserController.java index df95af5c..20f2a452 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/user/AppUserController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/user/AppUserController.java @@ -1,16 +1,20 @@ package cn.iocoder.yudao.module.system.controller.app.user; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.tenant.TenantService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -22,6 +26,8 @@ public class AppUserController { @Resource private AdminUserService userService; + @Resource + private TenantService tenantService; /** * 微信小程序端修改个人信息 @@ -36,4 +42,23 @@ public class AppUserController { return success(true); } + /** + * 根据用户手机号查询所在的所有租户--员工登录 + * @author vinjor-M + * @date 14:51 2024/10/16 + * @param phone 手机号 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ + @GetMapping("/getListByPhone") + @PermitAll + @Operation(summary = "根据用户手机号查询所在的所有租户--员工登录", description = "根据用户手机号查询所在的所有租户--员工登录") + public CommonResult getListByPhone(@RequestParam("phone") String phone) { + List list = userService.selectListByPhoneStaff(phone); + List tenants = new ArrayList<>(); + if(!list.isEmpty()){ + tenants = tenantService.listByIds(list.stream().map(AdminUserDO::getTenantId).collect(Collectors.toList())); + } + return success(tenants); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java index fc33ec0e..e6d6bbff 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantSa import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; +import com.baomidou.mybatisplus.extension.service.IService; import javax.validation.Valid; import java.util.List; @@ -17,7 +18,7 @@ import java.util.Set; * * @author 芋道源码 */ -public interface TenantService { +public interface TenantService extends IService { /** * 创建租户 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index fae34c76..c6ebb968 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -9,8 +9,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.framework.tenant.config.TenantProperties; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; @@ -25,7 +23,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.service.ServicePackageDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; -import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper; import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum; import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum; @@ -40,6 +37,7 @@ import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -63,7 +61,7 @@ import static java.util.Collections.singleton; @Service @Validated @Slf4j -public class TenantServiceImpl implements TenantService { +public class TenantServiceImpl extends ServiceImpl implements TenantService { @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") @Autowired(required = false) // 由于 yudao.tenant.enable 配置项,可以关闭多租户的功能,所以这里只能不强制注入 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java index a1b23b8d..ae9d775e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqV import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; import cn.iocoder.yudao.module.system.controller.app.user.UserInfoVO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import com.baomidou.mybatisplus.extension.service.IService; import javax.validation.Valid; import java.io.InputStream; @@ -24,7 +25,7 @@ import java.util.Map; * * @author 芋道源码 */ -public interface AdminUserService { +public interface AdminUserService extends IService { /** * 创建用户 @@ -258,4 +259,13 @@ public interface AdminUserService { * @date 15:45 2024/9/24 **/ void setOpenId(Long userId,String openId); + + /** + * 根据手机号查询所有用户--员工 + * @author vinjor-M + * @date 14:43 2024/10/16 + * @param phone 手机号 + * @return java.util.List + **/ + List selectListByPhoneStaff(String phone); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 0706cae2..830392fe 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -31,6 +31,7 @@ import cn.iocoder.yudao.module.system.service.dept.PostService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.tenant.TenantService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.annotations.VisibleForTesting; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.service.impl.DiffParseFunction; @@ -61,7 +62,7 @@ import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*; */ @Service("adminUserService") @Slf4j -public class AdminUserServiceImpl implements AdminUserService { +public class AdminUserServiceImpl extends ServiceImpl implements AdminUserService { static final String USER_INIT_PASSWORD_KEY = "system.user.init-password"; @@ -585,6 +586,25 @@ public class AdminUserServiceImpl implements AdminUserService { userMapper.updateSetOpenId(userId,openId); } + /** + * 根据手机号查询所有用户--员工 + * + * @param phone 手机号 + * @return java.util.List + * @author vinjor-M + * @date 14:43 2024/10/16 + **/ + @Override + @TenantIgnore + public List selectListByPhoneStaff(String phone) { + //员工账号一定是有租户的 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(AdminUserDO::getUsername,phone) + .isNotNull(TenantBaseDO::getTenantId) + .groupBy(TenantBaseDO::getTenantId); + return this.list(queryWrapper); + } + /** * 对密码进行加密 *