判断String类型是否为空
String recommenderName = Optional.ofNullable(backendFlowDetailDTO).map(BackendFlowDetailDTO::getRecommenderName).orElse("");
String recommenderName = Optional.ofNullable(recommenderConditionDTO.getRecommenderName()).filter(n -> !"".equals(n)).orElse(null);
String recommenderAccount = Optional.ofNullable(backendFlowDetailDTO).map(BackendFlowDetailDTO::getRecommenderAccount).orElse("");
String recommenderAccount = Optional.ofNullable(recommenderConditionDTO.getRecommenderAccount()).filter(acc -> !"".equals(acc)).orElse(null);
判断Integer类型是否为空
Integer detailType = Optional.ofNullable(backendFlowDetailDTO).map(BackendFlowDetailDTO::getDetailType).orElse(null);
判断Long类型是否为空
Long recommenderId=Optional.ofNullable(recommenderConditionDTO.getRecommenderId()).filter(id -> id > 0L).orElse(null);
pagehelper分页查询查询出的符合条件的数据为0条的返回(emtpyList())
//如果存在推广员相关查询条件,但未查询到推广员,则一定不会查到流水记录
if (CollectionUtils.isEmpty(recommenders)) {
return new PageModelVO<>(Collections.emptyList(), 0L);
}
limit分页查询的pageNum和pageSize
long rows = pageModelDTO.getPageSize();
long limit = (pageModelDTO.getCurrentPage() - 1) * rows;
使用updateByPrimaryKeySelective动态sql,根据主键id修改数据,修改前要判断数据是否存在,因为updateByPrimarkSelective修改时主键不存在也会显示修改成功
/**
* 修改推广员状态
*
* @param recommenderStatusUpdateDTO
*/
@Override
public void updateRecommenderStatus(Long operaterId, RecommenderStatusUpdateDTO recommenderStatusUpdateDTO) {
LOGGER.info("operaterId = {},recommenderStatusUpdateDTO = {}", operaterId, recommenderStatusUpdateDTO);
if (null == operaterId || operaterId < 1L) {
throw new BusinessException(AuthBusinessError.SYS_REQUEST_PARAMETER_INVALIDATE, "operaterId不能为空或小于1");
}
int tarStatus = recommenderStatusUpdateDTO.getStatus();
if (!STATUS_MAPPING.containsKey(tarStatus)) {
throw new BusinessException(AuthBusinessError.SYS_REQUEST_PARAMETER_INVALIDATE, "不合法的状态类型");
}
RecommenderDO recommender = getRecommenderByPrimaryKey(recommenderStatusUpdateDTO.getId());
int oldStatus = recommender.getStatus();
if (tarStatus == oldStatus) {
throw new BusinessException(AuthBusinessError.SYS_REQUEST_PARAMETER_INVALIDATE, "推广员已经为" +
STATUS_MAPPING.get(tarStatus).getDisc() + "状态");
}
//更新数据
recommender.setStatus(tarStatus);
recommender.setGmtModified(Instant.now().getEpochSecond());
recommender.setUpdater(operaterId);
LOGGER.info("recommender = {}", recommender);
recommenderMapper.updateByPrimaryKeySelective(recommender);
}
/**
* 根据推广员主键集合查询推广员列表
*
* @param ids
* @return
*/
@Override
public List<RecommenderDO> selectRecommenderByIds(List<Long> ids) {
LOGGER.info("ids = {}", ids);
if (CollectionUtils.isEmpty(ids)) {
throw new BusinessException(AuthBusinessError.SYS_REQUEST_PARAMETER_INVALIDATE, "ids不能为空");
}
if (ids.size() < ParticularMark.WRITE_THRESHOLD.getIdentity()) {
return recommenderMapper.selectByIds(ids);
}
return ArrayAlloter.allotByMax(ids, ParticularMark.WRITE_THRESHOLD.getIdentity(), false)
.stream().map(recommenderMapper::selectByIds).flatMap(List::stream).collect(Collectors.toList());
}