其他分享
首页 > 其他分享> > 客户信息管理的历史订单查看

客户信息管理的历史订单查看

作者:互联网

客户信息管理的历史订单查看

1、显示客户历史订单、及显示订单明细

OrderController

 @Controller
 @RequestMapping("order")
 public class OrderController {
     @Autowired
     private IOrderService orderService;
 ​
     @PostMapping("list")
     public void list(int cusid, HttpServletResponse response,int page,int rows) throws IOException {
         response.setContentType("text/html;charset=UTF-8");
         DatagridResult datagridResult = orderService.list(cusid,page,rows);
         response.getWriter().print(JSON.toJSONStringWithDateFormat(datagridResult, "yyyy-MM-dd HH:mm:ss"));
    }
     @PostMapping("findById")
     public void findById(int id,HttpServletResponse response) throws IOException {
         response.setContentType("text/html;charset=UTF-8");
         TCustomerOrder order = orderService.findById(id);
         response.getWriter().print(JSON.toJSONStringWithDateFormat(order, "yyyy-MM-dd HH:mm:ss"));
    }
 ​
 }
 ​

IOrderService

 public interface IOrderService {
     //客户历史订单查询分页
     DatagridResult list(int cusid, int page, int rows);
     //显示订单明细
     TCustomerOrder findById(int id);
 ​
 }

OrderServiceImpl(防止有事务加上注解Transactional)

 @Service
 @Transactional
 public class OrderServiceImpl implements IOrderService {
     @Autowired
     private TCustomerOrderMapper orderMapper;
 ​
     @Override
     public DatagridResult list(int cusid, int page, int rows) {
         PageHelper.startPage(page,rows);
 ​
         TCustomerOrderExample orderExample = new TCustomerOrderExample();
         orderExample.createCriteria().andCusidEqualTo(cusid);
         List<TCustomerOrder> list = orderMapper.selectByExample(orderExample);
         PageInfo<TCustomerOrder> pageInfo = new PageInfo<>(list);
 ​
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setTotal(pageInfo.getTotal());
         datagridResult.setRows(list);
         return datagridResult;
    }
 ​
     @Override
     public TCustomerOrder findById(int id) {
         //除了这个也可以按最简单的
 //       return orderMapper.selectByPrimaryKey(id);
         TCustomerOrderExample orderExample = new TCustomerOrderExample();
         orderExample.createCriteria().andIdEqualTo(id);
         List<TCustomerOrder> tCustomerOrders = orderMapper.selectByExample(orderExample);
         return tCustomerOrders.get(0);
    }
 ​
 }

2、显示总金额(自定义mapper)+订购详情

OrderDetailsController(没有日期直接RestController)

 @RestController
 @RequestMapping("orderDetails")
 public class OrderDetailsController {
     @Autowired
     private IOrderDetailsService orderDetailsService;
     @PostMapping("getTotalPrice")
     public Map getTotalPrice(int orderId){
         Map map = new HashMap();
         int totalMoney = orderDetailsService.getTotalPrice(orderId);
         map.put("totalMoney",totalMoney);
         return map;
    }
     @PostMapping("list")
     public DatagridResult list(int orderId, int page, int rows){
         return orderDetailsService.selectOrderDetilsList(orderId,page,rows);
    }
 }

IOrderDetailsService

 public interface IOrderDetailsService {
     //订单明细总金额
     int getTotalPrice(int orderId);
     //显示订购详情
     DatagridResult selectOrderDetilsList(int orderId, int page, int rows);
 }

OrderDetailsServiceImpl(自定义mapper需要在TOrderDetailsMapper中自定义方法,下方代码)

 @Service
 @Transactional
 public class OrderDetailsServiceImpl implements IOrderDetailsService {
     @Autowired
     private TOrderDetailsMapper orderDetailsMapper;
 ​
     @Override
     public int getTotalPrice(int orderId) {
         //select sum(sum) from t_order_details where orderId = ?
         //还是用的自定义mapper
         return orderDetailsMapper.getTotalPriceByOrderId(orderId);
    }
 ​
     @Override
     public DatagridResult selectOrderDetilsList(int orderId, int page, int rows) {
         PageHelper.startPage(page,rows);
         TOrderDetailsExample orderDetailsExample = new TOrderDetailsExample();
         orderDetailsExample.createCriteria().andOrderidEqualTo(orderId);
         List<TOrderDetails> list = orderDetailsMapper.selectByExample(orderDetailsExample);
         PageInfo<TOrderDetails> pageInfo = new PageInfo<>(list);
 ​
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setRows(list);
         datagridResult.setTotal(pageInfo.getTotal());
         return datagridResult;
    }
 }

TOrderDetailsMapper中新增

 public interface TOrderDetailsMapper {
     //查询订单总价
     int getTotalPriceByOrderId(int orderId);
 }

TOrderDetailsMapper.xml中写自定义SQL语句

最下方(#{orderId}里面的参数随便写不影响 )

 <select id="getTotalPriceByOrderId" parameterType="int" resultType="int">
      select sum(sum) from t_order_details where orderId = #{orderId}
 </select>

至此,历史订单查看完成

标签:orderId,查看,int,list,信息管理,page,订单,datagridResult,public
来源: https://www.cnblogs.com/wangshikang/p/16398994.html