javacodeadmin/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java

348 lines
12 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ruoyi.system.controller;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.system.controllerUtil.VerificationResult;
import com.ruoyi.system.controllerUtil.OrderUtil;
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.getId()));
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());
}
}
}
//添加订单日志记录
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) {
List<OrderLog> list = orderLogService.selectOrderLogByOrderId(orderId);
for (OrderLog orderLogdata : list) {
Users users = usersService.selectUsersById(orderLogdata.getWorkerId());
if (users != null) {
orderLogdata.setWorkerName(users.getName());
}
}
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.getId());
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);
}
}