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.HRContract;
import cn.ibizlab.humanresource.core.humanresource.service.IHRContractService;
import cn.ibizlab.humanresource.core.humanresource.filter.HRContractSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"合同信息" })
@RestController("HRApi-hrcontract")
@RequestMapping("")
public class HRContractResource {

    @Autowired
    public IHRContractService hrcontractService;

    @Autowired
    @Lazy
    public HRContractMapping hrcontractMapping;

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdto),'iBizHumanResources-HRContract-Create')")
    @ApiOperation(value = "新建合同信息", tags = {"合同信息" },  notes = "新建合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcontracts")
    @Transactional
    public ResponseEntity<HRContractDTO> create(@RequestBody HRContractDTO hrcontractdto) {
        HRContract domain = hrcontractMapping.toDomain(hrcontractdto);
		hrcontractService.create(domain);
        HRContractDTO dto = hrcontractMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdtos),'iBizHumanResources-HRContract-Create')")
    @ApiOperation(value = "批量新建合同信息", tags = {"合同信息" },  notes = "批量新建合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcontracts/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HRContractDTO> hrcontractdtos) {
        hrcontractService.createBatch(hrcontractMapping.toDomain(hrcontractdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrcontract" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrcontractService.get(#hrcontract_id),'iBizHumanResources-HRContract-Update')")
    @ApiOperation(value = "更新合同信息", tags = {"合同信息" },  notes = "更新合同信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrcontracts/{hrcontract_id}")
    @Transactional
    public ResponseEntity<HRContractDTO> update(@PathVariable("hrcontract_id") String hrcontract_id, @RequestBody HRContractDTO hrcontractdto) {
		HRContract domain  = hrcontractMapping.toDomain(hrcontractdto);
        domain .setHrcontractid(hrcontract_id);
		hrcontractService.update(domain );
		HRContractDTO dto = hrcontractMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcontractService.getHrcontractByEntities(this.hrcontractMapping.toDomain(#hrcontractdtos)),'iBizHumanResources-HRContract-Update')")
    @ApiOperation(value = "批量更新合同信息", tags = {"合同信息" },  notes = "批量更新合同信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrcontracts/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HRContractDTO> hrcontractdtos) {
        hrcontractService.updateBatch(hrcontractMapping.toDomain(hrcontractdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrcontractService.get(#hrcontract_id),'iBizHumanResources-HRContract-Remove')")
    @ApiOperation(value = "删除合同信息", tags = {"合同信息" },  notes = "删除合同信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrcontracts/{hrcontract_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrcontract_id") String hrcontract_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrcontractService.remove(hrcontract_id));
    }

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

    @PostAuthorize("hasPermission(this.hrcontractMapping.toDomain(returnObject.body),'iBizHumanResources-HRContract-Get')")
    @ApiOperation(value = "获取合同信息", tags = {"合同信息" },  notes = "获取合同信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrcontracts/{hrcontract_id}")
    public ResponseEntity<HRContractDTO> get(@PathVariable("hrcontract_id") String hrcontract_id) {
        HRContract domain = hrcontractService.get(hrcontract_id);
        HRContractDTO dto = hrcontractMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取合同信息草稿", tags = {"合同信息" },  notes = "获取合同信息草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrcontracts/getdraft")
    public ResponseEntity<HRContractDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrcontractMapping.toDto(hrcontractService.getDraft(new HRContract())));
    }

    @ApiOperation(value = "检查合同信息", tags = {"合同信息" },  notes = "检查合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcontracts/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HRContractDTO hrcontractdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrcontractService.checkKey(hrcontractMapping.toDomain(hrcontractdto)));
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdto),'iBizHumanResources-HRContract-Save')")
    @ApiOperation(value = "保存合同信息", tags = {"合同信息" },  notes = "保存合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcontracts/save")
    public ResponseEntity<Boolean> save(@RequestBody HRContractDTO hrcontractdto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrcontractService.save(hrcontractMapping.toDomain(hrcontractdto)));
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdtos),'iBizHumanResources-HRContract-Save')")
    @ApiOperation(value = "批量保存合同信息", tags = {"合同信息" },  notes = "批量保存合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrcontracts/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HRContractDTO> hrcontractdtos) {
        hrcontractService.saveBatch(hrcontractMapping.toDomain(hrcontractdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "获取执行中", tags = {"合同信息" } ,notes = "获取执行中")
    @RequestMapping(method= RequestMethod.GET , value="/hrcontracts/fetchactive")
	public ResponseEntity<List<HRContractDTO>> fetchActive(HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchActive(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "查询执行中", tags = {"合同信息" } ,notes = "查询执行中")
    @RequestMapping(method= RequestMethod.POST , value="/hrcontracts/searchactive")
	public ResponseEntity<Page<HRContractDTO>> searchActive(@RequestBody HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"合同信息" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrcontracts/fetchdefault")
	public ResponseEntity<List<HRContractDTO>> fetchDefault(HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchDefault(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"合同信息" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrcontracts/searchdefault")
	public ResponseEntity<Page<HRContractDTO>> searchDefault(@RequestBody HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchWaitSign-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "获取待续签", tags = {"合同信息" } ,notes = "获取待续签")
    @RequestMapping(method= RequestMethod.GET , value="/hrcontracts/fetchwaitsign")
	public ResponseEntity<List<HRContractDTO>> fetchWaitSign(HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchWaitSign(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchWaitSign-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "查询待续签", tags = {"合同信息" } ,notes = "查询待续签")
    @RequestMapping(method= RequestMethod.POST , value="/hrcontracts/searchwaitsign")
	public ResponseEntity<Page<HRContractDTO>> searchWaitSign(@RequestBody HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchWaitSign(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchWaitStop-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "获取待终止", tags = {"合同信息" } ,notes = "获取待终止")
    @RequestMapping(method= RequestMethod.GET , value="/hrcontracts/fetchwaitstop")
	public ResponseEntity<List<HRContractDTO>> fetchWaitStop(HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchWaitStop(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchWaitStop-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "查询待终止", tags = {"合同信息" } ,notes = "查询待终止")
    @RequestMapping(method= RequestMethod.POST , value="/hrcontracts/searchwaitstop")
	public ResponseEntity<Page<HRContractDTO>> searchWaitStop(@RequestBody HRContractSearchContext context) {
        Page<HRContract> domains = hrcontractService.searchWaitStop(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdto),'iBizHumanResources-HRContract-Create')")
    @ApiOperation(value = "根据员工建立合同信息", tags = {"合同信息" },  notes = "根据员工建立合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcontracts")
    @Transactional
    public ResponseEntity<HRContractDTO> createByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractDTO hrcontractdto) {
        HRContract domain = hrcontractMapping.toDomain(hrcontractdto);
        domain.setHremployeeid(hremployee_id);
		hrcontractService.create(domain);
        HRContractDTO dto = hrcontractMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdtos),'iBizHumanResources-HRContract-Create')")
    @ApiOperation(value = "根据员工批量建立合同信息", tags = {"合同信息" },  notes = "根据员工批量建立合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcontracts/batch")
    public ResponseEntity<Boolean> createBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRContractDTO> hrcontractdtos) {
        List<HRContract> domainlist=hrcontractMapping.toDomain(hrcontractdtos);
        for(HRContract domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrcontractService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrcontract" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrcontractService.get(#hrcontract_id),'iBizHumanResources-HRContract-Update')")
    @ApiOperation(value = "根据员工更新合同信息", tags = {"合同信息" },  notes = "根据员工更新合同信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrcontracts/{hrcontract_id}")
    @Transactional
    public ResponseEntity<HRContractDTO> updateByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrcontract_id") String hrcontract_id, @RequestBody HRContractDTO hrcontractdto) {
        HRContract domain = hrcontractMapping.toDomain(hrcontractdto);
        domain.setHremployeeid(hremployee_id);
        domain.setHrcontractid(hrcontract_id);
		hrcontractService.update(domain);
        HRContractDTO dto = hrcontractMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrcontractService.getHrcontractByEntities(this.hrcontractMapping.toDomain(#hrcontractdtos)),'iBizHumanResources-HRContract-Update')")
    @ApiOperation(value = "根据员工批量更新合同信息", tags = {"合同信息" },  notes = "根据员工批量更新合同信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrcontracts/batch")
    public ResponseEntity<Boolean> updateBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRContractDTO> hrcontractdtos) {
        List<HRContract> domainlist=hrcontractMapping.toDomain(hrcontractdtos);
        for(HRContract domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrcontractService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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

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

    @PostAuthorize("hasPermission(this.hrcontractMapping.toDomain(returnObject.body),'iBizHumanResources-HRContract-Get')")
    @ApiOperation(value = "根据员工获取合同信息", tags = {"合同信息" },  notes = "根据员工获取合同信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrcontracts/{hrcontract_id}")
    public ResponseEntity<HRContractDTO> getByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrcontract_id") String hrcontract_id) {
        HRContract domain = hrcontractService.get(hrcontract_id);
        HRContractDTO dto = hrcontractMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据员工获取合同信息草稿", tags = {"合同信息" },  notes = "根据员工获取合同信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrcontracts/getdraft")
    public ResponseEntity<HRContractDTO> getDraftByHREmployee(@PathVariable("hremployee_id") String hremployee_id) {
        HRContract domain = new HRContract();
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrcontractMapping.toDto(hrcontractService.getDraft(domain)));
    }

    @ApiOperation(value = "根据员工检查合同信息", tags = {"合同信息" },  notes = "根据员工检查合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcontracts/checkkey")
    public ResponseEntity<Boolean> checkKeyByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractDTO hrcontractdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrcontractService.checkKey(hrcontractMapping.toDomain(hrcontractdto)));
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdto),'iBizHumanResources-HRContract-Save')")
    @ApiOperation(value = "根据员工保存合同信息", tags = {"合同信息" },  notes = "根据员工保存合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcontracts/save")
    public ResponseEntity<Boolean> saveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractDTO hrcontractdto) {
        HRContract domain = hrcontractMapping.toDomain(hrcontractdto);
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrcontractService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrcontractMapping.toDomain(#hrcontractdtos),'iBizHumanResources-HRContract-Save')")
    @ApiOperation(value = "根据员工批量保存合同信息", tags = {"合同信息" },  notes = "根据员工批量保存合同信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrcontracts/savebatch")
    public ResponseEntity<Boolean> saveBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRContractDTO> hrcontractdtos) {
        List<HRContract> domainlist=hrcontractMapping.toDomain(hrcontractdtos);
        for(HRContract domain:domainlist){
             domain.setHremployeeid(hremployee_id);
        }
        hrcontractService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工获取执行中", tags = {"合同信息" } ,notes = "根据员工获取执行中")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcontracts/fetchactive")
	public ResponseEntity<List<HRContractDTO>> fetchHRContractActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchActive(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchActive-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工查询执行中", tags = {"合同信息" } ,notes = "根据员工查询执行中")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcontracts/searchactive")
	public ResponseEntity<Page<HRContractDTO>> searchHRContractActiveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchActive(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工获取DEFAULT", tags = {"合同信息" } ,notes = "根据员工获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcontracts/fetchdefault")
	public ResponseEntity<List<HRContractDTO>> fetchHRContractDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchDefault(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工查询DEFAULT", tags = {"合同信息" } ,notes = "根据员工查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcontracts/searchdefault")
	public ResponseEntity<Page<HRContractDTO>> searchHRContractDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchWaitSign-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工获取待续签", tags = {"合同信息" } ,notes = "根据员工获取待续签")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcontracts/fetchwaitsign")
	public ResponseEntity<List<HRContractDTO>> fetchHRContractWaitSignByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchWaitSign(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchWaitSign-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工查询待续签", tags = {"合同信息" } ,notes = "根据员工查询待续签")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcontracts/searchwaitsign")
	public ResponseEntity<Page<HRContractDTO>> searchHRContractWaitSignByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchWaitSign(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRContract-searchWaitStop-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工获取待终止", tags = {"合同信息" } ,notes = "根据员工获取待终止")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrcontracts/fetchwaitstop")
	public ResponseEntity<List<HRContractDTO>> fetchHRContractWaitStopByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchWaitStop(context) ;
        List<HRContractDTO> list = hrcontractMapping.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-HRContract-searchWaitStop-all') and hasPermission(#context,'iBizHumanResources-HRContract-Get')")
	@ApiOperation(value = "根据员工查询待终止", tags = {"合同信息" } ,notes = "根据员工查询待终止")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrcontracts/searchwaitstop")
	public ResponseEntity<Page<HRContractDTO>> searchHRContractWaitStopByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRContractSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRContract> domains = hrcontractService.searchWaitStop(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrcontractMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

