营业统计
This commit is contained in:
@ -0,0 +1,96 @@
|
||||
package cn.iocoder.yudao.module.member.controller.admin.business;
|
||||
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessSaveReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
|
||||
import cn.iocoder.yudao.module.member.service.business.BusinessService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - 营业统计")
|
||||
@RestController
|
||||
@RequestMapping("/t/business")
|
||||
@Validated
|
||||
public class BusinessController {
|
||||
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
// @PostMapping("/create")
|
||||
// @Operation(summary = "创建营业统计")
|
||||
// @PreAuthorize("@ss.hasPermission('t:business:create')")
|
||||
// public CommonResult<Long> createBusiness(@Valid @RequestBody BusinessSaveReqVO createReqVO) {
|
||||
// return success(businessService.createBusiness(createReqVO));
|
||||
// }
|
||||
|
||||
// @PutMapping("/update")
|
||||
// @Operation(summary = "更新营业统计")
|
||||
// @PreAuthorize("@ss.hasPermission('t:business:update')")
|
||||
// public CommonResult<Boolean> updateBusiness(@Valid @RequestBody BusinessSaveReqVO updateReqVO) {
|
||||
// businessService.updateBusiness(updateReqVO);
|
||||
// return success(true);
|
||||
// }
|
||||
|
||||
// @DeleteMapping("/delete")
|
||||
// @Operation(summary = "删除营业统计")
|
||||
// @Parameter(name = "id", description = "编号", required = true)
|
||||
// @PreAuthorize("@ss.hasPermission('t:business:delete')")
|
||||
// public CommonResult<Boolean> deleteBusiness(@RequestParam("id") Long id) {
|
||||
// businessService.deleteBusiness(id);
|
||||
// return success(true);
|
||||
// }
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得营业统计")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('t:business:query')")
|
||||
public CommonResult<BusinessRespVO> getBusiness(@RequestParam("id") Long id) {
|
||||
BusinessDO business = businessService.getBusiness(id);
|
||||
return success(BeanUtils.toBean(business, BusinessRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得营业统计分页")
|
||||
@PreAuthorize("@ss.hasPermission('t:business:query')")
|
||||
public CommonResult<PageResult<BusinessRespVO>> getBusinessPage(@Valid BusinessPageReqVO pageReqVO) {
|
||||
PageResult<BusinessDO> pageResult = businessService.getBusinessPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, BusinessRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出营业统计 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('t:business:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportBusinessExcel(@Valid BusinessPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<BusinessDO> list = businessService.getBusinessPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "营业统计.xls", "数据", BusinessRespVO.class,
|
||||
BeanUtils.toBean(list, BusinessRespVO.class));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.member.controller.admin.business.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 营业统计分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BusinessPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "营业额")
|
||||
private BigDecimal turnover;
|
||||
|
||||
@Schema(description = "订单数")
|
||||
private Integer orderSum;
|
||||
|
||||
@Schema(description = "顾客数")
|
||||
private Integer customerSum;
|
||||
|
||||
@Schema(description = "均单价")
|
||||
private BigDecimal priceAvg;
|
||||
|
||||
@Schema(description = "充值钱包")
|
||||
private BigDecimal rechargePurse;
|
||||
|
||||
@Schema(description = "补贴钱包")
|
||||
private BigDecimal subsidyPurse;
|
||||
|
||||
@Schema(description = "VIP免单")
|
||||
private Integer gratis;
|
||||
|
||||
@Schema(description = "早餐")
|
||||
private BigDecimal breakfast;
|
||||
|
||||
@Schema(description = "午餐")
|
||||
private BigDecimal lunch;
|
||||
|
||||
@Schema(description = "晚餐")
|
||||
private BigDecimal dinner;
|
||||
|
||||
@Schema(description = "智能称重")
|
||||
private BigDecimal weigh;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package cn.iocoder.yudao.module.member.controller.admin.business.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 营业统计 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class BusinessRespVO {
|
||||
|
||||
@Schema(description = "营业统计编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15591")
|
||||
@ExcelProperty("营业统计编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "营业额")
|
||||
@ExcelProperty("营业额")
|
||||
private BigDecimal turnover;
|
||||
|
||||
@Schema(description = "订单数")
|
||||
@ExcelProperty("订单数")
|
||||
private Integer orderSum;
|
||||
|
||||
@Schema(description = "顾客数")
|
||||
@ExcelProperty("顾客数")
|
||||
private Integer customerSum;
|
||||
|
||||
@Schema(description = "均单价")
|
||||
@ExcelProperty("均单价")
|
||||
private BigDecimal priceAvg;
|
||||
|
||||
@Schema(description = "充值钱包")
|
||||
@ExcelProperty("充值钱包")
|
||||
private BigDecimal rechargePurse;
|
||||
|
||||
@Schema(description = "补贴钱包")
|
||||
@ExcelProperty("补贴钱包")
|
||||
private BigDecimal subsidyPurse;
|
||||
|
||||
@Schema(description = "VIP免单")
|
||||
@ExcelProperty("VIP免单")
|
||||
private Integer gratis;
|
||||
|
||||
@Schema(description = "早餐")
|
||||
@ExcelProperty("早餐")
|
||||
private BigDecimal breakfast;
|
||||
|
||||
@Schema(description = "午餐")
|
||||
@ExcelProperty("午餐")
|
||||
private BigDecimal lunch;
|
||||
|
||||
@Schema(description = "晚餐")
|
||||
@ExcelProperty("晚餐")
|
||||
private BigDecimal dinner;
|
||||
|
||||
@Schema(description = "智能称重")
|
||||
@ExcelProperty("智能称重")
|
||||
private BigDecimal weigh;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package cn.iocoder.yudao.module.member.controller.admin.business.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 营业统计新增/修改 Request VO")
|
||||
@Data
|
||||
public class BusinessSaveReqVO {
|
||||
|
||||
@Schema(description = "营业统计编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15591")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "营业额")
|
||||
private BigDecimal turnover;
|
||||
|
||||
@Schema(description = "订单数")
|
||||
private Integer orderSum;
|
||||
|
||||
@Schema(description = "顾客数")
|
||||
private Integer customerSum;
|
||||
|
||||
@Schema(description = "均单价")
|
||||
private BigDecimal priceAvg;
|
||||
|
||||
@Schema(description = "充值钱包")
|
||||
private BigDecimal rechargePurse;
|
||||
|
||||
@Schema(description = "补贴钱包")
|
||||
private BigDecimal subsidyPurse;
|
||||
|
||||
@Schema(description = "VIP免单")
|
||||
private Integer gratis;
|
||||
|
||||
@Schema(description = "早餐")
|
||||
private BigDecimal breakfast;
|
||||
|
||||
@Schema(description = "午餐")
|
||||
private BigDecimal lunch;
|
||||
|
||||
@Schema(description = "晚餐")
|
||||
private BigDecimal dinner;
|
||||
|
||||
@Schema(description = "智能称重")
|
||||
private BigDecimal weigh;
|
||||
|
||||
}
|
@ -115,14 +115,6 @@ public class MemberUserController {
|
||||
convertSet(pageResult.getList(), MemberUserDO::getGroupId));
|
||||
return success(MemberUserConvert.INSTANCE.convertPage(pageResult, tags, levels, groups));
|
||||
}
|
||||
@GetMapping("/heat")
|
||||
@Operation(summary = "获得会员热量分析")
|
||||
@PreAuthorize("@ss.hasPermission('member:user:query')")
|
||||
public CommonResult<List<Map>> getUserHeat(@RequestParam(value = "userId",required = false) Long userId,
|
||||
@RequestParam(value = "startDate",required = false) LocalDateTime startDate,
|
||||
@RequestParam(value = "endDate",required = false) LocalDateTime endDate,
|
||||
@RequestParam(value = "orderId",required = false)Long orderId){
|
||||
return success(memberUserService.getUserHeat(userId,startDate,endDate,orderId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,16 +17,17 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@ -107,6 +108,14 @@ public class AppMemberUserController {
|
||||
public CommonResult<Boolean> NutritionWeek(@Valid @RequestBody AppBindCardVO vo){
|
||||
return success(userService.bindCard(vo.getCardId()));
|
||||
}
|
||||
|
||||
@GetMapping("/heat")
|
||||
@Operation(summary = "获得会员热量分析")
|
||||
@PreAuthorize("@ss.hasPermission('member:user:query')")
|
||||
public CommonResult<List<Map>> getUserHeat(@RequestParam(value = "userId",required = false) Long userId,
|
||||
@RequestParam(value = "startDate",required = false) LocalDateTime startDate,
|
||||
@RequestParam(value = "endDate",required = false) LocalDateTime endDate,
|
||||
@RequestParam(value = "orderId",required = false)Long orderId){
|
||||
return success(userService.getUserHeat(userId,startDate,endDate,orderId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
package cn.iocoder.yudao.module.member.dal.dataobject.business;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 营业统计 DO
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@TableName("t_business")
|
||||
@KeySequence("t_business_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BusinessDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 营业统计编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 营业额
|
||||
*/
|
||||
private BigDecimal turnover;
|
||||
/**
|
||||
* 订单数
|
||||
*/
|
||||
private Integer orderSum;
|
||||
/**
|
||||
* 顾客数
|
||||
*/
|
||||
private Integer customerSum;
|
||||
/**
|
||||
* 均单价
|
||||
*/
|
||||
private BigDecimal priceAvg;
|
||||
/**
|
||||
* 充值钱包
|
||||
*/
|
||||
private BigDecimal rechargePurse;
|
||||
/**
|
||||
* 补贴钱包
|
||||
*/
|
||||
private BigDecimal subsidyPurse;
|
||||
/**
|
||||
* VIP免单
|
||||
*/
|
||||
private Integer gratis;
|
||||
/**
|
||||
* 早餐
|
||||
*/
|
||||
private BigDecimal breakfast;
|
||||
/**
|
||||
* 午餐
|
||||
*/
|
||||
private BigDecimal lunch;
|
||||
/**
|
||||
* 晚餐
|
||||
*/
|
||||
private BigDecimal dinner;
|
||||
/**
|
||||
* 智能称重
|
||||
*/
|
||||
private BigDecimal weigh;
|
||||
/**
|
||||
* 门店编号
|
||||
*/
|
||||
private Long carteenId;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.member.dal.mysql.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 营业统计 Mapper
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@Mapper
|
||||
public interface BusinessMapper extends BaseMapperX<BusinessDO> {
|
||||
|
||||
default PageResult<BusinessDO> selectPage(BusinessPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<BusinessDO>()
|
||||
.eqIfPresent(BusinessDO::getTurnover, reqVO.getTurnover())
|
||||
.eqIfPresent(BusinessDO::getOrderSum, reqVO.getOrderSum())
|
||||
.eqIfPresent(BusinessDO::getCustomerSum, reqVO.getCustomerSum())
|
||||
.eqIfPresent(BusinessDO::getPriceAvg, reqVO.getPriceAvg())
|
||||
.eqIfPresent(BusinessDO::getRechargePurse, reqVO.getRechargePurse())
|
||||
.eqIfPresent(BusinessDO::getSubsidyPurse, reqVO.getSubsidyPurse())
|
||||
.eqIfPresent(BusinessDO::getGratis, reqVO.getGratis())
|
||||
.eqIfPresent(BusinessDO::getBreakfast, reqVO.getBreakfast())
|
||||
.eqIfPresent(BusinessDO::getLunch, reqVO.getLunch())
|
||||
.eqIfPresent(BusinessDO::getDinner, reqVO.getDinner())
|
||||
.eqIfPresent(BusinessDO::getWeigh, reqVO.getWeigh())
|
||||
.betweenIfPresent(BusinessDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(BusinessDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package cn.iocoder.yudao.module.member.job;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.orderdetail.OrderDetailDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.business.BusinessMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.orderdetail.OrderDetailMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
|
||||
import cn.iocoder.yudao.module.member.enums.TimePeriodEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author:qjq
|
||||
* @Date:2024/4/3 14:50
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class BusinessBatchJob implements JobHandler {
|
||||
@Resource
|
||||
private BusinessMapper businessMapper;
|
||||
@Resource
|
||||
private DishOrderMapper dishOrderMapper;
|
||||
@Resource
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
@Resource
|
||||
private CardMapper cardMapper;
|
||||
/**
|
||||
* 执行任务
|
||||
*
|
||||
* @param param 参数
|
||||
* @return 结果
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public String execute(String param) throws Exception {
|
||||
LocalDateTime now = LocalDateTimeUtil.now();
|
||||
//昨天时间
|
||||
LocalDateTime offset = LocalDateTimeUtil.offset(now, -1, ChronoUnit.DAYS);
|
||||
//获取昨天开始与结束
|
||||
LocalDateTime startDate = LocalDateTimeUtil.beginOfDay(offset);
|
||||
LocalDateTime endDate = LocalDateTimeUtil.endOfDay(offset);
|
||||
List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(new LambdaQueryWrapperX<DishOrderDO>()
|
||||
.betweenIfPresent(DishOrderDO::getCreateTime, startDate, endDate)
|
||||
.eq(DishOrderDO::getOrderStatus, DishOrderDO.COMPLETE));
|
||||
//根据名店id进行分组
|
||||
Map<Long, List<DishOrderDO>> collect = dishOrderDOS.stream().collect(Collectors.groupingBy(DishOrderDO::getStoreId));
|
||||
List<BusinessDO> list=new ArrayList<>();
|
||||
for (Map.Entry<Long, List<DishOrderDO>> map : collect.entrySet()) {
|
||||
BusinessDO build = BusinessDO.builder().build();
|
||||
List<DishOrderDO> value = map.getValue();
|
||||
Long carteenId = map.getKey();
|
||||
//获取营业额
|
||||
double sum = value.stream().mapToDouble(d -> d.getTotalMoney().doubleValue()).sum();
|
||||
build.setTurnover(BigDecimal.valueOf(sum));
|
||||
//订单数
|
||||
build.setOrderSum(value.size());
|
||||
//顾客数 根据用户id进行去重统计
|
||||
long count = value.stream().map(DishOrderDO::getUserId).distinct().count();
|
||||
build.setCustomerSum((int) count);
|
||||
//均单价 总价和/订单数
|
||||
BigDecimal divide = value.stream()
|
||||
.map(DishOrderDO::getTotalMoney)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.divide(BigDecimal.valueOf(build.getOrderSum()), RoundingMode.CEILING);
|
||||
build.setPriceAvg(divide);
|
||||
//充值钱包
|
||||
BigDecimal reduce = cardMapper.selectList(new LambdaQueryWrapperX<CardDO>()
|
||||
.betweenIfPresent(CardDO::getCreateTime, startDate, endDate)
|
||||
.inIfPresent(CardDO::getUserId, value
|
||||
.stream()
|
||||
.map(DishOrderDO::getUserId)
|
||||
.collect(Collectors.toList()))
|
||||
.eq(CardDO::getFlag, CardDO.ADD))
|
||||
.stream()
|
||||
.map(CardDO::getMoney)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
build.setRechargePurse(reduce);
|
||||
//早餐
|
||||
value.forEach(x-> x.setPayMethods(TimePeriodEnum.getTimePeriod(x.getCreateTime())));
|
||||
Map<String, List<DishOrderDO>> collect1 = value.stream().collect(Collectors.groupingBy(DishOrderDO::getPayMethods));
|
||||
for (Map.Entry<String, List<DishOrderDO>> maps : collect1.entrySet()) {
|
||||
List<DishOrderDO> value1 = maps.getValue();
|
||||
String key = maps.getKey();
|
||||
//早餐
|
||||
if(key.equalsIgnoreCase(CostTypeEnum.MORNING.getCode())){
|
||||
build.setBreakfast(value1
|
||||
.stream()
|
||||
.map(DishOrderDO::getTotalMoney)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
}
|
||||
//午餐
|
||||
else if(key.equalsIgnoreCase(CostTypeEnum.NOON.getCode())){
|
||||
build.setLunch(value1
|
||||
.stream()
|
||||
.map(DishOrderDO::getTotalMoney)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
}else {
|
||||
build.setDinner(value1
|
||||
.stream()
|
||||
.map(DishOrderDO::getTotalMoney)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
}
|
||||
}
|
||||
//统计称重数据
|
||||
List<Long> orderIds = value.stream().map(DishOrderDO::getId).collect(Collectors.toList());
|
||||
BigDecimal decimal = orderDetailMapper.selectList(new LambdaQueryWrapperX<OrderDetailDO>()
|
||||
.inIfPresent(OrderDetailDO::getOrderId, orderIds))
|
||||
.stream()
|
||||
.map(OrderDetailDO::getWeight)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
build.setWeigh(decimal);
|
||||
//设置门店编号
|
||||
build.setCarteenId(carteenId);
|
||||
list.add(build);
|
||||
}
|
||||
Boolean b = businessMapper.insertBatch(list);
|
||||
log.info("[execute][定时插入统计营业数据是否成功 {}]", b);
|
||||
return String.format("定时插入统计营业数据是否成功 %s ", b);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.member.service.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessSaveReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
|
||||
|
||||
import javax.validation.*;
|
||||
|
||||
/**
|
||||
* 营业统计 Service 接口
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
public interface BusinessService {
|
||||
|
||||
/**
|
||||
* 创建营业统计
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createBusiness(@Valid BusinessSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新营业统计
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateBusiness(@Valid BusinessSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除营业统计
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteBusiness(Long id);
|
||||
|
||||
/**
|
||||
* 获得营业统计
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 营业统计
|
||||
*/
|
||||
BusinessDO getBusiness(Long id);
|
||||
|
||||
/**
|
||||
* 获得营业统计分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 营业统计分页
|
||||
*/
|
||||
PageResult<BusinessDO> getBusinessPage(BusinessPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.iocoder.yudao.module.member.service.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessSaveReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.business.BusinessMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper;
|
||||
import cn.iocoder.yudao.module.member.dal.mysql.orderdetail.OrderDetailMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 营业统计 Service 实现类
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BusinessServiceImpl implements BusinessService {
|
||||
|
||||
@Resource
|
||||
private BusinessMapper businessMapper;
|
||||
@Resource
|
||||
private DishOrderMapper dishOrderMapper;
|
||||
@Resource
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
@Resource
|
||||
private CardMapper cardMapper;
|
||||
@Override
|
||||
public Long createBusiness(BusinessSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
BusinessDO business = BeanUtils.toBean(createReqVO, BusinessDO.class);
|
||||
businessMapper.insert(business);
|
||||
// 返回
|
||||
return business.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBusiness(BusinessSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateBusinessExists(updateReqVO.getId());
|
||||
// 更新
|
||||
BusinessDO updateObj = BeanUtils.toBean(updateReqVO, BusinessDO.class);
|
||||
businessMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBusiness(Long id) {
|
||||
// 校验存在
|
||||
validateBusinessExists(id);
|
||||
// 删除
|
||||
businessMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateBusinessExists(Long id) {
|
||||
if (businessMapper.selectById(id) == null) {
|
||||
throw exception(ErrorCodeConstants.BUSINESS_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusinessDO getBusiness(Long id) {
|
||||
return businessMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<BusinessDO> getBusinessPage(BusinessPageReqVO pageReqVO) {
|
||||
return businessMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user