Merge pull request '更新代码' (#20) from Huatao_branch into master

Fanyiwen_branch
meickrq7f 3 years ago
commit e92f251c39

@ -47,7 +47,11 @@
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<version>3.141.59</version> <version>3.141.59</version>
</dependency> </dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>
<profile> <profile>

@ -2,9 +2,10 @@ package com.example.testdemo;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication @SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
public class ServerApplication { public class ServerApplication {
public static void main(String[] args) { public static void main(String[] args) {
@ -12,7 +13,6 @@ public class ServerApplication {
SpringApplication.run(ServerApplication.class, args); SpringApplication.run(ServerApplication.class, args);
} }
} }

@ -0,0 +1,53 @@
package com.example.testdemo.entity;
public class Good {
private int id;
private String phoneNum;
private int shelfNum;
private int floorNum;
private String time;
public Good(){
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getPhoneNum(){
return phoneNum;
}
public void setPhoneNum(String phoneNum){
this.phoneNum = phoneNum;
}
public int getShelfNum(){
return shelfNum;
}
public void setShelfNum(int shelfNum){
this.shelfNum = shelfNum;
}
public int getFloorNum(){
return floorNum;
}
public void setFloorNum(int floorNum){
this.floorNum = floorNum;
}
public String getTime(){
return time;
}
public void setTime(String time){
this.time = time;
}
}

@ -0,0 +1,46 @@
package com.example.testdemo.entity;
public class Operation {
private int id;
private String pickUpCode;
private String phoneNum;
private String time;
public Operation(){
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getPickUpCode(){
return pickUpCode;
}
public void setPickUpCode(String PickUpCode){
this.pickUpCode = PickUpCode;
}
public String getPhoneNum(){
return phoneNum;
}
public void setPhoneNum(String PhoneNum){
this.phoneNum = PhoneNum;
}
public String getTime(){
return time;
}
public void setTime(String time){
this.time = time;
}
}

@ -0,0 +1,16 @@
package com.example.testdemo.manager;
import com.example.testdemo.entity.Good;
import org.springframework.stereotype.Repository;
import java.util.List;
@org.apache.ibatis.annotations.Mapper
@Repository
public interface GoodManager {
List<Good> queryGoodsById(int id);
List<Good> queryGoodsByPhonenum(String phonenum);
void delete(int id);
}

@ -1,25 +1,22 @@
package com.example.testdemo.config; package com.example.testdemo.manager;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import jdk.nashorn.internal.scripts.JS; import com.example.testdemo.entity.Good;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import sun.rmi.runtime.Log;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.websocket.*; import javax.websocket.*;
import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpoint;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -27,16 +24,17 @@ import java.util.concurrent.atomic.AtomicInteger;
@Slf4j @Slf4j
@ServerEndpoint("/result") @ServerEndpoint("/result")
@Component @Component
public class SendObjectMessage { public class MessageManager {
@Autowired
private GoodManager gmanager;
private static String TAG = "SendObjectMessage"; private static String TAG = "SendObjectMessage";
private static AtomicInteger onlineCount = new AtomicInteger(0); private static AtomicInteger onlineCount = new AtomicInteger(0);
private static ConcurrentLinkedQueue<SendObjectMessage> socket = new ConcurrentLinkedQueue<SendObjectMessage>(); private static ConcurrentLinkedQueue<MessageManager> socket = new ConcurrentLinkedQueue<MessageManager>();
private Session session; private Session session;
private SendObjectMessage mObject = null; private MessageManager mObject = null;
@OnOpen @OnOpen
public void onOpen(Session session) { public void onOpen(Session session) {
@ -79,7 +77,6 @@ public class SendObjectMessage {
String op = js.getString("op"); String op = js.getString("op");
if(op.equals("connect")){ if(op.equals("connect")){
log.info(TAG, "connect"); log.info(TAG, "connect");
JSONObject content = js.getJSONObject("content"); JSONObject content = js.getJSONObject("content");
String user = content.getString("user"); String user = content.getString("user");
@ -96,8 +93,9 @@ public class SendObjectMessage {
if(con.equals("yes")){ if(con.equals("yes")){
try { try {
log.info(TAG, "testSelenium1"); log.info(TAG, "testSelenium");
testSelenium1();
testSelenium();
} catch (Exception e) { } catch (Exception e) {
@ -142,7 +140,7 @@ public class SendObjectMessage {
} }
public static void testSelenium1() throws Exception { public static void testSelenium() throws Exception {//打开浏览器调用js文件
// 使用HtmlUnitDriver 是不需要 安装 浏览器 和 驱动支持\ // 使用HtmlUnitDriver 是不需要 安装 浏览器 和 驱动支持\
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
@ -176,4 +174,20 @@ public class SendObjectMessage {
return script.toString();//返回读取的文件流 return script.toString();//返回读取的文件流
} }
public void queryGoodsById(int id){
List<Good> goodsList = gmanager.queryGoodsById(id);
for(Good g:goodsList){
System.out.println(g);
}
}
public void queryGoodsByPhonenum(String phonenum){
List<Good> goodsList = gmanager.queryGoodsByPhonenum(phonenum);
for(Good g:goodsList) {
System.out.println(g);
}
}
} }

@ -0,0 +1,18 @@
package com.example.testdemo.manager;
import com.example.testdemo.entity.Operation;
import jdk.nashorn.internal.runtime.OptimisticReturnFilters;
import org.springframework.stereotype.Repository;
import java.util.List;
@org.apache.ibatis.annotations.Mapper
@Repository
public interface OperationManager {
void addOperation(String pickupcode, String phonenum, String time);
List<Operation> queryOperationsByPhone(String phonenum);
}

@ -1,4 +1,4 @@
package com.example.testdemo.config; package com.example.testdemo.manager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

@ -14,5 +14,3 @@ spring:
prefix: prefix:
classpath: /template classpath: /template
cache: false cache: false

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.testdemo.manager.GoodManager">
<select id="queryGoodsById" resultType="Good" parameterType="int">
select * from goods where id = #{id};
</select>
<delete id="deleteGoods" parameterType="int">
delete from goods where id = #{id};
</delete>
<select id="queryGoodsByPhone" resultType="Good" parameterType="String">
select * from goods where phonenum = #{phonenum};
</select>
</mapper>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.testdemo.manager.OperationManager">
<insert id = "addOperation" parameterType="String">
insert into operations(pickupcode, phonenum, time) values (#{pickupcode},#{phonenum},#{time})})
</insert>
<select id="queryOperationsByPhone" resultType="Operation" parameterType="String">
select * from goods where id = #{phonenum};
</select>
</mapper>

@ -10,6 +10,7 @@
// Connecting to ROS // Connecting to ROS
// ----------------- // -----------------
var ros = new ROSLIB.Ros({ var ros = new ROSLIB.Ros({
url : 'ws://192.168.43.20:9090' url : 'ws://192.168.43.20:9090'
}); });
@ -25,29 +26,64 @@
ros.on('close', function() { ros.on('close', function() {
console.log('Connection to websocket server closed.'); console.log('Connection to websocket server closed.');
}); });
var move_base= new ROSLIB.ActionClient({
// Publishing a Topic
// ------------------
var cmdVel = new ROSLIB.Topic({
ros : ros, ros : ros,
name : '/cmd_vel', serverName : '/move_base',
messageType : 'geometry_msgs/Twist' actionName : 'move_base_msgs/MoveBaseAction'
}); });
var twist = new ROSLIB.Message({ var currentTime = new Date();
linear : { var secs = Math.floor(currentTime.getTime()/1000)
x : 0.1, var nsecs = Math.round(1000000000*(currentTime.getTime()/1000-secs))
y : 0.2,
z : 0.3 var goal = new ROSLIB.Goal({
actionClient: move_base,
goalMessage:{
target_pose:{
header:{
frame_id:'map',
stamp:{
secs: secs,
nsecs:nsecs
}
},
pose:{
position:{
x:-3.97, //-0.743 -0.0273 取件点
y:1.68, //3.00 -0.09
z:0.000
}, },
angular : { orientation:{
x : -0.1, x:0.000,
y : -0.2, y:0.000,
z : -0.3 z:0.000,
w:1.000
}
} }
}
}
});
goal.on('feedback', function(feedback) {
console.log('Feedback: ' + feedback.sequence);
}); });
cmdVel.publish(twist);
goal.on('result', function(result) {
console.log('Final Result: ' + result.sequence);
});
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
goal.send();
</script> </script>
</head> </head>

@ -1,97 +0,0 @@
// document.write('<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>\n');
// document.write('<script type="text/javascript" src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>\n');
var ros = new ROSLIB.Ros({
url : 'ws://192.168.43.20:9090'
});
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
var move_base= new ROSLIB.ActionClient({
ros : ros,
serverName : '/move_base',
actionName : 'move_base_msgs/MoveBaseAction'
});
var currentTime = new Date();
var secs = Math.floor(currentTime.getTime()/1000)
var nsecs = Math.round(1000000000*(currentTime.getTime()/1000-secs))
var goal = new ROSLIB.Goal({
actionClient: move_base,
goalMessage:{
target_pose:{
header:{
frame_id:'map',
stamp:{
secs: secs,
nsecs:nsecs
}
},
pose:{
position:{
x:-3.97, //-0.743 -0.0273 取件点
y:1.68, //3.00 -0.09
z:0.000
},
orientation:{
x:0.000,
y:0.000,
z:0.000,
w:1.000
}
}
}
}
});
goal.on('feedback', function(feedback) {
console.log('Feedback: ' + feedback.sequence);
});
goal.on('result', function(result) {
console.log('Final Result: ' + result.sequence);
});
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
goal.send();
var cmdVel = new ROSLIB.Topic({
ros : ros,
name : '/cmd_vel',
messageType : 'geometry_msgs/Twist'
});
var twist = new ROSLIB.Message({
linear : {
x : 0.1,
y : 0.2,
z : 0.3
},
angular : {
x : -0.1,
y : -0.2,
z : -0.3
}
});
//cmdVel.publish(twist);
Loading…
Cancel
Save