package com.iailab.module.data.channel.kio.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
|
import com.iailab.module.data.channel.kio.dao.ChannelKioDeviceDao;
|
import com.iailab.module.data.channel.kio.dto.ChannelKioDeviceDTO;
|
import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity;
|
import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService;
|
import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
|
import org.apache.commons.lang3.StringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年06月04日
|
*/
|
@Service
|
public class ChannelKioDeviceServiceImpl extends BaseServiceImpl<ChannelKioDeviceDao, ChannelKioDeviceEntity> implements ChannelKioDeviceService {
|
|
@Resource
|
ChannelKioTagService channelKioTagService;
|
|
@Override
|
public PageData<ChannelKioDeviceDTO> page(Map<String, Object> params) {
|
IPage<ChannelKioDeviceEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_TIME, false),
|
getWrapper(params)
|
);
|
return getPageData(page, ChannelKioDeviceDTO.class);
|
}
|
|
@Override
|
public List<ChannelKioDeviceDTO> list(Map<String, Object> params) {
|
List<ChannelKioDeviceEntity> list = baseDao.selectList(getWrapper(params));
|
return ConvertUtils.sourceToTarget(list, ChannelKioDeviceDTO.class);
|
}
|
|
private QueryWrapper<ChannelKioDeviceEntity> getWrapper(Map<String, Object> params){
|
String instanceName = (String)params.get("instanceName");
|
QueryWrapper<ChannelKioDeviceEntity> wrapper = new QueryWrapper<>();
|
wrapper.like(StringUtils.isNotBlank(instanceName), "instance_name", instanceName);
|
return wrapper;
|
}
|
|
@Override
|
public ChannelKioDeviceDTO get(String id) {
|
ChannelKioDeviceEntity entity = baseDao.selectById(id);
|
return ConvertUtils.sourceToTarget(entity, ChannelKioDeviceDTO.class);
|
}
|
|
@Override
|
public void save(ChannelKioDeviceDTO dto) {
|
ChannelKioDeviceEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioDeviceEntity.class);
|
insert(entity);
|
}
|
|
@Override
|
public void update(ChannelKioDeviceDTO dto) {
|
ChannelKioDeviceEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioDeviceEntity.class);
|
updateById(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
Arrays.asList(ids).forEach(id -> {
|
channelKioTagService.deleteByDeviceName(get(id).getInstanceName());
|
});
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
}
|