mirror of
https://gitee.com/sdyunze/iotlink.git
synced 2026-09-01 15:33:12 +08:00
fix:
1. 添加电信dcp接口 2. 无激活sql优化
This commit is contained in:
@@ -37,6 +37,10 @@
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yunze.apiCommon.Vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName DxDetail
|
||||
* @Description
|
||||
* @Author QiMing
|
||||
* @Date 2022/11/8 11:14
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class DxDetail {
|
||||
|
||||
private String enterprise;
|
||||
private Date firstActivatedAt;
|
||||
private String iccid;
|
||||
private String detectedImei;
|
||||
private String imsi;
|
||||
private Date lastSubscriptionPackageChangeAt;
|
||||
private Date lastSubscriptionChangeDateAt;
|
||||
private String msisdn;
|
||||
private String organizationId;
|
||||
private String state;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.yunze.apiCommon.config;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @ClassName RestTemplateConfig
|
||||
* @Description
|
||||
* @Author QiMing
|
||||
* @Date 2022/11/4 23:28
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@ConditionalOnMissingBean(RestTemplate.class)
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用HttpClient作为底层客户端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ClientHttpRequestFactory getClientHttpRequestFactory() {
|
||||
int timeout = 5000;
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setConnectTimeout(timeout)
|
||||
.setConnectionRequestTimeout(timeout)
|
||||
.setSocketTimeout(timeout)
|
||||
.build();
|
||||
CloseableHttpClient client = HttpClientBuilder
|
||||
.create()
|
||||
.setDefaultRequestConfig(config)
|
||||
.build();
|
||||
return new HttpComponentsClientHttpRequestFactory(client);
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package com.yunze.apiCommon.upstreamAPI.DianXinDCP.qm;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunze.apiCommon.Vo.DxDetail;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName DxDcpUtil
|
||||
* @Description
|
||||
* @Author QiMing
|
||||
* @Date 2022/11/7 15:49
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DxDcpUtil {
|
||||
|
||||
@Resource
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public DxDcpUtil(Map<String, Object> init_map) {
|
||||
Object cd_username1 = init_map.get("cd_username");
|
||||
if (null != cd_username1) {
|
||||
String cd_username[] = init_map.get("cd_username").toString().split(",");
|
||||
String cd_pwd[] = init_map.get("cd_pwd").toString().split(",");
|
||||
username = cd_username[0];
|
||||
password = cd_pwd[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: getToken
|
||||
* @Description: //
|
||||
* @Param: []
|
||||
* @Return: java.lang.String
|
||||
* @Date: 2022/11/7 14:10
|
||||
* @Author: QiMing
|
||||
*/
|
||||
public String getToken(String username, String password) {
|
||||
String token = null;
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
map.add("grant_type", "password");
|
||||
map.add("client_id", "client_id");
|
||||
map.add("username", username);
|
||||
map.add("password", password);
|
||||
|
||||
HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity(map, httpHeaders);
|
||||
try {
|
||||
ResponseEntity<Map> exchange = restTemplate.exchange("https://global.ct10649.com/iot/api/auth/token", HttpMethod.POST, httpEntity, Map.class);
|
||||
Map<String, Object> body = exchange.getBody();
|
||||
if (null == body) {
|
||||
return getToken(username, password);
|
||||
}
|
||||
Object access_token = body.get("access_token");
|
||||
token = "Bearer " + access_token;
|
||||
} catch (Exception e) {
|
||||
log.error("com.yunze.apiCommon.upstreamAPI.DianXinDCP.qm.DxApi.getToken ---- {}", e.getMessage());
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private String url = "https://global.ct10649.com/iot/api/subscriptions/details?additionalFields=DATES";
|
||||
|
||||
public DxDetail subscriptions(String iccid, Map<String, Object> init_map) {
|
||||
DxDcpUtil dxDcpUtil = new DxDcpUtil(init_map);
|
||||
Object sica_token_dx = redisTemplate.opsForValue().get(dxDcpUtil.password + "SICA_TOKEN_DX");
|
||||
String token = sica_token_dx == null ? "" : sica_token_dx.toString();
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
token = getToken(dxDcpUtil.username, dxDcpUtil.password);
|
||||
if (!StringUtils.isEmpty(token.trim())) {
|
||||
redisTemplate.opsForValue().set(dxDcpUtil.password + "SICA_TOKEN_DX", token, 25, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(iccid);
|
||||
map.put("identifierValues", list);
|
||||
map.put("identifierType", "ICC");
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
httpHeaders.add(HttpHeaders.AUTHORIZATION, token);
|
||||
HttpEntity<String> httpEntity = new HttpEntity(map, httpHeaders);
|
||||
try {
|
||||
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
||||
if (200 != exchange.getStatusCodeValue()) {
|
||||
return null;
|
||||
}
|
||||
String body = exchange.getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
JSONArray jsonArray = JSONObject.parseArray(jsonObject.get("subscriptions").toString());
|
||||
DxDetail vo = JSONObject.parseObject(jsonArray.get(0).toString(), DxDetail.class);
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("com.yunze.apiCommon.upstreamAPI.DianXinDCP.qm.DxApi.subscriptions ---- {}", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.yunze.apiCommon.upstreamAPI;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yunze.apiCommon.mapper.YzCardRouteMapper;
|
||||
import com.yunze.apiCommon.upstreamAPI.DianXinCMP.Inquire.Query_DX;
|
||||
@@ -10,17 +9,18 @@ import com.yunze.apiCommon.upstreamAPI.DianXinCMP5G.Inquire.Query_DX5G;
|
||||
import com.yunze.apiCommon.upstreamAPI.DianXinCMP5G.change.ServiceAccept_DX5G;
|
||||
import com.yunze.apiCommon.upstreamAPI.DianXinDCP.DcpDxService;
|
||||
import com.yunze.apiCommon.upstreamAPI.DianXinDCP.change.serviceAccept_DianXinDCP;
|
||||
import com.yunze.apiCommon.upstreamAPI.DianXinDCP.qm.DxDcpUtil;
|
||||
import com.yunze.apiCommon.upstreamAPI.IoTLink.Inquire.Query_IoTLink;
|
||||
import com.yunze.apiCommon.upstreamAPI.IoTLink.change.serviceAccept_IoTLink;
|
||||
import com.yunze.apiCommon.upstreamAPI.LianTongCMP.Inquire.Query_LT;
|
||||
import com.yunze.apiCommon.upstreamAPI.LianTongCMP.change.serviceAccept_LT;
|
||||
import com.yunze.apiCommon.upstreamAPI.SDYiDong.Inquire.Query_Sdiot;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEC.Inquire.Query_YD;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEC.YD_EC_Api;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEC.change.serviceAccept_YD;
|
||||
import com.yunze.apiCommon.upstreamAPI.YiDongEcV2.Inquire.Query_EcV2;
|
||||
import com.yunze.apiCommon.utils.VeDate;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -39,6 +39,10 @@ public class PublicApiService {
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private DxDcpUtil dxDcpUtil;
|
||||
|
||||
/**
|
||||
* 内部API 调用
|
||||
* @param Param
|
||||
@@ -671,6 +675,8 @@ public class PublicApiService {
|
||||
serviceAccept_DianXinDCP Ser = new serviceAccept_DianXinDCP(find_card_route_map);
|
||||
//bind_type = 联系人姓名 imei = 联系人手机号码
|
||||
rmap.put("data",Ser.realNameRemove(iccid,"iccid"));
|
||||
}else if(function_name.equals("queryCardActiveTime")){
|
||||
rmap.put("data",dxDcpUtil.subscriptions(iccid, find_card_route_map));
|
||||
}
|
||||
|
||||
rmap.put("Message", "操作成功");
|
||||
|
||||
@@ -2,11 +2,9 @@ package com.yunze.apiCommon.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunze.apiCommon.mapper.YzCardRouteMapper;
|
||||
import com.yunze.apiCommon.Vo.DxDetail;
|
||||
import com.yunze.apiCommon.upstreamAPI.PublicApiService;
|
||||
import com.yunze.apiCommon.utils.Arith;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -1147,6 +1145,16 @@ public class ApiUtil_NoStatic{
|
||||
} else {
|
||||
statusMessage = Data.get("message").toString();
|
||||
}
|
||||
} else if (cd_code.equals("DianXin_DCP")) {
|
||||
Object data1 = data.get("data");
|
||||
if (null != data1) {
|
||||
DxDetail dxDetail = JSONObject.parseObject(JSON.toJSONString(data1), DxDetail.class);
|
||||
statusCode = 200;
|
||||
if (null != dxDetail.getFirstActivatedAt()) {
|
||||
activateDate = DateUtil.getDate2Str(DateUtil.DATE_FULL_STR, dxDetail.getFirstActivatedAt());
|
||||
openDate = activateDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Outdata.put("Message", data.get("Message"));
|
||||
|
||||
@@ -1864,27 +1864,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
a.iccid,
|
||||
b.iccid,
|
||||
b.msisdn AS card_no,
|
||||
b.used,
|
||||
<![CDATA[( (IF( a.test_period_last_time > a.silent_period_last_time, a.test_period_last_time, a.silent_period_last_time ))]]> AS last_time,
|
||||
case when (a.test_period_last_time > a.silent_period_last_time) then a.test_period_last_time else a.silent_period_last_time end AS last_time,
|
||||
b.activate_date,
|
||||
b.syn_Time,
|
||||
b.deliver_date,
|
||||
b.network_type
|
||||
FROM
|
||||
yz_card_info_expand a,
|
||||
yz_card_info b
|
||||
yz_card_info_expand a right join yz_card_info b on a.iccid = b.iccid
|
||||
WHERE
|
||||
a.iccid = b.iccid
|
||||
AND channel_id = #{channel_id}
|
||||
and LENGTH(trim( b.activate_date )) <![CDATA[ < ]]> 1
|
||||
AND ISNULL( b.deliver_date ) = 1
|
||||
b.channel_id = #{channel_id}
|
||||
and trim(b.activate_date) is null
|
||||
AND ISNULL(b.deliver_date) = 1
|
||||
and b.is_polling = 1
|
||||
)
|
||||
xu
|
||||
WHERE
|
||||
xu.last_time<![CDATA[( <= ]]> CURRENT_DATE
|
||||
/*WHERE xu.last_time<![CDATA[ <= ]]> CURRENT_DATE*/
|
||||
ORDER BY
|
||||
used DESC,
|
||||
last_time ASC,
|
||||
|
||||
Reference in New Issue
Block a user