huangzhen
2024-02-04 89a72db182bc4312caf4abfa60969c325cbb98bb
bug修复
已修改7个文件
已添加1个文件
228 ■■■■■ 文件已修改
src/main/java/com/gkhy/fourierSpecialGasMonitor/application/account/service/impl/AccountAppServiceImpl.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/controller/DataReceiveController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/domain/account/service/impl/UserDomainServiceImpl.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/entity/req/UploadGasFluxReqDTO.java 127 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/enums/HeartbeatExecEnum.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasCategoryServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/utils/PasswordCheckUtil.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/application/account/service/impl/AccountAppServiceImpl.java
@@ -30,12 +30,14 @@
import com.gkhy.fourierSpecialGasMonitor.domain.account.service.UserDomainService;
import com.gkhy.fourierSpecialGasMonitor.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.fourierSpecialGasMonitor.domain.account.service.UserRoleDomainService;
import com.gkhy.fourierSpecialGasMonitor.utils.PasswordCheckUtil;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@@ -289,9 +291,12 @@
        CreateUserBO createUserBO = new CreateUserBO();
        createUserBO.setName(createNewUserAppReqDTO.getName());
        createUserBO.setRealName(createNewUserAppReqDTO.getRealName());
        //如果没有提供密码,初始密码为“123456”
        //如果没有提供密码,初始密码为“Gkhy@c413”
        if(createNewUserAppReqDTO.getPwd() == null || createNewUserAppReqDTO.getPwd().isEmpty()){
            createNewUserAppReqDTO.setPwd("123456");
            createNewUserAppReqDTO.setPwd("Gkhy@c413");
        }
        if (!StringUtils.isEmpty(createNewUserAppReqDTO.getPwd())){
            PasswordCheckUtil.passwordIsValid(createNewUserAppReqDTO.getPwd());
        }
        createUserBO.setPwd(createNewUserAppReqDTO.getPwd());
        createUserBO.setPhone(createNewUserAppReqDTO.getPhone());
src/main/java/com/gkhy/fourierSpecialGasMonitor/controller/DataReceiveController.java
@@ -50,8 +50,8 @@
    @PostMapping("/upload/gasFlux")
    public ForeignResult uploadGasFlux(@RequestBody UploadGasFluxReqDTO reqDto){
        UploadGasFluxReqDTO uploadGasFluxReqDTO = reqDto.expansionFactor();
        ForeignResult result = dataReceiveService.uploadGasFlux(uploadGasFluxReqDTO);
        //UploadGasFluxReqDTO uploadGasFluxReqDTO = reqDto.expansionFactor();
        ForeignResult result = dataReceiveService.uploadGasFlux(reqDto);
        return result;
    }
src/main/java/com/gkhy/fourierSpecialGasMonitor/domain/account/service/impl/UserDomainServiceImpl.java
@@ -7,6 +7,7 @@
import com.gkhy.fourierSpecialGasMonitor.commons.domain.SearchResult;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.SystemCacheKeyEnum;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.UserRoleEnum;
import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException;
import com.gkhy.fourierSpecialGasMonitor.commons.model.PageQuery;
import com.gkhy.fourierSpecialGasMonitor.commons.utils.BeanCopyUtils;
@@ -25,6 +26,8 @@
import com.gkhy.fourierSpecialGasMonitor.domain.account.service.SysDepartmentDomainService;
import com.gkhy.fourierSpecialGasMonitor.domain.account.service.UserDomainService;
import com.gkhy.fourierSpecialGasMonitor.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.fourierSpecialGasMonitor.utils.PasswordCheckUtil;
import com.gkhy.fourierSpecialGasMonitor.utils.ThreadLocalUtil;
import com.google.common.collect.Range;
import com.google.common.hash.Hashing;
import org.redisson.api.RMapCache;
@@ -67,6 +70,14 @@
    @Autowired
    private SysDepartmentDomainService departmentDomainService;
    private User getCurrentUser(){
        Long userId = ThreadLocalUtil.get().getId();
        User user = userRepository.findUserByIdAndStatus(userId, UserStatusEnum.STATUS_ACTIVE.getStatus());
        if (user == null)
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"未成功获取用户信息");
        return user;
    }
    @Override
    @Transactional
@@ -291,22 +302,37 @@
    @Override
    @Transactional
    public boolean updateUserPwd(Long uid, String oldPwd, String newPwd) {
        if(uid == null || oldPwd == null || newPwd == null || oldPwd.isEmpty() || newPwd.isEmpty())
        User currentUser = getCurrentUser();
        Boolean flag = false;
        for (SysUserRoleBind sysUserRoleBind : currentUser.getSysUserRoleBinds()) {
            if ("超级管理员".equals(sysUserRoleBind.getRole().getName())){
                flag = true;
            }
        }
        if(uid == null || oldPwd == null || newPwd == null || newPwd.isEmpty())
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "参数缺失");
        Optional<User> userOptional = userRepository.findById(uid);
        if(!userOptional.isPresent()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_ACCOUNT_NOT_EXIST.getCode(), "用户不存在");
        }
        User user = userOptional.get();
        //验证旧密码
        String hash = String.valueOf(Hashing.hmacMd5(user.getSalt().getBytes(StandardCharsets.UTF_8)).hashString(oldPwd,
                StandardCharsets.UTF_8));
        if(!hash.equals(user.getHash()))
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode(), "旧密码错误");
        String newSalt = String.valueOf(Hashing.hmacMd5("".getBytes()).hashString(""+uid+Range.atLeast(1)+System.nanoTime(),
                StandardCharsets.UTF_8));
        String newHash = String.valueOf(Hashing.hmacMd5(newSalt.getBytes(StandardCharsets.UTF_8)).hashString(newPwd,
                StandardCharsets.UTF_8));
        PasswordCheckUtil.passwordIsValid(newPwd.trim());
        if (!flag){
            if(oldPwd.isEmpty()) {
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "参数缺失");
            }
            //验证旧密码
            String hash = String.valueOf(Hashing.hmacMd5(user.getSalt().getBytes(StandardCharsets.UTF_8)).hashString(oldPwd,
                    StandardCharsets.UTF_8));
            if(!hash.equals(user.getHash()))
                throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode(), "旧密码错误");
        }
        String newSalt = genPasswordSalt();
        String newHash = genPasswordHash(newPwd, newSalt);
        //String newSalt = String.valueOf(Hashing.hmacMd5("".getBytes()).hashString(""+uid+Range.atLeast(1)+System.nanoTime(),
        //        StandardCharsets.UTF_8));
        //String newHash = String.valueOf(Hashing.hmacMd5(newSalt.getBytes(StandardCharsets.UTF_8)).hashString(newPwd,
        //        StandardCharsets.UTF_8));
        if(userRepository.updatePassword(uid,newHash,newSalt, LocalDateTime.now()) == 1){
//            deleteUserCache(uid);
            return true;
@@ -641,7 +667,4 @@
        String hash = Hashing.hmacMd5(salt.getBytes(StandardCharsets.UTF_8)).hashBytes(password.getBytes(StandardCharsets.UTF_8)).toString();
        return hash;
    }
}
src/main/java/com/gkhy/fourierSpecialGasMonitor/entity/req/UploadGasFluxReqDTO.java
@@ -63,68 +63,67 @@
    private Double gasValue19;
    private int gasName20;
    private Double gasValue20;
    public UploadGasFluxReqDTO expansionFactor(){
        if (gasValue01 != null) {
            gasValue01 = Math.round(gasValue01 * 3600 * 100.0) / 100.0;
        }
        if (gasValue02 != null) {
            gasValue02 = Math.round(gasValue02 * 3600 * 100.0) / 100.0;
        }
        if (gasValue03 != null) {
            gasValue03 = Math.round(gasValue03 * 3.6 * 100.0) / 100.0;
        }
        if (gasValue04 != null) {
            gasValue04 = Math.round(gasValue04 * 3600 * 100.0) / 100.0;
        }
        if (gasValue05 != null) {
            gasValue05 = Math.round(gasValue05 * 3600 * 100.0) / 100.0;
        }
        if (gasValue06 != null) {
            gasValue06 = Math.round(gasValue06 * 3600 * 100.0) / 100.0;
        }
        if (gasValue07 != null) {
            gasValue07 = Math.round(gasValue07 * 3600 * 100.0) / 100.0;
        }
        if (gasValue08 != null) {
            gasValue08 = Math.round(gasValue08 * 3600 * 100.0) / 100.0;
        }
        if (gasValue09 != null) {
            gasValue09 = Math.round(gasValue09 * 3600 * 100.0) / 100.0;
        }
        if (gasValue10 != null) {
            gasValue10 = Math.round(gasValue10 * 3600 * 100.0) / 100.0;
        }
        if (gasValue11 != null) {
            gasValue11 = Math.round(gasValue11 * 3600 * 100.0) / 100.0;
        }
        if (gasValue12 != null) {
            gasValue12 = Math.round(gasValue12 * 3600 * 100.0) / 100.0;
        }
        if (gasValue13 != null) {
            gasValue13 = Math.round(gasValue13 * 3600 * 100.0) / 100.0;
        }
        if (gasValue14 != null) {
            gasValue14 = Math.round(gasValue14 * 3600 * 100.0) / 100.0;
        }
        if (gasValue15 != null) {
            gasValue15 = Math.round(gasValue15 * 3600 * 100.0) / 100.0;
        }
        if (gasValue16 != null) {
            gasValue16 = Math.round(gasValue16 * 3600 * 100.0) / 100.0;
        }
        if (gasValue17 != null) {
            gasValue17 = Math.round(gasValue17 * 3600 * 100.0) / 100.0;
        }
        if (gasValue18 != null) {
            gasValue18 = Math.round(gasValue18 * 3600 * 100.0) / 100.0;
        }
        if (gasValue19 != null) {
            gasValue19 = Math.round(gasValue19 * 3600 * 100.0) / 100.0;
        }
        if (gasValue20 != null) {
            gasValue20 = Math.round(gasValue20 * 3600 * 100.0) / 100.0;
        }
        return this;
    }
    //public UploadGasFluxReqDTO expansionFactor(){
    //    if (gasValue01 != null) {
    //        gasValue01 = Math.round(gasValue01 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue02 != null) {
    //        gasValue02 = Math.round(gasValue02 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue03 != null) {
    //        gasValue03 = Math.round(gasValue03 * 3.6 * 100.0) / 100.0;
    //    }
    //    if (gasValue04 != null) {
    //        gasValue04 = Math.round(gasValue04 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue05 != null) {
    //        gasValue05 = Math.round(gasValue05 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue06 != null) {
    //        gasValue06 = Math.round(gasValue06 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue07 != null) {
    //        gasValue07 = Math.round(gasValue07 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue08 != null) {
    //        gasValue08 = Math.round(gasValue08 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue09 != null) {
    //        gasValue09 = Math.round(gasValue09 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue10 != null) {
    //        gasValue10 = Math.round(gasValue10 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue11 != null) {
    //        gasValue11 = Math.round(gasValue11 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue12 != null) {
    //        gasValue12 = Math.round(gasValue12 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue13 != null) {
    //        gasValue13 = Math.round(gasValue13 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue14 != null) {
    //        gasValue14 = Math.round(gasValue14 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue15 != null) {
    //        gasValue15 = Math.round(gasValue15 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue16 != null) {
    //        gasValue16 = Math.round(gasValue16 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue17 != null) {
    //        gasValue17 = Math.round(gasValue17 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue18 != null) {
    //        gasValue18 = Math.round(gasValue18 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue19 != null) {
    //        gasValue19 = Math.round(gasValue19 * 3600 * 100.0) / 100.0;
    //    }
    //    if (gasValue20 != null) {
    //        gasValue20 = Math.round(gasValue20 * 3600 * 100.0) / 100.0;
    //    }
    //    return this;
    //}
}
src/main/java/com/gkhy/fourierSpecialGasMonitor/enums/HeartbeatExecEnum.java
@@ -7,7 +7,7 @@
 */
public enum HeartbeatExecEnum {
    GAS_CONCENTRATION((byte)1,"【气体浓度】实时推送心跳监测异常 ---> 1分钟内未收到远端数据"),
    GAS_CONCENTRATION((byte)1,"【气体浓度】实时推送心跳监测异常 ---> 5分钟内未收到远端数据"),
    GAS_FLUX((byte)2,"【气体通量】实时推送心跳监测异常 ---> 30分钟内未收到远端数据"),
    ;
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/HeartbeatSchedule.java
@@ -50,12 +50,12 @@
    @Scheduled(cron = "0 0/1 * * * ?")
    @Scheduled(cron = "0 0/5 * * * ?")
    @Async(value = "SocketTaskExecutor")
    public void gasConcentrationStatus() {
        GasConcentration gasConcentration = gasConcentrationService.getLastData();
        if (gasConcentration != null){
            LocalDateTime lastReceiveTime = gasConcentration.getDataReceivingTime().plusMinutes(2);
            LocalDateTime lastReceiveTime = gasConcentration.getDataReceivingTime().plusMinutes(5);
            if (LocalDateTime.now().compareTo(lastReceiveTime) > 0){
                try {
                    heartbeatExcWebsocketServer.sendInfo(HeartbeatExecEnum.GAS_CONCENTRATION.getStatus()+"",null);
src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/GasCategoryServiceImpl.java
@@ -76,7 +76,7 @@
    }
    @Override
    public Result createGasCategory(CreateGasCategoryReqDTO reqDto) {
    public synchronized Result createGasCategory(CreateGasCategoryReqDTO reqDto) {
        if (reqDto == null)
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"参数不能为空");
        if (StringUtils.isBlank(reqDto.getMolecularFormula()))
src/main/java/com/gkhy/fourierSpecialGasMonitor/utils/PasswordCheckUtil.java
对比新文件
@@ -0,0 +1,31 @@
package com.gkhy.fourierSpecialGasMonitor.utils;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException;
/**
 * @author Mr.huang
 * @decription
 * @date 2024/1/4 10:44
 */
public class PasswordCheckUtil {
    public static void passwordIsValid(String pwd){
        if (pwd.length() < 8){
            throw new BusinessException(PasswordCheckUtil.class, ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码长度不够");
        }
        if (!pwd.matches(".*[A-Z].*")){
            throw new BusinessException(PasswordCheckUtil.class,ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码至少包含大小写字母、数字、特殊字符");
        }
        if (!pwd.matches(".*[a-z].*")){
            throw new BusinessException(PasswordCheckUtil.class,ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码至少包含大小写字母、数字、特殊字符");
        }
        if (!pwd.matches(".*\\d.*")){
            throw new BusinessException(PasswordCheckUtil.class,ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码至少包含大小写字母、数字、特殊字符");
        }
        if (!pwd.matches(".*[!@#$%^&*.()?+`~<>,-].*")){
            throw new BusinessException(PasswordCheckUtil.class,ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码至少包含大小写字母、数字、特殊字符");
        }
    }
}