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.base.domain.HROMHierarchy;
import cn.ibizlab.humanresource.core.base.service.IHROMHierarchyService;
import cn.ibizlab.humanresource.core.base.filter.HROMHierarchySearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"组织层次结构" })
@RestController("HRApi-hromhierarchy")
@RequestMapping("")
public class HROMHierarchyResource {

    @Autowired
    public IHROMHierarchyService hromhierarchyService;

    @Autowired
    @Lazy
    public HROMHierarchyMapping hromhierarchyMapping;

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydto),'iBizHumanResources-HROMHierarchy-Create')")
    @ApiOperation(value = "新建组织层次结构", tags = {"组织层次结构" },  notes = "新建组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchies")
    @Transactional
    public ResponseEntity<HROMHierarchyDTO> create(@RequestBody HROMHierarchyDTO hromhierarchydto) {
        HROMHierarchy domain = hromhierarchyMapping.toDomain(hromhierarchydto);
		hromhierarchyService.create(domain);
        HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydtos),'iBizHumanResources-HROMHierarchy-Create')")
    @ApiOperation(value = "批量新建组织层次结构", tags = {"组织层次结构" },  notes = "批量新建组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchies/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        hromhierarchyService.createBatch(hromhierarchyMapping.toDomain(hromhierarchydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hromhierarchy" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hromhierarchyService.get(#hromhierarchy_id),'iBizHumanResources-HROMHierarchy-Update')")
    @ApiOperation(value = "更新组织层次结构", tags = {"组织层次结构" },  notes = "更新组织层次结构")
	@RequestMapping(method = RequestMethod.PUT, value = "/hromhierarchies/{hromhierarchy_id}")
    @Transactional
    public ResponseEntity<HROMHierarchyDTO> update(@PathVariable("hromhierarchy_id") String hromhierarchy_id, @RequestBody HROMHierarchyDTO hromhierarchydto) {
		HROMHierarchy domain  = hromhierarchyMapping.toDomain(hromhierarchydto);
        domain .setOmhierarchyid(hromhierarchy_id);
		hromhierarchyService.update(domain );
		HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.getHromhierarchyByEntities(this.hromhierarchyMapping.toDomain(#hromhierarchydtos)),'iBizHumanResources-HROMHierarchy-Update')")
    @ApiOperation(value = "批量更新组织层次结构", tags = {"组织层次结构" },  notes = "批量更新组织层次结构")
	@RequestMapping(method = RequestMethod.PUT, value = "/hromhierarchies/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        hromhierarchyService.updateBatch(hromhierarchyMapping.toDomain(hromhierarchydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.get(#hromhierarchy_id),'iBizHumanResources-HROMHierarchy-Remove')")
    @ApiOperation(value = "删除组织层次结构", tags = {"组织层次结构" },  notes = "删除组织层次结构")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hromhierarchies/{hromhierarchy_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hromhierarchy_id") String hromhierarchy_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.remove(hromhierarchy_id));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.getHromhierarchyByIds(#ids),'iBizHumanResources-HROMHierarchy-Remove')")
    @ApiOperation(value = "批量删除组织层次结构", tags = {"组织层次结构" },  notes = "批量删除组织层次结构")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hromhierarchies/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        hromhierarchyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(returnObject.body),'iBizHumanResources-HROMHierarchy-Get')")
    @ApiOperation(value = "获取组织层次结构", tags = {"组织层次结构" },  notes = "获取组织层次结构")
	@RequestMapping(method = RequestMethod.GET, value = "/hromhierarchies/{hromhierarchy_id}")
    public ResponseEntity<HROMHierarchyDTO> get(@PathVariable("hromhierarchy_id") String hromhierarchy_id) {
        HROMHierarchy domain = hromhierarchyService.get(hromhierarchy_id);
        HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取组织层次结构草稿", tags = {"组织层次结构" },  notes = "获取组织层次结构草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hromhierarchies/getdraft")
    public ResponseEntity<HROMHierarchyDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyMapping.toDto(hromhierarchyService.getDraft(new HROMHierarchy())));
    }

    @ApiOperation(value = "检查组织层次结构", tags = {"组织层次结构" },  notes = "检查组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchies/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HROMHierarchyDTO hromhierarchydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.checkKey(hromhierarchyMapping.toDomain(hromhierarchydto)));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydto),'iBizHumanResources-HROMHierarchy-Save')")
    @ApiOperation(value = "保存组织层次结构", tags = {"组织层次结构" },  notes = "保存组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchies/save")
    public ResponseEntity<Boolean> save(@RequestBody HROMHierarchyDTO hromhierarchydto) {
        return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.save(hromhierarchyMapping.toDomain(hromhierarchydto)));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydtos),'iBizHumanResources-HROMHierarchy-Save')")
    @ApiOperation(value = "批量保存组织层次结构", tags = {"组织层次结构" },  notes = "批量保存组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchies/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        hromhierarchyService.saveBatch(hromhierarchyMapping.toDomain(hromhierarchydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROMHierarchy-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"组织层次结构" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hromhierarchies/fetchdefault")
	public ResponseEntity<List<HROMHierarchyDTO>> fetchDefault(HROMHierarchySearchContext context) {
        Page<HROMHierarchy> domains = hromhierarchyService.searchDefault(context) ;
        List<HROMHierarchyDTO> list = hromhierarchyMapping.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-HROMHierarchy-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"组织层次结构" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hromhierarchies/searchdefault")
	public ResponseEntity<Page<HROMHierarchyDTO>> searchDefault(@RequestBody HROMHierarchySearchContext context) {
        Page<HROMHierarchy> domains = hromhierarchyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hromhierarchyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROMHierarchy-searchRootOrg-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "获取顶级组织", tags = {"组织层次结构" } ,notes = "获取顶级组织")
    @RequestMapping(method= RequestMethod.GET , value="/hromhierarchies/fetchrootorg")
	public ResponseEntity<List<HROMHierarchyDTO>> fetchRootOrg(HROMHierarchySearchContext context) {
        Page<HROMHierarchy> domains = hromhierarchyService.searchRootOrg(context) ;
        List<HROMHierarchyDTO> list = hromhierarchyMapping.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-HROMHierarchy-searchRootOrg-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "查询顶级组织", tags = {"组织层次结构" } ,notes = "查询顶级组织")
    @RequestMapping(method= RequestMethod.POST , value="/hromhierarchies/searchrootorg")
	public ResponseEntity<Page<HROMHierarchyDTO>> searchRootOrg(@RequestBody HROMHierarchySearchContext context) {
        Page<HROMHierarchy> domains = hromhierarchyService.searchRootOrg(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hromhierarchyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydto),'iBizHumanResources-HROMHierarchy-Create')")
    @ApiOperation(value = "根据结构层次类别建立组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别建立组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies")
    @Transactional
    public ResponseEntity<HROMHierarchyDTO> createByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody HROMHierarchyDTO hromhierarchydto) {
        HROMHierarchy domain = hromhierarchyMapping.toDomain(hromhierarchydto);
        domain.setHromhierarchycatid(hromhierarchycat_id);
		hromhierarchyService.create(domain);
        HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydtos),'iBizHumanResources-HROMHierarchy-Create')")
    @ApiOperation(value = "根据结构层次类别批量建立组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别批量建立组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/batch")
    public ResponseEntity<Boolean> createBatchByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        List<HROMHierarchy> domainlist=hromhierarchyMapping.toDomain(hromhierarchydtos);
        for(HROMHierarchy domain:domainlist){
            domain.setHromhierarchycatid(hromhierarchycat_id);
        }
        hromhierarchyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hromhierarchy" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hromhierarchyService.get(#hromhierarchy_id),'iBizHumanResources-HROMHierarchy-Update')")
    @ApiOperation(value = "根据结构层次类别更新组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别更新组织层次结构")
	@RequestMapping(method = RequestMethod.PUT, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/{hromhierarchy_id}")
    @Transactional
    public ResponseEntity<HROMHierarchyDTO> updateByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @PathVariable("hromhierarchy_id") String hromhierarchy_id, @RequestBody HROMHierarchyDTO hromhierarchydto) {
        HROMHierarchy domain = hromhierarchyMapping.toDomain(hromhierarchydto);
        domain.setHromhierarchycatid(hromhierarchycat_id);
        domain.setOmhierarchyid(hromhierarchy_id);
		hromhierarchyService.update(domain);
        HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.getHromhierarchyByEntities(this.hromhierarchyMapping.toDomain(#hromhierarchydtos)),'iBizHumanResources-HROMHierarchy-Update')")
    @ApiOperation(value = "根据结构层次类别批量更新组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别批量更新组织层次结构")
	@RequestMapping(method = RequestMethod.PUT, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/batch")
    public ResponseEntity<Boolean> updateBatchByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        List<HROMHierarchy> domainlist=hromhierarchyMapping.toDomain(hromhierarchydtos);
        for(HROMHierarchy domain:domainlist){
            domain.setHromhierarchycatid(hromhierarchycat_id);
        }
        hromhierarchyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.get(#hromhierarchy_id),'iBizHumanResources-HROMHierarchy-Remove')")
    @ApiOperation(value = "根据结构层次类别删除组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别删除组织层次结构")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/{hromhierarchy_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @PathVariable("hromhierarchy_id") String hromhierarchy_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.remove(hromhierarchy_id));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyService.getHromhierarchyByIds(#ids),'iBizHumanResources-HROMHierarchy-Remove')")
    @ApiOperation(value = "根据结构层次类别批量删除组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别批量删除组织层次结构")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/batch")
    public ResponseEntity<Boolean> removeBatchByHROMHierarchyCat(@RequestBody List<String> ids) {
        hromhierarchyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(returnObject.body),'iBizHumanResources-HROMHierarchy-Get')")
    @ApiOperation(value = "根据结构层次类别获取组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别获取组织层次结构")
	@RequestMapping(method = RequestMethod.GET, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/{hromhierarchy_id}")
    public ResponseEntity<HROMHierarchyDTO> getByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @PathVariable("hromhierarchy_id") String hromhierarchy_id) {
        HROMHierarchy domain = hromhierarchyService.get(hromhierarchy_id);
        HROMHierarchyDTO dto = hromhierarchyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据结构层次类别获取组织层次结构草稿", tags = {"组织层次结构" },  notes = "根据结构层次类别获取组织层次结构草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/getdraft")
    public ResponseEntity<HROMHierarchyDTO> getDraftByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id) {
        HROMHierarchy domain = new HROMHierarchy();
        domain.setHromhierarchycatid(hromhierarchycat_id);
        return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyMapping.toDto(hromhierarchyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据结构层次类别检查组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别检查组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/checkkey")
    public ResponseEntity<Boolean> checkKeyByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody HROMHierarchyDTO hromhierarchydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.checkKey(hromhierarchyMapping.toDomain(hromhierarchydto)));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydto),'iBizHumanResources-HROMHierarchy-Save')")
    @ApiOperation(value = "根据结构层次类别保存组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别保存组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/save")
    public ResponseEntity<Boolean> saveByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody HROMHierarchyDTO hromhierarchydto) {
        HROMHierarchy domain = hromhierarchyMapping.toDomain(hromhierarchydto);
        domain.setHromhierarchycatid(hromhierarchycat_id);
        return ResponseEntity.status(HttpStatus.OK).body(hromhierarchyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hromhierarchyMapping.toDomain(#hromhierarchydtos),'iBizHumanResources-HROMHierarchy-Save')")
    @ApiOperation(value = "根据结构层次类别批量保存组织层次结构", tags = {"组织层次结构" },  notes = "根据结构层次类别批量保存组织层次结构")
	@RequestMapping(method = RequestMethod.POST, value = "/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/savebatch")
    public ResponseEntity<Boolean> saveBatchByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody List<HROMHierarchyDTO> hromhierarchydtos) {
        List<HROMHierarchy> domainlist=hromhierarchyMapping.toDomain(hromhierarchydtos);
        for(HROMHierarchy domain:domainlist){
             domain.setHromhierarchycatid(hromhierarchycat_id);
        }
        hromhierarchyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROMHierarchy-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "根据结构层次类别获取DEFAULT", tags = {"组织层次结构" } ,notes = "根据结构层次类别获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/fetchdefault")
	public ResponseEntity<List<HROMHierarchyDTO>> fetchHROMHierarchyDefaultByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id,HROMHierarchySearchContext context) {
        context.setN_hromhierarchycatid_eq(hromhierarchycat_id);
        Page<HROMHierarchy> domains = hromhierarchyService.searchDefault(context) ;
        List<HROMHierarchyDTO> list = hromhierarchyMapping.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-HROMHierarchy-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "根据结构层次类别查询DEFAULT", tags = {"组织层次结构" } ,notes = "根据结构层次类别查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/searchdefault")
	public ResponseEntity<Page<HROMHierarchyDTO>> searchHROMHierarchyDefaultByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody HROMHierarchySearchContext context) {
        context.setN_hromhierarchycatid_eq(hromhierarchycat_id);
        Page<HROMHierarchy> domains = hromhierarchyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hromhierarchyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROMHierarchy-searchRootOrg-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "根据结构层次类别获取顶级组织", tags = {"组织层次结构" } ,notes = "根据结构层次类别获取顶级组织")
    @RequestMapping(method= RequestMethod.GET , value="/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/fetchrootorg")
	public ResponseEntity<List<HROMHierarchyDTO>> fetchHROMHierarchyRootOrgByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id,HROMHierarchySearchContext context) {
        context.setN_hromhierarchycatid_eq(hromhierarchycat_id);
        Page<HROMHierarchy> domains = hromhierarchyService.searchRootOrg(context) ;
        List<HROMHierarchyDTO> list = hromhierarchyMapping.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-HROMHierarchy-searchRootOrg-all') and hasPermission(#context,'iBizHumanResources-HROMHierarchy-Get')")
	@ApiOperation(value = "根据结构层次类别查询顶级组织", tags = {"组织层次结构" } ,notes = "根据结构层次类别查询顶级组织")
    @RequestMapping(method= RequestMethod.POST , value="/hromhierarchycats/{hromhierarchycat_id}/hromhierarchies/searchrootorg")
	public ResponseEntity<Page<HROMHierarchyDTO>> searchHROMHierarchyRootOrgByHROMHierarchyCat(@PathVariable("hromhierarchycat_id") String hromhierarchycat_id, @RequestBody HROMHierarchySearchContext context) {
        context.setN_hromhierarchycatid_eq(hromhierarchycat_id);
        Page<HROMHierarchy> domains = hromhierarchyService.searchRootOrg(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hromhierarchyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

