Java工具类

public class FormatUtils {
    private static final int DIGITNUM = 10;

    public FormatUtils() {
    }

    public static List<Integer> str2IntArray(String str) {
        return str2IntArray(str, ";");
    }

    public static List<Integer> str2IntArray(String str, String seperator) {
        List<Integer> ret = Lists.newArrayList();
        if (StringUtils.isEmpty(str)) {
            return ret;
        } else {
            String[] nums = str.split(seperator);
            String[] var4 = nums;
            int var5 = nums.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String num = var4[var6];
                ret.add(Integer.valueOf(num));
            }

            return ret;
        }
    }

    public static String intArray2Str(List<Integer> nums) {
        return intArray2Str(nums, ";");
    }

    public static String intArray2Str(List<Integer> nums, String seperator) {
        String str = null;
        if (nums == null) {
            return null;
        } else if (nums.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < nums.size(); ++i) {
                Integer num = (Integer)nums.get(i);
                if (i == 0) {
                    str = String.valueOf(num);
                } else {
                    str = str + seperator + num;
                }
            }

            return str;
        }
    }

    public static List<Long> str2LongArray(String str) {
        return str2LongArray(str, ";");
    }

    public static List<Long> str2LongArray(String str, String seperator) {
        List<Long> ret = Lists.newArrayList();
        if (StringUtils.isEmpty(str)) {
            return ret;
        } else {
            String[] nums = str.split(seperator);
            String[] var4 = nums;
            int var5 = nums.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String num = var4[var6];
                ret.add(Long.valueOf(num));
            }

            return ret;
        }
    }

    public static String longArray2Str(List<Long> nums) {
        return longArray2Str(nums, ";");
    }

    public static String longArray2Str(List<Long> nums, String seperator) {
        String str = null;
        if (nums == null) {
            return null;
        } else if (nums.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < nums.size(); ++i) {
                Long num = (Long)nums.get(i);
                if (i == 0) {
                    str = String.valueOf(num);
                } else {
                    str = str + seperator + num;
                }
            }

            return str;
        }
    }

    public static List<String> str2StrArray(String str) {
        return str2StrArray(str, ";");
    }

    public static List<String> str2StrArray(String str, String seperator) {
        if (StringUtils.isEmpty(str)) {
            return Lists.newArrayList();
        } else {
            String[] strs = str.split(seperator);
            List<String> ret = new ArrayList();
            String[] var4 = strs;
            int var5 = strs.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String url = var4[var6];
                ret.add(url);
            }

            return ret;
        }
    }

    public static String strArray2Str(List<String> strs) {
        return strArray2Str(strs, ";");
    }

    public static String strArray2Str(List<String> strs, String seperator) {
        StringBuilder ret = new StringBuilder();
        if (strs == null) {
            return null;
        } else if (strs.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < strs.size(); ++i) {
                String str = (String)strs.get(i);
                ret.append(str);
                if (i != strs.size() - 1) {
                    ret.append(seperator);
                }
            }

            return ret.toString();
        }
    }

    public static Map<String, String> str2StrMap(String mapStr) {
        Map<String, String> map = Maps.newHashMap();
        if (StringUtils.isEmpty(mapStr)) {
            return map;
        } else {
            String[] strList = mapStr.split(";");
            String[] var3 = strList;
            int var4 = strList.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                String str = var3[var5];
                String[] kv = str.split(":");
                if (kv != null && kv.length == 2) {
                    map.put(kv[0], kv[1]);
                }
            }

            return map;
        }
    }

    public static String strMap2Str(Map<String, String> mapStr) {
        StringBuilder ret = new StringBuilder();
        if (CollectionUtils.isEmpty(mapStr)) {
            return ret.toString();
        } else {
            Set<Entry<String, String>> entrys = mapStr.entrySet();
            int i = 0;
            Iterator var4 = entrys.iterator();

            while(var4.hasNext()) {
                Entry<String, String> entry = (Entry)var4.next();
                if (entry.getKey() != null && entry.getValue() != null) {
                    ret.append((String)entry.getKey()).append(":").append((String)entry.getValue());
                    if (i != entrys.size() - 1) {
                        ret.append(";");
                    }

                    ++i;
                }
            }

            return ret.toString();
        }
    }

    public static String printStr(long num) {
        return printStr(10, num);
    }

    public static String printStr(int digitNum, long num) {
        return String.format("%0" + digitNum + "d", num);
    }

    public static <T> T mapToDTO(Map<?, ?> map, Class<T> clz) {
        return JSON.parseObject(JSON.toJSONString(map), clz);
    }

    public static Map<String, Object> dtoToMap(Object object) {
        return JSON.parseObject(JSON.toJSONString(object));
    }

    public static String toJsonString(Map<?, ?> map) {
        if (map == null) {
            return null;
        } else {
            return map.isEmpty() ? "" : JSON.toJSONString(map);
        }
    }

    public static Double formatDiscount(Integer discount) {
        return (double)discount / 10000.0D;
    }

    public static Integer formatDiscount(Double discount) {
        return Double.valueOf(discount * 10000.0D).intValue();
    }

    public static String mapToKeyValueStrSortByKey(Map<String, Object> map, String... ignoreParams) {
        if (CollectionUtils.isEmpty(map)) {
            return "";
        } else {
            List<String> ignoreList = ignoreParams != null ? Arrays.asList(ignoreParams) : null;
            String keyValueStr = (String)map.entrySet().stream().filter((entry) -> {
                return ignoreList == null || !ignoreList.contains(entry.getKey());
            }).sorted(Entry.comparingByKey()).map((entry) -> {
                return (String)entry.getKey() + entry.getValue();
            }).collect(Collectors.joining());
            return keyValueStr;
        }
    }

    public static String mapToValueStrSortByKey(Map<String, Object> map, String... ignoreParams) {
        if (CollectionUtils.isEmpty(map)) {
            return "";
        } else {
            List<String> ignoreList = ignoreParams != null ? Arrays.asList(ignoreParams) : null;
            String valueStr = (String)map.entrySet().stream().filter((entry) -> {
                return ignoreList == null || !ignoreList.contains(entry.getKey());
            }).sorted(Entry.comparingByKey()).map((entry) -> {
                return String.valueOf(entry.getValue());
            }).collect(Collectors.joining());
            return valueStr;
        }
    }

    public static String camelToSnake(String field) {
        String regex = "([a-z])([A-Z]+)";
        String replacement = "$1_$2";
        return field.replaceAll(regex, replacement).toLowerCase();
    }
}

RestTemplate与Get/POST请求

public <T extends BaseBLXResponse> T execute(BaseBLXRequest<T> request) {
        String uri = request.getRequestUri();
        String url = baseUrl + uri;

        SerializeConfig config = new SerializeConfig();
        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        Map<String, Object> map = JSON.parseObject(JSON.toJSONString(request, config));

        String method = request.getMethod();
        String resultJson = "";
        if (method.equals(METHOD_GET)) {
            MultiValueMap<String, String> param= new LinkedMultiValueMap<>();
            for (String key : map.keySet()) {
                param.add(key, map.get(key).toString());
            }
            UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
            URI urlGet = builder.queryParams(param).build().encode().toUri();
            logger.info("=========>uri: {}, urlGet: {}", uri, urlGet);

            ResponseEntity<String> responseEntity = restTemplate.getForEntity(urlGet, String.class);
            resultJson = responseEntity.getBody();
        } else if (method.equals(METHOD_POST)) {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);

            MultiValueMap<String, Object> reqBean= new LinkedMultiValueMap<>();
            for (String key : map.keySet()) {
                reqBean.add(key, map.get(key));
            }
            logger.info("=========>uri: {}, reqBean: {}", uri, reqBean);

            HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(reqBean, headers);
            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
            resultJson = responseEntity.getBody();
        }
        logger.info("=========>uri: {}, resultJson: {}", uri, resultJson);

        JSONObject result = JSON.parseObject(resultJson);
        String code = result.getString("code");
        String msg = result.getString("msg");
        JSONObject respData = new JSONObject();
        if (SUCCESS_CODE.equals(code)) {
            respData = result.getJSONObject("data");
        }
        respData.put("code", code);
        respData.put("msg", msg);
        return respData.toJavaObject(request.getResponseClass());
    }

php实现百万级数据快速导出CSV

//让程序一直运行
set_time_limit(0);
//设置程序运行内存
ini_set('memory_limit', '128M');
//导出文件名
$fileName = '测试导出数据';
header('Content-Encoding: UTF-8');
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
header('Content-Disposition: attachment;filename="' . $fileName . '.csv"');
//打开php标准输出流
$fp = fopen('php://output', 'a');
//添加BOM头,以UTF8编码导出CSV文件,如果文件头未添加BOM头,打开会出现乱码。
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));
//添加导出标题
fputcsv($fp, ['姓名', '岁数', '邮箱']);
$nums = 10000; //每次导出数量
$count = Test::find()->count();
$step = ceil($count/$nums);//循环次数
for($i = 0; $i < $step; $i++) {
    $result = Test::find()
        ->select(['name', 'age', 'email'])
        ->limit($nums)
        ->offset($i * $nums)
        ->asArray()
        ->all();
    foreach ($result as $item) {
        fputcsv($fp, $item);
    }
    //每1万条数据就刷新缓冲区
    ob_flush();
    flush();
}
exit;