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.bo.quotation.QuotationAddBO;
import com.ruoyi.project.business.domain.bo.quotation.QuotationCopyBO;
import com.ruoyi.project.business.domain.bo.quotation.QuotationQueryBO;
import com.ruoyi.project.business.domain.vo.quotation.QuotationExportVO;
import com.ruoyi.project.business.domain.vo.quotation.QuotationVO;
import com.ruoyi.project.business.service.quotation.ITqQuotationService;
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-10
 */
@RestController
@RequestMapping("/business/quotation")
public class TqQuotationController extends BaseController {

    @Autowired
    private ITqQuotationService tqQuotationService;

    /**
     * 查询【报价】列表
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuotationQueryBO queryBO) {
        startPage();
        List<QuotationVO> list = tqQuotationService.selectTqQuotationList(queryBO);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:export')")
    @Log(title = "【导出报价】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuotationQueryBO queryBO) {
        List<QuotationExportVO> list = tqQuotationService.listExportVO(queryBO);
        ExcelUtil<QuotationExportVO> util = new ExcelUtil<QuotationExportVO>(QuotationExportVO.class);
        util.exportExcel(response, list, MessageUtils.message("quotation.quotation"));
    }

    /**
     * 获取【报价详情】详细信息
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tqQuotationService.selectTqQuotationById(id));
    }

    /**
     * 新增【新增报价】
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:add')")
    @Log(title = "【新增报价】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuotationAddBO quotationAddBO) {
        tqQuotationService.insertTqQuotation(quotationAddBO);
        return success();
    }

    /**
     * 修改【编辑报价】
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:edit')")
    @Log(title = "【编辑报价】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuotationAddBO quotationAddBO) {
        tqQuotationService.updateTqQuotation(quotationAddBO);
        return success();
    }

    /**
     * 【复制版本】
     */
    // @PreAuthorize("@ss.hasPermi('business:quotation:copy')")
    @Log(title = "【复制版本】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/copy")
    public AjaxResult copyVersion(@RequestBody QuotationCopyBO copyBO) {
        tqQuotationService.copyVersions(copyBO);
        return success();
    }

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

    /**
     * 根据项目id查询报价列表
     */
    @GetMapping("/listByProjectId/{projectId}")
    public AjaxResult listByProjectId(@PathVariable("projectId") Long projectId) {
        return success(tqQuotationService.listByProjectId(projectId));
    }

    // @PreAuthorize("@ss.hasPermi('business:quotation:query')")
    @GetMapping(value = "/price/{quotationId}")
    public AjaxResult getPrice(@PathVariable("quotationId") Long quotationId) {
        return success(tqQuotationService.getPriceInfo(quotationId));
    }

    @GetMapping(value = "/salesDiscount/{quotationId}")
    public AjaxResult getSalesDiscountByQuotationId(@PathVariable("quotationId") Long quotationId) {
        return success(tqQuotationService.getSalesDiscountByQuotationId(quotationId));
    }

}
