hjl
2024-06-18 aaa3384609da2dfb7d6788a2a2b3d92a2bff0813
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.ruoyi.worker.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.utils.GaoDeMapUtil;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.worker.entity.MasterWorker;
import com.ruoyi.worker.entity.Order;
import com.ruoyi.worker.entity.RecoveryServe;
import com.ruoyi.worker.mapper.MasterWorkerMapper;
import com.ruoyi.worker.service.MasterWorkerService;
import com.ruoyi.worker.service.OrderService;
import com.ruoyi.worker.service.RecoveryServeService;
import com.ruoyi.worker.vo.OrderCountVO;
import com.ruoyi.worker.vo.OrderListVO;
import com.ruoyi.worker.vo.OrderNotHandleVO;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 师傅信息表 服务实现类
 * </p>
 *
 * @author hjl
 * @since 2024-06-03
 */
@Service
public class MasterWorkerServiceImpl extends ServiceImpl<MasterWorkerMapper, MasterWorker> implements MasterWorkerService {
 
    @Resource
    private OrderService orderService;
    @Resource
    private RecoveryServeService recoveryServeService;
 
    @Override
    public OrderCountVO orderCount(Integer id) {
        return baseMapper.orderCount(id);
    }
 
    @Override
    public List<OrderListVO> orderNotHandle(Integer userid, String longitude, String latitude) {
        List<Order> orderList = orderService.lambdaQuery().eq(Order::getServerId, userid).eq(Order::getState, Constants.TWO)
                .eq(Order::getIsDelete, 0).eq(Order::getType, Constants.ZERO).list();
        // 根据经纬度距离封装
        List<OrderNotHandleVO> list = new ArrayList<>();
        for (Order order : orderList) {
            // 用户下单经纬度
            Double orderLongitude = order.getLongitude();
            Double orderLatitude = order.getLatitude();
            String orderPosition = orderLongitude + "," + orderLatitude;
            // 根据经纬度计算与师傅的距离
            Result<Long> result = GaoDeMapUtil.getDistance(orderPosition, longitude + "," + latitude);
            Long distance = result.getDatas();
            // vo类信息封装
            OrderListVO orderListVO = new OrderListVO(order.getServeId());
            BeanUtils.copyProperties(orderListVO, orderListVO);
            OrderNotHandleVO vo = new OrderNotHandleVO(distance, orderListVO);
            list.add(vo);
        }
        // 根据距离排序
        list.sort(Comparator.comparing(OrderNotHandleVO::getDistance));
        List<OrderListVO> resultList = list.stream().map(OrderNotHandleVO::getOrderList).collect(Collectors.toList());
        for (OrderListVO orderListVO : resultList) {
            Integer serveId = orderListVO.getServeId();
            // 回收服务信息
            RecoveryServe recoveryServe = recoveryServeService.lambdaQuery().eq(RecoveryServe::getId, serveId)
                    .eq(RecoveryServe::getIsDelete, 0).one();
            if (null != recoveryServe) {
                orderListVO.setServePicture(recoveryServe.getCover());
            }
        }
        return resultList;
    }
 
}