Commit 9643630e8b801b968378efdf50fb4eced6c7ec31
1 parent
17bf353d
feature(*): 新增查询进行中待办数量的接口
- 新增查询进行中待办数量的接口
Showing
5 changed files
with
85 additions
and
105 deletions
fw-shirasawa-common/src/main/java/cn/fw/shirasawa/common/utils/MobileUtil.java deleted
1 | -package cn.fw.shirasawa.common.utils; | |
2 | - | |
3 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | -import lombok.Data; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | - | |
7 | -import java.io.IOException; | |
8 | -import java.util.HashMap; | |
9 | -import java.util.Map; | |
10 | - | |
11 | -/** | |
12 | - * 电话号码工具 | |
13 | - * <p> | |
14 | - * | |
15 | - * @author kurisu | |
16 | - */ | |
17 | -@Slf4j | |
18 | -public class MobileUtil { | |
19 | - private final static String JUHE_API = "http://apis.juhe.cn/mobile/get"; | |
20 | - private final static String APP_KEY = "3ae2492bf1b1a382943924e1a1a25e4d"; | |
21 | - private final static ObjectMapper objectMapper = new ObjectMapper(); | |
22 | - | |
23 | - public static String attribution(String mobile) { | |
24 | - if (StringUtils.isEmpty(mobile)) { | |
25 | - return ""; | |
26 | - } | |
27 | - final Map<String, String> param = new HashMap<>(); | |
28 | - param.put("phone", mobile); | |
29 | - param.put("key", APP_KEY); | |
30 | - final String resultString = HttpClientUtil.doGet(JUHE_API, param); | |
31 | - try { | |
32 | - final JuHeResult juHeResult = objectMapper.readValue(resultString, JuHeResult.class); | |
33 | - final int errorCode = Integer.valueOf(juHeResult.getError_code()); | |
34 | - final String reason = juHeResult.getReason(); | |
35 | - if (errorCode != 0) { | |
36 | - log.error("调用聚合API获取手机号码:{} 归属地异常:{}", mobile, errorCode + ":" + reason); | |
37 | - return ""; | |
38 | - } | |
39 | - final String province = juHeResult.getResult().getProvince(); | |
40 | - final String city = juHeResult.getResult().getCity(); | |
41 | - return province.concat(" ").concat(city); | |
42 | - } catch (IOException e) { | |
43 | - e.printStackTrace(); | |
44 | - } | |
45 | - return "未知"; | |
46 | - } | |
47 | - | |
48 | - @Data | |
49 | - public static class JuHeResult { | |
50 | - /** | |
51 | - * 错误码 | |
52 | - */ | |
53 | - private String error_code; | |
54 | - /** | |
55 | - * 结果 | |
56 | - */ | |
57 | - private String resultcode; | |
58 | - /** | |
59 | - * 错误原因 | |
60 | - */ | |
61 | - private String reason; | |
62 | - /** | |
63 | - * 结果 | |
64 | - */ | |
65 | - private Result result; | |
66 | - | |
67 | - | |
68 | - } | |
69 | - | |
70 | - @Data | |
71 | - public static class Result { | |
72 | - /** | |
73 | - * 省 | |
74 | - */ | |
75 | - private String province; | |
76 | - /** | |
77 | - * 市 | |
78 | - */ | |
79 | - private String city; | |
80 | - /** | |
81 | - * 区划编码 | |
82 | - */ | |
83 | - private String areacode; | |
84 | - /** | |
85 | - * 邮编 | |
86 | - */ | |
87 | - private String zip; | |
88 | - /** | |
89 | - * 公司 | |
90 | - */ | |
91 | - private String company; | |
92 | - /** | |
93 | - * | |
94 | - */ | |
95 | - private String card; | |
96 | - | |
97 | - } | |
98 | - | |
99 | -} | |
100 | 0 | \ No newline at end of file |
fw-shirasawa-common/src/main/java/cn/fw/shirasawa/common/utils/MobileUtil.kt
0 → 100644
1 | +package cn.fw.shirasawa.common.utils | |
2 | + | |
3 | +import cn.fw.common.annotation.NoArg | |
4 | +import com.fasterxml.jackson.databind.ObjectMapper | |
5 | +import org.slf4j.LoggerFactory | |
6 | +import java.io.IOException | |
7 | + | |
8 | + | |
9 | +/** | |
10 | + * | |
11 | + * 电话号码工具类 | |
12 | + * | |
13 | + * @className : MobileUtil | |
14 | + * @description : 电话号码工具类 | |
15 | + * @author : kurisu | |
16 | + * @date : 2023-03-14 16:49 | |
17 | + * @version : 1.0 | |
18 | + */ | |
19 | + | |
20 | +private const val API_URL = "http://phone.kinako.com.cn/query" | |
21 | +private val objectMapper = ObjectMapper() | |
22 | +private val log = LoggerFactory.getLogger("MobileUtil"); | |
23 | + | |
24 | +fun attribution(mobile: String): String { | |
25 | + if (StringUtils.isEmpty(mobile)) { | |
26 | + return "" | |
27 | + } | |
28 | + val param: MutableMap<String, String> = HashMap() | |
29 | + param["phone"] = mobile | |
30 | + val resultString = HttpClientUtil.doGet(API_URL, param) | |
31 | + try { | |
32 | + val phoneResult = objectMapper.readValue(resultString, PhoneResult::class.java) | |
33 | + val reason = phoneResult.result | |
34 | + if (phoneResult.code != 0) { | |
35 | + log.error("调用API获取手机号码:{} 归属地异常:{}", mobile, phoneResult.code.toString() + ":" + reason) | |
36 | + return "" | |
37 | + } | |
38 | + log.info("手机号码:{} 归属地信息:{}", mobile, phoneResult.toString()) | |
39 | + val province = phoneResult.data?.province ?: "" | |
40 | + val city = phoneResult.data?.city ?: "" | |
41 | + return "$province $city" | |
42 | + } catch (e: IOException) { | |
43 | + e.printStackTrace() | |
44 | + } | |
45 | + return "" | |
46 | +} | |
47 | + | |
48 | +@NoArg | |
49 | +data class PhoneResult(val code: Int, val result: String, val success: Boolean, val data: Result?) { | |
50 | + override fun toString(): String { | |
51 | + return "PhoneResult(code=$code, result='$result', success=$success, data=$data)" | |
52 | + } | |
53 | +} | |
54 | + | |
55 | +@NoArg | |
56 | +data class Result( | |
57 | + val province: String?, | |
58 | + val city: String?, | |
59 | + val area_code: String?, | |
60 | + val zip_code: String?, | |
61 | + val card_type: String? | |
62 | +) { | |
63 | + override fun toString(): String { | |
64 | + return "Result(province=$province, city=$city, area_code=$area_code, zip_code=$zip_code, card_type=$card_type)" | |
65 | + } | |
66 | +} | ... | ... |
fw-shirasawa-rpc/src/main/java/cn/fw/shirasawa/rpc/member/MemberRpcService.java
... | ... | @@ -6,14 +6,17 @@ import cn.fw.member.sdk.api.MemberApi; |
6 | 6 | import cn.fw.member.sdk.vo.BatchUserParam; |
7 | 7 | import cn.fw.member.sdk.vo.MobileLocation; |
8 | 8 | import cn.fw.member.sdk.vo.UserBaseInfoVO; |
9 | +import cn.fw.shirasawa.common.utils.MobileUtilKt; | |
9 | 10 | import cn.fw.shirasawa.rpc.AbsBaseRpcService; |
10 | 11 | import cn.fw.shirasawa.rpc.member.dto.MemberUserDTO; |
11 | 12 | import com.alibaba.fastjson.JSONObject; |
13 | +import lombok.Getter; | |
12 | 14 | import lombok.RequiredArgsConstructor; |
13 | 15 | import lombok.extern.slf4j.Slf4j; |
14 | 16 | import org.apache.commons.lang3.StringUtils; |
15 | 17 | import org.springframework.beans.BeanUtils; |
16 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | +import org.springframework.cache.annotation.Cacheable; | |
17 | 20 | import org.springframework.stereotype.Service; |
18 | 21 | import org.springframework.util.CollectionUtils; |
19 | 22 | |
... | ... | @@ -148,14 +151,19 @@ public class MemberRpcService extends AbsBaseRpcService { |
148 | 151 | * @param mobile |
149 | 152 | * @return |
150 | 153 | */ |
154 | + @Cacheable(cacheNames = "mobile:attribution", key = "#mobile", unless = "#result.isEmpty()") | |
151 | 155 | public String attribution(final String mobile) { |
152 | 156 | if (StringUtils.isBlank(mobile)) { |
153 | - return null; | |
157 | + return ""; | |
154 | 158 | } |
155 | 159 | try { |
160 | + String attribution = MobileUtilKt.attribution(mobile); | |
161 | + if (StringUtils.isNotBlank(attribution)) { | |
162 | + return attribution; | |
163 | + } | |
156 | 164 | Message<MobileLocation> msg = functionApi.queryMobileLocation(mobile); |
157 | 165 | if (!msg.isSuccess()) { |
158 | - return null; | |
166 | + return ""; | |
159 | 167 | } |
160 | 168 | MobileLocation data = msg.getData(); |
161 | 169 | if (data != null) { |
... | ... | @@ -165,11 +173,11 @@ public class MemberRpcService extends AbsBaseRpcService { |
165 | 173 | } |
166 | 174 | } catch (Exception ignored) { |
167 | 175 | } |
168 | - return null; | |
176 | + return ""; | |
169 | 177 | } |
170 | 178 | |
171 | 179 | @Override |
172 | - protected String getKeyPrefix() { | |
180 | + public String getKeyPrefix() { | |
173 | 181 | return this.keyPrefix; |
174 | 182 | } |
175 | 183 | } | ... | ... |
fw-shirasawa-server/src/main/resources/application.yml
fw-shirasawa-service/src/main/java/cn/fw/shirasawa/service/bus/follow/strategy/AbstractFollowStrategy.java
1 | 1 | package cn.fw.shirasawa.service.bus.follow.strategy; |
2 | 2 | |
3 | 3 | import cn.fw.shirasawa.common.utils.DateUtil; |
4 | -import cn.fw.shirasawa.common.utils.MobileUtil; | |
4 | +import cn.fw.shirasawa.common.utils.MobileUtilKt; | |
5 | 5 | import cn.fw.shirasawa.common.utils.StringUtils; |
6 | 6 | import cn.fw.shirasawa.domain.db.OriginalData; |
7 | 7 | import cn.fw.shirasawa.domain.db.follow.FollowRecord; |
... | ... | @@ -636,7 +636,7 @@ public abstract class AbstractFollowStrategy implements FollowStrategy { |
636 | 636 | vo.setMobile(record.getContacts()); |
637 | 637 | vo.setVin(cluePool.getFrameNo()); |
638 | 638 | vo.setRealMobile(record.getContacts()); |
639 | - vo.setRegion(MobileUtil.attribution(record.getContacts())); | |
639 | + vo.setRegion(memberRpcService.attribution(record.getContacts())); | |
640 | 640 | |
641 | 641 | //默认已经打过电话 |
642 | 642 | Boolean hadCall = Boolean.TRUE; | ... | ... |