| | |
| | | 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(); |
| | | /** |
| | | * 获取 |
| | | */ |
| | | 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) { |
| | | 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()); |
| | | } |
| | | 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()); |
| | | // |
| | | |
| | | return wrapper; |
| | | return true; |
| | | } |
| | | |
| | | private void asyncCall(SimuPo simu) { |
| | | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | scopeTask(simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | private void scopeTask(SimuPo simu) { |
| | | try { |
| | | DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); |
| | | update(simu, 1, null); |
| | | |
| | | //boolean flag = tifService.splitTif(dsd); |
| | | //update(simu, flag ? 2 : 20, flag ? null : "切分数据出错"); |
| | | //if (!flag) return; |
| | | |
| | | //flag = aiService.sendRequest(task.getDataType(), dsd.getDataTime()); |
| | | //update(simu, flag ? 3 : 20, flag ? null : "识别数据出错"); |
| | | //if (!flag) return; |
| | | |
| | | //flag = geoJsonService.processResults(task, dsd); |
| | | //update(simu, flag ? 10 : 20, flag ? "执行完成" : "处理结果出错"); |
| | | } 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); |
| | | } |
| | | } |