
package org.sky.scientific.controller;

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.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.sky.core.boot.ctrl.KdController;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.pojo.entity.YfzdEntity;
import org.sky.scientific.service.IYfzdService;
import org.springframework.web.bind.annotation.*;

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

/**
 * 研发制度 控制器
 *
 * @author Kd
 * @since 2025-06-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/yfzd")
@Tag(name = "研发制度", description = "研发制度接口")
public class YfzdController extends KdController {

	private final IYfzdService service;

	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "获取指定年度的制度文件", description = "传入yfzd")
	public R<Map<String, List<YfzdEntity>>> selectYfzd(YfzdEntity yfzd) {
		Map<String, List<YfzdEntity>> map = service.selectYfzd(yfzd);
		return R.data(map);
	}

	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增或修改", description = "传入yfzd")
	public R saveOrUpdate(@Valid @RequestBody YfzdEntity yfzd) {
		return R.status(service.editYfzd(yfzd));
	}

	@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)));
	}

	@GetMapping("/download")
	@ApiOperationSupport(order = 10)
	@Operation(summary = "一键下载")
	public void downloadZipFiles(HttpServletRequest request, HttpServletResponse response, String year){
		service.downloadZipFiles(request,response, year);
	}

}
