提交 70f7dc62 authored 作者: 吴德鹏's avatar 吴德鹏

国家管理

上级 08d8bf91
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.Country;
import com.example.afrishop_v3.repository.CountryRepository;
import com.example.afrishop_v3.util.HttpsUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.testng.annotations.Test;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Auther: wudepeng
* @Date: 2021/01/14
* @Description:国家管理
*/
@RestController
@RequestMapping("/country")
public class CountryController extends Controller {
private static Logger logger = LoggerFactory.getLogger(CountryController.class);
private final CountryRepository countryRepository;
public CountryController(CountryRepository countryRepository) {
this.countryRepository = countryRepository;
}
@GetMapping
public Result findAllCountries(@RequestParam(value = "country", required = false) String country,
HttpServletRequest request) throws IOException {
Map<String, Object> params = new HashMap<>();
//所有国家
List<Country> countries = countryRepository.findAllByCountryName(country);
//过滤非空(信息不完善)的国家
List<Country> collect = countries.stream()
.filter(c -> StringUtils.isNotBlank(c.getCountryName()))
.filter(c -> StringUtils.isNotBlank(c.getAreaCode()))
.filter(c -> StringUtils.isNotBlank(c.getNationalFlag()))
.collect(Collectors.toList());
//获取客户端ip
String ip = this.getRealIpAddress(request);
String countryName = HttpsUtil.useIpFindCountry(ip);
logger.info("ip:" + ip);
logger.info("countryName:" + countryName);
//根据ip查询国家
List<Country> list = countryRepository.findAllByCountryName(countryName);
//获取默认的国家
Optional<Country> defaultCountry = list.stream().findFirst();
params.put("countries", collect);
params.put("defaultCountry", defaultCountry.orElse(collect.get(0)));
return new Result(params);
}
}
package com.example.afrishop_v3.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Where;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 country
*
* @author lipengjun
* @date 2021-01-14 08:18:53
*/
@Where(clause = "status=1")
@Entity
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 国家ID
*/
@Id
private String id;
/**
* 国家名称
*/
private String countryName;
/**
* 国家(中文)
*/
private String countryCname;
/**
* 区号
*/
private String areaCode;
/**
* 国旗
*/
private String nationalFlag;
/**
* 设置:国家ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:国家ID
*/
public String getId() {
return id;
}
/**
* 设置:国家名称
*/
public void setCountryName(String countryName) {
this.countryName = countryName;
}
/**
* 获取:国家名称
*/
public String getCountryName() {
return countryName;
}
/**
* 设置:国家(中文)
*/
public void setCountryCname(String countryCname) {
this.countryCname = countryCname;
}
/**
* 获取:国家(中文)
*/
public String getCountryCname() {
return countryCname;
}
/**
* 设置:区号
*/
public void setAreaCode(String areaCode) {
this.areaCode = areaCode;
}
/**
* 获取:区号
*/
public String getAreaCode() {
return areaCode;
}
/**
* 设置:国旗
*/
public void setNationalFlag(String nationalFlag) {
this.nationalFlag = nationalFlag;
}
/**
* 获取:国旗
*/
public String getNationalFlag() {
return nationalFlag;
}
@Override
public String toString() {
return "Country{" +
"id='" + id + '\'' +
", countryName='" + countryName + '\'' +
", countryCname='" + countryCname + '\'' +
", areaCode='" + areaCode + '\'' +
", nationalFlag='" + nationalFlag + '\'' +
'}';
}
}
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.Country;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @Auther: wudepeng
* @Date: 2021/01/14
* @Description:
*/
public interface CountryRepository extends JpaRepository<Country, String> {
// @Query(value = "select c from #{#entityName} c where c.countryName=:country order by c.sort,c.countryName")
@Query(value = "select c.id,c.country_name,c.country_cname,c.area_code,c.national_flag from country c where if(?1!='',c.country_name like concat('%',?1,'%') or c.country_cname like concat('%',?1,'%'),1=1) order by c.sort asc ,c.country_name asc", nativeQuery = true)
List<Country> findAllByCountryName(String country);
}
...@@ -70,7 +70,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -70,7 +70,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests().antMatchers("/api/auth/**", "/search/image/**", "/itemStation/**", "/startPage/**", .authorizeRequests().antMatchers("/api/auth/**", "/search/image/**", "/itemStation/**", "/startPage/**",
"/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**", "/version/**", "/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**", "/version/**",
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**", "/paypal/**", "/discover/bonus/**", "/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**", "/paypal/**", "/discover/bonus/**",
"/problem/**", "/cube/**", "/activity/**", "/attributes/**", "/stripe/**", "/coupon/**", "/logistics/freeShippingThreshold","/visit/**").permitAll() "/problem/**", "/cube/**", "/activity/**", "/attributes/**", "/stripe/**", "/coupon/**", "/logistics/freeShippingThreshold",
"/visit/**", "/search/**", "/country/**").permitAll()
.antMatchers("/api/test/**").permitAll() .antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
......
...@@ -89,7 +89,7 @@ paypal: ...@@ -89,7 +89,7 @@ paypal:
mode: live mode: live
stripe: stripe:
success_url: https://app.afrieshop.com/afrishop/stripe/success success_url: https://app.afrieshop.com/zion/stripe/success
cancel_url: https://app.afrieshop.com/afrishop/stripe/cancel cancel_url: https://app.afrieshop.com/zion/stripe/cancel
public_key: pk_test_y5dXLjyUyBD11Ta9g2DGynxN0048vnmpGz public_key: pk_test_y5dXLjyUyBD11Ta9g2DGynxN0048vnmpGz
secret_key: sk_test_tGl2q7Omxehpli7R3Z6xU6G900iL1eX32c secret_key: sk_test_tGl2q7Omxehpli7R3Z6xU6G900iL1eX32c
package com.example.afrishop_v3; //package com.example.afrishop_v3;
//
import com.example.afrishop_v3.models.JsonTag; //import com.example.afrishop_v3.models.Country;
import com.example.afrishop_v3.models.TbCfOrder; //import com.example.afrishop_v3.models.JsonTag;
import com.example.afrishop_v3.models.Token; //import com.example.afrishop_v3.models.TbCfOrder;
import com.example.afrishop_v3.repository.TbCfOrderRepository; //import com.example.afrishop_v3.models.Token;
import com.example.afrishop_v3.repository.TokenRepository; //import com.example.afrishop_v3.repository.CountryRepository;
import com.google.gson.JsonObject; //import com.example.afrishop_v3.repository.TbCfOrderRepository;
import net.sf.json.JSONObject; //import com.example.afrishop_v3.repository.TokenRepository;
import org.junit.jupiter.api.Test; //import com.example.afrishop_v3.util.IdUtil;
import org.junit.runner.Result; //import com.google.gson.JsonObject;
import org.junit.runner.RunWith; //import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired; //import net.sf.json.JSONObject;
import org.springframework.boot.test.context.SpringBootTest; //import org.junit.Test;
import org.springframework.http.ResponseEntity; //import org.junit.runner.Result;
import org.springframework.test.context.junit4.SpringRunner; //import org.junit.runner.RunWith;
import org.springframework.web.client.RestTemplate; //import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
import java.text.SimpleDateFormat; //import org.springframework.http.ResponseEntity;
import java.time.LocalDateTime; //import org.springframework.test.context.junit4.SpringRunner;
import java.util.*; //import org.springframework.web.client.RestTemplate;
//
@RunWith(SpringRunner.class) //import java.text.SimpleDateFormat;
@SpringBootTest //import java.time.LocalDateTime;
public class AfrishopV3ApplicationTests { //import java.util.*;
//import java.util.concurrent.ExecutorService;
RestTemplate restTemplate = new RestTemplate(); //import java.util.concurrent.Executors;
//import java.util.concurrent.Future;
@Test //import java.util.concurrent.locks.ReentrantLock;
void contextLoads() { //
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //@RunWith(SpringRunner.class)
String now = format.format(new Date()); //@SpringBootTest
System.out.println(now); //public class AfrishopV3ApplicationTests {
} //
// RestTemplate restTemplate = new RestTemplate();
private String url = "http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing"; //
@Autowired // @Test
private TbCfOrderRepository orderRepository; // public void contextLoads() {
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// post35789572fbf643cdab55901d1dc511a6 // String now = format.format(new Date());
// userInfo00297bf300ed45e092a5182dececad21 // System.out.println(now);
// productSharervv32GmG4q // }
// amount0.9 //
// orderId008272b1fb994aef9b199449f46d5aa5 // private String url = "http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing";
// @Autowired
@Test // private TbCfOrderRepository orderRepository;
public void test1() { //
//// post35789572fbf643cdab55901d1dc511a6
Optional<TbCfOrder> byId = orderRepository.findById("12a9d7d1042348278c97980a00fc67c4"); //// userInfo00297bf300ed45e092a5182dececad21
JSONObject json=new JSONObject(); //// productSharervv32GmG4q
json.put("userInfo", "32dcda5a709c4265a6f01686ae9b1c1c"); //// amount0.9
json.put("amount", byId.get().getItemsPrice()); //// orderId008272b1fb994aef9b199449f46d5aa5
json.put("orderId","12a9d7d1042348278c97980a00fc67c4"); //
System.out.println(json); // @Test
ResponseEntity<Result> resultResponseEntity = restTemplate.postForEntity(url, json, Result.class); // public void test1() {
System.err.println(resultResponseEntity); //
} // Optional<TbCfOrder> byId = orderRepository.findById("12a9d7d1042348278c97980a00fc67c4");
// JSONObject json = new JSONObject();
@Autowired // json.put("userInfo", "32dcda5a709c4265a6f01686ae9b1c1c");
private TokenRepository tokenRepository; // json.put("amount", byId.get().getItemsPrice());
// json.put("orderId", "12a9d7d1042348278c97980a00fc67c4");
@Test // System.out.println(json);
public void test2(){ // ResponseEntity<Result> resultResponseEntity = restTemplate.postForEntity(url, json, Result.class);
List list=new ArrayList(); // System.err.println(resultResponseEntity);
list.add(2); // }
list.add(1); //
list.add(3); // @Autowired
list.forEach(System.out::println); // private TokenRepository tokenRepository;
//
} // @Autowired
// private CountryRepository countryRepository;
} //
//
// @Test
// public void test2() {
// List list = new ArrayList();
// list.add(2);
// list.add(1);
// list.add(3);
// list.forEach(System.out::println);
//
// }
//
// private ReentrantLock reentrantLock = new ReentrantLock();
//
// @Test
// public void testImport() {
// ExecutorService executorService = Executors.newCachedThreadPool();
//
// for (int i = 0; i < 20; i++) {
// executorService.execute(() -> importCountry());
// }
//
// }
//
// @Test
// public void importCountry() {
//
// String url = "https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8";
// ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
// String body = forEntity.getBody();
// System.err.println(body);
// JSONObject jsonObject = JSONObject.fromObject(body);
// String status = jsonObject.getString("status");
// if ("0".equals(status)) {
// JSONArray jsonArray = jsonObject.getJSONArray("result");
// for (int i = 0; i < jsonArray.size(); i++) {
// Country country = new Country();
// JSONObject object = jsonArray.getJSONObject(i);
// String ename = object.getString("ename");
// String cname = object.getString("cname");
// String areaCode = object.getString("areacode");
// String nationalFlag = object.getString("nationalflag");
// country.setAreaCode(areaCode);
// country.setCountryCname(cname);
// country.setCountryName(ename);
// country.setNationalFlag(nationalFlag);
// country.setId(IdUtil.createIdbyUUID());
// countryRepository.save(country);
//
// }
// }
//
//
// }
//
//
//}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论