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.annotation.Resource;
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.AttendanceDto;
import org.sky.scientific.pojo.vo.AttendanceVO;
import org.sky.scientific.service.IAttendanceService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/attendance")
@Tag(name = "考勤管理")
public class AttendanceController extends KdController {

	@Resource
	private IAttendanceService service;

	@GetMapping("page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "每月考勤信息-分页查询")
	public R<IPage<AttendanceVO>> page(AttendanceDto attendance, Query query) {
		return R.data(service.selectAttendancePage(attendance, Condition.getPage(query)));
	}

	@PostMapping("/submit/batch")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "每月考勤信息-批量新增或修改")
	public R submit(@Valid @RequestBody AttendanceDto attendance) {
		return R.status(service.batchSubmit(attendance));
	}

	@PostMapping("/import")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "每月考勤信息-导入", description = "传入excel")
	public R importAttendance(MultipartFile file,String yearAndMonth) {
		service.importAttendance(file, yearAndMonth);
		return R.success("操作成功");
	}

	@PostMapping("export")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "每月考勤信息-导出")
	public void exportAttendance(@RequestBody AttendanceDto dto, HttpServletResponse response) {
		service.exportAttendance(response, dto);
	}

	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "每月考勤信息-清除考勤数据", description  = "多个 unicode、yearAndMonth")
	public R remove(@RequestBody List<AttendanceDto> attendanceList) {
		return R.status(service.clearAttendance(attendanceList));
	}

}
