package cn.ibizlab.ehr.webapi.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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import cn.ibizlab.ehr.webapi.dto.*;
import cn.ibizlab.ehr.webapi.mapping.*;
import cn.ibizlab.ehr.core.pim.domain.PIMPERSONCHANGE;
import cn.ibizlab.ehr.core.pim.service.IPIMPERSONCHANGEService;
import cn.ibizlab.ehr.core.pim.filter.PIMPERSONCHANGESearchContext;




@Slf4j
@Api(tags = {"PIMPERSONCHANGE" })
@RestController("WebApi-pimpersonchange")
@RequestMapping("")
public class PIMPERSONCHANGEResource {

    @Autowired
    private IPIMPERSONCHANGEService pimpersonchangeService;

    @Autowired
    @Lazy
    private PIMPERSONCHANGEMapping pimpersonchangeMapping;




    @ApiOperation(value = "Save", tags = {"PIMPERSONCHANGE" },  notes = "Save")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/save")
    public ResponseEntity<Boolean> save(@RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.save(pimpersonchangeMapping.toDomain(pimpersonchangedto)));
    }

    @ApiOperation(value = "SaveBatch", tags = {"PIMPERSONCHANGE" },  notes = "SaveBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        pimpersonchangeService.saveBatch(pimpersonchangeMapping.toDomain(pimpersonchangedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @ApiOperation(value = "驳回", tags = {"PIMPERSONCHANGE" },  notes = "驳回")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/{pimpersonchange_id}/bh")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> bH(@PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE pimpersonchange = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        pimpersonchange = pimpersonchangeService.bH(pimpersonchange);
        pimpersonchangedto = pimpersonchangeMapping.toDto(pimpersonchange);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }




    @ApiOperation(value = "确认", tags = {"PIMPERSONCHANGE" },  notes = "确认")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/{pimpersonchange_id}/ensure")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> ensure(@PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE pimpersonchange = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        pimpersonchange = pimpersonchangeService.ensure(pimpersonchange);
        pimpersonchangedto = pimpersonchangeMapping.toDto(pimpersonchange);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }




    @PreAuthorize("hasPermission(#pimpersonchange_id,'Update',{this.getEntity(),'Sql'})")
    @ApiOperation(value = "Update", tags = {"PIMPERSONCHANGE" },  notes = "Update")
	@RequestMapping(method = RequestMethod.PUT, value = "/pimpersonchanges/{pimpersonchange_id}")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> update(@PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
		PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonchangeid(pimpersonchange_id);
		pimpersonchangeService.update(domain);
		PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(#pimpersonchange_id,'Update',{this.getEntity(),'Sql'})")
    @ApiOperation(value = "UpdateBatch", tags = {"PIMPERSONCHANGE" },  notes = "UpdateBatch")
	@RequestMapping(method = RequestMethod.PUT, value = "/pimpersonchanges/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        pimpersonchangeService.updateBatch(pimpersonchangeMapping.toDomain(pimpersonchangedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @PreAuthorize("hasPermission(#pimpersonchange_id,'Get',{this.getEntity(),'Sql'})")
    @ApiOperation(value = "Get", tags = {"PIMPERSONCHANGE" },  notes = "Get")
	@RequestMapping(method = RequestMethod.GET, value = "/pimpersonchanges/{pimpersonchange_id}")
    public ResponseEntity<PIMPERSONCHANGEDTO> get(@PathVariable("pimpersonchange_id") String pimpersonchange_id) {
        PIMPERSONCHANGE domain = pimpersonchangeService.get(pimpersonchange_id);
        PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }




    @PreAuthorize("hasPermission('','Create',{this.getEntity(),'Sql'})")
    @ApiOperation(value = "Create", tags = {"PIMPERSONCHANGE" },  notes = "Create")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> create(@RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
		pimpersonchangeService.create(domain);
        PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('','Create',{this.getEntity(),'Sql'})")
    @ApiOperation(value = "createBatch", tags = {"PIMPERSONCHANGE" },  notes = "createBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        pimpersonchangeService.createBatch(pimpersonchangeMapping.toDomain(pimpersonchangedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @PreAuthorize("hasPermission('Remove',{#pimpersonchange_id,{this.getEntity(),'Sql'}})")
    @ApiOperation(value = "Remove", tags = {"PIMPERSONCHANGE" },  notes = "Remove")
	@RequestMapping(method = RequestMethod.DELETE, value = "/pimpersonchanges/{pimpersonchange_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("pimpersonchange_id") String pimpersonchange_id) {
         return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.remove(pimpersonchange_id));
    }

    @ApiOperation(value = "RemoveBatch", tags = {"PIMPERSONCHANGE" },  notes = "RemoveBatch")
	@RequestMapping(method = RequestMethod.DELETE, value = "/pimpersonchanges/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        pimpersonchangeService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @ApiOperation(value = "确认", tags = {"PIMPERSONCHANGE" },  notes = "确认")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/{pimpersonchange_id}/qr")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> qR(@PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE pimpersonchange = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        pimpersonchange = pimpersonchangeService.qR(pimpersonchange);
        pimpersonchangedto = pimpersonchangeMapping.toDto(pimpersonchange);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }




    @ApiOperation(value = "CheckKey", tags = {"PIMPERSONCHANGE" },  notes = "CheckKey")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpersonchanges/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        return  ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.checkKey(pimpersonchangeMapping.toDomain(pimpersonchangedto)));
    }




    @ApiOperation(value = "GetDraft", tags = {"PIMPERSONCHANGE" },  notes = "GetDraft")
	@RequestMapping(method = RequestMethod.GET, value = "/pimpersonchanges/getdraft")
    public ResponseEntity<PIMPERSONCHANGEDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeMapping.toDto(pimpersonchangeService.getDraft(new PIMPERSONCHANGE())));
    }

    @PreAuthorize("hasPermission('Get',{#context,'HistoryRec',this.getEntity(),'Sql'})")
	@ApiOperation(value = "fetch历史审批记录", tags = {"PIMPERSONCHANGE" } ,notes = "fetch历史审批记录")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/fetchhistoryrec")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchHistoryRec(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHistoryRec(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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("hasPermission('Get',{#context,'HistoryRec',this.getEntity(),'Sql'})")
	@ApiOperation(value = "search历史审批记录", tags = {"PIMPERSONCHANGE" } ,notes = "search历史审批记录")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/searchhistoryrec")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchHistoryRec(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHistoryRec(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

    @PreAuthorize("hasPermission('Get',{#context,'PIMCL_NOTAPPROVAL',this.getEntity(),'Sql'})")
	@ApiOperation(value = "fetchPIMCL_NOTAPPROVAL", tags = {"PIMPERSONCHANGE" } ,notes = "fetchPIMCL_NOTAPPROVAL")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/fetchpimcl_notapproval")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchPIMCL_NOTAPPROVAL(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchPIMCL_NOTAPPROVAL(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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("hasPermission('Get',{#context,'PIMCL_NOTAPPROVAL',this.getEntity(),'Sql'})")
	@ApiOperation(value = "searchPIMCL_NOTAPPROVAL", tags = {"PIMPERSONCHANGE" } ,notes = "searchPIMCL_NOTAPPROVAL")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/searchpimcl_notapproval")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchPIMCL_NOTAPPROVAL(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchPIMCL_NOTAPPROVAL(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

    @PreAuthorize("hasPermission('Get',{#context,'HeadRed',this.getEntity(),'Sql'})")
	@ApiOperation(value = "fetch总部记录", tags = {"PIMPERSONCHANGE" } ,notes = "fetch总部记录")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/fetchheadred")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchHeadRed(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHeadRed(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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("hasPermission('Get',{#context,'HeadRed',this.getEntity(),'Sql'})")
	@ApiOperation(value = "search总部记录", tags = {"PIMPERSONCHANGE" } ,notes = "search总部记录")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/searchheadred")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchHeadRed(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHeadRed(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

    @PreAuthorize("hasPermission('Get',{#context,'Default',this.getEntity(),'Sql'})")
	@ApiOperation(value = "fetchDEFAULT", tags = {"PIMPERSONCHANGE" } ,notes = "fetchDEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/fetchdefault")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchDefault(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchDefault(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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("hasPermission('Get',{#context,'Default',this.getEntity(),'Sql'})")
	@ApiOperation(value = "searchDEFAULT", tags = {"PIMPERSONCHANGE" } ,notes = "searchDEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/pimpersonchanges/searchdefault")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchDefault(PIMPERSONCHANGESearchContext context) {
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}



    @ApiOperation(value = "SaveByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "SaveByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/save")
    public ResponseEntity<Boolean> saveByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.save(domain));
    }

    @ApiOperation(value = "SaveBatchByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "SaveBatchByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/savebatch")
    public ResponseEntity<Boolean> saveBatchByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        List<PIMPERSONCHANGE> domainlist=pimpersonchangeMapping.toDomain(pimpersonchangedtos);
        for(PIMPERSONCHANGE domain:domainlist){
             domain.setPimpersonid(pimperson_id);
        }
        pimpersonchangeService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "驳回ByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "驳回ByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchangepimpersonchangeid}/bh")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> bHByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
        domain = pimpersonchangeService.bH(domain) ;
        pimpersonchangedto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }

    @ApiOperation(value = "确认ByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "确认ByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchangepimpersonchangeid}/ensure")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> ensureByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
        domain = pimpersonchangeService.ensure(domain) ;
        pimpersonchangedto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }

    @ApiOperation(value = "UpdateByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "UpdateByPIMPERSON")
	@RequestMapping(method = RequestMethod.PUT, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchange_id}")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> updateByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
        domain.setPimpersonchangeid(pimpersonchange_id);
		pimpersonchangeService.update(domain);
        PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "UpdateBatchByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "UpdateBatchByPIMPERSON")
	@RequestMapping(method = RequestMethod.PUT, value = "/pimpeople/{pimperson_id}/pimpersonchanges/batch")
    public ResponseEntity<Boolean> updateBatchByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        List<PIMPERSONCHANGE> domainlist=pimpersonchangeMapping.toDomain(pimpersonchangedtos);
        for(PIMPERSONCHANGE domain:domainlist){
            domain.setPimpersonid(pimperson_id);
        }
        pimpersonchangeService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "GetByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "GetByPIMPERSON")
	@RequestMapping(method = RequestMethod.GET, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchange_id}")
    public ResponseEntity<PIMPERSONCHANGEDTO> getByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id) {
        PIMPERSONCHANGE domain = pimpersonchangeService.get(pimpersonchange_id);
        PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "CreateByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "CreateByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> createByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
		pimpersonchangeService.create(domain);
        PIMPERSONCHANGEDTO dto = pimpersonchangeMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "createBatchByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "createBatchByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/batch")
    public ResponseEntity<Boolean> createBatchByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody List<PIMPERSONCHANGEDTO> pimpersonchangedtos) {
        List<PIMPERSONCHANGE> domainlist=pimpersonchangeMapping.toDomain(pimpersonchangedtos);
        for(PIMPERSONCHANGE domain:domainlist){
            domain.setPimpersonid(pimperson_id);
        }
        pimpersonchangeService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "RemoveByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "RemoveByPIMPERSON")
	@RequestMapping(method = RequestMethod.DELETE, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchange_id}")
    @Transactional
    public ResponseEntity<Boolean> removeByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id) {
		return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.remove(pimpersonchange_id));
    }

    @ApiOperation(value = "RemoveBatchByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "RemoveBatchByPIMPERSON")
	@RequestMapping(method = RequestMethod.DELETE, value = "/pimpeople/{pimperson_id}/pimpersonchanges/batch")
    public ResponseEntity<Boolean> removeBatchByPIMPERSON(@RequestBody List<String> ids) {
        pimpersonchangeService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "确认ByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "确认ByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/{pimpersonchangepimpersonchangeid}/qr")
    @Transactional
    public ResponseEntity<PIMPERSONCHANGEDTO> qRByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @PathVariable("pimpersonchange_id") String pimpersonchange_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        PIMPERSONCHANGE domain = pimpersonchangeMapping.toDomain(pimpersonchangedto);
        domain.setPimpersonid(pimperson_id);
        domain = pimpersonchangeService.qR(domain) ;
        pimpersonchangedto = pimpersonchangeMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangedto);
    }

    @ApiOperation(value = "CheckKeyByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "CheckKeyByPIMPERSON")
	@RequestMapping(method = RequestMethod.POST, value = "/pimpeople/{pimperson_id}/pimpersonchanges/checkkey")
    public ResponseEntity<Boolean> checkKeyByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id, @RequestBody PIMPERSONCHANGEDTO pimpersonchangedto) {
        return  ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeService.checkKey(pimpersonchangeMapping.toDomain(pimpersonchangedto)));
    }

    @ApiOperation(value = "GetDraftByPIMPERSON", tags = {"PIMPERSONCHANGE" },  notes = "GetDraftByPIMPERSON")
    @RequestMapping(method = RequestMethod.GET, value = "/pimpeople/{pimperson_id}/pimpersonchanges/getdraft")
    public ResponseEntity<PIMPERSONCHANGEDTO> getDraftByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id) {
        PIMPERSONCHANGE domain = new PIMPERSONCHANGE();
        domain.setPimpersonid(pimperson_id);
        return ResponseEntity.status(HttpStatus.OK).body(pimpersonchangeMapping.toDto(pimpersonchangeService.getDraft(domain)));
    }

	@ApiOperation(value = "fetch历史审批记录ByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "fetch历史审批记录ByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/fetchhistoryrec")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchPIMPERSONCHANGEHistoryRecByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHistoryRec(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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);
	}

	@ApiOperation(value = "search历史审批记录ByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "search历史审批记录ByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/searchhistoryrec")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchPIMPERSONCHANGEHistoryRecByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHistoryRec(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

	@ApiOperation(value = "fetchPIMCL_NOTAPPROVALByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "fetchPIMCL_NOTAPPROVALByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/fetchpimcl_notapproval")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchPIMPERSONCHANGEPIMCL_NOTAPPROVALByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchPIMCL_NOTAPPROVAL(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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);
	}

	@ApiOperation(value = "searchPIMCL_NOTAPPROVALByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "searchPIMCL_NOTAPPROVALByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/searchpimcl_notapproval")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchPIMPERSONCHANGEPIMCL_NOTAPPROVALByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchPIMCL_NOTAPPROVAL(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

	@ApiOperation(value = "fetch总部记录ByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "fetch总部记录ByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/fetchheadred")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchPIMPERSONCHANGEHeadRedByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHeadRed(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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);
	}

	@ApiOperation(value = "search总部记录ByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "search总部记录ByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/searchheadred")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchPIMPERSONCHANGEHeadRedByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchHeadRed(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

	@ApiOperation(value = "fetchDEFAULTByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "fetchDEFAULTByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/fetchdefault")
	public ResponseEntity<List<PIMPERSONCHANGEDTO>> fetchPIMPERSONCHANGEDefaultByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchDefault(context) ;
        List<PIMPERSONCHANGEDTO> list = pimpersonchangeMapping.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);
	}

	@ApiOperation(value = "searchDEFAULTByPIMPERSON", tags = {"PIMPERSONCHANGE" } ,notes = "searchDEFAULTByPIMPERSON")
    @RequestMapping(method= RequestMethod.GET , value="/pimpeople/{pimperson_id}/pimpersonchanges/searchdefault")
	public ResponseEntity<Page<PIMPERSONCHANGEDTO>> searchPIMPERSONCHANGEDefaultByPIMPERSON(@PathVariable("pimperson_id") String pimperson_id,PIMPERSONCHANGESearchContext context) {
        context.setN_pimpersonid_eq(pimperson_id);
        Page<PIMPERSONCHANGE> domains = pimpersonchangeService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(pimpersonchangeMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}


    /**
     * 用户权限校验
     * @return
     */
	public PIMPERSONCHANGE getEntity(){
        return new PIMPERSONCHANGE();
    }

}
