package com.qianwen.smartman.modules.notify.service.impl; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.base.BaseServiceImpl; import com.qianwen.core.secure.utils.AuthUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.constant.DictConstant; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.notify.convert.NotifySystemConvert; import com.qianwen.smartman.modules.notify.entity.Notice; import com.qianwen.smartman.modules.notify.entity.NotifySystem; import com.qianwen.smartman.modules.notify.mapper.NotifySystemMapper; import com.qianwen.smartman.modules.notify.service.INoticeService; import com.qianwen.smartman.modules.notify.service.INotifySystemService; import com.qianwen.smartman.modules.notify.vo.NotifySystemSelectVO; import com.qianwen.smartman.modules.notify.vo.NotifySystemUnreadVO; import com.qianwen.smartman.modules.notify.vo.NotifySystemVO; import com.qianwen.smartman.modules.system.entity.Dict; import com.qianwen.smartman.modules.system.service.IDictService; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/service/impl/NotifySystemServiceImpl.class */ public class NotifySystemServiceImpl extends BaseServiceImpl implements INotifySystemService { @Autowired @Lazy private INoticeService noticeService; @Autowired private IDictService dictService; @Override // org.springblade.modules.notify.service.INotifySystemService public NotifySystemUnreadVO getUnreadList() { List dicts = this.dictService.list(Wrappers.lambdaQuery().select(Dict::getDictKey, Dict::getDictValue).eq(Dict::getCode, DictConstant.NOTICE_CODE)); /* List dicts = this.dictService.list((Wrapper) Wrappers.lambdaQuery().select(new SFunction[]{(v0) -> { return v0.getDictKey(); }, (v0) -> { return v0.getDictValue(); }}).eq((v0) -> { return v0.getCode(); }, DictConstant.NOTICE_CODE));*/ Map noticeDict = dicts.stream().collect(Collectors.toMap((v0) -> { return v0.getDictKey(); }, (v0) -> { return v0.getDictValue(); })); List notifySystems = ((NotifySystemMapper) this.baseMapper).getUnreadList(AuthUtil.getUserId()); if (Func.isEmpty(notifySystems)) { return new NotifySystemUnreadVO(); } if (Func.isNotEmpty(noticeDict)) { notifySystems = notifySystems.stream().peek(o -> { o.setCategoryName((String) noticeDict.get(String.valueOf(o.getCategory()))); }).collect(Collectors.toList()); } List internalList = notifySystems.stream().filter(o2 -> { return o2.getNotifyType().equals(1); }).collect(Collectors.toList()); List noticeList = notifySystems.stream().filter(o3 -> { return o3.getNotifyType().equals(2); }).collect(Collectors.toList()); NotifySystemUnreadVO notifySystemUnreadVO = NotifySystemUnreadVO.builder().totalList(notifySystems).internalList(internalList).noticeList(noticeList).build(); return notifySystemUnreadVO; } @Override // org.springblade.modules.notify.service.INotifySystemService public IPage pageNotifySystem(NotifySystemSelectVO selectVO, IPage page) { Long userId = AuthUtil.getUserId(); Integer notifyType = selectVO.getNotifyType(); selectVO.setUserId(Func.toStr(userId)); if (Func.equals(1, notifyType)) { Wrapper wrapper = Wrappers.lambdaQuery() .eq(NotifySystem::getNotifyType, 1).eq(NotifySystem::getNotifyUser, userId).orderByDesc(NotifySystem::getNotifyTime); /* Wrapper wrapper = (Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getNotifyType(); }, 1)).eq((v0) -> { return v0.getNotifyUser(); }, userId)).orderByDesc((v0) -> { return v0.getNotifyTime(); });*/ return NotifySystemConvert.INSTANCE.convert(page(page, wrapper)); } else if (Func.equals(2, notifyType)) { IPage voPage = ((NotifySystemMapper) this.baseMapper).pageNotifySystem(selectVO, page); List records = voPage.getRecords(); List dicts = this.dictService.list(Wrappers.lambdaQuery().select(Dict::getDictKey, Dict::getDictValue).eq(Dict::getCode, DictConstant.NOTICE_CODE)); /* List dicts = this.dictService.list((Wrapper) Wrappers.lambdaQuery().select(new SFunction[]{(v0) -> { return v0.getDictKey(); }, (v0) -> { return v0.getDictValue(); }}).eq((v0) -> { return v0.getCode(); }, DictConstant.NOTICE_CODE));*/ Map noticeDict = dicts.stream().collect(Collectors.toMap((v0) -> { return v0.getDictKey(); }, (v0) -> { return v0.getDictValue(); })); records.forEach(o -> { o.setCategoryName((String) noticeDict.get(String.valueOf(o.getCategory()))); }); return voPage; } else { return new Page<>(); } } @Override // org.springblade.modules.notify.service.INotifySystemService public NotifySystemVO detail(String id) { NotifySystem system = (NotifySystem) getById(id); Integer notifyType = system.getNotifyType(); NotifySystemVO systemVO = NotifySystemConvert.INSTANCE.convert(system); if (Func.equals(1, notifyType)) { return systemVO; } if (Func.equals(2, notifyType)) { String sourceId = system.getSourceId(); Notice notice = (Notice) this.noticeService.getById(Long.valueOf(sourceId)); if (Func.isEmpty(notice)) { throw new ServiceException(MessageUtils.message("notify.notice.already.delete", new Object[0])); } Integer category = notice.getCategory(); String content = notice.getContent(); Dict dict = this.dictService.getOne(Lambda.create() .select(Dict::getDictKey, Dict::getDictValue).eq(Dict::getCode, DictConstant.NOTICE_CODE) .eq(Dict::getDictKey, category.toString()) .limit()); /* Dict dict = (Dict) this.dictService.getOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().select((v0) -> { return v0.getDictKey(); }, (v0) -> { return v0.getDictValue(); }).eq((v0) -> { return v0.getCode(); }, DictConstant.NOTICE_CODE)).eq((v0) -> { return v0.getDictKey(); }, category.toString())).limit());*/ if (Func.isNotEmpty(dict)) { String dictValue = dict.getDictValue(); systemVO.setCategoryName(dictValue); } systemVO.setMessage(content); return systemVO; } return systemVO; } }