Commit dbe9f1ff authored by tank.li@mushiny.com's avatar tank.li@mushiny.com

南沙WCS版本临时存储地址

parent ed563f66
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mushiny</groupId> <artifactId>wcs-server</artifactId> <version>v8</version> <packaging>jar</packaging> <name>wcs</name> <description>热度计算</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Dalston.SR1</spring-cloud.version> <docker.image.prefix>wms-wcs-service</docker.image.prefix> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!--spring stream--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency> <!--连接池--> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.19</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.9.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> <version>1.4.5.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.2.6.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.1.1</version> </dependency> <!--动态反射--> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!--分布式锁--> <!-- redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- redisson--> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>3.3.2</version> </dependency> <!--分布式锁结束--> <!--web mvc--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.3.10.RELEASE</version> </dependency> <!--webmvc--> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.10</version> </dependency> </dependencies> <!--管理--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
\ No newline at end of file
FROM java:openjdk-8-jre-alpine
VOLUME /tmp
ADD wcs-1.0.jar wcs-1.0.jar
RUN sh -c 'touch /wcs-1.0.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/wcs-1.0.jar"]
package com.mushiny;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableScheduling
@EnableTransactionManagement
public class WcsApplication {
public static void main(String[] args) {
SpringApplication.run(WcsApplication.class, args);
}
}
package com.mushiny.astar;
import java.util.*;
/**
* Created by Tank.li on 2017/7/4.
*/
public class AStar {
//步长单位
private static final int STEP = 1;
/**
* 当前运算用的地图
*/
private Map<NodeKey,Node> currMap;
public Map<NodeKey, Node> getCurrMap() {
return currMap;
}
public void setCurrMap(Map<NodeKey, Node> currMap) {
this.currMap = currMap;
}
private List<Node> closeList = new ArrayList<>();
private List<Node> openList = new ArrayList<>();
public Node findPath(Node startNode, Node endNode) {
// 把起点增加 open list
startNode = currMap.get(new NodeKey(startNode.getX(),startNode.getY()));
endNode = currMap.get(new NodeKey(endNode.getX(),endNode.getY()));
openList.add(startNode);
while (openList.size() > 0) {
// 遍历 open list 。查找 F值最小的节点,把它作为当前要处理的节点
Node currentNode = findMinFNodeInOpneList();
// 从open list中移除
openList.remove(currentNode);
// 把这个节点移到 close list
closeList.add(currentNode);
ArrayList<Node> neighborNodes = findNeighborNodes(currentNode);
for (Node node : neighborNodes) {
if (exists(openList, node)) {
foundPoint(currentNode, node);
} else {
notFoundPoint(currentNode, endNode, node);
}
}
if (find(openList, endNode) != null) {
return find(openList, endNode);
}
}
return find(openList, endNode);
}
public ArrayList<Node> findNeighborNodes(Node currentNode) {
//ArrayList<Node> arrayList = new ArrayList<Node>();
// 仅仅考虑上下左右,不考虑斜对角
ArrayList<Node> list = new ArrayList<>();
Iterator<Node> iter = currentNode.getNodes().keySet().iterator();
while (iter.hasNext()) {
Node next = iter.next();
if(!closeList.contains(next)){
list.add(next);
}
}
return list;
}
public Node findMinFNodeInOpneList() {
Node tempNode = openList.get(0);
for (Node node : openList) {
if (node.getF() < tempNode.getF()) {
tempNode = node;
}
}
return tempNode;
}
private void foundPoint(Node tempStart, Node node) {
int G = calcG(tempStart, node);
if (G < node.getG()) {
node.setParentNode(tempStart);
node.setG(G);
node.calcF();
}
}
private void notFoundPoint(Node tempStart, Node end, Node node) {
node.setParentNode(tempStart);
node.setG(calcG(tempStart, node));
node.setH(calcH(end, node)); ;
node.calcF();
openList.add(node);
}
private int calcG(Node start, Node node) {
int G = STEP;
int parentG = node.getParentNode() != null ? node.getParentNode().getG() : 1;
return G + parentG;
}
private int calcH(Node end, Node node) {
int step = Math.abs(node.getX() - end.getX()) + Math.abs(node.getY() - end.getY());
return step * STEP;
}
public static Node find(List<Node> nodes, Node point) {
for (Node n : nodes)
if ((n.getX() == point.getX()) && (n.getY() == point.getY())) {
return n;
}
return null;
}
public static boolean exists(List<Node> nodes, Node node) {
for (Node n : nodes) {
if ((n.getX() == node.getX()) && (n.getY() == node.getY())) {
return true;
}
}
return false;
}
public static void main(String[] args) {
Map<NodeKey, Node> map = new HashMap<>();
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
NodeKey nodeKey = new NodeKey(i+1,j+1);
Node node = new Node();
node.setX(i+1);
node.setY(j+1);
node.setG(1);
map.put(nodeKey,node);
}
}
Iterator<Node> iter = map.values().iterator();
while (iter.hasNext()) {
Node curr = iter.next();
Map<Node, Integer> nextNodes = new HashMap<>();
Iterator<Node> iter2 = map.values().iterator();
while (iter2.hasNext()) {
Node node = iter2.next();
if(isNext(node,curr)){
nextNodes.put(node,100);
}
}
curr.setNodes(nextNodes);
}
AStar aStar = new AStar();
aStar.setCurrMap(map);
Node start = new Node();
start.setY(3);
start.setX(3);
Node end = new Node();
end.setY(98);
end.setX(100);
long startTime = System.currentTimeMillis();
Node nodeEnd = aStar.findPath(start,end);
System.out.println("===>"+(System.currentTimeMillis() - startTime));
while (nodeEnd.getParentNode()!=null){
System.out.println(nodeEnd.toString());
nodeEnd = nodeEnd.getParentNode();
}
}
private static boolean isNext(Node node, Node curr) {
//只有四个 相邻的
return (Math.abs(node.getX()-curr.getX())==1 && (node.getY()==curr.getY()))
||(Math.abs(node.getY()-curr.getY())==1 && (node.getX()==curr.getX()));
}
}
package com.mushiny.astar;
import java.util.Map;
/**
* Created by Tank.li on 2017/7/4.
*/
public class Node implements java.io.Serializable{
private String nodeId;
public String getNodeId() {
return nodeId;
}
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
private Node parentNode;//用于回溯
private int f;
private int g;
private int h;
private int x;
private int y;
private Map<Node,Integer> nodes;//用于初始化和计算 key是node value是cost值
public Node getParentNode() {
return parentNode;
}
public void setParentNode(Node parentNode) {
this.parentNode = parentNode;
}
public int getF() {
return f;
}
public void setF(int f) {
this.f = f;
}
public int getG() {
return g;
}
public void setG(int g) {
this.g = g;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Map<Node, Integer> getNodes() {
return nodes;
}
public void setNodes(Map<Node, Integer> nodes) {
this.nodes = nodes;
}
public void calcF() {
this.f = this.g + this.h;
}
@Override
public String toString() {
return "Node{" +
"x=" + x +
", y=" + y +
'}';
}
}
package com.mushiny.astar;
/**
* Created by Tank.li on 2017/7/4.
*/
public class NodeKey implements java.io.Serializable{
private int x;
private int y;
public NodeKey(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeKey nodeKey = (NodeKey) o;
if (x != nodeKey.x) return false;
return y == nodeKey.y;
}
@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}
package com.mushiny.astar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Tank.li on 2017/7/4.
*/
public class WareHouseMap implements java.io.Serializable{
//地图ID 可能分多个地图
private int id;
//地图名字
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//基本地图给空车跑路用 临时锁格、小车故障、格子不可用等
private Map<NodeKey,Node> basicMap = new HashMap<>();
//工作地图状态随时会变化,驮货车的路线(Cost值不同)、临时锁格、小车故障、格子不可用等也要考虑
private Map<NodeKey,Node> workMap = new HashMap<>();
public Node getBasicNode(NodeKey nodeId){
return basicMap.get(nodeId);
}
public Node getWorkNode(NodeKey nodeId){
return workMap.get(nodeId);
}
public void putBasicNode(NodeKey nodeId,Node node){
basicMap.put(nodeId,node);
}
public void putWorkNode(NodeKey nodeId,Node node){
workMap.put(nodeId,node);
}
public List<Node> getBasicPath(NodeKey nodeKeyA, NodeKey nodeKeyB) {
Node nodeA = basicMap.get(nodeKeyA);
return null;
}
}
package com.mushiny.astar;
import java.util.List;
/**
* Created by Tank.li on 2017/7/4.
*/
public class WareHouseMapManager {
private WareHouseMap wareHouseMap;
public WareHouseMap getWareHouseMap() {
return wareHouseMap;
}
public void setWareHouseMap(WareHouseMap wareHouseMap) {
this.wareHouseMap = wareHouseMap;
}
public WareHouseMapManager(WareHouseMap wareHouseMap) {
this.wareHouseMap = wareHouseMap;
}
/**
* 获取基本路径 给空车使用
* @param x1 起点的x轴
* @param y1 起点的y轴
* @param x2 终点的x轴
* @param y2 终点的y轴
* @return
*/
public List<Node> getBasicPath(int x1,int y1, int x2,int y2){
NodeKey nodeKey1 = new NodeKey(x1,y1);
NodeKey nodeKey2 = new NodeKey(x2,y2);
return this.getWareHouseMap().getBasicPath(nodeKey1,nodeKey2);
}
}
package com.mushiny.beans;
import com.mushiny.beans.enums.AddressStatus;
import com.mushiny.business.WareHouseManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
/**
* Created by Tank.li on 2017/6/26.
*/
public class Address extends BaseObject {
//当前位置的货架 pod 和 车 robot
private Pod pod;
private Robot robot;
public Pod getPod() {
return pod;
}
public void setPod(Pod pod) {
this.pod = pod;
}
public Robot getRobot() {
return robot;
}
public void setRobot(Robot robot) {
this.robot = robot;
}
private long lockedBy;//被哪个小车锁定,在返回存储区时锁定
public long getLockedBy() {
return lockedBy;
}
public void setLockedBy(long lockedBy) {
this.lockedBy = lockedBy;
}
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
private String pkId;
public String getPkId() {
return pkId;
}
public void setPkId(String pkId) {
this.pkId = pkId;
}
private String classValue;
private String classDir;
public String getClassValue() {
return classValue;
}
public void setClassValue(String classValue) {
this.classValue = classValue;
}
public String getClassDir() {
return classDir;
}
public void setClassDir(String classDir) {
this.classDir = classDir;
}
private AddressGroup addressGroup;//所属组 可以是空的
public AddressGroup getAddressGroup() {
return addressGroup;
}
public void setAddressGroup(AddressGroup addressGroup) {
this.addressGroup = addressGroup;
}
private Address groupOutterAddr;//指向同组外部
private Address groupInnerAddr;//指向同组内部
public Address getGroupOutterAddr() {
return groupOutterAddr;
}
public void setGroupOutterAddr(Address groupOutterAddr) {
this.groupOutterAddr = groupOutterAddr;
}
public Address getGroupInnerAddr() {
return groupInnerAddr;
}
public void setGroupInnerAddr(Address groupInnerAddr) {
this.groupInnerAddr = groupInnerAddr;
}
private String id;//ADDRESSCODEID
private String sectionId;
public String getSectionId() {
return sectionId;
}
public void setSectionId(String sectionId) {
this.sectionId = sectionId;
}
private int xPosition;//地标位置
private int yPosition;//地标位置
public static final String TABLE = "WD_NODE";
@Override
public String getTable() {
return TABLE;
}
public static final String IDNAME = "ADDRESSCODEID";
@Override
public String getIdName() {
return IDNAME;
}
public Address(int x, int y) {
this.xPosition = x;
this.yPosition = y;
}
public Address() {
}
//相对得分值
private double score;
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
//距离热度 zc 跟最近工位的常量距离,仓库生成后一般不会变动
private int hot;
public int getHot() {
return hot;
}
public void setHot(int hot) {
this.hot = hot;
}
private String nodeState;//格子状态 Available/Reserved/Occupied/Unavailable
private String wareHouseId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getxPosition() {
return xPosition;
}
public void setxPosition(int xPosition) {
this.xPosition = xPosition;
}
public int getyPosition() {
return yPosition;
}
public void setyPosition(int yPosition) {
this.yPosition = yPosition;
}
public String getNodeState() {
return nodeState;
}
private final static Logger logger = LoggerFactory.getLogger(Address.class);
public void setNodeState(String nodeState) {
logger.debug("设置地址格Address["+this.getId()+"]状态是:"+nodeState);
if(!Objects.equals(this.nodeState, nodeState)){
this.addKV("NODE_STATE", nodeState);
}
this.nodeState = nodeState;
}
public String getWareHouseId() {
return wareHouseId;
}
public void setWareHouseId(String wareHouseId) {
this.wareHouseId = wareHouseId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();;
if (this.getAddressGroup() != null) {
AddressGroup addressGroup = this.getAddressGroup();
List<Address> addresses = addressGroup.getGroupAddrs();
sb.append("[");
for (int i = 0; i < addresses.size(); i++) {
Address address = addresses.get(i);
if (i < addresses.size() - 1) {
sb.append(address.getId()).append(",");
} else {
sb.append(address.getId());
}
}
sb.append("]");
}
return "Address{" +
"id='" + id + '\'' +
", addressGroup=" + sb +
", AddressType=" + this.getType() +
", lockedBy=" + lockedBy +
", pod=" + (pod == null ? "" : pod.getPodName()) +
", robot=" + (robot == null ? "" : robot.getRobotId()) +
", nodeState='" + nodeState + '\'' +
'}';
}
@Override
public boolean equals(Object obj) {
if(obj==null){
return false;
}
Address addr = (Address) obj;
return Objects.equals(this.getId(),addr.getId());
}
/**
* 锁定解锁格子只能同步试试
* @param robotId 当前车
* @param lock_unlock 锁定或解锁
* @return
*/
public synchronized boolean robotLock(long robotId, boolean lock_unlock) {
if (lock_unlock) {
logger.info("小车"+robotId+"锁定目标 lockedBy "+this.getLockedBy()+"NodeState "+this.getNodeState());
if ((this.getLockedBy()==robotId || this.getLockedBy()==0)){
this.setLockedBy(robotId);
this.setNodeState(AddressStatus.RESERVED);
logger.info("小车"+robotId+"锁定目标:"+this.getId()+"成功!");
return true;
}
logger.error("小车"+robotId+"锁定目标:"+this.getId()+"失败!");
return false;
} else {
if ((this.getLockedBy()==robotId) || this.getLockedBy() == 0L){
this.setLockedBy(0L);
this.setNodeState(AddressStatus.AVALIABLE);
logger.info("小车"+robotId+"解锁目标:"+this.getId()+"成功!");
return true;
}
logger.error("小车"+robotId+"解锁目标:"+this.getId()+"失败,被其他车 "+this.getLockedBy()+" 锁定!");
return false;
}
}
}
package com.mushiny.beans;
import com.mushiny.beans.enums.AddressStatus;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Tank.li on 2017/8/17.
*/
public class AddressGroup implements java.io.Serializable{
private String groupId;
//只定义最内和最外两个节点 ,两个节点间可能存在无数个中间节点
private Address innerAddr;
private Address outterAddr;
public String getGroupId() {
return groupId;
}
public AddressGroup(String groupId) {
this.groupId = groupId;
}
//从外到内的列表
public List<Address> getGroupAddrs(){
List<Address> list = new ArrayList<>();
Address node = this.getOutterAddr();
while (node!=null){
list.add(node);
node=node.getGroupInnerAddr();
}
return list;
}
/**
* 这组成员从该节点往外的所有节点
* @param address
* @return
*/
public List<Address> getOutterAddrs(Address address){
List<Address> list = new ArrayList<>();
Address node = address.getGroupOutterAddr();
while (node!=null){
list.add(node);
node=node.getGroupOutterAddr();
}
return list;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public Address getInnerAddr() {
return innerAddr;
}
public void setInnerAddr(Address innerAddr) {
this.innerAddr = innerAddr;
}
public Address getOutterAddr() {
return outterAddr;
}
public void setOutterAddr(Address outterAddr) {
this.outterAddr = outterAddr;
}
}
package com.mushiny.beans;
import java.util.Objects;
/**
* Created by Tank.li on 2017/10/17.
*/
public class BaseBpo extends BaseObject {
//操作类型 TODO
public static final int INSERT = 1;
public static final int UPDATE = 2;
public static final int DELETE = 3;
private int operType = INSERT;
public int getOperType() {
return operType;
}
public void setOperType(int operType) {
this.operType = operType;
}
private Object Id;
private String table;
private String idName;
@Override
public Object getId() {
return Id;
}
public void setId(Object id) {
Id = id;
}
@Override
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
@Override
public String getIdName() {
return idName;
}
public void setIdName(String idName) {
this.idName = idName;
}
}
package com.mushiny.beans;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Tank.li on 2017/7/25.
*/
public abstract class BaseObject implements java.io.Serializable{
private String activeThread;//activeThread
public String getActiveThread() {
return activeThread;
}
public void setActiveThread(String activeThread) {
this.activeThread = activeThread;
}
private Map<String,Object> kv = new ConcurrentHashMap<>();
private Map<String,Object> con;
private Map<String,Object> delCon;//删除条件
public Map<String, Object> getDelCon() {
return delCon;
}
public void setDelCon(Map<String, Object> delCon) {
this.delCon = delCon;
}
public Map<String, Object> getCon() {
return con;
}
public void setCon(Map<String, Object> con) {
this.con = con;
}
public Map getNewValue(){
return kv;
}
public Map<String, Object> getKv() {
return kv;
}
public void setKv(Map<String, Object> kv) {
this.kv = kv;
}
/**
* 做多次操作
* @param key
* @param value
* @return
*/
public BaseObject addKV(String key, Object value){
if(key == null || value == null){
return this;
}
kv.put(key,value);
return this;
}
public void clearKV(){
kv.clear();
}
public abstract Object getId();
public abstract String getTable();
public abstract String getIdName();
}
package com.mushiny.beans;
/**
* Created by Tank.li on 2017/8/7.
*/
public class Charger extends BaseObject{
public static final String TABLE_NAME="MD_CHARGER";
public static final String ID_NAME="ID";
/*statusIndex:1, 2, 3, 4
statusName:充电, 空闲, 离线, 故障*/
public static final int CHARGING = 1;
public static final int IDLE = 2;
public static final int OFFLINE = 3;
public static final int ERROR = 4;
private String chargerId;
private String addressCodeId;
private int direct;
private String name;
private String state;
private String wareHouseId;
private String sectionId;
//美的的charger包含Mac地址
private String mac;
private String chargerAddr;//充电桩实际地址
private Integer rcsChargerId;
private Integer chargerType;
public String getChargerAddr() {
return chargerAddr;
}
public void setChargerAddr(String chargerAddr) {
this.chargerAddr = chargerAddr;
}
public String getMac() {
return mac;
}
public void setMac(String mac) {
this.mac = mac;
}
public Integer getRcsChargerId() {
return rcsChargerId;
}
public void setRcsChargerId(Integer rcsChargerId) {
this.rcsChargerId = rcsChargerId;
}
public Integer getChargerType() {
return chargerType;
}
public void setChargerType(Integer chargerType) {
this.chargerType = chargerType;
}
public String getWareHouseId() {
return wareHouseId;
}
public void setWareHouseId(String wareHouseId) {
this.wareHouseId = wareHouseId;
}
public String getSectionId() {
return sectionId;
}
public void setSectionId(String sectionId) {
this.sectionId = sectionId;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getChargerId() {
return chargerId;
}
public void setChargerId(String chargerId) {
this.chargerId = chargerId;
}
public String getAddressCodeId() {
return addressCodeId;
}
public void setAddressCodeId(String addressCodeId) {
this.addressCodeId = addressCodeId;
}
public int getDirect() {
return direct;
}
public void setDirect(int direct) {
this.direct = direct;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public Object getId() {
return this.getChargerId();
}
@Override
public String getTable() {
return TABLE_NAME;
}
@Override
public String getIdName() {
return ID_NAME;
}
@Override
public String toString() {
return "chargerId:"+chargerId+" ,chargerName:"+name+" ,rcsChargerId:"+rcsChargerId+" ,chargerType:"+chargerType+" ,chargerState:"+state;
}
}
package com.mushiny.beans;
/**
* Created by Tank.li on 2017/6/26.
*/
public class Item implements java.io.Serializable{
private String itemId;
private String itemName;
private int amount;
private String uniType;
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getUniType() {
return uniType;
}
public void setUniType(String uniType) {
this.uniType = uniType;
}
@Override
public String toString() {
return "Item{" +
"itemId='" + itemId + '\'' +
", itemName='" + itemName + '\'' +
", amount=" + amount +
", uniType='" + uniType + '\'' +
'}';
}
}
package com.mushiny.beans;
import com.mushiny.beans.enums.AddressStatus;
import com.mushiny.beans.enums.AddressType;
import com.mushiny.beans.order.Order;
import com.mushiny.beans.order.StationPodOrder;
import com.mushiny.business.RobotManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* 计算热度使用的Pod对象 跟数据库存储没关系
* Created by Tank.li on 2017/6/25.
*/
public class Pod extends BaseObject{
private final static Logger logger = LoggerFactory.getLogger(Pod.class);
private String podId;
private String podName;
private Long rcsPodId;//RCS扫码出来的POD
private long lockedBy;//被哪个小车锁定,在初始化时锁定
public long getLockedBy() {
return lockedBy;
}
public void setLockedBy(long lockedBy) {
this.lockedBy = lockedBy;
}
//pod绑定的Robot 在收到实时包时更新
private Robot robot;
/*POD朝向 角度*/
private int direct;
//private String addressId;
private String sectionId;
private String wareHouseId;
private String clientId;
//最终可能要去的位置排序 如果被占用就取下一个
private List<Address> favorAddrs;
private double hot = 0.0;
//排序后换成Z值的HOT,跟位置一起排序算得
private int zHot = 0;
//pod当前位置
private Address address;
//pod当前移动的目标位置,一旦调度单生成目的地后,会更新POD的目标位置==调度单的目标位置
private String movTargetAddrId;
private Set<PodPosition> podPositions;
private Address ideaTarget;
private int isNewCreated;
public void setIsNewCreated(int isNewCreated) {
this.isNewCreated = isNewCreated;
}
public int getIsNewCreated() {
return isNewCreated;
}
public Long getRcsPodId() {
return rcsPodId;
}
public void setRcsPodId(Long rcsPodId) {
this.rcsPodId = rcsPodId;
}
public String getMovTargetAddrId() {
return movTargetAddrId;
}
public void setMovTargetAddrId(String movTargetAddrId) {
this.movTargetAddrId = movTargetAddrId;
}
public Robot getRobot() {
return robot;
}
public void setRobot(Robot robot) {
this.robot = robot;
}
public int getDirect() {
return direct;
}
public void setDirect(int direct) {
this.direct = direct;
}
public String getSectionId() {
return sectionId;
}
public void setSectionId(String sectionId) {
this.sectionId = sectionId;
}
public List<Address> getFavorAddrs() {
return favorAddrs;
}
public void setFavorAddrs(List<Address> favorAddrs) {
this.favorAddrs = favorAddrs;
}
public Address getIdeaTarget() {
return ideaTarget;
}
public void setIdeaTarget(Address ideaTarget) {
this.ideaTarget = ideaTarget;
}
public int getzHot() {
return zHot;
}
public void setzHot(int zHot) {
this.zHot = zHot;
}
public double getHot() {
return hot;
}
public void setHot(double hot) {
this.hot = hot;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
logger.debug("设置POD位置:"+address);
if (this.address != null) {
this.address.setPod(null);
logger.error("setAddress:this.address:"+this.address);
}
this.address = address;
}
public String getPodId() {
return podId;
}
public void setPodId(String podId) {
this.podId = podId;
}
public String getPodName() {
return podName;
}
public void setPodName(String podName) {
this.podName = podName;
}
/*public String getId() {
return addressId;
}
public void setId(String addressId) {
this.addressId = addressId;
}*/
public String getWareHouseId() {
return wareHouseId;
}
public void setWareHouseId(String wareHouseId) {
this.wareHouseId = wareHouseId;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public Set<PodPosition> getPodPositions() {
return podPositions;
}
public void setPodPositions(Set<PodPosition> podPositions) {
this.podPositions = podPositions;
}
@Override
public Object getId() {
return this.podId;
}
public static final String TABLE = "MD_POD";
@Override
public String getTable() {
return TABLE;
}
public static final String IDNAME = "ID";
@Override
public String getIdName() {
return IDNAME;
}
@Override
public String toString() {
return "Pod{" +
"podName='" + podName + '\'' +
", rcsPodId=" + rcsPodId +
", lockedBy=" + lockedBy +
", robot=" + (robot==null? "":robot.getRobotId()) +
", direct=" + direct +
", isNewCreated=" + isNewCreated +
//", sectionId='" + sectionId + '\'' +
", address=" + (address==null? "":address.getId()+":"+address.getNodeState()) +
//", \n 热度: favorAddrs=" + favorAddrs +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pod pod = (Pod) o;
if (direct != pod.direct) return false;
return podId.equals(pod.podId);
}
@Override
public int hashCode() {
int result = podId.hashCode();
result = 31 * result + direct;
return result;
}
/**
* 同步锁定POD
* @param order
* @return
*/
public synchronized boolean lockPod(Order order) {
Long robotId = order.getRobot().getRobotId();
//已经被其他车锁定
if(lockedBy!= 0 && lockedBy != robotId){
return false;
}
//锁定该POD
this.lockedBy = robotId;
return true;
}
}
package com.mushiny.beans;
import java.util.Set;
/**
* Created by Tank.li on 2017/6/25.
*/
public class PodCell implements java.io.Serializable {
private String cellId;
private String podPositionId;
private String podCellName;
private Set<Item> items;
public String getCellId() {
return cellId;
}
public void setCellId(String cellId) {
this.cellId = cellId;
}
public String getPodPositionId() {
return podPositionId;
}
public void setPodPositionId(String podPositionId) {
this.podPositionId = podPositionId;
}
public String getPodCellName() {
return podCellName;
}
public void setPodCellName(String podCellName) {
this.podCellName = podCellName;
}
public Set<Item> getItems() {
return items;
}
public void setItems(Set<Item> items) {
this.items = items;
}
}
package com.mushiny.beans;
import java.util.List;
import java.util.Set;
/**
* Created by Tank.li on 2017/6/25.
*/
public class PodPosition {
private String podPositionId;
private String podPositionName;
private String position;//四个面A B C D
private String podId;
private Set<PodCell> podCells;
public String getPodPositionId() {
return podPositionId;
}
public void setPodPositionId(String podPositionId) {
this.podPositionId = podPositionId;
}
public String getPodPositionName() {
return podPositionName;
}
public void setPodPositionName(String podPositionName) {
this.podPositionName = podPositionName;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getPodId() {
return podId;
}
public void setPodId(String podId) {
this.podId = podId;
}
public Set<PodCell> getPodCells() {
return podCells;
}
public void setPodCells(Set<PodCell> podCells) {
this.podCells = podCells;
}
}
This diff is collapsed.
package com.mushiny.beans;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Objects;
/**
* Created by Tank.li on 2017/7/22.
*/
public class RobotStatusChangeListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
Object oldValue = evt.getOldValue();
Object newValue = evt.getNewValue();
Robot robot = (Robot) evt.getSource();
if("status".equals(propertyName)){
Integer oldStatus = (Integer) oldValue;
Integer newStatus = (Integer) newValue;
if(!Objects.equals(oldStatus, newStatus)){
robot.setPersistFlag(true);//确实发生变化 需要持久到数据库
}
}
//更新地址
if("addressId".equals(propertyName)){
String oldAddress = (String) oldValue;
String newAddress = (String) newValue;
if(!Objects.equals(oldAddress,newAddress)){
robot.setPersistFlag(true);//确实发生变化 需要持久到数据库
}
}
//更新pod pod属性的变化指 朝向、id (换了个POD 或者转了个面)
if("pod".equals(propertyName)){
Pod oldPod = (Pod) oldValue;
Pod newPod = (Pod) newValue;
if(!Objects.equals(oldPod,newPod)){
robot.setPersistFlag(true);//确实发生变化 需要持久到数据库
}
}
}
/*因为报文和状态都是一坨,所以拆不开 统一主动commit*/
private final static Logger logger = LoggerFactory.getLogger(RobotStatusChangeListener.class);
/**
* 更新机器人状态
* @param robot
* @param oldStatus
* @param newStatus
*/
public void updateStatus(Robot robot, Integer oldStatus, Integer newStatus) {
robot.addKV("oldStatus",oldStatus);
robot.addKV("status",newStatus);
logger.debug("小车Robot_id"+robot.getRobotId()+"状态更新结束,status:"+oldStatus+"==>"+newStatus);
}
/**
* 更新小车地址 保险起见 把xy坐标更新了
* @param robot
* @param oldAddress
* @param newAddress
*/
public void updateAddress(Robot robot, String oldAddress, String newAddress) {
robot.addKV("OLDADDRCODEID",oldAddress);
robot.addKV("ADDRESSCODEID",newAddress);
logger.debug("小车Robot_id"+robot.getRobotId()+"位置更新结束,address:"+oldAddress+"==>"+newAddress);
}
/**
* 更新POD
* @param robot
* @param oldPod
* @param newPod
*/
public void updatePod(Robot robot, Pod oldPod, Pod newPod) {
String oldPodId = oldPod==null? null:oldPod.getPodId();
String newPodId = newPod==null? null:newPod.getPodId();
robot.addKV("pod_id",newPodId);
logger.debug("小车Robot_id"+robot.getRobotId()+"状态更新结束,pod_id:"+oldPodId+"==>"+newPodId);
}
}
package com.mushiny.beans;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Tank.li on 2017/7/20.
*/
public class Section implements java.io.Serializable{
private String activeMapId;
public String getActiveMapId() {
return activeMapId;
}
public void setActiveMapId(String activeMapId) {
this.activeMapId = activeMapId;
}
private String section_id;
private String section_name;
private String wareHouse_id;
private long rcs_sectionId;
public Map<String,AddressGroup> addressGroupMap = new HashMap<>();
/**
* 当前section的调度单组 key是小车的robot_id
*/
private List<Address> storageAddrs;
public List<Address> getStorageAddrs() {
return storageAddrs;
}
public void setStorageAddrs(List<Address> storageAddrs) {
this.storageAddrs = storageAddrs;
}
//所有的格子列表
public List<Address> addressList = new ArrayList<>();
//所有格子索引
public Map<String,Address> addressMap = new ConcurrentHashMap<>();
//所有充电桩的地址 key是chargerId
public Map<String,Charger> chargers = new ConcurrentHashMap<>();
//所有工作站
public Map<String,WorkStation> workStationMap = new ConcurrentHashMap<>();
//自动移动扫描的位置
public Map<Address,WorkStation> scanPoionts = new ConcurrentHashMap<>();
//工位工作停止点
public Map<Address, WorkStation> stopPoionts = new ConcurrentHashMap<>();
//POD回程缓冲点
public Map<Address, WorkStation> bufferPoionts = new ConcurrentHashMap<>();
public long getRcs_sectionId() {
return rcs_sectionId;
}
public void setRcs_sectionId(long rcs_sectionId) {
this.rcs_sectionId = rcs_sectionId;
}
public String getSection_name() {
return section_name;
}
public void setSection_name(String section_name) {
this.section_name = section_name;
}
public String getSection_id() {
return section_id;
}
public void setSection_id(String section_id) {
this.section_id = section_id;
}
public String getWareHouse_id() {
return wareHouse_id;
}
public void setWareHouse_id(String wareHouse_id) {
this.wareHouse_id = wareHouse_id;
}
@Override
public String toString() {
return "Section{" +
"section_id='" + section_id + '\'' +
", section_name='" + section_name + '\'' +
'}';
}
}
package com.mushiny.beans;
/**
* Created by Tank.li on 2017/7/20.
*/
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 仓库对象 一个系统初始化可能包含多个仓库
*/
public class WareHouse implements java.io.Serializable {
private String wareHouseId;
private String wareHouseName;
public Map<String,Section> sectionMap = new ConcurrentHashMap<>();
public String getWareHouseId() {
return wareHouseId;
}
public void setWareHouseId(String wareHouseId) {
this.wareHouseId = wareHouseId;
}
public String getWareHouseName() {
return wareHouseName;
}
public void setWareHouseName(String wareHouseName) {
this.wareHouseName = wareHouseName;
}
}
package com.mushiny.beans;
import com.mushiny.beans.order.Order;
import com.mushiny.comm.JsonUtils;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicLong;
/**
* Created by Tank.li on 2017/6/26.
*/
public class WorkStation {
public AtomicLong inAddr1 = new AtomicLong();//旋转区入口1计数器
public AtomicLong inAddr2 = new AtomicLong();//旋转区入口2计数器
//public Queue<Pod> podQueue = new LinkedList<>();//排队的POD
/*private Pod onScanPod;
private Pod onMidPod;
private Pod onStopPod;*/
/*public Pod getOnScanPod() {
return onScanPod;
}
public void setOnScanPod(Pod onScanPod) {
this.onScanPod = onScanPod;
}*/
/*public Pod getOnMidPod() {
return onMidPod;
}
public void setOnMidPod(Pod onMidPod) {
this.onMidPod = onMidPod;
}*/
/*public Pod getOnStopPod() {
return onStopPod;
}
public void setOnStopPod(Pod onStopPod) {
this.onStopPod = onStopPod;
}*/
private String workStationId;
private String wareHouseId;
private String sectionId;
private String rotatePoint;
public String getRotatePoint() {
return rotatePoint;
}
public void setRotatePoint(String rotatePoint) {
this.rotatePoint = rotatePoint;
}
private String scanPoint;
//STOP点是工作站的计算点
private String stopPoint;
private String bufferPoint;
private String midPoint;//扫描点和停止点中间那个
public String getMidPoint() {
return midPoint;
}
public void setMidPoint(String midPoint) {
this.midPoint = midPoint;
}
//旋转区外部入口
public List<String> rotateOutInAddrs = new ArrayList<>();
//旋转区从工作站方向入口
private String station2RotateAddr;
private int face;//工作站朝向
public String getSectionId() {
return sectionId;
}
public void setSectionId(String sectionId) {
this.sectionId = sectionId;
}
public int getFace() {
return face;
}
public void setFace(int face) {
this.face = face;
}
public String getStation2RotateAddr() {
return station2RotateAddr;
}
public void setStation2RotateAddr(String station2RotateAddr) {
this.station2RotateAddr = station2RotateAddr;
}
//旋转区出口
private String rotateInOutAddr;
public String getRotateInOutAddr() {
return rotateInOutAddr;
}
public void setRotateInOutAddr(String rotateInOutAddr) {
this.rotateInOutAddr = rotateInOutAddr;
}
public String getScanPoint() {
return scanPoint;
}
public void setScanPoint(String scanPoint) {
this.scanPoint = scanPoint;
}
public String getStopPoint() {
return stopPoint;
}
public void setStopPoint(String stopPoint) {
this.stopPoint = stopPoint;
}
public String getBufferPoint() {
return bufferPoint;
}
public void setBufferPoint(String bufferPoint) {
this.bufferPoint = bufferPoint;
}
public String getWorkStationId() {
return workStationId;
}
public void setWorkStationId(String workStationId) {
this.workStationId = workStationId;
}
public String getWareHouseId() {
return wareHouseId;
}
public void setWareHouseId(String wareHouseId) {
this.wareHouseId = wareHouseId;
}
@Override
public String toString() {
return "WorkStation{" +
", workStationId='" + workStationId + '\'' +
", inAddrs='" + JsonUtils.list2Json(rotateOutInAddrs) + '\'' +
", rotateInOutAddr='" + rotateInOutAddr + '\'' +
", rotatePoint='" + rotatePoint + '\'' +
", scanPoint='" + scanPoint + '\'' +
", stopPoint='" + stopPoint + '\'' +
", bufferPoint='" + bufferPoint + '\'' +
", midPoint='" + midPoint + '\'' +
", face=" + face +
'}';
}
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/8/19.
*/
public class AddressStatus {
public static final String AVALIABLE = "Available";
public static final String OCCUPIED = "Occupied";
public static final String RESERVED = "Reserved";
public static final String UNAVAILABLE = "Unavailable";
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/9/11.
*/
public class AddressType {
public static final int STORAGE = 1;
public static final int LINE = 8;
public static final int ROBOTPARK = 7;
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/11/6.
*/
public class ChargerStatus {
public static final String CHARGING = "Charging";
public static final String ERROR = "Error";
public static final String AVAILABLE = "Available";
public static final String OFFLINE = "Offline";
}
package com.mushiny.beans.enums;
import com.mushiny.beans.order.Order;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Tank.li on 2017/11/7.
*/
public class OrderErrorMessage {
private static Map<Integer,String> errorMsg = new HashMap();
static {
/*public static final int ERROR_POD_NONEEDFACE = 7; //TRIPPOSITION表记录没有需要的面
public static final int ERROR_POD_ONPATH = 8; //重车路径的存储位上有POD
public static final int ERROR_NO_HOTADDRESS = 9; //热度计算没有可用的存储位
public static final int ERROR_NOPOD = 10; //调度单没有POD
public static final int SUCCESS = 0;
public static final int ERROR_EMPTY_PATH = 1;//空车路径计算失败!
public static final int ERROR_HEAVY_PATH = 2;//重车路径计算失败!
public static final int ERROR_START_POINT = 3;//小车不在路径起始位置
public static final int NO_END_POINT = 4;//没有终点位置
public static final int ERROR_ENDPOINT_NOTMATCH = 11;//终点位置不是路径最后一个节点
public static final int ERROR_NO_WCSPATH = 5;//没有下发的路径 长度是0或1
public static final int ERROR_POD = 6;//没有扫到POD 或者POD错误 被使用*/
errorMsg.put(Order.ERROR_POD_NONEEDFACE,"7:TRIPPOSITION表记录没有需要的面");
errorMsg.put(Order.ERROR_POD_ONPATH,"8:重车路径的存储位上有POD");
errorMsg.put(Order.ERROR_NO_HOTADDRESS,"9:热度计算没有可用的存储位");
errorMsg.put(Order.ERROR_NOPOD,"10:调度单没有POD");
errorMsg.put(Order.ERROR_EMPTY_PATH,"1:空车路径计算失败");
errorMsg.put(Order.ERROR_HEAVY_PATH,"2:重车路径计算失败");
errorMsg.put(Order.ERROR_START_POINT,"3:小车不在路径起始位置");
errorMsg.put(Order.NO_END_POINT,"4:没有终点位置");
errorMsg.put(Order.ERROR_ENDPOINT_NOTMATCH,"11:终点位置不是路径最后一个节点");
errorMsg.put(Order.ERROR_NO_WCSPATH,"5:没有下发的路径 长度是0或1");
errorMsg.put(Order.ERROR_POD,"6:没有扫到POD 或者POD错误 被使用");
errorMsg.put(Order.ERROR_POD_NOTINMAP,"66:货架没有地址");
errorMsg.put(Order.ERROR_CHARGE_WITHPOD,"驮着货架充电");
errorMsg.put(Order.ERROR_NOCHARGER,"充电桩不存在!");
errorMsg.put(Order.ERROR_LOCK_ENDADDR,"20:终点地址锁定失败");
}
public static String getMsg(Integer key){
return errorMsg.get(key);
}
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/8/18.
*/
public enum OrderPositionStatus {
Available("Available"),
Process("Process"),
Not_Finished("Not_Finish"),
Finished("Finish");
private String type;
OrderPositionStatus(String type) {
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/9/2.
*/
public class PodStatus {
public static final String RESERVED = "Reserved";
public static final String AVAILABLE = "Available";
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/8/18.
*/
public class TripStatus {
public static final String AVAILABLE = "Available"; //可运行的都是Avaliable
public static final String NEW = "New"; //新建的都是New
public static final String PROCESS = "Process";
public static final String LEAVING = "Leaving"; //回库房 可以分配下一个了 进入小车的下一个调度单组的
public static final String NOT_FINISHED = "NotFinish"; //需要检查子菜单的状态 可能运行一半又释放回去了
public static final String FINISHED = "Finish";
}
package com.mushiny.beans.enums;
/**
* Created by Tank.li on 2017/9/6.
*/
public class TripType {
public static final String POD_RUN = "PodRun";
public static final String EMPTY_RUN = "EmptyRun";
public static final String STOW_POD = "StowPod";
public static final String PICK_POD = "PickPod";
public static final String CHARGER_DRIVE = "ChargerDrive";
public static final String POD_SCAN = "PodScan";
public static final String IBP_POD = "IBPPod";
public static final String OBP_POD = "OBPPod";
public static final String ICQA_POD = "ICQAPod";
public static final String CARRY_EMPTY_POD = "CarryEmptyPod";
public static final String CARRY_FULL_POD = "CarryFullPod";
}
package com.mushiny.beans.map;
import com.mushiny.beans.Address;
import com.mushiny.beans.enums.AddressType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by Tank.li on 2017/9/11.
*/
public class NodeList {
private final static Logger logger = LoggerFactory.getLogger(NodeList.class);
private Integer x;//x轴包含的列表
private List<Address> addressList;
private boolean revert;
private List<List<Long>> addrsList = new ArrayList<>();//输出该轴 多条存储区的路径
public List<List<Long>> getAddrsList() {
return addrsList;
}
public boolean isRevert() {
return revert;
}
public void setRevert(boolean revert) {
this.revert = revert;
}
public Integer getX() {
return x;
}
public void setX(Integer x) {
this.x = x;
}
public List<Address> getAddressList() {
return addressList;
}
public void setAddressList(List<Address> addressList) {
this.addressList = addressList;
}
//正向反向排序
public void sort() {
if (revert) {
Collections.sort(this.addressList, new NodeAddrComparator());
} else {
Collections.sort(this.addressList, new RevertNodeAddrComparator());
}
}
private List<Long> sNodes = new ArrayList<>();
public List<Long> getsNodes() {
return sNodes;
}
public void export() {
Address last = null;
List<Long> list = null;
for (int i = 0; i < addressList.size(); i++) {
Address address = addressList.get(i);
if (last == null || last.getType() != AddressType.STORAGE) {
if (address.getType() == AddressType.STORAGE) {
list = new ArrayList<>();
addrsList.add(list);
list.add(Long.parseLong(address.getId()));
}
}else{
if (address.getType() == AddressType.STORAGE) {
if (list != null) {
list.add(Long.parseLong(address.getId()));
}
}
}
last = address;
}
logger.debug(this.getX()+"生成的路径有:"+addrsList.size());
for (int i = 0; i < addrsList.size(); i++) {
List<Long> aLong = addrsList.get(i);
StringBuilder sb = new StringBuilder("[");
for (int j = 0; j < aLong.size(); j++) {
Long addr = aLong.get(j);
if (j<aLong.size()-1) {
sb.append(addr).append(",");
} else {
sb.append(addr);
}
}
sb.append("]");
logger.debug("路径:"+i+":"+sb);
}
//生成首尾
for (int i = 0; i < addrsList.size(); i++) {
List<Long> longs = addrsList.get(i);
if(longs.size()>1){
sNodes.add(longs.get(0));
sNodes.add(longs.get(longs.size()-1));
}else{
sNodes.add(longs.get(0));
}
}
if (sNodes.size() > 2) {
//去掉首尾
sNodes.remove(0);
sNodes.remove(sNodes.size() - 1);
}
StringBuilder sb = new StringBuilder("[");
for (int j = 0; j < sNodes.size(); j++) {
Long addr = sNodes.get(j);
if (j < sNodes.size() - 1) {
sb.append(addr).append(",");
} else {
sb.append(addr);
}
}
sb.append("]");
logger.debug("sNodes:"+sb.toString());
}
private class NodeAddrComparator implements Comparator<Address> {
@Override
public int compare(Address o1, Address o2) {
if (o1.getxPosition() - o2.getxPosition() > 0) return 1;
if (o1.getxPosition() - o2.getxPosition() == 0) return 0;
return -1;
}
}
private class RevertNodeAddrComparator implements Comparator<Address> {
@Override
public int compare(Address o1, Address o2) {
if (o1.getxPosition() - o2.getxPosition() > 0) return -1;
if (o1.getxPosition() - o2.getxPosition() == 0) return 0;
return 1;
}
}
}
package com.mushiny.beans.map;
import java.util.Comparator;
/**
* Created by Tank.li on 2017/9/11.
*/
public class NodeListComparator implements Comparator<NodeList>{
@Override
public int compare(NodeList o1, NodeList o2) {
if (o1.getX() - o2.getX()>0) return 1;
if (o1.getX() - o2.getX()==0) return 0;
return -1;
}
}
package com.mushiny.beans.order;
import com.mushiny.beans.Address;
import com.mushiny.beans.Charger;
import com.mushiny.beans.Pod;
import com.mushiny.beans.Robot;
import com.mushiny.beans.enums.OrderErrorMessage;
import com.mushiny.beans.enums.TripStatus;
import com.mushiny.comm.CommonUtils;
import com.mushiny.comm.JsonUtils;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import org.apache.http.client.utils.DateUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Created by Tank.li on 2017/9/5.
*/
public class ChargerDriveOrder extends Order {
public static final int CHARGER_MUSHINY = 1;
public static final int CHARGER_MUSHINY3 = 3;
public static final int CHARGER_MIDIA = 2;
private Charger charger;
public Charger getCharger() {
return charger;
}
public void setCharger(Charger charger) {
this.charger = charger;
}
@Override
public void sendMessage2Rcs() {
if(this.wcsPath.getSeriesPath() == null || this.wcsPath.getSeriesPath().size() ==0){
logger.error("调度单初始化失败,不能发送消息:"+this);
return;
}
Map message = this.genWcsMessage();
message.put("chargerID",this.getCharger().getRcsChargerId());
message.put("chargerType",this.getCharger().getChargerType());
message.put("batterManufacturerNumber", this.getRobot().getBatteryNumber());
int type = this.getCharger().getChargerType();
switch (type){
case CHARGER_MUSHINY :
MessageSender.sendMapMessage(message, ISender.WCS_RCS_AGV_CHARGE);
break;
case CHARGER_MUSHINY3 ://3号类型是美的的新充电桩 已经不用了
MessageSender.sendMapMessage(message, ISender.WCS_RCS_AGV_CHARGE);
break;
case CHARGER_MIDIA :
message.put("mac",this.getCharger().getMac());
message.put("chargerAddr",Long.parseLong(this.getCharger().getChargerAddr()));
MessageSender.sendMapMessage(message, ISender.WCS_RCS_MIDEA_CHARGE);
break;
default:
logger.error("没有这种充电桩类型:"+type);
}
//MessageSender.sendMapMessage(message, ISender.WCS_RCS_AGV_CHARGE);
this.setMessage(JsonUtils.map2Json(message));
this.setSend2RcsTime(DateUtils.formatDate(new Date(System.currentTimeMillis())));
}
@Override
public void initOrder() {
//如果在执行充电任务时发现驮着货架,将生成内存中的PodRun任务 直接执行
if(this.getRobot().getPod()!=null){
this.setOrderError(Order.ERROR_CHARGE_WITHPOD);
return;
}
if(this.getWareHouseManager() == null){
logger.error("this.getWareHouseManager() is null!");
return;
}
//20181018 找小车所在位置的货架与小车未解绑
try {
String addr = this.getRobot().getAddressId();
Address address = this.getWareHouseManager().getAddressByAddressCodeId(addr,this.getRobot().getSectionId());
if(address.getPod() != null && Objects.equals(address.getPod().getRobot(),this.getRobot()) ){
logger.error("小车驮着货架不允许充电!");
this.setOrderError(Order.ERROR_CHARGE_WITHPOD);
return;
}
if(this.charger ==null){
this.setOrderError(Order.ERROR_NOCHARGER);
return;
}
//获取终点
String endAddr = this.charger.getAddressCodeId();
this.setEndAddr(Long.parseLong(endAddr));
Long srcAddr = Long.parseLong(getRobot().getAddressId());
this.wcsPath.setSrcAddr(srcAddr);
this.wcsPath.setEndAddr(Long.parseLong(endAddr));
Integer sourceVertex = CommonUtils.long2Int(srcAddr);
Integer targetVertex = CommonUtils.long2Int(getEndAddr());
List<Long> path = this.getWebApiBusiness().getEmptyPath(this.getWareHouseId(),getSectionId(),sourceVertex,targetVertex);
if(path==null || path.size()==0 || path.size() == 1){
this.setOrderError(Order.ERROR_EMPTY_PATH);
}
this.wcsPath.setSeriesPath(path);
//旋转角度
this.wcsPath.setRotateTheta(this.getCharger().getDirect());
} catch (Exception e) {
logger.error("初始化失败 order:"+this,e);
}
}
@Override
public void process() {
if(this.wcsPath.getSeriesPath() == null || this.wcsPath.getSeriesPath().size() ==0){
logger.error("调度单初始化失败,不能发送消息:"+this);
return;
}
this.addKV("TRIP_STATE", TripStatus.PROCESS);
this.getJdbcRepository().updateBusinessObject(this);
}
@Override
public void finish() {
if(this.wcsPath.getSeriesPath() == null || this.wcsPath.getSeriesPath().size() ==0){
logger.error("调度单初始化失败,不能发送消息:"+this);
return;
}
this.addKV("TRIP_STATE", TripStatus.FINISHED);
this.getJdbcRepository().updateBusinessObject(this);
}
@Override
public boolean isFinish() {
//return Objects.equals(Long.parseLong(this.getRobot().getAddressId()), this.getEndAddr());
logger.debug("位移包不结束调度单,从充电时间电量判断去结束!"+this);
if(Objects.equals(Long.parseLong(this.getRobot().getAddressId()), this.getEndAddr())
&& this.getRobot().getStatus() == Robot.CHARGING){
this.setCanFinish(true);
}
return false;
}
@Override
public String getType() {
return "ChargerDrive";
}
@Override
public void setType(String type) {
}
@Override
public String toString() {
return "ChargerDriveOrder{" +
"msg=" + this.getMessage() +
"sendTime=" + this.getSend2RcsTime() +
"charger=" + charger +
", wcsPath=" + wcsPath +
", orderId=" + this.getOrderId() +
", orderError=" + OrderErrorMessage.getMsg(this.getOrderError()) +
", type=" + this.getType() +
'}';
}
@Override
public void reInitOrder() {
this.initOrder();
}
@Override
public Pod getPod() {
return null;
}
}
package com.mushiny.beans.order;
import com.mushiny.beans.Address;
import com.mushiny.beans.Pod;
import com.mushiny.beans.Robot;
import com.mushiny.beans.Section;
import com.mushiny.beans.enums.AddressStatus;
import com.mushiny.beans.enums.TripStatus;
import com.mushiny.comm.CommonUtils;
import com.mushiny.comm.JsonUtils;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import org.apache.http.client.utils.DateUtils;
import java.util.*;
/**
* Created by Tank.li on 2017/9/5.
*/
public class EmptyRunOrder extends Order {
private String type="EmptyRun";
/*private Long endAddr;
public Long getEndAddr() {
return endAddr;
}
public void setEndAddr(Long endAddr) {
this.endAddr = endAddr;
}*/
/*
Long robotID
Long sectionID
Long time
Long podUpAddress
Long podDownAddress
Boolean isRotatePod
Int rotateTheta
List<Long> seriesPath*/
@Override
public void sendMessage2Rcs() {
Map msg = genWcsMessage();
MessageSender.sendMapMessage(msg, ISender.WCS_RCS_AGV_SERIESPATH);
this.setMessage(JsonUtils.map2Json(msg));
this.setSend2RcsTime(DateUtils.formatDate(new Date(System.currentTimeMillis())));
}
@Override
public void initOrder() {
if (this.getEndAddr() == 0L){
lockRandomStorage();//锁定最近存储区
}
this.wcsPath.setEndAddr(this.getEndAddr());
Long srcAddr = Long.parseLong(getRobot().getAddressId());
this.wcsPath.setSrcAddr(srcAddr);
Integer sourceVertex = CommonUtils.long2Int(srcAddr);
Integer targetVertex = CommonUtils.long2Int(this.getEndAddr());
List<Long> path = this.getWebApiBusiness().getEmptyPath(this.getWareHouseId(),getSectionId(),sourceVertex,targetVertex);
this.wcsPath.setSeriesPath(path);
}
/**
* 所有存储位的随机
*/
private void lockRandomStorage() {
Section section = this.getWareHouseManager().getSectionById(this.getSectionId());
List<Address> storageAddrs = section.getStorageAddrs();
Random random = new Random();
//获取小车小车位置映射表
Map robots = this.getRobotManager().getRegistRobots();
Iterator<Robot> iterator = robots.values().iterator();
Map<String,Robot> idleRobots = new HashMap();
while (iterator.hasNext()) {
Robot next = iterator.next();
if(next.isAvaliable() && next.getStatus() == Robot.IDLE) {
//小车的地址
idleRobots.put(next.getAddressId(), next);
}
}
List<Integer> list = new ArrayList();
for (int i = 0; i < storageAddrs.size(); i++) {
Integer ranInt = random.nextInt(storageAddrs.size());
if(!list.contains(ranInt)){
list.add(ranInt);
}
}
for (int i = 0; i < list.size(); i++) {
Integer integer = list.get(i);
//从第一个节点判断
if(integer < storageAddrs.size()){
Address address = storageAddrs.get(integer);
//只要车不在存储位、其他车目标地址不在存储位
//并且该存储位上有货架(很重要,不能去空闲位置 容易挡道)
// 并且该存储位的货架没有分配调度任务(New 或 Available)
//可能存在延迟 避免不了冲突
if(idleRobots.get(address.getId()) == null && address.getLockedBy() == 0L
&& Objects.equals(address.getNodeState(), AddressStatus.OCCUPIED)
&& noTripOnAddr(address)){
address.robotLock(this.getRobot().getRobotId(),true);
this.setEndAddr(Long.parseLong(address.getId()));
}
}
}
}
private static final String TRIP_ON_ADDRESS = "SELECT 1 FROM RCS_TRIP,MD_POD " +
"WHERE RCS_TRIP.POD_ID=MD_POD.ID " +
"AND RCS_TRIP.TRIP_STATE IN (?,?,?) AND POD_ID=?";
private boolean noTripOnAddr(Address address) {
Pod pod = this.getPodManager().getPodByAddress(address.getId(),address.getSectionId());
if (pod == null){
return false;
}
List rows = this.getJdbcRepository().queryBySql(TRIP_ON_ADDRESS,
TripStatus.AVAILABLE,TripStatus.NEW,TripStatus.PROCESS,pod.getPodId());
return rows==null || rows.size() == 0;
}
@Override
public void process() {
if(isInMem()){
return;
}
this.addKV("TRIP_STATE", TripStatus.PROCESS);
this.getJdbcRepository().updateBusinessObject(this);
}
@Override
public void finish() {
if (!isInMem()) {
this.addKV("TRIP_STATE", TripStatus.FINISHED);
this.getJdbcRepository().updateBusinessObject(this);
}
Address endAddr = this.getWareHouseManager().getAddressByAddressCodeId(this.getEndAddr(),this.getSectionId());
if (endAddr != null) {
endAddr.setLockedBy(0L); //TODO
getRobot().setLockedAddr(0L);
}
}
@Override
public boolean isFinish() {
Long end = this.getWcsPath().getEndAddr();
return Objects.equals(Long.parseLong(this.getRobot().getAddressId()), this.getEndAddr())
|| Objects.equals(Long.parseLong(this.getRobot().getAddressId()), end);
}
@Override
public String getType() {
return this.type;
}
@Override
public void setType(String type) {
this.type=type;
}
@Override
public void reInitOrder() {
this.initOrder();//一样处理
}
@Override
public String toString() {
return "EmptyRun{" +
"msg=" + this.getMessage() +
"sendTime=" + this.getSend2RcsTime() +
", wcsPath=" + wcsPath +
", orderId=" + this.getOrderId() +
", type=" + this.getType() +
'}';
}
}
package com.mushiny.beans.order;
import com.mushiny.beans.BaseObject;
/**
* 用于异步删除的对象
* Created by Tank.li on 2017/10/16.
*/
public class EnroutePod extends BaseObject{
@Override
public Object getId() {
return this.uuid;
}
private String uuid;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
private String table;
public void setTable(String table){
this.table = table;
}
@Override
public String getTable() {
return this.table;
}
@Override
public String getIdName() {
return "ID";
}
}
This diff is collapsed.
package com.mushiny.beans.order;
import com.mushiny.beans.BaseObject;
/**
* Created by Tank.li on 2017/9/6.
*/
public class OrderPosition extends BaseObject {
private String orderPositionId;
private String podId;
public String getPodId() {
return podId;
}
public void setPodId(String podId) {
this.podId = podId;
}
private int index;
private String useFace;
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getUseFace() {
return useFace;
}
public void setUseFace(String useFace) {
this.useFace = useFace;
}
public String getOrderPositionId() {
return orderPositionId;
}
public void setOrderPositionId(String orderPositionId) {
this.orderPositionId = orderPositionId;
}
@Override
public Object getId() {
return this.orderPositionId;
}
public static final String TABLE = "RCS_TRIPPOSITION";
@Override
public String getTable() {
return TABLE;
}
public static final String IDNAME = "ID";
@Override
public String getIdName() {
return IDNAME;
}
@Override
public String toString() {
return "OrderPosition{" +
"orderPositionId='" + orderPositionId + '\'' +
", podId='" + podId + '\'' +
", index=" + index +
", useFace='" + useFace + '\'' +
'}';
}
}
package com.mushiny.beans.order;
import com.mushiny.beans.Section;
import com.mushiny.beans.enums.TripStatus;
import com.mushiny.business.WebApiBusiness;
import com.mushiny.comm.CommonUtils;
import com.mushiny.comm.JsonUtils;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import org.apache.http.client.utils.DateUtils;
import java.util.*;
/**
* pod巡检的调度单
* Created by Tank.li on 2017/9/19.
*/
public class PodScanOrder extends Order {
private String type = "PodScan";
//小车奔跑路径
private List<Long> path;
private Long startScan;//
private Long endScan;//
public Long getStartScan() {
return startScan;
}
public void setStartScan(Long startScan) {
this.startScan = startScan;
}
public Long getEndScan() {
return endScan;
}
public void setEndScan(Long endScan) {
this.endScan = endScan;
}
public List<Long> getPath() {
return path;
}
public void setPath(List<Long> path) {
this.path = path;
}
@Override
public void sendMessage2Rcs() {
Map msg = new HashMap();
msg.put("robotID",this.getRobot().getRobotId());
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
msg.put("sectionID",section.getRcs_sectionId());
msg.put("time", System.currentTimeMillis());
msg.put("path",this.wcsPath.getSeriesPath());
msg.put("startScan",this.getStartScan());
msg.put("endScan",this.getEndScan());
MessageSender.sendMapMessage(msg, ISender.WCS_RCS_PODSCAN_PATH);
this.setMessage(JsonUtils.map2Json(msg));
this.setSend2RcsTime(DateUtils.formatDate(new Date(System.currentTimeMillis())));
}
@Override
public void initOrder() {
logger.debug("初始化扫描POD的路径:" + this.getType() + ":" + this.getPath());
this.wcsPath.setEndAddr(this.getEndAddr());
Long srcAddr = Long.parseLong(getRobot().getAddressId());
this.wcsPath.setSrcAddr(srcAddr);
//第一阶段任务 空车
Integer sourceVertex = CommonUtils.long2Int(srcAddr);
//第一个节点是路径的第一个节点
if(this.getPath() != null && this.getPath().size() == 0){
this.setOrderError(Order.ERROR_EMPTY_PATH);
return;
}
this.setStartScan(this.getPath().get(0));
this.setEndScan(this.getPath().get(this.getPath().size()-1));
Integer targetVertex = Integer.parseInt(this.getPath().get(0)+"");
//从重车走路径,不钻货架
List<Long> path = this.getWebApiBusiness().getHeavyPath(this.getWareHouseId(),getSectionId(),sourceVertex,targetVertex);
if(path==null || path.size()==0){
this.setOrderError(Order.ERROR_HEAVY_PATH);
return;
}
this.add2Path(path,this.getPath());
wcsPath.setPodUpAddress(0L);
wcsPath.setPodDownAddress(0L);
this.wcsPath.setSeriesPath(path);
WebApiBusiness.logPath(path,"全");
}
@Override
public void process() {
this.addKV("TRIP_STATE", TripStatus.PROCESS);
this.getJdbcRepository().updateBusinessObject(this);
}
@Override
public void finish() {
this.addKV("TRIP_STATE", TripStatus.FINISHED);
this.getJdbcRepository().updateBusinessObject(this);
}
@Override
public String toString() {
return "PodScanOrder{" +
"type='" + type + '\'' +
", msg =" + this.getMessage() +
", sendTime =" + this.getMessage() +
", startScan=" + startScan +
", endScan=" + endScan +
", path=" + path +
", RCSTime=" + this.getSend2RcsTime() +
", robot=" + (this.getRobot()==null?"":this.getRobot().getRobotId()) +
'}';
}
@Override
public void reInitOrder() {
this.initOrder();
}
@Override
public boolean isFinish() {
return Objects.equals(this.getRobot().getAddressId(),this.getEndScan()+"");
}
@Override
public String getType() {
return type;
}
@Override
public void setType(String type) {
this.type = type;
}
}
package com.mushiny.beans.order;
import java.util.HashMap;
import java.util.Map;
/**
* 支持IBPPod OBPPod ICQAPod 三种Trip调度类型
* Created by Tank.li on 2017/9/25.
*/
public class PqaPodOrder extends StationPodOrder{
@Override
public void finish() {
super.finish();
//通过Trip调度类型 和 PodID删除ENROUTEPOD表记录 PQA_ENROUTEPOD
/*if(this.getIndex() == Order.BUFFER2STORAGE){
unBindEnroutePod("PQA_ENROUTEPOD",this.getPod().getPodId());
}*/
}
}
This diff is collapsed.
package com.mushiny.beans.order;
import com.mushiny.comm.JsonUtils;
import java.util.List;
/**
* Created by Tank.li on 2017/9/5.
*/
public class WcsPath implements java.io.Serializable {
private Long robotID;
private Long time;
private Long sectionID;
private Integer rotateTheta = 0;
private List<Long> seriesPath;
private Long podUpAddress = 0L;
private Long podDownAddress = 0L;
private Boolean isRotatePod = Boolean.FALSE;
private Long srcAddr;
private Long endAddr;
public Long getSrcAddr() {
return srcAddr;
}
public void setSrcAddr(Long srcAddr) {
this.srcAddr = srcAddr;
}
public Long getEndAddr() {
return endAddr;
}
public void setEndAddr(Long endAddr) {
this.endAddr = endAddr;
}
public Long getRobotID() {
return robotID;
}
public void setRobotID(Long robotID) {
this.robotID = robotID;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public Long getSectionID() {
return sectionID;
}
public void setSectionID(Long sectionID) {
this.sectionID = sectionID;
}
public Integer getRotateTheta() {
return rotateTheta;
}
public void setRotateTheta(Integer rotateTheta) {
this.rotateTheta = rotateTheta;
}
public List<Long> getSeriesPath() {
return seriesPath;
}
public void setSeriesPath(List<Long> seriesPath) {
this.seriesPath = seriesPath;
}
public Long getPodUpAddress() {
return podUpAddress;
}
public void setPodUpAddress(Long podUpAddress) {
this.podUpAddress = podUpAddress;
}
public Long getPodDownAddress() {
return podDownAddress;
}
public void setPodDownAddress(Long podDownAddress) {
this.podDownAddress = podDownAddress;
}
public Boolean getRotatePod() {
return isRotatePod;
}
public void setRotatePod(Boolean rotatePod) {
isRotatePod = rotatePod;
}
@Override
public String toString() {
return "WcsPath{" +
"robotID=" + robotID +
", podUpAddress=" + podUpAddress +
", podDownAddress=" + podDownAddress +
", endAddr=" + endAddr +
", srcAddr=" + srcAddr +
", seriesPath=" + JsonUtils.list2Json(seriesPath) +
'}';
}
public static void main(String[] args) {
WcsPath path = new WcsPath();
path.setPodDownAddress(0L);
path.setPodUpAddress(0L);
System.out.println(path);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 子转入库
*/
public class ANNTOMVINOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
@Override
public void process() {
super.process();
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.STOCKIN);
message.put(MideaConstants.INSTRUCT, this.getInstructId());
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 子转出库
*/
public class ANNTOMVOUTOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
public void process() {
super.process();
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.SOURCE_ADDRESS, this.getWcsPath().getPodUpAddress());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.STOCKOUT);
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by Administrator on 2018/8/9.
*/
public class CarryEmptyPodOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.INSTRUCT, this.getInstructId());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
MessageSender.sendMapMessage(message, ISender.WCS_WMS_ARRIVED_STATION);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by Administrator on 2018/8/9.
*/
public class CarryFullPodOrder extends PodRunOrder{
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.INSTRUCT, this.getInstructId());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
MessageSender.sendMapMessage(message, ISender.WCS_WMS_ARRIVED_STATION);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.ISender;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by Administrator on 2018/7/13.
*/
public class CarryPodOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.INSTRUCT, this.getInstructId());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 完工入库
*/
public class FINISHESWAREHOUSINGOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
public void process() {
super.process();
/**Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.RUNNING);
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);**/
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.STOCKIN);
message.put(MideaConstants.INSTRUCT, this.getInstructId());
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
}
}
package com.mushiny.beans.order.midea;
import com.mushiny.beans.Section;
import com.mushiny.mq.MessageSender;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 领料出库
*/
public class LMGETMATERIALOrder extends PodRunOrder {
@Override
public String getType() {
return super.getType();
}
@Override
public void setType(String type) {
super.setType(type);
}
public void process() {
super.process();
Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.SOURCE_ADDRESS, this.getWcsPath().getPodUpAddress());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.RUNNING);
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
}
@Override
public void finish() {
super.finish();
Map message = new LinkedHashMap();
Section section = this.getWareHouseManager().getSectionById(this.getRobot().getSectionId());
message.put("sectionID",section.getRcs_sectionId());
message.put(MideaConstants.TRIP_ID,this.getOrderId());
message.put(MideaConstants.TRIP_TYPE,this.getType());
message.put(MideaConstants.TARGET_ADDRESS, this.getEndAddr());
message.put(MideaConstants.SOURCE_ADDRESS, this.getWcsPath().getPodUpAddress());
message.put(MideaConstants.DRIVE_ID, this.getRobot().getRobotId());
message.put(MideaConstants.POD_INDEX,this.getPod().getPodId());
message.put(MideaConstants.INSTRUCT_STATUS, MideaConstants.STOCKOUT);
message.put(MideaConstants.INSTRUCT, this.getInstructId());
MessageSender.sendMapMessage(message, MideaConstants.INSTRUCTACK);
//
}
}
package com.mushiny.beans.order.midea;
/**
* Created by Administrator on 2018/7/13.
*/
public class MideaConstants {
public static final String INSTRUCTACK = "InstructAck";
public static final String TRIP_ID = "tripId";
public static final String TRIP_TYPE = "tripType";
public static final String POD_INDEX = "podIndex";
public static final String INSTRUCT_STATUS = "instructStatus";
public static final String DRIVE_ID = "driverId";
public static final String TARGET_ADDRESS = "targetAddress";
public static final String RUNNING = "RUNNING";
public static final String STOCKIN = "STOCKIN";
public static final String STOCKOUT = "STOCKOUT";
public static final String SOURCE_ADDRESS = "sourceAddress";
public static final String ANNTOMVIN = "ANNTOMVIN";
public static final String ANNTOMVOUT = "ANNTOMVOUT";
public static final String FINISHESWAREHOUSING = "FINISHESWAREHOUSING";
public static final String LMGETMATERIAL = "LMGETMATERIAL";
public static final String CarryPod = "CarryPod";
public static final String PACKAGE = "com.mushiny.beans.order.midea.";
public static final String POSTFIX = "Order";
public static final String INSTRUCT = "INSTRUCT";
}
This diff is collapsed.
package com.mushiny.business;
import com.mushiny.beans.Address;
import java.util.Comparator;
/**
* Created by Tank.li on 2017/6/28.
*/
public class AddrScoreComparator implements Comparator<Address> {
/*JDK7中的Collections.Sort方法实现中,
如果两个值是相等的,那么compare方法需要返回0,
否则 可能 会在排序时抛错,而JDK6是没有这个限制的*/
@Override
public int compare(Address o1, Address o2) {
if (o1.getScore() - o2.getScore()>0) return 1;
if (o1.getScore() - o2.getScore()==0) return 0;
return -1;
}
}
package com.mushiny.business;
import com.mushiny.beans.Address;
import java.util.Comparator;
/**
* Created by Tank.li on 2017/6/26.
*/
public class AddressComparator implements Comparator<Address> {
@Override
public int compare(Address o1, Address o2) {
//return o1.getHot() - o2.getHot();
if (o1.getHot() - o2.getHot()>0) return 1;
if (o1.getHot() - o2.getHot()==0) return 0;
return -1;
}
}
package com.mushiny.business;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Tank.li on 2017/7/26.
*/
public class MapJsonExample{
public static void main1(String[] args) {
try {
ObjectMapper mapper = new ObjectMapper();
String json = "";
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "mkyong");
map.put("age", 29);
// convert map to JSON string
json = mapper.writeValueAsString(map);
System.out.println("===>"+json);
json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
// pretty print
System.out.println(json);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
ObjectMapper mapper = new ObjectMapper();
String json = "{\"name\":\"mkyong\", \"age\":29}";
Map<String, Object> map = new HashMap<String, Object>();
// convert JSON string to Map
map = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});//比 Map<String, String> 准确
System.out.println(map);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.mushiny.business;
import com.mushiny.comm.CommonUtils;
import com.mushiny.comm.MediaConfig;
import com.mushiny.jdbc.repositories.JdbcRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2018/1/19.
*/
//@Component
//@org.springframework.core.annotation.Order(value = 1)
public class MediaInit implements CommandLineRunner {
private final static Logger logger = LoggerFactory.getLogger(MediaInit.class);
private static MediaConfig mediaConfig = new MediaConfig();
@Autowired
private JdbcRepository jdbcRepository;
private String initPods(){
//MediaConfig mediaConfig = new MediaConfig();
String podsStr = mediaConfig.getProperties().getProperty("pods");
logger.debug("读取mediaPod配置文件:pods="+podsStr);
if (!CommonUtils.isEmpty(podsStr)){
String[] pod_addrArr = podsStr.split(",");
logger.debug("开始更新POD,配置中共"+pod_addrArr.length+"个POD");
for (int i = 0; i < pod_addrArr.length; i++) {
String pod_addr = pod_addrArr[i];
String[] podAddr = pod_addr.split("-");
String podIndex = podAddr[0];
String addr = podAddr[1];
List parmsList = new ArrayList();
parmsList.add(addr); //placemark
parmsList.add(podAddr[2]); //x
parmsList.add(podAddr[3]); //y
parmsList.add("Available"); //state
parmsList.add(0); //toward
parmsList.add(podIndex); //pod_index
logger.debug("media演示场地pod地址初始化:podIndex="+podIndex+", paramsList="+ parmsList);
int num = jdbcRepository.updateByKey("MEDIA.UpdatePodAddrByPodIndex", parmsList);
}
}
return podsStr;
}
private void clearRobots(){
Map delMap = new HashMap();
delMap.put("1","1");
int delNum = jdbcRepository.deleteRecords("WCS_ROBOT", delMap);
//jdbcRepository.queryByKey("MEDIA.DeleteRobots");
logger.debug("media演示场地,清除所有小车共:"+delNum);
}
private void clearTrips(){
Map delMap = new HashMap();
delMap.put("1", "1");
int delNumTrips = jdbcRepository.deleteRecords("RCS_TRIP", delMap);
//jdbcRepository.queryByKey("MEDIA.DeleteTrips");
logger.debug("media演示场地,清除所有调度单共:"+delNumTrips);
int delNumTripPositions = jdbcRepository.deleteRecords("RCS_TRIPPOSITION", delMap);
//jdbcRepository.queryByKey("MEDIA.DeleteTripPositions");
logger.debug("media演示场地,清除所有调度单明细共:"+delNumTripPositions);
}
private void clearEnroutepods(){
Map delMap = new HashMap();
delMap.put("1", "1");
int delNumIB = jdbcRepository.deleteRecords("IB_ENROUTEPOD", delMap);
//jdbcRepository.queryByKey("MEDIA.DeleteIB");
logger.debug("media演示场地,清除IB在途pod共:"+delNumIB);
int delNumOB = jdbcRepository.deleteRecords("OB_ENROUTEPOD", delMap);
//jdbcRepository.queryByKey("MEDIA.DeleteOB");
logger.debug("media演示场地,清除OB在途pod共:"+delNumOB);
int delNumPQA = jdbcRepository.deleteRecords("PQA_ENROUTEPOD", delMap);
//jdbcRepository.queryByKey("MEDIA.DeletePQA");
logger.debug("media演示场地,清除PQA在途pod共:"+delNumPQA);
}
/*public static void main(String[] args) {
System.out.println(initPods());
}*/
@Override
public void run(String... strings) throws Exception {
logger.debug("开始初始化Media演示地图...");
clearTrips();
clearRobots();
clearEnroutepods();
initPods();
logger.debug("初始化Media演示地图结束!");
}
}
This diff is collapsed.
package com.mushiny.business;
import com.mushiny.beans.Pod;
import java.util.Comparator;
/**
* Created by Tank.li on 2017/6/28.
*/
public class PodComparator implements Comparator<Pod> {
@Override
public int compare(Pod o1, Pod o2) {
//return (o1.getHot()-o2.getHot()>0)? 1:-1;
if (o1.getHot() - o2.getHot()>0) return 1;
if (o1.getHot() - o2.getHot()==0) return 0;
return -1;
}
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.mushiny.business;
import com.mushiny.beans.enums.TripStatus;
import com.mushiny.comm.CommonUtils;
import com.mushiny.jdbc.repositories.JdbcRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2018/3/21.
*/
@Component
@org.springframework.core.annotation.Order(value = 1)
public class RunningOrderInit implements CommandLineRunner {
private final static Logger logger = LoggerFactory.getLogger(RunningOrderInit.class);
private Map processRobots = new HashMap();
@Autowired
private JdbcRepository jdbcRepository;
private int restoreProcessTrip2Available(){
String getProcessTrip_sql = "select * from RCS_TRIP where trip_state=? or trip_state=?";
String updateProcessTrip_sql = "update RCS_TRIP set trip_state=? where ID=?";
String getProcessTripPosition_sql = "select * from RCS_TRIPPOSITION where TRIP_ID=? and tripposition_state=?";
String updateProcessTripPosition_sql = "update RCS_TRIPPOSITION set tripposition_state=? where ID=?";
List<Map> rows = this.jdbcRepository.queryBySql(getProcessTrip_sql.toUpperCase(), TripStatus.PROCESS, TripStatus.LEAVING);
if (rows!=null && rows.size()>0){
logger.debug("上一次未完成的调度单有:"+rows.size()+"条");
List<Map> positionRows;
for (int i = 0; i < rows.size(); i++) {
Map map = rows.get(i);
String tripId = CommonUtils.parseString("ID", map);
String robotId = CommonUtils.parseString("DRIVE_ID", map);
String tripType = CommonUtils.parseString("TRIP_TYPE", map);
processRobots.put(robotId, map);
this.jdbcRepository.updateBySql(updateProcessTrip_sql.toUpperCase(), TripStatus.AVAILABLE, tripId);
logger.debug("更新RCS_TRIP状态Process-->Available成功,tripId:"+tripId);
positionRows = this.jdbcRepository.queryBySql(getProcessTripPosition_sql.toUpperCase(), tripId, TripStatus.PROCESS);
if (positionRows!=null && positionRows.size()>0){
logger.debug("调度单tripId:"+tripId+"中正在进行的明细有:"+positionRows.size()+"条");
for (int j = 0; j < positionRows.size(); j++) {
Map positionMap = positionRows.get(j);
String positionId = CommonUtils.parseString("ID", positionMap);
this.jdbcRepository.updateBySql(updateProcessTripPosition_sql.toUpperCase(), TripStatus.AVAILABLE, positionId);
logger.debug("更新RCS_TRIPPOSITION状态Process-->Available成功,tripPositionId:"+positionId);
}
}
}
}else{
logger.debug("重启wcs后,未扫描到上一次正在执行中的调度单");
}
return 1;
}
private void clearRobots(){
Map delMap = new HashMap();
delMap.put("1","1");
int delNum = jdbcRepository.deleteRecords("WCS_ROBOT", delMap);
logger.debug("启动WCS,清除所有小车共:"+delNum);
}
@Override
public void run(String... strings) throws Exception {
logger.debug("启动WCS,准备清除数据库所有小车...");
clearRobots();
restoreProcessTrip2Available();
logger.debug("启动WCS,已经清除数据库所有小车,并还原所有Process调度单为Available...");
}
}
package com.mushiny.business;
import com.mushiny.comm.CommonUtils;
import com.mushiny.jdbc.repositories.JdbcRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Tank.li on 2017/7/25.
*/
@Component
@org.springframework.core.annotation.Order(value = 0)
public class SystemPropertiesManager implements CommandLineRunner{
private final static Logger logger = LoggerFactory.getLogger(RobotManager.class);
@Autowired
private JdbcRepository jdbcRepository;
private Map<SysKey,String> properties = new ConcurrentHashMap<>();
public String getProperty(String key,String wareHouseId){
return properties.get(new SysKey(wareHouseId,key));
}
@Override
public void run(String... strings) throws Exception {
loadSystemProperties();
}
@Scheduled(fixedDelay = 100000l)
public void loadSystemProperties() {
/*SYSTEM_KEY` varchar(255) NOT NULL,
`SYSTEM_VALUE` varchar(255) NOT NULL,
`WAREHOUSE_ID` varchar(255) NOT NULL,*/
logger.debug("加载系统参数信息.....");
List<Map> rows = this.jdbcRepository.queryByKey("SystemPropertiesManager.loadSystemProperty");
for (int i = 0; i < rows.size(); i++) {
Map row = rows.get(i);
String WAREHOUSE_ID = CommonUtils.parseString("WAREHOUSE_ID",row);
String SYSTEM_KEY = CommonUtils.parseString("SYSTEM_KEY",row);
String SYSTEM_VALUE = CommonUtils.parseString("SYSTEM_VALUE",row);
properties.put(new SysKey(WAREHOUSE_ID,SYSTEM_KEY), SYSTEM_VALUE);
}
logger.debug("加载系统参数信息结束:"+properties);
}
private class SysKey{
private String wareHouseId;
private String key;
public SysKey(String wareHouseId, String key) {
this.wareHouseId = wareHouseId;
this.key = key;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SysKey sysKey = (SysKey) o;
if (wareHouseId != null ? !wareHouseId.equals(sysKey.wareHouseId) : sysKey.wareHouseId != null)
return false;
return key != null ? key.equals(sysKey.key) : sysKey.key == null;
}
@Override
public int hashCode() {
int result = wareHouseId != null ? wareHouseId.hashCode() : 0;
result = 31 * result + (key != null ? key.hashCode() : 0);
return result;
}
}
}
This diff is collapsed.
package com.mushiny.business;
/**
* Created by Tank.li on 2017/7/26.
*/
import com.mushiny.beans.Pod;
import com.mushiny.beans.WorkStation;
import com.mushiny.beans.order.Order;
import com.mushiny.comm.CommonUtils;
import com.mushiny.comm.JsonUtils;
import com.mushiny.map.MapManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
@Component
public class WebApiBusiness {
private final static Logger logger = LoggerFactory.getLogger(WebApiBusiness.class);
private final RestTemplateBuilder builder;
@Value("${mushiny.webapi.path-planning.emptyPath}")
private String path_empty_url;
@Value("${mushiny.webapi.path-planning.heavyPath}")
private String path_heavy_url;
@Value("${mushiny.webapi.callStowPods_url}")
private String callStowPods_url;
@Value("${mushiny.webapi.path-planning.updateNewCost}")
private String update_newCost_url;
@Value("${mushiny.webapi.path-planning.addHeavyCost}")
private String add_heavyCost_url;
@Autowired
public WebApiBusiness(RestTemplateBuilder builder) {
this.builder = builder;
}
@Value("${mushiny.webapi.path-planning.turning}")
private String path_podTurning_url;
/**
* 获取POD旋转度数
* */
public int getPodTurning(String face, int sourceToward ,int targetToward){
RestTemplate restTemplate = builder.build();
/*String restUrl = "http://192.168.1.10:12003/path-planning/pod/turning?" +
"face={face}&sourceToward={sourceToward}&targetToward={targetToward}";*/
return restTemplate.getForObject(path_podTurning_url,Integer.class,face,sourceToward,targetToward);
}
/**
* @deprecated
* @param pod
* @param workStation
* @param needFace
* @return
*/
public static int getPodTurning2(Pod pod, WorkStation workStation,String needFace){
int podFace = pod.getDirect();
int wsFace = workStation.getFace();
logger.debug("计算旋转角度: podFace:"+podFace+" wsFace:"+wsFace+" needFace:"+needFace);
return CommonUtils.aFaceToward(podFace,wsFace,needFace);
}
public static void main(String[] args) {
/*WorkStation workStation = new WorkStation();
workStation.setFace(180);
Pod pod = new Pod();
pod.setDirect(270);
String needFace = "D";
System.out.println("计算A面角度:"+ getPodTurning2(pod,workStation,needFace));*/
System.out.println(JsonUtils.json2List("",Long.class));
}
public List<Long> getEmptyPath(String warehouseId,String sectionId, Integer sourceVertex ,Integer targetVertex){
RestTemplate restTemplate = builder.build();
String res = null;
try {
logger.debug("emptyPath:"+warehouseId+" " +sectionId+" " +sourceVertex+" " +targetVertex);
res = restTemplate.getForObject(this.path_empty_url,
String.class, warehouseId,sectionId,sourceVertex,targetVertex);
} catch (RestClientException e) {
logger.error("空车车路径获取失败! sourceVertex:"+sourceVertex+" targetVertex:"+targetVertex,e);
}
List<Long> path = JsonUtils.json2List(res,Long.class);
logPath(path,"空车");
return path;
}
public List<Long> getHeavyPath(String warehouseId,String sectionId, Integer sourceVertex ,Integer targetVertex){
RestTemplate restTemplate = builder.build();
String res = null;
try {
logger.debug("heavyPath:"+warehouseId+" " +sectionId+" " +sourceVertex+" " +targetVertex);
res = restTemplate.getForObject(this.path_heavy_url,
String.class, warehouseId,sectionId,sourceVertex,targetVertex);
} catch (Exception e) {
logger.error("重车车路径获取失败! sourceVertex:"+sourceVertex+" targetVertex:"+targetVertex,e);
}
List<Long> path = JsonUtils.json2List(res,Long.class);
logPath(path,"重车");
return path;
/*List<Integer> path = new ArrayList<>();
path.add(11);
path.add(12);
path.add(13);
path.add(14);
path.add(15);
return path;*/
}
public void callStowPods(String logicStationId) {
RestTemplate restTemplate = builder.build();
String res = null;
try {
logger.debug("logicStationId:"+logicStationId+" this.callStowPods_url:"+this.callStowPods_url);
res = restTemplate.getForObject(this.callStowPods_url, String.class, logicStationId);
logger.debug("callStowPods_url返回结果:"+res);
} catch (Exception e) {
logger.error(" 呼叫StowPod失败:logicStationId:"+logicStationId,e);
}
}
public String updateNewCost(String warehouseId,String sectionId, String addressList, String newCost){
RestTemplate restTemplate = builder.build();
String res = null;
try {
logger.debug("updateNewCost:"+warehouseId+" " +sectionId+" " +addressList+" " +newCost);
res = restTemplate.getForObject(this.update_newCost_url,
String.class, warehouseId,sectionId,addressList,newCost);
} catch (RestClientException e) {
logger.error("更新NEW-COST失败! addressList:"+addressList+" newCost:"+newCost,e);
}
if ("1".equals(res)){
logger.debug("path-planning更新NEW-COST成功! addressList:"+addressList+" newCost:"+newCost);
}else{
logger.debug("path-planning更新NEW-COST失败! addressList:"+addressList+" newCost:"+newCost);
}
return res;
}
public String addHeavyCost(String warehouseId,String sectionId, String addressList, String heavyCost){
RestTemplate restTemplate = builder.build();
String res = null;
try {
logger.debug("addHeavyCost:"+warehouseId+" " +sectionId+" " +addressList+" " +heavyCost);
res = restTemplate.getForObject(this.add_heavyCost_url,
String.class, warehouseId,sectionId,addressList,heavyCost);
} catch (RestClientException e) {
logger.error("addHeavyCost失败! addressList:"+addressList+" heavyCost:"+heavyCost,e);
}
if ("1".equals(res)){
logger.debug("path-planning:addHeavyCost成功! addressList:"+addressList+" heavyCost:"+heavyCost);
}else{
logger.debug("path-planning:addHeavyCost失败! addressList:"+addressList+" heavyCost:"+heavyCost);
}
return res;
}
public static String logPath(List<Long> pod2Target,String type) {
StringBuilder stringBuilder = new StringBuilder("[");
for (int i = 0; i < pod2Target.size(); i++) {
Long integer = pod2Target.get(i);
if (i < pod2Target.size() - 1) {
stringBuilder.append(integer).append(",");
} else {
stringBuilder.append(integer);
}
}
stringBuilder.append("]");
logger.debug(type + "路径是:" + stringBuilder.toString());
return stringBuilder.toString();
}
}
\ No newline at end of file
package com.mushiny.comm;
import java.io.*;
import java.util.Properties;
/**
* Created by zf on 2017/11/17.
*/
public class AGVConfigParameters {
private Properties properties = new Properties();
private String defaultFilePath = "/AGVConfigParameters.properties";
public Properties getProperties() {
if (properties == null || properties.isEmpty()){
init(defaultFilePath);
}
return properties;
}
public AGVConfigParameters() {
init(defaultFilePath);
}
private void init(String filePath){
//读取属性文件a.properties
try {
if (CommonUtils.isEmpty(filePath)){
filePath = defaultFilePath;
}
InputStream in = AGVConfigParameters.class.getResourceAsStream(filePath);
properties.load(in); ///加载属性列表
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/*public String getProperty(String key){
if (properties==null || properties.isEmpty()){
return "AGVConfigParameters配置文件为空!";
}
return properties.getProperty(key);
}
public void setProperty(String key, String value){
if (properties == null){
init(defaultFilePath);
}
properties.setProperty(key, value);
}
///保存属性到b.properties文件
public void addProperty(String key, String value){
System.out.println("addProperty:"+key+" "+value);
if (properties == null || properties.isEmpty()){
init(defaultFilePath);
}
try {
String filePath = AGVConfigParameters.class.getResource(defaultFilePath).toString();
filePath = filePath.substring(6);
File file = new File(filePath);
if (!file.exists()){
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file, true);
properties.setProperty(key, value);
properties.store(fos, "add new properties!");
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AGVConfigParameters t = new AGVConfigParameters();
t.addProperty("b", "3");
}*/
}
package com.mushiny.comm;
/**
* Created by Tank.li on 2017/10/25.
*/
public class Agv {
private String name;
private int status;
private boolean available;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
}
package com.mushiny.comm;
import com.mushiny.beans.Robot;
import java.util.Objects;
/**
* Created by Tank.li on 2017/10/25.
*/
public class BizActor {
private static final Object locker = new Object();
public void action(Agv agv){
synchronized (locker){
if(agv.isAvailable() && agv.getStatus()==1){
agv.setAvailable(false);
agv.setStatus(Robot.WORKING);
System.out.println(Thread.currentThread().getName()+"执行");
try {
Thread.sleep(6000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"执行结束");
}else{
System.out.println(Thread.currentThread().getName()+"未执行");
}
agv.setStatus(Robot.IDLE);
agv.setAvailable(true);
}
}
}
package com.mushiny.comm;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* Created by zf on 2018/1/26.
*/
//@Aspect
@Component
public class CheckFunctionUseTime {
private final static Logger LOGGER = LoggerFactory.getLogger(CheckFunctionUseTime.class);
public static final String POINT = "execution(* com.mushiny.controller.WcsController.*(..))";
private static final long ONE_MINUTE = 10;
//@Around(POINT)
public Object timeAround(ProceedingJoinPoint joinPoint) {
// 定义返回对象、得到方法需要的参数
Object obj = null;
Object[] args = joinPoint.getArgs();
long startTime = System.currentTimeMillis();
try {
obj = joinPoint.proceed(args);
} catch (Throwable e) {
LOGGER.error("统计某方法执行耗时环绕通知出错", e);
}
// 获取执行的方法名
long endTime = System.currentTimeMillis();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String methodName = signature.getDeclaringTypeName() + "." + signature.getName();
// 打印耗时的信息
this.printExecTime(methodName, startTime, endTime);
return obj;
}
/**
* 打印方法执行耗时的信息,如果超过了一定的时间,才打印
* @param methodName
* @param startTime
* @param endTime
*/
private void printExecTime(String methodName, long startTime, long endTime) {
long diffTime = endTime - startTime;
if (diffTime > ONE_MINUTE) {
LOGGER.debug("-----" + methodName + " 方法执行耗时:" +diffTime +" ms");
}
}
}
This diff is collapsed.
package com.mushiny.comm;
/**
* Created by Tank.li on 2017/7/27.
*/
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.JavaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JsonUtils {
private static ObjectMapper objectMapper = new ObjectMapper();
public static <T> String bean2Json(T bean) {
try {
return objectMapper.writeValueAsString(bean);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static String map2Json(Map map) {
try {
return objectMapper.writeValueAsString(map);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static String list2Json(List list) {
try {
return objectMapper.writeValueAsString(list);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static <T> T json2Bean(String json, Class<T> beanClass) {
try {
return objectMapper.readValue(json, beanClass);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static <T> List<T> json2List(String json, Class<T> beanClass) {
if(CommonUtils.isEmpty(json)){
return new ArrayList<>();
}
try {
return (List<T>) objectMapper.readValue(json, getCollectionType(List.class, beanClass));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Map json2Map(String json) {
if(CommonUtils.isEmpty(json)){
return new HashMap();
}
try {
return (Map) objectMapper.readValue(json, Map.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
return objectMapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
}
public static void main(String[] args) {
Map data = new HashMap();
data.put("sectionID","1");
data.put("reCode", "1");
data.put("reMsg", "succes");
/*List<String> canwork = new ArrayList<>();
List<String> cannotwork = new ArrayList<>();
canwork.add("1");
canwork.add("2");
canwork.add("3");
cannotwork.add("4");
cannotwork.add("5");
cannotwork.add("6");
data.put("blockedAddressList",cannotwork);
data.put("availableAddressList",canwork);*/
String json = map2Json(data);
System.out.println(json);
System.out.println("===>"+Long.parseLong("P0000003".substring(1)));
}
}
package com.mushiny.comm;
import org.springframework.stereotype.Component;
import java.io.InputStream;
import java.util.Properties;
/**
* Created by zf on 2017/11/17.
*/
@Component
public class MediaConfig {
private Properties properties = new Properties();
private String defaultFilePath = "/mediaPods.properties";
public Properties getProperties() {
if (properties == null || properties.isEmpty()){
init(defaultFilePath);
}
return properties;
}
public MediaConfig() {
init(defaultFilePath);
}
private void init(String filePath){
//读取属性文件a.properties
try {
if (CommonUtils.isEmpty(filePath)){
filePath = defaultFilePath;
}
InputStream in = MediaConfig.class.getResourceAsStream(filePath);
properties.load(in); ///加载属性列表
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/*public String getProperty(String key){
if (properties==null || properties.isEmpty()){
return "AGVConfigParameters配置文件为空!";
}
return properties.getProperty(key);
}
public void setProperty(String key, String value){
if (properties == null){
init(defaultFilePath);
}
properties.setProperty(key, value);
}
///保存属性到b.properties文件
public void addProperty(String key, String value){
System.out.println("addProperty:"+key+" "+value);
if (properties == null || properties.isEmpty()){
init(defaultFilePath);
}
try {
String filePath = AGVConfigParameters.class.getResource(defaultFilePath).toString();
filePath = filePath.substring(6);
File file = new File(filePath);
if (!file.exists()){
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file, true);
properties.setProperty(key, value);
properties.store(fos, "add new properties!");
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AGVConfigParameters t = new AGVConfigParameters();
t.addProperty("b", "3");
}*/
}
package com.mushiny.comm;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if(SpringUtil.applicationContext == null) {
SpringUtil.applicationContext = applicationContext;
}
System.out.println("ApplicationContext配置成功,在普通类可以通过调用SpringUtils.getAppContext()获取applicationContext对象,applicationContext="+SpringUtil.applicationContext+"========");
}
//获取applicationContext
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
//通过name获取 Bean.
public static Object getBean(String name){
return getApplicationContext().getBean(name);
}
//通过class获取Bean.
public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz);
}
//通过name,以及Clazz返回指定的Bean
public static <T> T getBean(String name,Class<T> clazz){
return getApplicationContext().getBean(name, clazz);
}
}
package com.mushiny.comm;
/**
* Created by Tank.li on 2017/10/25.
*/
public class TestThread extends Thread{
private BizActor bizActor = new BizActor();
private Agv agv;
public Agv getAgv() {
return agv;
}
public void setAgv(Agv agv) {
this.agv = agv;
}
public TestThread(String name) {
super(name);
}
@Override
public void run() {
bizActor.action(agv);
}
}
package com.mushiny.comm;
import com.mushiny.beans.Robot;
import java.util.Map;
/**
* Created by Tank.li on 2017/10/25.
*/
public class ThreadTest {
public static void main(String[] args) {
}
}
package com.mushiny.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by Administrator on 2018/7/3.
*/
@RestController
@RequestMapping("/carry")
public class CarryPodController {
}
package com.mushiny.controller;
import com.mushiny.beans.Pod;
import com.mushiny.beans.Section;
import com.mushiny.business.PodManager;
import com.mushiny.business.WareHouseManager;
import com.mushiny.mq.MessageSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2018/7/3.
*/
@RestController
@RequestMapping(value="/midea")
public class MideaController {
@Autowired
private PodManager podManager;
@Autowired
private WareHouseManager wareHouseManager;
@Autowired
private MessageSender messageSender;
@GetMapping(path = "/allPodsInfo")
public String checkWorkStationAddrs(HttpServletRequest request, HttpServletResponse response) {
response.setHeader("Access-Control-Allow-Origin", "*");
String sectionId = request.getParameter("sectionId");
Section section = this.wareHouseManager.getSectionById(sectionId);
if(section == null){
section = this.wareHouseManager.getSectionByRcsSectionId(Long.parseLong(sectionId));
}
//获取所有信息
List<Pod> pods = this.podManager.getPods(section);
return "";
}
@GetMapping(path = "/send2Rmq")
public String send2Rmq(HttpServletRequest request, HttpServletResponse response) {
/*generalErrorID
seriousErrorList List
commonErrorList List
errorStatus
sectionID
time
robotID
seriousErrorID
commonErrorID
generalErrorList List*/
/*response.setHeader("Access-Control-Allow-Origin", "*");
Map data = new HashMap();
data.put("robotID",1L);
data.put("time",System.currentTimeMillis());
data.put("generalErrorID",1);
List generalErrorList = new ArrayList();
Map detail = new HashMap();
detail.put("description","不在Tag位");
detail.put("generalErrorID",1);
detail.put("bitPosition",2);
generalErrorList.add(detail);
data.put("generalErrorList",generalErrorList);
data.put("seriousErrorID",1);
data.put("commonErrorID",1);
data.put("errorStatus","errorStatus");*/
Map data = new HashMap();
/*请求名称 String name
sectionID Long sectionID
时间戳 Long requestTime*/
data.put("sectionID",1L);
data.put("requestTime",System.currentTimeMillis());
this.messageSender.sendMsg("section1","RCS_WCS_MAP_REQUEST",data);
return "OK";
}
}
package com.mushiny.controller;
import com.mushiny.service.PodService;
import com.mushiny.service.impl.PodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by Tank.li on 2017/7/3.
*/
@RestController
@RequestMapping(value="/heatdegree")
public class PodHeatDegreeController {
@Autowired
private PodService podService;
@RequestMapping("/pod2node")
public String computeTargetPosition(String podId, String sectionId) {
return podService.computeTargetAddress(podId,sectionId);
}
}
This diff is collapsed.
package com.mushiny.jdbc.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.Environment;
import javax.sql.DataSource;
/**
* Created by Tank.li on 2017/6/13.
*/
@Configuration
@ImportResource(locations={"classpath:sql.xml"})
public class JdbcConfig {
@Autowired
private Environment env;
@Bean
public DataSource dataSource() {
System.out.println("in init datasource");
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名
dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码
dataSource.setInitialSize(2);
dataSource.setMaxActive(20);
dataSource.setMinIdle(0);
dataSource.setMaxWait(60000);
dataSource.setValidationQuery("SELECT 1");
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(true);
dataSource.setPoolPreparedStatements(false);
return dataSource;
}
}
package com.mushiny.jdbc.config;
import java.util.Properties;
/**
* Created by Tank.li on 2017/6/13.
*/
public class SqlMapper {
private Properties sqls;
public Properties getSqls() {
return sqls;
}
public void setSqls(Properties sqls) {
this.sqls = sqls;
}
}
package com.mushiny.jdbc.domain;
/**
* Created by Tank.li on 2017/6/13.
*/
public abstract class BaseParam implements IParam {
//定义的java.sql.Types.***类型,为空的话,默认返回字符串
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
//无参数构造函数 默认为字符串
public BaseParam() {
this.type = java.sql.Types.CHAR;
}
/**
* 构造不同的返回类型,java.sql.Types定义了格式
*
* @param type java.sql.Types 里头定义的类型格式
*/
public BaseParam(int type) {
this.type = type;
}
private int index;
private Object value;
@Override
public int getIndex() {
return index;
}
@Override
public void setIndex(int index) {
this.index = index;
}
@Override
public Object getValue() {
return value;
}
@Override
public void setValue(Object value) {
this.value = value;
}
@Override
public String toString() {
return "index:"+index+" value:"+value;
}
}
package com.mushiny.jdbc.domain;
import java.sql.CallableStatement;
/**
* Created by Tank.li on 2017/6/13.
*/
public interface IParam {
/**
* 索引值
* @param index
*/
void setIndex(int index);
/**
* 参数
* @param value
*/
void setValue(Object value);
/**
* 返回值
* @return
*/
Object getValue();
/**
* 返回索引
* @return
*/
int getIndex();
//注册参数//入参与返回参数注册方式不一样
/**
* 设置参数
* @param callableStatement
*/
void registerParam(CallableStatement callableStatement);
}
package com.mushiny.jdbc.domain;
import java.sql.CallableStatement;
import java.sql.SQLException;
/**
* Created by Tank.li on 2017/6/13.
*/
public class InOutParam extends BaseParam {
@Override
public void registerParam(CallableStatement callableStatement) {
try {
callableStatement.setObject(this.getIndex(),this.getValue(),this.getType());
callableStatement.registerOutParameter(this.getIndex(),this.getType());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.mushiny.jdbc.domain;
import java.sql.CallableStatement;
import java.sql.SQLException;
/**
* Created by Tank.li on 2017/6/13.
*/
public class InParam extends BaseParam {
@Override
public void registerParam(CallableStatement callableStatement) {
try {
callableStatement.setObject(this.getIndex(),this.getValue(),this.getType());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.mushiny.jdbc.domain;
import java.sql.CallableStatement;
import java.sql.SQLException;
/**
* Created by Tank.li on 2017/6/13.
*/
public class OutParam extends BaseParam {
@Override
public void registerParam(CallableStatement callableStatement) {
try {
callableStatement.registerOutParameter(this.getIndex(),this.getType());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.mushiny.jdbc.repositories;
import com.mushiny.beans.BaseObject;
import com.mushiny.comm.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Tank.li on 2017/9/23.
*/
public class BoPersister extends Thread {
private final static Logger logger = LoggerFactory.getLogger(BoPersister.class);
private JdbcRepository jdbcRepository;
public JdbcRepository getJdbcRepository() {
return jdbcRepository;
}
public void setJdbcRepository(JdbcRepository jdbcRepository) {
this.jdbcRepository = jdbcRepository;
}
public void persist(BaseObject baseObject) {
if (baseObject.getDelCon() != null && !baseObject.getDelCon().isEmpty()) {
//做删除操作
jdbcRepository.deleteRecords(baseObject.getTable(), baseObject.getDelCon());
} else if(baseObject.getId() == null //?
&& (baseObject.getCon()==null || baseObject.getCon().isEmpty())){
//新增操作
jdbcRepository.insertBusinessObject(baseObject);
}else {
//做更新操作
Map newValue = baseObject.getNewValue();
if (newValue == null || newValue.isEmpty()) {
//logger.debug("未做更新操作,表"+baseObject.getTable()+"的状态是空:"+newValue);
return;
}
CommonUtils.modifyUselessInfo(newValue);
Map con = new HashMap();
con.put(baseObject.getIdName(), baseObject.getId());
jdbcRepository.updateRecords(baseObject.getTable(), newValue, con);
baseObject.clearKV();
logger.debug("BO:" + baseObject.getTable() + "状态已刷新到数据库!" + baseObject.getActiveThread()+" "
+ baseObject.getIdName() + ":" + baseObject.getId());
}
}
@Override
public void run() {
BaseObject baseObject = null;
while((baseObject = jdbcRepository.getBo())!=null){
if (baseObject.getCon() == null) {
try {
persist(baseObject);
} catch (Throwable e) {
e.printStackTrace();
logger.error("persist(baseObject) fail:" + baseObject.getActiveThread()+" "
+baseObject.getTable() + " "+baseObject.getId()+" "+baseObject.getKv(),e);
}
}else {
//按条件批量更新
try {
this.jdbcRepository.updateRecords(baseObject.getTable(),
baseObject.getNewValue(),baseObject.getCon());
} catch (Throwable e) {
e.printStackTrace();
logger.error("updateRecords fail:" + baseObject.getActiveThread()+" "
+baseObject.getTable() + " "+baseObject.getNewValue()+" "+baseObject.getCon(),e);
}
}
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment