Browse Source

Merge remote-tracking branch 'origin/master'

fuxubing 3 years ago
parent
commit
b0823a0895

+ 6 - 1
pom.xml

@@ -22,7 +22,12 @@
 	</properties>
 
 	<dependencies>
-	
+		<!-- 阿里sdk -->
+		<dependency>
+			<groupId>com.aliyun</groupId>
+			<artifactId>aliyun-java-sdk-core</artifactId>
+			<version>4.4.2</version>
+		</dependency>
 	
 <!--   ureport -->
 <!-- <dependency>

+ 124 - 0
src/main/java/com/reptileclient/jlifeapp/config/SendSms.java

@@ -0,0 +1,124 @@
+package com.reptileclient.jlifeapp.config;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.alibaba.fastjson.JSONObject;
+import com.aliyuncs.CommonRequest;
+import com.aliyuncs.CommonResponse;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.profile.DefaultProfile;
+import com.reptileclient.jlifeapp.util.DateUtils;
+
+/**
+ * 阿里 短信发送
+ * 
+ * @author lurz
+ *
+ */
+@Component
+public class SendSms {
+
+	private static final Logger logger = LoggerFactory.getLogger(SendSms.class);
+
+	public static String RegionId = "cn-hangzhou";
+	public static String AccessKeyId = "LTAI4Fv6kRSmkeYvxiqQG4h8";
+	public static String AccessSecret = "1jiphJgwiHKwXafnPVIWPYSCpQFcyl";
+
+	public static String SignName = "鲸致生活";//
+//	public static String TemplateCode = "SMS_164390038";// 模板编号
+
+	public static String TemplateCode = "SMS_217145321";// 模板编号 数据token通知
+
+//	public static String ms_yanzhen_code = "ms_yanzhen_code";
+	
+	
+	public static Map<String,Integer> msCount=new HashMap<String, Integer>();
+
+	public static Boolean sendAliMs(String phoneNumber) {
+		DefaultProfile profile = DefaultProfile.getProfile(RegionId, AccessKeyId, AccessSecret);
+		IAcsClient client = new DefaultAcsClient(profile);
+
+		CommonRequest request = new CommonRequest();
+		request.setMethod(MethodType.POST);
+		request.setDomain("dysmsapi.aliyuncs.com");
+		request.setVersion("2017-05-25");
+		request.setAction("SendSms");
+		request.putQueryParameter("RegionId", RegionId);
+		request.putQueryParameter("SignName", SignName);
+		request.putQueryParameter("TemplateCode", TemplateCode);
+
+		request.putQueryParameter("PhoneNumbers", phoneNumber);
+//		request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
+		try {
+			CommonResponse response = client.getCommonResponse(request);
+			// {"Message":"OK","RequestId":"776079FB-BE0C-4F14-AB21-4987181732FD","BizId":"369007669305321014^0","Code":"OK"}
+			logger.info("手机号{}发送了一次通知,返回值:{}", phoneNumber, response.getData());
+
+			JSONObject js = JSONObject.parseObject(response.getData());
+			String Message = js.get("Message").toString();
+			String Code = js.get("Code").toString();
+			if (Message.equals("OK") && Code.equals("OK")) {
+				return true;
+			}
+
+			System.out.println(response.getData());
+		} catch (ServerException e) {
+			e.printStackTrace();
+		} catch (ClientException e) {
+			e.printStackTrace();
+		}
+
+		return false;
+	}
+
+	public static void sendMs(List<String> phoneList) {
+
+//		Integer code = (int) ((Math.random() * 9 + 1) * 100000);
+		phoneList.forEach(e -> {
+			sendAliMs(e);
+			//Boolean sendAliMs = 
+		});
+	}
+
+	public static void toSendMs() {
+		//当日最多发3次
+		logger.info("**********发送失败短信通知了****************************");
+		String currentDay = DateUtils.getCurrentDay();
+		if(msCount.containsKey(currentDay)) {
+			if(msCount.get(currentDay)>3) {
+				return ;
+			}
+			
+			Integer ct=msCount.get(currentDay)+1;
+			msCount.put(currentDay, ct);
+		}else {
+			msCount.put(currentDay, 1);
+		}
+		 
+		
+		List<String> phoneList = new ArrayList<String>();
+		phoneList.add("18516779956"); //设置要发的手机号
+		phoneList.add("15629121030");
+		phoneList.add("15294264365");
+		
+		sendMs(phoneList);
+	}
+
+	public static void main(String[] args) {
+		toSendMs();
+	}
+
+}

+ 8 - 0
src/main/java/com/reptileclient/jlifeapp/constant/HemaConstant.java

@@ -60,4 +60,12 @@ public class HemaConstant {
 			+ "{\"op\":\"=\",\"key\":\"storeId\"},"
 			+ "{\"op\":\"=\",\"key\":\"bizOrderId\"}]}}";
 	
+	
+	public static String test_parm="{\"code\":\"public_query;i_sale_detail_zzb.query\","
+			+ "\"where\":{\"pageIndex\":1,\"pageSize\":100,\"sorts\":[],\"dimensions\":[\"biz_order_id\","
+			+ "\"store_name\",\"supplier_name\",\"auction_title\",\"pay_time\",\"refund_time\",\"order_channel\","
+			+ "\"stock_unit\",\"discount_info\"],\"wheres\":[{\"value\":\"282136170\",\"op\":\"=\",\"key\":"
+			+ "\"supplierNo\"},{\"value\":\"2021-05-17\",\"op\":\"=\",\"key\":\"startDate\"},"
+			+ "{\"value\":\"2021-05-18\",\"op\":\"=\",\"key\":\"endDate\"},{\"op\":\"=\",\"key\":\"skuCode\"},"
+			+ "{\"op\":\"=\",\"key\":\"storeId\"},{\"op\":\"=\",\"key\":\"bizOrderId\"}]}}";
  }

+ 75 - 0
src/main/java/com/reptileclient/jlifeapp/schedule/NoticeTokenTask.java

@@ -0,0 +1,75 @@
+package com.reptileclient.jlifeapp.schedule;
+
+import com.reptileclient.jlifeapp.config.SendSms;
+import com.reptileclient.jlifeapp.constant.HemaConstant;
+import com.reptileclient.jlifeapp.constant.JlifeConstant;
+import com.reptileclient.jlifeapp.dao.hm.HmTokenMapper;
+import com.reptileclient.jlifeapp.entity.hm.HmToken;
+import com.reptileclient.jlifeapp.service.HmSalesOrderService;
+import com.reptileclient.jlifeapp.util.DateUtils;
+import com.reptileclient.jlifeapp.util.HttpUtil;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ *  token超时处理通知
+ * @author lu
+ *
+ */
+@Component
+public class NoticeTokenTask {
+	
+
+	private static final Logger logger = LoggerFactory.getLogger(NoticeTokenTask.class);
+	
+	@Autowired
+	HmSalesOrderService hmSalesOrderService;
+	
+	@Autowired
+	HmTokenMapper hmtk;
+	
+	@Autowired
+	SendSms sms;
+
+	@Scheduled(cron = "0 0 8-22 * * ?") // 每天8到22点每小时执行一次
+	public void runTask() {
+		
+		
+		logger.info("开始  验证token.........................");
+		try {
+			HmToken hm = hmtk.selectAll();
+//			String resultData = HttpUtil.requestGet(hm.getToken(), "{}", JlifeConstant.HM_STATION);
+			
+			String parmJson =HemaConstant.test_parm;
+			Map<String, Object> request = HttpUtil.request(hm.getToken(), parmJson, HemaConstant.HEMADATA_LYSJYJXS_URL);
+			
+			logger.info("接口返回信息:"+request);
+			if (request.get("success").toString().equals("true")) {
+				
+			}else {
+				//失败处理发短信
+				sms.toSendMs();
+			}
+			
+		} catch (Exception e) {
+			sms.toSendMs();
+			e.printStackTrace();
+			
+		}
+		
+		
+
+	}
+
+	 
+	 
+
+}

+ 5 - 0
src/main/java/com/reptileclient/jlifeapp/util/DateUtils.java

@@ -11,6 +11,11 @@ public class DateUtils {
 	
 	public static SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
+	
+	public static String getCurrentDay() {
+		return format.format(new Date());
+	}
+	
 	/**
 	 * 获取前一天
 	 * 

+ 1 - 0
src/main/java/com/reptileclient/jlifeapp/util/HttpUtil.java

@@ -53,6 +53,7 @@ public class HttpUtil {
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
         headers.add("Accept", MediaType.APPLICATION_JSON.toString());
+        headers.add("referer", "https://shuhe.hemaos.com/console/workspace/539/preview");
         List<String> cookies = new ArrayList<>();
         cookies.add("WDKSESSID=" + token);
         headers.put(HttpHeaders.COOKIE, cookies);

+ 20 - 14
src/test/java/jlifereptileserver/Test.java

@@ -4,9 +4,11 @@ import com.reptileclient.jlifeapp.PostorderApplication;
 import com.reptileclient.jlifeapp.dao.hm.HmBookOrderMapper;
 import com.reptileclient.jlifeapp.dao.jz.OrderGoodsMapper;
 import com.reptileclient.jlifeapp.dao.jz.OrderMapper;
+import com.reptileclient.jlifeapp.schedule.NoticeTokenTask;
 import com.reptileclient.jlifeapp.service.HmBookOrderService;
 import com.reptileclient.jlifeapp.service.HmPaymentOrderService;
 import com.reptileclient.jlifeapp.service.HmSalesOrderService;
+import com.reptileclient.jlifeapp.util.DateUtils;
 import com.reptileclient.jlifeapp.util.HttpUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.runner.RunWith;
@@ -15,6 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -35,6 +38,9 @@ public class Test {
 
     @Autowired
     private OrderMapper orderMapper;
+    
+    @Autowired
+    NoticeTokenTask noticeTokenTask;
 
     public static void main(String[] args) {
         String durl = "https://wdk-excel.oss-cn-beijing.aliyuncs.com/export/20201202/2209128993378/20201202_145732.xlsx";
@@ -86,20 +92,20 @@ public class Test {
         //hmBookOrderService.updateByBookOrderNo("4509489","77001");
 
         //hmPaymentOrderService.updateByPaymentNo("2021011723418501", "44003");
-        List<Map<String, Object>> match = hmBookOrderService.match();
-        match.forEach(item -> {
-            String bookOrderNo = String.valueOf(item.get("book_order_no"));
-            String stationCode = String.valueOf(item.get("station_code"));
-            String paymentNo = String.valueOf(item.get("payment_no"));
-
-            //更新服务单
-            hmBookOrderService.updateByBookOrderNo(bookOrderNo, stationCode);
-            //更新支付单
-            if (StringUtils.isNotBlank(paymentNo)) {
-                hmPaymentOrderService.updateByPaymentNo(paymentNo, stationCode);
-            }
-        });
-
+//        List<Map<String, Object>> match = hmBookOrderService.match();
+//        match.forEach(item -> {
+//            String bookOrderNo = String.valueOf(item.get("book_order_no"));
+//            String stationCode = String.valueOf(item.get("station_code"));
+//            String paymentNo = String.valueOf(item.get("payment_no"));
+//
+//            //更新服务单
+//            hmBookOrderService.updateByBookOrderNo(bookOrderNo, stationCode);
+//            //更新支付单
+//            if (StringUtils.isNotBlank(paymentNo)) {
+//                hmPaymentOrderService.updateByPaymentNo(paymentNo, stationCode);
+//            }
+//        });
+//    	noticeTokenTask.runTask();
     }