/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.yifu.cloud.plus.v1.yifu.archives.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TPreEmpMain;
import com.yifu.cloud.plus.v1.yifu.archives.service.TPreEmpMainService;
import com.yifu.cloud.plus.v1.yifu.archives.vo.PreEmpMainDetailVo;
import com.yifu.cloud.plus.v1.yifu.archives.vo.TPreEmpMainSearchVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.MenuUtil;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 预入职-主表
 *
 * @author hgw
 * @date 2024-06-17 11:31:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tpreempmain")
@Tag(name = "预入职-主表管理")
public class TPreEmpMainController {

	private final TPreEmpMainService tPreEmpMainService;

	private final MenuUtil menuUtil;

	/**
	 * 简单分页查询
	 *
	 * @param page        分页对象
	 * @param tPreEmpMain 预入职-主表
	 * @return
	 */
	@Operation(description = "简单分页查询")
	@GetMapping("/page")
	public R<IPage<TPreEmpMain>> getTPreEmpMainPage(Page<TPreEmpMain> page, TPreEmpMainSearchVo tPreEmpMain) {
		YifuUser user = SecurityUtils.getUser();
		menuUtil.setAuthSql(user, tPreEmpMain);
		return new R<>(tPreEmpMainService.getTPreEmpMainPage(page, tPreEmpMain));
	}

	/**
	 * 不分页查询
	 *
	 * @param tPreEmpMain 预入职-主表
	 * @return
	 */
	@Operation(summary = "不分页查询", description = "不分页查询")
	@PostMapping("/noPage")
	//@PreAuthorize("@pms.hasPermission('archives_tpreempmain_get')" )
	public R<List<TPreEmpMain>> getTPreEmpMainNoPage(@RequestBody TPreEmpMainSearchVo tPreEmpMain) {
		return R.ok(tPreEmpMainService.noPageDiy(tPreEmpMain));
	}

	/**
	 * 通过id查询预入职-主表
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询：hasPermission('archives_tpreempmain_get')")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain_get')")
	public R<PreEmpMainDetailVo> getById(@PathVariable("id") String id) {
		return tPreEmpMainService.getInfoById(id);
	}

	/**
	 * 草稿预入职
	 * hgw
	 * 2024-6-17 17:39:15
	 */
	@Operation(summary = "草稿预入职", description = "草稿预入职：hasPermission('archives_tpreempmain_draft')")
	@SysLog("草稿预入职")
	@PostMapping("/saveDraftPreEmpMain")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain_draft')")
	public R<String> saveDraftPreEmpMain(@RequestBody PreEmpMainDetailVo vo) {
		return tPreEmpMainService.saveDraftPreEmpMain(vo);
	}
	/**
	 * 保存预入职
	 * hgw
	 * 2024-6-17 17:39:15
	 */
	@Operation(summary = "保存预入职", description = "保存预入职：hasPermission('archives_tpreempmain_add')")
	@SysLog("保存预入职")
	@PostMapping("/savePreEmpMain")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain_add')")
	public R<String> savePreEmpMain(@RequestBody PreEmpMainDetailVo vo) {
		return tPreEmpMainService.savePreEmpMain(vo);
	}

	/**
	 * 修改预入职-主表
	 *
	 * @param tPreEmpMain 预入职-主表
	 * @return R
	 */
	@Operation(summary = "修改预入职-主表", description = "修改预入职-主表：hasPermission('archives_tpreempmain_edit')")
	@SysLog("修改预入职-主表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain_edit')")
	public R<Boolean> updateById(@RequestBody TPreEmpMain tPreEmpMain) {
		return R.ok(tPreEmpMainService.updateById(tPreEmpMain));
	}

	/**
	 * 通过id删除预入职-主表
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除预入职-主表", description = "通过id删除预入职-主表：hasPermission('archives_tpreempmain_del')")
	@SysLog("通过id删除预入职-主表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain_del')")
	public R<Boolean> removeById(@PathVariable String id) {
		return R.ok(tPreEmpMainService.removeById(id));
	}

	/**
	 * 预入职-主表 批量导入
	 *
	 * @author hgw
	 * @date 2024-06-17 11:31:08
	 **/
	@SneakyThrows
	@Operation(description = "批量新增预入职-主表 hasPermission('archives_tpreempmain-batch-import')")
	@SysLog("批量新增预入职-主表")
	@PostMapping("/importListAdd")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain-batch-import')")
	public R<List<ErrorMessage>> importListAdd(@RequestBody MultipartFile file) {
		return tPreEmpMainService.importDiy(file.getInputStream());
	}

	/**
	 * 预入职-主表 批量导出
	 *
	 * @author hgw
	 * @date 2024-06-17 11:31:08
	 **/
	@Operation(description = "导出预入职-主表 hasPermission('archives_tpreempmain-export')")
	@PostMapping("/export")
	@PreAuthorize("@pms.hasPermission('archives_tpreempmain-export')")
	public void export(HttpServletResponse response, @RequestBody TPreEmpMainSearchVo searchVo) {
		tPreEmpMainService.listExport(response, searchVo);
	}
}
