修改工具类
This commit is contained in:
parent
655fb1addc
commit
e9d37cfc7a
|
|
@ -82,8 +82,8 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
|||
}
|
||||
|
||||
// 校验用户被删除
|
||||
Map<String, Object> map = ToolsUtil.jsonToMap(RedisUtil.hGet(AdminConfig.backstageManageKey, uid).toString());
|
||||
if (map == null || map.get("isDelete").toString().equals("1")) {
|
||||
Map<String, String> map = ToolsUtil.jsonToMap(RedisUtil.hGet(AdminConfig.backstageManageKey, uid).toString());
|
||||
if (map == null || map.get("isDelete").equals("1")) {
|
||||
RedisUtil.del(token);
|
||||
RedisUtil.hDel(AdminConfig.backstageManageKey, uid);
|
||||
AjaxResult result = AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), HttpEnum.TOKEN_INVALID.getMsg());
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.hxkj.common.entity.system.SystemLogOperate;
|
|||
import com.hxkj.common.mapper.system.SystemLogOperateMapper;
|
||||
import com.hxkj.common.utils.HttpUtil;
|
||||
import com.hxkj.common.utils.IpUtil;
|
||||
import com.hxkj.common.utils.RequestUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
|
|
@ -116,10 +117,10 @@ public class LogAspect {
|
|||
SystemLogOperate model = new SystemLogOperate();
|
||||
model.setAdminId(adminId);
|
||||
model.setTitle(logAnnotation.title());
|
||||
model.setIp(IpUtil.getIpAddress(request));
|
||||
model.setIp(IpUtil.getIpAddress());
|
||||
model.setType(request.getMethod());
|
||||
model.setMethod(className + "." + methodName + "()");
|
||||
model.setUrl(HttpUtil.route());
|
||||
model.setUrl(RequestUtil.route());
|
||||
model.setArgs(params);
|
||||
model.setError(error);
|
||||
model.setStatus(status);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.hxkj.admin.validate.PageParam;
|
|||
import com.hxkj.admin.vo.album.AlbumVo;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.utils.ArrayUtil;
|
||||
import com.hxkj.common.utils.ToolsUtil;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -20,7 +21,7 @@ import java.util.Map;
|
|||
* 相册管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/album")
|
||||
@RequestMapping("api/album")
|
||||
public class AlbumController {
|
||||
|
||||
@Resource
|
||||
|
|
@ -69,7 +70,7 @@ public class AlbumController {
|
|||
return AjaxResult.failed("缺少cid参数");
|
||||
}
|
||||
|
||||
List<Integer> ids = ToolsUtil.objectToListAsInt(params.get("ids"));
|
||||
List<Integer> ids = ArrayUtil.objectToListAsInt(params.get("ids"));
|
||||
iAlbumService.albumMove(ids, Integer.parseInt(params.get("cid").toString()));
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/article")
|
||||
@RequestMapping("api/article")
|
||||
public class ArticleController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.Map;
|
|||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/index")
|
||||
@RequestMapping("api/index")
|
||||
public class IndexController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.util.Map;
|
|||
* 上传管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/upload")
|
||||
@RequestMapping("api/upload")
|
||||
public class UploadController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.util.*;
|
|||
* 缓存监控管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/monitor")
|
||||
@RequestMapping("api/monitor")
|
||||
public class CacheController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import java.util.Map;
|
|||
* 服务监控管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/monitor")
|
||||
@RequestMapping("api/monitor")
|
||||
public class ServerController {
|
||||
/**
|
||||
* 服务器信息
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import java.util.Map;
|
|||
* 基础设置管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/setting")
|
||||
@RequestMapping("api/setting")
|
||||
public class BasicsController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
* 系统管理员管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/system/admin")
|
||||
@RequestMapping("api/system/admin")
|
||||
public class SystemAdminController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
* 系统日志管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/system/log")
|
||||
@RequestMapping("api/system/log")
|
||||
public class SystemLogController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
* 系统登录管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/system")
|
||||
@RequestMapping("api/system")
|
||||
public class SystemLoginController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.hxkj.admin.LikeAdminThreadLocal;
|
|||
import com.hxkj.admin.config.aop.Log;
|
||||
import com.hxkj.admin.service.ISystemMenuService;
|
||||
import com.hxkj.admin.validate.system.SystemMenuParam;
|
||||
import com.hxkj.admin.vo.system.SystemAuthVo;
|
||||
import com.hxkj.admin.vo.system.SystemMenuVo;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.validator.annotation.IDMust;
|
||||
|
|
@ -13,13 +12,12 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/system/menu")
|
||||
@RequestMapping("api/system/menu")
|
||||
public class SystemMenuController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import javax.annotation.Resource;
|
|||
* 系统角色管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/system/role")
|
||||
@RequestMapping("api/system/role")
|
||||
public class SystemRoleController {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class AlbumServiceImpl implements IAlbumService {
|
|||
BeanUtils.copyProperties(album, vo);
|
||||
|
||||
vo.setUri(UrlUtil.toAbsoluteUrl(album.getUri()));
|
||||
vo.setSize(ToolsUtil.toStorageUnit(album.getSize()));
|
||||
vo.setSize(ToolsUtil.storageUnit(album.getSize()));
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(album.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtil.timestampToDate(album.getUpdateTime()));
|
||||
albumVoArrayList.add(vo);
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ public class SystemAdminServiceImpl implements ISystemAdminService {
|
|||
this.cacheAdminUserByUid(adminId);
|
||||
|
||||
if (systemAdminParam.getPassword() != null) {
|
||||
String token = Objects.requireNonNull(HttpUtil.obj()).getHeader("token");
|
||||
String token = Objects.requireNonNull(RequestUtil.handler()).getHeader("token");
|
||||
RedisUtil.del(AdminConfig.backstageTokenKey + token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
|||
}
|
||||
|
||||
try {
|
||||
sysAdmin.setLastLoginIp(HttpUtil.ip());
|
||||
sysAdmin.setLastLoginIp(IpUtil.getIpAddress());
|
||||
sysAdmin.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||
systemAdminMapper.updateById(sysAdmin);
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
|||
response.put("token", token);
|
||||
|
||||
// 更新登录信息
|
||||
sysAdmin.setLastLoginIp(HttpUtil.ip());
|
||||
sysAdmin.setLastLoginIp(IpUtil.getIpAddress());
|
||||
sysAdmin.setLastLoginTime(TimeUtil.timestamp());
|
||||
systemAdminMapper.updateById(sysAdmin);
|
||||
|
||||
|
|
@ -118,13 +118,13 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
|||
*/
|
||||
private void recordLoginLog(Integer adminId, String username, String error) {
|
||||
try {
|
||||
HttpServletRequest request = Objects.requireNonNull(HttpUtil.obj());
|
||||
HttpServletRequest request = Objects.requireNonNull(RequestUtil.handler());
|
||||
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
||||
|
||||
SystemLogLogin model = new SystemLogLogin();
|
||||
model.setAdminId(adminId);
|
||||
model.setUsername(username);
|
||||
model.setIp(HttpUtil.ip());
|
||||
model.setIp(IpUtil.getIpAddress());
|
||||
model.setOs(userAgent.getOperatingSystem().getName());
|
||||
model.setBrowser(userAgent.getBrowser().getName());
|
||||
model.setStatus(StringUtil.isEmpty(error) ? 1 : 0);
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class SystemRoleMenuServiceImpl implements ISystemRoleMenuService {
|
|||
}
|
||||
}
|
||||
|
||||
RedisUtil.hSet(AdminConfig.backstageRolesKey, String.valueOf(roleId), ArrayUtil.listStrToString(menuArray, ","));
|
||||
RedisUtil.hSet(AdminConfig.backstageRolesKey, String.valueOf(roleId), ArrayUtil.listToStringByStr(menuArray, ","));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ public class ServerResult {
|
|||
long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
|
||||
long totalCpu = user + nice + cSys + idle + ioWait + irq + softer + steal;
|
||||
cpu.setCpuNum(processor.getLogicalProcessorCount());
|
||||
cpu.setTotal(totalCpu);
|
||||
cpu.setSys(cSys);
|
||||
cpu.setUsed(user);
|
||||
cpu.setWait(ioWait);
|
||||
cpu.setFree(idle);
|
||||
cpu.setTotal(ArithUtil.round(ArithUtil.mul(totalCpu, 100), 2));
|
||||
cpu.setSys(ArithUtil.round(ArithUtil.mul(cSys / cpu.getTotal(), 100), 2));
|
||||
cpu.setUsed(ArithUtil.round(ArithUtil.mul(user / cpu.getTotal(), 100), 2));
|
||||
cpu.setWait(ArithUtil.round(ArithUtil.mul(ioWait / cpu.getTotal(), 100), 2));
|
||||
cpu.setFree( ArithUtil.round(ArithUtil.mul(idle / cpu.getTotal(), 100), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ public class ArithUtil {
|
|||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
|
||||
* 小数点以后10位,以后的数字四舍五入。
|
||||
* 小数点以后10位,以后的数字四舍五入
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
* @return 两个参数的商
|
||||
|
|
@ -66,7 +67,7 @@ public class ArithUtil {
|
|||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
|
||||
* 定精度,以后的数字四舍五入。
|
||||
* 定精度,以后的数字四舍五入。
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.hxkj.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数组工具类
|
||||
|
|
@ -98,7 +98,23 @@ public class ArrayUtil {
|
|||
* @param separator 分割符号
|
||||
* @return String
|
||||
*/
|
||||
public static String listToString(List<Long> list, String separator) {
|
||||
public static String listToStringByLong(List<Long> list, String separator) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object o : list) {
|
||||
sb.append(o).append(separator);
|
||||
}
|
||||
return list.isEmpty() ? "" : sb.substring(0, sb.toString().length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表转字符串
|
||||
*
|
||||
* @author fzr
|
||||
* @param list 列表 [1, 2, 4] -> 1,2,3
|
||||
* @param separator 分割符号
|
||||
* @return String
|
||||
*/
|
||||
public static String listToStringByInt(List<Integer> list, String separator) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object o : list) {
|
||||
sb.append(o).append(separator);
|
||||
|
|
@ -114,7 +130,7 @@ public class ArrayUtil {
|
|||
* @param separator 分割符号
|
||||
* @return String
|
||||
*/
|
||||
public static String listStrToString(List<String> list, String separator) {
|
||||
public static String listToStringByStr(List<String> list, String separator) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object o : list) {
|
||||
sb.append(o).append(separator);
|
||||
|
|
@ -127,21 +143,22 @@ public class ArrayUtil {
|
|||
*
|
||||
* @author fzr
|
||||
* @param str 字符串
|
||||
* @return List<Integer>
|
||||
* @param regex 分隔符
|
||||
* @return List<Long>
|
||||
*/
|
||||
public static List<Integer> stringToArray(String str){
|
||||
return stringToArrayByRegex(str, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串分割,转化为数组
|
||||
*
|
||||
* @author fzr
|
||||
* @param str 字符串
|
||||
* @return List<String>
|
||||
*/
|
||||
public static List<String> stringToArrayStr(String str){
|
||||
return stringToArrayStrRegex(str, ",");
|
||||
public static List<Long> stringToListAsLong(String str, String regex){
|
||||
List<Long> list = new ArrayList<>();
|
||||
if (str.contains(regex)){
|
||||
String[] split = str.split(regex);
|
||||
for (String value : split) {
|
||||
if(!StringUtil.isBlank(value)){
|
||||
list.add(Long.parseLong(value.trim()));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
list.add(Long.parseLong(str));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,12 +169,10 @@ public class ArrayUtil {
|
|||
* @param regex 分隔符
|
||||
* @return List<Integer>
|
||||
*/
|
||||
public static List<Integer> stringToArrayByRegex(String str, String regex){
|
||||
public static List<Integer> stringToListAsInt(String str, String regex){
|
||||
List<Integer> list = new ArrayList<>();
|
||||
if (str.contains(regex)){
|
||||
|
||||
String[] split = str.split(regex);
|
||||
|
||||
for (String value : split) {
|
||||
if(!StringUtil.isBlank(value)){
|
||||
list.add(Integer.parseInt(value.trim()));
|
||||
|
|
@ -170,22 +185,20 @@ public class ArrayUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* 字符串分割,转化为数组
|
||||
* 字符串分割,转化为数组
|
||||
*
|
||||
* @author fzr
|
||||
* @param str 字符串
|
||||
* @param regex 分隔符
|
||||
* @return List<String>
|
||||
*/
|
||||
public static List<String> stringToArrayStrRegex(String str, String regex ){
|
||||
public static List<String> stringToListAsStr(String str, String regex){
|
||||
List<String> list = new ArrayList<>();
|
||||
if (str.contains(regex)){
|
||||
|
||||
String[] split = str.split(regex);
|
||||
|
||||
for (String value : split) {
|
||||
if(!StringUtil.isBlank(value)){
|
||||
list.add(value);
|
||||
list.add(value.trim());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
|
@ -194,4 +207,88 @@ public class ArrayUtil {
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转列表Map
|
||||
*
|
||||
* @author fzr
|
||||
* @param s 字符串
|
||||
* @return Map<String, Long>
|
||||
*/
|
||||
public static List<Map<String, Long>> stringToListAsMapLong(String s) {
|
||||
Type type = new TypeToken<List<Map<String, Long>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转列表Map
|
||||
*
|
||||
* @author fzr
|
||||
* @param s 字符串
|
||||
* @return Map<String, Integer>
|
||||
*/
|
||||
public static List<Map<String, Integer>> stringToListAsMapInt(String s) {
|
||||
Type type = new TypeToken<List<Map<String, Integer>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转列表Map
|
||||
*
|
||||
* @author fzr
|
||||
* @param s 字符串
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public static List<Map<String, Object>> stringToListAsMapObj(String s) {
|
||||
Type type = new TypeToken<List<Map<String, Object>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转列表Map
|
||||
*
|
||||
* @author fzr
|
||||
* @param s 字符串
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static List<Map<String, String>> stringToListAsMapStr(String s) {
|
||||
Type type = new TypeToken<List<Map<String, String>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转List
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return List<Long>
|
||||
*/
|
||||
public static List<Integer> objectToListAsLong(Object object) {
|
||||
Type type = new TypeToken<List<Long>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转List
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return List<Integer>
|
||||
*/
|
||||
public static List<Integer> objectToListAsInt(Object object) {
|
||||
Type type = new TypeToken<List<Integer>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转List
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return List<String>
|
||||
*/
|
||||
public static List<Integer> objectToListAsStr(Object object) {
|
||||
Type type = new TypeToken<List<String>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class ConfigUtil {
|
|||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
return ToolsUtil.jsonToMapAsStr(config.getValue());
|
||||
return ToolsUtil.jsonToMap(config.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,135 +14,12 @@ import java.security.cert.X509Certificate;
|
|||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 请求工具类
|
||||
* HTTP工具类
|
||||
*/
|
||||
public class HttpUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
|
||||
|
||||
/**
|
||||
* 获取请求对象
|
||||
*
|
||||
* @author fzr
|
||||
* @return HttpServletRequest
|
||||
*/
|
||||
public static HttpServletRequest obj() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
return servletRequestAttributes.getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不带参请求URl
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String url() {
|
||||
HttpServletRequest request = HttpUtil.obj();
|
||||
if (request != null) {
|
||||
return request.getRequestURL().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求路由
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String route() {
|
||||
HttpServletRequest request = HttpUtil.obj();
|
||||
if (request != null) {
|
||||
return request.getRequestURI();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求域名
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String domain() {
|
||||
HttpServletRequest request = HttpUtil.obj();
|
||||
if (request != null) {
|
||||
String requestUrl = request.getRequestURL().toString();
|
||||
List<String> urls = Arrays.asList(requestUrl.split("/"));
|
||||
|
||||
String agree = "http:";
|
||||
if (request.getServerPort() == 443) {
|
||||
agree = "https:";
|
||||
}
|
||||
|
||||
return agree + "//" + urls.get(2).split(":")[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求客户端IP
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String ip() {
|
||||
HttpServletRequest request = HttpUtil.obj();
|
||||
if (request != null) {
|
||||
String ipAddress;
|
||||
try {
|
||||
ipAddress = request.getHeader("x-forwarded-for");
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress.equals("127.0.0.1")) {
|
||||
InetAddress inet = null;
|
||||
try {
|
||||
inet = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert inet != null;
|
||||
ipAddress = inet.getHostAddress();
|
||||
}
|
||||
}
|
||||
if (ipAddress != null && ipAddress.length() > 15) {
|
||||
if (ipAddress.indexOf(",") > 0) {
|
||||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ipAddress="";
|
||||
}
|
||||
return ipAddress == null ? "" : ipAddress;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是GET请求
|
||||
*
|
||||
* @author fzr
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isGet() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request.getMethod().equals("GET");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定URL发送GET方法的请求 (不带参)
|
||||
*
|
||||
|
|
@ -213,6 +90,7 @@ public class HttpUtil {
|
|||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @author fzr
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
|
|
@ -269,6 +147,7 @@ public class HttpUtil {
|
|||
/**
|
||||
* 发送SSL的POST请求
|
||||
*
|
||||
* @author fzr
|
||||
* @param url 请求地址
|
||||
* @param param 请求参数
|
||||
* @return String
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ public class IpUtil {
|
|||
/**
|
||||
* 获取客户端IP
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @return IP地址
|
||||
* @author fzr
|
||||
* @return IP地址 (113.67.10.194)
|
||||
*/
|
||||
public static String getIpAddress(HttpServletRequest request) {
|
||||
public static String getIpAddress() {
|
||||
HttpServletRequest request = RequestUtil.handler();
|
||||
if (request == null) {
|
||||
return "unknown";
|
||||
}
|
||||
|
|
@ -51,11 +52,12 @@ public class IpUtil {
|
|||
/**
|
||||
* 根据IP获取所在地址
|
||||
*
|
||||
* @author fzr
|
||||
* @param ip Ip地址
|
||||
* @return String (广州省 广州市)
|
||||
*/
|
||||
public static String getRealAddressByIP(String ip) {
|
||||
String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
|
||||
String IP_URL = "https://whois.pconline.com.cn/ipJson.jsp";
|
||||
String UNKNOWN = "XX XX";
|
||||
|
||||
// 内网不查询
|
||||
|
|
@ -95,6 +97,7 @@ public class IpUtil {
|
|||
/**
|
||||
* 检查是否为内部IP地址
|
||||
*
|
||||
* @author fzr
|
||||
* @param address byte地址
|
||||
* @return 结果
|
||||
*/
|
||||
|
|
@ -132,6 +135,7 @@ public class IpUtil {
|
|||
/**
|
||||
* 将IPv4地址转换成字节
|
||||
*
|
||||
* @author fzr
|
||||
* @param text IPv4地址
|
||||
* @return byte 字节
|
||||
*/
|
||||
|
|
@ -206,6 +210,7 @@ public class IpUtil {
|
|||
/**
|
||||
* 获取IP地址
|
||||
*
|
||||
* @author fzr
|
||||
* @return 本地IP地址
|
||||
*/
|
||||
public static String getHostIp() {
|
||||
|
|
@ -219,6 +224,7 @@ public class IpUtil {
|
|||
/**
|
||||
* 获取主机名
|
||||
*
|
||||
* @author fzr
|
||||
* @return 本地主机名
|
||||
*/
|
||||
public static String getHostName() {
|
||||
|
|
@ -232,6 +238,7 @@ public class IpUtil {
|
|||
/**
|
||||
* 从多级反向代理中获得第一个非unknown IP地址
|
||||
*
|
||||
* @author fzr
|
||||
* @param ip 获得的IP地址
|
||||
* @return 第一个非unknown IP地址
|
||||
*/
|
||||
|
|
@ -249,8 +256,9 @@ public class IpUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* 检测给定字符串是否为未知,多用于检测HTTP请求相关
|
||||
* 检测给定字符串是否为未知,多用于检测HTTP请求相关
|
||||
*
|
||||
* @author fzr
|
||||
* @param checkString 被检测的字符串
|
||||
* @return 是否未知
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
package com.hxkj.common.utils;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 请求工具类
|
||||
*/
|
||||
public class RequestUtil {
|
||||
|
||||
/**
|
||||
* 获取请求对象
|
||||
*
|
||||
* @author fzr
|
||||
* @return HttpServletRequest
|
||||
*/
|
||||
public static HttpServletRequest handler() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
return servletRequestAttributes.getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不带参请求URl
|
||||
* 示例: https://127.0.0.1:8082/api/system/menu/menus
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String url() {
|
||||
HttpServletRequest request = RequestUtil.handler();
|
||||
if (request != null) {
|
||||
return request.getRequestURL().toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求路由
|
||||
* 示例: /api/system/menu/menus
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String route() {
|
||||
HttpServletRequest request = RequestUtil.handler();
|
||||
if (request != null) {
|
||||
return request.getRequestURI();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求域名
|
||||
* 示例: https://127.0.0.1
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String domain() {
|
||||
HttpServletRequest request = RequestUtil.handler();
|
||||
if (request != null) {
|
||||
String requestUrl = request.getRequestURL().toString();
|
||||
List<String> urls = Arrays.asList(requestUrl.split("/"));
|
||||
|
||||
String agree = "http:";
|
||||
if (request.getServerPort() == 443) {
|
||||
agree = "https:";
|
||||
}
|
||||
|
||||
return agree + "//" + urls.get(2).split(":")[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是GET请求
|
||||
*
|
||||
* @author fzr
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isGet() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request.getMethod().equals("GET");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是POST请求
|
||||
*
|
||||
* @author fzr
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isPost() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request.getMethod().equals("POST");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是PUT请求
|
||||
*
|
||||
* @author fzr
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isPUT() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request.getMethod().equals("PUT");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是DELETE请求
|
||||
*
|
||||
* @author fzr
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isDelete() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (servletRequestAttributes != null) {
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request.getMethod().equals("DELETE");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -452,7 +452,7 @@ public class TimeUtil {
|
|||
* @author fzr
|
||||
* @return int
|
||||
*/
|
||||
public static long monthDay(){
|
||||
public static Integer monthDay(){
|
||||
Date date = new Date();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class ToolsUtil {
|
|||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public static String toStorageUnit(Long size) {
|
||||
public static String storageUnit(Long size) {
|
||||
if (size == null) {
|
||||
return "0B";
|
||||
}
|
||||
|
|
@ -133,31 +133,19 @@ public class ToolsUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* JSON转map
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public static Map<String, Object> jsonToMap(String json){
|
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转map
|
||||
* JSON转 Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static Map<String, String> jsonToMapAsStr(String json){
|
||||
public static Map<String, String> jsonToMap(String json){
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转map
|
||||
* JSON转Map<String, String>
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
|
|
@ -169,41 +157,31 @@ public class ToolsUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* 字符串转List<Map<String, String>>
|
||||
*
|
||||
* @author fzr
|
||||
* @param s 字符串
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
public static List<Map<String, String>> stringToListAsMap(String s) {
|
||||
Type type = new TypeToken<List<Map<String, String>>>() {}.getType();
|
||||
return JSON.parseObject(s, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转List<Integer>
|
||||
*
|
||||
* @author fzr
|
||||
* @param object 对象
|
||||
* @return List<Integer>
|
||||
*/
|
||||
public static List<Integer> objectToListAsInt(Object object) {
|
||||
Type type = new TypeToken<List<Integer>>() {}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* map合并
|
||||
* map合并(Object)
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Object
|
||||
*/
|
||||
public static Map<String, Object> mergeMap(Map<String, Object> map, Map<String, Object> map1){
|
||||
public static Map<String, Object> mergeMapByObj(Map<String, Object> map, Map<String, Object> map1){
|
||||
HashMap<String, Object> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
/**
|
||||
* map合并(String)
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 对象
|
||||
* @return Object
|
||||
*/
|
||||
public static Map<String, String> mergeMapByStr(Map<String, String> map, Map<String, String> map1){
|
||||
HashMap<String, String> map2 = new HashMap<>();
|
||||
map2.putAll(map);
|
||||
map2.putAll(map1);
|
||||
return map2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class UrlUtil {
|
|||
|
||||
String engine = ConfigUtil.get("storage", "default", "local");
|
||||
if (engine.equals("local")) {
|
||||
return HttpUtil.domain() + "/" + uploadPrefix + url;
|
||||
return RequestUtil.domain() + "/" + uploadPrefix + url;
|
||||
}
|
||||
|
||||
Map<String, String> config = ConfigUtil.getMap("storage", engine);
|
||||
|
|
@ -53,7 +53,7 @@ public class UrlUtil {
|
|||
|
||||
String engine = ConfigUtil.get("storage", "default", "local");
|
||||
if (engine.equals("local")) {
|
||||
return url.replace(HttpUtil.domain() + "/" + uploadPrefix + "/", "");
|
||||
return url.replace(RequestUtil.domain() + "/" + uploadPrefix + "/", "");
|
||||
}
|
||||
|
||||
Map<String, String> config = ConfigUtil.getMap("storage", engine);
|
||||
|
|
@ -69,7 +69,7 @@ public class UrlUtil {
|
|||
public static String domain() {
|
||||
String engine = ConfigUtil.get("storage", "default", "local");
|
||||
if (engine.equals("local")) {
|
||||
return HttpUtil.domain() + "/";
|
||||
return RequestUtil.domain() + "/";
|
||||
}
|
||||
|
||||
Map<String, String> config = ConfigUtil.getMap("storage", engine);
|
||||
|
|
|
|||
Loading…
Reference in New Issue