package com.ruoyi.frequency.mallorderaddress.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.mallorderaddress.entity.MallOrderAddress;
import com.ruoyi.frequency.mallorderaddress.service.MallOrderAddressService;
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/mallorderaddress")
public class MallOrderAddressController extends BaseController
{
    @Autowired
    private MallOrderAddressService mallOrderAddressService;

    /**
     * 查询订单地址列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallorderaddress:list')")
    @GetMapping("/list")
    public TableDataInfo<MallOrderAddress> list(MallOrderAddress mallOrderAddress)
    {
        startPage();
        List<MallOrderAddress> list = mallOrderAddressService.selectMallOrderAddressList(mallOrderAddress);
        return getDataTable(list);
    }

    /**
     * 导出订单地址列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallorderaddress:export')")
    @Log(title = "订单地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallOrderAddress mallOrderAddress)
    {
        List<MallOrderAddress> list = mallOrderAddressService.selectMallOrderAddressList(mallOrderAddress);
        ExcelUtil<MallOrderAddress> util = new ExcelUtil<MallOrderAddress>(MallOrderAddress.class);
        return util.exportExcel(list, "订单地址数据");
    }

    /**
     * 获取订单地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallorderaddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallOrderAddress> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallOrderAddressService.selectMallOrderAddressById(id));
    }

    /**
     * 新增订单地址
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallorderaddress:add')")
    @Log(title = "订单地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallOrderAddress mallOrderAddress)
    {
        return toAjax(mallOrderAddressService.insertMallOrderAddress(mallOrderAddress));
    }

    /**
     * 修改订单地址
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallorderaddress:edit')")
    @Log(title = "订单地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallOrderAddress mallOrderAddress)
    {
        return toAjax(mallOrderAddressService.updateMallOrderAddress(mallOrderAddress));
    }

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