增加数据处理测试方法,增加列表方法
This commit is contained in:
parent
4dda3065aa
commit
6d401e5b06
@ -28,6 +28,18 @@
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.22</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -148,4 +148,5 @@ public class AreaController extends DefaultBaseController {
|
||||
return areaService.listByCode(areaCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import ink.wgink.module.dictionary.pojo.dtos.AreaDTO;
|
||||
import ink.wgink.pojo.dtos.ZTreeDTO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -38,6 +39,14 @@ public interface IAreaDao extends IInitBaseTable {
|
||||
*/
|
||||
void remove(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 删除地区字典
|
||||
*
|
||||
* @param params
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void delete(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 修改地区字典
|
||||
*
|
||||
|
@ -72,6 +72,13 @@ public interface IAreaService {
|
||||
*/
|
||||
AreaDTO getByCode(String areaCode);
|
||||
|
||||
/**
|
||||
* 地区列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<AreaDTO> list();
|
||||
|
||||
/**
|
||||
* 通过上级ID获取地区字典列表
|
||||
*
|
||||
@ -119,4 +126,5 @@ public interface IAreaService {
|
||||
* @return
|
||||
*/
|
||||
List<AreaDTO> listSubByCode(String areaCode);
|
||||
|
||||
}
|
||||
|
@ -62,6 +62,13 @@ public interface IDataService extends IDictionaryCheckService {
|
||||
*/
|
||||
DataDTO get(String dataId);
|
||||
|
||||
/**
|
||||
* 字典列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<DataDTO> list();
|
||||
|
||||
/**
|
||||
* 通过上级ID获取字典列表
|
||||
*
|
||||
@ -101,4 +108,5 @@ public interface IDataService extends IDictionaryCheckService {
|
||||
* @return
|
||||
*/
|
||||
List<DataDTO> listByCode(String dataCode);
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,12 @@ public class AreaServiceImpl extends DefaultBaseService implements IAreaService
|
||||
return areaDao.get(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AreaDTO> list() {
|
||||
Map<String, Object> params = getHashMap(0);
|
||||
return areaDao.list(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AreaDTO> listByParentId(String areaParentId) {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
|
@ -82,6 +82,12 @@ public class DataServiceImpl extends DefaultBaseService implements IDataService
|
||||
return dataDao.get(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDTO> list() {
|
||||
Map<String, Object> params = getHashMap(0);
|
||||
return dataDao.list(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDTO> listByParentId(String dataParentId) {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
|
@ -66,7 +66,7 @@
|
||||
var setting = {
|
||||
async: {
|
||||
enable: true,
|
||||
autoLoad: true,
|
||||
autoLoad: false,
|
||||
type: 'get',
|
||||
url: top.restAjax.path('api/area/listztree', []),
|
||||
autoParam: ['id'],
|
||||
@ -88,6 +88,14 @@
|
||||
},
|
||||
};
|
||||
var zTree = $.fn.zTree.init($("#leftTree"), setting);
|
||||
zTree.addNodes(null, {
|
||||
id: '0',
|
||||
pId: '-1',
|
||||
name: top.dataMessage.tree.rootName,
|
||||
url: 'javascript:;',
|
||||
isParent: 'true'
|
||||
});
|
||||
common.refreshTree('leftTree');
|
||||
}
|
||||
initSize();
|
||||
initIFrame();
|
||||
|
54
module-dictionary/src/test/java/AreaTest.java
Normal file
54
module-dictionary/src/test/java/AreaTest.java
Normal file
@ -0,0 +1,54 @@
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @ClassName: AreaTest
|
||||
* @Description: 地区测试
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/11/24 3:25 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class AreaTest {
|
||||
|
||||
private String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/db_smart_city_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUnnecessaryAreas() throws SQLException {
|
||||
Connection connection = DriverManager.getConnection(jdbcUrl, "root", "root");
|
||||
String SQL = "DELETE FROM data_area WHERE area_code NOT LIKE ?";
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(SQL)) {
|
||||
// 保留的根节点编码
|
||||
preparedStatement.setString(1, "1509%");
|
||||
System.out.println(preparedStatement);
|
||||
int removeCount = preparedStatement.executeUpdate();
|
||||
System.out.println("删除总数:" + removeCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateAreaRootParentId() throws SQLException {
|
||||
Connection connection = DriverManager.getConnection(jdbcUrl, "root", "root");
|
||||
String SQL = "UPDATE data_area SET area_parent_id = 0 WHERE area_code = ?";
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(SQL)) {
|
||||
// 设置更新的地区编码
|
||||
preparedStatement.setString(1, "150900000000");
|
||||
System.out.println(preparedStatement);
|
||||
int updateCount = preparedStatement.executeUpdate();
|
||||
System.out.println("更新成功:" + updateCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
92
module-dictionary/src/test/java/DataTest.java
Normal file
92
module-dictionary/src/test/java/DataTest.java
Normal file
@ -0,0 +1,92 @@
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @ClassName: DataTest
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/11/24 4:09 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DataTest {
|
||||
|
||||
private String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/db_smart_city_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertJson() throws Exception {
|
||||
Connection connection = DriverManager.getConnection(jdbcUrl, "root", "root");
|
||||
String jsonArrayFilePath = "/Users/wanggeng/Desktop/9+x-房屋-任务系统字典.txt";
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(jsonArrayFilePath)));
|
||||
StringBuilder jsonArraySB = new StringBuilder();
|
||||
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
||||
jsonArraySB.append(line);
|
||||
}
|
||||
if (jsonArraySB.length() == 0) {
|
||||
return;
|
||||
}
|
||||
String gmtDate = DateUtil.getTime();
|
||||
String SQL = "INSERT INTO `data_data` (" +
|
||||
"`data_id`, " +
|
||||
"`data_parent_id`, " +
|
||||
"`data_name`, " +
|
||||
"`data_summary`, " +
|
||||
"`data_code`, " +
|
||||
"`data_sort`, " +
|
||||
"`creator`, " +
|
||||
"`gmt_create`, " +
|
||||
"`modifier`, " +
|
||||
"`gmt_modified`, " +
|
||||
"`is_delete`) " +
|
||||
"VALUES (?, ? ,? ,? ,? ,? ,'1' ,'" + gmtDate + "', '1', '" + gmtDate + "', '0');";
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(SQL)) {
|
||||
JSONArray jsonArray = JSONArray.parseArray(jsonArraySB.toString());
|
||||
insertDatas(jsonArray, 53, "", preparedStatement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
*
|
||||
* @param jsonArray
|
||||
* @param parentCode
|
||||
* @param preparedStatement
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void insertDatas(JSONArray jsonArray, int lastIndex, String parentCode, PreparedStatement preparedStatement) throws SQLException {
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
int dataSort = lastIndex + (i + 1);
|
||||
String dataCode = String.format("%s%04d", parentCode, dataSort);
|
||||
preparedStatement.setString(1, jsonObject.getString("dataId"));
|
||||
preparedStatement.setString(2, jsonObject.getString("dataParentId"));
|
||||
preparedStatement.setString(3, jsonObject.getString("dataName"));
|
||||
preparedStatement.setString(4, jsonObject.getString("dataSummary"));
|
||||
preparedStatement.setString(5, dataCode);
|
||||
preparedStatement.setInt(6, dataSort);
|
||||
preparedStatement.executeUpdate();
|
||||
JSONArray subDatas = jsonObject.getJSONArray("subData");
|
||||
if (!subDatas.isEmpty()) {
|
||||
insertDatas(subDatas, 0, dataCode, preparedStatement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user