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.secure.annotation.IsAdmin;
import org.sky.core.tenant.annotation.NonDS;
import org.sky.core.tool.api.R;
import org.sky.core.tool.utils.Func;
import org.sky.scientific.pojo.entity.Subject;
import org.sky.scientific.pojo.entity.SubjectEnterprise;
import org.sky.scientific.pojo.vo.SubjectVO;
import org.sky.scientific.service.ISubjectService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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


/**
 * 控制器
 *
 */
@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("/subject")
@Tag(name = "会计科目设置")
public class SubjectController extends KdController {

	private final ISubjectService service;

	@GetMapping("/lazy-list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "研发费用会计科目设置-懒加载列表")
	public R<List<SubjectVO>> lazyList(Long parentId, @Parameter(hidden = true) @RequestParam Map<String, Object> subject){
		List<SubjectVO> list = service.lazyList(parentId, subject);
		return R.data(list);
	}

	@PostMapping("submit")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "研发费用会计科目设置-新增或修改")
	public R submit(@Valid @RequestBody Subject subject) {
		return R.status(service.submitSubject(subject));
	}

	@DeleteMapping("/remove/{subjectId}")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "研发费用会计科目设置-删除", description = "传入ids")
	public R removeSubject(@PathVariable(value = "subjectId") Long subjectId) {
		return R.status(service.deleteSubject(subjectId));
	}

	@GetMapping("/enterprise/page")
	@ApiOperationSupport(order = 15)
	@Operation(summary = "企业会计科目设置-分页", description = "传入xmGoods")
	public R<IPage<SubjectEnterprise>> selectSubjectEnterprisePage(SubjectEnterprise dto, Query query) {
		IPage<SubjectEnterprise> pages = service.selectSubjectEnterpriseList(Condition.getPage(query), dto);
		return R.data(pages);
	}

	@PostMapping("/enterprise/submit")
	@ApiOperationSupport(order = 17)
	@Operation(summary = "企业会计科目设置-新增或修改", description = "传入xmGoods")
	public R submitSubjectEnterprise(@Valid @RequestBody SubjectEnterprise subjectEnterprise) {
		return R.status(service.submitSubjectEnterprise(subjectEnterprise));
	}

	@PostMapping("/enterprise/import")
	@ApiOperationSupport(order = 19)
	@Operation(summary = "企业会计科目设置-导入", description = "传入excel")
	public R importSubjectEnterprise(MultipartFile file) {
		return R.data(service.importSubjectEnterprise(file));
	}

	@PostMapping("/enterprise/remove")
	@ApiOperationSupport(order = 22)
	@Operation(summary = "企业会计科目设置-批量删除", description = "传入ids")
	public R removeSubjectEnterprise(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
		return R.status(service.deleteBatchSubjectEnterprise(Func.toLongList(ids)));
	}

 	@GetMapping("/enterprise/export")
	@ApiOperationSupport(order = 25)
	@Operation(summary = "企业会计科目设置-导出数据", description = "传入xmGoods")
	public void exportSubjectEnterprise(SubjectEnterprise dto, HttpServletResponse response) {
		service.exportSubjectEnterprise(response, dto);
	}
}
