xin
2025-07-16 0526acc407572d23b1030e0ffd842406ae0bc121
Merge remote-tracking branch 'origin/pxb' into xin
10 files modified
178 ■■■■ changed files
oying-system/src/main/java/com/oying/modules/rider/domain/RiderOrderRecord.java 3 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/domain/RiderSourceInfoHttp.java 3 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/mapper/RiderOrderRecordMapper.java 2 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/rest/WxRiderController.java 4 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/service/RiderOrderRecordService.java 16 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/service/impl/RiderInfoServiceImpl.java 18 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/service/impl/RiderOrderRecordServiceImpl.java 71 ●●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/utils/Constants.java 2 ●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/utils/RiderSourceHttpUtils.java 14 ●●●●● patch | view | raw | blame | history
oying-system/src/main/resources/mapper/rider/RiderOrderRecordMapper.xml 45 ●●●● patch | view | raw | blame | history
oying-system/src/main/java/com/oying/modules/rider/domain/RiderOrderRecord.java
@@ -96,6 +96,9 @@
    @ApiModelProperty(value = "配送费详情Id")
    private String deliveryFeeId;
    @ApiModelProperty(value = "预计送达时间")
    private String orderTime;
    public void copy(RiderOrderRecord source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
oying-system/src/main/java/com/oying/modules/rider/domain/RiderSourceInfoHttp.java
@@ -4,6 +4,7 @@
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
/**
* @description /
@@ -18,6 +19,6 @@
    private String message;
    private RiderSourceInfo data;
    private List<RiderSourceInfo> data;
}
oying-system/src/main/java/com/oying/modules/rider/mapper/RiderOrderRecordMapper.java
@@ -19,4 +19,6 @@
    IPage<RiderOrderRecord> findAll(@Param("criteria") RiderOrderRecordQueryCriteria criteria, Page<Object> page);
    List<RiderOrderRecord> findAll(@Param("criteria") RiderOrderRecordQueryCriteria criteria);
    RiderOrderRecord selectRiderInfo(@Param("orderNum") String orderNum);
}
oying-system/src/main/java/com/oying/modules/rider/rest/WxRiderController.java
@@ -127,10 +127,10 @@
        return ResponseEntity.ok(R.success(result));
    }
    @GetMapping("riderOperationOrder")
    @PostMapping("riderOperationOrder")
    @ApiOperation("骑手上报到店/取货配送")
    // @PreAuthorize("@el.check('riderOrderRecord:list')")
    public ResponseEntity<?> riderOperationOrder(OrderRiderOperationVo orderRiderOperation) {
    public ResponseEntity<?> riderOperationOrder(@RequestBody OrderRiderOperationVo orderRiderOperation) {
        // 订单号不能为空
        if (orderRiderOperation.getOrderNum() == null || orderRiderOperation.getOrderNum().equals("")) {
            return ResponseEntity.ok(R.fail(Constants.HTTP_CODE_FAIL, "订单号不能为空"));
oying-system/src/main/java/com/oying/modules/rider/service/RiderOrderRecordService.java
@@ -2,6 +2,8 @@
import com.oying.modules.rider.domain.RiderOrderRecord;
import com.oying.modules.rider.domain.dto.RiderOrderRecordQueryCriteria;
import java.text.ParseException;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
@@ -60,6 +62,7 @@
    */
    void download(List<RiderOrderRecord> all, HttpServletResponse response) throws IOException;
    /**
     * 骑手接单
     * @param orderNum
@@ -88,5 +91,18 @@
     */
    R riderOperationOrder(OrderRiderOperationVo orderRiderOperation);
    /**
     * 骑手完成订单状态
     * @param orderNum
     * @throws IOException /
     */
    R riderCompleteOrder(String orderNum);
    /**
     * 骑手完成订单修改接口
     * @param orderNum
     * @param
     * @throws IOException /
     */
    void updateRiderOrderInfo(String orderNum) ;
}
oying-system/src/main/java/com/oying/modules/rider/service/impl/RiderInfoServiceImpl.java
@@ -101,17 +101,21 @@
    @Transactional(rollbackFor = Exception.class)
    public void syncRiderSourceInfo(String sourcePlatform) {
        Long riderId = SecurityUtils.getCurrentUserId();
        // 添加请求参数
        List<String> phoneList = new ArrayList<>();
        phoneList.add(SecurityUtils.getCurrentUsername());
        // 查询其他平台的数据
        RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(SecurityUtils.getCurrentUsername(), sourcePlatform);
        RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(phoneList, sourcePlatform);
        // 请求成功
        if (riderSourceInfoHttp.getCode().equals(Constants.HTTP_CODE_SUCCESS)) {
            // 检查是否存在该平台的骑手信息
            QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>();
            riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId);
            RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper);
            // 获取骑手信息等于空
            if (null != riderSourceInfoHttp.getData()) {
                RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData();
                // 检查是否存在该平台的骑手信息
                QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>();
                riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId);
                RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper);
            if (!riderSourceInfoHttp.getData().isEmpty()) {
                // 单个骑手信息同步只取第一条数据
                RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData().get(0);
                // 如果存在该平台的骑手信息
                if (null == riderInfo) {
                    // 如果不存在,则创建新的骑手三方信息
oying-system/src/main/java/com/oying/modules/rider/service/impl/RiderOrderRecordServiceImpl.java
@@ -3,7 +3,6 @@
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oying.exception.BadRequestException;
import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.store.service.StoreService;
import com.oying.modules.rider.domain.RiderIncomeDetail;
import com.oying.modules.rider.domain.RiderInfo;
@@ -29,6 +28,8 @@
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.io.IOException;
@@ -126,6 +127,41 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRiderOrderInfo(String orderNum) {
        // 查询骑手订单信息
        RiderOrderRecord riderOrderRecord = riderOrderRecordMapper.selectRiderInfo(orderNum);
        // 当前为接单 设置为待取货状态 1-待取货 2-配送中 3-已完成 4-商家取消 5-骑手取消 6-客户取消 7-系统取消
        RiderOrderRecord riderOrderRecordUpdate = new RiderOrderRecord();
        riderOrderRecordUpdate.setRecordId(riderOrderRecord.getRecordId());
        riderOrderRecordUpdate.setOrderNum(orderNum);
        riderOrderRecordUpdate.setOrderStatus(Constants.ORDER_STATUS_FINISH);
        // 判断是否超时 当前时间和预计送达时间做比较// 获取当前时间
        Timestamp now = new Timestamp(System.currentTimeMillis());
        // 获取订单的预计送达时间(假设 orderResponse.getOrder().getOrderTime() 返回的是 Timestamp 类型)
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime orderLocalTime = LocalDateTime.parse(riderOrderRecord.getOrderTime(), formatter);
        Timestamp orderTime = Timestamp.valueOf(orderLocalTime);
        // 判断是否超时
        String isOvertime = Constants.IS_OVERTIME_YES;
        if (now.after(orderTime)) {
            isOvertime = Constants.IS_OVERTIME_YES;
        }
        // 设置到订单记录中
        riderOrderRecordUpdate.setIsOvertime(isOvertime);
        // 完成时间
        Timestamp finishTime = new Timestamp(System.currentTimeMillis());
        riderOrderRecordUpdate.setFinishTime(finishTime);
        // 接单时间-完成时间 计算出相隔秒数
        Timestamp acceptTime = riderOrderRecord.getAcceptTime();
        // 计算两个时间之间的秒数差
        long durationInSeconds = (finishTime.getTime() - acceptTime.getTime()) / 1000;
        riderOrderRecordUpdate.setDeliveryDuration(durationInSeconds);
        // 更新订单状态
        riderOrderRecordMapper.updateById(riderOrderRecordUpdate);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R riderGrabOrder(String orderNum) {
        Long riderId = SecurityUtils.getCurrentUserId();
        // 查询骑手信息
@@ -145,9 +181,17 @@
            }
            // 查询当前订单 检查订单是否已经被其他骑手抢到或取消 直接返回
            OrderResponse orderResponse = orderService.getByOrderNum(orderNum);
            if (orderResponse == null || orderResponse.getOrder() == null) {
                return R.fail(400, "订单信息不存在,请稍后重试");
            }
            int orderStatus = orderResponse.getOrder().getOrderStatus();
            // 2商家已接单 4商家已备货 这两个状态可以接单
            if (orderResponse == null || orderResponse.getOrder().getOrderStatus() != 2 || orderResponse.getOrder().getOrderStatus() != 4) {
                return R.fail(400, "订单已经被其他骑手接单或顾客取消,请稍后重试");
            if (orderStatus != 2 && orderStatus != 4) {
                return R.fail(400, "订单已经被其他骑手接单或取消,请稍后重试");
            }
            // 商家备货状态 查看是否存在骑手信息
            if (orderStatus == 4 && orderResponse.getOrder().getRiderId() != null) {
                return R.fail(400, "订单已经被其他骑手接单,请稍后重试");
            }
            // 订单没有被接单或取消的情况下,进行接单操作
            // 1.新增骑手接单记录
@@ -181,7 +225,13 @@
        riderOrderRecord.setMerchantId(orderResponse.getOrder().getStoreId());
        riderOrderRecord.setMerchantName(orderResponse.getOrder().getStoreName());
        riderOrderRecord.setMerchantAddress(orderResponse.getOrder().getStoreAddress());
        riderOrderRecord.setReceiverAddress(orderResponse.getAddress().getDetail());
        // 收货地址 拼接地址
        String receiverAddress = orderResponse.getAddress().getCity()
                + orderResponse.getAddress().getDistrict()
                + orderResponse.getAddress().getStreet()
                + orderResponse.getAddress().getShortAddress()
                + orderResponse.getAddress().getDetail();
        riderOrderRecord.setReceiverAddress(receiverAddress);
        // 当前为接单 设置为待取货状态 0-已接单 1-已到店 2-配送中 3-已完成 4-商家取消 5-骑手取消 6-客户取消 7-系统取消
        riderOrderRecord.setOrderStatus(Constants.ORDER_STATUS_OK);
        riderOrderRecord.setAcceptTime(new Timestamp(System.currentTimeMillis()));
@@ -202,6 +252,7 @@
        // 配送费详情Id
        // riderOrderRecord.setDeliveryFeeId(orderResponse.getOrder().getDeliveryFeeId());
        riderOrderRecord.setOrderIncome(orderResponse.getOrder().getSendPrice());
        riderOrderRecord.setOrderTime(orderResponse.getOrder().getOrderTime());
        create(riderOrderRecord);
    }
@@ -243,8 +294,8 @@
        Order order = orderResponse.getOrder();
        // 添加订单操作记录 订单完成
        orderService.operationLog(orderResponse, OrderStatusEnum.SEVEN, orderResponse.getOrder().getRiderName());
        // 修改骑手端的订单状态
        updateRiderOrderStatus(orderNum, Constants.ORDER_STATUS_FINISH);
        // 修改骑手端的订单状态 // 修改完成时间
        updateRiderOrderInfo(orderNum);
        // 返回参数
        orderResponse.getOrder().setOrderStatus(OrderStatusEnum.SEVEN.getKey());
        // 查询骑手钱包信息
@@ -272,7 +323,13 @@
        riderIncomeDetail.setDeliveryTime(new Timestamp(System.currentTimeMillis()));
        riderIncomeDetail.setOrderStatus(Constants.ORDER_STATUS_FINISH);
        riderIncomeDetail.setStartAddress(orderResponse.getOrder().getStoreAddress());
        riderIncomeDetail.setEndAddress(orderResponse.getAddress().getDetail());
        // 收货地址 拼接地址
        String receiverAddress = orderResponse.getAddress().getCity()
                + orderResponse.getAddress().getDistrict()
                + orderResponse.getAddress().getStreet()
                + orderResponse.getAddress().getShortAddress()
                + orderResponse.getAddress().getDetail();
        riderIncomeDetail.setEndAddress(receiverAddress);
        riderIncomeDetailService.save(riderIncomeDetail);
        return R.success(orderResponse);
    }
oying-system/src/main/java/com/oying/modules/rider/utils/Constants.java
@@ -42,7 +42,7 @@
     * 超时状态 1-是 0-否
     */
    String IS_OVERTIME_NO = "0";
    String IS_OVERTIME = "1";
    String IS_OVERTIME_YES = "1";
    /**
     * 订单来源: 1-平台派单 2-骑手抢单 3-商家直派 4-其他
oying-system/src/main/java/com/oying/modules/rider/utils/RiderSourceHttpUtils.java
@@ -12,6 +12,8 @@
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -66,15 +68,15 @@
     * @return: riderSourceInfoHttp
     * @author: pxb
     */
    public static RiderSourceInfoHttp getRiderSourceInfoHttp(String phone, String sourcePlatform) {
        HashMap<String, Object> paramMap = new HashMap<>(2);
        paramMap.put("phone", phone);
        paramMap.put("sourcePlatform", sourcePlatform);
    public static RiderSourceInfoHttp getRiderSourceInfoHttp(List<String> phones, String sourcePlatform) {
        HashMap<String, Object> param = new HashMap<>(2);
        param.put("phones", phones);
        param.put("sourcePlatform", sourcePlatform);
        // String url = "";
        // 转化成对象
        RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp();
        // try {
        //     String result = httpPostRequest(paramMap, url);
        //     String result = httpPostRequest(param, url);
        //     // 转换数据
        //     riderSourceInfoHttp = riderConvertUtils(result);
        // } catch (Exception e) {
@@ -91,7 +93,7 @@
        riderSourceInfo.setPhone("18706999997");
        riderSourceInfo.setCardName("张三");
        riderSourceInfo.setEnabled(Constants.SOURCE_ENABLED_ON);
        riderSourceInfoHttp.setData(riderSourceInfo);
        riderSourceInfoHttp.getData().add(riderSourceInfo);
        return riderSourceInfoHttp;
    }
oying-system/src/main/resources/mapper/rider/RiderOrderRecordMapper.xml
@@ -30,13 +30,39 @@
        <result column="merchant_latitude" property="merchantLatitude"/>
        <result column="user_id" property="userId"/>
        <result column="delivery_fee_id" property="deliveryFeeId"/>
        <result column="order_time" property="orderTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        record_id, order_id, order_num, merchant_id, merchant_name, merchant_address,
        receiver_address, order_status, accept_time, accept_num, finish_time, delivery_duration,
        is_overtime, order_source, order_income, create_by, create_time, update_by, update_time,
        rider_id, phone, rider_name, user_id, user_longitude, user_latitude, merchant_longitude, merchant_latitude,delivery_fee_id
        record_id,
        order_id,
        order_num,
        merchant_id,
        merchant_name,
        merchant_address,
        receiver_address,
        order_status,
        accept_time,
        accept_num,
        finish_time,
        delivery_duration,
        is_overtime,
        order_source,
        order_income,
        create_by,
        create_time,
        update_by,
        update_time,
        rider_id,
        phone,
        rider_name,
        user_id,
        user_longitude,
        user_latitude,
        merchant_longitude,
        merchant_latitude,
        delivery_fee_id,
        order_time
    </sql>
    <select id="findAll" resultMap="BaseResultMap">
        select
@@ -59,13 +85,13 @@
                and merchant_id = #{criteria.merchantId}
            </if>
            <if test="criteria.merchantName != null">
                and merchant_name like concat('%',#{criteria.merchantName},'%')
                and merchant_name like concat('%', #{criteria.merchantName}, '%')
            </if>
            <if test="criteria.merchantAddress != null">
                and merchant_address like concat('%',#{criteria.merchantAddress},'%')
                and merchant_address like concat('%', #{criteria.merchantAddress}, '%')
            </if>
            <if test="criteria.receiverAddress != null">
                and receiver_address like concat('%',#{criteria.receiverAddress},'%')
                and receiver_address like concat('%', #{criteria.receiverAddress}, '%')
            </if>
            <if test="criteria.orderStatus != null">
                and order_status = #{criteria.orderStatus}
@@ -85,4 +111,9 @@
        </where>
        order by create_time desc
    </select>
    <select id="selectRiderInfo" resultMap="BaseResultMap">
        select record_id recordId ,accept_time as acceptTime, order_time as orderTime
        from qs_rider_order_record where order_num = #{orderNum}
    </select>
</mapper>