sonarqube质量修复

This commit is contained in:
gaoqr
2025-10-29 15:54:09 +08:00
parent f1ac0bf2a4
commit d679409fbd
27 changed files with 75 additions and 137 deletions
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.controller.admin.permission;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
@@ -83,7 +82,7 @@ public class MenuController {
public CommonResult<List<MenuRespVO>> getCustomMenuList() {
List <MenuDO> list;
LoginUser loginUser = getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
AdminUserDO user = userService.getUser(loginUser.getId());
@@ -113,7 +112,7 @@ public class MenuController {
public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) {
List <MenuDO> list;
LoginUser loginUser = getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
@@ -1,6 +1,6 @@
package com.cf.imes.module.system.framework.sms.core.client;
import com.cf.imes.framework.common.core.KeyValue;
import cn.hutool.core.lang.Pair;
import com.cf.imes.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO;
import com.cf.imes.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
import com.cf.imes.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO;
@@ -24,7 +24,7 @@ public interface SmsClient {
* @return 短信发送结果
*/
SmsSendRespDTO sendSms(Long logId, String mobile, String apiTemplateId,
List<KeyValue<String, Object>> templateParams) throws Throwable;
List<Pair<String, Object>> templateParams) throws Throwable;
/**
* 解析接收短信的接收结果
@@ -2,6 +2,7 @@ package com.cf.imes.module.system.framework.sms.core.client.impl.aliyun;
import cn.hutool.core.date.format.FastDateFormat;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
@@ -9,7 +10,6 @@ import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.cf.imes.framework.common.core.KeyValue;
import com.cf.imes.framework.common.util.collection.MapUtils;
import com.cf.imes.framework.common.util.http.HttpUtils;
import com.cf.imes.framework.common.util.json.JsonUtils;
@@ -45,6 +45,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
private static final String URL = "https://dysmsapi.aliyuncs.com";
private static final String HOST = "dysmsapi.aliyuncs.com";
private static final String VERSION = "2017-05-25";
private static final String TEMPLATECODE_KEY = "TemplateCode";
private static final String RESPONSE_CODE_SUCCESS = "OK";
@@ -56,14 +57,14 @@ public class AliyunSmsClient extends AbstractSmsClient {
@Override
public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId,
List<KeyValue<String, Object>> templateParams) throws Throwable {
List<Pair<String, Object>> templateParams) throws Throwable {
Assert.notBlank(properties.getSignature(), "短信签名不能为空");
// 1. 执行请求
// 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/SendSms
TreeMap<String, Object> queryParam = new TreeMap<>();
queryParam.put("PhoneNumbers", mobile);
queryParam.put("SignName", properties.getSignature());
queryParam.put("TemplateCode", apiTemplateId);
queryParam.put(TEMPLATECODE_KEY, apiTemplateId);
queryParam.put("TemplateParam", JsonUtils.toJsonString(MapUtils.convertMap(templateParams)));
queryParam.put("OutId", sendLogId);
JSONObject response = request("SendSms", queryParam);
@@ -101,7 +102,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
// 1. 执行请求
// 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/QuerySmsTemplate
TreeMap<String, Object> queryParam = new TreeMap<>();
queryParam.put("TemplateCode", apiTemplateId);
queryParam.put(TEMPLATECODE_KEY, apiTemplateId);
JSONObject response = request("QuerySmsTemplate", queryParam);
// 2.1 请求失败
@@ -112,7 +113,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
}
// 2.2 请求成功
return new SmsTemplateRespDTO()
.setId(response.getStr("TemplateCode"))
.setId(response.getStr(TEMPLATECODE_KEY))
.setContent(response.getStr("TemplateContent"))
.setAuditStatus(convertSmsTemplateAuditStatus(response.getInt("TemplateStatus")))
.setAuditReason(response.getStr("Reason"));
@@ -2,13 +2,13 @@ package com.cf.imes.module.system.framework.sms.core.client.impl.debug;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.HmacAlgorithm;
import cn.hutool.http.HttpUtil;
import com.cf.imes.framework.common.core.KeyValue;
import com.cf.imes.framework.common.util.collection.MapUtils;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO;
@@ -40,7 +40,7 @@ public class DebugDingTalkSmsClient extends AbstractSmsClient {
@Override
public SmsSendRespDTO sendSms(Long sendLogId, String mobile,
String apiTemplateId, List<KeyValue<String, Object>> templateParams) throws Throwable {
String apiTemplateId, List<Pair<String, Object>> templateParams) throws Throwable {
// 构建请求
String url = buildUrl("robot/send");
Map<String, Object> params = new HashMap<>();
@@ -1,6 +1,6 @@
package com.cf.imes.module.system.mq.message.sms;
import com.cf.imes.framework.common.core.KeyValue;
import cn.hutool.core.lang.Pair;
import lombok.Data;
import jakarta.validation.constraints.NotNull;
@@ -37,7 +37,7 @@ public class SmsSendMessage {
/**
* 短信模板参数
*/
private List<KeyValue<String, Object>> templateParams;
private List<Pair<String, Object>> templateParams;
/**
* 短信消息模板类型:system_sms_template.type
@@ -1,6 +1,6 @@
package com.cf.imes.module.system.mq.producer.sms;
import com.cf.imes.framework.common.core.KeyValue;
import cn.hutool.core.lang.Pair;
import com.cf.imes.module.system.dal.dataobject.sms.SmsTemplateDO;
import com.cf.imes.module.system.mq.message.sms.SmsSendMessage;
import lombok.extern.slf4j.Slf4j;
@@ -32,7 +32,7 @@ public class SmsProducer {
* @param template 模板信息
* @param templateParams 短信模板参数
*/
public void sendSmsSendMessage(Long logId, String mobile, SmsTemplateDO template, List<KeyValue<String, Object>> templateParams) {
public void sendSmsSendMessage(Long logId, String mobile, SmsTemplateDO template, List<Pair<String, Object>> templateParams) {
SmsSendMessage message = new SmsSendMessage().setLogId(logId).setMobile(mobile);
message.setChannelId(template.getChannelId()).setApiTemplateId(template.getApiTemplateId()).setTemplateType(template.getType()).setTemplateParams(templateParams);
// event异步发送短信,保证子线程内部request不为空
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.Assert.AssertUtils;
import com.cf.imes.framework.common.util.date.LocalDateTimeUtils;
@@ -222,6 +223,9 @@ public class InvoiceServiceImpl implements InvoiceService {
public void applyInvoice(InvoiceRecordsReqVO reqVO) {
Long organId = SecurityFrameworkUtils.getUserOrganId();
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
List<Long> purchaseRecordId = reqVO.getPurchaseRecordId();
// 查询发票抬头
InvoiceTitleInfoDO invoiceTitleInfoDO = invoiceTitleInfoMapper.selectOne(new LambdaQueryWrapper<InvoiceTitleInfoDO>()
@@ -329,6 +333,11 @@ public class InvoiceServiceImpl implements InvoiceService {
@Override
@Transactional(rollbackFor = Exception.class)
public void confirmInvoice(InvoiceConfirmReqVO reqVO, MultipartFile file) throws IOException {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (loginUser == null) {
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
}
// 校验发票申请记录是否存在
InvoiceRecordsDO invoiceRecordsDO = validateInvoiceExists(reqVO.getId());
@@ -378,7 +387,6 @@ public class InvoiceServiceImpl implements InvoiceService {
}
// 更新开票人信息
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
invoiceRecordsDO.setInvoicePerson(loginUser.getNickname());
invoiceRecordsDO.setInvoicePersonId(loginUser.getId());
@@ -79,7 +79,7 @@ public class ManualAdjustAccountBalanceServiceImpl implements ManualAdjustAccoun
OrganAmountDO organAmountDO = organAmountService.validOrganAmount(organId);
Integer incomeExpenseType = IncomeExpenseTypeEnum.INCOME.getCode();
OrganRechargeAmountRespVO rechargeRespVO = null;
OrganRechargeAmountRespVO rechargeRespVO = new OrganRechargeAmountRespVO();;
switch (AdjustTypeEnum.getByType(saveReqVO.getAdjustType())) {
case INCREASE:
// 调增直接累加
@@ -3,7 +3,7 @@ package com.cf.imes.module.system.service.sms;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.lang.Assert;
import com.cf.imes.framework.common.core.KeyValue;
import cn.hutool.core.lang.Pair;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.module.system.dal.redis.RedisKeyConstants;
@@ -13,7 +13,6 @@ import com.cf.imes.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO
import com.cf.imes.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
import com.cf.imes.module.system.dal.dataobject.sms.SmsTemplateDO;
import com.cf.imes.module.system.mq.message.sms.SmsSendMessage;
import com.cf.imes.module.system.mq.producer.sms.SmsProducer;
import com.cf.imes.module.system.enums.ErrorCodeConstants;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
@@ -42,9 +41,6 @@ public class SmsSendServiceImpl implements SmsSendService {
@Resource
private SmsLogService smsLogService;
@Resource
private SmsProducer smsProducer;
@Resource
private RedisTemplate redisTemplate;
@@ -60,7 +56,7 @@ public class SmsSendServiceImpl implements SmsSendService {
// 校验手机号码是否存在
mobile = validateMobile(mobile);
// 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志
List<KeyValue<String, Object>> newTemplateParams = buildTemplateParams(template, templateParams);
List<Pair<String, Object>> newTemplateParams = buildTemplateParams(template, templateParams);
// 创建发送日志。如果模板被禁用,则不发送短信,只记录日志
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus());
@@ -97,13 +93,13 @@ public class SmsSendServiceImpl implements SmsSendService {
* @return 处理后的参数
*/
@VisibleForTesting
List<KeyValue<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) {
List<Pair<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) {
return template.getParams().stream().map(key -> {
Object value = templateParams.get(key);
if (value == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, key);
}
return new KeyValue<>(key, value);
return new Pair<>(key, value);
}).collect(Collectors.toList());
}
@@ -121,7 +117,7 @@ public class SmsSendServiceImpl implements SmsSendService {
SmsClient smsClient = smsChannelService.getSmsClient();
Assert.notNull(smsClient, "短信客户端({}) 不存在", message.getChannelId());
List<KeyValue<String, Object>> templateParams = message.getTemplateParams();
List<Pair<String, Object>> templateParams = message.getTemplateParams();
String channelCode = null;
// 发送短信
try {
@@ -130,7 +126,7 @@ public class SmsSendServiceImpl implements SmsSendService {
channelCode = sendResponse.getChannelCode();
// 发送成功后操作
if (sendResponse.getSuccess()) {
for (KeyValue<String, Object> keyValue : templateParams) {
for (Pair<String, Object> keyValue : templateParams) {
if ("code".equals(keyValue.getKey())) {
redisTemplate.opsForValue().set(String.format(RedisKeyConstants.SMS_CAPTCHA_VERIFICATION, sendResponse.getMobile()), keyValue.getValue(), smsCodeProperties.getExpireTimes());
}
@@ -1,7 +1,7 @@
package com.cf.imes.module.system.service.sms;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.map.MapUtil;
import com.cf.imes.framework.common.core.KeyValue;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.enums.UserTypeEnum;
import com.cf.imes.framework.test.core.ut.BaseRedisUnitTest;
@@ -100,7 +100,7 @@ public class SmsSendServiceImplTest extends BaseRedisUnitTest {
assertEquals(smsLogId, resultSmsLogId);
// 断言调用
verify(smsProducer).sendSmsSendMessage(eq(smsLogId), eq(mobile), eq(template),
eq(Lists.newArrayList(new KeyValue<>("code", "1234"), new KeyValue<>("op", "login"))));
eq(Lists.newArrayList(new Pair<>("code", "1234"), new Pair<>("op", "login"))));
}
/**
@@ -192,7 +192,7 @@ public class SmsSendServiceImplTest extends BaseRedisUnitTest {
// 准备参数
SmsSendMessage message = randomPojo(SmsSendMessage.class);
message.setMobile("15601691300");
message.setTemplateParams(List.of(new KeyValue<>("code", "123456")));
message.setTemplateParams(List.of(new Pair<>("code", "123456")));
// mock SmsClientFactory 的方法
SmsClient smsClient = mock(SmsClient.class);
when(smsChannelService.getSmsClient()).thenReturn(smsClient);
@@ -221,7 +221,7 @@ public class SmsSendServiceImplTest extends BaseRedisUnitTest {
@Test
void testDoSendSms_fail() throws Throwable {
SmsSendMessage message = randomPojo(SmsSendMessage.class);
message.setTemplateParams(List.of(new KeyValue<>("code", "999999")));
message.setTemplateParams(List.of(new Pair<>("code", "999999")));
// mock SmsClientFactory 的方法
SmsClient smsClient = spy(SmsClient.class);
when(smsChannelService.getSmsClient()).thenReturn(smsClient);