package com.sa.ibiz.demo.demo.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.OrgSecUser;
import com.sa.ibiz.demo.demo.service.OrgSecUserService;
import com.sa.ibiz.demo.demo.service.dto.OrgSecUserSearchFilter;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;

@RestController
@RequestMapping("/demo/orgsecuser")
public class OrgSecUserResource
{
	@Autowired
	private OrgSecUserService service;


	@PostMapping(value = "/checkKey")
	public ResponseEntity<OrgSecUser> checkKey(@Validated @RequestBody OrgSecUser data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("组织部门人员[checkKey]操作发生错误","OrgSecUser",data.getOrgsecuserid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/removeDefault")
	public ResponseEntity<OrgSecUser> removeDefault(@Validated @RequestBody OrgSecUser data){
		service.removeDefault(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<OrgSecUser> create(@Validated @RequestBody OrgSecUser data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("组织部门人员[create]操作发生错误","OrgSecUser",data.getOrgsecuserid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<OrgSecUser> update(@Validated @RequestBody OrgSecUser data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("组织部门人员[update]操作发生错误","OrgSecUser",data.getOrgsecuserid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<OrgSecUser> get(@Validated @PathVariable String id){
		OrgSecUser data=new OrgSecUser();
		data.setOrgsecuserid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("组织部门人员[get]操作发生错误","OrgSecUser",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<OrgSecUser> getDraft(@Validated @RequestBody OrgSecUser data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("组织部门人员[getDraft]操作发生错误","OrgSecUser","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<OrgSecUser> remove(@Validated @RequestBody OrgSecUser data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("组织部门人员[remove]操作发生错误","OrgSecUser",data.getOrgsecuserid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<OrgSecUser>> searchDefaultPage(@Validated @RequestBody OrgSecUserSearchFilter filter){
		Page<OrgSecUser> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<OrgSecUser>> listDefault(@Validated @RequestBody OrgSecUserSearchFilter filter){
		List<OrgSecUser> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
