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_USER_ROLE;
import cn.ibizlab.core.uaa.service.ISYS_USER_ROLEService;
import cn.ibizlab.core.uaa.filter.SYS_USER_ROLESearchContext;




@Slf4j
@Api(tags = {"SYS_USER_ROLE" })
@RestController("uaaapi-sys_user_role")
@RequestMapping("")
public class SYS_USER_ROLEResource {

    @Autowired
    private ISYS_USER_ROLEService sys_user_roleService;

    @Autowired
    @Lazy
    private SYS_USER_ROLEMapping sys_user_roleMapping;




    @ApiOperation(value = "CheckKey", tags = {"SYS_USER_ROLE" },  notes = "CheckKey")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_user_roles/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.checkKey(sys_user_roleMapping.toDomain(sys_user_roledto)));
    }




    @PreAuthorize("hasPermission('','CREATE',this.getEntity())")
    @ApiOperation(value = "GetDraft", tags = {"SYS_USER_ROLE" },  notes = "GetDraft")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_user_roles/getdraft")
    public ResponseEntity<SYS_USER_ROLEDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleMapping.toDto(sys_user_roleService.getDraft(new SYS_USER_ROLE())));
    }




    @PreAuthorize("hasPermission(#sys_user_role_id,'UPDATE',this.getEntity())")
    @ApiOperation(value = "Update", tags = {"SYS_USER_ROLE" },  notes = "Update")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_user_roles/{sys_user_role_id}")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> update(@PathVariable("sys_user_role_id") String sys_user_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
		SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setUserroleid(sys_user_role_id);
		sys_user_roleService.update(domain);
		SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(#sys_user_role_id,'UPDATE',this.getEntity())")
    @ApiOperation(value = "UpdateBatch", tags = {"UpdateBatch" },  notes = "UpdateBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_user_roles/updatebatch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        sys_user_roleService.updateBatch(sys_user_roleMapping.toDomain(sys_user_roledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




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

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




    @PreAuthorize("hasPermission('','CREATE',this.getEntity())")
    @ApiOperation(value = "Create", tags = {"SYS_USER_ROLE" },  notes = "Create")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_user_roles")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> create(@RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
		sys_user_roleService.create(domain);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.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_user_roles/createbatch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        sys_user_roleService.createBatch(sys_user_roleMapping.toDomain(sys_user_roledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }




    @PreAuthorize("hasPermission(#sys_user_role_id,'READ',this.getEntity())")
    @ApiOperation(value = "Get", tags = {"SYS_USER_ROLE" },  notes = "Get")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_user_roles/{sys_user_role_id}")
    public ResponseEntity<SYS_USER_ROLEDTO> get(@PathVariable("sys_user_role_id") String sys_user_role_id) {
        SYS_USER_ROLE domain = sys_user_roleService.get(sys_user_role_id);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }




    @ApiOperation(value = "Save", tags = {"SYS_USER_ROLE" },  notes = "Save")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_user_roles/save")
    public ResponseEntity<Boolean> save(@RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.save(sys_user_roleMapping.toDomain(sys_user_roledto)));
    }

    @ApiOperation(value = "SaveBatch", tags = {"SaveBatch" },  notes = "SaveBatch")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_user_roles/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        sys_user_roleService.saveBatch(sys_user_roleMapping.toDomain(sys_user_roledtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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



    @ApiOperation(value = "CheckKeyBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "CheckKeyBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_user_roles/checkkey")
    public ResponseEntity<Boolean> checkKeyBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.checkKey(sys_user_roleMapping.toDomain(sys_user_roledto)));
    }

    @ApiOperation(value = "GetDraftBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "GetDraftBySYS_ROLE")
    @RequestMapping(method = RequestMethod.GET, value = "/sys_roles/{sys_role_id}/sys_user_roles/getdraft")
    public ResponseEntity<SYS_USER_ROLEDTO> getDraftBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id) {
        SYS_USER_ROLE domain = new SYS_USER_ROLE();
        domain.setRoleid(sys_role_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleMapping.toDto(sys_user_roleService.getDraft(domain)));
    }

    @ApiOperation(value = "UpdateBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "UpdateBySYS_ROLE")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_roles/{sys_role_id}/sys_user_roles/{sys_user_role_id}")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> updateBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @PathVariable("sys_user_role_id") String sys_user_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setRoleid(sys_role_id);
        domain.setUserroleid(sys_user_role_id);
		sys_user_roleService.update(domain);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.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_user_roles/updatebatch")
    public ResponseEntity<Boolean> updateBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
            domain.setRoleid(sys_role_id);
        }
        sys_user_roleService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

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

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

    @ApiOperation(value = "CreateBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "CreateBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_user_roles")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> createBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setRoleid(sys_role_id);
		sys_user_roleService.create(domain);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.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_user_roles/createbatch")
    public ResponseEntity<Boolean> createBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
            domain.setRoleid(sys_role_id);
        }
        sys_user_roleService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "GetBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "GetBySYS_ROLE")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_roles/{sys_role_id}/sys_user_roles/{sys_user_role_id}")
    public ResponseEntity<SYS_USER_ROLEDTO> getBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @PathVariable("sys_user_role_id") String sys_user_role_id) {
        SYS_USER_ROLE domain = sys_user_roleService.get(sys_user_role_id);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "SaveBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" },  notes = "SaveBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_user_roles/save")
    public ResponseEntity<Boolean> saveBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setRoleid(sys_role_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.save(domain));
    }

    @ApiOperation(value = "SaveBatchBySYS_ROLE", tags = {"SaveBatchBySYS_ROLE" },  notes = "SaveBatchBySYS_ROLE")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_roles/{sys_role_id}/sys_user_roles/savebatch")
    public ResponseEntity<Boolean> saveBatchBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
             domain.setRoleid(sys_role_id);
        }
        sys_user_roleService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "fetchDEFAULTBySYS_ROLE", tags = {"SYS_USER_ROLEBySYS_ROLE" } ,notes = "fetchDEFAULTBySYS_ROLE")
    @RequestMapping(method= RequestMethod.GET , value="/sys_roles/{sys_role_id}/sys_user_roles/fetchdefault")
	public ResponseEntity<List<SYS_USER_ROLEDTO>> fetchSYS_USER_ROLEDefaultBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id,SYS_USER_ROLESearchContext context) {
        context.setN_sys_roleid_eq(sys_role_id);
        Page<SYS_USER_ROLE> domains = sys_user_roleService.searchDefault(context) ;
        List<SYS_USER_ROLEDTO> list = sys_user_roleMapping.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_USER_ROLEBySYS_ROLE" } ,notes = "searchDEFAULTBySYS_ROLE")
    @RequestMapping(method= RequestMethod.GET , value="/sys_roles/{sys_role_id}/sys_user_roles/searchdefault")
	public ResponseEntity<Page<SYS_USER_ROLEDTO>> searchSYS_USER_ROLEDefaultBySYS_ROLE(@PathVariable("sys_role_id") String sys_role_id,SYS_USER_ROLESearchContext context) {
        context.setN_sys_roleid_eq(sys_role_id);
        Page<SYS_USER_ROLE> domains = sys_user_roleService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sys_user_roleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}



    @ApiOperation(value = "CheckKeyBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "CheckKeyBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles/checkkey")
    public ResponseEntity<Boolean> checkKeyBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        return  ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.checkKey(sys_user_roleMapping.toDomain(sys_user_roledto)));
    }

    @ApiOperation(value = "GetDraftBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "GetDraftBySYS_USER")
    @RequestMapping(method = RequestMethod.GET, value = "/sys_users/{sys_user_id}/sys_user_roles/getdraft")
    public ResponseEntity<SYS_USER_ROLEDTO> getDraftBySYS_USER(@PathVariable("sys_user_id") String sys_user_id) {
        SYS_USER_ROLE domain = new SYS_USER_ROLE();
        domain.setUserid(sys_user_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleMapping.toDto(sys_user_roleService.getDraft(domain)));
    }

    @ApiOperation(value = "UpdateBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "UpdateBySYS_USER")
	@RequestMapping(method = RequestMethod.PUT, value = "/sys_users/{sys_user_id}/sys_user_roles/{sys_user_role_id}")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> updateBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @PathVariable("sys_user_role_id") String sys_user_role_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setUserid(sys_user_id);
        domain.setUserroleid(sys_user_role_id);
		sys_user_roleService.update(domain);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "UpdateBatchBySYS_USER", tags = {"UpdateBatchBySYS_USER" },  notes = "UpdateBatchBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles/updatebatch")
    public ResponseEntity<Boolean> updateBatchBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
            domain.setUserid(sys_user_id);
        }
        sys_user_roleService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "RemoveBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "RemoveBySYS_USER")
	@RequestMapping(method = RequestMethod.DELETE, value = "/sys_users/{sys_user_id}/sys_user_roles/{sys_user_role_id}")
    @Transactional
    public ResponseEntity<Boolean> removeBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @PathVariable("sys_user_role_id") String sys_user_role_id) {
		return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.remove(sys_user_role_id));
    }

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

    @ApiOperation(value = "CreateBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "CreateBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles")
    @Transactional
    public ResponseEntity<SYS_USER_ROLEDTO> createBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setUserid(sys_user_id);
		sys_user_roleService.create(domain);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "createBatchBySYS_USER", tags = {"createBatchBySYS_USER" },  notes = "createBatchBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles/createbatch")
    public ResponseEntity<Boolean> createBatchBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
            domain.setUserid(sys_user_id);
        }
        sys_user_roleService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "GetBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "GetBySYS_USER")
	@RequestMapping(method = RequestMethod.GET, value = "/sys_users/{sys_user_id}/sys_user_roles/{sys_user_role_id}")
    public ResponseEntity<SYS_USER_ROLEDTO> getBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @PathVariable("sys_user_role_id") String sys_user_role_id) {
        SYS_USER_ROLE domain = sys_user_roleService.get(sys_user_role_id);
        SYS_USER_ROLEDTO dto = sys_user_roleMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "SaveBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" },  notes = "SaveBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles/save")
    public ResponseEntity<Boolean> saveBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody SYS_USER_ROLEDTO sys_user_roledto) {
        SYS_USER_ROLE domain = sys_user_roleMapping.toDomain(sys_user_roledto);
        domain.setUserid(sys_user_id);
        return ResponseEntity.status(HttpStatus.OK).body(sys_user_roleService.save(domain));
    }

    @ApiOperation(value = "SaveBatchBySYS_USER", tags = {"SaveBatchBySYS_USER" },  notes = "SaveBatchBySYS_USER")
	@RequestMapping(method = RequestMethod.POST, value = "/sys_users/{sys_user_id}/sys_user_roles/savebatch")
    public ResponseEntity<Boolean> saveBatchBySYS_USER(@PathVariable("sys_user_id") String sys_user_id, @RequestBody List<SYS_USER_ROLEDTO> sys_user_roledtos) {
        List<SYS_USER_ROLE> domainlist=sys_user_roleMapping.toDomain(sys_user_roledtos);
        for(SYS_USER_ROLE domain:domainlist){
             domain.setUserid(sys_user_id);
        }
        sys_user_roleService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "fetchDEFAULTBySYS_USER", tags = {"SYS_USER_ROLEBySYS_USER" } ,notes = "fetchDEFAULTBySYS_USER")
    @RequestMapping(method= RequestMethod.GET , value="/sys_users/{sys_user_id}/sys_user_roles/fetchdefault")
	public ResponseEntity<List<SYS_USER_ROLEDTO>> fetchSYS_USER_ROLEDefaultBySYS_USER(@PathVariable("sys_user_id") String sys_user_id,SYS_USER_ROLESearchContext context) {
        context.setN_sys_userid_eq(sys_user_id);
        Page<SYS_USER_ROLE> domains = sys_user_roleService.searchDefault(context) ;
        List<SYS_USER_ROLEDTO> list = sys_user_roleMapping.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_USER", tags = {"SYS_USER_ROLEBySYS_USER" } ,notes = "searchDEFAULTBySYS_USER")
    @RequestMapping(method= RequestMethod.GET , value="/sys_users/{sys_user_id}/sys_user_roles/searchdefault")
	public ResponseEntity<Page<SYS_USER_ROLEDTO>> searchSYS_USER_ROLEDefaultBySYS_USER(@PathVariable("sys_user_id") String sys_user_id,SYS_USER_ROLESearchContext context) {
        context.setN_sys_userid_eq(sys_user_id);
        Page<SYS_USER_ROLE> domains = sys_user_roleService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(sys_user_roleMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}


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

}
