package com.zksy.controller.info;

import cn.hutool.core.date.DateTime;
import com.zksy.info.domain.EArchivesAdministration;
import com.zksy.info.domain.EEmployeeMaster;
import com.zksy.info.domain.EEnterpriseInfo;
import com.zksy.info.service.EArchivesAdministrationService;
import com.zksy.info.service.EEmployeeMasterService;
import com.zksy.utils.AjaxResult;
import com.zksy.utils.ExcelExportUtil;
import com.zksy.utils.ExcelImportUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 员工合同管理控制层
 * @date 2025/6/24 14:33:13
 */
@RestController
@RequestMapping("/eemployeeMaster")
@Api(tags = "员工合同管理",description = "员工合同管理desc")
public class EEmployeeMasterController {
    @Autowired
    private EEmployeeMasterService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "员工合同管理查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize,String contractStatus,String fullName, String contractNo){
        return AjaxResult.success(service.findByPage(pageNum, pageSize,contractStatus,fullName, contractNo));
    }
    @GetMapping("/getEAdminLicenseInfoList")
    @ApiOperation(value = "员工合同管理查询")
    public AjaxResult getEAdminLicenseInfoList(String contractStatus,String fullName,String contractNo){
        return AjaxResult.success(service.getEEmployeeMasterList(contractStatus,fullName,contractNo));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询员工合同管理")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "员工合同管理保存")
    public AjaxResult save(@RequestBody EEmployeeMaster eemployeeMaster) {
        return service.save(eemployeeMaster) ? AjaxResult.success(eemployeeMaster) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "员工合同管理修改")
    public AjaxResult update(@RequestBody EEmployeeMaster eemployeeMaster) {
        eemployeeMaster.setUpdateTime(LocalDateTime.now());
        return service.updateById(eemployeeMaster) ? AjaxResult.success(eemployeeMaster) : AjaxResult.error("更新失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "员工合同管理删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据")
    public AjaxResult importData(MultipartFile file) {
        return AjaxResult.success(service.saveOrUpdateBatch(ExcelImportUtil.importExcel(file, EEmployeeMaster.class)));
    }
    @GetMapping("/exportData")
    @ApiOperation(value = "导出数据")
    public void exportData(HttpServletResponse response, String contractStatus,String fullName,String contractNo) {
        ExcelExportUtil.exportExcel(response,service.getEEmployeeMasterList(contractStatus,fullName,contractNo), EEmployeeMaster.class, "员工合同信息","员工合同信息");
    }
}
