| | |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.builder.ExcelWriterBuilder; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.admin.entity.*; |
| | | import com.ruoyi.admin.mapper.OrderMapper; |
| | | import com.ruoyi.admin.mapper.UserMapper; |
| | | import com.ruoyi.admin.request.OrderCountRequest; |
| | | import com.ruoyi.admin.request.OrderQueryRequest; |
| | | import com.ruoyi.admin.service.*; |
| | | import com.ruoyi.admin.service.MasterWorkerService; |
| | | import com.ruoyi.admin.service.OrderService; |
| | | import com.ruoyi.admin.service.RecoveryClassifyService; |
| | | import com.ruoyi.admin.service.RecoveryServeService; |
| | | import com.ruoyi.admin.vo.*; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.OrderConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.order.api.entity.ServeRecord; |
| | | import com.ruoyi.order.api.feignClient.EvaluateClient; |
| | | import com.ruoyi.order.api.feignClient.OrderClient; |
| | | import com.ruoyi.order.api.feignClient.ServeRecordClient; |
| | | import org.apache.commons.codec.CharEncoding; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | @Resource |
| | | private MasterWorkerService masterWorkerService; |
| | | @Resource |
| | | private ServeRecordService serveRecordService; |
| | | private OrderClient orderClient; |
| | | @Resource |
| | | private ServeCoordinateService serveCoordinateService; |
| | | private EvaluateClient evaluateClient; |
| | | @Resource |
| | | private EvaluateService evaluateService; |
| | | @Resource |
| | | private ChangeDispatchService changeDispatchService; |
| | | private ServeRecordClient serveRecordClient; |
| | | |
| | | /** |
| | | * linux服务器保存订单轨迹文件夹 |
| | | */ |
| | | private static final String BASE_PATH = "/usr/local/coordinate/"; |
| | | // private static final String BASE_PATH = "D:/Desktop/coordinate/"; |
| | | |
| | | @Override |
| | | public OrderResultVO orderCountHome(OrderCountRequest orderCount) { |
| | | List<String> cityList = orderCount.getCityList(); |
| | | Integer orderState = orderCount.getOrderState(); |
| | | String countType = orderCount.getCountType(); |
| | | String startTime = orderCount.getStartTime(); |
| | | String endTime = orderCount.getEndTime(); |
| | | List<OrderQueryVO> list; |
| | | // 根据查询类型查询订单信息 |
| | | if (OrderConstants.YEAR.equals(countType)) { |
| | | list = baseMapper.orderCountByYear(cityList, orderState, startTime, endTime); |
| | | } else if (OrderConstants.MONTH.equals(countType)) { |
| | | list = baseMapper.orderCountByMonth(cityList, orderState, startTime, endTime); |
| | | } else if (OrderConstants.WEEK.equals(countType)) { |
| | | list = baseMapper.orderCountByWeek(cityList, orderState, startTime, endTime); |
| | | } else if (OrderConstants.TODAY.equals(countType)) { |
| | | list = baseMapper.orderCountByToday(cityList, orderState, startTime, endTime); |
| | | } else { |
| | | list = new ArrayList<>(); |
| | | } |
| | | // 计算订单总额及总订单数量 |
| | | BigDecimal totalMoney; |
| | | int orderNumber; |
| | | if (list.isEmpty()) { |
| | | totalMoney = BigDecimal.ZERO; |
| | | orderNumber = 0; |
| | | } else { |
| | | totalMoney = list.stream().map(OrderQueryVO::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | orderNumber = list.stream().map(OrderQueryVO::getNumber).collect(Collectors.toList()).stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | return new OrderResultVO(totalMoney, orderNumber, list); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal totalMoneyByQuarter(String startDateStr, String endDateStr, List<String> cityList) { |
| | | return baseMapper.totalMoneyByQuarter(startDateStr, endDateStr, cityList); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal totalMoneyByYear(List<String> cityList) { |
| | | return baseMapper.totalMoneyByYear(cityList); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal totalMoneyByMonth(List<String> cityList) { |
| | | return baseMapper.totalMoneyByMonth(cityList); |
| | | } |
| | | |
| | | @Override |
| | | public R<String> excelExport(OrderQueryRequest orderQueryRequest, HttpServletResponse response) { |
| | | public R<String> excelExport(List<com.ruoyi.order.api.entity.Order> list, HttpServletResponse response) { |
| | | try { |
| | | response.setCharacterEncoding(Constants.UTF8); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | |
| | | return R.fail("excel导出失败!"); |
| | | } |
| | | try { |
| | | List<String> ids = orderQueryRequest.getIds(); |
| | | List<Order> list; |
| | | if (null != ids && !ids.isEmpty()) { |
| | | list = baseMapper.exportByIdList(ids); |
| | | } else { |
| | | list = baseMapper.exportList(orderQueryRequest); |
| | | } |
| | | // excel模板封装 |
| | | ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream()); |
| | | InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" + Constants.EXCEL_ORDER_FILE_NAME + ".xlsx"); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<Order> queryPage(OrderQueryRequest orderQueryRequest) { |
| | | Page<Order> page = Page.of(orderQueryRequest.getPageNum(), orderQueryRequest.getPageSize()); |
| | | // 基础查询 |
| | | IPage<Order> pageList = baseMapper.queryPage(orderQueryRequest, page); |
| | | for (Order order : pageList.getRecords()) { |
| | | ChangeDispatch changeDispatch = changeDispatchService.lambdaQuery() |
| | | .eq(ChangeDispatch::getOrderId, order.getId()) |
| | | .eq(ChangeDispatch::getIsDelete, 0) |
| | | .orderByDesc(ChangeDispatch::getCreateTime) |
| | | .last("limit 1").one(); |
| | | if (null != changeDispatch) { |
| | | order.setApplyReason(changeDispatch.getApplyReason()); |
| | | } |
| | | } |
| | | return pageList; |
| | | } |
| | | |
| | | @Override |
| | | public OrderDetailVO orderListDetail(String id) { |
| | | OrderDetailVO result = new OrderDetailVO(); |
| | | Order order = this.getById(id); |
| | | com.ruoyi.order.api.entity.Order order = orderClient.detail(id).getData(); |
| | | orderInfo(result, order); |
| | | // 预约人信息 |
| | | userInfo(result, order); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private void evaluateInfo(OrderDetailVO result, Order order) { |
| | | Evaluate evaluate = evaluateService.lambdaQuery().eq(Evaluate::getOrderId, order.getId()) |
| | | .eq(Evaluate::getIsDelete, 0).one(); |
| | | private void evaluateInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | com.ruoyi.order.api.entity.Evaluate evaluate = evaluateClient.oneByOrderId(order.getId()).getData(); |
| | | OrderByEvaluateVO orderByEvaluate = new OrderByEvaluateVO(); |
| | | if (null != evaluate) { |
| | | orderByEvaluate.setStarRating(evaluate.getStarRating()); |
| | | orderByEvaluate.setStarRating(BigDecimal.valueOf(evaluate.getStarRating())); |
| | | orderByEvaluate.setEvaluateTime(evaluate.getCreateTime()); |
| | | orderByEvaluate.setEvaluateContent(evaluate.getContent()); |
| | | } |
| | | result.setEvaluateInfo(orderByEvaluate); |
| | | } |
| | | |
| | | private void serveRecordInfo(OrderDetailVO result, Order order) { |
| | | ServeRecord serveRecord = serveRecordService.lambdaQuery().eq(ServeRecord::getOrderId, order.getId()) |
| | | .eq(ServeRecord::getIsDelete, 0).one(); |
| | | // 师傅路线轨迹 |
| | | List<ServeCoordinate> serveCoordinateList = serveCoordinateService.lambdaQuery() |
| | | .eq(ServeCoordinate::getWorkerId, order.getServerId()) |
| | | .eq(ServeCoordinate::getIsDelete, 0) |
| | | .eq(ServeCoordinate::getOrderId, order.getId()) |
| | | .orderByDesc(ServeCoordinate::getCreateTime).list(); |
| | | private void serveRecordInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | OrderByServeRecordVO orderByServeRecord = new OrderByServeRecordVO(); |
| | | orderByServeRecord.setAcceptOrderTime(order.getAcceptTime()); |
| | | orderByServeRecord.setReachTime(order.getTime()); |
| | | orderByServeRecord.setCoordinate(serveCoordinateList.stream().map(ServeCoordinate::getCoordinate).collect(Collectors.toList())); |
| | | // 服务记录 包含现场照片 |
| | | ServeRecord serveRecord = serveRecordClient.serveRecordByOrderId(order.getId()).getData(); |
| | | // 师傅路线轨迹 |
| | | String masterFolderPath = BASE_PATH + order.getServerId(); |
| | | File masterFolder = new File(masterFolderPath); |
| | | // 检查师傅ID的文件夹是否存在,存在就读取轨迹数据 |
| | | System.out.println("文件是否存在:" + masterFolder.exists()); |
| | | if (masterFolder.exists()) { |
| | | // 检查订单ID的JSON文件是否存在,不存在则创建 |
| | | String jsonFilePath = masterFolderPath + "/" + order.getId() + ".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<JSONObject> coordinate = JSONObject.parseObject(jsonContent, List.class); |
| | | List<String> coordinateList = new ArrayList<>(); |
| | | if (null != coordinate) { |
| | | for (JSONObject jsonObject : coordinate) { |
| | | Object s = jsonObject.get("coordinate"); |
| | | coordinateList.add(String.valueOf(s)); |
| | | } |
| | | orderByServeRecord.setCoordinate(coordinateList); |
| | | } |
| | | } catch (IOException e) { |
| | | System.out.println(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | if (null != serveRecord) { |
| | | orderByServeRecord.setPhoto(Arrays.stream(serveRecord.getPhoto().split(",")).collect(Collectors.toList())); |
| | | } |
| | | result.setServeRecordInfo(orderByServeRecord); |
| | | } |
| | | |
| | | private void workerInfo(OrderDetailVO result, Order order) { |
| | | private void workerInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | MasterWorker worker = masterWorkerService.getById(order.getServerId()); |
| | | if (null == worker) { |
| | | throw new GlobalException("服务人员信息异常,请重试"); |
| | | } |
| | | if (null != worker) { |
| | | OrderByWorkerVO orderByWorker = new OrderByWorkerVO(); |
| | | orderByWorker.setProfilePicture(worker.getProfilePicture()); |
| | | orderByWorker.setName(worker.getRealName()); |
| | |
| | | orderByWorker.setSex(worker.getSex()); |
| | | result.setWorkerInfo(orderByWorker); |
| | | } |
| | | } |
| | | |
| | | private void serveInfo(OrderDetailVO result, Order order) { |
| | | private void serveInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | RecoveryServe recoveryServe = recoveryServeService.getById(order.getServeId()); |
| | | if (null == recoveryServe) { |
| | | throw new GlobalException("回收服务信息异常,请重试"); |
| | |
| | | result.setServeInfo(orderByServe); |
| | | } |
| | | |
| | | private void orderInfo(OrderDetailVO result, Order order) { |
| | | private void orderInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | if (null == order) { |
| | | throw new GlobalException("订单信息异常,请重试"); |
| | | } |
| | |
| | | result.setOrderInfo(orderInfo); |
| | | } |
| | | |
| | | private void userInfo(OrderDetailVO result, Order order) { |
| | | private void userInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | Integer userId = order.getUserId(); |
| | | User user = userMapper.selectById(userId); |
| | | OrderByUserInfoVO orderByUserInfo = new OrderByUserInfoVO(); |
| | |
| | | result.setUserInfo(orderByUserInfo); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<OrderCountVO> orderCount(String name, String phone, Page<OrderCountVO> page) { |
| | | return baseMapper.orderCount(name, phone, page); |
| | | } |
| | | |
| | | @Override |
| | | public OrderPageCountVO orderPageCount(OrderQueryRequest orderQueryRequest) { |
| | | List<Order> orderList = baseMapper.orderPageCount(orderQueryRequest); |
| | | int total = 0; |
| | | int toBeDispatched = 0; |
| | | int stayDoorstep = 0; |
| | | int toBeCompleted = 0; |
| | | int completed = 0; |
| | | int canceled = 0; |
| | | int reInvestment = 0; |
| | | for (Order order : orderList) { |
| | | total++; |
| | | Integer state = order.getState(); |
| | | if (Constants.ZERO.equals(state)) { |
| | | toBeDispatched++; |
| | | } else if (Constants.ONE.equals(state)) { |
| | | stayDoorstep++; |
| | | } else if (Constants.TWO.equals(state)) { |
| | | toBeCompleted++; |
| | | } else if (Constants.THREE.equals(state)) { |
| | | completed++; |
| | | } else if (Constants.FOUR.equals(state)) { |
| | | canceled++; |
| | | } else if (Constants.FIVE.equals(state)) { |
| | | reInvestment++; |
| | | } |
| | | } |
| | | return new OrderPageCountVO(total, toBeDispatched, stayDoorstep, |
| | | toBeCompleted, completed, canceled, reInvestment); |
| | | } |
| | | } |