package cn.ezhizao.project.business.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.domain.BizProductInspectionInstruction;
import cn.ezhizao.project.business.service.IBizProductInspectionInstructionService;

/**
 * 产品配置分选标准、检测指导项Controller
 *
 * @author ezhizao
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/business/productInspectionInstruction")
public class BizProductInspectionInstructionController extends BaseController
{
    @Resource
    private IBizProductInspectionInstructionService bizProductInspectionInstructionService;

    /**
     * 查询产品配置分选标准、检测指导项列表
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizProductInspectionInstruction bizProductInspectionInstruction) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductInspectionInstruction);
//        startPage();
        List<BizProductInspectionInstruction> list = bizProductInspectionInstructionService.getList(bizProductInspectionInstruction);
        return getDataTable(list);
    }

    /**
     * 导出产品配置分选标准、检测指导项列表
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:export')")
    @Log(title = "产品配置分选标准、检测指导项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProductInspectionInstruction bizProductInspectionInstruction) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductInspectionInstruction);
        List<BizProductInspectionInstruction> list = bizProductInspectionInstructionService.getList(bizProductInspectionInstruction);
        ExcelUtil<BizProductInspectionInstruction> util = new ExcelUtil<BizProductInspectionInstruction>(BizProductInspectionInstruction.class);
        util.exportExcel(response, list, "产品配置分选标准、检测指导项数据");
    }

    /**
     * 获取产品配置分选标准、检测指导项详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizProductInspectionInstructionService.getById(id));
    }

    /**
     * 新增产品配置分选标准、检测指导项
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:add')")
    @Log(title = "产品配置分选标准、检测指导项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProductInspectionInstruction bizProductInspectionInstruction) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductInspectionInstruction);
        return toAjax(bizProductInspectionInstructionService.save(bizProductInspectionInstruction));
    }

    @Log(title = "产品配置分选标准、检测指导项", businessType = BusinessType.INSERT)
    @PostMapping("/saveBatch")
    public AjaxResult saveBatch(@RequestBody List<BizProductInspectionInstruction> bizProductInspectionInstructions) throws NoSuchFieldException, IllegalAccessException
    {
        for (BizProductInspectionInstruction bizProductInspectionInstruction : bizProductInspectionInstructions) {
            setTenantId(bizProductInspectionInstruction);
        }
        return toAjax(bizProductInspectionInstructionService.saveBatch(bizProductInspectionInstructions));
    }

    /**
     * 修改产品配置分选标准、检测指导项
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:edit')")
    @Log(title = "产品配置分选标准、检测指导项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProductInspectionInstruction bizProductInspectionInstruction) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProductInspectionInstruction);
        return toAjax(bizProductInspectionInstructionService.updateById(bizProductInspectionInstruction));
    }

    /**
     * 删除产品配置分选标准、检测指导项
     */
//    @PreAuthorize("@ss.hasPermi('business:productInspectionInstruction:remove')")
    @Log(title = "产品配置分选标准、检测指导项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizProductInspectionInstructionService.removeBatchByIds(ids));
    }
}
