fix: 优化逻辑
This commit is contained in:
parent
76821ca786
commit
8c20e76cd0
@ -65,11 +65,23 @@ public class FishDraftData implements Serializable {
|
||||
*/
|
||||
private Date strdt;
|
||||
|
||||
/**
|
||||
* 开始日期
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String strdtStr;
|
||||
|
||||
/**
|
||||
* 结束日期
|
||||
*/
|
||||
private Date enddt;
|
||||
|
||||
/**
|
||||
* 结束日期
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String enddtStr;
|
||||
|
||||
/**
|
||||
* 游向(上行/下行/上行折返/下行折返)
|
||||
*/
|
||||
|
||||
@ -413,12 +413,19 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
case "strdt":
|
||||
if (!StringUtils.hasText(cellValue)) {
|
||||
importRow.getWarnings().add(fieldName);
|
||||
data.setStrdtStr(cellValue);
|
||||
} else {
|
||||
Date strdt = parseDate(cellValue);
|
||||
if (strdt == null) {
|
||||
importRow.getWarnings().add(fieldName);
|
||||
data.setStrdt(null);
|
||||
data.setStrdtStr(cellValue);
|
||||
}else{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = sdf.format(strdt);
|
||||
data.setStrdtStr(dateString);
|
||||
data.setStrdt(strdt);
|
||||
}
|
||||
data.setStrdt(strdt);
|
||||
}
|
||||
break;
|
||||
case "enddt":
|
||||
@ -452,6 +459,13 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
objectObjectHashMap.put("value", fileName);
|
||||
importRow.getVdpthList().add(objectObjectHashMap);
|
||||
vdpthList.add(fileName);
|
||||
} else if (com.yfd.platform.utils.FileUtil.isVideoFileName(fileName)) {
|
||||
Map<String, String> objectObjectHashMap = new HashMap<>();
|
||||
objectObjectHashMap.put("name", fileName);
|
||||
objectObjectHashMap.put("value", fileName);
|
||||
importRow.getVdpthList().add(objectObjectHashMap);
|
||||
vdpthList.add(fileName);
|
||||
importRow.getVdpthsWarnings().add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,6 +488,13 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
objectObjectHashMap.put("value", fileName);
|
||||
importRow.getPicpthList().add(objectObjectHashMap);
|
||||
picpthList.add(fileName);
|
||||
} else if (!com.yfd.platform.utils.FileUtil.isImageFileName(fileName)) {
|
||||
Map<String, String> objectObjectHashMap = new HashMap<>();
|
||||
objectObjectHashMap.put("name", fileName);
|
||||
objectObjectHashMap.put("value", fileName);
|
||||
importRow.getPicpthList().add(objectObjectHashMap);
|
||||
picpthList.add(fileName);
|
||||
importRow.getPicpthsWarnings().add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -529,6 +550,8 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
return importRow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void validateStationFpssRelation(FishDraftData data, FishImportResult.FishImportRow importRow) {
|
||||
loadStationAndBaseCache();
|
||||
if (StringUtils.hasText(data.getHbrvcd()) && StringUtils.hasText(data.getRstcd())) {
|
||||
@ -1119,28 +1142,54 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析日期字符串,支持多种格式
|
||||
* @param dateStr 日期字符串
|
||||
* @return 解析后的 Date 对象,如果解析失败返回 null
|
||||
*/
|
||||
private Date parseDate(String dateStr) {
|
||||
if (!StringUtils.hasText(dateStr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 去除首尾空格
|
||||
dateStr = dateStr.trim();
|
||||
|
||||
// 支持的日期格式列表(按常用程度排序)
|
||||
String[] patterns = {
|
||||
"yyyy-MM-dd HH:mm:ss",
|
||||
"yyyy-MM-dd",
|
||||
"yyyy/MM/dd",
|
||||
"yyyy.MM.dd",
|
||||
"yyyyMMdd"
|
||||
"yyyy-MM-dd HH:mm:ss", // 2024-01-15 14:30:00
|
||||
"yyyy-MM-dd", // 2024-01-15
|
||||
"yyyy/MM/dd HH:mm:ss", // 2024/01/15 14:30:00
|
||||
"yyyy/MM/dd", // 2024/01/15
|
||||
"yyyy.MM.dd HH:mm:ss", // 2024.01.15 14:30:00
|
||||
"yyyy.MM.dd", // 2024.01.15
|
||||
"yyyyMMdd HHmmss", // 20240115 143000
|
||||
"yyyyMMdd", // 20240115
|
||||
"yyyy年MM月dd日", // 2024年01月15日
|
||||
"yyyy年MM月dd日HH时mm分ss秒" // 2024年01月15日14时30分00秒
|
||||
};
|
||||
|
||||
for (String pattern : patterns) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
sdf.setLenient(false);
|
||||
return sdf.parse(dateStr);
|
||||
} catch (ParseException ignored) {
|
||||
sdf.setLenient(false); // 严格模式,不允许非法日期
|
||||
Date parsedDate = sdf.parse(dateStr);
|
||||
|
||||
// 验证解析后的日期是否合理(例如年份不能是 0001)
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(parsedDate);
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
if (year >= 1900 && year <= 2100) {
|
||||
return parsedDate;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
// 尝试下一个格式
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("无法解析日期: '{}'", dateStr);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer parseInteger(String value) {
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return null;
|
||||
|
||||
@ -69,11 +69,110 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
|
||||
|
||||
@Override
|
||||
public List<SdEngInfoBH> selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) {
|
||||
String baseId = sdEngInfoBHRequest.getBaseId();
|
||||
String hbrvcd = sdEngInfoBHRequest.getHbrvcd();
|
||||
String ennm = sdEngInfoBHRequest.getEnnm();
|
||||
List<String> rvcds = sdEngInfoBHRequest.getRvcds();
|
||||
List<String> hbrvcds = sdEngInfoBHRequest.getHbrvcds();
|
||||
String userId = SecurityUtils.getUserId();
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
|
||||
// 管理员直接查询
|
||||
if ("admin".equals(currentUsername)) {
|
||||
return queryEngInfoList(sdEngInfoBHRequest, null, null);
|
||||
}
|
||||
|
||||
// 获取用户权限范围
|
||||
List<SysUserDataScope> sysUserDataScopes = sysUserDataScopeMapper.selectList(
|
||||
new LambdaQueryWrapper<SysUserDataScope>()
|
||||
.eq(SysUserDataScope::getUserId, userId)
|
||||
.select(SysUserDataScope::getOrgId, SysUserDataScope::getOrgType)
|
||||
);
|
||||
|
||||
if (sysUserDataScopes == null || sysUserDataScopes.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 分类权限类型
|
||||
Set<String> stationCodes = new HashSet<>();
|
||||
Set<String> basinCodes = new HashSet<>();
|
||||
|
||||
for (SysUserDataScope scope : sysUserDataScopes) {
|
||||
String orgType = scope.getOrgType();
|
||||
String orgId = scope.getOrgId();
|
||||
|
||||
if ("STATION".equals(orgType)) {
|
||||
stationCodes.add(orgId);
|
||||
} else if ("HBRVCD".equals(orgType)) {
|
||||
basinCodes.add(orgId);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有具体站点权限且数量较少,直接使用 IN
|
||||
if (!stationCodes.isEmpty() && stationCodes.size() <= 100) {
|
||||
return queryEngInfoList(sdEngInfoBHRequest, stationCodes, null);
|
||||
}
|
||||
|
||||
// 如果只有流域权限或站点数量过多,使用流域过滤
|
||||
if (!basinCodes.isEmpty()) {
|
||||
return queryEngInfoList(sdEngInfoBHRequest, null, basinCodes);
|
||||
}
|
||||
|
||||
// 站点数量过多但没有流域信息,分批查询
|
||||
if (!stationCodes.isEmpty()) {
|
||||
return queryEngInfoByBatches(sdEngInfoBHRequest, stationCodes);
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询工程信息列表
|
||||
*/
|
||||
private List<SdEngInfoBH> queryEngInfoList(SdEngInfoBHRequest request,
|
||||
Set<String> stationCodes,
|
||||
Set<String> basinCodes) {
|
||||
LambdaQueryWrapper<SdEngInfoBH> wrapper = buildQueryWrapper(request);
|
||||
|
||||
// 添加权限过滤
|
||||
if (stationCodes != null && !stationCodes.isEmpty()) {
|
||||
wrapper.in(SdEngInfoBH::getStcd, stationCodes);
|
||||
} else if (basinCodes != null && !basinCodes.isEmpty()) {
|
||||
wrapper.in(SdEngInfoBH::getHbrvcd, basinCodes);
|
||||
}
|
||||
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分批查询(当站点数量过多时)
|
||||
*/
|
||||
private List<SdEngInfoBH> queryEngInfoByBatches(SdEngInfoBHRequest request, Set<String> stationCodes) {
|
||||
List<SdEngInfoBH> result = new ArrayList<>();
|
||||
int batchSize = 100; // 每批最多 100 个站点
|
||||
|
||||
List<String> stationList = new ArrayList<>(stationCodes);
|
||||
for (int i = 0; i < stationList.size(); i += batchSize) {
|
||||
int end = Math.min(i + batchSize, stationList.size());
|
||||
List<String> batch = stationList.subList(i, end);
|
||||
|
||||
LambdaQueryWrapper<SdEngInfoBH> wrapper = buildQueryWrapper(request);
|
||||
wrapper.in(SdEngInfoBH::getStcd, batch);
|
||||
|
||||
List<SdEngInfoBH> batchResult = this.list(wrapper);
|
||||
if (batchResult != null && !batchResult.isEmpty()) {
|
||||
result.addAll(batchResult);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
private LambdaQueryWrapper<SdEngInfoBH> buildQueryWrapper(SdEngInfoBHRequest request) {
|
||||
String baseId = request.getBaseId();
|
||||
String hbrvcd = request.getHbrvcd();
|
||||
String ennm = request.getEnnm();
|
||||
List<String> rvcds = request.getRvcds();
|
||||
List<String> hbrvcds = request.getHbrvcds();
|
||||
|
||||
LambdaQueryWrapper<SdEngInfoBH> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(StringUtils.hasText(baseId), SdEngInfoBH::getBaseId, baseId)
|
||||
.eq(StringUtils.hasText(hbrvcd), SdEngInfoBH::getHbrvcd, hbrvcd)
|
||||
@ -83,14 +182,7 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
|
||||
.select(SdEngInfoBH::getStcd, SdEngInfoBH::getEnnm, SdEngInfoBH::getBaseId)
|
||||
.orderByAsc(SdEngInfoBH::getOrderIndex);
|
||||
|
||||
Set<String> authorizedStations = getUserAuthorizedStationCodes();
|
||||
if (authorizedStations != null && !authorizedStations.isEmpty()) {
|
||||
wrapper.in(SdEngInfoBH::getStcd, authorizedStations);
|
||||
} else if (!"admin".equals(SecurityUtils.getCurrentUsername())){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return this.list(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -14,6 +14,7 @@ import com.yfd.platform.system.mapper.SysRoleMapper;
|
||||
import com.yfd.platform.system.service.ISysOrganizationService;
|
||||
import com.yfd.platform.system.service.IUserService;
|
||||
import com.yfd.platform.utils.ObjectConverterUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
@ -79,7 +80,7 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
||||
String[] split = orgscope.split(",");
|
||||
List<String> stringList = Arrays.asList(split);
|
||||
Set<String> set = new HashSet<>();
|
||||
if (stringList.size() > 0) {
|
||||
if (!stringList.isEmpty()) {
|
||||
List<SysOrganization> list =
|
||||
sysOrganizationMapper.selectList(new LambdaQueryWrapper<SysOrganization>().in(SysOrganization::getId, stringList));
|
||||
list.forEach(l -> set.add(l.getParentid()));
|
||||
@ -243,20 +244,34 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
||||
***********************************/
|
||||
@Override
|
||||
public List<Map<String, Object>> getOrgScopeTree(String roleId) {
|
||||
LambdaQueryWrapper<SysOrganization> queryWrapper =
|
||||
new LambdaQueryWrapper<>();
|
||||
|
||||
LambdaQueryWrapper<SysOrganization> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if(!"admin".equals(SecurityUtils.getCurrentUsername())){
|
||||
String userId = SecurityUtils.getUserId();
|
||||
List<SysRole> roles = sysRoleMapper.getRoleByUserId(userId);
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (SysRole role : roles) {
|
||||
String orgscope = role.getOrgscope();
|
||||
if(StrUtil.isNotBlank(orgscope)){
|
||||
ids.addAll(Arrays.asList(orgscope.split(",")));
|
||||
}
|
||||
}
|
||||
if(ids.isEmpty()){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
queryWrapper.in(SysOrganization::getId, ids);
|
||||
}
|
||||
queryWrapper.eq(SysOrganization::getIsvaild, '1');
|
||||
queryWrapper.orderByAsc(SysOrganization::getOrgcode);
|
||||
List<Map<String, Object>> listMaps = this.listMaps(queryWrapper);
|
||||
List<Map<String, Object>> mapList = this.listMaps(queryWrapper);
|
||||
List<Map<String, Object>> listMaps = ObjectConverterUtil.convertMapFieldsToEntityFormat(SysOrganization.class, mapList);
|
||||
// 获取当前角色
|
||||
SysRole sysRole = sysRoleMapper.selectById(roleId);
|
||||
String orgscope = sysRole.getOrgscope();
|
||||
List<String> ids = new ArrayList<>();
|
||||
if (StrUtil.isNotBlank(orgscope)) {
|
||||
String[] split = orgscope.split(",");
|
||||
ids = Arrays.asList(split);
|
||||
ids.addAll(Arrays.asList(orgscope.split(",")));
|
||||
}
|
||||
|
||||
for (Map<String, Object> map : listMaps) {
|
||||
String id = (String) map.get("id");
|
||||
if (ids.contains(id)) {
|
||||
|
||||
@ -391,6 +391,42 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
fis.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件名是否为图片类型
|
||||
*/
|
||||
public static boolean isImageFileName(String fileName) {
|
||||
if (fileName == null || fileName.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String lowerName = fileName.toLowerCase();
|
||||
return lowerName.endsWith(".jpg")
|
||||
|| lowerName.endsWith(".jpeg")
|
||||
|| lowerName.endsWith(".png")
|
||||
|| lowerName.endsWith(".gif")
|
||||
|| lowerName.endsWith(".bmp")
|
||||
|| lowerName.endsWith(".webp")
|
||||
|| lowerName.endsWith(".svg");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件名是否为视频类型
|
||||
*/
|
||||
public static boolean isVideoFileName(String fileName) {
|
||||
if (fileName == null || fileName.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String lowerName = fileName.toLowerCase();
|
||||
return lowerName.endsWith(".mp4")
|
||||
|| lowerName.endsWith(".avi")
|
||||
|| lowerName.endsWith(".mov")
|
||||
|| lowerName.endsWith(".wmv")
|
||||
|| lowerName.endsWith(".flv")
|
||||
|| lowerName.endsWith(".mkv");
|
||||
}
|
||||
|
||||
|
||||
public static String getMd5(File file) {
|
||||
return getMd5(getByte(file));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user