package cn.ezhizao.project.business.publicSeal.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 cn.ezhizao.project.business.publicSeal.domain.BizPublicSeal;
import cn.ezhizao.project.business.publicSeal.service.IBizPublicSealService;
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;


/**
 * 电子图纸Controller
 *
 * @author ezhizao
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/business/publicSeal")
public class BizPublicSealController extends BaseController
{
    @Resource
    private IBizPublicSealService bizPublicSealService;

    /**
     * 查询电子图纸列表
     */
    @Log(title = "公共章查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizPublicSeal bizPublicSeal) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(bizPublicSeal);
        startPage();
        List<BizPublicSeal> list = bizPublicSealService.getList(bizPublicSeal);
        return getDataTable(list);
    }

    /**
     * 导出电子图纸列表
     */
    @Log(title = "公共章导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPublicSeal bizPublicSeal) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(bizPublicSeal);
        List<BizPublicSeal> list = bizPublicSealService.getList(bizPublicSeal);
        ExcelUtil<BizPublicSeal> util = new ExcelUtil<BizPublicSeal>(BizPublicSeal.class);
        util.exportExcel(response, list, "电子图纸数据");
    }

    /**
     * 获取电子图纸详细信息
     */
    @Log(title = "公共章查询详细信息", businessType = BusinessType.EXPORT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizPublicSealService.getById(id));
    }

    /**
     * 新增电子图纸
     */
    @Log(title = "公共章新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPublicSeal bizPublicSeal) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(bizPublicSeal);
        return toAjax(bizPublicSealService.updateById(bizPublicSeal));
    }

    /**
     * 修改电子图纸
     */
    @Log(title = "公共章修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPublicSeal bizPublicSeal) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(bizPublicSeal);
        return toAjax(bizPublicSealService.updateById(bizPublicSeal));
    }

    /**
     * 删除电子图纸
     */
    @Log(title = "公共章删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizPublicSealService.removeBatchByIds(ids));
    }
}
