最新公告
  • 新注册用户请前往个人中心绑定邮箱以便接收相关凭证邮件!!!点击前往个人中心
  • 从零到企业级SSM电商项目实战教程(四十二)前后台订单列表,订单详情,发货功能开发

    OrderController.java

    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse detail(HttpSession session, Long orderNo) {
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if (user == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
    
        return iOrderService.getOrderDetail(user.getId(), orderNo);
    }
    
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(HttpSession session, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if (user == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
    
        return iOrderService.getOrderList(user.getId(), pageNum, pageSize);
    }
    

    IOrderService.java

    ServerResponse getOrderDetail(Integer userId, Long orderNo);
    
    ServerResponse getOrderList(Integer userId, int pageNum, int pageSize);
    
    //backend
    ServerResponse manageList(int pageNum, int pageSize);
    
    ServerResponse manageDetail(Long orderNo);
    
    ServerResponse manageSearch(Long orderNo, int pageNum, int pageSize);
    
    ServerResponse manageSendGoods(Long orderNo);
    

    OrderServiceImpl.java

    public ServerResponse getOrderDetail(Integer userId, Long orderNo) {
        Order order = orderMapper.selectByUserIdAndOrderNo(userId, orderNo);
        if (order != null) {
            List orderItemList = orderItemMapper.getByOrderNoUserId(orderNo, userId);
            OrderVo orderVo = assembleOrderVo(order, orderItemList);
            return ServerResponse.createBySuccess(orderVo);
        }
        return ServerResponse.createByErrorMessage("没有找到该订单");
    
    }
    
    public ServerResponse getOrderList(Integer userId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List orderList = orderMapper.selectByUserId(userId);
    
        List orderVoList = assembleOrderVoList(orderList, userId);
        PageInfo pageResult = new PageInfo(orderList);
        pageResult.setList(orderVoList);
        return ServerResponse.createBySuccess(pageResult);
    }
    
    private List assembleOrderVoList(List orderList, Integer userId) {
        List orderVoList = Lists.newArrayList();
        for (Order order : orderList) {
            List orderItemList = Lists.newArrayList();
            if (userId == null) {
                //todo 管理员查询时不需要传参userId
                orderItemList = orderItemMapper.getByOrderNo(order.getOrderNo());
            } else {
                orderItemList = orderItemMapper.getByOrderNoUserId(order.getOrderNo(), userId);
            }
            OrderVo orderVo = assembleOrderVo(order, orderItemList);
            orderVoList.add(orderVo);
        }
        return orderVoList;
    }
    
    //backend
    public ServerResponse manageList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
    
        List orderList = orderMapper.selectAllOrder();
        List orderVoList = this.assembleOrderVoList(orderList, null);
        PageInfo pageResult = new PageInfo(orderList);
        pageResult.setList(orderVoList);
        return ServerResponse.createBySuccess(pageResult);
    }
    
    public ServerResponse manageDetail(Long orderNo) {
        Order order = orderMapper.selectByOrderNo(orderNo);
        if (order != null) {
            List orderItemList = orderItemMapper.getByOrderNo(orderNo);
            OrderVo orderVo = assembleOrderVo(order, orderItemList);
            return ServerResponse.createBySuccess(orderVo);
        }
        return ServerResponse.createByErrorMessage("订单不存在");
    
    }
    
    public ServerResponse manageSearch(Long orderNo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Order order = orderMapper.selectByOrderNo(orderNo);
        if (order != null) {
            List orderItemList = orderItemMapper.getByOrderNo(orderNo);
            OrderVo orderVo = assembleOrderVo(order, orderItemList);
    
            PageInfo pageResult = new PageInfo(Lists.newArrayList(order));
            pageResult.setList(Lists.newArrayList(orderVo));
            return ServerResponse.createBySuccess(pageResult);
        }
        return ServerResponse.createByErrorMessage("订单不存在!");
    }
    
    public ServerResponse manageSendGoods(Long orderNo) {
        Order order = orderMapper.selectByOrderNo(orderNo);
        if (order != null) {
            if (order.getStatus() == Const.OrderStatusEnum.PAID.getCode()) {
                order.setStatus(Const.OrderStatusEnum.SHIPPED.getCode());
                order.setSendTime(new Date());
                orderMapper.updateByPrimaryKeySelective(order);
                return ServerResponse.createBySuccess("发货成功");
            }
        }
        return ServerResponse.createByErrorMessage("订单不存在");
    }
    

    OrderMapper.java

    List selectByUserId(Integer userId);
    
    List selectAllOrder();
    

    OrderMapper.xml

    
    
    
    

    OrderItemMapper.java

    List getByOrderNo(@Param("orderNo")Long orderNo);
    

    OrderItemMapper.xml

    
    

    OrderManageController.java

    controller包下的backedn包下创建OrderManageController.java

    package com.mmall.controller.backend;
    
    import com.github.pagehelper.PageInfo;
    import com.mmall.common.Const;
    import com.mmall.common.ResponseCode;
    import com.mmall.common.ServerResponse;
    import com.mmall.pojo.User;
    import com.mmall.service.IOrderService;
    import com.mmall.service.IUserService;
    import com.mmall.vo.OrderVo;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.servlet.http.HttpSession;
    
    /**
     * @Author: Geekerstar(jikewenku.com)
     * @Date: 2018/6/25 13:08
     * @Description:
     */
    @RestController
    @RequestMapping("/manage/order")
    public class OrderManageController {
    
    
        @Autowired
        private IUserService iUserService;
        @Autowired
        private IOrderService iOrderService;
    
        @RequestMapping("list.do")
        @ResponseBody
        public ServerResponse orderList(HttpSession session, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                                  @RequestParam(value = "pageSize",defaultValue = "10")int pageSize){
    
            User user = (User)session.getAttribute(Const.CURRENT_USER);
            if(user == null){
                return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");
    
            }
            if(iUserService.checkAdminRole(user).isSuccess()){
                //填充我们增加产品的业务逻辑
                return iOrderService.manageList(pageNum,pageSize);
            }else{
                return ServerResponse.createByErrorMessage("无权限操作");
            }
        }
    
        @RequestMapping("detail.do")
        @ResponseBody
        public ServerResponse orderDetail(HttpSession session, Long orderNo){
    
            User user = (User)session.getAttribute(Const.CURRENT_USER);
            if(user == null){
                return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");
    
            }
            if(iUserService.checkAdminRole(user).isSuccess()){
                //填充我们增加产品的业务逻辑
    
                return iOrderService.manageDetail(orderNo);
            }else{
                return ServerResponse.createByErrorMessage("无权限操作");
            }
        }
    
    
    
        @RequestMapping("search.do")
        @ResponseBody
        public ServerResponse orderSearch(HttpSession session, Long orderNo,@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                                    @RequestParam(value = "pageSize",defaultValue = "10")int pageSize){
            User user = (User)session.getAttribute(Const.CURRENT_USER);
            if(user == null){
                return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");
    
            }
            if(iUserService.checkAdminRole(user).isSuccess()){
                //填充我们增加产品的业务逻辑
                return iOrderService.manageSearch(orderNo,pageNum,pageSize);
            }else{
                return ServerResponse.createByErrorMessage("无权限操作");
            }
        }
    
    
    
        @RequestMapping("send_goods.do")
        @ResponseBody
        public ServerResponse orderSendGoods(HttpSession session, Long orderNo){
    
            User user = (User)session.getAttribute(Const.CURRENT_USER);
            if(user == null){
                return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");
    
            }
            if(iUserService.checkAdminRole(user).isSuccess()){
                //填充我们增加产品的业务逻辑
                return iOrderService.manageSendGoods(orderNo);
            }else{
                return ServerResponse.createByErrorMessage("无权限操作");
            }
        }
    
    }
    
    本站所有文章均由网友分享,仅用于参考学习用,请勿直接转载,如有侵权,请联系网站客服删除相关文章。若由于商用引起版权纠纷,一切责任均由使用者承担
    极客文库 » 从零到企业级SSM电商项目实战教程(四十二)前后台订单列表,订单详情,发货功能开发

    常见问题FAQ

    如果资源链接失效了怎么办?
    本站用户分享的所有资源都有自动备份机制,如果资源链接失效,请联系本站客服QQ:2580505920更新资源地址。
    如果用户分享的资源与描述不符怎么办?
    可以联系客服QQ:2580505920,如果要求合理可以安排退款或者退赞助积分。
    如何分享个人资源获取赞助积分或其他奖励?
    本站用户可以分享自己的资源,但是必须保证资源没有侵权行为。点击个人中心,根据操作填写并上传即可。资源所获收益完全归属上传者,每周可申请提现一次。
    如果您发现了本资源有侵权行为怎么办?
    及时联系客服QQ:2580505920,核实予以删除。

    1 评论

    参与讨论

    • 169会员总数(位)
    • 3735资源总数(个)
    • 1本周发布(个)
    • 0 今日发布(个)
    • 443稳定运行(天)

    欢迎加入「极客文库」,成为原创作者从这里开始!

    立即加入 了解更多
    成为赞助用户享有更多特权立即升级