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.HRArchives;
import cn.ibizlab.humanresource.core.humanresource.service.IHRArchivesService;
import cn.ibizlab.humanresource.core.humanresource.filter.HRArchivesSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"档案信息" })
@RestController("HRApi-hrarchives")
@RequestMapping("")
public class HRArchivesResource {

    @Autowired
    public IHRArchivesService hrarchivesService;

    @Autowired
    @Lazy
    public HRArchivesMapping hrarchivesMapping;

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdto),'iBizHumanResources-HRArchives-Create')")
    @ApiOperation(value = "新建档案信息", tags = {"档案信息" },  notes = "新建档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrarchives")
    @Transactional
    public ResponseEntity<HRArchivesDTO> create(@RequestBody HRArchivesDTO hrarchivesdto) {
        HRArchives domain = hrarchivesMapping.toDomain(hrarchivesdto);
		hrarchivesService.create(domain);
        HRArchivesDTO dto = hrarchivesMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdtos),'iBizHumanResources-HRArchives-Create')")
    @ApiOperation(value = "批量新建档案信息", tags = {"档案信息" },  notes = "批量新建档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrarchives/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        hrarchivesService.createBatch(hrarchivesMapping.toDomain(hrarchivesdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrarchives" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrarchivesService.get(#hrarchives_id),'iBizHumanResources-HRArchives-Update')")
    @ApiOperation(value = "更新档案信息", tags = {"档案信息" },  notes = "更新档案信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrarchives/{hrarchives_id}")
    @Transactional
    public ResponseEntity<HRArchivesDTO> update(@PathVariable("hrarchives_id") String hrarchives_id, @RequestBody HRArchivesDTO hrarchivesdto) {
		HRArchives domain  = hrarchivesMapping.toDomain(hrarchivesdto);
        domain .setHrarchivesid(hrarchives_id);
		hrarchivesService.update(domain );
		HRArchivesDTO dto = hrarchivesMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrarchivesService.getHrarchivesByEntities(this.hrarchivesMapping.toDomain(#hrarchivesdtos)),'iBizHumanResources-HRArchives-Update')")
    @ApiOperation(value = "批量更新档案信息", tags = {"档案信息" },  notes = "批量更新档案信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrarchives/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        hrarchivesService.updateBatch(hrarchivesMapping.toDomain(hrarchivesdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrarchivesService.get(#hrarchives_id),'iBizHumanResources-HRArchives-Remove')")
    @ApiOperation(value = "删除档案信息", tags = {"档案信息" },  notes = "删除档案信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrarchives/{hrarchives_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrarchives_id") String hrarchives_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrarchivesService.remove(hrarchives_id));
    }

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

    @PostAuthorize("hasPermission(this.hrarchivesMapping.toDomain(returnObject.body),'iBizHumanResources-HRArchives-Get')")
    @ApiOperation(value = "获取档案信息", tags = {"档案信息" },  notes = "获取档案信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrarchives/{hrarchives_id}")
    public ResponseEntity<HRArchivesDTO> get(@PathVariable("hrarchives_id") String hrarchives_id) {
        HRArchives domain = hrarchivesService.get(hrarchives_id);
        HRArchivesDTO dto = hrarchivesMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取档案信息草稿", tags = {"档案信息" },  notes = "获取档案信息草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrarchives/getdraft")
    public ResponseEntity<HRArchivesDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrarchivesMapping.toDto(hrarchivesService.getDraft(new HRArchives())));
    }

    @ApiOperation(value = "检查档案信息", tags = {"档案信息" },  notes = "检查档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrarchives/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HRArchivesDTO hrarchivesdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrarchivesService.checkKey(hrarchivesMapping.toDomain(hrarchivesdto)));
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdto),'iBizHumanResources-HRArchives-Save')")
    @ApiOperation(value = "保存档案信息", tags = {"档案信息" },  notes = "保存档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrarchives/save")
    public ResponseEntity<Boolean> save(@RequestBody HRArchivesDTO hrarchivesdto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrarchivesService.save(hrarchivesMapping.toDomain(hrarchivesdto)));
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdtos),'iBizHumanResources-HRArchives-Save')")
    @ApiOperation(value = "批量保存档案信息", tags = {"档案信息" },  notes = "批量保存档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrarchives/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        hrarchivesService.saveBatch(hrarchivesMapping.toDomain(hrarchivesdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "获取有效档案", tags = {"档案信息" } ,notes = "获取有效档案")
    @RequestMapping(method= RequestMethod.GET , value="/hrarchives/fetchactive")
	public ResponseEntity<List<HRArchivesDTO>> fetchActive(HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchActive(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "查询有效档案", tags = {"档案信息" } ,notes = "查询有效档案")
    @RequestMapping(method= RequestMethod.POST , value="/hrarchives/searchactive")
	public ResponseEntity<Page<HRArchivesDTO>> searchActive(@RequestBody HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"档案信息" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrarchives/fetchdefault")
	public ResponseEntity<List<HRArchivesDTO>> fetchDefault(HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchDefault(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"档案信息" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrarchives/searchdefault")
	public ResponseEntity<Page<HRArchivesDTO>> searchDefault(@RequestBody HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchNonArchives-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "获取员工不在档", tags = {"档案信息" } ,notes = "获取员工不在档")
    @RequestMapping(method= RequestMethod.GET , value="/hrarchives/fetchnonarchives")
	public ResponseEntity<List<HRArchivesDTO>> fetchNonArchives(HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchNonArchives(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchNonArchives-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "查询员工不在档", tags = {"档案信息" } ,notes = "查询员工不在档")
    @RequestMapping(method= RequestMethod.POST , value="/hrarchives/searchnonarchives")
	public ResponseEntity<Page<HRArchivesDTO>> searchNonArchives(@RequestBody HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchNonArchives(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchNonEmployee-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "获取非员工在档", tags = {"档案信息" } ,notes = "获取非员工在档")
    @RequestMapping(method= RequestMethod.GET , value="/hrarchives/fetchnonemployee")
	public ResponseEntity<List<HRArchivesDTO>> fetchNonEmployee(HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchNonEmployee(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchNonEmployee-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "查询非员工在档", tags = {"档案信息" } ,notes = "查询非员工在档")
    @RequestMapping(method= RequestMethod.POST , value="/hrarchives/searchnonemployee")
	public ResponseEntity<Page<HRArchivesDTO>> searchNonEmployee(@RequestBody HRArchivesSearchContext context) {
        Page<HRArchives> domains = hrarchivesService.searchNonEmployee(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdto),'iBizHumanResources-HRArchives-Create')")
    @ApiOperation(value = "根据员工建立档案信息", tags = {"档案信息" },  notes = "根据员工建立档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrarchives")
    @Transactional
    public ResponseEntity<HRArchivesDTO> createByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesDTO hrarchivesdto) {
        HRArchives domain = hrarchivesMapping.toDomain(hrarchivesdto);
        domain.setHremployeeid(hremployee_id);
		hrarchivesService.create(domain);
        HRArchivesDTO dto = hrarchivesMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdtos),'iBizHumanResources-HRArchives-Create')")
    @ApiOperation(value = "根据员工批量建立档案信息", tags = {"档案信息" },  notes = "根据员工批量建立档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrarchives/batch")
    public ResponseEntity<Boolean> createBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        List<HRArchives> domainlist=hrarchivesMapping.toDomain(hrarchivesdtos);
        for(HRArchives domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrarchivesService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrarchives" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrarchivesService.get(#hrarchives_id),'iBizHumanResources-HRArchives-Update')")
    @ApiOperation(value = "根据员工更新档案信息", tags = {"档案信息" },  notes = "根据员工更新档案信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrarchives/{hrarchives_id}")
    @Transactional
    public ResponseEntity<HRArchivesDTO> updateByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrarchives_id") String hrarchives_id, @RequestBody HRArchivesDTO hrarchivesdto) {
        HRArchives domain = hrarchivesMapping.toDomain(hrarchivesdto);
        domain.setHremployeeid(hremployee_id);
        domain.setHrarchivesid(hrarchives_id);
		hrarchivesService.update(domain);
        HRArchivesDTO dto = hrarchivesMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrarchivesService.getHrarchivesByEntities(this.hrarchivesMapping.toDomain(#hrarchivesdtos)),'iBizHumanResources-HRArchives-Update')")
    @ApiOperation(value = "根据员工批量更新档案信息", tags = {"档案信息" },  notes = "根据员工批量更新档案信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrarchives/batch")
    public ResponseEntity<Boolean> updateBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        List<HRArchives> domainlist=hrarchivesMapping.toDomain(hrarchivesdtos);
        for(HRArchives domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrarchivesService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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

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

    @PostAuthorize("hasPermission(this.hrarchivesMapping.toDomain(returnObject.body),'iBizHumanResources-HRArchives-Get')")
    @ApiOperation(value = "根据员工获取档案信息", tags = {"档案信息" },  notes = "根据员工获取档案信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrarchives/{hrarchives_id}")
    public ResponseEntity<HRArchivesDTO> getByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrarchives_id") String hrarchives_id) {
        HRArchives domain = hrarchivesService.get(hrarchives_id);
        HRArchivesDTO dto = hrarchivesMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据员工获取档案信息草稿", tags = {"档案信息" },  notes = "根据员工获取档案信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrarchives/getdraft")
    public ResponseEntity<HRArchivesDTO> getDraftByHREmployee(@PathVariable("hremployee_id") String hremployee_id) {
        HRArchives domain = new HRArchives();
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrarchivesMapping.toDto(hrarchivesService.getDraft(domain)));
    }

    @ApiOperation(value = "根据员工检查档案信息", tags = {"档案信息" },  notes = "根据员工检查档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrarchives/checkkey")
    public ResponseEntity<Boolean> checkKeyByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesDTO hrarchivesdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrarchivesService.checkKey(hrarchivesMapping.toDomain(hrarchivesdto)));
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdto),'iBizHumanResources-HRArchives-Save')")
    @ApiOperation(value = "根据员工保存档案信息", tags = {"档案信息" },  notes = "根据员工保存档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrarchives/save")
    public ResponseEntity<Boolean> saveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesDTO hrarchivesdto) {
        HRArchives domain = hrarchivesMapping.toDomain(hrarchivesdto);
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrarchivesService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrarchivesMapping.toDomain(#hrarchivesdtos),'iBizHumanResources-HRArchives-Save')")
    @ApiOperation(value = "根据员工批量保存档案信息", tags = {"档案信息" },  notes = "根据员工批量保存档案信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrarchives/savebatch")
    public ResponseEntity<Boolean> saveBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRArchivesDTO> hrarchivesdtos) {
        List<HRArchives> domainlist=hrarchivesMapping.toDomain(hrarchivesdtos);
        for(HRArchives domain:domainlist){
             domain.setHremployeeid(hremployee_id);
        }
        hrarchivesService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工获取有效档案", tags = {"档案信息" } ,notes = "根据员工获取有效档案")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrarchives/fetchactive")
	public ResponseEntity<List<HRArchivesDTO>> fetchHRArchivesActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchActive(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工查询有效档案", tags = {"档案信息" } ,notes = "根据员工查询有效档案")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrarchives/searchactive")
	public ResponseEntity<Page<HRArchivesDTO>> searchHRArchivesActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工获取DEFAULT", tags = {"档案信息" } ,notes = "根据员工获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrarchives/fetchdefault")
	public ResponseEntity<List<HRArchivesDTO>> fetchHRArchivesDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchDefault(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工查询DEFAULT", tags = {"档案信息" } ,notes = "根据员工查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrarchives/searchdefault")
	public ResponseEntity<Page<HRArchivesDTO>> searchHRArchivesDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchNonArchives-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工获取员工不在档", tags = {"档案信息" } ,notes = "根据员工获取员工不在档")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrarchives/fetchnonarchives")
	public ResponseEntity<List<HRArchivesDTO>> fetchHRArchivesNonArchivesByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchNonArchives(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchNonArchives-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工查询员工不在档", tags = {"档案信息" } ,notes = "根据员工查询员工不在档")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrarchives/searchnonarchives")
	public ResponseEntity<Page<HRArchivesDTO>> searchHRArchivesNonArchivesByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchNonArchives(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRArchives-searchNonEmployee-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工获取非员工在档", tags = {"档案信息" } ,notes = "根据员工获取非员工在档")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrarchives/fetchnonemployee")
	public ResponseEntity<List<HRArchivesDTO>> fetchHRArchivesNonEmployeeByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchNonEmployee(context) ;
        List<HRArchivesDTO> list = hrarchivesMapping.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-HRArchives-searchNonEmployee-all') and hasPermission(#context,'iBizHumanResources-HRArchives-Get')")
	@ApiOperation(value = "根据员工查询非员工在档", tags = {"档案信息" } ,notes = "根据员工查询非员工在档")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrarchives/searchnonemployee")
	public ResponseEntity<Page<HRArchivesDTO>> searchHRArchivesNonEmployeeByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRArchivesSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRArchives> domains = hrarchivesService.searchNonEmployee(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrarchivesMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

