| | |
| | | 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.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.OrderQueryRequest; |
| | | 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.text.SimpleDateFormat; |
| | | 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; |
| | | 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(List<String> idList, 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.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-disposition"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(Constants.EXCEL_ORDER_FILE_NAME, CharEncoding.UTF_8) + ".xlsx"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + |
| | | URLEncoder.encode(Constants.EXCEL_ORDER_FILE_NAME, CharEncoding.UTF_8) + ".xlsx"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | return R.fail("excel导出失败!"); |
| | | } |
| | | try { |
| | | List<Order> list = lambdaQuery().in(Order::getId, idList).eq(Order::getIsDelete, 0).list(); |
| | | // 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()); |
| | | // 基础查询 |
| | | return baseMapper.queryPage(orderQueryRequest, page); |
| | | } |
| | | |
| | | @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(); |
| | | orderByEvaluate.setStarRating(evaluate.getStarRating()); |
| | | orderByEvaluate.setEvaluateTime(evaluate.getCreateTime()); |
| | | orderByEvaluate.setEvaluateContent(evaluate.getContent()); |
| | | if (null != evaluate) { |
| | | 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(); |
| | | if (null == serveRecord) { |
| | | throw new GlobalException("服务记录信息异常,请重试"); |
| | | } |
| | | // 师傅路线轨迹 |
| | | List<ServeCoordinate> serveCoordinateList = serveCoordinateService.lambdaQuery().eq(ServeCoordinate::getWorkerId, order.getServerId()) |
| | | .eq(ServeCoordinate::getIsDelete, 0).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())); |
| | | orderByServeRecord.setPhoto(Arrays.stream(serveRecord.getPhoto().split(",")).collect(Collectors.toList())); |
| | | if (null != order.getArriveTime()) { |
| | | orderByServeRecord.setReachTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(order.getArriveTime())); |
| | | } |
| | | // 服务记录 包含现场照片 |
| | | 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())); |
| | | orderByServeRecord.setCardPic(serveRecord.getCardPic()); |
| | | orderByServeRecord.setPaperPic(serveRecord.getPaperPic()); |
| | | orderByServeRecord.setMachinePic(serveRecord.getMachinePic()); |
| | | } |
| | | 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("服务人员信息异常,请重试"); |
| | | } |
| | | OrderByWorkerVO orderByWorker = new OrderByWorkerVO(); |
| | | orderByWorker.setProfilePicture(worker.getProfilePicture()); |
| | | orderByWorker.setName(worker.getRealName()); |
| | | orderByWorker.setPhone(worker.getPhone()); |
| | | orderByWorker.setSex(worker.getSex()); |
| | | if (null != worker) { |
| | | orderByWorker.setProfilePicture(worker.getProfilePicture()); |
| | | orderByWorker.setName(worker.getRealName()); |
| | | orderByWorker.setPhone(worker.getPhone()); |
| | | orderByWorker.setSex(worker.getSex()); |
| | | } else { |
| | | orderByWorker.setName(order.getServerName()); |
| | | orderByWorker.setPhone(order.getServerPhone()); |
| | | } |
| | | 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("回收服务信息异常,请重试"); |
| | | } |
| | | RecoveryClassify recoveryClassify = recoveryClassifyService.getById(recoveryServe.getClassifyId()); |
| | | if (null == recoveryClassify) { |
| | | throw new GlobalException("回收服务分类信息异常,请重试"); |
| | | } |
| | | OrderByServeVO orderByServe = new OrderByServeVO(); |
| | | orderByServe.setServeName(recoveryServe.getServeName()); |
| | | orderByServe.setSupClassify(recoveryClassify.getSupClassify()); |
| | | orderByServe.setSubClassify(recoveryClassify.getSubClassify()); |
| | | if (null != recoveryServe) { |
| | | RecoveryClassify recoveryClassify = recoveryClassifyService.getById(recoveryServe.getClassifyId()); |
| | | orderByServe.setServeName(recoveryServe.getServeName()); |
| | | orderByServe.setCover(recoveryServe.getCover()); |
| | | if (null != recoveryClassify) { |
| | | orderByServe.setSupClassify(recoveryClassify.getSupClassify()); |
| | | orderByServe.setSubClassify(recoveryClassify.getSubClassify()); |
| | | } |
| | | } else { |
| | | orderByServe.setServeName(order.getServeName()); |
| | | } |
| | | orderByServe.setPrice(order.getServePrice()); |
| | | orderByServe.setSubsidy(order.getSubsidy()); |
| | | result.setServeInfo(orderByServe); |
| | | } |
| | | |
| | | private void orderInfo(OrderDetailVO result, Order order) { |
| | | if (null == order) { |
| | | throw new GlobalException("订单信息异常,请重试"); |
| | | } |
| | | private void orderInfo(OrderDetailVO result, com.ruoyi.order.api.entity.Order order) { |
| | | // 订单信息 |
| | | OrderInfoVO orderInfo = new OrderInfoVO(); |
| | | orderInfo.setOrderNumber(order.getOrderNumber()); |
| | | orderInfo.setPlaceOrderTime(order.getTime()); |
| | | orderInfo.setState(order.getState()); |
| | | if (null != order) { |
| | | orderInfo.setOrderNumber(order.getOrderNumber()); |
| | | orderInfo.setPlaceOrderTime(order.getCreateTime()); |
| | | orderInfo.setState(order.getState()); |
| | | orderInfo.setReservationRemark(order.getReservationRemark()); |
| | | } |
| | | 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); |
| | | if (null == user) { |
| | | throw new GlobalException("预约人信息异常,请重试"); |
| | | } |
| | | OrderByUserInfoVO orderByUserInfo = new OrderByUserInfoVO(); |
| | | orderByUserInfo.setProfilePicture(user.getProfilePicture()); |
| | | orderByUserInfo.setUserNumber(user.getUserNo()); |
| | | if (null != user) { |
| | | orderByUserInfo.setProfilePicture(user.getProfilePicture()); |
| | | orderByUserInfo.setUserNumber(user.getUserNo()); |
| | | } |
| | | orderByUserInfo.setReservationName(order.getReservationName()); |
| | | orderByUserInfo.setReservationPhone(order.getReservationPhone()); |
| | | orderByUserInfo.setReservationAddress(order.getReservationAddress()); |
| | | if (order.getAddress()!=null) { |
| | | orderByUserInfo.setReservationAddress(order.getReservationAddress() + order.getAddress()); |
| | | }else { |
| | | orderByUserInfo.setReservationAddress(order.getReservationAddress()); |
| | | } |
| | | orderByUserInfo.setTime(order.getTime()); |
| | | result.setUserInfo(orderByUserInfo); |
| | | } |
| | | |
| | | /** |
| | | * 订单id列表 |
| | | * |
| | | * @param orderQueryRequest 订单列表查询参数 |
| | | * @return 订单id列表 |
| | | */ |
| | | @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); |
| | | public List<String> queryIdList(OrderQueryRequest orderQueryRequest) { |
| | | // 基础查询 |
| | | Page<com.ruoyi.order.api.entity.Order> pageList = orderClient.queryPage(orderQueryRequest).getData(); |
| | | return pageList.getRecords().stream().map(com.ruoyi.order.api.entity.Order::getId).collect(Collectors.toList()); |
| | | } |
| | | } |