
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.YsZjfyycqdtfyEntity;
import org.sky.scientific.pojo.vo.YsZjfyycqdtfyVO;
import org.sky.scientific.service.IYsZjfyycqdtfyService;
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-zjfyycqdtfy")
@Tag(name = "项目预算-折旧费用与长期待摊费用", description = "项目预算-折旧费用与长期待摊费用接口")
public class YsZjfyycqdtfyController extends KdController {

	private final IYsZjfyycqdtfyService service;

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

	@PostMapping("/submit")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增/修改")
	public R save(@Valid @RequestBody YsZjfyycqdtfyEntity entity) {
		return R.status(service.submit(entity));
	}

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

	@SneakyThrows
	@PostMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出")
	public void exportYsZjfyycqdtfy(HttpServletResponse response, @RequestBody YsZjfyycqdtfyVO dto) {
		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");
		response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("项目预算-折旧费用与长期待摊费用.xls", Charsets.UTF_8));
		service.exportYsZjfyycqdtfy(response.getOutputStream(), dto);
	}

}
