All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.mingsoft.init.biz.impl.ModelTableBizImpl Maven / Gradle / Ivy

/**
The MIT License (MIT) * Copyright (c) 2019 铭飞科技

 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package net.mingsoft.init.biz.impl;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSON;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.SpringUtil;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import net.mingsoft.init.entity.ModelTableEntity;
import net.mingsoft.init.biz.IModelTableBiz;
import net.mingsoft.init.dao.IModelTableDao;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;

/**
 * 模块列表管理持久化层
 * @author 铭飞科技
 * 创建日期:2020-5-29 16:04:15
* 历史修订:
*/ @Service("initmodelTableBizImpl") @Transactional public class ModelTableBizImpl extends BaseBizImpl implements IModelTableBiz { @Autowired private IModelTableDao modelTableDao; @Autowired private DataSource dataSource; @Override protected IBaseDao getDao() { // TODO Auto-generated method stub return modelTableDao; } @Override public void execute(String id) { ModelTableEntity modelTableEntity = (ModelTableEntity)modelTableDao.getEntity(Integer.parseInt(id)); if(modelTableEntity!=null&& StrUtil.isNotBlank(modelTableEntity.getMtFiles())){ //解析文件JSON List maps = JSON.parseArray(modelTableEntity.getMtFiles(), Map.class); for (Map file: maps) { try { //创建执行对象 ScriptRunner runner = new ScriptRunner(dataSource.getConnection()); //设置全部执行 runner.setSendFullScript(true); FileReader reader = null; File path = FileUtil.file(BasicUtil.getRealPath(file.get("path").toString())); //文件不存在则跳过 if(path.exists()){ reader = new FileReader(path); runner.runScript(reader); reader.close(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy