package com.ruoyi.frequency.malladdress.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.malladdress.entity.MallAddress;
import com.ruoyi.frequency.malladdress.service.MallAddressService;
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 2024-01-25
 */
@RestController
@RequestMapping("/frequency/malladdress")
public class MallAddressController extends BaseController
{
    @Autowired
    private MallAddressService mallAddressService;

    /**
     * 查询地址列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:list')")
    @GetMapping("/list")
    public TableDataInfo<MallAddress> list(MallAddress mallAddress)
    {
        startPage();
        List<MallAddress> list = mallAddressService.selectMallAddressList(mallAddress);
        return getDataTable(list);
    }

    /**
     * 导出地址列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:export')")
    @Log(title = "地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallAddress mallAddress)
    {
        List<MallAddress> list = mallAddressService.selectMallAddressList(mallAddress);
        ExcelUtil<MallAddress> util = new ExcelUtil<MallAddress>(MallAddress.class);
        return util.exportExcel(list, "地址数据");
    }

    /**
     * 获取地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallAddress> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallAddressService.selectMallAddressById(id));
    }

    /**
     * 新增地址
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:add')")
    @Log(title = "地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAddress mallAddress)
    {
        return toAjax(mallAddressService.insertMallAddress(mallAddress));
    }

    /**
     * 修改地址
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:edit')")
    @Log(title = "地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAddress mallAddress)
    {
        return toAjax(mallAddressService.updateMallAddress(mallAddress));
    }

    /**
     * 删除地址
     */
    @PreAuthorize("@ss.hasPermi('frequency:malladdress:remove')")
    @Log(title = "地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(mallAddressService.deleteMallAddressByIds(ids,delFlag));
    }
}
