package com.gyee.frame.controller.admin;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.gyee.frame.common.base.BaseController;
import com.gyee.frame.model.auto.TsysDatas;
import com.gyee.frame.model.custom.PublicMsg;
import com.gyee.frame.model.custom.Ueditor;
import com.gyee.frame.service.UeditorService;
import io.swagger.annotations.Api;

/**
 * 百度Controller
 * @ClassName: UeditorController
 * @author gyee
 * @date 2019-11-20 22:34
 */
@Api(value = "百度编辑器")
@Controller
@RequestMapping("/UeditorController")
public class UeditorController  extends BaseController{
	@Autowired
	private UeditorService ueditorService;
	
	
	@RequestMapping("/ueditor")
    @ResponseBody
    public Object ueditor(HttpServletRequest request,String action,MultipartFile upfile) {
		if("websocket".equals(action)) {
			  return PublicMsg.UEDITOR_CONFIG;
		}
		if ("uploadimage".equals(action)) {//图片上传
			
			try {
				//添加文件到本地
				TsysDatas	tsysDatas = ueditorService.fileDataByinsert(upfile);
				//添加文件信息
				ueditorService.fileInfoByininsert(tsysDatas.getId());
				String url2=request.getScheme()+"://"+ request.getServerName()+":"+request.getLocalPort()+request.getContextPath()+"/"+tsysDatas.getFilePath();
				Ueditor ueditor = new Ueditor("SUCCESS",url2, "ssss", "");
			    return ueditor;
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			return null;
		}if ("uploadfile".equals(action)) {//文件上传


		}
		return PublicMsg.UeditorMsg.ERROR.get();
    }

    @RequestMapping(value="/imgUpload")
    @ResponseBody
    public Ueditor imgUpload(MultipartFile upfile) {
        Ueditor ueditor = new Ueditor();
        return ueditor;
    }
    
    

    	
    public String updateAvatar(MultipartFile file)
    {
        try
        {
            if (!file.isEmpty())
            {
                //插入文件存储表
            	String id=sysDatasService.insertSelective(file);
                if(id!=null){
                	 return id;
                }
            }
            return null;
        }
        catch (Exception e)
        {
            return null;
        }
    }

	
}
