Merge remote-tracking branch 'origin/master'

This commit is contained in:
GYJ
2025-02-14 14:59:26 +08:00
20 changed files with 897 additions and 11 deletions

View File

@@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopTable;
/**
* 台桌配置 映射层。
*
* @author zs
* @since 2025-02-13
*/
public interface ShopTableMapper extends BaseMapper<ShopTable> {
}

View File

@@ -0,0 +1,45 @@
package com.czg.service.account.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.GeoService;
import com.czg.exception.ApiNotPrintException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import java.util.Objects;
/**
* 经纬度
*
* @author Administrator
*/
@Service
@Slf4j
public class GeoServiceImpl implements GeoService {
private final RestClient restClient = RestClient.create();
private static final String API_KEY = "7a7f2e4790ea222660a027352ee3af39";
private static final String BASE_URL = "https://restapi.amap.com/v3/geocode/regeo";
@Override
public JSONObject getAddress(String lat, String lng) {
// 高德 API 坐标格式为 "经度,纬度"
String location = lng + "," + lat;
String response = restClient.get()
.uri(BASE_URL + "?key=" + API_KEY + "&location=" + location)
.retrieve()
.body(String.class);
JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject == null) {
log.warn("经纬度获取失败{}", response);
throw new ApiNotPrintException("获取经纬度失败");
}
return jsonObject.getJSONObject("regeocode");
}
}

View File

@@ -2,23 +2,29 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.CoordinateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.czg.account.dto.PageDTO;
import com.czg.account.dto.shopinfo.ShopInfoAddDTO;
import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
import com.czg.account.dto.shopinfo.ShopInfoEditDTO;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.enums.StatusEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.ShopInfoMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.GeoUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Administrator
@@ -28,11 +34,27 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Resource
private SysUserService sysUserService;
@Resource
private SysUsersRolesService sysUsersRolesService;
@Resource
private SysRoleService sysRoleService;
@Resource
private MerchantRegisterService merchantRegisterService;
@Resource
private ShopTableService shopTableService;
private ShopInfo getShopInfo(Long shopId) {
ShopInfo shopInfo = getById(shopId);
if (shopInfo == null) {
throw new ApiNotPrintException("店铺不存在");
}
if ((DateUtil.date().toLocalDateTime().isAfter(shopInfo.getExpireTime())) || shopInfo.getStatus() != StatusEnum.ENABLED.value()) {
throw new ApiNotPrintException("店铺已过期,请联系商家");
}
if (StatusEnum.DISABLE.value() == shopInfo.getOnSale()) {
throw new ApiNotPrintException("店铺已停业,请联系商家");
}
shopInfo.setBookingSms(null);
shopInfo.setOperationPwd(null);
shopInfo.setBindAccount(null);
return shopInfo;
}
@Override
public Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status) {
@@ -99,4 +121,24 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
public ShopInfo detail() {
return queryChain().eq(ShopInfo::getId, StpKit.USER.getLoginIdAsLong()).one();
}
@Override
public ShopInfoByCodeDTO getByCode(String tableCode, String lat, String lng, boolean checkState) {
ShopTable shopTable = shopTableService.queryChain().eq(ShopTable::getTableCode, tableCode).one();
if (shopTable == null) {
throw new ApiNotPrintException("错误的台桌码");
}
if (checkState && !shopTable.canUseByStatus()) {
throw new ApiNotPrintException("台桌状态不可用");
}
ShopInfo shopInfo = getShopInfo(shopTable.getShopId());
double distance = 0;
if (StrUtil.isAllNotBlank(lat, lng, shopInfo.getLat(), shopInfo.getLng())) {
// 计算距离,单位:米
distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng));
}
return new ShopInfoByCodeDTO(distance, shopInfo, shopTable);
}
}

View File

@@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopTable;
import com.czg.account.service.ShopTableService;
import com.czg.service.account.mapper.ShopTableMapper;
import org.springframework.stereotype.Service;
/**
* 台桌配置 服务层实现。
*
* @author zs
* @since 2025-02-13
*/
@Service
public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable> implements ShopTableService{
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopTableMapper">
</mapper>

View File

@@ -23,13 +23,13 @@ public class Main {
// packageName 指定生成代码项目
// tableName 指定需要生成的表
String packageName = "system";
// String packageName = "account";
// String packageName = "product";
// String packageName = "order";
// String servicePackageName = "system";
// String servicePackageName = "account";
// String servicePackageName = "product";
String packageName = "account";
String tableName = "tb_order_detail";
String author = "ww";
String tableName = "tb_shop_table";
String author = "zs";
//配置数据源
HikariDataSource dataSource = new HikariDataSource();