rain
2024-04-18 3dae83e56bbdef77404be7b47d19136bb8251c8c
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -10,11 +10,13 @@
import com.dji.sample.patches.utils.ShapeFileUtil;
import com.dji.sample.patches.xml.mode.XMLTemplateModel;
import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@@ -42,7 +44,7 @@
    @Autowired
    private PatchesConfigPojo patchesConfigPojo;
    @Transactional
    public MultipartFile insertGeo(MultipartFile file, String workspaceId, String waylineName, double airportLat, double airportLon) throws Exception {
        List<LotInfo> list = new ArrayList<>();
        File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip());
@@ -74,8 +76,45 @@
        String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径
        zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
        multipartFile = convert(new File(destKMZFile));
        MultipartFileTOFileUtil.deleteFile(file1);
        return multipartFile;
    }
    @Transactional
    public void savaInMysql(List<TbDkjbxxEntity> list,String workspaceId){
        for (int i = 0; i <list.size() ; i++) {
            LotInfo lotInfo = new LotInfo();
            lotInfo.setWorkspaceId(workspaceId);
            lotInfo=dbConvertToEntity(list.get(i),workspaceId);
            mapper.insert(lotInfo);
        }
    }
    /**
     * 将SQlite数据库中DKJBXX对象转换为LotInfo对象。
     * @param file 需要转换的DKJBXX对象。
     * @return 返回一个构建好的LotInfo对象,包含从数据库实体中转换来的信息。
     */
    private LotInfo dbConvertToEntity(TbDkjbxxEntity file,String workspaceId) {
        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())
                    .workspaceId(workspaceId)
                    .build();
        }
        return builder.build();
    }
}