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 {
|
public interface ScenicMapper {
|
||||||
List<ScenicRespVO> list(ScenicReqQuery scenicReqQuery);
|
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);
|
List<ScenicAppVO> appList(ScenicReqQuery scenicReqQuery);
|
||||||
|
|
||||||
ScenicRespVO getAppById(Long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过经纬度计算景区距离
|
* 通过经纬度计算景区距离
|
||||||
*
|
*
|
||||||
|
@@ -13,15 +13,17 @@ import java.util.Date;
|
|||||||
* 景区管理表
|
* 景区管理表
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("scenic")
|
|
||||||
public class ScenicEntity {
|
public class ScenicEntity {
|
||||||
@TableId
|
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 景区名称
|
* 景区名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
private Integer mpId;
|
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 price;
|
||||||
private BigDecimal sourceVideoPrice;
|
private BigDecimal sourceVideoPrice;
|
||||||
private BigDecimal sourceImagePrice;
|
private BigDecimal sourceImagePrice;
|
||||||
|
@@ -74,19 +74,6 @@ public class ScenicRespVO {
|
|||||||
*/
|
*/
|
||||||
// 详细地址
|
// 详细地址
|
||||||
private String address;
|
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 Integer lensNum;
|
||||||
private String kfCodeUrl;
|
private String kfCodeUrl;
|
||||||
|
@@ -39,21 +39,22 @@ public class ScenicRepository {
|
|||||||
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
||||||
|
|
||||||
public ScenicEntity getScenic(Long id) {
|
public ScenicEntity getScenic(Long id) {
|
||||||
|
String key = String.format(SCENIC_CACHE_KEY, id);
|
||||||
try {
|
try {
|
||||||
ScenicV2DTO scenicDTO = scenicIntegrationService.getScenic(id);
|
ScenicV2WithConfigDTO scenicDTO = scenicIntegrationService.getScenicWithConfig(id);
|
||||||
ScenicEntity scenicEntity = convertToScenicEntity(scenicDTO);
|
ScenicEntity scenicEntity = convertToScenicEntity(scenicDTO);
|
||||||
|
|
||||||
// 请求成功,写入缓存
|
// 请求成功,写入缓存
|
||||||
if (scenicEntity != null) {
|
if (scenicEntity != null) {
|
||||||
redisTemplate.opsForValue().set(
|
redisTemplate.opsForValue().set(
|
||||||
String.format(SCENIC_CACHE_KEY, id),
|
key,
|
||||||
JacksonUtil.toJSONString(scenicEntity)
|
JacksonUtil.toJSONString(scenicEntity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return scenicEntity;
|
return scenicEntity;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 请求失败,尝试从缓存获取历史成功数据
|
// 请求失败,尝试从缓存获取历史成功数据
|
||||||
String cacheKey = String.format(SCENIC_CACHE_KEY, id);
|
String cacheKey = key;
|
||||||
if (redisTemplate.hasKey(cacheKey)) {
|
if (redisTemplate.hasKey(cacheKey)) {
|
||||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicEntity.class);
|
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicEntity.class);
|
||||||
}
|
}
|
||||||
@@ -63,6 +64,7 @@ public class ScenicRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
||||||
|
String key = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
||||||
try {
|
try {
|
||||||
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
||||||
ScenicConfigEntity configEntity = convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
ScenicConfigEntity configEntity = convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
||||||
@@ -70,14 +72,14 @@ public class ScenicRepository {
|
|||||||
// 请求成功,写入缓存
|
// 请求成功,写入缓存
|
||||||
if (configEntity != null) {
|
if (configEntity != null) {
|
||||||
redisTemplate.opsForValue().set(
|
redisTemplate.opsForValue().set(
|
||||||
String.format(SCENIC_CONFIG_CACHE_KEY, scenicId),
|
key,
|
||||||
JacksonUtil.toJSONString(configEntity)
|
JacksonUtil.toJSONString(configEntity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return configEntity;
|
return configEntity;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 请求失败,尝试从缓存获取历史成功数据
|
// 请求失败,尝试从缓存获取历史成功数据
|
||||||
String cacheKey = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
String cacheKey = key;
|
||||||
if (redisTemplate.hasKey(cacheKey)) {
|
if (redisTemplate.hasKey(cacheKey)) {
|
||||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicConfigEntity.class);
|
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicConfigEntity.class);
|
||||||
}
|
}
|
||||||
@@ -174,7 +176,34 @@ public class ScenicRepository {
|
|||||||
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
||||||
return entity;
|
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) {
|
private ScenicConfigEntity convertToScenicConfigEntity(ScenicV2WithConfigDTO dto, Long scenicId) {
|
||||||
if (dto == null || dto.getConfig() == null) {
|
if (dto == null || dto.getConfig() == null) {
|
||||||
return 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.entity.DeviceEntity;
|
||||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
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.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.req.ScenicReqQuery;
|
||||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||||
import com.ycwl.basic.repository.DeviceRepository;
|
import com.ycwl.basic.repository.DeviceRepository;
|
||||||
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
import com.ycwl.basic.service.mobile.AppScenicService;
|
import com.ycwl.basic.service.mobile.AppScenicService;
|
||||||
import com.ycwl.basic.service.pc.ScenicAccountService;
|
import com.ycwl.basic.service.pc.ScenicAccountService;
|
||||||
import com.ycwl.basic.utils.ApiResponse;
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
@@ -57,6 +60,8 @@ public class AppScenicServiceImpl implements AppScenicService {
|
|||||||
private ExtraDeviceMapper extraDeviceMapper;
|
private ExtraDeviceMapper extraDeviceMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, String> redisTemplate;
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private ScenicRepository scenicRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResponse<PageInfo<ScenicAppVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
public ApiResponse<PageInfo<ScenicAppVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
||||||
@@ -75,7 +80,27 @@ public class AppScenicServiceImpl implements AppScenicService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResponse<ScenicRespVO> getDetails(Long id) {
|
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);
|
ScenicDeviceCountVO scenicDeviceCountVO = deviceMapper.deviceCountByScenicId(id);
|
||||||
scenicRespVO.setLensNum(scenicDeviceCountVO.getTotalDeviceCount());
|
scenicRespVO.setLensNum(scenicDeviceCountVO.getTotalDeviceCount());
|
||||||
return ApiResponse.success(scenicRespVO);
|
return ApiResponse.success(scenicRespVO);
|
||||||
|
Reference in New Issue
Block a user