package org.dromara.eims.service.impl;
|
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.dromara.common.core.service.EquService;
|
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.eims.domain.EimsEqu;
|
import org.dromara.eims.domain.EimsEquType;
|
import org.dromara.eims.domain.bo.EimsEquBo;
|
import org.dromara.eims.domain.vo.EimsEquTypeVo;
|
import org.dromara.eims.domain.vo.EimsEquVo;
|
import org.dromara.eims.mapper.EimsEquMapper;
|
import org.dromara.eims.mapper.EimsEquTypeMapper;
|
import org.dromara.eims.service.IEimsEquService;
|
import lombok.RequiredArgsConstructor;
|
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
/**
|
* 【设备台账】Service业务层处理
|
*
|
* @author zhuguifei
|
* @date 2025-01-04
|
*/
|
@RequiredArgsConstructor
|
@Service
|
public class EimsEquServiceImpl implements IEimsEquService, EquService {
|
|
private final EimsEquMapper baseMapper;
|
private final EimsEquTypeMapper equTypeMapper;
|
|
/**
|
* 查询【设备台账】
|
*
|
* @param equId 主键
|
* @return 【设备台账】
|
*/
|
@Override
|
public EimsEquVo queryById(Long equId) {
|
return baseMapper.selectVoById(equId);
|
}
|
|
@Override
|
public EimsEquVo queryByAssetNo(String assetNo) {
|
LambdaQueryWrapper<EimsEqu> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(EimsEqu::getAssetNo, assetNo);
|
EimsEquVo eimsEquVo = baseMapper.selectVoOne(lqw);
|
return eimsEquVo;
|
}
|
|
/**
|
* 分页查询【设备台账】列表
|
*
|
* @param bo 查询条件
|
* @param pageQuery 分页参数
|
* @return 【设备台账】分页列表
|
*/
|
@Override
|
public TableDataInfo<EimsEquVo> queryPageList(EimsEquBo bo, PageQuery pageQuery) {
|
LambdaQueryWrapper<EimsEqu> lqw = buildQueryWrapper(bo);
|
Page<EimsEquVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
return TableDataInfo.build(result);
|
}
|
|
/**
|
* 查询符合条件的【设备台账】列表
|
*
|
* @param bo 查询条件
|
* @return 【设备台账】列表
|
*/
|
@Override
|
public List<EimsEquVo> queryList(EimsEquBo bo) {
|
LambdaQueryWrapper<EimsEqu> lqw = buildQueryWrapper(bo);
|
return baseMapper.selectVoList(lqw);
|
}
|
|
private LambdaQueryWrapper<EimsEqu> buildQueryWrapper(EimsEquBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<EimsEqu> lqw = Wrappers.lambdaQuery();
|
lqw.like(StringUtils.isNotBlank(bo.getAssetNo()), EimsEqu::getAssetNo, bo.getAssetNo());
|
Long equTypeId = bo.getEquTypeId();
|
/**
|
* equTypeId = 0 时查询所有设备(默认根目录id为0,详见SysEquTypeServiceImpl中selectEquTypeTreeList)
|
* equTypeId 为其他值时只查当前设备类型id和后代设备类型id
|
*/
|
if (equTypeId != null && equTypeId > 0) {
|
List<Long> allDescendantIds = getAllDescendantIds(equTypeId);
|
lqw.in(EimsEqu::getEquTypeId, allDescendantIds);
|
}
|
|
lqw.like(StringUtils.isNotBlank(bo.getEquName()), EimsEqu::getEquName, bo.getEquName());
|
lqw.eq(StringUtils.isNotBlank(bo.getModelNo()), EimsEqu::getModelNo, bo.getModelNo());
|
lqw.eq(StringUtils.isNotBlank(bo.getMadeIn()), EimsEqu::getMadeIn, bo.getMadeIn());
|
lqw.eq(bo.getRatedPower() != null, EimsEqu::getRatedPower, bo.getRatedPower());
|
lqw.eq(StringUtils.isNotBlank(bo.getPlateInfo()), EimsEqu::getPlateInfo, bo.getPlateInfo());
|
lqw.eq(bo.getPurchaseDate() != null, EimsEqu::getPurchaseDate, bo.getPurchaseDate());
|
lqw.eq(bo.getStatus() != null, EimsEqu::getStatus, bo.getStatus());
|
lqw.eq(StringUtils.isNotBlank(bo.getLocation()), EimsEqu::getLocation, bo.getLocation());
|
lqw.eq(bo.getDeptUsed() != null, EimsEqu::getDeptUsed, bo.getDeptUsed());
|
lqw.eq(bo.getRespPerson() != null, EimsEqu::getRespPerson, bo.getRespPerson());
|
lqw.eq(StringUtils.isNotBlank(bo.getContactPhone()), EimsEqu::getContactPhone, bo.getContactPhone());
|
lqw.eq(bo.getDeployDate() != null, EimsEqu::getDeployDate, bo.getDeployDate());
|
lqw.eq(bo.getTrialDate() != null, EimsEqu::getTrialDate, bo.getTrialDate());
|
lqw.eq(bo.getPlanAcceptDate() != null, EimsEqu::getPlanAcceptDate, bo.getPlanAcceptDate());
|
lqw.eq(bo.getActualAcceptDate() != null, EimsEqu::getActualAcceptDate, bo.getActualAcceptDate());
|
lqw.eq(bo.getImportStatus() != null, EimsEqu::getImportStatus, bo.getImportStatus());
|
lqw.eq(StringUtils.isNotBlank(bo.getEquCode()), EimsEqu::getEquCode, bo.getEquCode());
|
lqw.eq(bo.getInventoryFlag() != null, EimsEqu::getInventoryFlag, bo.getInventoryFlag());
|
lqw.eq(bo.getInventoryDate() != null, EimsEqu::getInventoryDate, bo.getInventoryDate());
|
lqw.eq(bo.getServiceLife() != null, EimsEqu::getServiceLife, bo.getServiceLife());
|
lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
|
EimsEqu::getDeployDate, params.get("beginTime"), params.get("endTime"));
|
// 按创建日期倒序
|
lqw.orderByDesc(EimsEqu::getCreateTime);
|
return lqw;
|
}
|
|
/**
|
* 根据id,获取所有后代id
|
*
|
* @param rootId
|
* @return
|
*/
|
public List<Long> getAllDescendantIds(Long rootId) {
|
List<Long> result = new ArrayList<>();
|
result.add(rootId);
|
collectDescendants(rootId, result);
|
return result;
|
}
|
|
private void collectDescendants(Long currentId, List<Long> collector) {
|
QueryWrapper<EimsEquType> equTypeWrapper = new QueryWrapper<>();
|
equTypeWrapper.lambda().eq(EimsEquType::getParentId, currentId);
|
|
List<EimsEquTypeVo> children = equTypeMapper.selectVoList(equTypeWrapper);
|
if (children != null && !children.isEmpty()) {
|
for (EimsEquTypeVo child : children) {
|
Long childId = child.getEquTypeId();
|
collector.add(childId);
|
collectDescendants(childId, collector);
|
}
|
}
|
}
|
|
/**
|
* 新增【设备台账】
|
*
|
* @param bo 【设备台账】
|
* @return 是否新增成功
|
*/
|
@Override
|
public Boolean insertByBo(EimsEquBo bo) {
|
EimsEqu add = MapstructUtils.convert(bo, EimsEqu.class);
|
validEntityBeforeSave(add);
|
boolean flag = baseMapper.insert(add) > 0;
|
if (flag) {
|
bo.setEquId(add.getEquId());
|
}
|
return flag;
|
}
|
|
/**
|
* 修改【设备台账】
|
*
|
* @param bo 【设备台账】
|
* @return 是否修改成功
|
*/
|
@Override
|
public Boolean updateByBo(EimsEquBo bo) {
|
EimsEqu update = MapstructUtils.convert(bo, EimsEqu.class);
|
validEntityBeforeSave(update);
|
return baseMapper.updateById(update) > 0;
|
}
|
|
/**
|
* 保存前的数据校验
|
*/
|
private void validEntityBeforeSave(EimsEqu entity) {
|
//TODO 做一些数据校验,如唯一约束
|
}
|
|
/**
|
* 校验并批量删除【设备台账】信息
|
*
|
* @param ids 待删除的主键集合
|
* @param isValid 是否进行有效性校验
|
* @return 是否删除成功
|
*/
|
@Override
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
if (isValid) {
|
//TODO 做一些业务上的校验,判断是否需要校验
|
}
|
return baseMapper.deleteByIds(ids) > 0;
|
}
|
|
@Override
|
public String selectEquNameByIds(String equIds) {
|
List<String> list = new ArrayList<>();
|
for (Long id : StringUtils.splitTo(equIds, Convert::toLong)) {
|
EimsEquVo vo = SpringUtils.getAopProxy(this).queryById(id);
|
if (ObjectUtil.isNotNull(vo)) {
|
list.add(vo.getEquName());
|
}
|
}
|
return String.join(StringUtils.SEPARATOR, list);
|
}
|
}
|