add 分页查询收藏标识

This commit is contained in:
liao
2023-09-11 15:31:46 +08:00
parent 2934b820a9
commit ba755b56cb
2 changed files with 40 additions and 1 deletions
@@ -39,6 +39,6 @@ public class FieldCommon {
public static final String STR_TO_DATE_PREFIX = "str_to_date('"; // 格式化时间格式的前缀
public static final String STR_TO_DATE_SUFFIX = "','%Y-%m-%d %H:%i:%s')"; // 格式化时间格式的后缀
public static final String COLLECTION_FLAG = "collectionFlag"; // 收藏标识
}
@@ -14,6 +14,8 @@ 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.personal.entity.LawsStandardCollection;
import com.jero.modules.personal.service.ILawsStandardCollectionService;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
@@ -24,6 +26,7 @@ import com.jero.modules.tag.enums.TableNameEnum;
import com.jero.modules.tag.enums.LawsFieldTypeEnum;
import com.jero.modules.tag.service.ILawsAreaService;
import com.spire.ms.System.Collections.ArrayList;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,6 +55,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
private ISysDepartService sysDepartService;
@Autowired
private IOSSFileService ossFileService;
@Autowired
private ILawsStandardCollectionService lawsStandardCollectionService;
/**
* @Author: liao
@@ -86,10 +91,44 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
IPage<Map<String, Object>> infoPage = lawsCommonMapper.getCommonPage(page, tableName, selectField, selectCondition);
// 对返回的数据做处理
infoPage.getRecords().forEach(map -> processResultMap(map, fieldListSelect));
// 是否收藏判断标识
collectionFlag(infoPage.getRecords());
// 待处理
return infoPage;
}
/**
* @Author: liao
* @Date: 2023/9/11 14:49
* @Description: 是否收藏标识判断
**/
private void collectionFlag(List<Map<String, Object>> records) {
// 获取全部id集合
List<String> ids = records.stream().map(kv ->
String.valueOf(kv.get("id"))).collect(Collectors.toList());
if (CollectionUtils.isEmpty(ids)) return;
// 获取登录用户
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// 查询标准收藏表
LambdaQueryWrapper<LawsStandardCollection> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(LawsStandardCollection::getCollectorId, loginUser.getId());
queryWrapper.in(LawsStandardCollection::getStandardId, ids);
List<LawsStandardCollection> standardCollectionList = lawsStandardCollectionService.list(queryWrapper);
if (CollectionUtils.isEmpty(standardCollectionList)) {
records.forEach(map -> map.put(FieldCommon.COLLECTION_FLAG, false));
return;
}
List<String> standardIdList = standardCollectionList.stream()
.map(LawsStandardCollection::getStandardId).collect(Collectors.toList());
records.forEach(map -> {
if (standardIdList.contains(String.valueOf(map.get("id")))) {
map.put(FieldCommon.COLLECTION_FLAG, true);
} else {
map.put(FieldCommon.COLLECTION_FLAG, false);
}
});
}
/**
* @Author: liao
* @Date: 2023/8/25 11:52