修复shiro问题,及达梦地址,新增用户信息导入代码,新增poi依赖
This commit is contained in:
@@ -89,6 +89,24 @@
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.shiro</groupId>-->
|
||||
<!-- <artifactId>shiro-spring</artifactId>-->
|
||||
<!-- <version>1.7.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- https://mvnrepository.com/artifact/org.pac4j/pac4j-cas -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.pac4j</groupId>-->
|
||||
<!-- <artifactId>pac4j-cas</artifactId>-->
|
||||
<!-- <version>5.0.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– https://mvnrepository.com/artifact/io.buji/buji-pac4j –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.buji</groupId>-->
|
||||
<!-- <artifactId>buji-pac4j</artifactId>-->
|
||||
<!-- <version>6.0.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@@ -171,6 +189,16 @@
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>11.2.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>hcframe-base</finalName>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hcframe.base.module.shiro;
|
||||
|
||||
import com.hcframe.base.module.data.annotation.DataIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -36,7 +35,4 @@ public class FtToken implements Serializable {
|
||||
|
||||
private Date expireTime;
|
||||
|
||||
@DataIgnore
|
||||
private String test;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +41,13 @@ public class ShiroConfig {
|
||||
return new CustomRealm();
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public DefaultWebSessionManager sessionManager() {
|
||||
// DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
// sessionManager.setSessionIdUrlRewritingEnabled(false);
|
||||
// return sessionManager;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 权限管理,配置主要是Realm的管理认证
|
||||
*/
|
||||
@@ -80,4 +88,6 @@ public class ShiroConfig {
|
||||
public static LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,19 +19,24 @@
|
||||
<dependency>
|
||||
<groupId>net.unicon.cas</groupId>
|
||||
<artifactId>cas-client-autoconfig-support</artifactId>
|
||||
<version>1.4.0-GA</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jasig.cas.client</groupId>
|
||||
<artifactId>cas-client-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jasig.cas.client</groupId>
|
||||
<artifactId>cas-client-core</artifactId>
|
||||
<version>${java.cas.client.version}</version>
|
||||
<version>2.2.0-GA</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>net.unicon.cas</groupId>-->
|
||||
<!-- <artifactId>cas-client-autoconfig-support</artifactId>-->
|
||||
<!-- <version>1.4.0-GA</version>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.jasig.cas.client</groupId>-->
|
||||
<!-- <artifactId>cas-client-core</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.jasig.cas.client</groupId>-->
|
||||
<!-- <artifactId>cas-client-core</artifactId>-->
|
||||
<!-- <version>${java.cas.client.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.hcframe</groupId>
|
||||
<artifactId>hcframe-boot-starter</artifactId>
|
||||
|
||||
@@ -73,6 +73,7 @@ public class ShiroRealmConfig implements SystemRealm {
|
||||
// druid 资源路径
|
||||
map.put("/druid/**",ShiroType.ANON);
|
||||
map.put("/cas/valid",ShiroType.ANON);
|
||||
map.put("/test",ShiroType.AUTH);
|
||||
// 其余路径均拦截
|
||||
map.put("/**", ShiroType.ANON);
|
||||
return map;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.hcframe.config.module.cms;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.BaseMapperImpl;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @version 1.0
|
||||
* @className CasConrtroller
|
||||
* @date 2021年04月12日 2:41 下午
|
||||
* @description 描述
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/cms")
|
||||
public class CasConrtroller {
|
||||
|
||||
final BaseMapper baseMapper;
|
||||
|
||||
public CasConrtroller(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper) {
|
||||
this.baseMapper = baseMapper;
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public ResultVO<Object> getCms() {
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.hcframe.config.module.controller;
|
||||
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.redis.RedisUtil;
|
||||
import net.unicon.cas.client.configuration.CasClientConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.CookieValue;
|
||||
@@ -52,7 +51,7 @@ public class CasController {
|
||||
return ResultVO.getSuccess(redisUtil.hget("session", token));
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
@GetMapping("/cas/logout")
|
||||
@ResponseBody
|
||||
public ResultVO<String> logout(HttpServletResponse response, @CookieValue("X-Access-Token") String token) {
|
||||
Cookie cookie = new Cookie("X-Access-Token", null);
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
package com.hcframe.config.module.controller;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.jasig.cas.client.authentication.AttributePrincipal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
@@ -31,54 +26,76 @@ public class TestController {
|
||||
@GetMapping("/casProxy")
|
||||
public ResultVO<Object> getCasProxy(HttpServletRequest request) throws IOException {
|
||||
String serviceUrl = "http://192.168.1.130:8084/user/manage/ja";
|
||||
//1、获取到AttributePrincipal对象
|
||||
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
||||
if (principal == null) {
|
||||
return ResultVO.getFailed("用户未登录");
|
||||
}
|
||||
// try {
|
||||
//1、获取到AttributePrincipal对象
|
||||
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
||||
if (principal == null) {
|
||||
return ResultVO.getFailed("用户未登录");
|
||||
}
|
||||
return ResultVO.getSuccess(principal);
|
||||
// } catch (ClassCastException e) {
|
||||
// return ResultVO.getSuccess(request.getUserPrincipal());
|
||||
// }
|
||||
|
||||
//2、获取对应的(PT)proxy ticket
|
||||
String proxyTicket = principal.getProxyTicketFor(serviceUrl);
|
||||
if (proxyTicket == null) {
|
||||
return ResultVO.getFailed("PGT 或 PT 不存在");
|
||||
}
|
||||
URL url = new URL(serviceUrl + "?ticket=" + proxyTicket);// 不需要cookie,只需传入代理票据
|
||||
// String proxyTicket = principal.getProxyTicketFor(serviceUrl);
|
||||
// if (proxyTicket == null) {
|
||||
// return ResultVO.getFailed("PGT 或 PT 不存在");
|
||||
// }
|
||||
// URL url = new URL(serviceUrl + "?ticket=" + proxyTicket);// 不需要cookie,只需传入代理票据
|
||||
//
|
||||
// HttpURLConnection conn;
|
||||
// conn = (HttpURLConnection) url.openConnection();
|
||||
// //使用POST方式
|
||||
// conn.setRequestMethod("GET");
|
||||
// // 设置是否向connection输出,因为这个是post请求,参数要放在
|
||||
// // Post 请求不能使用缓存
|
||||
// conn.setUseCaches(false);
|
||||
//
|
||||
// //设置本次连接是否自动重定向
|
||||
// conn.setInstanceFollowRedirects(true);
|
||||
// // 配置本次连接的Content-type,配置为application/x-www-form-urlencoded的
|
||||
// // 意思是正文是urlencoded编码过的form参数
|
||||
// conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
|
||||
// // 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
||||
// // 要注意的是connection.getOutputStream会隐含的进行connect。
|
||||
// conn.connect();
|
||||
//
|
||||
//// DataOutputStream out = new DataOutputStream(conn
|
||||
//// .getOutputStream());
|
||||
////// 正文,正文内容其实跟get的URL中 '? '后的参数字符串一致
|
||||
//// String content = "start=" + URLEncoder.encode("1901-01-01", "UTF-8")+"&end="+URLEncoder.encode("2018-01-01", "UTF-8");
|
||||
//// // DataOutputStream.writeBytes将字符串中的16位的unicode字符以8位的字符形式写到流里面
|
||||
//// out.writeBytes(content);
|
||||
////// 流用完记得关
|
||||
//// out.flush();
|
||||
//// out.close();
|
||||
// StringBuilder result = new StringBuilder();
|
||||
// //获取响应
|
||||
// BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null){
|
||||
// result.append(line);
|
||||
// }
|
||||
// reader.close();
|
||||
// //连接断了
|
||||
// conn.disconnect();
|
||||
|
||||
HttpURLConnection conn;
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
//使用POST方式
|
||||
conn.setRequestMethod("GET");
|
||||
// 设置是否向connection输出,因为这个是post请求,参数要放在
|
||||
// Post 请求不能使用缓存
|
||||
conn.setUseCaches(false);
|
||||
|
||||
//设置本次连接是否自动重定向
|
||||
conn.setInstanceFollowRedirects(true);
|
||||
// 配置本次连接的Content-type,配置为application/x-www-form-urlencoded的
|
||||
// 意思是正文是urlencoded编码过的form参数
|
||||
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
|
||||
// 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
||||
// 要注意的是connection.getOutputStream会隐含的进行connect。
|
||||
conn.connect();
|
||||
|
||||
// DataOutputStream out = new DataOutputStream(conn
|
||||
// .getOutputStream());
|
||||
//// 正文,正文内容其实跟get的URL中 '? '后的参数字符串一致
|
||||
// String content = "start=" + URLEncoder.encode("1901-01-01", "UTF-8")+"&end="+URLEncoder.encode("2018-01-01", "UTF-8");
|
||||
// // DataOutputStream.writeBytes将字符串中的16位的unicode字符以8位的字符形式写到流里面
|
||||
// out.writeBytes(content);
|
||||
//// 流用完记得关
|
||||
// out.flush();
|
||||
// out.close();
|
||||
StringBuilder result = new StringBuilder();
|
||||
//获取响应
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null){
|
||||
result.append(line);
|
||||
}
|
||||
reader.close();
|
||||
//连接断了
|
||||
conn.disconnect();
|
||||
return ResultVO.getSuccess(result.toString());
|
||||
}
|
||||
@GetMapping("/ivid")
|
||||
public ResultVO<String> ivid(HttpServletRequest request) {
|
||||
// HttpSession session = request.getSession();
|
||||
// session.invalidate();
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
subject.logout();
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public ResultVO<String> logout(HttpServletRequest request) {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
subject.logout();
|
||||
return ResultVO.getSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ server:
|
||||
context-path: /config
|
||||
cas:
|
||||
server-url-prefix: http://192.168.1.131:8080/cas
|
||||
client-host-url: http://192.168.1.130:8081
|
||||
client-host-url: http://192.168.1.194:8081
|
||||
validation-type: cas3
|
||||
server-login-url: http://192.168.1.131:8080/cas/login
|
||||
# 代理模式
|
||||
proxy-callback-url: http://192.168.1.130:8081/config/proxyCallback
|
||||
proxy-receptor-url: /config/proxyCallback
|
||||
# proxy-callback-url: http://192.168.1.130:8081/config/proxyCallback
|
||||
# proxy-receptor-url: /config/proxyCallback
|
||||
pagehelper:
|
||||
auto-runtime-dialect: true
|
||||
spring:
|
||||
@@ -123,7 +123,7 @@ hystrix:
|
||||
hcframe:
|
||||
config:
|
||||
# 是否开启redis 用户登录,若开启此项,需要配置redis节点及相关配置,若不开启,需要注释掉redis相关配置信息
|
||||
isRedisLogin: true
|
||||
isRedisLogin: false
|
||||
# 用户登陆超时设置,单位为小时,此值不能为0
|
||||
loginTimeout: 4
|
||||
# 是否开启controller日志监控
|
||||
|
||||
@@ -2,7 +2,7 @@ spring:
|
||||
profiles:
|
||||
active: @profile.name@
|
||||
application:
|
||||
name: cloud-gateway
|
||||
name: cloud-gateway1
|
||||
# 若不使用redis需要注释掉此类信息
|
||||
redis:
|
||||
database: @redis.database@
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
package com.hcframe.user.common.utils;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
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.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @date 2020.01.16
|
||||
*/
|
||||
@Component
|
||||
public class POIUtil {
|
||||
|
||||
|
||||
private final static String XLS = "xls";
|
||||
private final static String XLSX = "xlsx";
|
||||
|
||||
public static Workbook getWorkBook(String filepath) {
|
||||
File file = new File(filepath);
|
||||
// 获得文件名
|
||||
String fileName = file.getName();
|
||||
// 创建Workbook工作薄对象,表示整个excel
|
||||
Workbook workbook = null;
|
||||
try {
|
||||
// 获取excel文件的io流
|
||||
InputStream is = new FileInputStream(filepath);
|
||||
// 根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
|
||||
if (fileName.endsWith(XLS)) {
|
||||
// 2003
|
||||
workbook = new HSSFWorkbook(is);
|
||||
} else if (fileName.endsWith(XLSX)) {
|
||||
// 2007
|
||||
workbook = new XSSFWorkbook(is);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
// public static String getCellValue(Cell cell) {
|
||||
// Object cellValue = "";
|
||||
// if (cell == null) {
|
||||
// return "";
|
||||
// }
|
||||
// // 把数字当成String来读,避免出现1读成1.0的情况
|
||||
// if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
||||
// //cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||
// }
|
||||
// // 判断数据的类型
|
||||
// switch (cell.getCellType()) {
|
||||
// case Cell.CELL_TYPE_NUMERIC: // 数字
|
||||
// if (DateUtil.isCellDateFormatted(cell)) {
|
||||
// //用于转化为日期格式
|
||||
// try {
|
||||
// Date d = cell.getDateCellValue();
|
||||
// cellValue = d;
|
||||
// } catch (Exception e) {
|
||||
// cellValue = null;
|
||||
// }
|
||||
// } else {
|
||||
// cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||
// cellValue = String.valueOf(cell.getStringCellValue());
|
||||
// }
|
||||
// break;
|
||||
// case Cell.CELL_TYPE_STRING: // 字符串
|
||||
// cellValue = String.valueOf(cell.getStringCellValue());
|
||||
// break;
|
||||
// case Cell.CELL_TYPE_BOOLEAN: // Boolean
|
||||
// cellValue = String.valueOf(cell.getBooleanCellValue());
|
||||
// break;
|
||||
// case Cell.CELL_TYPE_FORMULA: // 公式
|
||||
// cellValue = String.valueOf(cell.getCellFormula());
|
||||
// break;
|
||||
// case Cell.CELL_TYPE_BLANK: // 空值
|
||||
// cellValue = "";
|
||||
// break;
|
||||
// case Cell.CELL_TYPE_ERROR: // 故障
|
||||
// cellValue = "";
|
||||
// break;
|
||||
// default:
|
||||
// cellValue = "";
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// return String.valueOf(cellValue);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 写入表格
|
||||
*
|
||||
* @param list
|
||||
* @param startRow
|
||||
* @param sheet
|
||||
* @param filePath
|
||||
* @param split
|
||||
* @param headList
|
||||
* @param title
|
||||
* @return
|
||||
*/
|
||||
public static Workbook writeList(List<Map<String, Object>> list, int startRow, String sheet, String filePath, String[] split, List<Map<String, Object>> headList, String title) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet1 = workbook.createSheet(sheet);
|
||||
Row fisrtRow = sheet1.createRow(0);
|
||||
Map<String, Integer> headMap = new HashMap<>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
int finalI = i;
|
||||
Optional<Map<String, Object>> optional = headList.stream().filter(map -> map.get("base_label").equals(split[finalI])).findAny();
|
||||
if (optional.isPresent()) {
|
||||
Cell cell = fisrtRow.createCell(i);
|
||||
cell.setCellValue((String) optional.get().get("base_name"));
|
||||
headMap.put(split[i], i);
|
||||
} else {
|
||||
if ("date".equals(split[i]) || "name".equals(split[i])) {
|
||||
Cell cell = fisrtRow.createCell(i);
|
||||
cell.setCellValue(title);
|
||||
headMap.put(split[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Row row = sheet1.createRow(i + startRow);
|
||||
Map<String, Object> map = list.get(i);
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
Cell cell = row.createCell(headMap.get(entry.getKey()));
|
||||
cell.setCellValue(String.valueOf(entry.getValue()));
|
||||
}
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入表格
|
||||
*
|
||||
* @param list
|
||||
* @param startRow
|
||||
* @param sheet
|
||||
* @param filePath
|
||||
* @param split
|
||||
* @param headList
|
||||
* @param title
|
||||
* @return
|
||||
*/
|
||||
public static Workbook writeToDayMonth(List<Map<String, Object>> list, int startRow, String sheet, String filePath, String[] split, Map<String, Object> headList, String title) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet1 = workbook.createSheet(sheet);
|
||||
Row fisrtRow = sheet1.createRow(0);
|
||||
Map<String, Integer> headMap = new HashMap<>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
Cell cell = fisrtRow.createCell(i);
|
||||
cell.setCellValue((String) headList.get(split[i]));
|
||||
headMap.put(split[i], i);
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Row row = sheet1.createRow(i + startRow);
|
||||
Map<String, Object> map = list.get(i);
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
if (!StringUtils.isEmpty(headMap.get(entry.getKey()))) {
|
||||
Cell cell = row.createCell(headMap.get(entry.getKey()));
|
||||
cell.setCellValue(String.valueOf(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无模板导出
|
||||
*
|
||||
* @param list
|
||||
* @param startRow
|
||||
* @param sheet
|
||||
* @param fileHead
|
||||
* @return
|
||||
*/
|
||||
public static Workbook writeListNoFile(List<Map<String, Object>> list, int startRow, String sheet, String[] fileHead) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet1 = workbook.getSheet(sheet);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Row row = sheet1.createRow(i + startRow);
|
||||
Map<String, Object> map = list.get(i);
|
||||
int j = 0;
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
Cell cell = row.createCell(j);
|
||||
cell.setCellValue(String.valueOf(entry.getValue()));
|
||||
}
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(POIUtil.class.getClassLoader().getResource("a.xlsx").getPath());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> validCode(String code) {
|
||||
Condition condition = Condition.creatCriteria().andEqual("ROLE_CODE", code).build();
|
||||
Condition condition = Condition.creatCriteria().andEqual("ROLE_CODE", code).andEqual("DELETED",1).build();
|
||||
Long i = baseMapper.count(TABLE_NAME, condition);
|
||||
if (i > 0L) {
|
||||
return ResultVO.getFailed("角色编码不能重复");
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.hcframe.user.module.manage.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @version 1.0
|
||||
* @className ManageMapper
|
||||
* @date 2021年04月06日 4:26 下午
|
||||
* @description 描述
|
||||
*/
|
||||
public interface ManageMapper {
|
||||
List<Map<String, Object>> selectPersonList(String name, String department);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.hcframe.user.module.manage.mapper.impl;
|
||||
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.BaseMapperImpl;
|
||||
import com.hcframe.user.module.manage.mapper.ManageMapper;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
* @version 1.0
|
||||
* @className ManageMapperImpl
|
||||
* @date 2021年04月06日 4:27 下午
|
||||
* @description 描述
|
||||
*/
|
||||
@Component
|
||||
public class ManageMapperImpl implements ManageMapper {
|
||||
|
||||
final BaseMapper baseMapper;
|
||||
|
||||
public ManageMapperImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper){
|
||||
this.baseMapper = baseMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> selectPersonList(String name, String department) {
|
||||
String sql = "SELECT GB_CAS_MEMBER.ID,GB_CAS_MEMBER.NAME,GB_CAS_DEPT.NAME \n" +
|
||||
"FROM GBCAS.GB_CAS_MEMBER \n" +
|
||||
"LEFT JOIN GBCAS.GB_CAS_DEPT ON GB_CAS_MEMBER.DEPT_CODE = GB_CAS_DEPT.CODE\n" +
|
||||
"WHERE GB_CAS_MEMBER.NAME = '" + name + "' AND GB_CAS_DEPT.NAME = '"+department+"' AND DELETED = 1";
|
||||
return baseMapper.selectSql(sql);
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,30 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.hcframe.base.common.ResultVO;
|
||||
import com.hcframe.base.common.ServiceException;
|
||||
import com.hcframe.base.common.WebPageInfo;
|
||||
import com.hcframe.base.common.utils.DateUtil;
|
||||
import com.hcframe.base.common.utils.JudgeException;
|
||||
import com.hcframe.base.module.data.module.BaseMapper;
|
||||
import com.hcframe.base.module.data.module.BaseMapperImpl;
|
||||
import com.hcframe.base.module.data.service.TableService;
|
||||
import com.hcframe.base.module.tableconfig.entity.OsSysTable;
|
||||
import com.hcframe.user.common.utils.MD5Utils;
|
||||
import com.hcframe.user.common.utils.POIUtil;
|
||||
import com.hcframe.user.module.manage.mapper.ManageMapper;
|
||||
import com.hcframe.user.module.manage.service.ManageService;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.hcframe.user.module.manage.service.ManageService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -40,11 +49,19 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
|
||||
final TableService tableService;
|
||||
|
||||
final ManageMapper manageMapper;
|
||||
|
||||
final POIUtil poiUtil;
|
||||
|
||||
|
||||
public ManageServiceDataImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper,
|
||||
TableService tableService) {
|
||||
TableService tableService,
|
||||
ManageMapper manageMapper,
|
||||
POIUtil poiUtil) {
|
||||
this.baseMapper = baseMapper;
|
||||
this.tableService = tableService;
|
||||
this.manageMapper = manageMapper;
|
||||
this.poiUtil = poiUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,8 +138,37 @@ public class ManageServiceDataImpl implements ManageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultVO<Object> sync() {
|
||||
baseMapper.selectAll("GB_CAS_MEMBER");
|
||||
Workbook workbook = POIUtil.getWorkBook("/Volumes/DATA/2021年3月花名册.xlsx");
|
||||
Sheet sheet = workbook.getSheet("Sheet1");
|
||||
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
Cell cell = row.getCell(1);
|
||||
String department = cell.getStringCellValue();
|
||||
cell = row.getCell(2);
|
||||
String name = cell.getStringCellValue();
|
||||
cell = row.getCell(3);
|
||||
String date = String.valueOf(cell.getNumericCellValue());
|
||||
cell = row.getCell(4);
|
||||
String title = cell.getStringCellValue();
|
||||
List<Map<String, Object>> list = manageMapper.selectPersonList(name, department);
|
||||
if (list != null&&list.size()>0) {
|
||||
System.out.println(name+":"+list.get(0).get("ID"));
|
||||
System.out.println(name+":"+list.get(0).get("ID"));
|
||||
String str = date.substring(date.indexOf(".") + 1, date.length());
|
||||
if (str.equals("1")) {
|
||||
date = date + "0";
|
||||
}
|
||||
System.out.println(date.trim()+".01 00:00:00");
|
||||
Date date1 = DateUtil.StringFormat(date.trim()+".01 00:00:00","yyyy.MM.dd HH:mm:ss");
|
||||
for (Map<String, Object> map : list) {
|
||||
map.put("TIME_TO_WORK", date1);
|
||||
map.put("TITLE_NAME", title);
|
||||
baseMapper.updateByPk(TABLE_INFO, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ spring:
|
||||
druid:
|
||||
# 配置sqlite文件路径,需要填写绝对路径,推荐将sqlite文件放入到服务器上,而非程序jar包或war包中
|
||||
driver-class-name: dm.jdbc.driver.DmDriver
|
||||
url: jdbc:dm://192.168.1.131:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
|
||||
url: jdbc:dm://192.168.100.98:5236/GBCAS?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
|
||||
username: GBCAS
|
||||
password: 123456789
|
||||
#使用Druid数据源
|
||||
|
||||
Reference in New Issue
Block a user