
package org.sky.scientific.controller;

import com.alibaba.fastjson.JSONObject;
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 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.TechnicianDTO;
import org.sky.scientific.pojo.vo.TechnicianHoursMonthlyVO;
import org.sky.scientific.pojo.vo.XmTechnicianHoursVO;
import org.sky.scientific.service.IXmTechnicianHoursService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 研发人员研发工时记录表 控制器
 *
 * @author Kd
 * @since 2025-06-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("xm/technician/hours")
@Tag(name = "研发人员研发工时记录表")
public class XmTechnicianHoursController extends KdController {

 	private final IXmTechnicianHoursService service;

	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "分页")
	public R<IPage<XmTechnicianHoursVO>> selectPage(XmTechnicianHoursVO dto, Query query) {
		return R.data(service.selectPage(dto, Condition.getPage(query)));
	}

	@PostMapping("/import")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "导入", description = "传入excel")
	public R importHours(MultipartFile file,String yearAndMonth) {
		service.importXmTechnicianHours(file, yearAndMonth);
		return R.success("操作成功");
	}

	@PostMapping("/submit/batch")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "新增/修改")
	public R submit(@RequestBody XmTechnicianHoursVO dto) {
		return R.status(service.batchSubmit(dto));
	}

	@PostMapping("/clear/batch")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "清除工时", description = "{\"yearAndMonth\":\"202507\",\"xmAndUnicodeList\":[{\"xmId\":\"1943241918440747010\",\"unicode\":\"ccd86a42-2369-4517-832e-004307e5237e\"}]}")
	public R clear(@RequestBody JSONObject dto) {
		return R.status(service.clear(dto));
	}

	@PostMapping("/export")
	@ApiOperationSupport(order = 12)
	@Operation(summary = "导出")
	public void export(HttpServletResponse response, @RequestBody XmTechnicianHoursVO param) {
		service.export(response, param);
	}

	@GetMapping("/list/print")
	@ApiOperationSupport(order = 15)
	@Operation(summary = "自动生成-打印")
	public R<List<JSONObject>> selectListForPrint(XmTechnicianHoursVO dto) {
		return R.data(service.selectListForPrint(dto));
	}

	@GetMapping("/myyfgsfpb")
	@ApiOperationSupport(order = 20)
	@Operation(summary = "每月研发工时分配表")
	public R<IPage<TechnicianHoursMonthlyVO>> meiyueyanfagongshifenpeibiao(TechnicianDTO dto, Query query){
		return R.data(service.meiyueyanfagongshifenpeibiao(Condition.getPage(query), dto));
	}

}
