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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.DF;
import com.sa.ibiz.demo.demo.service.DFService;
import com.sa.ibiz.demo.demo.service.dto.DFSearchFilter;
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/df")
public class DFResource
{
	@Autowired
	private DFService service;


	@PostMapping(value = "/create")
	public ResponseEntity<DF> create(@Validated @RequestBody DF data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("电费[create]操作发生错误","DF",data.getDfid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<DF> remove(@Validated @RequestBody DF data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("电费[remove]操作发生错误","DF",data.getDfid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<DF> get(@Validated @PathVariable String id){
		DF data=new DF();
		data.setDfid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("电费[get]操作发生错误","DF",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<DF> update(@Validated @RequestBody DF data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("电费[update]操作发生错误","DF",data.getDfid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<DF> getDraft(@Validated @RequestBody DF data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("电费[getDraft]操作发生错误","DF","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<DF> checkKey(@Validated @RequestBody DF data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("电费[checkKey]操作发生错误","DF",data.getDfid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<DF>> searchDefaultPage(@Validated @RequestBody DFSearchFilter filter){
		Page<DF> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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