package com.fs.store.controller;

import java.util.List;

import com.fs.common.core.domain.R;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsUserAddress;
import com.fs.store.service.IFsUserAddressService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 用户地址Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/userAddress")
public class FsUserAddressController extends BaseController
{
    @Autowired
    private IFsUserAddressService fsUserAddressService;

    /**
     * 查询用户地址列表
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserAddress fsUserAddress)
    {
        startPage();
        List<FsUserAddress> list = fsUserAddressService.selectFsUserAddressList(fsUserAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址列表
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:export')")
    @Log(title = "用户地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserAddress fsUserAddress)
    {
        List<FsUserAddress> list = fsUserAddressService.selectFsUserAddressList(fsUserAddress);
        ExcelUtil<FsUserAddress> util = new ExcelUtil<FsUserAddress>(FsUserAddress.class);
        return util.exportExcel(list, "userAddress");
    }

    /**
     * 获取用户地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserAddressService.selectFsUserAddressById(id));
    }

    /**
     * 新增用户地址
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:add')")
    @Log(title = "用户地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserAddress fsUserAddress)
    {
        return toAjax(fsUserAddressService.insertFsUserAddress(fsUserAddress));
    }

    /**
     * 修改用户地址
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:edit')")
    @Log(title = "用户地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserAddress fsUserAddress)
    {
        return toAjax(fsUserAddressService.updateFsUserAddress(fsUserAddress));
    }

    /**
     * 删除用户地址
     */
    @PreAuthorize("@ss.hasPermi('store:userAddress:remove')")
    @Log(title = "用户地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsUserAddressService.deleteFsUserAddressByIds(ids));
    }
    @GetMapping("/getAddressList")
    public R getAddressList(FsUserAddress fsUserAddress)
    {
        fsUserAddress.setIsDel(0);
        List<FsUserAddress> list = fsUserAddressService.selectFsUserAddressList(fsUserAddress);
        return R.ok().put("data", list);
    }
}
