| | |
| | | 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.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.domain.vo.SimuVo; |
| | | import com.se.simu.helper.StringHelper; |
| | | import com.se.simu.helper.WebHelper; |
| | | 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 javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | /** |
| | | * 仿真服务类 |
| | |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | | public Integer getMaxId() { |
| | | return simuMapper.selectMaxId(); |
| | | @Resource |
| | | GedbService gedbService; |
| | | |
| | | /** |
| | | * 获取 |
| | | */ |
| | | public IPage<SimuPo> get(SimuVo vo) { |
| | | QueryWrapper<SimuPo> wrapper = getPageWrapper(vo); |
| | | |
| | | Page<SimuPo> page = new Page<>(vo.getPageIndex(), vo.getPageSize()); |
| | | page.addOrder(OrderItem.desc("id")); |
| | | |
| | | IPage<SimuPo> paged = simuMapper.selectPage(page, wrapper); |
| | | |
| | | return paged; |
| | | } |
| | | |
| | | 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()); |
| | | // |
| | | private QueryWrapper<SimuPo> getPageWrapper(SimuVo vo) { |
| | | QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); |
| | | if (null != vo.getId()) { |
| | | wrapper.eq("id", vo.getId()); |
| | | } |
| | | if (null != vo.getPid()) { |
| | | wrapper.eq("pid", vo.getPid()); |
| | | } |
| | | if (null != vo.getNum()) { |
| | | wrapper.eq("num", vo.getNum()); |
| | | } |
| | | if (!StringUtils.isEmpty(vo.getName())) { |
| | | wrapper.like("lower(name)", vo.getName().trim().toLowerCase()); |
| | | } |
| | | if (!CollUtil.isEmpty(vo.getStatus())) { |
| | | wrapper.in("status", vo.getStatus()); |
| | | } |
| | | |
| | | return true; |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | |
| | | return FileUtil.del(dir); |
| | | } |
| | | |
| | | /** |
| | | * 获取 |
| | | */ |
| | | public IPage<SimuPo> get(SimuVo vo) { |
| | | QueryWrapper<SimuPo> wrapper = getPageWrapper(vo); |
| | | |
| | | Page<SimuPo> page = new Page<>(vo.getPageIndex(), vo.getPageSize()); |
| | | page.addOrder(OrderItem.desc("id")); |
| | | |
| | | IPage<SimuPo> paged = simuMapper.selectPage(page, wrapper); |
| | | |
| | | return paged; |
| | | public Integer getMaxId() { |
| | | return simuMapper.selectMaxId(); |
| | | } |
| | | |
| | | private QueryWrapper<SimuPo> getPageWrapper(SimuVo vo) { |
| | | public SimuPo getSimuByPid(Integer pid) { |
| | | QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); |
| | | if (null != vo.getId()) { |
| | | wrapper.eq("id", vo.getId()); |
| | | } |
| | | if (null != vo.getPid()) { |
| | | wrapper.eq("pid", vo.getPid()); |
| | | } |
| | | if (null != vo.getNum()) { |
| | | wrapper.eq("num", vo.getNum()); |
| | | } |
| | | if (!StringUtils.isEmpty(vo.getName())) { |
| | | wrapper.like("lower(name)", vo.getName().trim().toLowerCase()); |
| | | } |
| | | if (!CollUtil.isEmpty(vo.getStatus())) { |
| | | wrapper.in("status", vo.getStatus()); |
| | | wrapper.eq("pid", pid); |
| | | |
| | | return simuMapper.selectOne(wrapper); |
| | | } |
| | | |
| | | public boolean create(CreateSimuVo vo) { |
| | | DataPo data = BeanUtil.copyProperties(vo, DataPo.class); |
| | | data.setPath(vo.getName(), vo.getName()); |
| | | initPath(data); |
| | | |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | |
| | | int rows = simuMapper.insert(simu); |
| | | if (rows > 0) { |
| | | asyncCall(simu); |
| | | } |
| | | |
| | | return wrapper; |
| | | return rows > 0; |
| | | } |
| | | |
| | | private void initPath(DataPo data) { |
| | | createDir(inPath + File.separator + data.getInPath()); |
| | | createDir(outPath + 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) { |
| | | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | scope(simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | /** |
| | | * 处理,状态:0-创建仿真,1-连接GEDB库,2-下载空间数据,3-下载高程数据,4-模拟内涝仿真,5-处理仿真数据,10-完成,-10-出错 |
| | | */ |
| | | private void scope(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)); |
| | | |
| | | update(simu, 2, null); |
| | | gedbService.copeVectors(token, data, db); |
| | | |
| | | update(simu, 3, null); |
| | | gedbService.copeDem(token, data); |
| | | |
| | | update(simu, 4, null); |
| | | // 模拟内涝仿真 |
| | | |
| | | //update(simu, 5, null); |
| | | // 处理仿真数据 |
| | | |
| | | //update(simu, 10, "完成"); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | update(simu, -10, ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void update(SimuPo simu, int status, String rs) { |
| | | simu.setStatus(status); |
| | | if (null != rs) simu.setResult(rs); |
| | | simu.setUpdateTime(WebHelper.getCurrentTimestamp()); |
| | | |
| | | simuMapper.updateById(simu); |
| | | } |
| | | } |