Commit f6923f3f authored by Junling Bu's avatar Junling Bu
Browse files

refac[litemall-admin-api]: 对小商场后台服务的GET参数进行校验。

parent 1af95638
...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.db.service.LitemallRegionService; ...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.db.service.LitemallRegionService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -19,6 +21,7 @@ import java.util.Map; ...@@ -19,6 +21,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/address") @RequestMapping("/wx/address")
@Validated
public class WxAddressController { public class WxAddressController {
private final Log logger = LogFactory.getLog(WxAddressController.class); private final Log logger = LogFactory.getLog(WxAddressController.class);
...@@ -93,13 +96,10 @@ public class WxAddressController { ...@@ -93,13 +96,10 @@ public class WxAddressController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(@LoginUser Integer userId, Integer id) { public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
if(userId == null){ if(userId == null){
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if(id == null){
return ResponseUtil.badArgument();
}
LitemallAddress address = addressService.findById(id); LitemallAddress address = addressService.findById(id);
if(address == null){ if(address == null){
......
...@@ -20,6 +20,7 @@ import org.linlinjava.litemall.wx.service.CaptchaCodeManager; ...@@ -20,6 +20,7 @@ import org.linlinjava.litemall.wx.service.CaptchaCodeManager;
import org.linlinjava.litemall.wx.service.UserTokenManager; import org.linlinjava.litemall.wx.service.UserTokenManager;
import org.linlinjava.litemall.wx.util.IpUtil; import org.linlinjava.litemall.wx.util.IpUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -33,6 +34,7 @@ import java.util.Map; ...@@ -33,6 +34,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/auth") @RequestMapping("/wx/auth")
@Validated
public class WxAuthController { public class WxAuthController {
private final Log logger = LogFactory.getLog(WxAuthController.class); private final Log logger = LogFactory.getLog(WxAuthController.class);
......
...@@ -6,17 +6,20 @@ import org.linlinjava.litemall.db.domain.LitemallBrand; ...@@ -6,17 +6,20 @@ import org.linlinjava.litemall.db.domain.LitemallBrand;
import org.linlinjava.litemall.db.service.LitemallBrandService; import org.linlinjava.litemall.db.service.LitemallBrandService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/brand") @RequestMapping("/wx/brand")
@Validated
public class WxBrandController { public class WxBrandController {
private final Log logger = LogFactory.getLog(WxBrandController.class); private final Log logger = LogFactory.getLog(WxBrandController.class);
...@@ -42,14 +45,14 @@ public class WxBrandController { ...@@ -42,14 +45,14 @@ public class WxBrandController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(@RequestParam(value = "page", defaultValue = "1") Integer page, public Object list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "10") Integer size) {
List<LitemallBrand> brandList = brandService.query(page, size); List<LitemallBrand> brandList = brandService.query(page, size);
int total = brandService.queryTotalCount(); int total = brandService.queryTotalCount();
int totalPages = (int) Math.ceil((double) total / size); int totalPages = (int) Math.ceil((double) total / size);
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("brandList", brandList); data.put("brandList", brandList);
data.put("totalPages", totalPages); data.put("totalPages", totalPages);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
...@@ -72,17 +75,13 @@ public class WxBrandController { ...@@ -72,17 +75,13 @@ public class WxBrandController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(Integer id) { public Object detail(@NotNull Integer id) {
if(id == null){
return ResponseUtil.badArgument();
}
LitemallBrand entity = brandService.findById(id); LitemallBrand entity = brandService.findById(id);
if(entity == null){ if(entity == null){
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("brand",entity); data.put("brand",entity);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil; ...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -20,6 +21,7 @@ import java.util.Map; ...@@ -20,6 +21,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/cart") @RequestMapping("/wx/cart")
@Validated
public class WxCartController { public class WxCartController {
private final Log logger = LogFactory.getLog(WxCartController.class); private final Log logger = LogFactory.getLog(WxCartController.class);
...@@ -316,7 +318,7 @@ public class WxCartController { ...@@ -316,7 +318,7 @@ public class WxCartController {
if(checkValue == null){ if(checkValue == null){
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
Boolean isChecked = ((checkValue.intValue()) == 1); Boolean isChecked = (checkValue == 1);
cartService.updateCheck(userId, productIds, isChecked); cartService.updateCheck(userId, productIds, isChecked);
return index(userId); return index(userId);
...@@ -369,7 +371,7 @@ public class WxCartController { ...@@ -369,7 +371,7 @@ public class WxCartController {
* } * }
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@RequestMapping("goodscount") @GetMapping("goodscount")
public Object goodscount(@LoginUser Integer userId) { public Object goodscount(@LoginUser Integer userId) {
if(userId == null){ if(userId == null){
return ResponseUtil.ok(0); return ResponseUtil.ok(0);
......
...@@ -4,17 +4,20 @@ import org.linlinjava.litemall.core.util.ResponseUtil; ...@@ -4,17 +4,20 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallCategory; import org.linlinjava.litemall.db.domain.LitemallCategory;
import org.linlinjava.litemall.db.service.LitemallCategoryService; import org.linlinjava.litemall.db.service.LitemallCategoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/catalog") @RequestMapping("/wx/catalog")
@Validated
public class WxCatalogController { public class WxCatalogController {
@Autowired @Autowired
private LitemallCategoryService categoryService; private LitemallCategoryService categoryService;
...@@ -43,8 +46,8 @@ public class WxCatalogController { ...@@ -43,8 +46,8 @@ public class WxCatalogController {
*/ */
@GetMapping("index") @GetMapping("index")
public Object index(Integer id, public Object index(Integer id,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "10") Integer size) {
// 所有一级分类目录 // 所有一级分类目录
List<LitemallCategory> l1CatList = categoryService.queryL1(); List<LitemallCategory> l1CatList = categoryService.queryL1();
...@@ -63,7 +66,7 @@ public class WxCatalogController { ...@@ -63,7 +66,7 @@ public class WxCatalogController {
currentSubCategory = categoryService.queryByPid(currentCategory.getId()); currentSubCategory = categoryService.queryByPid(currentCategory.getId());
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("categoryList", l1CatList); data.put("categoryList", l1CatList);
data.put("currentCategory", currentCategory); data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory); data.put("currentSubCategory", currentSubCategory);
...@@ -97,7 +100,7 @@ public class WxCatalogController { ...@@ -97,7 +100,7 @@ public class WxCatalogController {
currentSubCategory = categoryService.queryByPid(currentCategory.getId()); currentSubCategory = categoryService.queryByPid(currentCategory.getId());
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("categoryList", l1CatList); data.put("categoryList", l1CatList);
data.put("allList", allList); data.put("allList", allList);
data.put("currentCategory", currentCategory); data.put("currentCategory", currentCategory);
...@@ -123,16 +126,12 @@ public class WxCatalogController { ...@@ -123,16 +126,12 @@ public class WxCatalogController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("current") @GetMapping("current")
public Object current(Integer id) { public Object current(@NotNull Integer id) {
if (id == null) {
return ResponseUtil.badArgument();
}
// 当前分类 // 当前分类
LitemallCategory currentCategory = categoryService.findById(id); LitemallCategory currentCategory = categoryService.findById(id);
List<LitemallCategory> currentSubCategory = categoryService.queryByPid(currentCategory.getId()); List<LitemallCategory> currentSubCategory = categoryService.queryByPid(currentCategory.getId());
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("currentCategory", currentCategory); data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory); data.put("currentSubCategory", currentSubCategory);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
......
...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.core.util.JacksonUtil; ...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -19,6 +21,7 @@ import java.util.Map; ...@@ -19,6 +21,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/collect") @RequestMapping("/wx/collect")
@Validated
public class WxCollectController { public class WxCollectController {
@Autowired @Autowired
private LitemallCollectService collectService; private LitemallCollectService collectService;
...@@ -47,15 +50,13 @@ public class WxCollectController { ...@@ -47,15 +50,13 @@ public class WxCollectController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(@LoginUser Integer userId, Byte type, public Object list(@LoginUser Integer userId,
@RequestParam(value = "page", defaultValue = "1") Integer page, @NotNull Byte type,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
if(userId == null){ if(userId == null){
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if(type == null){
return ResponseUtil.badArgument();
}
List<LitemallCollect> collectList = collectService.queryByType(userId, type, page, size); List<LitemallCollect> collectList = collectService.queryByType(userId, type, page, size);
int count = collectService.countByType(userId, type); int count = collectService.countByType(userId, type);
...@@ -63,7 +64,7 @@ public class WxCollectController { ...@@ -63,7 +64,7 @@ public class WxCollectController {
List<Object> collects = new ArrayList<>(collectList.size()); List<Object> collects = new ArrayList<>(collectList.size());
for(LitemallCollect collect : collectList){ for(LitemallCollect collect : collectList){
Map<String, Object> c = new HashMap(); Map<String, Object> c = new HashMap<String, Object>();
c.put("id", collect.getId()); c.put("id", collect.getId());
c.put("type", collect.getType()); c.put("type", collect.getType());
c.put("valueId", collect.getValueId()); c.put("valueId", collect.getValueId());
...@@ -77,7 +78,7 @@ public class WxCollectController { ...@@ -77,7 +78,7 @@ public class WxCollectController {
collects.add(c); collects.add(c);
} }
Map<String, Object> result = new HashMap(); Map<String, Object> result = new HashMap<String, Object>();
result.put("collectList", collects); result.put("collectList", collects);
result.put("totalPages", totalPages); result.put("totalPages", totalPages);
return ResponseUtil.ok(result); return ResponseUtil.ok(result);
...@@ -132,7 +133,7 @@ public class WxCollectController { ...@@ -132,7 +133,7 @@ public class WxCollectController {
collectService.add(collect); collectService.add(collect);
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("type", handleType); data.put("type", handleType);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.wx.annotation.LoginUser; ...@@ -9,8 +9,10 @@ import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.UserInfoService; import org.linlinjava.litemall.wx.service.UserInfoService;
import org.linlinjava.litemall.wx.dao.UserInfo; import org.linlinjava.litemall.wx.dao.UserInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -19,6 +21,7 @@ import java.util.Map; ...@@ -19,6 +21,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/comment") @RequestMapping("/wx/comment")
@Validated
public class WxCommentController { public class WxCommentController {
@Autowired @Autowired
private LitemallCommentService commentService; private LitemallCommentService commentService;
...@@ -79,10 +82,10 @@ public class WxCommentController { ...@@ -79,10 +82,10 @@ public class WxCommentController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("count") @GetMapping("count")
public Object count(Byte type, Integer valueId) { public Object count(@NotNull Byte type, @NotNull Integer valueId) {
int allCount = commentService.count(type, valueId, 0, 0, 0); int allCount = commentService.count(type, valueId, 0, 0, 0);
int hasPicCount = commentService.count(type, valueId, 1, 0, 0); int hasPicCount = commentService.count(type, valueId, 1, 0, 0);
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("allCount", allCount); data.put("allCount", allCount);
data.put("hasPicCount", hasPicCount); data.put("hasPicCount", hasPicCount);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
...@@ -111,13 +114,11 @@ public class WxCommentController { ...@@ -111,13 +114,11 @@ public class WxCommentController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(Byte type, Integer valueId, Integer showType, public Object list(@NotNull Byte type,
@RequestParam(value = "page", defaultValue = "1") Integer page, @NotNull Integer valueId,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @NotNull Integer showType,
if(!ObjectUtils.allNotNull(type, valueId, showType)){ @RequestParam(defaultValue = "1") Integer page,
return ResponseUtil.badArgument(); @RequestParam(defaultValue = "10") Integer size) {
}
List<LitemallComment> commentList = commentService.query(type, valueId, showType, page, size); List<LitemallComment> commentList = commentService.query(type, valueId, showType, page, size);
int count = commentService.count(type, valueId, showType, page, size); int count = commentService.count(type, valueId, showType, page, size);
...@@ -132,7 +133,7 @@ public class WxCommentController { ...@@ -132,7 +133,7 @@ public class WxCommentController {
commentVoList.add(commentVo); commentVoList.add(commentVo);
} }
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("data", commentVoList); data.put("data", commentVoList);
data.put("count", count); data.put("count", count);
data.put("currentPage", page); data.put("currentPage", page);
......
...@@ -8,6 +8,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil; ...@@ -8,6 +8,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -21,10 +22,11 @@ import java.util.Map; ...@@ -21,10 +22,11 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/wx/express") @RequestMapping("/wx/express")
@Validated
public class WxExpressController { public class WxExpressController {
@Autowired @Autowired
ExpressService expressService; private ExpressService expressService;
@PostMapping("query") @PostMapping("query")
public Object query(@LoginUser Integer userId, @RequestBody String body) { public Object query(@LoginUser Integer userId, @RequestBody String body) {
......
...@@ -8,6 +8,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil; ...@@ -8,6 +8,7 @@ import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -17,6 +18,7 @@ import java.util.Map; ...@@ -17,6 +18,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/footprint") @RequestMapping("/wx/footprint")
@Validated
public class WxFootprintController { public class WxFootprintController {
@Autowired @Autowired
private LitemallFootprintService footprintService; private LitemallFootprintService footprintService;
...@@ -78,8 +80,8 @@ public class WxFootprintController { ...@@ -78,8 +80,8 @@ public class WxFootprintController {
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(@LoginUser Integer userId, public Object list(@LoginUser Integer userId,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "10") Integer size) {
if(userId == null){ if(userId == null){
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
...@@ -90,7 +92,7 @@ public class WxFootprintController { ...@@ -90,7 +92,7 @@ public class WxFootprintController {
List<Object> footprintVoList = new ArrayList<>(footprintList.size()); List<Object> footprintVoList = new ArrayList<>(footprintList.size());
for(LitemallFootprint footprint : footprintList){ for(LitemallFootprint footprint : footprintList){
Map<String, Object> c = new HashMap(); Map<String, Object> c = new HashMap<String, Object>();
c.put("id", footprint.getId()); c.put("id", footprint.getId());
c.put("goodsId", footprint.getGoodsId()); c.put("goodsId", footprint.getGoodsId());
c.put("addTime", footprint.getAddTime()); c.put("addTime", footprint.getAddTime());
......
...@@ -5,15 +5,19 @@ import org.apache.commons.logging.Log; ...@@ -5,15 +5,19 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -22,6 +26,7 @@ import java.util.Map; ...@@ -22,6 +26,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/goods") @RequestMapping("/wx/goods")
@Validated
public class WxGoodsController { public class WxGoodsController {
private final Log logger = LogFactory.getLog(WxGoodsController.class); private final Log logger = LogFactory.getLog(WxGoodsController.class);
...@@ -79,11 +84,7 @@ public class WxGoodsController { ...@@ -79,11 +84,7 @@ public class WxGoodsController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(@LoginUser Integer userId, Integer id) { public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
if (id == null) {
return ResponseUtil.badArgument();
}
// 商品信息 // 商品信息
LitemallGoods info = goodsService.findById(id); LitemallGoods info = goodsService.findById(id);
...@@ -174,10 +175,7 @@ public class WxGoodsController { ...@@ -174,10 +175,7 @@ public class WxGoodsController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("category") @GetMapping("category")
public Object category(Integer id) { public Object category(@NotNull Integer id) {
if (id == null) {
return ResponseUtil.badArgument();
}
LitemallCategory cur = categoryService.findById(id); LitemallCategory cur = categoryService.findById(id);
LitemallCategory parent = null; LitemallCategory parent = null;
List<LitemallCategory> children = null; List<LitemallCategory> children = null;
...@@ -230,9 +228,9 @@ public class WxGoodsController { ...@@ -230,9 +228,9 @@ public class WxGoodsController {
@GetMapping("list") @GetMapping("list")
public Object list(Integer categoryId, Integer brandId, String keyword, Boolean isNew, Boolean isHot, public Object list(Integer categoryId, Integer brandId, String keyword, Boolean isNew, Boolean isHot,
@LoginUser Integer userId, @LoginUser Integer userId,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size, @RequestParam(defaultValue = "10") Integer size,
String sort, String order) { @Sort String sort, @Order String order) {
//添加到搜索历史 //添加到搜索历史
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) { if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
...@@ -335,11 +333,7 @@ public class WxGoodsController { ...@@ -335,11 +333,7 @@ public class WxGoodsController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("related") @GetMapping("related")
public Object related(Integer id) { public Object related(@NotNull Integer id) {
if (id == null) {
return ResponseUtil.badArgument();
}
LitemallGoods goods = goodsService.findById(id); LitemallGoods goods = goodsService.findById(id);
if (goods == null) { if (goods == null) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
......
...@@ -5,6 +5,7 @@ import org.linlinjava.litemall.db.domain.*; ...@@ -5,6 +5,7 @@ import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -16,6 +17,7 @@ import java.util.Map; ...@@ -16,6 +17,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/home") @RequestMapping("/wx/home")
@Validated
public class WxHomeController { public class WxHomeController {
@Autowired @Autowired
private LitemallAdService adService; private LitemallAdService adService;
...@@ -86,7 +88,7 @@ public class WxHomeController { ...@@ -86,7 +88,7 @@ public class WxHomeController {
categoryGoods = goodsService.queryByCategory(l2List, 0, SystemConfig.getCatlogMoreLimit()); categoryGoods = goodsService.queryByCategory(l2List, 0, SystemConfig.getCatlogMoreLimit());
} }
Map catGoods = new HashMap(); Map<String, Object> catGoods = new HashMap<String, Object>();
catGoods.put("id", catL1.getId()); catGoods.put("id", catL1.getId());
catGoods.put("name", catL1.getName()); catGoods.put("name", catL1.getName());
catGoods.put("goodsList", categoryGoods); catGoods.put("goodsList", categoryGoods);
......
...@@ -27,10 +27,12 @@ import org.springframework.transaction.TransactionDefinition; ...@@ -27,10 +27,12 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -59,6 +61,7 @@ import java.util.Map; ...@@ -59,6 +61,7 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/wx/order") @RequestMapping("/wx/order")
@Validated
public class WxOrderController { public class WxOrderController {
private final Log logger = LogFactory.getLog(WxOrderController.class); private final Log logger = LogFactory.getLog(WxOrderController.class);
...@@ -87,7 +90,7 @@ public class WxOrderController { ...@@ -87,7 +90,7 @@ public class WxOrderController {
private NotifyService notifyService; private NotifyService notifyService;
@Autowired @Autowired
LitemallUserFormIdService formIdService; private LitemallUserFormIdService formIdService;
public WxOrderController() { public WxOrderController() {
} }
...@@ -129,15 +132,13 @@ public class WxOrderController { ...@@ -129,15 +132,13 @@ public class WxOrderController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@RequestMapping("list") @RequestMapping("list")
public Object list(@LoginUser Integer userId, Integer showType, public Object list(@LoginUser Integer userId,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(defaultValue = "0") Integer showType,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
if (userId == null) { if (userId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if (showType == null) {
showType = 0;
}
List<Short> orderStatus = OrderUtil.orderStatus(showType); List<Short> orderStatus = OrderUtil.orderStatus(showType);
List<LitemallOrder> orderList = orderService.queryByOrderStatus(userId, orderStatus); List<LitemallOrder> orderList = orderService.queryByOrderStatus(userId, orderStatus);
...@@ -192,13 +193,10 @@ public class WxOrderController { ...@@ -192,13 +193,10 @@ public class WxOrderController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(@LoginUser Integer userId, Integer orderId) { public Object detail(@LoginUser Integer userId, @NotNull Integer orderId) {
if (userId == null) { if (userId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if (orderId == null) {
return ResponseUtil.badArgument();
}
// 订单信息 // 订单信息
LitemallOrder order = orderService.findById(orderId); LitemallOrder order = orderService.findById(orderId);
...@@ -737,13 +735,12 @@ public class WxOrderController { ...@@ -737,13 +735,12 @@ public class WxOrderController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("comment") @GetMapping("comment")
public Object comment(@LoginUser Integer userId, Integer orderId, Integer goodsId) { public Object comment(@LoginUser Integer userId,
@NotNull Integer orderId,
@NotNull Integer goodsId) {
if (userId == null) { if (userId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if (orderId == null) {
return ResponseUtil.badArgument();
}
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.findByOidAndGid(orderId, goodsId); List<LitemallOrderGoods> orderGoodsList = orderGoodsService.findByOidAndGid(orderId, goodsId);
int size = orderGoodsList.size(); int size = orderGoodsList.size();
......
...@@ -6,14 +6,17 @@ import org.linlinjava.litemall.db.domain.LitemallRegion; ...@@ -6,14 +6,17 @@ import org.linlinjava.litemall.db.domain.LitemallRegion;
import org.linlinjava.litemall.db.service.LitemallRegionService; import org.linlinjava.litemall.db.service.LitemallRegionService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/wx/region") @RequestMapping("/wx/region")
@Validated
public class WxRegionController { public class WxRegionController {
private final Log logger = LogFactory.getLog(WxRegionController.class); private final Log logger = LogFactory.getLog(WxRegionController.class);
...@@ -37,14 +40,8 @@ public class WxRegionController { ...@@ -37,14 +40,8 @@ public class WxRegionController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(Integer pid) { public Object list(@NotNull Integer pid) {
if(pid == null){
return ResponseUtil.badArgument();
}
List<LitemallRegion> regionList = regionService.queryByPid(pid); List<LitemallRegion> regionList = regionService.queryByPid(pid);
return ResponseUtil.ok(regionList); return ResponseUtil.ok(regionList);
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.wx.web; package org.linlinjava.litemall.wx.web;
import org.hibernate.validator.constraints.NotEmpty;
import org.linlinjava.litemall.db.domain.LitemallKeyword; import org.linlinjava.litemall.db.domain.LitemallKeyword;
import org.linlinjava.litemall.db.domain.LitemallSearchHistory; import org.linlinjava.litemall.db.domain.LitemallSearchHistory;
import org.linlinjava.litemall.db.service.LitemallKeywordService; import org.linlinjava.litemall.db.service.LitemallKeywordService;
...@@ -7,10 +8,8 @@ import org.linlinjava.litemall.db.service.LitemallSearchHistoryService; ...@@ -7,10 +8,8 @@ import org.linlinjava.litemall.db.service.LitemallSearchHistoryService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -18,6 +17,7 @@ import java.util.Map; ...@@ -18,6 +17,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/search") @RequestMapping("/wx/search")
@Validated
public class WxSearchController { public class WxSearchController {
@Autowired @Autowired
private LitemallKeywordService keywordsService; private LitemallKeywordService keywordsService;
...@@ -80,13 +80,9 @@ public class WxSearchController { ...@@ -80,13 +80,9 @@ public class WxSearchController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("helper") @GetMapping("helper")
public Object helper(String keyword) { public Object helper(@NotEmpty String keyword,
if(keyword == null){ @RequestParam(defaultValue = "1") Integer page,
return ResponseUtil.badArgument(); @RequestParam(defaultValue = "10") Integer size) {
}
Integer page = 1;
Integer size = 10;
List<LitemallKeyword> keywordsList = keywordsService.queryByKeyword(keyword, page, size); List<LitemallKeyword> keywordsList = keywordsService.queryByKeyword(keyword, page, size);
String[] keys = new String[keywordsList.size()]; String[] keys = new String[keywordsList.size()];
int index = 0; int index = 0;
......
...@@ -10,6 +10,7 @@ import org.springframework.core.io.Resource; ...@@ -10,6 +10,7 @@ import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -22,6 +23,7 @@ import java.util.Map; ...@@ -22,6 +23,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/storage") @RequestMapping("/wx/storage")
@Validated
public class WxStorageController { public class WxStorageController {
@Autowired @Autowired
......
...@@ -4,17 +4,20 @@ import org.linlinjava.litemall.db.domain.LitemallTopic; ...@@ -4,17 +4,20 @@ import org.linlinjava.litemall.db.domain.LitemallTopic;
import org.linlinjava.litemall.db.service.LitemallTopicService; import org.linlinjava.litemall.db.service.LitemallTopicService;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/wx/topic") @RequestMapping("/wx/topic")
@Validated
public class WxTopicController { public class WxTopicController {
@Autowired @Autowired
private LitemallTopicService topicService; private LitemallTopicService topicService;
...@@ -38,11 +41,11 @@ public class WxTopicController { ...@@ -38,11 +41,11 @@ public class WxTopicController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("list") @GetMapping("list")
public Object list(@RequestParam(value = "page", defaultValue = "1") Integer page, public Object list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "10") Integer size) { @RequestParam(defaultValue = "10") Integer size) {
List<LitemallTopic> topicList = topicService.queryList(page, size); List<LitemallTopic> topicList = topicService.queryList(page, size);
int total = topicService.queryTotal(); int total = topicService.queryTotal();
Map<String, Object> data = new HashMap(); Map<String, Object> data = new HashMap<String, Object>();
data.put("data", topicList); data.put("data", topicList);
data.put("count", total); data.put("count", total);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
...@@ -62,11 +65,7 @@ public class WxTopicController { ...@@ -62,11 +65,7 @@ public class WxTopicController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("detail") @GetMapping("detail")
public Object detail(Integer id) { public Object detail(@NotNull Integer id) {
if(id == null){
return ResponseUtil.badArgument();
}
LitemallTopic topic = topicService.findById(id); LitemallTopic topic = topicService.findById(id);
return ResponseUtil.ok(topic); return ResponseUtil.ok(topic);
} }
...@@ -85,11 +84,7 @@ public class WxTopicController { ...@@ -85,11 +84,7 @@ public class WxTopicController {
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("related") @GetMapping("related")
public Object related(Integer id) { public Object related(@NotNull Integer id) {
if(id == null){
return ResponseUtil.badArgument();
}
List<LitemallTopic> topicRelatedList = topicService.queryRelatedList(id, 0, 4); List<LitemallTopic> topicRelatedList = topicService.queryRelatedList(id, 0, 4);
return ResponseUtil.ok(topicRelatedList); return ResponseUtil.ok(topicRelatedList);
} }
......
...@@ -7,31 +7,30 @@ import org.linlinjava.litemall.db.service.LitemallUserFormIdService; ...@@ -7,31 +7,30 @@ import org.linlinjava.litemall.db.service.LitemallUserFormIdService;
import org.linlinjava.litemall.db.service.LitemallUserService; import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@RestController @RestController
@RequestMapping("/wx/formid") @RequestMapping("/wx/formid")
@Validated
public class WxUserFormId { public class WxUserFormId {
@Autowired @Autowired
LitemallUserService userService; private LitemallUserService userService;
@Autowired @Autowired
LitemallUserFormIdService formIdService; private LitemallUserFormIdService formIdService;
@GetMapping("create") @GetMapping("create")
public Object create(@LoginUser Integer userId, String formId) { public Object create(@LoginUser Integer userId, @NotNull String formId) {
if (userId == null) { if (userId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if (formId == null) {
return ResponseUtil.badArgument();
}
LitemallUser user = userService.findById(userId); LitemallUser user = userService.findById(userId);
LitemallUserFormid userFormid = new LitemallUserFormid(); LitemallUserFormid userFormid = new LitemallUserFormid();
userFormid.setOpenid(user.getWeixinOpenid()); userFormid.setOpenid(user.getWeixinOpenid());
......
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