新需求开发

This commit is contained in:
wanghao
2025-09-17 14:30:53 +08:00
parent 3e4f5ebe3e
commit cd6b8e49e5
19 changed files with 991 additions and 44 deletions
@@ -913,4 +913,8 @@ public class SysDepartController {
return sysDepartService.queryDepartNameByOrgCodes(orgCodeSet);
}
@GetMapping("/departDataInit")
public void departDataInit(){
sysDepartService.departDataInit();
}
}
@@ -264,4 +264,6 @@ public interface ISysDepartService extends IService<SysDepart> {
List<BaseUser> queryUserByOrgCode(String orgCode);
Map<String, String> queryDepartNameByOrgCodes(Set<String> orgCodeSet);
void departDataInit();
}
@@ -15,6 +15,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.config.TenantContext;
import org.jeecg.common.constant.CommonConstant;
@@ -38,11 +43,14 @@ import org.jeecg.modules.system.manager.UserCacheManager;
import org.jeecg.modules.system.mapper.*;
import org.jeecg.modules.system.model.DepartIdModel;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.untils.CoordinateConverter;
import org.jeecg.modules.system.util.FindsDepartsChildrenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -82,6 +90,8 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
private SysUserRoleMapper sysUserRoleMapper;
@Autowired
private UserCacheManager userCacheManager;
@Autowired
private CoordinateConverter converter;
@Override
//todo departids字段做了调整,这里功能需要的话,后面再改
@@ -1520,4 +1530,135 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
return departMapper.selectDepartGpsByDepartId(departId);
}
@Override
@Transactional
public void departDataInit() {
String filePath = "D:\\Project\\Java\\rk\\文档\\新疆油田-24\\各二级单位坐标位置更正统计9.15.xlsx";
// 获取目前的二级单位数据
List<SysDepart> secondDeparts = departMapper
.selectList(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getParentId, "1683768826307096578"));
// 二级单位名称分组
Map<String, SysDepart> secondMap = secondDeparts.stream()
.collect(Collectors.toMap(SysDepart::getDepartName, depart -> depart, (existing, replacement) -> existing));
// 获取目前的三级部门数据
List<SysDepart> threeDeparts = departMapper
.selectList(new LambdaQueryWrapper<SysDepart>()
.in(SysDepart::getParentId, secondDeparts.stream().map(SysDepart::getId).collect(Collectors.toList())));
// 三级部门名称分组
Map<String, SysDepart> threeMap = threeDeparts.stream()
.collect(Collectors.toMap(SysDepart::getDepartName, depart -> depart, (existing, replacement) -> existing));
// 获取目前的四级部门数据
List<SysDepart> fourDeparts = departMapper
.selectList(new LambdaQueryWrapper<SysDepart>()
.in(SysDepart::getParentId, threeDeparts.stream().map(SysDepart::getId).collect(Collectors.toList())));
// 三级部门名称分组
Map<String, SysDepart> fourMap = fourDeparts.stream()
.collect(Collectors.toMap(SysDepart::getDepartName, depart -> depart, (existing, replacement) -> existing));
List<SysDepart> secondDepartList = new ArrayList<>();
List<SysDepart> threeDepartList = new ArrayList<>();
List<SysDepart> fourDepartList = new ArrayList<>();
try (FileInputStream file = new FileInputStream(filePath);
XSSFWorkbook workbook = new XSSFWorkbook(file)) {
// 获取第一个工作表
XSSFSheet sheet = workbook.getSheetAt(0);
// 从第二行开始(索引为1
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
// 获取第一个单元格(索引0)的数据 二级单位名称
XSSFCell firstCell = row.getCell(0);
String firstCellValue = firstCell != null ? getCellValue(firstCell) : "[空]";
// 获取第二个单元格(索引1)的数据 三级部门名称
XSSFCell secondCell = row.getCell(1);
String secondCellValue = secondCell != null ? getCellValue(secondCell) : "[空]";
// 获取第三个单元格(索引1)的数据 经度
XSSFCell threeCell = row.getCell(2);
String threeCellValue = secondCell != null ? getCellValue(threeCell) : "[空]";
// 获取第四个单元格(索引1)的数据 经度
XSSFCell fourCell = row.getCell(3);
String fourCellValue = secondCell != null ? getCellValue(fourCell) : "[空]";
if (StrUtil.isNotBlank(firstCellValue)) {
SysDepart depart = secondMap.get(firstCellValue);
if (depart == null) {
// 现有不存在 需添加
SysDepart newDepart = new SysDepart();
newDepart.setDepartName(firstCellValue);
newDepart.setParentId("1683768826307096578");
newDepart.setOrgCategory("2");
newDepart.setOrgType("2");
this.saveDepartData(newDepart,GlobalUtils.getLoginUser().getUsername());
if (null != newDepart.getId()){
SysDepartGps departGps = new SysDepartGps();
departGps.setDepartId(newDepart.getId());
String run = converter.run(threeCellValue + "-" + fourCellValue);
System.out.println(run);
// // 经度
// departGps.setLng();
// // 纬度
// departGps.setLat();
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("读取Excel文件失败: " + e.getMessage());
}
}
/**
* 获取单元格的值
*/
private String getCellValue(XSSFCell cell) {
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case STRING:
return cell.getStringCellValue().trim();
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue().toString();
} else {
// 处理数字格式,避免科学计数法
double numericValue = cell.getNumericCellValue();
if (numericValue == Math.floor(numericValue)) {
// 如果是整数
return String.valueOf((long) numericValue);
} else {
// 如果是小数
return String.valueOf(numericValue);
}
}
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
case FORMULA:
try {
return String.valueOf(cell.getNumericCellValue());
} catch (Exception e) {
return cell.getStringCellValue().trim();
}
case BLANK:
return "";
default:
return "";
}
}
}