You've already forked FrameTour-BE
refactor(scenic): 重构景区相关接口和数据结构
-移除了 ScenicMapper 中的冗余方法 - 更新了 ScenicEntity 和 ScenicRespVO 的字段结构 - 重构了 ScenicRepository 中的缓存逻辑 - 优化了 AppScenicServiceImpl 中的景区详情获取方法
This commit is contained in:
@@ -21,46 +21,8 @@ import java.util.List;
|
||||
public interface ScenicMapper {
|
||||
List<ScenicRespVO> list(ScenicReqQuery scenicReqQuery);
|
||||
|
||||
ScenicEntity get(Long id);
|
||||
|
||||
ScenicRespVO getById(Long id);
|
||||
|
||||
int add(ScenicAddOrUpdateReq scenic);
|
||||
|
||||
int deleteById(Long id);
|
||||
|
||||
int update(ScenicAddOrUpdateReq scenic);
|
||||
|
||||
int updateStatus(Long id);
|
||||
|
||||
ScenicConfigEntity getConfig(Long scenicId);
|
||||
/**
|
||||
* 添加景区配置
|
||||
*
|
||||
* @param scenicConfig
|
||||
* @return
|
||||
*/
|
||||
int addConfig(ScenicConfigEntity scenicConfig);
|
||||
|
||||
/**
|
||||
* 修改景区配置
|
||||
*
|
||||
* @param scenicConfigEntity
|
||||
* @return
|
||||
*/
|
||||
int updateConfigById(ScenicConfigEntity scenicConfigEntity);
|
||||
|
||||
/**
|
||||
* 根据景区id删除配置
|
||||
*
|
||||
* @param scenicId
|
||||
*/
|
||||
void deleteConfigByScenicId(Long scenicId);
|
||||
|
||||
List<ScenicAppVO> appList(ScenicReqQuery scenicReqQuery);
|
||||
|
||||
ScenicRespVO getAppById(Long id);
|
||||
|
||||
/**
|
||||
* 通过经纬度计算景区距离
|
||||
*
|
||||
|
@@ -13,15 +13,17 @@ import java.util.Date;
|
||||
* 景区管理表
|
||||
*/
|
||||
@Data
|
||||
@TableName("scenic")
|
||||
public class ScenicEntity {
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 景区名称
|
||||
*/
|
||||
private String name;
|
||||
private Integer mpId;
|
||||
private String phone;
|
||||
private String logoUrl;
|
||||
// 封面图
|
||||
private String coverUrl;
|
||||
/**
|
||||
* 景区介绍
|
||||
*/
|
||||
@@ -63,6 +65,7 @@ public class ScenicEntity {
|
||||
/**
|
||||
* 景区源素材价格,元
|
||||
*/
|
||||
private String kfCodeUrl;
|
||||
private BigDecimal price;
|
||||
private BigDecimal sourceVideoPrice;
|
||||
private BigDecimal sourceImagePrice;
|
||||
|
@@ -74,19 +74,6 @@ public class ScenicRespVO {
|
||||
*/
|
||||
// 详细地址
|
||||
private String address;
|
||||
/**
|
||||
* 状态 1启用0关闭
|
||||
*/
|
||||
// 状态 1启用0关闭
|
||||
private Integer status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
// 景区源素材价格,元
|
||||
private BigDecimal price;
|
||||
private BigDecimal sourceVideoPrice;
|
||||
private BigDecimal sourceImagePrice;
|
||||
// 镜头数
|
||||
private Integer lensNum;
|
||||
private String kfCodeUrl;
|
||||
|
@@ -39,21 +39,22 @@ public class ScenicRepository {
|
||||
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
||||
|
||||
public ScenicEntity getScenic(Long id) {
|
||||
String key = String.format(SCENIC_CACHE_KEY, id);
|
||||
try {
|
||||
ScenicV2DTO scenicDTO = scenicIntegrationService.getScenic(id);
|
||||
ScenicV2WithConfigDTO scenicDTO = scenicIntegrationService.getScenicWithConfig(id);
|
||||
ScenicEntity scenicEntity = convertToScenicEntity(scenicDTO);
|
||||
|
||||
// 请求成功,写入缓存
|
||||
if (scenicEntity != null) {
|
||||
redisTemplate.opsForValue().set(
|
||||
String.format(SCENIC_CACHE_KEY, id),
|
||||
key,
|
||||
JacksonUtil.toJSONString(scenicEntity)
|
||||
);
|
||||
}
|
||||
return scenicEntity;
|
||||
} catch (Exception e) {
|
||||
// 请求失败,尝试从缓存获取历史成功数据
|
||||
String cacheKey = String.format(SCENIC_CACHE_KEY, id);
|
||||
String cacheKey = key;
|
||||
if (redisTemplate.hasKey(cacheKey)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicEntity.class);
|
||||
}
|
||||
@@ -63,6 +64,7 @@ public class ScenicRepository {
|
||||
}
|
||||
|
||||
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
||||
String key = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
||||
try {
|
||||
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
||||
ScenicConfigEntity configEntity = convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
||||
@@ -70,14 +72,14 @@ public class ScenicRepository {
|
||||
// 请求成功,写入缓存
|
||||
if (configEntity != null) {
|
||||
redisTemplate.opsForValue().set(
|
||||
String.format(SCENIC_CONFIG_CACHE_KEY, scenicId),
|
||||
key,
|
||||
JacksonUtil.toJSONString(configEntity)
|
||||
);
|
||||
}
|
||||
return configEntity;
|
||||
} catch (Exception e) {
|
||||
// 请求失败,尝试从缓存获取历史成功数据
|
||||
String cacheKey = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
||||
String cacheKey = key;
|
||||
if (redisTemplate.hasKey(cacheKey)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicConfigEntity.class);
|
||||
}
|
||||
@@ -174,7 +176,34 @@ public class ScenicRepository {
|
||||
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
private ScenicEntity convertToScenicEntity(ScenicV2WithConfigDTO dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
ScenicEntity entity = new ScenicEntity();
|
||||
entity.setId(Long.parseLong(dto.getId()));
|
||||
entity.setName(dto.getName());
|
||||
entity.setMpId(dto.getMpId());
|
||||
entity.setStatus(dto.getStatus().toString());
|
||||
entity.setCreateTime(new java.util.Date(dto.getCreateTime()));
|
||||
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
||||
if (dto.getConfig() != null) {
|
||||
entity.setAddress(ConfigValueUtil.getStringValue(dto.getConfig(), "address"));
|
||||
entity.setArea(ConfigValueUtil.getStringValue(dto.getConfig(), "area"));
|
||||
entity.setCity(ConfigValueUtil.getStringValue(dto.getConfig(), "city"));
|
||||
entity.setProvince(ConfigValueUtil.getStringValue(dto.getConfig(), "province"));
|
||||
entity.setLatitude(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "latitude"));
|
||||
entity.setLongitude(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "longitude"));
|
||||
entity.setRadius(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "radius"));
|
||||
entity.setPhone(ConfigValueUtil.getStringValue(dto.getConfig(), "phone"));
|
||||
entity.setLogoUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "logoUrl"));
|
||||
entity.setCoverUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "coverUrl"));
|
||||
entity.setKfCodeUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "kfCodeUrl"));
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ScenicConfigEntity convertToScenicConfigEntity(ScenicV2WithConfigDTO dto, Long scenicId) {
|
||||
if (dto == null || dto.getConfig() == null) {
|
||||
return null;
|
||||
|
@@ -14,9 +14,12 @@ import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginRespVO;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.repository.DeviceRepository;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.mobile.AppScenicService;
|
||||
import com.ycwl.basic.service.pc.ScenicAccountService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
@@ -57,6 +60,8 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
private ExtraDeviceMapper extraDeviceMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<ScenicAppVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
||||
@@ -75,7 +80,27 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
|
||||
@Override
|
||||
public ApiResponse<ScenicRespVO> getDetails(Long id) {
|
||||
ScenicRespVO scenicRespVO = scenicMapper.getAppById(id);
|
||||
ScenicEntity scenic = scenicRepository.getScenic(id);
|
||||
ScenicRespVO scenicRespVO = new ScenicRespVO();
|
||||
|
||||
// 将ScenicEntity的值通过set/get方式写入到ScenicRespVO
|
||||
if (scenic != null) {
|
||||
scenicRespVO.setId(scenic.getId());
|
||||
scenicRespVO.setName(scenic.getName());
|
||||
scenicRespVO.setPhone(scenic.getPhone());
|
||||
scenicRespVO.setLogoUrl(scenic.getLogoUrl());
|
||||
scenicRespVO.setCoverUrl(scenic.getCoverUrl());
|
||||
scenicRespVO.setIntroduction(scenic.getIntroduction());
|
||||
scenicRespVO.setLongitude(scenic.getLongitude());
|
||||
scenicRespVO.setLatitude(scenic.getLatitude());
|
||||
scenicRespVO.setRadius(scenic.getRadius());
|
||||
scenicRespVO.setProvince(scenic.getProvince());
|
||||
scenicRespVO.setCity(scenic.getCity());
|
||||
scenicRespVO.setArea(scenic.getArea());
|
||||
scenicRespVO.setAddress(scenic.getAddress());
|
||||
scenicRespVO.setKfCodeUrl(scenic.getKfCodeUrl());
|
||||
}
|
||||
|
||||
ScenicDeviceCountVO scenicDeviceCountVO = deviceMapper.deviceCountByScenicId(id);
|
||||
scenicRespVO.setLensNum(scenicDeviceCountVO.getTotalDeviceCount());
|
||||
return ApiResponse.success(scenicRespVO);
|
||||
|
Reference in New Issue
Block a user