提交 feea6b9a 编写于 作者: ibizdev's avatar ibizdev

ibizdev提交

上级 1ec8ec0c
*2020-4-29*
初始化文件
<template>
<codelist v-if="tag" :tag="tag" :value="value" :codelistType="codelistType" :renderMode="renderMode" :valueSeparator="valueSeparator" :textSeparator="textSeparator"></codelist>
<app-upload-file-info v-else-if="Object.is(this.editorType,'PICTURE') || Object.is(this.editorType,'PICTURE_ONE') || Object.is(this.editorType,'FILEUPLOADER')" :value="value" :name="name"></app-upload-file-info>
<span class="app-span" v-else >{{text}}</span>
</template>
......@@ -18,6 +19,14 @@ export default class DropDownList extends Vue {
*/
@Prop() public value?: any;
/**
* 当前表单项名称
*
* @type {*}
* @memberof AppSpan
*/
@Prop() public name?: any;
/**
* 代码表标识
*
......@@ -99,15 +108,6 @@ export default class DropDownList extends Vue {
public load(){
if(!this.value || this.tag){
return; //代码表走codelist组件
} else if(Object.is(this.editorType,'PICTURE') || Object.is(this.editorType,'PICTURE_ONE') || Object.is(this.editorType,'FILEUPLOADER')){
let files: any[] = JSON.parse(this.value);
let names: any[] = [];
if(files.length && files.length > 0){
files.forEach((item:any) => {
names.push(item.name);
});
this.text = names.join(',');
}
}else{
this.text = this.value;
}
......
......@@ -15,5 +15,6 @@ export default {
permissionid: '系统资源标识',
createdate: '建立时间',
updatedate: '更新时间',
permissiontype: '资源类型',
},
};
\ No newline at end of file
......@@ -14,5 +14,6 @@ export default {
permissionid: '系统资源标识',
createdate: '建立时间',
updatedate: '更新时间',
permissiontype: '资源类型',
},
};
\ No newline at end of file
......@@ -21,7 +21,8 @@
</i-col>
<i-col v-show="detailsModel.sys_permissionid.visible" :style="{}" :lg="{ span: 24, offset: 0 }">
<app-form-item name='sys_permissionid' :itemRules="this.rules.sys_permissionid" class='' :caption="$t('entities.sys_permission.main_form.details.sys_permissionid')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.sys_permissionid.error" :isEmptyCaption="false" labelPos="LEFT">
<app-span :value="data.sys_permissionid" style=""></app-span>
<app-span name='sys_permissionid'
:value="data.sys_permissionid" style=""></app-span>
</app-form-item>
</i-col>
......
......@@ -34,7 +34,8 @@
</i-col>
<i-col v-show="detailsModel.type.visible" :style="{}" :lg="{ span: 24, offset: 0 }">
<app-form-item name='type' :itemRules="this.rules.type" class='' :caption="$t('entities.sys_role_permission.main_form.details.type')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.type.error" :isEmptyCaption="false" labelPos="LEFT">
<app-span :value="data.type" tag='CLPermissionType' codelistType='STATIC' style=""></app-span>
<app-span name='type'
:value="data.type" tag='CLPermissionType' codelistType='STATIC' style=""></app-span>
</app-form-item>
</i-col>
......@@ -65,7 +66,8 @@
</i-col>
<i-col v-show="detailsModel.sys_role_permissionid.visible" :style="{}" :lg="{ span: 24, offset: 0 }">
<app-form-item name='sys_role_permissionid' :itemRules="this.rules.sys_role_permissionid" class='' :caption="$t('entities.sys_role_permission.main_form.details.sys_role_permissionid')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.sys_role_permissionid.error" :isEmptyCaption="false" labelPos="LEFT">
<app-span :value="data.sys_role_permissionid" style=""></app-span>
<app-span name='sys_role_permissionid'
:value="data.sys_role_permissionid" style=""></app-span>
</app-form-item>
</i-col>
......
......@@ -21,7 +21,8 @@
</i-col>
<i-col v-show="detailsModel.sys_roleid.visible" :style="{}" :lg="{ span: 24, offset: 0 }">
<app-form-item name='sys_roleid' :itemRules="this.rules.sys_roleid" class='' :caption="$t('entities.sys_role.main_form.details.sys_roleid')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.sys_roleid.error" :isEmptyCaption="false" labelPos="LEFT">
<app-span :value="data.sys_roleid" style=""></app-span>
<app-span name='sys_roleid'
:value="data.sys_roleid" style=""></app-span>
</app-form-item>
</i-col>
......
......@@ -21,7 +21,8 @@
</i-col>
<i-col v-show="detailsModel.sys_user_roleid.visible" :style="{}" :lg="{ span: 24, offset: 0 }">
<app-form-item name='sys_user_roleid' :itemRules="this.rules.sys_user_roleid" class='' :caption="$t('entities.sys_user_role.main_form.details.sys_user_roleid')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.sys_user_roleid.error" :isEmptyCaption="false" labelPos="LEFT">
<app-span :value="data.sys_user_roleid" style=""></app-span>
<app-span name='sys_user_roleid'
:value="data.sys_user_roleid" style=""></app-span>
</app-form-item>
</i-col>
......
......@@ -135,6 +135,13 @@ public class SYS_PSDEOPPRIV extends EntityMP implements Serializable {
@JSONField(name = "updatedate" , format="yyyy-MM-dd HH:mm:ss")
@JsonProperty("updatedate")
private Timestamp updatedate;
/**
* 资源类型
*/
@TableField(value = "permissiontype")
@JSONField(name = "permissiontype")
@JsonProperty("permissiontype")
private String permissiontype;
......@@ -215,6 +222,13 @@ public class SYS_PSDEOPPRIV extends EntityMP implements Serializable {
this.permissionid = permissionid ;
this.modify("permissionid",permissionid);
}
/**
* 设置 [资源类型]
*/
public void setPermissiontype(String permissiontype){
this.permissiontype = permissiontype ;
this.modify("permissiontype",permissiontype);
}
}
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[权限/资源] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_PERMISSIONServiceImpl")
public class SYS_PERMISSIONServiceImpl extends ServiceImpl<SYS_PERMISSIONMapper, SYS_PERMISSION> implements ISYS_PERMISSIONService {
@Autowired
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[系统菜单项] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_PSAPPMENUITEMServiceImpl")
public class SYS_PSAPPMENUITEMServiceImpl extends ServiceImpl<SYS_PSAPPMENUITEMMapper, SYS_PSAPPMENUITEM> implements ISYS_PSAPPMENUITEMService {
private int batchSize = 500;
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[实体数据操作标识] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_PSDEOPPRIVServiceImpl")
public class SYS_PSDEOPPRIVServiceImpl extends ServiceImpl<SYS_PSDEOPPRIVMapper, SYS_PSDEOPPRIV> implements ISYS_PSDEOPPRIVService {
private int batchSize = 500;
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[实体] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_PSSYSTEMServiceImpl")
public class SYS_PSSYSTEMServiceImpl extends ServiceImpl<SYS_PSSYSTEMMapper, SYS_PSSYSTEM> implements ISYS_PSSYSTEMService {
private int batchSize = 500;
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[系统角色] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_ROLEServiceImpl")
public class SYS_ROLEServiceImpl extends ServiceImpl<SYS_ROLEMapper, SYS_ROLE> implements ISYS_ROLEService {
@Autowired
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[角色权限关系] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_ROLE_PERMISSIONServiceImpl")
public class SYS_ROLE_PERMISSIONServiceImpl extends ServiceImpl<SYS_ROLE_PERMISSIONMapper, SYS_ROLE_PERMISSION> implements ISYS_ROLE_PERMISSIONService {
private int batchSize = 500;
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[系统用户] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_USERServiceImpl")
public class SYS_USERServiceImpl extends ServiceImpl<SYS_USERMapper, SYS_USER> implements ISYS_USERService {
@Autowired
......
......@@ -39,7 +39,7 @@ import com.alibaba.fastjson.JSONObject;
* 实体[用户角色关系] 服务对象接口实现
*/
@Slf4j
@Service
@Service("SYS_USER_ROLEServiceImpl")
public class SYS_USER_ROLEServiceImpl extends ServiceImpl<SYS_USER_ROLEMapper, SYS_USER_ROLE> implements ISYS_USER_ROLEService {
private int batchSize = 500;
......
[
{
"predefineddatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"entities":[
{
"dename":"SYS_ROLE_PERMISSION",
"delogicname":"角色权限关系",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -15,8 +16,7 @@
"delogicname":"权限/资源",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -24,8 +24,7 @@
"delogicname":"用户角色关系",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -33,8 +32,7 @@
"delogicname":"系统用户",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -42,8 +40,7 @@
"delogicname":"系统角色",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -51,8 +48,7 @@
"delogicname":"系统菜单项",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
,
{
......@@ -60,8 +56,9 @@
"delogicname":"实体数据操作标识",
"sysmoudle":{"id":"UAA","name":"uaa"},
"dedataset":[{"id":"Default","name":"默认数据集"}],
"dedatarange":[{"id":"ALL","name":"全部数据"},{"id":"CURORG","name":"当前单位"},{"id":"PORG","name":"上级单位"},{"id":"SORG","name":"下级单位"},{"id":"CURORGDEPT","name":"当前部门"},{"id":"PORGDEPT","name":"上级部门"},{"id":"SORGDEPT","name":"下级部门"}],
"deprivs":[{"id":"READ","name":"READ"},{"id":"CREATE","name":"CREATE"},{"id":"UPDATE","name":"UPDATE"},{"id":"DELETE","name":"DELETE"}]
"deaction":[{"id":"CREATE","name":"新建","type":"BUILTIN"},{"id":"UPDATE","name":"编辑","type":"BUILTIN"},{"id":"READ","name":"读取","type":"BUILTIN"},{"id":"DELETE","name":"删除","type":"BUILTIN"},{"id":"CUSTOM","name":"自定义行为","type":"USERCUSTOM"}]
}
]
}
......@@ -2,7 +2,7 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<!--输出实体[SYS_PSDEOPPRIV]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_psdeoppriv-42-1">
<changeSet author="a_A_5d9d78509" id="tab-sys_psdeoppriv-51-1">
<createTable tableName="IBZPSDEOPPRIV">
<column name="SYS_PSDEOPPRIVID" remarks="" type="VARCHAR(200)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_PSDEOPPRIV_SYS_PSDEOPPR"/>
......@@ -33,6 +33,8 @@
</column>
<column name="UPDATEDATE" remarks="" type="DATETIME">
</column>
<column name="PERMISSIONTYPE" remarks="" type="VARCHAR(100)">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_USER]数据结构 -->
......
......@@ -25,7 +25,7 @@
<!--数据查询[Default]-->
<sql id="Default" databaseId="mysql">
<![CDATA[ SELECT t1.`CREATEDATE`, t1.`PERMISSIONID`, t1.`PSDATAENTITYID`, t1.`PSDATAENTITYNAME`, t1.`PSDEDATARANGEID`, t1.`PSDEDATARANGENAME`, t1.`PSDEDATASETID`, t1.`PSDEDATASETNAME`, t1.`PSSYSMODULEID`, t1.`PSSYSMODULENAME`, t1.`PSSYSTEMID`, t1.`SYS_PSDEOPPRIVID`, t1.`SYS_PSDEOPPRIVNAME`, t1.`UPDATEDATE` FROM `IBZPSDEOPPRIV` t1
<![CDATA[ SELECT t1.`CREATEDATE`, t1.`PERMISSIONID`, t1.`PERMISSIONTYPE`, t1.`PSDATAENTITYID`, t1.`PSDATAENTITYNAME`, t1.`PSDEDATARANGEID`, t1.`PSDEDATARANGENAME`, t1.`PSDEDATASETID`, t1.`PSDEDATASETNAME`, t1.`PSSYSMODULEID`, t1.`PSSYSMODULENAME`, t1.`PSSYSTEMID`, t1.`SYS_PSDEOPPRIVID`, t1.`SYS_PSDEOPPRIVNAME`, t1.`UPDATEDATE` FROM `IBZPSDEOPPRIV` t1
]]>
</sql>
......
......@@ -137,6 +137,14 @@ public class SYS_PSDEOPPRIVDTO extends DTOBase implements Serializable {
@JsonProperty("updatedate")
private Timestamp updatedate;
/**
* 属性 [PERMISSIONTYPE]
*
*/
@JSONField(name = "permissiontype")
@JsonProperty("permissiontype")
private String permissiontype;
/**
* 设置 [SYS_PSDEOPPRIVNAME]
......@@ -226,6 +234,14 @@ public class SYS_PSDEOPPRIVDTO extends DTOBase implements Serializable {
this.modify("permissionid",permissionid);
}
/**
* 设置 [PERMISSIONTYPE]
*/
public void setPermissiontype(String permissiontype){
this.permissiontype = permissiontype ;
this.modify("permissiontype",permissiontype);
}
}
package cn.ibizlab.util.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@AllArgsConstructor
public class FileItem
{
private String id;
private String name;
private long size;
private String ext;
}
package cn.ibizlab.util.rest;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@Slf4j
public class FileController
{
@Autowired
private FileService fileService;
@PostMapping(value = "${ibiz.uploadpath.path:ibizutil/upload}")
public ResponseEntity<FileItem> upload(@RequestParam("file") MultipartFile multipartFile){
return ResponseEntity.ok().body(fileService.saveFile(multipartFile));
}
private final String defaultdownloadpath="ibizutil/download/{id}";
protected String getDefaultdownloadpath(){
return defaultdownloadpath;
}
@GetMapping(value = "${ibiz.file.downloadpath:"+defaultdownloadpath+"}")
@ResponseStatus(HttpStatus.OK)
public void download(@PathVariable String id, HttpServletResponse response){
File file= fileService.getFile(id);
response.setHeader("Content-Disposition", "attachment;filename="+getFileName(file.getName()));
this.sendRespose(response, file);
}
protected void sendRespose(HttpServletResponse response, File file){
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
}
catch (Exception e) {
//throw e;
}
finally {
if (bis != null) {
try {
bis.close();
}
catch (IOException e) {
}
}
if (bos != null) {
try {
bos.close();
}
catch (IOException e) {
}
}
}
}
protected String getFileName(String fileName){
try {
return new String(fileName.getBytes("utf-8"),"iso8859-1");//防止中文乱码
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return fileName;
}
}
\ No newline at end of file
......@@ -4,14 +4,19 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.enums.DEPredefinedFieldType;
import cn.ibizlab.util.filter.QueryWrapperContext;
import cn.ibizlab.util.helper.DEFieldCacheMap;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -31,147 +36,149 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
* 表格权限检查 :用于检查当前用户是否拥有表格数据的读取、删除权限
*
* @param authentication
* @param obj_action 表格行为,如:[READ,DELETE]
* @param grid_param 表格参数,如:当前表格所处实体(EntityName)、表格删除的数据主键(srfkeys)
* @param deAction 表格行为,如:[READ,DELETE]
* @param gridParam 表格参数,如:当前表格所处实体(EntityName)、表格删除的数据主键(srfkeys)
* @return true/false true则允许当前行为,false拒绝行为
*/
@Override
public boolean hasPermission(Authentication authentication, Object obj_action, Object grid_param) {
public boolean hasPermission(Authentication authentication, Object deAction, Object gridParam) {
//未开启权限校验、超级管理员则不进行权限检查
if(AuthenticationUser.getAuthenticationUser().getSuperuser()==1 || !enablePermissionValid)
return true; //系统没开启权限、超级管理员 两种情况不进行权限检查
return true;
String action = "";
if (deAction instanceof String)
action = (String) deAction;
if (StringUtils.isEmpty(action))
return false;
//获取当前用户权限列表
JSONObject userPermission= AuthenticationUser.getAuthenticationUser().getPermisionList();
if(userPermission==null)
return false;
try{
String action = "";
List gridParamList = (ArrayList) gridParam;
if(action.equals("DELETE")){ //grid delete
//准备参数
Object srfKey =gridParamList.get(0);
EntityBase entity = (EntityBase) gridParamList.get(1);
String entityName = entity.getClass().getSimpleName();
if (obj_action instanceof String)
action = (String) obj_action;
//获取实体行为权限信息
JSONObject permissionList=userPermission.getJSONObject("deActionPermission");
if (StringUtils.isEmpty(action))
//检查是否有操作权限[create.update.delete.read]
if(!validHasPermission(permissionList,entityName,action)){
return false;
}
//检查是否有数据权限[单行删除]
ServiceImpl service= SpringContextHolder.getBean(String.format("%s%s",entityName,"ServiceImpl"));//获取实体service对象
Map<String,String> permissionField=getPermissionField(entity);//获取组织、部门预置属性
String permissionSQL=getPermissionSQLById(permissionList,entityName,action,srfKey,permissionField);//获取权限SQL
if(StringUtils.isEmpty(permissionSQL))
return false;
QueryWrapper permissionWrapper=getPermissionWrapper(permissionSQL);//构造权限条件
return testDataAccess(service,permissionWrapper);//执行权限检查
}
else{ //grid fetch
//准备参数
Object searchContext=gridParamList.get(0);
String dataSet=String.valueOf(gridParamList.get(1));
EntityBase entity = (EntityBase) gridParamList.get(2);
String entityName = entity.getClass().getSimpleName();
JSONObject permissionList= AuthenticationUser.getAuthenticationUser().getPermisionList();//获取权限列表
//获取数据集权限信息
JSONObject permissionList=userPermission.getJSONObject("deDataSetPermission");
if(permissionList==null)
if(StringUtils.isEmpty(entityName)|| StringUtils.isEmpty(dataSet)|| StringUtils.isEmpty(action))
return false;
List param_list = (ArrayList) grid_param;
if(obj_action.equals("DELETE")){ //表格删除权限校验
Object srfkey =param_list.get(0);
EntityBase cur_entity = (EntityBase) param_list.get(1);
String entityName = cur_entity.getClass().getSimpleName();
ServiceImpl service= SpringContextHolder.getBean(String.format("%s%s",getBeanName(entityName),"ServiceImpl"));//获取当前实体service
JSONObject formDataAbility=permissionList.getJSONObject("dataAbility-form");//由于表格删除是不跟着dataSet走,所以此处走form获取权限
Map<String,String> permissionField=getPermissionField(cur_entity);//获取系统预置属性列表
String selectCond=generatePermissionSQLForm(formDataAbility,entityName,action,srfkey,permissionField);//拼接权限条件
if(StringUtils.isEmpty(selectCond))
return false;
QueryWrapper permissionCond=getPermissionCond(selectCond,permissionField);
return testDataAccess(service,permissionCond);//执行权限检查
}
else{ //表格查询权限校验
Object searchContext=param_list.get(0);
String dataSet=String.valueOf(param_list.get(1));
EntityBase cur_entity = (EntityBase) param_list.get(2);
String entityName = cur_entity.getClass().getSimpleName();
if(StringUtils.isEmpty(entityName)|| StringUtils.isEmpty(dataSet)|| StringUtils.isEmpty(action))
return false;
JSONObject gridDataAbility=permissionList.getJSONObject("dataAbility-grid");//获取表格的权限数据
Map<String,String> permissionField=getPermissionField(cur_entity);//获取系统预置属性列表
String selectCond=generatePermissionSQLGrid(gridDataAbility,entityName,action,dataSet,permissionField,null);//拼接权限条件
if(StringUtils.isEmpty(selectCond))
return false;
filterDataAccess(searchContext,selectCond);//过滤出权限内的数据
//检查是否有操作权限[create.update.delete.read]
if(!validHasPermission(permissionList,entityName,dataSet,action)){
return false;
}
return true;
}catch (Exception e){
throw new RuntimeException("系统在进行权限检查时出现异常,原因为:"+e);
Map<String,String> permissionField=getPermissionField(entity);//获取组织、部门预置属性
String permissionSQL=getPermissionSQLByList(permissionList,entityName,action,dataSet,permissionField);//获取权限SQL
if(StringUtils.isEmpty(permissionSQL))
return false;
fillPermissionSQL(searchContext,permissionSQL);//将权限SQL添加到searchContext中,过滤出权限内数据
}
return true;
}
/**
* 表单权限检查 :用于检查当前用户是否拥有表单的新建、编辑、删除权限
*
* @param authentication
* @param srfkey 当前操作数据的主键
* @param srfKey 当前操作数据的主键
* @param action 当前操作行为:如:[READ、UPDATE、DELETE]
* @param cur_entity 当前操作的实体对象
* @return true/false true则允许当前行为,false拒绝行为
*/
@Override
public boolean hasPermission(Authentication authentication, Serializable srfkey, String action, Object cur_entity) {
public boolean hasPermission(Authentication authentication, Serializable srfKey, String action, Object cur_entity) {
//未开启权限校验、超级管理员则不进行权限检查
if(AuthenticationUser.getAuthenticationUser().getSuperuser()==1 || !enablePermissionValid)
return true; //系统没开启权限、超级管理员 两种情况不进行权限检查
boolean isPermission;
return true;
EntityBase entity = null;
if (cur_entity instanceof EntityBase)
entity = (EntityBase) cur_entity;
if (StringUtils.isEmpty(entity))
return false;
try {
String entityName = entity.getClass().getSimpleName(); //实体名
if(action.equals("CREATE")){ //表单新建权限校验
JSONObject permissionList= AuthenticationUser.getAuthenticationUser().getPermisionList();//获取权限列表
JSONObject formDataAbility=permissionList.getJSONObject("dataAbility-form");//获取表单的权限数据
return isFormCreatePermission(formDataAbility,entityName,action);//拼接权限条件
JSONObject userPermission= AuthenticationUser.getAuthenticationUser().getPermisionList();
JSONObject permissionList=userPermission.getJSONObject("deActionPermission");
String entityName = entity.getClass().getSimpleName();
if(action.equals("CREATE")){
return validHasPermission(permissionList,entityName,action);
}
else{
//拥有全部数据访问权限时,则跳过权限检查
if(isAllData(permissionList,entityName,action)){
return true;
}
else{
//表单编辑、查询权限校验
ServiceImpl service= SpringContextHolder.getBean(String.format("%s%s",getBeanName(entityName),"ServiceImpl"));//获取当前实体service
JSONObject permissionList= AuthenticationUser.getAuthenticationUser().getPermisionList();//获取权限列表
JSONObject formDataAbility=permissionList.getJSONObject("dataAbility-form");//获取表单的权限数据
if(isAllData(formDataAbility,entityName,action)){//若为全部数据则直接返回,不再进行校验
return true;
}
Map<String,String> permissionField=getPermissionField(entity);//获取系统预置属性
String selectCond=generatePermissionSQLForm(formDataAbility,entityName,action,srfkey,permissionField);//根据uaa中分配的权限拼接where条件
if(StringUtils.isEmpty(selectCond))
return false;
QueryWrapper permissionCond=getPermissionCond(selectCond,permissionField);
isPermission=testDataAccess(service,permissionCond);//执行权限检查
//检查是否有操作权限[create.update.delete.read]
if(!validHasPermission(permissionList,entityName,action)){
return false;
}
}catch (Exception e){
throw new RuntimeException("系统在进行权限检查时出现异常,原因为:"+e);
//检查是否有数据权限
ServiceImpl service= SpringContextHolder.getBean(String.format("%s%s",entityName,"ServiceImpl"));
Map<String,String> permissionField=getPermissionField(entity);//获取组织、部门预置属性
String permissionSQL=getPermissionSQLById(permissionList,entityName,action,srfKey,permissionField);//获取权限SQL
if(StringUtils.isEmpty(permissionSQL))
return false;
QueryWrapper permissionWrapper=getPermissionWrapper(permissionSQL);//构造权限条件
return testDataAccess(service,permissionWrapper);//执行权限检查
}
return isPermission;
}
/**
* 判断是否包含全部数据
* @param formDataAbility
* 是否为全部数据
* @param permissionList
* @param entityName
* @param action
* @return
*/
private boolean isAllData(JSONObject formDataAbility, String entityName, String action) {
private boolean isAllData(JSONObject permissionList, String entityName, String action) {
if(formDataAbility==null)
if(permissionList==null)
return false;
if(!formDataAbility.containsKey(entityName))
if(!permissionList.containsKey(entityName))
return false;
JSONObject entityObj=formDataAbility.getJSONObject(entityName);//获取实体
if(!entityObj.containsKey(action))
return false;
JSONArray entityOperation=entityObj.getJSONArray(action);//行为:read;insert...
if(entityOperation.size()==0)
return false;
if(entityOperation.contains("ALL")){ //全部数据
JSONObject entity=permissionList.getJSONObject(entityName);
if(entity.containsKey(action) && entity.getJSONArray(action).contains("ALL"))
return true;
}
return false;
return false;
}
/**
......@@ -179,40 +186,27 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
* @param gridDataAbility
* @param entityName
* @param action
* @param dataSet
* @param dataSetName
* @param permissionField
* @param srfkey
* @return
*/
private String generatePermissionSQLGrid(JSONObject gridDataAbility, String entityName, String action, String dataSet, Map<String,String> permissionField,Object srfkey){
if(gridDataAbility==null)
return null;
if(!gridDataAbility.containsKey(entityName))
return null;
JSONObject entityObj=gridDataAbility.getJSONObject(entityName);//获取实体
if(!entityObj.containsKey(dataSet))
return null;
JSONObject dedatasetObject=entityObj.getJSONObject(dataSet);//获取实体数据集
if(!dedatasetObject.containsKey(action))
return null;
JSONArray entityOperation=dedatasetObject.getJSONArray(action);//行为:read;insert...
if(entityOperation.size()==0)
return null;
private String getPermissionSQLByList(JSONObject gridDataAbility, String entityName, String action, String dataSetName, Map<String,String> permissionField){
if(StringUtils.isEmpty(srfkey))
return getPermissionCond(entityOperation,permissionField); //拼接权限条件-查询
else
return String.format(" (%s) AND (%sid='%s')",getPermissionCond(entityOperation,permissionField),srfkey); //拼接权限条件-删除
JSONObject entity=gridDataAbility.getJSONObject(entityName);//获取实体
JSONObject dataSet=entity.getJSONObject(dataSetName);//获取实体数据集
JSONArray opprivList=dataSet.getJSONArray(action);//行为:read;insert...
if(opprivList.size()==0)
return null;
return getPermissionSQL(opprivList,permissionField); //拼接权限条件-查询
}
/**
* 表格拼接权限条件,过滤出权限数据
* 填充权限SQL
* @param targetDomainObject
* @param permissionCond
* @throws Exception
*/
private void filterDataAccess(Object targetDomainObject, String permissionCond) throws Exception{
private void fillPermissionSQL(Object targetDomainObject, String permissionCond){
if(targetDomainObject instanceof QueryWrapperContext){
QueryWrapperContext queryWrapperContext = (QueryWrapperContext) targetDomainObject;
QueryWrapper queryWrapper = queryWrapperContext.getSelectCond();
......@@ -220,53 +214,79 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
}
}
/**
* 校验是否有访问实体行为能力
* @param permissionList 权限列表
* @param entityName 实体名称
* @param action 操作行为
* @return
*/
private boolean validHasPermission(JSONObject permissionList, String entityName, String action){
boolean hasPermission=false;
if(permissionList==null)
return false;
if(!permissionList.containsKey(entityName))
return false;
JSONObject entity=permissionList.getJSONObject(entityName);
if(entity.containsKey(action)){
hasPermission=true;
}
return hasPermission;
}
/**
* 拼接表单数据查询条件
* @param formDataAbility
* 校验是否有访问数据集能力
* @param permissionList
* @param entityName
* @param dataSetName
* @param action
* @param srfkey
* @param permissionField
* @return
*/
private String generatePermissionSQLForm(JSONObject formDataAbility, String entityName, String action, Object srfkey, Map<String,String> permissionField){
if(formDataAbility==null)
return null;
if(!formDataAbility.containsKey(entityName))
return null;
JSONObject entityObj=formDataAbility.getJSONObject(entityName);//获取实体
if(!entityObj.containsKey(action))
return null;
JSONArray entityOperation=entityObj.getJSONArray(action);//行为:read;insert...
if(entityOperation.size()==0)
return null;
String resultCond=getPermissionCond(entityOperation,permissionField);
if(StringUtils.isEmpty(srfkey))
return String.format(" (%s)",resultCond,entityName.toLowerCase()); //拼接权限条件-新建
else
return String.format(" (%s) AND (%sid='%s')",resultCond,entityName.toLowerCase(),srfkey); //拼接权限条件-编辑
private boolean validHasPermission(JSONObject permissionList, String entityName, String dataSetName, String action ){
boolean hasPermission=false;
if(permissionList==null)
return false;
if(!permissionList.containsKey(entityName))
return false;
JSONObject entity=permissionList.getJSONObject(entityName);
if(!entity.containsKey(dataSetName))
return false;
JSONObject dataSet=entity.getJSONObject(dataSetName);//获取实体数据集
if(dataSet.containsKey(action)){
hasPermission=true;
}
return hasPermission;
}
/**
* 判断当前用户是否拥有建立表单数据权限
* 获取单条权限数据SQL
* @param formDataAbility
* @param entityName
* @param targetType
* @param action
* @param srfKey
* @param permissionField
* @return
*/
private boolean isFormCreatePermission(JSONObject formDataAbility, String entityName, String targetType){
if(formDataAbility==null)
return false;
if(!formDataAbility.containsKey(entityName))
return false;
JSONObject entityObj=formDataAbility.getJSONObject(entityName);//获取实体
if(!entityObj.containsKey(targetType))
return false;
return true;
private String getPermissionSQLById(JSONObject formDataAbility, String entityName, String action, Object srfKey, Map<String,String> permissionField){
JSONObject entity=formDataAbility.getJSONObject(entityName);//获取实体
JSONArray opprivList=entity.getJSONArray(action);//行为:read;insert...
if(opprivList.size()==0)
return null;
String permissionSQL=getPermissionSQL(opprivList,permissionField);
String keyField=permissionField.get("keyfield");
if(StringUtils.isEmpty(keyField)){
throw new RuntimeException("权限校验失败,请检查当前实体中是否已经配置主键属性!");
}
return String.format(" (%s) AND (%s='%s')",permissionSQL,keyField,srfKey); //拼接权限条件-编辑
}
/**
* 表单权限检查
* @param service
......@@ -274,25 +294,28 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
* @return
*/
private boolean testDataAccess(ServiceImpl service, QueryWrapper permissionCond){
boolean isPermission=false;
List list=service.list(permissionCond);
if(list.size()>0)
isPermission=true;
boolean isPermission=false;
List list=service.list(permissionCond);
if(list.size()>0)
isPermission=true;
return isPermission;
}
/**
* 拼接权限条件(表单/表格)共用
* @param entityOperation
* 获取权限SQL
* @param oppriList
* @param permissionField
* @return
*/
private String getPermissionCond(JSONArray entityOperation, Map<String,String> permissionField){
private String getPermissionSQL(JSONArray oppriList, Map<String,String> permissionField){
String nPermissionSQL = "1<>1";
String orgField=permissionField.get("orgfield");
String orgDeptField=permissionField.get("orgsecfield");
String createManField=permissionField.get("createmanfield");
StringBuffer permissionSQL=new StringBuffer();
AuthenticationUser authenticationUser = AuthenticationUser.getAuthenticationUser();
JSONObject userInfo = authenticationUser.getOrgInfo();
JSONObject orgObject = userInfo.getJSONObject("org");
......@@ -302,61 +325,55 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
JSONArray orgDeptParent = orgDeptObject.getJSONArray("porgdept");
JSONArray orgDeptChild = orgDeptObject.getJSONArray("sorgdept");
for(int i=0;i<entityOperation.size();i++){
if(i>0 && (!StringUtils.isEmpty(permissionSQL.toString())))
permissionSQL.append("OR");
String permissionCond=entityOperation.getString(i);//权限配置条件
for(int i=0;i<oppriList.size();i++){
permissionSQL.append("OR");
String permissionCond=oppriList.getString(i);//权限配置条件
if(permissionCond.equals("CURORG")){ //本单位
permissionSQL.append(String.format("(%s='%s')",orgField,AuthenticationUser.getAuthenticationUser().getOrgid()));
}
if(permissionCond.equals("SORG")){//下级单位
permissionSQL.append(String.format(" %s in(%s) ", orgField, formatStringArr(orgChild)));
}
if(permissionCond.equals("PORG")){//上级单位
else if(permissionCond.equals("PORG")){//上级单位
permissionSQL.append(String.format(" %s in(%s) ", orgField, formatStringArr(orgParent)));
}
if(permissionCond.equals("CREATEMAN")){//建立人
permissionSQL.append(String.format("(createman='%s')",AuthenticationUser.getAuthenticationUser().getUserid()));
else if(permissionCond.equals("SORG")){//下级单位
permissionSQL.append(String.format(" %s in(%s) ", orgField, formatStringArr(orgChild)));
}
if(permissionCond.equals("CURORGDEPT")){//本部门
permissionSQL.append(String.format("(orgsecid='%s')",AuthenticationUser.getAuthenticationUser().getMdeptid()));
else if(permissionCond.equals("CREATEMAN")){//建立人
permissionSQL.append(String.format("(%s='%s')",createManField,AuthenticationUser.getAuthenticationUser().getUserid()));
}
if(permissionCond.equals("SORGDEPT")){//下级部门
permissionSQL.append(String.format(" %s in (%s) ", orgDeptField, formatStringArr(orgDeptChild)));
else if(permissionCond.equals("CURORGDEPT")){//本部门
permissionSQL.append(String.format("(%s='%s')",orgDeptField,AuthenticationUser.getAuthenticationUser().getMdeptid()));
}
if(permissionCond.equals("PORGDEPT")){//上级部门
else if(permissionCond.equals("PORGDEPT")){//上级部门
permissionSQL.append(String.format(" %s in (%s) ", orgDeptField, formatStringArr(orgDeptParent)));
}
if(permissionCond.equals("ALL")){//全部数据
else if(permissionCond.equals("SORGDEPT")){//下级部门
permissionSQL.append(String.format(" %s in (%s) ", orgDeptField, formatStringArr(orgDeptChild)));
}
else if(permissionCond.equals("ALL")){//全部数据
permissionSQL.append("(1=1)");
}
}
else{
permissionSQL.append(nPermissionSQL);
}
}
if(StringUtils.isEmpty(permissionSQL.toString()))
return "";
String resultCond=permissionSQL.toString();
if(resultCond.endsWith("OR")){
resultCond=resultCond.substring(0,resultCond.lastIndexOf("OR"));
}
String resultCond=parseResult(permissionSQL, "OR");
return resultCond;
}
/**
* 拼接权限查询条件(表单/表格)共用
* 构造 wrapper
* @param whereCond
* @param permissionField
* @return
*/
private QueryWrapper getPermissionCond(String whereCond, Map<String,String> permissionField){
QueryWrapper allPermissionCond=new QueryWrapper();
if(StringUtils.isEmpty(whereCond))
return allPermissionCond;
allPermissionCond.apply(whereCond);
private QueryWrapper getPermissionWrapper(String whereCond){
return allPermissionCond;
QueryWrapper permissionWrapper=new QueryWrapper();
if(!StringUtils.isEmpty(whereCond)){
permissionWrapper.apply(whereCond);
}
return permissionWrapper;
}
/**
......@@ -365,47 +382,78 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
* @return
*/
private Map<String,String> getPermissionField(EntityBase entityBase){
Map<String,String> permissionFiled=new HashMap<>();
String orgField="orgid"; //组织权限默认值
String orgsecField="orgsecid"; //部门权限默认值
// Map<Field, PreField> preFields= entityBase.SearchPreField(); //从缓存中获取当前类预置属性
// //寻找实体权限属性
// for (Map.Entry<Field,PreField> entry : preFields.entrySet()){
// Field prefield=entry.getKey();//获取注解字段
// PreField fieldAnnotation=entry.getValue();//获取注解值
// PredefinedType prefieldType=fieldAnnotation.preType();
// if(prefieldType==PredefinedType.ORGID)//用户配置系统预置属性-组织机构标识
// orgField=prefield.getName();
// if(prefieldType==PredefinedType.ORGSECTORID)//用户配置系统预置属性-部门标识
// orgsecField=prefield.getName();
// }
String orgField="orgid"; //组织属性
String orgDeptField="orgsecid"; //部门属性
String createManField="createman"; //创建人属性
String keyField="";//主键属性
DEFieldCacheMap.getFieldMap(entityBase.getClass().getName());
Map <Field, DEField> preFields= SearchDEField(entityBase.getClass().getName()); //从缓存中获取当前类预置属性
for (Map.Entry<Field,DEField> entry : preFields.entrySet()){
Field preField=entry.getKey();//获取注解字段
DEField fieldAnnotation=entry.getValue();//获取注解值
DEPredefinedFieldType prefieldType=fieldAnnotation.preType();
if(prefieldType==prefieldType.ORGID)//用户配置系统预置属性-组织机构标识
orgField=preField.getName();
if(prefieldType==prefieldType.ORGSECTORID)//用户配置系统预置属性-部门标识
orgDeptField=preField.getName();
if(fieldAnnotation.isKeyField())//用户配置系统预置属性-部门标识
keyField=preField.getName();
}
permissionFiled.put("orgfield",orgField);
permissionFiled.put("orgsecfield",orgsecField);
permissionFiled.put("orgsecfield",orgDeptField);
permissionFiled.put("createmanfield",createManField);
permissionFiled.put("keyfield",keyField);
return permissionFiled;
}
/**
* 获取bean名称
* @param className
*获取含有@DEField注解的实体属性
* @param className do对象类名
* @return
*/
private String getBeanName(String className) {
if (Character.isLowerCase(className.charAt(0))) {
return className;
} else {
return (new StringBuilder()).append(Character.toLowerCase(className.charAt(0))).append(className.substring(1)).toString();
private Map <Field, DEField> SearchDEField(String className){
List<Field> fields = DEFieldCacheMap.getFields(className);
Map <Field, DEField> deFieldMap =new HashMap<>();
for(Field field:fields){
DEField deField=field.getAnnotation(DEField.class);
if(!ObjectUtils.isEmpty(deField)) {
deFieldMap.put(field,deField);
}
}
return deFieldMap;
}
/**
* 转换[a,b]格式字符串到 'a','b'格式
*
* @return
*/
private String formatStringArr(JSONArray array) {
String[] arr = array.toArray(new String[array.size()]);
return "'" + String.join("','", arr) + "'";
}
/**
* 格式转换
*
* @param cond
* @param operator
* @return
*/
private String parseResult(StringBuffer cond, String operator) {
String resultCond = cond.toString();
if (resultCond.startsWith(operator))
resultCond = resultCond.replaceFirst(operator, "");
if (resultCond.endsWith(operator))
resultCond = resultCond.substring(0, resultCond.lastIndexOf(operator));
return resultCond;
}
}
\ No newline at end of file
package cn.ibizlab.util.service;
import cn.ibizlab.util.domain.FileItem;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
public interface FileService
{
FileItem saveFile(MultipartFile multipartFile);
File getFile(String fileid);
}
\ No newline at end of file
package cn.ibizlab.util.service;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.errors.InternalServerErrorException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.UUID;
@Primary
@Slf4j
@Service
public class SimpleFileService implements FileService {
@Value("${ibiz.filePath:/app/file/}")
private String fileRoot;
@Override
public FileItem saveFile(MultipartFile multipartFile) {
FileItem item=null;
// 获取文件名
String fileName = multipartFile.getOriginalFilename();
// 获取文件后缀
String extname="."+getExtensionName(fileName);
// 用uuid作为文件名,防止生成的临时文件重复
String fileid= UUID.randomUUID().toString();
String fileFullPath = this.fileRoot+"ibztuit"+File.separator+fileid+File.separator+fileName;
File file = new File(fileFullPath);
File parent = new File(file.getParent());
if(!parent.exists())
parent.mkdirs();
try {
FileCopyUtils.copy(multipartFile.getInputStream() , Files.newOutputStream(file.toPath()));
item=new FileItem(fileid,fileName, (int)multipartFile.getSize() ,extname);
} catch (IOException e) {
throw new InternalServerErrorException("文件上传失败");
}
return item;
}
@Override
public File getFile(String fileid) {
String dirpath = this.fileRoot+"ibztuit"+File.separator+fileid;
File parent = new File(dirpath);
if (parent.exists() && parent.isDirectory() && parent.listFiles().length > 0) {
return parent.listFiles()[0];
}
throw new InternalServerErrorException("文件未找到");
}
/**
* 获取文件扩展名
* @param filename
* @return
*/
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
}
\ No newline at end of file
......@@ -104,7 +104,10 @@ public class SimpleUserService implements AuthenticationUserService{
JSONObject orgInfo=ouFeignClient.getOrgInfo(user.getLoginname());
if(orgInfo==null)
throw new RuntimeException("获取用户信息失败,请检查用户中心[IBZOU]中是否存在当前用户!");
JSONObject curUser=orgInfo.getJSONObject("curuser");
user.setOrgInfo(orgInfo);
user.setMdeptid(curUser.getString("orgdept"));
user.setOrgid(curUser.getString("org"));
}
}
......
......@@ -60,3 +60,7 @@ logging:
ribbon:
ReadTimeout: 60000
ConnectTimeout: 60000
#系统是否开启权限验证
ibiz:
enablePermissionValid: false
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册