| | |
| | | package com.iailab.module.data.channel.kio.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.channel.kio.dao.ChannelKioTagDao; |
| | | import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity; |
| | | import com.iailab.module.data.channel.kio.service.ChannelKioTagService; |
| | | import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO; |
| | | import com.iailab.module.data.channel.tag.vo.TagImportExcelVO; |
| | | import com.iailab.module.data.channel.tag.vo.TagImportRespVO; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static com.iailab.module.data.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * @author lirm |
| | |
| | | public void deleteByDeviceName(String name) { |
| | | channelKioTagDao.delete(new QueryWrapper<ChannelKioTagEntity>().eq("device",name)); |
| | | } |
| | | |
| | | @Override |
| | | public TagImportRespVO importKioTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String device) { |
| | | // 1.1 参数校验 |
| | | if (CollUtil.isEmpty(importTags)) { |
| | | throw exception(TAG_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 遍历,逐个创建 or 更新 |
| | | TagImportRespVO respVO = TagImportRespVO.builder().createTagNames(new ArrayList<>()) |
| | | .updateTagNames(new ArrayList<>()).failureTagNames(new LinkedHashMap<>()).build(); |
| | | importTags.forEach(importTag -> { |
| | | // 判断如果不存在,再进行插入 |
| | | ChannelKioTagEntity existTag = channelKioTagDao.selectOne(new QueryWrapper<ChannelKioTagEntity>() |
| | | .eq("device", device) |
| | | .eq("tag_name",importTag.getTagName())); |
| | | if (existTag == null) { |
| | | ChannelKioTagEntity channelKioTagEntity = ConvertUtils.sourceToTarget(importTag, ChannelKioTagEntity.class); |
| | | channelKioTagEntity.setId(UUID.randomUUID().toString()); |
| | | channelKioTagEntity.setEnabled(CommonConstant.IS_ENABLE); |
| | | channelKioTagEntity.setDevice(device); |
| | | channelKioTagEntity.setCreateTime(new Date()); |
| | | channelKioTagDao.insert(channelKioTagEntity); |
| | | |
| | | respVO.getCreateTagNames().add(channelKioTagEntity.getTagName()); |
| | | return; |
| | | } |
| | | |
| | | // 如果存在,判断是否允许更新 |
| | | if (!isUpdateSupport) { |
| | | respVO.getFailureTagNames().put(importTag.getTagName(), TAG_EXISTS.getMsg()); |
| | | return; |
| | | } |
| | | |
| | | ChannelKioTagEntity updateTag = BeanUtils.toBean(importTag, ChannelKioTagEntity.class); |
| | | updateTag.setId(existTag.getId()); |
| | | baseMapper.updateById(updateTag); |
| | | respVO.getUpdateTagNames().add(importTag.getTagName()); |
| | | }); |
| | | return respVO; |
| | | } |
| | | } |