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.BizProcessInspectionPicture;
import cn.ezhizao.project.business.service.IBizProcessInspectionPictureService;

/**
 * 电子图纸Controller
 *
 * @author ezhizao
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/business/picture")
public class BizProcessInspectionPictureController extends BaseController
{
    @Resource
    private IBizProcessInspectionPictureService bizProcessInspectionPictureService;

    /**
     * 查询电子图纸列表
     */
    @PreAuthorize("@ss.hasPermi('business:picture:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizProcessInspectionPicture bizProcessInspectionPicture) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionPicture);
        startPage();
        List<BizProcessInspectionPicture> list = bizProcessInspectionPictureService.getList(bizProcessInspectionPicture);
        return getDataTable(list);
    }

    /**
     * 导出电子图纸列表
     */
    @PreAuthorize("@ss.hasPermi('business:picture:export')")
    @Log(title = "电子图纸", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProcessInspectionPicture bizProcessInspectionPicture) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionPicture);
        List<BizProcessInspectionPicture> list = bizProcessInspectionPictureService.getList(bizProcessInspectionPicture);
        ExcelUtil<BizProcessInspectionPicture> util = new ExcelUtil<BizProcessInspectionPicture>(BizProcessInspectionPicture.class);
        util.exportExcel(response, list, "电子图纸数据");
    }

    /**
     * 获取电子图纸详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:picture:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizProcessInspectionPictureService.getById(id));
    }

    /**
     * 新增电子图纸
     */
    @PreAuthorize("@ss.hasPermi('business:picture:add')")
    @Log(title = "电子图纸", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProcessInspectionPicture bizProcessInspectionPicture) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionPicture);
        return toAjax(bizProcessInspectionPictureService.save(bizProcessInspectionPicture));
    }

    /**
     * 修改电子图纸
     */
    @PreAuthorize("@ss.hasPermi('business:picture:edit')")
    @Log(title = "电子图纸", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProcessInspectionPicture bizProcessInspectionPicture) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizProcessInspectionPicture);
        return toAjax(bizProcessInspectionPictureService.updateById(bizProcessInspectionPicture));
    }

    /**
     * 删除电子图纸
     */
    @PreAuthorize("@ss.hasPermi('business:picture:remove')")
    @Log(title = "电子图纸", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizProcessInspectionPictureService.removeBatchByIds(ids));
    }
}
