add 对多日期、用户、组织机构、文件类型做处理

This commit is contained in:
liao
2023-08-25 16:23:32 +08:00
parent ca4a4225aa
commit dbfa515dba
@@ -1,5 +1,6 @@
package com.jero.modules.laws.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.constant.enums.LanguageEnum;
@@ -11,6 +12,12 @@ import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.common.constant.ResultCommon;
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
import com.jero.modules.laws.common.service.ILawsCommonService;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.tag.entity.LawsArea;
import com.jero.modules.tag.entity.LawsTag;
import com.jero.modules.tag.enums.TableNameEnum;
@@ -39,6 +46,12 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
private LawsCommonMapper lawsCommonMapper;
@Autowired
private ILawsAreaService lawsAreaService;
@Autowired
private ISysUserService sysUserService;
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private IOSSFileService ossFileService;
/**
* @Author: liao
@@ -71,10 +84,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
String selectCondition = getSelectCondition(parameterMap, fieldListCondition);
// 获取分页查询结果
IPage<Map<String, Object>> infoPage = lawsCommonMapper.getCommonPage(page, tableName, selectField, selectCondition);
infoPage.getRecords().forEach(map -> {
// 对返回的数据做处理
processResultMap(map, fieldListSelect);
});
// 对返回的数据做处理
infoPage.getRecords().forEach(map -> processResultMap(map, fieldListSelect));
// 待处理
return infoPage;
}
@@ -94,9 +105,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 如果value不为null和"",对返回结果做处理
if (StringUtils.isNotBlank(value)) {
// 对返回的字段值做处理
processResultFieldValue(key, value, fieldList);
processResultFieldValue(key, value, fieldList, map);
}
}
}
@@ -105,18 +115,33 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
* @Date: 2023/8/25 11:55
* @Description: 对返回的字段值做处理
**/
private String processResultFieldValue(String key, String value, List<LawsTag> fieldList) {
private void processResultFieldValue(String key, String value, List<LawsTag> fieldList, Map<String, Object> map) {
for (LawsTag lawsTag : fieldList) {
if (key.equals(lawsTag.getDbFieldName())) {
List<String> valueList = Arrays.asList(value.split(","));
if (LawsFieldTypeEnum.DATE_MANY.getValue().equals(lawsTag.getFieldShowType())) {
// 如果是多日期格式,做去重处理
List<String> valueList = Arrays.asList(value.split(","))
.stream().distinct().collect(Collectors.toList());
value = StringUtils.join(valueList, ",");
map.put(key, StringUtils.join(valueList.stream()
.distinct().collect(Collectors.toList()), ","));
} else if (LawsFieldTypeEnum.USER_SINGLE.getValue().equals(lawsTag.getFieldShowType())) {
// 如果是用户弹框(列表查询会查询多次,但是业务上应该不会在列表上展示,应该不会影响性能)
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysUserLambdaQueryWrapper.in(SysUser::getId, valueList);
map.put(key, sysUserService.list(sysUserLambdaQueryWrapper));
} else if (LawsFieldTypeEnum.GROUP_SINGLE.getValue().equals(lawsTag.getFieldShowType())
|| LawsFieldTypeEnum.GROUP_MANY.getValue().equals(lawsTag.getFieldShowType())) {
// 如果是组织机构弹框(列表查询会查询多次,但是业务上应该不会在列表上展示,应该不会影响性能)
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDepartLambdaQueryWrapper.in(SysDepart::getId, valueList);
map.put(key, sysDepartService.list(sysDepartLambdaQueryWrapper));
} else if (LawsFieldTypeEnum.FILE_UP.getValue().equals(lawsTag.getFieldShowType())) {
// 如果是文件上传(列表查询会查询多次,但是业务上应该不会在列表上展示,应该不会影响性能)
LambdaQueryWrapper<OSSFile> ossFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
ossFileLambdaQueryWrapper.in(OSSFile::getId, valueList);
map.put(key, ossFileService.list(ossFileLambdaQueryWrapper));
}
}
}
return value;
}
/**