559 lines
20 KiB
Java
559 lines
20 KiB
Java
package com.ruoyi.system.controller;
|
||
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import com.ruoyi.system.ControllerUtil.DispatchUtil;
|
||
import com.ruoyi.system.ControllerUtil.OrderUtil;
|
||
import com.ruoyi.system.ControllerUtil.VerificationResult;
|
||
import com.ruoyi.system.ControllerUtil.WXsendMsgUtil;
|
||
import com.ruoyi.system.domain.*;
|
||
import com.ruoyi.system.service.*;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.GetMapping;
|
||
import org.springframework.web.bind.annotation.PostMapping;
|
||
import org.springframework.web.bind.annotation.PutMapping;
|
||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||
import org.springframework.web.bind.annotation.PathVariable;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
import com.ruoyi.common.annotation.Log;
|
||
import com.ruoyi.common.core.controller.BaseController;
|
||
import com.ruoyi.common.core.domain.AjaxResult;
|
||
import com.ruoyi.common.enums.BusinessType;
|
||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||
import com.ruoyi.common.core.page.TableDataInfo;
|
||
import com.ruoyi.system.service.ISysUserService;
|
||
import com.ruoyi.system.service.IServiceGoodsService;
|
||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||
import com.ruoyi.system.domain.ServiceGoods;
|
||
|
||
/**
|
||
* 服务订单Controller
|
||
*
|
||
* @author ruoyi
|
||
* @date 2025-05-13
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/system/Order")
|
||
public class OrderController extends BaseController {
|
||
@Autowired
|
||
private IOrderService orderService;
|
||
@Autowired
|
||
private IServiceGoodsService serviceGoodsService;
|
||
@Autowired
|
||
IUsersService usersService;
|
||
@Autowired
|
||
IOrderCallService orderCallService;
|
||
@Autowired
|
||
IOrderCommentService orderCommentService;
|
||
@Autowired
|
||
IOrderSoundLogService orderSoundLogService;
|
||
@Autowired
|
||
IOrderSoundService orderSoundService;
|
||
|
||
@Autowired
|
||
IOrderLogService orderLogService;
|
||
@Autowired
|
||
INotifyOrderService notifyOrderService;
|
||
@Autowired
|
||
private ISysUserService sysUserService;
|
||
|
||
/**
|
||
* 查询服务订单列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:list')")
|
||
@GetMapping("/list")
|
||
public TableDataInfo list(Order order) {
|
||
startPage();
|
||
List<Order> list = orderService.selectOrderList(order);
|
||
for (Order orderdata : list) {
|
||
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(orderdata.getProductId());
|
||
if (serviceGoods != null) {
|
||
orderdata.setProductName(serviceGoods.getTitle());
|
||
}
|
||
Users users = usersService.selectUsersById(orderdata.getUid());
|
||
if (users != null) {
|
||
orderdata.setUname(users.getName());
|
||
}
|
||
orderdata.setThjl(orderCallService.selectCountOrderCallByOid(orderdata.getId()));
|
||
orderdata.setFwpj(orderCommentService.selectCountOrderCommentByOid(orderdata.getOrderId()));
|
||
orderdata.setLywj(orderSoundService.selectCountOrderSoundByOid(orderdata.getId()));
|
||
orderdata.setJdjl(orderLogService.selectCountOrderLogByOrderId(orderdata.getOrderId()));
|
||
orderdata.setTzjl(notifyOrderService.selectNotifyOrderCountByOid(orderdata.getId()));
|
||
|
||
}
|
||
return getDataTable(list);
|
||
}
|
||
|
||
/**
|
||
* 导出服务订单列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:export')")
|
||
@Log(title = "服务订单", businessType = BusinessType.EXPORT)
|
||
@PostMapping("/export")
|
||
public void export(HttpServletResponse response, Order order) {
|
||
List<Order> list = orderService.selectOrderList(order);
|
||
ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
|
||
util.exportExcel(response, list, "服务订单数据");
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "/{id}")
|
||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||
Order order = orderService.selectOrderById(id);
|
||
if (order != null){
|
||
order.setOrderLog(new OrderLog());
|
||
}
|
||
|
||
return success(order);
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "generateCode")
|
||
public AjaxResult generateCode() {
|
||
return success(OrderUtil.generateCode());
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 新增服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:add')")
|
||
@Log(title = "服务订单", businessType = BusinessType.INSERT)
|
||
@PostMapping
|
||
public AjaxResult add(@RequestBody Order order) {
|
||
OrderUtil orderUtil = new OrderUtil();
|
||
//1,根据用户手机号和地址判断用户的数据数据和地址数据
|
||
//如果用户数据不存在,则添加用户数据
|
||
//如果用户地址不存在,则添加用户地址数据
|
||
if (order.getType() == 1) {
|
||
Map<String, Object> map = orderUtil.isUser(order.getPhone(), order.getAddress());
|
||
if (map.get("code").equals("1")) {
|
||
Users usersdata = (Users) map.get("users");
|
||
UserAddress userAddressdata = (UserAddress) map.get("UserAddress");
|
||
if (userAddressdata != null) {
|
||
order.setAddressId(userAddressdata.getId());
|
||
}
|
||
if (usersdata != null) {
|
||
order.setUid(usersdata.getId());
|
||
}
|
||
|
||
}
|
||
order.setUserPhone(order.getPhone());
|
||
}
|
||
//添加订单日志记录
|
||
int flg= orderService.insertOrder(order);
|
||
if (flg>0){
|
||
return toAjax(orderUtil.SaveOrderLog(order));
|
||
}else{
|
||
return error();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "/selectBaseProjectList/{id}")
|
||
public AjaxResult selectBaseProjectList(@PathVariable("id") Long id) {
|
||
Order order = orderService.selectOrderById(id);
|
||
if (order != null){
|
||
ServiceGoods serviceGoods=serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
if(serviceGoods!=null){
|
||
return success(serviceGoods);
|
||
}else{
|
||
return error();
|
||
}
|
||
}else{
|
||
return error();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 修改服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "服务订单", businessType = BusinessType.UPDATE)
|
||
@PutMapping
|
||
public AjaxResult edit(@RequestBody Order order) {
|
||
//插入订单日志记录
|
||
OrderUtil orderUtil = new OrderUtil();
|
||
Order oldorder=orderService.selectOrderById(order.getId());
|
||
//验证订单状态
|
||
VerificationResult verificationResult = orderUtil.validateOrderStatusChange(order, oldorder);
|
||
if (verificationResult.getCode().equals(VerificationResult.CODE_SUCCESS)){
|
||
|
||
//特殊情况,状态不变的情况下,不插入日志记录
|
||
if (!verificationResult.getData().equals("NODATA")){
|
||
//开始服务,需要给order做标记
|
||
orderUtil.SaveOrderLog(order);
|
||
}else{
|
||
if(!order.getStatus().equals(oldorder.getStatus())){
|
||
orderUtil.SaveOrderLog(order);
|
||
}
|
||
}
|
||
return toAjax(orderService.updateOrder(order));
|
||
}else{
|
||
return error(verificationResult.getData());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:remove')")
|
||
@Log(title = "服务订单", businessType = BusinessType.DELETE)
|
||
@DeleteMapping("/{ids}")
|
||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||
return toAjax(orderService.deleteOrderByIds(ids));
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取订单接单记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/receive-records/{orderId}")
|
||
public AjaxResult getReceiveRecords(@PathVariable("orderId") String orderId) {
|
||
System.out.println("=== 获取接单记录 ===");
|
||
System.out.println("订单ID: " + orderId);
|
||
|
||
List<OrderLog> list = orderLogService.selectOrderLogByOrderIdASC(orderId);
|
||
System.out.println("查询到的日志记录数量: " + (list != null ? list.size() : "null"));
|
||
|
||
if (list != null && !list.isEmpty()) {
|
||
System.out.println("第一条记录: " + list.get(0));
|
||
for (OrderLog orderLogdata : list) {
|
||
System.out.println("处理日志记录: ID=" + orderLogdata.getId() + ", 标题=" + orderLogdata.getTitle());
|
||
if (orderLogdata.getWorkerId() != null) {
|
||
Users users = usersService.selectUsersById(orderLogdata.getWorkerId());
|
||
if (users != null) {
|
||
orderLogdata.setWorkerName(users.getName());
|
||
System.out.println("设置师傅姓名: " + users.getName());
|
||
} else {
|
||
System.out.println("未找到师傅信息,workerId: " + orderLogdata.getWorkerId());
|
||
}
|
||
} else {
|
||
System.out.println("日志记录没有师傅ID");
|
||
}
|
||
}
|
||
} else {
|
||
System.out.println("没有找到订单日志记录");
|
||
}
|
||
|
||
return success(list);
|
||
}
|
||
|
||
// /**
|
||
// * 获取订单通话记录
|
||
// */
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/call-records/{orderId}")
|
||
public AjaxResult getCallRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
return success(orderCallService.selectOrderCallByOid(data.getId()));
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取订单录音文件
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/audio-records/{orderId}")
|
||
public AjaxResult getAudioRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
List<OrderSound> list = orderSoundService.selectOrderSoundByOid(data.getId());
|
||
for (OrderSound orderSounddata : list) {
|
||
orderSounddata.setFile("https://img.huafurenjia.cn/" + orderSounddata.getFile());
|
||
// https://img.huafurenjia.cn/
|
||
Users users = usersService.selectUsersById(orderSounddata.getWorkerUid());
|
||
Order order = orderService.selectOrderById(orderSounddata.getOid());
|
||
if (users != null) {
|
||
orderSounddata.setWorkerName(users.getName());
|
||
}
|
||
if (order != null) {
|
||
orderSounddata.setOcode(order.getOrderId());
|
||
}
|
||
}
|
||
return success(list);
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取订单通知记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/notify-records/{orderId}")
|
||
public AjaxResult getNotifyRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
return success(notifyOrderService.selectNotifyOrderByOid(data.getId()));
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取订单通知记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/comment-records/{orderId}")
|
||
public AjaxResult getCommentRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
List<OrderComment> list = orderCommentService.selectOrderCommentByOid(data.getOrderId());
|
||
for (OrderComment orderCommentdata : list) {
|
||
Users users = usersService.selectUsersById(orderCommentdata.getUid());
|
||
if (users != null) {
|
||
orderCommentdata.setUname(users.getName());
|
||
}
|
||
}
|
||
return success(list);
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取用户下拉列表
|
||
*/
|
||
@GetMapping("/userOptions")
|
||
public AjaxResult getUserOptions() {
|
||
List<SysUser> users = sysUserService.selectUserList(new SysUser());
|
||
return AjaxResult.success(users);
|
||
}
|
||
|
||
/**
|
||
* 获取商品下拉列表
|
||
*/
|
||
@GetMapping("/serviceGoodsOptions")
|
||
public AjaxResult getServiceGoodsOptions() {
|
||
List<ServiceGoods> goods = serviceGoodsService.selectServiceGoodsList(new ServiceGoods());
|
||
return AjaxResult.success(goods);
|
||
}
|
||
|
||
/**
|
||
* 派单接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "订单派单", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/dispatch")
|
||
public AjaxResult dispatch(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
Long orderId = Long.valueOf(params.get("orderId").toString());
|
||
Integer receiveType = Integer.valueOf(params.get("receiveType").toString());
|
||
Long workerId = null;
|
||
if (params.get("workerId") != null) {
|
||
workerId = Long.valueOf(params.get("workerId").toString());
|
||
}
|
||
// 查询师傅
|
||
Users users = usersService.selectUsersById(workerId);
|
||
if (users == null) {
|
||
return error("工人不存在");
|
||
}
|
||
|
||
// 查询订单
|
||
Order order = orderService.selectOrderById(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if (order.getStatus() != 1) {
|
||
return error("只有待接单状态的订单才能派单");
|
||
}
|
||
//给师傅派单的时候的推送
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
WXsendMsgUtil.sendMsgForWorkerInfo(users.getOpenid(), order, serviceGoods);
|
||
DispatchUtil.creatWorkerForOrder(order,users);
|
||
//
|
||
// // 更新订单的派单类型
|
||
// order.setReceiveType(receiveType.longValue());
|
||
//
|
||
// // 如果是指定工人,需要验证工人信息
|
||
// if (receiveType == 3 && workerId != null) {
|
||
// // 这里可以添加工人验证逻辑
|
||
// // 暂时跳过工人验证
|
||
// }
|
||
//
|
||
// // 更新订单状态为待服务
|
||
// order.setStatus(2L);
|
||
|
||
return toAjax(1);
|
||
} catch (Exception e) {
|
||
return error("派单失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取可派单工人列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/getCanDoWorkerList")
|
||
public TableDataInfo getCanDoWorkerList(Users users) {
|
||
startPage();
|
||
List<Users> list = usersService.selectUsersList(users);
|
||
return getDataTable(list);
|
||
}
|
||
|
||
/**
|
||
* 获取所有工人列表(用于订单处理)
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@GetMapping("/getWorkerList")
|
||
public AjaxResult getWorkerList() {
|
||
Users users = new Users();
|
||
users.setType("2"); // 工人类型
|
||
List<Users> list = usersService.selectUsersList(users);
|
||
return AjaxResult.success(list);
|
||
}
|
||
|
||
/**
|
||
* 更换师傅接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "更换师傅", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/change-worker")
|
||
public AjaxResult changeWorker(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:调用DispatchUtil进行重新派单
|
||
|
||
return success("更换师傅成功");
|
||
} catch (Exception e) {
|
||
return error("更换师傅失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 出发上门接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "出发上门", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/departure")
|
||
public AjaxResult departure(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:更新订单状态为出发上门,记录出发时间等
|
||
|
||
return success("出发上门成功");
|
||
} catch (Exception e) {
|
||
return error("出发上门失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 确认到达接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "确认到达", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/confirm-arrival")
|
||
public AjaxResult confirmArrival(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:更新订单状态为已到达,记录到达时间等
|
||
|
||
return success("确认到达成功");
|
||
} catch (Exception e) {
|
||
return error("确认到达失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 结束订单接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "结束订单", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/end-order")
|
||
public AjaxResult endOrder(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:更新订单状态为已结束,记录结束时间等
|
||
|
||
return success("订单已结束");
|
||
} catch (Exception e) {
|
||
return error("结束订单失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开始服务接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "开始服务", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/start-service")
|
||
public AjaxResult startService(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:更新订单状态为服务中,记录开始时间等
|
||
|
||
return success("开始服务成功");
|
||
} catch (Exception e) {
|
||
return error("开始服务失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 项目报价接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "项目报价", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/project-quote")
|
||
public AjaxResult projectQuote(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:创建项目报价,更新订单状态等
|
||
|
||
return success("项目报价成功");
|
||
} catch (Exception e) {
|
||
return error("项目报价失败:" + e.getMessage());
|
||
}
|
||
}
|
||
}
|