v 2.3.0 GA

This commit is contained in:
Crystal.Sea
2020-11-12 07:24:22 +08:00
parent 2928bff260
commit a44022b625
23 changed files with 490 additions and 184 deletions

View File

@@ -17,7 +17,22 @@
package org.maxkey.persistence.service;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
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.maxkey.domain.Organizations;
import org.maxkey.identity.kafka.KafkaIdentityAction;
import org.maxkey.identity.kafka.KafkaIdentityTopic;
@@ -25,6 +40,10 @@ import org.maxkey.identity.kafka.KafkaProvisioningService;
import org.maxkey.persistence.mapper.OrganizationsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
@Service
public class OrganizationsService extends JpaBaseService<Organizations>{
@@ -71,5 +90,183 @@ public class OrganizationsService extends JpaBaseService<Organizations>{
}
return false;
}
public boolean importing(MultipartFile file) {
if(file ==null){
return false;
}
InputStream is = null;
Workbook wb = null;
List<Organizations> orgsList = null;
try {
is = file.getInputStream();
String xls = ".xls";
String xlsx = ".xlsx";
int columnSize = 46;
orgsList = Lists.newArrayList();
if (file.getOriginalFilename().toLowerCase().endsWith(xls)) {
wb = new HSSFWorkbook(is);
} else if (file.getOriginalFilename().toLowerCase().endsWith(xlsx)) {
wb = new XSSFWorkbook(is);
} else {
throw new RuntimeException("maxKey用户导入没有Excel类型");
}
int sheetSize = wb.getNumberOfSheets();
//遍历sheet页
for (int i = 0; i < sheetSize; i++) {
Sheet sheet = wb.getSheetAt(i);
int rowSize = sheet.getLastRowNum() + 1;
//遍历行
for (int j = 1; j < rowSize; j++) {
Row row = sheet.getRow(j);
//略过空行和前3行
if (row == null || j <3 ) {
continue;
} else {
//其他行是数据行
Organizations organization =new Organizations();
for (int k = 0; k < columnSize; k++) {
if (k == 0) {
// 上级编码
Cell cell = row.getCell(k);
organization.setParentId(getValue(cell));
} else if (k == 1) {
// 上级名称
Cell cell = row.getCell(k);
organization.setParentName(getValue(cell));
} else if (k == 2) {
// 机构编码
Cell cell = row.getCell(k);
organization.setId(getValue(cell));
} else if (k == 3) {
// 机构名称
Cell cell = row.getCell(k);
organization.setName(getValue(cell));
} else if (k == 4) {
// 机构全称
Cell cell = row.getCell(k);
organization.setFullName(getValue(cell));
} else if (k == 5) {
// 编码路径
Cell cell = row.getCell(k);
organization.setCodePath(getValue(cell));
} else if (k == 6) {
// 名称路径
Cell cell = row.getCell(k);
organization.setNamePath(getValue(cell));
} else if (k == 7) {
// 机构类型
Cell cell = row.getCell(k);
organization.setType(getValue(cell));
} else if (k == 8) {
// 所属分支机构
Cell cell = row.getCell(k);
organization.setDivision(getValue(cell));
} else if (k == 9) {
// 级别
Cell cell = row.getCell(k);
String level=getValue(cell);
organization.setLevel(level.equals("") ? "1" : level);
} else if (k == 10) {
// 排序
Cell cell = row.getCell(k);
String sortIndex=getValue(cell);
organization.setSortIndex(sortIndex.equals("") ? "1" : sortIndex);
} else if (k == 11) {
// 联系人
Cell cell = row.getCell(k);
organization.setContact(getValue(cell));
} else if (k == 12) {
// 联系电话
Cell cell = row.getCell(k);
organization.setPhone(getValue(cell));
}else if (k == 13) {
// 邮箱
Cell cell = row.getCell(k);
organization.setEmail(getValue(cell));
}else if (k == 14) {
// 传真
Cell cell = row.getCell(k);
organization.setFax(getValue(cell));
}else if (k == 24) {
// 工作-国家
Cell cell = row.getCell(k);
organization.setCountry(getValue(cell));
}else if (k == 25) {
// 工作-省
Cell cell = row.getCell(k);
organization.setRegion(getValue(cell));
}else if (k == 26) {
// 工作-城市
Cell cell = row.getCell(k);
organization.setLocality(getValue(cell));
}else if (k == 27) {
// 工作-地址
Cell cell = row.getCell(k);
organization.setLocality(getValue(cell));
}else if (k == 28) {
// 邮编
Cell cell = row.getCell(k);
organization.setPostalCode(getValue(cell));
}else if (k == 29) {
// 详细描述
Cell cell = row.getCell(k);
organization.setDescription(getValue(cell));
}
}
organization.setStatus("1");
orgsList.add(organization);
}
}
}
// 数据去重
if(CollectionUtils.isEmpty(orgsList)){
orgsList = orgsList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new));
}
} catch (IOException e) {
e.printStackTrace();
}finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(wb != null) {
try {
wb.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return batchInsert(orgsList);
}
/**
* 根据数据格式返回数据
*
* @param cell
* @return
*/
public static String getValue(Cell cell) {
if (cell == null) {
return "";
} else if (cell.getCellType() == CellType.BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
cell.setBlank();
return String.valueOf(cell.getStringCellValue().trim());
} else {
return String.valueOf(cell.getStringCellValue().trim());
}
}
}

View File

@@ -90,7 +90,6 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
*/
@Override
public UserInfoMapper getMapper() {
// TODO Auto-generated method stub
return (UserInfoMapper)super.getMapper();
}
@@ -357,10 +356,11 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
return false;
}
InputStream is = null;
Workbook wb = null;
List<UserInfo> userInfoList = null;
try {
is = file.getInputStream();
Workbook wb;
String xls = ".xls";
String xlsx = ".xlsx";
int columnSize = 46;
@@ -382,15 +382,14 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
//遍历行
for (int j = 1; j < rowSize; j++) {
Row row = sheet.getRow(j);
//略过空行和第一
if (row == null || j <2 ) {
//略过空行和前3
if (row == null || j <3 ) {
continue;
} else {
//其他行是数据行
UserInfo userInfo = new UserInfo();
userInfo.setCreatedDate(DateUtils.formatDateTime(new Date()));
int rangeType = -1;
for (int k = 0; k < columnSize; k++) {
if (k == 0) {
// 登录账号
@@ -401,61 +400,62 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
Cell cell = row.getCell(k);
userInfo.setPassword(getValue(cell));
} else if (k == 2) {
// 员工编码
Cell cell = row.getCell(k);
userInfo.setEmployeeNumber(getValue(cell));
} else if (k == 3) {
// 用户类型
Cell cell = row.getCell(k);
userInfo.setUserType(getValue(cell));
} else if (k == 4) {
// 用户名
// 用户显示
Cell cell = row.getCell(k);
userInfo.setDisplayName(getValue(cell));
} else if (k == 5) {
} else if (k == 3) {
// 姓
Cell cell = row.getCell(k);
userInfo.setFamilyName(getValue(cell));
} else if (k == 6) {
} else if (k == 4) {
// 名
Cell cell = row.getCell(k);
userInfo.setGivenName(getValue(cell));
} else if (k == 7) {
} else if (k == 5) {
// 中间名
Cell cell = row.getCell(k);
userInfo.setMiddleName(getValue(cell));
} else if (k == 8) {
} else if (k == 6) {
// 昵称
Cell cell = row.getCell(k);
userInfo.setNickName(getValue(cell));
} else if (k == 9) {
} else if (k == 7) {
// 性别
Cell cell = row.getCell(k);
userInfo.setGender(Integer.valueOf(getValue(cell)));
} else if (k == 10) {
// AD域账号
Cell cell = row.getCell(k);
userInfo.setWindowsAccount(getValue(cell));
} else if (k == 11) {
// 出生日期
Cell cell = row.getCell(k);
userInfo.setBirthDate(getValue(cell));
} else if (k == 12) {
String gender = getValue(cell);
userInfo.setGender(gender.equals("")? 1 : Integer.valueOf(getValue(cell)));
} else if (k == 8) {
// 语言偏好
Cell cell = row.getCell(k);
userInfo.setPreferredLanguage(getValue(cell));
} else if (k == 13) {
} else if (k == 9) {
// 时区
Cell cell = row.getCell(k);
userInfo.setTimeZone(getValue(cell));
}else if (k == 14) {
} else if (k == 10) {
// 用户类型
Cell cell = row.getCell(k);
userInfo.setUserType(getValue(cell));
} else if (k == 11) {
// 员工编码
Cell cell = row.getCell(k);
userInfo.setEmployeeNumber(getValue(cell));
} else if (k == 12) {
// AD域账号
Cell cell = row.getCell(k);
userInfo.setWindowsAccount(getValue(cell));
}else if (k == 13) {
// 所属机构
Cell cell = row.getCell(k);
userInfo.setOrganization(getValue(cell));
}else if (k == 15) {
}else if (k == 14) {
// 分支机构
Cell cell = row.getCell(k);
userInfo.setDivision(getValue(cell));
}else if (k == 15) {
// 部门编号
Cell cell = row.getCell(k);
userInfo.setDepartmentId(getValue(cell));
}else if (k == 16) {
// 部门名称
Cell cell = row.getCell(k);
@@ -528,54 +528,58 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
// 证件号码
Cell cell = row.getCell(k);
userInfo.setIdCardNo(getValue(cell));
}else if (k == 34) {
} else if (k == 34) {
// 出生日期
Cell cell = row.getCell(k);
userInfo.setBirthDate(getValue(cell));
}else if (k == 35) {
// 婚姻状态 todo 现在数据字段类型是 tinyint
// Cell cell = row.getCell(k);
// userInfo.setMarried(getValue(cell));
}else if (k == 35) {
}else if (k == 36) {
// 开始工作时间
Cell cell = row.getCell(k);
userInfo.setStartWorkDate(getValue(cell));
}else if (k == 36) {
// 国家
Cell cell = row.getCell(k);
userInfo.setHomeCountry(getValue(cell));
}else if (k == 37) {
// 省
Cell cell = row.getCell(k);
userInfo.setHomeRegion(getValue(cell));
}else if (k == 38) {
// 城市
Cell cell = row.getCell(k);
userInfo.setHomeLocality(getValue(cell));
}else if (k == 39) {
// 家庭地址
Cell cell = row.getCell(k);
userInfo.setHomeStreetAddress(getValue(cell));
}else if (k == 40) {
// 家庭邮编
Cell cell = row.getCell(k);
userInfo.setHomePostalCode(getValue(cell));
}else if (k == 41) {
// 家庭传真
Cell cell = row.getCell(k);
userInfo.setHomeFax(getValue(cell));
}else if (k == 42) {
// 家庭电话
Cell cell = row.getCell(k);
userInfo.setHomePhoneNumber(getValue(cell));
}else if (k == 43) {
// 家庭邮箱
Cell cell = row.getCell(k);
userInfo.setHomeEmail(getValue(cell));
}else if (k == 44) {
// 个人主页
Cell cell = row.getCell(k);
userInfo.setWebSite(getValue(cell));
}else if (k == 45) {
}else if (k == 38) {
// 即时通讯
Cell cell = row.getCell(k);
userInfo.setDefineIm(getValue(cell));
}else if (k == 39) {
// 国家
Cell cell = row.getCell(k);
userInfo.setHomeCountry(getValue(cell));
}else if (k == 40) {
// 省
Cell cell = row.getCell(k);
userInfo.setHomeRegion(getValue(cell));
}else if (k == 41) {
// 城市
Cell cell = row.getCell(k);
userInfo.setHomeLocality(getValue(cell));
}else if (k == 42) {
// 家庭地址
Cell cell = row.getCell(k);
userInfo.setHomeStreetAddress(getValue(cell));
}else if (k == 43) {
// 家庭邮编
Cell cell = row.getCell(k);
userInfo.setHomePostalCode(getValue(cell));
}else if (k == 44) {
// 家庭传真
Cell cell = row.getCell(k);
userInfo.setHomeFax(getValue(cell));
}else if (k == 45) {
// 家庭电话
Cell cell = row.getCell(k);
userInfo.setHomePhoneNumber(getValue(cell));
}else if (k == 46) {
// 家庭邮箱
Cell cell = row.getCell(k);
userInfo.setHomeEmail(getValue(cell));
}
}
userInfo.setStatus(1);
@@ -595,7 +599,13 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(wb != null) {
try {
wb.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -617,7 +627,7 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
} else if (cell.getCellType() == CellType.BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
cell.setCellType(CellType.STRING);
cell.setBlank();
return String.valueOf(cell.getStringCellValue().trim());
} else {
return String.valueOf(cell.getStringCellValue().trim());

View File

@@ -24,7 +24,7 @@ spring.servlet.multipart.max-file-size=4194304
#server.servlet.encoding.force=true
#datasource
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.password=maxkey
spring.datasource.url=jdbc:mysql://localhost/maxkey?autoReconnect=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
@@ -69,24 +69,24 @@ spring.messages.encoding=UTF-8
spring.main.banner-mode=log
spring.main.allow-bean-definition-overriding=true
###########【Kafka集群】###########
###########\u3010Kafka\u96c6\u7fa4\u3011###########
spring.kafka.bootstrap-servers=localhost:9092
###########【初始化生产者配置】###########
# 重试次数
###########\u3010\u521d\u59cb\u5316\u751f\u4ea7\u8005\u914d\u7f6e\u3011###########
# \u91cd\u8bd5\u6b21\u6570
spring.kafka.producer.retries=0
# 应答级别:多少个分区副本备份完成时向生产者发送ack确认(可选0、1、all/-1)
# \u5e94\u7b54\u7ea7\u522b:\u591a\u5c11\u4e2a\u5206\u533a\u526f\u672c\u5907\u4efd\u5b8c\u6210\u65f6\u5411\u751f\u4ea7\u8005\u53d1\u9001ack\u786e\u8ba4(\u53ef\u90090\u30011\u3001all/-1)
spring.kafka.producer.acks=1
# 批量大小
# \u6279\u91cf\u5927\u5c0f
spring.kafka.producer.batch-size=16384
# 提交延时
# \u63d0\u4ea4\u5ef6\u65f6
spring.kafka.producer.properties.linger.ms=0
# 当生产端积累的消息达到batch-size或接收到消息linger.ms后,生产者就会将消息提交给kafka
# linger.ms为0表示每接收到一条消息就提交给kafka,这时候batch-size其实就没用了
# \u5f53\u751f\u4ea7\u7aef\u79ef\u7d2f\u7684\u6d88\u606f\u8fbe\u5230batch-size\u6216\u63a5\u6536\u5230\u6d88\u606flinger.ms\u540e,\u751f\u4ea7\u8005\u5c31\u4f1a\u5c06\u6d88\u606f\u63d0\u4ea4\u7ed9kafka
# linger.ms\u4e3a0\u8868\u793a\u6bcf\u63a5\u6536\u5230\u4e00\u6761\u6d88\u606f\u5c31\u63d0\u4ea4\u7ed9kafka,\u8fd9\u65f6\u5019batch-size\u5176\u5b9e\u5c31\u6ca1\u7528\u4e86
# 生产端缓冲区大小
# \u751f\u4ea7\u7aef\u7f13\u51b2\u533a\u5927\u5c0f
spring.kafka.producer.buffer-memory = 33554432
# Kafka提供的序列化和反序列化类
# Kafka\u63d0\u4f9b\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7c7b
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
# 自定义分区器
# \u81ea\u5b9a\u4e49\u5206\u533a\u5668
# spring.kafka.producer.properties.partitioner.class=com.felix.kafka.producer.CustomizePartitioner