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.SettlementStoreRate;
import com.yiqi.settlement.domain.dto.SettlementStoreRateQueryDTO;
import com.yiqi.settlement.domain.vo.SettlementStoreRateListVO;
import com.yiqi.settlement.service.ISettlementStoreRateService;
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/store/rate")
public class SettlementStoreRateController extends BaseController {

    @Autowired
    private ISettlementStoreRateService settlementStoreRateService;

    /**
     * 查询门店结算费率配置列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:store:rate:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询门店结算费率配置列表")
    public TableDataInfo list(SettlementStoreRateQueryDTO queryDTO) {
        startPage();
        List<SettlementStoreRateListVO> list = settlementStoreRateService.queryList(queryDTO);
        return getDataTable(list);
    }

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

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

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

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

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

}
