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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.XM;
import com.sa.ibiz.demo.demo.service.XMService;
import com.sa.ibiz.demo.demo.service.dto.XMSearchFilter;
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/xm")
public class XMResource
{
	@Autowired
	private XMService service;


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

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