Explorar o código

[百岗WMS]AGV接口开发99

caosy hai 1 semana
pai
achega
b0219e8e88

+ 3 - 1
src/com/uas/mes/api/pda/PdaInMaterialController.java

@@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.io.IOException;
+
 /**
  * 原材料入库接口
  * @data  2016年12月21日 下午2:19:44
@@ -223,7 +225,7 @@ public class PdaInMaterialController extends BaseApiController {
 	}
 
 	@RequestMapping(value = "/agvreturn.action", method = RequestMethod.POST)
-	public ModelMap agvreturn(String barcode,String agvlocation){
+	public ModelMap agvreturn(String barcode,String agvlocation) throws IOException {
 		if (barcode == null||agvlocation==null) {
 			throw new APIErrorException(APIErrorCode.ILLEGAL_ARGUMENTS, "请勿传空数据");
 		}

+ 57 - 0
src/com/uas/mes/api/pda/PdaLocaTransController.java

@@ -1,5 +1,6 @@
 package com.uas.mes.api.pda;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -75,5 +76,61 @@ public class PdaLocaTransController extends BaseApiController{
 		pdaLocaTransService.whcodeTransfer(data, whcode);
 		
 	}
+
+
+	/**
+	 * 扫码式上架,采集条码号获取信息,并且点亮建议货架
+	 * @param code  条码号
+	 * @param single 是否单盘 1 表示单盘 ,0表示非单盘
+	 * @return
+	 */
+	@RequestMapping(value = "/scanGetBarData.action", method = RequestMethod.GET)
+	public ModelMap getBarDataScan(String code) throws IOException {
+		if (code == null) {
+			throw new APIErrorException(APIErrorCode.ILLEGAL_ARGUMENTS, "请传递必要的参数");
+		}
+		return success(pdaLocaTransService.scanGetBarData(code));
+	}
+
+	/**
+	 * 扫码式确认上架或者储位转移
+	 * @param code 条码号
+	 * @param location 储位编号
+	 * @param single 是否单盘 1 表示单盘 ,0表示非单盘
+	 * @param ifmix 是否允许混放 1 允许
+	 * @return
+	 */
+	@RequestMapping(value = "/scanConfirmTrans.action", method = RequestMethod.POST)
+	public ModelMap scanConfirmTrans(String code,String location) throws IOException {
+		if (null == code || null == location) {
+			throw new APIErrorException(APIErrorCode.ILLEGAL_ARGUMENTS, "请传递必要的参数");
+		}
+		return success(pdaLocaTransService.scanConfirmTrans(code,location));
+	}
+
+	/**
+	 * 结束上架
+	 */
+	@RequestMapping(value = "/scanEndTrans.action", method = RequestMethod.POST)
+	public ModelMap scanEndTrans() throws IOException {
+		return success(pdaLocaTransService.scanEndTrans());
+	}
+
+	/**
+	 * 查询仓位里面的物料和数量汇总
+	 * @param location
+	 * @return
+	 * @throws IOException
+	 */
+	@RequestMapping(value = "/getLocationProd.action", method = RequestMethod.GET)
+	public ModelMap getLocationProd() throws IOException {
+		return success(pdaLocaTransService.getLocationProd());
+	}
+
+
+	@RequestMapping(value = "/getagvcode.action", method = RequestMethod.GET)
+	public ModelMap getagvcode() throws IOException {
+		return success(pdaLocaTransService.getagvcode());
+	}
 	
 }

+ 32 - 0
src/com/uas/mes/api/pda/PdaOutMaterialController.java

@@ -438,4 +438,36 @@ public class PdaOutMaterialController extends BaseApiController {
 		return success(pdaOutMaterialService.endProdOut(id));
 	}
 
+
+
+	/**
+	 * AGV开始出库
+	 * @param id  多个出库单pi_id 逗号拼接
+	 * @return
+	 */
+	@RequestMapping(value="/startProdOutagv.action",method = RequestMethod.POST)
+	public ModelMap startProdOutagv(int id,String agvcode) throws IOException, ParserConfigurationException, TransformerException, InterruptedException {
+		return success(pdaOutMaterialService.startProdOutagv(id,agvcode));
+	}
+
+	/**
+	 * AGV结束出库灭灯
+	 * @param id
+	 * @return
+	 */
+	@RequestMapping(value="/endProdOutagv.action",method = RequestMethod.POST)
+	public ModelMap endProdOutagv(int id,String agvcode) throws IOException, ParserConfigurationException, TransformerException {
+		return success(pdaOutMaterialService.endProdOutagv(id,agvcode));
+	}
+
+	/**
+	 * AGV移动轨道
+	 * @param id
+	 * @return
+	 */
+	@RequestMapping(value="/deviceControlagv.action",method = RequestMethod.POST)
+	public ModelMap deviceControlagv(String agvcode) throws IOException, ParserConfigurationException, TransformerException {
+		return success(pdaOutMaterialService.deviceControlagv(agvcode));
+	}
+
 }

+ 3 - 3
src/com/uas/pda/dao/PdaCommonDao.java

@@ -40,15 +40,15 @@ public interface PdaCommonDao {
 
 	String turnEndCodingCommand(int id, int pbDetno) throws IOException, ParserConfigurationException, TransformerException;
 
-	String turnScanLocationON(String code, String emCode) throws IOException;
+	String turnScanLocationON(String code, String location) throws IOException;
 
 	String turnScanLocationOff(String code,String location,int ifcontinuous,String emCode) throws IOException;
 
 	String scanEndTransOff(String emCode) throws IOException;
 
-	String turnStartGYOutCommand(int id,String shelfcode) throws IOException; //感应式发送出库亮灯指令
+	String turnStartGYOutCommand(int id,String agvcode) throws IOException; //感应式发送出库亮灯指令
 
-	String turnStandByCommand(String shelfcode);
+	String turnStandByCommand(int id);
 
 
 }

+ 150 - 93
src/com/uas/pda/dao/impl/PdaCommonDaoImpl.java

@@ -1,33 +1,35 @@
 package com.uas.pda.dao.impl;
 
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.*;
-
 import com.uas.erp.core.BaseUtil;
 import com.uas.erp.core.HttpUtil;
-import com.uas.erp.core.TCPUtil;
-import jsx3.app.DOM;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Repository;
-
 import com.uas.erp.core.StringUtil;
+import com.uas.erp.core.TCPUtil;
 import com.uas.erp.core.exception.APIErrorException;
 import com.uas.erp.core.exception.APIErrorException.APIErrorCode;
 import com.uas.erp.dao.BaseDao;
 import com.uas.erp.dao.SqlRowList;
 import com.uas.erp.model.Page;
 import com.uas.pda.dao.PdaCommonDao;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Repository;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.*;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.*;
 
 @Repository("pdaCommonDaoImpl")
 public class PdaCommonDaoImpl implements PdaCommonDao {
@@ -362,7 +364,7 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 	/**
 	 * 扫码式出库条码采集灭灯
 	 * @param id
-	 * @param detno
+	 * @param
 	 * @return
 	 */
 	@Override
@@ -470,41 +472,56 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 
 
 	/**
-	 * 扫码式上架亮灯,建议仓位
+	 * AGV入库生成任务
 	 * @param code  条码号
-	 * @param emCode 操作人
+	 * @param location 起始位
 	 * @return
 	 */
 	@Override
-	public String turnScanLocationON(String code, String emCode)  {
+	public String turnScanLocationON(String code, String location)  {
 		SqlRowList rs = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode" +
-				" where pb_barcode=? and pb_inmancode=? and pb_inoutno='扫码式上架' and pb_type='扫码式'", code, emCode);
-		String type = null, shcode = null, ip = null, shnoaddress = null,color = null;
-		int level = 0, port = 0;
-		String da = createStringOfZeros(100);
+				" where pb_barcode =? and nvl(pb_ifget,0)=0 and pb_type='AGV入库' order by pb_detno ", code);
+		String type = null, shcode = null, ip = null, color = null;
+		int number = 0;
 		if (rs.hasNext()) {
 			while (rs.next()) {
-				if (rs.getCurrentIndex() == 0) {
-					shcode = rs.getString("pb_shelfcode");
-					shnoaddress = rs.getString("sh_noaddress");
-					level = rs.getInt("pb_level");
-					port = rs.getInt("sh_port");
-					ip = rs.getString("sh_ip");
-					color = colorcode(rs.getInt("pb_color"));
-				}
-				//拼接位置100个字符,将第几个位置的0替换掉,pb_levelnumber;
-				da = replaceCharacter(da, rs.getGeneralInt("pb_levelnumber"), '1');
-			}
-			//String reste = DengCommand(shnoaddress,ip,port,da);
-			String reste = "";
-			try {
-				reste = sendCodingCommand(shnoaddress, level, ip, port, da,color);
-			}catch (Exception e){
-				e.printStackTrace();
+				JSONObject jsonObject = new JSONObject();
+
+				// 添加基本字段
+				jsonObject.put("reqCode", baseDao.getSeqId("agv_seq"));
+				jsonObject.put("taskCode", rs.getString("pb_id"));
+				jsonObject.put("taskTyp", "RK");
+				jsonObject.put("ctnrTyp", "1");
+				jsonObject.put("ctnrCode", rs.getString("pb_barcode"));
+
+				// 创建positionCodePath数组
+				JSONArray positionCodePathArray = new JSONArray();
+
+				// 创建第一个positionCodePath对象并添加到数组
+				JSONObject positionCodePath1 = new JSONObject();
+				positionCodePath1.put("positionCode",location);
+				positionCodePath1.put("type", "00");
+				positionCodePathArray.put(positionCodePath1);
+
+				// 创建第二个positionCodePath对象并添加到数组
+				JSONObject positionCodePath2 = new JSONObject();
+				positionCodePath2.put("positionCode", rs.getString("pb_location"));
+				positionCodePath2.put("type", "00");
+				positionCodePathArray.put(positionCodePath2);
+
+				// 将positionCodePath数组添加到外层JSONObject
+				jsonObject.put("positionCodePath", positionCodePathArray);
+				ip = rs.getString("sh_ip");
+				// 打印JSON字符串
+				System.out.println(jsonObject.toString()); // 使用4个空格进行缩进
+				sendTurnOnOutCommand(ip,"rcms/services/rest/hikRpcService/genAgvSchedulingTask",jsonObject.toString());
 			}
-			reste = "点亮"+reste;
+
+			String reste = rs.getString("pb_location");
 			return reste;
 		}
+
+		//sendGYOUTCommand
 		return null;
 	}
 
@@ -546,30 +563,35 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 		return null;
 	}
 
+    /*
+    AGV根据人员取消入库任务
+     */
 	@Override
 	public String scanEndTransOff(String emCode) throws IOException {
 		SqlRowList rs = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode" +
-				" where pb_inmancode=? and pb_inoutno='扫码式上架' and pb_type='扫码式'", emCode);
-		String type = null, shcode = null, ip = null, shnoaddress = null,color = null;
-		int level = 0, port = 0;
-		String da = createStringOfZeros(100);
-		String reste="";
-		if(rs.hasNext()) {
+				" where pb_inoutno='AGV入库' and nvl(pb_ifget,0)=0 and pb_inmancode=? order by pb_detno ", emCode);
+		String type = null, shcode = null, ip = null, color = null;
+		int number = 0;
+		if (rs.hasNext()) {
 			while (rs.next()) {
-				shcode = rs.getString("pb_shelfcode");
-				shnoaddress = rs.getString("sh_noaddress");
-				level = rs.getInt("pb_level");
-				port = rs.getInt("sh_port");
-				ip = rs.getString("sh_ip");
-				color = colorcode(rs.getInt("pb_color"));
+				JSONObject jsonObject = new JSONObject();
+
+				// 添加基本字段
+				jsonObject.put("reqCode", baseDao.getSeqId("agv_seq"));
+				jsonObject.put("taskCode", rs.getString("pb_id"));
+				jsonObject.put("forceCancel", "1");
+				jsonObject.put("matterArea", rs.getString("pb_location"));
+
+				// 打印JSON字符串
+				System.out.println(jsonObject.toString()); // 使用4个空格进行缩进
+				sendTurnOnOutCommand(ip,"rcms/services/rest/hikRpcService/cancelTask",jsonObject.toString());
 			}
-			//String reste = DengCommand(shnoaddress,ip,port,da);
-			String reste1 = sendCodingCommand(shnoaddress, level, ip, port, da, color);
-			//灭一个删一个数据
-			reste = StringUtil.hasText(reste)?reste+"," + reste1:reste+reste1;
-			reste = "结束上架,灭灯"+reste;
+
+			String reste = "料架号:"+shcode+",位置:"+",点亮";
 			return reste;
 		}
+
+		//sendGYOUTCommand
 		return null;
 	}
 
@@ -604,30 +626,51 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 	}
 
 	/**
-	 * 感应式出库点亮发送指令
+	 * AGV出库发送指令
 	 * @param id 出库单Id 一次性全部点亮
-	 * @param shelfcode 料架编号
+	 * @param agvcode AGV编号
 	 */
 	@Override
-	public String turnStartGYOutCommand(int id,String shelfcode) throws IOException {
+	public String turnStartGYOutCommand(int id,String agvcode) throws IOException {
 		SqlRowList rs = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode" +
-				" where pb_piid =? and nvl(pb_ifget,0)=0 and pb_type='感应式' and pb_shelfcode=?", id, shelfcode);
+				" where pb_piid =? and nvl(pb_ifget,0)=0 and pb_type='AGV' order by pb_detno ", id);
 		String type = null, shcode = null, ip = null, color = null;
 		int number = 0;
-		ArrayList<Integer> positions = new ArrayList<>();
 		if (rs.hasNext()) {
 			while (rs.next()) {
-				if (rs.getCurrentIndex() == 0) {
-					shcode = rs.getString("pb_shelfcode");
-					number = rs.getInt("pb_number");//在整个料架的第几个位置
-					ip = rs.getString("sh_ip");
-					color = colorcode(rs.getInt("pb_color"));
-				}
-				//拼接位置100个字符,将第几个位置的0替换掉,pb_levelnumber;
-				positions.add(number-1);
+				JSONObject jsonObject = new JSONObject();
+
+				// 添加基本字段
+				jsonObject.put("reqCode", baseDao.getSeqId("agv_seq"));
+				jsonObject.put("taskCode", rs.getString("pb_id"));
+				jsonObject.put("taskTyp", "CK");
+				jsonObject.put("ctnrTyp", "1");
+				jsonObject.put("ctnrCode", rs.getString("pb_barcode"));
+
+				// 创建positionCodePath数组
+				JSONArray positionCodePathArray = new JSONArray();
+
+				// 创建第一个positionCodePath对象并添加到数组
+				JSONObject positionCodePath1 = new JSONObject();
+				positionCodePath1.put("positionCode", rs.getString("pb_location"));
+				positionCodePath1.put("type", "00");
+				positionCodePathArray.put(positionCodePath1);
+
+				// 创建第二个positionCodePath对象并添加到数组
+				JSONObject positionCodePath2 = new JSONObject();
+				positionCodePath2.put("positionCode", agvcode);
+				positionCodePath2.put("type", "00");
+				positionCodePathArray.put(positionCodePath2);
+
+				// 将positionCodePath数组添加到外层JSONObject
+				jsonObject.put("positionCodePath", positionCodePathArray);
+
+				// 打印JSON字符串
+				System.out.println(jsonObject.toString()); // 使用4个空格进行缩进
+				sendTurnOnOutCommand(ip,"rcms/services/rest/hikRpcService/genAgvSchedulingTask",jsonObject.toString());
 			}
-			String reste = sendTurnOnOutCommand(ip,positions,color);
-			reste = "料架号:"+shcode+",位置:"+",点亮"+reste;
+
+			String reste = "料架号:"+shcode+",位置:"+",点亮";
 			return reste;
 		}
 
@@ -636,23 +679,22 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 	}
 
 	/**
-	 * 感应式出库亮灯
+	 * AGV指令发送
 	 * @param ip
-	 * @param positions
-	 * @param color
+	 * @param message
 	 * @return
 	 */
-	private String sendTurnOnOutCommand(String ip,ArrayList <Integer> positions,String color )  {
+	private String sendTurnOnOutCommand(String ip,String method,String message )  {
 		/**{
 		 "Action": 2,
 		 "Positions": [4,5,6],
 		 "Color":6
 		 }*/
-		Map<String,String> map = new HashMap<>();
-		map.put("Action","2");
-		map.put("Positions",positions.toString());
+//		Map<String,String> map = new HashMap<>();
+//		map.put("Action","2");
+//		map.put("Positions",positions.toString());
 		try {
-			HttpUtil.Response response = HttpUtil.sendPostRequest("http://" +ip+"/TurnOn",map);
+			HttpUtil.Response response = HttpUtil.doPost("http://" +ip+"/"+method,message,false,null);
 			/*{ Succeed : true, Code : 0, Message : “已切换为出库模式。” }
 			{ Succeed : false, Code : 10, Message : "失败:Token 错误。"}
 			{ Succeed : false, Code : 50, Message : “失败:设备仍在执行作业。” }
@@ -667,11 +709,12 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 			}else{
 				String res = response.getResponseText();
 				Map<Object, Object> resMap = BaseUtil.parseFormStoreToMap(res);
-				if(Boolean.valueOf(resMap.get("Succeed").toString())){
-					return "成功";
-				}else{
-					return resMap.get("Message").toString();
-				}
+//				if(Boolean.valueOf(resMap.get("message").toString())){
+//					return "成功";
+//				}else{
+//					return resMap.get("message").toString();
+//				}
+				return resMap.get("message").toString();
 			}
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -679,22 +722,36 @@ public class PdaCommonDaoImpl implements PdaCommonDao {
 		}
 	}
 	/**
-	 * 恢复待机模式
-	 * @param shelfcode
+	 * 取消AGV出库任务
+	 * @param id
 	 * @return
 	 */
 	@Override
-	public String turnStandByCommand(String  shelfcode) {
-		SqlRowList rs = baseDao.queryForRowSet("select sh_ip from shelf where sh_code=?",shelfcode);
-		if (rs.next()) {
+	public String turnStandByCommand(int  id) {
+		SqlRowList rs = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode" +
+				" where pb_piid =? and nvl(pb_ifget,0)=0 and pb_type='AGV' order by pb_detno ", id);
+		String type = null, shcode = null, ip = null, color = null;
+		int number = 0;
+		if (rs.hasNext()) {
+			while (rs.next()) {
+				JSONObject jsonObject = new JSONObject();
 
-		/*恢复调用/Standby
-		{ Succeed : true, Code : 0, Message : “已切换为待机模式。” }
-		{ Succeed : false, Code : 10, Message : "失败:Token 错误。"}
-		{ Succeed : false, Code : 20, Message : “失败:当前有未修正的错误。” }
-		{ Succeed : false, Code : 21, Message : “失败:当前有未完成的作业。” }*/
-			return null;
+				// 添加基本字段
+				jsonObject.put("reqCode", baseDao.getSeqId("agv_seq"));
+				jsonObject.put("taskCode", rs.getString("pb_id"));
+				jsonObject.put("forceCancel", "1");
+				jsonObject.put("matterArea", rs.getString("pb_location"));
+
+				// 打印JSON字符串
+				System.out.println(jsonObject.toString()); // 使用4个空格进行缩进
+				sendTurnOnOutCommand(ip,"rcms/services/rest/hikRpcService/cancelTask",jsonObject.toString());
+			}
+
+			String reste = "料架号:"+shcode+",位置:"+",点亮";
+			return reste;
 		}
+
+		//sendGYOUTCommand
 		return null;
 	}
 

+ 2 - 1
src/com/uas/pda/service/PdaInMaterialService.java

@@ -1,5 +1,6 @@
 package com.uas.pda.service;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -38,6 +39,6 @@ public interface PdaInMaterialService {
 	String  agvuplocation(String barcode,String location);
 
 
-	String agvreturn(String barcode,String agvlocation);
+	String agvreturn(String barcode,String agvlocation) throws IOException;
 
 }

+ 12 - 0
src/com/uas/pda/service/PdaLocaTransService.java

@@ -1,5 +1,7 @@
 package com.uas.pda.service;
 
+import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 public interface PdaLocaTransService {
@@ -11,4 +13,14 @@ public interface PdaLocaTransService {
 	Map<String, Object> getCodeWhcode(String code, String type);
 
 	void whcodeTransfer(String data, String whcode);
+
+	Map<String,Object> scanGetBarData(String code) throws IOException;
+
+	Map<String,Object>  scanConfirmTrans(String code,String location) throws IOException;
+
+	String scanEndTrans() throws IOException;
+
+	List<Map<String, Object>> getLocationProd();
+
+	List<Map<String, Object>> getagvcode();
 }

+ 7 - 0
src/com/uas/pda/service/PdaOutMaterialService.java

@@ -73,4 +73,11 @@ public interface PdaOutMaterialService {
 	String endProdOut(int id) throws IOException, ParserConfigurationException, TransformerException;
 
 
+	Map<String, Object> startProdOutagv(int id,String agvcode) throws IOException, ParserConfigurationException, TransformerException, InterruptedException;
+
+	String endProdOutagv(int id,String agvcode) throws IOException, ParserConfigurationException, TransformerException;
+
+	String deviceControlagv(String agvcode) throws IOException, ParserConfigurationException, TransformerException;
+
+
 }

+ 15 - 4
src/com/uas/pda/service/impl/PdaInMaterialServiceImpl.java

@@ -11,9 +11,11 @@ import com.uas.erp.dao.SqlRowList;
 import com.uas.erp.service.scm.ProdInOutService;
 import com.uas.pda.dao.PdaCommonDao;
 import com.uas.pda.service.PdaInMaterialService;
+import com.uas.pda.service.PdaLocaTransService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -29,6 +31,10 @@ public  class PdaInMaterialServiceImpl implements PdaInMaterialService {
 	@Autowired
 	private ProdInOutService prodInOutService;
 
+	@Autowired
+	private PdaLocaTransService pdaLocaTransService;
+
+
 	/**
 	 * 针对输入的入库单号,和仓库进行模糊查询
 	 */
@@ -875,18 +881,23 @@ public  class PdaInMaterialServiceImpl implements PdaInMaterialService {
 	public String agvuplocation(String barcode, String location) {
 		SqlRowList rs = baseDao.queryForRowSet("select * from barcode left join product on pr_code = bar_prodcode where bar_code = ? and bar_status = 1",barcode);
 		if (!rs.next())
-			throw new APIErrorException(APIErrorCode.DATA_NOT_FOUND,"条码"+barcode+"不存在");
+			throw new APIErrorException(APIErrorCode.DATA_NOT_FOUND,"条码"+barcode+"不存在或已经出库");
 		if(baseDao.checkIf("productlocation","pl_code = '"+location+"' and pl_type is not null ")
 				&baseDao.checkIf("barcode","bar_location = '"+location+"' and bar_status = '1' "))
 		{
 			throw new APIErrorException(APIErrorCode.DATA_NOT_FOUND,"存在条码属于仓位:"+location);
 		}
+		baseDao.execute("delete PRODOUTPREBAR where pb_barcode = ? and pb_type = 'AGV入库'",barcode);
 		baseDao.execute("update barcode set bar_location = ? where bar_code = ?",location,barcode);
-		return null;
+		return "条码:"+barcode+"上架仓位:"+location+"成功";
 	}
 
 	@Override
-	public String agvreturn(String barcode, String agvlocation) {
-		return null;
+	public String agvreturn(String barcode, String agvlocation) throws IOException {
+		SqlRowList rs = baseDao.queryForRowSet("select * from barcode left join product on pr_code = bar_prodcode where bar_code = ? and bar_status = 1",barcode);
+		if (!rs.next())
+			throw new APIErrorException(APIErrorCode.DATA_NOT_FOUND,"条码"+barcode+"不存在或已经出库");
+		Map<String, Object> map = pdaLocaTransService.scanConfirmTrans(barcode,agvlocation);
+		return map.get("log").toString();
 	}
 }

+ 137 - 9
src/com/uas/pda/service/impl/PdaLocaTransServiceImpl.java

@@ -1,25 +1,31 @@
 package com.uas.pda.service.impl;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import com.uas.erp.core.BaseUtil;
 import com.uas.erp.core.FlexJsonUtil;
+import com.uas.erp.core.StringUtil;
 import com.uas.erp.core.exception.APIErrorException;
 import com.uas.erp.core.exception.APIErrorException.APIErrorCode;
+import com.uas.erp.core.support.SystemSession;
 import com.uas.erp.dao.BaseDao;
 import com.uas.erp.dao.SqlRowList;
+import com.uas.pda.dao.PdaCommonDao;
 import com.uas.pda.service.PdaLocaTransService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @Service("pdaLocaTransService")
 public class PdaLocaTransServiceImpl implements PdaLocaTransService{
 	@Autowired
 	private BaseDao baseDao;
+	@Autowired
+	private PdaCommonDao pdaCommonDao;
     
 	@Override
 	public Map<String, Object> getCodeData(String whcode, String code,
@@ -142,6 +148,128 @@ public class PdaLocaTransServiceImpl implements PdaLocaTransService{
 		}		
 		baseDao.execute(sqls);
 	}
-	
+
+	/**
+	 * AGV入库获取条码信息
+	 * @param code 条码号
+	 * @return
+	 */
+	@Override
+	public Map<String, Object> scanGetBarData(String code) throws IOException {
+		//先将这个人+这个条码+与目前(单盘或者非单盘属性不一致)的灯先熄灭,再重新操作?
+		SqlRowList rs = baseDao.queryForRowSet("select bar_prodcode,pr_detail,pr_spec,pr_orispeccode,bar_location," +
+				" bar_code,bar_remain,bar_whcode,pr_location,bar_outboxcode1 "+
+				" from barcode left join product on pr_code=bar_prodcode where (bar_code=?) and nvl(bar_status,0)=1",code);
+		if(rs.next()){
+			//建议仓位:只提供一个
+			//判断是否是箱号:如果是箱号的话,则不允许上单盘货架
+			Map<String, Object>  map =  new HashMap<>();
+			{
+				map = rs.getCurrentMap();
+				map.put("TYPE","条码号");
+			}
+			//插入到 prodoutprebar 单号为:pb_inoutno 扫码上架 pb_barcode,条码,人
+			SqlRowList rs1 = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode " +
+					" where pb_barcode=? and nvl(pb_ifget,0)=0 ",code);
+			if(rs1.next()){
+				throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"条码:"+code+"已存在正在执行的入库出库任务");
+			}
+			return map;
+		}else {
+			throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"条码不存在库存中");
+		}
+	}
+
+	/**
+	 * AGV上架发起任务单
+	 * @param code 条码号
+	 * @param location 储位编号
+	 * @return
+	 */
+	@Transactional
+	@Override
+	public Map<String, Object> scanConfirmTrans(String code,String location) throws IOException {
+		SqlRowList rs = baseDao.queryForRowSet("select bar_prodcode,pr_detail,pr_spec,pr_orispeccode,bar_location," +
+				" bar_code,bar_remain,bar_whcode,pr_location,bar_outboxcode1 "+
+				" from barcode left join product on pr_code=bar_prodcode where (bar_code=?) and nvl(bar_status,0)=1",code);
+		if(rs.next()){
+			String type ="";
+
+			SqlRowList rs1 = baseDao.queryForRowSet("select * from prodoutprebar left join shelf on sh_code=pb_shelfcode " +
+					" where pb_barcode=? and nvl(pb_ifget,0)=0 ",code);
+			if(rs1.next()){
+				throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"条码:"+code+"已存在正在执行的入库出库任务");
+			}
+			type  = "条码";
+
+			//判断仓位是否在仓位资料中存在
+			 rs1 = baseDao.queryForRowSet("select *  from Shelf where sh_code=? and sh_type in( 'AGV入库','AGV出库') ",location);
+			if(!rs1.next()){
+				throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"仓位:"+location+"不属于AGV出入库点位,不允许操作");
+			}
+            String em_code = null;
+			try
+			{
+				em_code = SystemSession.getUser().getEm_code();
+			}catch(Exception exception) {
+				em_code = "WUYX";
+			}
+
+			String err = baseDao.callProcedure("SP_SCANTRANSGETLOCATION",code,em_code );
+			if(null !=err){
+				throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,err);
+			}
+			String er = pdaCommonDao.turnScanLocationON(code, location);
+
+			Map<String, Object> map = new HashMap<>();
+			map.put("log", "条码:" + code + ",上架到仓位:" + er + "发送任务单");
+
+			return map;
+		}else {
+			throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"条码不存在库存中");
+		}
+	}
+
+	/**
+	 * 清除当前人员发起的AGV入库任务单
+	 * @return
+	 */
+	@Override
+	public String scanEndTrans() throws IOException {
+		//将当前登录人上架灯全部熄灭
+		String er = pdaCommonDao.scanEndTransOff(SystemSession.getUser().getEm_code());
+		//删除
+		baseDao.execute("delete from prodoutprebar where pb_inoutno='AGV入库' and pb_inmancode=?",SystemSession.getUser().getEm_code());
+		return er;
+	}
+
+	/**
+	 * 获取当前人员AGV入库任务单
+	 * @return
+	 */
+	@Override
+	public List<Map<String, Object>> getLocationProd() {
+			SqlRowList	rs = baseDao.queryForRowSet("select pb_barcode,pb_location,pb_prodcode,pr_detail,pr_spec  from PRODOUTPREBAR left join product on pr_code=pb_prodcode" +
+					" where pb_inman = ? and pb_inoutno='AGV入库' order by pb_id asc ",SystemSession.getUser().getEm_name());
+			if (rs.hasNext()) {
+				return rs.getResultList();
+			} else {
+				throw new APIErrorException(APIErrorCode.BUSINESS_FAILED, "人员:" + SystemSession.getUser().getEm_name() + "目前无入库任务!");
+			}
+
+	}
+
+	@Override
+	public List<Map<String, Object>> getagvcode() {
+		SqlRowList	rs = baseDao.queryForRowSet("select sh_code  from Shelf " +
+				" where sh_type = 'AGV出库' order by sh_code desc ");
+		if (rs.hasNext()) {
+			return rs.getResultList();
+		} else {
+			return null;
+		}
+
+	}
+
 
 }

+ 82 - 6
src/com/uas/pda/service/impl/PdaOutMaterialServiceImpl.java

@@ -1972,9 +1972,10 @@ public class PdaOutMaterialServiceImpl implements PdaOutMaterialService {
 		SqlRowList rs0 = baseDao.queryForRowSet("select * from (select pb_detno,pb_type,max(pb_color)pb_color,pb_shelfcode from prodoutprebar where pb_piid =? and nvl(pb_ifget,0)=0 group by pb_detno,pb_type,pb_shelfcode) order by pb_detno",id);
 		if(rs0.hasNext()) {
 			while (rs0.next()) {
-				if("AGV".equals(rs0.getString("pb_type"))){
-					str = pdaCommonDao.turnStartGYOutCommand(id,rs0.getString("pb_shelfcode"));
-				}else if("扫码式".equals(rs0.getString("pb_type"))){
+//				if("AGV".equals(rs0.getString("pb_type"))){
+//					str = pdaCommonDao.turnStartGYOutCommand(id,rs0.getString("pb_shelfcode"));
+//				}else
+				if("扫码式".equals(rs0.getString("pb_type"))){
 					str = pdaCommonDao.turnStartCodingCommand(id,rs0.getInt("pb_detno"));
 				}
 				returnStr.append(str).append(",");
@@ -2001,9 +2002,10 @@ public class PdaOutMaterialServiceImpl implements PdaOutMaterialService {
 		SqlRowList rs0 = baseDao.queryForRowSet("select * from (select pb_detno,pb_type,pb_shelfcode from prodoutprebar where pb_piid =? and nvl(pb_ifget,0)=0 group by pb_detno,pb_type,pb_shelfcode) order by pb_detno",id);
 		if(rs0.hasNext()) {
 			while (rs0.next()) {
-				if("AGV".equals(rs0.getString("pb_type"))){
-					str = pdaCommonDao.turnStandByCommand(rs0.getString("pb_shelfcode"));
-				}else if("扫码式".equals(rs0.getString("pb_type"))){
+//				if("AGV".equals(rs0.getString("pb_type"))){
+//					str = pdaCommonDao.turnStandByCommand(rs0.getString("pb_shelfcode"));
+//				}else
+				if("扫码式".equals(rs0.getString("pb_type"))){
 					str = pdaCommonDao.turnEndCodingCommand(id,rs0.getInt("pb_detno"));
 				}
 				returnStr.append(str).append(",");
@@ -2016,6 +2018,80 @@ public class PdaOutMaterialServiceImpl implements PdaOutMaterialService {
 		return "已经结束出库亮灯!";
 	}
 
+	@Override
+	public Map<String, Object> startProdOutagv(int id, String agvcode) throws IOException, ParserConfigurationException, TransformerException, InterruptedException {
+		//先结束上次的出库
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+		Date date = new Date();
+		String currentTime = sdf.format(date);
+		//System.out.println("当前时间begin(毫秒):" + currentTime);
+		endProdOutagv(id,agvcode);
+		date = new Date();
+		currentTime = sdf.format(date);
+		//System.out.println("当前时间end(毫秒):" + currentTime);
+		//根据出库单需要出库的物料+仓库,查找对应的barcode 找到对应的货架+位置 发送指令请求进行点亮
+
+		//String err = baseDao.callProcedure("SP_OUTSTARTPREBAR",id,SystemSession.getUser().getEm_code());  这个记得还原
+		String err = baseDao.callProcedure("SP_OUTSTARTPREBAR",id,"WUYX");
+
+		if(null !=err){
+			throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"该出库单预抓取条码失败,无法点亮料架备料!"+err);
+		}
+		String str = null;
+		StringBuffer returnStr = new StringBuffer();
+		SqlRowList rs0 = baseDao.queryForRowSet("select *  from prodoutprebar where pb_piid =? and nvl(pb_ifget,0)=0  and pb_type = 'AGV' order by pb_detno",id);
+		if(rs0.hasNext()) {
+//			while (rs0.next()) {
+//				if("AGV".equals(rs0.getString("pb_type"))){
+					str = pdaCommonDao.turnStartGYOutCommand(id,agvcode);
+//				}
+//				if("扫码式".equals(rs0.getString("pb_type"))){
+//					str = pdaCommonDao.turnStartCodingCommand(id,rs0.getInt("pb_detno"));
+//				}
+				returnStr.append(str).append(",");
+//			}
+			//System.out.println("当前时间end2(毫秒):" + currentTime);
+			Map<String,Object> map = new HashMap<>();
+			map.put("log",returnStr.toString());
+			try{
+				map.put("next",getNextByBatchDeal(String.valueOf(id)));	//提示用户下一条采集数据
+			}
+			catch (Exception e) {
+				map.put("next", null);
+			}
+			return map;
+		}else{
+			throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"该出库单预抓取条码未抓取到AGV条码,无需发起任务!");
+		}
+	}
+
+	@Override
+	public String endProdOutagv(int id, String agvcode) throws IOException, ParserConfigurationException, TransformerException {
+		String str = null;
+		StringBuffer returnStr = new StringBuffer();
+		SqlRowList rs0 = baseDao.queryForRowSet("select *  from prodoutprebar where pb_piid =? and nvl(pb_ifget,0)=0  and pb_type = 'AGV' order by pb_detno",id);
+		if(rs0.hasNext()) {
+//			while (rs0.next()) {
+				if("AGV".equals(rs0.getString("pb_type"))){
+					str = pdaCommonDao.turnStandByCommand(id);
+				}
+				returnStr.append(str).append(",");
+			baseDao.execute("delete from prodoutprebar where pb_piid=?",id);
+			return "已删除任务!";
+		}/*else{
+			throw new APIErrorException(APIErrorCode.BUSINESS_FAILED,"该出库单预抓取条码未抓取到智能料架机条码,无需点亮料架备料!");
+		}*/
+		return "已删除任务!";
+	}
+
+	/**
+	 * AGV轨道控制
+	 */
+	@Override
+	public String deviceControlagv(String agvcode) throws IOException, ParserConfigurationException, TransformerException {
+		return null;
+	}
+
 
 	/**
 	 * 扫码式,扫条码出库传递灭灯,重新点亮指令