|
@@ -0,0 +1,87 @@
|
|
|
+package com.fdkankan.user.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.Base64Converter;
|
|
|
+import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.common.util.SecurityUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.user.common.RedisKeyUtil;
|
|
|
+import com.fdkankan.user.constant.LoginConstant;
|
|
|
+import com.fdkankan.user.entity.User;
|
|
|
+import com.fdkankan.user.service.ICameraDetailService;
|
|
|
+import com.fdkankan.user.service.IScenePlusService;
|
|
|
+import com.fdkankan.user.service.ISceneProService;
|
|
|
+import com.fdkankan.user.service.IUserService;
|
|
|
+import com.fdkankan.user.vo.request.LoginParam;
|
|
|
+import com.fdkankan.user.vo.response.LoginVo;
|
|
|
+import com.fdkankan.user.vo.response.UserVo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AppService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+
|
|
|
+ public LoginVo login(LoginParam param) {
|
|
|
+ if (StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ String password = Base64Converter.decode(Base64Converter.subText(param.getPassword()));
|
|
|
+ String passwordCode = SecurityUtil.MD5(password);
|
|
|
+ User user = userService.getByUserName(param.getPhoneNum());
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+ if(!user.getPassword().equals(passwordCode)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ String token = this.redisLogin(user.getUserName(), JSONObject.toJSONString(user));
|
|
|
+
|
|
|
+ Long count = cameraDetailService.getCountByUserId(user.getId());
|
|
|
+ if(param.getCameraType() == null){
|
|
|
+ param.setCameraType( 4);
|
|
|
+ }
|
|
|
+ List<Integer> resourceList = new ArrayList<>();
|
|
|
+ if(param.getCameraType() == 4){
|
|
|
+ resourceList = Arrays.asList(1,2,12,13,14);
|
|
|
+ }else {
|
|
|
+ resourceList = Collections.singletonList(3);
|
|
|
+ }
|
|
|
+ Long sceneProCount = sceneProService.getCountByUserId(user.getId(),resourceList);
|
|
|
+ Long scenePlusCount = scenePlusService.getCountByUserId(user.getId(),resourceList);
|
|
|
+ UserVo userVo = new UserVo();
|
|
|
+ userVo.setCameraCount(count);
|
|
|
+ userVo.setSceneCount(sceneProCount + scenePlusCount);
|
|
|
+ BeanUtils.copyProperties(user,userVo);
|
|
|
+ LoginVo vo = new LoginVo();
|
|
|
+ vo.setToken(token);
|
|
|
+ vo.setUser(userVo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String redisLogin(String userName,String value){
|
|
|
+ String token = JwtUtil.createJWT(-1,userName,"app");
|
|
|
+ String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ userName;
|
|
|
+ redisUtil.set(redisKey, token,21600);
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+}
|