package com.ruoyi.frequency.store.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.store.entity.Store;
import com.ruoyi.frequency.store.model.result.StoreCount;
import com.ruoyi.frequency.store.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 表现师Controller
 *
 * @author liwenlong
 * @date 2023-09-22
 */
@RestController
@RequestMapping("/frequency/store")
public class StoreController extends BaseController
{
    @Autowired
    private StoreService storeService;

    /**
     * 查询商户列表
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:list')")
    @PostMapping("/list")
    public TableDataInfo<Store> list(@RequestBody Store store)
    {
        startPage();
        List<Store> list = storeService.selectStoreList(store);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Store store)
    {
        StoreCount count = storeService.statistics(store);
        return AjaxResult.success(count);
    }

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

    /**
     * 获取商户详细信息
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeService.selectStoreById(id));
    }

    /**
     * 新增商户
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:add')")
    @Log(title = "商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Store store)
    {
        return toAjax(storeService.insertStore(store));
    }

    /**
     * 修改商户
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:edit')")
    @Log(title = "商户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Store store)
    {
        return toAjax(storeService.updateStore(store));
    }

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


   /**
     * 修改扣款金额
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:updateViolationDeduction')")
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/updateViolationDeduction")
    public AjaxResult updateViolationDeduction(@RequestBody Store store)
    {
        return toAjax(storeService.updateViolationDeduction(store));
    }


    /**
     * 修改余额
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:updateBalance')")
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBalance")
    public AjaxResult updateBalance(@RequestBody Store store)
    {
        return storeService.updateBalance(store);
    }
    /**
     * 设置为企业
     */
    //@PreAuthorize("@ss.hasPermi('frequency:store:setUpEnterprise')")
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/setUpEnterprise")
    public AjaxResult setUpEnterprise(@RequestBody Store store)
    {
        return storeService.setUpEnterprise(store);
    }


    /**
     * 设置为官方账号
     */
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/setUpPlatform")
    public AjaxResult setUpPlatform(@RequestBody Store store)
    {
        return storeService.setUpPlatform(store);
    }

    /**
     * 设置为DD认证
     */
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/setDDAuth")
    public AjaxResult setDDAuth(@RequestBody Store store)
    {
        return storeService.setDDAuth(store);
    }

    /**
     * 修改提成比例
     */
    @Log(title = "表现师", businessType = BusinessType.UPDATE)
    @PostMapping("/setCommissionRatio")
    public AjaxResult setCommissionRatio(@RequestBody Store store)
    {
        return storeService.setCommissionRatio(store);
    }
}
