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.HRTechnicalTitle;
import cn.ibizlab.humanresource.core.humanresource.service.IHRTechnicalTitleService;
import cn.ibizlab.humanresource.core.humanresource.filter.HRTechnicalTitleSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"职称信息" })
@RestController("HRApi-hrtechnicaltitle")
@RequestMapping("")
public class HRTechnicalTitleResource {

    @Autowired
    public IHRTechnicalTitleService hrtechnicaltitleService;

    @Autowired
    @Lazy
    public HRTechnicalTitleMapping hrtechnicaltitleMapping;

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledto),'iBizHumanResources-HRTechnicalTitle-Create')")
    @ApiOperation(value = "新建职称信息", tags = {"职称信息" },  notes = "新建职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtechnicaltitles")
    @Transactional
    public ResponseEntity<HRTechnicalTitleDTO> create(@RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        HRTechnicalTitle domain = hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto);
		hrtechnicaltitleService.create(domain);
        HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos),'iBizHumanResources-HRTechnicalTitle-Create')")
    @ApiOperation(value = "批量新建职称信息", tags = {"职称信息" },  notes = "批量新建职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtechnicaltitles/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        hrtechnicaltitleService.createBatch(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtechnicaltitle" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtechnicaltitleService.get(#hrtechnicaltitle_id),'iBizHumanResources-HRTechnicalTitle-Update')")
    @ApiOperation(value = "更新职称信息", tags = {"职称信息" },  notes = "更新职称信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrtechnicaltitles/{hrtechnicaltitle_id}")
    @Transactional
    public ResponseEntity<HRTechnicalTitleDTO> update(@PathVariable("hrtechnicaltitle_id") String hrtechnicaltitle_id, @RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
		HRTechnicalTitle domain  = hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto);
        domain .setHrtechnicaltitleid(hrtechnicaltitle_id);
		hrtechnicaltitleService.update(domain );
		HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleService.getHrtechnicaltitleByEntities(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos)),'iBizHumanResources-HRTechnicalTitle-Update')")
    @ApiOperation(value = "批量更新职称信息", tags = {"职称信息" },  notes = "批量更新职称信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrtechnicaltitles/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        hrtechnicaltitleService.updateBatch(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleService.get(#hrtechnicaltitle_id),'iBizHumanResources-HRTechnicalTitle-Remove')")
    @ApiOperation(value = "删除职称信息", tags = {"职称信息" },  notes = "删除职称信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrtechnicaltitles/{hrtechnicaltitle_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrtechnicaltitle_id") String hrtechnicaltitle_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleService.remove(hrtechnicaltitle_id));
    }

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

    @PostAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(returnObject.body),'iBizHumanResources-HRTechnicalTitle-Get')")
    @ApiOperation(value = "获取职称信息", tags = {"职称信息" },  notes = "获取职称信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrtechnicaltitles/{hrtechnicaltitle_id}")
    public ResponseEntity<HRTechnicalTitleDTO> get(@PathVariable("hrtechnicaltitle_id") String hrtechnicaltitle_id) {
        HRTechnicalTitle domain = hrtechnicaltitleService.get(hrtechnicaltitle_id);
        HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取职称信息草稿", tags = {"职称信息" },  notes = "获取职称信息草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrtechnicaltitles/getdraft")
    public ResponseEntity<HRTechnicalTitleDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleMapping.toDto(hrtechnicaltitleService.getDraft(new HRTechnicalTitle())));
    }

    @ApiOperation(value = "检查职称信息", tags = {"职称信息" },  notes = "检查职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtechnicaltitles/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleService.checkKey(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto)));
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledto),'iBizHumanResources-HRTechnicalTitle-Save')")
    @ApiOperation(value = "保存职称信息", tags = {"职称信息" },  notes = "保存职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtechnicaltitles/save")
    public ResponseEntity<Boolean> save(@RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleService.save(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto)));
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos),'iBizHumanResources-HRTechnicalTitle-Save')")
    @ApiOperation(value = "批量保存职称信息", tags = {"职称信息" },  notes = "批量保存职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrtechnicaltitles/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        hrtechnicaltitleService.saveBatch(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"职称信息" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrtechnicaltitles/fetchdefault")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchDefault(HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchDefault(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"职称信息" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrtechnicaltitles/searchdefault")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchDefault(@RequestBody HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchHigh-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "获取高级", tags = {"职称信息" } ,notes = "获取高级")
    @RequestMapping(method= RequestMethod.GET , value="/hrtechnicaltitles/fetchhigh")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHigh(HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchHigh(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchHigh-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "查询高级", tags = {"职称信息" } ,notes = "查询高级")
    @RequestMapping(method= RequestMethod.POST , value="/hrtechnicaltitles/searchhigh")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHigh(@RequestBody HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchHigh(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchJunior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "获取初级", tags = {"职称信息" } ,notes = "获取初级")
    @RequestMapping(method= RequestMethod.GET , value="/hrtechnicaltitles/fetchjunior")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchJunior(HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchJunior(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchJunior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "查询初级", tags = {"职称信息" } ,notes = "查询初级")
    @RequestMapping(method= RequestMethod.POST , value="/hrtechnicaltitles/searchjunior")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchJunior(@RequestBody HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchJunior(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchMiddle-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "获取中级", tags = {"职称信息" } ,notes = "获取中级")
    @RequestMapping(method= RequestMethod.GET , value="/hrtechnicaltitles/fetchmiddle")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchMiddle(HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchMiddle(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchMiddle-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "查询中级", tags = {"职称信息" } ,notes = "查询中级")
    @RequestMapping(method= RequestMethod.POST , value="/hrtechnicaltitles/searchmiddle")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchMiddle(@RequestBody HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchMiddle(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchSenior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "获取正高级", tags = {"职称信息" } ,notes = "获取正高级")
    @RequestMapping(method= RequestMethod.GET , value="/hrtechnicaltitles/fetchsenior")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchSenior(HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchSenior(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchSenior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "查询正高级", tags = {"职称信息" } ,notes = "查询正高级")
    @RequestMapping(method= RequestMethod.POST , value="/hrtechnicaltitles/searchsenior")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchSenior(@RequestBody HRTechnicalTitleSearchContext context) {
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchSenior(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledto),'iBizHumanResources-HRTechnicalTitle-Create')")
    @ApiOperation(value = "根据员工建立职称信息", tags = {"职称信息" },  notes = "根据员工建立职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtechnicaltitles")
    @Transactional
    public ResponseEntity<HRTechnicalTitleDTO> createByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        HRTechnicalTitle domain = hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto);
        domain.setHremployeeid(hremployee_id);
		hrtechnicaltitleService.create(domain);
        HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos),'iBizHumanResources-HRTechnicalTitle-Create')")
    @ApiOperation(value = "根据员工批量建立职称信息", tags = {"职称信息" },  notes = "根据员工批量建立职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/batch")
    public ResponseEntity<Boolean> createBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        List<HRTechnicalTitle> domainlist=hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos);
        for(HRTechnicalTitle domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrtechnicaltitleService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrtechnicaltitle" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrtechnicaltitleService.get(#hrtechnicaltitle_id),'iBizHumanResources-HRTechnicalTitle-Update')")
    @ApiOperation(value = "根据员工更新职称信息", tags = {"职称信息" },  notes = "根据员工更新职称信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/{hrtechnicaltitle_id}")
    @Transactional
    public ResponseEntity<HRTechnicalTitleDTO> updateByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrtechnicaltitle_id") String hrtechnicaltitle_id, @RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        HRTechnicalTitle domain = hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto);
        domain.setHremployeeid(hremployee_id);
        domain.setHrtechnicaltitleid(hrtechnicaltitle_id);
		hrtechnicaltitleService.update(domain);
        HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleService.getHrtechnicaltitleByEntities(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos)),'iBizHumanResources-HRTechnicalTitle-Update')")
    @ApiOperation(value = "根据员工批量更新职称信息", tags = {"职称信息" },  notes = "根据员工批量更新职称信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/batch")
    public ResponseEntity<Boolean> updateBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        List<HRTechnicalTitle> domainlist=hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos);
        for(HRTechnicalTitle domain:domainlist){
            domain.setHremployeeid(hremployee_id);
        }
        hrtechnicaltitleService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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

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

    @PostAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(returnObject.body),'iBizHumanResources-HRTechnicalTitle-Get')")
    @ApiOperation(value = "根据员工获取职称信息", tags = {"职称信息" },  notes = "根据员工获取职称信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/{hrtechnicaltitle_id}")
    public ResponseEntity<HRTechnicalTitleDTO> getByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @PathVariable("hrtechnicaltitle_id") String hrtechnicaltitle_id) {
        HRTechnicalTitle domain = hrtechnicaltitleService.get(hrtechnicaltitle_id);
        HRTechnicalTitleDTO dto = hrtechnicaltitleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据员工获取职称信息草稿", tags = {"职称信息" },  notes = "根据员工获取职称信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/getdraft")
    public ResponseEntity<HRTechnicalTitleDTO> getDraftByHREmployee(@PathVariable("hremployee_id") String hremployee_id) {
        HRTechnicalTitle domain = new HRTechnicalTitle();
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleMapping.toDto(hrtechnicaltitleService.getDraft(domain)));
    }

    @ApiOperation(value = "根据员工检查职称信息", tags = {"职称信息" },  notes = "根据员工检查职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/checkkey")
    public ResponseEntity<Boolean> checkKeyByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleService.checkKey(hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto)));
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledto),'iBizHumanResources-HRTechnicalTitle-Save')")
    @ApiOperation(value = "根据员工保存职称信息", tags = {"职称信息" },  notes = "根据员工保存职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/save")
    public ResponseEntity<Boolean> saveByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleDTO hrtechnicaltitledto) {
        HRTechnicalTitle domain = hrtechnicaltitleMapping.toDomain(hrtechnicaltitledto);
        domain.setHremployeeid(hremployee_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrtechnicaltitleService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrtechnicaltitleMapping.toDomain(#hrtechnicaltitledtos),'iBizHumanResources-HRTechnicalTitle-Save')")
    @ApiOperation(value = "根据员工批量保存职称信息", tags = {"职称信息" },  notes = "根据员工批量保存职称信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hremployees/{hremployee_id}/hrtechnicaltitles/savebatch")
    public ResponseEntity<Boolean> saveBatchByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody List<HRTechnicalTitleDTO> hrtechnicaltitledtos) {
        List<HRTechnicalTitle> domainlist=hrtechnicaltitleMapping.toDomain(hrtechnicaltitledtos);
        for(HRTechnicalTitle domain:domainlist){
             domain.setHremployeeid(hremployee_id);
        }
        hrtechnicaltitleService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工获取DEFAULT", tags = {"职称信息" } ,notes = "根据员工获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtechnicaltitles/fetchdefault")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHRTechnicalTitleDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchDefault(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工查询DEFAULT", tags = {"职称信息" } ,notes = "根据员工查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtechnicaltitles/searchdefault")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHRTechnicalTitleDefaultByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchHigh-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工获取高级", tags = {"职称信息" } ,notes = "根据员工获取高级")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtechnicaltitles/fetchhigh")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHRTechnicalTitleHighByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchHigh(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchHigh-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工查询高级", tags = {"职称信息" } ,notes = "根据员工查询高级")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtechnicaltitles/searchhigh")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHRTechnicalTitleHighByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchHigh(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchJunior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工获取初级", tags = {"职称信息" } ,notes = "根据员工获取初级")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtechnicaltitles/fetchjunior")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHRTechnicalTitleJuniorByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchJunior(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchJunior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工查询初级", tags = {"职称信息" } ,notes = "根据员工查询初级")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtechnicaltitles/searchjunior")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHRTechnicalTitleJuniorByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchJunior(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchMiddle-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工获取中级", tags = {"职称信息" } ,notes = "根据员工获取中级")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtechnicaltitles/fetchmiddle")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHRTechnicalTitleMiddleByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchMiddle(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchMiddle-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工查询中级", tags = {"职称信息" } ,notes = "根据员工查询中级")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtechnicaltitles/searchmiddle")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHRTechnicalTitleMiddleByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchMiddle(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HRTechnicalTitle-searchSenior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工获取正高级", tags = {"职称信息" } ,notes = "根据员工获取正高级")
    @RequestMapping(method= RequestMethod.GET , value="/hremployees/{hremployee_id}/hrtechnicaltitles/fetchsenior")
	public ResponseEntity<List<HRTechnicalTitleDTO>> fetchHRTechnicalTitleSeniorByHREmployee(@PathVariable("hremployee_id") String hremployee_id,HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchSenior(context) ;
        List<HRTechnicalTitleDTO> list = hrtechnicaltitleMapping.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-HRTechnicalTitle-searchSenior-all') and hasPermission(#context,'iBizHumanResources-HRTechnicalTitle-Get')")
	@ApiOperation(value = "根据员工查询正高级", tags = {"职称信息" } ,notes = "根据员工查询正高级")
    @RequestMapping(method= RequestMethod.POST , value="/hremployees/{hremployee_id}/hrtechnicaltitles/searchsenior")
	public ResponseEntity<Page<HRTechnicalTitleDTO>> searchHRTechnicalTitleSeniorByHREmployee(@PathVariable("hremployee_id") String hremployee_id, @RequestBody HRTechnicalTitleSearchContext context) {
        context.setN_hremployeeid_eq(hremployee_id);
        Page<HRTechnicalTitle> domains = hrtechnicaltitleService.searchSenior(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrtechnicaltitleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

