package com.ruoyi.mall.controller;

import java.util.List;
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 com.ruoyi.mall.domain.MallAppAddress;
import com.ruoyi.mall.service.IMallAppAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * app地址管理Controller
 *
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/mall/mallAppAddress")
public class MallAppAddressController extends BaseController
{
    @Resource
    private IMallAppAddressService mallAppAddressService;

    /**
     * 查询app地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAppAddress mallAppAddress)
    {
        startPage();
        mallAppAddress.setDelFlag("0");
        List<MallAppAddress> list = mallAppAddressService.selectMallAppAddressList(mallAppAddress);
        return getDataTable(list);
    }

    /**
     * 导出app地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:export')")
    @Log(title = "app地址管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallAppAddress mallAppAddress)
    {
        List<MallAppAddress> list = mallAppAddressService.selectMallAppAddressList(mallAppAddress);
        ExcelUtil<MallAppAddress> util = new ExcelUtil<MallAppAddress>(MallAppAddress.class);
        return util.exportExcel(list, "app地址管理数据");
    }

    /**
     * 获取app地址管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:query')")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        return AjaxResult.success(mallAppAddressService.selectMallAppAddressByAddressId(addressId));
    }

    /**
     * 新增app地址管理
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:add')")
    @Log(title = "app地址管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAppAddress mallAppAddress)
    {
        return toAjax(mallAppAddressService.insertMallAppAddress(mallAppAddress));
    }

    /**
     * 修改app地址管理
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:edit')")
    @Log(title = "app地址管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAppAddress mallAppAddress)
    {
        return toAjax(mallAppAddressService.updateMallAppAddress(mallAppAddress));
    }

    /**
     * 删除app地址管理
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppAddress:remove')")
    @Log(title = "app地址管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds)
    {
        return toAjax(mallAppAddressService.deleteMallAppAddressByAddressIds(addressIds));
    }
}
