Skip to content

Commit

Permalink
⚡ 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHENFENG13 committed Jan 25, 2022
1 parent f567ac2 commit 7365a01
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ltd/newbee/mall/common/ServiceResultEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public enum ServiceResultEnum {

ORDER_NOT_EXIST_ERROR("订单不存在!"),

ORDER_ITEM_NOT_EXIST_ERROR("订单项不存在!"),

NULL_ADDRESS_ERROR("地址不能为空!"),

ORDER_PRICE_ERROR("订单价格异常!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package ltd.newbee.mall.controller.admin;

import ltd.newbee.mall.common.NewBeeMallCategoryLevelEnum;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.entity.GoodsCategory;
import ltd.newbee.mall.service.NewBeeMallCategoryService;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class NewBeeMallGoodsCategoryController {
@GetMapping("/categories")
public String categoriesPage(HttpServletRequest request, @RequestParam("categoryLevel") Byte categoryLevel, @RequestParam("parentId") Long parentId, @RequestParam("backParentId") Long backParentId) {
if (categoryLevel == null || categoryLevel < 1 || categoryLevel > 3) {
return "error/error_5xx";
NewBeeMallException.fail("参数异常");
}
request.setAttribute("path", "newbee_mall_category");
request.setAttribute("parentId", parentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import ltd.newbee.mall.common.Constants;
import ltd.newbee.mall.common.NewBeeMallCategoryLevelEnum;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.entity.GoodsCategory;
import ltd.newbee.mall.entity.NewBeeMallGoods;
Expand Down Expand Up @@ -69,16 +70,14 @@ public String edit(HttpServletRequest request) {
return "admin/newbee_mall_goods_edit";
}
}
return "error/error_5xx";
NewBeeMallException.fail("分类数据不完善");
return null;
}

@GetMapping("/goods/edit/{goodsId}")
public String edit(HttpServletRequest request, @PathVariable("goodsId") Long goodsId) {
request.setAttribute("path", "edit");
NewBeeMallGoods newBeeMallGoods = newBeeMallGoodsService.getNewBeeMallGoodsById(goodsId);
if (newBeeMallGoods == null) {
return "error/error_400";
}
if (newBeeMallGoods.getGoodsCategoryId() > 0) {
if (newBeeMallGoods.getGoodsCategoryId() != null || newBeeMallGoods.getGoodsCategoryId() > 0) {
//有分类字段则查询相关分类数据返回给前端以供分类的三级联动显示
Expand Down Expand Up @@ -203,9 +202,6 @@ public Result update(@RequestBody NewBeeMallGoods newBeeMallGoods) {
@ResponseBody
public Result info(@PathVariable("id") Long id) {
NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(id);
if (goods == null) {
return ResultGenerator.genFailResult(ServiceResultEnum.DATA_NOT_EXIST.getResult());
}
return ResultGenerator.genSuccessResult(goods);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
package ltd.newbee.mall.controller.admin;

import ltd.newbee.mall.common.IndexConfigTypeEnum;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.entity.GoodsCategory;
import ltd.newbee.mall.entity.IndexConfig;
import ltd.newbee.mall.service.NewBeeMallCategoryService;
import ltd.newbee.mall.service.NewBeeMallIndexConfigService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.Result;
Expand Down Expand Up @@ -43,7 +42,7 @@ public class NewBeeMallGoodsIndexConfigController {
public String indexConfigsPage(HttpServletRequest request, @RequestParam("configType") int configType) {
IndexConfigTypeEnum indexConfigTypeEnum = IndexConfigTypeEnum.getIndexConfigTypeEnumByType(configType);
if (indexConfigTypeEnum.equals(IndexConfigTypeEnum.DEFAULT)) {
return "error/error_5xx";
NewBeeMallException.fail("参数异常");
}

request.setAttribute("path", indexConfigTypeEnum.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ public String searchPage(@RequestParam Map<String, Object> params, HttpServletRe
@GetMapping("/goods/detail/{goodsId}")
public String detailPage(@PathVariable("goodsId") Long goodsId, HttpServletRequest request) {
if (goodsId < 1) {
return "error/error_5xx";
NewBeeMallException.fail("参数异常");
}
NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(goodsId);
if (goods == null) {
NewBeeMallException.fail(ServiceResultEnum.GOODS_NOT_EXIST.getResult());
}
if (Constants.SELL_STATUS_UP != goods.getGoodsSellStatus()) {
NewBeeMallException.fail(ServiceResultEnum.GOODS_PUT_DOWN.getResult());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import ltd.newbee.mall.common.Constants;
import ltd.newbee.mall.common.IndexConfigTypeEnum;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.controller.vo.NewBeeMallIndexCarouselVO;
import ltd.newbee.mall.controller.vo.NewBeeMallIndexCategoryVO;
import ltd.newbee.mall.controller.vo.NewBeeMallIndexConfigGoodsVO;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class IndexController {
public String indexPage(HttpServletRequest request) {
List<NewBeeMallIndexCategoryVO> categories = newBeeMallCategoryService.getCategoriesForIndex();
if (CollectionUtils.isEmpty(categories)) {
return "error/error_5xx";
NewBeeMallException.fail("分类数据不完善");
}
List<NewBeeMallIndexCarouselVO> carousels = newBeeMallCarouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
List<NewBeeMallIndexConfigGoodsVO> hotGoodses = newBeeMallIndexConfigService.getConfigGoodsesForIndex(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(), Constants.INDEX_GOODS_HOT_NUMBER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public class OrderController {
public String orderDetailPage(HttpServletRequest request, @PathVariable("orderNo") String orderNo, HttpSession httpSession) {
NewBeeMallUserVO user = (NewBeeMallUserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
NewBeeMallOrderDetailVO orderDetailVO = newBeeMallOrderService.getOrderDetailByOrderNo(orderNo, user.getUserId());
if (orderDetailVO == null) {
return "error/error_5xx";
}
request.setAttribute("orderDetailVO", orderDetailVO);
return "mall/order-detail";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package ltd.newbee.mall.controller.mall;

import ltd.newbee.mall.common.Constants;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.controller.vo.NewBeeMallShoppingCartItemVO;
import ltd.newbee.mall.controller.vo.NewBeeMallUserVO;
Expand Down Expand Up @@ -43,14 +44,14 @@ public String cartListPage(HttpServletRequest request,
//购物项总数
itemsTotal = myShoppingCartItems.stream().mapToInt(NewBeeMallShoppingCartItemVO::getGoodsCount).sum();
if (itemsTotal < 1) {
return "error/error_5xx";
NewBeeMallException.fail("购物项不能为空");
}
//总价
for (NewBeeMallShoppingCartItemVO newBeeMallShoppingCartItemVO : myShoppingCartItems) {
priceTotal += newBeeMallShoppingCartItemVO.getGoodsCount() * newBeeMallShoppingCartItemVO.getSellingPrice();
}
if (priceTotal < 1) {
return "error/error_5xx";
NewBeeMallException.fail("购物项价格异常");
}
}
request.setAttribute("itemsTotal", itemsTotal);
Expand Down Expand Up @@ -118,7 +119,7 @@ public String settlePage(HttpServletRequest request,
priceTotal += newBeeMallShoppingCartItemVO.getGoodsCount() * newBeeMallShoppingCartItemVO.getSellingPrice();
}
if (priceTotal < 1) {
return "error/error_5xx";
NewBeeMallException.fail("购物项价格异常");
}
}
request.setAttribute("priceTotal", priceTotal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package ltd.newbee.mall.service.impl;

import ltd.newbee.mall.common.NewBeeMallCategoryLevelEnum;
import ltd.newbee.mall.common.NewBeeMallException;
import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.controller.vo.NewBeeMallSearchGoodsVO;
import ltd.newbee.mall.dao.GoodsCategoryMapper;
Expand Down Expand Up @@ -91,9 +92,13 @@ public String updateNewBeeMallGoods(NewBeeMallGoods goods) {

@Override
public NewBeeMallGoods getNewBeeMallGoodsById(Long id) {
return goodsMapper.selectByPrimaryKey(id);
NewBeeMallGoods newBeeMallGoods = goodsMapper.selectByPrimaryKey(id);
if (newBeeMallGoods == null) {
NewBeeMallException.fail(ServiceResultEnum.GOODS_NOT_EXIST.getResult());
}
return newBeeMallGoods;
}

@Override
public Boolean batchUpdateSellStatus(Long[] ids, int sellStatus) {
return goodsMapper.batchUpdateSellStatus(ids, sellStatus) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,25 @@ public String saveOrder(NewBeeMallUserVO user, List<NewBeeMallShoppingCartItemVO
@Override
public NewBeeMallOrderDetailVO getOrderDetailByOrderNo(String orderNo, Long userId) {
NewBeeMallOrder newBeeMallOrder = newBeeMallOrderMapper.selectByOrderNo(orderNo);
if (newBeeMallOrder != null) {
//验证是否是当前userId下的订单,否则报错
if (!userId.equals(newBeeMallOrder.getUserId())) {
NewBeeMallException.fail(ServiceResultEnum.NO_PERMISSION_ERROR.getResult());
}
List<NewBeeMallOrderItem> orderItems = newBeeMallOrderItemMapper.selectByOrderId(newBeeMallOrder.getOrderId());
//获取订单项数据
if (!CollectionUtils.isEmpty(orderItems)) {
List<NewBeeMallOrderItemVO> newBeeMallOrderItemVOS = BeanUtil.copyList(orderItems, NewBeeMallOrderItemVO.class);
NewBeeMallOrderDetailVO newBeeMallOrderDetailVO = new NewBeeMallOrderDetailVO();
BeanUtil.copyProperties(newBeeMallOrder, newBeeMallOrderDetailVO);
newBeeMallOrderDetailVO.setOrderStatusString(NewBeeMallOrderStatusEnum.getNewBeeMallOrderStatusEnumByStatus(newBeeMallOrderDetailVO.getOrderStatus()).getName());
newBeeMallOrderDetailVO.setPayTypeString(PayTypeEnum.getPayTypeEnumByType(newBeeMallOrderDetailVO.getPayType()).getName());
newBeeMallOrderDetailVO.setNewBeeMallOrderItemVOS(newBeeMallOrderItemVOS);
return newBeeMallOrderDetailVO;
}
if (newBeeMallOrder == null) {
NewBeeMallException.fail(ServiceResultEnum.ORDER_NOT_EXIST_ERROR.getResult());
}
return null;
//验证是否是当前userId下的订单,否则报错
if (!userId.equals(newBeeMallOrder.getUserId())) {
NewBeeMallException.fail(ServiceResultEnum.NO_PERMISSION_ERROR.getResult());
}
List<NewBeeMallOrderItem> orderItems = newBeeMallOrderItemMapper.selectByOrderId(newBeeMallOrder.getOrderId());
//获取订单项数据
if (CollectionUtils.isEmpty(orderItems)) {
NewBeeMallException.fail(ServiceResultEnum.ORDER_ITEM_NOT_EXIST_ERROR.getResult());
}
List<NewBeeMallOrderItemVO> newBeeMallOrderItemVOS = BeanUtil.copyList(orderItems, NewBeeMallOrderItemVO.class);
NewBeeMallOrderDetailVO newBeeMallOrderDetailVO = new NewBeeMallOrderDetailVO();
BeanUtil.copyProperties(newBeeMallOrder, newBeeMallOrderDetailVO);
newBeeMallOrderDetailVO.setOrderStatusString(NewBeeMallOrderStatusEnum.getNewBeeMallOrderStatusEnumByStatus(newBeeMallOrderDetailVO.getOrderStatus()).getName());
newBeeMallOrderDetailVO.setPayTypeString(PayTypeEnum.getPayTypeEnumByType(newBeeMallOrderDetailVO.getPayType()).getName());
newBeeMallOrderDetailVO.setNewBeeMallOrderItemVOS(newBeeMallOrderItemVOS);
return newBeeMallOrderDetailVO;
}

@Override
Expand Down

0 comments on commit 7365a01

Please sign in to comment.