| | |
| | | package org.jeecg.modules.msi.webapi.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.util.JdbcUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.modules.msi.webapi.entity.MsiWebapiJsonEntity; |
| | |
| | | import org.jeecg.modules.msi.webapi.service.IMsiWebapiJsonService; |
| | | import org.jeecg.modules.msi.webapi.vo.DetailedListVo; |
| | | import org.jeecg.modules.msi.webapi.vo.MachineEquipentInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.jdbc.datasource.DataSourceUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | @Service |
| | | public class MsiWebapiJsonServiceImpl extends ServiceImpl<MsiWebapiJsonMapper, MsiWebapiJsonEntity> implements IMsiWebapiJsonService { |
| | | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | /** |
| | | * 解析单条数据保存到单表 |
| | | * @param data |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean saveTableAutomationOne(List<MachineEquipentInfo> data) { |
| | | if (data ==null || data.isEmpty()) { |
| | |
| | | listParameter.add(parameter); |
| | | } |
| | | } |
| | | //状态数据 |
| | | // 执行状态数据SQL |
| | | try { |
| | | executeBatchSql(listStatus); |
| | | executeBatchSql(listParameter); |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error("执行SQL批量插入失败", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | /** |
| | | * 批量执行SQL语句 |
| | | * @param sqlList SQL语句列表 |
| | | * @throws SQLException |
| | | */ |
| | | private void executeBatchSql(List<String> sqlList) throws SQLException { |
| | | if (CollectionUtils.isEmpty(sqlList)) { |
| | | return; |
| | | } |
| | | |
| | | Connection connection = null; |
| | | Statement statement = null; |
| | | |
| | | try { |
| | | connection = DataSourceUtils.getConnection(jdbcTemplate.getDataSource()); |
| | | connection.setAutoCommit(false); |
| | | statement = connection.createStatement(); |
| | | |
| | | for (String sql : sqlList) { |
| | | statement.addBatch(sql); |
| | | } |
| | | |
| | | statement.executeBatch(); |
| | | connection.commit(); |
| | | } catch (SQLException e) { |
| | | if (connection != null) { |
| | | connection.rollback(); |
| | | } |
| | | throw e; |
| | | } finally { |
| | | JdbcUtils.closeStatement(statement); |
| | | DataSourceUtils.releaseConnection(connection, jdbcTemplate.getDataSource()); |
| | | } |
| | | } |
| | | |
| | | |