luodangjia
2024-11-05 0c569ab4b38d972213eeaf7e8965f33f8ec650fd
ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java
@@ -7,9 +7,7 @@
import com.ruoyi.admin.netty.NettyChannelMap;
import com.ruoyi.admin.netty.NettyWebSocketController;
import com.ruoyi.admin.service.*;
import com.ruoyi.admin.utils.AddressDto;
import com.ruoyi.admin.utils.DescribeInstances;
import com.ruoyi.admin.utils.OcrBase;
import com.ruoyi.admin.vo.OrderByServeRecordVO;
import com.ruoyi.admin.vo.OrderDetailVO;
import com.ruoyi.admin.vo.OrderReasinDto;
@@ -17,38 +15,28 @@
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.utils.GaoDeMapUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SnowflakeIdWorker;
import com.ruoyi.common.core.vo.CityInfoVO;
import com.ruoyi.common.core.vo.PaperInVo;
import com.ruoyi.common.core.vo.PrintDto;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.entity.*;
import com.ruoyi.order.api.entity.ChangeDispatch;
import com.ruoyi.order.api.entity.Order;
import com.ruoyi.order.api.entity.OrderCountVO;
import com.ruoyi.order.api.entity.OrderPageCountVO;
import com.ruoyi.order.api.entity.OrderQueryRequest;
import com.ruoyi.order.api.entity.OrderRequest;
import com.ruoyi.order.api.feignClient.ExchangeDispatchClient;
import com.ruoyi.order.api.feignClient.OrderClient;
import com.ruoyi.order.api.request.OrderCountDataRequest;
import com.ruoyi.system.api.model.LoginUser;
import com.tencentcloudapi.ocr.v20181119.models.BusinessCardOCRResponse;
import com.tencentcloudapi.ocr.v20181119.models.ClassifyDetectOCRResponse;
import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Response;
import com.tencentcloudapi.ocr.v20181119.models.WaybillOCRResponse;
import io.netty.channel.ChannelHandlerContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.Get;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
@@ -57,7 +45,15 @@
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * <p>
@@ -133,7 +129,8 @@
    @Resource
    private RecoveryClassifyService recoveryClassifyService;
    @Resource
    private FranchiseeService franchiseeService;
    /**
     * 订单列表
     *
@@ -159,7 +156,21 @@
            List<Integer> classIds = recoveryClassifyService.lambdaQuery().eq(RecoveryClassify::getId, orderQueryRequest.getClassNameId()).list().stream().map(RecoveryClassify::getId).collect(Collectors.toList());
            servIds = recoveryServeService.lambdaQuery().eq(BaseEntity::getIsDelete,0).in(RecoveryServe::getClassifyId, classIds).list().stream().map(RecoveryServe::getId).collect(Collectors.toList());
        }
        if(orderQueryRequest.getServeId()!=null){
            servIds.add(orderQueryRequest.getServeId());
        }
        orderQueryRequest.setServIds(servIds);
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            String[] siteIds = byId.getSiteIds().split(",");
            orderQueryRequest.setSiteIds(siteIds);
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok(new Page<Order>());
            }
        }
        Page<Order> data = orderClient.queryPage(orderQueryRequest).getData();
        if (null != data) {
            for (Order record : data.getRecords()) {
@@ -179,7 +190,45 @@
        }
        return R.ok(data);
    }
    /**
     * 订单id列表
     *
     * @param orderQueryRequest 订单列表查询参数
     */
    @ApiOperation(value = "订单id列表-分页", tags = {"后台-订单管理"})
    @PostMapping(value = "/queryIdList")
    public R<List<String>> queryIdList(@RequestBody OrderQueryRequest orderQueryRequest) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        if (loginUser.getIsFranchisee()) {
            if (null == orderQueryRequest.getCityList() || orderQueryRequest.getCityList().isEmpty()) {
                orderQueryRequest.setCityList(loginUser.getCityList());
            } else {
                orderQueryRequest.getCityList().addAll(loginUser.getCityList());
            }
        }
        List<Integer> servIds = new ArrayList<>();
        if (orderQueryRequest.getClassNameId()!=null){
            List<Integer> classIds = recoveryClassifyService.lambdaQuery().eq(RecoveryClassify::getId, orderQueryRequest.getClassNameId()).list().stream().map(RecoveryClassify::getId).collect(Collectors.toList());
            servIds = recoveryServeService.lambdaQuery().eq(BaseEntity::getIsDelete,0).in(RecoveryServe::getClassifyId, classIds).list().stream().map(RecoveryServe::getId).collect(Collectors.toList());
        }
        if(orderQueryRequest.getServeId()!=null){
            servIds.add(orderQueryRequest.getServeId());
        }
        orderQueryRequest.setServIds(servIds);
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            String[] siteIds = byId.getSiteIds().split(",");
            orderQueryRequest.setSiteIds(siteIds);
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok();
            }
        }
        return R.ok(orderService.queryIdList(orderQueryRequest));
    }
    /**
     * 订单列表
     */
@@ -203,8 +252,19 @@
            List<Integer> classIds = recoveryClassifyService.lambdaQuery().eq(RecoveryClassify::getId, orderQueryRequest.getClassNameId()).list().stream().map(RecoveryClassify::getId).collect(Collectors.toList());
            servIds = recoveryServeService.lambdaQuery().eq(BaseEntity::getIsDelete,0).in(RecoveryServe::getClassifyId, classIds).list().stream().map(RecoveryServe::getId).collect(Collectors.toList());
        }
        if (orderQueryRequest.getServeId()!=null){
            servIds.add(orderQueryRequest.getServeId());
        }
        orderQueryRequest.setServIds(servIds);
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            String[] siteIds = byId.getSiteIds().split(",");
            orderQueryRequest.setSiteIds(siteIds);
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok();
            }
        }
        return R.ok(orderClient.orderPageCount(orderQueryRequest).getData());
    }
@@ -340,17 +400,11 @@
    /**
     * 订单派单/改派
     *
     * @param type 1:订单派单;2:订单改派
     */
    @RequiresPermissions("order_reassignment")
    @ApiOperation(value = "订单列表-订单派单/改派", tags = {"后台-订单管理"})
    @PostMapping(value = "/reassignment")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "操作类型(1:订单派单;2:订单改派)", name = "type", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "服务人员id", name = "workerId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "改派原因", name = "applyReason", dataType = "String")
    })
    @Transactional(rollbackFor = Exception.class)
    public R<String> reassignment(@RequestBody OrderReasinDto orderReasinDto) {
//        String[] split = orderIds.split(",");
@@ -367,11 +421,22 @@
        if (Constants.TWO.equals(orderId.getType())) {
            if (order.getState().equals(Constants.SIX) || order.getState().equals(Constants.THREE)) {
                orderClient.updateState(order.getId(), Constants.ONE);
                //如果是待改派,将上门时间设置为最新的,并且更新再投原因
                if (order.getState().equals(Constants.SIX)){
                    dispatchClient.changeReason(order.getId(), orderReasinDto.getReason());
                    orderClient.updateArrivalTime(order.getId(),orderReasinDto.getArriveTime());
                }
            }
            // 订单状态为 待完工时,需要更改状态 待上门且清空师傅到达预约点时间
            if (order.getState().equals(Constants.TWO)) {
                orderClient.updateStateAndArrivalTime(orderId.getOrderId(), Constants.ONE);
            }
            // 生成改派信息
//            ChangeDispatch changeDispatch = new ChangeDispatch();
//            changeDispatch.setWorkerId(item.getServerId());
@@ -496,8 +561,23 @@
        orderCountDataRequest.setCityList(cityList);
        orderCountDataRequest.setPageNum(pageNum);
        orderCountDataRequest.setPageSize(pageSize);
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String[] siteIds = new String[0];
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            siteIds  = byId.getSiteIds().split(",");
            orderCountDataRequest.setSiteIds(Arrays.asList(siteIds));
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok(new Page<>());
            }
        }
        // 远程调用
        Page<OrderCountVO> data = orderClient.orderCount(orderCountDataRequest).getData();
        List<Integer> idList = data.getRecords().stream().map(OrderCountVO::getWorkerId)
                .collect(Collectors.toList());
        List<MasterWorker> masterWorkerList;
@@ -579,52 +659,71 @@
    @ApiOperation(value = "获师傅", tags = {"后台-订单管理-地图统计"})
    @PostMapping(value = "/map/line")
    public R<List<OrderByServeRecordVO>> line(Integer id) {
        R<List<Order>> workday = orderClient.workday(id);
        System.out.println(workday.getData());
        List<OrderByServeRecordVO> list = new ArrayList<>();
        for (Order datum : workday.getData()) {
            OrderByServeRecordVO orderByServeRecord = new OrderByServeRecordVO();
        // 获取当天时间
        String today = DateUtils.dateTimeNow("yyyy-MM-dd");
        OrderByServeRecordVO orderByServeRecord = new OrderByServeRecordVO();
            String masterFolderPath = "/usr/local/coordinate/" + datum.getServerId();
            File masterFolder = new File(masterFolderPath);
        String masterFolderPath = "/usr/local/coordinate/" + id;
//        String masterFolderPath = "F:/DeskTop/coordinate/" + id;
        File masterFolder = new File(masterFolderPath);
//             检查师傅ID的文件夹是否存在,存在就读取轨迹数据
            System.out.println("文件是否存在:" + masterFolder.exists());
            if (masterFolder.exists()) {
        System.out.println("文件是否存在:" + masterFolder.exists());
        if (masterFolder.exists()) {
//                 检查订单ID的JSON文件是否存在,不存在则创建
                String jsonFilePath = masterFolderPath + "/" + datum.getId() + ".json";
            String jsonFilePath = masterFolderPath + "/" + today + ".json";
//                String jsonFilePath = "C:\\Users\\Admin\\Desktop\\1814257493315514369.json";
                File jsonFile = new File(jsonFilePath);
                System.out.println("订单Json文件是否存在:" + jsonFile.exists());
                if (jsonFile.exists()) {
                    try {
                        String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath)));
                        System.out.println("JSON 文件内容:" + jsonContent);
                        List<com.alibaba.fastjson2.JSONObject> coordinate = com.alibaba.fastjson2.JSONObject.parseObject(jsonContent, List.class);
                        List<String> coordinateList = new ArrayList<>();
                        if (null != coordinate) {
                            for (com.alibaba.fastjson2.JSONObject jsonObject : coordinate) {
                                Object s = jsonObject.get("coordinate");
                                coordinateList.add(String.valueOf(s));
                            }
                            orderByServeRecord.setCoordinate(coordinateList);
                        }
                    } catch (IOException e) {
                        System.out.println(e.getMessage());
                    }
                    list.add(orderByServeRecord);
                }
            File jsonFile = new File(jsonFilePath);
            System.out.println("订单Json文件是否存在:" + jsonFile.exists());
            List<String> coordinateList = getCoordinateList(jsonFile, jsonFilePath);
            orderByServeRecord.setCoordinate(coordinateList);
            //获取轨迹标点
            String baseMarkerPath = "/usr/local/marker/" + id;
//            String baseMarkerPath = "F:/DeskTop/marker/" + id;
            //标点根目录
            File markerMasterFolder = new File(baseMarkerPath);
            if (markerMasterFolder.exists()) {
                // 标点json文件路径
                String markerJsonFilePath = markerMasterFolder + "/" + today + ".json";
                File markerJsonFile = new File(markerJsonFilePath);
                List<String> markerCoordinateList = getCoordinateList(markerJsonFile,
                        markerJsonFilePath);
                orderByServeRecord.setMarker(markerCoordinateList);
            }
            list.add(orderByServeRecord);
        }
        return R.ok(list);
    }
    /**
     * 获取坐标集合
     * @param jsonFile json文件
     * @param jsonFilePath 文件路径
     * @return
     */
    private static List<String> getCoordinateList(File jsonFile, String jsonFilePath) {
        if (jsonFile.exists()) {
            try {
                String jsonContent = new String(Files.readAllBytes(Paths.get(jsonFilePath)));
                System.out.println("JSON 文件内容:" + jsonContent);
                List<com.alibaba.fastjson2.JSONObject> coordinate = com.alibaba.fastjson2.JSONObject.parseObject(jsonContent, List.class);
                List<String> coordinateList = new ArrayList<>();
                if (null != coordinate) {
                    for (com.alibaba.fastjson2.JSONObject jsonObject : coordinate) {
                        Object s = jsonObject.get("coordinate");
                        if (s != null) {
                            coordinateList.add(s.toString());
                        }
                    }
                }
                return coordinateList;
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }
        }
        return Collections.emptyList();
    }
    @Resource
    private RegionService regionService;