|
@@ -1,5 +1,7 @@
|
|
|
package com.uas.eis.service.Impl;
|
|
package com.uas.eis.service.Impl;
|
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.uas.eis.beans.result.Result;
|
|
import com.uas.eis.beans.result.Result;
|
|
|
import com.uas.eis.convertor.*;
|
|
import com.uas.eis.convertor.*;
|
|
|
import com.uas.eis.dao.BaseDao;
|
|
import com.uas.eis.dao.BaseDao;
|
|
@@ -9,18 +11,32 @@ import com.uas.eis.sdk.resp.*;
|
|
|
import com.uas.eis.service.RequestSTKService;
|
|
import com.uas.eis.service.RequestSTKService;
|
|
|
import com.uas.eis.service.STKService;
|
|
import com.uas.eis.service.STKService;
|
|
|
import com.uas.eis.utils.BaseUtil;
|
|
import com.uas.eis.utils.BaseUtil;
|
|
|
|
|
+import okhttp3.FormBody;
|
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
|
|
+import okhttp3.Request;
|
|
|
|
|
+import okhttp3.Response;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
|
+import org.springframework.web.client.HttpStatusCodeException;
|
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -36,6 +52,10 @@ public class STKServiceImpl implements STKService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RequestSTKService requestSTKService;
|
|
private RequestSTKService requestSTKService;
|
|
|
|
|
|
|
|
|
|
+ private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+
|
|
|
|
|
+ private final RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result getJobList(ProductPageDTO productPageDTO) {
|
|
public Result getJobList(ProductPageDTO productPageDTO) {
|
|
|
int pageNum = 1;
|
|
int pageNum = 1;
|
|
@@ -293,6 +313,73 @@ public class STKServiceImpl implements STKService {
|
|
|
return Result.success(map);
|
|
return Result.success(map);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 全局OkHttp客户端
|
|
|
|
|
+ private static final OkHttpClient client = new OkHttpClient.Builder()
|
|
|
|
|
+ .connectTimeout(10, TimeUnit.SECONDS)
|
|
|
|
|
+ .readTimeout(10, TimeUnit.SECONDS)
|
|
|
|
|
+ .writeTimeout(10, TimeUnit.SECONDS)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+// public String submitWorkDaily(Integer id, String caller, String cookie ,String URL) {
|
|
|
|
|
+// // 构造表单参数
|
|
|
|
|
+// FormBody formBody = new FormBody.Builder()
|
|
|
|
|
+// .add("id", String.valueOf(id))
|
|
|
|
|
+// .add("caller", caller)
|
|
|
|
|
+// .build();
|
|
|
|
|
+//
|
|
|
|
|
+// Request request = new Request.Builder()
|
|
|
|
|
+// .url(URL)
|
|
|
|
|
+// .header("Cookie",cookie)
|
|
|
|
|
+// .post(formBody)
|
|
|
|
|
+// .build();
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// try {
|
|
|
|
|
+// Response response = client.newCall(request).execute();
|
|
|
|
|
+// if (response.isSuccessful() && response.body() != null) {
|
|
|
|
|
+// return response.body().string();
|
|
|
|
|
+// }
|
|
|
|
|
+// return "请求失败,状态码:" + response.code();
|
|
|
|
|
+// } catch (HttpStatusCodeException e) {
|
|
|
|
|
+// // 第三方接口返回500/404/401都会进这里
|
|
|
|
|
+// logger.error("ERP接口异常,状态码:{},响应体:{}", e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
+// return "第三方服务异常:" + e.getResponseBodyAsString();
|
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
|
+// logger.error("本地调用发生未知异常", e);
|
|
|
|
|
+// return "本地代码异常:" + e.getMessage();
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ public String loginERP(String j_username, String j_password, String master, String URL) throws IOException {
|
|
|
|
|
+ // 构造表单参数
|
|
|
|
|
+ FormBody formBody = new FormBody.Builder()
|
|
|
|
|
+ .add("j_username", j_username)
|
|
|
|
|
+ .add("j_password", j_password)
|
|
|
|
|
+ .add("master", master)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(URL)
|
|
|
|
|
+ .post(formBody)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ try (Response response = client.newCall(request).execute()) {
|
|
|
|
|
+ if (response.isSuccessful() && response.body() != null) {
|
|
|
|
|
+ return response.body().string();
|
|
|
|
|
+ }
|
|
|
|
|
+// if (response.isSuccessful() && response.body() != null && response.headers() != null) {
|
|
|
|
|
+// String setCookies = response.headers().get("Set-Cookie");
|
|
|
|
|
+// if(setCookies != null && !"".equals(setCookies)){
|
|
|
|
|
+// return setCookies.substring(0,setCookies.indexOf(";"));
|
|
|
|
|
+// }else{
|
|
|
|
|
+// return response.body().string();
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ return "请求失败,状态码:" + response.code();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result createWorkDaily(WorkDailyDTO workDailyDTO) {
|
|
public Result createWorkDaily(WorkDailyDTO workDailyDTO) {
|
|
|
if(workDailyDTO == null) {
|
|
if(workDailyDTO == null) {
|
|
@@ -311,7 +398,68 @@ public class STKServiceImpl implements STKService {
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
map.put("id", id);
|
|
map.put("id", id);
|
|
|
map.put("code", code);
|
|
map.put("code", code);
|
|
|
- return Result.success(map);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ String LoginUrl="http://120.132.120.244:8099/ERP/api/pda/login.action";
|
|
|
|
|
+ String URL="http://120.132.120.244:8099/ERP/oa/persontask/submitWorkDaily.action";
|
|
|
|
|
+ String master="BT";
|
|
|
|
|
+ String caller="WorkDaily";
|
|
|
|
|
+ String empcode = workDailyDTO.getEmpcode();
|
|
|
|
|
+ Object em_password = baseDao.getFieldDataByCondition("employee", "em_password", "em_code='" + empcode + "'");
|
|
|
|
|
+
|
|
|
|
|
+ String j_username = null;
|
|
|
|
|
+ String j_password = null;
|
|
|
|
|
+ if(em_password != null){
|
|
|
|
|
+ j_username = empcode;
|
|
|
|
|
+ j_password = em_password.toString();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ map.put("message", "员工账号不正确!");
|
|
|
|
|
+ return Result.error(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ String JsonResponse = loginERP(j_username, j_password, master, LoginUrl);
|
|
|
|
|
+// String resultResponse = submitWorkDaily(id, caller, JsonResponse, URL);
|
|
|
|
|
+// map.put("id", id);
|
|
|
|
|
+// map.put("code", resultResponse);
|
|
|
|
|
+// return Result.success(map);
|
|
|
|
|
+ Map<String, Object> mapResponse = objectMapper.readValue(JsonResponse, new TypeReference<Map<String, Object>>() {});
|
|
|
|
|
+ if(mapResponse != null && mapResponse.get("sessionId")!=null){
|
|
|
|
|
+ String sessionId = mapResponse.get("sessionId").toString();
|
|
|
|
|
+ String cookie = "JSESSIONID="+sessionId;
|
|
|
|
|
+ String resultResponse = submitWorkDaily(id, caller, cookie, URL);
|
|
|
|
|
+ Map<String, Object> resultMapResponse = objectMapper.readValue(resultResponse, new TypeReference<Map<String, Object>>() {});
|
|
|
|
|
+
|
|
|
|
|
+ if(resultMapResponse != null && resultMapResponse.get("success") != null){
|
|
|
|
|
+ String success = resultMapResponse.get("success").toString();
|
|
|
|
|
+ if("true".equals(success)){
|
|
|
|
|
+ map.put("message", "对接成功!");
|
|
|
|
|
+ return Result.success(map);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return Result.error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if (resultMapResponse != null && resultMapResponse.get("exceptionInfo") != null){
|
|
|
|
|
+ map.put("message", resultMapResponse.get("exceptionInfo").toString());
|
|
|
|
|
+ return Result.error(map);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return Result.error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if(mapResponse != null && mapResponse.get("success") != null){
|
|
|
|
|
+ if("false".equals(mapResponse.get("success").toString())){
|
|
|
|
|
+ if(mapResponse.get("reason") != null) {
|
|
|
|
|
+ map.put("message", mapResponse.get("reason").toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.error(map);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return Result.error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.error();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ map.put("message", "人员登录异常!");
|
|
|
|
|
+ return Result.error(map);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -743,4 +891,28 @@ public class STKServiceImpl implements STKService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String submitWorkDaily(Integer id, String caller,String cookie , String URL) {
|
|
|
|
|
+ logger.info("请求ERP接口,id={},caller={}", id, caller);
|
|
|
|
|
+ MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
|
|
|
|
+ paramMap.add("id", String.valueOf(id));
|
|
|
|
|
+ paramMap.add("caller", caller);
|
|
|
|
|
+
|
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
|
|
+ headers.add("Cookie", cookie);
|
|
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(paramMap, headers);
|
|
|
|
|
+ try {
|
|
|
|
|
+ ResponseEntity<String> res = restTemplate.postForEntity(URL, request, String.class);
|
|
|
|
|
+ logger.info("ERP正常返回,code:{},body:{}", res.getStatusCode(), res.getBody());
|
|
|
|
|
+ return res.getBody();
|
|
|
|
|
+ } catch (HttpStatusCodeException e) {
|
|
|
|
|
+ // 第三方接口返回500/404/401都会进这里
|
|
|
|
|
+ logger.error("ERP接口异常,状态码:{},响应体:{}", e.getStatusCode(), e.getResponseBodyAsString(), e);
|
|
|
|
|
+ return e.getResponseBodyAsString();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("本地调用发生未知异常", e);
|
|
|
|
|
+ return "本地代码异常:" + e.getMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|