Kaynağa Gözat

app实现登录时套餐到期购买套餐以及套餐到期自动退出

hurixing 1 yıl önce
ebeveyn
işleme
5be9164d4c

+ 16 - 0
hcp-app/src/main/java/com/yingyangfly/app/controller/LearningPackageController.java

@@ -47,4 +47,20 @@ public class LearningPackageController {
     }
 
 
+    /**
+     * 查询所有套餐(无需登录)
+     */
+    @ApiOperation("获取服务套餐列表")
+    @PostMapping("/get/list")
+    @TraceLog
+    public ResultResponse getList() {
+
+        List<LearningPackage> learningPackageList = learnPackageService.getList("system", "0");
+
+        List<LearningPackageVo> learningPackageVoList = EntityConverter.convertList(learningPackageList, LearningPackageVo.class);
+
+        return ResultResponse.success(learningPackageVoList);
+    }
+
+
 }

+ 33 - 0
hcp-app/src/main/java/com/yingyangfly/app/controller/PayOrderController.java

@@ -1,5 +1,7 @@
 package com.yingyangfly.app.controller;
 
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.yingyangfly.common.dto.ResultResponse;
 import com.yingyangfly.common.log.annotation.TraceLog;
 import com.yingyangfly.core.annotation.Log;
@@ -8,16 +10,20 @@ import com.yingyangfly.core.dto.AppCurrentLoginUser;
 import com.yingyangfly.core.enums.OperatorType;
 import com.yingyangfly.core.security.util.TokenUtil;
 import com.yingyangfly.core.service.PayService;
+import com.yingyangfly.core.service.impl.AppUserService;
 import com.yingyangfly.core.util.EntityConverter;
 import com.yingyangfly.core.vo.PayOrderVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
 
@@ -36,6 +42,9 @@ public class PayOrderController {
     @Autowired
     private TokenUtil tokenUtil;
 
+    @Resource
+    private AppUserService appUserService;
+
 
     /**
      * 查询我的订单
@@ -121,4 +130,28 @@ public class PayOrderController {
     }
 
 
+    /**
+     * 支付订单
+     * (无需登录)
+     */
+    @ApiOperation("获取支付二维码")
+    @PostMapping("/white/list/createPreOrder")
+    @TraceLog
+    public ResultResponse whiteListPayOrder(@RequestBody PayOrder payOrder) throws Exception {
+        if (StringUtils.isEmpty(payOrder.getMobile())) {
+            throw new BadCredentialsException("获取支付二维码失败!   ");
+        }
+        AppCurrentLoginUser userDetails = (AppCurrentLoginUser) appUserService.loadUserByUsername(payOrder.getMobile());
+        if (ObjectUtils.isNull(userDetails)) {
+            throw new BadCredentialsException("用户不存在!");
+        }
+        payOrder.setUserName(userDetails.getName());
+        payOrder.setUserId(userDetails.getId());
+        payOrder.setOrgCode(userDetails.getOrgCode());
+        payOrder.setOrgName(userDetails.getOrgName());
+        Map<String, Object> map =  payService.createPreOrder(payOrder);
+        return ResultResponse.success(map);
+    }
+
+
 }

+ 2 - 0
hcp-app/src/main/resources/application.yml

@@ -34,3 +34,5 @@ security:
       - /app/task/**
       - /im/**
       - /game_voice/**
+      - /app/learn/package/get/list
+      - /app/pay/white/list/createPreOrder

+ 14 - 1
hcp-core/src/main/java/com/yingyangfly/core/security/filter/JwtAuthenticationFilter.java

@@ -5,6 +5,7 @@ import com.yingyangfly.common.dto.ResultResponse;
 import com.yingyangfly.core.enums.RedisStatusEnums;
 import com.yingyangfly.core.security.util.JwtUtil;
 import com.yingyangfly.core.security.util.TokenUtil;
+import com.yingyangfly.core.service.impl.CacheUserService;
 import com.yingyangfly.core.util.Sha256WithSaltUtils;
 import com.yingyangfly.redis.client.RedisClient;
 import jodd.net.HttpMethod;
@@ -90,7 +91,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
             }
             redisClient.set(signKey,"",60);
         }
-        // 获取请求来源 (app获取pc端)
+        // 获取请求来源 (app或者pc端)
         String requestSource = jwtUtil.getRequestSourceFromToken(authToken);
         if (ObjectUtils.isEmpty(requestSource)) {
             handleUnauthorized(response,HttpServletResponse.SC_UNAUTHORIZED,"登录已过期");
@@ -117,6 +118,18 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
                     // 刷新token过期时间
                     redisClient.set(tokenKey,authHeader, RedisStatusEnums.REDIS_EXPIRATION_TIME_1.getCode());
                 }
+                if ("app".equals(requestSource)){
+                    String tokenRedis = redisClient.get(String.format("%s%s", "token:app:", username),"");
+                    if (StringUtils.isBlank(tokenRedis)){
+                        handleUnauthorized(response,HttpServletResponse.SC_UNAUTHORIZED,"登录已过期");
+                        return;
+                    }
+                    if (!authHeader.equals(tokenRedis)){
+                        handleUnauthorized(response,HttpServletResponse.SC_UNAUTHORIZED,"登录已过期");
+                        return;
+                    }
+
+                }
             }
         } catch (Exception e) {
             log.error(e.getMessage());

+ 2 - 0
hcp-core/src/main/java/com/yingyangfly/core/service/LearnPackageService.java

@@ -19,4 +19,6 @@ public interface LearnPackageService {
     void delete(Long id);
 
     LearningPackage selectById(Long relationId);
+
+    List<LearningPackage> getList(String orgCode,String status);
 }

+ 86 - 12
hcp-core/src/main/java/com/yingyangfly/core/service/impl/AppUserService.java

@@ -3,6 +3,7 @@ package com.yingyangfly.core.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.util.StringUtils;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -18,8 +19,6 @@ import com.yingyangfly.common.utils.DateUtils;
 import com.yingyangfly.core.api.ImApi;
 import com.yingyangfly.core.domain.*;
 import com.yingyangfly.core.dto.*;
-import com.yingyangfly.core.enums.MsgTemplateEnums;
-import com.yingyangfly.core.enums.RedisStatusEnums;
 import com.yingyangfly.core.enums.StatusEnums;
 import com.yingyangfly.core.mapper.*;
 import com.yingyangfly.core.recommend.RecommendFacade;
@@ -27,7 +26,6 @@ import com.yingyangfly.core.security.util.TokenUtil;
 import com.yingyangfly.core.service.*;
 import com.yingyangfly.core.util.AmountUtils;
 import com.yingyangfly.core.util.Sm4Util;
-import com.yingyangfly.core.util.SmgUtil;
 import com.yingyangfly.redis.client.RedisClient;
 import lombok.extern.slf4j.Slf4j;
 import org.assertj.core.util.Sets;
@@ -40,10 +38,11 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -470,7 +469,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         }
         patientDto.setEquipmentPledge(AmountUtils.F2Y4STR(appUser.getEquipmentPledge()));
         //查询科室
-        if(!StringUtils.isEmpty(appUser.getHospitalDepartment())){
+        if(!org.springframework.util.StringUtils.isEmpty(appUser.getHospitalDepartment())){
             Department department = departmentService.getById(appUser.getHospitalDepartment());
             if(department!=null){
                 patientDto.setHospitalDepartmentName(department.getDepartmentName());
@@ -510,6 +509,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         }
         String encrypt = Sm4Util.encrypt(mobile);
         AppUser appUser = this.selectByMobile(encrypt,"0");
+
         AppCurrentLoginUser userDetails = (AppCurrentLoginUser) createAppLoginUser(appUser);
         if(StrUtil.isNotBlank(sn)){
             Equipment equipment = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getSn,sn));
@@ -520,7 +520,8 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
                 return ResultResponse.fail("不存在此用户信息");
             }
         }
-        String token = tokenUtil.generateToken(userDetails, false,"app");
+        String token = tokenUtil.generateToken(userDetails, false,"app_large_screen");
+
         //记录登录历史
         LoginRecord loginRecord = new LoginRecord();
         loginRecord.setCreateTime(new Date());
@@ -536,8 +537,60 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         redisClient.del(redisKey);
         return ResultResponse.success(token);
     }
+
     public ResultResponse loginMsg(String checkCode, String mobile) {
-        return loginMsg(checkCode,mobile,null);
+        String redisKey = "hcp:mobile:" + mobile;
+        String checkCodeRedis = redisClient.get(redisKey, "");
+        if (StringUtils.isEmpty(checkCodeRedis)) {
+            return ResultResponse.fail("验证码已经过期");
+        }
+        String errorNumKey = "app:error:num:"+mobile;
+        String errorNumRedis = redisClient.get(errorNumKey, "");
+        if (ObjectUtils.isNotNull(errorNumRedis)){
+            if (Integer.parseInt(errorNumRedis) >= 3){
+                return ResultResponse.fail("验证码错误了3次,账户锁定10分钟");
+            }
+        }
+        if (!checkCodeRedis.equals(checkCode)) {
+            Integer errorNum = 0;
+            if (ObjectUtils.isNotNull(errorNumRedis)){
+                errorNum = Integer.parseInt(errorNumRedis);
+            }
+            errorNum++;
+            redisClient.set(errorNumKey,String.valueOf(errorNum),600);
+            return ResultResponse.fail("验证码输入错误");
+        }
+        String encrypt = Sm4Util.encrypt(mobile);
+        AppUser appUser = this.selectByMobile(encrypt,"0");
+        if (ObjectUtils.isNull(appUser.getOrderEndTime())){
+            return ResultResponse.fail("请充值后在进行登录");
+        }
+        if (LocalDate.parse(appUser.getOrderEndTime()).isBefore(LocalDate.now())){
+            return ResultResponse.fail("你的套餐已到期,请充值后登录!");
+        }
+        AppCurrentLoginUser userDetails = (AppCurrentLoginUser) createAppLoginUser(appUser);
+
+        String token = tokenUtil.generateToken(userDetails, false,"app");
+        String tokenRedis = redisClient.get(String.format("%s%s", "token:app:", mobile),"");
+        if (StringUtils.isNotBlank(tokenRedis)){
+            redisClient.del(String.format("%s%s", "token:app:", mobile));
+        }
+        redisClient.set(String.format("%s%s", "token:app:", mobile),token);
+
+        //记录登录历史
+        LoginRecord loginRecord = new LoginRecord();
+        loginRecord.setCreateTime(new Date());
+        loginRecord.setUpdateTime(new Date());
+        loginRecord.setLoginName(userDetails.getUsername());
+        loginRecord.setUserType("0");
+        loginRecord.setLoginUserId(userDetails.getId());
+        loginRecord.setOrgCode(userDetails.getOrgCode());
+        loginRecord.setOrgName(userDetails.getOrgName());
+        loginRecordMapper.insert(loginRecord);
+        log.info("{}", JSON.toJSONString(tokenUtil.getAppCurrentLoginUser()));
+        log.info("<<<<<<<<<<<登陆成功删除 redis 短信信息>>>>>>>>>>>>");
+        redisClient.del(redisKey);
+        return ResultResponse.success(token);
     }
 
     public ResultResponse getCheckCode(String mobile) {
@@ -551,17 +604,25 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         if (appUser == null) {
             return ResultResponse.fail("患者不存在");
         }
-        Random rand = new Random();
-        int randomNumber = rand.nextInt(1000000);
-        String random = String.format("%06d", randomNumber);
+        if (ObjectUtils.isNull(appUser.getOrderEndTime())){
+            return ResultResponse.success(false);
+        }
+        if (LocalDate.parse(appUser.getOrderEndTime()).isBefore(LocalDate.now())){
+            return ResultResponse.success(false);
+        }
+//        Random rand = new Random();
+//        int randomNumber = rand.nextInt(1000000);
+//        String random = String.format("%06d", randomNumber);
         //6位随机数
-        Boolean isSuccess = SmgUtil.sendCheckCode(mobile, MsgTemplateEnums.GET_CHECK_CODE.getTempalteCode(), random);
+//        Boolean isSuccess = SmgUtil.sendCheckCode(mobile, MsgTemplateEnums.GET_CHECK_CODE.getTempalteCode(), random);
+        String random = "123456";
+        Boolean isSuccess = true;
         if (isSuccess) {
             // 防机器
             redisClient.set("hcp:sms:mobile:"+mobile,random,60);
             //存入redis
             redisClient.set("hcp:mobile:" + mobile, random, 120);
-            return ResultResponse.success();
+            return ResultResponse.success(true);
         } else {
             return ResultResponse.fail("发送异常");
         }
@@ -800,4 +861,17 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         }
         appUserMapper.updateById(appUser);
     }
+
+    /**
+     * 删除缓存的token 实现自动退出
+     */
+    public void expireLogOutJob(){
+        LambdaQueryWrapper<AppUser> appUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        appUserLambdaQueryWrapper.or(wrapper -> wrapper.isNull(AppUser::getOrderEndTime)
+                .or().lt(AppUser::getOrderEndTime, new Date()));
+        List<AppUser> appUserList = appUserMapper.selectList(appUserLambdaQueryWrapper);
+        for (AppUser appUser : appUserList) {
+            redisClient.del(String.format("%s%s", "token:app:", Sm4Util.decrypt(appUser.getMobile())));
+        }
+    }
 }

+ 26 - 0
hcp-core/src/main/java/com/yingyangfly/core/service/impl/LearnPackageServiceImpl.java

@@ -16,6 +16,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
 import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
@@ -51,6 +53,10 @@ public class LearnPackageServiceImpl implements LearnPackageService {
         LoginUser loginUser = tokenUtil.getUser();
         queryWrapper.eq("org_code",loginUser.getSysUser().getOrgCode());
         List<LearningPackage> learningPackages = learningPackagMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(learningPackages)){
+            queryWrapper.eq("org_code","system");
+            learningPackages = learningPackagMapper.selectList(queryWrapper);
+        }
         for (LearningPackage learningPackage :learningPackages) {
             learningPackage.setPriceYUAN(AmountUtils.F2Y4STR(learningPackage.getPrice()));
             String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date());
@@ -94,4 +100,24 @@ public class LearnPackageServiceImpl implements LearnPackageService {
     public LearningPackage selectById(Long relationId) {
         return learningPackagMapper.selectById(relationId);
     }
+
+    @Override
+    public List<LearningPackage> getList(String orgCode, String status) {
+        LambdaQueryWrapper<LearningPackage> lambdaQueryWrapper = new LambdaQueryWrapper();
+        if (StringUtils.isNotEmpty(orgCode)){
+            lambdaQueryWrapper.eq(LearningPackage::getOrgCode,orgCode);
+        }
+        if (StringUtils.isNotEmpty(status)){
+            lambdaQueryWrapper.eq(LearningPackage::getStatus,status);
+        }
+        List<LearningPackage> learningPackages = learningPackagMapper.selectList(lambdaQueryWrapper);
+        for (LearningPackage learningPackage :learningPackages) {
+            learningPackage.setPriceYUAN(AmountUtils.F2Y4STR(learningPackage.getPrice()));
+            String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date());
+            learningPackage.setStartTime(startTime);
+            Date endDate = DateUtils.addDays(new Date(), learningPackage.getDays());
+            learningPackage.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,endDate));
+        }
+        return learningPackages;
+    }
 }

+ 1 - 1
hcp-core/src/main/java/com/yingyangfly/core/service/impl/SysUserService.java

@@ -148,7 +148,7 @@ public class SysUserService extends  ServiceImpl<SysUserMapper,SysUser> {
             throw new ServiceException("对不起,您的账号:" + username + " 已停用");
         }else if (StatusEnums.LOCK.getCode().equals(user.getStatus())){
             log.info("<<<<<<<<<登录用户:{}已停用>>>>>>>>", username);
-            throw new ServiceException("对不起,您的账号:" + username + " 已锁定,请联系管理员进行解锁");
+            throw new ServiceException("对不起,您的账号:" + username + "已锁定,请联系管理员进行解锁");
         }
         UserDetails userDetails =  createLoginUser(user);
         if(userDetails != null){

+ 2 - 2
hcp-large-screen/src/main/resources/application-prod.yml

@@ -22,9 +22,9 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     name: master
-    url: jdbc:mysql://47.93.254.212:3485/hcp0524?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+    url: jdbc:mysql://47.93.254.212:3485/hcp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
     username: root
-    password: root
+    password: SkyMedic$240307
     driver-class-name: com.mysql.cj.jdbc.Driver
     filters: stat
     maxActive: 100

+ 6 - 0
hcp-platform/src/main/java/com/yingyangfly/platform/job/RenewWarnJob.java

@@ -21,4 +21,10 @@ public class RenewWarnJob {
         appUserService.renewWarnJob();
         log.info("<<<<<<<<<<<<<<<<续费功能提醒结束>>>>>>>>>>>>>>>>>>");
     }
+
+    public void expireLogOut() {
+        log.info("<<<<<<<<<<<<<<<<<到期自动退出登录开始>>>>>>>>>>>>>>>>>>>>>");
+        appUserService.expireLogOutJob();
+        log.info("<<<<<<<<<<<<<<<<<<到期自动退出登录结束>>>>>>>>>>>>>>>>>>>>");
+    }
 }

+ 2 - 2
hcp-platform/src/main/resources/application-dev.yml

@@ -8,9 +8,9 @@ spring:
   servlet:
     multipart:
       # 单个文件大小
-      max-file-size:  100MB
+      max-file-size:  200MB
       # 设置总上传的文件大小
-      max-request-size:  100MB
+      max-request-size:  200MB
   data:
     mongodb:
       authentication-database: admin