| | |
| | | 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.AddressDto; |
| | | import com.ruoyi.admin.utils.DescribeInstances; |
| | | import com.ruoyi.admin.utils.OcrBase; |
| | | 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.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.exception.ServiceException; |
| | | 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 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 javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | 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 = {"后台-订单管理"}) |
| | |
| | | }) |
| | | 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; |
| | | |
| | | |
| | | @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(); |
| | | List<MasterWorker> list = masterWorkerService.lambdaQuery() |
| | | .eq(MasterWorker::getIsDelete, 0).list(); |
| | | if (null != data) { |
| | | for (Order record : data.getRecords()) { |
| | | // 回收服务信息 |
| | | Integer serverId = record.getServerId(); |
| | | MasterWorker masterWorker = masterWorkerService.lambdaQuery() |
| | | .eq(MasterWorker::getId, serverId) |
| | | .eq(MasterWorker::getIsDelete, 0).one(); |
| | | MasterWorker masterWorker = list.stream().filter(e -> e.getId().equals(serverId)).findFirst().orElse(null); |
| | | if (null != masterWorker) { |
| | | record.setServerName(masterWorker.getRealName()); |
| | | record.setServerPhone(masterWorker.getPhone()); |
| | |
| | | } |
| | | return R.ok(data); |
| | | } |
| | | |
| | | /** |
| | | * 订单id列表 |
| | | * |
| | | * @param orderQueryRequest 订单列表查询参数 |
| | | */ |
| | | @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()); |
| | | } |
| | | |
| | |
| | | .eq(MasterWorker::getIsDelete, 0).one(); |
| | | order.setServerName(masterWorker.getRealName()); |
| | | order.setServerPhone(masterWorker.getPhone()); |
| | | // 待上门 |
| | | order.setState(Constants.ONE); |
| | | order.setAcceptTime(new Date()); |
| | | // 待上门 2.0 改为待预约 |
| | | order.setState(7); |
| | | } else { |
| | | // 待派单状态 |
| | | order.setState(Constants.ZERO); |
| | |
| | | order.setSiteName(site.getSiteName()); |
| | | } |
| | | |
| | | Order orderData = orderClient.detail(order.getOrderId()).getData(); |
| | | |
| | | if(order.getTime()!=null&& order.getServerId()!=null&&(!order.getTime().equals(orderData.getTime()) || !order.getServerId().equals(orderData.getServerId()))){ |
| | | // 修改sys_change_dispatch 为已改派 |
| | | dispatchClient.changeReason(order.getOrderId(),""); |
| | | } |
| | | |
| | | // 师傅信息 |
| | | if (null != order.getServerId()) { |
| | | MasterWorker masterWorker = masterWorkerService.lambdaQuery() |
| | |
| | | /** |
| | | * 订单派单/改派 |
| | | * |
| | | * @param type 1:订单派单;2:订单改派 |
| | | */ |
| | | @RequiresPermissions("order_reassignment") |
| | | @ApiOperation(value = "订单列表-订单派单/改派", tags = {"后台-订单管理"}) |
| | | @GetMapping(value = "/reassignment") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "操作类型(1:订单派单;2:订单改派)", name = "type", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "服务人员id", name = "workerId", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "改派原因", name = "applyReason", dataType = "String") |
| | | }) |
| | | @PostMapping(value = "/reassignment") |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<String> reassignment(@RequestParam Integer type, @RequestParam String orderId, |
| | | @RequestParam Integer workerId, String applyReason) { |
| | | 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())) { |
| | | orderClient.updateArrivalTime(order.getId(),orderReasinDto.getArriveTime()); |
| | | |
| | | if (order.getState().equals(Constants.SIX) || order.getState().equals(Constants.THREE)) { |
| | | orderClient.updateState(order.getId(), Constants.ONE); |
| | | orderClient.updateState(order.getId(), 7); |
| | | |
| | | //如果是待改派,将上门时间设置为最新的,并且更新再投原因 |
| | | if (order.getState().equals(Constants.SIX)){ |
| | | dispatchClient.changeReason(order.getId(), ""); |
| | | } |
| | | |
| | | } |
| | | // 订单状态为 待完工时,需要更改状态 待上门且清空师傅到达预约点时间 |
| | | 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(); |
| | | }else { |
| | | orderClient.updateArrivalTime(order.getId(),orderReasinDto.getArriveTime()); |
| | | orderClient.updateState(order.getId(), 7); |
| | | } |
| | | ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(workerId)); |
| | | ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(orderReasinDto.getWorkerId())); |
| | | if (null != context) { |
| | | NettyWebSocketController.sendMsgToClient(context, "您有一条新的订单,请注意查收!"); |
| | | } |
| | |
| | | // } catch (IOException e) { |
| | | // return R.fail("订单推送失败!"); |
| | | // } |
| | | return result ? R.ok() : R.fail(); |
| | | } |
| | | |
| | | return R.ok() ; |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiOperation(value = "订单列表-excel导出", tags = {"后台-订单管理"}) |
| | | @PostMapping(value = "/excelExport") |
| | | public R<String> excelExport(@RequestBody OrderQueryRequest orderQueryRequest, HttpServletResponse response) { |
| | | |
| | | 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 orderService.excelExport(new ArrayList<>(), 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); |
| | | for (Order datum : result.getData()) { |
| | | if(StringUtils.hasLength(datum.getServerName())){ |
| | | datum.setServerName(datum.getServerName().charAt(0)+"***"); |
| | | } |
| | | if(StringUtils.hasLength(datum.getServerPhone())){ |
| | | datum.setServerPhone(around(datum.getServerPhone(), 3, 4)); |
| | | } |
| | | } |
| | | // 独立orderService |
| | | return orderService.excelExport(result.getData(), response); |
| | | } |
| | | |
| | | private static String around(String str, int left, int right){ |
| | | if (str == null || (str.length() < left + right +1)){ |
| | | return str; |
| | | } |
| | | String regex = String.format("(?<=\\w{%d})\\w(?=\\w{%d})", left, right); |
| | | return str.replaceAll(regex, "*"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return R.ok(DescribeInstances.ocr(ocrAddress)); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(LocalDateTime.now().plusMonths(1)); |
| | | } |
| | | |
| | | /** |
| | | * 订单列表-excel导出 |
| | | * |
| | |
| | | @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true) |
| | | }) |
| | | public R<Page<OrderCountVO>> orderCount(String name, String phone, |
| | | @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | public R<Page<OrderCountVO>> orderCount(@RequestBody OrderCountDataRequest orderCountDataRequest) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | List<String> cityList = new ArrayList<>(); |
| | | if (loginUser.getIsFranchisee()) { |
| | | cityList = loginUser.getCityList(); |
| | | if (orderCountDataRequest.getCityList().isEmpty()) { |
| | | List<String> cityList = new ArrayList<>(); |
| | | if (loginUser.getIsFranchisee()) { |
| | | cityList = loginUser.getCityList(); |
| | | orderCountDataRequest.setCityList(cityList); |
| | | } |
| | | } |
| | | // 查询参数 |
| | | OrderCountDataRequest orderCountDataRequest = new OrderCountDataRequest(); |
| | | orderCountDataRequest.setWorkerName(name); |
| | | orderCountDataRequest.setWorkerPhone(phone); |
| | | 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; |
| | |
| | | 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 = {"后台-订单管理-地图统计[2.0]"}) |
| | | @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!=null&&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!=""&&!cityCode.contains("0000"), 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<Map<String,Object>> line(Integer id) { |
| | | |
| | | Map<String,Object> map = new HashMap<>(); |
| | | |
| | | List<OrderByServeRecordVO> list = new ArrayList<>(); |
| | | // 获取当天时间 |
| | | String today = DateUtils.dateTimeNow("yyyy-MM-dd"); |
| | | 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()); |
| | | 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; |
| | | // String baseMarkerPath = "F:/DeskTop/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); |
| | | } |
| | | map.put("orderByServeRecordVO", list); |
| | | MasterWorker masterWorker = masterWorkerService.getById(id); |
| | | map.put("masterWorker", masterWorker); |
| | | |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 获取坐标集合 |
| | | * @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); |
| | | // } |
| | | |
| | | @ApiOperation(value = "导入模板下载", tags = {"管理后台"}) |
| | | @PostMapping(value = "/importTemplate") |
| | | public R<String> importTemplate(HttpServletResponse response) throws Exception { |
| | | List<FrozenBuckleImportDTO> list = new ArrayList<>(); |
| | | FrozenBuckleImportDTO bean = new FrozenBuckleImportDTO(); |
| | | list.add(bean); |
| | | // 这里URLEncoder.encode可以防止中文乱码 |
| | | String fileName = URLEncoder.encode("订单导入模板", "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), FrozenBuckleImportDTO.class).sheet("订单导入模板").doWrite(list); |
| | | return R.ok("下载成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 管理后台-订单导入 |
| | | */ |
| | | @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(); |
| | | } |
| | | |
| | | /** |
| | | * 批量修改订单时间 |
| | | * @param ids 站点多条id拼接 |
| | | */ |
| | | @ApiOperation(value = "订单列表-批量修改订单时间", tags = {"后台-订单管理[2.0]"}) |
| | | @GetMapping(value = "/batchOrderUpdateTime") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "多个id ',' 拼接", name = "ids", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "修改上门时间", name = "time", dataType = "String", required = true), |
| | | }) |
| | | public R<Boolean> batchOrderUpdateTime(@RequestParam("ids") String ids, @RequestParam("time") String time) { |
| | | orderClient.batchUpdateTime(ids, time); |
| | | 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(1) |
| | | .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(); |
| | | |
| | | String time = frozenBuckleImportDTO.getTime(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | try{ |
| | | format.parse(time); |
| | | }catch (Exception e){ |
| | | throw new ServiceException("上门时间格式错误"); |
| | | } |
| | | |
| | | if(!StringUtils.hasLength(address)){ |
| | | return R.fail("详细地址不能为空"); |
| | | } |
| | | // 解析地址经纬度 |
| | | CityInfoVO cityInfoVO = GaoDeMapUtil.getAddressInfo((province==null?"":province) |
| | | + (city==null?"":city) |
| | | + (area==null?"":area) |
| | | + address).getDatas(); |
| | | if(cityInfoVO==null||Objects.isNull(cityInfoVO.getLongitude()) || Objects.isNull(cityInfoVO.getLatitude())){ |
| | | return R.fail("地址输入不正确"); |
| | | } |
| | | 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()); |
| | | if (!StringUtils.hasLength(city)){ |
| | | order.setCity(cityInfoVO.getCity()); |
| | | } |
| | | // 站点信息 |
| | | Site site = sites.stream().filter(e -> e.getSiteName().equals(frozenBuckleImportDTO.getSiteName())).findFirst().orElse(null); |
| | | if(Objects.nonNull(site)){ |
| | | order.setSiteId(site.getId()); |
| | | }else { |
| | | return R.fail("站点信息不存在"); |
| | | } |
| | | // 师傅信息 |
| | | 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()); |
| | | }else { |
| | | return R.fail("师傅信息不存在"); |
| | | } |
| | | 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()); |
| | | }else { |
| | | return R.fail("服务信息不存在"); |
| | | } |
| | | 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 R.ok(); |
| | | } |
| | | |
| | | } |