102 lines
3.6 KiB
Java
102 lines
3.6 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import org.apache.commons.collections.MapUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
public class FlowUtil {
|
|
|
|
|
|
/**
|
|
* 获取文件url
|
|
*
|
|
* @param map
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public static String getFileUrl(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : ((Map) ((List) o).get(0)).get("url").toString()).orElse(null);
|
|
}
|
|
|
|
/**
|
|
* 获取文件url完整链接
|
|
*
|
|
* @param map
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public static String getFileUrlWithHost(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : PathUtil.getServerUrl() + "/image/" + ((Map) ((List) o).get(0)).get("url").toString()).orElse(null);
|
|
}
|
|
|
|
/**
|
|
* 获取文件原来的名称
|
|
*
|
|
* @param map
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public static String getFileOriginFileName(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : ((Map) ((List) o).get(0)).get("name").toString()).orElse(null);
|
|
}
|
|
|
|
/**
|
|
* 获取下拉Long
|
|
*
|
|
* @param map
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public static Long getPullDownLong(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : Convert.toLong(((List) o).get(0))).orElse(null);
|
|
}
|
|
|
|
public static Date getDate(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : DateUtil.parse(o.toString())).orElse(null);
|
|
}
|
|
|
|
public static Date getStartDate(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : DateUtil.parse(Convert.toStr(((List) o).get(0)))).orElse(null);
|
|
}
|
|
|
|
public static Date getEndDate(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : DateUtil.parse(Convert.toStr(((List) o).get(1)))).orElse(null);
|
|
}
|
|
|
|
public static String getJSONString(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(JSON::toJSONString).orElse(null);
|
|
}
|
|
|
|
public static List getList(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : ((List) o)).orElse(null);
|
|
}
|
|
|
|
public static String getStrings(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : StringUtils.join(((List) o), ",")).orElse(null);
|
|
}
|
|
|
|
public static String getString(Map<String, Object> map, String key) {
|
|
return MapUtils.getString(map, key);
|
|
}
|
|
|
|
public static Integer getPullDownInteger(Map<String, Object> map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : Convert.toInt(((List) o).get(0))).orElse(null);
|
|
}
|
|
|
|
public static String getLongitude(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : JSON.parseObject(o.toString()).getString("lng")).orElse(null);
|
|
}
|
|
|
|
public static String getLatitude(Map map, String key) {
|
|
return Optional.ofNullable(map.get(key)).map(o -> "".equals(o) ? null : JSON.parseObject(o.toString()).getString("lat")).orElse(null);
|
|
}
|
|
|
|
}
|