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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.WFStepData;
import com.sa.ibiz.demo.demo.service.WFStepDataService;
import com.sa.ibiz.demo.demo.service.dto.WFStepDataSearchFilter;
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/wfstepdata")
public class WFStepDataResource
{
	@Autowired
	private WFStepDataService service;


	@PostMapping(value = "/remove")
	public ResponseEntity<WFStepData> remove(@Validated @RequestBody WFStepData data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("工作流步骤数据[remove]操作发生错误","WFStepData",data.getWfstepdataid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<WFStepData> update(@Validated @RequestBody WFStepData data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("工作流步骤数据[update]操作发生错误","WFStepData",data.getWfstepdataid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/rollback")
	public ResponseEntity<WFStepData> rollback(@Validated @RequestBody WFStepData data){
		service.rollback(data);
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<WFStepData> get(@Validated @PathVariable String id){
		WFStepData data=new WFStepData();
		data.setWfstepdataid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("工作流步骤数据[get]操作发生错误","WFStepData",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<WFStepData> create(@Validated @RequestBody WFStepData data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("工作流步骤数据[create]操作发生错误","WFStepData",data.getWfstepdataid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<WFStepData> getDraft(@Validated @RequestBody WFStepData data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("工作流步骤数据[getDraft]操作发生错误","WFStepData","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<WFStepData> checkKey(@Validated @RequestBody WFStepData data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("工作流步骤数据[checkKey]操作发生错误","WFStepData",data.getWfstepdataid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<WFStepData>> searchDefaultPage(@Validated @RequestBody WFStepDataSearchFilter filter){
		Page<WFStepData> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<WFStepData>> listDefault(@Validated @RequestBody WFStepDataSearchFilter filter){
		List<WFStepData> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchmyhist")
	public ResponseEntity<Page<WFStepData>> searchMyHistPage(@Validated @RequestBody WFStepDataSearchFilter filter){
		Page<WFStepData> searchResult = service.searchMyHist(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listmyhist")
	public ResponseEntity<List<WFStepData>> listMyHist(@Validated @RequestBody WFStepDataSearchFilter filter){
		List<WFStepData> searchResult = service.listMyHist(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
