大屏看板控制类增加接口
This commit is contained in:
parent
83149a73e7
commit
e8da7060c9
|
|
@ -3,19 +3,37 @@ package com.nflg.mobilebroken.admin.controller;
|
|||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.nflg.mobilebroken.admin.service.ITranslate;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.request.TranslateWordRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.request.KanBanGasketStandardInfoRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.request.KanBanQueryStatementRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.request.KanBanScheduleInfoRequest;
|
||||
import com.nflg.mobilebroken.common.pojo.request.KanBanThresholdInfoRequest;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
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.message.BasicHeader;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -24,37 +42,185 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("/kanban")
|
||||
public class KanbanController extends ControllerBase{
|
||||
|
||||
public static final String KANBAN_URL = "http://47.94.198.125:5555/zhonglv/";
|
||||
private static OkHttpClient okHttpClient;
|
||||
private static int timeout = 80;
|
||||
/**
|
||||
* 初始化数据
|
||||
* @param
|
||||
* @return 翻译结果
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("initialize")
|
||||
public ApiResult<String> initialize(){
|
||||
JSONArray array=new JSONArray();
|
||||
String initdata1=httpOfGet("http://47.94.198.125:5555/zhonglv/initdata1","type","initworktime");
|
||||
String initdata1=HttpOfGet(KANBAN_URL+"initdata1","type","initworktime");
|
||||
JSONObject jsonObject = JSONUtil.parseObj(initdata1);
|
||||
array.add(jsonObject);
|
||||
String initdata2=httpOfGet("http://47.94.198.125:5555/zhonglv/initdata1","type","initstandard");
|
||||
String initdata2=HttpOfGet(KANBAN_URL+"initdata1","type","initstandard");
|
||||
JSONObject jsonObject2 = JSONUtil.parseObj(initdata2);
|
||||
array.add(jsonObject2);
|
||||
String getdata1=httpOfGet("http://47.94.198.125:5555/zhonglv/getdata1","type","alarm");
|
||||
String getdata1=HttpOfGet(KANBAN_URL+"getdata1","type","alarm");
|
||||
JSONObject jsonObject3 = JSONUtil.parseObj(getdata1);
|
||||
array.add(jsonObject3);
|
||||
String getdata2=httpOfGet("http://47.94.198.125:5555/zhonglv/getdata1","type","device");
|
||||
String getdata2=HttpOfGet(KANBAN_URL+"getdata1","type","device");
|
||||
JSONObject jsonObject4 = JSONUtil.parseObj(getdata2);
|
||||
array.add(jsonObject4);
|
||||
String getdata3=httpOfGet("http://47.94.198.125:5555/zhonglv/getdata1","type","chart");
|
||||
String getdata3=HttpOfGet(KANBAN_URL+"getdata1","type","chart");
|
||||
JSONObject jsonObject5 = JSONUtil.parseObj(getdata3);
|
||||
array.add(jsonObject5);
|
||||
String getdata4=httpOfGet("http://47.94.198.125:5555/zhonglv/getdata1","type","other");
|
||||
String getdata4=HttpOfGet(KANBAN_URL+"getdata1","type","other");
|
||||
JSONObject jsonObject6 = JSONUtil.parseObj(getdata4);
|
||||
array.add(jsonObject6);
|
||||
return ApiResult.success(jsonObject6.toString());
|
||||
}
|
||||
|
||||
public static String httpOfGet(String url, String paramName, String paramValue){
|
||||
/**
|
||||
* 班次设置保存接口
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("saveSchedule")
|
||||
public ApiResult<String> saveSchedule(@Valid @RequestBody KanBanScheduleInfoRequest request) throws Exception {
|
||||
Map<String,Object> map=objectToMap(request);
|
||||
/* map.put("work1startime","00:00");
|
||||
map.put("work1endtime","23:30");
|
||||
map.put("work2startime","00:00");
|
||||
map.put("work2endtime","23:30");
|
||||
map.put("work3startime","00:00");
|
||||
map.put("work3endtime","23:30");
|
||||
map.put("work1planproduce","300");
|
||||
map.put("work2planproduce","300");
|
||||
map.put("work3planproduce","00");*/
|
||||
String result=doPostFormData(KANBAN_URL+"saveworktime1/",map).body().string();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
if(jsonObject.get("status").equals("success")){
|
||||
return ApiResult.success("success");
|
||||
}else{
|
||||
return ApiResult.error(jsonObject.get("message").toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 阈值参数设置保存接口
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("saveThreshold")
|
||||
public ApiResult<String> saveThreshold(@Valid @RequestBody KanBanThresholdInfoRequest request) throws Exception {
|
||||
Map<String, Object> map=objectToMap(request);
|
||||
/* map.put("screen_P80_threshold","6.3");
|
||||
map.put("screen_P100_threshold","6.9");
|
||||
map.put("mid_input_F100_threshold","6.9");
|
||||
map.put("mid_output_P100_threshold","25");
|
||||
map.put("mid_output_P50_threshold","10");
|
||||
map.put("mid_passing_threshold","98");
|
||||
map.put("fine_input_F100_threshold","20");
|
||||
map.put("fine_output_P100_threshold","10");
|
||||
map.put("fine_output_P50_threshold","12");
|
||||
map.put("fine_passing_threshold","56");
|
||||
map.put("mid_dutyRatio_min","99");
|
||||
map.put("mid_dutyRatio_max","100");
|
||||
map.put("fine_dutyRatio_min","1");
|
||||
map.put("fine_dutyRatio_max","88");
|
||||
map.put("mid_P80_min","5");
|
||||
map.put("mid_P80_max","55");*/
|
||||
String result=doPostFormData(KANBAN_URL+"savestandard1/",map).body().string();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
if(jsonObject.get("status").equals("success")){
|
||||
return ApiResult.success("success");
|
||||
}else{
|
||||
return ApiResult.error(jsonObject.get("message").toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 报表查询接口
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("queryStatement")
|
||||
public ApiResult<String> queryStatement(@Valid @RequestBody KanBanQueryStatementRequest request) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(DateTimeToStr(request.getStartTime()));
|
||||
jsonArray.put(DateTimeToStr(request.getEndTime()));
|
||||
String result=HttpOfPost(KANBAN_URL+"statement1/",jsonArray.toString());
|
||||
if(null!=result){
|
||||
return ApiResult.success(result);
|
||||
}
|
||||
return ApiResult.error("查询出错");
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数标定接口
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("saveGasketStandard")
|
||||
public ApiResult<String> saveGasketStandard(@Valid @RequestBody KanBanGasketStandardInfoRequest request) throws Exception {
|
||||
Map<String, Object> map=objectToMap(request);
|
||||
/* map.put("mid_gasket_startime","2026-01-05 08:57");
|
||||
map.put("mid_gasket_endtime","2026-01-05 10:57");
|
||||
map.put("mid_gasket_abrasion","1");
|
||||
map.put("fine1_gasket_startime","2026-01-05 08:57");
|
||||
map.put("fine1_gasket_endtime","2026-01-05 10:57");
|
||||
map.put("fine1_gasket_abrasion","1");
|
||||
map.put("fine2_gasket_startime","2026-01-05 08:57");
|
||||
map.put("fine2_gasket_endtime","2026-01-05 10:57");
|
||||
map.put("fine2_gasket_abrasion","1");
|
||||
map.put("mid_ratedPower","1");
|
||||
map.put("fine1_ratedPower","1");
|
||||
map.put("fine2_ratedPower","1");*/
|
||||
String result=doPostFormData(KANBAN_URL+"save_gasketstandard1/",map).body().string();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||
if(jsonObject.get("status").equals("success")){
|
||||
return ApiResult.success("success");
|
||||
}else{
|
||||
return ApiResult.error(jsonObject.get("message").toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String DateTimeToStr(LocalDateTime localDateTime ){
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneOffset.UTC);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
return zonedDateTime.format(formatter);
|
||||
}
|
||||
|
||||
|
||||
public static String HttpOfPost(String url, String jsonArray){
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
try {
|
||||
// 创建JSON字符串实体
|
||||
StringEntity entity = new StringEntity(jsonArray);
|
||||
httpPost.setEntity(entity);
|
||||
httpPost.setHeader("Accept", "application/json");
|
||||
httpPost.setHeader("Content-type", "application/json");
|
||||
|
||||
// 发送请求并获取响应
|
||||
CloseableHttpResponse response = client.execute(httpPost);
|
||||
try {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
if (responseEntity != null) {
|
||||
return EntityUtils.toString(responseEntity);
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
client.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String HttpOfGet(String url, String paramName, String paramValue){
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
try {
|
||||
HttpGet request = new HttpGet(url);
|
||||
|
|
@ -64,8 +230,6 @@ public class KanbanController extends ControllerBase{
|
|||
request.addHeader(new BasicHeader(paramName, paramValue));
|
||||
CloseableHttpResponse response = httpClient.execute(request);
|
||||
try {
|
||||
//int statusCode = response.getStatusLine().getStatusCode();
|
||||
// 获取响应体内容
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
return responseBody;
|
||||
} finally {
|
||||
|
|
@ -82,4 +246,69 @@ public class KanbanController extends ControllerBase{
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* form-data表单请求
|
||||
*
|
||||
* @param url URL地址
|
||||
* @param map 参数
|
||||
* @return Response
|
||||
* @throws IOException e
|
||||
*/
|
||||
public static Response doPostFormData(String url, Map<String, Object> map) throws Exception {
|
||||
okhttp3.RequestBody requestBody = buildRequestBody(map);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header("Content-Type", "multipart/form-data")
|
||||
.post(requestBody)
|
||||
.build();
|
||||
|
||||
return getOkHttpClient().newCall(request).execute();
|
||||
}
|
||||
/**
|
||||
* 获取对象
|
||||
*
|
||||
* @return OkHttpClient
|
||||
*/
|
||||
private static 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;
|
||||
}
|
||||
/**
|
||||
* 构建键值对表单
|
||||
*
|
||||
* @param map 参数
|
||||
* @return RequestBody
|
||||
*/
|
||||
private static okhttp3.RequestBody buildRequestBody(Map<String, Object> map) {
|
||||
FormBody.Builder builder = new FormBody.Builder(StandardCharsets.UTF_8);
|
||||
if (map != null && map.size() > 0) {
|
||||
for (String string : map.keySet()) {
|
||||
builder.add(string, (String) map.get(string));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
|
||||
return Arrays.stream(fields)
|
||||
.peek(field -> field.setAccessible(true))
|
||||
.collect(Collectors.toMap(Field::getName, field -> {
|
||||
try {
|
||||
return field.get(obj);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.nflg.mobilebroken.common.pojo.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class KanBanGasketStandardInfoRequest {
|
||||
|
||||
private String mid_gasket_startime;
|
||||
private String mid_gasket_endtime;
|
||||
private String mid_gasket_abrasion;
|
||||
private String fine1_gasket_startime;
|
||||
private String fine1_gasket_endtime;
|
||||
private String fine1_gasket_abrasion;
|
||||
private String fine2_gasket_startime;
|
||||
private String fine2_gasket_endtime;
|
||||
private String fine2_gasket_abrasion;
|
||||
private String mid_ratedPower;
|
||||
private String fine1_ratedPower;
|
||||
private String fine2_ratedPower;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.nflg.mobilebroken.common.pojo.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Data
|
||||
public class KanBanQueryStatementRequest {
|
||||
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.nflg.mobilebroken.common.pojo.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
public class KanBanScheduleInfoRequest {
|
||||
|
||||
private String work1startime;
|
||||
private String work1endtime;
|
||||
private String work2startime;
|
||||
private String work2endtime;
|
||||
private String work3startime;
|
||||
private String work3endtime;
|
||||
private String work1planproduce;
|
||||
private String work2planproduce;
|
||||
private String work3planproduce;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.nflg.mobilebroken.common.pojo.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class KanBanThresholdInfoRequest {
|
||||
|
||||
private String screen_P80_threshold;
|
||||
private String screen_P100_threshold;
|
||||
private String mid_input_F100_threshold;
|
||||
private String mid_output_P100_threshold;
|
||||
private String mid_output_P50_threshold;
|
||||
private String mid_passing_threshold;
|
||||
private String fine_input_F100_threshold;
|
||||
private String fine_output_P100_threshold;
|
||||
private String fine_output_P50_threshold;
|
||||
private String fine_passing_threshold;
|
||||
private String mid_dutyRatio_min;
|
||||
private String mid_dutyRatio_max;
|
||||
private String fine_dutyRatio_min;
|
||||
private String fine_dutyRatio_max;
|
||||
private String mid_P80_min;
|
||||
private String mid_P80_max;
|
||||
}
|
||||
Loading…
Reference in New Issue