|
@@ -1,22 +1,23 @@
|
|
package com.iotechn.unimall.admin.api.tourism.impl;
|
|
package com.iotechn.unimall.admin.api.tourism.impl;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import com.iotechn.unimall.app.api.user.UserService;
|
|
|
|
-import com.iotechn.unimall.data.domain.NoticeMessageInfo;
|
|
|
|
-import com.iotechn.unimall.data.mapper.NoticeMessageInfoMapper;
|
|
|
|
|
|
+import com.iotechn.unimall.admin.api.tourism.IFoodInfoService;
|
|
|
|
+import com.iotechn.unimall.data.domain.*;
|
|
|
|
+import com.iotechn.unimall.data.mapper.*;
|
|
|
|
+import com.iotechn.unimall.data.util.EntCoordUtil;
|
|
import org.apache.ibatis.session.RowBounds;
|
|
import org.apache.ibatis.session.RowBounds;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
import com.iotechn.unimall.core.exception.ServiceException;
|
|
import com.iotechn.unimall.core.exception.ServiceException;
|
|
import com.iotechn.unimall.data.util.ExcelUtil;
|
|
import com.iotechn.unimall.data.util.ExcelUtil;
|
|
-import com.iotechn.unimall.data.mapper.FoodInfoMapper;
|
|
|
|
-import com.iotechn.unimall.data.domain.FoodInfo;
|
|
|
|
-import com.iotechn.unimall.admin.api.tourism.IFoodInfoService;
|
|
|
|
import com.iotechn.unimall.data.model.Page;
|
|
import com.iotechn.unimall.data.model.Page;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -28,14 +29,24 @@ import org.springframework.transaction.annotation.Transactional;
|
|
* @date 2023-05-26
|
|
* @date 2023-05-26
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-public class FoodInfoServiceImpl implements IFoodInfoService{
|
|
|
|
|
|
+public class FoodInfoServiceImpl implements IFoodInfoService {
|
|
@Autowired
|
|
@Autowired
|
|
private FoodInfoMapper foodInfoMapper;
|
|
private FoodInfoMapper foodInfoMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private NoticeMessageInfoMapper noticeMessageInfoMapper;
|
|
private NoticeMessageInfoMapper noticeMessageInfoMapper;
|
|
@Autowired
|
|
@Autowired
|
|
- private UserService userService;
|
|
|
|
-
|
|
|
|
|
|
+ private DishClassifyInfoMapper dishClassifyInfoMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FoodDishesInfoMapper foodDishesInfoMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FoodGroupInfoMapper foodGroupInfoMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FoodGroupOrderInfoMapper foodGroupOrderInfoMapper;
|
|
|
|
+ /**
|
|
|
|
+ * 地球半径,单位 km
|
|
|
|
+ */
|
|
|
|
+ private static final double EARTH_RADIUS = 6378.137;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Boolean add(FoodInfo foodInfo) throws ServiceException {
|
|
public Boolean add(FoodInfo foodInfo) throws ServiceException {
|
|
// userService.checkVerifyCode(foodInfo.getContactsPhone(), foodInfo.getVerifyCode());
|
|
// userService.checkVerifyCode(foodInfo.getContactsPhone(), foodInfo.getVerifyCode());
|
|
@@ -126,10 +137,112 @@ public class FoodInfoServiceImpl implements IFoodInfoService{
|
|
}
|
|
}
|
|
wrapper.eq("delete_flag", 0);
|
|
wrapper.eq("delete_flag", 0);
|
|
List<FoodInfo> list = foodInfoMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
|
|
List<FoodInfo> list = foodInfoMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)){
|
|
|
|
+ for (FoodInfo foodInfo:list) {
|
|
|
|
+ Integer displaysNum=0;
|
|
|
|
+ //查询店铺菜品分类
|
|
|
|
+ List<DishClassifyInfo> dishClassifyInfoList = dishClassifyInfoMapper.selectList(new EntityWrapper<DishClassifyInfo>()
|
|
|
|
+ .eq("food_id",foodInfo.getId())
|
|
|
|
+ .orderBy("top_marking",false));
|
|
|
|
+ if (!CollectionUtils.isEmpty(dishClassifyInfoList)){
|
|
|
|
+ for (DishClassifyInfo dishClassifyInfo:dishClassifyInfoList){
|
|
|
|
+ List<FoodDishesInfo> foodDishesInfoList = foodDishesInfoMapper.selectList(new EntityWrapper<FoodDishesInfo>()
|
|
|
|
+ .eq("food_id",foodInfo.getId())
|
|
|
|
+ .eq("classify",dishClassifyInfo.getClassifyName())
|
|
|
|
+ .orderBy("top_marking",false).orderBy("gmt_create",false));
|
|
|
|
+ if (!CollectionUtils.isEmpty(foodDishesInfoList)){
|
|
|
|
+ dishClassifyInfo.setFoodDishesInfoList(foodDishesInfoList);
|
|
|
|
+ dishClassifyInfo.setDishesNum(foodDishesInfoList.size());
|
|
|
|
+ displaysNum=displaysNum+foodDishesInfoList.size();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ foodInfo.setDisplaysNum(displaysNum);
|
|
|
|
+ foodInfo.setDishClassifyInfoList(dishClassifyInfoList);
|
|
|
|
+ }
|
|
|
|
+ List<FoodGroupInfo> foodGroupInfoList = foodGroupInfoMapper.selectList(new EntityWrapper<FoodGroupInfo>()
|
|
|
|
+ .eq("food_id",foodInfo.getId()));
|
|
|
|
+ if (!CollectionUtils.isEmpty(foodGroupInfoList)){
|
|
|
|
+ for (FoodGroupInfo foodGroupInfo:foodGroupInfoList){
|
|
|
|
+ //查询已售数量
|
|
|
|
+ List<FoodGroupOrderInfo> foodGroupOrderInfoList=foodGroupOrderInfoMapper.selectList(new EntityWrapper<FoodGroupOrderInfo>()
|
|
|
|
+ .eq("group_id",foodGroupInfo.getId()));
|
|
|
|
+ foodGroupInfo.setSoldNum(foodGroupOrderInfoList.size());
|
|
|
|
+ //查询已使用数量
|
|
|
|
+ List<FoodGroupOrderInfo> foodGroupOrderInfoList1=foodGroupOrderInfoMapper.selectList(new EntityWrapper<FoodGroupOrderInfo>()
|
|
|
|
+ .eq("group_id",foodGroupInfo.getId())
|
|
|
|
+ .eq("status","1"));
|
|
|
|
+ foodGroupInfo.setUsedNum(foodGroupOrderInfoList1.size());
|
|
|
|
+ foodGroupInfo.setNotUseNum(foodGroupOrderInfoList.size()-foodGroupOrderInfoList1.size());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ foodInfo.setFoodGroupInfoList(foodGroupInfoList);
|
|
|
|
+ foodInfo.setGroupNum(foodGroupInfoList.size());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
Integer count = foodInfoMapper.selectCount(wrapper);
|
|
Integer count = foodInfoMapper.selectCount(wrapper);
|
|
return new Page<FoodInfo>(list, page, limit, count);
|
|
return new Page<FoodInfo>(list, page, limit, count);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Page<FoodInfo> foodList(Long commonId,String location, String label, String searchKeyWord, String searchType, String userLongitude,String userLatitude,String place,Integer page, Integer limit) throws ServiceException {
|
|
|
|
+ List<FoodInfo> list =foodInfoMapper.getFoodInfoPage(commonId,label,searchKeyWord,(page - 1) * limit, limit, searchType);
|
|
|
|
+ List<FoodInfo> foodInfoList=new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)){
|
|
|
|
+ //查询发货地经纬度
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ FoodInfo foodInfo = list.get(i);
|
|
|
|
+ String [] tempArray = foodInfo.getLocation().split(",");
|
|
|
|
+ //店铺经纬度
|
|
|
|
+ double longitude = Double.parseDouble(tempArray[0]);
|
|
|
|
+ double latitude = Double.parseDouble(tempArray[1]);
|
|
|
|
+ //根据用户经纬度求距离
|
|
|
|
+ if (!StringUtils.isEmpty(userLatitude) && !StringUtils.isEmpty(userLongitude)) {
|
|
|
|
+ double lat1 = Math.toRadians(Double.valueOf(userLatitude));
|
|
|
|
+ double lng1 = Math.toRadians(Double.valueOf(userLongitude));
|
|
|
|
+ // 纬度之差
|
|
|
|
+ double a = lat1 - latitude;
|
|
|
|
+ // 经度之差
|
|
|
|
+ double b = lng1 - longitude;
|
|
|
|
+ // 计算两点距离的公式
|
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
|
|
|
|
+ Math.cos(lat1) * Math.cos(latitude) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
|
+
|
|
|
|
+ // 弧长乘地球半径, 返回单位: 千米
|
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
|
+ foodInfo.setDistance(Math.floor(s));
|
|
|
|
+ }
|
|
|
|
+ //根据用户定位的位置求距离
|
|
|
|
+ else if (!StringUtils.isEmpty(place)) {
|
|
|
|
+ //根据装货城市获取经纬度
|
|
|
|
+ String str = EntCoordUtil.getCoordinate(place);
|
|
|
|
+ String str1 = str.substring(0, str.indexOf(","));//经度
|
|
|
|
+ String str2 = str.substring(str1.length() + 1, str.length());//纬度
|
|
|
|
+
|
|
|
|
+ //装货地经纬度
|
|
|
|
+ double lng1 = Math.toRadians(Double.valueOf(str1));
|
|
|
|
+ double lat1 = Math.toRadians(Double.valueOf(str2));
|
|
|
|
+ // 纬度之差
|
|
|
|
+ double a = lat1 - latitude;
|
|
|
|
+ // 经度之差
|
|
|
|
+ double b = lng1 - longitude;
|
|
|
|
+ // 计算两点距离的公式
|
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
|
|
|
|
+ Math.cos(lat1) * Math.cos(latitude) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
|
+ // 弧长乘地球半径, 返回单位: 千米
|
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
|
+ foodInfo.setDistance(Math.floor(s));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //按距离排序
|
|
|
|
+ if ("2".equals(searchType)) {
|
|
|
|
+ list.sort(Comparator.comparing(FoodInfo::getDistance));
|
|
|
|
+ }
|
|
|
|
+ foodInfoList.addAll(list);
|
|
|
|
+ }
|
|
|
|
+ Integer count = list.size();
|
|
|
|
+ return new Page<FoodInfo>(list, page, limit, count);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Boolean delete(String id) {
|
|
public Boolean delete(String id) {
|
|
@@ -174,6 +287,36 @@ public class FoodInfoServiceImpl implements IFoodInfoService{
|
|
noticeMessageInfo.setGmtCreate(now);
|
|
noticeMessageInfo.setGmtCreate(now);
|
|
noticeMessageInfo.setGmtUpdate(now);
|
|
noticeMessageInfo.setGmtUpdate(now);
|
|
noticeMessageInfoMapper.insert(noticeMessageInfo);
|
|
noticeMessageInfoMapper.insert(noticeMessageInfo);
|
|
|
|
+ List<FoodInfo> foodInfoList = foodInfoMapper.selectList(new EntityWrapper<FoodInfo>()
|
|
|
|
+ .orderBy("weight_sort", false)
|
|
|
|
+ .eq("delete_flag", 0));
|
|
|
|
+ Long sort=0l;
|
|
|
|
+ if (!CollectionUtils.isEmpty(foodInfoList)) {
|
|
|
|
+ sort=foodInfoList.get(0).getWeightSort()+1;
|
|
|
|
+ }
|
|
|
|
+ foodInfo.setWeightSort(sort);
|
|
|
|
+ DishClassifyInfo dishClassifyInfo=new DishClassifyInfo();
|
|
|
|
+ dishClassifyInfo.setFoodId(foodInfo1.getId());
|
|
|
|
+ dishClassifyInfo.setClassifyName("荤菜");
|
|
|
|
+ dishClassifyInfo.setTopMarking(6l);
|
|
|
|
+ dishClassifyInfo.setGmtCreate(now);
|
|
|
|
+ dishClassifyInfo.setGmtUpdate(now);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
|
|
+ dishClassifyInfo.setClassifyName("素菜");
|
|
|
|
+ dishClassifyInfo.setTopMarking(5l);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
|
|
+ dishClassifyInfo.setClassifyName("主食");
|
|
|
|
+ dishClassifyInfo.setTopMarking(4l);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
|
|
+ dishClassifyInfo.setClassifyName("汤品");
|
|
|
|
+ dishClassifyInfo.setTopMarking(3l);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
|
|
+ dishClassifyInfo.setClassifyName("凉菜");
|
|
|
|
+ dishClassifyInfo.setTopMarking(2l);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
|
|
+ dishClassifyInfo.setClassifyName("串类");
|
|
|
|
+ dishClassifyInfo.setTopMarking(1l);
|
|
|
|
+ dishClassifyInfoMapper.insert(dishClassifyInfo);
|
|
}
|
|
}
|
|
return foodInfoMapper.updateById(foodInfo) > 0;
|
|
return foodInfoMapper.updateById(foodInfo) > 0;
|
|
}
|
|
}
|