fix: 优化逻辑
This commit is contained in:
parent
76821ca786
commit
8c20e76cd0
@ -65,11 +65,23 @@ public class FishDraftData implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Date strdt;
|
private Date strdt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始日期
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String strdtStr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束日期
|
* 结束日期
|
||||||
*/
|
*/
|
||||||
private Date enddt;
|
private Date enddt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束日期
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String enddtStr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 游向(上行/下行/上行折返/下行折返)
|
* 游向(上行/下行/上行折返/下行折返)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -413,12 +413,19 @@ public class FishImportServiceImpl implements IFishImportService {
|
|||||||
case "strdt":
|
case "strdt":
|
||||||
if (!StringUtils.hasText(cellValue)) {
|
if (!StringUtils.hasText(cellValue)) {
|
||||||
importRow.getWarnings().add(fieldName);
|
importRow.getWarnings().add(fieldName);
|
||||||
|
data.setStrdtStr(cellValue);
|
||||||
} else {
|
} else {
|
||||||
Date strdt = parseDate(cellValue);
|
Date strdt = parseDate(cellValue);
|
||||||
if (strdt == null) {
|
if (strdt == null) {
|
||||||
importRow.getWarnings().add(fieldName);
|
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;
|
break;
|
||||||
case "enddt":
|
case "enddt":
|
||||||
@ -452,6 +459,13 @@ public class FishImportServiceImpl implements IFishImportService {
|
|||||||
objectObjectHashMap.put("value", fileName);
|
objectObjectHashMap.put("value", fileName);
|
||||||
importRow.getVdpthList().add(objectObjectHashMap);
|
importRow.getVdpthList().add(objectObjectHashMap);
|
||||||
vdpthList.add(fileName);
|
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);
|
objectObjectHashMap.put("value", fileName);
|
||||||
importRow.getPicpthList().add(objectObjectHashMap);
|
importRow.getPicpthList().add(objectObjectHashMap);
|
||||||
picpthList.add(fileName);
|
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;
|
return importRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void validateStationFpssRelation(FishDraftData data, FishImportResult.FishImportRow importRow) {
|
private void validateStationFpssRelation(FishDraftData data, FishImportResult.FishImportRow importRow) {
|
||||||
loadStationAndBaseCache();
|
loadStationAndBaseCache();
|
||||||
if (StringUtils.hasText(data.getHbrvcd()) && StringUtils.hasText(data.getRstcd())) {
|
if (StringUtils.hasText(data.getHbrvcd()) && StringUtils.hasText(data.getRstcd())) {
|
||||||
@ -1119,28 +1142,54 @@ public class FishImportServiceImpl implements IFishImportService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析日期字符串,支持多种格式
|
||||||
|
* @param dateStr 日期字符串
|
||||||
|
* @return 解析后的 Date 对象,如果解析失败返回 null
|
||||||
|
*/
|
||||||
private Date parseDate(String dateStr) {
|
private Date parseDate(String dateStr) {
|
||||||
if (!StringUtils.hasText(dateStr)) {
|
if (!StringUtils.hasText(dateStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 去除首尾空格
|
||||||
|
dateStr = dateStr.trim();
|
||||||
|
|
||||||
|
// 支持的日期格式列表(按常用程度排序)
|
||||||
String[] patterns = {
|
String[] patterns = {
|
||||||
"yyyy-MM-dd HH:mm:ss",
|
"yyyy-MM-dd HH:mm:ss", // 2024-01-15 14:30:00
|
||||||
"yyyy-MM-dd",
|
"yyyy-MM-dd", // 2024-01-15
|
||||||
"yyyy/MM/dd",
|
"yyyy/MM/dd HH:mm:ss", // 2024/01/15 14:30:00
|
||||||
"yyyy.MM.dd",
|
"yyyy/MM/dd", // 2024/01/15
|
||||||
"yyyyMMdd"
|
"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) {
|
for (String pattern : patterns) {
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||||
sdf.setLenient(false);
|
sdf.setLenient(false); // 严格模式,不允许非法日期
|
||||||
return sdf.parse(dateStr);
|
Date parsedDate = sdf.parse(dateStr);
|
||||||
} catch (ParseException ignored) {
|
|
||||||
|
// 验证解析后的日期是否合理(例如年份不能是 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer parseInteger(String value) {
|
private Integer parseInteger(String value) {
|
||||||
if (!StringUtils.hasText(value)) {
|
if (!StringUtils.hasText(value)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -69,11 +69,110 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SdEngInfoBH> selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) {
|
public List<SdEngInfoBH> selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) {
|
||||||
String baseId = sdEngInfoBHRequest.getBaseId();
|
String userId = SecurityUtils.getUserId();
|
||||||
String hbrvcd = sdEngInfoBHRequest.getHbrvcd();
|
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||||
String ennm = sdEngInfoBHRequest.getEnnm();
|
|
||||||
List<String> rvcds = sdEngInfoBHRequest.getRvcds();
|
// 管理员直接查询
|
||||||
List<String> hbrvcds = sdEngInfoBHRequest.getHbrvcds();
|
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<>();
|
LambdaQueryWrapper<SdEngInfoBH> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(StringUtils.hasText(baseId), SdEngInfoBH::getBaseId, baseId)
|
wrapper.eq(StringUtils.hasText(baseId), SdEngInfoBH::getBaseId, baseId)
|
||||||
.eq(StringUtils.hasText(hbrvcd), SdEngInfoBH::getHbrvcd, hbrvcd)
|
.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)
|
.select(SdEngInfoBH::getStcd, SdEngInfoBH::getEnnm, SdEngInfoBH::getBaseId)
|
||||||
.orderByAsc(SdEngInfoBH::getOrderIndex);
|
.orderByAsc(SdEngInfoBH::getOrderIndex);
|
||||||
|
|
||||||
Set<String> authorizedStations = getUserAuthorizedStationCodes();
|
return wrapper;
|
||||||
if (authorizedStations != null && !authorizedStations.isEmpty()) {
|
|
||||||
wrapper.in(SdEngInfoBH::getStcd, authorizedStations);
|
|
||||||
} else if (!"admin".equals(SecurityUtils.getCurrentUsername())){
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.list(wrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.ISysOrganizationService;
|
||||||
import com.yfd.platform.system.service.IUserService;
|
import com.yfd.platform.system.service.IUserService;
|
||||||
import com.yfd.platform.utils.ObjectConverterUtil;
|
import com.yfd.platform.utils.ObjectConverterUtil;
|
||||||
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@ -79,7 +80,7 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
String[] split = orgscope.split(",");
|
String[] split = orgscope.split(",");
|
||||||
List<String> stringList = Arrays.asList(split);
|
List<String> stringList = Arrays.asList(split);
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new HashSet<>();
|
||||||
if (stringList.size() > 0) {
|
if (!stringList.isEmpty()) {
|
||||||
List<SysOrganization> list =
|
List<SysOrganization> list =
|
||||||
sysOrganizationMapper.selectList(new LambdaQueryWrapper<SysOrganization>().in(SysOrganization::getId, stringList));
|
sysOrganizationMapper.selectList(new LambdaQueryWrapper<SysOrganization>().in(SysOrganization::getId, stringList));
|
||||||
list.forEach(l -> set.add(l.getParentid()));
|
list.forEach(l -> set.add(l.getParentid()));
|
||||||
@ -243,20 +244,34 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
***********************************/
|
***********************************/
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> getOrgScopeTree(String roleId) {
|
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.eq(SysOrganization::getIsvaild, '1');
|
||||||
queryWrapper.orderByAsc(SysOrganization::getOrgcode);
|
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);
|
SysRole sysRole = sysRoleMapper.selectById(roleId);
|
||||||
String orgscope = sysRole.getOrgscope();
|
String orgscope = sysRole.getOrgscope();
|
||||||
List<String> ids = new ArrayList<>();
|
List<String> ids = new ArrayList<>();
|
||||||
if (StrUtil.isNotBlank(orgscope)) {
|
if (StrUtil.isNotBlank(orgscope)) {
|
||||||
String[] split = orgscope.split(",");
|
ids.addAll(Arrays.asList(orgscope.split(",")));
|
||||||
ids = Arrays.asList(split);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map<String, Object> map : listMaps) {
|
for (Map<String, Object> map : listMaps) {
|
||||||
String id = (String) map.get("id");
|
String id = (String) map.get("id");
|
||||||
if (ids.contains(id)) {
|
if (ids.contains(id)) {
|
||||||
|
|||||||
@ -391,6 +391,42 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
fis.close();
|
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) {
|
public static String getMd5(File file) {
|
||||||
return getMd5(getByte(file));
|
return getMd5(getByte(file));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user