第三方配置
This commit is contained in:
parent
cdc1fd0883
commit
ab1e2efc78
|
@ -0,0 +1,77 @@
|
|||
package net.maku.system.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.query.Query;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.system.convert.SysThirdLoginConfigConvert;
|
||||
import net.maku.system.entity.SysThirdLoginConfigEntity;
|
||||
import net.maku.system.service.SysThirdLoginConfigService;
|
||||
import net.maku.system.vo.SysThirdLoginConfigVO;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys/third/config")
|
||||
@Tag(name = "第三方登录配置")
|
||||
@AllArgsConstructor
|
||||
public class SysThirdLoginConfigController {
|
||||
private final SysThirdLoginConfigService sysThirdLoginConfigService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('third:config:all')")
|
||||
public Result<PageResult<SysThirdLoginConfigVO>> page(@ParameterObject @Valid Query query) {
|
||||
PageResult<SysThirdLoginConfigVO> page = sysThirdLoginConfigService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('third:config:all')")
|
||||
public Result<SysThirdLoginConfigVO> get(@PathVariable("id") Long id) {
|
||||
SysThirdLoginConfigEntity entity = sysThirdLoginConfigService.getById(id);
|
||||
|
||||
return Result.ok(SysThirdLoginConfigConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('third:config:all')")
|
||||
public Result<String> save(@RequestBody SysThirdLoginConfigVO vo) {
|
||||
sysThirdLoginConfigService.save(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('third:config:all')")
|
||||
public Result<String> update(@RequestBody @Valid SysThirdLoginConfigVO vo) {
|
||||
sysThirdLoginConfigService.update(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('third:config:all')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList) {
|
||||
sysThirdLoginConfigService.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.maku.system.convert;
|
||||
|
||||
import net.maku.system.entity.SysThirdLoginConfigEntity;
|
||||
import net.maku.system.vo.SysThirdLoginConfigVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysThirdLoginConfigConvert {
|
||||
SysThirdLoginConfigConvert INSTANCE = Mappers.getMapper(SysThirdLoginConfigConvert.class);
|
||||
|
||||
SysThirdLoginConfigEntity convert(SysThirdLoginConfigVO vo);
|
||||
|
||||
SysThirdLoginConfigVO convert(SysThirdLoginConfigEntity entity);
|
||||
|
||||
List<SysThirdLoginConfigVO> convertList(List<SysThirdLoginConfigEntity> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package net.maku.system.dao;
|
||||
|
||||
import net.maku.framework.mybatis.dao.BaseDao;
|
||||
import net.maku.system.entity.SysThirdLoginConfigEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysThirdLoginConfigDao extends BaseDao<SysThirdLoginConfigEntity> {
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package net.maku.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_third_login_config")
|
||||
public class SysThirdLoginConfigEntity {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 开放平台类型
|
||||
*/
|
||||
private String openType;
|
||||
|
||||
/**
|
||||
* ClientID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* ClientSecret
|
||||
*/
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* RedirectUri
|
||||
*/
|
||||
private String redirectUri;
|
||||
|
||||
/**
|
||||
* AgentID
|
||||
*/
|
||||
private String agentId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
@Version
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Integer deleted;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package net.maku.system.service;
|
||||
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import net.maku.framework.common.query.Query;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.BaseService;
|
||||
import net.maku.system.entity.SysThirdLoginConfigEntity;
|
||||
import net.maku.system.vo.SysThirdLoginConfigVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
public interface SysThirdLoginConfigService extends BaseService<SysThirdLoginConfigEntity> {
|
||||
|
||||
PageResult<SysThirdLoginConfigVO> page(Query query);
|
||||
|
||||
void save(SysThirdLoginConfigVO vo);
|
||||
|
||||
void update(SysThirdLoginConfigVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 根据类型,获取授权请求
|
||||
*
|
||||
* @param openType 第三方登录类型
|
||||
*/
|
||||
AuthRequest getAuthRequest(String openType);
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package net.maku.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.request.*;
|
||||
import net.maku.framework.common.exception.ServerException;
|
||||
import net.maku.framework.common.query.Query;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.system.convert.SysThirdLoginConfigConvert;
|
||||
import net.maku.system.dao.SysThirdLoginConfigDao;
|
||||
import net.maku.system.entity.SysThirdLoginConfigEntity;
|
||||
import net.maku.system.enums.ThirdLoginEnum;
|
||||
import net.maku.system.service.SysThirdLoginConfigService;
|
||||
import net.maku.system.vo.SysThirdLoginConfigVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysThirdLoginConfigServiceImpl extends BaseServiceImpl<SysThirdLoginConfigDao, SysThirdLoginConfigEntity> implements SysThirdLoginConfigService {
|
||||
|
||||
@Override
|
||||
public PageResult<SysThirdLoginConfigVO> page(Query query) {
|
||||
IPage<SysThirdLoginConfigEntity> page = baseMapper.selectPage(getPage(query), Wrappers.lambdaQuery());
|
||||
|
||||
return new PageResult<>(SysThirdLoginConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(SysThirdLoginConfigVO vo) {
|
||||
SysThirdLoginConfigEntity entity = SysThirdLoginConfigConvert.INSTANCE.convert(vo);
|
||||
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(SysThirdLoginConfigVO vo) {
|
||||
SysThirdLoginConfigEntity entity = SysThirdLoginConfigConvert.INSTANCE.convert(vo);
|
||||
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthRequest getAuthRequest(String openType) {
|
||||
SysThirdLoginConfigEntity config = baseMapper.selectOne(new LambdaQueryWrapper<SysThirdLoginConfigEntity>()
|
||||
.eq(SysThirdLoginConfigEntity::getOpenType, openType));
|
||||
|
||||
if (config == null) {
|
||||
throw new ServerException("未找到第三方登录配置");
|
||||
}
|
||||
|
||||
AuthRequest authRequest = switch (ThirdLoginEnum.toEnum(openType)) {
|
||||
case WECHAT_WORK -> new AuthWeChatEnterpriseQrcodeRequest(AuthConfig.builder()
|
||||
.clientId(config.getClientId())
|
||||
.clientSecret(config.getClientSecret())
|
||||
.redirectUri(config.getRedirectUri())
|
||||
.agentId(config.getAgentId())
|
||||
.build());
|
||||
case DING_TALK -> new AuthDingTalkRequest(AuthConfig.builder()
|
||||
.clientId(config.getClientId())
|
||||
.clientSecret(config.getClientSecret())
|
||||
.redirectUri(config.getRedirectUri())
|
||||
.build());
|
||||
case FEI_SHU -> new AuthFeishuRequest(AuthConfig.builder()
|
||||
.clientId(config.getClientId())
|
||||
.clientSecret(config.getClientSecret())
|
||||
.redirectUri(config.getRedirectUri())
|
||||
.build());
|
||||
case WECHAT_OPEN -> new AuthWeChatOpenRequest(AuthConfig.builder()
|
||||
.clientId(config.getClientId())
|
||||
.clientSecret(config.getClientSecret())
|
||||
.redirectUri(config.getRedirectUri())
|
||||
.build());
|
||||
};
|
||||
|
||||
return authRequest;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package net.maku.system.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.maku.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 第三方登录配置
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* <a href="https://maku.net">MAKU</a>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "第三方登录配置")
|
||||
public class SysThirdLoginConfigVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "开放平台类型")
|
||||
private String openType;
|
||||
|
||||
@Schema(description = "ClientID")
|
||||
private String clientId;
|
||||
|
||||
@Schema(description = "ClientSecret")
|
||||
private String clientSecret;
|
||||
|
||||
@Schema(description = "RedirectUri")
|
||||
private String redirectUri;
|
||||
|
||||
@Schema(description = "AgentID")
|
||||
private String agentId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user