package com.jsowell.web.controller.pile;

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

import com.jsowell.pile.dto.MakeOrderFreeDTO;
import com.jsowell.pile.service.OrderPileOccupyService;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.pile.domain.OrderPileOccupy;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.common.core.page.TableDataInfo;

/**
 * 占桩订单Controller
 *
 * @author jsowell
 * @date 2023-09-08
 */
@RestController
@RequestMapping("/pile/occupy")
public class OrderPileOccupyController extends BaseController {
    @Autowired
    private OrderPileOccupyService orderPileOccupyService;

    /**
     * 查询占桩订单列表
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderPileOccupy orderPileOccupy) {
        startPage();
        List<OrderPileOccupy> list = orderPileOccupyService.selectOrderPileOccupyList(orderPileOccupy);
        return getDataTable(list);
    }

    /**
     * 导出占桩订单列表
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:export')")
    @Log(title = "占桩订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderPileOccupy orderPileOccupy) {
        List<OrderPileOccupy> list = orderPileOccupyService.selectOrderPileOccupyList(orderPileOccupy);
        ExcelUtil<OrderPileOccupy> util = new ExcelUtil<OrderPileOccupy>(OrderPileOccupy.class);
        util.exportExcel(response, list, "占桩订单数据");
    }

    /**
     * 获取占桩订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderPileOccupyService.selectByPrimaryKey(id.intValue()));
    }

    /**
     * 新增占桩订单
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:add')")
    @Log(title = "占桩订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPileOccupy orderPileOccupy) {
        return toAjax(orderPileOccupyService.insert(orderPileOccupy));
    }

    /**
     * 修改占桩订单
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:edit')")
    @Log(title = "占桩订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPileOccupy orderPileOccupy) {
        return toAjax(orderPileOccupyService.updateByPrimaryKey(orderPileOccupy));
    }

    /**
     * 使某笔订单免费/修改订单金额
     * http://localhost:8080/pile/occupy/updateOrderAmount
     * @param dto
     * @return
     */
    @PreAuthorize("@ss.hasPermi('pile:occupy:edit')")
    @PostMapping("/updateOrderAmount")
    public AjaxResult updateOrderAmount(@RequestBody MakeOrderFreeDTO dto) {
        return toAjax(orderPileOccupyService.updateOrderInfoForWeb(dto));
    }

    /**
     * 删除占桩订单
     */
    // @PreAuthorize("@ss.hasPermi('pile:occupy:remove')")
    // @Log(title = "占桩订单", businessType = BusinessType.DELETE)
    // @DeleteMapping("/{ids}")
    // public AjaxResult remove(@PathVariable Long[] ids)
    // {
    //     return toAjax(orderPileOccupyService.deleteByPrimaryKey(ids));
    // }
}
