zoujiajian 3 лет назад
Родитель
Сommit
79e693e8eb

+ 29 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/PhoneAreaCode.java

@@ -0,0 +1,29 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCode
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:48
+ */
+@Getter
+@Setter
+public class PhoneAreaCode {
+	@TableId(type = IdType.AUTO)
+	private Integer id;
+
+	private String nameCn;
+
+	private String nameUs;
+
+	private Integer areaCode;
+
+	private String continent;
+
+	private Integer sorted;
+}

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/PhoneCode.java

@@ -15,4 +15,6 @@ public class PhoneCode extends BaseEntity{
 	private String phone;
 
 	private String code;
+
+	private Integer cid;
 }

+ 28 - 0
netflix-dao/src/main/java/com/cyksj/model/views/PhoneAreaCodeView.java

@@ -0,0 +1,28 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.SearchBean;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCodeView
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:16
+ */
+@Getter
+@Setter
+@SearchBean(tables = "phone_area_code",
+		orderBy = "sorted")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class PhoneAreaCodeView implements Serializable {
+
+	private String nameCn;
+
+	private String nameUs;
+
+	private Integer areaCode;
+}

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -609,6 +609,7 @@ public class RedisService {
         QUESTION_RESPONSE_KEY("question_response_key:%s", "问卷回答key", 60 * 60 * 24L),
         IMPORT_ACCOUNT_CACHE_KEY("import_account_cache_key:%s", "导入缓存key", 60 * 10L),
         MAKERTING_MSG_KEY("makerting_msg_key", "营销短信", 60 * 60 * 24 * 30),
+        PHONE_AREA_CODE("phone_area_code:key", "国家或地区码", 60 * 60 * 24 * 15),
         ;
 
         private String name;

+ 1 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -330,6 +330,7 @@ public class AuthorizationController {
         String code = StringUtil.getRandomCodeStr(digit);
         phoneCode.setCode(code);
         if (phoneCode.getId() == null) {
+            phoneCode.setCid(cid);
             phoneCodeMapper.insert(phoneCode);
         } else phoneCodeMapper.updateById(phoneCode);
         if (!isFree) {

+ 55 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/PhoneAreaCodeController.java

@@ -0,0 +1,55 @@
+package com.cyksj.web.controller.user;
+
+import cn.hutool.core.util.StrUtil;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.model.views.PhoneAreaCodeView;
+import com.cyksj.redis.RedisService;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCodeController
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:09
+ */
+@RestController
+@RequestMapping("/applets/phone")
+@Slf4j
+@RequiredArgsConstructor
+public class PhoneAreaCodeController {
+	private final BeanSearcher beanSearcher;
+
+	private final RedisService redisService;
+
+	/**
+	 * 获取国家或地区手机号代码
+	 */
+	@GetMapping("/get/areaCode")
+	public Result<List<PhoneAreaCodeView>> getPhoneAreaCode(String name) throws Exception {
+		String key = RedisService.key.PHONE_AREA_CODE.getName();
+		Object value = redisService.get(key);
+		List<PhoneAreaCodeView> phoneAreaCodeViews = null;
+		if (value == null) {
+			phoneAreaCodeViews = beanSearcher.searchAll(PhoneAreaCodeView.class, MapUtils.builder().build());
+			redisService.setNx(key, Jsons.toJson(phoneAreaCodeViews), RedisService.key.PHONE_AREA_CODE.getTimeout());
+		}
+		if (phoneAreaCodeViews == null) {
+			phoneAreaCodeViews = Jsons.parseList(value.toString(), PhoneAreaCodeView.class);
+		}
+		if (StrUtil.isNotBlank(name)) {
+			phoneAreaCodeViews = phoneAreaCodeViews.stream().filter(view -> view.getNameCn().contains(name)).collect(Collectors.toList());
+		}
+		return GatewayResponse.SUCCESS.newBuilder().toResult(phoneAreaCodeViews);
+	}
+}