
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.XmOtherCostExcel;
import org.sky.scientific.pojo.dto.XmOtherCostQuery;
import org.sky.scientific.pojo.entity.XmOtherCostEntity;
import org.sky.scientific.service.IXmOtherCostService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 项目-其他费用-基本信息台账
 *
 * @author Kd
 * @since 2025-07-28
 */
@RestController
@AllArgsConstructor
@RequestMapping("/xm/other-cost")
@Tag(name = "项目-其他费用-基本信息台账")
public class XmOtherCostController extends KdController {

	private final IXmOtherCostService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "分页")
	public R<IPage<XmOtherCostEntity>> page(XmOtherCostQuery param, Query query) {
		IPage<XmOtherCostEntity> pages = service.selectPage(Condition.getPage(query), param);
		return R.data(pages);
	}

	@PostMapping("import")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "导入")
	public R importCost(MultipartFile file, String yearAndMonth) {
		service.importData(file, yearAndMonth);
		return R.success("操作成功");
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "新增或修改")
	public R submit(@Valid @RequestBody XmOtherCostEntity 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)));
	}

 	@GetMapping("/export")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "导出数据", description  = "传入xmDesignCost")
	public void exportXmDesignCost(@Parameter(hidden = true) @RequestParam Map<String, Object> xmDesignCost, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<XmOtherCostEntity> queryWrapper = Condition.getQueryWrapper(xmDesignCost, XmOtherCostEntity.class);
		List<XmOtherCostExcel> list = service.export(queryWrapper);
		ExcelUtil.export(response, "项目-其他费用-基本信息台账" + DateUtil.time(), "项目-其他费用-基本信息台账数据表", list, XmOtherCostExcel.class);
	}
//
//	@GetMapping("/summary")
//	@ApiOperationSupport(order = 10)
//	@Operation(summary = "其他费用-汇总表")
//	public R<List<XmOtherCostExcel>> summary(XmOtherCostQuery param) {
//		List<XmOtherCostExcel> list = service.export(Condition.getQueryWrapper(param, XmOtherCostEntity.class));
//		return R.data(list);
//	}

}
