18 changed files with 14126 additions and 49 deletions
@ -1 +1 @@ |
|||||
ALTER TABLE esd_admin.sys_menu ADD menu_code varchar(50) NULL COMMENT '菜单编码'; |
ALTER TABLE esua_epdc_admin.sys_menu ADD menu_code varchar(50) NULL COMMENT '菜单编码'; |
||||
|
File diff suppressed because it is too large
@ -0,0 +1,100 @@ |
|||||
|
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<Map<String, String>> articleList = ExcelImportUtil.importExcel(file.getInputStream(), Map.class, importParams); |
||||
|
|
||||
|
for (Map<String, String> 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; |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue