package com.sinosig.web.module.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.module.service.SJZDXService;
import com.sinosig.web.module.domain.SJZDX;
import com.sinosig.web.module.filter.*;

@RestController
@RequestMapping(value = "")
public class SJZDXController {
	@Autowired
    SJZDXService sjzdxservice;


	@RequestMapping(method = RequestMethod.POST, value = "/sjzdxes")
    public ResponseEntity<SJZDX> create(@RequestBody SJZDX sjzdx) {
        SJZDX sjzdx2 = sjzdxservice.create(sjzdx);
        return ResponseEntity.status(HttpStatus.OK).body(sjzdx2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/sjzdxes/{sjzdx_id}")
    public ResponseEntity<SJZDX> get(@PathVariable("sjzdx_id") String sjzdx_id) {
        SJZDX sjzdx = sjzdxservice.get( sjzdx_id);
        return ResponseEntity.status(HttpStatus.OK).body(sjzdx);
    }

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

	@RequestMapping(method = RequestMethod.POST, value = "/sjzdxes/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody SJZDX sjzdx) {
        boolean b = sjzdxservice.checkKey(sjzdx);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/sjzdxes/{sjzdx_id}")
    public ResponseEntity<SJZDX> update(@PathVariable("sjzdx_id") String sjzdx_id, @RequestBody SJZDX sjzdx) {
        SJZDX sjzdx2 = sjzdxservice.update(sjzdx_id, sjzdx);
        return ResponseEntity.status(HttpStatus.OK).body(sjzdx2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/sjzdxes/getdraft")
    public ResponseEntity<SJZDX> getDraft() {
        //SJZDX sjzdx = sjzdxservice.getDraft( sjzdx_id);
        return ResponseEntity.status(HttpStatus.OK).body(new SJZDX());
    }

	@RequestMapping(method = RequestMethod.POST, value = "/sjzdxes/{sjzdx_id}/save")
    public ResponseEntity<SJZDX> save(@PathVariable("sjzdx_id") String sjzdx_id, @RequestBody SJZDX sjzdx) {
        SJZDX sjzdx2 = sjzdxservice.save(sjzdx_id, sjzdx);
        return ResponseEntity.status(HttpStatus.OK).body(sjzdx2);
    }

    @RequestMapping(method= RequestMethod.GET , value="/sjzdxes/fetchclzl")
	public ResponseEntity<List<SJZDX>> fetchCLZL(SJZDXSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<SJZDX> page = sjzdxservice.fetchCLZL(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());
    }

    @RequestMapping(method= RequestMethod.GET , value="/sjzdxes/fetchywly")
	public ResponseEntity<List<SJZDX>> fetchYWLY(SJZDXSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<SJZDX> page = sjzdxservice.fetchYWLY(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());
    }

    @RequestMapping(method= RequestMethod.GET , value="/sjzdxes/fetchcldl")
	public ResponseEntity<List<SJZDX>> fetchCLDL(SJZDXSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<SJZDX> page = sjzdxservice.fetchCLDL(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());
    }

    @RequestMapping(method= RequestMethod.GET , value="/sjzdxes/fetchdefault")
	public ResponseEntity<List<SJZDX>> fetchDefault(SJZDXSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<SJZDX> page = sjzdxservice.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());
    }


}
