|
@@ -1,64 +1,23 @@
|
|
package com.github.zuihou.business.typeHandler;
|
|
package com.github.zuihou.business.typeHandler;
|
|
|
|
|
|
|
|
|
|
-import com.alibaba.druid.pool.DruidDataSource;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.baidubce.util.JsonUtils;
|
|
import com.baidubce.util.JsonUtils;
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
|
|
-import com.github.zuihou.common.util.StringUtil;
|
|
|
|
-import com.github.zuihou.context.BaseContextHandler;
|
|
|
|
-import lombok.Data;
|
|
|
|
import org.apache.ibatis.type.BaseTypeHandler;
|
|
import org.apache.ibatis.type.BaseTypeHandler;
|
|
import org.apache.ibatis.type.JdbcType;
|
|
import org.apache.ibatis.type.JdbcType;
|
|
import org.apache.ibatis.type.MappedJdbcTypes;
|
|
import org.apache.ibatis.type.MappedJdbcTypes;
|
|
import org.apache.ibatis.type.MappedTypes;
|
|
import org.apache.ibatis.type.MappedTypes;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
-import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
-import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
-import javax.sql.DataSource;
|
|
|
|
-import java.sql.*;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.sql.CallableStatement;
|
|
|
|
+import java.sql.PreparedStatement;
|
|
|
|
+import java.sql.ResultSet;
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
|
|
|
|
|
|
@MappedTypes(ResourceAutoCode.class)
|
|
@MappedTypes(ResourceAutoCode.class)
|
|
@MappedJdbcTypes(JdbcType.VARCHAR)
|
|
@MappedJdbcTypes(JdbcType.VARCHAR)
|
|
-@Configuration
|
|
|
|
-@Component
|
|
|
|
public class ResourceAutoCodeHandler extends BaseTypeHandler<ResourceAutoCode> {
|
|
public class ResourceAutoCodeHandler extends BaseTypeHandler<ResourceAutoCode> {
|
|
|
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
|
-
|
|
|
|
- private static String url;
|
|
|
|
- @Value("${zuihou.mysql.url}")
|
|
|
|
- public void setUrl(String url) {
|
|
|
|
- this.url = url;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static String username;
|
|
|
|
- @Value("${zuihou.mysql.username}")
|
|
|
|
- public void setUsername(String username) {
|
|
|
|
- this.username = username;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static String password;
|
|
|
|
- @Value("${zuihou.mysql.password}")
|
|
|
|
- public void setPassword(String password) {
|
|
|
|
- this.password = password;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static String driverClassName;
|
|
|
|
- @Value("${zuihou.mysql.driverClassName}")
|
|
|
|
- public void setDriverClassName(String driverClassName) {
|
|
|
|
- this.driverClassName = driverClassName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void setNonNullParameter(PreparedStatement preparedStatement, int i, ResourceAutoCode resourceAutoCode, JdbcType jdbcType) throws SQLException {
|
|
public void setNonNullParameter(PreparedStatement preparedStatement, int i, ResourceAutoCode resourceAutoCode, JdbcType jdbcType) throws SQLException {
|
|
preparedStatement.setString(i, resourceAutoCode.getId().toString());
|
|
preparedStatement.setString(i, resourceAutoCode.getId().toString());
|
|
@@ -66,17 +25,7 @@ public class ResourceAutoCodeHandler extends BaseTypeHandler<ResourceAutoCode> {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResourceAutoCode getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
|
|
public ResourceAutoCode getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
|
|
- //return resourceAutoCodeService.getById(resultSet.getString(columnName));
|
|
|
|
- String id = resultSet.getString(columnName);
|
|
|
|
- String sql = "select * from zuihou_base_yj_0000.imcs_resource_autocode where id="+ id;
|
|
|
|
- DruidDataSource dataSource = new DruidDataSource();
|
|
|
|
- dataSource.setUrl(this.url);
|
|
|
|
- dataSource.setUsername(this.username);
|
|
|
|
- dataSource.setPassword(this.password);
|
|
|
|
- dataSource.setDriverClassName(this.driverClassName);
|
|
|
|
- jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
|
- ResourceAutoCode resourceAutoCode = jdbcTemplate.queryForObject(sql, new Object[]{},new BeanPropertyRowMapper<ResourceAutoCode>(ResourceAutoCode.class));
|
|
|
|
- return resourceAutoCode;
|
|
|
|
|
|
+ return ResourceAutoCode.builder().id(resultSet.getLong(columnName)).build();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|