package com.younike.server.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.younike.common.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.OrderAddress;
import com.younike.system.service.IOrderAddressService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 订单服务地址Controller
 * 
 * @author elev
 * @date 2022-01-07
 */
@Api("订单服务地址接口")
@RestController
@RequestMapping("/system/address")
public class ServerOrderAddressController extends BaseController {
    @Autowired
    private IOrderAddressService orderAddressService;

    /**
     * 查询订单服务地址列表
     */
    @ApiOperation("查询订单服务地址列表")
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAddress orderAddress) {
        startPage();
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        return getDataTable(list);
    }

    /**
     * 导出订单服务地址列表
     */
    @ApiOperation("导出订单服务地址列表")
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "订单服务地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderAddress orderAddress) {
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        ExcelUtil<OrderAddress> util = new ExcelUtil<OrderAddress>(OrderAddress.class);
        return util.exportExcel(list, "订单服务地址数据");
    }

    /**
     * 获取订单服务地址详细信息
     */
    @ApiOperation("获取订单服务地址详细信息")
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(orderAddressService.selectOrderAddressByOrderId(orderId));
    }

    /**
     * 新增订单服务地址
     */
    @ApiOperation("新增订单服务地址")
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "订单服务地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderAddress orderAddress) {
        return toAjax(orderAddressService.insertOrderAddress(orderAddress));
    }

    /**
     * 修改订单服务地址
     */
    @ApiOperation("修改订单服务地址")
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "订单服务地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderAddress orderAddress) {
        return toAjax(orderAddressService.updateOrderAddress(orderAddress));
    }

    /**
     * 删除订单服务地址
     */
    @ApiOperation("删除订单服务地址")
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "订单服务地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(orderAddressService.deleteOrderAddressByOrderIds(orderIds));
    }
}
