
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.tool.api.R;
import org.sky.core.tool.utils.DateUtil;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.excel.YsZjfyycqdtfyExcel;
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.util.List;
import java.util.Map;

/**
 * 项目预算-折旧费用与长期待摊费用 控制器
 *
 * @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("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入ysZjfyycqdtfy")
	public R save(@Valid @RequestBody YsZjfyycqdtfyEntity ysZjfyycqdtfy) {
		return R.status(service.save(ysZjfyycqdtfy));
	}

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

	@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("操作成功");
	}

	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入ysZjfyycqdtfy")
	public void exportYsZjfyycqdtfy(@Parameter(hidden = true) @RequestParam Map<String, Object> ysZjfyycqdtfy, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<YsZjfyycqdtfyEntity> queryWrapper = Condition.getQueryWrapper(ysZjfyycqdtfy, YsZjfyycqdtfyEntity.class);
		List<YsZjfyycqdtfyExcel> list = service.exportYsZjfyycqdtfy(queryWrapper);
		ExcelUtil.export(response, "项目预算-折旧费用与长期待摊费用数据" + DateUtil.time(), "项目预算-折旧费用与长期待摊费用数据表", list, YsZjfyycqdtfyExcel.class);
	}

}
