首页下半更改

This commit is contained in:
liuyingfang
2024-04-15 10:15:16 +08:00
parent d7dfeee159
commit 46cd954abf
8 changed files with 157 additions and 95 deletions

View File

@@ -1,6 +1,8 @@
package com.chaozhanggui.system.cashierservice.dao; package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon; import com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon;
import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
import com.chaozhanggui.system.cashierservice.entity.vo.CouAndShopVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -36,7 +38,9 @@ public interface TbMerchantCouponMapper {
List<TbMerchantCoupon> queryAllByLimit(TbMerchantCoupon tbMerchantCoupon, @Param("pageable") Pageable pageable); List<TbMerchantCoupon> queryAllByLimit(TbMerchantCoupon tbMerchantCoupon, @Param("pageable") Pageable pageable);
List<TbMerchantCoupon> queryAllByPage(@Param("page")Integer page, @Param("size")Integer size); List<CouAndShopVo> queryAllByPage(@Param("pageable")Integer page, @Param("sizeable")Integer size, @Param("rightTopLng") Double rightTopLng,
@Param("rightTopLat")Double rightTopLat, @Param("leftBottomLng")Double leftBottomLng, @Param("leftBottomLat")Double leftBottomLat,
@Param("cities")String cities, @Param("order")String order,@Param("lng")String lng,@Param("lat")String lat);
/** /**
* 统计总行数 * 统计总行数
* *

View File

@@ -135,6 +135,7 @@ public class TbMerchantCoupon implements Serializable {
private String merchantId; private String merchantId;
public Integer getId() { public Integer getId() {
return id; return id;
} }

View File

@@ -12,12 +12,20 @@ public class HomeDto {
*/ */
private String address; private String address;
/** /**
* 品类 * 经度
*/
private String lat;
/**
* 纬度
*/
private String lng;
/**
* 品类 1.附近1Km
*/ */
private String type; private String type;
/** /**
* 1.我最近 2.销量优先 3.价格优先 * 1.我最近 2.销量优先 3.价格优先
*/ */
private Integer orderBy; private Integer orderBy;
@@ -26,52 +34,4 @@ public class HomeDto {
private Integer page; private Integer page;
private Integer size; private Integer size;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
public Integer getOther() {
return other;
}
public void setOther(Integer other) {
this.other = other;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
} }

View File

@@ -0,0 +1,41 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import lombok.Data;
/**
* @author lyf
*/
@Data
public class CouAndShopVo {
/**
* 自增
*/
private Integer id;
/**
* 优惠券名称
*/
private String title;
private String shopId;
/**
* 优惠金额
*/
private Double amount;
/**
* 发放数量
*/
private Integer number;
/**
* 折扣 ,一位小数
*/
private Float ratio;
/**
* 关联商品Id
*/
private String relationIds;
private String shopName;
private String logo;
}

View File

@@ -36,7 +36,7 @@ public class HomeVO {
/** /**
* 折扣 * 折扣
*/ */
private Float discount; private BigDecimal discount;
/** /**
* 共省金额 * 共省金额
*/ */
@@ -164,11 +164,11 @@ public class HomeVO {
this.salePrice = salePrice; this.salePrice = salePrice;
} }
public Float getDiscount() { public BigDecimal getDiscount() {
return discount; return discount;
} }
public void setDiscount(Float discount) { public void setDiscount(BigDecimal discount) {
this.discount = discount; this.discount = discount;
} }

View File

@@ -19,11 +19,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -59,13 +57,23 @@ public class HomePageService {
} else { } else {
beginNo = (homeDto.getPage() - 1) * homeDto.getSize(); beginNo = (homeDto.getPage() - 1) * homeDto.getSize();
} }
//优惠卷 //经纬度(附近一km)
List<TbMerchantCoupon> tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize()); Map<String, double[]> topAndBottomMap = new HashMap<>();
List<CouAndShopVo> tbMerchantCoupons = new ArrayList<>();
if (homeDto.getOther() != null && homeDto.getOther() == 1){
topAndBottomMap = LocationUtils.returnLLSquarePoint(Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), 1);
tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), topAndBottomMap.get("rightTopPoint")[0],topAndBottomMap.get("rightTopPoint")[1],
topAndBottomMap.get("leftBottomPoint")[0],topAndBottomMap.get("leftBottomPoint")[1],homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat());
}else {
tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), null,null,null,null,
homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat());
}
//统计shopId以及productId //统计shopId以及productId
List<String> shopIds = new ArrayList<>(); List<String> shopIds = new ArrayList<>();
List<String> productIds = new ArrayList<>(); List<String> productIds = new ArrayList<>();
List<Integer> productIdsInt = new ArrayList<>(); List<Integer> productIdsInt = new ArrayList<>();
for (TbMerchantCoupon coupon : tbMerchantCoupons) { for (CouAndShopVo coupon : tbMerchantCoupons) {
shopIds.add(coupon.getShopId()); shopIds.add(coupon.getShopId());
productIds.add(coupon.getRelationIds()); productIds.add(coupon.getRelationIds());
productIdsInt.add(Integer.valueOf(coupon.getRelationIds())); productIdsInt.add(Integer.valueOf(coupon.getRelationIds()));
@@ -82,10 +90,9 @@ public class HomePageService {
//组装 //组装
List<HomeVO> homeVOList = new ArrayList<>(); List<HomeVO> homeVOList = new ArrayList<>();
for (TbMerchantCoupon o : tbMerchantCoupons) { for (CouAndShopVo o : tbMerchantCoupons) {
HomeVO homeVO = new HomeVO(); HomeVO homeVO = new HomeVO();
homeVO.setId(o.getId()); homeVO.setId(o.getId());
homeVO.setDiscount(o.getRatio());
for (TbShopInfo tbShopInfo : shopInfo.get()) { for (TbShopInfo tbShopInfo : shopInfo.get()) {
if (o.getShopId().equals(tbShopInfo.getId().toString())) { if (o.getShopId().equals(tbShopInfo.getId().toString())) {
homeVO.setShopName(tbShopInfo.getShopName()); homeVO.setShopName(tbShopInfo.getShopName());
@@ -104,18 +111,26 @@ public class HomePageService {
} }
for (TbProduct tbProduct : product.get()) { for (TbProduct tbProduct : product.get()) {
if (o.getRelationIds().equals(tbProduct.getId().toString())) { if (o.getRelationIds().equals(tbProduct.getId().toString())) {
homeVO.setProductName(tbProduct.getName()); homeVO.setProductName(o.getTitle());
homeVO.setImage(tbProduct.getCoverImg()); homeVO.setImage(tbProduct.getCoverImg());
homeVO.setProductId(tbProduct.getId()); homeVO.setProductId(tbProduct.getId());
} }
} }
for (TbProductSku tbProductSku : productSku.get()) { for (TbProductSku tbProductSku : productSku.get()) {
if (o.getRelationIds().equals(tbProductSku.getProductId())) { if (o.getRelationIds().equals(tbProductSku.getProductId())) {
homeVO.setOriginPrice(tbProductSku.getSalePrice()); //原价
homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber())); if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO)==0){
Float discount = homeVO.getDiscount(); homeVO.setOriginPrice(BigDecimal.ZERO);
BigDecimal discountDecimal = new BigDecimal(discount); homeVO.setDiscount(BigDecimal.ZERO);
homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1"))))); }else {
homeVO.setOriginPrice(tbProductSku.getSalePrice());
homeVO.setDiscount(new BigDecimal(o.getAmount()).divide(tbProductSku.getSalePrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN));
}
//销量
homeVO.setRealSalesNumber(new BigDecimal(o.getNumber()));
//现价
homeVO.setSalePrice(new BigDecimal(o.getAmount().toString()));
// 共省金额
homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice())); homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice()));
} }
} }
@@ -161,7 +176,7 @@ public class HomePageService {
BigDecimal originPrice = o.getOriginPrice(); BigDecimal originPrice = o.getOriginPrice();
if (originPrice.compareTo(BigDecimal.ZERO) != 0) { if (originPrice.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN); BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN);
o.setDiscount(multiply.floatValue()); o.setDiscount(multiply);
} else { } else {
o.setDiscount(null); o.setDiscount(null);
} }

View File

@@ -43,12 +43,14 @@ public class LocationUtils {
} }
/** /**
* @param longitude 经度 * @param longitude 经度 108
* @param latitude 纬度 * @param latitude 纬度 34
* @param distanceInKm 范围(千米) * @param distanceInKm 范围(千米)
* 大于左下的经度lat小于右上的经度lat
* 大于左下的纬度lng小于右上的纬度lng
* return Map<String, double[]> stringMap * return Map<String, double[]> stringMap
* 右顶点 double[] leftTopPoints = stringMap.get("rightTopPoint"); * 右顶点 double[] leftTopPoints = stringMap.get("rightTopPoint");
* 左点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); * 左点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
*/ */
public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, double distanceInKm) { public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, double distanceInKm) {
Map<String, double[]> squareMap = new HashMap<>(); Map<String, double[]> squareMap = new HashMap<>();
@@ -67,31 +69,38 @@ public class LocationUtils {
double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2}; double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2};
squareMap.put("rightTopPoint", rightTopPoint); squareMap.put("rightTopPoint", rightTopPoint);
squareMap.put("leftBottomPoint", leftBottomPoint); squareMap.put("leftBottomPoint", leftBottomPoint);
// 打印结果 // 打印结果rightTopPoint[0]纬度lngrightTopPoint[1]经度lat
// System.out.println("rightTop" + rightTopPoint[0] + "======" + rightTopPoint[1]); System.out.println("rightTop" + rightTopPoint[0] + "======" + rightTopPoint[1]);
// System.out.println("leftBottom" + leftBottomPoint[0] + "======" + leftBottomPoint[1]); System.out.println("leftBottom" + leftBottomPoint[0] + "======" + leftBottomPoint[1]);
return squareMap; return squareMap;
} }
/** /**
* 将角度转化为弧度 * 将角度转化为弧度
*/ */
public static double radians(double d) { public static double radians(double d) {
return d * Math.PI / 180.0; return d * Math.PI / 180.0;
} }
//1KM
public static void main(String[] args) {
Map<String, double[]> stringMap = returnLLSquarePoint(108.954398, 34.308687, 1);
double[] leftTopPoints = stringMap.get("rightTopPoint");
double[] leftBottomPoints = stringMap.get("leftBottomPoint");
double lat2 = 108.975418;
double lon2 = 34.280890;
double distance3 = getDistanceFrom2LngLat(109.019993, 34.342849, lat2, lon2);
System.out.println(distance3);
// 计算距离
double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2);
double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2);
System.out.println("Distance between the two points is: " + distance1 + " km");
System.out.println("Distance between the two points is: " + distance2 + " km");
}
// public static void main(String[] args) { // public static void main(String[] args) {
// Map<String, double[]> stringMap = returnLLSquarePoint(108.954398, 34.308687, 1); // Map<String, double[]> stringMap = returnLLSquarePoint(34.342849, 109.019993, 1);
// double[] leftTopPoints = stringMap.get("rightTopPoint");
// double[] leftBottomPoints = stringMap.get("leftBottomPoint");
// //
// double lat2 = 108.954398;
// double lon2 = 34.308687;
//
// // 计算距离
// double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2);
// double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2);
// System.out.println("Distance between the two points is: " + distance1 + " km");
// System.out.println("Distance between the two points is: " + distance2 + " km");
// } // }
} }

View File

@@ -268,13 +268,45 @@
</if> </if>
</where> </where>
</select> </select>
<select id="queryAllByPage" resultType="com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon"> <select id="queryAllByPage" resultType="com.chaozhanggui.system.cashierservice.entity.vo.CouAndShopVo">
select SELECT
id, status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id cou.id as id,
from tb_merchant_coupon cou.title as title,
where class_type ='product' cou.shop_id as shopId,
AND ratio IS NOT NULL cou.amount as amount,
limit #{page}, #{size} cou.number as number,
cou.ratio as ratio,
cou.relation_ids as relationIds,
info.shop_name as shopName,
info.logo
FROM
tb_merchant_coupon as cou
LEFT JOIN tb_shop_info as info ON cou.shop_id = info.id
<where>
cou.class_type = 'product'
AND cou.`status` = 1
AND info.cities =#{cities}
<if test="rightTopLng != null and rightTopLng != '' and leftBottomLng != null and leftBottomLng != ''">
AND info.lng BETWEEN #{leftBottomLng} AND #{rightTopLng}
AND info.lat BETWEEN #{leftBottomLat} AND #{rightTopLat}
</if>
</where>
<choose>
<when test="order == '1'">
ORDER BY (ABS(info.lat - #{lat}) + ABS(info.lng - #{lng})) ASC
</when>
<when test="order == '2'">
ORDER BY cou.number ASC
</when>
<when test="order == '3'">
ORDER BY cou.amount ASC
</when>
<otherwise>
ORDER BY cou.id ASC
</otherwise>
</choose>
limit #{pageable}, #{sizeable}
</select> </select>
<!--新增所有列--> <!--新增所有列-->