Procházet zdrojové kódy

售货机 推货和推送

xubh před 4 roky
rodič
revize
355d987b0d

+ 4 - 0
src/main/java/com/minpay/common/action/VendingMachineAction.java

@@ -153,13 +153,16 @@ 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", "推货失败");
 			}
@@ -173,6 +176,7 @@ public class VendingMachineAction implements IMINAction {
 			vpn.setFlowno(flowno);
 			vpn.setImeiAddr(imeiAddr);
 			vpn.setCargono(cargoNo);
+
 			vpn.setCreateTime(DateUtil.getCurrentDateTimeString());
 			vpn.setModifyTime(DateUtil.getCurrentDateTimeString());
 			vpn.setDeliveryno(deliveryNo);

+ 3 - 1
src/main/java/com/minpay/common/service/impl/RunBatchServiceImpl.java

@@ -41,7 +41,7 @@ public class RunBatchServiceImpl implements IRunBatchService {
 		//获取当前时间
 		String dateTime = DateUtil.getCurrentDateTimeString();
 		//获取前5分钟的时间
-		String newdateTime =  DataUtil.plusTimeSecond(dateTime, -25);;
+		String newdateTime =  DataUtil.plusTimeSecond(dateTime, -300);;
 		VmEquipmentInfExample veExample = new VmEquipmentInfExample();
 		veExample.createCriteria().andStateEqualTo("00").andModifyTimeLessThanOrEqualTo(newdateTime);
 		
@@ -85,6 +85,8 @@ public class RunBatchServiceImpl implements IRunBatchService {
 			resultsMap.put("imeiAddr",vpn.getImeiAddr());
 			resultsMap.put("cargoNo",vpn.getCargono());	
 			resultsMap.put("cargoState",vpn.getCargoState());
+			resultsMap.put("MINView","JSON");
+
 			//调用通用接口执行
 			JSONObject jsonOb = JSONObject.fromObject(resultsMap);
 			String sendUrl = vpn.getPushUrl();

+ 19 - 1
src/main/java/com/minpay/common/service/impl/VendingMachineServiceImpl.java

@@ -49,19 +49,37 @@ public class VendingMachineServiceImpl implements IVendingMachineService {
 		String imei = strArr[1];
 		System.out.println(imei);
 		VmEquipmentInfExample veExample = new VmEquipmentInfExample();
-		veExample.createCriteria().andImeiAddrEqualTo(imei).andStateEqualTo("00");
+		List<String> stateList = new ArrayList<String>();
+		stateList.add("00");
+		stateList.add("01");
+		veExample.createCriteria().andImeiAddrEqualTo(imei).andStateIn(stateList);
 		//查询是否有此设备
 		List<VmEquipmentInf> list = Service.lookup(IMINDataBaseService.class)
 											.getMybatisMapper(VmEquipmentInfMapper.class)
 											.selectByExample(veExample);
 		//有此设备(进行更新数据)
 		if( list.size() == 1 ){
+			VmEquipmentInf vm = list.get(0);
+			//更新心跳次数和最后跳动时间
+			vm.setState("00");
+			vm.setModifyTime(DateUtil.getCurrentDateTimeString());
+			if(CommonUtil.objToint(vm.getHeartRates()) > 999999999) {
+				vm.setHeartRates("1");
+			}
+			else {
+				vm.setHeartRates(CommonUtil.add(vm.getHeartRates(), "1"));
+			}
+			Service.lookup(IMINDataBaseService.class)
+					.getMybatisMapper(VmEquipmentInfMapper.class)
+					.updateByPrimaryKeySelective(vm);
+
 			String[] arr1= new String[3];
 			List<String> restList = new ArrayList<String>();
 			restList.add(ShConstant.BACK_HEARTBEAT);
 			restList.add(imei);
 			restList.add(ShConstant.NORMAL);
 			String strr = assembleReturnMessage(restList);
+
 			//进行登陆
 			runMap.put("runData", strr);
 			runMap.put("imei", imei);

+ 53 - 3
src/main/java/com/minpay/common/util/HttpPost.java

@@ -1,8 +1,8 @@
 package com.minpay.common.util;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
+import com.startup.minpay.util.Log;
+
+import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
@@ -71,4 +71,54 @@ public class HttpPost {
 		System.out.println("result:"+result);
 		return result;
 	}
+	/**
+	 * 发送post请求(推货专用)
+	 * @param url
+	 * @param param "a=111&b=123"
+	 * @return
+	 */
+	public static String sendPostFormachine(String url, String param){
+		String result = "";
+		try{
+			param = URLEncoder.encode(param, "utf-8");
+			URL httpurl = new URL(url);
+			HttpURLConnection httpConn = (HttpURLConnection)httpurl.openConnection();
+			httpConn.setDoOutput(true);
+			httpConn.setDoInput(true);
+			// 设置传递方式
+			httpConn.setRequestMethod("POST");
+			// 设置维持长连接
+			httpConn.setRequestProperty("Connection", "Keep-Alive");
+			// 设置文件字符集:
+			httpConn.setRequestProperty("Charset", "UTF-8");
+			// 转换为字节数组
+			//byte[] data = ("formData=" + param.toString()).getBytes();
+			byte[] data = (param.toString()).getBytes();
+			// 设置文件长度
+			httpConn.setRequestProperty("Content-Length", String.valueOf(data.length));
+			// 设置文件类型:
+			httpConn.setRequestProperty("contentType", "application/json");
+//			PrintWriter out = new PrintWriter(httpConn.getOutputStream());
+//			out.print(param.getBytes());
+//			out.flush();
+//			out.close();
+			OutputStream out = new DataOutputStream(httpConn.getOutputStream()) ;
+			// 写入请求的字符串
+			out.write((param.toString()).getBytes());
+			out.flush();
+			out.close();
+
+			BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(),"UTF-8"));
+			String line;
+			while ((line = in.readLine())!= null){
+				result += line;
+			}
+			in.close();
+		}catch(Exception e){
+			System.out.println("error!!"+e);
+		}
+		Log.info("返回:".concat(result));
+		System.out.println("result:"+result);
+		return result;
+	}
 }

+ 2 - 2
src/main/java/com/minpay/qd/task/RunMerchantAction.java

@@ -20,9 +20,9 @@ public class RunMerchantAction {
 	 */
 	public void execute() throws Exception{
 		System.out.println("任务开始...._-------------");
-		/*System.out.println(DateUtil.getCurrentDateTimeString());
+		System.out.println(DateUtil.getCurrentDateTimeString());
 		//Service.lookup(IRunBatchService.class).runPushnews();
-		Service.lookup(IRunBatchService.class).updateMachineState();	*/
+		Service.lookup(IRunBatchService.class).updateMachineState();
 		System.out.println("任务结束...._-------------");
 	}
 }