Skip to content

Commit

Permalink
集成登录平台的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
YunlongChen committed Dec 19, 2023
1 parent 4b5c973 commit 1645af8
Show file tree
Hide file tree
Showing 84 changed files with 3,070 additions and 104 deletions.
8 changes: 1 addition & 7 deletions checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<property name="max" value="180"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

Expand Down Expand Up @@ -265,12 +265,6 @@
<module name="VariableDeclarationUsageDistance">
<property name="severity" value="warning"/>
</module>
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<!-- <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>-->
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
</module>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cn.chenyunlong.qing.domain.auth.admin;

import cn.chenyunlong.codegen.annotation.*;
import cn.chenyunlong.common.annotation.FieldDesc;
import cn.chenyunlong.common.constants.ValidStatus;
import cn.chenyunlong.jpa.support.BaseJpaAggregate;
import cn.chenyunlong.jpa.support.converter.ValidStatusConverter;
import cn.hutool.core.util.IdUtil;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@GenVo
@GenCreator
@GenUpdater
@GenQuery
@GenCreateRequest
@GenUpdateRequest
@GenQueryRequest
@GenResponse
@GenRepository
@GenService
@GenServiceImpl
@GenFeign(serverName = "stanic")
@GenController
@GenMapper
@Entity
@Table(name = "admin_account")
@Data
public class AdminAccount extends BaseJpaAggregate {

@FieldDesc(name = "手机号")
@NotBlank(message = "手机号不能为空")
private String phone;

@FieldDesc(name = "密码")
@IgnoreVo
@NotBlank(message = "密码不能为空")
private String password;

@FieldDesc(name = "用户名")
private String username;

private String uid;

private String realName;

@FieldDesc(name = "部门ID")
private Long departmentId;

@FieldDesc(name = "额外信息")
@Column(columnDefinition = "text")
private String extInfo;

@Convert(converter = ValidStatusConverter.class)
@IgnoreUpdater
@IgnoreCreator
private ValidStatus validStatus;

public void init() {
setValidStatus(ValidStatus.VALID);
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
setPassword(encoder.encode(getPassword()));
setUid(IdUtil.randomUUID().replaceAll("-", ""));
}

public void valid() {
setValidStatus(ValidStatus.VALID);
}

public void invalid() {
setValidStatus(ValidStatus.INVALID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.chenyunlong.qing.domain.auth.admin;

import cn.chenyunlong.codegen.annotation.GenRepository;
import cn.chenyunlong.jpa.support.BaseJpaAggregate;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.*;


@GenRepository
@Entity
@Table(name = "admin_account_platform_rel")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class AdminAccountPlatformRel extends BaseJpaAggregate {

private Long adminAccountId;

private Long platformId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.chenyunlong.qing.domain.auth.admin;

import cn.chenyunlong.codegen.annotation.GenRepository;
import cn.chenyunlong.jpa.support.BaseJpaAggregate;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.*;

@EqualsAndHashCode(callSuper = false)
@GenRepository
@Entity
@Table(name = "admin_account_role_rel")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AdminAccountRoleRel extends BaseJpaAggregate {

private Long adminAccountId;

private Long roleId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package cn.chenyunlong.qing.domain.auth.admin.controller;

import cn.chenyunlong.common.constants.CodeEnum;
import cn.chenyunlong.common.model.JsonResult;
import cn.chenyunlong.common.model.PageRequestWrapper;
import cn.chenyunlong.common.model.PageResult;
import cn.chenyunlong.qing.domain.auth.admin.dto.creator.AdminAccountCreator;
import cn.chenyunlong.qing.domain.auth.admin.dto.query.AdminAccountQuery;
import cn.chenyunlong.qing.domain.auth.admin.dto.request.*;
import cn.chenyunlong.qing.domain.auth.admin.dto.response.AdminAccountResponse;
import cn.chenyunlong.qing.domain.auth.admin.dto.updater.AdminAccountUpdater;
import cn.chenyunlong.qing.domain.auth.admin.dto.vo.AdminAccountVO;
import cn.chenyunlong.qing.domain.auth.admin.mapper.AdminAccountMapper;
import cn.chenyunlong.qing.domain.auth.admin.service.IAdminAccountService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.stream.Collectors;

@RestController
@Slf4j
@RequestMapping("api/v1/admin-account")
@RequiredArgsConstructor
public class AdminAccountController {
private final IAdminAccountService adminAccountService;

/**
* createRequest
*/
@PostMapping
public JsonResult<Long> createAdminAccount(@RequestBody AdminAccountCreateRequest request) {
AdminAccountCreator creator = AdminAccountMapper.INSTANCE.request2Dto(request);
return JsonResult.success(adminAccountService.createAdminAccount(creator));
}

/**
* update request
*/
@PostMapping("updateAdminAccount")
public JsonResult<String> updateAdminAccount(@RequestBody AdminAccountUpdateRequest request) {
AdminAccountUpdater updater = AdminAccountMapper.INSTANCE.request2Updater(request);
adminAccountService.updateAdminAccount(updater);
return JsonResult.success(CodeEnum.Success.getName());
}

/**
* valid
*/
@PostMapping("valid/{id}")
public JsonResult<String> validAdminAccount(@PathVariable Long id) {
adminAccountService.validAdminAccount(id);
return JsonResult.success(CodeEnum.Success.getName());
}

/**
* invalid
*/
@PostMapping("invalid/{id}")
public JsonResult<String> invalidAdminAccount(@PathVariable Long id) {
adminAccountService.invalidAdminAccount(id);
return JsonResult.success(CodeEnum.Success.getName());
}

/**
* 为用户分配角色
*/
@PostMapping(value = "assignRolesToUser")
public JsonResult<String> assignRolesToUser(@RequestBody UserRolesRequest request) {
adminAccountService.assignRolesToUser(request.getAccountId(), request.getRoleIds());
return JsonResult.success(CodeEnum.Success.getName());
}

/**
* 为用户分配平台
*/
@PostMapping("assignPlatformsToUser")
public JsonResult<String> assignPlatformsToUser(@RequestBody UserAuthPlatformsRequest request) {
adminAccountService.assignPlatformsToUser(request.getPlatformIds(), request.getAccountId());
return JsonResult.success(CodeEnum.Success.getName());
}

/**
* findById
*/
@GetMapping("findById/{id}")
public JsonResult<AdminAccountResponse> findById(@PathVariable Long id) {
AdminAccountVO vo = adminAccountService.findById(id);
AdminAccountResponse response = AdminAccountMapper.INSTANCE.vo2CustomResponse(vo);
return JsonResult.success(response);
}

/**
* findByPage request
*/
@PostMapping("page")
public JsonResult<PageResult<AdminAccountResponse>> page(
@RequestBody PageRequestWrapper<AdminAccountQueryRequest> request) {
PageRequestWrapper<AdminAccountQuery> wrapper = new PageRequestWrapper<>();
wrapper.setBean(AdminAccountMapper.INSTANCE.request2Query(request.getBean()));
wrapper.setSorts(request.getSorts());
wrapper.setPageSize(request.getPageSize());
wrapper.setPage(request.getPage());
Page<AdminAccountVO> page = adminAccountService.findByPage(wrapper);
return JsonResult.success(
PageResult.of(
page.getContent().stream()
.map(AdminAccountMapper.INSTANCE::vo2CustomResponse)
.collect(Collectors.toList()),
page.getTotalElements(),
page.getSize(),
page.getNumber())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cn.chenyunlong.qing.domain.auth.admin.dto.creator;

import io.swagger.v3.oas.annotations.media.Schema;

import java.lang.Long;
import java.lang.String;

import lombok.Data;

@Schema
@Data
public class AdminAccountCreator {
@Schema(
title = "phone",
description = "phone"
)
private String phone;

@Schema(
title = "password",
description = "password"
)
private String password;

@Schema(
title = "username",
description = "username"
)
private String username;

@Schema(
title = "uid",
description = "uid"
)
private String uid;

@Schema(
title = "realName",
description = "realName"
)
private String realName;

@Schema(
title = "departmentId",
description = "departmentId"
)
private Long departmentId;

@Schema(
title = "extInfo",
description = "extInfo"
)
private String extInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cn.chenyunlong.qing.domain.auth.admin.dto.query;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Schema
@Data
public class AdminAccountQuery {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cn.chenyunlong.qing.domain.auth.admin.dto.request;

import cn.chenyunlong.common.model.Request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Schema
@Data
public class AdminAccountCreateRequest implements Request {
@Schema(
title = "phone",
description = "phone"
)
private String phone;

@Schema(
title = "password",
description = "password"
)
private String password;

@Schema(
title = "username",
description = "username"
)
private String username;

@Schema(
title = "uid",
description = "uid"
)
private String uid;

@Schema(
title = "realName",
description = "realName"
)
private String realName;

@Schema(
title = "departmentId",
description = "departmentId"
)
private Long departmentId;

@Schema(
title = "extInfo",
description = "extInfo"
)
private String extInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cn.chenyunlong.qing.domain.auth.admin.dto.request;

import cn.chenyunlong.common.model.Request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Schema
@Data
public class AdminAccountQueryRequest implements Request {
}
Loading

0 comments on commit 1645af8

Please sign in to comment.