首页下半更改
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.chaozhanggui.system.cashierservice.dao;
|
||||
|
||||
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.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -36,7 +38,9 @@ public interface TbMerchantCouponMapper {
|
||||
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);
|
||||
/**
|
||||
* 统计总行数
|
||||
*
|
||||
|
||||
@@ -135,6 +135,7 @@ public class TbMerchantCoupon implements Serializable {
|
||||
private String merchantId;
|
||||
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,20 @@ public class HomeDto {
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 品类
|
||||
* 经度
|
||||
*/
|
||||
private String lat;
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String lng;
|
||||
/**
|
||||
* 品类 1.附近1Km
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 1.理我最近 2.销量优先 3.价格优先
|
||||
* 1.离我最近 2.销量优先 3.价格优先
|
||||
*/
|
||||
private Integer orderBy;
|
||||
|
||||
@@ -26,52 +34,4 @@ public class HomeDto {
|
||||
private Integer page;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class HomeVO {
|
||||
/**
|
||||
* 折扣
|
||||
*/
|
||||
private Float discount;
|
||||
private BigDecimal discount;
|
||||
/**
|
||||
* 共省金额
|
||||
*/
|
||||
@@ -164,11 +164,11 @@ public class HomeVO {
|
||||
this.salePrice = salePrice;
|
||||
}
|
||||
|
||||
public Float getDiscount() {
|
||||
public BigDecimal getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(Float discount) {
|
||||
public void setDiscount(BigDecimal discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,9 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,13 +57,23 @@ public class HomePageService {
|
||||
} else {
|
||||
beginNo = (homeDto.getPage() - 1) * homeDto.getSize();
|
||||
}
|
||||
//优惠卷
|
||||
List<TbMerchantCoupon> tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize());
|
||||
//经纬度(附近一km)
|
||||
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
|
||||
List<String> shopIds = new ArrayList<>();
|
||||
List<String> productIds = new ArrayList<>();
|
||||
List<Integer> productIdsInt = new ArrayList<>();
|
||||
for (TbMerchantCoupon coupon : tbMerchantCoupons) {
|
||||
for (CouAndShopVo coupon : tbMerchantCoupons) {
|
||||
shopIds.add(coupon.getShopId());
|
||||
productIds.add(coupon.getRelationIds());
|
||||
productIdsInt.add(Integer.valueOf(coupon.getRelationIds()));
|
||||
@@ -82,10 +90,9 @@ public class HomePageService {
|
||||
|
||||
//组装
|
||||
List<HomeVO> homeVOList = new ArrayList<>();
|
||||
for (TbMerchantCoupon o : tbMerchantCoupons) {
|
||||
for (CouAndShopVo o : tbMerchantCoupons) {
|
||||
HomeVO homeVO = new HomeVO();
|
||||
homeVO.setId(o.getId());
|
||||
homeVO.setDiscount(o.getRatio());
|
||||
for (TbShopInfo tbShopInfo : shopInfo.get()) {
|
||||
if (o.getShopId().equals(tbShopInfo.getId().toString())) {
|
||||
homeVO.setShopName(tbShopInfo.getShopName());
|
||||
@@ -104,18 +111,26 @@ public class HomePageService {
|
||||
}
|
||||
for (TbProduct tbProduct : product.get()) {
|
||||
if (o.getRelationIds().equals(tbProduct.getId().toString())) {
|
||||
homeVO.setProductName(tbProduct.getName());
|
||||
homeVO.setProductName(o.getTitle());
|
||||
homeVO.setImage(tbProduct.getCoverImg());
|
||||
homeVO.setProductId(tbProduct.getId());
|
||||
}
|
||||
}
|
||||
for (TbProductSku tbProductSku : productSku.get()) {
|
||||
if (o.getRelationIds().equals(tbProductSku.getProductId())) {
|
||||
homeVO.setOriginPrice(tbProductSku.getSalePrice());
|
||||
homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber()));
|
||||
Float discount = homeVO.getDiscount();
|
||||
BigDecimal discountDecimal = new BigDecimal(discount);
|
||||
homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1")))));
|
||||
//原价
|
||||
if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO)==0){
|
||||
homeVO.setOriginPrice(BigDecimal.ZERO);
|
||||
homeVO.setDiscount(BigDecimal.ZERO);
|
||||
}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()));
|
||||
}
|
||||
}
|
||||
@@ -161,7 +176,7 @@ public class HomePageService {
|
||||
BigDecimal originPrice = o.getOriginPrice();
|
||||
if (originPrice.compareTo(BigDecimal.ZERO) != 0) {
|
||||
BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN);
|
||||
o.setDiscount(multiply.floatValue());
|
||||
o.setDiscount(multiply);
|
||||
} else {
|
||||
o.setDiscount(null);
|
||||
}
|
||||
|
||||
@@ -43,12 +43,14 @@ public class LocationUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param longitude 经度
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度 108
|
||||
* @param latitude 纬度 34
|
||||
* @param distanceInKm 范围(千米)
|
||||
* 大于左下的经度lat,小于右上的经度lat
|
||||
* 大于左下的纬度lng,小于右上的纬度lng
|
||||
* return Map<String, double[]> stringMap
|
||||
* 右顶点 double[] leftTopPoints = stringMap.get("rightTopPoint");
|
||||
* 左顶点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
* 右上顶点 double[] leftTopPoints = stringMap.get("rightTopPoint");
|
||||
* 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
*/
|
||||
public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, double distanceInKm) {
|
||||
Map<String, double[]> squareMap = new HashMap<>();
|
||||
@@ -67,31 +69,38 @@ public class LocationUtils {
|
||||
double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2};
|
||||
squareMap.put("rightTopPoint", rightTopPoint);
|
||||
squareMap.put("leftBottomPoint", leftBottomPoint);
|
||||
// 打印结果
|
||||
// System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]);
|
||||
// System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]);
|
||||
// 打印结果rightTopPoint[0]纬度lng,rightTopPoint[1]经度lat
|
||||
System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]);
|
||||
System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]);
|
||||
return squareMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将角度转化为弧度
|
||||
*/
|
||||
public static double radians(double d) {
|
||||
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) {
|
||||
// Map<String, double[]> stringMap = returnLLSquarePoint(108.954398, 34.308687, 1);
|
||||
// double[] leftTopPoints = stringMap.get("rightTopPoint");
|
||||
// double[] leftBottomPoints = stringMap.get("leftBottomPoint");
|
||||
// Map<String, double[]> stringMap = returnLLSquarePoint(34.342849, 109.019993, 1);
|
||||
//
|
||||
// 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");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -268,13 +268,45 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="queryAllByPage" resultType="com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon">
|
||||
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
|
||||
from tb_merchant_coupon
|
||||
where class_type ='product'
|
||||
AND ratio IS NOT NULL
|
||||
limit #{page}, #{size}
|
||||
<select id="queryAllByPage" resultType="com.chaozhanggui.system.cashierservice.entity.vo.CouAndShopVo">
|
||||
SELECT
|
||||
cou.id as id,
|
||||
cou.title as title,
|
||||
cou.shop_id as shopId,
|
||||
cou.amount as amount,
|
||||
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>
|
||||
|
||||
<!--新增所有列-->
|
||||
|
||||
Reference in New Issue
Block a user