package cn.ibizlab.humanresource.hrapi.rest;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import cn.ibizlab.humanresource.hrapi.dto.*;
import cn.ibizlab.humanresource.hrapi.mapping.*;
import cn.ibizlab.humanresource.core.base.domain.HROrgContact;
import cn.ibizlab.humanresource.core.base.service.IHROrgContactService;
import cn.ibizlab.humanresource.core.base.filter.HROrgContactSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"组织联系信息" })
@RestController("HRApi-hrorgcontact")
@RequestMapping("")
public class HROrgContactResource {

    @Autowired
    public IHROrgContactService hrorgcontactService;

    @Autowired
    @Lazy
    public HROrgContactMapping hrorgcontactMapping;

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "新建组织联系信息", tags = {"组织联系信息" },  notes = "新建组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgcontacts")
    @Transactional
    public ResponseEntity<HROrgContactDTO> create(@RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
		hrorgcontactService.create(domain);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "批量新建组织联系信息", tags = {"组织联系信息" },  notes = "批量新建组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgcontacts/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        hrorgcontactService.createBatch(hrorgcontactMapping.toDomain(hrorgcontactdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgcontact" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "更新组织联系信息", tags = {"组织联系信息" },  notes = "更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<HROrgContactDTO> update(@PathVariable("hrorgcontact_id") String hrorgcontact_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
		HROrgContact domain  = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain .setHrorgcontactid(hrorgcontact_id);
		hrorgcontactService.update(domain );
		HROrgContactDTO dto = hrorgcontactMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByEntities(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos)),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "批量更新组织联系信息", tags = {"组织联系信息" },  notes = "批量更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorgcontacts/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        hrorgcontactService.updateBatch(hrorgcontactMapping.toDomain(hrorgcontactdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "删除组织联系信息", tags = {"组织联系信息" },  notes = "删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrorgcontact_id") String hrorgcontact_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.remove(hrorgcontact_id));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByIds(#ids),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "批量删除组织联系信息", tags = {"组织联系信息" },  notes = "批量删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorgcontacts/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        hrorgcontactService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgContact-Get')")
    @ApiOperation(value = "获取组织联系信息", tags = {"组织联系信息" },  notes = "获取组织联系信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrorgcontacts/{hrorgcontact_id}")
    public ResponseEntity<HROrgContactDTO> get(@PathVariable("hrorgcontact_id") String hrorgcontact_id) {
        HROrgContact domain = hrorgcontactService.get(hrorgcontact_id);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取组织联系信息草稿", tags = {"组织联系信息" },  notes = "获取组织联系信息草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrorgcontacts/getdraft")
    public ResponseEntity<HROrgContactDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactMapping.toDto(hrorgcontactService.getDraft(new HROrgContact())));
    }

    @ApiOperation(value = "检查组织联系信息", tags = {"组织联系信息" },  notes = "检查组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgcontacts/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HROrgContactDTO hrorgcontactdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.checkKey(hrorgcontactMapping.toDomain(hrorgcontactdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "保存组织联系信息", tags = {"组织联系信息" },  notes = "保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgcontacts/save")
    public ResponseEntity<Boolean> save(@RequestBody HROrgContactDTO hrorgcontactdto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.save(hrorgcontactMapping.toDomain(hrorgcontactdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "批量保存组织联系信息", tags = {"组织联系信息" },  notes = "批量保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgcontacts/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        hrorgcontactService.saveBatch(hrorgcontactMapping.toDomain(hrorgcontactdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "获取DEFAULT", tags = {"组织联系信息" } ,notes = "获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrorgcontacts/fetchdefault")
	public ResponseEntity<List<HROrgContactDTO>> fetchDefault(HROrgContactSearchContext context) {
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
        List<HROrgContactDTO> list = hrorgcontactMapping.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-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "查询DEFAULT", tags = {"组织联系信息" } ,notes = "查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrorgcontacts/searchdefault")
	public ResponseEntity<Page<HROrgContactDTO>> searchDefault(@RequestBody HROrgContactSearchContext context) {
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrorgcontactMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "根据法人建立组织联系信息", tags = {"组织联系信息" },  notes = "根据法人建立组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgcontacts")
    @Transactional
    public ResponseEntity<HROrgContactDTO> createByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hrlegal_id);
		hrorgcontactService.create(domain);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "根据法人批量建立组织联系信息", tags = {"组织联系信息" },  notes = "根据法人批量建立组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> createBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
            domain.setHrorganizationid(hrlegal_id);
        }
        hrorgcontactService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgcontact" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "根据法人更新组织联系信息", tags = {"组织联系信息" },  notes = "根据法人更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<HROrgContactDTO> updateByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hrlegal_id);
        domain.setHrorgcontactid(hrorgcontact_id);
		hrorgcontactService.update(domain);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByEntities(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos)),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "根据法人批量更新组织联系信息", tags = {"组织联系信息" },  notes = "根据法人批量更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> updateBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
            domain.setHrorganizationid(hrlegal_id);
        }
        hrorgcontactService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "根据法人删除组织联系信息", tags = {"组织联系信息" },  notes = "根据法人删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.remove(hrorgcontact_id));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByIds(#ids),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "根据法人批量删除组织联系信息", tags = {"组织联系信息" },  notes = "根据法人批量删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> removeBatchByHRLegal(@RequestBody List<String> ids) {
        hrorgcontactService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgContact-Get')")
    @ApiOperation(value = "根据法人获取组织联系信息", tags = {"组织联系信息" },  notes = "根据法人获取组织联系信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/{hrorgcontact_id}")
    public ResponseEntity<HROrgContactDTO> getByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id) {
        HROrgContact domain = hrorgcontactService.get(hrorgcontact_id);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据法人获取组织联系信息草稿", tags = {"组织联系信息" },  notes = "根据法人获取组织联系信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/getdraft")
    public ResponseEntity<HROrgContactDTO> getDraftByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id) {
        HROrgContact domain = new HROrgContact();
        domain.setHrorganizationid(hrlegal_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactMapping.toDto(hrorgcontactService.getDraft(domain)));
    }

    @ApiOperation(value = "根据法人检查组织联系信息", tags = {"组织联系信息" },  notes = "根据法人检查组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/checkkey")
    public ResponseEntity<Boolean> checkKeyByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.checkKey(hrorgcontactMapping.toDomain(hrorgcontactdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "根据法人保存组织联系信息", tags = {"组织联系信息" },  notes = "根据法人保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/save")
    public ResponseEntity<Boolean> saveByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hrlegal_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "根据法人批量保存组织联系信息", tags = {"组织联系信息" },  notes = "根据法人批量保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgcontacts/savebatch")
    public ResponseEntity<Boolean> saveBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
             domain.setHrorganizationid(hrlegal_id);
        }
        hrorgcontactService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "根据法人获取DEFAULT", tags = {"组织联系信息" } ,notes = "根据法人获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrlegals/{hrlegal_id}/hrorgcontacts/fetchdefault")
	public ResponseEntity<List<HROrgContactDTO>> fetchHROrgContactDefaultByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id,HROrgContactSearchContext context) {
        context.setN_hrorganizationid_eq(hrlegal_id);
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
        List<HROrgContactDTO> list = hrorgcontactMapping.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-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "根据法人查询DEFAULT", tags = {"组织联系信息" } ,notes = "根据法人查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrlegals/{hrlegal_id}/hrorgcontacts/searchdefault")
	public ResponseEntity<Page<HROrgContactDTO>> searchHROrgContactDefaultByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgContactSearchContext context) {
        context.setN_hrorganizationid_eq(hrlegal_id);
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrorgcontactMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "根据运营单位建立组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位建立组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts")
    @Transactional
    public ResponseEntity<HROrgContactDTO> createByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hroperationunit_id);
		hrorgcontactService.create(domain);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Create')")
    @ApiOperation(value = "根据运营单位批量建立组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位批量建立组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> createBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
            domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgcontactService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgcontact" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "根据运营单位更新组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<HROrgContactDTO> updateByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hroperationunit_id);
        domain.setHrorgcontactid(hrorgcontact_id);
		hrorgcontactService.update(domain);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByEntities(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos)),'iBizHumanResources-HROrgContact-Update')")
    @ApiOperation(value = "根据运营单位批量更新组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位批量更新组织联系信息")
	@RequestMapping(method = RequestMethod.PUT, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> updateBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
            domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgcontactService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.get(#hrorgcontact_id),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "根据运营单位删除组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/{hrorgcontact_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.remove(hrorgcontact_id));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactService.getHrorgcontactByIds(#ids),'iBizHumanResources-HROrgContact-Remove')")
    @ApiOperation(value = "根据运营单位批量删除组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位批量删除组织联系信息")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/batch")
    public ResponseEntity<Boolean> removeBatchByHROperationUnit(@RequestBody List<String> ids) {
        hrorgcontactService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgContact-Get')")
    @ApiOperation(value = "根据运营单位获取组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位获取组织联系信息")
	@RequestMapping(method = RequestMethod.GET, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/{hrorgcontact_id}")
    public ResponseEntity<HROrgContactDTO> getByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgcontact_id") String hrorgcontact_id) {
        HROrgContact domain = hrorgcontactService.get(hrorgcontact_id);
        HROrgContactDTO dto = hrorgcontactMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据运营单位获取组织联系信息草稿", tags = {"组织联系信息" },  notes = "根据运营单位获取组织联系信息草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/getdraft")
    public ResponseEntity<HROrgContactDTO> getDraftByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id) {
        HROrgContact domain = new HROrgContact();
        domain.setHrorganizationid(hroperationunit_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactMapping.toDto(hrorgcontactService.getDraft(domain)));
    }

    @ApiOperation(value = "根据运营单位检查组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位检查组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/checkkey")
    public ResponseEntity<Boolean> checkKeyByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.checkKey(hrorgcontactMapping.toDomain(hrorgcontactdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdto),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "根据运营单位保存组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/save")
    public ResponseEntity<Boolean> saveByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgContactDTO hrorgcontactdto) {
        HROrgContact domain = hrorgcontactMapping.toDomain(hrorgcontactdto);
        domain.setHrorganizationid(hroperationunit_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgcontactService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrorgcontactMapping.toDomain(#hrorgcontactdtos),'iBizHumanResources-HROrgContact-Save')")
    @ApiOperation(value = "根据运营单位批量保存组织联系信息", tags = {"组织联系信息" },  notes = "根据运营单位批量保存组织联系信息")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgcontacts/savebatch")
    public ResponseEntity<Boolean> saveBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgContactDTO> hrorgcontactdtos) {
        List<HROrgContact> domainlist=hrorgcontactMapping.toDomain(hrorgcontactdtos);
        for(HROrgContact domain:domainlist){
             domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgcontactService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "根据运营单位获取DEFAULT", tags = {"组织联系信息" } ,notes = "根据运营单位获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hroperationunits/{hroperationunit_id}/hrorgcontacts/fetchdefault")
	public ResponseEntity<List<HROrgContactDTO>> fetchHROrgContactDefaultByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id,HROrgContactSearchContext context) {
        context.setN_hrorganizationid_eq(hroperationunit_id);
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
        List<HROrgContactDTO> list = hrorgcontactMapping.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-HROrgContact-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgContact-Get')")
	@ApiOperation(value = "根据运营单位查询DEFAULT", tags = {"组织联系信息" } ,notes = "根据运营单位查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hroperationunits/{hroperationunit_id}/hrorgcontacts/searchdefault")
	public ResponseEntity<Page<HROrgContactDTO>> searchHROrgContactDefaultByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgContactSearchContext context) {
        context.setN_hrorganizationid_eq(hroperationunit_id);
        Page<HROrgContact> domains = hrorgcontactService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrorgcontactMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

