package com.ruoyi.cms.controller.cms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.cms.domain.CommercialArea;
import com.ruoyi.cms.service.ICommercialAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商圈Controller
 * 
 * @author Lishundong
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/cms/area")
@Api(tags = "后台：商圈")
public class  CommercialAreaController extends BaseController
{
    @Autowired
    private ICommercialAreaService commercialAreaService;

    /**
     * 查询商圈列表
     */
    @ApiOperation("查询商圈列表")
    @PreAuthorize("@ss.hasPermi('cms:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommercialArea commercialArea)
    {
        startPage();
        List<CommercialArea> list = commercialAreaService.selectCommercialAreaList(commercialArea);
        return getDataTable(list);
    }

    /**
     * 导出商圈列表
     */
    @ApiOperation("导出商圈列表")
    @PreAuthorize("@ss.hasPermi('cms:area:export')")
    @Log(title = "商圈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommercialArea commercialArea)
    {
        List<CommercialArea> list = commercialAreaService.selectCommercialAreaList(commercialArea);
        ExcelUtil<CommercialArea> util = new ExcelUtil<CommercialArea>(CommercialArea.class);
        util.exportExcel(response, list, "商圈数据");
    }

    /**
     * 获取商圈详细信息
     */
    @ApiOperation("获取商圈详细信息")
    @PreAuthorize("@ss.hasPermi('cms:area:query')")
    @GetMapping(value = "/{commercialAreaId}")
    public AjaxResult getInfo(@PathVariable("commercialAreaId") Long commercialAreaId)
    {
        return success(commercialAreaService.selectCommercialAreaByCommercialAreaId(commercialAreaId));
    }

    /**
     * 新增商圈
     */
    @ApiOperation("新增商圈")
    @PreAuthorize("@ss.hasPermi('cms:area:add')")
    @Log(title = "商圈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommercialArea commercialArea)
    {
        return toAjax(commercialAreaService.insertCommercialArea(commercialArea));
    }

    /**
     * 修改商圈
     */
    @ApiOperation("修改商圈")
    @PreAuthorize("@ss.hasPermi('cms:area:edit')")
    @Log(title = "商圈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommercialArea commercialArea)
    {
        return toAjax(commercialAreaService.updateCommercialArea(commercialArea));
    }

    /**
     * 删除商圈
     */
    @ApiOperation("删除商圈")
    @PreAuthorize("@ss.hasPermi('cms:area:remove')")
    @Log(title = "商圈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commercialAreaIds}")
    public AjaxResult remove(@PathVariable Long[] commercialAreaIds)
    {
        return toAjax(commercialAreaService.deleteCommercialAreaByCommercialAreaIds(commercialAreaIds));
    }
}
