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.VolumeDataEntity;
import com.platform.http.gfs.SetVolume;
import com.platform.service.IVolumeService;
import com.platform.utils.ThreadVolumeImm;

/** gfs业务
 * @author chen
 *
 */
@Controller
public class VolumeController extends BaseController{
	
	public static Logger log = Logger.getLogger(VolumeController.class);
	
	/**
	 * gfs业务管理
	 */
	@Resource(name = "volumeService")
	private IVolumeService volumeService;
	
	/**
	 * volumeClient 请求 客户端类
	 */
	SetVolume volumeClient = new SetVolume();
	
	/** volume更新
	 * @param res
	 * @param req
	 * @param form
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/volume/update", method = RequestMethod.POST)
	@ResponseBody
	public String volumeUpdate(HttpServletRequest res, HttpServletResponse req,
			@RequestBody VolumeDataEntity form) throws Exception {
		log.error("/oracle/update");
		int rest = volumeService.save(form);
		if (rest == 1) {
			req.setStatus(200);
		}
		else {
			req.setStatus(500);
		}
		String result = volumeService.getAllvolume();
		new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-update").start();
		return result;
	}
	
	/** volume删除
	 * @param res
	 * @param req
	 * @param entity
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/volume/delete", method = RequestMethod.POST)
	@ResponseBody
	public String volumeDelete(HttpServletRequest res, HttpServletResponse req,
			@RequestBody VolumeDataEntity entity) throws Exception {
		log.error("/volume/delete");
		int rest = volumeService.delete(entity);
		if (rest == 1) {
			req.setStatus(200);
		}
		else {
			req.setStatus(500);
		}
		String result = volumeClient.getAllvolume();
		new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-delete").start();
		return result;
	}

}
