| | |
| | | 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.*; |
| | | 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.*; |
| | | 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.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 = {"后台-订单管理"}) |
| | |
| | | // 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(); |
| | | } |
| | | |
| | | } |