修复请假流程bug,优化代码
This commit is contained in:
parent
ed2331433d
commit
16fd455b75
|
@ -1,12 +1,8 @@
|
|||
package com.len.base;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
|
@ -14,49 +10,53 @@ import org.springframework.web.bind.WebDataBinder;
|
|||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2017/12/19.
|
||||
* @email 154040976@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseController<T> {
|
||||
|
||||
@InitBinder
|
||||
protected void initBinder(WebDataBinder binder) {
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(
|
||||
new SimpleDateFormat("yyyy-MM-dd"), true));
|
||||
}
|
||||
@InitBinder
|
||||
protected void initBinder(WebDataBinder binder) {
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(
|
||||
new SimpleDateFormat("yyyy-MM-dd"), true));
|
||||
}
|
||||
|
||||
@ExceptionHandler({ UnauthorizedException.class, AuthorizationException.class })
|
||||
public String authorizationException(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (isAjaxRequest(request)) {
|
||||
Map<String,Object> map = Maps.newHashMap();
|
||||
map.put("code", "-998");
|
||||
map.put("message", "无权限");
|
||||
//response.gets
|
||||
return null;
|
||||
} else {
|
||||
String message="权限不足";
|
||||
try {
|
||||
message = URLEncoder.encode(message,"utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "redirect:/error/403?message="+message;
|
||||
@ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
|
||||
public String authorizationException(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (isAjaxRequest(request)) {
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("code", "403");
|
||||
map.put("message", "无权限");
|
||||
return JSON.toJSONString(map);
|
||||
} else {
|
||||
String message = "权限不足";
|
||||
try {
|
||||
message = URLEncoder.encode(message, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("BaseController:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "redirect:/error/403?message=" + message;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
String requestedWith = request.getHeader("x-requested-with");
|
||||
if (requestedWith != null && requestedWith.equalsIgnoreCase("XMLHttpRequest")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
private static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
String requestedWith = request.getHeader("x-requested-with");
|
||||
return requestedWith != null && requestedWith.equalsIgnoreCase("XMLHttpRequest");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.len.base.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.len.base.BaseMapper;
|
||||
|
@ -200,12 +199,10 @@ public abstract class BaseServiceImpl<T, E extends Serializable> implements Base
|
|||
try {
|
||||
tList = getMappser().selectListByPage(t);
|
||||
} catch (MyException e) {
|
||||
// logger.error("class:BaseServiceImpl ->method:show->message:" + e.getMessage());
|
||||
log.error("class:BaseServiceImpl ->method:show->message:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
ReType reType = new ReType(tPage.getTotal(), tList);
|
||||
return reType;
|
||||
return new ReType(tPage.getTotal(), tList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue