package jnpf.limsService.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import jnpf.limsEntity.LimsBizLogEntity;
|
import jnpf.limsEntity.bizlog.BizLogAction;
|
import jnpf.limsEntity.bizlog.BizLogType;
|
import jnpf.limsEntity.bizlog.LimsBizLogQueryParam;
|
import jnpf.limsEntity.bizlog.LimsBizLogVo;
|
import jnpf.limsMapper.LimsBizLogMapper;
|
import jnpf.limsService.LimsBizLogService;
|
import jnpf.permission.UserApi;
|
import jnpf.permission.entity.UserEntity;
|
import jnpf.util.DateUtil;
|
import jnpf.util.UploaderUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@Service
|
public class LimsBizLogServiceImpl
|
extends ServiceImpl<LimsBizLogMapper, LimsBizLogEntity>
|
implements LimsBizLogService {
|
|
@Autowired
|
private UserApi userApi;
|
|
@Override
|
public List<LimsBizLogVo> listByBizCode(LimsBizLogQueryParam q) {
|
QueryWrapper<LimsBizLogEntity> wrapper = new QueryWrapper<>();
|
wrapper.lambda()
|
.eq(LimsBizLogEntity::getBizCode, q.getBizCode())
|
.eq(LimsBizLogEntity::getDeleteMark, 0);
|
if (StringUtils.hasText(q.getBizType())) {
|
wrapper.lambda().eq(LimsBizLogEntity::getBizType, q.getBizType());
|
}
|
if (StringUtils.hasText(q.getActionType())) {
|
wrapper.lambda().eq(LimsBizLogEntity::getActionType, q.getActionType());
|
}
|
if (StringUtils.hasText(q.getOperatorUserId())) {
|
wrapper.lambda().eq(LimsBizLogEntity::getOperatorUserId, q.getOperatorUserId());
|
}
|
if (q.getStartTime() != null) {
|
wrapper.lambda().ge(LimsBizLogEntity::getCreatorTime, q.getStartTime());
|
}
|
if (q.getEndTime() != null) {
|
wrapper.lambda().le(LimsBizLogEntity::getCreatorTime, q.getEndTime());
|
}
|
wrapper.lambda().orderByDesc(LimsBizLogEntity::getCreatorTime).orderByDesc(LimsBizLogEntity::getLogSeq);
|
|
Page<LimsBizLogEntity> page = new Page<>(q.getCurrentPage(), q.getPageSize());
|
Page<LimsBizLogEntity> result = this.page(page, wrapper);
|
List<LimsBizLogEntity> rows = result.getRecords();
|
|
// 批量补 user 信息
|
List<String> userIds = rows.stream()
|
.map(LimsBizLogEntity::getOperatorUserId)
|
.filter(StringUtils::hasText)
|
.distinct()
|
.collect(Collectors.toList());
|
Map<String, UserEntity> userMap = new HashMap<>();
|
if (!userIds.isEmpty()) {
|
List<UserEntity> users = userApi.getUserName(userIds);
|
if (users != null) {
|
userMap = users.stream().collect(Collectors.toMap(UserEntity::getId, u -> u, (a, b) -> a));
|
}
|
}
|
|
List<LimsBizLogVo> voList = new ArrayList<>(rows.size());
|
for (LimsBizLogEntity e : rows) {
|
voList.add(toVo(e, userMap));
|
}
|
// 把 total 写回 Pagination 入参,Controller 复制到 PaginationVO 即可
|
q.setData(voList, result.getTotal());
|
return voList;
|
}
|
|
private LimsBizLogVo toVo(LimsBizLogEntity e, Map<String, UserEntity> userMap) {
|
LimsBizLogVo vo = new LimsBizLogVo();
|
vo.setId(e.getId());
|
vo.setLogSeq(e.getLogSeq());
|
vo.setBizCode(e.getBizCode());
|
vo.setBizType(e.getBizType());
|
vo.setActionType(e.getActionType());
|
vo.setActionLabel(e.getActionLabel());
|
vo.setCreatorTime(e.getCreatorTime() == null ? null
|
: DateUtil.dateToString(e.getCreatorTime(), "yyyy-MM-dd HH:mm"));
|
vo.setCreatorUserId(e.getOperatorUserId());
|
|
BizLogAction action = parseAction(e.getActionType());
|
vo.setType(action == null ? null : action.getFrontendType());
|
|
UserEntity user = userMap.get(e.getOperatorUserId());
|
if (user != null) {
|
vo.setCreatorUserName(user.getRealName());
|
vo.setHeadIcon(UploaderUtil.uploaderImg(user.getHeadIcon()));
|
}
|
|
// JSON 字符串直接透传,前端 JSON.parse 解析(与平台原生日志一致)
|
vo.setDataLog(e.getDataLog());
|
vo.setExtraJson(e.getExtraJson());
|
return vo;
|
}
|
|
private BizLogAction parseAction(String code) {
|
if (code == null) return null;
|
for (BizLogAction a : BizLogAction.values()) {
|
if (a.getCode().equals(code)) return a;
|
}
|
return null;
|
}
|
|
/** 仅供切面/调用方查 bizType 文案,目前未直接用,保留扩展 */
|
@SuppressWarnings("unused")
|
private BizLogType parseType(String code) {
|
if (code == null) return null;
|
for (BizLogType t : BizLogType.values()) {
|
if (t.getCode().equals(code)) return t;
|
}
|
return null;
|
}
|
}
|