|
|
@@ -5,9 +5,11 @@ import org.apache.commons.logging.LogFactory;
|
|
|
import org.linlinjava.litemall.core.util.RegexUtil;
|
|
|
import org.linlinjava.litemall.core.util.ResponseUtil;
|
|
|
import org.linlinjava.litemall.db.domain.LitemallAddress;
|
|
|
+import org.linlinjava.litemall.db.domain.LitemallRegion;
|
|
|
import org.linlinjava.litemall.db.service.LitemallAddressService;
|
|
|
import org.linlinjava.litemall.db.service.LitemallRegionService;
|
|
|
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
|
|
+import org.linlinjava.litemall.wx.service.GetRegionService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
@@ -18,6 +20,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.*;
|
|
|
|
|
|
/**
|
|
|
* 用户收货地址服务
|
|
|
@@ -25,7 +28,7 @@ import java.util.Map;
|
|
|
@RestController
|
|
|
@RequestMapping("/wx/address")
|
|
|
@Validated
|
|
|
-public class WxAddressController {
|
|
|
+public class WxAddressController extends GetRegionService{
|
|
|
private final Log logger = LogFactory.getLog(WxAddressController.class);
|
|
|
|
|
|
@Autowired
|
|
|
@@ -33,6 +36,12 @@ public class WxAddressController {
|
|
|
@Autowired
|
|
|
private LitemallRegionService regionService;
|
|
|
|
|
|
+ private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(6);
|
|
|
+
|
|
|
+ private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();
|
|
|
+
|
|
|
+ private static ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, 6, 1000, TimeUnit.MILLISECONDS, WORK_QUEUE, HANDLER);
|
|
|
+
|
|
|
/**
|
|
|
* 用户收货地址列表
|
|
|
*
|
|
|
@@ -46,17 +55,32 @@ public class WxAddressController {
|
|
|
}
|
|
|
List<LitemallAddress> addressList = addressService.queryByUid(userId);
|
|
|
List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
|
|
|
+ List<LitemallRegion> regionList = getLitemallRegions();
|
|
|
for (LitemallAddress address : addressList) {
|
|
|
Map<String, Object> addressVo = new HashMap<>();
|
|
|
addressVo.put("id", address.getId());
|
|
|
addressVo.put("name", address.getName());
|
|
|
addressVo.put("mobile", address.getMobile());
|
|
|
addressVo.put("isDefault", address.getIsDefault());
|
|
|
- String province = regionService.findById(address.getProvinceId()).getName();
|
|
|
- String city = regionService.findById(address.getCityId()).getName();
|
|
|
- String area = regionService.findById(address.getAreaId()).getName();
|
|
|
- String addr = address.getAddress();
|
|
|
- String detailedAddress = province + city + area + " " + addr;
|
|
|
+ Callable<String> provinceCallable = ()->regionList.stream().filter(region->region.getId().equals(address.getProvinceId())).findAny().orElse(null).getName();
|
|
|
+ Callable<String> cityCallable = ()->regionList.stream().filter(region->region.getId().equals(address.getCityId())).findAny().orElse(null).getName();
|
|
|
+ Callable<String> areaCallable = ()->regionList.stream().filter(region->region.getId().equals(address.getAreaId())).findAny().orElse(null).getName();
|
|
|
+ FutureTask<String> provinceNameCallableTask = new FutureTask<>(provinceCallable);
|
|
|
+ FutureTask<String> cityNameCallableTask = new FutureTask<>(cityCallable);
|
|
|
+ FutureTask<String> areaNameCallableTask = new FutureTask<>(areaCallable);
|
|
|
+ executorService.submit(provinceNameCallableTask);
|
|
|
+ executorService.submit(cityNameCallableTask);
|
|
|
+ executorService.submit(areaNameCallableTask);
|
|
|
+ String detailedAddress="";
|
|
|
+ try {
|
|
|
+ String province=provinceNameCallableTask.get();
|
|
|
+ String city =cityNameCallableTask.get();
|
|
|
+ String area =areaNameCallableTask.get();
|
|
|
+ String addr = address.getAddress();
|
|
|
+ detailedAddress = province + city + area + " " + addr;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
addressVo.put("detailedAddress", detailedAddress);
|
|
|
|
|
|
addressVoList.add(addressVo);
|