package com.ruoyi.admin.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.admin.entity.MasterWorker; import com.ruoyi.admin.netty.NettyChannelMap; import com.ruoyi.admin.netty.NettyWebSocketController; import com.ruoyi.admin.service.MasterWorkerService; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.order.api.entity.ChangeDispatch; import com.ruoyi.order.api.feignClient.ExchangeDispatchClient; import com.ruoyi.order.api.request.ChangeDispatchRequest; import com.ruoyi.system.api.model.LoginUser; 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.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** *

* 改派管理 前端控制器 *

* * @author hjl * @since 2024-05-31 */ @RestController @RequestMapping("/changeDispatch") @Api(tags = {"后台-系统设置-订单改派管理"}) public class ChangeDispatchController { @Resource private ExchangeDispatchClient dispatchClient; @Resource private MasterWorkerService masterWorkerService; @Resource private TokenService tokenService; /** * 订单改派分页列表 * * @param pageNum 页码 * @param pageSize 每页显示条数 */ @RequiresPermissions("reassignment_apply") @ApiOperation(value = "订单改派分页查询列表", tags = {"后台-系统设置-订单改派管理"}) @GetMapping(value = "/page") @ApiImplicitParams({ @ApiImplicitParam(value = "师傅名称", name = "workerName", dataType = "String"), @ApiImplicitParam(value = "订单编号", name = "orderNumber", dataType = "String"), @ApiImplicitParam(value = "下单用户名称", name = "userName", dataType = "String"), @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true), @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true) }) public R> queryPageList(String workerName, String orderNumber, String userName, @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { LoginUser loginUser = tokenService.getLoginUser(); List cityList = new ArrayList<>(); if (loginUser.getIsFranchisee()) { cityList = loginUser.getCityList(); } ChangeDispatchRequest changeDispatchRequest = new ChangeDispatchRequest(); changeDispatchRequest.setWorkerName(workerName); changeDispatchRequest.setOrderNumber(orderNumber); changeDispatchRequest.setUserName(userName); changeDispatchRequest.setPageNum(pageNum); changeDispatchRequest.setPageSize(pageSize); changeDispatchRequest.setCityList(cityList); return dispatchClient.queryPageList(changeDispatchRequest); } /** * 订单改派详情 * * @param changeDispatch 订单改派信息 */ @ApiOperation(value = "新增订单改派", tags = {"后台-系统设置-订单改派管理"}) @PostMapping(value = "/save") public R save(@RequestBody ChangeDispatch changeDispatch) { return R.ok(dispatchClient.save(changeDispatch).getData()); } /** * 订单改派详情 * * @param id 订单改派id */ @RequiresPermissions("reassignment_detail") @ApiOperation(value = "订单改派详情", tags = {"后台-系统设置-订单改派管理"}) @GetMapping(value = "/detail") @ApiImplicitParams({ @ApiImplicitParam(value = "订单改派id", name = "id", dataType = "Integer", required = true) }) public R detail(@RequestParam String id) { return dispatchClient.detail(id); } /** * 根据id批量删除订单改派 * * @param ids 订单改派多条id拼接 */ @RequiresPermissions("reassignment_delete") @ApiOperation(value = "批量删除订单改派", tags = {"后台-系统设置-订单改派管理"}) @GetMapping(value = "/batchDelete") @ApiImplicitParams({ @ApiImplicitParam(value = "多条订单改派id ',' 拼接", name = "ids", dataType = "String", required = true) }) public R batchDelete(@RequestParam String ids) { return dispatchClient.batchDelete(ids); } /** * 拒绝订单改派申请 * * @param id 改派申请记录id */ @RequiresPermissions("reassignment_reject") @ApiOperation(value = "拒绝订单改派申请", tags = {"后台-系统设置-订单改派管理"}) @GetMapping(value = "/refuse") @ApiImplicitParams({ @ApiImplicitParam(value = "改派申请记录id", name = "id", dataType = "String", required = true) }) public R refuse(@RequestParam("id") String id) { return dispatchClient.refuseChangeDispatch(id); } /** * 订单改派师傅 * * @param changeId 改派订单id * @param workerId 师傅id */ @RequiresPermissions("reassignment_reassignment") @ApiOperation(value = "订单改派师傅", tags = {"后台-系统设置-订单改派管理"}) @GetMapping(value = "/changeWorker") @ApiImplicitParams({ @ApiImplicitParam(value = "改派订单id", name = "changeId", dataType = "Integer", required = true), @ApiImplicitParam(value = "师傅id", name = "workerId", dataType = "Integer", required = true) }) public R changeWorker(@RequestParam String changeId, @RequestParam Integer workerId) { MasterWorker masterWorker = masterWorkerService.lambdaQuery() .eq(MasterWorker::getId, workerId).eq(MasterWorker::getIsDelete, 0).one(); if (null == masterWorker) { return R.fail("师傅信息异常!"); } Boolean data = dispatchClient.changeWorker(changeId, workerId, masterWorker.getRealName(), masterWorker.getPhone()).getData(); if (null != data && data) { ChannelHandlerContext context = NettyChannelMap.getData(String.valueOf(workerId)); if (null != context) { NettyWebSocketController.sendMsgToClient(context, "您有一条新的订单,请注意查收!"); } return R.ok(); // try { // WebSocketServer.sendInfo("您有一条新的订单,请注意查收!", String.valueOf(workerId)); // } catch (IOException e) { // return R.fail("师傅不在线!"); // } } return R.fail("订单推送异常!"); } }