@@ -1,2 +1,2 @@ | |||
artifactType=1 | |||
artifactFile=kqapi/target/kqapi.jar | |||
artifactFile=kq-vas-api/target/kqapi.jar |
@@ -208,7 +208,7 @@ public class AdminMatterManage { | |||
}); | |||
zzsfwMenuService.saveBatch(newMatters); | |||
} catch (IOException e) { | |||
log.error("导入失败:", e); | |||
log.error("导入失败:{}", e.getMessage()); | |||
throw BizException.wrap("政务服务事项导入失败"); | |||
} | |||
} | |||
@@ -251,7 +251,7 @@ public class AdminMatterManage { | |||
os.write(resource.readBytes()); | |||
os.flush(); | |||
} catch (IOException e) { | |||
log.error("下载失败:", e); | |||
log.error("下载失败:{}", e.getMessage()); | |||
throw BizException.wrap("事项配置模板下载失败"); | |||
} | |||
} | |||
@@ -0,0 +1,36 @@ | |||
package com.ningdatech.kqapi.common.config; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Component; | |||
/** | |||
* <p> | |||
* WebProps | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 10:20 2024/5/30 | |||
*/ | |||
@Component | |||
public class SystemProps { | |||
public static String webUrl; | |||
public static String servletContentPath; | |||
public static String getApiUrl() { | |||
return webUrl + servletContentPath; | |||
} | |||
@Value("${sys.web-url:}") | |||
public void setWebUrl(String webUrl) { | |||
SystemProps.webUrl = webUrl; | |||
} | |||
@Value("${server.servlet.context-path:}") | |||
public void setServletContentPath(String servletContentPath) { | |||
SystemProps.servletContentPath = servletContentPath; | |||
} | |||
} |
@@ -34,4 +34,6 @@ public class BizConst { | |||
public static final ApiResponse<Void> UNAUTHENTICATED = ApiResponse.of(401, "用户未登录!"); | |||
public static final String ANONYMOUS_FILE_DOWN_URL = "/api/v1/common/anonymous/file/download/"; | |||
} |
@@ -10,29 +10,42 @@ import org.apache.http.client.methods.HttpPost; | |||
import org.apache.http.conn.ssl.DefaultHostnameVerifier; | |||
import org.apache.http.conn.util.PublicSuffixMatcher; | |||
import org.apache.http.conn.util.PublicSuffixMatcherLoader; | |||
import org.apache.http.entity.StringEntity; | |||
import org.apache.http.impl.client.CloseableHttpClient; | |||
import org.apache.http.impl.client.HttpClients; | |||
import org.apache.http.message.BasicNameValuePair; | |||
import org.apache.http.util.EntityUtils; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import java.io.IOException; | |||
import java.net.URL; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* HttpUtil | |||
* </p> | |||
* | |||
* @author WendyYang | |||
* @since 12:01 2024/5/30 | |||
*/ | |||
public class HttpUtil { | |||
private Logger logger = LoggerFactory.getLogger(getClass()); | |||
private RequestConfig requestConfig = RequestConfig.custom() | |||
.setSocketTimeout(15000) | |||
.setConnectTimeout(15000) | |||
.setConnectionRequestTimeout(15000) | |||
.build(); | |||
private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class); | |||
private final RequestConfig requestConfig = RequestConfig.custom() | |||
.setSocketTimeout(15000) | |||
.setConnectTimeout(15000) | |||
.setConnectionRequestTimeout(15000) | |||
.build(); | |||
private static HttpUtil instance = null; | |||
private HttpUtil(){} | |||
public static HttpUtil getInstance(){ | |||
private HttpUtil() { | |||
} | |||
public static HttpUtil getInstance() { | |||
if (instance == null) { | |||
instance = new HttpUtil(); | |||
} | |||
@@ -40,39 +53,13 @@ public class HttpUtil { | |||
} | |||
/** | |||
* 发送 post 请求 | |||
* @param httpUrl 地址 | |||
*/ | |||
public String sendHttpPost(String httpUrl) throws IOException { | |||
HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost | |||
return sendHttpPost(httpPost); | |||
} | |||
/** | |||
* 发送 post 请求 | |||
* @param httpUrl 地址 | |||
* @param params 参数(格式:key1=value1&key2=value2) | |||
*/ | |||
public String sendHttpPost(String httpUrl, String params) throws IOException { | |||
HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost | |||
try { | |||
//设置参数 | |||
StringEntity stringEntity = new StringEntity(params, "UTF-8"); | |||
stringEntity.setContentType("application/x-www-form-urlencoded"); | |||
httpPost.setEntity(stringEntity); | |||
} catch (Exception e) { | |||
logger.error(e.getMessage()); | |||
} | |||
return sendHttpPost(httpPost); | |||
} | |||
/** | |||
* 发送 post 请求 | |||
* @param httpUrl 地址 | |||
* @param maps 参数 | |||
*/ | |||
* 发送 post 请求 | |||
* | |||
* @param httpUrl 地址 | |||
* @param maps 参数 | |||
*/ | |||
public String sendHttpPost(String httpUrl, Map<String, String> maps) throws IOException { | |||
HttpPost httpPost= new HttpPost(httpUrl);// 创建 httpPost | |||
HttpPost httpPost = new HttpPost(httpUrl);// 创建 httpPost | |||
// 创建参数队列 | |||
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); | |||
for (String key : maps.keySet()) { | |||
@@ -87,14 +74,15 @@ public class HttpUtil { | |||
} | |||
/** | |||
* 发送 Post请求 | |||
* @param httpPost | |||
*@return | |||
*/ | |||
* 发送 Post请求 | |||
* | |||
* @param httpPost | |||
* @return | |||
*/ | |||
private String sendHttpPost(HttpPost httpPost) throws IOException { | |||
CloseableHttpClient httpClient = null; | |||
CloseableHttpResponse response = null; | |||
HttpEntity entity = null; | |||
HttpEntity entity; | |||
String responseContent = null; | |||
try { | |||
// 创建默认的 httpClient 实例. | |||
@@ -123,96 +111,4 @@ public class HttpUtil { | |||
return responseContent; | |||
} | |||
/** | |||
* 发送 get 请求 | |||
* @param httpUrl | |||
*/ | |||
public String sendHttpGet(String httpUrl) throws IOException { | |||
HttpGet httpGet = new HttpGet(httpUrl);// 创建 get 请求 | |||
return sendHttpGet(httpGet); | |||
} | |||
/** | |||
* 发送 get请求 Https | |||
* @param httpUrl | |||
*/ | |||
public String sendHttpsGet(String httpUrl) { | |||
HttpGet httpGet = new HttpGet(httpUrl);// 创建 get 请求 | |||
return sendHttpsGet(httpGet); | |||
} | |||
/** | |||
* 发送 Get请求 | |||
* @param httpGet | |||
*@return | |||
*/ | |||
private String sendHttpGet(HttpGet httpGet) throws IOException { | |||
CloseableHttpClient httpClient = null; | |||
CloseableHttpResponse response = null; | |||
HttpEntity entity = null; | |||
String responseContent = null; | |||
try { | |||
// 创建默认的 httpClient 实例. | |||
httpClient = HttpClients.createDefault(); | |||
httpGet.setConfig(requestConfig); | |||
// 执行请求 | |||
response = httpClient.execute(httpGet); | |||
entity = response.getEntity(); | |||
responseContent = EntityUtils.toString(entity, "UTF-8"); | |||
} catch (Exception e) { | |||
logger.error(e.getMessage()); | |||
} finally { | |||
httpClient.close(); | |||
try { | |||
// 关闭连接,释放资源 | |||
if (response != null) { | |||
response.close(); | |||
} | |||
if (httpClient != null) { | |||
httpClient.close(); | |||
} | |||
} catch (IOException e) { | |||
logger.error(e.getMessage()); | |||
} | |||
} | |||
return responseContent; | |||
} | |||
/** | |||
* 发送 Get请求 Https | |||
*@return | |||
*/ | |||
private String sendHttpsGet(HttpGet httpGet) { | |||
CloseableHttpClient httpClient = null; | |||
CloseableHttpResponse response = null; | |||
HttpEntity entity = null; | |||
String responseContent = null; | |||
try { | |||
// 创建默认的 httpClient 实例. | |||
PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new | |||
URL(httpGet.getURI().toString())); | |||
DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); | |||
httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build(); | |||
httpGet.setConfig(requestConfig); | |||
// 执行请求 | |||
response = httpClient.execute(httpGet); | |||
entity = response.getEntity(); | |||
responseContent = EntityUtils.toString(entity, "UTF-8"); | |||
} catch (Exception e) { | |||
logger.error(e.getMessage()); | |||
} finally { | |||
try { | |||
// 关闭连接,释放资源 | |||
if (response != null) { | |||
response.close(); | |||
} | |||
if (httpClient != null) { | |||
httpClient.close(); | |||
} | |||
} catch (IOException e) { | |||
logger.error(e.getMessage()); | |||
} | |||
} | |||
return responseContent; | |||
} | |||
} |
@@ -290,7 +290,7 @@ public final class NdDateUtils { | |||
date = dateFormat.parse(dateStr); | |||
} catch (Exception e) { | |||
log.info("DateUtils error", e); | |||
log.info("DateUtils error:{}", e.getMessage()); | |||
} | |||
return date; | |||
} | |||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; | |||
import com.ningdatech.kqapi.common.exception.BizException; | |||
import com.ningdatech.kqapi.security.constant.AuthConst; | |||
import com.ningdatech.kqapi.security.model.WebRequestDetails; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.security.authentication.BadCredentialsException; | |||
import org.springframework.security.core.Authentication; | |||
@@ -24,6 +25,7 @@ import java.time.LocalDateTime; | |||
* @author WendyYang | |||
* @since 2023/9/1 | |||
**/ | |||
@Slf4j | |||
public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessingFilter { | |||
private final Boolean postOnly; | |||
@@ -49,7 +51,7 @@ public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessing | |||
} catch (BadCredentialsException | UsernameNotFoundException e) { | |||
throw e; | |||
} catch (Exception e) { | |||
logger.error("登录失败:", e); | |||
log.error("登录失败:{}", e.getMessage()); | |||
throw BizException.wrap("登录失败,请联系管理员!"); | |||
} | |||
} | |||
@@ -1,5 +1,14 @@ | |||
package com.ningdatech.kqapi.sso.utils; | |||
import com.ningdatech.kqapi.common.exception.BizException; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.math3.util.Pair; | |||
import org.springframework.util.LinkedMultiValueMap; | |||
import org.springframework.util.MultiValueMap; | |||
import javax.crypto.Mac; | |||
import javax.crypto.spec.SecretKeySpec; | |||
import javax.xml.bind.DatatypeConverter; | |||
import java.io.UnsupportedEncodingException; | |||
import java.net.URI; | |||
import java.net.URL; | |||
@@ -9,16 +18,6 @@ import java.text.SimpleDateFormat; | |||
import java.util.*; | |||
import java.util.stream.Collectors; | |||
import javax.crypto.Mac; | |||
import javax.crypto.spec.SecretKeySpec; | |||
import javax.xml.bind.DatatypeConverter; | |||
import org.apache.commons.math3.util.Pair; | |||
import org.springframework.util.LinkedMultiValueMap; | |||
import org.springframework.util.MultiValueMap; | |||
import lombok.extern.slf4j.Slf4j; | |||
/** | |||
* @author CMM | |||
* @since 2024/04/07 11:28 | |||
@@ -37,7 +36,7 @@ public class HmacAuthUtil { | |||
* @return | |||
*/ | |||
public static Map<String, String> generateHeader(String urlStr, String requestMethod, String accessKey, String secretKey) { | |||
log.info("params,urlStr={},requestMethod={},accessKey={},secretKey={}",urlStr,requestMethod,accessKey,secretKey); | |||
log.info("params,urlStr={},requestMethod={},accessKey={},secretKey={}", urlStr, requestMethod, accessKey, secretKey); | |||
Map<String, String> header = new HashMap<>(); | |||
try { | |||
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); | |||
@@ -48,7 +47,7 @@ public class HmacAuthUtil { | |||
String canonicalQueryString = getCanonicalQueryString(uri.getQuery()); | |||
String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + accessKey + "\n" + date + "\n"; | |||
String message = requestMethod.toUpperCase() + "\n" + uri.getPath() + "\n" + canonicalQueryString + "\n" + accessKey + "\n" + date + "\n"; | |||
Mac hasher = Mac.getInstance("HmacSHA256"); | |||
hasher.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA256")); | |||
@@ -65,10 +64,10 @@ public class HmacAuthUtil { | |||
header.put("X-BG-HMAC-ACCESS-KEY", accessKey); | |||
header.put("X-BG-DATE-TIME", date); | |||
} catch (Exception e) { | |||
log.error("generate error",e); | |||
throw new RuntimeException("generate header error"); | |||
log.error("generate error:{}", e.getMessage()); | |||
throw BizException.wrap("generate header error"); | |||
} | |||
log.info("header info,{}",header); | |||
log.info("header info,{}", header); | |||
return header; | |||
} | |||
@@ -82,9 +81,9 @@ public class HmacAuthUtil { | |||
int eqIndex = param.indexOf("="); | |||
String key = param; | |||
String value = ""; | |||
if(eqIndex!=-1){ | |||
if (eqIndex != -1) { | |||
key = param.substring(0, eqIndex); | |||
value = param.substring(eqIndex+1); | |||
value = param.substring(eqIndex + 1); | |||
} | |||
Pair<String, String> pair = new Pair<>(key, value); | |||
queryParamList.add(pair); | |||
@@ -96,15 +95,14 @@ public class HmacAuthUtil { | |||
try { | |||
String key = URLEncoder.encode(param.getKey(), "utf-8"); | |||
String value = URLEncoder.encode(Optional.ofNullable(param.getValue()).orElse(""), "utf-8") | |||
.replaceAll("\\%2B","%20") | |||
.replaceAll("\\+","%20") | |||
.replaceAll("\\%21","!") | |||
.replaceAll("\\%27","'") | |||
.replaceAll("\\%28","(") | |||
.replaceAll("\\%29",")") | |||
.replaceAll("\\%7E","~") | |||
.replaceAll("\\%25","%") | |||
; | |||
.replaceAll("\\%2B", "%20") | |||
.replaceAll("\\+", "%20") | |||
.replaceAll("\\%21", "!") | |||
.replaceAll("\\%27", "'") | |||
.replaceAll("\\%28", "(") | |||
.replaceAll("\\%29", ")") | |||
.replaceAll("\\%7E", "~") | |||
.replaceAll("\\%25", "%"); | |||
encodeParamList.add(new Pair<>(key, value)); | |||
} catch (UnsupportedEncodingException e) { | |||
throw new RuntimeException("encoding error"); | |||
@@ -234,6 +234,7 @@ public class UserInfoManage { | |||
@Transactional(rollbackFor = Exception.class) | |||
public void deleteUser(Long userId) { | |||
Assert.isTrue(LoginUserUtil.getUserId().equals(userId), "不能删除当前登录账号信息"); | |||
kickOff(userId); | |||
userInfoService.removeById(userId); | |||
userAuthService.removeByUserId(userId); | |||
@@ -34,8 +34,8 @@ public class CommonController { | |||
try { | |||
fileService.download(fileId, response); | |||
} catch (Exception e) { | |||
log.error("文件下载失败:", e); | |||
throw BizException.wrap("读物文件失败"); | |||
log.error("文件下载失败:{}", e.getMessage()); | |||
throw BizException.wrap("读取文件失败"); | |||
} | |||
} | |||
@@ -39,8 +39,8 @@ public class KqZzsfwMenuController { | |||
} | |||
@GetMapping("/zones") | |||
public List<TreeVO> getZones() { | |||
return matterManage.getZones(); | |||
public List<TreeVO> listZones() { | |||
return matterManage.listZones(); | |||
} | |||
@GetMapping("/windows") | |||
@@ -2,9 +2,9 @@ package com.ningdatech.kqapi.zzsfw.manage; | |||
import cn.hutool.core.bean.BeanUtil; | |||
import cn.hutool.core.collection.CollUtil; | |||
import cn.hutool.core.lang.Assert; | |||
import cn.hutool.core.util.StrUtil; | |||
import cn.hutool.json.JSONUtil; | |||
import cn.hutool.poi.excel.ExcelReader; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.ningdatech.basic.util.CollUtils; | |||
import com.ningdatech.file.entity.File; | |||
@@ -18,6 +18,8 @@ import com.ningdatech.kqapi.admin.model.vo.MatterDetailDTO; | |||
import com.ningdatech.kqapi.admin.model.vo.WebMatterDetailVO; | |||
import com.ningdatech.kqapi.admin.service.IWindowService; | |||
import com.ningdatech.kqapi.admin.service.IZoneService; | |||
import com.ningdatech.kqapi.common.config.SystemProps; | |||
import com.ningdatech.kqapi.common.constant.BizConst; | |||
import com.ningdatech.kqapi.scheduler.utils.ExcelUtil; | |||
import com.ningdatech.kqapi.zzsfw.constants.ZzsfwMenuConstant; | |||
import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum; | |||
@@ -35,15 +37,12 @@ import org.apache.commons.lang3.StringUtils; | |||
import org.apache.poi.ss.usermodel.CellType; | |||
import org.apache.poi.ss.usermodel.Row; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import org.apache.poi.ss.usermodel.Workbook; | |||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import org.springframework.web.multipart.MultipartFile; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.sql.Connection; | |||
import java.sql.DriverManager; | |||
import java.sql.Statement; | |||
@@ -105,22 +104,22 @@ public class MatterManage { | |||
} | |||
/** | |||
* 查询社区 | |||
* 查询专区 | |||
* | |||
* @return | |||
* @return \ | |||
*/ | |||
public List<TreeVO> getZones() { | |||
public List<TreeVO> listZones() { | |||
List<Zone> zones = zoneService.list(); | |||
if (zones.isEmpty()) { | |||
return Collections.emptyList(); | |||
} | |||
Map<Long, Integer> iconFileIdMap = new HashMap<>(); | |||
Map<Integer, Long> iconFileIdMap = new HashMap<>(); | |||
Map<Long, Integer> specialFeatureFileIdMap = new HashMap<>(); | |||
for (Zone zone : zones) { | |||
if (StrUtil.isNotBlank(zone.getZoneIcon())) { | |||
List<AttachFileVo> files = JSONUtil.toList(zone.getZoneIcon(), AttachFileVo.class); | |||
if (CollUtil.isNotEmpty(files)) { | |||
iconFileIdMap.put(files.get(0).getFileId(), zone.getId()); | |||
iconFileIdMap.put(zone.getId(), files.get(0).getFileId()); | |||
} | |||
} | |||
if (StrUtil.isNotBlank(zone.getSpecialFeature())) { | |||
@@ -132,44 +131,44 @@ public class MatterManage { | |||
} | |||
} | |||
} | |||
Map<Integer, String> iconUrlMap = new HashMap<>(); | |||
Map<Integer, List<FileResultVO>> specialFeatureUrlMap = new HashMap<>(); | |||
if (!iconFileIdMap.isEmpty() || !specialFeatureFileIdMap.isEmpty()) { | |||
List<Long> tmpFileIds = new ArrayList<>(); | |||
tmpFileIds.addAll(iconFileIdMap.keySet()); | |||
tmpFileIds.addAll(specialFeatureFileIdMap.keySet()); | |||
for (File file : fileService.listByIds(tmpFileIds)) { | |||
if (!specialFeatureFileIdMap.isEmpty()) { | |||
for (File file : fileService.listByIds(specialFeatureFileIdMap.keySet())) { | |||
String fileUrl = fileService.findUrlByFile(file, Duration.ofDays(30)); | |||
if (iconFileIdMap.containsKey(file.getId())) { | |||
iconUrlMap.put(iconFileIdMap.get(file.getId()), fileUrl); | |||
} else if (specialFeatureFileIdMap.containsKey(file.getId())) { | |||
FileResultVO retFile = FileResultVO.builder() | |||
.id(file.getId()) | |||
.url(fileUrl) | |||
.contentType(file.getContentType()) | |||
.fileType(file.getFileType()) | |||
.originalFileName(file.getOriginalFileName()) | |||
.size(file.getSize()) | |||
.suffix(file.getSuffix()) | |||
.build(); | |||
specialFeatureUrlMap.merge(specialFeatureFileIdMap.get(file.getId()), | |||
CollUtil.newArrayList(retFile), (v1, v2) -> { | |||
v1.addAll(v2); | |||
return v1; | |||
}); | |||
} | |||
FileResultVO retFile = FileResultVO.builder() | |||
.id(file.getId()) | |||
.url(fileUrl) | |||
.contentType(file.getContentType()) | |||
.fileType(file.getFileType()) | |||
.originalFileName(file.getOriginalFileName()) | |||
.size(file.getSize()) | |||
.suffix(file.getSuffix()) | |||
.build(); | |||
specialFeatureUrlMap.merge(specialFeatureFileIdMap.get(file.getId()), | |||
CollUtil.newArrayList(retFile), (v1, v2) -> { | |||
v1.addAll(v2); | |||
return v1; | |||
}); | |||
} | |||
} | |||
return CollUtils.convert(zones, w -> TreeVO.builder() | |||
.name(w.getZoneName()) | |||
.zoneIcon(iconUrlMap.get(w.getId())) | |||
.specialFeature(w.getSpecialFeature()) | |||
.specialFeatureFiles(specialFeatureUrlMap.get(w.getId())) | |||
.type(ZzsfwMenuConstant.MENU_TYPE_ZONE) | |||
.build()); | |||
return CollUtils.convert(zones, w -> { | |||
String iconUrl = null; | |||
if (iconFileIdMap.containsKey(w.getId())) { | |||
iconUrl = SystemProps.getApiUrl() + BizConst.ANONYMOUS_FILE_DOWN_URL + iconFileIdMap.get(w.getId()); | |||
} | |||
return TreeVO.builder() | |||
.name(w.getZoneName()) | |||
.zoneIcon(iconUrl) | |||
.specialFeature(w.getSpecialFeature()) | |||
.specialFeatureFiles(specialFeatureUrlMap.get(w.getId())) | |||
.type(ZzsfwMenuConstant.MENU_TYPE_ZONE) | |||
.build(); | |||
}); | |||
} | |||
@Deprecated | |||
public List<TreeVO> getZonesOld() { | |||
List<KqZzsfwMenu> matters = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class) | |||
@@ -437,46 +436,31 @@ public class MatterManage { | |||
} | |||
public String uploadMenu(MultipartFile file) throws IOException { | |||
InputStream inputStream = file.getInputStream(); | |||
Workbook workbook = new XSSFWorkbook(inputStream); | |||
Assert.notNull(workbook); | |||
Row row; | |||
//获取最大行数 | |||
Sheet sheet = workbook.getSheetAt(0); | |||
int rownum = sheet.getPhysicalNumberOfRows(); | |||
//获取最大列数 | |||
Integer num = 1; | |||
for (int i = 2; i < rownum; i++) { | |||
ExcelReader reader = cn.hutool.poi.excel.ExcelUtil.getReader(file.getInputStream(), 0); | |||
Sheet sheet = reader.getSheet(); | |||
int rowNo = sheet.getPhysicalNumberOfRows(); | |||
for (int i = 2; i < rowNo; 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); | |||
} | |||
KqZzsfwMenu menu = new KqZzsfwMenu(); | |||
menu.setItemName(itemName); | |||
@@ -498,23 +482,18 @@ public class MatterManage { | |||
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`的表) | |||
statement.executeUpdate(sql); | |||
System.out.println(" Table updated successfully."); | |||
log.info(" Table updated successfully."); | |||
// 5. 关闭资源 | |||
statement.close(); | |||
connection.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
log.error(e.getMessage()); | |||
} | |||
return "success!"; | |||
} | |||
@@ -123,6 +123,9 @@ log: | |||
swagger: | |||
enabled: true | |||
sys: | |||
web-url: http://kqzh.ningdatech.com | |||
hostname: iZbp13nwyvib53j4j1p2xoZ | |||
jasypt: | |||
encryptor: | |||
@@ -47,9 +47,9 @@ spring: | |||
datasource: | |||
type: com.zaxxer.hikari.HikariDataSource | |||
driverClassName: com.kingbase8.Driver | |||
url: jdbc:kingbase8://10.75.42.167:54321/kq_added_project?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8 | |||
url: ENC(/Bwlm+apsyR8EHuhBHBUpfBG/a9HkM12voHCw3quVoVcGh/1BNTSjyq1gCZ81+mAh84gCsLD5ZnA65/tuiFwvRcuWOHd4+WcAlbVw5MB0Wi1FtY0IeeDN69TSKOSToF/g5F8ggl+XyVJClrhkj0hcgMj4EAWsdJdcIuMsG+U1DItLYU4XfzYYw==) | |||
username: SYSTEM | |||
password: Kqvdsj@159260 | |||
password: ENC(ya6q/ZCE5Gdexu6OXZTlHTjKH9y28z89) | |||
# 数据源 | |||
hikari: | |||
@@ -103,7 +103,6 @@ nd: | |||
file: | |||
storage-type: ALI_OSS | |||
ali: | |||
protocol: http:// | |||
bucket: kqqfzx-295 | |||
urlPrefix: oss0eab-cn-shaoxing-sxdx-d01-a.ops.dxdtsxzwy.com | |||
@@ -127,6 +126,9 @@ swagger: | |||
hostname: iZut201mqskxt0mwme4tjfZ | |||
sys: | |||
web-url: https://qyxspt.kq.gov.cn:33060 | |||
jasypt: | |||
encryptor: | |||
password: CodeSheep | |||
@@ -1,28 +1,6 @@ | |||
package com.ningdatech.kqapi.menu; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.google.common.collect.Sets; | |||
import com.ningdatech.kqapi.AppTests; | |||
import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMenu; | |||
import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMattersDeduplicate; | |||
import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMatterDeduplicateService; | |||
import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMenuService; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.poi.ss.usermodel.Row; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import org.apache.poi.ss.usermodel.Workbook; | |||
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.time.LocalDateTime; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @Classname DuplicationTest | |||
@@ -32,69 +10,4 @@ import java.util.stream.Collectors; | |||
*/ | |||
public class DuplicationTest extends AppTests { | |||
@Autowired | |||
private IKqZzsfwMatterDeduplicateService matterDeduplicateService; | |||
@Autowired | |||
private IKqZzsfwMenuService menuService; | |||
@Test | |||
public void test() throws IOException { | |||
FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\去重后的事项数据.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; | |||
matterDeduplicateService.remove(Wrappers.lambdaQuery(KqZzsfwMattersDeduplicate.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()); | |||
Double numericCellValue = row.getCell(2).getNumericCellValue(); | |||
KqZzsfwMattersDeduplicate menu = new KqZzsfwMattersDeduplicate(); | |||
menu.setWebapplyurl(row.getCell(1).getStringCellValue()); | |||
menu.setQlName(row.getCell(0).getStringCellValue()); | |||
menu.setCreateOn(LocalDateTime.now()); | |||
menu.setCountNum(numericCellValue.intValue()); | |||
matterDeduplicateService.save(menu); | |||
} | |||
} | |||
} | |||
@Test | |||
public void syncUrl(){ | |||
List<KqZzsfwMenu> menus = menuService.list(Wrappers.lambdaQuery(KqZzsfwMenu.class)); | |||
List<KqZzsfwMattersDeduplicate> list = matterDeduplicateService.list(); | |||
Set<String> qlSet = Sets.newTreeSet(); | |||
Map<String, String> map = list.stream().filter(q -> qlSet.add(q.getQlName())) | |||
.filter(q -> StringUtils.isNotBlank(q.getWebapplyurl()) && StringUtils.isNotBlank(q.getQlName())) | |||
.collect(Collectors.toMap(q -> q.getQlName(), q -> q.getWebapplyurl())); | |||
for(KqZzsfwMenu menu : menus){ | |||
String itemName = menu.getItemName(); | |||
if(map.containsKey(itemName)){ | |||
String url = map.get(itemName); | |||
menu.setWebapplyurl(url); | |||
menu.setHasUrl(1); | |||
menuService.updateById(menu); | |||
} | |||
} | |||
} | |||
} |
@@ -1,60 +0,0 @@ | |||
package com.ningdatech.kqapi.menu; | |||
import org.apache.poi.ss.usermodel.*; | |||
import org.apache.poi.ss.util.CellRangeAddress; | |||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |||
import java.io.FileInputStream; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
public class ExcelSplitMergedCells { | |||
public static void main(String[] args) throws IOException { | |||
// 打开Excel文件 | |||
FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\8.8柯桥区企业综合服务中心政务服务事项清单.xlsx"); | |||
Workbook workbook = new XSSFWorkbook(fis); | |||
Sheet sheet = workbook.getSheetAt(0); | |||
// 获取合并单元格的范围 | |||
CellRangeAddress mergedRegion = sheet.getMergedRegion(0); // 0表示第一个合并的单元格 | |||
int firstRow = mergedRegion.getFirstRow(); | |||
int lastRow = mergedRegion.getLastRow(); | |||
int firstCol = mergedRegion.getFirstColumn(); | |||
int lastCol = mergedRegion.getLastColumn(); | |||
// 取消合并单元格 | |||
sheet.removeMergedRegion(0); | |||
Integer num = 0; | |||
// 创建新的单元格并复制内容 | |||
for (int i = firstRow; i <= lastRow; i++) { | |||
Row row = sheet.getRow(i); | |||
for (int j = firstCol; j <= lastCol; j++) { | |||
Cell oldCell = row.getCell(j); | |||
Cell newCell = row.createCell(j); | |||
newCell.setCellType(oldCell.getCellType()); | |||
switch (oldCell.getCellType()) { | |||
case STRING: | |||
newCell.setCellValue(oldCell.getStringCellValue()); | |||
break; | |||
case NUMERIC: | |||
newCell.setCellValue(oldCell.getNumericCellValue()); | |||
break; | |||
case BOOLEAN: | |||
newCell.setCellValue(oldCell.getBooleanCellValue()); | |||
break; | |||
case FORMULA: | |||
newCell.setCellFormula(oldCell.getCellFormula()); | |||
break; | |||
default: | |||
newCell.setCellValue(""); | |||
} | |||
} | |||
} | |||
// 保存修改后的Excel文件 | |||
fis.close(); | |||
FileOutputStream fos = new FileOutputStream("C:\\Users\\PoffyZhang\\Desktop\\8.8柯桥区企业综合服务中心政务服务事项清单2.xlsx"); | |||
workbook.write(fos); | |||
fos.close(); | |||
} | |||
} |
@@ -1,187 +0,0 @@ | |||
package com.ningdatech.kqapi.menu; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.ningdatech.kqapi.AppTests; | |||
import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwMenu; | |||
import com.ningdatech.kqapi.zzsfw.enumeration.ItemTypeEnum; | |||
import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwMenuService; | |||
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; | |||
/** | |||
* @Classname MenuTest | |||
* @Description | |||
* @Date 2023/10/27 9:51 | |||
* @Author PoffyZhang | |||
*/ | |||
public class MenuTest extends AppTests{ // | |||
@Autowired | |||
private IKqZzsfwMenuService 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(KqZzsfwMenu.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); | |||
KqZzsfwMenu menu = new KqZzsfwMenu(); | |||
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); | |||
} | |||
KqZzsfwMenu menu = new KqZzsfwMenu(); | |||
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(); | |||
} | |||
} | |||
} |
@@ -1,85 +0,0 @@ | |||
package com.ningdatech.kqapi.menu; | |||
import cn.hutool.core.date.DateUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.ningdatech.kqapi.AppTests; | |||
import com.ningdatech.kqapi.zzsfw.model.entity.KqZzsfwPolicy; | |||
import com.ningdatech.kqapi.zzsfw.service.IKqZzsfwPolicyService; | |||
import org.apache.poi.ss.usermodel.Row; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import org.apache.poi.ss.usermodel.Workbook; | |||
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.time.LocalDateTime; | |||
import java.util.Objects; | |||
/** | |||
* @Classname MenuTest | |||
* @Description | |||
* @Date 2023/10/27 9:51 | |||
* @Author PoffyZhang | |||
*/ | |||
public class PolicyTest extends AppTests { | |||
@Autowired | |||
private IKqZzsfwPolicyService policyService; | |||
@Test | |||
public void test() throws IOException { | |||
FileInputStream fis = new FileInputStream("C:\\Users\\PoffyZhang\\Desktop\\政策条例摘录.xlsx"); | |||
Workbook workbook = new XSSFWorkbook(fis); | |||
Assert.assertNotNull(workbook); | |||
Row row; | |||
policyService.remove(Wrappers.lambdaQuery(KqZzsfwPolicy.class)); | |||
if (workbook != null) { | |||
//获取最大行数 | |||
Sheet sheet = workbook.getSheetAt(0); | |||
int rownum = sheet.getPhysicalNumberOfRows(); | |||
//获取第一行 | |||
row = sheet.getRow(0); | |||
//获取最大列数 | |||
Integer sort = 1; | |||
for (int i = 2; i < rownum; i++) { | |||
row = sheet.getRow(i); | |||
if(row.getZeroHeight()){ | |||
continue; | |||
} | |||
String header = Objects.nonNull(row.getCell(0)) ? row.getCell(0).getStringCellValue() : null; | |||
String title = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getStringCellValue() : null; | |||
String secondTitle = Objects.nonNull(row.getCell(2)) ? row.getCell(2).getStringCellValue() : null; | |||
String regionName = Objects.nonNull(row.getCell(3)) ? row.getCell(3).getStringCellValue() : null; | |||
String department = Objects.nonNull(row.getCell(4)) ? row.getCell(4).getStringCellValue() : null; | |||
String issueDate = Objects.nonNull(row.getCell(5)) ? DateUtil.format(row.getCell(5).getDateCellValue(),"yyyy/MM/dd") : null; | |||
String status = Objects.nonNull(row.getCell(7)) ? row.getCell(7).getStringCellValue() : null; | |||
String applyTime = Objects.nonNull(row.getCell(8)) ? row.getCell(8).getStringCellValue() : null; | |||
String url = Objects.nonNull(row.getCell(9)) ? row.getCell(9).getStringCellValue() : null; | |||
KqZzsfwPolicy policy = new KqZzsfwPolicy(); | |||
policy.setHeader(header); | |||
policy.setTitle(title); | |||
policy.setSecondTitle(secondTitle); | |||
policy.setRegionName(regionName); | |||
policy.setDepartment(department); | |||
policy.setIssueDate(issueDate); | |||
policy.setStatus(status); | |||
policy.setApplyTime(applyTime); | |||
policy.setOnlineConsultationUrl(url); | |||
policy.setCreateOn(LocalDateTime.now()); | |||
policy.setSort(sort); | |||
policyService.save(policy); | |||
System.out.println("记数:" + (sort++)); | |||
} | |||
} | |||
} | |||
} |