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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.Org;
import com.sa.ibiz.demo.demo.service.OrgService;
import com.sa.ibiz.demo.demo.service.dto.OrgSearchFilter;
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/org")
public class OrgResource
{
	@Autowired
	private OrgService service;


	@PostMapping(value = "/remove")
	public ResponseEntity<Org> remove(@Validated @RequestBody Org data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("组织机构[remove]操作发生错误","Org",data.getOrgid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<Org> getDraft(@Validated @RequestBody Org data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("组织机构[getDraft]操作发生错误","Org","");
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<Org> get(@Validated @PathVariable String id){
		Org data=new Org();
		data.setOrgid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("组织机构[get]操作发生错误","Org",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<Org> update(@Validated @RequestBody Org data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("组织机构[update]操作发生错误","Org",data.getOrgid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/initUserObject")
	public ResponseEntity<Org> initUserObject(@Validated @RequestBody Org data){
		service.initUserObject(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<Org> checkKey(@Validated @RequestBody Org data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("组织机构[checkKey]操作发生错误","Org",data.getOrgid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/initAll")
	public ResponseEntity<Org> initAll(@Validated @RequestBody Org data){
		service.initAll(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<Org> create(@Validated @RequestBody Org data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("组织机构[create]操作发生错误","Org",data.getOrgid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchcurchild")
	public ResponseEntity<Page<Org>> searchCurChildPage(@Validated @RequestBody OrgSearchFilter filter){
		Page<Org> searchResult = service.searchCurChild(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listcurchild")
	public ResponseEntity<List<Org>> listCurChild(@Validated @RequestBody OrgSearchFilter filter){
		List<Org> searchResult = service.listCurChild(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<Org>> searchDefaultPage(@Validated @RequestBody OrgSearchFilter filter){
		Page<Org> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<Org>> listDefault(@Validated @RequestBody OrgSearchFilter filter){
		List<Org> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchcurcat")
	public ResponseEntity<Page<Org>> searchCurCatPage(@Validated @RequestBody OrgSearchFilter filter){
		Page<Org> searchResult = service.searchCurCat(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listcurcat")
	public ResponseEntity<List<Org>> listCurCat(@Validated @RequestBody OrgSearchFilter filter){
		List<Org> searchResult = service.listCurCat(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchallroot")
	public ResponseEntity<Page<Org>> searchAllRootPage(@Validated @RequestBody OrgSearchFilter filter){
		Page<Org> searchResult = service.searchAllRoot(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listallroot")
	public ResponseEntity<List<Org>> listAllRoot(@Validated @RequestBody OrgSearchFilter filter){
		List<Org> searchResult = service.listAllRoot(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
