记得上下班打卡 | git大法好,push需谨慎

Commit 13cae844 authored by stonepy's avatar stonepy

宣传手册修改geojson的保存方式

parent 7043e74a
......@@ -22,6 +22,6 @@ public class SweetManualExtConfigParam implements Serializable {
@ApiModelProperty("失物招领问卷星ID")
private String lostFoundWjxId;
@ApiModelProperty("地图GeoJSON文件地址")
private String mapGeojsonUrl;
@ApiModelProperty("地图GeoJSON数据")
private Object mapGeojson;
}
package com.liquidnet.service.sweet.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel("手册地图GeoJSON保存参数")
public class SweetManualMapGeojsonParam implements Serializable {
@ApiModelProperty(value = "电子手册id", required = true)
private String manualId;
@ApiModelProperty(value = "地图GeoJSON数据", required = true)
private Object mapGeojson;
}
......@@ -3,7 +3,7 @@ package com.liquidnet.service.sweet.service;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.dto.SweetManualExtConfigDto;
import com.liquidnet.service.sweet.param.SweetManualExtConfigParam;
import org.springframework.web.multipart.MultipartFile;
import com.liquidnet.service.sweet.param.SweetManualMapGeojsonParam;
public interface ISweetManualExtConfigService {
......@@ -11,5 +11,7 @@ public interface ISweetManualExtConfigService {
ResponseDto<Boolean> save(SweetManualExtConfigParam param);
ResponseDto<String> uploadGeojson(MultipartFile file);
ResponseDto<Object> getMapGeojson(String manualId);
ResponseDto<Boolean> saveMapGeojson(SweetManualMapGeojsonParam param);
}
......@@ -22,6 +22,6 @@ public class SweetManualExtConfigDto implements Serializable {
@ApiModelProperty("失物招领问卷星ID")
private String lostFoundWjxId;
@ApiModelProperty("地图GeoJSON文件地址")
private String mapGeojsonUrl;
@ApiModelProperty("地图GeoJSON数据")
private Object mapGeojson;
}
......@@ -66,9 +66,9 @@ public class SweetManual implements Serializable,Cloneable {
private String lostFoundWjxId;
/**
* 地图GeoJSON文件地址
* 地图GeoJSON数据
*/
private String mapGeojsonUrl;
private String mapGeojson;
/**
* 创建时间
......
......@@ -4,4 +4,4 @@ ALTER TABLE `sweet_manual`
ADD COLUMN `food_guide_url` varchar(500) NOT NULL DEFAULT '' COMMENT '餐饮攻略链接' AFTER `is_release_manual`,
ADD COLUMN `album_url` varchar(500) NOT NULL DEFAULT '' COMMENT '相册链接' AFTER `food_guide_url`,
ADD COLUMN `lost_found_wjx_id` varchar(200) NOT NULL DEFAULT '' COMMENT '失物招领问卷星ID' AFTER `album_url`,
ADD COLUMN `map_geojson_url` varchar(500) NOT NULL DEFAULT '' COMMENT '地图GeoJSON文件地址' AFTER `lost_found_wjx_id`;
ADD COLUMN `map_geojson` longtext NULL COMMENT '地图GeoJSON数据' AFTER `lost_found_wjx_id`;
use ln_scene;
-- 地图GeoJSON由文件地址改为直接存储JSON数据
ALTER TABLE `sweet_manual`
CHANGE COLUMN `map_geojson_url` `map_geojson` longtext NULL COMMENT '地图GeoJSON数据';
......@@ -3,6 +3,7 @@ package com.liquidnet.service.sweet.controller;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.dto.SweetManualExtConfigDto;
import com.liquidnet.service.sweet.param.SweetManualExtConfigParam;
import com.liquidnet.service.sweet.param.SweetManualMapGeojsonParam;
import com.liquidnet.service.sweet.service.ISweetManualExtConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -10,7 +11,6 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Api(tags = "草莓音乐节手册扩展配置")
@RestController
......@@ -35,9 +35,18 @@ public class SweetManualExtConfigController {
return sweetManualExtConfigService.save(param);
}
@PostMapping("uploadGeojson")
@ApiOperation("上传地图GeoJSON文件")
public ResponseDto<String> uploadGeojson(@RequestPart("file") MultipartFile file) {
return sweetManualExtConfigService.uploadGeojson(file);
@GetMapping("mapGeojson")
@ApiOperation("获取地图GeoJSON数据")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "manualId", value = "电子手册id", required = true),
})
public ResponseDto<Object> getMapGeojson(@RequestParam String manualId) {
return sweetManualExtConfigService.getMapGeojson(manualId);
}
@PostMapping("saveMapGeojson")
@ApiOperation("保存地图GeoJSON数据")
public ResponseDto<Boolean> saveMapGeojson(@RequestBody SweetManualMapGeojsonParam param) {
return sweetManualExtConfigService.saveMapGeojson(param);
}
}
package com.liquidnet.service.sweet.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.core.type.TypeReference;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.dto.vo.basicServices.UploadVo;
import com.liquidnet.service.sweet.dto.SweetManualExtConfigDto;
import com.liquidnet.service.sweet.entity.SweetManual;
import com.liquidnet.service.sweet.mapper.SweetManualMapper;
import com.liquidnet.service.sweet.param.SweetManualExtConfigParam;
import com.liquidnet.service.sweet.param.SweetManualMapGeojsonParam;
import com.liquidnet.service.sweet.service.ISweetManualExtConfigService;
import com.liquidnet.service.sweet.utils.RedisDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime;
import java.util.Map;
@Service
public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigService {
private static final String GEOJSON_IMG_PREFIX = "https://img.zhengzai.tv/";
@Value("${liquidnet.service.platform.url}")
private String platformUrl;
@Autowired
private SweetManualMapper sweetManualMapper;
......@@ -61,56 +46,60 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (exist == null) {
return ResponseDto.failure("手册不存在");
}
SweetManual update = SweetManual.getNew();
update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
update.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
update.setLostFoundWjxId(nullToEmpty(param.getLostFoundWjxId()));
update.setMapGeojsonUrl(nullToEmpty(param.getMapGeojsonUrl()));
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param));
return ResponseDto.success(true);
try {
SweetManual update = SweetManual.getNew();
update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
update.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
update.setLostFoundWjxId(nullToEmpty(param.getLostFoundWjxId()));
if (param.getMapGeojson() != null) {
update.setMapGeojson(serializeGeojson(param.getMapGeojson()));
}
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param));
return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
}
}
@Override
public ResponseDto<Object> getMapGeojson(String manualId) {
SweetManual manual = sweetManualMapper.selectOne(
Wrappers.lambdaQuery(SweetManual.class).eq(SweetManual::getManualId, manualId));
if (manual == null) {
return ResponseDto.failure("手册不存在");
}
return ResponseDto.success(parseGeojson(manual.getMapGeojson()));
}
@Override
public ResponseDto<String> uploadGeojson(MultipartFile file) {
if (file == null || file.isEmpty()) {
return ResponseDto.failure("文件不能为空");
public ResponseDto<Boolean> saveMapGeojson(SweetManualMapGeojsonParam param) {
if (StringUtil.isBlank(param.getManualId())) {
return ResponseDto.failure("手册id不能为空");
}
if (param.getMapGeojson() == null) {
return ResponseDto.failure("地图GeoJSON数据不能为空");
}
String filename = file.getOriginalFilename();
if (StringUtil.isBlank(filename)
|| (!filename.toLowerCase().endsWith(".geojson") && !filename.toLowerCase().endsWith(".json"))) {
return ResponseDto.failure("仅支持上传.geojson或.json文件");
SweetManual exist = sweetManualMapper.selectOne(
Wrappers.lambdaQuery(SweetManual.class).eq(SweetManual::getManualId, param.getManualId()));
if (exist == null) {
return ResponseDto.failure("手册不存在");
}
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
ByteArrayResource fileResource = new ByteArrayResource(file.getBytes()) {
@Override
public String getFilename() {
return filename;
}
};
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileResource);
body.add("pathName", "sweet/manual/geojson");
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.postForEntity(
platformUrl.concat("/platform/basicServices/alOss/upload"),
requestEntity,
String.class);
ResponseDto<UploadVo> dto = JsonUtils.fromJson(response.getBody(), new TypeReference<ResponseDto<UploadVo>>() {
});
if (dto == null || dto.getData() == null || StringUtil.isBlank(dto.getData().getOssPath())) {
return ResponseDto.failure("文件上传失败");
}
return ResponseDto.success(GEOJSON_IMG_PREFIX.concat(dto.getData().getOssPath()));
} catch (Exception e) {
return ResponseDto.failure("文件上传失败");
String geojson = serializeGeojson(param.getMapGeojson());
SweetManual update = SweetManual.getNew();
update.setMapGeojson(geojson);
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
SweetManualExtConfigDto cacheDto = toDto(exist);
cacheDto.setMapGeojson(parseGeojson(geojson));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), cacheDto);
return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
}
}
......@@ -120,7 +109,7 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
dto.setFoodGuideUrl(manual.getFoodGuideUrl());
dto.setAlbumUrl(manual.getAlbumUrl());
dto.setLostFoundWjxId(manual.getLostFoundWjxId());
dto.setMapGeojsonUrl(manual.getMapGeojsonUrl());
dto.setMapGeojson(parseGeojson(manual.getMapGeojson()));
return dto;
}
......@@ -130,10 +119,48 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
dto.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
dto.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
dto.setLostFoundWjxId(nullToEmpty(param.getLostFoundWjxId()));
dto.setMapGeojsonUrl(nullToEmpty(param.getMapGeojsonUrl()));
if (param.getMapGeojson() != null) {
dto.setMapGeojson(param.getMapGeojson());
} else {
dto.setMapGeojson(parseGeojson(exist.getMapGeojson()));
}
return dto;
}
private Object parseGeojson(String geojson) {
if (StringUtil.isBlank(geojson)) {
return null;
}
return JsonUtils.fromJson(geojson, Object.class);
}
private String serializeGeojson(Object geojson) {
if (geojson == null) {
return null;
}
String json;
if (geojson instanceof String) {
json = ((String) geojson).trim();
if (json.isEmpty()) {
return null;
}
} else {
json = JsonUtils.toJson(geojson);
}
validateGeojson(json);
return json;
}
private void validateGeojson(String json) {
Map<?, ?> map = JsonUtils.fromJson(json, Map.class);
if (map == null) {
throw new IllegalArgumentException("地图GeoJSON格式不正确");
}
if (!"FeatureCollection".equals(map.get("type"))) {
throw new IllegalArgumentException("地图GeoJSON必须为FeatureCollection格式");
}
}
private String nullToEmpty(String value) {
return value == null ? "" : value;
}
......
......@@ -7,7 +7,9 @@ import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.RandomUtil;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.base.constant.RedisKeyExpireConst;
......@@ -193,7 +195,7 @@ public class RedisDataUtils {
configDto.setFoodGuideUrl(manual.getFoodGuideUrl());
configDto.setAlbumUrl(manual.getAlbumUrl());
configDto.setLostFoundWjxId(manual.getLostFoundWjxId());
configDto.setMapGeojsonUrl(manual.getMapGeojsonUrl());
configDto.setMapGeojson(parseManualMapGeojson(manual.getMapGeojson()));
}
}
redisUtil.set(redisKey, configDto);
......@@ -213,6 +215,13 @@ public class RedisDataUtils {
redisUtil.del(SweetConstant.REDIS_KEY_SWEET_MANUAL_EXT_CONFIG.concat(manualId));
}
private Object parseManualMapGeojson(String geojson) {
if (StringUtil.isBlank(geojson)) {
return null;
}
return JsonUtils.fromJson(geojson, Object.class);
}
public List<String> setTagRedisData(String manualId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_MANUAL_SORT.concat(manualId);
SweetManualSort data = sweetManualSortMapper.selectOne(Wrappers.lambdaQuery(SweetManualSort.class).eq(SweetManualSort::getManualId, manualId));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment