package cn.ibizlab.humanresource.hrapi.rest;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import cn.ibizlab.humanresource.hrapi.dto.*;
import cn.ibizlab.humanresource.hrapi.mapping.*;
import cn.ibizlab.humanresource.core.humanresource.domain.HRCertificate;
import cn.ibizlab.humanresource.core.humanresource.service.IHRCertificateService;
import cn.ibizlab.humanresource.core.humanresource.filter.HRCertificateSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"证书信息" })
@RestController("HRApi-hrcertificate")
@RequestMapping("")
public class HRCertificateResource {

    @Autowired
    public IHRCertificateService hrcertificateService;

    @Autowired
    @Lazy
    public HRCertificateMapping hrcertificateMapping;

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedto),'iBizHumanResources-HRCertificate-Create')")
    @ApiOperation(value = "新建证书信息", tags = {"证书信息" },  notes = "新建证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcertificates")
    @Transactional
    public ResponseEntity<HRCertificateDTO> create(@RequestBody HRCertificateDTO hrcertificatedto) {
        HRCertificate domain = hrcertificateMapping.toDomain(hrcertificatedto);
		hrcertificateService.create(domain);
        HRCertificateDTO dto = hrcertificateMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedtos),'iBizHumanResources-HRCertificate-Create')")
    @ApiOperation(value = "批量新建证书信息", tags = {"证书信息" },  notes = "批量新建证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcertificates/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        hrcertificateService.createBatch(hrcertificateMapping.toDomain(hrcertificatedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrcertificate" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrcertificateService.get(#hrcertificate_id),'iBizHumanResources-HRCertificate-Update')")
    @ApiOperation(value = "更新证书信息", tags = {"证书信息" },  notes = "更新证书信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrcertificates/{hrcertificate_id}")
    @Transactional
    public ResponseEntity<HRCertificateDTO> update(@PathVariable("hrcertificate_id") String hrcertificate_id, @RequestBody HRCertificateDTO hrcertificatedto) {
		HRCertificate domain  = hrcertificateMapping.toDomain(hrcertificatedto);
        domain .setHrcertificateid(hrcertificate_id);
		hrcertificateService.update(domain );
		HRCertificateDTO dto = hrcertificateMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.getHrcertificateByEntities(this.hrcertificateMapping.toDomain(#hrcertificatedtos)),'iBizHumanResources-HRCertificate-Update')")
    @ApiOperation(value = "批量更新证书信息", tags = {"证书信息" },  notes = "批量更新证书信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrcertificates/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        hrcertificateService.updateBatch(hrcertificateMapping.toDomain(hrcertificatedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.get(#hrcertificate_id),'iBizHumanResources-HRCertificate-Remove')")
    @ApiOperation(value = "删除证书信息", tags = {"证书信息" },  notes = "删除证书信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrcertificates/{hrcertificate_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrcertificate_id") String hrcertificate_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.remove(hrcertificate_id));
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.getHrcertificateByIds(#ids),'iBizHumanResources-HRCertificate-Remove')")
    @ApiOperation(value = "批量删除证书信息", tags = {"证书信息" },  notes = "批量删除证书信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrcertificates/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        hrcertificateService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrcertificateMapping.toDomain(returnObject.body),'iBizHumanResources-HRCertificate-Get')")
    @ApiOperation(value = "获取证书信息", tags = {"证书信息" },  notes = "获取证书信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrcertificates/{hrcertificate_id}")
    public ResponseEntity<HRCertificateDTO> get(@PathVariable("hrcertificate_id") String hrcertificate_id) {
        HRCertificate domain = hrcertificateService.get(hrcertificate_id);
        HRCertificateDTO dto = hrcertificateMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取证书信息草稿", tags = {"证书信息" },  notes = "获取证书信息草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrcertificates/getdraft")
    public ResponseEntity<HRCertificateDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrcertificateMapping.toDto(hrcertificateService.getDraft(new HRCertificate())));
    }

    @ApiOperation(value = "检查证书信息", tags = {"证书信息" },  notes = "检查证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcertificates/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HRCertificateDTO hrcertificatedto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.checkKey(hrcertificateMapping.toDomain(hrcertificatedto)));
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedto),'iBizHumanResources-HRCertificate-Save')")
    @ApiOperation(value = "保存证书信息", tags = {"证书信息" },  notes = "保存证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcertificates/save")
    public ResponseEntity<Boolean> save(@RequestBody HRCertificateDTO hrcertificatedto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.save(hrcertificateMapping.toDomain(hrcertificatedto)));
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedtos),'iBizHumanResources-HRCertificate-Save')")
    @ApiOperation(value = "批量保存证书信息", tags = {"证书信息" },  notes = "批量保存证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcertificates/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        hrcertificateService.saveBatch(hrcertificateMapping.toDomain(hrcertificatedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "获取有效证书", tags = {"证书信息" } ,notes = "获取有效证书")
    @RequestMapping(method= RequestMethod.GET , value="/hrcertificates/fetchactive")
	public ResponseEntity<List<HRCertificateDTO>> fetchActive(HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchActive(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "查询有效证书", tags = {"证书信息" } ,notes = "查询有效证书")
    @RequestMapping(method= RequestMethod.POST , value="/hrcertificates/searchactive")
	public ResponseEntity<Page<HRCertificateDTO>> searchActive(@RequestBody HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"证书信息" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrcertificates/fetchdefault")
	public ResponseEntity<List<HRCertificateDTO>> fetchDefault(HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchDefault(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"证书信息" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrcertificates/searchdefault")
	public ResponseEntity<Page<HRCertificateDTO>> searchDefault(@RequestBody HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchInActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "获取有效证书", tags = {"证书信息" } ,notes = "获取有效证书")
    @RequestMapping(method= RequestMethod.GET , value="/hrcertificates/fetchinactive")
	public ResponseEntity<List<HRCertificateDTO>> fetchInActive(HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchInActive(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchInActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "查询有效证书", tags = {"证书信息" } ,notes = "查询有效证书")
    @RequestMapping(method= RequestMethod.POST , value="/hrcertificates/searchinactive")
	public ResponseEntity<Page<HRCertificateDTO>> searchInActive(@RequestBody HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchInActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchSoonExpired-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "获取即将过期", tags = {"证书信息" } ,notes = "获取即将过期")
    @RequestMapping(method= RequestMethod.GET , value="/hrcertificates/fetchsoonexpired")
	public ResponseEntity<List<HRCertificateDTO>> fetchSoonExpired(HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchSoonExpired(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchSoonExpired-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "查询即将过期", tags = {"证书信息" } ,notes = "查询即将过期")
    @RequestMapping(method= RequestMethod.POST , value="/hrcertificates/searchsoonexpired")
	public ResponseEntity<Page<HRCertificateDTO>> searchSoonExpired(@RequestBody HRCertificateSearchContext context) {
        Page<HRCertificate> domains = hrcertificateService.searchSoonExpired(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedto),'iBizHumanResources-HRCertificate-Create')")
    @ApiOperation(value = "根据员工建立证书信息", tags = {"证书信息" },  notes = "根据员工建立证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcertificates")
    @Transactional
    public ResponseEntity<HRCertificateDTO> createByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateDTO hrcertificatedto) {
        HRCertificate domain = hrcertificateMapping.toDomain(hrcertificatedto);
        domain.setHremployeeid(hremployee_id);
		hrcertificateService.create(domain);
        HRCertificateDTO dto = hrcertificateMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedtos),'iBizHumanResources-HRCertificate-Create')")
    @ApiOperation(value = "根据员工批量建立证书信息", tags = {"证书信息" },  notes = "根据员工批量建立证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcertificates/batch")
    public ResponseEntity<Boolean> createBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        List<HRCertificate> domainlist=hrcertificateMapping.toDomain(hrcertificatedtos);
        for(HRCertificate domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrcertificateService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrcertificate" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrcertificateService.get(#hrcertificate_id),'iBizHumanResources-HRCertificate-Update')")
    @ApiOperation(value = "根据员工更新证书信息", tags = {"证书信息" },  notes = "根据员工更新证书信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrcertificates/{hrcertificate_id}")
    @Transactional
    public ResponseEntity<HRCertificateDTO> updateByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrcertificate_id") String hrcertificate_id, @RequestBody HRCertificateDTO hrcertificatedto) {
        HRCertificate domain = hrcertificateMapping.toDomain(hrcertificatedto);
        domain.setHremployeeid(hremployee_id);
        domain.setHrcertificateid(hrcertificate_id);
		hrcertificateService.update(domain);
        HRCertificateDTO dto = hrcertificateMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.getHrcertificateByEntities(this.hrcertificateMapping.toDomain(#hrcertificatedtos)),'iBizHumanResources-HRCertificate-Update')")
    @ApiOperation(value = "根据员工批量更新证书信息", tags = {"证书信息" },  notes = "根据员工批量更新证书信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrcertificates/batch")
    public ResponseEntity<Boolean> updateBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        List<HRCertificate> domainlist=hrcertificateMapping.toDomain(hrcertificatedtos);
        for(HRCertificate domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrcertificateService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.get(#hrcertificate_id),'iBizHumanResources-HRCertificate-Remove')")
    @ApiOperation(value = "根据员工删除证书信息", tags = {"证书信息" },  notes = "根据员工删除证书信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hremployees/{hremployee_id}/hrcertificates/{hrcertificate_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrcertificate_id") String hrcertificate_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.remove(hrcertificate_id));
    }

    @PreAuthorize("hasPermission(this.hrcertificateService.getHrcertificateByIds(#ids),'iBizHumanResources-HRCertificate-Remove')")
    @ApiOperation(value = "根据员工批量删除证书信息", tags = {"证书信息" },  notes = "根据员工批量删除证书信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hremployees/{hremployee_id}/hrcertificates/batch")
    public ResponseEntity<Boolean> removeBatchByHREmployee(@RequestBody List<String> ids) {
        hrcertificateService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrcertificateMapping.toDomain(returnObject.body),'iBizHumanResources-HRCertificate-Get')")
    @ApiOperation(value = "根据员工获取证书信息", tags = {"证书信息" },  notes = "根据员工获取证书信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrcertificates/{hrcertificate_id}")
    public ResponseEntity<HRCertificateDTO> getByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrcertificate_id") String hrcertificate_id) {
        HRCertificate domain = hrcertificateService.get(hrcertificate_id);
        HRCertificateDTO dto = hrcertificateMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据员工获取证书信息草稿", tags = {"证书信息" },  notes = "根据员工获取证书信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrcertificates/getdraft")
    public ResponseEntity<HRCertificateDTO> getDraftByHREmployee(@PathVariable("hremployee_id") String hremployee_id) {
        HRCertificate domain = new HRCertificate();
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrcertificateMapping.toDto(hrcertificateService.getDraft(domain)));
    }

    @ApiOperation(value = "根据员工检查证书信息", tags = {"证书信息" },  notes = "根据员工检查证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcertificates/checkkey")
    public ResponseEntity<Boolean> checkKeyByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateDTO hrcertificatedto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.checkKey(hrcertificateMapping.toDomain(hrcertificatedto)));
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedto),'iBizHumanResources-HRCertificate-Save')")
    @ApiOperation(value = "根据员工保存证书信息", tags = {"证书信息" },  notes = "根据员工保存证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcertificates/save")
    public ResponseEntity<Boolean> saveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateDTO hrcertificatedto) {
        HRCertificate domain = hrcertificateMapping.toDomain(hrcertificatedto);
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrcertificateService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrcertificateMapping.toDomain(#hrcertificatedtos),'iBizHumanResources-HRCertificate-Save')")
    @ApiOperation(value = "根据员工批量保存证书信息", tags = {"证书信息" },  notes = "根据员工批量保存证书信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcertificates/savebatch")
    public ResponseEntity<Boolean> saveBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRCertificateDTO> hrcertificatedtos) {
        List<HRCertificate> domainlist=hrcertificateMapping.toDomain(hrcertificatedtos);
        for(HRCertificate domain:domainlist){
             domain.setHremployeeid(hremployee_id);
        }
        hrcertificateService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工获取有效证书", tags = {"证书信息" } ,notes = "根据员工获取有效证书")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcertificates/fetchactive")
	public ResponseEntity<List<HRCertificateDTO>> fetchHRCertificateActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchActive(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工查询有效证书", tags = {"证书信息" } ,notes = "根据员工查询有效证书")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcertificates/searchactive")
	public ResponseEntity<Page<HRCertificateDTO>> searchHRCertificateActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工获取DEFAULT", tags = {"证书信息" } ,notes = "根据员工获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcertificates/fetchdefault")
	public ResponseEntity<List<HRCertificateDTO>> fetchHRCertificateDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchDefault(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工查询DEFAULT", tags = {"证书信息" } ,notes = "根据员工查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcertificates/searchdefault")
	public ResponseEntity<Page<HRCertificateDTO>> searchHRCertificateDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchInActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工获取有效证书", tags = {"证书信息" } ,notes = "根据员工获取有效证书")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcertificates/fetchinactive")
	public ResponseEntity<List<HRCertificateDTO>> fetchHRCertificateInActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchInActive(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchInActive-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工查询有效证书", tags = {"证书信息" } ,notes = "根据员工查询有效证书")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcertificates/searchinactive")
	public ResponseEntity<Page<HRCertificateDTO>> searchHRCertificateInActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchInActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchSoonExpired-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工获取即将过期", tags = {"证书信息" } ,notes = "根据员工获取即将过期")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcertificates/fetchsoonexpired")
	public ResponseEntity<List<HRCertificateDTO>> fetchHRCertificateSoonExpiredByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchSoonExpired(context) ;
        List<HRCertificateDTO> list = hrcertificateMapping.toDto(domains.getContent());
	    return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
                .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
                .header("x-total", String.valueOf(domains.getTotalElements()))
                .body(list);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRCertificate-searchSoonExpired-all') and hasPermission(#context,'iBizHumanResources-HRCertificate-Get')")
	@ApiOperation(value = "根据员工查询即将过期", tags = {"证书信息" } ,notes = "根据员工查询即将过期")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcertificates/searchsoonexpired")
	public ResponseEntity<Page<HRCertificateDTO>> searchHRCertificateSoonExpiredByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRCertificateSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRCertificate> domains = hrcertificateService.searchSoonExpired(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcertificateMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

