package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.domain.CsPricingInventory;
import com.ruoyi.cs.service.ICsPricingInventoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 计价清单Controller
 *
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/cs/csPricingInventory")
public class CsPricingInventoryController extends BaseController
{
    @Resource
    private ICsPricingInventoryService csPricingInventoryService;

    /**
     * 查询计价清单列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsPricingInventory csPricingInventory)
    {
        startPage();
        csPricingInventory.setDelFlag("0");
        List<CsPricingInventory> list = csPricingInventoryService.selectCsPricingInventoryList(csPricingInventory);
        return getDataTable(list);
    }

    /**
     * 导出计价清单列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:export')")
    @Log(title = "计价清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsPricingInventory csPricingInventory)
    {
        List<CsPricingInventory> list = csPricingInventoryService.selectCsPricingInventoryList(csPricingInventory);
        ExcelUtil<CsPricingInventory> util = new ExcelUtil<CsPricingInventory>(CsPricingInventory.class);
        util.exportExcel(response, list, "计价清单数据");
    }

    /**
     * 导出计价清单列表模版
     */
    @Log(title = "导出计价清单列表模版", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response)
    {
        ExcelUtil<CsPricingInventory> util = new ExcelUtil<CsPricingInventory>(CsPricingInventory.class);
        util.exportExcel(response, null, "计价清单数据模版");
    }

    /**
     * 获取计价清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") String inventoryId)
    {
        return AjaxResult.success(csPricingInventoryService.selectCsPricingInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增计价清单
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:add')")
    @Log(title = "计价清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsPricingInventory csPricingInventory)
    {
        return toAjax(csPricingInventoryService.insertCsPricingInventory(csPricingInventory));
    }

    /**
     * 修改计价清单
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:edit')")
    @Log(title = "计价清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsPricingInventory csPricingInventory)
    {
        return toAjax(csPricingInventoryService.updateCsPricingInventory(csPricingInventory));
    }

    /**
     * 删除计价清单
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:remove')")
    @Log(title = "计价清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable String[] inventoryIds)
    {
        return toAjax(csPricingInventoryService.deleteCsPricingInventoryByInventoryIds(inventoryIds));
    }

    /**
     * 选中导出计价清单列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csPricingInventory:export')")
    @Log(title = "计价清单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelect")
    public void exportSelect(@RequestBody String[] inventoryIds)
    {
        List<CsPricingInventory> list = csPricingInventoryService.selectCsPricingInventoryInventoryIds(inventoryIds);
        ExcelUtil<CsPricingInventory> util = new ExcelUtil<CsPricingInventory>(CsPricingInventory.class);
        util.exportExcel(list, "计价清单数据");
    }

    /**
     * 获取计价清单_资源计费说明列表
     */
    @GetMapping(value = "/resourceCharging/{inventoryId}")
    public AjaxResult getResourceChargingInfo(@PathVariable("inventoryId") String inventoryId)
    {
        return AjaxResult.success(csPricingInventoryService.selectResourceChargingListByinventoryId(inventoryId));
    }

}
