package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Order;
import com.ruoyi.system.domain.Users;
import com.ruoyi.system.service.IOrderService;
import com.ruoyi.system.service.IUsersService;
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.system.domain.OrderSound;
import com.ruoyi.system.service.IOrderSoundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务订单录音文件Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/OrderSound")
public class OrderSoundController extends BaseController
{
    @Autowired
    private IOrderSoundService orderSoundService;
    @Autowired
    private IUsersService usersService;

    @Autowired
    private IOrderService orderService;
    /**
     * 查询服务订单录音文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderSound orderSound)
    {
        startPage();
        List<OrderSound> list = orderSoundService.selectOrderSoundList(orderSound);
        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 getDataTable(list);
    }

    /**
     * 导出服务订单录音文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:export')")
    @Log(title = "服务订单录音文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderSound orderSound)
    {
        List<OrderSound> list = orderSoundService.selectOrderSoundList(orderSound);
        ExcelUtil<OrderSound> util = new ExcelUtil<OrderSound>(OrderSound.class);
        util.exportExcel(response, list, "服务订单录音文件数据");
    }

    /**
     * 获取服务订单录音文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(orderSoundService.selectOrderSoundById(id));
    }

    /**
     * 新增服务订单录音文件
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:add')")
    @Log(title = "服务订单录音文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderSound orderSound)
    {
        return toAjax(orderSoundService.insertOrderSound(orderSound));
    }

    /**
     * 修改服务订单录音文件
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:edit')")
    @Log(title = "服务订单录音文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderSound orderSound)
    {
        return toAjax(orderSoundService.updateOrderSound(orderSound));
    }

    /**
     * 删除服务订单录音文件
     */
    @PreAuthorize("@ss.hasPermi('system:OrderSound:remove')")
    @Log(title = "服务订单录音文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(orderSoundService.deleteOrderSoundByIds(ids));
    }
}
