From ecca9ab70a9a87bcb60977c92fbf81053b8fc1bb Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 04 九月 2024 09:17:55 +0800
Subject: [PATCH] 新增优化
---
ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java | 391 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 313 insertions(+), 78 deletions(-)
diff --git a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java
index 2ed177b..688ba80 100644
--- a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java
+++ b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OrderController.java
@@ -1,33 +1,52 @@
package com.ruoyi.worker.controller;
-import com.ruoyi.admin.api.entity.ChangeDispatch;
-import com.ruoyi.admin.api.feignClient.AdminClient;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.utils.DateUtils;
+import com.ruoyi.common.core.utils.GaoDeMapUtil;
+import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.order.api.entity.ChangeDispatch;
+import com.ruoyi.order.api.entity.Order;
+import com.ruoyi.order.api.entity.OrderDetailVO;
+import com.ruoyi.order.api.entity.OrderSubmitRequest;
+import com.ruoyi.order.api.feignClient.ExchangeDispatchClient;
+import com.ruoyi.order.api.feignClient.OrderClient;
import com.ruoyi.system.api.model.LoginUserInfo;
-import com.ruoyi.worker.entity.Evaluate;
import com.ruoyi.worker.entity.MasterWorker;
-import com.ruoyi.worker.entity.Order;
-import com.ruoyi.worker.entity.ServeRecord;
-import com.ruoyi.worker.request.OrderSubmitRequest;
-import com.ruoyi.worker.service.EvaluateService;
+import com.ruoyi.worker.entity.RecoveryServe;
import com.ruoyi.worker.service.MasterWorkerService;
-import com.ruoyi.worker.service.OrderService;
-import com.ruoyi.worker.service.ServeRecordService;
-import com.ruoyi.worker.vo.OrderDetailVO;
+import com.ruoyi.worker.service.RecoveryServeService;
+import com.ruoyi.worker.vo.ServeCoordinate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-import java.util.Date;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.Resource;
+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>
@@ -43,18 +62,27 @@
public class OrderController {
@Resource
- private OrderService orderService;
- @Resource
private TokenService tokenService;
- @Resource
- private AdminClient adminClient;
@Resource
private MasterWorkerService masterWorkerService;
@Resource
- private ServeRecordService serveRecordService;
+ private OrderClient orderClient;
@Resource
- private EvaluateService evaluateService;
+ private ExchangeDispatchClient dispatchClient;
+ @Resource
+ private RecoveryServeService recoveryServeService;
+ @Resource
+ private RedisService redisService;
+
+ /**
+ * linux服务器保存订单轨迹文件夹
+ */
+ // private static final String BASE_PATH = "/usr/local/coordinate/";
+ private static final String BASE_PATH = "F:/DeskTop/coordinate/";
+ // private static final String BASE_MARKER_PATH = "/usr/local/marker/";
+// private static final String BASE_PATH = "D:/Desktop/coordinate/";
+ private static final String BASE_MARKER_PATH = "F:/DeskTop/marker/";
/**
* 师傅端-获取订单列表
*
@@ -65,12 +93,29 @@
@ApiImplicitParams({
@ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结)", name = "state", dataType = "Integer", required = true)
})
- public R<List<Order>> orderList(@RequestParam Integer state) {
+ public R<Page<Order>> orderList(@RequestParam Integer state,
+ @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
if (null == loginWorker) {
return R.loginExpire("登录失效!");
}
- return R.ok(orderService.orderList(loginWorker.getUserid(), state));
+ Page<Order> dataList = orderClient.orderListWorker(loginWorker.getUserid(), state, pageNum, pageSize).getData();
+ List<Order> orderList = dataList.getRecords();
+ List<Integer> ids = orderList.stream().map(Order::getServeId).collect(Collectors.toList());
+ if (!ids.isEmpty()) {
+ List<RecoveryServe> serveList = recoveryServeService.lambdaQuery()
+ .in(RecoveryServe::getId, ids).list();
+ Map<Integer, String> map = serveList.stream().collect(Collectors.toMap(RecoveryServe::getId,
+ mw -> Optional.ofNullable(mw.getCover()).orElse("")));
+ for (Order order : orderList) {
+ order.setCover(map.get(order.getServeId()));
+ if (order.getAddress()!=null) {
+ order.setReservationAddress(order.getReservationAddress() + order.getAddress());
+ }
+ }
+ }
+ return R.ok(dataList);
}
/**
@@ -81,17 +126,22 @@
@ApiOperation(value = "申请订单改派", tags = {"师傅端-订单列表"})
@GetMapping(value = "/applyChange")
@ApiImplicitParams({
- @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true),
+ @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true),
@ApiImplicitParam(value = "改派原因", name = "reason", dataType = "String", required = true)
})
- public R<String> applyChange(@RequestParam Integer orderId, @RequestParam String reason) {
+ @Transactional(rollbackFor = Exception.class)
+ public R<String> applyChange(@RequestParam String orderId, @RequestParam String reason) {
LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
if (null == loginWorker) {
return R.loginExpire("登录失效!");
}
- ChangeDispatch data = adminClient.changeDispatchOne(orderId).getData();
+ ChangeDispatch data = dispatchClient.changeDispatchOne(orderId).getData();
if (null != data) {
- return R.fail("当前订单已提交改派申请!");
+ if (Constants.ZERO.equals(data.getState())) {
+ return R.fail("当前订单已提交改派申请,请等待改派!");
+ } else if (Constants.ONE.equals(data.getState())) {
+ return R.fail("当前等单已改派!");
+ }
}
MasterWorker masterWorker = masterWorkerService.getById(loginWorker.getUserid());
// 订单改派信息
@@ -100,8 +150,9 @@
changeDispatch.setWorkerName(masterWorker.getRealName());
changeDispatch.setApplyReason(reason);
changeDispatch.setApplyTime(DateUtils.getNowDate());
- changeDispatch.setState(0);
- Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
+ changeDispatch.setState(Constants.ZERO);
+ Boolean result = orderClient.changeOrderState(orderId, Constants.SIX).getData();
+ Order order = orderClient.detail(orderId).getData();
if (null == order) {
throw new GlobalException("订单信息异常!");
}
@@ -110,8 +161,42 @@
changeDispatch.setUserId(order.getUserId());
changeDispatch.setUserName(order.getReservationName());
// 添加改派信息
- Boolean save = adminClient.changeDispatchSave(changeDispatch).getData();
- return save ? R.ok() : R.fail();
+ Boolean save = dispatchClient.changeDispatchSave(changeDispatch).getData();
+ return result && save ? R.ok() : R.fail();
+ }
+
+ /**
+ * 师傅端-已到达预约地点
+ *
+ * @param orderId 订单id
+ */
+ @ApiOperation(value = "订单路线导航", tags = {"师傅端-首页"})
+ @GetMapping(value = "/checkDistance")
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true),
+ @ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true),
+ @ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true)
+ })
+ public R<Object> checkDistance(@RequestParam String orderId, @RequestParam String longitude,
+ @RequestParam String latitude) {
+ LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
+ if (null == loginWorker) {
+ return R.loginExpire("登录失效!");
+ }
+ // 校验经纬度
+ Order order = orderClient.detail(orderId).getData();
+ // 用户下单位置经纬度
+ String orderPosition = order.getLongitude() + "," + order.getLatitude();
+ // 师傅经纬度
+ String workerPosition = longitude + "," + latitude;
+ // 师傅当前位置离用户下单位置具体距离
+ Long distance = GaoDeMapUtil.getDistance(orderPosition, workerPosition).getDatas();
+ // 上传时判断是否在下单位置附件,距离大于某个值则 不允许上传
+ if (distance > Constants.THREE_THOUSAND) {
+// throw new GlobalException("您当前手机定位超出当前订单预约地址范围 3km,无法提供回收服务!");
+ return R.ok(Boolean.FALSE, "您当前手机定位超出当前订单预约地址范围 3km,无法提供回收服务!");
+ }
+ return R.ok(true);
}
/**
@@ -122,29 +207,17 @@
@ApiOperation(value = "订单路线导航", tags = {"师傅端-首页"})
@GetMapping(value = "/orderNavigation")
@ApiImplicitParams({
- @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true),
+ @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true),
@ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true),
@ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true)
})
- public R<Object> orderNavigation(@RequestParam Integer orderId, @RequestParam String longitude,
+ public R<Object> orderNavigation(@RequestParam String orderId, @RequestParam String longitude,
@RequestParam String latitude) {
LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
if (null == loginWorker) {
return R.loginExpire("登录失效!");
}
- Order order = orderService.lambdaQuery().eq(Order::getId, orderId)
- .eq(Order::getServerId, loginWorker.getUserid())
- .eq(Order::getIsDelete, 0).one();
- if (null == order) {
- throw new GlobalException("请确认当前订单所派单师傅是否是您!");
- }
- // 用户下单经纬度
- Double userLongitude = order.getLongitude();
- Double userLatitude = order.getLatitude();
- String userPosition = userLongitude + "," + userLatitude;
- // 师傅当前位置 经纬度
- String workerPosition = longitude + "," + latitude;
- return R.ok(orderService.orderNavigation(userPosition, workerPosition));
+ return R.ok(orderClient.orderNavigation(orderId, loginWorker.getUserid(), longitude, latitude).getData());
}
/**
@@ -157,18 +230,12 @@
@ApiImplicitParams({
@ApiImplicitParam(value = "orderId", name = "orderId", dataType = "Integer", required = true)
})
- public R<Boolean> reachPosition(@RequestParam Integer orderId) {
+ public R<Boolean> reachPosition(@RequestParam String orderId) {
LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
if (null == loginWorker) {
return R.loginExpire("登录失效!");
}
- Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getServerId, loginWorker.getUserid())
- .eq(Order::getIsDelete, 0).one();
- if (null == order) {
- throw new GlobalException("请确认当前订单所派单师傅是否是您!");
- }
- order.setState(Constants.THREE);
- return R.ok(orderService.updateById(order));
+ return orderClient.reachPosition(orderId, loginWorker.getUserid());
}
/**
@@ -179,17 +246,25 @@
@ApiOperation(value = "订单详情", tags = {"师傅端-订单列表"})
@GetMapping(value = "/orderDetail")
@ApiImplicitParams({
- @ApiImplicitParam(value = "orderId", name = "orderId", dataType = "Integer", required = true)
+ @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true)
})
- public R<OrderDetailVO> orderDetail(@RequestParam Integer orderId) {
- // 订单信息
- Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
- // 服务信息(服务备注、上门时间、完成时间、完成所拍现场照片)
- ServeRecord serveRecord = serveRecordService.lambdaQuery().eq(ServeRecord::getOrderId, orderId)
- .eq(ServeRecord::getIsDelete, 0).one();
- // 评价信息
- Evaluate evaluate = evaluateService.lambdaQuery().eq(Evaluate::getOrderId, orderId).eq(Evaluate::getIsDelete, 0).one();
- return R.ok(new OrderDetailVO(order, serveRecord, evaluate));
+ public R<OrderDetailVO> orderDetail(@RequestParam String orderId) {
+ LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
+ if (null == loginWorker) {
+ return R.loginExpire("登录失效!");
+ }
+ R<OrderDetailVO> orderDetail = orderClient.orderDetail(orderId);
+ if (null == orderDetail) {
+ return R.fail();
+ }
+ OrderDetailVO data = orderDetail.getData();
+ Integer serveId = data.getOrderInfo().getServeId();
+ RecoveryServe recoveryServe = recoveryServeService.lambdaQuery()
+ .eq(RecoveryServe::getId, serveId).one();
+ if (null != recoveryServe) {
+ data.getOrderInfo().setCover(recoveryServe.getCover());
+ }
+ return R.ok(data);
}
/**
@@ -200,22 +275,182 @@
@ApiOperation(value = "订单完工-提交订单", tags = {"师傅端-订单列表"})
@PostMapping(value = "/orderSubmit")
public R<Boolean> orderSubmit(@RequestBody OrderSubmitRequest orderSubmitRequest) {
- // 订单信息
- Order order = orderService.lambdaQuery().eq(Order::getId, orderSubmitRequest.getOrderId())
- .eq(Order::getIsDelete, 0).one();
- // 订单不存在,或订单状态异常(订单状态为2才可提交)
- if (null == order || !Constants.TWO.equals(order.getState())) {
- throw new GlobalException("订单不存在或订单状态异常!");
+ LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
+ if (null == loginWorker) {
+ return R.loginExpire("登录失效!");
}
- order.setCompleteTime(new Date());
- order.setState(Constants.THREE);
- boolean update = orderService.updateById(order);
- // 服务记录
- ServeRecord serveRecord = new ServeRecord();
- serveRecord.setOrderId(order.getId());
- serveRecord.setPhoto(String.join(",", orderSubmitRequest.getPhoto()));
- boolean save = serveRecordService.save(serveRecord);
- return R.ok(update && save);
+ return orderClient.orderSubmit(orderSubmitRequest);
+ }
+
+ /**
+ * 师傅端-定时调度记录师傅所走路线经纬度
+ *
+ * @param longitude 经度
+ * @param latitude 纬度
+ */
+ @ApiOperation(value = "订单进行-记录全天路线经纬度", tags = {"师傅端-订单列表"})
+ @GetMapping(value = "/coordinate")
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true),
+ @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true)
+ })
+ public R<Boolean> coordinate(@RequestParam Double longitude, @RequestParam Double latitude) {
+ LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
+ if (null == loginWorker) {
+ return R.loginExpire("登录失效!");
+ }
+ // 获取当天时间
+ String today = DateUtils.dateTimeNow("yyyy-MM-dd");
+ Integer workerId = loginWorker.getUserid();
+ ServeCoordinate serveCoordinate = new ServeCoordinate();
+ serveCoordinate.setWorkerId(workerId);
+ serveCoordinate.setDate(today);
+ serveCoordinate.setCoordinate(longitude + "," + latitude);
+ serveCoordinate.setLongitude(longitude);
+ serveCoordinate.setLatitude(latitude);
+ List<ServeCoordinate> list = new ArrayList<>();
+ list.add(serveCoordinate);
+ String jsonString = JSONObject.toJSONString(list);
+ // 检查师傅ID的文件夹是否存在,不存在则创建
+ String masterFolderPath = BASE_PATH + workerId;
+ File masterFolder = new File(masterFolderPath);
+ if (!masterFolder.exists()) {
+ // 创建师傅ID的文件夹
+ masterFolder.mkdirs();
+ }
+
+ // 检查订单ID的JSON文件是否存在,不存在则创建
+ String jsonFilePath = masterFolderPath + "/" + today + ".json";
+ File jsonFile = new File(jsonFilePath);
+ if (!jsonFile.exists()) {
+ try {
+ // 创建订单ID的JSON文件
+ jsonFile.createNewFile();
+ // 首次记录轨迹
+ FileWriter writer = new FileWriter(jsonFile);
+ writer.write(jsonString);
+ writer.close();
+ } catch (IOException e) {
+ return R.fail(e.getMessage());
+ }
+ } else {
+ // 读取订单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();
+ data.setWorkerId(workerId);
+ data.setDate(today);
+ data.setCoordinate(longitude + "," + latitude);
+ data.setLongitude(longitude);
+ data.setLatitude(latitude);
+ coordinate.add(data);
+ String itemStr = JSONObject.toJSONString(coordinate);
+ FileWriter writer = new FileWriter(jsonFile);
+ writer.write(itemStr);
+ writer.close();
+ } catch (IOException e) {
+ return R.fail(e.getMessage());
+ }
+ }
+ return R.ok();
+ }
+ /**
+ * 师傅端-定时调度记录师傅当天的轨迹标点
+ *
+ * @param longitude 经度
+ * @param latitude 纬度
+ */
+ @ApiOperation(value = "订单进行-记录当天的轨迹标点", tags = {"师傅端-订单列表"})
+ @GetMapping(value = "/marker")
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "经度", name = "longitude", dataType = "Integer", required = true),
+ @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "Integer", required = true)
+ })
+ public R<Boolean> marker(@RequestParam Double longitude, @RequestParam Double latitude) {
+ LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
+ if (null == loginWorker) {
+ return R.loginExpire("登录失效!");
+ }
+ // 获取当天时间
+ String today = DateUtils.dateTimeNow("yyyy-MM-dd");
+ Integer workerId = 1;
+ // Integer workerId = loginWorker.getUserid();
+ ServeCoordinate serveCoordinate = new ServeCoordinate();
+ serveCoordinate.setWorkerId(workerId);
+ serveCoordinate.setDate(today);
+ serveCoordinate.setCoordinate(longitude + "," + latitude);
+ serveCoordinate.setLongitude(longitude);
+ serveCoordinate.setLatitude(latitude);
+ List<ServeCoordinate> list = new ArrayList<>();
+ list.add(serveCoordinate);
+ String jsonString = JSONObject.toJSONString(list);
+ // 检查师傅ID的文件夹是否存在,不存在则创建
+ String masterFolderPath = BASE_MARKER_PATH + workerId;
+ File masterFolder = new File(masterFolderPath);
+ if (!masterFolder.exists()) {
+ // 创建师傅ID的文件夹
+ masterFolder.mkdirs();
+ }
+
+ // 检查今天的JSON文件是否存在,不存在则创建
+ String jsonFilePath = masterFolderPath + "/" + today + ".json";
+ File jsonFile = new File(jsonFilePath);
+ if (!jsonFile.exists()) {
+ try {
+ // 创建今天的JSON文件
+ jsonFile.createNewFile();
+ // 首次记录标点
+ FileWriter writer = new FileWriter(jsonFile);
+ writer.write(jsonString);
+ writer.close();
+ } catch (IOException e) {
+ return R.fail(e.getMessage());
+ }
+ } else {
+ // 读取订单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();
+ data.setWorkerId(workerId);
+ data.setDate(today);
+ data.setCoordinate(longitude + "," + latitude);
+ data.setLongitude(longitude);
+ data.setLatitude(latitude);
+ coordinate.add(data);
+ String itemStr = JSONObject.toJSONString(coordinate);
+ FileWriter writer = new FileWriter(jsonFile);
+ writer.write(itemStr);
+ writer.close();
+ } catch (IOException e) {
+ return R.fail(e.getMessage());
+ }
+ }
+ return R.ok();
+ }
+
+ @ApiOperation(value = "上传经纬度", tags = {"师傅端-首页"})
+ @GetMapping(value = "/putLocation")
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "workId", name = "workId", dataType = "int", required = true),
+ @ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true),
+ @ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true)
+ })
+ 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());
+ Set<Integer> strings = new HashSet<>();
+ strings.add(workId);
+ redisService.setCacheSet("workerLocation:"+address.getDatas()+":", strings);
+ redisService.setCacheObject("work:"+workId+":", longitude+","+latitude);
+ return R.ok();
+
}
}
--
Gitblit v1.7.1