
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.YsSjfyExcel;
import org.sky.scientific.pojo.entity.YsSjfyEntity;
import org.sky.scientific.pojo.vo.YsSjfyVO;
import org.sky.scientific.service.IYsSjfyService;
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-sjfy")
@Tag(name = "项目预算-设计费用", description = "项目预算-设计费用接口")
public class YsSjfyController extends KdController {

	private final IYsSjfyService service;

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

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

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

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

 	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入ysSjfy")
	public void exportYsSjfy(@Parameter(hidden = true) @RequestParam Map<String, Object> ysSjfy, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<YsSjfyEntity> queryWrapper = Condition.getQueryWrapper(ysSjfy, YsSjfyEntity.class);
		List<YsSjfyExcel> list = service.exportYsSjfy(queryWrapper);
		ExcelUtil.export(response, "项目预算-设计费用数据" + DateUtil.time(), "项目预算-设计费用数据表", list, YsSjfyExcel.class);
	}

}
