package com.yiqi.admin.controller.order;

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

import com.yiqi.common.constant.UrlConstants;
import com.yiqi.order.domain.OrderDelivery;
import com.yiqi.order.domain.dto.OrderDeliveryRequestDTO;
import com.yiqi.order.domain.vo.OrderDeliveryVO;
import com.yiqi.order.service.IOrderDeliveryService;
import com.yiqi.system.domain.SysStore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 订单配送Controller
 *
 * @author ruoyi
 * @date 2024-09-07
 */
@Api(tags = "管理后台 - 订单配送")
@RestController
@RequestMapping(UrlConstants.managerApi + "/order/delivery")
public class OrderDeliveryController extends BaseController {
    @Autowired
    private IOrderDeliveryService orderDeliveryService;

    /**
     * 查询订单配送列表
     */
    @PreAuthorize("@ss.hasPermi('order:delivery:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询订单配送列表")
    public TableDataInfo list(OrderDeliveryRequestDTO requestDTO) {
        startPage();
        List<OrderDeliveryVO> list = orderDeliveryService.selectOrderDeliveryList(requestDTO);
        return getDataTable(list);
    }

    /**
     * 导出订单配送列表
     */
    @PreAuthorize("@ss.hasPermi('order:delivery:export')")
    @Log(title = "订单配送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出订单配送列表")
    public void export(HttpServletResponse response, OrderDeliveryRequestDTO requestDTO) {
        List<OrderDeliveryVO> list = orderDeliveryService.selectOrderDeliveryList(requestDTO);
        ExcelUtil<OrderDeliveryVO> util = new ExcelUtil<OrderDeliveryVO>(OrderDeliveryVO.class);
        util.exportExcel(response, list, "订单配送数据");
    }

    /**
     * 获取订单配送详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取订单配送详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        OrderDelivery orderDelivery = orderDeliveryService.getById(id);
        return success(orderDelivery);
    }

    /**
     * 新增订单配送
     */
    @PreAuthorize("@ss.hasPermi('order:delivery:add')")
    @Log(title = "订单配送", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增订单配送")
    public AjaxResult add(@RequestBody OrderDelivery orderDelivery) {
        orderDelivery.setCreateById(getUserId());
        orderDelivery.setCreateBy(getUsername());
        return toAjax(orderDeliveryService.save(orderDelivery));
    }

    /**
     * 修改订单配送
     */
    @PreAuthorize("@ss.hasPermi('order:delivery:edit')")
    @Log(title = "订单配送", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改订单配送")
    public AjaxResult edit(@RequestBody OrderDelivery orderDelivery) {
        orderDelivery.setUpdateById(getUserId());
        orderDelivery.setUpdateBy(getUsername());
        return toAjax(orderDeliveryService.updateById(orderDelivery));
    }

    /**
     * 删除订单配送
     */
    @PreAuthorize("@ss.hasPermi('order:delivery:remove')")
    @Log(title = "订单配送", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除订单配送")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(orderDeliveryService.removeBatchByIds(Arrays.asList(ids)));
    }

}
