mirror of
https://gitee.com/sdyunze/iotlink.git
synced 2026-09-01 15:33:12 +08:00
轮训 改为 轮询,新功能自动轮询,添加rabmq队列
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
package com.yunze.apiCommon.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface YzCardPollingUtilCzcMapper {
|
||||
//查询所有通道ID
|
||||
List<String> selAllRoute();
|
||||
//查询通道ID下有多少卡
|
||||
String selRouteCardCount(String route_id);
|
||||
//修改通道卡总数
|
||||
void updRouteCount(Map<String,Object> map);
|
||||
//查询通道下的卡iccid 状态为 1
|
||||
List<String> selCardIccid(Map<String,Object> map);
|
||||
//查询通道信息
|
||||
Map<String,Object> selRouteParma(Map<String,Object> map);
|
||||
//查询真实号码
|
||||
String selMsidn(String iccid);
|
||||
|
||||
List<String> selRoute();
|
||||
String selRouteCode(String route);
|
||||
Integer selCountByRoute(String route);
|
||||
|
||||
List<String> selIccids(String route);
|
||||
List<String> selIccidsLimit(Map<String,Object> map);
|
||||
|
||||
Map<String,Object> selRouteMap(String route);
|
||||
|
||||
Map<String,Object> selCardPacket(String iccid);
|
||||
|
||||
Map<String,Object> selCardUseInfo(String iccid);
|
||||
|
||||
void updCardUsedByDayIsFastDayInMonth(Map<String,Object> map);
|
||||
|
||||
Map<String,Object> selCardOne(String iccid);
|
||||
|
||||
void insertMonth(Map<String,Object> map);
|
||||
|
||||
void updAutoPollingInfo(String iccid);
|
||||
void updAutoPollingError(String iccid);
|
||||
void updAutoPollingAll();
|
||||
}
|
||||
+21
@@ -5,8 +5,11 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEC.YD_EC_Api;
|
||||
import com.yunze.apiCommon.utils.HttpUtil;
|
||||
import com.yunze.apiCommon.utils.UrlUtil;
|
||||
import com.yunze.apiCommon.utils.VeDate;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -56,7 +59,25 @@ public class Query_YD extends YD_EC_Api {
|
||||
String Str = send(url,json);
|
||||
return repeat(Str,json,url);
|
||||
}
|
||||
public String autoPolling(List<String> cardForiList){
|
||||
String functionNm = "/query/sim-data-usage-monthly/batch";
|
||||
String url = server_Ip+functionNm;
|
||||
//https://api.iot.10086.cn/v5/ec/query/sim-data-usage-daily/batch?transid=xxxxxx&token=xxxxx&iccids=xxx_xxx_xxx&queryDate= xxxxxx
|
||||
String transid = appId + new SimpleDateFormat("YYYYMMDDHHMMSS").format(new Date());
|
||||
String queryDate = VeDate.getYesterday();
|
||||
String pinUrl=url+"?"+"transid="+transid+"&token="+token+"&iccids=";
|
||||
for (int i = 0; i < cardForiList.size(); i++) {
|
||||
|
||||
if (i==0){
|
||||
pinUrl =pinUrl+cardForiList.get(i);
|
||||
}else{
|
||||
pinUrl =pinUrl+"_"+cardForiList.get(i);
|
||||
}
|
||||
}
|
||||
pinUrl = pinUrl + "&queryDate=" + queryDate;
|
||||
String res = HttpUtil.get(pinUrl);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.yunze.apiCommon.utils;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -32,7 +33,13 @@ public class VeDate {
|
||||
Date currentTime_2 = formatter.parse(dateString, pos);
|
||||
return currentTime_2;
|
||||
}
|
||||
|
||||
public static String getYesterday(){
|
||||
LocalDate currentDate =LocalDate.now( );
|
||||
LocalDate previousDate =currentDate.minusDays(1);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
||||
String formattedDate = previousDate.format(formatter);
|
||||
return formattedDate;
|
||||
}
|
||||
/**
|
||||
* 获取现在时间
|
||||
*
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yunze.apiCommon.mapper.YzCardPollingUtilCzcMapper">
|
||||
|
||||
<!--1.查询现有通道-->
|
||||
<select id="selAllRoute" resultType="java.lang.String">
|
||||
select cd_id from yz_card_route yz_card_route where cd_state = '1' and cd_lunxun = '1'
|
||||
</select>
|
||||
<!--2.查询传入的通道ID下游多少张卡-->
|
||||
<select id="selRouteCardCount" parameterType="java.lang.String" resultType="java.lang.String">
|
||||
select count(*) as cd_count from yz_card_info where channel_id = #{route_id}
|
||||
</select>
|
||||
<!--3.修改传入的通道ID下的卡总数 -->
|
||||
<update id="updRouteCount" parameterType="java.util.Map">
|
||||
update yz_card_route set cd_count =#{cd_count} where cd_id =#{route_id}
|
||||
</update>
|
||||
<!--查询通道下的卡iccid 状态为1-->
|
||||
<select id="selCardIccid" parameterType="java.util.Map" resultType="java.lang.String">
|
||||
select iccid from yz_card_info where channel_id = #{route_id} and status_ShowId = '4'
|
||||
</select>
|
||||
<!-- 查询通道信息-->
|
||||
<select id="selRouteParma" parameterType="java.util.Map" resultType="java.util.Map">
|
||||
select cd_code,cd_name,cd_username,cd_pwd,cd_key,cd_status,cd_operator_type from yz_card_route where cd_id = #{route_id}
|
||||
</select>
|
||||
<!-- 查询真实号码-->
|
||||
<select id="selMsidn" parameterType="java.lang.String" resultType="java.lang.String">
|
||||
select msisdn from yz_card_info where iccid = #{iccid}
|
||||
</select>
|
||||
|
||||
<select id="selRoute" resultType="java.lang.String">
|
||||
select distinct route_id from yz_auto_polling
|
||||
</select>
|
||||
|
||||
<select id="selRouteCode" parameterType="java.lang.String" resultType="java.lang.String">
|
||||
select cd_code from yz_card_route where cd_id = #{route}
|
||||
</select>
|
||||
|
||||
<select id="selCountByRoute" resultType="java.lang.Integer" parameterType="java.lang.String">
|
||||
select count(*) from yz_auto_polling where route_id =#{route}
|
||||
</select>
|
||||
|
||||
<select id="selIccids" resultType="java.lang.String" parameterType="java.lang.String">
|
||||
select iccid from yz_auto_polling where route_id=#{route}
|
||||
</select>
|
||||
|
||||
<select id="selIccidsLimit" resultType="java.lang.String" parameterType="java.util.Map">
|
||||
select iccid from yz_auto_polling where route_id =#{route} limit #{li} ,100
|
||||
</select>
|
||||
|
||||
<select id="selRouteMap" resultType="java.util.Map" parameterType="java.lang.String">
|
||||
SELECT
|
||||
cd_status,
|
||||
cd_code,
|
||||
cd_username,
|
||||
cd_pwd,
|
||||
cd_key,
|
||||
cd_control_type
|
||||
FROM
|
||||
yz_card_route
|
||||
where
|
||||
cd_id=#{route}
|
||||
|
||||
|
||||
</select>
|
||||
|
||||
<select id="selCardPacket" parameterType="java.lang.String" resultType="java.util.Map">
|
||||
select p.packet_valid_name
|
||||
from yz_card_info i left JOIN yz_order o on i.iccid = o.iccid
|
||||
left Join yz_card_packet p on o.packet_id = p.packet_id
|
||||
where i.iccid =#{iccid} LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selCardUseInfo" parameterType="java.lang.String" resultType="java.util.Map">
|
||||
select o.validate_type,o.packet_id,p.packet_valid_name ,p.error_flow from yz_order o
|
||||
LEFT JOIN yz_card_packet p on o.packet_id = p.packet_id
|
||||
where iccid=#{iccid} LIMIT 1
|
||||
</select>
|
||||
|
||||
<update id="updCardUsedByDayIsFastDayInMonth" parameterType="java.util.Map">
|
||||
update yz_card_info set used=#{used},remaining=#{remaining} where iccid =#{iccid}
|
||||
</update>
|
||||
|
||||
<select id="selCardOne" parameterType="java.lang.String" resultType="java.util.Map">
|
||||
select used,remaining from yz_card_info where iccid =#{iccid}
|
||||
</select>
|
||||
|
||||
<insert id="insertMonth" parameterType="java.util.Map">
|
||||
insert into yz_card_month (iccid,used,year_month)values (
|
||||
#{iccid},#{used},#{month}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updAutoPollingInfo" parameterType="java.util.Map">
|
||||
update yz_auto_polling set day_auto ='1' ,day_type='1' where iccid =#{iccid}
|
||||
</update>
|
||||
|
||||
<update id="updAutoPollingError" parameterType="java.util.Map">
|
||||
update yz_auto_polling set day_auto ='1' ,day_type='0' where iccid =#{iccid}
|
||||
</update>
|
||||
|
||||
<update id="updAutoPollingAll" >
|
||||
update yz_auto_polling set day_auto ='0' ,day_type='0'
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.yunze.common.utils.yunze;
|
||||
|
||||
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
|
||||
/***
|
||||
@@ -864,8 +867,12 @@ public class VeDate {
|
||||
* @return
|
||||
*/
|
||||
public static String getMonthDate(String yyyy_MM_dd_HH_mm_ss,int month) {
|
||||
return getMonthDate( yyyy_MM_dd_HH_mm_ss, month, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
public static String getMonthDate(String yyyy_MM_dd_HH_mm_ss,int month,String format) {
|
||||
try {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(format);
|
||||
Date date1 = formatter.parse(yyyy_MM_dd_HH_mm_ss);
|
||||
LocalDateTime localDateTime = date1.toInstant()
|
||||
.atZone(ZoneId.systemDefault() )
|
||||
@@ -880,6 +887,7 @@ public class VeDate {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*获取 多少秒后的时间
|
||||
* @param yyyy_MM_dd_HH_mm_ss
|
||||
@@ -919,38 +927,126 @@ public class VeDate {
|
||||
return bool;
|
||||
}
|
||||
|
||||
public static String getNowMonthFistDayCZC(){
|
||||
LocalDate localDate = LocalDate.now();
|
||||
LocalDate fastday = localDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
String newData = fastday+" 00:00:00";
|
||||
return newData;
|
||||
}
|
||||
public static String getNowMonthLastDayCZC(){
|
||||
LocalDate localDate = LocalDate.now();
|
||||
LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||
String newData = lastDay+" 23:59:59";
|
||||
return newData;
|
||||
}
|
||||
|
||||
public static String getFistDayInMonthByDateCZC(String date){
|
||||
//month -> 2023-07-01
|
||||
String[] split = date.split("-");
|
||||
int yyy = Integer.parseInt(split[0]);
|
||||
int mmm = Integer.parseInt(split[1]);
|
||||
int ddd = Integer.parseInt(split[2]);
|
||||
LocalDate localDate = LocalDate.of(yyy, mmm, ddd);
|
||||
LocalDate fastday = localDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
String newData = fastday+" 00:00:00";
|
||||
return newData;
|
||||
}
|
||||
public static String getLastDayInMonthByDateCZC(String date){
|
||||
String[] split = date.split("-");
|
||||
int yyy = Integer.parseInt(split[0]);
|
||||
int mmm = Integer.parseInt(split[1]);
|
||||
int ddd = Integer.parseInt(split[2]);
|
||||
LocalDate localDate = LocalDate.of(yyy, mmm, ddd);
|
||||
LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
|
||||
String newData = lastDay+" 23:59:59";
|
||||
return newData;
|
||||
}
|
||||
public static List<String> getCzcSelUsedDateMonthYear(String active_date){
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date();
|
||||
String today = format.format(date);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
||||
// 声明保存日期集合
|
||||
List<String> list = new ArrayList<String>();
|
||||
try {
|
||||
// 转化成日期类型
|
||||
Date startDate = sdf.parse(active_date);
|
||||
Date endDate = sdf.parse(today);
|
||||
|
||||
//用Calendar 进行日期比较判断
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
while (startDate.getTime()<=endDate.getTime()){
|
||||
// 把日期添加到集合
|
||||
String dateA = sdf.format(startDate);
|
||||
String[] split = dateA.split("-");
|
||||
String add = split[0] + split[1];
|
||||
|
||||
list.add(add);
|
||||
// 设置日期
|
||||
calendar.setTime(startDate);
|
||||
//把日期增加一天
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
// 获取增加后的日期
|
||||
startDate=calendar.getTime();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (list.size()/12==0){
|
||||
return list;
|
||||
}else {
|
||||
int x= list.size()/12;
|
||||
int i = x * 12;
|
||||
for (int j = 0; j <i; j++) {
|
||||
list.remove(0);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static boolean dayIsLastDayOfMonth(String day){//判断传入时间是否为 当月最后一天
|
||||
LocalDate date = LocalDate.parse(day);
|
||||
LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
|
||||
return date.equals(lastDayOfMonth);
|
||||
|
||||
}
|
||||
public static boolean isFirstDayOfMonth(){ //判断当前是否为当月第2天
|
||||
Calendar calendar =Calendar.getInstance();
|
||||
int day0fMonth =calendar.get(Calendar.DAY_OF_MONTH);
|
||||
return day0fMonth == 2;
|
||||
}
|
||||
|
||||
public static boolean isFirstDayOfMonthOuth(){ //判断当前是否为当月第1天
|
||||
Calendar calendar =Calendar.getInstance();
|
||||
int day0fMonth =calendar.get(Calendar.DAY_OF_MONTH);
|
||||
return day0fMonth == 1;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
//
|
||||
// SimpleDateFormat sdfutc = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
//// Date date = "2022-11-30 11:30:30.123";
|
||||
// Date date = new Date(2022, 11, 30, 11, 30, 30);
|
||||
// sdfutc.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
//// sdfutc.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// System.out.println("北京时间(特指UTC+8:00): " + sdf.format(date));
|
||||
// System.out.println("UTC时间(特指UTC+0:00): " + sdfutc.format(date));
|
||||
String timeStr2=LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
|
||||
System.out.println(timeStr2);
|
||||
boolean firstDayOfMonth = isFirstDayOfMonth();
|
||||
System.out.println(firstDayOfMonth);
|
||||
// String nowMonthFistDayCZC = getStringDateShort();
|
||||
// System.out.println(nowMonthFistDayCZC);
|
||||
// System.out.println(nowMonthFistDayCZC.equals("-01"));
|
||||
//System.out.println("2023-07-01".split("-")[1]);
|
||||
// LocalDate localDate = LocalDate.of(2023, 07, 01);
|
||||
// System.out.println(localDate);
|
||||
// String lastDayInMonthByDateCZC = getLastDayInMonthByDateCZC("2023-07-01");
|
||||
// String getFistDayInMonthByDateCZC = getFistDayInMonthByDateCZC("2023-07-01");
|
||||
// System.out.println(lastDayInMonthByDateCZC);
|
||||
// System.out.println(getFistDayInMonthByDateCZC);
|
||||
|
||||
|
||||
// VeDate v=new VeDate();
|
||||
/*
|
||||
System.out.println(v.GetHH_MM_SS("2006-11-03 12:22:10"));*/
|
||||
/* String str[]=getYyyyAndMm();
|
||||
System.out.println(str[0]+str[1]+str[2]);*/
|
||||
// System.out.println(TimeComparison("08:30:00","08:30:01"));
|
||||
/* String yyyy_MM_dd= getFirstDayOfNextMonth("2021-04-30","yyyy-MM-dd");
|
||||
System.out.println(yyyy_MM_dd);
|
||||
|
||||
System.out.println(TimeComparison_yyyy_MM_dd("2021-04-30",yyyy_MM_dd));
|
||||
System.out.println(TimeComparison_yyyy_MM_dd("2021-05-31",yyyy_MM_dd));*/
|
||||
//System.out.println(TimeComparison_yyyy_MM_dd("2022-11-03 17:10:50","2022-11-02 17:10:50"));
|
||||
|
||||
|
||||
|
||||
|
||||
//System.out.println(getStringDateShort().substring(0,7));
|
||||
// System.out.println(getFirstDayOfGivenMonth(getMonthDate(getStringDateSSS(),-1),"yyyy-MM"));
|
||||
//System.out.println(getFirstDayOfGivenMonth(getMonthDate(getStringDateSSS(),-1),"yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
//System.out.println(getNo(4));
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yunze.quartz.task.yunze.card;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务处理 卡轮训
|
||||
*/
|
||||
@Component("autoPolling")
|
||||
public class AutoPolling {
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
public void autoPollingCzc(){
|
||||
String polling_queueName = "admin_autoPollingCzc_queue";
|
||||
String polling_routingKey = "admin.autoPollingCzc.queue";
|
||||
String polling_exchangeName = "admin_exchange";//路由
|
||||
try {
|
||||
Map<String, Object> start_type = new HashMap<>();
|
||||
start_type.put("Masage", "autoPollingCzc ");//启动类型
|
||||
rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_type), message -> {
|
||||
// 设置消息过期时间 30 分钟 过期
|
||||
message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
|
||||
return message;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.out.println("自动轮训Czc失败: " + e.getMessage().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -712,8 +712,13 @@
|
||||
"card_exchangeName": "admin_exchange",
|
||||
"card_queueName": "admin_smsCCTextField_queue",
|
||||
"card_routingKey": "admin.smsCCTextField.queue"
|
||||
},{
|
||||
"card_exchangeName": "admin_exchange",
|
||||
"card_queueName": "admin_autoPollingCzc_queue",
|
||||
"card_routingKey": "admin.autoPollingCzc.queue"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
]
|
||||
@@ -0,0 +1,217 @@
|
||||
package com.yunze.task.yunze.card;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import com.yunze.apiCommon.mapper.YzCardPollingUtilCzcMapper;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEC.Inquire.Query_YD;
|
||||
import com.yunze.apiCommon.utils.InternalApiRequest;
|
||||
import com.yunze.apiCommon.utils.VeDate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class autoPollingCzcTaskMQ {
|
||||
|
||||
@Resource
|
||||
private YzCardPollingUtilCzcMapper yzCardPollingUtilCzcMapper;
|
||||
|
||||
@Resource
|
||||
private InternalApiRequest internalApiRequest;
|
||||
|
||||
@Transactional
|
||||
@RabbitHandler
|
||||
@RabbitListener(queues = "admin_autoPollingCzc_queue")
|
||||
public void init() {
|
||||
// 将轮询全部修改为今日为轮询
|
||||
yzCardPollingUtilCzcMapper.updAutoPollingAll();
|
||||
// 获取需要自动同步卡 的通道分组
|
||||
List<String> routes = yzCardPollingUtilCzcMapper.selRoute();
|
||||
for (int i = 0; i < routes.size(); i++) {
|
||||
//判断通道是否为 ECV5 todo 后续根据需求自己对接上游接口
|
||||
String code = yzCardPollingUtilCzcMapper.selRouteCode(routes.get(i));
|
||||
if (code.equals("YiDong_EC")) {
|
||||
//是 移动ECV5
|
||||
//获取route信息进行 创建 移动官方对象
|
||||
Map<String, Object> initRoute = yzCardPollingUtilCzcMapper.selRouteMap(routes.get(i));
|
||||
//YD_EC_Api yd_ec_api = new YD_EC_Api(initRoute,initRoute.get("cd_code").toString());//
|
||||
Query_YD query_yd = new Query_YD(initRoute, initRoute.get("cd_code").toString());
|
||||
// 轮训表中 的卡号
|
||||
List<String> iccids = yzCardPollingUtilCzcMapper.selIccids(routes.get(i));
|
||||
//拆分List
|
||||
List<List<String>> lists = subList(iccids, 100);
|
||||
for (int j = 0; j < lists.size(); j++) {
|
||||
// 将拆分出来的List 拼接去做接口请求 YDECV5
|
||||
String res = query_yd.autoPolling(lists.get(j));
|
||||
log.info("自动轮训-上游返回数据:{}",res);
|
||||
Map<String, Object> resMap = JSONObject.parseObject(res);
|
||||
String status = resMap.get("status").toString();
|
||||
if (status.equals("0")){
|
||||
log.info("上游请求成功");
|
||||
List<Map<String,Object>> result=(List<Map<String,Object>>)resMap.get("result");
|
||||
for (int k = 0; k < result.size(); k++) {
|
||||
List<Map<String, Object>> cardMapList = (List<Map<String, Object>>) result.get(k).get("dataAmountList");
|
||||
Map<String, Object> cardUsedMap = cardMapList.get(0);
|
||||
String iccid = cardUsedMap.get("iccid").toString();
|
||||
double dataAmount = Double.parseDouble(cardUsedMap.get("dataAmount").toString());
|
||||
double used = dataAmount / 1024;
|
||||
CalculateUsage(iccid,used);
|
||||
// 修改auto_polling表中字段 全部成功
|
||||
yzCardPollingUtilCzcMapper.updAutoPollingInfo(iccid);
|
||||
}
|
||||
}else{
|
||||
log.error("轮训失败:{}",resMap.get("message").toString());
|
||||
List<String> errorIccids = lists.get(j);
|
||||
for (int k = 0; k < errorIccids.size(); k++) {
|
||||
String iccid = errorIccids.get(k);
|
||||
yzCardPollingUtilCzcMapper.updAutoPollingError(iccid);
|
||||
}
|
||||
// todo 上游接口请求失败,将本次循环的数据 添加至 失败从新执行
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* list 拆分
|
||||
*
|
||||
* @param sourceList 被拆分List
|
||||
* @param n 拆分的List大小
|
||||
* @param <T>
|
||||
* @return 拆分玩之后的List
|
||||
*/
|
||||
private static <T> List<List<T>> subList(List<T> sourceList, int n) {
|
||||
List<List<T>> rsList = new ArrayList<>();
|
||||
if (n <= 0) {
|
||||
rsList.add(sourceList);
|
||||
return rsList;
|
||||
}
|
||||
int listSize = sourceList.size();
|
||||
int groupNum = (sourceList.size() / n) + 1;
|
||||
for (int i = 0; i < groupNum; i++) {
|
||||
List<T> subList = new ArrayList<>();
|
||||
for (int j = i * n; j < (i + 1) * n; j++) {
|
||||
if (j < listSize) {
|
||||
subList.add(sourceList.get(j));
|
||||
}
|
||||
}
|
||||
rsList.add(subList);
|
||||
}
|
||||
if (rsList.get(rsList.size() - 1).size() == 0) {
|
||||
rsList.remove(rsList.size() - 1);
|
||||
}
|
||||
return rsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算用量
|
||||
* @param iccid 卡号
|
||||
* @param used 用量
|
||||
*/
|
||||
private void CalculateUsage(String iccid,double used){
|
||||
Map<String, Object> updMap = new HashMap<>();
|
||||
//1.有无资费 或年月资费
|
||||
Map<String, Object> packetMap = yzCardPollingUtilCzcMapper.selCardPacket(iccid);
|
||||
String now = com.yunze.common.utils.yunze.VeDate.getStringDateShort();//yyyy-mm-dd
|
||||
if (packetMap == null){
|
||||
//卡未充值资费
|
||||
log.info("卡:{},未订购资费,用量:{}",iccid,used);
|
||||
}else {
|
||||
String packet_valid_name = packetMap.get("packet_valid_name").toString();
|
||||
if (packet_valid_name.equals("月")){
|
||||
//资费充值为 月套餐
|
||||
log.info("卡:{},订购月资费包,用量:{}",iccid,used);
|
||||
//3. 校验是否为一个月第一天,如果是 则初始化 月资费的剩余用量
|
||||
boolean firstDayOfMonth = com.yunze.common.utils.yunze.VeDate.isFirstDayOfMonth();
|
||||
if (firstDayOfMonth){
|
||||
//是当月第一天
|
||||
Map<String, Object> infoUsedMap = yzCardPollingUtilCzcMapper.selCardUseInfo(iccid);
|
||||
double error_flow = Double.parseDouble(infoUsedMap.get("error_flow").toString());
|
||||
double remaining = error_flow - used;
|
||||
updMap.put("remaining",remaining);
|
||||
updMap.put("used",used);
|
||||
updMap.put("iccid",iccid);
|
||||
yzCardPollingUtilCzcMapper.updCardUsedByDayIsFastDayInMonth(updMap);
|
||||
log.info("月套餐二号更新 :卡号{},用量{},剩余{}",iccid,used,remaining);
|
||||
}else{
|
||||
//不是最后一天
|
||||
Map<String, Object> infoUsedMap = yzCardPollingUtilCzcMapper.selCardOne(iccid);
|
||||
String oldUsed = infoUsedMap.get("used").toString();
|
||||
double remaining = Double.parseDouble(infoUsedMap.get("remaining").toString());
|
||||
double r = used - Double.parseDouble(oldUsed);
|
||||
updMap.put("remaining",remaining-r);
|
||||
updMap.put("used",used);
|
||||
updMap.put("iccid",iccid);
|
||||
yzCardPollingUtilCzcMapper.updCardUsedByDayIsFastDayInMonth(updMap);
|
||||
log.info("月套餐日常轮询 :卡号{},用量{},剩余{}",iccid,used,remaining);
|
||||
}
|
||||
}else if (packet_valid_name.equals("年")){
|
||||
//资费充值为 年套餐
|
||||
log.info("卡:{},订购年资费包,用量:{}",iccid,used);
|
||||
//2. 校验是否为月最后一天,如果是则区分卡是否为年包,是年包 则将卡用量详情 插入 yz_card_month表
|
||||
boolean isLastDay = com.yunze.common.utils.yunze.VeDate.isFirstDayOfMonthOuth();//判断是否为最后一天
|
||||
if (isLastDay){
|
||||
//是最后一天 将用量传入
|
||||
String[] split = now.split("-");
|
||||
String time = split[0]+split[1];
|
||||
Map<String, Object> monthMap = new HashMap<>();
|
||||
monthMap.put("iccid",iccid);
|
||||
monthMap.put("used",used);
|
||||
monthMap.put("month",time);
|
||||
yzCardPollingUtilCzcMapper.insertMonth(monthMap);
|
||||
}
|
||||
//修改 用量及剩余用量
|
||||
// todo 判断是否在年包有效期,表字段未设置 后续补充
|
||||
Map<String, Object> infoUsedMap = yzCardPollingUtilCzcMapper.selCardOne(iccid);
|
||||
String oldUsed = infoUsedMap.get("used").toString();
|
||||
double remaining = Double.parseDouble(infoUsedMap.get("remaining").toString());
|
||||
double r = used - Double.parseDouble(oldUsed);
|
||||
updMap.put("remaining",remaining-r);
|
||||
updMap.put("used",used);
|
||||
updMap.put("iccid",iccid);
|
||||
yzCardPollingUtilCzcMapper.updCardUsedByDayIsFastDayInMonth(updMap);
|
||||
log.info("年套餐日常轮询 :卡号{},用量{},剩余{}",iccid,used,remaining);
|
||||
}else{
|
||||
//未知类型套餐
|
||||
log.info("卡:{},订购未知资费包,用量:{}",iccid,used);
|
||||
Map<String, Object> infoUsedMap = yzCardPollingUtilCzcMapper.selCardOne(iccid);
|
||||
String oldUsed = infoUsedMap.get("used").toString();
|
||||
double remaining = Double.parseDouble(infoUsedMap.get("remaining").toString());
|
||||
double r = used - Double.parseDouble(oldUsed);
|
||||
updMap.put("remaining",remaining-r);
|
||||
updMap.put("used",used);
|
||||
updMap.put("iccid",iccid);
|
||||
yzCardPollingUtilCzcMapper.updCardUsedByDayIsFastDayInMonth(updMap);
|
||||
log.info("年套餐日常轮询 :卡号{},用量{},剩余{}",iccid,used,remaining);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String nowDateShortNuber = VeDate.getNowDateShortNuber();
|
||||
System.out.println(nowDateShortNuber);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user