1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.fdkankan.app.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.app.service.*;
- import com.fdkankan.common.constant.ConstantFilePath;
- import com.fdkankan.common.constant.ConstantRegex;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.util.*;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.sms.SendMailAcceUtils;
- import com.fdkankan.sms.SmsService;
- import com.fdkankan.app.common.RedisKeyUtil;
- import com.fdkankan.app.constant.LoginConstant;
- import com.fdkankan.app.entity.Camera;
- import com.fdkankan.app.entity.CameraDetail;
- import com.fdkankan.app.entity.User;
- import com.fdkankan.app.vo.request.LoginParam;
- import com.fdkankan.app.vo.response.LoginVo;
- import com.fdkankan.app.vo.response.UserVo;
- import org.apache.commons.lang3.StringUtils;
- import org.omg.PortableInterceptor.INACTIVE;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import java.util.*;
- @Service
- public class LoginService {
- @Autowired
- private IUserService userService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private ICameraService cameraService;
- @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 void logout(String userName) {
- String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA+ userName;
- redisUtil.del(redisKey);
- }
- 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;
- }
- }
|