|
@@ -0,0 +1,59 @@
|
|
|
+package com.xy.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.xy.annotate.RestMappingController;
|
|
|
+import com.xy.dto.DeviceDataDto;
|
|
|
+import com.xy.dto.MercMiniDeviceDto;
|
|
|
+import com.xy.service.DeviceDataServiceImpl;
|
|
|
+import com.xy.utils.MercAuthUtils;
|
|
|
+import com.xy.utils.R;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/***
|
|
|
+ * 商家端小程序-首页
|
|
|
+ * @author 谭斌
|
|
|
+ * @date 2023/3/13 14:38
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Api(tags = "商家端小程序-首页")
|
|
|
+@RestMappingController("merc-mini/homepage")
|
|
|
+public class MercMiniDeviceHomePageController {
|
|
|
+
|
|
|
+ private final DeviceDataServiceImpl deviceDataService;
|
|
|
+
|
|
|
+ @PostMapping("count")
|
|
|
+ @ApiOperation("首页统计")
|
|
|
+ public R<MercMiniDeviceDto.HomePageVO> homepageCount() {
|
|
|
+ MercMiniDeviceDto.HomePageVO vo = new MercMiniDeviceDto.HomePageVO();
|
|
|
+ Long mercId = MercAuthUtils.getMercId();
|
|
|
+ //当天
|
|
|
+ MercMiniDeviceDto.DayCountVO day = new MercMiniDeviceDto.DayCountVO().setOrderNum(0).setSalesPrice(0).setRefundMoney(0);
|
|
|
+ List<DeviceDataDto.Vo> mercDataOneDay = deviceDataService.getMercDataOneDay(mercId, DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN));
|
|
|
+ if (CollUtil.isNotEmpty(mercDataOneDay)) {
|
|
|
+ day.setSalesPrice(mercDataOneDay.stream().mapToInt(DeviceDataDto.Vo::getSalesMoney).sum());
|
|
|
+ day.setOrderNum(mercDataOneDay.stream().mapToInt(DeviceDataDto.Vo::getSalesCount).sum());
|
|
|
+ day.setRefundMoney(mercDataOneDay.stream().mapToInt(DeviceDataDto.Vo::getRefundMoney).sum());
|
|
|
+ }
|
|
|
+ vo.setDay(day);
|
|
|
+ //当月
|
|
|
+ MercMiniDeviceDto.MonthCountVO month = new MercMiniDeviceDto.MonthCountVO().setOrderNum(0).setSalesPrice(0).setRefundMoney(0);
|
|
|
+ List<DeviceDataDto.Vo> mercDataOneMonth = deviceDataService.getMercDataOneMonth(mercId, DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN));
|
|
|
+ if (CollUtil.isNotEmpty(mercDataOneMonth)) {
|
|
|
+ month.setSalesPrice(mercDataOneMonth.stream().mapToInt(DeviceDataDto.Vo::getSalesMoney).sum());
|
|
|
+ month.setOrderNum(mercDataOneMonth.stream().mapToInt(DeviceDataDto.Vo::getSalesCount).sum());
|
|
|
+ month.setRefundMoney(mercDataOneMonth.stream().mapToInt(DeviceDataDto.Vo::getRefundMoney).sum());
|
|
|
+ }
|
|
|
+ vo.setMonth(month);
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+}
|