Forráskód Böngészése

售货机 推货和推送

xubh 4 éve
szülő
commit
cb90f2d98d

+ 2 - 5
src/main/java/com/minpay/common/action/VendingMachineAction.java

@@ -139,7 +139,7 @@ public class VendingMachineAction implements IMINAction {
 
 			restList.add(imeiAddr);     //机台号
 			restList.add("|");
-			restList.add(orderNo);	//订单号
+			restList.add(deliveryNo);	//订单号
 			restList.add("]");
 			restList.add("(bFA 00 06 00 24");
 			String cargoNo16 = DataUtil.str10ToStr16(Integer.valueOf(cargoNo));
@@ -153,16 +153,13 @@ public class VendingMachineAction implements IMINAction {
 				code = Service.lookup(IClientService.class).sendMsg(param, imeiAddr);
 				if(!"200".equals(code)){
 					returnData.put("code", code);
-					vpn.setCargoState("01");
 					returnData.put("msg", "推货失败");
 				}else{
 					vpn.setState("00");
-					vpn.setCargoState("00");
 					returnData.put("code", code);
 					returnData.put("msg", "推货成功");
 				}
 			} catch (Exception e) {
-				vpn.setCargoState("01");
 				returnData.put("code", "999");
 				returnData.put("msg", "推货失败");
 			}
@@ -176,7 +173,7 @@ public class VendingMachineAction implements IMINAction {
 			vpn.setFlowno(flowno);
 			vpn.setImeiAddr(imeiAddr);
 			vpn.setCargono(cargoNo);
-
+			vpn.setCargoState("02");
 			vpn.setCreateTime(DateUtil.getCurrentDateTimeString());
 			vpn.setModifyTime(DateUtil.getCurrentDateTimeString());
 			vpn.setDeliveryno(deliveryNo);

+ 2 - 0
src/main/java/com/minpay/common/constant/ShConstant.java

@@ -17,6 +17,8 @@ public class ShConstant implements IMINBusinessConstant{
 	static final public String SIGNAL = "y";
 	/**售货机反馈*/
 	static final public String FEEDBACK = "a";
+	/**服务端收到反馈后发送确认指令*/
+	static final public String 		Q = "q";
 	/**服务器返回心跳*/
 	static final public String BACK_HEARTBEAT = "b";
 	/**设备正常*/

+ 2 - 1
src/main/java/com/minpay/common/service/IVendingMachineService.java

@@ -35,8 +35,9 @@ public interface IVendingMachineService extends IMINLocalService {
 	 * @param strArr
 	 * @param im
 	 * @throws MINBusinessException
+     * @return
 	 */
-	void dropGoods(String[] strArr, String im) throws MINBusinessException;
+	Map<String, String> dropGoods(String[] strArr, String im) throws MINBusinessException;
 
 	/**
 	 * 推送温度回调

+ 5 - 0
src/main/java/com/minpay/common/service/impl/ClientServiceImpl.java

@@ -64,6 +64,11 @@ public class ClientServiceImpl implements IClientService {
 		}else if(ShConstant.SIGNAL.equals(action)){
 			Map<String, String> runData = Service.lookup(IVendingMachineService.class).signal(strArr, im);
 			cr.setParam(runData.get("runData"));
+			/**推货成功*/
+		}else if(ShConstant.FEEDBACK.equals(action)){
+			Log.debug("================收到推送货物成功消息:".concat(param));
+			Map<String, String> runData =  Service.lookup(IVendingMachineService.class).dropGoods(strArr, im);
+			cr.setParam(runData.get("runData"));
 		}
 
 		//String[] strArr = DataUtil.strToArr(param);

+ 73 - 77
src/main/java/com/minpay/common/service/impl/VendingMachineServiceImpl.java

@@ -10,19 +10,13 @@ import com.min.util.CommonUtil;
 import com.min.util.DateUtil;
 import com.minpay.common.constant.ShConstant;
 import com.minpay.common.service.IVendingMachineService;
-import com.minpay.common.util.DataUtil;
 import com.minpay.common.util.HttpPost;
 import com.minpay.db.table.mapper.VmDeliveryInfMapper;
 import com.minpay.db.table.mapper.VmEquipmentInfMapper;
 import com.minpay.db.table.mapper.VmOrderDetailsMapper;
 import com.minpay.db.table.mapper.VmProEquRelMapper;
 import com.minpay.db.table.mapper.VmPushNewsMapper;
-import com.minpay.db.table.model.VmDeliveryInf;
-import com.minpay.db.table.model.VmEquipmentInf;
-import com.minpay.db.table.model.VmEquipmentInfExample;
-import com.minpay.db.table.model.VmOrderDetails;
-import com.minpay.db.table.model.VmProEquRel;
-import com.minpay.db.table.model.VmPushNews;
+import com.minpay.db.table.model.*;
 import com.minpay.db.table.own.mapper.MachineMapper;
 import com.startup.minpay.frame.exception.MINBusinessException;
 import com.startup.minpay.frame.service.base.IMINDataBaseService;
@@ -207,85 +201,88 @@ public class VendingMachineServiceImpl implements IVendingMachineService {
 	 * 掉货回调
 	 */
 	@Override
-	public void dropGoods(String[] strArr,String imeiAddr) throws MINBusinessException {
-		if(!CommonUtil.isEmpty(imeiAddr)){
-			//货道号
-			String cargoNo = strArr[3];
-			//推货状态
-			String cargoState = strArr[4];
-			Map<String, String> map = new HashMap<String, String>();
-			map.put("state", "00");
-			map.put("cargoNo", cargoNo);
-			map.put("type", "00");
-			map.put("imeiAddr", imeiAddr);
-			map.put("pushType", "00");
-			
-			//查询收到的推货信息 最近的
-			List<Map<String, String>> pnList = Service.lookup(IMINDataBaseService.class)
-														.getMybatisMapper(MachineMapper.class)
-														.queryMaxPushNews(map);
-			if(pnList.size() > 0){
-				//获取消息
-				Map<String, String> pushNewsMap = pnList.get(0);					
-				String deliveryno = pushNewsMap.get("deliveryno");
-				
-				/**根据推货编号 修改商品库存 和 推货表状态*/
-				//查询推货详情
-				VmDeliveryInf vdi = Service.lookup(IMINDataBaseService.class)
-											.getMybatisMapper(VmDeliveryInfMapper.class)
-											.selectByPrimaryKey(deliveryno);
-				if("00".equals(cargoState)){ //出货正常
-					// 提货状态:0未出货1部分出货2已出货3卡货4清零5处理中
-					vdi.setStatus("1");
-					//订单详情编号
-					String orddetid = vdi.getOrdDetId();
-					//查询订单详情
-					VmOrderDetails vod = Service.lookup(IMINDataBaseService.class)
-												.getMybatisMapper(VmOrderDetailsMapper.class)
-												.selectByPrimaryKey(orddetid);
-					//商品关联编号
-					String equRelId = vod.getProEquRelId();
-					VmProEquRel vpe = Service.lookup(IMINDataBaseService.class)
-											.getMybatisMapper(VmProEquRelMapper.class)
-											.selectByPrimaryKey(equRelId);
-			
-					if(!vpe.getProductNums().equals("0")) {
-						//变更数量
-						vpe.setProductNums(CommonUtil.subtract(vpe.getProductNums(), "1"));
-					}
-					vpe.setModifyTime(DateUtil.getCurrentDateTimeString());
-					Service.lookup(IMINDataBaseService.class)
-							.getMybatisMapper(VmProEquRelMapper.class)
-							.updateByPrimaryKeySelective(vpe);
-					// 增加提货数量 + 1
-					vdi.setDeliveryNums(CommonUtil.add(vdi.getDeliveryNums(), "1"));
-					
-				}else if("01".equals(cargoState)){//出货失败
-					vdi.setStatus("3");
-				}
-				
-				// 全部提货完毕
-				if(vdi.getProNums().equals(vdi.getDeliveryNums())) {
-					// 提货状态:0未出货1部分出货2已出货3卡货4清零5处理中
-					vdi.setStatus("2");
+	public Map<String, String> dropGoods(String[] strArr, String imeiAddr) throws MINBusinessException {
+		//推货编号
+		String deliveryId = strArr[2];
+		//推货状态
+		String state = strArr[3];
+
+		VmDeliveryInf vdi = Service.lookup(IMINDataBaseService.class)
+									.getMybatisMapper(VmDeliveryInfMapper.class)
+									.selectByPrimaryKey(deliveryId);
+		String cargoState = "";
+		//成功的不在处理
+		if(vdi!= null && !vdi.equals("2")){
+			if("01".equals(state)){
+				cargoState ="00";
+				// 提货状态:0未出货1部分出货2已出货3卡货4清零5处理中
+				vdi.setStatus("1");
+				//订单详情编号
+				String orddetid = vdi.getOrdDetId();
+				//查询订单详情
+				VmOrderDetails vod = Service.lookup(IMINDataBaseService.class)
+						.getMybatisMapper(VmOrderDetailsMapper.class)
+						.selectByPrimaryKey(orddetid);
+				//商品关联编号
+				String equRelId = vod.getProEquRelId();
+				VmProEquRel vpe = Service.lookup(IMINDataBaseService.class)
+						.getMybatisMapper(VmProEquRelMapper.class)
+						.selectByPrimaryKey(equRelId);
+
+				if(!vpe.getProductNums().equals("0")) {
+					//变更数量
+					vpe.setProductNums(CommonUtil.subtract(vpe.getProductNums(), "1"));
 				}
-				//变更推货状态
+				vpe.setModifyTime(DateUtil.getCurrentDateTimeString());
 				Service.lookup(IMINDataBaseService.class)
-						.getMybatisMapper(VmDeliveryInfMapper.class)
-						.updateByPrimaryKeySelective(vdi);
+						.getMybatisMapper(VmProEquRelMapper.class)
+						.updateByPrimaryKeySelective(vpe);
+				// 增加提货数量 + 1
+				vdi.setDeliveryNums(CommonUtil.add(vdi.getDeliveryNums(), "1"));
+
+			}else {//出货失败
+				cargoState ="01";
+				vdi.setStatus("3");
+			}
+			// 全部提货完毕
+			if(vdi.getProNums().equals(vdi.getDeliveryNums())) {
+				// 提货状态:0未出货1部分出货2已出货3卡货4清零5处理中
+				vdi.setStatus("2");
+			}
+			//变更推货状态
+			Service.lookup(IMINDataBaseService.class)
+					.getMybatisMapper(VmDeliveryInfMapper.class)
+					.updateByPrimaryKeySelective(vdi);
+			VmPushNewsExample  vmPushNewsExample = new VmPushNewsExample();
+			vmPushNewsExample.createCriteria().andDeliverynoEqualTo(deliveryId);
+			List<VmPushNews> VmPushNewsList = Service.lookup(IMINDataBaseService.class)
+													.getMybatisMapper(VmPushNewsMapper.class)
+													.selectByExample(vmPushNewsExample);
+			if(VmPushNewsList.size() == 1 ){
 				//变更消息状态
 				VmPushNews vpm = new VmPushNews();
-				vpm.setFlowno(pushNewsMap.get("flowno"));
+				vpm.setFlowno(VmPushNewsList.get(0).getFlowno());
 				vpm.setState("02");
 				vpm.setCargoState(cargoState);
 				vpm.setModifyTime(DateUtil.getCurrentDateTimeString());
 				Service.lookup(IMINDataBaseService.class)
-				.getMybatisMapper(VmPushNewsMapper.class)
-				.updateByPrimaryKeySelective(vpm);
+						.getMybatisMapper(VmPushNewsMapper.class)
+						.updateByPrimaryKeySelective(vpm);
 			}
-			
+
 		}
-		
+ 		//[q|机序列号(5位)|执行订单号(10位)|ok]
+		/**设置放回*/
+		List<String> restList = new ArrayList<String>();
+		restList.add(ShConstant.Q);
+		restList.add(imeiAddr);
+		restList.add(deliveryId);
+		restList.add("ok");
+		String strr = assembleReturnMessage(restList);
+		//设置返回值
+		Map<String,String> runMap = new HashMap<String,String>();
+		runMap.put("runData", strr);
+		return runMap;
 	}
 	/*
 	 * 推送温度回调
@@ -355,6 +352,5 @@ public class VendingMachineServiceImpl implements IVendingMachineService {
 	}
 
 
-	
 }
 

+ 2 - 2
src/main/java/com/minpay/ma/client/ChatServer.java

@@ -120,7 +120,7 @@ public class ChatServer {
      * @throws IOException 
      */
     public static String sendMsg(String param, String socketId) throws IOException {
-        Log.info("发送消息:" + param);
+        Log.info("======================发送消息:" + param);
     	Socket socket = socketList.get(socketId);
     	String ret = "200";
     	if(socket != null) {
@@ -133,7 +133,7 @@ public class ChatServer {
             if(!CommonUtil.isEmpty(ree)){
                 bw.write(ree);
                 bw.flush();
-                Log.info("返回消息:" + ree);
+                Log.info("==============================返回消息:" + ree);
            }
             
     	}else{