| | |
| | | package com.mes; |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.mes.bigstorage.entity.BigStorageCage; |
| | | import com.mes.bigstorage.service.BigStorageCageDetailsService; |
| | | import com.mes.bigstorage.service.BigStorageCageService; |
| | | import com.mes.common.config.Const; |
| | | import com.mes.damage.entity.Damage; |
| | | import com.mes.damage.service.DamageService; |
| | | import com.mes.edgglasstask.entity.EdgGlassTaskInfo; |
| | | import com.mes.edgglasstask.service.EdgGlassTaskInfoService; |
| | | import com.mes.job.PlcStorageCageTask; |
| | | import com.mes.pp.entity.ReportingWork; |
| | | import com.mes.pp.entity.ReportingWorkDetail; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author : zhoush |
| | |
| | | PlcStorageCageTask plcStorageCageTask; |
| | | @Autowired |
| | | BigStorageCageDetailsService bigStorageCageDetailsService; |
| | | @Autowired |
| | | DamageService damageService; |
| | | @Autowired |
| | | EdgGlassTaskInfoService edgGlassTaskInfoService; |
| | | |
| | | // @Autowired |
| | | // BigStorageCageFeedTaskMapper bigStorageCageFeedTaskMapper; |
| | | |
| | | @Test |
| | | public void testInsertSlot() { |
| | | List<BigStorageCage> list = new ArrayList(); |
| | | for (int j = 1; j <= 5; j++) { |
| | | for (int i = 1 + (55 * (j - 1)); i <= 55 * j; i++) { |
| | | BigStorageCage cage = new BigStorageCage(); |
| | | cage.setDeviceId(j); |
| | | cage.setSlot(i); |
| | | cage.setMinThickness(4); |
| | | cage.setMaxThickness(6); |
| | | cage.setEnableState(1); |
| | | cage.setRemainWidth(5000); |
| | | list.add(cage); |
| | | } |
| | | } |
| | | for (int i = 276; i <= 300; i++) { |
| | | BigStorageCage cage = new BigStorageCage(); |
| | | cage.setDeviceId(6); |
| | | cage.setSlot(i); |
| | | cage.setMinThickness(8); |
| | | cage.setMaxThickness(12); |
| | | cage.setEnableState(1); |
| | | cage.setRemainWidth(5000); |
| | | list.add(cage); |
| | | } |
| | | for (int i = 301; i <= 330; i++) { |
| | | BigStorageCage cage = new BigStorageCage(); |
| | | cage.setDeviceId(7); |
| | | cage.setSlot(i); |
| | | cage.setMinThickness(8); |
| | | cage.setMaxThickness(12); |
| | | cage.setEnableState(1); |
| | | cage.setRemainWidth(5000); |
| | | list.add(cage); |
| | | } |
| | | for (int i = 331; i <= 355; i++) { |
| | | BigStorageCage cage = new BigStorageCage(); |
| | | cage.setDeviceId(8); |
| | | cage.setSlot(i); |
| | | cage.setMinThickness(8); |
| | | cage.setMaxThickness(12); |
| | | cage.setEnableState(1); |
| | | cage.setRemainWidth(5000); |
| | | list.add(cage); |
| | | } |
| | | for (int i = 356; i <= 380; i++) { |
| | | BigStorageCage cage = new BigStorageCage(); |
| | | cage.setDeviceId(9); |
| | | cage.setSlot(i); |
| | | cage.setMinThickness(15); |
| | | cage.setMaxThickness(19); |
| | | cage.setEnableState(1); |
| | | cage.setRemainWidth(5000); |
| | | list.add(cage); |
| | | } |
| | | bigStorageCageService.saveBatch(list); |
| | | } |
| | | |
| | | @Test |
| | | public void testFindPath() { |
| | |
| | | |
| | | @Test |
| | | public void judgeGlassTypeStatus() { |
| | | plcStorageCageTask.judgeGlassTypeStatus("P24060403|6|7", Const.A09_OUT_TARGET_POSITION); |
| | | plcStorageCageTask.judgeGlassTypeStatus("P24060403|6|7", Const.A09_OUT_TARGET_POSITION, "mesD03Address"); |
| | | } |
| | | |
| | | @Test |
| | |
| | | log.info("获取大理片笼信息:{}", bigStorageCageDetailsService.selectBigStorageCageDetails("P24060403|3|6")); |
| | | } |
| | | |
| | | @Test |
| | | public void insertDamage() { |
| | | Damage damage=new Damage(); |
| | | damage.setGlassId("P24060403|3|6"); |
| | | damage.setLine(2001); |
| | | damage.setWorkingProcedure("磨边"); |
| | | damage.setRemark(""); |
| | | damage.setStatus(2); |
| | | damageService.insertDamage(damage); |
| | | } |
| | | |
| | | @Test |
| | | public void updateOutGlassStateTask() { |
| | | plcStorageCageTask.updateOutGlassStateTask(); |
| | | } |
| | | |
| | | @Test |
| | | public void chaxun(){ |
| | | List<EdgGlassTaskInfo> edgGlassTaskInfoList = edgGlassTaskInfoService.list(new QueryWrapper<EdgGlassTaskInfo>() |
| | | .select("Top 1 *") |
| | | .eq("glass_id", "P24072402|1|13") |
| | | ); |
| | | log.info("在尺寸表中获取玻璃信息{}", edgGlassTaskInfoList); |
| | | } |
| | | |
| | | @Test |
| | | public void ca(){ |
| | | try { |
| | | // 目标系统的API URL |
| | | String url = "http://192.168.3.119:8086/reportingWork/mesSaveReportingWorkWorn"; |
| | | URL obj = new URL(url); |
| | | HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
| | | |
| | | // 设置请求方法和请求头 |
| | | con.setRequestMethod("POST"); |
| | | con.setRequestProperty("Content-Type", "application/json; utf-8"); |
| | | con.setRequestProperty("Accept", "application/json"); |
| | | con.setDoOutput(true); |
| | | |
| | | // 创建 JSON 对象 |
| | | JSONObject result = new JSONObject(); |
| | | |
| | | ReportingWork reportingWork = new ReportingWork(); |
| | | reportingWork.setOrderId("NG24042301"); |
| | | reportingWork.setProductionId("NG24042301A"); |
| | | reportingWork.setProcessId("NG24042301A001"); |
| | | reportingWork.setDeviceName("磨边机"); |
| | | reportingWork.setThisProcess("切割"); |
| | | reportingWork.setNextProcess("磨边"); |
| | | reportingWork.setThisCompletedQuantity(1); |
| | | reportingWork.setThisWornQuantity(0); |
| | | reportingWork.setClasses("早班"); |
| | | reportingWork.setReportingWorkTime(LocalDateTime.now()); |
| | | reportingWork.setTeamsGroupsName("小廖一号"); |
| | | reportingWork.setCreator("小廖"); |
| | | |
| | | List<ReportingWorkDetail> reportingWorkDetails = new ArrayList<>(); |
| | | ReportingWorkDetail reportingWorkDetail = new ReportingWorkDetail(); |
| | | reportingWorkDetail.setTechnologyNumber(1); |
| | | reportingWorkDetail.setOrderNumber(1); |
| | | reportingWorkDetail.setCompletedQuantity(1); |
| | | reportingWorkDetail.setBreakageQuantity(0); |
| | | reportingWorkDetails.add(reportingWorkDetail); |
| | | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | // 将 ReportingWork 转换为 JSONObject |
| | | JSONObject reportingWorkJson = new JSONObject(objectMapper.writeValueAsString(reportingWork)); |
| | | reportingWorkJson.put("reportingWorkTime", reportingWork.getReportingWorkTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); |
| | | // 将 ReportingWorkDetail 列表转换为 JSONArray |
| | | JSONArray detailsJsonArray = new JSONArray(objectMapper.writeValueAsString(reportingWorkDetails)); |
| | | |
| | | // 将 JSON 对象和数组添加到结果对象中 |
| | | result.put("title", reportingWorkJson); |
| | | result.put("detail", detailsJsonArray); |
| | | result.put("type", 0); |
| | | result.put("userId", "admin"); |
| | | result.put("userName", "admin"); |
| | | result.put("qualityInsStatus", 0); |
| | | |
| | | // 将 result 对象转换为字符串 |
| | | String jsonInputString = result.toString(); |
| | | System.out.println("jsonInputString : " + result); |
| | | // 发送请求 |
| | | try (OutputStream os = con.getOutputStream()) { |
| | | byte[] input = jsonInputString.getBytes("utf-8"); |
| | | os.write(input, 0, input.length); |
| | | } |
| | | |
| | | // 获取响应码 |
| | | int responseCode = con.getResponseCode(); |
| | | System.out.println("Response Code : " + responseCode); |
| | | |
| | | // 获取响应内容 |
| | | try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) { |
| | | StringBuilder response = new StringBuilder(); |
| | | String inputLine; |
| | | while ((inputLine = in.readLine()) != null) { |
| | | response.append(inputLine); |
| | | } |
| | | System.out.println("Response Body: " + response.toString()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |