feat:充值流程

This commit is contained in:
dzc committed 2025-09-29 11:41:56 +08:00
1 parent a50a4a6a60
commit 28afa35b35
18 files changed
+521 -2

No files matched your search

@@ -0,0 +1,33 @@
package com.bsd.pjcloud.common.core.constant.enums;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 日期范围类型
*/
@AllArgsConstructor
@Getter
public enum DateRangeTypeEnum {
YESTERDAY("0", "昨天"),
TODAY("1", "今日"),
THIS_WEEK("2", "本周"),
THIS_MONTH("3", "本月"),
CURRENT_SEASON("4", "本季度"),
HALF_YEAR("5", "近半年"),
THIS_YEAR("6", "本年"),
;
private final String type;
private final String description;
public static DateRangeTypeEnum valueOfByType(String type) {
if (ObjectUtil.isEmpty(type)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
}
}
@@ -0,0 +1,59 @@
package com.bsd.pjcloud.common.core.util;
import com.bsd.pjcloud.common.core.constant.enums.DateRangeTypeEnum;
import lombok.experimental.UtilityClass;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
/**
* 时间范围工具类
*/
@UtilityClass
public class DateRangeTool {
static public LocalDate[] transitionDateTypeToDateList(DateRangeTypeEnum dateType) {
LocalDateTime[] localDateTimes = transitionDateTypeToDateTimeList(dateType);
return new LocalDate[]{localDateTimes[0].toLocalDate(), localDateTimes[1].toLocalDate(),};
}
static public LocalDateTime[] transitionDateTypeToDateTimeList(DateRangeTypeEnum dateType) {
LocalDateTime now = LocalDateTime.now();
switch (dateType) {
case YESTERDAY:
return new LocalDateTime[]{
LocalDateTime.now().minusDays(1).withHour(0).withMinute(0).withSecond(0),
LocalDateTime.now().minusDays(1).withHour(23).withMinute(59).withSecond(59)
};
case TODAY:
return new LocalDateTime[]{
LocalDateTime.now().withHour(0).withMinute(0).withSecond(0),
LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)
};
case THIS_WEEK:
LocalDateTime weekStart = now.minusDays(7).withHour(0).withMinute(0).withSecond(0);
LocalDateTime weekEnd = now.withHour(23).withMinute(59).withSecond(59);
return new LocalDateTime[]{weekStart, weekEnd};
case THIS_MONTH:
LocalDateTime monthStart = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime monthEnd = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
return new LocalDateTime[]{monthStart, monthEnd};
case CURRENT_SEASON:
LocalDateTime quarterStart = now.with(now.getMonth().firstMonthOfQuarter()).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime quarterEnd = quarterStart.plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
return new LocalDateTime[]{quarterStart, quarterEnd};
case HALF_YEAR:
LocalDateTime halfYearStart = now.with(now.getMonth().firstMonthOfQuarter()).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime halfYearEnd = halfYearStart.plusMonths(6).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
return new LocalDateTime[]{halfYearStart, halfYearEnd};
case THIS_YEAR:
LocalDateTime yearStart = now.with(TemporalAdjusters.firstDayOfYear()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime yearEnd = now.with(TemporalAdjusters.lastDayOfYear()).withHour(23).withMinute(59).withSecond(59);
return new LocalDateTime[]{yearStart, yearEnd};
default:
return null;
}
}
}
@@ -0,0 +1,25 @@
package com.bsd.pjcloud.hard.api.dto.panel;
import com.bsd.pjcloud.common.core.constant.enums.DateRangeTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PanelCanteenDto {
private DateRangeTypeEnum dateRangeType = DateRangeTypeEnum.YESTERDAY;
private LocalDateTime[] totalTimeList;
private String hourType;
private Long limit;
}
@@ -0,0 +1,98 @@
package com.bsd.pjcloud.hard.api.vo.hard;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PanelCanteenVo {
/**
* 用餐时间段(早中晚)
*/
private String hourType;
/**
* 商品名
*/
private String productStr;
/**
* 用餐人数
*/
private Long personCount;
/**
* 购买次数
*/
private Long buyCount;
/**
* 购买商品数量
*/
private Long buyProductCount;
/**
* 购买总金额(分)
*/
private Long totalPrice;
/**
* 时间
*/
private LocalDate time;
/**
* 时间字符串
*/
private LocalDate timeStr;
/**
* 周几
*/
private String weekStr;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class HourTypeItemVo {
private String type;
private String typeStr;
private List<PanelCanteenVo> list;
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class HourTypeVo {
/**
* 早
*/
private HourTypeItemVo morning;
/**
* 中
*/
private HourTypeItemVo noon;
/**
* 晚
*/
private HourTypeItemVo evening;
}
}
@@ -0,0 +1,58 @@
package com.bsd.pjcloud.hard.controller.panel;
import cn.hutool.core.util.ObjectUtil;
import com.bsd.pjcloud.common.core.util.DateRangeTool;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.dto.panel.PanelCanteenDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo;
import com.bsd.pjcloud.hard.service.PanelCanteenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/panel-canteen")
@Tag(description = "panel-canteen", name = "食堂统计")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PanelCanteenController {
private final PanelCanteenService panelCanteenService;
@PostMapping(value = "/group/by-time-and-hour-type")
@Operation(summary = "用餐数据统计(根据时间段和日期分类统计)")
public R<PanelCanteenVo.HourTypeVo> groupByTimeAndHourType(PanelCanteenDto dto) {
if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isNotEmpty(dto.getTotalTimeList())) {
dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType()));
}
return R.ok(panelCanteenService.groupByTimeAndHourType(dto));
}
@PostMapping(value = "/group/by-time-and-custom-hour")
@Operation(summary = "用餐数据统计(根据自定义时间段和日期分类统计)")
public R<List<PanelCanteenVo>> groupByTimeAndCustomHour(PanelCanteenDto dto) {
if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isNotEmpty(dto.getTotalTimeList())) {
dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType()));
}
return R.ok(panelCanteenService.groupByTimeAndCustomHour(dto));
}
@PostMapping(value = "/top")
@Operation(summary = "排行榜")
public R<List<PanelCanteenVo>> top(PanelCanteenDto dto) {
if (ObjectUtil.isNotEmpty(dto.getDateRangeType()) && ObjectUtil.isNotEmpty(dto.getTotalTimeList())) {
dto.setTotalTimeList(DateRangeTool.transitionDateTypeToDateTimeList(dto.getDateRangeType()));
}
dto.setLimit(5L);
return R.ok(panelCanteenService.top(dto));
}
}
@@ -0,0 +1,17 @@
package com.bsd.pjcloud.hard.controller.panel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@RequestMapping("/panel-mch")
@Tag(description = "panel-mch", name = "商户统计")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PanelMchController {
}
@@ -0,0 +1,17 @@
package com.bsd.pjcloud.hard.controller.panel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@RequestMapping("/panel-mch")
@Tag(description = "panel-mch", name = "超市统计")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PanelSupermarketController {
}
@@ -10,8 +10,10 @@ import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderSumAndCountDto;
import com.bsd.pjcloud.hard.api.dto.panel.PanelCanteenDto;
import com.bsd.pjcloud.hard.api.entity.manager.HardManagerEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
import com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo;
import com.bsd.pjcloud.hard.api.vo.order.*;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -133,4 +135,9 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
List<HardOrderSumAndCountVo> sumAndCountTotalByHourType(@Param("dto") HardOrderSumAndCountDto dto);
HardZyCardSyncVo totalYearMonthDay(@Param("dto") HardOrderDto hardOrderDto);
/**
* 用餐数据统计(根据时间段和日期分类统计)
*/
List<PanelCanteenVo> groupByTimeAndHourType(@Param("dto") PanelCanteenDto dto);
}
@@ -0,0 +1,24 @@
package com.bsd.pjcloud.hard.service;
import com.bsd.pjcloud.hard.api.dto.panel.PanelCanteenDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo;
import java.util.List;
public interface PanelCanteenService {
/**
* 用餐数据统计(根据时间段和日期分类统计)
*/
PanelCanteenVo.HourTypeVo groupByTimeAndHourType(PanelCanteenDto dto);
/**
* 用餐数据统计(根据自定义时间段和日期分类统计)
*/
List<PanelCanteenVo> groupByTimeAndCustomHour(PanelCanteenDto dto);
/**
* 排行榜
*/
List<PanelCanteenVo> top(PanelCanteenDto dto);
}
@@ -0,0 +1,4 @@
package com.bsd.pjcloud.hard.service;
public interface PanelMchService {
}
@@ -0,0 +1,5 @@
package com.bsd.pjcloud.hard.service;
public interface PanelSupermarketService {
}
@@ -0,0 +1,109 @@
package com.bsd.pjcloud.hard.service.impl.panel;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.bsd.pjcloud.hard.api.constant.order.HardHourTypeEnum;
import com.bsd.pjcloud.hard.api.dto.panel.PanelCanteenDto;
import com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.PanelCanteenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class PanelCanteenServiceImpl implements PanelCanteenService {
private final HardOrderMapper hardOrderMapper;
/**
* 用餐数据统计(根据时间段和日期分类统计)
*/
@Override
public PanelCanteenVo.HourTypeVo groupByTimeAndHourType(PanelCanteenDto dto) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
List<PanelCanteenVo> dateList = generatePanelCanteenList(dto.getTotalTimeList());
PanelCanteenVo.HourTypeVo result = new PanelCanteenVo.HourTypeVo();
List<HardHourTypeEnum> hourTypeList = List.of(HardHourTypeEnum.MORNING, HardHourTypeEnum.NOONING, HardHourTypeEnum.NIGHT);
hourTypeList.stream().map(hourType -> CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
PanelCanteenDto queryDto = BeanUtil.toBean(dto, PanelCanteenDto.class);
queryDto.setHourType(hourType.getType());
List<PanelCanteenVo> sqlList = hardOrderMapper.groupByTimeAndHourType(queryDto);
// 处理查询出来的数据
List<PanelCanteenVo> resultList = BeanUtil.copyToList(dateList, PanelCanteenVo.class);
for (PanelCanteenVo v : resultList) {
sqlList.stream().filter(item -> ObjectUtil.equals(item.getTime(), v.getTime())).forEach(target -> {
v.setHourType(target.getHourType());
v.setPersonCount(target.getPersonCount());
v.setBuyCount(target.getBuyCount());
v.setBuyProductCount(target.getBuyProductCount());
v.setTotalPrice(target.getTotalPrice());
});
}
// 组装数据
PanelCanteenVo.HourTypeItemVo vo = PanelCanteenVo.HourTypeItemVo.builder().list(resultList).type(hourType.getType()).typeStr(hourType.getDescription()).build();
switch (hourType) {
case MORNING:
result.setMorning(vo);
break;
case NOONING:
result.setNoon(vo);
break;
case NIGHT:
result.setEvening(vo);
break;
}
})).toList().forEach(CompletableFuture::join);
return result;
}
/**
* 用餐数据统计(根据时间段和日期分类统计)
*/
@Override
public List<PanelCanteenVo> groupByTimeAndCustomHour(PanelCanteenDto dto) {
return List.of();
}
/**
* 排行榜
*/
@Override
public List<PanelCanteenVo> top(PanelCanteenDto dto) {
return null;
}
private List<PanelCanteenVo> generatePanelCanteenList(LocalDateTime[] totalTimeList) {
List<PanelCanteenVo> dateList = new LinkedList<>();
LocalDate startTime = totalTimeList[0].toLocalDate();
LocalDate endTime = totalTimeList[1].toLocalDate();
LocalDate currentDate = startTime;
while (!currentDate.isAfter(endTime)) {
PanelCanteenVo entity = new PanelCanteenVo();
entity.setPersonCount(0L);
entity.setBuyCount(0L);
entity.setBuyProductCount(0L);
entity.setTime(currentDate);
entity.setWeekStr(LocalDateTimeUtil.dayOfWeek(currentDate).toChinese());
dateList.add(entity);
currentDate = currentDate.plusDays(1);
}
return dateList;
}
}
@@ -0,0 +1,15 @@
package com.bsd.pjcloud.hard.service.impl.panel;
import com.bsd.pjcloud.hard.service.PanelMchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class PanelMchServiceImpl implements PanelMchService {
}
@@ -0,0 +1,15 @@
package com.bsd.pjcloud.hard.service.impl.panel;
import com.bsd.pjcloud.hard.service.PanelSupermarketService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class PanelSupermarketServiceImpl implements PanelSupermarketService {
}
@@ -549,4 +549,32 @@
</if>
</where>
</select>
<select id="groupByTimeAndHourType" resultType="com.bsd.pjcloud.hard.api.vo.hard.PanelCanteenVo">
select
date(o.create_time) as time,
o.hour_type as hourType,
SUM(a.product_count) as buyProductCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as buyCount,
count(distinct o.user_id) as personCount
from hard_car a
inner join hard_parent_car p on a.parent_car_id = p.id and p.del_flag = '0'
inner join hard_order o on o.parent_car_id = p.id and o.del_flag = '0' and o.hour_type is not null and
o.hour_type not in ('-1', 'null')
<where>
a.del_flag = '0'
<if test="dto.totalTimeList != null and dto.totalTimeList.length == 2">
and o.create_time between #{dto.totalTimeList[0]} and #{dto.totalTimeList[1]}
</if>
<if test="dto.hourType != null and dto.hourType != '' ">
and o.hour_type = #{dto.hourType}
</if>
</where>
group by date(o.create_time), o.hour_type
<if test="dto.limit != null">
limit #{dto.limit}
</if>
</select>
</mapper>
@@ -55,7 +55,7 @@ public class WalletRechargeApplyController {
@PostMapping("/save-topup")
@Operation(summary = "新增充值")
@Idempotent(expireTime = 3, info = "正在充值中,请勿重复操作")
@Idempotent(expireTime = 3, key = "'/wallet-recharge-apply/save-topup' + #dto.getInvoiceId()", info = "正在充值中,请勿重复操作")
public R comparePageJoin(@RequestBody WalletRechargeSaveTopupDto dto) {
walletRechargeApplyService.saveTopup(dto);
return R.ok();
@@ -12,7 +12,9 @@ import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.flow.task.constant.TaskCheckStatusEnum;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.constant.WalletInvoiceStatusCheckEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletManageBalanceDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeBindInvoiceDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeInvoiceApplyDto;
@@ -97,6 +99,7 @@ public class WalletRechargeInvoiceController {
@GetMapping("/select")
public R select(@ParameterObject Page page, @ParameterObject WalletRechargeBindInvoiceDto dto) {
DataScope dataScope = null;
dto.setProcessStatus(TaskCheckStatusEnum.RESULT.getCode());
return R.ok(walletRechargeInvoiceService.scopePageList(page, dto, dataScope));
}
@@ -117,7 +117,9 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
WalletRechargeInvoiceEntity invoice = walletRechargeInvoiceService.getById(dto.getInvoiceId());
if (ObjectUtil.isEmpty(invoice)) throw new RuntimeException("发票记录不存在");
if (ObjectUtil.isNotEmpty(invoice.getApplyId())) throw new RuntimeException("该发票已被绑定");
if (ObjectUtil.notEqual(invoice.getProcessStatus(), TaskCheckStatusEnum.RESULT.getCode())) {
throw new RuntimeException("发票未审核通过");
}
WalletRechargeApplyEntity apply = new WalletRechargeApplyEntity();
apply.setInvoiceId(invoice.getId());