package com.yijia.customer.controller;

import java.util.List;
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.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.customer.domain.CustomerGradeSetting;
import com.yijia.customer.service.ICustomerGradeSettingService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 客户优惠等级设置Controller
 * 
 * @author yijia
 * @date 2020-12-21
 */
@RestController
@RequestMapping("/customer/setting")
public class CustomerGradeSettingController extends BaseController
{
    @Autowired
    private ICustomerGradeSettingService customerGradeSettingService;

    /**
     * 查询客户优惠等级设置列表
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerGradeSetting customerGradeSetting)
    {
        startPage();
        List<CustomerGradeSetting> list = customerGradeSettingService.selectCustomerGradeSettingList(customerGradeSetting);
        return getDataTable(list);
    }

    /**
     * 导出客户优惠等级设置列表
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:export')")
    @Log(title = "客户优惠等级设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerGradeSetting customerGradeSetting)
    {
        List<CustomerGradeSetting> list = customerGradeSettingService.selectCustomerGradeSettingList(customerGradeSetting);
        ExcelUtil<CustomerGradeSetting> util = new ExcelUtil<CustomerGradeSetting>(CustomerGradeSetting.class);
        return util.exportExcel(list, "setting");
    }

    /**
     * 获取客户优惠等级设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerGradeSettingService.selectCustomerGradeSettingById(id));
    }

    /**
     * 新增客户优惠等级设置
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:add')")
    @Log(title = "客户优惠等级设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerGradeSetting customerGradeSetting)
    {
        return toAjax(customerGradeSettingService.insertCustomerGradeSetting(customerGradeSetting));
    }

    /**
     * 修改客户优惠等级设置
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:edit')")
    @Log(title = "客户优惠等级设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerGradeSetting customerGradeSetting)
    {
        return toAjax(customerGradeSettingService.updateCustomerGradeSetting(customerGradeSetting));
    }

    /**
     * 删除客户优惠等级设置
     */
    @PreAuthorize("@ss.hasPermi('customer:setting:remove')")
    @Log(title = "客户优惠等级设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerGradeSettingService.deleteCustomerGradeSettingByIds(ids));
    }
}
