| | |
| | | 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); |
| | | |
| | |
| | | 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) { |
| | | 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); |
| | | } |
| | | } |