|
@@ -1,19 +1,23 @@
|
|
|
package com.fdkankan.ucenter.controller.app;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.amazonaws.services.marketplacemetering.model.UsageRecord;
|
|
|
+import com.dtflys.forest.annotation.JSONBody;
|
|
|
+import com.fdkankan.common.constant.SceneConstant;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
import com.fdkankan.common.util.SecurityUtil;
|
|
|
import com.fdkankan.ucenter.common.Result;
|
|
|
import com.fdkankan.ucenter.constant.LoginConstant;
|
|
|
-import com.fdkankan.ucenter.entity.User;
|
|
|
-import com.fdkankan.ucenter.service.ISceneProService;
|
|
|
-import com.fdkankan.ucenter.service.IUserService;
|
|
|
+import com.fdkankan.ucenter.entity.*;
|
|
|
+import com.fdkankan.ucenter.service.*;
|
|
|
import com.fdkankan.ucenter.service.impl.LoginService;
|
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
|
import com.fdkankan.ucenter.vo.response.LoginVo;
|
|
|
import com.fdkankan.ucenter.vo.response.UserVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -24,6 +28,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -33,11 +40,32 @@ public class SceneApiController {
|
|
|
@Autowired
|
|
|
ISceneProService sceneProService;
|
|
|
@Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
IUserService userService;
|
|
|
- @Value("${main.url}")
|
|
|
- private String mainUrl;
|
|
|
@Autowired
|
|
|
LoginService loginService;
|
|
|
+ @Autowired
|
|
|
+ ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ ISceneCooperationService cooperationService;
|
|
|
+
|
|
|
+ @Value("${main.url}")
|
|
|
+ private String mainUrl;
|
|
|
+
|
|
|
+ @Value("${scene.url}")
|
|
|
+ private String sceneUrl;
|
|
|
+
|
|
|
+ @Value("${scene.pro.url}")
|
|
|
+ private String sceneProUrl;
|
|
|
+
|
|
|
+ @Value("${scene.pro.new.url}")
|
|
|
+ private String sceneProNewUrl;
|
|
|
+
|
|
|
+ @Value("${scene.pro.v4.url}")
|
|
|
+ private String sceneProV4Url;
|
|
|
|
|
|
/**
|
|
|
* 获取指定场景信息
|
|
@@ -48,6 +76,130 @@ public class SceneApiController {
|
|
|
return Result.success( sceneProService.getInfo(num) );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //跳转到编辑页面
|
|
|
+ @RequestMapping("/goEditScenePage")
|
|
|
+ public void goEditScenePage(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
|
|
+ String phoneNum = request.getParameter("phoneNum");
|
|
|
+ String password = request.getParameter("password");
|
|
|
+ String sceneNum = request.getParameter("sceneNum");
|
|
|
+ String childName = request.getParameter("childName");
|
|
|
+ String lang = request.getParameter("lang");
|
|
|
+ String vlog = request.getParameter("vlog");
|
|
|
+
|
|
|
+ ScenePro scene = sceneProService.getByNum(sceneNum);
|
|
|
+ ScenePlus scenePlus = null;
|
|
|
+ if(scene == null){
|
|
|
+ scenePlus = scenePlusService.getByNum(sceneNum);
|
|
|
+ }
|
|
|
+ if(scene == null && scenePlus == null) {
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
+ }
|
|
|
+ Long userId = scene == null ? scenePlus.getUserId() : scene.getUserId();
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(childName)){
|
|
|
+ Camera cameraEntity = cameraService.getByChildName(childName);
|
|
|
+ if(cameraEntity != null){
|
|
|
+ CameraDetail cameraDetailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
|
|
|
+ if(cameraDetailEntity != null && cameraDetailEntity.getCooperationUser() != null){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
+ }
|
|
|
+ UserVo user = new UserVo();
|
|
|
+ if(userId == null){
|
|
|
+ user.setUserName(childName);
|
|
|
+ user.setCameraLogin(1);
|
|
|
+ user.setCameraId(cameraEntity.getId());
|
|
|
+ }else {
|
|
|
+ User dbUser = userService.getById(userId);
|
|
|
+ BeanUtils.copyProperties(dbUser,user);
|
|
|
+ }
|
|
|
+
|
|
|
+ String token = JwtUtil.createJWT(-1, user.getUserName(),"user");
|
|
|
+ loginService.redisLogin(user.getUserName(), JSONObject.toJSONString(user));
|
|
|
+
|
|
|
+ //登录成功
|
|
|
+ if(scene.getWebSite().contains(sceneProUrl)){
|
|
|
+ response.sendRedirect(mainUrl + sceneProUrl.replace("show", "edit").replace("PC", "Mobile") +
|
|
|
+ sceneNum + "&t=" +System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(scene.getIsUpgrade() != null && scene.getIsUpgrade() == 1){
|
|
|
+ if(scene.getWebSite().contains(sceneProV4Url)){
|
|
|
+ response.sendRedirect(mainUrl + sceneProV4Url.replace("s", "e") +
|
|
|
+ sceneNum + "&t=" +System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(scene.getWebSite().contains(sceneProNewUrl)){
|
|
|
+ response.sendRedirect(mainUrl + sceneProNewUrl.replace("s", "e") +
|
|
|
+ sceneNum + "&t=" +System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(phoneNum) || StringUtils.isEmpty(password)
|
|
|
+ || StringUtils.isEmpty(sceneNum)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(userId == null) {
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userService.getByUserName(phoneNum);
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+ UserVo ssoUser = new UserVo();
|
|
|
+ BeanUtils.copyProperties(user,ssoUser);
|
|
|
+
|
|
|
+ if(ssoUser.getId().longValue() != scene.getUserId().longValue()) {
|
|
|
+ HashMap<String, User> cooMap = cooperationService.getByNumList(Arrays.asList(sceneNum));
|
|
|
+ User cooUser = cooMap.get(sceneNum);
|
|
|
+ if(cooUser == null ){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
+ }
|
|
|
+ if(cooUser.getId().longValue() != ssoUser.getId().longValue()){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!SecurityUtil.MD5(password).equals(ssoUser.getPassword()))
|
|
|
+ {
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+
|
|
|
+ String token = JwtUtil.createJWT(-1, ssoUser.getUserName(),"user");
|
|
|
+ loginService.redisLogin(ssoUser.getUserName(),JSONObject.toJSONString(ssoUser));
|
|
|
+ //登录成功
|
|
|
+ if(scene.getWebSite().contains(sceneProUrl)){
|
|
|
+ response.sendRedirect(mainUrl + sceneProUrl.replace("show", "edit").replace("PC", "Mobile") +
|
|
|
+ sceneNum + "&t=" +System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(scene.getIsUpgrade() != null && scene.getIsUpgrade() == 1){
|
|
|
+ if(scene.getWebSite().contains(sceneProV4Url)){
|
|
|
+ response.sendRedirect(mainUrl + sceneProV4Url.replace("s", "e") +
|
|
|
+ sceneNum + "&t=" +System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(scene.getWebSite().contains(sceneProNewUrl)) {
|
|
|
+ response.sendRedirect(mainUrl + sceneProNewUrl.replace("s", "e") +
|
|
|
+ sceneNum + "&t=" + System.currentTimeMillis() + "&token=" + token + "&app" +
|
|
|
+ (lang == null ? "" : "&lang=" + lang) + (vlog == null ? "" : "&vlog=" + vlog));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//app调用 跳转到官网消费页面
|
|
|
@RequestMapping("/goConsumptionPage")
|
|
|
public void goConsumptionPage(HttpServletRequest request, HttpServletResponse response) throws Exception{
|