
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.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.scientific.pojo.dto.SalaryDTO;
import org.sky.scientific.pojo.entity.SalaryEntity;
import org.sky.scientific.pojo.vo.SalaryVO;
import org.sky.scientific.service.ISalaryService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 技术人员工资表 控制器
 *
 * @author Kd
 * @since 2025-06-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/salary")
@Tag(name = "每月工资信息")
public class SalaryController extends KdController {

	private final ISalaryService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "分页")
	public R<IPage<SalaryVO>> selectSalaryMonthlyPage(SalaryDTO salary, Query query) {
		IPage<SalaryVO> pages = service.selectSalaryPage(Condition.getPage(query), salary);
		return R.data(pages);
	}

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

	@GetMapping("/fetchTechnicianByYearAndMonth")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "引用当月研发人员名单", description = "传入选中的年，比如2025")
	public R<Boolean> fetchTechnicianByYearAndMonth(String yearAndMonth) {
		return R.status(service.fetchTechnicianByYearAndMonth(yearAndMonth));
	}

	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "每月工资信息-修改", description  = "传入salary, 其中technicianId、yearAndMonth必传")
	public R update(@Valid @RequestBody SalaryEntity salary) {
		return R.status(service.updateSalary(salary));
	}

	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "每月工资信息-清除工资数据", description  = "多个 technicianId、yearAndMonth")
	public R remove(@RequestBody List<SalaryEntity> salaryList) {
		return R.status(service.clearSalary(salaryList));
	}

 	@PostMapping("/export-salary")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "每月工资信息-导出", description  = "传入salary")
	public void exportSalary(HttpServletResponse response, @RequestBody SalaryDTO dto) {
		service.exportSalary(response, dto);
	}

}
