xuhy
2025-04-17 6e70ee2d0b73f70fe1140cc7d51c4e847d50aa51
ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java
@@ -1,6 +1,7 @@
package com.ruoyi.worker.controller;
import cn.afterturn.easypoi.cache.manager.IFileLoader;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.Constants;
@@ -41,8 +42,11 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.Synchronized;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -91,19 +95,21 @@
     *
     * @param state 订单状态(0:全部、1:待上门、2:已完结)
     */
    @ApiOperation(value = "订单列表", tags = {"师傅端-订单列表"})
    @ApiOperation(value = "订单列表", tags = {"师傅端-订单列表[2.0]"})
    @GetMapping(value = "/orderList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结)", name = "state", dataType = "Integer", required = true)
            @ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结、7:待预约)", name = "state", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "姓名,电话,地址搜索", name = "searchValues", dataType = "String", required = false),
    })
    public R<Page<Order>> orderList(@RequestParam Integer state,
                                    @RequestParam String searchValues,
                                    @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        Page<Order> dataList = orderClient.orderListWorker(loginWorker.getUserid(), state, pageNum, pageSize).getData();
        Page<Order> dataList = orderClient.orderListWorker(loginWorker.getUserid(), state,searchValues, pageNum, pageSize).getData();
        List<Order> orderList = dataList.getRecords();
        List<Integer> ids = orderList.stream().map(Order::getServeId).collect(Collectors.toList());
        if (!ids.isEmpty()) {
@@ -297,6 +303,7 @@
            @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true)
    })
    @Synchronized
    public R<Boolean> coordinate(@RequestParam Double longitude, @RequestParam Double latitude) {
        System.err.println("调用记录经纬度"+ LocalDateTime.now());
@@ -305,6 +312,13 @@
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        Object cacheObject2 = redisService.getCacheObject("LOCK" + loginWorker.getUserid());
        if (cacheObject2!=null){
            return R.ok();
        }else {
            redisService.setCacheObject("LOCK" + loginWorker.getUserid(),"1", 10L, TimeUnit.SECONDS);
        }
        // 获取当天时间
        String today = DateUtils.dateTimeNow("yyyy-MM-dd");
        Integer workerId = loginWorker.getUserid();
@@ -343,7 +357,6 @@
            // 读取订单ID的JSON文件内容
            try {
                String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath)));
                System.out.println("JSON 文件内容:" + jsonContent);
                List<ServeCoordinate> coordinate = JSONObject.parseObject(jsonContent, List.class);
                // 订单轨迹信息
                ServeCoordinate data = new ServeCoordinate();
@@ -368,7 +381,7 @@
        LocalDateTime now = LocalDateTime.now();
        // 减去三十分钟
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(10);
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(5);
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
@@ -378,7 +391,7 @@
        String nowStr = now.format(formatter);
        redisService.setCacheObject("MARK:"+workerId+":"+nowStr,longitude + "," + latitude);
        redisService.setCacheObject("MARK:"+workerId+":"+nowStr,longitude + "," + latitude, 10L, TimeUnit.MINUTES);
        String cacheObject = redisService.getCacheObject("MARK:" + workerId + ":" + formattedTime);
        if (cacheObject!=null){
@@ -418,14 +431,14 @@
            System.err.println("-----当前距离"+distance);
            //如果超出一定范围,存入Mark文件
            if (distance<50){
                redisService.setCacheObject("TIME:"+workerId,LocalDateTime.now());
                redisService.setCacheObject("TIME:"+workerId,LocalDateTime.now(), 10L, TimeUnit.MINUTES);
                marker(longitude,latitude);
            }
            }
        }
        redisService.deleteObject("LOCK" + loginWorker.getUserid());
        return R.ok();
    }
@@ -435,7 +448,7 @@
        // 检查差值是否小于等于2分钟
        long minutes = Math.abs(duration.toMinutes());
        return minutes >= 10;
        return minutes >= 5;
    }
    /**
     * 师傅端-定时调度记录师傅当天的轨迹标点
@@ -494,7 +507,6 @@
            // 读取订单ID的JSON文件内容
            try {
                String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath)));
                System.out.println("JSON 文件内容:" + jsonContent);
                List<ServeCoordinate> coordinate = JSONObject.parseObject(jsonContent, List.class);
                // 订单轨迹信息
                ServeCoordinate data = new ServeCoordinate();
@@ -525,7 +537,7 @@
//
//    }
    @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页"})
    @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页[2.0]"})
    @GetMapping(value = "/putLocation")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "workId", name = "workId", dataType = "int", required = true),
@@ -535,11 +547,20 @@
    public R<Object> orderNavigation(@RequestParam Integer workId, @RequestParam String longitude,
                                     @RequestParam String latitude) {
        Result<String> address = GaoDeMapUtil.getCityCode(longitude, latitude);
        System.err.println(address.getDatas());
        String cityCode = address.getDatas();
        System.err.println("城市code"+cityCode);
        String provinceCode = cityCode.substring(0, 2) + "0000";
        System.err.println("省份code"+provinceCode);
        Set<Integer> strings = new HashSet<>();
        strings.add(workId);
        redisService.setCacheSet("workerLocation:"+address.getDatas()+":", strings);
        redisService.setCacheSet("workerLocation:"+cityCode+":", strings);
        redisService.setCacheSet("workerLocation:"+provinceCode+":", strings);
        redisService.setCacheObject("work:"+workId+":", longitude+","+latitude);
        masterWorkerService.lambdaUpdate()
                .set(MasterWorker::getWorkerLon, longitude)
                .set(MasterWorker::getWorkerLat, latitude)
                .eq(MasterWorker::getId, workId)
                .eq(MasterWorker::getIsDelete, 0).update();
        return R.ok();
    }