You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

180 lines
5.7 KiB

package com.wyz.demo.service.impl;
import com.wyz.demo.dao.OrderRepository;
import com.wyz.demo.dao.UserRepository;
import com.wyz.demo.dto.OrderDTO;
import com.wyz.demo.po.OrderPO;
import com.wyz.demo.po.UserPO;
import com.wyz.demo.service.OrderService;
import com.wyz.demo.vo.CommonOrderVO;
import com.wyz.demo.vo.DetailOrderVO;
import com.wyz.demo.vo.SelfOrderVO;
import com.wyz.demo.vo.SelfPickedOrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private UserRepository userRepository;
@Autowired
private OrderRepository orderRepository;
/**
* 获取全部订单 - 根据用户名
* @Param username 用户名
*/
@Override
public List<SelfOrderVO> getOrdersByUsername(String username) {
int sender_id = userRepository.getIdByUsername(username);
List<OrderPO> orders = orderRepository.getOrdersBySenderId(sender_id);
List<SelfOrderVO> res = new ArrayList<>();
for (OrderPO orderPO : orders) {
SelfOrderVO orderVO = new SelfOrderVO();
orderVO.setId(orderPO.getId());
orderVO.setTimestamp(orderPO.getTimestamp());
orderVO.setDescription(orderPO.getDescription());
orderVO.setPrice(orderPO.getPrice());
String receiver = userRepository.getUsernameById(orderPO.getReceiverId());
orderVO.setReceiver(receiver);
orderVO.setStatus(orderPO.getStatus());
res.add(orderVO);
}
return res;
}
/**
* 获取某个用户全部接单
* @param username
* @return
*/
public List<SelfPickedOrderVO> getPickedOrdersByUsername(String username){
int receiver_id = userRepository.getIdByUsername(username);
List<OrderPO> orders = orderRepository.getOrdersByReceiverId(receiver_id);
List<SelfPickedOrderVO> res = new ArrayList<>();
for (OrderPO orderPO : orders) {
SelfPickedOrderVO orderVO = new SelfPickedOrderVO();
orderVO.setId(orderPO.getId());
orderVO.setTimestamp(orderPO.getTimestamp());
orderVO.setDescription(orderPO.getDescription());
orderVO.setPrice(orderPO.getPrice());
String sender = userRepository.getUsernameById(orderPO.getSenderId());
orderVO.setSender(sender);
orderVO.setStatus(orderPO.getStatus());
res.add(orderVO);
}
return res;
}
@Override
public void addOrder(OrderDTO orderDTO, HttpSession sess) {
OrderPO orderPO = new OrderPO();
orderPO.setDescription(orderDTO.getDescription());
orderPO.setWhen(orderDTO.getWhen());
orderPO.setLocation(orderDTO.getLocation());
orderPO.setSenderId(userRepository.getIdByUsername((String)sess.getAttribute("username")));
orderPO.setPrice(orderDTO.getPrice());
orderPO.setComment(orderDTO.getComment());
orderRepository.addOrder(orderPO);
}
@Override
public List<CommonOrderVO> getAllUnpickOrders() {
List<OrderPO> orderPOs = orderRepository.getAllUnpickOrders();
List<CommonOrderVO> commonOrderVOs = new ArrayList<>();
for (OrderPO orderPO : orderPOs) {
// log.info("获取全部订单:{}",orderPO);
CommonOrderVO commonOrderVO = new CommonOrderVO();
commonOrderVO.setId(orderPO.getId());
commonOrderVO.setDescription(orderPO.getDescription());
commonOrderVO.setWhen(orderPO.getWhen());
commonOrderVO.setLocation(orderPO.getLocation());
commonOrderVO.setSender(userRepository.getUsernameById(orderPO.getSenderId()));
commonOrderVO.setPrice(orderPO.getPrice());
commonOrderVOs.add(commonOrderVO);
}
return commonOrderVOs;
}
@Override
public DetailOrderVO getDetailOrder(int orderId) {
OrderPO orderPO = orderRepository.getOrderById(orderId);
UserPO userPO = userRepository.getUserById(orderPO.getSenderId());
DetailOrderVO detailOrderVO = new DetailOrderVO();
detailOrderVO.setDescription(orderPO.getDescription());
detailOrderVO.setWhen(orderPO.getWhen());
detailOrderVO.setLocation(orderPO.getLocation());
detailOrderVO.setSender(userPO.getUsername());
detailOrderVO.setPhone(userPO.getPhone());
detailOrderVO.setComment(orderPO.getComment());
detailOrderVO.setPrice(orderPO.getPrice());
return detailOrderVO;
}
@Override
public void pickOrder(int order_id, HttpSession sess) {
String receiver = (String)sess.getAttribute("username");
int receiver_id = userRepository.getIdByUsername(receiver);
orderRepository.pickOrder(order_id, receiver_id);
}
@Override
public void cancelPickedOrder(int order_id) {
orderRepository.cancelPickedOrder(order_id);
}
@Override
public void confirmPickedOrder(int order_id) {
orderRepository.confirmPickedOrder(order_id);
}
/**
* 下单者-取消订单
*/
public void cancelOrder(int order_id){
orderRepository.cancelOrder(order_id);
}
/**
* 下单者-确认完成
*/
public void confirmOrder(int order_id){
orderRepository.confirmOrder(order_id);
}
}