| | |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.config.pojo.PatchesConfigPojo; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.utils.GeoToolsUtil; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import com.dji.sample.territory.dao.ITbDkjbxxMapper; |
| | | import com.dji.sample.territory.dao.ITbFjMapper; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import com.dji.sample.territory.service.ITbDkjbxxService; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert; |
| | | import static com.dji.sample.patches.utils.ZipUtil.zipFolder; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | |
| | | @Service |
| | | @DS("sqlite") |
| | | public class TbDkjbxxServiceImpl extends ServiceImpl<ITbDkjbxxMapper, TbDkjbxxEntity> implements ITbDkjbxxService { |
| | | } |
| | | private static final String RESOURCE_FILE_PATH = "DB/resource_db.db"; |
| | | @Autowired |
| | | private ITbDkjbxxMapper mapper; |
| | | @Autowired |
| | | private PatchesConfigPojo patchesConfigPojo; |
| | | |
| | | /** |
| | | * 上传DB文件并覆盖之前DB文件,自动读取数据到本地数据库 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public ResponseResult<String> uploadFile(MultipartFile file) { |
| | | if (file.isEmpty()) { |
| | | return ResponseResult.error("所上传的文件为空"); |
| | | } |
| | | try { |
| | | // 获取上传的文件输入流 |
| | | InputStream inputStream = file.getInputStream(); |
| | | // 创建输出流,将文件内容写入资源文件 |
| | | OutputStream outputStream = new FileOutputStream(RESOURCE_FILE_PATH); |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | outputStream.close(); |
| | | inputStream.close(); |
| | | return ResponseResult.success("文件上传成功"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | return ResponseResult.error(e.getMessage()); // 将异常信息包含在响应中返回给客户端 |
| | | } |
| | | } |
| | | |
| | | public MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException { |
| | | List<TbDkjbxxEntity> list = mapper.selectList(null); |
| | | List<LotInfo> info = dbConvertToEntity(list); |
| | | Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(info, airportLat, airportLon); |
| | | XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, info); |
| | | CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines()); |
| | | // 压缩文件夹中的内容 |
| | | String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径 |
| | | zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile); |
| | | MultipartFile multipartFile = convert(new File(destKMZFile)); |
| | | return multipartFile; |
| | | } |
| | | |
| | | private List<LotInfo> dbConvertToEntity(List<TbDkjbxxEntity> list) { |
| | | List<LotInfo> infos =new ArrayList<>(); |
| | | for (TbDkjbxxEntity file : list) { |
| | | LotInfo.LotInfoBuilder builder = LotInfo.builder(); |
| | | if (file != null) { |
| | | builder.bsm(file.getBsm()) |
| | | .bz(file.getBz()) |
| | | .dkmj(file.getDkmj()) |
| | | .dkmc(file.getDkmc()) |
| | | .dkbh(file.getDkbh()) |
| | | .xmc(file.getXmc()) |
| | | .xzb(file.getXzb()) |
| | | .sfbhzdk(file.getSfbhzdk()) |
| | | .sjlx(file.getSjlx()) |
| | | .dkfw(file.getDkfw()) |
| | | .xzqdm(file.getXzqdm()) |
| | | .yzb(file.getYzb()) |
| | | .kzxx(file.getKzxx()) |
| | | .dklx(file.getDklx()) |
| | | .build(); |
| | | infos.add(builder.build()); |
| | | } |
| | | } |
| | | return infos; |
| | | } |
| | | public void insert(List<LotInfo> list) { |
| | | for (LotInfo lotInfo : list) { |
| | | TbDkjbxxEntity entity = new TbDkjbxxEntity(); |
| | | entity.setBsm(lotInfo.getBsm()); |
| | | entity.setDkbh(lotInfo.getDkbh()); |
| | | entity.setXzb(lotInfo.getXzb()); |
| | | entity.setYzb(lotInfo.getYzb()); |
| | | entity.setDkfw(lotInfo.getDkfw()); |
| | | mapper.insert(entity); |
| | | } |
| | | } |
| | | } |