package cn.ibizlab.api.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.api.dto.*;
import cn.ibizlab.api.mapping.*;
import cn.ibizlab.core.uaa.domain.SysRolePermission;
import cn.ibizlab.core.uaa.service.ISysRolePermissionService;
import cn.ibizlab.core.uaa.filter.SysRolePermissionSearchContext;

@Slf4j
@Api(tags = {"SysRolePermission" })
@RestController("api-sysrolepermission")
@RequestMapping("")
public class SysRolePermissionResource {

    @Autowired
    private ISysRolePermissionService sysrolepermissionService;

    @Autowired
    @Lazy
    public SysRolePermissionMapping sysrolepermissionMapping;

    public SysRolePermissionDTO permissionDTO=new SysRolePermissionDTO();

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Get-all')")
    @ApiOperation(value = "Get", tags = {"SysRolePermission" },  notes = "Get")
	@RequestMapping(method = RequestMethod.GET, value = "/sysrolepermissions/{sysrolepermission_id}")
    public ResponseEntity<SysRolePermissionDTO> get(@PathVariable("sysrolepermission_id") String sysrolepermission_id) {
        SysRolePermission domain = sysrolepermissionService.get(sysrolepermission_id);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Remove-all')")
    @ApiOperation(value = "Remove", tags = {"SysRolePermission" },  notes = "Remove")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<Boolean> remove(@PathVariable("sysrolepermission_id") String sysrolepermission_id) {
         return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.remove(sysrolepermission_id));
    }

    @PreAuthorize("hasPermission('Remove',{'Sql',this.humanMapping,this.permissionDTO,#ids})")
    @ApiOperation(value = "RemoveBatch", tags = {"SysRolePermission" },  notes = "RemoveBatch")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sysrolepermissions/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        sysrolepermissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-GetDraft-all')")
    @ApiOperation(value = "GetDraft", tags = {"SysRolePermission" },  notes = "GetDraft")
	@RequestMapping(method = RequestMethod.GET, value = "/sysrolepermissions/getdraft")
    public ResponseEntity<SysRolePermissionDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionMapping.toDto(sysrolepermissionService.getDraft(new SysRolePermission())));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Create-all')")
    @ApiOperation(value = "Create", tags = {"SysRolePermission" },  notes = "Create")
	@RequestMapping(method = RequestMethod.POST, value = "/sysrolepermissions")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> create(@RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
		sysrolepermissionService.create(domain);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Create',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "createBatch", tags = {"SysRolePermission" },  notes = "createBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sysrolepermissions/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        sysrolepermissionService.createBatch(sysrolepermissionMapping.toDomain(sysrolepermissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-CheckKey-all')")
    @ApiOperation(value = "CheckKey", tags = {"SysRolePermission" },  notes = "CheckKey")
	@RequestMapping(method = RequestMethod.POST, value = "/sysrolepermissions/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.checkKey(sysrolepermissionMapping.toDomain(sysrolepermissiondto)));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Save-all')")
    @ApiOperation(value = "Save", tags = {"SysRolePermission" },  notes = "Save")
	@RequestMapping(method = RequestMethod.POST, value = "/sysrolepermissions/save")
    public ResponseEntity<Boolean> save(@RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.save(sysrolepermissionMapping.toDomain(sysrolepermissiondto)));
    }

    @PreAuthorize("hasPermission('Save',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "SaveBatch", tags = {"SysRolePermission" },  notes = "SaveBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sysrolepermissions/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        sysrolepermissionService.saveBatch(sysrolepermissionMapping.toDomain(sysrolepermissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Update-all')")
    @ApiOperation(value = "Update", tags = {"SysRolePermission" },  notes = "Update")
	@RequestMapping(method = RequestMethod.PUT, value = "/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> update(@PathVariable("sysrolepermission_id") String sysrolepermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
		SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setRolepermissionid(sysrolepermission_id);
		sysrolepermissionService.update(domain);
		SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Update',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "UpdateBatch", tags = {"SysRolePermission" },  notes = "UpdateBatch")
	@RequestMapping(method = RequestMethod.PUT, value = "/sysrolepermissions/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        sysrolepermissionService.updateBatch(sysrolepermissionMapping.toDomain(sysrolepermissiondtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "fetchDEFAULT", tags = {"SysRolePermission" } ,notes = "fetchDEFAULT")
    @RequestMapping(method= RequestMethod.GET , value="/sysrolepermissions/fetchdefault")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchDefault(SysRolePermissionSearchContext context) {
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "searchDEFAULT", tags = {"SysRolePermission" } ,notes = "searchDEFAULT")
    @RequestMapping(method= RequestMethod.POST , value="/sysrolepermissions/searchdefault")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchDefault(@RequestBody SysRolePermissionSearchContext context) {
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "fetchpermissionenable1", tags = {"SysRolePermission" } ,notes = "fetchpermissionenable1")
    @RequestMapping(method= RequestMethod.GET , value="/sysrolepermissions/fetchpermissionenable1")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchPermissionenable1(SysRolePermissionSearchContext context) {
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "searchpermissionenable1", tags = {"SysRolePermission" } ,notes = "searchpermissionenable1")
    @RequestMapping(method= RequestMethod.POST , value="/sysrolepermissions/searchpermissionenable1")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchPermissionenable1(@RequestBody SysRolePermissionSearchContext context) {
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Get-all')")
    @ApiOperation(value = "GetBySysPermission", tags = {"SysRolePermission" },  notes = "GetBySysPermission")
	@RequestMapping(method = RequestMethod.GET, value = "/syspermissions/{syspermission_id}/sysrolepermissions/{sysrolepermission_id}")
    public ResponseEntity<SysRolePermissionDTO> getBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id) {
        SysRolePermission domain = sysrolepermissionService.get(sysrolepermission_id);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Remove-all')")
    @ApiOperation(value = "RemoveBySysPermission", tags = {"SysRolePermission" },  notes = "RemoveBySysPermission")
	@RequestMapping(method = RequestMethod.DELETE, value = "/syspermissions/{syspermission_id}/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<Boolean> removeBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id) {
		return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.remove(sysrolepermission_id));
    }

    @PreAuthorize("hasPermission('Remove',{'Sql',this.humanMapping,this.permissionDTO,#ids})")
    @ApiOperation(value = "RemoveBatchBySysPermission", tags = {"SysRolePermission" },  notes = "RemoveBatchBySysPermission")
	@RequestMapping(method = RequestMethod.DELETE, value = "/syspermissions/{syspermission_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> removeBatchBySysPermission(@RequestBody List<String> ids) {
        sysrolepermissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-GetDraft-all')")
    @ApiOperation(value = "GetDraftBySysPermission", tags = {"SysRolePermission" },  notes = "GetDraftBySysPermission")
    @RequestMapping(method = RequestMethod.GET, value = "/syspermissions/{syspermission_id}/sysrolepermissions/getdraft")
    public ResponseEntity<SysRolePermissionDTO> getDraftBySysPermission(@PathVariable("syspermission_id") String syspermission_id) {
        SysRolePermission domain = new SysRolePermission();
        domain.setPermissionid(syspermission_id);
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionMapping.toDto(sysrolepermissionService.getDraft(domain)));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Create-all')")
    @ApiOperation(value = "CreateBySysPermission", tags = {"SysRolePermission" },  notes = "CreateBySysPermission")
	@RequestMapping(method = RequestMethod.POST, value = "/syspermissions/{syspermission_id}/sysrolepermissions")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> createBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setPermissionid(syspermission_id);
		sysrolepermissionService.create(domain);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Create',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "createBatchBySysPermission", tags = {"SysRolePermission" },  notes = "createBatchBySysPermission")
	@RequestMapping(method = RequestMethod.POST, value = "/syspermissions/{syspermission_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> createBatchBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
            domain.setPermissionid(syspermission_id);
        }
        sysrolepermissionService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-CheckKey-all')")
    @ApiOperation(value = "CheckKeyBySysPermission", tags = {"SysRolePermission" },  notes = "CheckKeyBySysPermission")
	@RequestMapping(method = RequestMethod.POST, value = "/syspermissions/{syspermission_id}/sysrolepermissions/checkkey")
    public ResponseEntity<Boolean> checkKeyBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.checkKey(sysrolepermissionMapping.toDomain(sysrolepermissiondto)));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Save-all')")
    @ApiOperation(value = "SaveBySysPermission", tags = {"SysRolePermission" },  notes = "SaveBySysPermission")
	@RequestMapping(method = RequestMethod.POST, value = "/syspermissions/{syspermission_id}/sysrolepermissions/save")
    public ResponseEntity<Boolean> saveBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setPermissionid(syspermission_id);
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.save(domain));
    }

    @PreAuthorize("hasPermission('Save',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "SaveBatchBySysPermission", tags = {"SysRolePermission" },  notes = "SaveBatchBySysPermission")
	@RequestMapping(method = RequestMethod.POST, value = "/syspermissions/{syspermission_id}/sysrolepermissions/savebatch")
    public ResponseEntity<Boolean> saveBatchBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
             domain.setPermissionid(syspermission_id);
        }
        sysrolepermissionService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Update-all')")
    @ApiOperation(value = "UpdateBySysPermission", tags = {"SysRolePermission" },  notes = "UpdateBySysPermission")
	@RequestMapping(method = RequestMethod.PUT, value = "/syspermissions/{syspermission_id}/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> updateBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setPermissionid(syspermission_id);
        domain.setRolepermissionid(sysrolepermission_id);
		sysrolepermissionService.update(domain);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Update',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "UpdateBatchBySysPermission", tags = {"SysRolePermission" },  notes = "UpdateBatchBySysPermission")
	@RequestMapping(method = RequestMethod.PUT, value = "/syspermissions/{syspermission_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> updateBatchBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
            domain.setPermissionid(syspermission_id);
        }
        sysrolepermissionService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "fetchDEFAULTBySysPermission", tags = {"SysRolePermission" } ,notes = "fetchDEFAULTBySysPermission")
    @RequestMapping(method= RequestMethod.GET , value="/syspermissions/{syspermission_id}/sysrolepermissions/fetchdefault")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchSysRolePermissionDefaultBySysPermission(@PathVariable("syspermission_id") String syspermission_id,SysRolePermissionSearchContext context) {
        context.setN_sys_permissionid_eq(syspermission_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "searchDEFAULTBySysPermission", tags = {"SysRolePermission" } ,notes = "searchDEFAULTBySysPermission")
    @RequestMapping(method= RequestMethod.POST , value="/syspermissions/{syspermission_id}/sysrolepermissions/searchdefault")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchSysRolePermissionDefaultBySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody SysRolePermissionSearchContext context) {
        context.setN_sys_permissionid_eq(syspermission_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "fetchpermissionenable1BySysPermission", tags = {"SysRolePermission" } ,notes = "fetchpermissionenable1BySysPermission")
    @RequestMapping(method= RequestMethod.GET , value="/syspermissions/{syspermission_id}/sysrolepermissions/fetchpermissionenable1")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchSysRolePermissionPermissionenable1BySysPermission(@PathVariable("syspermission_id") String syspermission_id,SysRolePermissionSearchContext context) {
        context.setN_sys_permissionid_eq(syspermission_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "searchpermissionenable1BySysPermission", tags = {"SysRolePermission" } ,notes = "searchpermissionenable1BySysPermission")
    @RequestMapping(method= RequestMethod.POST , value="/syspermissions/{syspermission_id}/sysrolepermissions/searchpermissionenable1")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchSysRolePermissionPermissionenable1BySysPermission(@PathVariable("syspermission_id") String syspermission_id, @RequestBody SysRolePermissionSearchContext context) {
        context.setN_sys_permissionid_eq(syspermission_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Get-all')")
    @ApiOperation(value = "GetBySysRole", tags = {"SysRolePermission" },  notes = "GetBySysRole")
	@RequestMapping(method = RequestMethod.GET, value = "/sysroles/{sysrole_id}/sysrolepermissions/{sysrolepermission_id}")
    public ResponseEntity<SysRolePermissionDTO> getBySysRole(@PathVariable("sysrole_id") String sysrole_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id) {
        SysRolePermission domain = sysrolepermissionService.get(sysrolepermission_id);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Remove-all')")
    @ApiOperation(value = "RemoveBySysRole", tags = {"SysRolePermission" },  notes = "RemoveBySysRole")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sysroles/{sysrole_id}/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<Boolean> removeBySysRole(@PathVariable("sysrole_id") String sysrole_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id) {
		return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.remove(sysrolepermission_id));
    }

    @PreAuthorize("hasPermission('Remove',{'Sql',this.humanMapping,this.permissionDTO,#ids})")
    @ApiOperation(value = "RemoveBatchBySysRole", tags = {"SysRolePermission" },  notes = "RemoveBatchBySysRole")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sysroles/{sysrole_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> removeBatchBySysRole(@RequestBody List<String> ids) {
        sysrolepermissionService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-GetDraft-all')")
    @ApiOperation(value = "GetDraftBySysRole", tags = {"SysRolePermission" },  notes = "GetDraftBySysRole")
    @RequestMapping(method = RequestMethod.GET, value = "/sysroles/{sysrole_id}/sysrolepermissions/getdraft")
    public ResponseEntity<SysRolePermissionDTO> getDraftBySysRole(@PathVariable("sysrole_id") String sysrole_id) {
        SysRolePermission domain = new SysRolePermission();
        domain.setRoleid(sysrole_id);
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionMapping.toDto(sysrolepermissionService.getDraft(domain)));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Create-all')")
    @ApiOperation(value = "CreateBySysRole", tags = {"SysRolePermission" },  notes = "CreateBySysRole")
	@RequestMapping(method = RequestMethod.POST, value = "/sysroles/{sysrole_id}/sysrolepermissions")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> createBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setRoleid(sysrole_id);
		sysrolepermissionService.create(domain);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Create',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "createBatchBySysRole", tags = {"SysRolePermission" },  notes = "createBatchBySysRole")
	@RequestMapping(method = RequestMethod.POST, value = "/sysroles/{sysrole_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> createBatchBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
            domain.setRoleid(sysrole_id);
        }
        sysrolepermissionService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-CheckKey-all')")
    @ApiOperation(value = "CheckKeyBySysRole", tags = {"SysRolePermission" },  notes = "CheckKeyBySysRole")
	@RequestMapping(method = RequestMethod.POST, value = "/sysroles/{sysrole_id}/sysrolepermissions/checkkey")
    public ResponseEntity<Boolean> checkKeyBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.checkKey(sysrolepermissionMapping.toDomain(sysrolepermissiondto)));
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Save-all')")
    @ApiOperation(value = "SaveBySysRole", tags = {"SysRolePermission" },  notes = "SaveBySysRole")
	@RequestMapping(method = RequestMethod.POST, value = "/sysroles/{sysrole_id}/sysrolepermissions/save")
    public ResponseEntity<Boolean> saveBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setRoleid(sysrole_id);
        return ResponseEntity.status(HttpStatus.OK).body(sysrolepermissionService.save(domain));
    }

    @PreAuthorize("hasPermission('Save',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "SaveBatchBySysRole", tags = {"SysRolePermission" },  notes = "SaveBatchBySysRole")
	@RequestMapping(method = RequestMethod.POST, value = "/sysroles/{sysrole_id}/sysrolepermissions/savebatch")
    public ResponseEntity<Boolean> saveBatchBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
             domain.setRoleid(sysrole_id);
        }
        sysrolepermissionService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Update-all')")
    @ApiOperation(value = "UpdateBySysRole", tags = {"SysRolePermission" },  notes = "UpdateBySysRole")
	@RequestMapping(method = RequestMethod.PUT, value = "/sysroles/{sysrole_id}/sysrolepermissions/{sysrolepermission_id}")
    @Transactional
    public ResponseEntity<SysRolePermissionDTO> updateBySysRole(@PathVariable("sysrole_id") String sysrole_id, @PathVariable("sysrolepermission_id") String sysrolepermission_id, @RequestBody SysRolePermissionDTO sysrolepermissiondto) {
        SysRolePermission domain = sysrolepermissionMapping.toDomain(sysrolepermissiondto);
        domain.setRoleid(sysrole_id);
        domain.setRolepermissionid(sysrolepermission_id);
		sysrolepermissionService.update(domain);
        SysRolePermissionDTO dto = sysrolepermissionMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission('Update',{'Sql',this.humanMapping,#humandtos})")
    @ApiOperation(value = "UpdateBatchBySysRole", tags = {"SysRolePermission" },  notes = "UpdateBatchBySysRole")
	@RequestMapping(method = RequestMethod.PUT, value = "/sysroles/{sysrole_id}/sysrolepermissions/batch")
    public ResponseEntity<Boolean> updateBatchBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody List<SysRolePermissionDTO> sysrolepermissiondtos) {
        List<SysRolePermission> domainlist=sysrolepermissionMapping.toDomain(sysrolepermissiondtos);
        for(SysRolePermission domain:domainlist){
            domain.setRoleid(sysrole_id);
        }
        sysrolepermissionService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "fetchDEFAULTBySysRole", tags = {"SysRolePermission" } ,notes = "fetchDEFAULTBySysRole")
    @RequestMapping(method= RequestMethod.GET , value="/sysroles/{sysrole_id}/sysrolepermissions/fetchdefault")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchSysRolePermissionDefaultBySysRole(@PathVariable("sysrole_id") String sysrole_id,SysRolePermissionSearchContext context) {
        context.setN_sys_roleid_eq(sysrole_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Default-all')")
	@ApiOperation(value = "searchDEFAULTBySysRole", tags = {"SysRolePermission" } ,notes = "searchDEFAULTBySysRole")
    @RequestMapping(method= RequestMethod.POST , value="/sysroles/{sysrole_id}/sysrolepermissions/searchdefault")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchSysRolePermissionDefaultBySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody SysRolePermissionSearchContext context) {
        context.setN_sys_roleid_eq(sysrole_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "fetchpermissionenable1BySysRole", tags = {"SysRolePermission" } ,notes = "fetchpermissionenable1BySysRole")
    @RequestMapping(method= RequestMethod.GET , value="/sysroles/{sysrole_id}/sysrolepermissions/fetchpermissionenable1")
	public ResponseEntity<List<SysRolePermissionDTO>> fetchSysRolePermissionPermissionenable1BySysRole(@PathVariable("sysrole_id") String sysrole_id,SysRolePermissionSearchContext context) {
        context.setN_sys_roleid_eq(sysrole_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
        List<SysRolePermissionDTO> list = sysrolepermissionMapping.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','ibzuaa-SysRolePermission-Permissionenable1-all')")
	@ApiOperation(value = "searchpermissionenable1BySysRole", tags = {"SysRolePermission" } ,notes = "searchpermissionenable1BySysRole")
    @RequestMapping(method= RequestMethod.POST , value="/sysroles/{sysrole_id}/sysrolepermissions/searchpermissionenable1")
	public ResponseEntity<Page<SysRolePermissionDTO>> searchSysRolePermissionPermissionenable1BySysRole(@PathVariable("sysrole_id") String sysrole_id, @RequestBody SysRolePermissionSearchContext context) {
        context.setN_sys_roleid_eq(sysrole_id);
        Page<SysRolePermission> domains = sysrolepermissionService.searchPermissionenable1(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sysrolepermissionMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}
