package cn.ezhizao.project.business.auxiliaryProcess.controller;

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

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 org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.project.business.auxiliaryProcess.domain.BizAuxiliaryProcess;
import cn.ezhizao.project.business.auxiliaryProcess.service.IBizAuxiliaryProcessService;

/**
 * 辅助工序Controller
 *
 * @author ezhizao
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/business/auxiliaryProcess")
public class BizAuxiliaryProcessController extends BaseController
{
    @Resource
    private IBizAuxiliaryProcessService bizAuxiliaryProcessService;

    /**
     * 查询辅助工序列表
     */
    @Log(title = "辅助工序查询", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizAuxiliaryProcess bizAuxiliaryProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAuxiliaryProcess);
        startPage();
        List<BizAuxiliaryProcess> list = bizAuxiliaryProcessService.getList(bizAuxiliaryProcess);
        return getDataTable(list);
    }
    @Log(title = "辅助工序查询所有", businessType = BusinessType.SELECT)
    @GetMapping("/all")
    public TableDataInfo allList(BizAuxiliaryProcess bizAuxiliaryProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAuxiliaryProcess);
        List<BizAuxiliaryProcess> list = bizAuxiliaryProcessService.getList(bizAuxiliaryProcess);
        return getDataTable(list);
    }

    /**
     * 导出辅助工序列表
     */
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:export')")
    @Log(title = "辅助工序导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizAuxiliaryProcess bizAuxiliaryProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAuxiliaryProcess);
        List<BizAuxiliaryProcess> list = bizAuxiliaryProcessService.getList(bizAuxiliaryProcess);
        ExcelUtil<BizAuxiliaryProcess> util = new ExcelUtil<BizAuxiliaryProcess>(BizAuxiliaryProcess.class);
        util.exportExcel(response, list, "辅助工序数据");
    }

    /**
     * 获取辅助工序详细信息
     */
    @Log(title = "辅助工序查询详细信息", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizAuxiliaryProcessService.getById(id));
    }

    /**
     * 新增辅助工序
     */
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:add')")
    @Log(title = "辅助工序新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAuxiliaryProcess bizAuxiliaryProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAuxiliaryProcess);
        return toAjax(bizAuxiliaryProcessService.save(bizAuxiliaryProcess));
    }

    /**
     * 修改辅助工序
     */
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:edit')")
    @Log(title = "辅助工序修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizAuxiliaryProcess bizAuxiliaryProcess) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizAuxiliaryProcess);
        return toAjax(bizAuxiliaryProcessService.updateById(bizAuxiliaryProcess));
    }

    /**
     * 删除辅助工序
     */
    @PreAuthorize("@ss.hasPermi('business:auxiliaryProcess:remove')")
    @Log(title = "辅助工序删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizAuxiliaryProcessService.removeBatchByIds(ids));
    }
}
