package com.sinosig.web.external.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import com.sinosig.web.external.service.JQXBJService;
import com.sinosig.web.external.domain.JQXBJ;
import com.sinosig.web.external.filter.*;

@RestController
@RequestMapping(value = "")
public class JQXBJController {
	@Autowired
    JQXBJService jqxbjservice;


	@RequestMapping(method = RequestMethod.PUT, value = "/jqxbjs/{jqxbj_id}")
    public ResponseEntity<JQXBJ> update(@PathVariable("jqxbj_id") String jqxbj_id, @RequestBody JQXBJ jqxbj) {
        JQXBJ jqxbj2 = jqxbjservice.update(jqxbj_id, jqxbj);
        return ResponseEntity.status(HttpStatus.OK).body(jqxbj2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/jqxbjs/{jqxbj_id}")
    public ResponseEntity<JQXBJ> get(@PathVariable("jqxbj_id") String jqxbj_id) {
        JQXBJ jqxbj = jqxbjservice.get( jqxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(jqxbj);
    }

	@RequestMapping(method = RequestMethod.DELETE, value = "/jqxbjs/{jqxbj_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("jqxbj_id") String jqxbj_id) {
        boolean b = jqxbjservice.remove( jqxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/jqxbjs/{jqxbj_id}/save")
    public ResponseEntity<JQXBJ> save(@PathVariable("jqxbj_id") String jqxbj_id, @RequestBody JQXBJ jqxbj) {
        JQXBJ jqxbj2 = jqxbjservice.save(jqxbj_id, jqxbj);
        return ResponseEntity.status(HttpStatus.OK).body(jqxbj2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/jqxbjs")
    public ResponseEntity<JQXBJ> create(@RequestBody JQXBJ jqxbj) {
        JQXBJ jqxbj2 = jqxbjservice.create(jqxbj);
        return ResponseEntity.status(HttpStatus.OK).body(jqxbj2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/jqxbjs/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody JQXBJ jqxbj) {
        boolean b = jqxbjservice.checkKey(jqxbj);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/jqxbjs/getdraft")
    public ResponseEntity<JQXBJ> getDraft() {
        //JQXBJ jqxbj = jqxbjservice.getDraft( jqxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(new JQXBJ());
    }

    @RequestMapping(method= RequestMethod.GET , value="/jqxbjs/fetchdefault")
	public ResponseEntity<List<JQXBJ>> fetchDefault(JQXBJSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<JQXBJ> page = jqxbjservice.fetchDefault(searchContext);
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(pageable.getPageNumber()))
        		.header("x-per-page", String.valueOf(pageable.getPageSize()))
        		.header("x-total", String.valueOf(page.getTotalElements()))
        		.body(page.getContent());
    }


}
