hjl
2024-07-02 242725f795b4cca830421c07f714a3ec36af0add
ruoyi-service/ruoyi-admin/src/main/java/com/ruoyi/admin/controller/OrderController.java
@@ -3,11 +3,13 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.Order;
import com.ruoyi.admin.entity.*;
import com.ruoyi.admin.request.OrderQueryRequest;
import com.ruoyi.admin.service.OrderService;
import com.ruoyi.admin.service.*;
import com.ruoyi.admin.sorcket.WebSocketServer;
import com.ruoyi.admin.vo.OrderCountVO;
import com.ruoyi.admin.vo.OrderDetailVO;
import com.ruoyi.admin.vo.OrderPageCountVO;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.SnowflakeIdWorker;
@@ -19,7 +21,10 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@@ -38,10 +43,35 @@
    @Resource
    private OrderService orderService;
    @Resource
    private MasterWorkerService masterWorkerService;
    @Resource
    private SiteService siteService;
    @Resource
    private RecoveryServeService recoveryServeService;
    @Resource
    private RecoveryServePriceService recoveryServePriceService;
    @Resource
    private ChangeDispatchService changeDispatchService;
    /**
     * 雪花算法类
     */
    private static final SnowflakeIdWorker SNOW_FLAKE_ID_WORKER = new SnowflakeIdWorker(5, 5);
    /**
     * socket测试
     */
    @ApiOperation(value = "socket测试", tags = {"后台-订单管理"})
    @GetMapping(value = "/socketTest")
    public R<String> socketTest(@RequestParam String msg, @RequestParam String id) {
        try {
            WebSocketServer.sendInfo(msg, id);
            return R.ok("消息推送成功!");
        } catch (IOException e) {
            return R.fail();
        }
    }
    /**
     * 根据前台用户id查询所有订单信息
@@ -85,6 +115,15 @@
    }
    /**
     * 订单列表
     */
    @ApiOperation(value = "订单列表-各订单数量统计", tags = {"后台-订单管理"})
    @GetMapping(value = "/orderPageCount")
    public R<OrderPageCountVO> orderPageCount() {
        return R.ok(orderService.orderPageCount());
    }
    /**
     * 站点详情
     *
     * @param id 站点id
@@ -107,9 +146,97 @@
    @ApiOperation(value = "订单列表-新增订单", tags = {"后台-订单管理"})
    @PostMapping(value = "/save")
    public R<String> save(@RequestBody Order order) {
        // 站点信息
        Site site = siteService.lambdaQuery()
                .eq(Site::getId, order.getSiteId())
                .eq(Site::getIsDelete, 0).one();
        order.setSiteName(site.getSiteName());
        // 回收服务信息
        RecoveryServe recoveryServe = recoveryServeService.lambdaQuery()
                .eq(RecoveryServe::getId, order.getServeId())
                .eq(RecoveryServe::getIsDelete, 0).one();
        order.setServeName(recoveryServe.getServeName());
        // 不同城市会有不同的回收价格
        RecoveryServePrice price = recoveryServePriceService.lambdaQuery()
                .eq(RecoveryServePrice::getRecoveryServeId, recoveryServe.getId())
                .eq(RecoveryServePrice::getIsDelete, 0)
                .eq(RecoveryServePrice::getCity, order.getCity()).one();
        if (null == price) {
            order.setServePrice(recoveryServe.getDefaultPrice());
            order.setOrderMoney(recoveryServe.getDefaultPrice());
        } else {
            order.setServePrice(price.getRecoveryPrice());
            order.setOrderMoney(price.getRecoveryPrice());
        }
        // 师傅信息
        MasterWorker masterWorker = masterWorkerService.lambdaQuery()
                .eq(MasterWorker::getId, order.getServerId())
                .eq(MasterWorker::getIsDelete, 0).one();
        order.setServerName(masterWorker.getRealName());
        order.setServerPhone(masterWorker.getPhone());
        // 后台订单
        order.setType(Constants.ONE);
        // 待派单状态
        order.setState(Constants.ZERO);
        order.setSubsidy(BigDecimal.ZERO);
        order.setOrderNumber(String.valueOf(SNOW_FLAKE_ID_WORKER.nextId()));
        return orderService.save(order) ? R.ok() : R.fail();
    }
    /**
     * 新增订单
     * 后台订单与用户端及师傅端无关联
     *
     * @param type 1:订单派单;2:订单改派
     */
    @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")
    })
    public R<String> reassignment(@RequestParam Integer type, @RequestParam Integer orderId,
                                  @RequestParam Integer workerId, String applyReason) {
        Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
        MasterWorker masterWorker = masterWorkerService.lambdaQuery()
                .eq(MasterWorker::getId, workerId)
                .eq(MasterWorker::getIsDelete, 0).one();
        // 订单派单
        boolean result = true;
        if (Constants.ONE.equals(type)) {
            order.setServerId(workerId);
            order.setServerName(masterWorker.getRealName());
            order.setServerPhone(masterWorker.getPhone());
            order.setAcceptTime(new Date());
            order.setState(Constants.ONE);
            result = orderService.updateById(order);
        } else if (Constants.TWO.equals(type)) {
            order.setServeId(workerId);
            order.setServerName(masterWorker.getRealName());
            order.setServerPhone(masterWorker.getPhone());
            result = orderService.updateById(order);
            // 生成改派信息
            ChangeDispatch changeDispatch = new ChangeDispatch();
            changeDispatch.setWorkerId(order.getServerId());
            changeDispatch.setWorkerName(order.getServerName());
            changeDispatch.setApplyReason(applyReason);
            changeDispatch.setApplyTime(new Date());
            changeDispatch.setState(Constants.ONE);
            changeDispatch.setOrderId(String.valueOf(order.getId()));
            changeDispatch.setOrderNumber(order.getOrderNumber());
            changeDispatch.setUserId(String.valueOf(order.getUserId()));
            changeDispatch.setUserName(order.getReservationName());
            changeDispatch.setIsDelete(Constants.ZERO);
            changeDispatchService.save(changeDispatch);
        }
        try {
            WebSocketServer.sendInfo("您有一条新的订单,请注意查收!", String.valueOf(workerId));
        } catch (IOException e) {
            return R.fail("订单推送失败!");
        }
        return result ? R.ok() : R.fail();
    }
    /**
@@ -132,12 +259,12 @@
    /**
     * 订单列表-excel导出
     *
     * @param idList 订单id
     * @param orderQueryRequest 筛选参数
     */
    @ApiOperation(value = "订单列表-excel导出", tags = {"后台-订单管理"})
    @PostMapping(value = "/excelExport")
    public R<String> excelExport(@RequestBody List<String> idList, HttpServletResponse response) {
        return orderService.excelExport(idList, response);
    public R<String> excelExport(@RequestBody OrderQueryRequest orderQueryRequest, HttpServletResponse response) {
        return orderService.excelExport(orderQueryRequest, response);
    }
    /**
@@ -151,8 +278,8 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "师傅姓名", name = "name", dataType = "String"),
            @ApiImplicitParam(value = "师傅电话", name = "phone", dataType = "String"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer",required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer",required = true)
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<OrderCountVO>> orderCount(String name, String phone,
                                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,