|
@@ -2,21 +2,28 @@ package cn.rankin.apiweb.controller;
|
|
|
|
|
|
import cn.rankin.apiweb.assist.resolver.NeedUser;
|
|
|
import cn.rankin.apiweb.code.ApiWebCode;
|
|
|
+import cn.rankin.apiweb.service.download.DownloadInfoService;
|
|
|
import cn.rankin.apiweb.service.event.EventService;
|
|
|
+import cn.rankin.common.utils.api.model.APICode;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.data.api.app.vo.DeviceUserVo;
|
|
|
+import cn.rankin.data.api.user.dto.DownloadInfoDTO;
|
|
|
import cn.rankin.data.api.user.dto.EventLogDTO;
|
|
|
+import cn.rankin.data.api.user.entity.DownloadInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-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.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* CallbackController
|
|
|
* Created by huodongdong on 2017/10/27.
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/callback")
|
|
|
public class CallbackController {
|
|
@@ -24,6 +31,9 @@ public class CallbackController {
|
|
|
@Autowired
|
|
|
private EventService eventService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DownloadInfoService downloadInfoService;
|
|
|
+
|
|
|
@RequestMapping(value = "/event", method = RequestMethod.POST)
|
|
|
public APIResult<Boolean> addEvent(@NeedUser DeviceUserVo user, @RequestBody EventLogDTO eventLog) {
|
|
|
if (eventLog.getEventType() == null ) {
|
|
@@ -36,5 +46,80 @@ public class CallbackController {
|
|
|
APIResult<Boolean> result = eventService.addLog(eventLog);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download/add", method = RequestMethod.POST)
|
|
|
+ public APIResult<Boolean> addDownloadInfo(HttpServletRequest request, @NeedUser DeviceUserVo user, @RequestBody DownloadInfoDTO dto) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1.获得客户机信息
|
|
|
+ */
|
|
|
+ String requestUrl = request.getRequestURL().toString();//得到请求的URL地址
|
|
|
+ String requestUri = request.getRequestURI();//得到请求的资源
|
|
|
+ String queryString = request.getQueryString();//得到请求的URL地址中附带的参数
|
|
|
+ String remoteAddr = request.getRemoteAddr();//得到来访者的IP地址
|
|
|
+ String remoteHost = request.getRemoteHost();
|
|
|
+ int remotePort = request.getRemotePort();
|
|
|
+ String remoteUser = request.getRemoteUser();
|
|
|
+ String method = request.getMethod();//得到请求URL地址时使用的方法
|
|
|
+ String pathInfo = request.getPathInfo();
|
|
|
+ String localAddr = request.getLocalAddr();//获取WEB服务器的IP地址
|
|
|
+ String localName = request.getLocalName();//获取WEB服务器的主机名
|
|
|
+ String info = request.getHeader("user-agent");
|
|
|
+
|
|
|
+ if(StringUtils.isBlank(dto.getLessonId())){
|
|
|
+ return APIResult.error(ApiWebCode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(dto.getData())){
|
|
|
+ //return APIResult.error(ApiWebCode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+ dto.setMerchantId(user.getMerchantId());
|
|
|
+ dto.setUserId(user.getUid());
|
|
|
+
|
|
|
+
|
|
|
+ DownloadInfo downloadInfo = downloadInfoService.add(dto);
|
|
|
+ if(downloadInfo != null){
|
|
|
+ return APIResult.ok();
|
|
|
+ }else{
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download/list", method = RequestMethod.GET)
|
|
|
+ public APIResult<List<DownloadInfo>> findByUserId(@NeedUser DeviceUserVo user) {
|
|
|
+ List<DownloadInfo> downloadInfos = downloadInfoService.findByUserId(user.getUid());
|
|
|
+ return APIResult.ok(downloadInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download/find", method = RequestMethod.GET)
|
|
|
+ public APIResult<DownloadInfo> findByLessonUserId(@NeedUser DeviceUserVo user,@RequestParam("lessonId") String lessonId) {
|
|
|
+ DownloadInfo downloadInfo = downloadInfoService.findByLessonUserId(user.getUid(),lessonId);
|
|
|
+ if(downloadInfo != null){
|
|
|
+ return APIResult.ok(downloadInfo);
|
|
|
+ }else{
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download/delete", method = RequestMethod.DELETE)
|
|
|
+ public APIResult<Boolean> deleteByLessonUserId(@NeedUser DeviceUserVo user,@RequestParam("lessonId") String lessonId) {
|
|
|
+ DownloadInfo downloadInfo = downloadInfoService.deleteByLessonUserId(user.getUid(),lessonId);
|
|
|
+ if(downloadInfo == null){
|
|
|
+ APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+ return APIResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download/update", method = RequestMethod.PUT)
|
|
|
+ public APIResult<Boolean> updateByLessonUserId(@NeedUser DeviceUserVo user,@RequestParam("lessonId") String lessonId) {
|
|
|
+ DownloadInfo downloadInfo = downloadInfoService.updateByLessonUserId(user.getUid(),lessonId);
|
|
|
+ if(downloadInfo == null){
|
|
|
+ APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+ return APIResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|