Browse Source

Merge remote-tracking branch 'origin/main'

1 month ago
parent
commit
55aad6ca78
30 changed files with 796 additions and 25 deletions
  1. 0 5
      edu-travel-common/edu-travel-common-cache/src/main/java/edu/travel/cache/aspects/CacheAspects.java
  2. 4 0
      edu-travel-common/edu-travel-common-util/pom.xml
  3. 1 1
      edu-travel-gateway/src/main/java/edu/travel/config/CorsAutoConfiguration.java
  4. 5 0
      edu-travel-oauth/pom.xml
  5. 3 0
      edu-travel-oauth/src/main/java/edu/travel/OauthServerApplication.java
  6. 38 0
      edu-travel-oauth/src/main/java/edu/travel/config/SmsSwitch.java
  7. 23 0
      edu-travel-oauth/src/main/java/edu/travel/dto/CheckImageDto.java
  8. 6 0
      edu-travel-oauth/src/main/java/edu/travel/entity/EduTenant.java
  9. 54 0
      edu-travel-oauth/src/main/java/edu/travel/entity/SysRole.java
  10. 43 0
      edu-travel-oauth/src/main/java/edu/travel/entity/SysUserRole.java
  11. 7 0
      edu-travel-oauth/src/main/java/edu/travel/mapper/SysRoleMapper.java
  12. 8 0
      edu-travel-oauth/src/main/java/edu/travel/mapper/SysUserRoleMapper.java
  13. 10 0
      edu-travel-oauth/src/main/java/edu/travel/service/SysRoleService.java
  14. 9 0
      edu-travel-oauth/src/main/java/edu/travel/service/SysUserRoleService.java
  15. 57 0
      edu-travel-oauth/src/main/java/edu/travel/service/impl/SysRoleServiceImpl.java
  16. 21 0
      edu-travel-oauth/src/main/java/edu/travel/service/impl/SysUserRoleServiceImpl.java
  17. 7 2
      edu-travel-oauth/src/main/java/edu/travel/service/impl/UserServiceImpl.java
  18. 50 0
      edu-travel-oauth/src/main/java/edu/travel/utils/SMSUtils.java
  19. 84 0
      edu-travel-oauth/src/main/java/edu/travel/web/IndexController.java
  20. 3 0
      edu-travel-oauth/src/main/resources/bootstrap-dev.yml
  21. 6 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/entity/EduTenant.java
  22. 22 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/enums/UserStatus.java
  23. 11 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/ISysRoleService.java
  24. 13 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/ITenantService.java
  25. 46 3
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/impl/ISysRoleServiceImpl.java
  26. 97 3
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/impl/ITenantServiceImpl.java
  27. 83 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/vo/EduTenantVo.java
  28. 44 11
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/web/SysRoleController.java
  29. 38 0
      edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/web/TenantController.java
  30. 3 0
      edu-travel-service/pom.xml

+ 0 - 5
edu-travel-common/edu-travel-common-cache/src/main/java/edu/travel/cache/aspects/CacheAspects.java

@@ -26,8 +26,6 @@ public class CacheAspects {
     @Pointcut("@annotation(edu.travel.cache.annotation.ClearAndReloadCache)")
     public void cachePointcut() {}
 
-
-
     @Around("cachePointcut()")
     public Object cacheAround(ProceedingJoinPoint joinPoint) throws Throwable {
         Signature signature = joinPoint.getSignature();
@@ -65,9 +63,6 @@ public class CacheAspects {
         return result;
     }
 
-
-
-
     private Set getKeys(String pattern) {
         return redisTemplate.keys("*"+pattern+"*");
     }

+ 4 - 0
edu-travel-common/edu-travel-common-util/pom.xml

@@ -24,5 +24,9 @@
             <version>3.8.1</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 1 - 1
edu-travel-gateway/src/main/java/edu/travel/config/CorsAutoConfiguration.java

@@ -12,7 +12,7 @@ import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
 import org.springframework.web.util.pattern.PathPatternParser;
 
 @Configuration
-@ConditionalOnBean(GlobalCorsProperties.class)
+//@ConditionalOnBean(GlobalCorsProperties.class)
 public class CorsAutoConfiguration {
     @Autowired
     private GlobalCorsProperties globalCorsProperties;

+ 5 - 0
edu-travel-oauth/pom.xml

@@ -129,6 +129,11 @@
             <artifactId>edu-travel-common-cache</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>com.volcengine</groupId>
+            <artifactId>volc-sdk-java</artifactId>
+            <version>1.0.105</version>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>

+ 3 - 0
edu-travel-oauth/src/main/java/edu/travel/OauthServerApplication.java

@@ -2,9 +2,11 @@ package edu.travel;
 
 import edu.travel.cache.annotation.EnableRedis;
 import edu.travel.cache.annotation.EnableRedisCache;
+import edu.travel.config.SmsSwitch;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 
 /**
@@ -15,6 +17,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 @EnableDiscoveryClient
 @MapperScan("edu.travel.mapper")
 @EnableRedisCache
+@EnableConfigurationProperties(SmsSwitch.class)
 public class OauthServerApplication
 {
     public static void main( String[] args )

+ 38 - 0
edu-travel-oauth/src/main/java/edu/travel/config/SmsSwitch.java

@@ -0,0 +1,38 @@
+package edu.travel.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "sms.blends.huoshan")
+public class SmsSwitch {
+    private String aK;
+
+    private String sK;
+    /**
+     * 短信开关
+     */
+    private boolean enable;
+    /**
+     * 短信账号
+     */
+    private String smsAccount;
+    /**
+     * 国内签名
+     */
+    private String chinaSign;
+    /**
+     * 国外签名
+     */
+    private String otherSign;
+    /**
+     * 国内模板ID
+     */
+    private String chinaTemplateId;
+    /**
+     * 国外模板ID
+     */
+    private String otherTemplateId;
+}

+ 23 - 0
edu-travel-oauth/src/main/java/edu/travel/dto/CheckImageDto.java

@@ -0,0 +1,23 @@
+package edu.travel.dto;
+import lombok.Data;
+
+@Data
+public class CheckImageDto {
+    /**
+     * 验证码标识
+     */
+    private String uuid;
+    /**
+     * 验证码
+     */
+    private String code;
+    /**
+     * 手机号
+     */
+    private String phoneNumber;
+
+    /**
+     * 地区编号
+     */
+    private String countryCode;
+}

+ 6 - 0
edu-travel-oauth/src/main/java/edu/travel/entity/EduTenant.java

@@ -57,6 +57,12 @@ public class EduTenant extends BaseEntity {
     private String tenantPhone;
 
     /**
+     * 密码
+     */
+    @TableField(value = "password")
+    private String password;
+
+    /**
      * 地区区号
      */
     @TableField(value = "tenant_area")

+ 54 - 0
edu-travel-oauth/src/main/java/edu/travel/entity/SysRole.java

@@ -0,0 +1,54 @@
+package edu.travel.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.security.core.GrantedAuthority;
+
+import java.io.Serializable;
+
+/**
+ * SysRole 类。
+ * <p>
+ * 描述:
+ *
+ * @author huangwenwen
+ * @date 2025/2/10
+ */
+
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName(value = "sys_role")
+public class SysRole extends BaseEntity implements Serializable, GrantedAuthority {
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 角色名称
+     */
+    @TableField(value = "`name`")
+    private String name;
+
+    /**
+     * 角色描述
+     */
+    @TableField(value = "remark")
+    private String remark;
+
+    @Override
+    public String getAuthority() {
+        if (name != null) {
+            return name;
+        }
+        return "";
+    }
+}

+ 43 - 0
edu-travel-oauth/src/main/java/edu/travel/entity/SysUserRole.java

@@ -0,0 +1,43 @@
+package edu.travel.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 用户与角色关联表
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName(value = "sys_user_role")
+public class SysUserRole implements Serializable {
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+    /**
+     * 用户id
+     */
+    @TableField(value = "user_id")
+    private Long userId;
+
+    /**
+     * 用户角色
+     */
+    @TableField(value = "role_id")
+    private Long roleId;
+
+    /**
+     * 项目code
+     */
+    @TableField(value = "project")
+    private String project;
+}

+ 7 - 0
edu-travel-oauth/src/main/java/edu/travel/mapper/SysRoleMapper.java

@@ -0,0 +1,7 @@
+package edu.travel.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import edu.travel.entity.SysRole;
+
+public interface SysRoleMapper extends BaseMapper<SysRole> {
+}

+ 8 - 0
edu-travel-oauth/src/main/java/edu/travel/mapper/SysUserRoleMapper.java

@@ -0,0 +1,8 @@
+package edu.travel.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import edu.travel.entity.SysUserRole;
+
+
+public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
+}

+ 10 - 0
edu-travel-oauth/src/main/java/edu/travel/service/SysRoleService.java

@@ -0,0 +1,10 @@
+package edu.travel.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import edu.travel.entity.SysRole;
+
+import java.util.List;
+
+public interface SysRoleService extends IService<SysRole> {
+    List<SysRole> getRoleListByUserId(Long userId);
+}

+ 9 - 0
edu-travel-oauth/src/main/java/edu/travel/service/SysUserRoleService.java

@@ -0,0 +1,9 @@
+package edu.travel.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import edu.travel.entity.SysUserRole;
+
+
+public interface SysUserRoleService extends IService<SysUserRole> {
+
+}

+ 57 - 0
edu-travel-oauth/src/main/java/edu/travel/service/impl/SysRoleServiceImpl.java

@@ -0,0 +1,57 @@
+package edu.travel.service.impl;
+
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import edu.travel.entity.SysRole;
+import edu.travel.entity.SysUserRole;
+import edu.travel.mapper.SysRoleMapper;
+import edu.travel.service.SysRoleService;
+import edu.travel.service.SysServiceImpl;
+import edu.travel.service.SysUserRoleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * SysServiceImpl 类。
+ * <p>
+ * 描述:
+ *
+ * @author huangwenwen
+ * @date 2025/2/10
+ */
+
+@Service
+public class SysRoleServiceImpl extends SysServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
+//public class SysRoleServiceImpl extends SysServiceImpl<SysRoleMapper, SysRole> implements GrantedAuthority {
+
+
+    @Autowired
+    private SysUserRoleService userRoleService;
+    @Autowired
+    private SysRoleService roleService;
+    @Override
+    public List<SysRole> getRoleListByUserId(Long userId) {
+            // 创建条件
+            LambdaQueryWrapper<SysUserRole> userRoleWrapper = new LambdaQueryWrapper<>();
+            userRoleWrapper.eq(SysUserRole::getUserId, userId);
+            List<SysUserRole> userRoleList = userRoleService.list(userRoleWrapper);
+            if (userRoleList.isEmpty()) {
+                return new ArrayList<>();
+            }
+            List<Long> roleIds = userRoleList.stream()
+                    .map(SysUserRole::getRoleId)
+                    .collect(Collectors.toList());
+            LambdaQueryWrapper<SysRole> roleWrapper = new LambdaQueryWrapper<>();
+            roleWrapper.in(SysRole::getId, roleIds);
+            return roleService.list(roleWrapper);
+    }
+
+
+
+}

+ 21 - 0
edu-travel-oauth/src/main/java/edu/travel/service/impl/SysUserRoleServiceImpl.java

@@ -0,0 +1,21 @@
+package edu.travel.service.impl;
+
+import edu.travel.entity.SysUserRole;
+import edu.travel.mapper.SysUserRoleMapper;
+import edu.travel.service.SysServiceImpl;
+import edu.travel.service.SysUserRoleService;
+import org.springframework.stereotype.Service;
+
+/**
+ * ISysRoleServiceImpl 类。
+ * <p>
+ * 描述:
+ *
+ * @author huangwenwen
+ * @date 2025/2/6
+ */
+
+@Service
+public class SysUserRoleServiceImpl extends SysServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {
+
+}

+ 7 - 2
edu-travel-oauth/src/main/java/edu/travel/service/UserServiceImpl.java → edu-travel-oauth/src/main/java/edu/travel/service/impl/UserServiceImpl.java

@@ -1,12 +1,16 @@
-package edu.travel.service;
+package edu.travel.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import edu.travel.entity.EduTenant;
+import edu.travel.entity.SysRole;
 import edu.travel.mapper.EduTenantMapper;
+import edu.travel.service.SysRoleService;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UserDetailsService;
@@ -17,6 +21,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
+import java.util.List;
 
 @Service
 public class UserServiceImpl implements UserDetailsService {
@@ -47,7 +52,7 @@ public class UserServiceImpl implements UserDetailsService {
             }
             if (code.equals(object.toString())){
                 redisTemplate.opsForValue().set(username+"_info", JSON.toJSONString(tenant));
-                return new User(tenant.getTenantPhone(),code,new ArrayList<>());
+                return new User(tenant.getTenantPhone(),code, new ArrayList<>());
             }
             throw new UsernameNotFoundException("验证码错误");
         }

+ 50 - 0
edu-travel-oauth/src/main/java/edu/travel/utils/SMSUtils.java

@@ -0,0 +1,50 @@
+package edu.travel.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.volcengine.model.request.SmsSendRequest;
+import com.volcengine.model.response.SmsSendResponse;
+import com.volcengine.service.sms.SmsService;
+import com.volcengine.service.sms.SmsServiceInfoConfig;
+import com.volcengine.service.sms.impl.SmsServiceImpl;
+import edu.travel.config.SmsSwitch;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class SMSUtils {
+
+    @Autowired
+    private SmsSwitch smsSwitch;
+
+    private static SmsService smsService;
+
+    public void sendMsg(String countryCode, String phoneNumber, String code){
+        smsService = SmsServiceImpl.getInstance(new SmsServiceInfoConfig(smsSwitch.getAK(), smsSwitch.getSK()));
+
+        SmsSendRequest req = new SmsSendRequest();
+        req.setPhoneNumbers(countryCode.replaceAll("\\+", "") + phoneNumber);
+        req.setSmsAccount(smsSwitch.getSmsAccount());
+        if(countryCode.equals("86") || StringUtils.isBlank(countryCode)){
+            req.setTemplateId(smsSwitch.getChinaTemplateId());
+            req.setSign(smsSwitch.getChinaSign());
+        }else {
+            req.setTemplateId(smsSwitch.getOtherTemplateId());
+            req.setSign(smsSwitch.getOtherSign());
+        }
+
+        Map<String,String> param = new HashMap<>();
+        param.put("code", code);
+        req.setTemplateParamByMap(param);
+
+        try {
+            SmsSendResponse response = smsService.sendV2(req);
+            System.out.println(JSON.toJSONString(response));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 84 - 0
edu-travel-oauth/src/main/java/edu/travel/web/IndexController.java

@@ -0,0 +1,84 @@
+package edu.travel.web;
+
+import cn.hutool.captcha.CaptchaUtil;
+import cn.hutool.captcha.CircleCaptcha;
+import edu.travel.dto.CheckImageDto;
+import edu.travel.resp.BaseResponse;
+import edu.travel.resp.PageResponse;
+import edu.travel.utils.SMSUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * IndexController 类。
+ * <p>
+ * 描述:登录页相关接口
+ *
+ * @author huangwenwen
+ * @date 2025/2/10
+ */
+
+@RestController
+@RequestMapping("/oauth")
+public class IndexController {
+
+    @Autowired
+    private SMSUtils smsUtils;
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    /**
+     * 获取图形验证码
+     * @param session
+     * @param response
+     * @throws IOException
+     */
+    @GetMapping("/createImageCode")
+    public void getCode(HttpSession session, HttpServletResponse response,String phoneNumber) throws IOException {
+
+        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 5);
+
+        String code = captcha.getCode();
+
+        redisTemplate.opsForValue().set(phoneNumber+"_image_code", code, 5, TimeUnit.MINUTES);
+
+        session.setAttribute("code",code);
+
+        captcha.write(response.getOutputStream());
+
+    }
+
+    /**
+     * 校验图形码,发送短信
+     */
+
+    @GetMapping("/verifyAndSendSms")
+    public BaseResponse verifyAndSendSms(CheckImageDto checkImageDto){
+        if (StringUtils.isBlank(checkImageDto.getPhoneNumber())|| StringUtils.isBlank(checkImageDto.getCode())){
+            return PageResponse.out(500, "手机号或验证码为空");
+        }
+        // 校验图形验证码
+        String imageCode = (String) redisTemplate.opsForValue().get(checkImageDto.getPhoneNumber() + "_image_code");
+        if (StringUtils.isBlank(imageCode)) return PageResponse.out(500, "验证码已失效");
+        if (!checkImageDto.getCode().equals(imageCode)) return PageResponse.out(500, "验证码错误");
+        //发送短信
+        Object o = redisTemplate.opsForValue().get(checkImageDto.getPhoneNumber() + "_user_sms");
+        if (o!=null) return PageResponse.out(500, "验证码已发送,请一分钟后重试");
+        //短信码
+        String smsCode = String.valueOf(new Random().nextInt(9000) + 1000);
+        redisTemplate.opsForValue().set(checkImageDto.getPhoneNumber() + "_user_sms", smsCode, 1, TimeUnit.MINUTES);
+        smsUtils.sendMsg(checkImageDto.getCountryCode(), checkImageDto.getPhoneNumber(), smsCode);
+        return PageResponse.out(200, "发送成功");
+    }
+
+}

+ 3 - 0
edu-travel-oauth/src/main/resources/bootstrap-dev.yml

@@ -30,4 +30,7 @@ spring:
             refresh: true
           - data-id: sentinel_oauth.yaml
             group: DEFAULT_GROUP
+            refresh: true
+          - data-id: sms-config-dev.yaml
+            group: DEFAULT_GROUP
             refresh: true

+ 6 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/entity/EduTenant.java

@@ -53,6 +53,12 @@ public class EduTenant extends BaseEntity {
     private String tenantPhone;
 
     /**
+     * 密码
+     */
+    @TableField(value = "password")
+    private String password;
+
+    /**
      * 地区区号
      */
     @TableField(value = "tenant_area")

+ 22 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/enums/UserStatus.java

@@ -0,0 +1,22 @@
+package edu.travel.tenant.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.Getter;
+
+
+/**
+ * 用户状态
+ */
+
+@Getter
+@AllArgsConstructor
+public enum UserStatus {
+    USER_STATUS_NORMAL(1,"正常"),
+    USER_STATUS_DISABLED(2,"禁用"),
+    USER_STATUS_DELETED(3,"删除");
+
+    private Integer code;
+    private String message;
+
+}

+ 11 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/ISysRoleService.java

@@ -5,8 +5,19 @@ import edu.travel.resp.BaseResponse;
 import edu.travel.tenant.entity.EduTenant;
 import edu.travel.tenant.entity.SysRole;
 
+import java.util.List;
+import java.util.Set;
+
 
 public interface ISysRoleService extends IService<SysRole> {
 
     Boolean add(SysRole sysRole, EduTenant principal);
+
+    void deleteByIds(Set<Long> ids);
+
+    void updateRoleById(SysRole sysRole);
+
+    void deleteById(Long id);
+
+    List<SysRole> getRoleByUserId(Long userId);
 }

+ 13 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/ITenantService.java

@@ -2,7 +2,20 @@ package edu.travel.tenant.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import edu.travel.tenant.entity.EduTenant;
+import edu.travel.tenant.vo.EduTenantVo;
+
+import java.util.List;
+import java.util.Set;
 
 public interface ITenantService extends IService<EduTenant> {
     public EduTenant getTenantByID(String tenantID);
+
+    void addTenant(EduTenant tenant);
+
+    void deleteByIds(Set<Long> ids);
+
+    void updateTenant(EduTenant tenant);
+
+
+    EduTenant getTenantById(Long id);
 }

+ 46 - 3
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/impl/ISysRoleServiceImpl.java

@@ -1,10 +1,8 @@
 package edu.travel.tenant.service.impl;
 
-import cn.hutool.core.lang.Snowflake;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import edu.travel.tenant.service.ITenantService;
 import org.apache.commons.lang3.StringUtils;
-import edu.travel.resp.BaseResponse;
 import edu.travel.tenant.entity.EduTenant;
 import edu.travel.tenant.entity.SysRole;
 import edu.travel.tenant.service.ISysRoleService;
@@ -14,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.*;
+
 /**
  * ISysRoleServiceImpl 类。
  * <p>
@@ -25,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 @Service
 public class ISysRoleServiceImpl extends SysServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
+
     @Autowired
     private ITenantService tenantService;
 
@@ -41,8 +42,50 @@ public class ISysRoleServiceImpl extends SysServiceImpl<SysRoleMapper, SysRole>
                 throw new RuntimeException("该角色已存在");
             }
             boolean save = this.save(sysRole);
-            return save;
+            if (!save) throw new RuntimeException("角色添加失败");
+            return true;
         }
         return false;
     }
+
+    @Override
+    @Transactional
+    public void deleteById(Long id) {
+
+    }
+
+    @Override
+    @Transactional
+    public void deleteByIds(Set<Long> ids) {
+        List<SysRole> listLink = super.getListLink(new LambdaQueryWrapper<SysRole>()
+                .in(SysRole::getId, ids));
+        if (listLink==null){
+            throw new RuntimeException("角色不存在");
+        }
+        if (listLink.size() != ids.size()) {
+            throw new RuntimeException("包含不存在的角色");
+        }
+        listLink.forEach(sysRole -> {
+            if (sysRole.getDeleteFlag() == 1) {
+                throw new RuntimeException("包含已删除角色");
+            }
+        });
+        this.removeByIds(ids);
+    }
+
+    @Override
+    public void updateRoleById(SysRole sysRole) {
+
+    }
+
+
+
+    @Override
+    public List<SysRole> getRoleByUserId(Long userId) {
+        if (userId != null) return null;
+        EduTenant tenant = tenantService.getTenantById(userId);
+        if (tenant != null) return null;
+
+        return null;
+    }
 }

+ 97 - 3
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/service/impl/ITenantServiceImpl.java

@@ -1,20 +1,114 @@
 package edu.travel.tenant.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 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 edu.travel.tenant.entity.EduTenant;
 import edu.travel.tenant.entity.EduTenant;
+import edu.travel.tenant.enums.UserStatus;
 import edu.travel.tenant.service.ITenantService;
 import edu.travel.service.SysServiceImpl;
 import edu.travel.tenant.mapper.EduTenantMapper;
+import edu.travel.tenant.vo.EduTenantVo;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 @Service
 public class ITenantServiceImpl extends SysServiceImpl<EduTenantMapper, EduTenant> implements ITenantService {
     @Override
     public EduTenant getTenantByID(String tenantID) {
-
         return super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone",tenantID));
     }
+
+    @Override
+    @Transactional
+    public void addTenant(EduTenant tenant) {
+        if (tenant == null) {
+            throw new RuntimeException("参数为空");
+        }
+        if (tenant.getTenantPhone() == null){
+            throw new RuntimeException("手机号为空");
+        }
+        EduTenant eduTenant = super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone", tenant.getTenantPhone()));
+        if (eduTenant != null&&eduTenant.getUserStatus()==0) {
+            throw new RuntimeException("该手机号已注册,用户状态为禁用");
+        }
+        if (eduTenant != null&&eduTenant.getUserStatus()==1) {
+            throw new RuntimeException("该手机号已注册,用户状态正常");
+        }
+        if (eduTenant == null){
+            this.save(tenant);
+        }
+    }
+
+    @Override
+    @Transactional
+    public void deleteByIds(Set<Long> ids) {
+        if (ids==null || ids.isEmpty()) {
+            throw new RuntimeException("参数为空");
+        }
+        List<EduTenant> tenants = this.listByIds(ids);
+        if (tenants == null || tenants.isEmpty()) {
+            throw new RuntimeException("用户不存在或已注销");
+        }
+        List<EduTenantVo> eduTenantVos = fillStatus(tenants);
+        ArrayList<Long> longs = new ArrayList<>();
+        eduTenantVos.forEach(eduTenantVo -> {
+            if (Objects.equals(eduTenantVo.getStatus(), UserStatus.USER_STATUS_DELETED.getCode())) {
+                throw new RuntimeException("包含已删除用户");
+            } else if (Objects.equals(eduTenantVo.getStatus(), UserStatus.USER_STATUS_DISABLED.getCode())) {
+                throw new RuntimeException("包含已禁用用户");
+            } else {
+                longs.add(eduTenantVo.getId());
+            }
+            this.removeByIds(longs);
+        });
+    }
+
+    @Override
+    @Transactional
+    public void updateTenant(EduTenant tenant) {
+        if (tenant == null) throw new RuntimeException("参数为空");
+        if (tenant.getId() == null) throw new RuntimeException("参数为空");
+        EduTenant eduTenant = super.getOneLink(new QueryWrapper<EduTenant>().eq("id", tenant.getId()));
+        if (eduTenant == null) throw new RuntimeException("用户不存在");
+        if (eduTenant.getDeleteFlag() == 1)  throw new RuntimeException("用户已注销");
+        if (eduTenant.getUserStatus() == 0) throw new RuntimeException("用户已禁用");
+        if (tenant.getTenantPhone() != null){
+            EduTenant eduTenant1 = super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone", tenant.getTenantPhone()));
+            if (eduTenant1 != null) throw new RuntimeException("该手机号已注册");
+        }
+        this.updateById(tenant);
+    }
+
+    @Override
+    public EduTenant getTenantById(Long id) {
+        return super.getOneLink(new LambdaQueryWrapper<EduTenant>().eq(EduTenant::getId,id)
+                .eq(EduTenant::getDeleteFlag,0)
+                .eq(EduTenant::getUserStatus,1));
+    }
+
+    /**
+     *
+     * 填充用户状态
+     */
+    private List<EduTenantVo> fillStatus(List<EduTenant> list) {
+        List<EduTenantVo> eduTenantVos = BeanUtil.copyToList(list, EduTenantVo.class);
+        eduTenantVos.forEach(eduTenantVo -> {
+            if (eduTenantVo.getDeleteFlag() == 1) {
+                eduTenantVo.setStatus(UserStatus.USER_STATUS_DELETED.getCode());
+            } else if (eduTenantVo.getUserStatus() == 0) {
+                eduTenantVo.setStatus(UserStatus.USER_STATUS_DISABLED.getCode());
+            } else {
+                eduTenantVo.setStatus(UserStatus.USER_STATUS_NORMAL.getCode());
+            }
+        });
+        return eduTenantVos;
+    }
+
 }

+ 83 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/vo/EduTenantVo.java

@@ -0,0 +1,83 @@
+package edu.travel.tenant.vo;
+
+import edu.travel.entity.BaseEntity;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * TenantVo 类。
+ * <p>
+ * 描述:
+ *
+ * @author huangwenwen
+ * @date 2025/2/8
+ */
+
+@Data
+public class EduTenantVo extends BaseEntity {
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 姓
+     */
+    private String tenantSurname;
+
+    /**
+     * 名
+     */
+    private String tenantName;
+
+    /**
+     * 性别 0男 1女
+     */
+    private Integer tenantSex;
+
+    /**
+     * 头像
+     */
+    private String tenantAvatar;
+
+    /**
+     * 手机号
+     */
+    private String tenantPhone;
+
+    /**
+     * 地区区号
+     */
+    private String tenantArea;
+
+    /**
+     * 生日日期
+     */
+    private Date tenantBirthday;
+
+    /**
+     * 微信小程序openid
+     */
+    private String tenantOpenId;
+
+    /**
+     * 微信小程序unionid
+     */
+    private String tenantUnionid;
+
+    /**
+     * 现实名
+     */
+    private String showName;
+
+    /**
+     * 用户状态
+     */
+    private Integer userStatus;
+
+    /**
+     * 用户所有状态 1正常 2冻结 2已删除
+     */
+    private Integer status;
+}

+ 44 - 11
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/web/SysRoleController.java

@@ -10,10 +10,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
-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 org.springframework.web.bind.annotation.*;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * SysRoleController 类。
@@ -34,20 +35,52 @@ public class SysRoleController extends BaseController<SysRole> {
     /**
      * 新增管理角色
      */
-    @PostMapping("/add")
-//    @PreAuthorize("hasAuthority = '超级管理员'")
-    public BaseResponse<Boolean> add(@Validated(InsertGroups.class) @RequestBody SysRole sysRole) {
+    @PostMapping("/addRole")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse<Boolean> addRole(@Validated(InsertGroups.class) @RequestBody SysRole sysRole) {
         EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         sysRoleService.add(sysRole,principal);
         return new BaseResponse<>(200,"success",true) ;
     }
 
     /**
-     * 删除角色
+     * 删除角色多个
      */
-    @PostMapping("/delete")
-    public BaseResponse<Boolean> delete(@RequestBody String ids) {
-//        sysRoleService.deleteByIds(ids);
+    @PostMapping("/deleteRoleByIds")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse<Boolean> deleteRoleByIds(@RequestBody List<Long> ids) {
+        HashSet<Long> longs = new HashSet<>(ids);
+        sysRoleService.deleteByIds(longs);
         return new BaseResponse<>(200,"success",true) ;
     }
+
+    /**
+     * 删除角色单个
+     */
+    @PostMapping("/deleteRoleById")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse<Boolean> deleteRoleById(Long id) {
+        sysRoleService.deleteById(id);
+        return new BaseResponse<>(200,"success",true) ;
+    }
+
+    /**
+     * 更新角色
+     */
+    @PostMapping("/updateRoleById")
+    public BaseResponse<Boolean> updateRoleById(@Validated(InsertGroups.class) @RequestBody SysRole sysRole) {
+        sysRoleService.updateRoleById(sysRole);
+        return new BaseResponse<>(200,"success",true) ;
+    }
+
+    /**
+     * 查询用户角色
+     */
+    @GetMapping("/getRoleByUserId")
+    public BaseResponse<List<SysRole>> getRoleByUserId(Long userId) {
+        List<SysRole> sysRoles = sysRoleService.getRoleByUserId(userId);
+        return new BaseResponse<>(200,"success",sysRoles) ;
+    }
+
+
 }

+ 38 - 0
edu-travel-service/edu-travel-service-tenement/src/main/java/edu/travel/tenant/web/TenantController.java

@@ -6,13 +6,19 @@ import edu.travel.resp.PageResponse;
 import edu.travel.tenant.entity.EduTenant;
 import edu.travel.tenant.entity.SysRole;
 import edu.travel.tenant.service.ITenantService;
+import edu.travel.tenant.vo.EduTenantVo;
 import edu.travel.web.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+import java.util.Set;
+
 @RestController
 @RequestMapping("/tenant")
 public class TenantController  extends BaseController<EduTenant> {
@@ -26,4 +32,36 @@ public class TenantController  extends BaseController<EduTenant> {
         return PageResponse.out(200,"success",list);
     }
 
+    @PostMapping("/addTenant")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse addTenant(EduTenant tenant) {
+        tenantService.addTenant(tenant);
+        return PageResponse.out(200,"success",tenant);
+    }
+
+    @PostMapping("/deleteTenantByIds")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse deleteTenant(Set<Long> ids) {
+        tenantService.deleteByIds(ids);
+        return PageResponse.out(200,"success",ids);
+    }
+
+    @PostMapping("/updateTenantById")
+//    @PreAuthorize("hasRole('超级管理员')")
+    public BaseResponse updateTenant(EduTenant tenant) {
+        tenantService.updateTenant(tenant);
+        return PageResponse.out(200,"success",tenant);
+    }
+
+    @GetMapping("/getTenantById")
+    public BaseResponse getTenantById(Long id) {
+        EduTenant tenant = tenantService.getTenantById(id);
+        return PageResponse.out(200,"success",tenant);
+    }
+
+//    @GetMapping("/getMenuList")
+//    public BaseResponse getMenuList() {
+//        List<SysRole> menuList = tenantService.getMenuList();
+//        return PageResponse.out(200,"success",menuList);
+//    }
 }

+ 3 - 0
edu-travel-service/pom.xml

@@ -18,6 +18,9 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
     </properties>
 
 </project>