首页相关逻辑,商品表中isShow给予不同含义,创建新用户更改
This commit is contained in:
parent
afbb6c2211
commit
11af368005
|
|
@ -92,7 +92,7 @@ public class DateUtil {
|
|||
* 日期 格式化
|
||||
*
|
||||
* @param localDateTime /
|
||||
* @param patten /
|
||||
* @param patten /
|
||||
* @return /
|
||||
*/
|
||||
public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) {
|
||||
|
|
@ -104,7 +104,7 @@ public class DateUtil {
|
|||
* 日期 格式化
|
||||
*
|
||||
* @param localDateTime /
|
||||
* @param df /
|
||||
* @param df /
|
||||
* @return /
|
||||
*/
|
||||
public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) {
|
||||
|
|
@ -173,6 +173,7 @@ public class DateUtil {
|
|||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
||||
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
||||
}
|
||||
|
||||
// 获取某个日期的开始时间
|
||||
public static Timestamp getDayStartTime(Date d) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
|
@ -187,6 +188,7 @@ public class DateUtil {
|
|||
|
||||
/**
|
||||
* 激活码到期时间
|
||||
*
|
||||
* @param monthsToAdd
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -218,6 +220,7 @@ public class DateUtil {
|
|||
cal.add(Calendar.DATE, 2 - dayofweek);
|
||||
return getDayStartTime(cal.getTime());
|
||||
}
|
||||
|
||||
// 获取某个日期的结束时间
|
||||
public static Timestamp getDayEndTime(Date d) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
|
@ -229,6 +232,7 @@ public class DateUtil {
|
|||
calendar.set(Calendar.MILLISECOND, 999);
|
||||
return new Timestamp(calendar.getTimeInMillis());
|
||||
}
|
||||
|
||||
// 获取本周的结束时间
|
||||
public static Date getEndDayOfWeek() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
|
@ -237,6 +241,7 @@ public class DateUtil {
|
|||
Date weekEndSta = cal.getTime();
|
||||
return getDayEndTime(weekEndSta);
|
||||
}
|
||||
|
||||
// 获取今年是哪一年
|
||||
public static Integer getNowYear() {
|
||||
Date date = new Date();
|
||||
|
|
@ -280,4 +285,136 @@ public class DateUtil {
|
|||
|
||||
return getDayStartTime(cal.getTime());
|
||||
}
|
||||
|
||||
// 获取本年的结束时间
|
||||
public static Date getEndDayOfYear() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, getNowYear());
|
||||
cal.set(Calendar.MONTH, Calendar.DECEMBER);
|
||||
cal.set(Calendar.DATE, 31);
|
||||
return getDayEndTime(cal.getTime());
|
||||
}
|
||||
|
||||
// 获取明天的开始时间
|
||||
public static Date getBeginDayOfTomorrow() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayBegin());
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
// 获取明天的结束时间
|
||||
public static Date getEndDayOfTomorrow() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayEnd());
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
// 获取当天的开始时间
|
||||
public static Date getDayBegin() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
// 获取当天的结束时间
|
||||
public static Date getDayEnd() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
cal.set(Calendar.MILLISECOND, 999);
|
||||
return cal.getTime();
|
||||
}
|
||||
//向后推30天
|
||||
public static Date getDate30DaysAgo() {
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate thirtyDaysAgo = today.minusDays(30);
|
||||
ZonedDateTime zonedDateTime = thirtyDaysAgo.atStartOfDay(ZoneId.systemDefault());
|
||||
return Date.from(zonedDateTime.toInstant());
|
||||
}
|
||||
//向后推7天
|
||||
public static Date getDate7DaysAgo() {
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate sevenDaysAgo = today.minusDays(7);
|
||||
ZonedDateTime zonedDateTime = sevenDaysAgo.atStartOfDay(ZoneId.systemDefault());
|
||||
return Date.from(zonedDateTime.toInstant());
|
||||
}
|
||||
//向后推一年天
|
||||
public static Date getDateOneYearAgo() {
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate oneYearAgo = today.minusYears(1);
|
||||
ZonedDateTime zonedDateTime = oneYearAgo.atStartOfDay(ZoneId.systemDefault());
|
||||
return Date.from(zonedDateTime.toInstant());
|
||||
}
|
||||
// 获取今天开始的时间戳(午夜00:00)
|
||||
public static long getTodayStartTimestamp() {
|
||||
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
ZonedDateTime zonedDateTime = todayStart.atZone(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
// 获取今天结束的时间戳(23:59:59)
|
||||
public static long getTodayEndTimestamp() {
|
||||
LocalDateTime todayEnd = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).withNano(999999999);
|
||||
ZonedDateTime zonedDateTime = todayEnd.atZone(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
public static String getTodayString(){
|
||||
// 获取今天的日期
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
// 定义一个DateTimeFormatter来格式化日期为"yyyy-MM-dd"格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
// 使用formatter来格式化今天的日期为字符串
|
||||
return today.format(formatter);
|
||||
}
|
||||
|
||||
|
||||
public static Long getDaysAgoInMilliseconds(int days) {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
LocalDate pastDate = currentDate.minusDays(days);
|
||||
ZonedDateTime zonedDateTime = pastDate.atStartOfDay(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
/**
|
||||
* 获取当前日期往前推30天的日期,并转换为Long类型(毫秒数)
|
||||
* @return 30天前的日期对应的毫秒数
|
||||
*/
|
||||
public static Long getThirtyDaysAgoInMilliseconds() {
|
||||
return getDaysAgoInMilliseconds(30);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期往前推7天的日期,并转换为Long类型(毫秒数)
|
||||
* @return 7天前的日期对应的毫秒数
|
||||
*/
|
||||
public static Long getSevenDaysAgoInMilliseconds() {
|
||||
return getDaysAgoInMilliseconds(7);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前年份的最后一天的日期,并转换为Long类型(毫秒数)
|
||||
* @return 本年结束日期对应的毫秒数
|
||||
*/
|
||||
public static Long getEndOfYearInMilliseconds() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
int year = currentDate.getYear();
|
||||
LocalDate endOfYear = LocalDate.of(year, 12, 31);
|
||||
ZonedDateTime zonedDateTime = endOfYear.atStartOfDay(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
public static Long getBeginningOfYearInMilliseconds() {
|
||||
LocalDate beginningOfYear = LocalDate.now().withMonth(1).withDayOfMonth(1);
|
||||
ZonedDateTime zonedDateTime = beginningOfYear.atStartOfDay(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,27 @@ public class SummaryController {
|
|||
private Object shopSummaryDate(@RequestParam Integer shopId,@RequestParam Integer day){
|
||||
return summaryService.selectSummaryDate(shopId,day);
|
||||
}
|
||||
|
||||
@GetMapping("/today")
|
||||
private Object shopSummaryDate(@RequestParam Integer shopId){
|
||||
return summaryService.selectSummaryToday(shopId);
|
||||
}
|
||||
|
||||
@GetMapping("/dateAmount")
|
||||
private Object shopSummaryAmount(@RequestParam Integer shopId,@RequestParam Integer day){
|
||||
return summaryService.selectSummaryAmount(shopId,day);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/dateProduct")
|
||||
private Object shopSummaryProduct(@RequestParam Integer shopId,@RequestParam Integer day,
|
||||
@RequestParam Integer page){
|
||||
return summaryService.selectSummaryProduct(shopId,day,page);
|
||||
}
|
||||
@GetMapping("/datePayType")
|
||||
private Object shopSummaryPayType(@RequestParam Integer shopId,@RequestParam Integer day){
|
||||
return summaryService.selectSummaryPayType(shopId,day);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,16 @@ public enum PayTypeEnum {
|
|||
return ot.getType();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return "未知支付方式";
|
||||
}
|
||||
|
||||
public static String getCodeByName(String code) {
|
||||
PayTypeEnum[] operateTypes = values();
|
||||
for (PayTypeEnum ot : operateTypes) {
|
||||
if (ot.type.equals(code)) {
|
||||
return ot.getName();
|
||||
}
|
||||
}
|
||||
return "未知支付方式";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ public class TbProduct implements Serializable {
|
|||
private Integer isOnSale = 0;
|
||||
|
||||
@Column(name = "`is_show`")
|
||||
@ApiModelProperty(value = "是否展示0-下架 1上架---废弃")
|
||||
@ApiModelProperty(value = "是否展示0-不展示 1.小程序2.收银端 9.全展示")
|
||||
private Integer isShow = 0;
|
||||
|
||||
@Column(name = "`type_enum`")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -15,13 +16,34 @@ import java.util.List;
|
|||
public interface ShopUserDutyDetailRepository extends JpaRepository<TbShopUserDutyDetail, Integer> {
|
||||
|
||||
@Query(value = "SELECT" +
|
||||
" product.product_id as productId, product.product_name as productName, SUM(product.num) as productNum" +
|
||||
" product.product_id as productId, product.product_name as productName, SUM(product.num),sum(product.amount) as productNum" +
|
||||
" FROM" +
|
||||
" tb_shop_user_duty_detail AS product" +
|
||||
" LEFT JOIN tb_shop_user_duty AS user ON product.duty_id = USER.id " +
|
||||
"WHERE user.shop_id = :shopId" +
|
||||
" AND user.login_time BETWEEN :startTime AND :endTime" +
|
||||
" GROUP BY product.product_id" +
|
||||
" Limit 5", nativeQuery = true)
|
||||
List<Object[]> searchByDutyId(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
" Limit :currentPage,5", nativeQuery = true)
|
||||
List<Object[]> searchByDutyId(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime
|
||||
,@Param("currentPage") Integer currentPage);
|
||||
|
||||
|
||||
@Query(value = "SELECT" +
|
||||
" SUM(product.num),SUM(user.amount)" +
|
||||
" FROM" +
|
||||
" tb_shop_user_duty_detail AS product" +
|
||||
" LEFT JOIN tb_shop_user_duty AS user ON product.duty_id = USER.id " +
|
||||
"WHERE user.shop_id = :shopId" +
|
||||
" AND user.login_time BETWEEN :startTime AND :endTime", nativeQuery = true)
|
||||
Tuple searchByDutyIdSum(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query(value = "SELECT" +
|
||||
" SUM(product.num),SUM(product.amount)" +
|
||||
" FROM" +
|
||||
" tb_shop_user_duty_detail AS product" +
|
||||
" LEFT JOIN tb_shop_user_duty AS user ON product.duty_id = USER.id " +
|
||||
"WHERE user.shop_id = :shopId" +
|
||||
" AND user.login_time BETWEEN :startTime AND :endTime" +
|
||||
" group by user.trade_day", nativeQuery = true)
|
||||
List<Object[]> searchByDayToAmount(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,5 +32,11 @@ public interface ShopUserDutyRepository extends JpaRepository<TbShopUserDuty, In
|
|||
"GROUP BY\n" +
|
||||
"\tshop_id,\n" +
|
||||
"\ttrade_day",nativeQuery = true)
|
||||
List<SumDateMapping> sumByDate(@Param("shopId")Integer shopId, @Param("startTime") Date startTime,@Param("endTime") Date endTime);
|
||||
List<Object[]> sumByDate(@Param("shopId")Integer shopId, @Param("startTime") Date startTime,@Param("endTime") Date endTime);
|
||||
|
||||
@Query("SELECT SUM(detail.orderNum), SUM(detail.amount) " +
|
||||
"FROM TbShopUserDuty detail " +
|
||||
"WHERE detail.shopId = :shopId " +
|
||||
"AND detail.loginTime BETWEEN :startTime AND :endTime")
|
||||
Tuple sumByShopIdToday(@Param("shopId") Integer shopId,@Param("startTime") Date startTime,@Param("endTime") Date endTime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -31,6 +32,7 @@ import java.util.List;
|
|||
**/
|
||||
public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Integer>, JpaSpecificationExecutor<TbOrderInfo> {
|
||||
|
||||
@Query(value = "SELECT COUNT(1) AS count,pay_type AS payType FROM tb_order_info Where shop_id = :shopId GROUP BY pay_type" ,nativeQuery = true)
|
||||
List<CountPayTypeMapping> countByShopId(@Param("shopId") String shopId);
|
||||
@Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " +
|
||||
" created_at BETWEEN :startTime AND :endTime GROUP BY pay_type" ,nativeQuery = true)
|
||||
List<Object[]> countByShopId(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
|
|
@ -33,4 +34,7 @@ public interface TbShopUserRepository extends JpaRepository<TbShopUser, Integer>
|
|||
@Query("SELECT count(0) from TbShopUser user where user.shopId = :shopId")
|
||||
Tuple searchByCount(@Param("shopId") String shopId);
|
||||
|
||||
@Query("SELECT count(0) from TbShopUser user where user.shopId = :shopId and user.createdAt BETWEEN :startTime AND :endTime")
|
||||
Tuple searchByCountToday(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
|
||||
}
|
||||
|
|
@ -13,4 +13,11 @@ public interface SummaryService {
|
|||
SummaryVO selectSummary(Integer shop);
|
||||
|
||||
Map<String,Object> selectSummaryDate(Integer shopId, Integer day);
|
||||
|
||||
Map<String,Object> selectSummaryToday(Integer shopId);
|
||||
|
||||
Map<String,Object> selectSummaryAmount(Integer shopId, Integer day);
|
||||
Map<String,Object> selectSummaryProduct(Integer shopId, Integer day,Integer page);
|
||||
|
||||
Map<String,Object> selectSummaryPayType(Integer shopId, Integer day);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.ysk.cashier.enums.PayTypeEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||
import cn.ysk.cashier.repository.mapping.CountPayTypeMapping;
|
||||
|
|
@ -8,6 +10,8 @@ import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
|||
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
|
||||
import cn.ysk.cashier.service.SummaryService;
|
||||
import cn.ysk.cashier.utils.DateUtil;
|
||||
import cn.ysk.cashier.vo.CountPayTypeVO;
|
||||
import cn.ysk.cashier.vo.SumDateVO;
|
||||
import cn.ysk.cashier.vo.SummaryVO;
|
||||
import cn.ysk.cashier.vo.ProductVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
@ -16,7 +20,10 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import javax.persistence.Tuple;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -38,17 +45,6 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
Tuple result = shopUserDutyRepository.sumByShopId(shopId);
|
||||
summaryVO.setPaymentsNumber(result.get(0, Long.class) == null?0L : result.get(0, Long.class));
|
||||
summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null? new BigDecimal("0") : result.get(1, BigDecimal.class));
|
||||
// List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId);
|
||||
//商品销量排行前五
|
||||
// List<ProductVO> list = new ArrayList<>();
|
||||
// for (Object[] o :objects) {
|
||||
// ProductVO productVO = new ProductVO();
|
||||
// productVO.setProductId((Integer) o[0]);
|
||||
// productVO.setProductName((String) o[1]);
|
||||
// productVO.setProductNum((BigDecimal)o[2]);
|
||||
// list.add(productVO);
|
||||
// }
|
||||
// summaryVO.setProductInfoList(list);
|
||||
if (summaryVO.getPaymentsNumber() == 0){
|
||||
summaryVO.setAverageSales(new BigDecimal("0"));
|
||||
}else {
|
||||
|
|
@ -57,7 +53,6 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
//用户数
|
||||
Tuple count = tbShopUserRepository.searchByCount(shopId.toString());
|
||||
summaryVO.setTotalUser(count.get(0, Long.class));
|
||||
|
||||
return summaryVO;
|
||||
}
|
||||
|
||||
|
|
@ -65,36 +60,174 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
public Map<String,Object> selectSummaryDate(Integer shopId, Integer day) {
|
||||
Date startTime = new Date();
|
||||
Date endTime = new Date();
|
||||
List<Object[]> sumDateMappings = new ArrayList<>();
|
||||
if (day == 7){
|
||||
startTime = DateUtil.getBeginDayOfWeek();
|
||||
endTime = DateUtil.getEndDayOfWeek();
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
|
||||
}else if (day == 30){
|
||||
startTime = DateUtil.getBeginDayOfMonth();
|
||||
endTime = DateUtil.getEndDayOfMonth();
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
|
||||
}else if (day == 360){
|
||||
startTime = DateUtil.getBeginDayOfYear();
|
||||
endTime = DateUtil.getDateOneYearAgo();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,DateUtil.getDate30DaysAgo(),DateUtil.getDayEnd());
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
//根据时间的营业额
|
||||
List<SumDateMapping> sumDateMappings = shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
|
||||
//根据时间商品排行
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime);
|
||||
// //根据时间商品排行
|
||||
// List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime);
|
||||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
map.put("productCount",tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple.get(1, BigDecimal.class));
|
||||
//商品销量排行前五
|
||||
List<ProductVO> list = new ArrayList<>();
|
||||
// for (Object[] o :objects) {
|
||||
// ProductVO productVO = new ProductVO();
|
||||
// productVO.setProductId((Integer) o[0]);
|
||||
// productVO.setProductName((String) o[1]);
|
||||
// productVO.setProductNum((BigDecimal)o[2]);
|
||||
// list.add(productVO);
|
||||
// }
|
||||
// list = list.stream()
|
||||
// .sorted(Comparator.comparing(ProductVO::getProductNum).reversed()) // 降序排序
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// map.put("totalProduct",list);
|
||||
//支付类型占比
|
||||
// List<CountPayTypeMapping> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString());
|
||||
// map.put("countPayType",countPayTypeMappings);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryProduct(Integer shopId, Integer day,Integer currentPage){
|
||||
//根据时间商品排行
|
||||
currentPage = (currentPage - 1) * 5;
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Date startTime ;
|
||||
Date endTime ;
|
||||
if (day == 7){
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 30){
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 360){
|
||||
startTime = DateUtil.getBeginDayOfYear();
|
||||
endTime = DateUtil.getEndDayOfYear();
|
||||
}else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime,currentPage);
|
||||
List<ProductVO> list = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
ProductVO productVO = new ProductVO();
|
||||
productVO.setProductId((Integer) o[0]);
|
||||
productVO.setProductName((String) o[1]);
|
||||
productVO.setProductNum((BigDecimal)o[2]);
|
||||
productVO.setAmount((BigDecimal)o[3]);
|
||||
list.add(productVO);
|
||||
}
|
||||
list = list.stream()
|
||||
.sorted(Comparator.comparing(ProductVO::getProductNum).reversed()) // 降序排序
|
||||
.collect(Collectors.toList());
|
||||
map.put("total",sumDateMappings);
|
||||
//汇总数据
|
||||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
map.put("productCount",tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple.get(1, BigDecimal.class));
|
||||
// List<Object[]> objects1 = shopUserDutyDetailRepository.searchByDayToAmount(shopId, startTime, endTime);
|
||||
map.put("totalProduct",list);
|
||||
//支付类型占比
|
||||
List<CountPayTypeMapping> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString());
|
||||
map.put("countPayType",countPayTypeMappings);
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryAmount(Integer shopId, Integer day){
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Date startTime ;
|
||||
Date endTime ;
|
||||
if (day == 7){
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 30){
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
|
||||
List<Object[]> objects = shopUserDutyRepository.sumByDate(shopId, startTime, endTime);
|
||||
//根据时间的销量
|
||||
List<SumDateVO> sumDateVOList = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
SumDateVO sumDateVO = new SumDateVO();
|
||||
sumDateVO.setAmount((BigDecimal) o[0]);
|
||||
sumDateVO.setTradeDay((String) o[1]);
|
||||
sumDateVOList.add(sumDateVO);
|
||||
}
|
||||
//填充日期
|
||||
Map<String, SumDateVO> dataMap = new HashMap<>();
|
||||
for (SumDateVO entry : sumDateVOList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigDecimal amount = entry.getAmount();
|
||||
dataMap.put(tradeDay, new SumDateVO(tradeDay, amount));
|
||||
}
|
||||
// 获取今天的日期
|
||||
LocalDate today = LocalDate.now();
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
// 转换为字符串
|
||||
List<SumDateVO> sumDateList = new ArrayList<>();
|
||||
for (int i = 0; i < day; i++) {
|
||||
LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
SumDateVO sumDateVO;
|
||||
// 检查数据Map中是否存在该日期的数据
|
||||
if (dataMap.containsKey(tradeDayString)) {
|
||||
sumDateVO = dataMap.get(tradeDayString);
|
||||
} else {
|
||||
// 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
sumDateVO = new SumDateVO(tradeDayString, BigDecimal.ZERO);
|
||||
}
|
||||
// 将SumDateVO对象添加到列表中
|
||||
sumDateList.add(sumDateVO);
|
||||
}
|
||||
map.put("total",sumDateList);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectSummaryToday(Integer shopId) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Tuple tuple = shopUserDutyRepository.sumByShopIdToday(shopId, DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
map.put("paymentsNumberToday", tuple.get(0, Long.class) == null?0L : tuple.get(0, Long.class));
|
||||
map.put("totalSalesToday", tuple.get(1, BigDecimal.class) == null? new BigDecimal("0") : tuple.get(1, BigDecimal.class));
|
||||
Tuple tuple1 = tbShopUserRepository.searchByCountToday(shopId.toString(), DateUtil.getTodayStartTimestamp(), DateUtil.getTodayEndTimestamp());
|
||||
map.put("userToday", tuple1.get(0, Long.class));
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryPayType(Integer shopId, Integer day){
|
||||
Long startTime ;
|
||||
Long endTime ;
|
||||
if (day == 7){
|
||||
startTime = DateUtil.getSevenDaysAgoInMilliseconds();
|
||||
endTime = DateUtil.getTodayEndTimestamp();
|
||||
}else if (day == 30){
|
||||
startTime = DateUtil.getThirtyDaysAgoInMilliseconds();
|
||||
endTime = DateUtil.getTodayEndTimestamp();
|
||||
}else if (day == 360){
|
||||
startTime = DateUtil.getBeginningOfYearInMilliseconds();
|
||||
endTime = DateUtil.getEndOfYearInMilliseconds();
|
||||
}else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
List<Object[]> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString(),startTime,endTime);
|
||||
List<CountPayTypeVO> countPayTypeVOList = new ArrayList<>();
|
||||
for (Object[] o :countPayTypeMappings) {
|
||||
CountPayTypeVO countPayTypeVO = new CountPayTypeVO();
|
||||
countPayTypeVO.setCount((BigInteger) o[0]);
|
||||
countPayTypeVO.setPayType(PayTypeEnum.getCodeByName((String) o[1]));
|
||||
countPayTypeVOList.add(countPayTypeVO);
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("countPayType",countPayTypeVOList);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
|||
}
|
||||
TbShopInfo byAccount = tbShopInfoRepository.findByAccount(resources.getAccount());
|
||||
User byUsername = userRepository.findByUsername(resources.getAccount());
|
||||
if (byAccount != null || byUsername.getId() != null){
|
||||
if (byAccount != null || byUsername != null){
|
||||
throw new BadRequestException("登录名已注册");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
public class CountPayTypeVO {
|
||||
//使用次数
|
||||
private BigInteger count;
|
||||
//日期
|
||||
private String payType;
|
||||
|
||||
public CountPayTypeVO() {
|
||||
|
||||
}
|
||||
|
||||
public BigInteger getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(BigInteger count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getPayType() {
|
||||
return payType;
|
||||
}
|
||||
|
||||
public void setPayType(String payType) {
|
||||
this.payType = payType;
|
||||
}
|
||||
|
||||
public CountPayTypeVO(BigInteger count, String payType) {
|
||||
this.count = count;
|
||||
this.payType = payType;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,15 @@ public class ProductVO {
|
|||
private String productName;
|
||||
|
||||
private BigDecimal productNum;
|
||||
private BigDecimal amount;
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Integer getProductId() {
|
||||
return productId;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class SumDateVO {
|
||||
private String tradeDay;
|
||||
private BigDecimal amount;
|
||||
|
||||
public SumDateVO() {
|
||||
|
||||
}
|
||||
|
||||
public String getTradeDay() {
|
||||
return tradeDay;
|
||||
}
|
||||
|
||||
public void setTradeDay(String tradeDay) {
|
||||
this.tradeDay = tradeDay;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public SumDateVO(String tradeDay, BigDecimal amount) {
|
||||
this.tradeDay = tradeDay;
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue