GarbageOrderController.java 16.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
package com.trash.garbage.controller;


import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.github.pagehelper.PageHelper;
import com.trash.carInfo.domain.vo.CarInfoVo;
import com.trash.common.annotation.Log;
import com.trash.common.config.trashConfig;
import com.trash.common.core.domain.AjaxResult;
import com.trash.common.core.domain.entity.SysUser;
import com.trash.common.core.domain.model.LoginUser;
import com.trash.common.core.page.PageDomain;
import com.trash.common.core.page.TableSupport;
import com.trash.common.enums.BusinessType;
import com.trash.common.utils.SecurityUtils;
import com.trash.common.utils.ServletUtils;
import com.trash.common.utils.StringUtils;
import com.trash.common.utils.file.FileUploadUtils;
import com.trash.common.utils.file.FileUtils;
import com.trash.common.utils.poi.ExcelUtil;
import com.trash.common.utils.sql.SqlUtil;
import com.trash.enterprise.domain.TransportationEnterprise;
import com.trash.framework.config.ServerConfig;
import com.trash.framework.web.service.TokenService;
import com.trash.garbage.custom.BizException;
import com.trash.garbage.global.Result;
import com.trash.garbage.global.ResultCode;
import com.trash.garbage.pojo.domain.DriverSend;
import com.trash.garbage.pojo.domain.GarOrder;
import com.trash.garbage.pojo.domain.GarOrderMatchAsk;
import com.trash.garbage.pojo.domain.GarOrderMatchDisposal;
import com.trash.garbage.service.*;
import com.trash.garbage.pojo.dto.*;
import com.trash.garbage.pojo.vo.GarOrderMatchAskVo;
import com.trash.garbage.pojo.vo.OrderDetailTransportVo;
import com.trash.garbage.pojo.vo.OrderDetailVo;
import com.trash.garbage.pojo.vo.ScanDriverDetailVo;
import com.trash.garbage.service.impl.GarAddressServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * 订单控制
 *
 * @author 20412
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class GarbageOrderController {

    @Autowired
    private GarOrderService garOrderService;
    @Autowired
    private ServerConfig serverConfig;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private GarOrderMatchAskService garOrderMatchAskService;

    private final static Integer[] USER_TYP_SELF_COMPANY = {2, 3};
    @Autowired
    private GarAddressService garAddressService;
    @Autowired
    private GarOrderMatchHandlerService garOrderMatchHandlerService;

    @PostMapping("/add")
    @Log(title = "创建订单", businessType = BusinessType.INSERT)
    public Result<?> saveOrder(@Validated @RequestBody OrderDto dto) {
        return Result.OK(garOrderService.saveOrder(dto));
    }

    @GetMapping("/query/message/list/{pageNo}/{pageSize}")
    public Result<?> queryOrderMessageList(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        return Result.OK(garOrderService.queryOrderMessageList(pageNo, pageSize));
    }

    @GetMapping("/query/message/count")
    public Result<Integer> queryOrderMessageCount() {
        return Result.OK(garOrderService.queryOrderMessageCount());
    }

    @PutMapping("/read/message")
    public Result<?> readMessage(@RequestBody List<String> messageIds) {
        return Result.OK(garOrderService.readMessage(messageIds));
    }


    @RequestMapping("/upload")
    public Result<?> uploadFile(@RequestParam("file") MultipartFile file) {
        log.info("上传文件");
        String fileName = null;
        try { // 上传文件路径
            String filePath = trashConfig.getUploadPath();
            // 上传并返回新文件名称
            fileName = FileUploadUtils.upload(filePath, file);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("上传文件失败");
            log.error("上传文件失败,请稍后再试",e);
            throw new BizException(ResultCode.CODE_400, ResultCode.CODE_400.getMsg());
        }
        String url = serverConfig.getUrl() + fileName;
        Map<String, String> urlMap = new HashMap<>();
        urlMap.put("url", url);
        urlMap.put("fileName", fileName);
        log.info("上传文件完成");
        return Result.OK(urlMap, "图片上传成功");
    }

    @GetMapping("/detail/{id}")
    public Result<OrderDetailVo> queryOrderDetail(@PathVariable("id") String id) {
        return Result.OK(garOrderService.queryOrderDetail(id));
    }

    @GetMapping("/handler/qrCode/{orderId}")
    public Result<String> createHandlerQrCode(@PathVariable("orderId") String orderId) {
        return Result.OK(garOrderService.createHandlerQrCode(orderId));
    }

    @GetMapping("/detail/transport/{id}")
    public Result<OrderDetailTransportVo> queryOrderTransportDetail(@PathVariable("id") String id) {
        return Result.OK(garOrderService.queryOrderTransportDetail(id));
    }

    @PutMapping("/update")
    @Log(title = "修改订单状态", businessType = BusinessType.UPDATE)
    public Result<String> updateOrder(@RequestBody OrderUpdateDto dto) {
        return Result.OK(garOrderService.updateOrder(dto));
    }

    @PostMapping("/askTransport")
    @Log(title = "确认趟次", businessType = BusinessType.INSERT)
    public Result<String> askTransport(@Validated @RequestBody AskTransportDto dto) {
        return Result.OK(garOrderService.askTransport(dto));
    }

    @GetMapping("/scan/detail/{askId}")
    @Log(title = "趟次详情", businessType = BusinessType.INSERT)
    public Result<GarOrderMatchAskVo> scanDetail(@PathVariable("askId") String askId) {
        return Result.OK(garOrderService.scanDetail(askId));
    }

    @PostMapping("/evaluate")
    @Log(title = "用户评价", businessType = BusinessType.INSERT)
    public Result<String> evaluateOrder(@Validated @RequestBody EvaluateDto dto) {
        return Result.OK(garOrderService.evaluateOrder(dto));
    }

    @GetMapping("/check/code/{validCode}")
    public Result<ScanDriverDetailVo> checkValidCode(@PathVariable("validCode") String validCode) {
        return Result.OK(garOrderService.checkValidCode(validCode));
    }


    @GetMapping("/queryGarOrderMatchAsk/{orderId}")
    public Result<Integer> queryGarOrderMatchAsk(@PathVariable String orderId) {
        return Result.OK(garOrderMatchAskService.queryGarOrderMatchAsk(orderId));
    }

    @GetMapping("/queryGarOrderMatchAsks/{orderId}")
    public Result<Integer> queryGarOrderMatchAsks(@PathVariable String orderId) {
        return Result.OK(garOrderMatchAskService.queryGarOrderMatchAsks(orderId));
    }

    @GetMapping("/queryErrType")
    public Result<Integer> queryErrType() {
        String phone = SecurityUtils.getLoginUser().getUser().getPhonenumber();
        return Result.OK(garOrderMatchAskService.queryErrType(phone));
    }

    @GetMapping("/queryCarCode")
    public Result<List<GarOrderMatchAsk>> queryCarCode(@RequestParam String orderId) {
        return Result.OK(garOrderMatchAskService.queryCarCode(orderId));
    }

    @PostMapping("/sendToDriver")
    public Result<Integer> sendToDriver(@RequestBody DriverSend driverSend) {
        String phone = SecurityUtils.getLoginUser().getUser().getPhonenumber();
        driverSend.setPhone(phone);
        driverSend.setState("0");
        return Result.OK(garOrderMatchAskService.addDriverSend(driverSend));
    }

    @PostMapping("/updateDriverSend")
    public Result<Integer> updateDriverSend(@RequestBody DriverSend driverSend) {
        String phone = SecurityUtils.getLoginUser().getUser().getPhonenumber();
        driverSend.setPhone(phone);
        driverSend.setState("1");
        return Result.OK(garOrderMatchAskService.updateDriverSendState(driverSend));
    }

    @GetMapping("/queryDriverSend")
    public Result<DriverSend> queryDriverSend() {
        String phone = SecurityUtils.getLoginUser().getUser().getPhonenumber();
        return Result.OK(garOrderMatchAskService.queryDriverSend(phone));
    }



    @GetMapping("/querySiteByTel")
    public Result<List<SiteInfoDTO>> querySiteByTel() {
        // 获取登录用户手机号
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        if (loginUser == null || loginUser.getUser() == null) {
            return null;
        }
        String phoneNumber = loginUser.getUser().getPhonenumber();

        // 使用手机号查询
        List<SiteInfoDTO> siteInfoDTO = garAddressService.querySiteByTel(phoneNumber);
        return Result.OK(siteInfoDTO);
    }

    @GetMapping("/query/list")
    public Result<?> queryOrderList(@RequestParam("type") Integer type,
                                    @RequestParam(value = "evaluateFlag", required = false) Integer evaluateFlag,
                                    @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return Result.OK(garOrderService.queryOrderList(type, evaluateFlag, pageNo, pageSize));
    }

    @PutMapping("/dispatch")
    public Result<?> dispatchDriverOrders(@RequestBody DispatchDto dto) {
        garOrderService.dispatchDriverOrders(dto);
        return Result.OK();
    }

    @PutMapping("/dispatch/disposal")
    public Result<?> dispatchDisposalOrders(@RequestBody DisposalDispatchDto dto) {
        garOrderService.dispatchDisposalOrders(dto);
        return Result.OK();
    }

    @GetMapping("/queryDispatch/{orderId}")
    public Result<?> queryDispatch(@PathVariable("orderId") String orderId) {

        return Result.OK(garOrderService.queryDispatch(orderId));
    }
    @GetMapping("/updateGarRealCarCount")
    public Result<?> updateGarRealCarCount(@RequestParam("orderId") String orderId,@RequestParam("garRealCarCount")Integer garRealCarCount) {
        return Result.OK(garOrderService.updateGarRealCarCount(orderId, garRealCarCount));
    }

    @GetMapping("/getGarOrderMatchHandlers")
    public Result<?> getGarOrderMatchHandlers(@RequestParam("orderId") String orderId) {
        return Result.OK(garOrderService.getGarOrderMatchHandlers(orderId));
    }

    @GetMapping("/queryDispatch/dss/{orderId}")
    public Result<?> queryDispatchDss(@PathVariable("orderId") String orderId) {

        return Result.OK(garOrderService.queryDispatch(orderId));
    }

    @GetMapping("/queryDisposalDispatch/{orderId}")
    public Result<?> queryDisposalDispatch(@PathVariable("orderId") String orderId) {
        return Result.OK(garOrderService.queryDisposalDispatch(orderId));
    }

    @GetMapping("/queryOrderHandlerStatus/{orderId}")
    public Result<?> queryOrderHandlerStatus(@PathVariable("orderId") String orderId) {
        return Result.OK(garOrderService.queryOrderHandlerStatus(orderId));
    }


    @PostMapping("/upload/imageUrl")
    public Result<?> uploadImageUrlByType(@RequestBody UploadDto dto) {
        return Result.OK(garOrderService.uploadImageUrlByType(dto));
    }

    /**
     * 导出清运订单列表
     */
    @PreAuthorize("@ss.hasPermi('garbage:order:export')")
    @Log(title = "清运订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GarOrder garOrder, HttpServletResponse response, HttpServletRequest request) {
        List<GarOrder> list = garOrderService.queryOrderListByGarOrder(garOrder);
        ExcelUtil<GarOrder> util = new ExcelUtil<GarOrder>(GarOrder.class);
        AjaxResult ajaxResult = util.exportExcel(list, "order");
        ajaxResult.put("msg",ajaxResult.get(AjaxResult.MSG_TAG));
        return ajaxResult;
//        try
//        {
//            String fileName = String.valueOf(ajaxResult.get(AjaxResult.MSG_TAG));
//            if (!FileUtils.isValidFilename(fileName))
//            {
//                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
//            }
//            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
//            String filePath = trashConfig.getDownloadPath() + fileName;
//
//            response.setCharacterEncoding("utf-8");
//            response.setContentType("multipart/form-data");
//            response.setHeader("Content-Disposition",
//                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
//            FileUtils.writeBytes(filePath, response.getOutputStream());
//        }
//        catch (Exception e)
//        {
//            log.error("下载文件失败", e);
//        }
    }

    @GetMapping("list")
    public Result<?> queryOrderList(OrderWebDto dto) {
        startPage();
        return Result.OK(garOrderService.queryOrderListByGarOrderPage(dto));
    }

    @GetMapping("/webDetail/{id}")
    public Result<OrderDetailVo> queryOrderWebDetail(@PathVariable("id") String id) {
        return Result.OK(garOrderService.queryOrderWebDetail(id));
    }

    @GetMapping("/queryByCarCode/{carCode}")
    public Result<String> queryByCarCode(@PathVariable("carCode") String carCode) {
                System.out.println("进入2");
        return Result.OK(garOrderMatchHandlerService.queryOrderNo(carCode));
    }

    @GetMapping("/evaluate/detail/{orderId}")
    public Result<?> queryEvaluateDetail(@PathVariable("orderId") String orderId) {
        return Result.OK(garOrderService.queryEvaluateDetail(orderId));
    }

    @GetMapping("/company")
    public Result<?> queryEnterpriseList(TransportationEnterprise dto) {
        dto.setId(null);
        if (ArrayUtils.contains(USER_TYP_SELF_COMPANY, dto.getUserTypeValue())) {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            if (Objects.nonNull(loginUser)) {
                SysUser user = loginUser.getUser();
                if (Objects.nonNull(user)) {
                    if (Objects.equals(dto.getUserTypeValue(), 2)) {
                        String id = garOrderService.queryCarIdOfDriver(user.getPhonenumber());
                        dto.setId(id);
                    } else if (Objects.equals(dto.getUserTypeValue(), 3)) {
                        dto.setServicePhone(user.getPhonenumber());
                    }
                }
            }
        }


        return Result.OK(garOrderService.queryEnterpriseList(dto));
    }

    @GetMapping("/docking/up/company")
    public Result<?> dockingUpCompany(TransportationEnterprise dto){
        if (ArrayUtils.contains(USER_TYP_SELF_COMPANY, dto.getUserTypeValue())) {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            if (Objects.nonNull(loginUser)) {
                SysUser user = loginUser.getUser();
                if (Objects.nonNull(user)) {
//                    if (Objects.equals(dto.getUserTypeValue(), 2)) {
//                        Long id = garOrderService.queryCarIdOfDriver(user.getPhonenumber());
//                        dto.setId(id);
//                    } else if (Objects.equals(dto.getUserTypeValue(), 3)) {
//                        dto.setServicePhone(user.getPhonenumber());
//                    }
                    dto.setServicePhone(user.getPhonenumber());
                }
            }
        }
        return Result.OK(garOrderService.dockingUpEnterpriseList(dto));
    }

    @GetMapping("/search/history")
    public Result<?> querySearchHistory() {
        return Result.OK(garOrderService.querySearchHistory());
    }

    @GetMapping("/queryBadgeByType/{type}")
    public Result<?> queryBadgeByType(@PathVariable("type") Integer type) {
        return Result.OK(garOrderService.queryBadgeByType(type));
    }



    protected void startPage() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }
    }

}