package com.platform.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.base.BaseController;
import com.platform.entities.VolumeEntity;
import com.platform.entities.VolumeForm;
import com.platform.entities.VolumeInitEntity;
import com.platform.http.gfs.HttpUtils;
import com.platform.service.IVolumeService;
import com.platform.utils.Configs;
import com.platform.utils.ThreadVolume;
import com.platform.utils.ThreadVolumeImm;

@Controller
public class VolumeController extends BaseController{
	
	public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(VolumeController.class);
	
	@Resource(name = "volumeService")
	private IVolumeService volumeService;
	
	HttpUtils ht = new HttpUtils();
	
	@RequestMapping(value = "/volume/update", method = RequestMethod.POST)
	@ResponseBody
	public String volumeUpdate(HttpServletRequest res, HttpServletResponse req,
			@RequestBody VolumeEntity form) throws Exception {
		Configs.CONSOLE_LOGGER.error("/oracle/update");
		int rest = volumeService.save(form);
		if (rest == 1) {
			req.setStatus(200);
		}
		else {
			req.setStatus(500);
		}
		String result = ht.sendPost("gfs/getAllvolume", null);
		new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-update").start();
		return result;
	}
	
	@RequestMapping(value = "/volume/delete", method = RequestMethod.POST)
	@ResponseBody
	public String volumeDelete(HttpServletRequest res, HttpServletResponse req,
			@RequestBody VolumeEntity entity) throws Exception {
		Configs.CONSOLE_LOGGER.error("/volume/delete");
		int rest = volumeService.delete(entity);
		if (rest == 1) {
			req.setStatus(200);
		}
		else {
			req.setStatus(500);
		}
		String result = ht.sendPost("gfs/getAllvolume", null);
		new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-delete").start();
		return result;
	}

}
