feat:食堂菜品部门统计
This commit is contained in:
1 parent
d4830a3470
commit
abf8d26507
10 files changed
+273
-16
No files matched your search
+10
@@ -59,4 +59,14 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
|
||||
|
||||
private String createTimeStr;
|
||||
|
||||
/**
|
||||
* 是否查询时间段为空的数据
|
||||
*/
|
||||
private Boolean hourTypeIsNotEmpty = false;
|
||||
|
||||
/**
|
||||
* 是否查询商品描述不为空的数据
|
||||
*/
|
||||
private Boolean productDescIsNotEmpty = false;
|
||||
|
||||
}
|
||||
+12
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class HardCanteenProductTotalVo {
|
||||
@@ -11,6 +12,12 @@ public class HardCanteenProductTotalVo {
|
||||
@Schema(description = "唯一编号")
|
||||
private String uniqueCode;
|
||||
|
||||
@Schema(description = "商户id")
|
||||
private Long mchId;
|
||||
|
||||
@Schema(description = "商户名称")
|
||||
private String mchName;
|
||||
|
||||
@Schema(description = "部门id")
|
||||
private Long userDeptId;
|
||||
|
||||
@@ -35,4 +42,9 @@ public class HardCanteenProductTotalVo {
|
||||
@Schema(description = "购买次数")
|
||||
private Long timeCount;
|
||||
|
||||
@Schema(description = "用餐部门总数")
|
||||
private Integer deptCount;
|
||||
|
||||
private List<HardCanteenProductTotalVo> children;
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.bsd.pjcloud.hard.controller.order;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo;
|
||||
import com.bsd.pjcloud.hard.service.HardCanteenTotalService;
|
||||
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.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 食堂部门统计
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/hard-canteen-total-dept")
|
||||
@Tag(description = "hard-canteen-total-dept", name = "食堂部门统计")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class HardCanteenDeptTotalController {
|
||||
|
||||
private final HardCanteenTotalService canteenTotalService;
|
||||
|
||||
@Operation(summary = "食堂菜品购买部门统计", description = "食堂菜品购买部门统计")
|
||||
@PostMapping("/list-by-dept")
|
||||
public R<List<HardCanteenProductTotalVo>> listByDept(@RequestBody HardOrderDto dto) {
|
||||
DataScope dataScope = null;
|
||||
return R.ok(canteenTotalService.listByDept(dto, dataScope));
|
||||
}
|
||||
|
||||
@Operation(summary = "食堂菜品购买用餐时间段统计", description = "食堂菜品购买用餐时间段统计")
|
||||
@PostMapping("/list-by-hour-type")
|
||||
public R<List<HardCanteenProductTotalVo>> listByHourType(@RequestBody HardOrderDto dto) {
|
||||
DataScope dataScope = null;
|
||||
return R.ok(canteenTotalService.listByHourType(dto, dataScope));
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -29,4 +29,8 @@ public interface HardCarMapper extends PjcloudBaseMapper<HardCarEntity> {
|
||||
Page<HardCanteenProductTotalVo> productTotal(Page page, @Param("dto") HardOrderDto dto, DataScope dataScope);
|
||||
|
||||
Page<HardCarVo> proudctQuery(Page page, @Param("dto") HardCarDto dto);
|
||||
|
||||
List<HardCanteenProductTotalVo> listByDept(@Param("dto") HardOrderDto dto, DataScope dataScope);
|
||||
|
||||
List<HardCanteenProductTotalVo> listByHourType(@Param("dto") HardOrderDto dto);
|
||||
}
|
||||
+10
@@ -26,4 +26,14 @@ public interface HardCanteenTotalService {
|
||||
* 菜品出售统计
|
||||
*/
|
||||
Page<HardCarVo> proudctQuery(Page page, HardCarDto dto);
|
||||
|
||||
/**
|
||||
* 食堂菜品购买部门统计
|
||||
*/
|
||||
List<HardCanteenProductTotalVo> listByDept(HardOrderDto dto, DataScope dataScope);
|
||||
|
||||
/**
|
||||
* 食堂菜品购买用餐时间段统计
|
||||
*/
|
||||
List<HardCanteenProductTotalVo> listByHourType(HardOrderDto dto, DataScope dataScope);
|
||||
}
|
||||
+109
-16
@@ -1,10 +1,11 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.order;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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.core.constant.enums.MerchantTypeEnum;
|
||||
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;
|
||||
@@ -14,14 +15,22 @@ import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardCarMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardCanteenTotalService;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletService;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -39,6 +48,7 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
private final HardCarMapper hardCarMapper;
|
||||
|
||||
private final RemoteDeptService remoteDeptService;
|
||||
private final RemoteMchService remoteMchService;
|
||||
|
||||
/**
|
||||
* 根据部门 食堂菜品购买统计
|
||||
@@ -47,21 +57,7 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hardCanteenProductTotalVoSetDeptData(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -89,4 +85,101 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
|
||||
return hardCarMapper.proudctQuery(page, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 食堂菜品购买部门统计
|
||||
*/
|
||||
@Override
|
||||
public List<HardCanteenProductTotalVo> listByDept(HardOrderDto dto, DataScope dataScope) {
|
||||
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
|
||||
// 查询所有的自营食堂
|
||||
List<MchManageVo> mchList = remoteMchService.getByTypes(List.of(MerchantTypeEnum.CANTEEN.getType())).getData();
|
||||
if (ObjectUtil.isEmpty(mchList)) return null;
|
||||
dto.setMchIds(mchList.stream().map(MchManageVo::getId).toList());
|
||||
List<HardCanteenProductTotalVo> list = hardCarMapper.listByDept(dto, dataScope);
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
// 限制最大线程数为10
|
||||
int threadCount = Math.min(list.size(), 10);
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
|
||||
try {
|
||||
List<CompletableFuture<Void>> futures = list.stream()
|
||||
.map(v -> CompletableFuture.runAsync(() -> {
|
||||
// 查询时间段
|
||||
HardOrderDto deptQuery = BeanUtil.toBean(dto, HardOrderDto.class);
|
||||
deptQuery.setMerchantId(v.getMchId());
|
||||
List<HardCanteenProductTotalVo> deptList = hardCarMapper.listByHourType(deptQuery);
|
||||
|
||||
for (HardCanteenProductTotalVo j : deptList) {
|
||||
if (ObjectUtil.isNotEmpty(v.getMchId())) j.setMchId(v.getMchId());
|
||||
}
|
||||
|
||||
v.setDeptCount(deptList.stream().map(HardCanteenProductTotalVo::getUserDeptId).distinct().toList().size());
|
||||
v.setChildren(deptList);
|
||||
}, executorService))
|
||||
.toList();
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
} finally {
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
// 添加商户信息
|
||||
hardCanteenProductTotalVoSetMchData(list);
|
||||
// 添加部门信息
|
||||
hardCanteenProductTotalVoSetDeptData(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 食堂菜品购买用餐时间段统计
|
||||
*/
|
||||
@Override
|
||||
public List<HardCanteenProductTotalVo> listByHourType(HardOrderDto dto, DataScope dataScope) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 为HardCanteenProductTotalVo增加部门信息
|
||||
*/
|
||||
private void hardCanteenProductTotalVoSetDeptData(List<HardCanteenProductTotalVo> list) {
|
||||
if (ObjectUtil.isEmpty(list)) return;
|
||||
// 查询部门名
|
||||
List<Long> userDeptList = new ArrayList<>();
|
||||
for (HardCanteenProductTotalVo i : list) {
|
||||
if (ObjectUtil.isNotEmpty(i.getUserDeptId())) userDeptList.add(i.getUserDeptId());
|
||||
if (ObjectUtil.isNotEmpty(i.getChildren())) {
|
||||
for (HardCanteenProductTotalVo j : i.getChildren()) {
|
||||
if (ObjectUtil.isNotEmpty(j.getUserDeptId())) userDeptList.add(j.getUserDeptId());
|
||||
}
|
||||
}
|
||||
}
|
||||
userDeptList = userDeptList.stream().distinct().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());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(v.getChildren())) {
|
||||
hardCanteenProductTotalVoSetDeptData(v.getChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hardCanteenProductTotalVoSetMchData(List<HardCanteenProductTotalVo> list) {
|
||||
if (ObjectUtil.isEmpty(list)) return;
|
||||
// 查询商户名
|
||||
List<Long> mchIdList = list.stream().map(HardCanteenProductTotalVo::getMchId).distinct().filter(ObjectUtil::isNotEmpty).toList();
|
||||
if (ObjectUtil.isEmpty(mchIdList)) return;
|
||||
List<MchManageVo> mchList = remoteMchService.getByIds(mchIdList).getData();
|
||||
if (ObjectUtil.isNotEmpty(mchList)) {
|
||||
for (HardCanteenProductTotalVo i : list) {
|
||||
mchList.stream().filter(m -> ObjectUtil.equals(i.getMchId(), m.getId())).findFirst().ifPresent(mch -> i.setMchName(mch.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -218,4 +218,63 @@
|
||||
group by a.product_id
|
||||
order by SUM(a.product_count) desc
|
||||
</select>
|
||||
|
||||
<select id="listByDept" resultType="com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo">
|
||||
select
|
||||
o.merchant_id as mchId,
|
||||
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.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.hourType != null and dto.hourType != '' ">
|
||||
and o.hour_type = #{dto.hourType}
|
||||
</if>
|
||||
<if test="dto.merchantId != null">
|
||||
and o.merchant_id = #{dto.merchantId}
|
||||
</if>
|
||||
</where>
|
||||
group by o.merchant_id
|
||||
order by o.merchant_id
|
||||
</select>
|
||||
|
||||
<select id="listByHourType" resultType="com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo">
|
||||
select
|
||||
o.user_dept_id,
|
||||
o.hour_type,
|
||||
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.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.createTimeList != null and dto.createTimeList.length == 2">
|
||||
and o.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
|
||||
</if>
|
||||
</where>
|
||||
group by o.user_dept_id, o.hour_type
|
||||
order by o.user_dept_id, o.hour_type
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+9
@@ -97,6 +97,15 @@
|
||||
<if test="dto.hourType != null and dto.hourType != '' ">
|
||||
and a.hour_type = #{dto.hourType}
|
||||
</if>
|
||||
<if test="dto.hourTypeIsNotEmpty != null and dto.hourTypeIsNotEmpty == true ">
|
||||
and ( a.hour_type is not null and a.hour_type not in ('-1') )
|
||||
</if>
|
||||
<if test="dto.productDescIsNotEmpty != null and dto.productDescIsNotEmpty == true ">
|
||||
and ( a.product_desc != '' )
|
||||
</if>
|
||||
<if test="dto.userId != null">
|
||||
and a.user_id = #{dto.userId}
|
||||
</if>
|
||||
<if test="dto.deptId != null">
|
||||
and a.dept_id = #{dto.deptId}
|
||||
</if>
|
||||
|
||||
+4
@@ -14,6 +14,10 @@ import java.util.List;
|
||||
@FeignClient(contextId = "remoteMchService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteMchService {
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/mch-manage/get-by-types")
|
||||
R<List<MchManageVo>> getByTypes(@RequestParam List<String> types);
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/mch-manage/get-by-id")
|
||||
R<MchManageVo> getById(@RequestParam Long id);
|
||||
|
||||
+8
@@ -54,6 +54,14 @@ public class MchManageController {
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
@Inner
|
||||
@GetMapping("/get-by-types")
|
||||
public R<List<MchManageVo>> getByTypes(@RequestParam List<String> types) {
|
||||
List<MchManageVo> list = mchManageService.list(MchManageDto.builder().typesList(types).build());
|
||||
if (ObjectUtil.isEmpty(list)) return R.failed("商户不存在");
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
@Inner
|
||||
@GetMapping("/get-by-id")
|
||||
public R<MchManageVo> getById(@RequestParam Long id) {
|
||||
|
||||
Reference in new issue
Block a user