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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.PVPart;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.dto.PVPartSearchFilter;
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/pvpart")
public class PVPartResource
{
	@Autowired
	private PVPartService service;


	@PostMapping(value = "/create")
	public ResponseEntity<PVPart> create(@Validated @RequestBody PVPart data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("门户视图部件[create]操作发生错误","PVPart",data.getPvpartid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<PVPart> getDraft(@Validated @RequestBody PVPart data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("门户视图部件[getDraft]操作发生错误","PVPart","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<PVPart> checkKey(@Validated @RequestBody PVPart data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("门户视图部件[checkKey]操作发生错误","PVPart",data.getPvpartid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<PVPart> update(@Validated @RequestBody PVPart data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("门户视图部件[update]操作发生错误","PVPart",data.getPvpartid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<PVPart> get(@Validated @PathVariable String id){
		PVPart data=new PVPart();
		data.setPvpartid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("门户视图部件[get]操作发生错误","PVPart",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<PVPart> remove(@Validated @RequestBody PVPart data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("门户视图部件[remove]操作发生错误","PVPart",data.getPvpartid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchcurpv")
	public ResponseEntity<Page<PVPart>> searchCurPVPage(@Validated @RequestBody PVPartSearchFilter filter){
		Page<PVPart> searchResult = service.searchCurPV(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listcurpv")
	public ResponseEntity<List<PVPart>> listCurPV(@Validated @RequestBody PVPartSearchFilter filter){
		List<PVPart> searchResult = service.listCurPV(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<PVPart>> searchDefaultPage(@Validated @RequestBody PVPartSearchFilter filter){
		Page<PVPart> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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