package com.gk.hotwork.Service.ServiceImpl;
|
|
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.gk.hotwork.Domain.FourColorPoint;
|
import com.gk.hotwork.Domain.FourColorPointCoord;
|
import com.gk.hotwork.Domain.dto.FourColorMapDto;
|
import com.gk.hotwork.Domain.dto.FourColorPointLocateDto;
|
import com.gk.hotwork.Service.FourColorMapService;
|
import com.gk.hotwork.Service.FourColorPointCoordService;
|
import com.gk.hotwork.Service.FourColorPointService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service
|
public class FourColorMapServiceImpl implements FourColorMapService {
|
|
@Autowired
|
private FourColorPointService pointService;
|
|
@Autowired
|
private FourColorPointCoordService coordService;
|
|
@Transactional
|
@Override
|
public String insertOneMapPoint(FourColorMapDto mapDto) {
|
String result = null;
|
String dtoCheckResult = checkFourColorMapDto(mapDto);
|
if(dtoCheckResult == null){
|
int step = 1;
|
FourColorPoint point = new FourColorPoint();
|
point.setId(mapDto.getId());
|
point.setEtype(mapDto.getEtype());
|
point.setName(mapDto.getName());
|
point.setType(mapDto.getType());
|
point.setText(mapDto.getText());
|
point.setShapeType(mapDto.getShapeType());
|
point.setClampToGround(mapDto.isClampToGround());
|
point.setGeoType(mapDto.getGeoType());
|
point.setColor(mapDto.getColor());
|
if(pointService.getById(point.getId()) != null){
|
result = "ID已存在";
|
return result;
|
}
|
if(pointService.save(point) == true){
|
step = 2;
|
}else {
|
throw new RuntimeException("数据库保存点位失败");
|
}
|
if(step == 2){
|
List<FourColorPointCoord> coordList = new ArrayList<>();
|
for(FourColorPointLocateDto locateDto : mapDto.getLocations()){
|
FourColorPointCoord coord = new FourColorPointCoord();
|
coord.setPointId(mapDto.getId());
|
coord.setLon(locateDto.getLon());
|
coord.setLat(locateDto.getLat());
|
coord.setHei(locateDto.getHei());
|
coordList.add(coord);
|
}
|
if(coordService.saveBatch(coordList) == true){
|
step = 3;
|
}else {
|
result = "业务错误";
|
throw new RuntimeException("数据库保存定位数据失败");
|
}
|
}
|
}else {
|
result = dtoCheckResult;
|
}
|
return result;
|
}
|
|
@Transactional
|
@Override
|
public boolean deleteMap(String id) {
|
boolean result = false;
|
FourColorPoint point = pointService.getById(id);
|
if(point == null || point.getId()==null || point.getId().isEmpty()){
|
return false;
|
}
|
//1、删除位置信息
|
List<FourColorPointCoord> coordList = coordService.findCoordListByPointId(id);
|
int step = 1;
|
if(coordList != null && coordList.size() > 0){
|
List<Long> idList = new ArrayList<>();
|
for(FourColorPointCoord coord : coordList){
|
idList.add(coord.getId());
|
}
|
if(coordService.removeByIds(idList) == true){
|
step = 2;
|
}else {
|
throw new RuntimeException("数据库删除定位数据失败");
|
}
|
}
|
//2、删除地图信息
|
if(step == 2){
|
if(pointService.removeById(point)){
|
result = true;
|
}else {
|
throw new RuntimeException("数据库删除地图失败");
|
}
|
}
|
return result;
|
}
|
|
@Override
|
public JSONObject getOnePointJsonById(String id) {
|
JSONObject mapJson = null;
|
FourColorPoint point = pointService.getById(id);
|
List<FourColorPointCoord> coordList = coordService.findCoordListByPointId(id);
|
if(point != null && !point.getId().isEmpty()){
|
mapJson = packageMapDto(point,coordList);
|
}
|
return mapJson;
|
}
|
|
@Override
|
public List<JSONObject> getPointListJson(int etype) {
|
//非60万吨和130万吨类型
|
if(etype != 1 && etype != 2){
|
return null;
|
}
|
List<JSONObject> mapDtoListJson = null;
|
List<FourColorPoint> pointList = pointService.findPointListByEtype(etype);
|
if(pointList != null && pointList.size() > 0){
|
mapDtoListJson = new ArrayList<>();
|
for(FourColorPoint point : pointList){
|
List<FourColorPointCoord> coordList = coordService.findCoordListByPointId(point.getId());
|
JSONObject mapDtoJson = packageMapDto(point,coordList);
|
if(mapDtoJson != null && !mapDtoJson.isEmpty()){
|
mapDtoListJson.add(mapDtoJson);
|
}
|
}
|
}
|
return mapDtoListJson;
|
}
|
|
private String checkFourColorMapDto(FourColorMapDto dto){
|
if(dto == null)
|
return "参数不能为空";
|
if(dto.getId() == null || dto.getId().isEmpty())
|
return "ID不能为空";
|
if(dto.getEtype() == null || dto.getEtype() <= 0)
|
return "企业类型不能为空";
|
if(dto.getEtype() != 1 && dto.getEtype() !=2)
|
return "企业类型错误";
|
if(dto.getName() == null || dto.getName().isEmpty())
|
return "名字不能为空";
|
if(dto.getColor() == null || dto.getColor().isEmpty())
|
return "颜色不能为空";
|
if(dto.getText() == null || dto.getText().isEmpty())
|
return "文字说明不能为空";
|
if(dto.getGeoType() == null || dto.getGeoType().isEmpty())
|
return "绘图形状不能为空";
|
if(dto.getType() == null || dto.getType().isEmpty())
|
return "四色图形状不能为空";
|
if(dto.getShapeType() == null || dto.getShapeType().isEmpty())
|
return "四色图形状不能为空";
|
if(dto.getLocations() == null || dto.getLocations().size() <= 0)
|
return "坐标不能为空";
|
return null;
|
}
|
|
private JSONObject packageMapDto(FourColorPoint point,List<FourColorPointCoord> coordList){
|
if(point == null)
|
return null;
|
JSONObject obj = JSONUtil.createObj();
|
obj.put("type",point.getType());
|
JSONObject prop = JSONUtil.createObj();
|
prop.put("attr",JSONUtil.createObj().put("name",point.getName()).put("id",point.getId()));
|
prop.put("type",point.getShapeType());
|
prop.put("style",JSONUtil.createObj().put("text",point.getText()).put("clampToGround",point.isClampToGround()).put("color",point.getColor()));
|
obj.put("properties",prop);
|
JSONObject geoLocate = JSONUtil.createObj();
|
geoLocate.put("type",point.getGeoType());
|
if(coordList != null && coordList.size() > 0){
|
JSONArray coordArray = JSONUtil.createArray();
|
for(FourColorPointCoord coord : coordList){
|
JSONArray co = JSONUtil.createArray();
|
co.add(coord.getLon());
|
co.add(coord.getLat());
|
co.add(coord.getHei());
|
coordArray.add(co);
|
}
|
geoLocate.put("coordinates",coordArray);
|
}
|
obj.put("geometry",geoLocate);
|
return obj;
|
}
|
|
}
|