1、Excel优化

Former-commit-id: 37c0bb9c46f915b2709546723add4b2e29ae001e
master
wangbing 5 years ago
parent 7aa13d85d4
commit 17fcfa5350

@ -76,15 +76,15 @@ public class ${table.getCName()}Ajax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(response.getResult()));
return ResponseUtil.apply(new WExcel<>(${table.getCName()}.class).loadData(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<${table.getCName()}> sheet = new WExcel<>(file.getBytes(), ${table.getCName()}.class, new WExcel.Validator<${table.getCName()}>() {
WExcel sheet = new WExcel<>(${table.getCName()}.class).loadData(file.getBytes(), new WExcel.Processor<${table.getCName()}>() {
@Override
public List<String> validate(${table.getCName()} o) {
public List<String> exec(${table.getCName()} o) {
${table.getCName()}CreateRequest request = MapperUtil.map(o, ${table.getCName()}CreateRequest.class);
return ValidationUtil.validate(request);
}

@ -79,9 +79,9 @@ public class DeptAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<Dept> sheet = new WExcel<>(file.getBytes(), Dept.class, new WExcel.Validator<Dept>() {
WExcel sheet = new WExcel<>(Dept.class).loadData(file.getBytes(), new WExcel.Processor<Dept>() {
@Override
public List<String> validate(Dept o) {
public List<String> exec(Dept o) {
DeptCreateRequest request = MapperUtil.map(o, DeptCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -79,16 +79,16 @@ public class DictAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<Dict> sheet = new WExcel<>(file.getBytes(), Dict.class, new WExcel.Validator<Dict>() {
WExcel sheet = new WExcel<>(Dict.class).loadData(file.getBytes(), new WExcel.Processor<Dict>() {
@Override
public List<String> validate(Dict o) {
public List<String> exec(Dict o) {
DictCreateRequest request = MapperUtil.map(o, DictCreateRequest.class);
return ValidationUtil.validate(request);
}
});
if (sheet.hasError()) {
return ResponseUtil.apply(sheet.getBytes(true), sheet.getName() + "-检查.xlsx");
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
} else {
return baseResponse;
}

@ -73,16 +73,16 @@ public class DictItemAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<DictItem> sheet = new WExcel<>(file.getBytes(), DictItem.class, new WExcel.Validator<DictItem>() {
WExcel sheet = new WExcel<>(DictItem.class).loadData(file.getBytes(), new WExcel.Processor<DictItem>() {
@Override
public List<String> validate(DictItem o) {
public List<String> exec(DictItem o) {
DictItemCreateRequest request = MapperUtil.map(o, DictItemCreateRequest.class);
return ValidationUtil.validate(request);
}
});
if (sheet.hasError()) {
return ResponseUtil.apply(sheet.getBytes(true), sheet.getName() + "-检查.xlsx");
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
} else {
return baseResponse;
}

@ -73,9 +73,9 @@ public class FileAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<File> sheet = new WExcel<>(file.getBytes(), File.class, new WExcel.Validator<File>() {
WExcel sheet = new WExcel<>(File.class).loadData(file.getBytes(), new WExcel.Processor<File>() {
@Override
public List<String> validate(File o) {
public List<String> exec(File o) {
FileCreateRequest request = MapperUtil.map(o, FileCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -79,9 +79,9 @@ public class ResAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<Res> sheet = new WExcel<>(file.getBytes(), Res.class, new WExcel.Validator<Res>() {
WExcel sheet = new WExcel<>(Res.class).loadData(file.getBytes(), new WExcel.Processor<Res>() {
@Override
public List<String> validate(Res o) {
public List<String> exec(Res o) {
ResCreateRequest request = MapperUtil.map(o, ResCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -73,9 +73,9 @@ public class RoleAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<Role> sheet = new WExcel<>(file.getBytes(), Role.class, new WExcel.Validator<Role>() {
WExcel sheet = new WExcel<>(Role.class).loadData(file.getBytes(), new WExcel.Processor<Role>() {
@Override
public List<String> validate(Role o) {
public List<String> exec(Role o) {
RoleCreateRequest request = MapperUtil.map(o, RoleCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -79,9 +79,9 @@ public class TokensAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<Tokens> sheet = new WExcel<>(file.getBytes(), Tokens.class, new WExcel.Validator<Tokens>() {
WExcel sheet = new WExcel<>(Tokens.class).loadData(file.getBytes(), new WExcel.Processor<Tokens>() {
@Override
public List<String> validate(Tokens o) {
public List<String> exec(Tokens o) {
TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -170,7 +170,6 @@ public class UserAjax {
return response;
}
Cookie cookie = CookieUtil.newCookie("token", tokensCreateRequest.getToken());
cookie.setPath("/");
httpServletResponse.addCookie(cookie);
response.setToken(tokensCreateRequest.getToken());
}
@ -181,6 +180,7 @@ public class UserAjax {
public UserLogoutResponse logout(UserLogoutRequest request) {
UserLogoutResponse response = new UserLogoutResponse();
if (LocalData.getToken() != null) {
TokensLogoutRequest tokensLogoutRequest = new TokensLogoutRequest();
tokensLogoutRequest.setToken(LocalData.getToken().getToken());
TokensLogoutResponse tokensLogoutResponse = tokensManager.logout(tokensLogoutRequest, LocalData.getSysToken());
@ -188,10 +188,8 @@ public class UserAjax {
response.addErrors(tokensLogoutResponse.getErrors());
return response;
}
HttpServletResponse HttpServletResponse = LocalData.getResponse();
Cookie token = CookieUtil.newCookie("token", "");
HttpServletResponse.addCookie(token);
}
CookieUtil.clearCookie("token");
return response;
}
@ -214,9 +212,9 @@ public class UserAjax {
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel<User> sheet = new WExcel<>(file.getBytes(), User.class, new WExcel.Validator<User>() {
WExcel sheet = new WExcel<>(User.class).loadData(file.getBytes(), new WExcel.Processor<User>() {
@Override
public List<String> validate(User o) {
public List<String> exec(User o) {
UserCreateRequest request = MapperUtil.map(o, UserCreateRequest.class);
return ValidationUtil.validate(request);
}

@ -15,8 +15,13 @@ import org.springframework.security.web.access.intercept.FilterSecurityIntercept
import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.Token;
import ${basePackage}.frame.utils.CookieUtil;
import ${basePackage}.frame.utils.IDgenerator;
import ${basePackage}.module.system.mgr.ResManager;
import ${basePackage}.module.system.mgr.TokensManager;
import ${basePackage}.module.system.req.ResCreateRequest;
import ${basePackage}.module.system.req.ResFindRequest;
import ${basePackage}.module.system.req.TokensBuildRequest;
import ${basePackage}.module.system.rsp.ResFindResponse;
import ${basePackage}.module.system.rsp.TokensBuildResponse;
import javax.servlet.Filter;
@ -119,9 +124,36 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return new Object() {
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
// 授权
Token token_ = LocalData.getToken();
if (token_ != null && token_.hasRes(request.getServletPath())) {
if (token_ == null) {
return false;
}
String path = request.getServletPath();
String[] profiles = LocalData.getEnvironment().getActiveProfiles();
for (String profile : profiles) {
if (profile.contains("dev")) {//测试环境捕获资源
ResFindRequest resFindRequest = new ResFindRequest();
resFindRequest.setPageSize(0);
resFindRequest.setResValue(request.getServletPath());
ResManager resManager = LocalData.getBean(ResManager.class);
ResFindResponse resFindResponse = resManager.find(resFindRequest, LocalData.getSysToken());
if (resFindResponse.getResult().size() == 0) {//资源不存在,主动收集资源
ResCreateRequest resCreateRequest = new ResCreateRequest();
resCreateRequest.setResCode(IDgenerator.nextUUID());
resCreateRequest.setResName("默认");
resCreateRequest.setResValue(path);
resCreateRequest.setValid(true);
resCreateRequest.setResType("");
resManager.create(resCreateRequest, LocalData.getSysToken());
}
}
}
// 授权
if (token_.hasRes(path)) {
return true;
}

@ -81,8 +81,7 @@ public class LocalData {
return getApplicationContext().getBean(t);
}
public static String getProp(String key) {
Environment env = getBean(Environment.class);
return env.getProperty(key, "");
public static Environment getEnvironment() {
return getBean(Environment.class);
}
}

@ -198,6 +198,10 @@ public class WExcel<T> implements Serializable, Cloneable {
return columnList;
}
public WExcel loadData(List<T> list) {
return loadData(list, null);
}
/**
* <br/>
*

@ -3,6 +3,7 @@ package ${basePackage}.frame.utils;
import ${basePackage}.frame.auth.LocalData;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* CookieUtil
@ -37,15 +38,30 @@ public class CookieUtil {
/**
* Cookie
*
* @param key
* @param name
* @param value
* @return passportID
*/
public static Cookie newCookie(String key, String value) {
public static Cookie newCookie(String name, String value) {
HttpServletRequest request = LocalData.getRequest();
Cookie cookie = new Cookie(key, value);
Cookie cookie = new Cookie(name, value);
cookie.setDomain(request.getServerName());
cookie.setPath(request.getContextPath());
cookie.setMaxAge(-1);
cookie.setPath("/");
return cookie;
}
/**
* Cookie
*
* @param name
*/
public static void clearCookie(String name) {
HttpServletRequest request = LocalData.getRequest();
HttpServletResponse response = LocalData.getResponse();
Cookie cookie = new Cookie(name, null);
cookie.setDomain(request.getServerName());
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
}

@ -66,6 +66,8 @@ public class User extends BaseEntity {
private String roleNames;
private String roleCodes;
public String getUserName() {
return this.userName;
}
@ -137,4 +139,12 @@ public class User extends BaseEntity {
public void setRoleNames(String roleNames) {
this.roleNames = roleNames;
}
public String getRoleCodes() {
return roleCodes;
}
public void setRoleCodes(String roleCodes) {
this.roleCodes = roleCodes;
}
}

@ -54,6 +54,19 @@ public class RoleManagerImpl implements RoleManager {
return response;
}
{//检查Code是否重复
RoleFindRequest roleFindRequest = new RoleFindRequest();
roleFindRequest.setCode(request.getCode());
RoleFindResponse roleFindResponse = find(roleFindRequest, token);
if (roleFindResponse.hasError()) {
response.addErrors(roleFindResponse.getErrors());
return response;
} else if (roleFindResponse.getResult().size() > 0) {
response.addError(ErrorType.BUSINESS_ERROR, "[" + request.getCode() + "]已存在");
return response;
}
}
long id = IDgenerator.nextId();
Role entity = MapperUtil.map(request, Role.class);
entity.setId(id);

@ -252,7 +252,7 @@ public class TokensManagerImpl implements xyz.wbsite.module.system.mgr.TokensMan
// 获取用户的资源
ResFindRequest resFindRequest = new ResFindRequest();
resFindRequest.setPageSize(0);
resFindRequest.setUserId(token.getUserId());
resFindRequest.setUserId(tokens.getUserId());
ResFindResponse resFindResponse = resManager.find(resFindRequest, token);
if (resFindResponse.hasError()) {
response.addErrors(resFindResponse.getErrors());

@ -15,9 +15,11 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.Message;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.module.system.ent.Dept;
import ${basePackage}.module.system.ent.Role;
import ${basePackage}.module.system.ent.User;
import ${basePackage}.module.system.mpr.UserMapper;
import ${basePackage}.module.system.req.DeptFindRequest;
import ${basePackage}.module.system.req.RoleFindRequest;
import ${basePackage}.module.system.req.UserCreateRequest;
import ${basePackage}.module.system.req.UserDeleteRequest;
import ${basePackage}.module.system.req.UserFindRequest;
@ -25,6 +27,7 @@ import ${basePackage}.module.system.req.UserGetRequest;
import ${basePackage}.module.system.req.UserRoleCreateRequest;
import ${basePackage}.module.system.req.UserUpdateRequest;
import ${basePackage}.module.system.rsp.DeptFindResponse;
import ${basePackage}.module.system.rsp.RoleFindResponse;
import ${basePackage}.module.system.rsp.UserCreateResponse;
import ${basePackage}.module.system.rsp.UserDeleteResponse;
import ${basePackage}.module.system.rsp.UserFindResponse;
@ -48,6 +51,8 @@ public class UserManagerImpl implements UserManager {
@Autowired
private DeptManager deptManager;
@Autowired
private RoleManager roleManager;
@Autowired
private UserRoleManager userRoleManager;
/**
@ -94,12 +99,26 @@ public class UserManagerImpl implements UserManager {
return response;
}
for (Long aLong : request.getRoleIdList()) {
for (String code : request.getRoleCodeList()) {
RoleFindRequest roleFindRequest = new RoleFindRequest();
roleFindRequest.setCode(code);
RoleFindResponse roleFindResponse = roleManager.find(roleFindRequest, token);
if (roleFindResponse.hasError()) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
response.addErrors(roleFindResponse.getErrors());
return response;
} else if (roleFindResponse.getResult().size() == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
response.addError(ErrorType.BUSINESS_ERROR, "[" + code + "]角色代码不存在!");
return response;
}
Role role = roleFindResponse.getResult().get(0);
UserRoleCreateRequest userRoleCreateRequest = new UserRoleCreateRequest();
userRoleCreateRequest.setUserId(id);
userRoleCreateRequest.setUserCode(null);
userRoleCreateRequest.setRoleId(aLong);
userRoleCreateRequest.setRoleCode(null);
userRoleCreateRequest.setUserCode(request.getUserCode());
userRoleCreateRequest.setRoleId(role.getId());
userRoleCreateRequest.setRoleCode(role.getCode());
UserRoleCreateResponse userRoleCreateResponse = userRoleManager.create(userRoleCreateRequest, token);
if (userRoleCreateResponse.hasError()) {
response.addErrors(userRoleCreateResponse.getErrors());

@ -4,6 +4,9 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${basePackage}.module.system.mpr.ResMapper">
<!--开启缓存-->
<cache/>
<sql id="table">`SYS_RES`</sql>
<sql id="entityColumnList">

@ -20,6 +20,7 @@
<result column="DEPT_ID" jdbcType="BIGINT" property="deptId"/>
<result column="DEPT_CODE" jdbcType="VARCHAR" property="deptCode"/>
<result column="DEPT_NAME" jdbcType="VARCHAR" property="deptName"/>
<result column="ROLE_CODES" jdbcType="VARCHAR" property="roleCodes"/>
<result column="ROLE_NAMES" jdbcType="VARCHAR" property="roleNames"/>
<result column="ROW_VERSION" jdbcType="BIGINT" property="rowVersion"/>
<result column="IS_DELETED" jdbcType="BIT" property="isDeleted"/>
@ -31,12 +32,12 @@
<select id="find" resultMap="user">
SELECT
t1.*,t2.ROLE_NAMES
t1.*,t2.ROLE_NAMES, t2.ROLE_CODES
FROM
`sys_user` t1,
(
SELECT
t2.user_id, GROUP_CONCAT(t3.NAME) ROLE_NAMES
t2.user_id, GROUP_CONCAT(t3.NAME) ROLE_NAMES, GROUP_CONCAT(t3.CODE) ROLE_CODES
FROM
`sys_user_role` t2,
`sys_role` t3

@ -59,7 +59,7 @@ public class UserCreateRequest extends BaseRequest {
private String deptCode;
@NotEmpty(message = "[roleIdList]角色主键不能为空")
private List<Long> roleIdList;
private List<String> roleCodeList;
public String getUserName() {
return this.userName;
@ -109,11 +109,11 @@ public class UserCreateRequest extends BaseRequest {
this.deptCode = deptCode;
}
public List<Long> getRoleIdList() {
return roleIdList;
public List<String> getRoleCodeList() {
return roleCodeList;
}
public void setRoleIdList(List<Long> roleIdList) {
this.roleIdList = roleIdList;
public void setRoleCodeList(List<String> roleCodeList) {
this.roleCodeList = roleCodeList;
}
}

@ -128,7 +128,7 @@ web.login.page=/login.htm
# 拦截验证
web.url.auth.included=/,/**/*.htm,/ajax/**,/api/**
# 直接放行
web.url.auth.excluded=/login.htm,/ajax/system/User/login
web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout
# 超级管理员
web.url.auth.admin=admin
web.url.auth.pwd=17fac3376f76d65943d1d26d1f7cb1e5

@ -128,7 +128,7 @@ web.login.page=/login.htm
# 拦截验证
web.url.auth.included=/,/**/*.htm,/ajax/**,/api/**
# 直接放行
web.url.auth.excluded=/login.htm,/ajax/system/User/login
web.url.auth.excluded=/login.htm,/ajax/system/User/login,/ajax/system/User/logout
# 超级管理员
web.url.auth.admin=admin
web.url.auth.pwd=17fac3376f76d65943d1d26d1f7cb1e5

@ -702,6 +702,7 @@
},
template: '' +
'<el-cascader ' +
' :value="value" ' +
' @input="input" ' +
' :show-all-levels="false" ' +
' :options="options" ' +

@ -315,7 +315,7 @@
case "logout":
new Ajax()
.module("system")
.target("user")
.target("User")
.method("logout")
.post(function (response) {
if (response.errors.length > 0) {

@ -166,8 +166,8 @@
<br>
<el-form-item label="用户角色" prop="roleIdList">
<el-transfer v-model="form.roleIdList" :data="roleList" :titles="['未选角色','已选角色']" style="width: 500px"></el-transfer>
<el-form-item label="用户角色" prop="roleCodeList">
<el-transfer v-model="form.roleCodeList" :data="roleList" :titles="['未选角色','已选角色']" style="width: 500px"></el-transfer>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
@ -205,7 +205,7 @@
userPwd: "",
userStatus: "1",
deptCode: "",
roleIdList: [],
roleCodeList: [],
rowVersion: ""
},
formRules: {
@ -229,7 +229,7 @@
deptCode: [
{min: 1, max: 50, message: '部门代码长度在 1 到 50 个字符', trigger: 'blur'}
],
roleIdList: [
roleCodeList: [
{required: true, message: '用户角色不能为空', trigger: 'blur'},
]
},
@ -265,6 +265,7 @@
this.form.deptId = item.deptId;
this.form.deptCode = item.deptCode;
this.form.deptName = item.deptName;
this.form.roleCodeList = item.roleCodes.split(",")
this.form.rowVersion = item.rowVersion;
break;
case "delete":
@ -287,7 +288,7 @@
} else {
this.roleList = response.result;
for (var i = 0; i < this.roleList.length; i++) {
this.roleList[i].key = this.roleList[i].id;
this.roleList[i].key = this.roleList[i].code;
this.roleList[i].label = this.roleList[i].name;
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.