
package org.sky.scientific.controller;

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 lombok.SneakyThrows;
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.Charsets;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.pojo.entity.YsZbtsysyfyEntity;
import org.sky.scientific.pojo.vo.YsZbtsysyfyVO;
import org.sky.scientific.service.IYsZbtsysyfyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.URLEncoder;

/**
 * 项目预算-装备调试费用与试验费用 控制器
 *
 * @author Kd
 * @since 2025-06-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ys-zbtsysyfy")
@Tag(name = "项目预算-装备调试费用与试验费用", description = "项目预算-装备调试费用与试验费用接口")
public class YsZbtsysyfyController extends KdController {

	private final IYsZbtsysyfyService service;

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

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

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

	@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 importZbtsysyfy(MultipartFile file, Long xmId) {
		service.importZbtsysyfy(file, xmId);
		return R.success("操作成功");
	}

	@SneakyThrows
	@PostMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据")
	public void exportYsZbtsysyfy(HttpServletResponse response, @RequestBody YsZbtsysyfyVO dto) {
		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");
		response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("项目预算-装备调试费用与试验费用.xls", Charsets.UTF_8));
		service.exportYsZbtsysyfy(response.getOutputStream(), dto);
	}

}
