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.pcm.domain.HRTransferApply;
import cn.ibizlab.humanresource.core.pcm.service.IHRTransferApplyService;
import cn.ibizlab.humanresource.core.pcm.filter.HRTransferApplySearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"调动申请" })
@RestController("HRApi-hrtransferapply")
@RequestMapping("")
public class HRTransferApplyResource {

    @Autowired
    public IHRTransferApplyService hrtransferapplyService;

    @Autowired
    @Lazy
    public HRTransferApplyMapping hrtransferapplyMapping;

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "新建调动申请", tags = {"调动申请" },  notes = "新建调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtransferapplies")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> create(@RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
		hrtransferapplyService.create(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "批量新建调动申请", tags = {"调动申请" },  notes = "批量新建调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtransferapplies/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        hrtransferapplyService.createBatch(hrtransferapplyMapping.toDomain(hrtransferapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtransferapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "更新调动申请", tags = {"调动申请" },  notes = "更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> update(@PathVariable("hrtransferapply_id") String hrtransferapply_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
		HRTransferApply domain  = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain .setHrtransferapplyid(hrtransferapply_id);
		hrtransferapplyService.update(domain );
		HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByEntities(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos)),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "批量更新调动申请", tags = {"调动申请" },  notes = "批量更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrtransferapplies/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        hrtransferapplyService.updateBatch(hrtransferapplyMapping.toDomain(hrtransferapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "删除调动申请", tags = {"调动申请" },  notes = "删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrtransferapply_id") String hrtransferapply_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.remove(hrtransferapply_id));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByIds(#ids),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "批量删除调动申请", tags = {"调动申请" },  notes = "批量删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrtransferapplies/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        hrtransferapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(returnObject.body),'iBizHumanResources-HRTransferApply-Get')")
    @ApiOperation(value = "获取调动申请", tags = {"调动申请" },  notes = "获取调动申请")
	@RequestMapping(method = RequestMethod.GET, value = "/hrtransferapplies/{hrtransferapply_id}")
    public ResponseEntity<HRTransferApplyDTO> get(@PathVariable("hrtransferapply_id") String hrtransferapply_id) {
        HRTransferApply domain = hrtransferapplyService.get(hrtransferapply_id);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取调动申请草稿", tags = {"调动申请" },  notes = "获取调动申请草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrtransferapplies/getdraft")
    public ResponseEntity<HRTransferApplyDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyMapping.toDto(hrtransferapplyService.getDraft(new HRTransferApply())));
    }

    @ApiOperation(value = "检查调动申请", tags = {"调动申请" },  notes = "检查调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtransferapplies/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HRTransferApplyDTO hrtransferapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.checkKey(hrtransferapplyMapping.toDomain(hrtransferapplydto)));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "保存调动申请", tags = {"调动申请" },  notes = "保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtransferapplies/save")
    public ResponseEntity<Boolean> save(@RequestBody HRTransferApplyDTO hrtransferapplydto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.save(hrtransferapplyMapping.toDomain(hrtransferapplydto)));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "批量保存调动申请", tags = {"调动申请" },  notes = "批量保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtransferapplies/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        hrtransferapplyService.saveBatch(hrtransferapplyMapping.toDomain(hrtransferapplydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"调动申请" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrtransferapplies/fetchdefault")
	public ResponseEntity<List<HRTransferApplyDTO>> fetchDefault(HRTransferApplySearchContext context) {
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
        List<HRTransferApplyDTO> list = hrtransferapplyMapping.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-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"调动申请" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrtransferapplies/searchdefault")
	public ResponseEntity<Page<HRTransferApplyDTO>> searchDefault(@RequestBody HRTransferApplySearchContext context) {
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtransferapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据组织建立调动申请", tags = {"调动申请" },  notes = "根据组织建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> createByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrorganizationid2(hrorganization_id);
		hrtransferapplyService.create(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据组织批量建立调动申请", tags = {"调动申请" },  notes = "根据组织批量建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> createBatchByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHrorganizationid2(hrorganization_id);
        }
        hrtransferapplyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtransferapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据组织更新调动申请", tags = {"调动申请" },  notes = "根据组织更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> updateByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrorganizationid2(hrorganization_id);
        domain.setHrtransferapplyid(hrtransferapply_id);
		hrtransferapplyService.update(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByEntities(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos)),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据组织批量更新调动申请", tags = {"调动申请" },  notes = "根据组织批量更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> updateBatchByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHrorganizationid2(hrorganization_id);
        }
        hrtransferapplyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据组织删除调动申请", tags = {"调动申请" },  notes = "根据组织删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.remove(hrtransferapply_id));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByIds(#ids),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据组织批量删除调动申请", tags = {"调动申请" },  notes = "根据组织批量删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> removeBatchByHROrganization(@RequestBody List<String> ids) {
        hrtransferapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(returnObject.body),'iBizHumanResources-HRTransferApply-Get')")
    @ApiOperation(value = "根据组织获取调动申请", tags = {"调动申请" },  notes = "根据组织获取调动申请")
	@RequestMapping(method = RequestMethod.GET, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/{hrtransferapply_id}")
    public ResponseEntity<HRTransferApplyDTO> getByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
        HRTransferApply domain = hrtransferapplyService.get(hrtransferapply_id);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据组织获取调动申请草稿", tags = {"调动申请" },  notes = "根据组织获取调动申请草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/getdraft")
    public ResponseEntity<HRTransferApplyDTO> getDraftByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id) {
        HRTransferApply domain = new HRTransferApply();
        domain.setHrorganizationid2(hrorganization_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyMapping.toDto(hrtransferapplyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据组织检查调动申请", tags = {"调动申请" },  notes = "根据组织检查调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/checkkey")
    public ResponseEntity<Boolean> checkKeyByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.checkKey(hrtransferapplyMapping.toDomain(hrtransferapplydto)));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据组织保存调动申请", tags = {"调动申请" },  notes = "根据组织保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/save")
    public ResponseEntity<Boolean> saveByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrorganizationid2(hrorganization_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据组织批量保存调动申请", tags = {"调动申请" },  notes = "根据组织批量保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorganizations/{hrorganization_id}/hrtransferapplies/savebatch")
    public ResponseEntity<Boolean> saveBatchByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
             domain.setHrorganizationid2(hrorganization_id);
        }
        hrtransferapplyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据组织获取DEFAULT", tags = {"调动申请" } ,notes = "根据组织获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrorganizations/{hrorganization_id}/hrtransferapplies/fetchdefault")
	public ResponseEntity<List<HRTransferApplyDTO>> fetchHRTransferApplyDefaultByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id,HRTransferApplySearchContext context) {
        context.setN_hrorganizationid2_eq(hrorganization_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
        List<HRTransferApplyDTO> list = hrtransferapplyMapping.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-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据组织查询DEFAULT", tags = {"调动申请" } ,notes = "根据组织查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrorganizations/{hrorganization_id}/hrtransferapplies/searchdefault")
	public ResponseEntity<Page<HRTransferApplyDTO>> searchHRTransferApplyDefaultByHROrganization(@PathVariable("hrorganization_id") String hrorganization_id, @RequestBody HRTransferApplySearchContext context) {
        context.setN_hrorganizationid2_eq(hrorganization_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtransferapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据员工建立调动申请", tags = {"调动申请" },  notes = "根据员工建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtransferapplies")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> createByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHremployeeid(hremployee_id);
		hrtransferapplyService.create(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据员工批量建立调动申请", tags = {"调动申请" },  notes = "根据员工批量建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> createBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrtransferapplyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtransferapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据员工更新调动申请", tags = {"调动申请" },  notes = "根据员工更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> updateByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHremployeeid(hremployee_id);
        domain.setHrtransferapplyid(hrtransferapply_id);
		hrtransferapplyService.update(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByEntities(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos)),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据员工批量更新调动申请", tags = {"调动申请" },  notes = "根据员工批量更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> updateBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrtransferapplyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据员工删除调动申请", tags = {"调动申请" },  notes = "根据员工删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hremployees/{hremployee_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.remove(hrtransferapply_id));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByIds(#ids),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据员工批量删除调动申请", tags = {"调动申请" },  notes = "根据员工批量删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hremployees/{hremployee_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> removeBatchByHREmployee(@RequestBody List<String> ids) {
        hrtransferapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(returnObject.body),'iBizHumanResources-HRTransferApply-Get')")
    @ApiOperation(value = "根据员工获取调动申请", tags = {"调动申请" },  notes = "根据员工获取调动申请")
	@RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrtransferapplies/{hrtransferapply_id}")
    public ResponseEntity<HRTransferApplyDTO> getByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
        HRTransferApply domain = hrtransferapplyService.get(hrtransferapply_id);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据员工获取调动申请草稿", tags = {"调动申请" },  notes = "根据员工获取调动申请草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrtransferapplies/getdraft")
    public ResponseEntity<HRTransferApplyDTO> getDraftByHREmployee(@PathVariable("hremployee_id") String hremployee_id) {
        HRTransferApply domain = new HRTransferApply();
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyMapping.toDto(hrtransferapplyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据员工检查调动申请", tags = {"调动申请" },  notes = "根据员工检查调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtransferapplies/checkkey")
    public ResponseEntity<Boolean> checkKeyByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.checkKey(hrtransferapplyMapping.toDomain(hrtransferapplydto)));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据员工保存调动申请", tags = {"调动申请" },  notes = "根据员工保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtransferapplies/save")
    public ResponseEntity<Boolean> saveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据员工批量保存调动申请", tags = {"调动申请" },  notes = "根据员工批量保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtransferapplies/savebatch")
    public ResponseEntity<Boolean> saveBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
             domain.setHremployeeid(hremployee_id);
        }
        hrtransferapplyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据员工获取DEFAULT", tags = {"调动申请" } ,notes = "根据员工获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtransferapplies/fetchdefault")
	public ResponseEntity<List<HRTransferApplyDTO>> fetchHRTransferApplyDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTransferApplySearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
        List<HRTransferApplyDTO> list = hrtransferapplyMapping.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-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据员工查询DEFAULT", tags = {"调动申请" } ,notes = "根据员工查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtransferapplies/searchdefault")
	public ResponseEntity<Page<HRTransferApplyDTO>> searchHRTransferApplyDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTransferApplySearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtransferapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据职位建立调动申请", tags = {"调动申请" },  notes = "根据职位建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrposts/{hrpost_id}/hrtransferapplies")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> createByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrpostid2(hrpost_id);
		hrtransferapplyService.create(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Create')")
    @ApiOperation(value = "根据职位批量建立调动申请", tags = {"调动申请" },  notes = "根据职位批量建立调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrposts/{hrpost_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> createBatchByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHrpostid2(hrpost_id);
        }
        hrtransferapplyService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtransferapply" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据职位更新调动申请", tags = {"调动申请" },  notes = "根据职位更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrposts/{hrpost_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<HRTransferApplyDTO> updateByHRPost(@PathVariable("hrpost_id") String hrpost_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrpostid2(hrpost_id);
        domain.setHrtransferapplyid(hrtransferapply_id);
		hrtransferapplyService.update(domain);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByEntities(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos)),'iBizHumanResources-HRTransferApply-Update')")
    @ApiOperation(value = "根据职位批量更新调动申请", tags = {"调动申请" },  notes = "根据职位批量更新调动申请")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrposts/{hrpost_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> updateBatchByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
            domain.setHrpostid2(hrpost_id);
        }
        hrtransferapplyService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.get(#hrtransferapply_id),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据职位删除调动申请", tags = {"调动申请" },  notes = "根据职位删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrposts/{hrpost_id}/hrtransferapplies/{hrtransferapply_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHRPost(@PathVariable("hrpost_id") String hrpost_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.remove(hrtransferapply_id));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyService.getHrtransferapplyByIds(#ids),'iBizHumanResources-HRTransferApply-Remove')")
    @ApiOperation(value = "根据职位批量删除调动申请", tags = {"调动申请" },  notes = "根据职位批量删除调动申请")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrposts/{hrpost_id}/hrtransferapplies/batch")
    public ResponseEntity<Boolean> removeBatchByHRPost(@RequestBody List<String> ids) {
        hrtransferapplyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(returnObject.body),'iBizHumanResources-HRTransferApply-Get')")
    @ApiOperation(value = "根据职位获取调动申请", tags = {"调动申请" },  notes = "根据职位获取调动申请")
	@RequestMapping(method = RequestMethod.GET, value = "/hrposts/{hrpost_id}/hrtransferapplies/{hrtransferapply_id}")
    public ResponseEntity<HRTransferApplyDTO> getByHRPost(@PathVariable("hrpost_id") String hrpost_id, @PathVariable("hrtransferapply_id") String hrtransferapply_id) {
        HRTransferApply domain = hrtransferapplyService.get(hrtransferapply_id);
        HRTransferApplyDTO dto = hrtransferapplyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据职位获取调动申请草稿", tags = {"调动申请" },  notes = "根据职位获取调动申请草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hrposts/{hrpost_id}/hrtransferapplies/getdraft")
    public ResponseEntity<HRTransferApplyDTO> getDraftByHRPost(@PathVariable("hrpost_id") String hrpost_id) {
        HRTransferApply domain = new HRTransferApply();
        domain.setHrpostid2(hrpost_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyMapping.toDto(hrtransferapplyService.getDraft(domain)));
    }

    @ApiOperation(value = "根据职位检查调动申请", tags = {"调动申请" },  notes = "根据职位检查调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrposts/{hrpost_id}/hrtransferapplies/checkkey")
    public ResponseEntity<Boolean> checkKeyByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.checkKey(hrtransferapplyMapping.toDomain(hrtransferapplydto)));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydto),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据职位保存调动申请", tags = {"调动申请" },  notes = "根据职位保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrposts/{hrpost_id}/hrtransferapplies/save")
    public ResponseEntity<Boolean> saveByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody HRTransferApplyDTO hrtransferapplydto) {
        HRTransferApply domain = hrtransferapplyMapping.toDomain(hrtransferapplydto);
        domain.setHrpostid2(hrpost_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtransferapplyService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrtransferapplyMapping.toDomain(#hrtransferapplydtos),'iBizHumanResources-HRTransferApply-Save')")
    @ApiOperation(value = "根据职位批量保存调动申请", tags = {"调动申请" },  notes = "根据职位批量保存调动申请")
	@RequestMapping(method = RequestMethod.POST, value = "/hrposts/{hrpost_id}/hrtransferapplies/savebatch")
    public ResponseEntity<Boolean> saveBatchByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody List<HRTransferApplyDTO> hrtransferapplydtos) {
        List<HRTransferApply> domainlist=hrtransferapplyMapping.toDomain(hrtransferapplydtos);
        for(HRTransferApply domain:domainlist){
             domain.setHrpostid2(hrpost_id);
        }
        hrtransferapplyService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据职位获取DEFAULT", tags = {"调动申请" } ,notes = "根据职位获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrposts/{hrpost_id}/hrtransferapplies/fetchdefault")
	public ResponseEntity<List<HRTransferApplyDTO>> fetchHRTransferApplyDefaultByHRPost(@PathVariable("hrpost_id") String hrpost_id,HRTransferApplySearchContext context) {
        context.setN_hrpostid2_eq(hrpost_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
        List<HRTransferApplyDTO> list = hrtransferapplyMapping.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-HRTransferApply-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTransferApply-Get')")
	@ApiOperation(value = "根据职位查询DEFAULT", tags = {"调动申请" } ,notes = "根据职位查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrposts/{hrpost_id}/hrtransferapplies/searchdefault")
	public ResponseEntity<Page<HRTransferApplyDTO>> searchHRTransferApplyDefaultByHRPost(@PathVariable("hrpost_id") String hrpost_id, @RequestBody HRTransferApplySearchContext context) {
        context.setN_hrpostid2_eq(hrpost_id);
        Page<HRTransferApply> domains = hrtransferapplyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtransferapplyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

