package com.ruoyi.frequency.customer.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.frequency.customer.entity.Customer;
import com.ruoyi.frequency.customer.model.result.CustomerCount;
import com.ruoyi.frequency.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户Controller
 *
 * @author liwenlong
 * @date 2023-09-22
 */
@RestController
@RequestMapping("/frequency/customer")
public class CustomerController extends BaseController
{
    @Autowired
    private CustomerService customerService;

    /**
     * 查询用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:customer:list')")
    @PostMapping("/list")
    public TableDataInfo<Customer> list(@RequestBody Customer customer)
    {
        startPage();
        List<Customer> list = customerService.selectCustomerList(customer);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Customer customer)
    {
        CustomerCount count = customerService.statistics(customer);
        return AjaxResult.success(count);
    }

    /**
     * 导出用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:customer:export')")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Customer customer)
    {
        List<Customer> list = customerService.selectCustomerList(customer);
        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class);
        return util.exportExcel(list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Customer> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerService.selectCustomerById(id));
    }

    /**
     * 删除用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:customer:remove')")
    @Log(title = "用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(customerService.deleteCustomerByIds(ids,delFlag));
    }

    /**
     * 修改余额
     */
    @Log(title = "设计师", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBalance")
    public AjaxResult updateBalance(@RequestBody Customer customer)
    {
        return customerService.updateBalance(customer);
    }

    /**
     * 修改积分
     */
    @Log(title = "设计师", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIntegral")
    public AjaxResult updateIntegral(@RequestBody Customer customer)
    {
        return customerService.updateIntegral(customer);
    }

}
