Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

Zimo 1 giorno fa
parent
commit
a8acf04385
16 ha cambiato i file con 527 aggiunte e 0 eliminazioni
  1. 1 0
      yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java
  2. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/devicegroup/IotDeviceGroupController.java
  3. 3 0
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
  4. 18 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
  5. 4 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthPortalLoginReqVO.java
  6. 23 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthPortalSsoLoginReqVO.java
  7. 93 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/AuthenticationController.java
  8. 36 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationPageReqVO.java
  9. 39 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationRespVO.java
  10. 25 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationSaveReqVO.java
  11. 46 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/authentication/AuthenticationDO.java
  12. 40 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/authentication/AuthenticationMapper.java
  13. 14 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java
  14. 54 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
  15. 55 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/authentication/AuthenticationService.java
  16. 71 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/authentication/AuthenticationServiceImpl.java

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -99,4 +99,5 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_DEPT_TYPE_NOT_EXISTS = new ErrorCode(274, "部门类型不存在");
     ErrorCode IOT_CAR_ZHBD_NOT_EXISTS = new ErrorCode(275, "中航北斗车辆表不存在");
     ErrorCode IOT_DAILY_REPORT_FUEL_NOT_EXISTS = new ErrorCode(276, "日报-油耗不存在");
+    ErrorCode IOT_AUTHENTICATION_NOT_EXISTS = new ErrorCode(277, "认证不存在");
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/devicegroup/IotDeviceGroupController.java

@@ -344,6 +344,11 @@ public class IotDeviceGroupController {
                                     monitor.setModelName(row.getModelName());
                                     monitor.setValue(row.getValue());
                                     monitors.add(monitor);
+                                    // 排序 运行状态 加载状态 字段 置后
+                                    monitors.sort(Comparator.comparingInt(m ->
+                                            m.getModelName().contains("加载状态") ? 2 :
+                                                    m.getModelName().contains("运行状态") ? 1 : 0
+                                    ));
                                 }
                             });
                         }

+ 3 - 0
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java

@@ -169,4 +169,7 @@ public interface ErrorCodeConstants {
     // ========== PMS IOT 1-002-030-000 ==========
     ErrorCode DEPT_SAP_ORG_NOT_EXISTS = new ErrorCode(1-002-030-000, "PMS 组织部门与SAP工厂/成本中心 对应关系不存在");
     ErrorCode SAP_ORG_NOT_EXISTS = new ErrorCode(1-002-030-001, "SAP中的组织主数据(工厂 成本中心)不存在");
+
+    // ========== PMS IOT 1-002-040-000 ==========
+    ErrorCode AUTHENTICATION_NOT_EXISTS = new ErrorCode(1-002-040-001, "认证不存在");
 }

+ 18 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java

@@ -228,4 +228,22 @@ public class AuthController {
         return success(authService.portalLogin(reqVO));
     }
 
+    @PostMapping("/portal/ssoLogin")
+    @PermitAll
+    @TenantIgnore
+    public CommonResult<AuthLoginRespVO> ssoLogin(@RequestBody AuthPortalSsoLoginReqVO reqVO) {
+        return success(authService.portalSsoLogin(reqVO));
+    }
+
+    @PostMapping("/ssoLogin/getToken")
+    @PermitAll
+    @TenantIgnore
+    @Operation(summary = "第三方应用获取随机码 用于请求真正的token", description = "")
+    public CommonResult<String> getToken(@RequestBody AuthPortalLoginReqVO reqVO) {
+        if (!portalSecret.equals(reqVO.getAppid())) {
+            throw new ServiceException(new ErrorCode(100, "验证失败"));
+        }
+        return success(authService.ssoGetToken(reqVO));
+    }
+
 }

+ 4 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthPortalLoginReqVO.java

@@ -19,6 +19,10 @@ public class AuthPortalLoginReqVO {
     @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
     private Integer type;
 
+    @Schema(description = "", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
+    @NotEmpty(message = "appid不能为空")
+    private String appid;
+
     @Schema(description = "工号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
     @NotEmpty(message = "工号不能为空")
     private String username;

+ 23 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthPortalSsoLoginReqVO.java

@@ -0,0 +1,23 @@
+package cn.iocoder.yudao.module.system.controller.admin.auth.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotEmpty;
+
+
+@Schema(description = "管理后台 - 门户登录 Request VO,使用 code 授权码 + 账号密码")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class AuthPortalSsoLoginReqVO {
+
+    @Schema(description = "code", requiredMode = Schema.RequiredMode.REQUIRED, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62")
+    @NotEmpty(message = "code不能为空")
+    private String code;
+
+}

+ 93 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/AuthenticationController.java

@@ -0,0 +1,93 @@
+package cn.iocoder.yudao.module.system.controller.admin.authentication;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationRespVO;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationSaveReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
+import cn.iocoder.yudao.module.system.service.authentication.AuthenticationService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.IOException;
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "管理后台 - 认证")
+@RestController
+@RequestMapping("/system/authentication")
+@Validated
+public class AuthenticationController {
+
+    @Resource
+    private AuthenticationService authenticationService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建认证")
+    @PreAuthorize("@ss.hasPermission('system:authentication:create')")
+    public CommonResult<Long> createAuthentication(@Valid @RequestBody AuthenticationSaveReqVO createReqVO) {
+        return success(authenticationService.createAuthentication(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新认证")
+    @PreAuthorize("@ss.hasPermission('system:authentication:update')")
+    public CommonResult<Boolean> updateAuthentication(@Valid @RequestBody AuthenticationSaveReqVO updateReqVO) {
+        authenticationService.updateAuthentication(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除认证")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('system:authentication:delete')")
+    public CommonResult<Boolean> deleteAuthentication(@RequestParam("id") Long id) {
+        authenticationService.deleteAuthentication(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得认证")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('system:authentication:query')")
+    public CommonResult<AuthenticationRespVO> getAuthentication(@RequestParam("id") Long id) {
+        AuthenticationDO authentication = authenticationService.getAuthentication(id);
+        return success(BeanUtils.toBean(authentication, AuthenticationRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得认证分页")
+    @PreAuthorize("@ss.hasPermission('system:authentication:query')")
+    public CommonResult<PageResult<AuthenticationRespVO>> getAuthenticationPage(@Valid AuthenticationPageReqVO pageReqVO) {
+        PageResult<AuthenticationDO> pageResult = authenticationService.getAuthenticationPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, AuthenticationRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出认证 Excel")
+    @PreAuthorize("@ss.hasPermission('system:authentication:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportAuthenticationExcel(@Valid AuthenticationPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<AuthenticationDO> list = authenticationService.getAuthenticationPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "认证.xls", "数据", AuthenticationRespVO.class,
+                        BeanUtils.toBean(list, AuthenticationRespVO.class));
+    }
+
+}

+ 36 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationPageReqVO.java

@@ -0,0 +1,36 @@
+package cn.iocoder.yudao.module.system.controller.admin.authentication.vo;
+
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 认证分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class AuthenticationPageReqVO extends PageParam {
+
+    @Schema(description = "用户id", example = "29956")
+    private Long userid;
+
+    @Schema(description = "工号")
+    private String jobNumber;
+
+    @Schema(description = "随机码")
+    private String randomCode;
+
+    @Schema(description = "备注", example = "你说的对")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 39 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationRespVO.java

@@ -0,0 +1,39 @@
+package cn.iocoder.yudao.module.system.controller.admin.authentication.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 认证 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class AuthenticationRespVO {
+
+    @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17795")
+    @ExcelProperty("主键")
+    private Long id;
+
+    @Schema(description = "用户id", example = "29956")
+    @ExcelProperty("用户id")
+    private Long userid;
+
+    @Schema(description = "工号")
+    @ExcelProperty("工号")
+    private String jobNumber;
+
+    @Schema(description = "随机码")
+    @ExcelProperty("随机码")
+    private String randomCode;
+
+    @Schema(description = "备注", example = "你说的对")
+    @ExcelProperty("备注")
+    private String remark;
+
+    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+}

+ 25 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/authentication/vo/AuthenticationSaveReqVO.java

@@ -0,0 +1,25 @@
+package cn.iocoder.yudao.module.system.controller.admin.authentication.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Schema(description = "管理后台 - 认证新增/修改 Request VO")
+@Data
+public class AuthenticationSaveReqVO {
+
+    @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17795")
+    private Long id;
+
+    @Schema(description = "用户id", example = "29956")
+    private Long userid;
+
+    @Schema(description = "工号")
+    private String jobNumber;
+
+    @Schema(description = "随机码")
+    private String randomCode;
+
+    @Schema(description = "备注", example = "你说的对")
+    private String remark;
+
+}

+ 46 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/authentication/AuthenticationDO.java

@@ -0,0 +1,46 @@
+package cn.iocoder.yudao.module.system.dal.dataobject.authentication;
+
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+/**
+ * 认证 DO
+ *
+ * @author ruiqi
+ */
+@TableName("system_authentication")
+@KeySequence("system_authentication_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class AuthenticationDO extends BaseDO {
+
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+    /**
+     * 用户id
+     */
+    private Long userid;
+    /**
+     * 工号
+     */
+    private String jobNumber;
+    /**
+     * 随机码
+     */
+    private String randomCode;
+    /**
+     * 备注
+     */
+    private String remark;
+
+}

+ 40 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/authentication/AuthenticationMapper.java

@@ -0,0 +1,40 @@
+package cn.iocoder.yudao.module.system.dal.mysql.authentication;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * 认证 Mapper
+ *
+ * @author ruiqi
+ */
+@Mapper
+public interface AuthenticationMapper extends BaseMapperX<AuthenticationDO> {
+
+    default PageResult<AuthenticationDO> selectPage(AuthenticationPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<AuthenticationDO>()
+                .eqIfPresent(AuthenticationDO::getUserid, reqVO.getUserid())
+                .eqIfPresent(AuthenticationDO::getJobNumber, reqVO.getJobNumber())
+                .eqIfPresent(AuthenticationDO::getRandomCode, reqVO.getRandomCode())
+                .eqIfPresent(AuthenticationDO::getRemark, reqVO.getRemark())
+                .betweenIfPresent(AuthenticationDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(AuthenticationDO::getId));
+    }
+
+    default List<AuthenticationDO> selectList(AuthenticationPageReqVO reqVO) {
+        return selectList(new LambdaQueryWrapperX<AuthenticationDO>()
+                .eqIfPresent(AuthenticationDO::getUserid, reqVO.getUserid())
+                .eqIfPresent(AuthenticationDO::getJobNumber, reqVO.getJobNumber())
+                .eqIfPresent(AuthenticationDO::getRandomCode, reqVO.getRandomCode())
+                .eqIfPresent(AuthenticationDO::getRemark, reqVO.getRemark())
+                .betweenIfPresent(AuthenticationDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(AuthenticationDO::getId));
+    }
+
+}

+ 14 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java

@@ -88,6 +88,14 @@ public interface AdminAuthService {
      */
     AuthLoginRespVO portalLogin(@Valid AuthPortalLoginReqVO reqVO);
 
+    /**
+     * 门户 登录 查询工号
+     *
+     * @param reqVO 登录信息
+     * @return 登录结果
+     */
+    AuthLoginRespVO portalSsoLogin(@Valid AuthPortalSsoLoginReqVO reqVO);
+
     /**
      * 刷新访问令牌
      *
@@ -111,4 +119,10 @@ public interface AdminAuthService {
      */
     void resetPassword(AuthResetPasswordReqVO reqVO);
 
+    /**
+     * 第三方登录
+     *
+     * @param reqVO appid username
+     */
+    String ssoGetToken(AuthPortalLoginReqVO reqVO);
 }

+ 54 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.system.service.auth;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
@@ -15,10 +16,13 @@ import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
 import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
 import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
+import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
+import cn.iocoder.yudao.module.system.dal.mysql.authentication.AuthenticationMapper;
 import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
 import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
 import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
@@ -45,7 +49,11 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import javax.validation.Validator;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.List;
 import java.util.Objects;
+import java.util.UUID;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@@ -87,6 +95,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
     @Setter // 为了单测:开启或者关闭验证码
     private Boolean captchaEnable;
 
+    @Resource
+    private AuthenticationMapper authenticationMapper;
     @Resource
     private AdminUserMapper userMapper;
 
@@ -313,6 +323,32 @@ public class AdminAuthServiceImpl implements AdminAuthService {
         }
     }
 
+    @Override
+    public AuthLoginRespVO portalSsoLogin(AuthPortalSsoLoginReqVO reqVO) {
+        if (StrUtil.isBlank(reqVO.getCode())) {
+            // 查询不到用户详情 返回 登录失败
+            throw exception(OAUTH2_CODE_NOT_EXISTS);
+        }
+        AuthenticationPageReqVO authReqVO = new AuthenticationPageReqVO();
+        authReqVO.setRandomCode(reqVO.getCode());
+        List<AuthenticationDO> authentications = authenticationMapper.selectList(authReqVO);
+        if (CollUtil.isNotEmpty(authentications)) {
+            AuthenticationDO auth = authentications.get(0);
+            // 如果随机码的创建时间 距离现在已经超过5分钟 则失效
+            LocalDateTime createTime = auth.getCreateTime();
+            LocalDateTime now = LocalDateTime.now();
+            // 计算时间差,如果超过5分钟则返回null
+            Duration duration = Duration.between(createTime, now);
+            if (duration.toMinutes() > 5) {
+                // 随机码已失效,不再生成token
+                return null;
+            }
+            // 创建 Token 令牌,记录登录日志 portal
+            return createTokenAfterLoginSuccess(auth.getUserid(), auth.getJobNumber(), LoginLogTypeEnum.LOGIN_PORTAL);
+        }
+        return null;
+    }
+
     @VisibleForTesting
     void validateCaptcha(AuthLoginReqVO reqVO) {
         ResponseModel response = doValidateCaptcha(reqVO);
@@ -429,4 +465,22 @@ public class AdminAuthServiceImpl implements AdminAuthService {
 
         userService.updateUserPassword(userByMobile.getId(), reqVO.getPassword());
     }
+
+    @Override
+    public String ssoGetToken(AuthPortalLoginReqVO reqVO) {
+        // 如果 当前用户表中存在 username 则返回随机 uuid 并存储到表 system_authentication
+        // 查询当前用户表中 用户 是否存在
+        AdminUserDO user = userMapper.selectByUsername(reqVO.getUsername());
+        if (ObjUtil.isEmpty(user)) {
+            throw exception(USER_NOT_EXISTS);
+        }
+        // 这里不生成pms令牌 先返回随机code
+        String randomCode = UUID.randomUUID().toString();
+        AuthenticationDO authentication = new AuthenticationDO();
+        authentication.setUserid(user.getId());
+        authentication.setJobNumber(reqVO.getUsername());
+        authentication.setRandomCode(randomCode);
+        authenticationMapper.insert(authentication);
+        return randomCode;
+    }
 }

+ 55 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/authentication/AuthenticationService.java

@@ -0,0 +1,55 @@
+package cn.iocoder.yudao.module.system.service.authentication;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationSaveReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
+
+import javax.validation.Valid;
+
+/**
+ * 认证 Service 接口
+ *
+ * @author ruiqi
+ */
+public interface AuthenticationService {
+
+    /**
+     * 创建认证
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createAuthentication(@Valid AuthenticationSaveReqVO createReqVO);
+
+    /**
+     * 更新认证
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateAuthentication(@Valid AuthenticationSaveReqVO updateReqVO);
+
+    /**
+     * 删除认证
+     *
+     * @param id 编号
+     */
+    void deleteAuthentication(Long id);
+
+    /**
+     * 获得认证
+     *
+     * @param id 编号
+     * @return 认证
+     */
+    AuthenticationDO getAuthentication(Long id);
+
+    /**
+     * 获得认证分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 认证分页
+     */
+    PageResult<AuthenticationDO> getAuthenticationPage(AuthenticationPageReqVO pageReqVO);
+
+}

+ 71 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/authentication/AuthenticationServiceImpl.java

@@ -0,0 +1,71 @@
+package cn.iocoder.yudao.module.system.service.authentication;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
+import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationSaveReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
+import cn.iocoder.yudao.module.system.dal.mysql.authentication.AuthenticationMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import javax.annotation.Resource;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.AUTHENTICATION_NOT_EXISTS;
+
+/**
+ * 认证 Service 实现类
+ *
+ * @author ruiqi
+ */
+@Service
+@Validated
+public class AuthenticationServiceImpl implements AuthenticationService {
+
+    @Resource
+    private AuthenticationMapper authenticationMapper;
+
+    @Override
+    public Long createAuthentication(AuthenticationSaveReqVO createReqVO) {
+        // 插入
+        AuthenticationDO authentication = BeanUtils.toBean(createReqVO, AuthenticationDO.class);
+        authenticationMapper.insert(authentication);
+        // 返回
+        return authentication.getId();
+    }
+
+    @Override
+    public void updateAuthentication(AuthenticationSaveReqVO updateReqVO) {
+        // 校验存在
+        validateAuthenticationExists(updateReqVO.getId());
+        // 更新
+        AuthenticationDO updateObj = BeanUtils.toBean(updateReqVO, AuthenticationDO.class);
+        authenticationMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteAuthentication(Long id) {
+        // 校验存在
+        validateAuthenticationExists(id);
+        // 删除
+        authenticationMapper.deleteById(id);
+    }
+
+    private void validateAuthenticationExists(Long id) {
+        if (authenticationMapper.selectById(id) == null) {
+            throw exception(AUTHENTICATION_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public AuthenticationDO getAuthentication(Long id) {
+        return authenticationMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<AuthenticationDO> getAuthenticationPage(AuthenticationPageReqVO pageReqVO) {
+        return authenticationMapper.selectPage(pageReqVO);
+    }
+
+}