后台首页新增统计,JPA关联优化,积分抵扣修复

This commit is contained in:
hupeng
2020-04-04 14:05:38 +08:00
parent cc1a6b6de8
commit d0a8cd1c7a
15 changed files with 223 additions and 28 deletions

View File

@ -1270,7 +1270,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
Double integralRatio = Double.valueOf(cacheDTO.getOther().getIntegralRatio());
if(totalPrice >= integralFull){
Double userIntegral = userInfo.getIntegral().doubleValue();
if(userIntegral >= integralMax) userIntegral = integralMax;
if(integralMax > 0 && userIntegral >= integralMax) userIntegral = integralMax;
deductionPrice = NumberUtil.mul(userIntegral, integralRatio);
if(deductionPrice < payPrice){
payPrice = NumberUtil.sub(payPrice.doubleValue(),deductionPrice);

View File

@ -143,7 +143,6 @@ public class StoreProductController extends BaseController {
if(!userType.equals(AppFromEnum.ROUNTINE.getValue())) {
userType = AppFromEnum.H5.getValue();
}
from = "app";
//app类型
if(StrUtil.isNotBlank(from) && AppFromEnum.APP.getValue().equals(from)){
String name = id+"_"+uid + "_"+from+"_product_detail_wap.jpg";

View File

@ -0,0 +1,87 @@
package co.yixiang.modules.shop.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
/**
* @author xwb
* @date 2020-04-02
*/
@Entity
@Data
@Table(name="yx_store_cart")
public class YxStoreCart implements Serializable {
/** 购物车表ID */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/** 用户ID */
@Column(name = "uid",nullable = false)
@NotNull
private Integer uid;
/** 类型 */
@Column(name = "type",nullable = false)
@NotBlank
private String type;
/** 商品ID */
@Column(name = "product_id",nullable = false)
@NotNull
private Integer productId;
/** 商品属性 */
@Column(name = "product_attr_unique",nullable = false)
@NotBlank
private String productAttrUnique;
/** 商品数量 */
@Column(name = "cart_num",nullable = false)
@NotNull
private Integer cartNum;
/** 添加时间 */
@Column(name = "add_time",nullable = false)
@NotNull
private Integer addTime;
/** 0 = 未购买 1 = 已购买 */
@Column(name = "is_pay",nullable = false)
@NotNull
private Integer isPay;
/** 是否删除 */
@Column(name = "is_del",nullable = false)
@NotNull
private Integer isDel;
/** 是否为立即购买 */
@Column(name = "is_new",nullable = false)
@NotNull
private Integer isNew;
/** 拼团id */
@Column(name = "combination_id")
private Integer combinationId;
/** 秒杀产品ID */
@Column(name = "seckill_id",nullable = false)
@NotNull
private Integer seckillId;
/** 砍价id */
@Column(name = "bargain_id",nullable = false)
@NotNull
private Integer bargainId;
public void copy(YxStoreCart source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -59,6 +59,7 @@ public class YxStoreProduct implements Serializable {
@Column(name = "bar_code",nullable = false)
private String barCode;
// private Integer cateId;
@ManyToOne(fetch=FetchType.LAZY,optional = false)
@JoinColumn(name = "cate_id")

View File

@ -0,0 +1,21 @@
package co.yixiang.modules.shop.repository;
import co.yixiang.modules.shop.domain.YxStoreCart;
import co.yixiang.modules.shop.service.dto.CountDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @author xwb
* @date 2020-04-02
*/
public interface YxStoreCartRepository extends JpaRepository<YxStoreCart, Long>, JpaSpecificationExecutor {
@Query(value ="SELECT t.cate_name as catename from yx_store_cart c " +
"LEFT JOIN yx_store_product p on c.product_id = p.id " +
"LEFT JOIN yx_store_category t on p.cate_id = t.id " +
"WHERE c.is_pay = 1",nativeQuery = true)
List<CountDto> findCateName();
}

View File

@ -25,6 +25,10 @@ public interface YxStoreOrderRepository extends JpaRepository<YxStoreOrder, Inte
"where refund_status=0 and is_del=0 and paid=1 and pay_time >= ?1",nativeQuery = true)
double sumPrice(Integer time);
@Query(value = "select IFNULL(sum(pay_price),0) from yx_store_order " +
"where refund_status=0 and is_del=0 and paid=1",nativeQuery = true)
double sumTotalPrice();
@Query(value = "select IFNULL(sum(pay_price),0) from yx_store_order " +
"where refund_status=0 and is_del=0 and paid=1 and pay_time >= ?1 and pay_time < ?2",nativeQuery = true)
double sumTPrice(Integer timeO, Integer timeT);

View File

@ -16,10 +16,7 @@ import co.yixiang.modules.activity.service.dto.YxStorePinkDTO;
import co.yixiang.modules.shop.domain.YxStoreOrder;
import co.yixiang.modules.shop.domain.YxStoreOrderStatus;
import co.yixiang.modules.shop.service.*;
import co.yixiang.modules.shop.service.dto.YxExpressDTO;
import co.yixiang.modules.shop.service.dto.YxStoreOrderDTO;
import co.yixiang.modules.shop.service.dto.YxStoreOrderQueryCriteria;
import co.yixiang.modules.shop.service.dto.YxWechatUserDTO;
import co.yixiang.modules.shop.service.dto.*;
import co.yixiang.modules.shop.service.param.ExpressParam;
import co.yixiang.mp.service.WxMpTemplateMessageService;
import co.yixiang.mp.service.YxTemplateService;
@ -74,6 +71,16 @@ public class StoreOrderController {
this.expressService = expressService;
}
/**@Valid
* 根据商品分类统计订单占比
*/
@GetMapping("/yxStoreOrder/orderCount")
@ApiOperation(value = "根据商品分类统计订单占比",notes = "根据商品分类统计订单占比",response = ExpressParam.class)
public ResponseEntity orderCount(){
OrderCountDto orderCountDto = yxStoreOrderService.getOrderCount();
return new ResponseEntity(orderCountDto, HttpStatus.OK);
}
@GetMapping(value = "/data/count")
@AnonymousAccess
public ResponseEntity getCount() {

View File

@ -1,6 +1,7 @@
package co.yixiang.modules.shop.service;
import co.yixiang.modules.shop.domain.YxStoreOrder;
import co.yixiang.modules.shop.service.dto.OrderCountDto;
import co.yixiang.modules.shop.service.dto.OrderTimeDataDTO;
import co.yixiang.modules.shop.service.dto.YxStoreOrderDTO;
import co.yixiang.modules.shop.service.dto.YxStoreOrderQueryCriteria;
@ -15,6 +16,9 @@ import java.util.Map;
*/
//@CacheConfig(cacheNames = "yxStoreOrder")
public interface YxStoreOrderService {
OrderCountDto getOrderCount();
OrderTimeDataDTO getOrderTimeData();
Map<String,Object> chartCount();

View File

@ -0,0 +1,9 @@
package co.yixiang.modules.shop.service.dto;
import lombok.Data;
//@Data
public interface CountDto {
String getCatename();
}

View File

@ -0,0 +1,21 @@
package co.yixiang.modules.shop.service.dto;
import lombok.Data;
import java.util.List;
@Data
public class OrderCountDto {
private List<String> column;
private List<OrderCountData> orderCountDatas;
@Data
public static class OrderCountData{
private String name;
private Integer value;
}
}

View File

@ -20,4 +20,9 @@ public class OrderTimeDataDTO implements Serializable {
private Integer lastWeekCount;//上周
private Double lastWeekPrice; //上周
private Long userCount;
private Long orderCount;
private Double priceCount;
private Long goodsCount;
}

View File

@ -3,6 +3,7 @@ package co.yixiang.modules.shop.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import co.yixiang.enums.OrderInfoEnum;
import co.yixiang.exception.BadRequestException;
import co.yixiang.exception.EntityExistException;
@ -12,9 +13,7 @@ import co.yixiang.modules.shop.domain.StoreOrderCartInfo;
import co.yixiang.modules.shop.domain.YxStoreOrder;
import co.yixiang.modules.shop.domain.YxStoreOrderStatus;
import co.yixiang.modules.shop.domain.YxUserBill;
import co.yixiang.modules.shop.repository.YxStoreOrderCartInfoRepository;
import co.yixiang.modules.shop.repository.YxStoreOrderRepository;
import co.yixiang.modules.shop.repository.YxUserRepository;
import co.yixiang.modules.shop.repository.*;
import co.yixiang.modules.shop.service.*;
import co.yixiang.modules.shop.service.dto.*;
import co.yixiang.modules.shop.service.mapper.YxStoreOrderMapper;
@ -48,6 +47,8 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
private final YxStoreOrderCartInfoRepository yxStoreOrderCartInfoRepository;
private final YxUserRepository userRepository;
private final YxStorePinkRepository storePinkRepository;
private final YxStoreProductRepository storeProductRepository;
private final YxStoreCartRepository yxStoreCartRepository;
private final YxStoreOrderMapper yxStoreOrderMapper;
@ -60,8 +61,8 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
public YxStoreOrderServiceImpl(YxStoreOrderRepository yxStoreOrderRepository, YxStoreOrderCartInfoRepository yxStoreOrderCartInfoRepository, YxUserRepository userRepository,
YxStorePinkRepository storePinkRepository, YxStoreOrderMapper yxStoreOrderMapper, YxUserBillService yxUserBillService,
YxStoreOrderStatusService yxStoreOrderStatusService, YxSystemStoreService systemStoreService,
YxUserService userService, YxPayService payService, YxMiniPayService miniPayService) {
YxStoreOrderStatusService yxStoreOrderStatusService, YxSystemStoreService systemStoreService,YxStoreCartRepository yxStoreCartRepository,
YxUserService userService, YxPayService payService, YxMiniPayService miniPayService,YxStoreProductRepository storeProductRepository) {
this.yxStoreOrderRepository = yxStoreOrderRepository;
this.yxStoreOrderCartInfoRepository = yxStoreOrderCartInfoRepository;
this.userRepository = userRepository;
@ -73,6 +74,39 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
this.payService = payService;
this.miniPayService = miniPayService;
this.systemStoreService = systemStoreService;
this.storeProductRepository = storeProductRepository;
this.yxStoreCartRepository = yxStoreCartRepository;
}
@Override
public OrderCountDto getOrderCount() {
//获取所有订单转态为已支付的
List<CountDto> nameList = yxStoreCartRepository.findCateName();
System.out.println("nameList:"+nameList);
Map<String,Integer> childrenMap = new HashMap<>();
nameList.forEach(i ->{
if(i != null) {
if(childrenMap.containsKey(i.getCatename())) {
childrenMap.put(i.getCatename(), childrenMap.get(i.getCatename())+1);
}else {
childrenMap.put(i.getCatename(), 1);
}
}
});
List<OrderCountDto.OrderCountData> list = new ArrayList<>();
List<String> columns = new ArrayList<>();
childrenMap.forEach((k,v) ->{
OrderCountDto.OrderCountData orderCountData = new OrderCountDto.OrderCountData();
orderCountData.setName(k);
orderCountData.setValue(v);
columns.add(k);
list.add(orderCountData);
});
OrderCountDto orderCountDto = new OrderCountDto();
orderCountDto.setColumn(columns);
orderCountDto.setOrderCountDatas(list);
return orderCountDto;
}
@Override
@ -86,17 +120,22 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService {
OrderTimeDataDTO orderTimeDataDTO = new OrderTimeDataDTO();
orderTimeDataDTO.setTodayCount(yxStoreOrderRepository.countByPayTimeGreaterThanEqual(today));
orderTimeDataDTO.setTodayPrice(yxStoreOrderRepository.sumPrice(today));
//orderTimeDataDTO.setTodayPrice(yxStoreOrderRepository.sumPrice(today));
orderTimeDataDTO.setProCount(yxStoreOrderRepository
.countByPayTimeLessThanAndPayTimeGreaterThanEqual(today,yesterday));
orderTimeDataDTO.setProPrice(yxStoreOrderRepository.sumTPrice(today,yesterday));
//orderTimeDataDTO.setProPrice(yxStoreOrderRepository.sumTPrice(today,yesterday));
orderTimeDataDTO.setLastWeekCount(yxStoreOrderRepository.countByPayTimeGreaterThanEqual(lastWeek));
orderTimeDataDTO.setLastWeekPrice(yxStoreOrderRepository.sumPrice(lastWeek));
//orderTimeDataDTO.setLastWeekPrice(yxStoreOrderRepository.sumPrice(lastWeek));
orderTimeDataDTO.setMonthCount(yxStoreOrderRepository.countByPayTimeGreaterThanEqual(nowMonth));
orderTimeDataDTO.setMonthPrice(yxStoreOrderRepository.sumPrice(nowMonth));
//orderTimeDataDTO.setMonthPrice(yxStoreOrderRepository.sumPrice(nowMonth));
orderTimeDataDTO.setUserCount(userRepository.count());
orderTimeDataDTO.setOrderCount(yxStoreOrderRepository.count());
orderTimeDataDTO.setPriceCount(yxStoreOrderRepository.sumTotalPrice());
orderTimeDataDTO.setGoodsCount(storeProductRepository.count());
return orderTimeDataDTO;
}

View File

@ -31,15 +31,13 @@ public class YxStoreProductReplyServiceImpl implements YxStoreProductReplyServic
private final YxStoreProductReplyMapper yxStoreProductReplyMapper;
private final YxUserService userService;
private final YxStoreProductService productService;
public YxStoreProductReplyServiceImpl(YxStoreProductReplyRepository yxStoreProductReplyRepository, YxStoreProductReplyMapper yxStoreProductReplyMapper,
YxUserService userService, YxStoreProductService productService) {
public YxStoreProductReplyServiceImpl(YxStoreProductReplyRepository yxStoreProductReplyRepository,
YxStoreProductReplyMapper yxStoreProductReplyMapper) {
this.yxStoreProductReplyRepository = yxStoreProductReplyRepository;
this.yxStoreProductReplyMapper = yxStoreProductReplyMapper;
this.userService = userService;
this.productService = productService;
}
@Override

View File

@ -38,18 +38,16 @@ import java.util.stream.Collectors;
public class YxStoreProductServiceImpl implements YxStoreProductService {
private final YxStoreProductRepository yxStoreProductRepository;
private final YxStoreCategoryRepository yxStoreCategoryRepository;
private final YxStoreProductAttrRepository yxStoreProductAttrRepository;
private final YxStoreProductAttrValueRepository yxStoreProductAttrValueRepository;
private final YxStoreProductAttrResultRepository yxStoreProductAttrResultRepository;
private final YxStoreProductMapper yxStoreProductMapper;
public YxStoreProductServiceImpl(YxStoreProductRepository yxStoreProductRepository, YxStoreCategoryRepository yxStoreCategoryRepository,
public YxStoreProductServiceImpl(YxStoreProductRepository yxStoreProductRepository,
YxStoreProductAttrRepository yxStoreProductAttrRepository, YxStoreProductAttrValueRepository yxStoreProductAttrValueRepository,
YxStoreProductAttrResultRepository yxStoreProductAttrResultRepository, YxStoreProductMapper yxStoreProductMapper) {
this.yxStoreProductRepository = yxStoreProductRepository;
this.yxStoreCategoryRepository = yxStoreCategoryRepository;
this.yxStoreProductAttrRepository = yxStoreProductAttrRepository;
this.yxStoreProductAttrValueRepository = yxStoreProductAttrValueRepository;
this.yxStoreProductAttrResultRepository = yxStoreProductAttrResultRepository;

View File

@ -37,10 +37,12 @@ spring:
#配置 Jpa
jpa:
properties:
hibernate:
# 生产环境设置成 none避免程序运行时自动更新数据库结构
ddl-auto: none
show-sql: true
ddl_auto: none
show_sql: true
format_sql: true
redis:
#数据库索引