Commit ec805a7f by 杨卫

feat:1047852:毛利额年月前端传参yyyyMM格式修改为yyyy-MM格式

1 parent a01dfa29
......@@ -9,6 +9,7 @@ import cn.com.glsx.dj.peanalysis.enums.MerchantBiMatterOperatorRoleTypeEnum;
import cn.com.glsx.dj.peanalysis.enums.MerchantBiMatterStatusEnum;
import cn.com.glsx.dj.peanalysis.mapper.*;
import cn.com.glsx.dj.peanalysis.model.*;
import cn.com.glsx.dj.peanalysis.utils.DateUtils;
import cn.com.glsx.dj.peanalysis.utils.PageUtils;
import cn.com.glsx.dj.peanalysis.utils.validation.BeanValidationUtils;
import cn.com.glsx.dj.peanalysis.validator.ValidationGroup;
......@@ -75,7 +76,11 @@ public class BiAnalyseBackgroundService {
PageUtils.handlerPage(rpcPagination);
Page<MerchantProfitRecordDTO> page = PageHelper.startPage(rpcPagination.getPageNum(), rpcPagination.getPageSize());
merchantProfitRecordMapper.selectProfitRecordList(rpcPagination.getCondition());
MerchantProfitRecordQryDTO condition = rpcPagination.getCondition();
if (StrUtil.isNotBlank(condition.getMonthYear())) {
condition.setMonthYear(DateUtils.replaceDateDash(condition.getMonthYear()));
}
merchantProfitRecordMapper.selectProfitRecordList(condition);
List<MerchantProfitRecordDTO> result = page.getResult();
if (CollUtil.isEmpty(result)) {
return page;
......@@ -87,6 +92,7 @@ public class BiAnalyseBackgroundService {
for (MerchantProfitRecordDTO merchantProfitRecordDTO : result) {
merchantProfitRecordDTO.setStoreName(merchantIdMapName.get(Optional.ofNullable(merchantProfitRecordDTO.getStoreId()).orElse(0L).intValue()));
merchantProfitRecordDTO.setMonthYear(DateUtils.addDash(merchantProfitRecordDTO.getMonthYear()));
}
return page;
......@@ -113,6 +119,7 @@ public class BiAnalyseBackgroundService {
// 商户信息
MerchantProfitRecordDetailDTO merchantProfitRecordDetailDTO = merchantProfitRecordConvert.merchantProfitRecord2DetailDto(merchantProfitRecord);
merchantProfitRecordDetailDTO.setMonthYear(DateUtils.addDash(merchantProfitRecordDetailDTO.getMonthYear()));
searchMerchantName(Lists.newArrayList(merchantProfitRecordDetailDTO.getStoreId().intValue()))
.stream().findFirst()
.filter(ObjectUtil::isNotNull)
......@@ -172,6 +179,7 @@ public class BiAnalyseBackgroundService {
@GlsxDistributeLockable(name = "BiAnalyseBackgroundService_RecordImport", time = 180, timeoutException = Exception.class)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void merchantProfitRecordAdd(MerchantProfitRecordOperationDTO request) {
request.setMonthYear(DateUtils.replaceDateDash(request.getMonthYear()));
BeanValidationUtils.validateAndThrow(request, ValidationGroup.Add.class);
Map<Integer, MerchantProfitRecordOperationDTO> checks = MapUtil.<Integer, MerchantProfitRecordOperationDTO>builder().put(0, request).build();
......@@ -530,9 +538,17 @@ public class BiAnalyseBackgroundService {
* @since 2025/12/17 17:28
* @param request 请求参数
*/
@GlsxDistributeLockable(name = "'BiAnalyseBackgroundService_BiMatterHandle_' + #request.id", time = 180, timeoutException = RpcServiceException.class)
public void merchantBiMatterDelete(MerchantBiMatterSingleIdDTO request) {
BeanValidationUtils.validateAndThrow(request, Default.class);
MerchantBiMatter merchantBiMatter = Optional.ofNullable(merchantBiMatterMapper.selectByPrimaryKey(request.getId()))
.orElseThrow(() -> new RpcServiceException(BiErrorEnum.MERCHANT_BI_MATTER_NOT_EXIST));
Integer status = Optional.ofNullable(merchantBiMatter.getStatus()).orElse(MerchantBiMatterStatusEnum.WAIT_PROCESS.getCode());
if (MerchantBiMatterStatusEnum.PROCESSED.getCode().compareTo(status) == 0) {
throw new RpcServiceException(BiErrorEnum.BI_MATTER_HANDLED_UNSUPPORTED_DEL);
}
MerchantBiMatter updateEntity = new MerchantBiMatter();
updateEntity.setId(request.getId());
updateEntity.setDeletedFlag(BaseModel.DeletedFlagEnum.D.name());
......
package cn.com.glsx.dj.peanalysis.utils;
import cn.com.glsx.dj.peanalysis.constants.SymbolConstants;
import cn.com.glsx.dj.peanalysis.utils.response.PeriodDescription;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
......@@ -236,6 +237,39 @@ public class DateUtils {
}
/**
* 替换日期字符串中的"-"为空
* @author yangwei
* @since 2025/12/22 14:04
* @param dateStr 日期字符串
* @return java.lang.String 替换后的字符串
*/
public static String replaceDateDash(String dateStr) {
if (StrUtil.isNotBlank(dateStr)) {
return dateStr.replace(SymbolConstants.DASH, StrUtil.EMPTY);
}
return dateStr;
}
/**
* 添加"-",eg:202507 -> 2025-07
* @author yangwei
* @since 2025/12/22 14:04
* @param yearMonth 年月
* @return java.lang.String 添加"-"后的日期
*/
public static String addDash(String yearMonth) {
if (StrUtil.isNotBlank(yearMonth) && yearMonth.length() == 6) {
// 202507 -> 2025-07
return yearMonth.substring(0, 4) + SymbolConstants.DASH + yearMonth.substring(4);
}
return yearMonth;
}
public static void main(String[] args) {
List<Pair<String, String>> previousPeriodsIncludingCurrent = getPreviousPeriodsIncludingCurrent("2025-12-01", "2025-12-07", 2, 8);
for (Pair<String, String> item : previousPeriodsIncludingCurrent) {
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性

      • 问题:replaceDateDash 和 addDash 方法没有处理异常情况,如果输入不符合预期格式,可能会导致数据不一致。
      • 优化建议:增加对输入格式的校验,确保输入符合预期格式,或者在方法内部增加异常处理机制。
    2. 安全性与潜在风险

      • 问题:代码中未见明显的安全漏洞,但需要注意 DateUtils 类中的方法处理用户输入时的安全性。
      • 优化建议:确保所有用户输入都经过严格的验证和清理,避免潜在的安全风险。
    3. 是否符合最佳实践

      • 问题:部分代码逻辑可以进一步简化,例如 Optional.ofNullable(...).orElseThrow(...) 可以考虑直接抛出自定义异常。
      • 优化建议:简化代码逻辑,提高可读性。例如,在 merchantBiMatterDelete 方法中,可以将 Optional.ofNullable(...).orElseThrow(...) 改为直接抛出自定义异常。
    4. 性能与资源利用效率

      • 问题:目前未发现明显的性能瓶颈,但需要关注 DateUtils 类中的字符串操作可能带来的性能开销。
      • 优化建议:评估字符串操作的性能影响,必要时可以考虑使用更高效的字符串处理方法。
    5. Commits信息的清晰性与准确性

      • 问题:提交信息描述较为简单,没有详细说明具体修改内容和原因。
      • 优化建议:提交信息应更加详细,说明修改的具体内容和原因,例如:“feat: 修改日期格式处理逻辑,将前端传参格式从 yyyyMM 调整为 yyyy-MM”。

    评分明细

    1. 功能实现的正确性与健壮性:36分
    2. 安全性与潜在风险:28分
    3. 是否符合最佳实践:18分
    4. 性能与资源利用效率:4分
    5. Commits信息的清晰性与准确性:4分

    总分:80分


    通过以上审查,建议开发者在后续开发中注重代码的健壮性、安全性、最佳实践以及代码提交信息的规范性,以提升整体代码质量。

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!