
package org.sky.scientific.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.excel.util.ExcelUtil;
import org.sky.core.mp.support.Condition;
import org.sky.core.secure.KdUser;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.DateUtil;
import org.sky.scientific.excel.XmJtbExcel;
import org.sky.scientific.pojo.dto.XmJtbDTO;
import org.sky.scientific.pojo.entity.XmJtbEntity;
import org.sky.scientific.pojo.vo.XmJtbVO;
import org.sky.scientific.service.IXmJtbService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 科研项目-项目结题表 控制器
 *
 * @author Kd
 * @since 2025-07-01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/xm/jtb")
@Tag(name = "科研项目-项目结题表", description = "科研项目-项目结题表接口")
public class XmJtbController extends KdController {

	private final IXmJtbService service;

	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description  = "传入xmJtb")
	public R<XmJtbVO> detail(XmJtbDTO xmJtb) {
		XmJtbVO detail = service.selectByCondition(xmJtb);
		return R.data(detail);
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "新增或修改", description  = "传入xmJtb")
	public R submit(@Valid @RequestBody XmJtbEntity xmJtb) {
		return R.status(service.submit(xmJtb));
	}

	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入xmJtb")
	public void exportXmJtb(@Parameter(hidden = true) @RequestParam Map<String, Object> xmJtb, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<XmJtbEntity> queryWrapper = Condition.getQueryWrapper(xmJtb, XmJtbEntity.class);
		List<XmJtbExcel> list = service.exportXmJtb(queryWrapper);
		ExcelUtil.export(response, "科研项目-项目结题表数据" + DateUtil.time(), "科研项目-项目结题表数据表", list, XmJtbExcel.class);
	}

}
