dengzedong
2024-11-06 db184afd0c5bf3359b44eb0251fa5b07386eb3ff
提交 | 用户 | 时间
c7f709 1 package com.iailab.module.data.channel.http.service.impl;
L 2
03e8ac 3 import cn.hutool.core.collection.CollUtil;
c7f709 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
L 5 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6 import com.iailab.framework.common.pojo.PageResult;
03e8ac 7 import com.iailab.framework.common.util.object.BeanUtils;
J 8 import com.iailab.framework.common.util.object.ConvertUtils;
c7f709 9 import com.iailab.module.data.channel.http.dao.HttpTagDao;
L 10 import com.iailab.module.data.channel.http.entity.HttpApiEntity;
11 import com.iailab.module.data.channel.http.entity.HttpTagEntity;
12 import com.iailab.module.data.channel.http.service.HttpApiService;
13 import com.iailab.module.data.channel.http.service.HttpTagService;
14 import com.iailab.module.data.channel.http.vo.HttpTagPageReqVO;
03e8ac 15 import com.iailab.module.data.channel.tag.vo.TagImportExcelVO;
J 16 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
17 import com.iailab.module.data.common.enums.CommonConstant;
c7f709 18 import lombok.extern.slf4j.Slf4j;
L 19 import org.springframework.stereotype.Service;
20
21 import javax.annotation.Resource;
03e8ac 22 import java.util.*;
J 23
24 import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
25 import static com.iailab.module.data.enums.ErrorCodeConstants.*;
c7f709 26
L 27 @Slf4j
28 @Service
29 public class HttpTagServiceImpl extends ServiceImpl<HttpTagDao, HttpTagEntity> implements HttpTagService {
30
31     @Resource
32     private HttpApiService httpApiService;
33
34     @Resource
35     private HttpTagDao httpTagDao;
36
37     @Override
38     public PageResult<HttpTagEntity> queryPage(HttpTagPageReqVO reqVO) {
39         return httpTagDao.selectPage(reqVO);
40     }
41
42     @Override
43     public HttpTagEntity info(String id) {
44         return httpTagDao.selectById(id);
45     }
46
47     @Override
48     public void add(HttpTagEntity httpTagEntity) {
49         httpTagDao.insert(httpTagEntity);
50     }
51
52     @Override
53     public void update(HttpTagEntity httpTagEntity) {
54         httpTagDao.updateById(httpTagEntity);
55     }
56
57     @Override
58     public void delete(String id) {
59         httpTagDao.deleteById(id);
60     }
61
62     @Override
63     public List<HttpTagEntity> list() {
64         return httpTagDao.selectList(new QueryWrapper<>());
65     }
66
67
68     @Override
69     public List<HttpTagEntity> selectList(Map<String, Object> params) {
70         String httpId = (String) params.get("httpId");
71         HttpApiEntity httpApiEntity = httpApiService.info(httpId);
72         return httpTagDao.selectList(new QueryWrapper<HttpTagEntity>()
73                         .eq("http_api_code", httpApiEntity.getCode())
74                         .orderByDesc("create_time"));
75     }
76
77     @Override
86145e 78     public List<HttpTagEntity> getApiId(String apiId) {
c7f709 79         return httpTagDao.selectList(new QueryWrapper<HttpTagEntity>()
86145e 80                 .eq("api_id", apiId)
c7f709 81                 .orderByDesc("create_time"));
L 82     }
83
e8ad66 84     @Override
D 85     public List<HttpTagEntity> getInfoByTagNoAndSourceId(String sourceId, String tagName) {
86         return httpTagDao.selectList(new QueryWrapper<HttpTagEntity>()
87         .eq("api_id",sourceId)
88         .eq("tag_name",tagName)
89         );
90     }
91
5b634f 92     @Override
03e8ac 93     public TagImportRespVO importHttpTagList(List<TagImportExcelVO> importTags, boolean isUpdateSupport, String apiId) {
J 94         // 1.1 参数校验
95         if (CollUtil.isEmpty(importTags)) {
96             throw exception(TAG_IMPORT_LIST_IS_EMPTY);
97         }
98         // 2. 遍历,逐个创建 or 更新
99         TagImportRespVO respVO = TagImportRespVO.builder().createTagNames(new ArrayList<>())
100                 .updateTagNames(new ArrayList<>()).failureTagNames(new LinkedHashMap<>()).build();
101         importTags.forEach(importTag -> {
102             // 判断如果不存在,再进行插入
103             HttpTagEntity existTag = httpTagDao.selectOne(new QueryWrapper<HttpTagEntity>()
104                     .eq("api_id", apiId)
105                     .eq("tag_name",importTag.getTagName()));
106             if (existTag == null) {
107                 HttpTagEntity httpTagEntity = ConvertUtils.sourceToTarget(importTag, HttpTagEntity.class);
108                 httpTagEntity.setId(UUID.randomUUID().toString());
109                 httpTagEntity.setEnabled(CommonConstant.IS_ENABLE);
110                 httpTagEntity.setApiId(apiId);
111                 httpTagEntity.setCreateTime(new Date());
112                 httpTagDao.insert(httpTagEntity);
113
114                 respVO.getCreateTagNames().add(httpTagEntity.getTagName());
115                 return;
116             }
117
118             // 如果存在,判断是否允许更新
119             if (!isUpdateSupport) {
120                 respVO.getFailureTagNames().put(importTag.getTagName(), TAG_EXISTS.getMsg());
121                 return;
122             }
123
124             HttpTagEntity updateTag = BeanUtils.toBean(importTag, HttpTagEntity.class);
125             updateTag.setId(existTag.getId());
126             baseMapper.updateById(updateTag);
127             respVO.getUpdateTagNames().add(importTag.getTagName());
128         });
129         return respVO;
130     }
131
c7f709 132 }