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.OrderInvoiceRecord;
import com.jsowell.pile.service.IOrderInvoiceRecordService;
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-04-10
 */
@RestController
@RequestMapping("/order/invoice")
public class OrderInvoiceRecordController extends BaseController {
	@Autowired
	private IOrderInvoiceRecordService orderInvoiceRecordService;

	/**
	 * 查询申请开票列表
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:list')")
	@GetMapping("/list")
	public TableDataInfo list(OrderInvoiceRecord orderInvoiceRecord) {
		startPage();
		List<OrderInvoiceRecord> list = orderInvoiceRecordService.selectOrderInvoiceRecordList(orderInvoiceRecord);
		return getDataTable(list);
	}

	/**
	 * 导出申请开票列表
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:export')")
	@Log(title = "申请开票", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, OrderInvoiceRecord orderInvoiceRecord) {
		List<OrderInvoiceRecord> list = orderInvoiceRecordService.selectOrderInvoiceRecordList(orderInvoiceRecord);
		ExcelUtil<OrderInvoiceRecord> util = new ExcelUtil<OrderInvoiceRecord>(OrderInvoiceRecord.class);
		util.exportExcel(response, list, "申请开票数据");
	}

	/**
	 * 获取申请开票详细信息
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Integer id) {
		return AjaxResult.success(orderInvoiceRecordService.selectInvoiceTitleVO(id));
	}

	/**
	 * 新增申请开票
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:add')")
	@Log(title = "申请开票", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody OrderInvoiceRecord orderInvoiceRecord) {
		return toAjax(orderInvoiceRecordService.insertOrderInvoiceRecord(orderInvoiceRecord));
	}

	/**
	 * 修改申请开票
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:edit')")
	@Log(title = "申请开票", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody OrderInvoiceRecord orderInvoiceRecord) {
		return toAjax(orderInvoiceRecordService.updateOrderInvoiceRecord(orderInvoiceRecord));
	}

	/**
	 * 删除申请开票
	 */
	@PreAuthorize("@ss.hasPermi('order:invoice:remove')")
	@Log(title = "申请开票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Integer[] ids) {
		return toAjax(orderInvoiceRecordService.deleteOrderInvoiceRecordByIds(ids));
	}
}
