柯桥增值式服务
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

191 líneas
8.2KB

  1. package com.ningdatech.kqapi.menu;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.ningdatech.kqapi.AppTests;
  4. import com.ningdatech.kqapi.zzsfw.entity.entity.DscSxAdsShareItemQltQlsxCommonIDVKq;
  5. import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMenu;
  6. import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum;
  7. import com.ningdatech.kqapi.zzsfw.service.IDscSxAdsShareItemQltQlsxCommonIDVKqService;
  8. import com.ningdatech.kqapi.zzsfw.service.INdKqZzsfwMenuService;
  9. import org.apache.poi.ss.usermodel.*;
  10. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  11. import org.junit.Assert;
  12. import org.junit.Test;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import java.io.FileInputStream;
  15. import java.io.IOException;
  16. import java.sql.Connection;
  17. import java.sql.DriverManager;
  18. import java.sql.Statement;
  19. import java.text.DecimalFormat;
  20. import java.time.LocalDateTime;
  21. import java.util.Objects;
  22. /**
  23. * @Classname MenuTest
  24. * @Description
  25. * @Date 2023/10/27 9:51
  26. * @Author PoffyZhang
  27. */
  28. public class MenuTest extends AppTests{ //
  29. @Autowired
  30. private INdKqZzsfwMenuService menuService;
  31. @Test
  32. public void test() throws IOException {
  33. FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\11.14柯桥.xlsx");
  34. Workbook workbook = new XSSFWorkbook(fis);
  35. Assert.assertNotNull(workbook);
  36. Row row;
  37. if (workbook != null) {
  38. //获取最大行数
  39. Sheet sheet = workbook.getSheetAt(0);
  40. int rownum = sheet.getPhysicalNumberOfRows();
  41. //获取第一行
  42. row = sheet.getRow(0);
  43. //获取最大列数
  44. Integer num = 1;
  45. menuService.remove(Wrappers.lambdaQuery(NdKqZzsfwMenu.class));
  46. for (int i = 2; i < rownum; i++) {
  47. row = sheet.getRow(i);
  48. if(row.getZeroHeight()){
  49. continue;
  50. }
  51. System.out.println("记数:" + (num++));
  52. System.out.println(row.getCell(0).getStringCellValue());
  53. System.out.println(row.getCell(1).getStringCellValue());
  54. System.out.println(row.getCell(2).getStringCellValue());
  55. Double numericCellValue = row.getCell(3).getNumericCellValue();
  56. String itemName = row.getCell(4).getStringCellValue();
  57. System.out.println(itemName);
  58. NdKqZzsfwMenu menu = new NdKqZzsfwMenu();
  59. menu.setItemName(itemName);
  60. menu.setZoneName(row.getCell(0).getStringCellValue());
  61. menu.setWindow(row.getCell(1).getStringCellValue());
  62. menu.setCreateOn(LocalDateTime.now());
  63. menu.setDepartment(row.getCell(2).getStringCellValue());
  64. menu.setSort(numericCellValue.intValue());
  65. //去查询 url
  66. // DscSxAdsShareItemQltQlsxCommonIDVKq item = itemQltQlsxCommonIDVKqService.getOne(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class)
  67. // .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getRowguid, DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl, DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName)
  68. // .eq(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, itemName)
  69. // .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl)
  70. // .last("limit 1"));
  71. // if(Objects.nonNull(item)){
  72. menu.setHasUrl(1);
  73. // menu.setWebapplyurl(item.getWebapplyurl());
  74. // menu.setItemRowid(item.getRowguid());
  75. // }
  76. menuService.save(menu);
  77. }
  78. }
  79. }
  80. @Test
  81. public void importData() throws IOException {
  82. FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\增值服务数据20240403.xlsx");
  83. Workbook workbook = new XSSFWorkbook(fis);
  84. Assert.assertNotNull(workbook);
  85. Row row;
  86. if (workbook != null) {
  87. //获取最大行数
  88. Sheet sheet = workbook.getSheetAt(0);
  89. int rownum = sheet.getPhysicalNumberOfRows();
  90. //获取第一行
  91. row = sheet.getRow(0);
  92. //获取最大列数
  93. Integer num = 1;
  94. for (int i = 2; i < rownum; i++) {
  95. row = sheet.getRow(i);
  96. if (row.getZeroHeight()) {
  97. continue;
  98. }
  99. System.out.println("记数:" + (num++));
  100. String zoneName = row.getCell(0).getStringCellValue();
  101. System.out.println(zoneName);
  102. DecimalFormat decimalFormat = new DecimalFormat("#");
  103. Integer sort = Integer.valueOf(decimalFormat.format(row.getCell(1).getNumericCellValue()));
  104. System.out.println(sort);
  105. String windowName = row.getCell(2).getStringCellValue();
  106. System.out.println(windowName);
  107. String department = row.getCell(3).getStringCellValue();
  108. System.out.println(department);
  109. String itemName = row.getCell(4).getStringCellValue();
  110. System.out.println(itemName);
  111. String serviceContent = row.getCell(5).getStringCellValue();
  112. System.out.println(serviceContent);
  113. String serviceProcess = row.getCell(6).getStringCellValue();
  114. System.out.println(serviceProcess);
  115. String telephone = "";
  116. CellType cellType = row.getCell(7).getCellType();
  117. if(cellType.equals(CellType.STRING)){
  118. telephone = row.getCell(7).getStringCellValue();
  119. System.out.println(telephone);
  120. }else if(cellType.equals(CellType.NUMERIC)){
  121. DecimalFormat decimalFormat2 = new DecimalFormat("#.#######");
  122. telephone = decimalFormat2.format(row.getCell(7).getNumericCellValue());
  123. System.out.println(telephone);
  124. }
  125. NdKqZzsfwMenu menu = new NdKqZzsfwMenu();
  126. menu.setItemName(itemName);
  127. menu.setZoneName(zoneName);
  128. menu.setWindow(windowName);
  129. menu.setDepartment(department);
  130. menu.setServiceContent(serviceContent);
  131. menu.setServiceProcess(serviceProcess);
  132. menu.setTelephone(telephone);
  133. menu.setType(ItemTypeEnum.ADDED.getCode());
  134. menu.setCreateOn(LocalDateTime.now());
  135. menu.setSort(sort);
  136. // menuService.save(menu);
  137. }
  138. }
  139. }
  140. @Test
  141. public void tableAndColumn() throws IOException {
  142. String url = "jdbc:mysql://47.98.125.47:3306/kqzzsfw?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false"; // 你的数据库URL
  143. String username = "root"; // 数据库用户名
  144. String password = "NingdaKeji123!"; // 数据库密码
  145. String table = "nd_kq_zzsfw_menu";
  146. try {
  147. // 1. 加载数据库驱动
  148. Class.forName("com.mysql.cj.jdbc.Driver");
  149. // 2. 建立数据库连接
  150. Connection connection = DriverManager.getConnection(url, username, password);
  151. // 3. 创建Statement对象
  152. Statement statement = connection.createStatement();
  153. // 4. 编写并执行DDL语句(创建一个名为`users`的表)
  154. // String createTableUsers = "alter table nd_kq_zzsfw_menu add column type tinyint default 1 comment '类型 1.政府服务 2.增值服务 3.特殊'";
  155. // String createTableUsers = "alter table nd_kq_zzsfw_menu add column service_content text comment '服务内容';";
  156. // String createTableUsers = "alter table nd_kq_zzsfw_menu add column service_process text comment '服务流程';";
  157. String createTableUsers = "alter table nd_kq_zzsfw_menu add column telephone text comment '咨询电话'";
  158. statement.executeUpdate(createTableUsers);
  159. System.out.println(" Table '" + table + "' updated successfully.");
  160. // 5. 关闭资源
  161. statement.close();
  162. connection.close();
  163. } catch (Exception e) {
  164. e.printStackTrace();
  165. }
  166. }
  167. }