forked from rongchao/epmet-cloud-rizhao
40 changed files with 747 additions and 134 deletions
@ -1,48 +1,48 @@ |
|||||
/** |
///**
|
||||
* Copyright 2018 人人开源 https://www.renren.io
|
// * Copyright 2018 人人开源 https://www.renren.io
|
||||
* <p> |
// * <p>
|
||||
* This program is free software: you can redistribute it and/or modify |
// * This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by |
// * it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or |
// * the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version. |
// * (at your option) any later version.
|
||||
* <p> |
// * <p>
|
||||
* This program is distributed in the hope that it will be useful, |
// * This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details. |
// * GNU General Public License for more details.
|
||||
* <p> |
// * <p>
|
||||
* You should have received a copy of the GNU General Public License |
// * You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
// */
|
||||
|
//
|
||||
package com.epmet.service; |
//package com.epmet.service;
|
||||
|
//
|
||||
import org.junit.Test; |
//import org.junit.Test;
|
||||
import org.junit.runner.RunWith; |
//import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest; |
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner; |
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
//
|
||||
/** |
///**
|
||||
* 多数据源测试 |
// * 多数据源测试
|
||||
* |
// *
|
||||
* @author Mark sunlightcs@gmail.com |
// * @author Mark sunlightcs@gmail.com
|
||||
* @since 1.0.0 |
// * @since 1.0.0
|
||||
*/ |
// */
|
||||
@RunWith(SpringRunner.class) |
//@RunWith(SpringRunner.class)
|
||||
@SpringBootTest |
//@SpringBootTest
|
||||
public class DynamicDataSourceTest { |
//public class DynamicDataSourceTest {
|
||||
@Autowired |
// @Autowired
|
||||
private DynamicDataSourceTestService dynamicDataSourceTestService; |
// private com.epmet.service.DynamicDataSourceTestService dynamicDataSourceTestService;
|
||||
|
//
|
||||
@Test |
// @Test
|
||||
public void test(){ |
// public void test(){
|
||||
Long id = 1067246875800000001L; |
// Long id = 1067246875800000001L;
|
||||
dynamicDataSourceTestService.selectById(id); |
// dynamicDataSourceTestService.selectById(id);
|
||||
dynamicDataSourceTestService.updateUser(id); |
// dynamicDataSourceTestService.updateUser(id);
|
||||
dynamicDataSourceTestService.updateUserBySlave1(id); |
// dynamicDataSourceTestService.updateUserBySlave1(id);
|
||||
dynamicDataSourceTestService.updateUserBySlave2(id); |
// dynamicDataSourceTestService.updateUserBySlave2(id);
|
||||
} |
// }
|
||||
|
//
|
||||
|
//
|
||||
} |
//}
|
||||
|
@ -0,0 +1,15 @@ |
|||||
|
package com.epmet.commons.mybatis.constant; |
||||
|
|
||||
|
public class AccessSettingConstant { |
||||
|
public static final String I_CREATED_KEY = "I_CREATED"; |
||||
|
public static final String I_CREATED_YES = "YES"; |
||||
|
|
||||
|
public static final String I_PART_KEY = "I_PART"; |
||||
|
public static final String I_PART_YES = "YES"; |
||||
|
|
||||
|
public static final String IN_GRID_KEY = "IN_GRID"; |
||||
|
public static final String IN_GRID_YES = "YES"; |
||||
|
|
||||
|
public static final String IN_DEPARTMENT_KEY = "IN_DEPARTMENT"; |
||||
|
public static final String IN_DEPARTMENT_YES = "YES"; |
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.commons.mybatis.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 组织首页-获取机关下部门列表-部门详情数据 |
||||
|
* |
||||
|
* @author sun |
||||
|
*/ |
||||
|
@Data |
||||
|
public class DepartmentListResultDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 部门Id |
||||
|
*/ |
||||
|
private String departmentId; |
||||
|
|
||||
|
/** |
||||
|
* 部门名称 |
||||
|
*/ |
||||
|
private String departmentName; |
||||
|
|
||||
|
/** |
||||
|
* 部门下总人数 |
||||
|
*/ |
||||
|
private Integer totalUser; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package com.epmet.commons.mybatis.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class RoleAccessSettingResultDTO { |
||||
|
|
||||
|
private String settingKey; |
||||
|
private String id; |
||||
|
private String settingName; |
||||
|
private String roleId; |
||||
|
|
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package com.epmet.commons.mybatis.feign; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dto.form.*; |
||||
|
import com.epmet.commons.mybatis.feign.fallback.GovAccessFeignClientFallback; |
||||
|
import com.epmet.commons.mybatis.feign.fallback.GovOrgFeignClientFallback; |
||||
|
import com.epmet.commons.tools.constant.ServiceConstant; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import org.springframework.cloud.openfeign.FeignClient; |
||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Set; |
||||
|
|
||||
|
/** |
||||
|
* @Description |
||||
|
* @Author sun |
||||
|
*/ |
||||
|
//, url = "localhost:8092"
|
||||
|
@FeignClient(name = ServiceConstant.GOV_ORG_SERVER, fallback = GovOrgFeignClientFallback.class) |
||||
|
public interface GovOrgFeignClient { |
||||
|
|
||||
|
/** |
||||
|
* 查询人员部门列表 |
||||
|
* @param staffId |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/gov/org/department/staff/{staffId}/departmentlist") |
||||
|
Result<List<DepartmentListResultDTO>> getDepartmentListByStaffId(@PathVariable("staffId") String staffId); |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
package com.epmet.commons.mybatis.feign.fallback; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dto.form.*; |
||||
|
import com.epmet.commons.mybatis.feign.GovAccessFeignClient; |
||||
|
import com.epmet.commons.mybatis.feign.GovOrgFeignClient; |
||||
|
import com.epmet.commons.tools.constant.ServiceConstant; |
||||
|
import com.epmet.commons.tools.utils.ModuleUtils; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Set; |
||||
|
|
||||
|
/** |
||||
|
* 调用政府端权限 |
||||
|
* @Author wxz |
||||
|
* @Description |
||||
|
* @Date 2020/4/24 11:17 |
||||
|
**/ |
||||
|
@Component |
||||
|
public class GovOrgFeignClientFallback implements GovOrgFeignClient { |
||||
|
|
||||
|
@Override |
||||
|
public Result<List<DepartmentListResultDTO>> getDepartmentListByStaffId(String staffId) { |
||||
|
return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getDepartmentListByStaffId", staffId); |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.epmet.dto.result; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class RoleAccessSettingResultDTO { |
||||
|
|
||||
|
private String settingKey; |
||||
|
private String id; |
||||
|
private String settingName; |
||||
|
private String settingValue; |
||||
|
private String roleId; |
||||
|
|
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dao; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.dto.result.RoleAccessSettingResultDTO; |
||||
|
import com.epmet.entity.RoleAccessSettingEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 权限配置 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-26 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface RoleAccessSettingDao extends BaseDao<RoleAccessSettingEntity> { |
||||
|
|
||||
|
List<RoleAccessSettingResultDTO> listRoleAccessSettingsByRoleId(String roleId); |
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 权限配置 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2020-04-26 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("role_access_setting") |
||||
|
public class RoleAccessSettingEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 配置KEY |
||||
|
*/ |
||||
|
private String settingKey; |
||||
|
|
||||
|
/** |
||||
|
* 配置name |
||||
|
*/ |
||||
|
private String settingName; |
||||
|
/** |
||||
|
* 配置值 |
||||
|
*/ |
||||
|
private String settingValue; |
||||
|
|
||||
|
/** |
||||
|
* 角色ID |
||||
|
*/ |
||||
|
private String roleId; |
||||
|
|
||||
|
/** |
||||
|
* 操作简介 |
||||
|
*/ |
||||
|
private String brief; |
||||
|
|
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
package com.epmet.redis; |
||||
|
|
||||
|
import com.epmet.commons.tools.redis.RedisKeys; |
||||
|
import com.epmet.commons.tools.redis.RedisUtils; |
||||
|
import com.epmet.dto.result.RoleAccessSettingResultDTO; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.function.BiConsumer; |
||||
|
|
||||
|
@Component |
||||
|
public class RoleAccessSettingRedis { |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisUtils redisUtils; |
||||
|
|
||||
|
public void set(Map<String, Object> settings, String roleId) { |
||||
|
String roleAccessSettingKey = RedisKeys.getRoleAccessSettingKey(roleId); |
||||
|
redisUtils.hMSet(roleAccessSettingKey, settings); |
||||
|
} |
||||
|
|
||||
|
public Map<String, String> get(String roleId) { |
||||
|
String roleAccessSettingKey = RedisKeys.getRoleAccessSettingKey(roleId); |
||||
|
Map<String, Object> s = redisUtils.hGetAll(roleAccessSettingKey); |
||||
|
Map<String, String> settings = new HashMap<>(); |
||||
|
s.forEach((s1, o) -> { |
||||
|
if (o != null) { |
||||
|
settings.put(s1, String.valueOf(o)); |
||||
|
} |
||||
|
}); |
||||
|
return settings; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.epmet.dao.RoleAccessSettingDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.RoleAccessSettingEntity" id="roleAccessSettingMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="settingKey" column="SETTING_KEY"/> |
||||
|
<result property="settingName" column="SETTING_NAME"/> |
||||
|
<result property="settingValue" column="SETTING_VALUE"/> |
||||
|
<result property="roleId" column="ROLE_ID"/> |
||||
|
<result property="brief" column="BRIEF"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<!--查询角色的权限相关配置--> |
||||
|
<select id="listRoleAccessSettingsByRoleId" resultType="com.epmet.dto.result.RoleAccessSettingResultDTO"> |
||||
|
select settings.* |
||||
|
from role_access_setting settings |
||||
|
where ROLE_ID = #{roleId} |
||||
|
AND DEL_FLAG = '0' |
||||
|
</select> |
||||
|
|
||||
|
|
||||
|
</mapper> |
@ -0,0 +1,38 @@ |
|||||
|
package com.epmet.test.govaccess; |
||||
|
|
||||
|
import com.epmet.dao.RoleAccessSettingDao; |
||||
|
import com.epmet.dto.result.RoleAccessSettingResultDTO; |
||||
|
import com.epmet.redis.RoleAccessSettingRedis; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RunWith(SpringRunner.class) |
||||
|
@SpringBootTest |
||||
|
public class AccessSettingTest { |
||||
|
|
||||
|
@Autowired |
||||
|
private RoleAccessSettingDao roleAccessSettingDao; |
||||
|
|
||||
|
@Autowired |
||||
|
private RoleAccessSettingRedis roleAccessSettingRedis; |
||||
|
|
||||
|
@Test |
||||
|
public void addAccessSettings2Redis() { |
||||
|
List<RoleAccessSettingResultDTO> settings = roleAccessSettingDao.listRoleAccessSettingsByRoleId("1"); |
||||
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>(); |
||||
|
settings.forEach(s -> { |
||||
|
objectObjectHashMap.put(s.getSettingKey(), s.getSettingValue()); |
||||
|
}); |
||||
|
roleAccessSettingRedis.set(objectObjectHashMap, "1"); |
||||
|
Map<String, String> map = roleAccessSettingRedis.get("1"); |
||||
|
System.out.println(map); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue