| | |
| | | package com.ruoyi.admin.controller; |
| | | |
| | | |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.entity.*; |
| | | import com.ruoyi.admin.importExcel.DemoDataListener; |
| | | import com.ruoyi.admin.importExcel.FrozenBuckleImportDTO; |
| | | import com.ruoyi.admin.netty.NettyChannelMap; |
| | | import com.ruoyi.admin.netty.NettyWebSocketController; |
| | | 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.service.*; |
| | | import com.ruoyi.admin.utils.DescribeInstances; |
| | | import com.ruoyi.admin.utils.HttpUtil; |
| | | import com.ruoyi.admin.vo.OrderByServeRecordVO; |
| | | import com.ruoyi.admin.vo.OrderDetailVO; |
| | | import com.ruoyi.admin.vo.OrderReasinDto; |
| | |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.GaoDeMapUtil; |
| | | import com.ruoyi.common.core.utils.SnowflakeIdWorker; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | 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 io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | import java.io.BufferedInputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | 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; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author hjl |
| | | * @since 2024-05-29 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/order") |
| | | @Api(tags = {"后台-订单管理"}) |
| | |
| | | @Resource |
| | | private RecoveryClassifyService recoveryClassifyService; |
| | | |
| | | |
| | | @Resource |
| | | private FranchiseeService franchiseeService; |
| | | /** |
| | | * 订单列表 |
| | | * |
| | |
| | | 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()) { |
| | |
| | | @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)); |
| | | } |
| | | /** |
| | |
| | | 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()); |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | OrderByServeRecordVO orderByServeRecord = new OrderByServeRecordVO(); |
| | | |
| | | String masterFolderPath = "/usr/local/coordinate/" + id; |
| | | // String masterFolderPath = "F:/DeskTop/coordinate/" + id; |
| | | File masterFolder = new File(masterFolderPath); |
| | | // 检查师傅ID的文件夹是否存在,存在就读取轨迹数据 |
| | | System.out.println("文件是否存在:" + masterFolder.exists()); |
| | |
| | | orderByServeRecord.setCoordinate(coordinateList); |
| | | //获取轨迹标点 |
| | | String baseMarkerPath = "/usr/local/marker/" + id; |
| | | // String baseMarkerPath = "F:/DeskTop/marker/" + id; |
| | | //标点根目录 |
| | | File markerMasterFolder = new File(baseMarkerPath); |
| | | if (markerMasterFolder.exists()) { |
| | |
| | | // return R.ok(list); |
| | | // } |
| | | |
| | | /** |
| | | * 管理后台-订单导入 |
| | | */ |
| | | @ApiOperation(value = "订单导入", tags = {"管理后台"}) |
| | | @PostMapping(value = "/importOrder") |
| | | public R<String> importOrder(@RequestParam("file") MultipartFile file) { |
| | | |
| | | if (!file.isEmpty()) { |
| | | //文件名称 |
| | | int begin = Objects.requireNonNull(file.getOriginalFilename()).indexOf("."); |
| | | //文件名称长度 |
| | | int last = file.getOriginalFilename().length(); |
| | | //判断文件格式是否正确 |
| | | String fileName = file.getOriginalFilename().substring(begin, last); |
| | | if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) { |
| | | throw new IllegalArgumentException("上传文件格式错误"); |
| | | } |
| | | } else { |
| | | throw new IllegalArgumentException("文件不能为空"); |
| | | } |
| | | try (InputStream inputStream = file.getInputStream()) { |
| | | return simpleRead(inputStream); |
| | | } catch (IOException e) { |
| | | System.out.println(e.getMessage()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 最简单的读的监听器 |
| | | */ |
| | | private R<String> simpleRead(InputStream inputStream){ |
| | | //获取正确数据 |
| | | ArrayList<FrozenBuckleImportDTO> successArrayList = new ArrayList<>(); |
| | | //获取错误数据 |
| | | EasyExcel.read(inputStream) |
| | | .head(FrozenBuckleImportDTO.class) |
| | | .registerReadListener(new DemoDataListener( |
| | | // 监听器中doAfterAllAnalysed执行此方法;所有读取完成之后处理逻辑 |
| | | successArrayList::addAll)) |
| | | // 设置sheet,默认读取第一个 |
| | | .sheet() |
| | | // 设置标题(字段列表)所在行数 |
| | | .headRowNumber(2) |
| | | .doRead(); |
| | | System.err.println(successArrayList); |
| | | |
| | | List<Site> sites = siteService.list(Wrappers.lambdaQuery(Site.class).eq(Site::getIsDelete, 0)); |
| | | List<MasterWorker> masterWorkers = masterWorkerService.list(Wrappers.lambdaQuery(MasterWorker.class).eq(MasterWorker::getIsDelete, 0)); |
| | | List<RecoveryServe> recoveryServes =recoveryServeService.list(Wrappers.lambdaQuery(RecoveryServe.class).eq(RecoveryServe::getIsDelete, 0)); |
| | | |
| | | for (FrozenBuckleImportDTO frozenBuckleImportDTO : successArrayList) { |
| | | OrderRequest order = new OrderRequest(); |
| | | BeanUtils.copyProperties(frozenBuckleImportDTO,order); |
| | | String province = frozenBuckleImportDTO.getProvince(); |
| | | String city = frozenBuckleImportDTO.getCity(); |
| | | String area = frozenBuckleImportDTO.getArea(); |
| | | String address = frozenBuckleImportDTO.getReservationAddress(); |
| | | |
| | | // 解析地址经纬度 |
| | | CityInfoVO cityInfoVO = GaoDeMapUtil.getAddressInfo(province + city + area + address).getDatas(); |
| | | String areaCode = cityInfoVO.getCode(); |
| | | String provinceCode = areaCode.substring(0, 2) + "0000"; |
| | | String cityCode = areaCode.substring(0, 4) + "00"; |
| | | order.setProvinceCode(provinceCode); |
| | | order.setCityCode(cityCode); |
| | | order.setAreaCode(areaCode); |
| | | order.setLongitude(cityInfoVO.getLongitude()); |
| | | order.setLatitude(cityInfoVO.getLatitude()); |
| | | |
| | | // 站点信息 |
| | | Site site = sites.stream().filter(e -> e.getSiteName().equals(frozenBuckleImportDTO.getSiteName())).findFirst().orElse(null); |
| | | if(Objects.nonNull(site)){ |
| | | order.setSiteId(site.getId()); |
| | | } |
| | | // 师傅信息 |
| | | if (StringUtils.hasLength(order.getServerName())) { |
| | | MasterWorker masterWorker = masterWorkers.stream().filter(e -> e.getRealName().equals(frozenBuckleImportDTO.getServerName())).findFirst().orElse(null); |
| | | if(Objects.nonNull(masterWorker)){ |
| | | order.setServerId(masterWorker.getId()); |
| | | order.setServerPhone(masterWorker.getPhone()); |
| | | } |
| | | order.setAcceptTime(new Date()); |
| | | // 待上门 |
| | | order.setState(Constants.ONE); |
| | | } else { |
| | | // 待派单状态 |
| | | order.setState(Constants.ZERO); |
| | | } |
| | | // 后台订单 |
| | | order.setType(Constants.ONE); |
| | | order.setSubsidy(BigDecimal.ZERO); |
| | | order.setOrderNumber(String.valueOf(SNOW_FLAKE_ID_WORKER.nextId())); |
| | | // 回收服务信息 |
| | | RecoveryServe recoveryServe = recoveryServes.stream().filter(e->e.getServeName().equals(frozenBuckleImportDTO.getServeName())).findFirst().orElse(null); |
| | | if(Objects.nonNull(recoveryServe)){ |
| | | order.setServeId(recoveryServe.getId()); |
| | | order.setServePrice(recoveryServe.getDefaultPrice()); |
| | | } |
| | | RecoveryServePrice one = recoveryServePriceService.lambdaQuery().eq(RecoveryServePrice::getCity, order.getCityCode()).eq(RecoveryServePrice::getRecoveryServeId, order.getServeId()).eq(BaseEntity::getIsDelete, 0).one(); |
| | | if (one==null) { |
| | | order.setOrderMoney(recoveryServe.getDefaultPrice()); |
| | | }else { |
| | | order.setOrderMoney(one.getRecoveryPrice()); |
| | | } |
| | | Boolean data = orderClient.save(order).getData(); |
| | | if (null == data) { |
| | | return R.fail(orderClient.save(order).getMsg()); |
| | | } |
| | | System.out.println("服务人员id:" + order.getServerId()); |
| | | ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(order.getServerId())); |
| | | System.out.println("socket连接信息:" + context); |
| | | if (null != context) { |
| | | System.out.println("服务端发送消息到: " + order.getServerId()); |
| | | NettyWebSocketController.sendMsgToClient(context, "您有一条新的订单,请注意查收!"); |
| | | } |
| | | return data ? R.ok() : R.fail(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |