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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.TSSDItem;
import com.sa.ibiz.demo.demo.service.TSSDItemService;
import com.sa.ibiz.demo.demo.service.dto.TSSDItemSearchFilter;
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/tssditem")
public class TSSDItemResource
{
	@Autowired
	private TSSDItemService service;


	@PostMapping(value = "/update")
	public ResponseEntity<TSSDItem> update(@Validated @RequestBody TSSDItem data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("任务时刻策略项[update]操作发生错误","TSSDItem",data.getTssditemid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<TSSDItem> create(@Validated @RequestBody TSSDItem data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("任务时刻策略项[create]操作发生错误","TSSDItem",data.getTssditemid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<TSSDItem> checkKey(@Validated @RequestBody TSSDItem data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("任务时刻策略项[checkKey]操作发生错误","TSSDItem",data.getTssditemid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<TSSDItem> get(@Validated @PathVariable String id){
		TSSDItem data=new TSSDItem();
		data.setTssditemid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("任务时刻策略项[get]操作发生错误","TSSDItem",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<TSSDItem> remove(@Validated @RequestBody TSSDItem data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("任务时刻策略项[remove]操作发生错误","TSSDItem",data.getTssditemid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<TSSDItem> getDraft(@Validated @RequestBody TSSDItem data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("任务时刻策略项[getDraft]操作发生错误","TSSDItem","");
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<TSSDItem>> searchDefaultPage(@Validated @RequestBody TSSDItemSearchFilter filter){
		Page<TSSDItem> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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