Commit 878a921a authored by Junling Bu's avatar Junling Bu
Browse files
parents 50028820 950b176f
...@@ -12,9 +12,17 @@ import java.util.List; ...@@ -12,9 +12,17 @@ import java.util.List;
@Service @Service
public class LitemallRegionService { public class LitemallRegionService {
@Resource @Resource
private LitemallRegionMapper regionMapper; private LitemallRegionMapper regionMapper;
public List<LitemallRegion> getAll(){
LitemallRegionExample example = new LitemallRegionExample();
byte b = 4;
example.or().andTypeNotEqualTo(b);
return regionMapper.selectByExample(example);
}
public List<LitemallRegion> queryByPid(Integer parentId) { public List<LitemallRegion> queryByPid(Integer parentId) {
LitemallRegionExample example = new LitemallRegionExample(); LitemallRegionExample example = new LitemallRegionExample();
example.or().andPidEqualTo(parentId); example.or().andPidEqualTo(parentId);
......
package org.linlinjava.litemall.wx.service;
import org.linlinjava.litemall.db.domain.LitemallRegion;
import org.linlinjava.litemall.db.service.LitemallRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author zhy
* @date 2019-01-17 23:07
**/
@Component
public class GetRegionService {
@Autowired
private LitemallRegionService regionService;
private static List<LitemallRegion> litemallRegions;
protected List<LitemallRegion> getLitemallRegions() {
if(litemallRegions==null){
createRegion();
}
return litemallRegions;
}
private synchronized void createRegion(){
if (litemallRegions == null) {
litemallRegions = regionService.getAll();
}
}
}
...@@ -5,9 +5,11 @@ import org.apache.commons.logging.LogFactory; ...@@ -5,9 +5,11 @@ import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.RegexUtil; import org.linlinjava.litemall.core.util.RegexUtil;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallAddress; 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.LitemallAddressService;
import org.linlinjava.litemall.db.service.LitemallRegionService; import org.linlinjava.litemall.db.service.LitemallRegionService;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.GetRegionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -18,6 +20,7 @@ import java.util.ArrayList; ...@@ -18,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.*;
/** /**
* 用户收货地址服务 * 用户收货地址服务
...@@ -25,185 +28,208 @@ import java.util.Map; ...@@ -25,185 +28,208 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/address") @RequestMapping("/wx/address")
@Validated @Validated
public class WxAddressController { public class WxAddressController extends GetRegionService {
private final Log logger = LogFactory.getLog(WxAddressController.class); private final Log logger = LogFactory.getLog(WxAddressController.class);
@Autowired @Autowired
private LitemallAddressService addressService; private LitemallAddressService addressService;
@Autowired
private LitemallRegionService regionService; @Autowired
private LitemallRegionService regionService;
/**
* 用户收货地址列表 private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(6);
*
* @param userId 用户ID private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();
* @return 收货地址列表
*/ private static ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, 6, 1000, TimeUnit.MILLISECONDS, WORK_QUEUE, HANDLER);
@GetMapping("list")
public Object list(@LoginUser Integer userId) { /**
if (userId == null) { * 用户收货地址列表
return ResponseUtil.unlogin(); *
} * @param userId 用户ID
List<LitemallAddress> addressList = addressService.queryByUid(userId); * @return 收货地址列表
List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size()); */
for (LitemallAddress address : addressList) { @GetMapping("list")
Map<String, Object> addressVo = new HashMap<>(); public Object list(@LoginUser Integer userId) {
addressVo.put("id", address.getId()); if (userId == null) {
addressVo.put("name", address.getName()); return ResponseUtil.unlogin();
addressVo.put("mobile", address.getMobile()); }
addressVo.put("isDefault", address.getIsDefault()); List<LitemallAddress> addressList = addressService.queryByUid(userId);
String province = regionService.findById(address.getProvinceId()).getName(); List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
String city = regionService.findById(address.getCityId()).getName(); List<LitemallRegion> regionList = getLitemallRegions();
String area = regionService.findById(address.getAreaId()).getName(); for (LitemallAddress address : addressList) {
String addr = address.getAddress(); Map<String, Object> addressVo = new HashMap<>();
String detailedAddress = province + city + area + " " + addr; addressVo.put("id", address.getId());
addressVo.put("detailedAddress", detailedAddress); addressVo.put("name", address.getName());
addressVo.put("mobile", address.getMobile());
addressVoList.add(addressVo); addressVo.put("isDefault", address.getIsDefault());
} Callable<String> provinceCallable = () -> regionList.stream().filter(region -> region.getId().equals(address.getProvinceId())).findAny().orElse(null).getName();
return ResponseUtil.ok(addressVoList); 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);
* @param userId 用户ID executorService.submit(cityNameCallableTask);
* @param id 收货地址ID executorService.submit(areaNameCallableTask);
* @return 收货地址详情 String detailedAddress = "";
*/ try {
@GetMapping("detail") String province = provinceNameCallableTask.get();
public Object detail(@LoginUser Integer userId, @NotNull Integer id) { String city = cityNameCallableTask.get();
if (userId == null) { String area = areaNameCallableTask.get();
return ResponseUtil.unlogin(); String addr = address.getAddress();
} detailedAddress = province + city + area + " " + addr;
}
LitemallAddress address = addressService.findById(id); catch (Exception e) {
if (address == null) { e.printStackTrace();
return ResponseUtil.badArgumentValue(); }
} addressVo.put("detailedAddress", detailedAddress);
Map<Object, Object> data = new HashMap<Object, Object>(); addressVoList.add(addressVo);
data.put("id", address.getId()); }
data.put("name", address.getName()); return ResponseUtil.ok(addressVoList);
data.put("provinceId", address.getProvinceId()); }
data.put("cityId", address.getCityId());
data.put("areaId", address.getAreaId()); /**
data.put("mobile", address.getMobile()); * 收货地址详情
data.put("address", address.getAddress()); *
data.put("isDefault", address.getIsDefault()); * @param userId 用户ID
String pname = regionService.findById(address.getProvinceId()).getName(); * @param id 收货地址ID
data.put("provinceName", pname); * @return 收货地址详情
String cname = regionService.findById(address.getCityId()).getName(); */
data.put("cityName", cname); @GetMapping("detail")
String dname = regionService.findById(address.getAreaId()).getName(); public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
data.put("areaName", dname); if (userId == null) {
return ResponseUtil.ok(data); return ResponseUtil.unlogin();
} }
private Object validate(LitemallAddress address) { LitemallAddress address = addressService.findById(id);
String name = address.getName(); if (address == null) {
if (StringUtils.isEmpty(name)) { return ResponseUtil.badArgumentValue();
return ResponseUtil.badArgument(); }
}
Map<Object, Object> data = new HashMap<Object, Object>();
// 测试收货手机号码是否正确 data.put("id", address.getId());
String mobile = address.getMobile(); data.put("name", address.getName());
if (StringUtils.isEmpty(mobile)) { data.put("provinceId", address.getProvinceId());
return ResponseUtil.badArgument(); data.put("cityId", address.getCityId());
} data.put("areaId", address.getAreaId());
if (!RegexUtil.isMobileExact(mobile)) { data.put("mobile", address.getMobile());
return ResponseUtil.badArgument(); data.put("address", address.getAddress());
} data.put("isDefault", address.getIsDefault());
String pname = regionService.findById(address.getProvinceId()).getName();
Integer pid = address.getProvinceId(); data.put("provinceName", pname);
if (pid == null) { String cname = regionService.findById(address.getCityId()).getName();
return ResponseUtil.badArgument(); data.put("cityName", cname);
} String dname = regionService.findById(address.getAreaId()).getName();
if (regionService.findById(pid) == null) { data.put("areaName", dname);
return ResponseUtil.badArgumentValue(); return ResponseUtil.ok(data);
} }
Integer cid = address.getCityId(); private Object validate(LitemallAddress address) {
if (cid == null) { String name = address.getName();
return ResponseUtil.badArgument(); if (StringUtils.isEmpty(name)) {
} return ResponseUtil.badArgument();
if (regionService.findById(cid) == null) { }
return ResponseUtil.badArgumentValue();
} // 测试收货手机号码是否正确
String mobile = address.getMobile();
Integer aid = address.getAreaId(); if (StringUtils.isEmpty(mobile)) {
if (aid == null) { return ResponseUtil.badArgument();
return ResponseUtil.badArgument(); }
} if (!RegexUtil.isMobileExact(mobile)) {
if (regionService.findById(aid) == null) { return ResponseUtil.badArgument();
return ResponseUtil.badArgumentValue(); }
}
Integer pid = address.getProvinceId();
String detailedAddress = address.getAddress(); if (pid == null) {
if (StringUtils.isEmpty(detailedAddress)) { return ResponseUtil.badArgument();
return ResponseUtil.badArgument(); }
} if (regionService.findById(pid) == null) {
return ResponseUtil.badArgumentValue();
Boolean isDefault = address.getIsDefault(); }
if (isDefault == null) {
return ResponseUtil.badArgument(); Integer cid = address.getCityId();
} if (cid == null) {
return null; return ResponseUtil.badArgument();
} }
if (regionService.findById(cid) == null) {
/** return ResponseUtil.badArgumentValue();
* 添加或更新收货地址 }
*
* @param userId 用户ID Integer aid = address.getAreaId();
* @param address 用户收货地址 if (aid == null) {
* @return 添加或更新操作结果 return ResponseUtil.badArgument();
*/ }
@PostMapping("save") if (regionService.findById(aid) == null) {
public Object save(@LoginUser Integer userId, @RequestBody LitemallAddress address) { return ResponseUtil.badArgumentValue();
if (userId == null) { }
return ResponseUtil.unlogin();
} String detailedAddress = address.getAddress();
Object error = validate(address); if (StringUtils.isEmpty(detailedAddress)) {
if (error != null) { return ResponseUtil.badArgument();
return error; }
}
Boolean isDefault = address.getIsDefault();
if (address.getIsDefault()) { if (isDefault == null) {
// 重置其他收获地址的默认选项 return ResponseUtil.badArgument();
addressService.resetDefault(userId); }
} return null;
}
if (address.getId() == null || address.getId().equals(0)) {
address.setId(null); /**
address.setUserId(userId); * 添加或更新收货地址
addressService.add(address); *
} else { * @param userId 用户ID
address.setUserId(userId); * @param address 用户收货地址
if (addressService.update(address) == 0) { * @return 添加或更新操作结果
return ResponseUtil.updatedDataFailed(); */
} @PostMapping("save")
} public Object save(@LoginUser Integer userId, @RequestBody LitemallAddress address) {
return ResponseUtil.ok(address.getId()); if (userId == null) {
} return ResponseUtil.unlogin();
}
/** Object error = validate(address);
* 删除收货地址 if (error != null) {
* return error;
* @param userId 用户ID }
* @param address 用户收货地址,{ id: xxx }
* @return 删除操作结果 if (address.getIsDefault()) {
*/ // 重置其他收获地址的默认选项
@PostMapping("delete") addressService.resetDefault(userId);
public Object delete(@LoginUser Integer userId, @RequestBody LitemallAddress address) { }
if (userId == null) {
return ResponseUtil.unlogin(); if (address.getId() == null || address.getId().equals(0)) {
} address.setId(null);
Integer id = address.getId(); address.setUserId(userId);
if (id == null) { addressService.add(address);
return ResponseUtil.badArgument(); } else {
} address.setUserId(userId);
if (addressService.update(address) == 0) {
addressService.delete(id); return ResponseUtil.updatedDataFailed();
return ResponseUtil.ok(); }
} }
return ResponseUtil.ok(address.getId());
}
/**
* 删除收货地址
*
* @param userId 用户ID
* @param address 用户收货地址,{ id: xxx }
* @return 删除操作结果
*/
@PostMapping("delete")
public Object delete(@LoginUser Integer userId, @RequestBody LitemallAddress address) {
if (userId == null) {
return ResponseUtil.unlogin();
}
Integer id = address.getId();
if (id == null) {
return ResponseUtil.badArgument();
}
addressService.delete(id);
return ResponseUtil.ok();
}
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort; ...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.GetRegionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -22,6 +23,7 @@ import java.util.ArrayList; ...@@ -22,6 +23,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.*;
/** /**
* 商品服务 * 商品服务
...@@ -30,275 +32,325 @@ import java.util.Map; ...@@ -30,275 +32,325 @@ import java.util.Map;
@RequestMapping("/wx/goods") @RequestMapping("/wx/goods")
@Validated @Validated
public class WxGoodsController { public class WxGoodsController {
private final Log logger = LogFactory.getLog(WxGoodsController.class); private final Log logger = LogFactory.getLog(WxGoodsController.class);
@Autowired @Autowired
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired
private LitemallGoodsProductService productService; @Autowired
@Autowired private LitemallGoodsProductService productService;
private LitemallIssueService goodsIssueService;
@Autowired @Autowired
private LitemallGoodsAttributeService goodsAttributeService; private LitemallIssueService goodsIssueService;
@Autowired
private LitemallBrandService brandService; @Autowired
@Autowired private LitemallGoodsAttributeService goodsAttributeService;
private LitemallCommentService commentService;
@Autowired @Autowired
private LitemallUserService userService; private LitemallBrandService brandService;
@Autowired
private LitemallCollectService collectService; @Autowired
@Autowired private LitemallCommentService commentService;
private LitemallFootprintService footprintService;
@Autowired @Autowired
private LitemallCategoryService categoryService; private LitemallUserService userService;
@Autowired
private LitemallSearchHistoryService searchHistoryService; @Autowired
@Autowired private LitemallCollectService collectService;
private LitemallGoodsSpecificationService goodsSpecificationService;
@Autowired @Autowired
private LitemallGrouponRulesService rulesService; private LitemallFootprintService footprintService;
@Autowired
/** private LitemallCategoryService categoryService;
* 商品详情
* <p> @Autowired
* 用户可以不登录。 private LitemallSearchHistoryService searchHistoryService;
* 如果用户登录,则记录用户足迹以及返回用户收藏信息。
* @Autowired
* @param userId 用户ID private LitemallGoodsSpecificationService goodsSpecificationService;
* @param id 商品ID
* @return 商品详情 @Autowired
*/ private LitemallGrouponRulesService rulesService;
@GetMapping("detail")
public Object detail(@LoginUser Integer userId, @NotNull Integer id) { private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(9);
// 商品信息
LitemallGoods info = goodsService.findById(id); private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();
// 商品属性 private static ThreadPoolExecutor executorService = new ThreadPoolExecutor(16, 16, 1000, TimeUnit.MILLISECONDS, WORK_QUEUE, HANDLER);
List<LitemallGoodsAttribute> goodsAttributeList = goodsAttributeService.queryByGid(id);
/**
// 商品规格 * 商品详情
// 返回的是定制的GoodsSpecificationVo * <p>
Object specificationList = goodsSpecificationService.getSpecificationVoList(id); * 用户可以不登录。
* 如果用户登录,则记录用户足迹以及返回用户收藏信息。
// 商品规格对应的数量和价格 *
List<LitemallGoodsProduct> productList = productService.queryByGid(id); * @param userId 用户ID
* @param id 商品ID
// 商品问题,这里是一些通用问题 * @return 商品详情
List<LitemallIssue> issue = goodsIssueService.query(); */
@GetMapping("detail")
// 商品品牌商 public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
Integer brandId = info.getBrandId(); // 商品信息
LitemallBrand brand = null; LitemallGoods info = goodsService.findById(id);
if (brandId == 0) {
brand = new LitemallBrand(); // 商品属性
} else { Callable<List> goodsAttributeListCallable = () -> goodsAttributeService.queryByGid(id);
brand = brandService.findById(info.getBrandId());
} // 商品规格 返回的是定制的GoodsSpecificationVo
Callable<Object> objectCallable = () -> goodsSpecificationService.getSpecificationVoList(id);
// 评论
List<LitemallComment> comments = commentService.queryGoodsByGid(id, 0, 2); // 商品规格对应的数量和价格
List<Map<String, Object>> commentsVo = new ArrayList<>(comments.size()); Callable<List> productListCallable = () -> productService.queryByGid(id);
int commentCount = commentService.countGoodsByGid(id, 0, 2);
for (LitemallComment comment : comments) { // 商品问题,这里是一些通用问题
Map<String, Object> c = new HashMap<>(); Callable<List> issueCallable = () -> goodsIssueService.query();
c.put("id", comment.getId());
c.put("addTime", comment.getAddTime()); // 商品品牌商
c.put("content", comment.getContent()); Callable<LitemallBrand> brandCallable = ()->{
LitemallUser user = userService.findById(comment.getUserId()); Integer brandId = info.getBrandId();
c.put("nickname", user.getNickname()); LitemallBrand brand;
c.put("avatar", user.getAvatar()); if (brandId == 0) {
c.put("picList", comment.getPicUrls()); brand = new LitemallBrand();
commentsVo.add(c); } else {
} brand = brandService.findById(info.getBrandId());
Map<String, Object> commentList = new HashMap<>(); }
commentList.put("count", commentCount); return brand;
commentList.put("data", commentsVo); };
//团购信息 // 评论
List<LitemallGrouponRules> rules = rulesService.queryByGoodsId(id); Callable<Map> commentsCallable = () -> {
List<LitemallComment> comments = commentService.queryGoodsByGid(id, 0, 2);
// 用户收藏 List<Map<String, Object>> commentsVo = new ArrayList<>(comments.size());
int userHasCollect = 0; int commentCount = commentService.countGoodsByGid(id, 0, 2);
if (userId != null) { for (LitemallComment comment : comments) {
userHasCollect = collectService.count(userId, id); Map<String, Object> c = new HashMap<>();
} c.put("id", comment.getId());
c.put("addTime", comment.getAddTime());
// 记录用户的足迹 c.put("content", comment.getContent());
if (userId != null) { LitemallUser user = userService.findById(comment.getUserId());
LitemallFootprint footprint = new LitemallFootprint(); c.put("nickname", user.getNickname());
footprint.setUserId(userId); c.put("avatar", user.getAvatar());
footprint.setGoodsId(id); c.put("picList", comment.getPicUrls());
footprintService.add(footprint); commentsVo.add(c);
} }
Map<String, Object> commentList = new HashMap<>();
Map<String, Object> data = new HashMap<>(); commentList.put("count", commentCount);
data.put("info", info); commentList.put("data", commentsVo);
data.put("userHasCollect", userHasCollect); return commentList;
data.put("issue", issue); };
data.put("comment", commentList);
data.put("specificationList", specificationList); //团购信息
data.put("productList", productList); Callable<List> grouponRulesCallable = () ->rulesService.queryByGoodsId(id);
data.put("attribute", goodsAttributeList);
data.put("brand", brand); // 用户收藏
data.put("groupon", rules); int userHasCollect = 0;
if (userId != null) {
//商品分享图片地址 userHasCollect = collectService.count(userId, id);
data.put("shareImage", info.getShareUrl()); }
return ResponseUtil.ok(data);
} // 记录用户的足迹 异步处理
if (userId != null) {
/** executorService.execute(()->{
* 商品分类类目 LitemallFootprint footprint = new LitemallFootprint();
* footprint.setUserId(userId);
* @param id 分类类目ID footprint.setGoodsId(id);
* @return 商品分类类目 footprintService.add(footprint);
*/ });
@GetMapping("category") }
public Object category(@NotNull Integer id) { FutureTask<List> goodsAttributeListTask = new FutureTask<>(goodsAttributeListCallable);
LitemallCategory cur = categoryService.findById(id); FutureTask<Object> objectCallableTask = new FutureTask<>(objectCallable);
LitemallCategory parent = null; FutureTask<List> productListCallableTask = new FutureTask<>(productListCallable);
List<LitemallCategory> children = null; FutureTask<List> issueCallableTask = new FutureTask<>(issueCallable);
FutureTask<Map> commentsCallableTsk = new FutureTask<>(commentsCallable);
if (cur.getPid() == 0) { FutureTask<LitemallBrand> brandCallableTask = new FutureTask<>(brandCallable);
parent = cur; FutureTask<List> grouponRulesCallableTask = new FutureTask<>(grouponRulesCallable);
children = categoryService.queryByPid(cur.getId());
cur = children.size() > 0 ? children.get(0) : cur; executorService.submit(goodsAttributeListTask);
} else { executorService.submit(objectCallableTask);
parent = categoryService.findById(cur.getPid()); executorService.submit(productListCallableTask);
children = categoryService.queryByPid(cur.getPid()); executorService.submit(issueCallableTask);
} executorService.submit(commentsCallableTsk);
Map<String, Object> data = new HashMap<>(); executorService.submit(brandCallableTask);
data.put("currentCategory", cur); executorService.submit(grouponRulesCallableTask);
data.put("parentCategory", parent);
data.put("brotherCategory", children); Map<String, Object> data = new HashMap<>();
return ResponseUtil.ok(data);
} try {
data.put("info", info);
/** data.put("userHasCollect", userHasCollect);
* 根据条件搜素商品 data.put("issue", issueCallableTask.get());
* <p> data.put("comment", commentsCallableTsk.get());
* 1. 这里的前五个参数都是可选的,甚至都是空 data.put("specificationList", objectCallableTask.get());
* 2. 用户是可选登录,如果登录,则记录用户的搜索关键字 data.put("productList", productListCallableTask.get());
* data.put("attribute", goodsAttributeListTask.get());
* @param categoryId 分类类目ID,可选 data.put("brand", brandCallableTask.get());
* @param brandId 品牌商ID,可选 data.put("groupon", grouponRulesCallableTask.get());
* @param keyword 关键字,可选 }
* @param isNew 是否新品,可选 catch (Exception e) {
* @param isHot 是否热买,可选 e.printStackTrace();
* @param userId 用户ID }
* @param page 分页页数
* @param size 分页大小 //商品分享图片地址
* @param sort 排序方式,支持"add_time", "retail_price"或"name" data.put("shareImage", info.getShareUrl());
* @param order 排序类型,顺序或者降序 return ResponseUtil.ok(data);
* @return 根据条件搜素的商品详情 }
*/
@GetMapping("list") /**
public Object list(Integer categoryId, Integer brandId, String keyword, Boolean isNew, Boolean isHot, * 商品分类类目
@LoginUser Integer userId, *
@RequestParam(defaultValue = "1") Integer page, * @param id 分类类目ID
@RequestParam(defaultValue = "10") Integer size, * @return 商品分类类目
@Sort(accepts = {"add_time", "retail_price", "name"}) @RequestParam(defaultValue = "add_time") String sort, */
@Order @RequestParam(defaultValue = "desc") String order) { @GetMapping("category")
public Object category(@NotNull Integer id) {
//添加到搜索历史 LitemallCategory cur = categoryService.findById(id);
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) { LitemallCategory parent = null;
LitemallSearchHistory searchHistoryVo = new LitemallSearchHistory(); List<LitemallCategory> children = null;
searchHistoryVo.setKeyword(keyword);
searchHistoryVo.setUserId(userId); if (cur.getPid() == 0) {
searchHistoryVo.setFrom("wx"); parent = cur;
searchHistoryService.save(searchHistoryVo); children = categoryService.queryByPid(cur.getId());
} cur = children.size() > 0 ? children.get(0) : cur;
} else {
//查询列表数据 parent = categoryService.findById(cur.getPid());
List<LitemallGoods> goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order); children = categoryService.queryByPid(cur.getPid());
int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order); }
Map<String, Object> data = new HashMap<>();
// 查询商品所属类目列表。 data.put("currentCategory", cur);
List<Integer> goodsCatIds = goodsService.getCatIds(brandId, keyword, isHot, isNew); data.put("parentCategory", parent);
List<LitemallCategory> categoryList = null; data.put("brotherCategory", children);
if (goodsCatIds.size() != 0) { return ResponseUtil.ok(data);
categoryList = categoryService.queryL2ByIds(goodsCatIds); }
} else {
categoryList = new ArrayList<>(0); /**
} * 根据条件搜素商品
* <p>
Map<String, Object> data = new HashMap<>(); * 1. 这里的前五个参数都是可选的,甚至都是空
data.put("goodsList", goodsList); * 2. 用户是可选登录,如果登录,则记录用户的搜索关键字
data.put("filterCategoryList", categoryList); *
data.put("count", total); * @param categoryId 分类类目ID,可选
return ResponseUtil.ok(data); * @param brandId 品牌商ID,可选
} * @param keyword 关键字,可选
* @param isNew 是否新品,可选
/** * @param isHot 是否热买,可选
* 新品首发页面的横幅 * @param userId 用户ID
* * @param page 分页页数
* @return 新品首发页面的横幅 * @param size 分页大小
*/ * @param sort 排序方式,支持"add_time", "retail_price"或"name"
@GetMapping("new") * @param order 排序类型,顺序或者降序
public Object newGoods() { * @return 根据条件搜素的商品详情
Map<String, String> bannerInfo = new HashMap<>(); */
bannerInfo.put("url", ""); @GetMapping("list")
bannerInfo.put("name", SystemConfig.getNewBannerTitle()); public Object list(
bannerInfo.put("imgUrl", SystemConfig.getNewImageUrl()); Integer categoryId,
Integer brandId,
Map<String, Object> data = new HashMap<>(); String keyword,
data.put("bannerInfo", bannerInfo); Boolean isNew,
return ResponseUtil.ok(data); Boolean isHot,
} @LoginUser Integer userId,
@RequestParam(defaultValue = "1") Integer page,
/** @RequestParam(defaultValue = "10") Integer size,
* 人气推荐页面的横幅 @Sort(accepts = {"add_time", "retail_price", "name"}) @RequestParam(defaultValue = "add_time") String sort,
* @Order @RequestParam(defaultValue = "desc") String order) {
* @return 人气推荐页面的横幅
*/ //添加到搜索历史
@GetMapping("hot") if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
public Object hotGoods() { LitemallSearchHistory searchHistoryVo = new LitemallSearchHistory();
Map<String, String> bannerInfo = new HashMap<>(); searchHistoryVo.setKeyword(keyword);
bannerInfo.put("url", ""); searchHistoryVo.setUserId(userId);
bannerInfo.put("name", SystemConfig.getHotBannerTitle()); searchHistoryVo.setFrom("wx");
bannerInfo.put("imgUrl", SystemConfig.getHotImageUrl()); searchHistoryService.save(searchHistoryVo);
Map<String, Object> data = new HashMap<>(); }
data.put("bannerInfo", bannerInfo);
return ResponseUtil.ok(data); //查询列表数据
} List<LitemallGoods> goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order);
int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order);
/**
* 商品详情页面“大家都在看”推荐商品 // 查询商品所属类目列表。
* List<Integer> goodsCatIds = goodsService.getCatIds(brandId, keyword, isHot, isNew);
* @param id, 商品ID List<LitemallCategory> categoryList = null;
* @return 商品详情页面推荐商品 if (goodsCatIds.size() != 0) {
*/ categoryList = categoryService.queryL2ByIds(goodsCatIds);
@GetMapping("related") } else {
public Object related(@NotNull Integer id) { categoryList = new ArrayList<>(0);
LitemallGoods goods = goodsService.findById(id); }
if (goods == null) {
return ResponseUtil.badArgumentValue(); Map<String, Object> data = new HashMap<>();
} data.put("goodsList", goodsList);
data.put("filterCategoryList", categoryList);
// 目前的商品推荐算法仅仅是推荐同类目的其他商品 data.put("count", total);
int cid = goods.getCategoryId(); return ResponseUtil.ok(data);
}
// 查找六个相关商品
int related = 6; /**
List<LitemallGoods> goodsList = goodsService.queryByCategory(cid, 0, related); * 新品首发页面的横幅
Map<String, Object> data = new HashMap<>(); *
data.put("goodsList", goodsList); * @return 新品首发页面的横幅
return ResponseUtil.ok(data); */
} @GetMapping("new")
public Object newGoods() {
/** Map<String, String> bannerInfo = new HashMap<>();
* 在售的商品总数 bannerInfo.put("url", "");
* bannerInfo.put("name", SystemConfig.getNewBannerTitle());
* @return 在售的商品总数 bannerInfo.put("imgUrl", SystemConfig.getNewImageUrl());
*/
@GetMapping("count") Map<String, Object> data = new HashMap<>();
public Object count() { data.put("bannerInfo", bannerInfo);
Integer goodsCount = goodsService.queryOnSale(); return ResponseUtil.ok(data);
Map<String, Object> data = new HashMap<>(); }
data.put("goodsCount", goodsCount);
return ResponseUtil.ok(data); /**
} * 人气推荐页面的横幅
*
* @return 人气推荐页面的横幅
*/
@GetMapping("hot")
public Object hotGoods() {
Map<String, String> bannerInfo = new HashMap<>();
bannerInfo.put("url", "");
bannerInfo.put("name", SystemConfig.getHotBannerTitle());
bannerInfo.put("imgUrl", SystemConfig.getHotImageUrl());
Map<String, Object> data = new HashMap<>();
data.put("bannerInfo", bannerInfo);
return ResponseUtil.ok(data);
}
/**
* 商品详情页面“大家都在看”推荐商品
*
* @param id, 商品ID
* @return 商品详情页面推荐商品
*/
@GetMapping("related")
public Object related(@NotNull Integer id) {
LitemallGoods goods = goodsService.findById(id);
if (goods == null) {
return ResponseUtil.badArgumentValue();
}
// 目前的商品推荐算法仅仅是推荐同类目的其他商品
int cid = goods.getCategoryId();
// 查找六个相关商品
int related = 6;
List<LitemallGoods> goodsList = goodsService.queryByCategory(cid, 0, related);
Map<String, Object> data = new HashMap<>();
data.put("goodsList", goodsList);
return ResponseUtil.ok(data);
}
/**
* 在售的商品总数
*
* @return 在售的商品总数
*/
@GetMapping("count")
public Object count() {
Integer goodsCount = goodsService.queryOnSale();
Map<String, Object> data = new HashMap<>();
data.put("goodsCount", goodsCount);
return ResponseUtil.ok(data);
}
} }
\ No newline at end of file
...@@ -79,6 +79,7 @@ public class WxHomeController { ...@@ -79,6 +79,7 @@ public class WxHomeController {
if (HomeCacheManager.hasData(HomeCacheManager.INDEX)) { if (HomeCacheManager.hasData(HomeCacheManager.INDEX)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.INDEX)); return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.INDEX));
} }
ExecutorService executorService = Executors.newFixedThreadPool(10);
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
...@@ -137,6 +138,7 @@ public class WxHomeController { ...@@ -137,6 +138,7 @@ public class WxHomeController {
} }
//缓存数据 //缓存数据
HomeCacheManager.loadData(HomeCacheManager.INDEX, data); HomeCacheManager.loadData(HomeCacheManager.INDEX, data);
executorService.shutdown();
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment