
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.scientific.excel.XmBgrzExcel;
import org.sky.scientific.pojo.entity.XmBgrzEntity;
import org.sky.scientific.pojo.vo.XmBgrzVO;
import org.sky.scientific.service.IXmBgrzService;
import org.springframework.web.bind.annotation.*;

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

/**
 * 项目-变更记录 控制器
 *
 * @author Kd
 * @since 2025-06-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("/xm-bgrz")
@Tag(name = "项目-变更记录", description = "项目-变更记录接口")
public class XmBgrzController extends KdController {

	private final IXmBgrzService service;

	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "分页", description  = "传入xmBgrz")
	public R<IPage<XmBgrzVO>> list(XmBgrzEntity xmBgrz, Query query) {
		IPage<XmBgrzVO> pages = service.selectBgrzPage(xmBgrz, Condition.getPage( query));
		return R.data(pages);
	}

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

	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入xmBgrz")
	public void export(@Parameter(hidden = true) @RequestParam Map<String, Object> xmBgrz, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<XmBgrzEntity> queryWrapper = Condition.getQueryWrapper(xmBgrz, XmBgrzEntity.class);
		List<XmBgrzExcel> list = service.exportXmBgrz(queryWrapper);
		ExcelUtil.export(response, "项目-变更记录数据" + DateUtil.time(), "项目-变更记录数据表", list, XmBgrzExcel.class);
	}

}
