package com.younike.web.controller.system;

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.SysCode;
import com.younike.system.service.ISysCodeService;
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-06
 */
@Api("店铺端常量接口")
@RestController
@RequestMapping("/system/code")
public class SysCodeController extends BaseController{
    @Autowired
    private ISysCodeService sysCodeService;

    /**
     * 查询店铺端常量列表
     */
    @ApiOperation("查询店铺端常量列表")
    @PreAuthorize("@ss.hasPermi('system:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCode sysCode) {
        startPage();
        List<SysCode> list = sysCodeService.selectSysCodeList(sysCode);
        return getDataTable(list);
    }

    /**
     * 导出店铺端常量列表
     */
    @ApiOperation("导出店铺端常量列表")
    @PreAuthorize("@ss.hasPermi('system:code:export')")
    @Log(title = "店铺端常量", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysCode sysCode) {
        List<SysCode> list = sysCodeService.selectSysCodeList(sysCode);
        ExcelUtil<SysCode> util = new ExcelUtil<SysCode>(SysCode.class);
        return util.exportExcel(list, "店铺端常量数据");
    }

    /**
     * 获取店铺端常量详细信息
     */
    @ApiOperation("获取店铺端常量详细信息")
    @PreAuthorize("@ss.hasPermi('system:code:query')")
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") String codeId) {
        return AjaxResult.success(sysCodeService.selectSysCodeByCodeId(codeId));
    }

    /**
     * 新增店铺端常量
     */
    @ApiOperation("新增店铺端常量")
    @PreAuthorize("@ss.hasPermi('system:code:add')")
    @Log(title = "店铺端常量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCode sysCode) {
        return toAjax(sysCodeService.insertSysCode(sysCode));
    }

    /**
     * 修改店铺端常量
     */
    @ApiOperation("修改店铺端常量")
    @PreAuthorize("@ss.hasPermi('system:code:edit')")
    @Log(title = "店铺端常量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCode sysCode) {
        return toAjax(sysCodeService.updateSysCode(sysCode));
    }

    /**
     * 删除店铺端常量
     */
    @ApiOperation("删除店铺端常量")
    @PreAuthorize("@ss.hasPermi('system:code:remove')")
    @Log(title = "店铺端常量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable String[] codeIds) {
        return toAjax(sysCodeService.deleteSysCodeByCodeIds(codeIds));
    }
}
