xieb
2024-04-28 f76eb78bbd16b925e005e09d6f448d961f91c21a
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
@@ -14,6 +14,7 @@
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.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbDkjbxxService;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,9 +29,12 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert;
import static com.dji.sample.patches.utils.ZipUtil.zipFolder;
import static com.dji.sample.territory.utils.CoordinateSystemUtil.*;
/**
 * @PROJECT_NAME: drone
@@ -41,11 +45,12 @@
@Service
@DS("sqlite-resource")
public class TbDkjbxxServiceImpl extends ServiceImpl<ITbDkjbxxMapper, TbDkjbxxEntity> implements ITbDkjbxxService {
    private static final String RESOURCE_FILE_PATH = "DB/resource_db.db";
    @Autowired
    private ITbDkjbxxMapper mapper;
    private ITbDkjbxxMapper iTbDkjbxxMapper;
    @Autowired
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    /**
     * 上传DB文件并覆盖之前DB文件,自动读取数据到本地数据库
@@ -53,15 +58,19 @@
     * @param file
     * @return
     */
    public ResponseResult<String> uploadFile(MultipartFile file) {
    public ResponseResult uploadFile(MultipartFile file) {
        if (file.isEmpty()) {
            return ResponseResult.error("所上传的文件为空");
            throw new IllegalArgumentException("上传文件为空");
        }
        boolean fileName = Objects.requireNonNull(file.getOriginalFilename()).endsWith("db");
        if (!fileName) {
            throw new IllegalArgumentException("检查文件是否为db文件");
        }
        try {
            // 获取上传的文件输入流
            InputStream inputStream = file.getInputStream();
            // 创建输出流,将文件内容写入资源文件
            OutputStream outputStream = new FileOutputStream(RESOURCE_FILE_PATH);
            OutputStream outputStream = new FileOutputStream(territoryConfigPojo.getPath());
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -72,7 +81,7 @@
            return ResponseResult.success("文件上传成功");
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.error(e.getMessage()); // 将异常信息包含在响应中返回给客户端
            return ResponseResult.error(e.getMessage());
        }
    }
@@ -89,7 +98,7 @@
     */
    @Transactional
    public MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException {
        List<TbDkjbxxEntity> list = mapper.selectList(null);
        List<TbDkjbxxEntity> list = iTbDkjbxxMapper.selectList(null);
        List<LotInfo> info = dbConvertToEntity(list);
        Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(info, airportLat, airportLon);
        // 创建XML模板模型
@@ -99,8 +108,7 @@
        String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径
        zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
        // 将压缩文件转换为MultipartFile对象
        MultipartFile multipartFile = convert(new File(destKMZFile));
        return multipartFile;
        return convert(new File(destKMZFile));
    }
    /**
@@ -112,6 +120,7 @@
    private List<LotInfo> dbConvertToEntity(List<TbDkjbxxEntity> list) {
        List<LotInfo> infos = new ArrayList<>();
        for (TbDkjbxxEntity file : list) {
            double[] coordinates = extractCoordinates(pointCGCStoWGS(file.getXzb(), file.getYzb()));
            // 使用Builder模式构建LotInfo对象
            LotInfo.LotInfoBuilder builder = LotInfo.builder();
            if (file != null) {
@@ -122,12 +131,12 @@
                        .dkmc(file.getDkmc())
                        .dkbh(file.getDkbh())
                        .xmc(file.getXmc())
                        .xzb(file.getXzb())
                        .xzb(coordinates[0])
                        .sfbhzdk(file.getSfbhzdk())
                        .sjlx(file.getSjlx())
                        .dkfw(file.getDkfw())
                        .dkfw(poylonCGCStoWGS(file.getDkfw()))
                        .xzqdm(file.getXzqdm())
                        .yzb(file.getYzb())
                        .yzb(coordinates[1])
                        .kzxx(file.getKzxx())
                        .dklx(file.getDklx())
                        .build();