
package org.sky.scientific.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.excel.util.ExcelUtil;
import org.sky.core.mp.support.Condition;
import org.sky.core.mp.support.Query;
import org.sky.core.secure.KdUser;
import org.sky.core.secure.annotation.IsAdmin;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.DateUtil;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.excel.YsWtwbyjkffyExcel;
import org.sky.scientific.pojo.entity.YsWtwbyjkffyEntity;
import org.sky.scientific.pojo.vo.YsWtwbyjkffyVO;
import org.sky.scientific.service.IYsWtwbyjkffyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 项目预算-委托外部研究开发费 控制器
 *
 * @author Kd
 * @since 2025-06-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ys-wtwbyjkffy")
@Tag(name = "项目预算-委托外部研究开发费", description = "项目预算-委托外部研究开发费接口")
public class YsWtwbyjkffyController extends KdController {

	private final IYsWtwbyjkffyService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "分页", description  = "传入ysWtwbyjkffy")
	public R<IPage<YsWtwbyjkffyVO>> page(YsWtwbyjkffyVO ysWtwbyjkffy, Query query) {
		IPage<YsWtwbyjkffyVO> pages = service.selectYsWtwbyjkffyPage(Condition.getPage(query), ysWtwbyjkffy);
		return R.data(pages);
	}

	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入ysWtwbyjkffy")
	public R save(@Valid @RequestBody YsWtwbyjkffyEntity ysWtwbyjkffy) {
		return R.status(service.save(ysWtwbyjkffy));
	}

	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改", description  = "传入ysWtwbyjkffy")
	public R update(@Valid @RequestBody YsWtwbyjkffyEntity ysWtwbyjkffy) {
		return R.status(service.updateWtwbyjkffy(ysWtwbyjkffy));
	}

	@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("import")
	@ApiOperationSupport(order = 8)
	@Operation(summary = "导入", description = "传入excel")
	public R importWtwbyjkffy(MultipartFile file, Long xmId) {
 		service.importWtwbyjkffy(file, xmId);
		return R.success("操作成功");
	}

 	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入ysWtwbyjkffy")
	public void exportYsWtwbyjkffy(@Parameter(hidden = true) @RequestParam Map<String, Object> ysWtwbyjkffy, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<YsWtwbyjkffyEntity> queryWrapper = Condition.getQueryWrapper(ysWtwbyjkffy, YsWtwbyjkffyEntity.class);
		List<YsWtwbyjkffyExcel> list = service.exportYsWtwbyjkffy(queryWrapper);
		ExcelUtil.export(response, "项目预算-委托外部研究开发费数据" + DateUtil.time(), "项目预算-委托外部研究开发费数据表", list, YsWtwbyjkffyExcel.class);
	}

}
