From fd586a2bcd4a423dcbf1f46fb84b7a3407c20885 Mon Sep 17 00:00:00 2001 From: yujintao Date: Tue, 19 Nov 2019 15:29:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ImportInShiBeiController.java | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 esua-epdc/epdc-module/epdc-demo/epdc-demo-server/src/main/java/com/elink/esua/epdc/controller/ImportInShiBeiController.java diff --git a/esua-epdc/epdc-module/epdc-demo/epdc-demo-server/src/main/java/com/elink/esua/epdc/controller/ImportInShiBeiController.java b/esua-epdc/epdc-module/epdc-demo/epdc-demo-server/src/main/java/com/elink/esua/epdc/controller/ImportInShiBeiController.java deleted file mode 100644 index 7db253462..000000000 --- a/esua-epdc/epdc-module/epdc-demo/epdc-demo-server/src/main/java/com/elink/esua/epdc/controller/ImportInShiBeiController.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.elink.esua.epdc.controller; - -import cn.afterturn.easypoi.excel.ExcelImportUtil; -import cn.afterturn.easypoi.excel.entity.ImportParams; -import com.alibaba.fastjson.JSONObject; -import com.elink.esua.epdc.commons.tools.utils.Result; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.CharEncoding; -import org.apache.http.HttpEntity; -import org.apache.http.HttpStatus; -import org.apache.http.ParseException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import java.io.*; -import java.util.List; -import java.util.Map; - -/** - * @author work@yujt.net.cn - * @date 1 1 - */ -@Slf4j -@RestController -@RequestMapping("inshibei") -public class ImportInShiBeiController { - - - @GetMapping("coterie/batchSave") - public Result importExcel(MultipartFile file, String userId, String token) { - ImportParams importParams = new ImportParams(); - importParams.setHeadRows(1); - try { - List> articleList = ExcelImportUtil.importExcel(file.getInputStream(), Map.class, importParams); - - for (Map objectMap : articleList) { - postWithParam(userId, token, objectMap.get("content"), objectMap.get("type")); - } - } catch (Exception e) { - e.printStackTrace(); - } - return new Result(); - } - - private void postWithParam(String userId, String token, String detail, String type) throws Exception { - CloseableHttpClient httpClient = HttpClients.createDefault(); - - JSONObject json = new JSONObject(); - json.put("userId", userId); - json.put("token", token); - json.put("detail", detail); - json.put("coterieType", type); - - HttpPost httpPost = new HttpPost("http://hxb.elinkit.com.cn/InShiBei/rest/coterie/save"); - StringEntity stringEntity = new StringEntity(json.toJSONString(), CharEncoding.UTF_8); - stringEntity.setContentEncoding(CharEncoding.UTF_8); - // 发送json数据需要设置contentType - stringEntity.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); - httpPost.setEntity(stringEntity); - - getStringResult(httpClient.execute(httpPost)); - } - - - private static String getStringResult(CloseableHttpResponse response) { - String result = null; - try { - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - HttpEntity httpEntity = response.getEntity(); - result = EntityUtils.toString(httpEntity, CharEncoding.UTF_8); - } else { - log.error("拉取失败,错误编码为:" + response.getStatusLine().getStatusCode()); - } - } catch (ParseException e) { - log.error("getResult方法格式转换异常ParseException"); - e.printStackTrace(); - } catch (IOException e) { - log.error("getResult方法IO异常IOException"); - e.printStackTrace(); - } finally { - try { - if (null != response) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return result; - } -}