
package org.sky.scientific.controller;

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.mp.support.Condition;
import org.sky.core.mp.support.Query;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.pojo.dto.XmCostDetailsDTO;
import org.sky.scientific.pojo.entity.DeductionCostQt;
import org.sky.scientific.pojo.entity.XmCostDetailsEntity;
import org.sky.scientific.pojo.vo.*;
import org.sky.scientific.service.IXmCostDetailsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 研发费用支出明细账 控制器
 *
 * @author Kd
 * @since 2025-07-30
 */
@RestController
@AllArgsConstructor
@RequestMapping("/xm/cost/details")
@Tag(name = "研发费用支出明细账", description = "研发费用支出明细账接口")
public class XmCostDetailsController extends KdController {

	private final IXmCostDetailsService service;

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

	@PostMapping("/import")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "导入")
	public R importXmCostDetails(MultipartFile file, String yearAndMonth) {
		return R.status(service.importXmCostDetails(file, yearAndMonth));
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "新增或修改")
	public R submit(@Valid @RequestBody XmCostDetailsEntity xmCostDetails) {
		return R.status(service.submit(xmCostDetails));
	}

	@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 exportXmCostDetails(HttpServletResponse response, XmCostDetailsDTO dto) {
		service.exportXmCostDetails(response, dto);
	}

	@GetMapping("/finance-list")
	@ApiOperationSupport(order = 20)
	@Operation(summary = "会计口径-研发费用辅助明细账")
	public R<List<FinanceCostDetailVO>> financeCostDetail(XmCostDetailsDTO dto) {
		return R.data(service.financeCostDetail(dto));
	}

	@GetMapping("/finance-summary")
	@ApiOperationSupport(order = 21)
		@Operation(summary = "会计口径-研发费用辅助账汇总表")
	public R<IPage<FinanceCostSummary>> financeCostSummary(Query query, XmCostDetailsDTO dto) {
		return R.data(service.financeCostSummary(Condition.getPage(query), dto));
	}

	@GetMapping("/high-tech-list")
	@ApiOperationSupport(order = 29)
	@Operation(summary = "高新口径-高新研发费用辅助明细账")
	public R<List<HighTechCostDetailVO>> highTechCostDetail(XmCostDetailsDTO dto) {
		return R.data(service.highTechCostDetail(dto));
	}

	@GetMapping("/high-tech-summary")
	@ApiOperationSupport(order = 30)
	@Operation(summary = "高新口径-研发费用辅助账汇总表")
	public R<IPage<HighTechCostSummary>> highTechCostSummary(Query query, XmCostDetailsDTO dto) {
		return R.data(service.highTechCostSummary(Condition.getPage(query), dto));
	}

	@GetMapping("/deduction-list")
	@ApiOperationSupport(order = 31)
	@Operation(summary = "加计扣除-研发支出辅助明细账")
	public R<List<DeductionCostDetailVO>> deductionCostDetail(XmCostDetailsDTO dto) {
		return R.data(service.deductionCostDetail(dto));
	}

	@GetMapping("/deduction-summary")
	@ApiOperationSupport(order = 32)
	@Operation(summary = "加计扣除-研发支出辅助汇总表")
	public R<DeductionCostSummary>deductionCostSummary(XmCostDetailsDTO dto) {
		return R.data(service.deductionCostSummary(dto));
	}

	@PostMapping("/deduction-qt")
	@ApiOperationSupport(order = 33)
	@Operation(summary = "加计扣除-研发支出辅助汇总表-其中：其他事项-提交")
	public R<Boolean> updateDeductionQt(@RequestBody DeductionCostQt dto) {
		return R.status(service.updateDeductionQt(dto));
	}
}
