package com.op.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.common.security.annotation.RequiresPermissions;
import com.op.wms.domain.BasePowderOrder;
import com.op.wms.service.IBasePowderOrderService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.page.TableDataInfo;

/**
 * 粉料采购计划Controller
 *
 * @author Open Platform
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/powderOrder")
public class BasePowderOrderController extends BaseController {
	@Autowired
	private IBasePowderOrderService basePowderOrderService;

	/**
	 * 查询粉料采购计划列表
	 */
	@RequiresPermissions("wms:powderOrder:list")
	@GetMapping("/list")
	public TableDataInfo list(BasePowderOrder basePowderOrder) {
		startPage();
		List<BasePowderOrder> list = basePowderOrderService.selectBasePowderOrderList(basePowderOrder);
		return getDataTable(list);
	}

	/**
	 * 导出粉料采购计划列表
	 */
	@RequiresPermissions("wms:powderOrder:export")
	@Log(title = "粉料采购计划", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BasePowderOrder basePowderOrder) {
		List<BasePowderOrder> list = basePowderOrderService.selectBasePowderOrderList(basePowderOrder);
		ExcelUtil<BasePowderOrder> util = new ExcelUtil<BasePowderOrder>(BasePowderOrder.class);
		util.exportExcel(response, list, "粉料采购计划数据");
	}

	/**
	 * 获取粉料采购计划详细信息
	 */
	@RequiresPermissions("wms:powderOrder:query")
	@GetMapping(value = "/{ID}")
	public AjaxResult getInfo(@PathVariable("ID") String ID) {
		return success(basePowderOrderService.selectBasePowderOrderByID(ID));
	}

	/**
	 * 新增粉料采购计划
	 */
	@RequiresPermissions("wms:powderOrder:add")
	@Log(title = "粉料采购计划", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BasePowderOrder basePowderOrder) {
		return toAjax(basePowderOrderService.insertBasePowderOrder(basePowderOrder));
	}

	/**
	 * 修改粉料采购计划
	 */
	@RequiresPermissions("wms:powderOrder:edit")
	@Log(title = "粉料采购计划", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BasePowderOrder basePowderOrder) {
		if (!"1".equals(basePowderOrder.getOrderStatus())){
			return  AjaxResult.error("无法修改");
		}
		return toAjax(basePowderOrderService.updateBasePowderOrder(basePowderOrder));
	}

	/**
	 * 删除粉料采购计划
	 */
	@RequiresPermissions("wms:powderOrder:remove")
	@Log(title = "粉料采购计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
	public AjaxResult remove(@PathVariable String[] IDs) {

		return toAjax(basePowderOrderService.deleteBasePowderOrderByIDs(IDs));
	}

	/**
	 * 确认收货
	 */

	@PostMapping("/confirmReceipt")
	public AjaxResult confirmReceipt(@RequestBody BasePowderOrder basePowderOrder) {
		if (!"1".equals(basePowderOrder.getOrderStatus())){
			return  AjaxResult.error("无法修改");
		}
		return toAjax(basePowderOrderService.confirmReceipt(basePowderOrder));
	}

	/**
	 * 不合格退回  --同步质检结构，判断是否合格
	 */

	@PostMapping("/powderReturn")
	public AjaxResult powderReturn(@RequestBody  String[] IDs) {

		return basePowderOrderService.powderReturn(IDs);
	}
}
