package com.ruoyi.frequency.relationaddress.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.relationaddress.entity.RelationAddress;
import com.ruoyi.frequency.relationaddress.service.RelationAddressService;
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 2023-07-20
 */
@RestController
@RequestMapping("/frequency/relationaddress")
public class RelationAddressController extends BaseController
{
    @Autowired
    private RelationAddressService relationAddressService;

    /**
     * 查询地址与相关对象关联;如订单关联地址等列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(RelationAddress relationAddress)
    {
        startPage();
        List<RelationAddress> list = relationAddressService.selectRelationAddressList(relationAddress);
        return getDataTable(list);
    }

    /**
     * 导出地址与相关对象关联;如订单关联地址等列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:export')")
    @Log(title = "地址与相关对象关联;如订单关联地址等", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RelationAddress relationAddress)
    {
        List<RelationAddress> list = relationAddressService.selectRelationAddressList(relationAddress);
        ExcelUtil<RelationAddress> util = new ExcelUtil<RelationAddress>(RelationAddress.class);
        return util.exportExcel(list, "地址与相关对象关联;如订单关联地址等数据");
    }

    /**
     * 获取地址与相关对象关联;如订单关联地址等详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(relationAddressService.selectRelationAddressById(id));
    }

    /**
     * 新增地址与相关对象关联;如订单关联地址等
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:add')")
    @Log(title = "地址与相关对象关联;如订单关联地址等", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RelationAddress relationAddress)
    {
        return toAjax(relationAddressService.insertRelationAddress(relationAddress));
    }

    /**
     * 修改地址与相关对象关联;如订单关联地址等
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:edit')")
    @Log(title = "地址与相关对象关联;如订单关联地址等", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RelationAddress relationAddress)
    {
        return toAjax(relationAddressService.updateRelationAddress(relationAddress));
    }

    /**
     * 删除地址与相关对象关联;如订单关联地址等
     */
    @PreAuthorize("@ss.hasPermi('frequency:relationaddress:remove')")
    @Log(title = "地址与相关对象关联;如订单关联地址等", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(relationAddressService.deleteRelationAddressByIds(ids));
    }
}
