超市统计订正

This commit is contained in:
zt
2025-03-14 14:08:08 +08:00
parent 4716e9f4be
commit 6a8c0462e1
11 changed files with 219 additions and 17 deletions

View File

@ -0,0 +1,64 @@
package cn.iocoder.yudao.module.member.controller.admin.storeorder.vo;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import lombok.*;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StoreOrderCountVO extends BaseDO {
private Integer orderId;
/**
* 读取卡号
*/
private String cardNumber;
/**
* 人脸
*/
private String openId;
/**
* 数量
*/
private Integer number;
/**
* 设备ID
*/
private String equipmentCode;
/**
* 离线缓存ID
*/
private String uuid;
/**
* 总价钱
*/
private Double totalPrice;
private Long userId;
/**
* 减免金额
*/
private Double reductionPrice;
/**
* 门店ID
*/
private Long carteenId;
/**
* 1-已支付2-已完成3-已取消4-已退款)
*/
private Integer status;
private Boolean billingExist;
private String billingNum;
private String timeSlot;
}

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.controller.app.storeorder;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -13,7 +12,6 @@ import cn.iocoder.yudao.module.member.controller.app.storeorder.dto.completeList
import cn.iocoder.yudao.module.member.controller.app.storeorder.vo.AppStoreOrderDetailVo;
import cn.iocoder.yudao.module.member.controller.app.storeorder.vo.AppStoreOrderVO;
import cn.iocoder.yudao.module.member.controller.app.storeorder.vo.CardDto;
import cn.iocoder.yudao.module.member.dal.dataobject.configdata.ConfigDataDO;
import cn.iocoder.yudao.module.member.dal.dataobject.storeorder.StoreOrderDO;
import cn.iocoder.yudao.module.member.enums.StoreOrderStatusEnum;
import cn.iocoder.yudao.module.member.service.async.MemberAsyncService;
@ -25,11 +23,7 @@ import cn.iocoder.yudao.module.system.api.carteen.CarteenApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
@ -41,7 +35,6 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.CONFIG_TYPE_NOT_EXISTS;
@Tag(name = "APP超市 - 商品订单")
@RestController
@ -158,6 +151,20 @@ public class AppStoreOrderController {
if(isInRange){
throw exception(new ErrorCode(1_007_904_009, "请明天购买"));
}
LocalTime currentTime = LocalTime.now();
// 定义开始时间和结束时间
LocalTime dsStartTime = LocalTime.of(0, 0);
LocalTime dsEndTime = LocalTime.of(1, 0);
// 判断当前时间是否在指定区间内
boolean isDsInRange = currentTime.isAfter(startTime) && currentTime.isBefore(endTime);
// 考虑边界情况,即当前时间是否等于开始时间
isDsInRange = isDsInRange || currentTime.equals(startTime);
if(isDsInRange){
throw exception(new ErrorCode(1_007_904_009, "当前时间不允许购买"));
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.dal.mysql.storeorder;
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.storeorder.vo.StoreOrderCountVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageVO;
import cn.iocoder.yudao.module.member.dal.dataobject.storeorder.StoreOrderDO;
@ -43,4 +44,7 @@ public interface StoreOrderMapper extends BaseMapperX<StoreOrderDO> {
List<StoreOrderPageVO> getStoreOrderPageNewList(@Param("vo") StoreOrderPageVO vo);
Integer updateByIdBillingExist (@Param("ids") Set<Long> ids, @Param("exist")Boolean exist);
Integer updateByIdBillingNum (@Param("ids") Set<Long> ids, @Param("num")String num);
List<StoreOrderCountVO> countOrder(@Param("startTime")String startTime,@Param("endTime")String endTime);
}

View File

@ -0,0 +1,101 @@
package cn.iocoder.yudao.module.member.job;
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.storeorder.vo.StoreOrderCountVO;
import cn.iocoder.yudao.module.member.dal.dataobject.storebusiness.StoreBusinessDO;
import cn.iocoder.yudao.module.member.dal.mysql.business.BusinessMapper;
import cn.iocoder.yudao.module.member.dal.mysql.storebusiness.StoreBusinessMapper;
import cn.iocoder.yudao.module.member.service.storeorder.StoreOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author:qjq 计算门店流水
* @Date:2024/4/24 下午3:22
*/
@Component
@Slf4j
public class StoreOrderCountJob implements JobHandler {
@Resource
private StoreOrderService storeOrderService;
@Resource
private BusinessMapper businessMapper;
@Resource
private StoreBusinessMapper storeBusinessMapper;
/**
* 执行任务
*
* @param param 参数
* @return 结果
* @throws Exception 异常
*/
@Override
@TenantIgnore
public String execute(String param) throws Exception {
try {
List<Long> allStoreId = businessMapper.getAllStoreId();
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 获取前一天的日期
LocalDate previousDate = currentDate.minusDays(1);
// 定义日期格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
// 将前一天的日期格式化为字符串
String formattedDate = previousDate.format(formatter);
List<StoreOrderCountVO> storeOrderCountVOS = storeOrderService.countOrder(formattedDate, formattedDate);
LocalDateTime startOfDay = currentDate.atStartOfDay();
LocalDateTime endOfDay = currentDate.atTime(LocalTime.MAX).withNano(0);
BigDecimal zero = BigDecimal.ZERO;
for (Long storeId:allStoreId){
StoreBusinessDO todayBusiness = storeBusinessMapper.getTodayBusiness(storeId, startOfDay, endOfDay);
List<StoreOrderCountVO> collect = storeOrderCountVOS.stream().filter(vo -> vo.getCarteenId().equals(storeId)).collect(Collectors.toList());
if (collect.isEmpty()){
todayBusiness.setTurnover(zero).setOrderSum(0).setCustomerSum(0).setPriceAvg(zero).setReduce(zero)
.setBreakfast(zero).setBreakfastNum(0)
.setLunch(zero).setLunchNum(0)
.setDinner(zero).setDinnerNum(0)
.setWeigh(zero);
}else {
double total = collect.stream().mapToDouble(StoreOrderCountVO::getTotalPrice).sum();
int size = collect.size();
BigDecimal divide = new BigDecimal(total).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP);
List<StoreOrderCountVO> breakfast = collect.stream().filter(vo -> vo.getTimeSlot().equals("早上")).collect(Collectors.toList());
double breakfastSum = breakfast.stream().mapToDouble(StoreOrderCountVO::getTotalPrice).sum();
List<StoreOrderCountVO> lunch = collect.stream().filter(vo -> vo.getTimeSlot().equals("中午")).collect(Collectors.toList());
double lunchSum = lunch.stream().mapToDouble(StoreOrderCountVO::getTotalPrice).sum();
List<StoreOrderCountVO> dinner = collect.stream().filter(vo -> vo.getTimeSlot().equals("晚上")).collect(Collectors.toList());
double dinnerSum = dinner.stream().mapToDouble(StoreOrderCountVO::getTotalPrice).sum();
double reduce = collect.stream().mapToDouble(StoreOrderCountVO::getReductionPrice).sum();
todayBusiness.setTurnover(new BigDecimal(total)).setOrderSum(size)
.setCustomerSum(size).setPriceAvg(divide).setReduce(new BigDecimal(reduce))
.setBreakfast(new BigDecimal(breakfastSum)).setBreakfastNum(breakfast.size())
.setLunch(new BigDecimal(lunchSum)).setLunchNum(lunch.size())
.setDinner(new BigDecimal(dinnerSum)).setDinnerNum(dinner.size())
.setWeigh(zero);
}
storeBusinessMapper.updateById(todayBusiness);
}
} catch (Exception e) {
return "超市订单统计失败";
}
return "超市订单统计成功";
}
}

View File

@ -84,6 +84,7 @@ public class StoreGoodsServiceImpl implements StoreGoodsService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteStoreGoods(Integer id) {
// 校验存在
validateStoreGoodsExists(id);
@ -92,6 +93,8 @@ public class StoreGoodsServiceImpl implements StoreGoodsService {
if(CollectionUtil.isNotEmpty(storeSaleGoodsDOS)){
throw exception(STORE_GOODS_IS_SALE);
}
StoreGoodsDO storeGoodsDO = storeGoodsMapper.selectById(id);
storeGoodsInventoryService.deleteByGoodsId(storeGoodsDO.getGoodsId(), storeGoodsDO.getCarteenId());
// 删除
storeGoodsMapper.deleteById(id);
}

View File

@ -68,4 +68,6 @@ public interface StoreGoodsInventoryService {
Integer getInventory(Integer goodsId,Long carteenId);
Map<Integer,Integer> getInventoryList(List<Integer> goodsIds, Long carteenId);
void deleteByGoodsId(Integer goodsId,Long carteenId);
}

View File

@ -174,4 +174,10 @@ public class StoreGoodsInventoryServiceImpl implements StoreGoodsInventoryServic
return Collections.emptyMap();
}
@Override
public void deleteByGoodsId(Integer goodsId, Long carteenId) {
storeGoodsInventoryMapper.delete(Wrappers.<StoreGoodsInventoryDO>lambdaUpdate().eq(StoreGoodsInventoryDO::getGoodsId, goodsId)
.eq(StoreGoodsInventoryDO::getCarteenId, carteenId));
}
}

View File

@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.member.service.storeorder;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.storegoodsinventory.vo.AddReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderCustomizeVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderSaveReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.*;
import cn.iocoder.yudao.module.member.controller.app.store.dto.FacePayDto;
import cn.iocoder.yudao.module.member.controller.app.store.dto.StoreOrderDto;
import cn.iocoder.yudao.module.member.controller.app.store.dto.StoreOrderUploadDto;
@ -98,4 +95,6 @@ public interface StoreOrderService {
AddReqVO refundAdmin(Integer orderId);
void completeList(List<Integer> orderIds);
List<StoreOrderCountVO> countOrder(String startTime,String endTime);
}

View File

@ -9,10 +9,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.admin.business.vo.StatisticsVo;
import cn.iocoder.yudao.module.member.controller.admin.storegoodsinventory.vo.AddReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storegoodsinventory.vo.GoodsInfoReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderCustomizeVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderPageVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderSaveReqVO;
import cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.*;
import cn.iocoder.yudao.module.member.controller.admin.storerefund.vo.StoreRefundSaveReqVO;
import cn.iocoder.yudao.module.member.controller.app.store.dto.*;
import cn.iocoder.yudao.module.member.controller.app.store.vo.UserInfoVo;
@ -52,6 +49,7 @@ import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -666,6 +664,11 @@ public class StoreOrderServiceImpl implements StoreOrderService {
}
}
@Override
public List<StoreOrderCountVO> countOrder(String startTime, String endTime) {
return storeOrderMapper.countOrder(startTime,endTime);
}
public void checkMoney(MemberUserDO user, BigDecimal totalMoney) {
//获取用户所在组分类
BigDecimal computeMoney = user.getMoney();

View File

@ -66,7 +66,7 @@
where DATE_FORMAT(md.create_time, '%Y%m%d') between #{startTime} and #{endTime} and mo.carteen_id = #{carteenId}
and md.deleted = false
and mo.deleted = false
and mo.status != 3
and mo.status != 3 and mo.status != 4
group by md.goods_name, md.custom_price
</select>

View File

@ -79,4 +79,17 @@
#{id}
</foreach>
</update>
<select id="countOrder" resultType="cn.iocoder.yudao.module.member.controller.admin.storeorder.vo.StoreOrderCountVO">
select *,
CASE
WHEN HOUR (mo.create_time) BETWEEN 0 AND 9 THEN '早上'
WHEN HOUR(mo.create_time) BETWEEN 10 AND 15 THEN '中午'
WHEN HOUR(mo.create_time) BETWEEN 16 AND 23 THEN '晚上'
ELSE '未知'
END AS timeSlot
from member_store_order mo
where DATE_FORMAT(mo.create_time, '%Y%m%d') between #{startTime} and #{endTime}
and mo.status not in (3, 4);
</select>
</mapper>