1,申请物料编码
This commit is contained in:
parent
056f908093
commit
b2dc5fa1b7
|
|
@ -11,6 +11,7 @@ import com.nflg.product.bomnew.pojo.dto.OriginalSaveBomDTO;
|
||||||
import com.nflg.product.bomnew.pojo.query.OriginalBomQuery;
|
import com.nflg.product.bomnew.pojo.query.OriginalBomQuery;
|
||||||
import com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
import com.nflg.product.bomnew.pojo.vo.BomOriginalListVO;
|
||||||
import com.nflg.product.bomnew.service.BomNewOriginalParentService;
|
import com.nflg.product.bomnew.service.BomNewOriginalParentService;
|
||||||
|
import com.nflg.product.bomnew.service.MaterialService;
|
||||||
import com.nflg.product.bomnew.util.EecExcelUtil;
|
import com.nflg.product.bomnew.util.EecExcelUtil;
|
||||||
import com.nflg.product.bomnew.util.TreeNode;
|
import com.nflg.product.bomnew.util.TreeNode;
|
||||||
import com.nflg.product.bomnew.util.VUtils;
|
import com.nflg.product.bomnew.util.VUtils;
|
||||||
|
|
@ -147,5 +148,18 @@ public class OriginalBomApi extends BaseApi {
|
||||||
return ResultVO.success(true);
|
return ResultVO.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
MaterialService materialService;
|
||||||
|
@ApiOperation("testaddMaterial")
|
||||||
|
@GetMapping("新增物料")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ResultVO<String> importBom(@RequestParam("drawingNo")String drawingNo,
|
||||||
|
@RequestParam("materialName")String materialName,
|
||||||
|
@RequestParam("materialCategoryCode")String materialCategoryCode) throws IOException {
|
||||||
|
|
||||||
|
materialService.addMaterial(drawingNo, materialName,materialCategoryCode);
|
||||||
|
return ResultVO.success("true");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,9 @@ public class NacosConfig {
|
||||||
@Value("${ini.share.path}")
|
@Value("${ini.share.path}")
|
||||||
private String sharePath;
|
private String sharePath;
|
||||||
|
|
||||||
|
@Value("${material.add.url}")
|
||||||
|
private String addMaterialUrl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,7 @@ public class MaterialMainDTO implements Serializable {
|
||||||
|
|
||||||
private List<String> materialTypeThreeFiles=new ArrayList<>();
|
private List<String> materialTypeThreeFiles=new ArrayList<>();
|
||||||
|
|
||||||
private Object materialTypeZeroFile=new Object();
|
|
||||||
|
|
||||||
private Object materialTypeOneFile=new Object();
|
|
||||||
|
|
||||||
private Object materialTypeTwoFile=new Object();
|
|
||||||
|
|
||||||
private List<String> attrs=new ArrayList<>();
|
private List<String> attrs=new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,21 @@ package com.nflg.product.bomnew.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||||
import com.nflg.product.bomnew.client.MaterialMainClient;
|
import com.nflg.product.bomnew.client.MaterialMainClient;
|
||||||
|
import com.nflg.product.bomnew.config.NacosConfig;
|
||||||
import com.nflg.product.bomnew.pojo.dto.MaterialMainDTO;
|
import com.nflg.product.bomnew.pojo.dto.MaterialMainDTO;
|
||||||
|
import com.nflg.product.bomnew.util.HttpUtils;
|
||||||
import nflg.product.common.constant.STATE;
|
import nflg.product.common.constant.STATE;
|
||||||
import nflg.product.common.vo.ResultVO;
|
import nflg.product.common.vo.ResultVO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MaterialService {
|
public class MaterialService {
|
||||||
|
|
@ -26,7 +32,7 @@ public class MaterialService {
|
||||||
* @param materialCategoryCode 物料类别编码
|
* @param materialCategoryCode 物料类别编码
|
||||||
* @return 物料编码
|
* @return 物料编码
|
||||||
*/
|
*/
|
||||||
public String addMaterial(String drawingNo, String materialName, String materialCategoryCode){
|
public String addMaterial(String drawingNo, String materialName, String materialCategoryCode) throws IOException {
|
||||||
MaterialMainDTO materialMainDTO=new MaterialMainDTO();
|
MaterialMainDTO materialMainDTO=new MaterialMainDTO();
|
||||||
materialMainDTO.setMaterialName(materialName);
|
materialMainDTO.setMaterialName(materialName);
|
||||||
materialMainDTO.setDrawingNo(drawingNo);
|
materialMainDTO.setDrawingNo(drawingNo);
|
||||||
|
|
@ -34,15 +40,13 @@ public class MaterialService {
|
||||||
materialMainDTO.setMaterialCategoryCode(materialCategoryCode);
|
materialMainDTO.setMaterialCategoryCode(materialCategoryCode);
|
||||||
materialMainDTO.setOpEnum(1);
|
materialMainDTO.setOpEnum(1);
|
||||||
materialMainDTO.setApplyDeptName(SessionUtil.getDepartName());
|
materialMainDTO.setApplyDeptName(SessionUtil.getDepartName());
|
||||||
|
String token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySW5mbyI6IntcImRlcGFydE5hbWVcIjpcIuS_oeaBr-a1geeoi-S4reW_gy9JVOaUr-aMgVwiLFwiZGVwYXJ0Um93SWRcIjoxNTg1MTk2OTc4NDEzNjk0OTc4LFwiZnVsbERlcHROYW1lXCI6XCJPVT1JVOaUr-aMgSxPVT3kv6Hmga_mtYHnqIvkuK3lv4MsT1U956aP5bu65Y2X5pa56Lev6Z2i5py65qKw5pyJ6ZmQ5YWs5Y-4LERDPW5mbGdcIixcInF1ZXJ5RGF0YVwiOjMsXCJyZWFsTmFtZVwiOlwi6YOR5Yab5qaVXCIsXCJyb3dJZFwiOjE1ODUxNjQ2NjgzMzU0Mzk4ODEsXCJ1c2VyQ29kZVwiOlwiUUhJMTcwNjIxMDBcIixcInVzZXJOYW1lXCI6XCJRSEkxNzA2MjEwMFwifSIsImV4cCI6MTcwMjAzMTg2MiwianRpIjoiMjdmMjg2MDUtNzgxZi00MDQwLWJkZDMtMzcwNGI2MWU1YzJiIn0.hpzLa9-ZYEqclA5iT-Jv62Ow3PduuP7Gqyvb7uYJcRE";
|
||||||
|
// String token=SessionUtil.getsessionKey();
|
||||||
|
HttpUtils httpUtils=new HttpUtils();
|
||||||
|
|
||||||
|
String s = httpUtils.doPost(NacosConfig.getNacosConfig().getAddMaterialUrl(),JSON.toJSONString(materialMainDTO),token);
|
||||||
|
return s;
|
||||||
|
|
||||||
ResultVO<String> stringResultVO = materialMainClient.addMaterialMainEntity(materialMainDTO);
|
|
||||||
if(stringResultVO.getState().equals(STATE.Success)){
|
|
||||||
return stringResultVO.getData();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new NflgBusinessException(STATE.Error, "申请编码失败"+stringResultVO.getMsg());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,393 @@
|
||||||
|
package com.nflg.product.bomnew.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import nflg.product.common.constant.STATE;
|
||||||
|
import okhttp3.*;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http请求工具类,封装于okHttp3
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class HttpUtils {
|
||||||
|
|
||||||
|
//请求类
|
||||||
|
private OkHttpClient okHttpClient;
|
||||||
|
|
||||||
|
//请求头类型
|
||||||
|
private final MediaType jsonMediaType = MediaType.parse("application/json;charset=utf-8");
|
||||||
|
|
||||||
|
//请求时间
|
||||||
|
private int timeout = 80;
|
||||||
|
|
||||||
|
public HttpUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpUtils(int timeout) {
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*请求返回响应头*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get请求返回响应头
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doGetRtnRsp(String url) throws IOException {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.build();
|
||||||
|
Response response = getOkHttpClient().newCall(request).execute();
|
||||||
|
|
||||||
|
if (response.code() != HttpStatus.OK.value()) {
|
||||||
|
log.error("请求失败" + (response.body() == null ? "" : ":" + response.body().string()));
|
||||||
|
throw new NflgBusinessException(STATE.ParamErr, "请求失败" + (response.body() == null ? "" : ":" + response.body().string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get请求,自动构造参数,传空则不构造
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doGetRtnRsp(String url, Map<String, String> map) throws IOException {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url + buildGetParams(map))
|
||||||
|
.get()
|
||||||
|
.build();
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post请求(表单)
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doPostRtnRsp(String url, Map<String, String> map) throws IOException {
|
||||||
|
RequestBody requestBody = buildRequestBody(map);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post请求(JSON)
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param json json字符串
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doPostRtnRsp(String url, String json,String token) throws IOException {
|
||||||
|
RequestBody requestBody = RequestBody.create(jsonMediaType, json);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.post(requestBody)
|
||||||
|
.addHeader("authorization",token)
|
||||||
|
.build();
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单请求
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doFormUrlEncodedPostRtnRsp(String url, Map<String, String> map) throws IOException {
|
||||||
|
RequestBody requestBody = buildRequestBody(map);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* form-data表单请求(兼容图片png\jpg\jpeg上传)
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doFileRequestBodyRtnRsp(String url, Map<String, String> map, File file) throws Exception {
|
||||||
|
RequestBody requestBody = buildFileRequestBody(map,file);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.header("Content-Type", "multipart/form-data")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*请求返回响应内容*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get请求(表单)
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doGet(String url) throws IOException {
|
||||||
|
Response response = doGetRtnRsp(url);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get请求(表单),自动构造参数
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doGet(String url, Map<String, String> map) throws IOException {
|
||||||
|
Response response = doGetRtnRsp(url, map);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post请求(表单)
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doPost(String url, Map<String, String> map) throws IOException {
|
||||||
|
Response response = doPostRtnRsp(url, map);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post请求(JSON)
|
||||||
|
*
|
||||||
|
* @param url 请求地址
|
||||||
|
* @param json json字符串
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doPost(String url, String json,String token) throws IOException {
|
||||||
|
System.out.println(url);
|
||||||
|
System.out.println(json);
|
||||||
|
Response response = doPostRtnRsp(url, json,token);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单请求
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doformPost(String url, Map<String, String> map) throws IOException {
|
||||||
|
Response response = doFormUrlEncodedPostRtnRsp(url, map);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multipart文件类型表单请求(兼容图片png\jpg\jpeg上传)
|
||||||
|
*
|
||||||
|
* @param url URL地址
|
||||||
|
* @param map 参数
|
||||||
|
* @return String
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public String doMultipartFormPost(String url, Map<String, String> map, File file) throws Exception {
|
||||||
|
Response response = doFileRequestBodyRtnRsp(url, map,file);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取网络图片流
|
||||||
|
*
|
||||||
|
* @param url url地址
|
||||||
|
* @return InputStream
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public InputStream getImageStream(String url) throws IOException {
|
||||||
|
OkHttpClient client = getOkHttpClient();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.build();
|
||||||
|
ResponseBody responseBody = client.newCall(request).execute().body();
|
||||||
|
if (responseBody == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return responseBody.byteStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*公共方法*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建键值对表单
|
||||||
|
*
|
||||||
|
* @param map 参数
|
||||||
|
* @return RequestBody
|
||||||
|
*/
|
||||||
|
private RequestBody buildRequestBody(Map<String, String> map) {
|
||||||
|
FormBody.Builder builder = new FormBody.Builder(StandardCharsets.UTF_8);
|
||||||
|
if (map != null && map.size() > 0) {
|
||||||
|
for (String string : map.keySet()) {
|
||||||
|
builder.add(string, map.get(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对象
|
||||||
|
*
|
||||||
|
* @return OkHttpClient
|
||||||
|
*/
|
||||||
|
private OkHttpClient getOkHttpClient() {
|
||||||
|
if (okHttpClient != null) {
|
||||||
|
return okHttpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
okHttpClient = new OkHttpClient.Builder()
|
||||||
|
.connectTimeout(timeout, TimeUnit.SECONDS)
|
||||||
|
.writeTimeout(timeout, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(timeout, TimeUnit.SECONDS)
|
||||||
|
.build();
|
||||||
|
return okHttpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建url请求字符串
|
||||||
|
*
|
||||||
|
* @param map 参数
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
private String buildGetParams(Map<String, String> map) {
|
||||||
|
if (map == null || map.size() == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder params = new StringBuilder();
|
||||||
|
for (String string : map.keySet()) {
|
||||||
|
params.append(string).append("=").append(map.get(string)).append("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "?" + params.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建multipart类型键值对表单
|
||||||
|
*
|
||||||
|
* @param map 参数
|
||||||
|
* @return RequestBody
|
||||||
|
*/
|
||||||
|
private RequestBody buildFileRequestBody(Map<String, String> map, File file)throws Exception {
|
||||||
|
|
||||||
|
MultipartBody.Builder multiBuilder=new MultipartBody.Builder();
|
||||||
|
// 设置请求体
|
||||||
|
multiBuilder.setType(MultipartBody.FORM);
|
||||||
|
String name = file.getName();
|
||||||
|
RequestBody filebody=null;
|
||||||
|
if(name.endsWith(".png")||name.endsWith(".PNG"))
|
||||||
|
{
|
||||||
|
filebody = MultipartBody.create(MediaType.parse("image/png"), file);
|
||||||
|
}else if(name.endsWith(".jpeg")||name.endsWith(".jpg")||name.endsWith(".JPEG")||name.endsWith(".JPG"))
|
||||||
|
{
|
||||||
|
filebody = MultipartBody.create(MediaType.parse("image/jpeg"), file);
|
||||||
|
}
|
||||||
|
if(filebody==null)
|
||||||
|
{
|
||||||
|
throw new Exception("图片文件上传类型"+name+"与要求不符");
|
||||||
|
}
|
||||||
|
|
||||||
|
multiBuilder.addFormDataPart("file", name, filebody);
|
||||||
|
if (map != null && map.size() > 0) {
|
||||||
|
for (String string : map.keySet()) {
|
||||||
|
multiBuilder.addFormDataPart(string, map.get(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return multiBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liusongsheng
|
||||||
|
* @date 2021/12/22 9:48
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String doGet(String url,String token) throws IOException {
|
||||||
|
Response response = doGetByToken(url,token);
|
||||||
|
if (response == null || response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* get请求返回响应头
|
||||||
|
* tokenType 为 Bearer
|
||||||
|
* @param url 请求地址
|
||||||
|
* @return Response
|
||||||
|
* @throws IOException e
|
||||||
|
*/
|
||||||
|
public Response doGetByToken(String url,String token) throws IOException {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.addHeader("Authorization", "Bearer " + token)
|
||||||
|
.build();
|
||||||
|
return getOkHttpClient().newCall(request).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ public class BaseApi {
|
||||||
ResultVO result = JwtUtil.parse(token);
|
ResultVO result = JwtUtil.parse(token);
|
||||||
if (result.getState().equals(STATE.Success.getState())) {
|
if (result.getState().equals(STATE.Success.getState())) {
|
||||||
LoginUserInfoDTO userInfo = (LoginUserInfoDTO) result.getData();
|
LoginUserInfoDTO userInfo = (LoginUserInfoDTO) result.getData();
|
||||||
|
userInfo.setSessionKey(token);
|
||||||
userInfo.setLanguage(language);
|
userInfo.setLanguage(language);
|
||||||
if (!Objects.isNull(userInfo)) {
|
if (!Objects.isNull(userInfo)) {
|
||||||
loginUser.set(userInfo);
|
loginUser.set(userInfo);
|
||||||
|
|
|
||||||
|
|
@ -87,4 +87,8 @@ public class SessionUtil {
|
||||||
public static String getLanguage() {
|
public static String getLanguage() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse(null);
|
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getsessionKey() {
|
||||||
|
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getSessionKey).orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,6 @@ public class LoginUserInfoDTO {
|
||||||
private String fullDeptName;
|
private String fullDeptName;
|
||||||
|
|
||||||
private String language;
|
private String language;
|
||||||
|
|
||||||
|
private String sessionKey;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue