
package org.sky.scientific.controller;

import com.alibaba.fastjson.JSONObject;
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.secure.annotation.IsAdmin;
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.XmDirectCostExcel;
import org.sky.scientific.pojo.entity.XmDirectCostEntity;
import org.sky.scientific.service.IXmDirectCostService;
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-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/direct-cost")
@Tag(name = "研发项目-直接投入费用")
public class XmDirectCostController extends KdController {

	private final IXmDirectCostService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "直接投入费用-基本信息台账-分页")
	public R<IPage<XmDirectCostEntity>> page(XmDirectCostEntity dto, Query query) {
		IPage<XmDirectCostEntity> pages = service.selectXmDirectCostPage(Condition.getPage(query), dto);
		return R.data(pages);
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "直接投入费用-基本信息台账-新增或修改")
	public R submit(@Valid @RequestBody XmDirectCostEntity entity) {
		return R.status(service.submit(entity));
	}

	@PostMapping("/import")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "直接投入费用-基本信息台账-导入")
	public R importXmLease(MultipartFile file, String yearAndMonth) {
		return R.data(service.importXmDirectCost(file, yearAndMonth));
	}

	@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 = "直接投入费用-基本信息台账-导出数据")
	public void export(@Parameter(hidden = true) @RequestParam Map<String, Object> map, KdUser kdUser, HttpServletResponse response) {
		QueryWrapper<XmDirectCostEntity> queryWrapper = Condition.getQueryWrapper(map, XmDirectCostEntity.class);
		List<XmDirectCostExcel> list = service.exportXmDirectCost(queryWrapper);
		ExcelUtil.export(response, "直接投入费用-基本信息台账" + DateUtil.time(), "直接投入费用-基本信息台账", list, XmDirectCostExcel.class);
	}

	@GetMapping("summary")
	@ApiOperationSupport(order = 20)
	@Operation(summary = "直接投入费用汇总表p081")
	public R<List<JSONObject>> tourufeiyonghuizongbiao(XmDirectCostEntity dto){
		return R.data(service.tourufeiyonghuizongbiao(dto));
	}
}
