package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.feeLog.domain.FeeLogQuery;
import com.ruoyi.bst.feeLog.domain.FeeLogVO;
import com.ruoyi.bst.feeLog.service.FeeLogService;
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;

/**
 * 改价记录Controller
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/bst/feeLog")
public class FeeLogController extends BaseController
{
    @Autowired
    private FeeLogService feeLogService;

    /**
     * 查询改价记录列表
     */
    @PreAuthorize("@ss.hasPermi('bst:feeLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeeLogQuery query)
    {
        startPage();
        startOrderBy();
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.ORDER_VIEW.getCode());
        List<FeeLogVO> list = feeLogService.selectFeeLogList(query);
        return getDataTable(list);
    }

    /**
     * 查询所有改价记录
     */
    @PreAuthorize("@ss.hasPermi('bst:feeLog:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(FeeLogQuery query){
        if (query.getOrderId() == null) {
            return error("订单ID不能为空");
        }
        startOrderBy();
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.ORDER_VIEW.getCode());
        List<FeeLogVO> list = feeLogService.selectFeeLogList(query);
        return success(list);
    }

    /**
     * 导出改价记录列表
     */
    @PreAuthorize("@ss.hasPermi('bst:feeLog:export')")
    @Log(title = "改价记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeeLogQuery query)
    {
        query.setScope(true);
        query.addAreaPermission(AreaJoinPermission.ORDER_VIEW.getCode());
        List<FeeLogVO> list = feeLogService.selectFeeLogList(query);
        ExcelUtil<FeeLogVO> util = new ExcelUtil<FeeLogVO>(FeeLogVO.class);
        util.exportExcel(response, list, "改价记录数据");
    }

    /**
     * 获取改价记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:feeLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(feeLogService.selectFeeLogById(id, true));
    }


}
