package cn.ezhizao.project.business.controller;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;

import cn.ezhizao.project.business.domain.BizWorkshop;
import cn.ezhizao.project.business.service.IBizWorkshopService;
import cn.ezhizao.project.system.domain.SysDept;
import cn.ezhizao.project.system.service.ISysDeptService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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


/**
 * 车间管理Controller
 *
 * @author ezhizao
 * @date 2024-02-22
 */
@RestController
@RequestMapping("/business/workshop")
public class BizWorkshopController extends BaseController
{
    @Resource
    private IBizWorkshopService bizWorkshopService;
    @Resource
    private ISysDeptService sysDeptService;

    /**
     * 查询车间管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:workshop:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizWorkshop bizWorkshop) throws NoSuchFieldException, IllegalAccessException
    {
//        startPage();
        List<BizWorkshop> list = bizWorkshopService.getList(bizWorkshop);
        return getDataTable(list);
    }

    /**
     * 导出车间管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:workshop:export')")
    @Log(title = "车间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizWorkshop bizWorkshop) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizWorkshop);
        List<BizWorkshop> list = bizWorkshopService.getList(bizWorkshop);
        ExcelUtil<BizWorkshop> util = new ExcelUtil<BizWorkshop>(BizWorkshop.class);
        util.exportExcel(response, list, "车间管理数据");
    }

    /**
     * 获取车间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:workshop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizWorkshopService.getById(id));
    }

}
