|
- package com.ningdatech.kqapi.menu;
-
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.ningdatech.kqapi.AppTests;
- import com.ningdatech.kqapi.zzsfw.entity.entity.DscSxAdsShareItemQltQlsxCommonIDVKq;
- import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMenu;
- import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum;
- import com.ningdatech.kqapi.zzsfw.service.IDscSxAdsShareItemQltQlsxCommonIDVKqService;
- import com.ningdatech.kqapi.zzsfw.service.INdKqZzsfwMenuService;
- import org.apache.poi.ss.usermodel.*;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.junit.Assert;
- import org.junit.Test;
- import org.springframework.beans.factory.annotation.Autowired;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- import java.text.DecimalFormat;
- import java.time.LocalDateTime;
- import java.util.Objects;
-
- /**
- * @Classname MenuTest
- * @Description
- * @Date 2023/10/27 9:51
- * @Author PoffyZhang
- */
- public class MenuTest extends AppTests{ //
-
- @Autowired
- private INdKqZzsfwMenuService menuService;
-
- @Test
- public void test() throws IOException {
- FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\11.14柯桥.xlsx");
- Workbook workbook = new XSSFWorkbook(fis);
- Assert.assertNotNull(workbook);
- Row row;
- if (workbook != null) {
- //获取最大行数
- Sheet sheet = workbook.getSheetAt(0);
- int rownum = sheet.getPhysicalNumberOfRows();
- //获取第一行
- row = sheet.getRow(0);
- //获取最大列数
- Integer num = 1;
-
- menuService.remove(Wrappers.lambdaQuery(NdKqZzsfwMenu.class));
-
- for (int i = 2; i < rownum; i++) {
- row = sheet.getRow(i);
- if(row.getZeroHeight()){
- continue;
- }
- System.out.println("记数:" + (num++));
- System.out.println(row.getCell(0).getStringCellValue());
- System.out.println(row.getCell(1).getStringCellValue());
- System.out.println(row.getCell(2).getStringCellValue());
- Double numericCellValue = row.getCell(3).getNumericCellValue();
- String itemName = row.getCell(4).getStringCellValue();
- System.out.println(itemName);
-
- NdKqZzsfwMenu menu = new NdKqZzsfwMenu();
- menu.setItemName(itemName);
- menu.setZoneName(row.getCell(0).getStringCellValue());
- menu.setWindow(row.getCell(1).getStringCellValue());
- menu.setCreateOn(LocalDateTime.now());
- menu.setDepartment(row.getCell(2).getStringCellValue());
- menu.setSort(numericCellValue.intValue());
-
- //去查询 url
- // DscSxAdsShareItemQltQlsxCommonIDVKq item = itemQltQlsxCommonIDVKqService.getOne(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class)
- // .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getRowguid, DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl, DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName)
- // .eq(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, itemName)
- // .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl)
- // .last("limit 1"));
- // if(Objects.nonNull(item)){
- menu.setHasUrl(1);
- // menu.setWebapplyurl(item.getWebapplyurl());
- // menu.setItemRowid(item.getRowguid());
- // }
-
- menuService.save(menu);
- }
- }
- }
-
-
- @Test
- public void importData() throws IOException {
- FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\增值服务数据20240403.xlsx");
- Workbook workbook = new XSSFWorkbook(fis);
- Assert.assertNotNull(workbook);
- Row row;
- if (workbook != null) {
- //获取最大行数
- Sheet sheet = workbook.getSheetAt(0);
- int rownum = sheet.getPhysicalNumberOfRows();
- //获取第一行
- row = sheet.getRow(0);
- //获取最大列数
- Integer num = 1;
-
- for (int i = 2; i < rownum; i++) {
- row = sheet.getRow(i);
- if (row.getZeroHeight()) {
- continue;
- }
- System.out.println("记数:" + (num++));
- String zoneName = row.getCell(0).getStringCellValue();
- System.out.println(zoneName);
- DecimalFormat decimalFormat = new DecimalFormat("#");
- Integer sort = Integer.valueOf(decimalFormat.format(row.getCell(1).getNumericCellValue()));
- System.out.println(sort);
- String windowName = row.getCell(2).getStringCellValue();
- System.out.println(windowName);
- String department = row.getCell(3).getStringCellValue();
- System.out.println(department);
- String itemName = row.getCell(4).getStringCellValue();
- System.out.println(itemName);
- String serviceContent = row.getCell(5).getStringCellValue();
- System.out.println(serviceContent);
- String serviceProcess = row.getCell(6).getStringCellValue();
- System.out.println(serviceProcess);
- String telephone = "";
- CellType cellType = row.getCell(7).getCellType();
- if(cellType.equals(CellType.STRING)){
- telephone = row.getCell(7).getStringCellValue();
- System.out.println(telephone);
- }else if(cellType.equals(CellType.NUMERIC)){
- DecimalFormat decimalFormat2 = new DecimalFormat("#.#######");
- telephone = decimalFormat2.format(row.getCell(7).getNumericCellValue());
- System.out.println(telephone);
- }
- NdKqZzsfwMenu menu = new NdKqZzsfwMenu();
- menu.setItemName(itemName);
- menu.setZoneName(zoneName);
- menu.setWindow(windowName);
- menu.setDepartment(department);
- menu.setServiceContent(serviceContent);
- menu.setServiceProcess(serviceProcess);
- menu.setTelephone(telephone);
- menu.setType(ItemTypeEnum.ADDED.getCode());
- menu.setCreateOn(LocalDateTime.now());
- menu.setSort(sort);
- // menuService.save(menu);
- }
- }
-
- }
-
-
- @Test
- public void tableAndColumn() throws IOException {
- String url = "jdbc:mysql://47.98.125.47:3306/kqzzsfw?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false"; // 你的数据库URL
- String username = "root"; // 数据库用户名
- String password = "NingdaKeji123!"; // 数据库密码
-
- String table = "nd_kq_zzsfw_menu";
-
- try {
- // 1. 加载数据库驱动
- Class.forName("com.mysql.cj.jdbc.Driver");
-
- // 2. 建立数据库连接
- Connection connection = DriverManager.getConnection(url, username, password);
-
- // 3. 创建Statement对象
- Statement statement = connection.createStatement();
-
- // 4. 编写并执行DDL语句(创建一个名为`users`的表)
- // String createTableUsers = "alter table nd_kq_zzsfw_menu add column type tinyint default 1 comment '类型 1.政府服务 2.增值服务 3.特殊'";
- // String createTableUsers = "alter table nd_kq_zzsfw_menu add column service_content text comment '服务内容';";
- // String createTableUsers = "alter table nd_kq_zzsfw_menu add column service_process text comment '服务流程';";
- String createTableUsers = "alter table nd_kq_zzsfw_menu add column telephone text comment '咨询电话'";
- statement.executeUpdate(createTableUsers);
-
- System.out.println(" Table '" + table + "' updated successfully.");
-
- // 5. 关闭资源
- statement.close();
- connection.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|