package com.klp.service.impl; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.klp.common.core.domain.PageQuery; import com.klp.common.core.page.TableDataInfo; import com.klp.common.utils.StringUtils; import com.klp.domain.WmsProcessAnomaly; import com.klp.domain.bo.WmsProcessAnomalyBo; import com.klp.domain.vo.WmsProcessAnomalyVo; import com.klp.mapper.WmsProcessAnomalyMapper; import com.klp.service.IWmsProcessAnomalyService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 工艺参数异常记录 Service 实现 */ @RequiredArgsConstructor @Service public class WmsProcessAnomalyServiceImpl implements IWmsProcessAnomalyService { private final WmsProcessAnomalyMapper baseMapper; @Override public TableDataInfo queryPageList(WmsProcessAnomalyBo bo, PageQuery pageQuery) { Page result = baseMapper.selectVoPage(pageQuery.build(), buildQueryWrapper(bo)); return TableDataInfo.build(result); } @Override public List queryList(WmsProcessAnomalyBo bo) { return baseMapper.selectVoList(buildQueryWrapper(bo)); } @Override @Transactional(rollbackFor = Exception.class) public void batchInsert(List boList) { if (boList == null || boList.isEmpty()) return; Date now = new Date(); List entities = boList.stream().map(bo -> { WmsProcessAnomaly e = BeanUtil.toBean(bo, WmsProcessAnomaly.class); if (e.getDetectedAt() == null) e.setDetectedAt(now); e.setCreateTime(now); return e; }).collect(Collectors.toList()); entities.forEach(baseMapper::insert); } private LambdaQueryWrapper buildQueryWrapper(WmsProcessAnomalyBo bo) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.eq(bo.getVersionId() != null, WmsProcessAnomaly::getVersionId, bo.getVersionId()); lqw.eq(bo.getPlanId() != null, WmsProcessAnomaly::getPlanId, bo.getPlanId()); lqw.eq(StringUtils.isNotBlank(bo.getCoilId()), WmsProcessAnomaly::getCoilId, bo.getCoilId()); lqw.eq(StringUtils.isNotBlank(bo.getParamCode()), WmsProcessAnomaly::getParamCode, bo.getParamCode()); lqw.eq(StringUtils.isNotBlank(bo.getAnomalyType()), WmsProcessAnomaly::getAnomalyType, bo.getAnomalyType()); lqw.orderByDesc(WmsProcessAnomaly::getDetectedAt); return lqw; } }