|
@@ -13,20 +13,31 @@ import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
|
import com.boman.common.redis.RedisKey;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
+import com.boman.domain.GenTable;
|
|
|
+import com.boman.domain.GenTableColumn;
|
|
|
import com.boman.domain.SysDictData;
|
|
|
+import com.boman.domain.SysRoleData;
|
|
|
import com.boman.domain.constant.*;
|
|
|
import com.boman.gen.api.RemoteGenTableColumnService;
|
|
|
import com.boman.gen.api.RemoteGenTableService;
|
|
|
-import com.boman.domain.GenTable;
|
|
|
-import com.boman.domain.GenTableColumn;
|
|
|
+import com.boman.system.api.RemoteDeptService;
|
|
|
import com.boman.system.api.RemoteDictDataService;
|
|
|
+import com.boman.system.api.RemoteRoleDataService;
|
|
|
+import com.boman.system.api.RemoteUserService;
|
|
|
import com.boman.system.api.domain.SysFile;
|
|
|
-import com.boman.web.core.domain.*;
|
|
|
+import com.boman.system.api.domain.SysRole;
|
|
|
+import com.boman.system.api.domain.SysUser;
|
|
|
+import com.boman.system.api.model.LoginUser;
|
|
|
+import com.boman.web.core.domain.ActionType;
|
|
|
+import com.boman.web.core.domain.FormDataDto;
|
|
|
+import com.boman.web.core.domain.RowResult;
|
|
|
+import com.boman.web.core.domain.TableContext;
|
|
|
import com.boman.web.core.service.delete.IBaseDeleteService;
|
|
|
import com.boman.web.core.service.save.IBaseSaveService;
|
|
|
import com.boman.web.core.service.select.IBaseSelectService;
|
|
|
import com.boman.web.core.service.submit.IBaseSubmitService;
|
|
|
import com.boman.web.core.service.update.IBaseUpdateService;
|
|
|
+import com.boman.web.core.utils.AuthUtils;
|
|
|
import com.boman.web.core.utils.IdUtils;
|
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
@@ -45,6 +56,7 @@ import java.util.function.Predicate;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
import static com.boman.domain.constant.FormDataConstant.*;
|
|
|
+import static com.boman.web.core.utils.AuthUtils.containsFunction;
|
|
|
import static com.boman.web.core.utils.ColumnUtils.*;
|
|
|
|
|
|
/**
|
|
@@ -70,18 +82,27 @@ public class TableServiceCmdService {
|
|
|
@Resource
|
|
|
private RestTemplate restTemplate;
|
|
|
@Resource
|
|
|
+ private TableContext tableContext;
|
|
|
+ @Resource
|
|
|
private RemoteDictDataService remoteDictDataService;
|
|
|
@Resource
|
|
|
private RemoteGenTableService remoteGenTableService;
|
|
|
@Resource
|
|
|
private RemoteGenTableColumnService remoteGenTableColumnService;
|
|
|
+ @Resource
|
|
|
+ private RemoteDeptService remoteDeptService;
|
|
|
+ @Resource
|
|
|
+ private RemoteRoleDataService remoteRoleDataService;
|
|
|
+ @Resource
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
|
public final AjaxResult objectSave(FormDataDto dto) {
|
|
|
AjaxResult result = AjaxResult.success();
|
|
|
|
|
|
- TableContext context = TableContext.createContext(dto);
|
|
|
+ // 权限校验在此方法中
|
|
|
+ TableContext context = tableContext.createContext(dto);
|
|
|
// 拿到pkName和maxId
|
|
|
String pkName = context.getPkName();
|
|
|
JSONObject commitData = context.getCommitData();
|
|
@@ -208,17 +229,18 @@ public class TableServiceCmdService {
|
|
|
*/
|
|
|
public AjaxResult queryList(FormDataDto dto) {
|
|
|
requireNonNull(dto.getTable(), "tableName = [" + dto.getTable() + "] 此表不存在");
|
|
|
-
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
JSONObject fixedData = ifNullSetEmpty(dto.getFixedData());
|
|
|
List<GenTableColumn> columns = genTable.getColumns();
|
|
|
|
|
|
// 查询条件
|
|
|
JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
|
|
|
+ // 权限
|
|
|
+ checkQueryListAuth(genTable, condition);
|
|
|
// 检查列
|
|
|
checkColumn(condition, columns);
|
|
|
// 封装好以后的查询条件
|
|
|
- JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
|
|
|
+ JSONObject packCondition = ifNullSetEmpty(selectService.packColCondition(columns, condition));
|
|
|
JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
|
|
|
// 检查列
|
|
|
checkColumn(showData, genTable.getColumns());
|
|
@@ -249,6 +271,26 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(rows);
|
|
|
}
|
|
|
|
|
|
+ private void checkQueryListAuth(GenTable genTable, JSONObject condition) {
|
|
|
+ containsFunction(genTable.getMenuRole(), GenTable.Q, "此模块:[" + genTable.getTableName() + "], 没有查询功能");
|
|
|
+
|
|
|
+ LoginUser loginUser = AuthUtils.getLoginUser();
|
|
|
+ if (SysUser.isAdmin(loginUser.getUserid())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> roleIdList = map(loginUser.getSysUser().getRoles(), SysRole::getId);
|
|
|
+ List<SysRoleData> roleDataList = remoteRoleDataService.listByRoleIdList(roleIdList);
|
|
|
+ if (isEmpty(roleDataList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 此张表所对应的roleData
|
|
|
+ SysRoleData roleData = filterOne(roleDataList, sysRoleData -> genTable.getTableName().equals(sysRoleData.getTableName()));
|
|
|
+ packAuthCondition(roleData.getDataScope(), condition, loginUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void handler(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
|
// 处理时间
|
|
|
handlerDate(result, columns);
|
|
@@ -426,33 +468,6 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(result);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 封装成查询条件 key: 列名, value:查询条件_查询类别
|
|
|
- * eg: [{"config_name": ["系统配置", "EQ", "varchar(100)"]}]
|
|
|
- *
|
|
|
- * @param columns columns
|
|
|
- * @return com.alibaba.fastjson.JSONObject
|
|
|
- */
|
|
|
- private JSONObject packColCondition(List<GenTableColumn> columns, JSONObject condition) {
|
|
|
- requireNonNull(columns);
|
|
|
-
|
|
|
- JSONObject result = new JSONObject(columns.size());
|
|
|
- for (Map.Entry<String, Object> entry : condition.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- Object value = entry.getValue();
|
|
|
- for (GenTableColumn column : columns) {
|
|
|
- // long string collection 暂时只作此三种类型判断
|
|
|
- if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
|
|
|
- // columnType 作为判断需不需要转义的一个标准,防止索引失效
|
|
|
- result.put(key, Lists.newArrayList(String.valueOf(value), column.getQueryType(), column.getColumnType()));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 获取表单查询字段、按钮、表头
|
|
|
* 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
|
|
@@ -806,5 +821,27 @@ public class TableServiceCmdService {
|
|
|
}
|
|
|
return sysDictData;
|
|
|
}
|
|
|
+
|
|
|
+ public void packAuthCondition (String dataScope, JSONObject condition, LoginUser loginUser) {
|
|
|
+ requireNonNull(dataScope, "dataScope is empty");
|
|
|
+
|
|
|
+ switch (dataScope){
|
|
|
+ case SysRoleData.ALL_DATA:
|
|
|
+ break;
|
|
|
+ case SysRoleData.DIY_DATA:
|
|
|
+ break;
|
|
|
+ case SysRoleData.SELF_DEPT_DATA:
|
|
|
+ // 本部门人员
|
|
|
+ condition.put(FormDataConstant.CREATE_BY, loginUser.getDeptUserIds());
|
|
|
+ break;
|
|
|
+ case SysRoleData.ALL_DEPT_DATA:
|
|
|
+ // 本部门以及子部门
|
|
|
+ condition.put(FormDataConstant.CREATE_BY, loginUser.getSubDeptUserIds());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|