
package org.sky.scientific.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.sky.core.boot.ctrl.KdController;
import org.sky.core.mp.support.Condition;
import org.sky.core.mp.support.Query;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.pojo.dto.XmGoodsDTO;
import org.sky.scientific.pojo.entity.XmGoodsEntity;
import org.sky.scientific.pojo.vo.XmGoodsVO;
import org.sky.scientific.service.IXmGoodsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 物料清单 控制器
 *
 * @author Kd
 * @since 2025-07-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/goods")
@Tag(name = "研发项目-物料管理")
public class XmGoodsController extends KdController {

	private final IXmGoodsService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "研发领料燃料动力明细清单-分页", description = "传入xmGoods")
	public R<IPage<XmGoodsVO>> page(XmGoodsDTO dto, Query query) {
		IPage<XmGoodsVO> pages = service.selectXmGoodsPage(Condition.getPage(query), dto);
		return R.data(pages);
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "研发领料燃料动力明细清单-新增或修改", description = "传入xmGoods")
	public R submit(@Valid @RequestBody XmGoodsEntity xmGoods) {
		return R.status(service.submit(xmGoods));
	}

	@PostMapping("/import")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "研发领料燃料动力明细清单-导入", description = "传入excel")
	public R importXmGoods(MultipartFile file, String yearAndMonth) {
		return R.data(service.importXmGoods(file, yearAndMonth));
	}

	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "研发领料燃料动力明细清单-批量删除", description = "传入ids")
	public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
		return R.status(service.physicalDeleteByIds(Func.toLongList(ids)));
	}

 	@PostMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "研发领料燃料动力明细清单-导出数据", description = "传入xmGoods")
	public void exportXmGoods(@RequestBody XmGoodsDTO dto, HttpServletResponse response) {
		service.exportXmGoods(response, dto);
	}

	@GetMapping("yanfalingliaodan")
	@ApiOperationSupport(order = 20)
	@Operation(summary = "材料燃料动力费用-研发领料单")
	public R<List<JSONObject>> yanfalingliaodan(XmGoodsDTO dto){
		return R.data(service.yanfalingliaodan(dto));
	}

}
