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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.DEDataChg2;
import com.sa.ibiz.demo.demo.service.DEDataChg2Service;
import com.sa.ibiz.demo.demo.service.dto.DEDataChg2SearchFilter;
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/dedatachg2")
public class DEDataChg2Resource
{
	@Autowired
	private DEDataChg2Service service;


	@PostMapping(value = "/getDraft")
	public ResponseEntity<DEDataChg2> getDraft(@Validated @RequestBody DEDataChg2 data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("实体数据变更（已处理）[getDraft]操作发生错误","DEDataChg2","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<DEDataChg2> remove(@Validated @RequestBody DEDataChg2 data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("实体数据变更（已处理）[remove]操作发生错误","DEDataChg2",data.getDedatachg2id().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<DEDataChg2> checkKey(@Validated @RequestBody DEDataChg2 data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("实体数据变更（已处理）[checkKey]操作发生错误","DEDataChg2",data.getDedatachg2id().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<DEDataChg2> update(@Validated @RequestBody DEDataChg2 data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("实体数据变更（已处理）[update]操作发生错误","DEDataChg2",data.getDedatachg2id().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<DEDataChg2> get(@Validated @PathVariable String id){
		DEDataChg2 data=new DEDataChg2();
		data.setDedatachg2id(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("实体数据变更（已处理）[get]操作发生错误","DEDataChg2",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<DEDataChg2> create(@Validated @RequestBody DEDataChg2 data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("实体数据变更（已处理）[create]操作发生错误","DEDataChg2",data.getDedatachg2id().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<DEDataChg2>> searchDefaultPage(@Validated @RequestBody DEDataChg2SearchFilter filter){
		Page<DEDataChg2> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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