package com.ruoyi.project.business.controller.quotation;

import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.domain.TqPriceDetail;
import com.ruoyi.project.business.domain.bo.quotation.NonstandardStatisticsQueryBO;
import com.ruoyi.project.business.domain.bo.quotation.PriceDetailQueryBO;
import com.ruoyi.project.business.domain.vo.quotation.NonstandardStatisticsVO;
import com.ruoyi.project.business.domain.vo.quotation.PriceDetailVO;
import com.ruoyi.project.business.service.quotation.ITqPriceDetailService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/business/price/detail")
public class TqPriceDetailController extends BaseController {

    @Autowired
    private ITqPriceDetailService tqPriceDetailService;

    /**
     * 查询【请填写功能名称】列表
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TqPriceDetail tqPriceDetail) {
        startPage();
        List<TqPriceDetail> list = tqPriceDetailService.selectTqPriceDetailList(tqPriceDetail);
        return getDataTable(list);
    }

    // @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(PriceDetailQueryBO queryBO) {
        List<PriceDetailVO> list = tqPriceDetailService.listAll(queryBO);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TqPriceDetail tqPriceDetail) {
        List<TqPriceDetail> list = tqPriceDetailService.selectTqPriceDetailList(tqPriceDetail);
        ExcelUtil<TqPriceDetail> util = new ExcelUtil<TqPriceDetail>(TqPriceDetail.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tqPriceDetailService.selectTqPriceDetailById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TqPriceDetail tqPriceDetail) {
        return toAjax(tqPriceDetailService.insertTqPriceDetail(tqPriceDetail));
    }

    /**
     * 修改【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TqPriceDetail tqPriceDetail) {
        return toAjax(tqPriceDetailService.updateTqPriceDetail(tqPriceDetail));
    }

    /**
     * 删除【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tqPriceDetailService.deleteTqPriceDetailByIds(ids));
    }

    /**
     * 非标统计查询
     */
    @GetMapping("/nonstandard/list")
    public TableDataInfo listNonstandardStatistics(NonstandardStatisticsQueryBO queryBO) {
        startPage();
        return getDataTable(tqPriceDetailService.listNonstandardStatistics(queryBO));
    }

    /**
     * 非标统计导出
     */
    @Log(title = "非标统计导出", businessType = BusinessType.INSERT)
    @PostMapping("/nonstandard/export")
    public void exportNonstandardStatistics(HttpServletResponse response, NonstandardStatisticsQueryBO queryBO) {
        List<NonstandardStatisticsVO> list = tqPriceDetailService.listNonstandardStatistics(queryBO);
        ExcelUtil<NonstandardStatisticsVO> util = new ExcelUtil<NonstandardStatisticsVO>(NonstandardStatisticsVO.class);
        util.exportExcel(response, list, MessageUtils.message("quotation.nonstandard.statistics"));
    }
}
