| | |
| | | package com.mes; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.mes.md.entity.*; |
| | | import com.mes.md.mapper.AccountMapper; |
| | | import com.mes.md.mapper.KBBTJPDrawingBPMapper; |
| | | import com.mes.md.mapper.MachineMapper; |
| | | import com.mes.md.mapper.PrimitiveTaskMapper; |
| | | import com.mes.md.service.AccountService; |
| | | import com.mes.md.service.PrimitiveTaskService; |
| | | import com.mes.md.service.ProjectService; |
| | | import com.mes.md.service.TaskingService; |
| | | import com.mes.tools.HexConversion; |
| | | import com.mes.utils.HexUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.io.DataInputStream; |
| | | import java.io.DataOutputStream; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.Socket; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @Author : yanzhixin |
| | |
| | | @Autowired |
| | | AccountService accountService; |
| | | |
| | | @Autowired |
| | | KBBTJPDrawingBPMapper kBBTJPDrawingBPMapper; |
| | | |
| | | @Autowired |
| | | PrimitiveTaskMapper primitiveTaskMapper; |
| | | |
| | | @Autowired |
| | | PrimitiveTaskService primitiveTaskService; |
| | | |
| | | @Autowired |
| | | TaskingService taskingService; |
| | | |
| | | |
| | | @Autowired |
| | | ProjectService projectService; |
| | | |
| | | @Autowired |
| | | MachineMapper machineMapper; |
| | | |
| | | @Test |
| | | public void testStr() { |
| | | String str=new String("4、发送任务 任务数据:{}, ".getBytes(),StandardCharsets.UTF_8); |
| | | int a=1; |
| | | log.info(str,1); |
| | | } |
| | | |
| | | @Test |
| | | public void testSaoMa3() { |
| | | try { |
| | | // 创建TCP客户端并连接到服务器 |
| | | String serverAddress = "192.168.1.8"; |
| | | int serverPort = 2001; |
| | | Socket clientSocket = new Socket(serverAddress, serverPort); |
| | | // 创建输入流和输出流 |
| | | InputStream inputStream = clientSocket.getInputStream(); |
| | | OutputStream outputStream = clientSocket.getOutputStream(); |
| | | // 发送数据给服务器 |
| | | String message = "start"; |
| | | outputStream.write(message.getBytes()); |
| | | // 读取服务器响应的数据 |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead = inputStream.read(buffer); |
| | | String receivedMessage = new String(buffer, 0, bytesRead); |
| | | System.out.println("收到服务器响应:" + receivedMessage); |
| | | // 关闭连接 |
| | | clientSocket.close(); |
| | | }catch (Exception e){ |
| | | log.info("扫码异常"); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void testSaoMa() { |
| | | try { |
| | | // 创建TCP客户端并连接到服务器 |
| | | String serverAddress = "192.168.1.8"; |
| | | int serverPort = 2001; |
| | | Socket clientSocket = new Socket(serverAddress, serverPort); |
| | | // 创建输入流和输出流 |
| | | InputStream inputStream = clientSocket.getInputStream(); |
| | | OutputStream outputStream = clientSocket.getOutputStream(); |
| | | // 发送数据给服务器 |
| | | String message = "start"; |
| | | outputStream.write(message.getBytes()); |
| | | // 读取服务器响应的数据 |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead = inputStream.read(buffer); |
| | | String receivedMessage = new String(buffer, 0, bytesRead); |
| | | System.out.println("收到服务器响应:" + receivedMessage); |
| | | // 发送数据给服务器 |
| | | String message2 = "stop"; |
| | | outputStream.write(message2.getBytes()); |
| | | |
| | | // 关闭连接 |
| | | clientSocket.close(); |
| | | }catch (Exception e){ |
| | | log.info("扫码异常"); |
| | | } |
| | | } |
| | | @Test |
| | | public void conncet(){ |
| | | try { |
| | | int bufSizes = 0; |
| | | byte[] msgs = new byte[2048]; |
| | | //创建连接 172.17.125.200 192.168.10.101 |
| | | Socket socket = new Socket("10.36.164.100", 1099); |
| | | try { |
| | | socket.setSoTimeout(3000); |
| | | //写入需要数据 |
| | | DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream()); |
| | | outToServer.write(HexUtil.stringToInt("000100000006010300000028")); |
| | | outToServer.flush(); |
| | | //读取数据 |
| | | DataInputStream in = new DataInputStream(socket.getInputStream()); |
| | | bufSizes = in.read(msgs); |
| | | String message = HexUtil.byteToHexString(bufSizes, msgs); |
| | | System.out.println(message); |
| | | } catch (Exception e) { |
| | | System.out.println("读取失败"); |
| | | try { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 |
| | | } catch (Exception e2) { |
| | | // TODO: handle exception |
| | | |
| | | } |
| | | } |
| | | socket.close(); |
| | | } catch (Exception e) { |
| | | System.out.println("异常"); |
| | | } |
| | | } |
| | | @Test |
| | | public void testFindPath() { |
| | | //String url = getClass().getResource("").getPath(); |
| | |
| | | log.info("完整路径"); |
| | | } |
| | | @Test |
| | | public void testByte() { |
| | | //String url = getClass().getResource("").getPath(); |
| | | //log.info("完整路径:{}", Arrays.asList(url)); |
| | | byte[] msgs = new byte[2048]; |
| | | msgs[0]=(byte)0; |
| | | msgs[1]=Byte.parseByte("1") ; |
| | | int g=HexConversion.bytesToInt(msgs,0); |
| | | |
| | | String message = HexConversion.byteToHexString(4, msgs); |
| | | byte font=msgs[1]; |
| | | String[] fontBit=String.format("%8s", Integer.toBinaryString((int)font)).replace(" ", "0").split(""); |
| | | byte[] bit=new byte[1]; |
| | | bit[0]=Byte.parseByte(fontBit[7]) ; |
| | | log.info("结果:{},{}",fontBit,bit); |
| | | //log.info("结果:{},{},{},{},{}",msgs,message,g,(msgs[0] & 0xFF),((msgs[1] & 0xFF)<<8)); |
| | | } |
| | | @Test |
| | | public void testFindAccount() { |
| | | Map<String, Object> Account=accountService.selectAccount("admin","12345"); |
| | | Map<String, Object> Account=accountService.selectAccount("beibo","57858555"); |
| | | if(Account.isEmpty()){ |
| | | System.out.println("成功"); |
| | | } |
| | | log.info("{}",Account); |
| | | } |
| | | |
| | | //连接客户表 |
| | | @Test |
| | | public void testInput() { |
| | | Machine machine=machineMapper.selectById(14); |
| | | taskingService.scanMachineAdd(machine, "46594135"); |
| | | log.info("内容{}",2); |
| | | } |
| | | |
| | | //连接客户表 |
| | | @Test |
| | | public void testSqlServerInput() { |
| | | |
| | | boolean is=projectService.insertProjectStandard(); |
| | | |
| | | |
| | | log.info("内容{}",is); |
| | | } |
| | | //连接客户表 |
| | | @Test |
| | | public void testMachineFinsh() { |
| | | Machine machine=machineMapper.selectById(14); |
| | | int a=taskingService.finishMachineTask(machine); |
| | | log.info("内容{}",a); |
| | | } |
| | | //定制查找任务 |
| | | @Test |
| | | public void testSqlServer() { |
| | | Machine machine=machineMapper.selectById(26); |
| | | String scan_id=""; |
| | | List<Tasking> taskingList=taskingService.findMachineTask(machine); |
| | | if(!taskingList.isEmpty()){ |
| | | Tasking tasking=taskingList.get(0); |
| | | if (scan_id.equals(tasking.getScanId())){ |
| | | |
| | | }else{ |
| | | List<Tasking> isExist=taskingService.findMachineTaskID(machine,scan_id); |
| | | if(isExist.isEmpty()){ |
| | | //读取客户数据库 |
| | | projectService.insertProjectCustomization(scan_id); |
| | | } |
| | | } |
| | | } |
| | | // insertProjectCustomization(); |
| | | log.info("内容{}",taskingList); |
| | | } |
| | | |
| | | //定制查找任务 |
| | | @Test |
| | | public void testSqlServeraa() { |
| | | Machine machine=machineMapper.selectById(12); |
| | | String scan_id="46399819"; |
| | | projectService.insertProjectCustomization(scan_id); |
| | | log.info("内容{}",machine); |
| | | } |
| | | //修改客户表 |
| | | @Test |
| | | public void testSqlServerUpdate() { |
| | | UpdateWrapper updateWrapper=new UpdateWrapper(); |
| | | KBBTJPDrawingBP kBBTJPDrawingBPs=new KBBTJPDrawingBP(); |
| | | kBBTJPDrawingBPMapper.update(kBBTJPDrawingBPs,updateWrapper); |
| | | List<KBBTJPDrawingBP> kBBTJPDrawingBP=kBBTJPDrawingBPMapper.selectJoinList(KBBTJPDrawingBP.class,new MPJLambdaWrapper<KBBTJPDrawingBP>() |
| | | .selectAll(KBBTJPDrawingBP.class) |
| | | .eq(KBBTJPDrawingBP::getScanId,"011045108661010000") |
| | | .orderByAsc(KBBTJPDrawingBP::getCreateDate) |
| | | .orderByAsc(KBBTJPDrawingBP::getTaskSequence)); |
| | | kBBTJPDrawingBP.get(0).setIsWorking(1); |
| | | kBBTJPDrawingBPMapper.updateById(kBBTJPDrawingBP.get(0)); |
| | | //kBBTJPDrawingBPMapper.update(kBBTJPDrawingBP,new QueryWrapper<>()); |
| | | // log.info("内容{}",KBBTJPDrawingBP); |
| | | } |
| | | |
| | | //修改客户表 |
| | | @Test |
| | | public void testSqlServerUpdate2() { |
| | | UpdateWrapper<KBBTJPDrawingBP> updateWrapper=new UpdateWrapper<KBBTJPDrawingBP>(); |
| | | updateWrapper.lambda().eq(KBBTJPDrawingBP::getScanId,"011045108661010000"); |
| | | |
| | | KBBTJPDrawingBP kBBTJPDrawingBPs=new KBBTJPDrawingBP(); |
| | | kBBTJPDrawingBPs.setIsWorking(2); |
| | | kBBTJPDrawingBPMapper.update(kBBTJPDrawingBPs,updateWrapper); |
| | | |
| | | // log.info("内容{}",KBBTJPDrawingBP); |
| | | } |
| | | |
| | | |
| | | |
| | | } |