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.HROrgAddress;
import cn.ibizlab.humanresource.core.base.service.IHROrgAddressService;
import cn.ibizlab.humanresource.core.base.filter.HROrgAddressSearchContext;
import cn.ibizlab.humanresource.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"组织地址" })
@RestController("HRApi-hrorgaddress")
@RequestMapping("")
public class HROrgAddressResource {

    @Autowired
    public IHROrgAddressService hrorgaddressService;

    @Autowired
    @Lazy
    public HROrgAddressMapping hrorgaddressMapping;

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdto),'iBizHumanResources-HROrgAddress-Create')")
    @ApiOperation(value = "新建组织地址", tags = {"组织地址" },  notes = "新建组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgaddresses")
    @Transactional
    public ResponseEntity<HROrgAddressDTO> create(@RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
		hrorgaddressService.create(domain);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Create')")
    @ApiOperation(value = "批量新建组织地址", tags = {"组织地址" },  notes = "批量新建组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgaddresses/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        hrorgaddressService.createBatch(hrorgaddressMapping.toDomain(hrorgaddressdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgaddress" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "更新组织地址", tags = {"组织地址" },  notes = "更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<HROrgAddressDTO> update(@PathVariable("hrorgaddress_id") String hrorgaddress_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
		HROrgAddress domain  = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain .setHrorgaddressid(hrorgaddress_id);
		hrorgaddressService.update(domain );
		HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.getHrorgaddressByEntities(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos)),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "批量更新组织地址", tags = {"组织地址" },  notes = "批量更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrorgaddresses/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        hrorgaddressService.updateBatch(hrorgaddressMapping.toDomain(hrorgaddressdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Remove')")
    @ApiOperation(value = "删除组织地址", tags = {"组织地址" },  notes = "删除组织地址")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("hrorgaddress_id") String hrorgaddress_id) {
         return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.remove(hrorgaddress_id));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.getHrorgaddressByIds(#ids),'iBizHumanResources-HROrgAddress-Remove')")
    @ApiOperation(value = "批量删除组织地址", tags = {"组织地址" },  notes = "批量删除组织地址")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrorgaddresses/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        hrorgaddressService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgAddress-Get')")
    @ApiOperation(value = "获取组织地址", tags = {"组织地址" },  notes = "获取组织地址")
	@RequestMapping(method = RequestMethod.GET, value = "/hrorgaddresses/{hrorgaddress_id}")
    public ResponseEntity<HROrgAddressDTO> get(@PathVariable("hrorgaddress_id") String hrorgaddress_id) {
        HROrgAddress domain = hrorgaddressService.get(hrorgaddress_id);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取组织地址草稿", tags = {"组织地址" },  notes = "获取组织地址草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/hrorgaddresses/getdraft")
    public ResponseEntity<HROrgAddressDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressMapping.toDto(hrorgaddressService.getDraft(new HROrgAddress())));
    }

    @ApiOperation(value = "检查组织地址", tags = {"组织地址" },  notes = "检查组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgaddresses/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody HROrgAddressDTO hrorgaddressdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.checkKey(hrorgaddressMapping.toDomain(hrorgaddressdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdto),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "保存组织地址", tags = {"组织地址" },  notes = "保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgaddresses/save")
    public ResponseEntity<Boolean> save(@RequestBody HROrgAddressDTO hrorgaddressdto) {
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.save(hrorgaddressMapping.toDomain(hrorgaddressdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "批量保存组织地址", tags = {"组织地址" },  notes = "批量保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrorgaddresses/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        hrorgaddressService.saveBatch(hrorgaddressMapping.toDomain(hrorgaddressdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Create')")
    @ApiOperation(value = "根据法人批量建立组织地址", tags = {"组织地址" },  notes = "根据法人批量建立组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/batch")
    public ResponseEntity<Boolean> createBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
            domain.setHrorganizationid(hrlegal_id);
        }
        hrorgaddressService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgaddress" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "根据法人更新组织地址", tags = {"组织地址" },  notes = "根据法人更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<HROrgAddressDTO> updateByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain.setHrorganizationid(hrlegal_id);
        domain.setHrorgaddressid(hrorgaddress_id);
		hrorgaddressService.update(domain);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.getHrorgaddressByEntities(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos)),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "根据法人批量更新组织地址", tags = {"组织地址" },  notes = "根据法人批量更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/batch")
    public ResponseEntity<Boolean> updateBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
            domain.setHrorganizationid(hrlegal_id);
        }
        hrorgaddressService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Remove')")
    @ApiOperation(value = "根据法人删除组织地址", tags = {"组织地址" },  notes = "根据法人删除组织地址")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.remove(hrorgaddress_id));
    }

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

    @PostAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgAddress-Get')")
    @ApiOperation(value = "根据法人获取组织地址", tags = {"组织地址" },  notes = "根据法人获取组织地址")
	@RequestMapping(method = RequestMethod.GET, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/{hrorgaddress_id}")
    public ResponseEntity<HROrgAddressDTO> getByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id) {
        HROrgAddress domain = hrorgaddressService.get(hrorgaddress_id);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据法人获取组织地址草稿", tags = {"组织地址" },  notes = "根据法人获取组织地址草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/getdraft")
    public ResponseEntity<HROrgAddressDTO> getDraftByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id) {
        HROrgAddress domain = new HROrgAddress();
        domain.setHrorganizationid(hrlegal_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressMapping.toDto(hrorgaddressService.getDraft(domain)));
    }

    @ApiOperation(value = "根据法人检查组织地址", tags = {"组织地址" },  notes = "根据法人检查组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/checkkey")
    public ResponseEntity<Boolean> checkKeyByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.checkKey(hrorgaddressMapping.toDomain(hrorgaddressdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdto),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "根据法人保存组织地址", tags = {"组织地址" },  notes = "根据法人保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/save")
    public ResponseEntity<Boolean> saveByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain.setHrorganizationid(hrlegal_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "根据法人批量保存组织地址", tags = {"组织地址" },  notes = "根据法人批量保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hrlegals/{hrlegal_id}/hrorgaddresses/savebatch")
    public ResponseEntity<Boolean> saveBatchByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
             domain.setHrorganizationid(hrlegal_id);
        }
        hrorgaddressService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROrgAddress-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgAddress-Get')")
	@ApiOperation(value = "根据法人获取DEFAULT", tags = {"组织地址" } ,notes = "根据法人获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hrlegals/{hrlegal_id}/hrorgaddresses/fetchdefault")
	public ResponseEntity<List<HROrgAddressDTO>> fetchHROrgAddressDefaultByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id,HROrgAddressSearchContext context) {
        context.setN_hrorganizationid_eq(hrlegal_id);
        Page<HROrgAddress> domains = hrorgaddressService.searchDefault(context) ;
        List<HROrgAddressDTO> list = hrorgaddressMapping.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-HROrgAddress-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgAddress-Get')")
	@ApiOperation(value = "根据法人查询DEFAULT", tags = {"组织地址" } ,notes = "根据法人查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hrlegals/{hrlegal_id}/hrorgaddresses/searchdefault")
	public ResponseEntity<Page<HROrgAddressDTO>> searchHROrgAddressDefaultByHRLegal(@PathVariable("hrlegal_id") String hrlegal_id, @RequestBody HROrgAddressSearchContext context) {
        context.setN_hrorganizationid_eq(hrlegal_id);
        Page<HROrgAddress> domains = hrorgaddressService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrorgaddressMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdto),'iBizHumanResources-HROrgAddress-Create')")
    @ApiOperation(value = "根据运营单位建立组织地址", tags = {"组织地址" },  notes = "根据运营单位建立组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses")
    @Transactional
    public ResponseEntity<HROrgAddressDTO> createByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain.setHrorganizationid(hroperationunit_id);
		hrorgaddressService.create(domain);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Create')")
    @ApiOperation(value = "根据运营单位批量建立组织地址", tags = {"组织地址" },  notes = "根据运营单位批量建立组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/batch")
    public ResponseEntity<Boolean> createBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
            domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgaddressService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "hrorgaddress" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "根据运营单位更新组织地址", tags = {"组织地址" },  notes = "根据运营单位更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<HROrgAddressDTO> updateByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain.setHrorganizationid(hroperationunit_id);
        domain.setHrorgaddressid(hrorgaddress_id);
		hrorgaddressService.update(domain);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.getHrorgaddressByEntities(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos)),'iBizHumanResources-HROrgAddress-Update')")
    @ApiOperation(value = "根据运营单位批量更新组织地址", tags = {"组织地址" },  notes = "根据运营单位批量更新组织地址")
	@RequestMapping(method = RequestMethod.PUT, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/batch")
    public ResponseEntity<Boolean> updateBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
            domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgaddressService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.hrorgaddressService.get(#hrorgaddress_id),'iBizHumanResources-HROrgAddress-Remove')")
    @ApiOperation(value = "根据运营单位删除组织地址", tags = {"组织地址" },  notes = "根据运营单位删除组织地址")
	@RequestMapping(method = RequestMethod.DELETE, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/{hrorgaddress_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id) {
		return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.remove(hrorgaddress_id));
    }

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

    @PostAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(returnObject.body),'iBizHumanResources-HROrgAddress-Get')")
    @ApiOperation(value = "根据运营单位获取组织地址", tags = {"组织地址" },  notes = "根据运营单位获取组织地址")
	@RequestMapping(method = RequestMethod.GET, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/{hrorgaddress_id}")
    public ResponseEntity<HROrgAddressDTO> getByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @PathVariable("hrorgaddress_id") String hrorgaddress_id) {
        HROrgAddress domain = hrorgaddressService.get(hrorgaddress_id);
        HROrgAddressDTO dto = hrorgaddressMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据运营单位获取组织地址草稿", tags = {"组织地址" },  notes = "根据运营单位获取组织地址草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/getdraft")
    public ResponseEntity<HROrgAddressDTO> getDraftByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id) {
        HROrgAddress domain = new HROrgAddress();
        domain.setHrorganizationid(hroperationunit_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressMapping.toDto(hrorgaddressService.getDraft(domain)));
    }

    @ApiOperation(value = "根据运营单位检查组织地址", tags = {"组织地址" },  notes = "根据运营单位检查组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/checkkey")
    public ResponseEntity<Boolean> checkKeyByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.checkKey(hrorgaddressMapping.toDomain(hrorgaddressdto)));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdto),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "根据运营单位保存组织地址", tags = {"组织地址" },  notes = "根据运营单位保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/save")
    public ResponseEntity<Boolean> saveByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgAddressDTO hrorgaddressdto) {
        HROrgAddress domain = hrorgaddressMapping.toDomain(hrorgaddressdto);
        domain.setHrorganizationid(hroperationunit_id);
        return ResponseEntity.status(HttpStatus.OK).body(hrorgaddressService.save(domain));
    }

    @PreAuthorize("hasPermission(this.hrorgaddressMapping.toDomain(#hrorgaddressdtos),'iBizHumanResources-HROrgAddress-Save')")
    @ApiOperation(value = "根据运营单位批量保存组织地址", tags = {"组织地址" },  notes = "根据运营单位批量保存组织地址")
	@RequestMapping(method = RequestMethod.POST, value = "/hroperationunits/{hroperationunit_id}/hrorgaddresses/savebatch")
    public ResponseEntity<Boolean> saveBatchByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody List<HROrgAddressDTO> hrorgaddressdtos) {
        List<HROrgAddress> domainlist=hrorgaddressMapping.toDomain(hrorgaddressdtos);
        for(HROrgAddress domain:domainlist){
             domain.setHrorganizationid(hroperationunit_id);
        }
        hrorgaddressService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizHumanResources-HROrgAddress-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgAddress-Get')")
	@ApiOperation(value = "根据运营单位获取DEFAULT", tags = {"组织地址" } ,notes = "根据运营单位获取DEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/hroperationunits/{hroperationunit_id}/hrorgaddresses/fetchdefault")
	public ResponseEntity<List<HROrgAddressDTO>> fetchHROrgAddressDefaultByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id,HROrgAddressSearchContext context) {
        context.setN_hrorganizationid_eq(hroperationunit_id);
        Page<HROrgAddress> domains = hrorgaddressService.searchDefault(context) ;
        List<HROrgAddressDTO> list = hrorgaddressMapping.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-HROrgAddress-searchDefault-all') and hasPermission(#context,'iBizHumanResources-HROrgAddress-Get')")
	@ApiOperation(value = "根据运营单位查询DEFAULT", tags = {"组织地址" } ,notes = "根据运营单位查询DEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/hroperationunits/{hroperationunit_id}/hrorgaddresses/searchdefault")
	public ResponseEntity<Page<HROrgAddressDTO>> searchHROrgAddressDefaultByHROperationUnit(@PathVariable("hroperationunit_id") String hroperationunit_id, @RequestBody HROrgAddressSearchContext context) {
        context.setN_hrorganizationid_eq(hroperationunit_id);
        Page<HROrgAddress> domains = hrorgaddressService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(hrorgaddressMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}

