大屏添加门店

This commit is contained in:
zengtao01
2024-04-16 17:55:49 +08:00
parent e47dbf0c4e
commit e03a48f237
18 changed files with 142 additions and 74 deletions

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.member.controller.admin.diningplates.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author zt
* @description <description class purpose>
* @since 2024/4/16
*/
@Data
public class DiningPlatesStoreVo {
@Schema(description = "门店ID")
private Long storeId;
@Schema(description = "门店ID")
private Integer num;
}

View File

@ -30,7 +30,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 大屏")
@RestController
@RequestMapping("/member/screen")
@PermitAll
public class ScreenController {
@Resource
@ -44,26 +43,30 @@ public class ScreenController {
@GetMapping("/getEvaluate")
@Operation(summary = "获得店铺评价,1-好评2-差评")
public Map<String,String> getEvaluate(){
return storeEvaluateService.getEvaluate();
@PermitAll
public Map<String,String> getEvaluate(Long storeId){
return storeEvaluateService.getEvaluate(storeId);
}
@GetMapping("/getData")
@Operation(summary = "食堂今日顾客流量")
public CommonResult<List<CustomerTrafficRespVO>> getData() {
List<CustomerTrafficDO> data = customerTrafficService.getData();
@PermitAll
public CommonResult<List<CustomerTrafficRespVO>> getData(Long storeId) {
List<CustomerTrafficDO> data = customerTrafficService.getData(storeId);
return success(BeanUtils.toBean(data, CustomerTrafficRespVO.class));
}
@GetMapping("/getUserCount")
@Operation(summary = "获取总顾客流量")
public CommonResult<Integer> getUserCount() {
return success(orderService.selectTodayUser());
@PermitAll
public CommonResult<Integer> getUserCount(Long storeId) {
return success(orderService.selectTodayUser(storeId));
}
@GetMapping("/selectDishSale")
@Operation(summary = "菜品今日销售")
public CommonResult<List<DishVo>> selectDishSale() {
return success(orderDetailService.selectDishSale());
@PermitAll
public CommonResult<List<DishVo>> selectDishSale(Long storeId) {
return success(orderDetailService.selectDishSale(storeId));
}
}

View File

@ -4,8 +4,12 @@ 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.diningplates.vo.DiningPlatesPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesStoreVo;
import cn.iocoder.yudao.module.member.dal.dataobject.diningplates.DiningPlatesDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 餐盘 Mapper
@ -25,4 +29,7 @@ public interface DiningPlatesMapper extends BaseMapperX<DiningPlatesDO> {
.orderByDesc(DiningPlatesDO::getId));
}
@Select("select store_id,count(*) as num from member_dining_plates where create_time = #{time} group by store_id")
List<DiningPlatesStoreVo> selectCountByStore(String time);
}

View File

@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.member.controller.app.order.vo.AppOrderPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;
@ -44,7 +43,7 @@ public interface DishOrderMapper extends BaseMapperX<DishOrderDO> {
.orderByDesc(DishOrderDO::getId));
}
@Select("select count(distinct user_id) from member_dish_order where create_time between #{startTime} and #{endTime}")
Integer selectTodayUser(@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);
Integer selectTodayUser(@Param("time") String time,@Param("storeId") Long storeId);
}

View File

@ -10,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -32,7 +31,7 @@ public interface OrderDetailMapper extends BaseMapperX<OrderDetailDO> {
.orderByDesc(OrderDetailDO::getId));
}
@Select("select dishes_name, sum(a.weight) as weight , sum(a.price) as price from member_order_detail a where a.create_time between #{startTime} and #{endTime} group by a.dishes_id,a.dishes_name")
List<DishVo> selectDishSale(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
@Select("")
List<DishVo> selectDishSale(@Param("time") String time, @Param("storeId") Long storeId);
}

View File

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.member.job;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesStoreVo;
import cn.iocoder.yudao.module.member.dal.dataobject.customertraffic.CustomerTrafficDO;
import cn.iocoder.yudao.module.member.service.customertraffic.CustomerTrafficService;
import cn.iocoder.yudao.module.member.service.diningplates.DiningPlatesService;
@ -12,6 +14,8 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
/**
* @author zt
@ -36,11 +40,21 @@ public class CustomerTrafficJob implements JobHandler {
public String execute(String param) {
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(MemberConstants.HOUR_FORMAT);
LocalDateTime localDateTime = LocalDateTime.now().withSecond(0);
Integer diningPlatesNum = platesService.getDiningPlatesNum(localDateTime,ROUND_TIME);
CustomerTrafficDO customerTrafficDO = new CustomerTrafficDO();
customerTrafficDO.setCustomerNum(diningPlatesNum).setTimePoint(localDateTime.format(dateFormatter));
List<DiningPlatesStoreVo> diningPlatesNum = platesService.getDiningPlatesNum(localDateTime, ROUND_TIME);
if(CollectionUtil.isNotEmpty(diningPlatesNum)){
List<CustomerTrafficDO> addList = new ArrayList<>();
diningPlatesNum.forEach(a -> {
if(a.getStoreId()!=null){
CustomerTrafficDO customerTrafficDO = new CustomerTrafficDO();
customerTrafficDO.setCustomerNum(a.getNum())
.setTimePoint(localDateTime.format(dateFormatter))
.setStoreId(a.getStoreId());
addList.add(customerTrafficDO);
}
});
trafficService.insertBatch(addList);
}
trafficService.insertOne(customerTrafficDO);
log.info("[execute][顾客统计任务顾客数量 ({}) 个]", diningPlatesNum);
return String.format("顾客统计定时任务顾客数量 %s 个", diningPlatesNum);
}

View File

@ -54,11 +54,11 @@ public interface CustomerTrafficService {
PageResult<CustomerTrafficDO> getCustomerTrafficPage(CustomerTrafficPageReqVO pageReqVO);
void insertOne(CustomerTrafficDO customerTrafficDO);
void insertBatch(List<CustomerTrafficDO> list);
/**
* 获取最新7个时间节点的数据
*/
List<CustomerTrafficDO> getData();
List<CustomerTrafficDO> getData(Long storeId);
}

View File

@ -72,15 +72,16 @@ public class CustomerTrafficServiceImpl implements CustomerTrafficService {
}
@Override
public void insertOne(CustomerTrafficDO customerTrafficDO) {
customerTrafficMapper.insert(customerTrafficDO);
public void insertBatch(List<CustomerTrafficDO> list) {
customerTrafficMapper.insertBatch(list);
}
@Override
public List<CustomerTrafficDO> getData() {
public List<CustomerTrafficDO> getData(Long storeId) {
LocalDateTime now = LocalDateTime.now();
List<CustomerTrafficDO> customerTrafficDOS = customerTrafficMapper.selectList(Wrappers.<CustomerTrafficDO>lambdaQuery()
.lt(CustomerTrafficDO::getCreateTime, now)
.eq(storeId!=null,CustomerTrafficDO::getStoreId,storeId)
.orderByDesc(CustomerTrafficDO::getCustomerNum)
.last("limit 7"));
return customerTrafficDOS;

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.service.diningplates;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesSaveReqVO;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesStoreVo;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoCardVO;
import cn.iocoder.yudao.module.member.dal.dataobject.diningplates.DiningPlatesDO;
@ -90,5 +91,5 @@ public interface DiningPlatesService {
AppUserInfoCardVO appCheckBind(String diningPlatesNum);
Integer getDiningPlatesNum(LocalDateTime localDateTime,Integer time);
List<DiningPlatesStoreVo> getDiningPlatesNum(LocalDateTime localDateTime, Integer time);
}

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesSaveReqVO;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesStoreVo;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoCardVO;
import cn.iocoder.yudao.module.member.dal.dataobject.diningplates.DiningPlatesDO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
@ -17,7 +18,6 @@ import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.service.card.CardService;
import cn.iocoder.yudao.module.member.util.MemberConstants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
@ -268,22 +268,15 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
@Override
public Integer getDiningPlatesNum(LocalDateTime localDateTime, Integer time) {
public List<DiningPlatesStoreVo> getDiningPlatesNum(LocalDateTime localDateTime, Integer time) {
// 获取当前时间
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(MemberConstants.TIME_FORMAT);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(MemberConstants.DATE_FORMAT);
LocalDateTime currentTime = localDateTime;
// 计算指定分钟之前的时间
LocalDateTime timeMinutesAgo = currentTime.minusMinutes(time);
String end = currentTime.format(dateFormatter);
String start = timeMinutesAgo.format(dateFormatter);
QueryWrapper<DiningPlatesDO> queryWrapper = new QueryWrapper<>();
queryWrapper.le("date_format(binding_time,'%Y-%m-%d %H:%i:%s')",end)
.gt("date_format(binding_time,'%Y-%m-%d %H:%i:%s')",start);
Integer l = diningPlatesMapper.selectCount(queryWrapper).intValue();
return l;
String nowTime = currentTime.format(dateFormatter);
List<DiningPlatesStoreVo> diningPlatesStoreVos = diningPlatesMapper.selectCountByStore(nowTime);
return diningPlatesStoreVos;
}
/**

View File

@ -89,6 +89,6 @@ public interface OrderService {
* 获取今日顾客总量
* @return
*/
Integer selectTodayUser();
Integer selectTodayUser(Long storeId);
}

View File

@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper;
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
import cn.iocoder.yudao.module.member.enums.TimePeriodEnum;
import cn.iocoder.yudao.module.member.service.orderdetail.OrderDetailService;
import cn.iocoder.yudao.module.member.util.MemberConstants;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -31,6 +32,7 @@ import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -215,19 +217,9 @@ public class OrderServiceImpl implements OrderService {
}
@Override
public Integer selectTodayUser() {
public Integer selectTodayUser(Long storeId) {
LocalDate today = LocalDate.now();
// 一天的开始时间
LocalDateTime startOfDay = today.atStartOfDay();
// 一天的结束时间
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
return dishOrderMapper.selectTodayUser(startOfDay,endOfDay);
String time = today.format(DateTimeFormatter.ofPattern(MemberConstants.DATE_FORMAT));
return dishOrderMapper.selectTodayUser(time,storeId);
}
}

View File

@ -59,5 +59,5 @@ public interface OrderDetailService {
List<OrderDetailDO> selectListByOrderIds(List<Long> orderIds);
List<DishVo> selectDishSale();
List<DishVo> selectDishSale(Long storeId);
}

View File

@ -30,8 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -180,17 +179,10 @@ public class OrderDetailServiceImpl implements OrderDetailService {
}
@Override
public List<DishVo> selectDishSale() {
// 获取当前日期
public List<DishVo> selectDishSale(Long storeId) {
LocalDate today = LocalDate.now();
// 一天的开始时间
LocalDateTime startOfDay = today.atStartOfDay();
// 一天的结束时间
LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
return orderDetailMapper.selectDishSale(startOfDay,endOfDay);
String time = today.format(DateTimeFormatter.ofPattern(MemberConstants.DATE_FORMAT));
return orderDetailMapper.selectDishSale(time,storeId);
}

View File

@ -59,7 +59,7 @@ public interface StoreEvaluateService {
StoreEvaluateDO selectByUserId(Long storeId);
Map<String,String> getEvaluate();
Map<String,String> getEvaluate(Long storeId);

View File

@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.member.controller.app.storeevaluate.vo.AppStoreEv
import cn.iocoder.yudao.module.member.dal.dataobject.storeevaluate.StoreEvaluateDO;
import cn.iocoder.yudao.module.member.dal.mysql.storeevaluate.StoreEvaluateMapper;
import cn.iocoder.yudao.module.member.util.MemberConstants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -107,20 +108,23 @@ public class StoreEvaluateServiceImpl implements StoreEvaluateService {
}
@Override
public Map<String, String> getEvaluate() {
public Map<String, String> getEvaluate(Long storeId) {
HashMap<String, String> result = new HashMap<>();
Long good = storeEvaluateMapper.selectCount(Wrappers.<StoreEvaluateDO>lambdaQuery()
.gt(StoreEvaluateDO::getEvaluate, MemberConstants.GOOD_EVALUATE));
Long total = storeEvaluateMapper.selectCount();
LambdaQueryWrapper<StoreEvaluateDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(storeId != null,StoreEvaluateDO::getStoreId,storeId);
Long good = storeEvaluateMapper.selectCount(queryWrapper
.gt(StoreEvaluateDO::getEvaluate, MemberConstants.GOOD_EVALUATE)
);
Long total = storeEvaluateMapper.selectCount(queryWrapper);
if(total == 0){
result.put("1","0");
result.put("0","0");
result.put("1","0.00%");
result.put("0","0.00%");
return result;
}
BigDecimal goodPercent = new BigDecimal(good).divide(new BigDecimal(total), 4, BigDecimal.ROUND_HALF_UP);
BigDecimal badPercent = BigDecimal.ONE.subtract(goodPercent);
result.put("1",goodPercent.multiply(new BigDecimal("100")).toString()+"%");
result.put("0",badPercent.multiply(new BigDecimal("100")).toString()+"%");
result.put("1",goodPercent.multiply(new BigDecimal("100")).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"%");
result.put("0",badPercent.multiply(new BigDecimal("100")).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"%");
return result;
}
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="selectTodayUser" resultType="integer">
select count(distinct user_id) from member_dish_order where
date_format(create_time,'%Y-%m-%d') = #{time}
<if test="storeId != null">
and store_id = #{storeId}
</if>
</select>
</mapper>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.member.dal.mysql.orderdetail.OrderDetailMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="selectDishSale" resultType="cn.iocoder.yudao.module.member.controller.admin.screen.vo.DishVo">
select dishes_name, sum(a.weight) as weight , sum(a.price) as price
from member_order_detail a
where date_format(a.create_time,'%Y-%m-%d') = #{time}
<if test="storeId != null">
and order_id in
(select id from member_dish_order
where store_id = #{storeId}
and date_format(create_time,'%Y-%m-%d') = #{time})
</if>
group by a.dishes_id,a.dishes_name
</select>
</mapper>