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-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java | 290 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 241 insertions(+), 49 deletions(-) diff --git a/ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java b/ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java index b4c8dd9..5752cdb 100644 --- a/ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java +++ b/ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java @@ -3,50 +3,74 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.ruoyi.admin.entity.*; +import com.ruoyi.admin.entity.MasterWorker; +import com.ruoyi.admin.entity.RecoveryClassify; +import com.ruoyi.admin.entity.RecoveryServe; +import com.ruoyi.admin.entity.RecoveryServePrice; +import com.ruoyi.admin.entity.Region; +import com.ruoyi.admin.entity.Site; 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.service.MasterWorkerService; +import com.ruoyi.admin.service.OrderService; +import com.ruoyi.admin.service.RecoveryClassifyService; +import com.ruoyi.admin.service.RecoveryServePriceService; +import com.ruoyi.admin.service.RecoveryServeService; +import com.ruoyi.admin.service.RegionService; +import com.ruoyi.admin.service.SiteService; 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; +import com.ruoyi.admin.vo.ReassinDto; 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 java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +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 javax.servlet.http.HttpServletResponse; -import java.math.BigDecimal; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; +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> @@ -111,7 +135,13 @@ }) public R<OrderDetailVO> orderDetail(@RequestParam String id) { // 独立orderService - return R.ok(orderService.orderListDetail(id)); + OrderDetailVO orderDetailVO = orderService.orderListDetail(id); + if (orderDetailVO.getServeRecordInfo().getPhoto()!=null&&!orderDetailVO.getServeRecordInfo().getPhoto().isEmpty()){ + if (orderDetailVO.getServeRecordInfo().getPhoto().get(0).equals("")){ + orderDetailVO.getServeRecordInfo().setPhoto(null); + } + } + return R.ok(orderDetailVO); } @Resource private RecoveryClassifyService recoveryClassifyService; @@ -162,7 +192,16 @@ } return R.ok(data); } - + /** + * 订单id列表 + * + * @param orderQueryRequest 订单列表查询参数 + */ + @ApiOperation(value = "订单id列表-分页", tags = {"后台-订单管理"}) + @PostMapping(value = "/queryIdList") + public R<List<String>> queryIdList(@RequestBody OrderQueryRequest orderQueryRequest) { + return R.ok(orderService.queryIdList(orderQueryRequest)); + } /** * 订单列表 */ @@ -231,6 +270,7 @@ .eq(MasterWorker::getIsDelete, 0).one(); order.setServerName(masterWorker.getRealName()); order.setServerPhone(masterWorker.getPhone()); + order.setAcceptTime(new Date()); // 待上门 order.setState(Constants.ONE); } else { @@ -322,11 +362,10 @@ /** * 订单派单/改派 * - * @param type 1:订单派单;2:订单改派 */ @RequiresPermissions("order_reassignment") @ApiOperation(value = "订单列表-订单派单/改派", tags = {"后台-订单管理"}) - @GetMapping(value = "/reassignment") + @PostMapping(value = "/reassignment") @ApiImplicitParams({ @ApiImplicitParam(value = "操作类型(1:订单派单;2:订单改派)", name = "type", dataType = "Integer", required = true), @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true), @@ -334,44 +373,43 @@ @ApiImplicitParam(value = "改派原因", name = "applyReason", dataType = "String") }) @Transactional(rollbackFor = Exception.class) - public R<String> reassignment(@RequestParam Integer type, @RequestParam String orderIds, - @RequestParam Integer workerId, String applyReason) { - String[] split = orderIds.split(","); - for (String orderId : split) { + public R<String> reassignment(@RequestBody OrderReasinDto orderReasinDto) { +// String[] split = orderIds.split(","); + for (ReassinDto orderId : orderReasinDto.getReassinDtos()) { MasterWorker masterWorker = masterWorkerService.lambdaQuery() - .eq(MasterWorker::getId, workerId) + .eq(MasterWorker::getId, orderReasinDto.getWorkerId()) .eq(MasterWorker::getIsDelete, 0).one(); - Order item = orderClient.detail(orderId).getData(); - Order order = orderClient.exchangeOrder(type, orderId, workerId, + Order item = orderClient.detail(orderId.getOrderId()).getData(); + Order order = orderClient.exchangeOrder(orderId.getType(), orderId.getOrderId(), orderReasinDto.getWorkerId(), masterWorker.getRealName(), masterWorker.getPhone()).getData(); // 订单派单 boolean result = true; - if (Constants.TWO.equals(type)) { + 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.TWO)) { - orderClient.updateStateAndArrivalTime(orderId, Constants.ONE); + orderClient.updateStateAndArrivalTime(orderId.getOrderId(), Constants.ONE); } // 生成改派信息 - ChangeDispatch changeDispatch = new ChangeDispatch(); - changeDispatch.setWorkerId(item.getServerId()); - changeDispatch.setWorkerName(item.getServerName()); - changeDispatch.setApplyReason(applyReason); - changeDispatch.setApplyTime(new Date()); - changeDispatch.setState(Constants.ONE); - changeDispatch.setOrderId(orderId); - changeDispatch.setOrderNumber(item.getOrderNumber()); - if (null != item.getUserId()) { - changeDispatch.setUserId(item.getUserId()); - } - changeDispatch.setUserName(item.getReservationName()); - changeDispatch.setIsDelete(Constants.ZERO); - result = dispatchClient.saveRecord(changeDispatch).getData(); +// ChangeDispatch changeDispatch = new ChangeDispatch(); +// changeDispatch.setWorkerId(item.getServerId()); +// changeDispatch.setWorkerName(item.getServerName()); +// changeDispatch.setApplyReason(orderReasinDto.getApplyReason()); +// changeDispatch.setApplyTime(new Date()); +// changeDispatch.setState(Constants.ONE); +// changeDispatch.setOrderId(orderId.getOrderId()); +// changeDispatch.setOrderNumber(item.getOrderNumber()); +// if (null != item.getUserId()) { +// changeDispatch.setUserId(item.getUserId()); +// } +// changeDispatch.setUserName(item.getReservationName()); +// changeDispatch.setIsDelete(Constants.ZERO); +// result = dispatchClient.saveRecord(changeDispatch).getData(); } - ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(workerId)); + ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(orderReasinDto.getWorkerId())); if (null != context) { NettyWebSocketController.sendMsgToClient(context, "您有一条新的订单,请注意查收!"); } @@ -411,6 +449,14 @@ @ApiOperation(value = "订单列表-excel导出", tags = {"后台-订单管理"}) @PostMapping(value = "/excelExport") public R<String> excelExport(@RequestBody OrderQueryRequest orderQueryRequest, HttpServletResponse response) { + 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()); + } + orderQueryRequest.setServIds(servIds); + + R<List<Order>> result = orderClient.excelExport(orderQueryRequest); // 独立orderService return orderService.excelExport(result.getData(), response); @@ -432,6 +478,10 @@ @PostMapping (value = "/ocr") public R<JSONObject> ocr(String ocrAddress) { return R.ok(DescribeInstances.ocr(ocrAddress)); + } + + public static void main(String[] args) { + System.out.println(LocalDateTime.now().plusMonths(1)); } /** @@ -494,4 +544,146 @@ return R.ok(data); } + @ApiOperation(value = "打印计数", tags = {"后台-订单管理"}) + @PostMapping(value = "/print") + public R print(@RequestParam Long id) { + + orderClient.count(String.valueOf(id)); + + return R.ok(); + } + + + + @ApiOperation(value = "打印入库单子", tags = {"后台-订单管理"}) + @PostMapping(value = "/paperCount") + public R paperCount(@RequestParam Integer id,@RequestParam String date) { + R<List<PaperInVo>> papercount = orderClient.papercount(String.valueOf(id),date); + for (PaperInVo datum : papercount.getData()) { + datum.setName(recoveryServeService.getById(datum.getServeId()).getServeName()); + } + PrintDto printDto =new PrintDto(); + printDto.setName(masterWorkerService.getById(id).getRealName()); + printDto.setPapers(papercount.getData()); + printDto.setDate(date); + return R.ok(printDto); + } + + @Resource + private RedisService redisService; + @ApiOperation(value = "地图统计", tags = {"后台-订单管理-地图统计"}) + @PostMapping(value = "/map/works") + public R<List<MasterWorker>> map(String cityCode,String name) { + + LoginUser loginUser = tokenService.getLoginUser(); + if (null == loginUser) { + return R.loginExpire("登录失效!"); + } + if (cityCode==null) { + if (loginUser.getIsFranchisee()) { + cityCode = loginUser.getCityList().get(0); + } else { + cityCode = "420100"; + } + } + Set<Integer> workIds = redisService.getCacheSet("workerLocation:" + cityCode+":"); + if (workIds==null||workIds.isEmpty()){ + return R.ok(new ArrayList<>()); + } + List<MasterWorker> list = masterWorkerService.lambdaQuery().in(MasterWorker::getId, workIds).eq(name!=null&&name!="",MasterWorker::getRealName,name).eq(cityCode!=null&&cityCode!="", MasterWorker::getCityCode,cityCode).list(); + for (MasterWorker masterWorker : list) { + masterWorker.setLacation(redisService.getCacheObject("work:"+masterWorker.getId()+":")); + } + return R.ok(list); + } + + @ApiOperation(value = "获师傅", tags = {"后台-订单管理-地图统计"}) + @PostMapping(value = "/map/line") + public R<List<OrderByServeRecordVO>> line(Integer id) { + List<OrderByServeRecordVO> list = new ArrayList<>(); + // 获取当天时间 + String today = DateUtils.dateTimeNow("yyyy-MM-dd"); + OrderByServeRecordVO orderByServeRecord = new OrderByServeRecordVO(); + + String masterFolderPath = "/usr/local/coordinate/" + id; + File masterFolder = new File(masterFolderPath); +// 检查师傅ID的文件夹是否存在,存在就读取轨迹数据 + System.out.println("文件是否存在:" + masterFolder.exists()); + if (masterFolder.exists()) { +// 检查订单ID的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()); + List<String> coordinateList = getCoordinateList(jsonFile, jsonFilePath); + orderByServeRecord.setCoordinate(coordinateList); + //获取轨迹标点 + String baseMarkerPath = "/usr/local/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; + + @ApiOperation(value = "获取城市名字", tags = {"后台-订单管理-地图统计"}) + @PostMapping(value = "/map/cityName") + public R line(String cityCode) { + Region one = regionService.lambdaQuery().eq(Region::getCode, cityCode).one(); + return R.ok(one.getName(),""); + } + + + + +// @ApiOperation(value = "获取司机的订单路线", tags = {"后台-订单管理-地图统计"}) +// @PostMapping(value = "/map/works/line") +// public R<List<MasterWorker>> map(@RequestParam Integer workId) { +// +// +// return R.ok(list); +// } + + + } -- Gitblit v1.7.1