From 3417cf014a65765e02696c1d121ce58b2b4a8aed Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 08 四月 2025 15:55:36 +0800 Subject: [PATCH] 修改pom.xml --- src/main/java/com/se/simu/service/SimuService.java | 230 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 171 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/se/simu/service/SimuService.java b/src/main/java/com/se/simu/service/SimuService.java index 5ae433c..435d1e5 100644 --- a/src/main/java/com/se/simu/service/SimuService.java +++ b/src/main/java/com/se/simu/service/SimuService.java @@ -8,88 +8,46 @@ 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.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 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") public class SimuService { - @Value("${sys.path.in}") - String inPath; - - @Value("${sys.path.out}") - String outPath; - @Resource SimuMapper simuMapper; - public Integer getMaxId() { - return simuMapper.selectMaxId(); - } + @Resource + PropertiesConfig config; - 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()); - // + @Resource + GedbService gedbService; - return true; - } + @Resource + UwService uwService; - /** - * 鍒犻櫎 - */ - public int del(List<Integer> ids) { - List<SimuPo> list = simuMapper.selectBatchIds(ids); - if (null != list && list.size() > 0) { - for (SimuPo po : list) { - try { - if (StringHelper.isEmpty(po.getData())) continue; + @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()); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - } - - return simuMapper.deleteBatchIds(ids); - } - - private boolean delDir(String dir) { - File file = new File(dir); - if (!file.exists() || !file.isDirectory()) { - return false; - } - - return FileUtil.del(dir); - } - - /** - * 鑾峰彇 - */ public IPage<SimuPo> get(SimuVo vo) { QueryWrapper<SimuPo> wrapper = getPageWrapper(vo); @@ -112,7 +70,7 @@ 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())) { @@ -121,4 +79,158 @@ return wrapper; } + + public int del(List<Integer> ids) { + List<SimuPo> list = simuMapper.selectBatchIds(ids); + if (null != list && list.size() > 0) { + for (SimuPo po : list) { + try { + if (StringHelper.isEmpty(po.getData())) continue; + + DataPo dp = JSONUtil.toBean(po.getData(), DataPo.class); + if (null == dp) continue; + + 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); + } + } + } + + return simuMapper.deleteBatchIds(ids); + } + + private boolean delDir(String dir) { + File file = new File(dir); + if (!file.exists() || !file.isDirectory()) { + return false; + } + + return FileUtil.del(dir); + } + + public Integer getMaxId() { + return simuMapper.selectMaxId(); + } + + public SimuPo getSimuByPid(Integer pid) { + QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); + 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(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) { + 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) { + ExecutorService executor = Executors.newSingleThreadExecutor(); + executor.execute(new Runnable() { + @Override + @SneakyThrows + public void run() { + cope(simu); + } + }); + executor.shutdown(); + } + + 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)); + + update(simu, 2, null); + gedbService.copeVectors(token, data, db); + + update(simu, 3, null); + gedbService.copeDem(token, data); + + 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, -simu.getStatus(), 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); + } } -- Gitblit v1.9.3