Skip to content

Commit

Permalink
Merge pull request #52 from Jzow/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jzow authored Sep 25, 2023
2 parents 72dd13d + bf6206c commit 13adb92
Show file tree
Hide file tree
Showing 23 changed files with 542 additions and 102 deletions.
68 changes: 34 additions & 34 deletions api/src/main/java/com/wansensoft/api/config/MybatisPlusConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public MybatisPlusConfig(RedisUtil redisUtil) {
* @return
*/
public Long getTenantIdByToken(String token) {
long tenantId = 0L;
long tenantId = -1L;
if(StringUtils.hasText(token)) {
tenantId = Long.parseLong(redisUtil.getString(token + ":tenantId"));
}
Expand All @@ -53,39 +53,39 @@ public Long getTenantIdByToken(String token) {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(HttpServletRequest request) {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
// @Override
// public Expression getTenantId() {
// String token = request.getHeader("Authorization");
// Long tenantId = getTenantIdByToken(token);
// if (tenantId!=0L) {
// return new LongValue(tenantId);
// } else {
// //超管
// return null;
// }
// }
//
// // 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
// @Override
// public boolean ignoreTable(String tableName) {
// //获取开启状态
// boolean res = true;
// String token = request.getHeader("Authorization");
// Long tenantId = getTenantIdByToken(token);
// if (tenantId!=0L) {
// // 这里可以判断是否过滤表
// if ("jsh_material_property".equals(tableName) || "jsh_sequence".equals(tableName)
// || "jsh_user_business".equals(tableName) || "jsh_function".equals(tableName)
// || "jsh_platform_config".equals(tableName) || "jsh_tenant".equals(tableName)) {
// res = true;
// } else {
// res = false;
// }
// }
// return res;
// }
// }));
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
@Override
public Expression getTenantId() {
String token = request.getHeader("Authorization");
Long tenantId = getTenantIdByToken(token);
if (tenantId!=0L) {
return new LongValue(tenantId);
} else {
//超管
return null;
}
}

// 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
@Override
public boolean ignoreTable(String tableName) {
//获取开启状态
boolean res = true;
String token = request.getHeader("Authorization");
Long tenantId = getTenantIdByToken(token);
if (tenantId!=0L) {
// 这里可以判断是否过滤表
if ("sys_user".equals(tableName) || "jsh_sequence".equals(tableName)
|| "jsh_user_business".equals(tableName) || "jsh_function".equals(tableName)
|| "jsh_platform_config".equals(tableName) || "jsh_tenant".equals(tableName)) {
res = true;
} else {
res = false;
}
}
return res;
}
}));


// 如果用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
Expand Down
26 changes: 19 additions & 7 deletions api/src/main/java/com/wansensoft/api/role/SysRoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
package com.wansensoft.api.role;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansensoft.dto.role.RoleListDTO;
import com.wansensoft.service.role.ISysRoleService;
import com.wansensoft.service.role.KtSysRoleService;
import com.wansensoft.service.system.ISysMenuService;
import com.wansensoft.utils.response.Response;
import com.wansensoft.vo.RoleVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -40,20 +40,32 @@ public class SysRoleController {

private final ISysRoleService roleService;

public SysRoleController(ISysMenuService menuService, ISysRoleService roleService) {
private final KtSysRoleService ktSysRoleService;

public SysRoleController(ISysMenuService menuService, ISysRoleService roleService, KtSysRoleService ktSysRoleService) {
this.menuService = menuService;
this.roleService = roleService;
this.ktSysRoleService = ktSysRoleService;
}


@GetMapping("menu")
public Response<JSONObject> queryMenu() {
return menuService.menuList();
}

@GetMapping("list")
public Response<List<RoleVO>> getRoleList() {
return roleService.roleList();
return ktSysRoleService.roleList();
}

@PostMapping("PageList")
public Response<Page<RoleVO>> getRolePageList(@RequestBody RoleListDTO roleListDTO) {
return ktSysRoleService.rolePageList(roleListDTO);
}

@PostMapping("updateStatus")
public Response<String> updateStatus(@RequestParam(value = "id") String id, @RequestParam(value = "status") Integer status) {
return ktSysRoleService.updateStatus(id, status);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public Response<String> addOrUpdate(@RequestBody AddOrUpdateUserDTO addOrUpdateU
public Response<String> deleteUser(@RequestParam(value = "ids") List<Long> ids) {
return userService.deleteUser(ids);
}

@PostMapping(value = "resetPassword")
public Response<String> resetPassword(@RequestParam(value = "id") Long id) {
return userService.resetPassword(id);
}
}
14 changes: 14 additions & 0 deletions domain/src/main/java/com/wansensoft/dto/role/RoleListDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wansensoft.dto.role;

import com.wansensoft.dto.PageSizeDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class RoleListDTO extends PageSizeDTO {

private String roleName;

private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class AddOrUpdateUserDTO {

private String username;

private String password;

private String phoneNumber;

private String email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ public class SysUser implements Serializable {
/**
* 删除标记,0未删除,1删除
*/
private Boolean deleteFlag;
private Integer deleteFlag;
}
7 changes: 7 additions & 0 deletions domain/src/main/java/com/wansensoft/vo/RoleVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
Expand All @@ -36,4 +38,9 @@ public class RoleVO {
private Integer priceLimit;

private Integer status;

private String description;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
}
51 changes: 38 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<kotlin.version>1.9.10</kotlin.version>
</properties>

<dependencies>
<dependency>
Expand Down Expand Up @@ -59,10 +60,14 @@
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<build>
<finalName>wansenerp</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
Expand All @@ -75,6 +80,36 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -96,16 +131,6 @@
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.mybatis.generator</groupId>-->
<!-- <artifactId>mybatis-generator-maven-plugin</artifactId>-->
<!-- <version>1.4.0</version>-->
<!-- <configuration>-->
<!-- <configurationFile>${basedir}/src/test/resources/generatorConfig.xml</configurationFile>-->
<!-- <verbose>true</verbose>-->
<!-- <overwrite>true</overwrite>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package com.wansensoft.service.role;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansensoft.dto.role.RoleListDTO;
import com.wansensoft.entities.role.SysRole;
import com.baomidou.mybatisplus.extension.service.IService;
import com.wansensoft.utils.response.Response;
Expand All @@ -27,4 +29,8 @@
public interface ISysRoleService extends IService<SysRole> {

Response<List<RoleVO>> roleList();

Response<Page<RoleVO>> rolePageList(RoleListDTO roleListDTO);

Response<String> updateStatus(String id, Integer status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.service.role

import com.wansensoft.entities.role.SysRoleMenuRel
import com.baomidou.mybatisplus.extension.service.IService

interface KtSysRoleMenuRelService : IService<SysRoleMenuRel> {

fun listByRoleId(roleId: Long?): List<SysRoleMenuRel>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansensoft.service.role

import com.wansensoft.entities.role.SysRoleMenuRel
import com.wansensoft.mappers.role.SysRoleMenuRelMapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service

@Service
open class KtSysRoleMenuRelServiceImpl : ServiceImpl<SysRoleMenuRelMapper, SysRoleMenuRel>(), KtSysRoleMenuRelService {

override fun listByRoleId(roleId: Long?): List<SysRoleMenuRel> {
requireNotNull(roleId) { "roleId must not be null" }

return lambdaQuery()
.eq(SysRoleMenuRel::getRoleId, roleId)
.list()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wansensoft.service.role

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.IService
import com.wansensoft.dto.role.RoleListDTO
import com.wansensoft.entities.role.SysRole
import com.wansensoft.utils.response.Response
import com.wansensoft.vo.RoleVO

interface KtSysRoleService : IService<SysRole> {

fun roleList() : Response<List<RoleVO>>

fun rolePageList(roleListDTO: RoleListDTO?) : Response<Page<RoleVO>>

fun updateStatus(id: String?, status: Int?) : Response<String>
}
Loading

0 comments on commit 13adb92

Please sign in to comment.