package com.younike.merchant;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.system.domain.MerchantCategory;
import com.younike.system.service.IMerchantCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 jubs
 * @date 2022-01-13
 */
@Api("店铺服务分类关联接口")
@RestController
@RequestMapping("/system/category")
public class MerchantCategoryController  extends BaseController {
    @Autowired
    private IMerchantCategoryService merchantCategoryService;

    /**
     * 查询店铺服务分类关联列表
     */
    @ApiOperation("查询店铺服务分类关联列表")
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantCategory merchantCategory) {
        startPage();
        List<MerchantCategory> list = merchantCategoryService.selectMerchantCategoryList(merchantCategory);
        return getDataTable(list);
    }

    /**
     * 导出店铺服务分类关联列表
     */
    @ApiOperation("导出店铺服务分类关联列表")
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "店铺服务分类关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MerchantCategory merchantCategory) {
        List<MerchantCategory> list = merchantCategoryService.selectMerchantCategoryList(merchantCategory);
        ExcelUtil<MerchantCategory> util = new ExcelUtil<MerchantCategory>(MerchantCategory.class);
        return util.exportExcel(list, "店铺服务分类关联数据");
    }

    /**
     * 获取店铺服务分类关联详细信息
     */
    @ApiOperation("获取店铺服务分类关联详细信息")
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(merchantCategoryService.selectMerchantCategoryById(id));
    }

    /**
     * 新增店铺服务分类关联
     */
    @ApiOperation("新增店铺服务分类关联")
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "店铺服务分类关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantCategory merchantCategory) {
        return toAjax(merchantCategoryService.insertMerchantCategory(merchantCategory));
    }

    /**
     * 修改店铺服务分类关联
     */
    @ApiOperation("修改店铺服务分类关联")
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "店铺服务分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantCategory merchantCategory) {
        return toAjax(merchantCategoryService.updateMerchantCategory(merchantCategory));
    }

    /**
     * 删除店铺服务分类关联
     */
    @ApiOperation("删除店铺服务分类关联")
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "店铺服务分类关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(merchantCategoryService.deleteMerchantCategoryByIds(ids));
    }
}
