package com.yiqi.admin.controller.settlement;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yiqi.common.constant.UrlConstants;
import com.yiqi.settlement.domain.SettlementFactoryRate;
import com.yiqi.settlement.domain.dto.SettlementFactoryRateQueryDTO;
import com.yiqi.settlement.domain.vo.SettlementFactoryRateListVO;
import com.yiqi.settlement.service.ISettlementFactoryRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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 com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 工厂结算费率配置Controller
 *
 * @author ruoyi
 * @date 2024-09-03
 */
@Api(tags = "管理后台 - 工厂结算费率配置")
@RestController
@RequestMapping(UrlConstants.managerApi + "/settlement/factory/rate")
public class SettlementFactoryRateController extends BaseController {

    @Autowired
    private ISettlementFactoryRateService settlementFactoryRateService;

    /**
     * 查询工厂结算费率配置列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询工厂结算费率配置列表")
    public TableDataInfo list(SettlementFactoryRateQueryDTO queryDTO) {
        startPage();
        List<SettlementFactoryRateListVO> list = settlementFactoryRateService.queryList(queryDTO);
        return getDataTable(list);
    }

    /**
     * 导出工厂结算费率配置列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:export')")
    @Log(title = "工厂结算费率配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出工厂结算费率配置列表")
    public void export(HttpServletResponse response, SettlementFactoryRateQueryDTO queryDTO) {
        List<SettlementFactoryRateListVO> list = settlementFactoryRateService.queryList(queryDTO);
        ExcelUtil<SettlementFactoryRateListVO> util = new ExcelUtil<SettlementFactoryRateListVO>(SettlementFactoryRateListVO.class);
        util.exportExcel(response, list, "工厂结算费率配置数据");
    }

    /**
     * 获取工厂结算费率配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取工厂结算费率配置详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(settlementFactoryRateService.getById(id));
    }

    /**
     * 新增工厂结算费率配置
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:add')")
    @Log(title = "工厂结算费率配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增工厂结算费率配置")
    public AjaxResult add(@RequestBody SettlementFactoryRate settlementFactoryRate) {
        settlementFactoryRate.setCreateById(getUserId());
        settlementFactoryRate.setCreateBy(getUsername());
        settlementFactoryRate.setCreateTime(new Date());
        return toAjax(settlementFactoryRateService.save(settlementFactoryRate));
    }

    /**
     * 修改工厂结算费率配置
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:edit')")
    @Log(title = "工厂结算费率配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改工厂结算费率配置")
    public AjaxResult edit(@RequestBody SettlementFactoryRate settlementFactoryRate) {
        settlementFactoryRate.setUpdateById(getUserId());
        settlementFactoryRate.setUpdateBy(getUsername());
        settlementFactoryRate.setUpdateTime(new Date());
        return toAjax(settlementFactoryRateService.updateById(settlementFactoryRate));
    }

    /**
     * 删除工厂结算费率配置
     */
    @PreAuthorize("@ss.hasPermi('settlement:factory:rate:remove')")
    @Log(title = "工厂结算费率配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除工厂结算费率配置")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(settlementFactoryRateService.removeByIds(Arrays.asList(ids)));
    }

}
