package cn.ibizlab.uaaapi.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.uaaapi.dto.*;
import cn.ibizlab.uaaapi.mapping.*;
import cn.ibizlab.core.uaa.domain.SYS_ROLE_PERMISSION;
import cn.ibizlab.core.uaa.service.ISYS_ROLE_PERMISSIONService;
import cn.ibizlab.core.uaa.filter.SYS_ROLE_PERMISSIONSearchContext;




@Slf4j
@Api(tags = {"SYS_ROLE_PERMISSION" })
@RestController("uaaapi-sys_role_permission")
@RequestMapping("")
public class SYS_ROLE_PERMISSIONResource {

    @Autowired
    private ISYS_ROLE_PERMISSIONService sys_role_permissionService;

    @Autowired
    @Lazy
    private SYS_ROLE_PERMISSIONMapping sys_role_permissionMapping;




    @PreAuthorize("hasPermission(#sys_role_permission_id,'READ',this.getEntity())")
    @ApiOperation(value = "Get", tags = {"SYS_ROLE_PERMISSION" },  notes = "Get")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_role_permissions/{sys_role_permission_id}")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> get(@PathVariable("sys_role_permission_id") String sys_role_permission_id) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionService.get(sys_role_permission_id);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }




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

    @ApiOperation(value = "RemoveBatch", tags = {"RemoveBatch" },  notes = "RemoveBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/removebatch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        sys_role_permissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @PreAuthorize("hasPermission('','CREATE',this.getEntity())")
    @ApiOperation(value = "GetDraft", tags = {"SYS_ROLE_PERMISSION" },  notes = "GetDraft")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_role_permissions/getdraft")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionMapping.toDto(sys_role_permissionService.getDraft(new SYS_ROLE_PERMISSION())));
    }




    @PreAuthorize("hasPermission('','CREATE',this.getEntity())")
    @ApiOperation(value = "Create", tags = {"SYS_ROLE_PERMISSION" },  notes = "Create")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> create(@RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
		sys_role_permissionService.create(domain);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('','CREATE',this.getEntity())")
    @ApiOperation(value = "createBatch", tags = {"createBatch" },  notes = "createBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/createbatch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        sys_role_permissionService.createBatch(sys_role_permissionMapping.toDomain(sys_role_permissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @ApiOperation(value = "CheckKey", tags = {"SYS_ROLE_PERMISSION" },  notes = "CheckKey")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.checkKey(sys_role_permissionMapping.toDomain(sys_role_permissiondto)));
    }




    @ApiOperation(value = "Save", tags = {"SYS_ROLE_PERMISSION" },  notes = "Save")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/save")
    public ResponseEntity<Boolean> save(@RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.save(sys_role_permissionMapping.toDomain(sys_role_permissiondto)));
    }

    @ApiOperation(value = "SaveBatch", tags = {"SaveBatch" },  notes = "SaveBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        sys_role_permissionService.saveBatch(sys_role_permissionMapping.toDomain(sys_role_permissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @PreAuthorize("hasPermission(#sys_role_permission_id,'UPDATE',this.getEntity())")
    @ApiOperation(value = "Update", tags = {"SYS_ROLE_PERMISSION" },  notes = "Update")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_role_permissions/{sys_role_permission_id}")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> update(@PathVariable("sys_role_permission_id") String sys_role_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
		SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setRolepermissionid(sys_role_permission_id);
		sys_role_permissionService.update(domain);
		SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(#sys_role_permission_id,'UPDATE',this.getEntity())")
    @ApiOperation(value = "UpdateBatch", tags = {"UpdateBatch" },  notes = "UpdateBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_role_permissions/updatebatch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        sys_role_permissionService.updateBatch(sys_role_permissionMapping.toDomain(sys_role_permissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission('READ',{#context,'Default',this.getEntity()})")
	@ApiOperation(value = "fetchDEFAULT", tags = {"SYS_ROLE_PERMISSION" } ,notes = "fetchDEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/sys_role_permissions/fetchdefault")
	public ResponseEntity<List<SYS_ROLE_PERMISSIONDTO>> fetchDefault(SYS_ROLE_PERMISSIONSearchContext context) {
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
        List<SYS_ROLE_PERMISSIONDTO> list = sys_role_permissionMapping.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('READ',{#context,'Default',this.getEntity()})")
	@ApiOperation(value = "searchDEFAULT", tags = {"SYS_ROLE_PERMISSION" } ,notes = "searchDEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/sys_role_permissions/searchdefault")
	public ResponseEntity<Page<SYS_ROLE_PERMISSIONDTO>> searchDefault(SYS_ROLE_PERMISSIONSearchContext context) {
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sys_role_permissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}



    @ApiOperation(value = "GetBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "GetBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/{sys_role_permission_id}")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> getBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionService.get(sys_role_permission_id);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "RemoveBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "RemoveBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/{sys_role_permission_id}")
    @Transactional
    public ResponseEntity<Boolean> removeBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id) {
		return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.remove(sys_role_permission_id));
    }

    @ApiOperation(value = "RemoveBatchBySYS_PERMISSION", tags = {"RemoveBatchBySYS_PERMISSION" },  notes = "RemoveBatchBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/removebatch")
    public ResponseEntity<Boolean> removeBatchBySYS_PERMISSION(@RequestBody List<String> ids) {
        sys_role_permissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "GetDraftBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "GetDraftBySYS_PERMISSION")
    @RequestMapping(method = RequestMethod.GET, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/getdraft")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> getDraftBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id) {
        SYS_ROLE_PERMISSION domain = new SYS_ROLE_PERMISSION();
        domain.setPermissionid(sys_permission_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionMapping.toDto(sys_role_permissionService.getDraft(domain)));
    }

    @ApiOperation(value = "CreateBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "CreateBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> createBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setPermissionid(sys_permission_id);
		sys_role_permissionService.create(domain);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "createBatchBySYS_PERMISSION", tags = {"createBatchBySYS_PERMISSION" },  notes = "createBatchBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/createbatch")
    public ResponseEntity<Boolean> createBatchBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
            domain.setPermissionid(sys_permission_id);
        }
        sys_role_permissionService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "CheckKeyBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "CheckKeyBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/checkkey")
    public ResponseEntity<Boolean> checkKeyBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.checkKey(sys_role_permissionMapping.toDomain(sys_role_permissiondto)));
    }

    @ApiOperation(value = "SaveBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "SaveBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/save")
    public ResponseEntity<Boolean> saveBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setPermissionid(sys_permission_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.save(domain));
    }

    @ApiOperation(value = "SaveBatchBySYS_PERMISSION", tags = {"SaveBatchBySYS_PERMISSION" },  notes = "SaveBatchBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/savebatch")
    public ResponseEntity<Boolean> saveBatchBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
             domain.setPermissionid(sys_permission_id);
        }
        sys_role_permissionService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "UpdateBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" },  notes = "UpdateBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/{sys_role_permission_id}")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> updateBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setPermissionid(sys_permission_id);
        domain.setRolepermissionid(sys_role_permission_id);
		sys_role_permissionService.update(domain);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "UpdateBatchBySYS_PERMISSION", tags = {"UpdateBatchBySYS_PERMISSION" },  notes = "UpdateBatchBySYS_PERMISSION")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_permissions/{sys_permission_id}/sys_role_permissions/updatebatch")
    public ResponseEntity<Boolean> updateBatchBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
            domain.setPermissionid(sys_permission_id);
        }
        sys_role_permissionService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "fetchDEFAULTBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" } ,notes = "fetchDEFAULTBySYS_PERMISSION")
    @RequestMapping(method= RequestMethod.GET , value="/sys_permissions/{sys_permission_id}/sys_role_permissions/fetchdefault")
	public ResponseEntity<List<SYS_ROLE_PERMISSIONDTO>> fetchSYS_ROLE_PERMISSIONDefaultBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id,SYS_ROLE_PERMISSIONSearchContext context) {
        context.setN_sys_permissionid_eq(sys_permission_id);
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
        List<SYS_ROLE_PERMISSIONDTO> list = sys_role_permissionMapping.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 = "searchDEFAULTBySYS_PERMISSION", tags = {"SYS_ROLE_PERMISSIONBySYS_PERMISSION" } ,notes = "searchDEFAULTBySYS_PERMISSION")
    @RequestMapping(method= RequestMethod.GET , value="/sys_permissions/{sys_permission_id}/sys_role_permissions/searchdefault")
	public ResponseEntity<Page<SYS_ROLE_PERMISSIONDTO>> searchSYS_ROLE_PERMISSIONDefaultBySYS_PERMISSION(@PathVariable("sys_permission_id") String sys_permission_id,SYS_ROLE_PERMISSIONSearchContext context) {
        context.setN_sys_permissionid_eq(sys_permission_id);
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sys_role_permissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}



    @ApiOperation(value = "GetBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "GetBySYS_ROLE")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_roles/{sys_role_id}/sys_role_permissions/{sys_role_permission_id}")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> getBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionService.get(sys_role_permission_id);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "RemoveBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "RemoveBySYS_ROLE")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sys_roles/{sys_role_id}/sys_role_permissions/{sys_role_permission_id}")
    @Transactional
    public ResponseEntity<Boolean> removeBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id) {
		return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.remove(sys_role_permission_id));
    }

    @ApiOperation(value = "RemoveBatchBySYS_ROLE", tags = {"RemoveBatchBySYS_ROLE" },  notes = "RemoveBatchBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/removebatch")
    public ResponseEntity<Boolean> removeBatchBySYS_ROLE(@RequestBody List<String> ids) {
        sys_role_permissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "GetDraftBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "GetDraftBySYS_ROLE")
    @RequestMapping(method = RequestMethod.GET, value = "/sys_roles/{sys_role_id}/sys_role_permissions/getdraft")
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> getDraftBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id) {
        SYS_ROLE_PERMISSION domain = new SYS_ROLE_PERMISSION();
        domain.setRoleid(sys_role_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionMapping.toDto(sys_role_permissionService.getDraft(domain)));
    }

    @ApiOperation(value = "CreateBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "CreateBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> createBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setRoleid(sys_role_id);
		sys_role_permissionService.create(domain);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "createBatchBySYS_ROLE", tags = {"createBatchBySYS_ROLE" },  notes = "createBatchBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/createbatch")
    public ResponseEntity<Boolean> createBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
            domain.setRoleid(sys_role_id);
        }
        sys_role_permissionService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "CheckKeyBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "CheckKeyBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/checkkey")
    public ResponseEntity<Boolean> checkKeyBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.checkKey(sys_role_permissionMapping.toDomain(sys_role_permissiondto)));
    }

    @ApiOperation(value = "SaveBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "SaveBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/save")
    public ResponseEntity<Boolean> saveBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setRoleid(sys_role_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_role_permissionService.save(domain));
    }

    @ApiOperation(value = "SaveBatchBySYS_ROLE", tags = {"SaveBatchBySYS_ROLE" },  notes = "SaveBatchBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/savebatch")
    public ResponseEntity<Boolean> saveBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
             domain.setRoleid(sys_role_id);
        }
        sys_role_permissionService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "UpdateBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" },  notes = "UpdateBySYS_ROLE")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_roles/{sys_role_id}/sys_role_permissions/{sys_role_permission_id}")
    @Transactional
    public ResponseEntity<SYS_ROLE_PERMISSIONDTO> updateBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @PathVariable("sys_role_permission_id") String sys_role_permission_id, @RequestBody SYS_ROLE_PERMISSIONDTO sys_role_permissiondto) {
        SYS_ROLE_PERMISSION domain = sys_role_permissionMapping.toDomain(sys_role_permissiondto);
        domain.setRoleid(sys_role_id);
        domain.setRolepermissionid(sys_role_permission_id);
		sys_role_permissionService.update(domain);
        SYS_ROLE_PERMISSIONDTO dto = sys_role_permissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "UpdateBatchBySYS_ROLE", tags = {"UpdateBatchBySYS_ROLE" },  notes = "UpdateBatchBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_role_permissions/updatebatch")
    public ResponseEntity<Boolean> updateBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_ROLE_PERMISSIONDTO> sys_role_permissiondtos) {
        List<SYS_ROLE_PERMISSION> domainlist=sys_role_permissionMapping.toDomain(sys_role_permissiondtos);
        for(SYS_ROLE_PERMISSION domain:domainlist){
            domain.setRoleid(sys_role_id);
        }
        sys_role_permissionService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "fetchDEFAULTBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" } ,notes = "fetchDEFAULTBySYS_ROLE")
    @RequestMapping(method= RequestMethod.GET , value="/sys_roles/{sys_role_id}/sys_role_permissions/fetchdefault")
	public ResponseEntity<List<SYS_ROLE_PERMISSIONDTO>> fetchSYS_ROLE_PERMISSIONDefaultBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id,SYS_ROLE_PERMISSIONSearchContext context) {
        context.setN_sys_roleid_eq(sys_role_id);
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
        List<SYS_ROLE_PERMISSIONDTO> list = sys_role_permissionMapping.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 = "searchDEFAULTBySYS_ROLE", tags = {"SYS_ROLE_PERMISSIONBySYS_ROLE" } ,notes = "searchDEFAULTBySYS_ROLE")
    @RequestMapping(method= RequestMethod.GET , value="/sys_roles/{sys_role_id}/sys_role_permissions/searchdefault")
	public ResponseEntity<Page<SYS_ROLE_PERMISSIONDTO>> searchSYS_ROLE_PERMISSIONDefaultBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id,SYS_ROLE_PERMISSIONSearchContext context) {
        context.setN_sys_roleid_eq(sys_role_id);
        Page<SYS_ROLE_PERMISSION> domains = sys_role_permissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sys_role_permissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}


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

}
