/*
 *    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.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.vo.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeProject;
import com.yifu.cloud.plus.v1.yifu.archives.service.TEmployeeProjectService;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeProjectExportVO;
import com.yifu.cloud.plus.v1.yifu.archives.vo.EmployeeProjectVO;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 项目档案表
 *
 * @author huyc
 * @date 2022-06-20 09:19:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/temployeeproject" )
@Tag(name = "项目档案表管理")
public class TEmployeeProjectController {

    private final TEmployeeProjectService tEmployeeProjectService;

	/**
	 * @param empId 人员档案id
	 * @Description: 根据人员档案id获取项目list
	 * @Author: hgw
	 * @Date: 2022/6/21 19:19
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.archives.entity.TEmployeeProject>>
	 **/
	@Operation(summary = "根据人员档案id获取项目list", description = "根据人员档案id获取项目list")
	@GetMapping("/getListByEmpId" )
	public R<List<TEmployeeProject>> getListByEmpId(@RequestParam String empId) {
		return R.ok(tEmployeeProjectService.getListByEmpId(empId, CommonConstants.ZERO_INT));
	}

    /**
     * 分页查询
     * @param page 分页对象
     * @param tEmployeeProject 项目档案表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    public R<IPage<TEmployeeProject>> getTEmployeeProjectPage(Page page, TEmployeeProject tEmployeeProject) {
        return R.ok(tEmployeeProjectService.getTEmployeeProjectInfoPage(page,tEmployeeProject));
    }


    /**
     * 通过id查询项目档案表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('archives_temployeeproject_get')" )
    public R getById(@PathVariable("id" ) String id) {
        return R.ok(tEmployeeProjectService.getById(id));
    }

    /**
     * 新增项目档案表
     * @param tEmployeeProject 项目档案表
     * @return R
     */
    @Operation(summary = "新增项目档案表", description = "新增项目档案表")
    @SysLog("新增项目档案表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('archives_temployeeproject_add')" )
    public R save(@Valid @RequestBody TEmployeeProject tEmployeeProject) {
        return R.ok(tEmployeeProjectService.save(tEmployeeProject));
    }

    /**
     * 修改项目档案表
     * @param tEmployeeProject 项目档案表
     * @return R
     */
    @Operation(summary = "修改项目档案表", description = "修改项目档案表")
    @SysLog("修改项目档案表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('archives_temployeeproject_edit')" )
    public R updateById(@RequestBody TEmployeeProject tEmployeeProject) {
        return R.ok(tEmployeeProjectService.updateById(tEmployeeProject));
    }

    /**
     * 通过id删除项目档案表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除项目档案表", description = "通过id删除项目档案表")
    @SysLog("通过id删除项目档案表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('archives_temployeeproject_del')" )
    public R removeById(@PathVariable String id) {
        return R.ok(tEmployeeProjectService.removeById(id));
    }

	/**
	 * 新增项目档案校验
	 * @param tEmployeeProject 项目档案表
	 * @Author huyc
	 * @Date 2022-06-20
	 * @return R
	 */
	@Operation(summary = "新增项目档案校验", description = "新增项目档案校验")
	@SysLog("新增项目档案校验" )
	@PostMapping("/check")
	@PreAuthorize("@pms.hasPermission('archives_temployeeproject_addcheck')" )
	public R addCheck(@Valid @RequestBody TEmployeeProject tEmployeeProject) {
		return R.ok(tEmployeeProjectService.addCheck(tEmployeeProject));
	}

	/**
	 * 复档复项相关操作
	 * @param jsonObject
	 * @Author huyc
	 * @Date 2022-06-20
	 * @return R
	 */
	@Operation(summary = "复档复项相关操作", description = "复档复项相关操作")
	@SysLog("复档复项相关操作" )
	@PostMapping("/reEmpInfo")
	@PreAuthorize("@pms.hasPermission('archives_temployeeproject_reempinfo')" )
	public R reEmpInfo(@RequestBody JSONObject jsonObject) {
		return R.ok(tEmployeeProjectService.reEmpInfo(jsonObject));
	}

	/**
	 * 减项
	 * @param tEmployeeProject
	 * @Author huyc
	 * @Date 2022-06-20
	 */
	@Operation(summary = "减项", description = "减项")
	@SysLog("减项" )
	@PostMapping("/deleteEmpPro")
	@PreAuthorize("@pms.hasPermission('archives_temployeeproject_delempproinfo')" )
	public R deleteEmpPro(@RequestBody TEmployeeProject tEmployeeProject) {
		return R.ok(tEmployeeProjectService.deleteEmpPro(tEmployeeProject));
	}

	/**
	 * 批量新增项目档案信息
	 *
	 * @param excelVOList
	 * @return R<List>
	 * @Author huyc
	 * @Date 2022-06-20
	 **/
	@Operation(description = "批量新增项目档案信息 hasPermission('wxhr:employeeProjectinfo_importListAdd')")
	@SysLog("批量新增项目档案信息")
	@PostMapping("/importListAdd")
	@PreAuthorize("@pms.hasPermission('wxhr:employeeProjectinfo_importListAdd')")
	public R<List<ErrorMessage>> importListAdd(@RequestExcel List<EmployeeProjectVO> excelVOList, BindingResult bindingResult, @RequestParam("idAdd") String idAdd) {
		return tEmployeeProjectService.importListAdd(excelVOList, bindingResult, idAdd);
	}

	/**
	 * 批量更新项目档案信息
	 * @param excelVOList
	 * @param bindingResult
	 * @return R<List>
	 * @Author huyc
	 * @Date 2022-06-21
	 **/
	@Operation(description = "批量更新项目档案信息 hasPermission('archives_project_importListUpdate')")
	@SysLog("批量更新项目档案信息")
	@PostMapping("/importListUpate")
	@PreAuthorize("@pms.hasPermission('archives_project_importListUpdate')")
	public R<List<ErrorMessage>> importListUpate(@RequestExcel List<EmployeeProjectVO> excelVOList, BindingResult bindingResult) {
		return tEmployeeProjectService.importEmpProjectUpdate(excelVOList, bindingResult);
	}

	/**
	 * 通过id批量删除项目档案
	 * @param ids
	 * @return R
	 */
	@Operation(summary = "通过id批量删除项目档案", description = "通过id批量删除项目档案")
	@SysLog("通过id批量删除项目档案" )
	@PostMapping("/{ids}" )
	@PreAuthorize("@pms.hasPermission('archives_temployeeproject_batchdel')" )
	public R<List<ErrorMessage>> removeByIds(@RequestParam String ids) {
		return tEmployeeProjectService.batchRemoveByIds(ids);
	}

	/**
	 * 批量导出项目档案信息
	 * @param projectDTO
	 * @param idstr
	 * @param exportFields
	 * @return R<List>
	 * @Author huyc
	 * @Date 2022-06-21
	 **/
	@ResponseExcel
	@PostMapping("/export")
	public void export(EmployeeProjectExportVO projectDTO,@RequestParam(name = "idstr", required = false)String idstr,
												   @RequestBody List<String> exportFields) {
		tEmployeeProjectService.listExportProject(projectDTO,idstr,exportFields);
	}

	/**
	 * 通过项目编码查询项目信息
	 * @param empNo
	 * @return R
	 */
	@Operation(summary = "通过项目编码查询项目信息", description = "通过项目编码查询项目信息")
	@PostMapping("/getItemInfo" )
	public R getItemByEmpNo(@RequestParam String empIdcard,@RequestParam String empNo) {
		return tEmployeeProjectService.getItemByEmpNo(empIdcard,empNo);
	}
}
