package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.Users;
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.OrderRework;
import com.ruoyi.system.service.IOrderReworkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * OrderReworkController
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/system/OrderRework")
public class OrderReworkController extends BaseController
{
    @Autowired
    private IOrderReworkService orderReworkService;
    @Autowired
    private IUsersService usersService;
    /**
     * 查询OrderRework列表
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderRework orderRework)
    {
        startPage();
        List<OrderRework> list = orderReworkService.selectOrderReworkList(orderRework);
        for(OrderRework  orderReworkdata:list){
            Users users=usersService.selectUsersById(orderReworkdata.getUid()) ;
            if(users!=null){
                orderReworkdata.setUname(users.getName());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出OrderRework列表
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:export')")
    @Log(title = "OrderRework", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderRework orderRework)
    {
        List<OrderRework> list = orderReworkService.selectOrderReworkList(orderRework);
        ExcelUtil<OrderRework> util = new ExcelUtil<OrderRework>(OrderRework.class);
        util.exportExcel(response, list, "OrderRework数据");
    }

    /**
     * 获取OrderRework详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderReworkService.selectOrderReworkById(id));
    }

    /**
     * 新增OrderRework
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:add')")
    @Log(title = "OrderRework", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRework orderRework)
    {
        return toAjax(orderReworkService.insertOrderRework(orderRework));
    }

    /**
     * 修改OrderRework
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:edit')")
    @Log(title = "OrderRework", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderRework orderRework)
    {
        return toAjax(orderReworkService.updateOrderRework(orderRework));
    }

    /**
     * 删除OrderRework
     */
    @PreAuthorize("@ss.hasPermi('system:OrderRework:remove')")
    @Log(title = "OrderRework", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderReworkService.deleteOrderReworkByIds(ids));
    }
}
