| | |
| | | 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.dto.GeLayer; |
| | | 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; |
| | | |
| | | /** |
| | | * 仿真服务类 |
| | | * |
| | | * @author WWW |
| | | * @date 2024-09-18 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | |
| | | @Resource |
| | | GedbService gedbService; |
| | | |
| | | /** |
| | | * 获取 |
| | | */ |
| | | @Resource |
| | | UwService uwService; |
| | | |
| | | @Resource |
| | | ResultService resultService; |
| | | |
| | | public IPage<SimuPo> get(SimuVo vo) { |
| | | QueryWrapper<SimuPo> wrapper = getPageWrapper(vo); |
| | | |
| | |
| | | if (null != vo.getNum()) { |
| | | wrapper.eq("num", vo.getNum()); |
| | | } |
| | | if (!StringUtils.isEmpty(vo.getName())) { |
| | | if (!StringHelper.isEmpty(vo.getName())) { |
| | | wrapper.like("lower(name)", vo.getName().trim().toLowerCase()); |
| | | } |
| | | if (!CollUtil.isEmpty(vo.getStatus())) { |
| | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | public int del(List<Integer> ids) { |
| | | List<SimuPo> list = simuMapper.selectBatchIds(ids); |
| | | if (null != list && list.size() > 0) { |
| | |
| | | |
| | | delDir(config.getInPath() + File.separator + dp.getInPath()); |
| | | delDir(config.getOutPath() + File.separator + dp.getOutPath()); |
| | | FileUtil.del(config.getInPath() + File.separator + dp.getInPath() + ".json"); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | |
| | | |
| | | public SimuPo getSimuByPid(Integer pid) { |
| | | QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("pid", pid); |
| | | wrapper.eq("id", pid); |
| | | wrapper.last("limit 1"); |
| | | |
| | | return simuMapper.selectOne(wrapper); |
| | | } |
| | | public SimuPo getSimuById(Integer id) { |
| | | return simuMapper.selectById(id); |
| | | } |
| | | |
| | | public SimuPo getSimuByServiceName(String serviceName) { |
| | | if (StringHelper.isEmpty(serviceName)) { |
| | | return null; |
| | | } |
| | | |
| | | QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("service_name", serviceName); |
| | | wrapper.last("limit 1"); |
| | | |
| | | 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(vo.getName(), vo.getName()); |
| | | data.setPath(date, date); |
| | | initPath(data); |
| | | |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | simu.setServiceName(date); |
| | | simu.setCreateTime(new Timestamp(now.getTime())); |
| | | |
| | | int rows = simuMapper.insert(simu); |
| | | if (rows > 0) { |
| | |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | scope(simu); |
| | | cope(simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | /** |
| | | * 处理,状态:0-创建仿真,1-连接GEDB库,2-下载空间数据,3-下载高程数据,4-模拟内涝仿真,5-处理仿真数据,10-完成,-10-出错 |
| | | */ |
| | | private void scope(SimuPo simu) { |
| | | private void cope(SimuPo simu) { |
| | | try { |
| | | DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); |
| | | |
| | |
| | | gedbService.copeDem(token, data); |
| | | |
| | | update(simu, 4, null); |
| | | // 模拟内涝仿真 |
| | | uwService.createRainFile(data); |
| | | |
| | | //update(simu, 5, null); |
| | | // 处理仿真数据 |
| | | update(simu, 5, null); |
| | | uwService.createConfig(data); |
| | | |
| | | //update(simu, 10, "完成"); |
| | | 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()); |
| | | } |
| | | } |
| | | |