CommonController.java
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.glsx.publicservice.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.github.pagehelper.util.StringUtil;
import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultCodeEnum;
import com.glsx.common.constants.ResultObject;
import com.glsx.publicservice.service.CommonService;
import com.glsx.publicservice.util.fastdfs.FastDFSClientWrapper;
/**
*
* @Title CommonController.java
* @Package com.glsx.publicservice.controller
* @Description TODO
* @author zhanghj
* @date 2019年2月16日 下午5:41:40
* @version 1.0.0
*/
@RestController
@RequestMapping(value="/common")
public class CommonController
{
private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
@Autowired
private CommonService commonService;
@RequestMapping(value="/sendVerificationCode", method={RequestMethod.GET, RequestMethod.POST})
public ResultObject sendVerificationCode(HttpServletRequest request, String phone){
Map<String, Object> result = new HashMap<String, Object>();
try{
if (StringUtil.isEmpty(phone)){
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:"+ verifyCode);
//result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
} catch(RedisSystemException e){
logger.error("获取验证码redis异常" + e.getMessage(), e);
/*
* 测试环境redis连接总被重试异常重试
*/
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:"+ verifyCode);
result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}catch(Exception e){
logger.error("获取验证码失败" + e.getMessage(), e);
return new ResultObject(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getMsg());
}
}
@AuthCheck
@RequestMapping(value="/uploadFile" , method = RequestMethod.POST)
public ResultObject uploadImage(@RequestParam("file")MultipartFile file, HttpServletRequest request) throws IOException{
String path = FastDFSClientWrapper.uploadFile(file);
logger.info("上传文件路径==" + path);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), path);
}
@RequestMapping(value="/upload", method=RequestMethod.GET)
public ModelAndView get(ModelAndView mv){
mv.setViewName("fileUpload");
return mv;
}
}