feat:食堂菜品购买统计-增加部门统计

This commit is contained in:
dzc committed 2025-08-01 17:10:38 +08:00
1 parent 92e4335c97
commit caafb3762d
8 files changed
+146 -4

No files matched your search

@@ -57,4 +57,6 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
*/
private String afterSaleNo;
private String createTimeStr;
}
@@ -8,6 +8,15 @@ import java.time.LocalDateTime;
@Data
public class HardCanteenProductTotalVo {
@Schema(description = "唯一编号")
private String uniqueCode;
@Schema(description = "部门id")
private Long userDeptId;
@Schema(description = "部门名")
private String userDeptName;
@Schema(description = "购买日期(年月日)")
private LocalDateTime createTime;
@@ -16,6 +16,8 @@ import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 食堂统计
*/
@@ -28,6 +30,13 @@ public class HardCanteenTotalController {
private final HardCanteenTotalService canteenTotalService;
@Operation(summary = "根据部门 食堂菜品购买统计", description = "根据部门 食堂菜品购买统计")
@PostMapping("/proudct-total-by-dept")
public R<List<HardCanteenProductTotalVo>> productTotalByDept(@ParameterObject Page page, @RequestBody HardOrderDto dto) {
DataScope dataScope = null;
return R.ok(canteenTotalService.productTotalByDept(page, dto, dataScope));
}
@Operation(summary = "食堂菜品购买统计", description = "食堂菜品购买统计")
@PostMapping("/proudct-total")
public R<Page<HardCanteenProductTotalVo>> productTotal(@ParameterObject Page page, @RequestBody HardOrderDto dto) {
@@ -12,6 +12,8 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface HardCarMapper extends PjcloudBaseMapper<HardCarEntity> {
@@ -22,6 +24,8 @@ public interface HardCarMapper extends PjcloudBaseMapper<HardCarEntity> {
return selectJoinPage(page, HardCarVo.class, wrapper);
}
List<HardCanteenProductTotalVo> productTotalByDept(@Param("dto") HardOrderDto dto, DataScope dataScope);
Page<HardCanteenProductTotalVo> productTotal(Page page, @Param("dto") HardOrderDto dto, DataScope dataScope);
Page<HardCarVo> proudctQuery(Page page, @Param("dto") HardCarDto dto);
@@ -8,8 +8,15 @@ import com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
import java.util.List;
public interface HardCanteenTotalService {
/**
* 根据部门 食堂菜品购买统计
*/
List<HardCanteenProductTotalVo> productTotalByDept(Page page, HardOrderDto dto, DataScope dataScope);
/**
* 食堂菜品购买统计
*/
@@ -1,6 +1,10 @@
package com.bsd.pjcloud.hard.service.impl.order;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenSpuService;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.dto.order.HardCarDto;
@@ -15,6 +19,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
/**
* 食堂统计
@@ -30,13 +38,47 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
private final HardOrderMapper hardOrderMapper;
private final HardCarMapper hardCarMapper;
private final RemoteDeptService remoteDeptService;
/**
* 根据部门 食堂菜品购买统计
*/
@Override
public List<HardCanteenProductTotalVo> productTotalByDept(Page page, HardOrderDto dto, DataScope dataScope) {
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
List<HardCanteenProductTotalVo> list = hardCarMapper.productTotalByDept(dto, dataScope);
if (ObjectUtil.isNotEmpty(list)) {
// 查询部门名
List<Long> userDeptList = list.stream().map(HardCanteenProductTotalVo::getUserDeptId).distinct().filter(ObjectUtil::isNotEmpty).toList();
if(ObjectUtil.isNotEmpty(userDeptList)){
Map<Long, SysDept> userDeptMap = remoteDeptService.getDeptByDeptIds(userDeptList).getData();
if (ObjectUtil.isNotEmpty(userDeptMap)) {
for (HardCanteenProductTotalVo v : list) {
SysDept sysDept = userDeptMap.get(v.getUserDeptId());
if (ObjectUtil.isNotEmpty(sysDept)) {
v.setUserDeptName(sysDept.getName());
}
}
}
}
}
return list;
}
/**
* 食堂菜品购买统计
*/
@Override
public Page<HardCanteenProductTotalVo> productTotal(Page page, HardOrderDto dto, DataScope dataScope) {
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
return hardCarMapper.productTotal(page, dto, dataScope);
Page<HardCanteenProductTotalVo> pageList = hardCarMapper.productTotal(page, dto, dataScope);
if (ObjectUtil.isNotEmpty(pageList)) {
for (HardCanteenProductTotalVo v : pageList.getRecords()) {
LocalDate localDate = v.getCreateTime().toLocalDate();
v.setUniqueCode(localDate + "_" + v.getHourType());
}
}
return pageList;
}
/**
@@ -41,7 +41,7 @@
<sql id="whereA">
a.del_flag = '0'
<if test="dto.createTimeStr != null ">
<if test="dto.createTimeStr != null and dto.createTimeStr != '' ">
and DATE_FORMAT(a.create_time, '%Y-%m-%d') = #{dto.createTimeStr}
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
@@ -49,6 +49,76 @@
</if>
</sql>
<select id="productTotalByDept" resultType="com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo">
select DATE_FORMAT(a.create_time, '%Y-%m-%d') as createTime,
o.user_dept_id,
SUM(a.product_count) as payCount,
SUM(a.total_price) as totalPrice,
count(distinct o.id) as timeCount,
count(distinct o.user_id) as payUserCount
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')
<where>
<include refid="whereA" />
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and o.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.hourType != null and dto.hourType != '' ">
and o.hour_type = #{dto.hourType}
</if>
<if test="dto.merchantId != null">
and o.merchant_id = #{dto.merchantId}
</if>
<if test="dto.isOfflineOrder != null">
and o.is_offline_order = #{dto.isOfflineOrder}
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and o.dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and o.dept_id NOT IN
</when>
<otherwise>
and o.dept_id IN
</otherwise>
</choose>
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.merchantDeptIds != null and dto.merchantDeptIds.size() != 0">
and o.merchant_dept_id in
<foreach collection="dto.merchantDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.mchIds != null and dto.mchIds.size() != 0">
and o.merchant_id in
<foreach collection="dto.mchIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and o.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.mchTypeCodes != null and dto.mchTypeCodes.size() != 0">
and o.merchant_type in
<foreach collection="dto.mchTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by o.user_dept_id
order by o.user_dept_id
</select>
<select id="productTotal" resultType="com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo">
select DATE_FORMAT(a.create_time, '%Y-%m-%d') as createTime,
o.hour_type,
@@ -61,7 +131,7 @@
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')
<where>
a.del_flag = 0
<include refid="whereA"/>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and o.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
@@ -3,4 +3,3 @@ com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService
com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopCategoryService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSKuService