| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.se.simu.config.PropertiesConfig; |
| | | import com.se.simu.domain.dto.GeDb; |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.domain.po.SimuPo; |
| | | import com.se.simu.domain.vo.CreateSimuVo; |
| | |
| | | import com.se.simu.mapper.SimuMapper; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.sql.Timestamp; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class SimuService { |
| | | @Value("${sys.path.in}") |
| | | String inPath; |
| | | |
| | | @Value("${sys.path.out}") |
| | | String outPath; |
| | | |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | |
| | | @Resource |
| | | GedbService gedbService; |
| | | |
| | | @Resource |
| | | UwService uwService; |
| | | |
| | | @Resource |
| | | ResultService resultService; |
| | | |
| | | /** |
| | | * 获取 |
| | |
| | | DataPo dp = JSONUtil.toBean(po.getData(), DataPo.class); |
| | | if (null == dp) continue; |
| | | |
| | | delDir(inPath + File.separator + dp.getInPath()); |
| | | delDir(outPath + File.separator + dp.getOutPath()); |
| | | delDir(config.getInPath() + File.separator + dp.getInPath()); |
| | | delDir(config.getOutPath() + File.separator + dp.getOutPath()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | |
| | | return simuMapper.selectMaxId(); |
| | | } |
| | | |
| | | public boolean create(CreateSimuVo vo) { |
| | | DataPo data = BeanUtil.copyProperties(vo, DataPo.class); |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | // |
| | | public SimuPo getSimuByPid(Integer pid) { |
| | | QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", pid); |
| | | wrapper.last("limit 1"); |
| | | |
| | | return true; |
| | | return simuMapper.selectOne(wrapper); |
| | | } |
| | | |
| | | public boolean create(CreateSimuVo vo) { |
| | | Date now = new Date(); |
| | | String date = StringHelper.YMDHMS2_FORMAT.format(now); |
| | | if (StringHelper.isEmpty(vo.getName())) { |
| | | vo.setName(date); |
| | | } |
| | | |
| | | DataPo data = BeanUtil.copyProperties(vo, DataPo.class); |
| | | data.setPath(date, date); |
| | | initPath(data); |
| | | |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | simu.setCreateTime(new Timestamp(now.getTime())); |
| | | |
| | | int rows = simuMapper.insert(simu); |
| | | if (rows > 0) { |
| | | asyncCall(simu); |
| | | } |
| | | |
| | | return rows > 0; |
| | | } |
| | | |
| | | private void initPath(DataPo data) { |
| | | createDir(config.getInPath() + File.separator + data.getInPath()); |
| | | createDir(config.getOutPath() + File.separator + data.getOutPath()); |
| | | } |
| | | |
| | | private void createDir(String path) { |
| | | File f = new File(path); |
| | | if (f.exists() && f.isDirectory()) { |
| | | FileUtil.del(f); |
| | | } |
| | | f.mkdirs(); |
| | | } |
| | | |
| | | private void asyncCall(SimuPo simu) { |
| | |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | scopeTask(simu); |
| | | cope(simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | private void scopeTask(SimuPo simu) { |
| | | /** |
| | | * 处理数据,状态标识: |
| | | * 0-创建仿真任务,1-连接GEDB库,2-下载空间数据,3-下载高程数据, |
| | | * 4-生成降雨文件,5-生成配置文件,6-模拟内涝仿真,7-处理水位文件, |
| | | * 8-处理排水文件,9-处理仿真结果,10-完成,-10-出错 |
| | | */ |
| | | private void cope(SimuPo simu) { |
| | | try { |
| | | DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); |
| | | |
| | | update(simu, 1, null); |
| | | String token = gedbService.getToken(); |
| | | GeDb db = gedbService.connectGedb(token, data); |
| | | simu.setData(JSONUtil.toJsonStr(data)); |
| | | |
| | | //boolean flag = tifService.splitTif(dsd); |
| | | //update(simu, flag ? 2 : 20, flag ? null : "切分数据出错"); |
| | | //if (!flag) return; |
| | | update(simu, 2, null); |
| | | gedbService.copeVectors(token, data, db); |
| | | |
| | | //flag = aiService.sendRequest(task.getDataType(), dsd.getDataTime()); |
| | | //update(simu, flag ? 3 : 20, flag ? null : "识别数据出错"); |
| | | //if (!flag) return; |
| | | update(simu, 3, null); |
| | | gedbService.copeDem(token, data); |
| | | |
| | | //flag = geoJsonService.processResults(task, dsd); |
| | | //update(simu, flag ? 10 : 20, flag ? "执行完成" : "处理结果出错"); |
| | | update(simu, 4, null); |
| | | uwService.createRainFile(data); |
| | | |
| | | update(simu, 5, null); |
| | | uwService.createConfig(data); |
| | | |
| | | update(simu, 6, null); |
| | | uwService.callExe(data); |
| | | |
| | | update(simu, 7, null); |
| | | //uwService.copeWaterFiles(); |
| | | |
| | | update(simu, 8, null); |
| | | uwService.copeDrainFiles(data); |
| | | |
| | | update(simu, 9, null); |
| | | resultService.process(data); |
| | | |
| | | update(simu, 10, "完成"); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | update(simu, -10, ex.getMessage()); |
| | | update(simu, -simu.getStatus(), ex.getMessage()); |
| | | } |
| | | } |
| | | |