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

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.priceRecord.domain.BizTaskTypePriceRecord;
import cn.ezhizao.project.business.priceRecord.service.IBizTaskTypePriceRecordService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 价目表Controller
 *
 * @author ruoyi
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/business/taskTypePriceRecord")
public class BizTaskTypePriceRecordController extends BaseController
{
    @Resource
    private IBizTaskTypePriceRecordService bizTaskTypePriceRecordService;

    /**
     * 查询价目表列表
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTaskTypePriceRecord bizTaskTypePriceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizTaskTypePriceRecord);
        startPage();
        List<BizTaskTypePriceRecord> list = bizTaskTypePriceRecordService.getList(bizTaskTypePriceRecord);
        return getDataTable(list);
    }

    /**
     * 导出价目表列表
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:export')")
    @Log(title = "价目表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizTaskTypePriceRecord bizTaskTypePriceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizTaskTypePriceRecord);
        List<BizTaskTypePriceRecord> list = bizTaskTypePriceRecordService.getList(bizTaskTypePriceRecord);
        ExcelUtil<BizTaskTypePriceRecord> util = new ExcelUtil<BizTaskTypePriceRecord>(BizTaskTypePriceRecord.class);
        util.exportExcel(response, list, "价目表数据");
    }

    /**
     * 获取价目表详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizTaskTypePriceRecordService.getById(id));
    }

    /**
     * 新增价目表
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:add')")
    @Log(title = "价目表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTaskTypePriceRecord bizTaskTypePriceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizTaskTypePriceRecord);
        return toAjax(bizTaskTypePriceRecordService.save(bizTaskTypePriceRecord));
    }

    /**
     * 修改价目表
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:edit')")
    @Log(title = "价目表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTaskTypePriceRecord bizTaskTypePriceRecord) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizTaskTypePriceRecord);
        return toAjax(bizTaskTypePriceRecordService.updateById(bizTaskTypePriceRecord));
    }

    /**
     * 删除价目表
     */
    @PreAuthorize("@ss.hasPermi('business:taskTypePriceRecord:remove')")
    @Log(title = "价目表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizTaskTypePriceRecordService.removeBatchByIds(ids));
    }
}
