package com.jsowell.web.controller.pile;

import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.pile.domain.OrderAbnormalRecord;
import com.jsowell.pile.service.IOrderAbnormalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 订单异常记录Controller
 *
 * @author jsowell
 * @date 2023-02-13
 */
@RestController
@RequestMapping("/order/abnormalRecord")
public class OrderAbnormalRecordController extends BaseController {
	@Autowired
	private IOrderAbnormalRecordService orderAbnormalRecordService;

	/**
	 * 查询订单异常记录列表
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:list')")
	@GetMapping("/list")
	public TableDataInfo list(OrderAbnormalRecord orderAbnormalRecord) {
		startPage();
		List<OrderAbnormalRecord> list = orderAbnormalRecordService.selectOrderAbnormalRecordList(orderAbnormalRecord);
		return getDataTable(list);
	}

	/**
	 * 导出订单异常记录列表
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:export')")
	@Log(title = "订单异常记录", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, OrderAbnormalRecord orderAbnormalRecord) {
		List<OrderAbnormalRecord> list = orderAbnormalRecordService.selectOrderAbnormalRecordList(orderAbnormalRecord);
		ExcelUtil<OrderAbnormalRecord> util = new ExcelUtil<OrderAbnormalRecord>(OrderAbnormalRecord.class);
		util.exportExcel(response, list, "订单异常记录数据");
	}

	/**
	 * 获取订单异常记录详细信息
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Integer id) {
		return AjaxResult.success(orderAbnormalRecordService.selectOrderAbnormalRecordById(id));
	}

	/**
	 * 新增订单异常记录
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:add')")
	@Log(title = "订单异常记录", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody OrderAbnormalRecord orderAbnormalRecord) {
		return toAjax(orderAbnormalRecordService.insertOrderAbnormalRecord(orderAbnormalRecord));
	}

	/**
	 * 修改订单异常记录
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:edit')")
	@Log(title = "订单异常记录", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody OrderAbnormalRecord orderAbnormalRecord) {
		return toAjax(orderAbnormalRecordService.updateOrderAbnormalRecord(orderAbnormalRecord));
	}

	/**
	 * 删除订单异常记录
	 */
	@PreAuthorize("@ss.hasPermi('order:abnormalRecord:remove')")
	@Log(title = "订单异常记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Integer[] ids) {
		return toAjax(orderAbnormalRecordService.deleteOrderAbnormalRecordByIds(ids));
	}
}
