package com.ruoyi.hezhi.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.hezhi.domain.TbMemberAddress;
import com.ruoyi.hezhi.service.ITbMemberAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户地址Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/hezhi/memberAddress")
public class TbMemberAddressController extends BaseController
{
    @Autowired
    private ITbMemberAddressService tbMemberAddressService;

    /**
     * 查询用户地址列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberAddress tbMemberAddress)
    {
        startPage();
        List<TbMemberAddress> list = tbMemberAddressService.selectTbMemberAddressList(tbMemberAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:export')")
    @Log(title = "用户地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberAddress tbMemberAddress)
    {
        List<TbMemberAddress> list = tbMemberAddressService.selectTbMemberAddressList(tbMemberAddress);
        ExcelUtil<TbMemberAddress> util = new ExcelUtil<TbMemberAddress>(TbMemberAddress.class);
        util.exportExcel(response, list, "用户地址数据");
    }

    /**
     * 获取用户地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:query')")
    @GetMapping(value = "/{memberAddressId}")
    public AjaxResult getInfo(@PathVariable("memberAddressId") Long memberAddressId)
    {
        return success(tbMemberAddressService.selectTbMemberAddressByMemberAddressId(memberAddressId));
    }

    /**
     * 新增用户地址
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:add')")
    @Log(title = "用户地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberAddress tbMemberAddress)
    {
        return toAjax(tbMemberAddressService.insertTbMemberAddress(tbMemberAddress));
    }

    /**
     * 修改用户地址
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:edit')")
    @Log(title = "用户地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberAddress tbMemberAddress)
    {
        return toAjax(tbMemberAddressService.updateTbMemberAddress(tbMemberAddress));
    }

    /**
     * 删除用户地址
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberAddress:remove')")
    @Log(title = "用户地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberAddressIds}")
    public AjaxResult remove(@PathVariable Long[] memberAddressIds)
    {
        return toAjax(tbMemberAddressService.deleteTbMemberAddressByMemberAddressIds(memberAddressIds));
    }
}
