mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
[improvement](headless) add batchUpdateStatus and opt deleteCollectionIndicators (#779)
This commit is contained in:
@@ -8,4 +8,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface TagCustomMapper {
|
||||
List<TagDO> query(TagFilter tagFilter);
|
||||
|
||||
Boolean batchUpdateStatus(List<TagDO> tagDOList);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface TagRepository {
|
||||
TagDO getTagById(Long id);
|
||||
|
||||
List<TagDO> query(TagFilter tagFilter);
|
||||
|
||||
Boolean batchUpdateStatus(List<TagDO> tagDOList);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,9 @@ public class TagRepositoryImpl implements TagRepository {
|
||||
public List<TagDO> query(TagFilter tagFilter) {
|
||||
return tagCustomMapper.query(tagFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean batchUpdateStatus(List<TagDO> tagDOList) {
|
||||
return tagCustomMapper.batchUpdateStatus(tagDOList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ public class CollectController {
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return collectService.createCollectionIndicators(user, collectDO.getId());
|
||||
return collectService.createCollectionIndicators(user, collectDO);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeleteMapping("/deleteCollectionIndicators/{id}")
|
||||
public boolean deleteCollectionIndicators(@PathVariable Long id,
|
||||
HttpServletRequest request,
|
||||
@@ -44,4 +45,12 @@ public class CollectController {
|
||||
return collectService.deleteCollectionIndicators(user, id);
|
||||
}
|
||||
|
||||
@PostMapping("/deleteCollectionIndicators")
|
||||
public boolean deleteCollectionIndicators(@RequestBody CollectDO collectDO,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return collectService.deleteCollectionIndicators(user, collectDO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.headless.server.rest;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
|
||||
@@ -42,6 +43,14 @@ public class TagController {
|
||||
return tagService.update(tagReq, user);
|
||||
}
|
||||
|
||||
@PostMapping("/batchUpdateStatus")
|
||||
public Boolean batchUpdateStatus(@RequestBody MetaBatchReq metaBatchReq,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return tagService.batchUpdateStatus(metaBatchReq, user);
|
||||
}
|
||||
|
||||
@DeleteMapping("delete/{id}")
|
||||
public Boolean delete(@PathVariable("id") Long id,
|
||||
HttpServletRequest request,
|
||||
@@ -55,7 +64,8 @@ public class TagController {
|
||||
public TagResp getTag(@PathVariable("id") Long id,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
return tagService.getTag(id);
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return tagService.getTag(id, user);
|
||||
}
|
||||
|
||||
@PostMapping("/queryTag")
|
||||
|
||||
@@ -10,10 +10,12 @@ import java.util.List;
|
||||
|
||||
public interface CollectService {
|
||||
|
||||
Boolean createCollectionIndicators(User user, Long id);
|
||||
Boolean createCollectionIndicators(User user, CollectDO collectDO);
|
||||
|
||||
Boolean deleteCollectionIndicators(User user, Long id);
|
||||
|
||||
Boolean deleteCollectionIndicators(User user, CollectDO collectDO);
|
||||
|
||||
List<CollectDO> getCollectList(String username);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.server.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilter;
|
||||
@@ -16,10 +17,11 @@ public interface TagService {
|
||||
|
||||
void delete(Long id, User user) throws Exception;
|
||||
|
||||
TagResp getTag(Long id);
|
||||
TagResp getTag(Long id, User user);
|
||||
|
||||
List<TagResp> query(TagFilter tagFilter);
|
||||
|
||||
PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user);
|
||||
|
||||
Boolean batchUpdateStatus(MetaBatchReq metaBatchReq, User user);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.tencent.supersonic.headless.server.persistence.mapper.CollectMapper;
|
||||
import com.tencent.supersonic.headless.server.service.CollectService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -22,12 +23,12 @@ public class CollectServiceImpl implements CollectService {
|
||||
private CollectMapper collectMapper;
|
||||
|
||||
@Override
|
||||
public Boolean createCollectionIndicators(User user, Long id) {
|
||||
CollectDO collectDO = new CollectDO();
|
||||
collectDO.setType(type);
|
||||
collectDO.setUsername(user.getName());
|
||||
collectDO.setCollectId(id);
|
||||
collectMapper.insert(collectDO);
|
||||
public Boolean createCollectionIndicators(User user, CollectDO collectReq) {
|
||||
CollectDO collect = new CollectDO();
|
||||
collect.setType(Strings.isEmpty(collectReq.getType()) ? type : collectReq.getType());
|
||||
collect.setUsername(user.getName());
|
||||
collect.setCollectId(collectReq.getId());
|
||||
collectMapper.insert(collect);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,6 +42,16 @@ public class CollectServiceImpl implements CollectService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteCollectionIndicators(User user, CollectDO collectReq) {
|
||||
QueryWrapper<CollectDO> collectDOQueryWrapper = new QueryWrapper<>();
|
||||
collectDOQueryWrapper.lambda().eq(CollectDO::getUsername, user.getName());
|
||||
collectDOQueryWrapper.lambda().eq(CollectDO::getCollectId, collectReq.getCollectId());
|
||||
collectDOQueryWrapper.lambda().eq(CollectDO::getType, collectReq.getType());
|
||||
collectMapper.delete(collectDOQueryWrapper);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CollectDO> getCollectList(String username) {
|
||||
QueryWrapper<CollectDO> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
|
||||
@@ -24,6 +25,7 @@ import com.tencent.supersonic.headless.server.service.CollectService;
|
||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||
import com.tencent.supersonic.headless.server.service.TagService;
|
||||
import com.tencent.supersonic.headless.server.utils.NameCheckUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -32,6 +34,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -102,8 +105,21 @@ public class TagServiceImpl implements TagService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagResp getTag(Long id) {
|
||||
return convert(tagRepository.getTagById(id));
|
||||
public TagResp getTag(Long id, User user) {
|
||||
// return convert(tagRepository.getTagById(id));
|
||||
TagDO tagDO = tagRepository.getTagById(id);
|
||||
TagResp tagResp = fillCollectAndAdminInfo(tagDO, user);
|
||||
return tagResp;
|
||||
}
|
||||
|
||||
private TagResp fillCollectAndAdminInfo(TagDO tagDO, User user) {
|
||||
List<Long> collectIds = collectService.getCollectList(user.getName())
|
||||
.stream().filter(collectDO -> TypeEnums.TAG.name().equalsIgnoreCase(collectDO.getType()))
|
||||
.map(CollectDO::getCollectId).collect(Collectors.toList());
|
||||
|
||||
List<TagResp> tagRespList = convertList(new ArrayList<>(Arrays.asList(tagDO)), collectIds);
|
||||
fillAdminRes(tagRespList, user);
|
||||
return tagRespList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,6 +164,30 @@ public class TagServiceImpl implements TagService {
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean batchUpdateStatus(MetaBatchReq metaBatchReq, User user) {
|
||||
if (Objects.isNull(metaBatchReq) || CollectionUtils.isEmpty(metaBatchReq.getIds())
|
||||
|| Objects.isNull(metaBatchReq.getStatus())) {
|
||||
return false;
|
||||
}
|
||||
TagFilter tagFilter = new TagFilter();
|
||||
tagFilter.setIds(metaBatchReq.getIds());
|
||||
List<TagDO> tagDOList = tagRepository.query(tagFilter);
|
||||
if (CollectionUtils.isEmpty(tagDOList)) {
|
||||
return true;
|
||||
}
|
||||
tagDOList.stream().forEach(tagDO -> {
|
||||
tagDO.setStatus(metaBatchReq.getStatus());
|
||||
tagDO.setUpdatedAt(new Date());
|
||||
tagDO.setUpdatedBy(user.getName());
|
||||
});
|
||||
|
||||
tagRepository.batchUpdateStatus(tagDOList);
|
||||
// todo sendEventBatch
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fillAdminRes(List<TagResp> tagRespList, User user) {
|
||||
List<ModelResp> modelRespList = modelService.getModelListWithAuth(user, null, AuthType.ADMIN);
|
||||
if (CollectionUtils.isEmpty(modelRespList)) {
|
||||
|
||||
@@ -107,4 +107,14 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="batchUpdateStatus" parameterType="java.util.List">
|
||||
<foreach collection="list" item="tag" separator=";">
|
||||
update s2_tag
|
||||
set status = #{tag.status,jdbcType=INTEGER},
|
||||
updated_at = #{tag.updatedAt,jdbcType=TIMESTAMP},
|
||||
updated_by = #{tag.updatedBy,jdbcType=VARCHAR}
|
||||
where id = #{tag.id,jdbcType=BIGINT}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -212,4 +212,33 @@ CREATE TABLE s2_tag(
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--20240301
|
||||
CREATE TABLE IF NOT EXISTS `s2_dictionary_conf` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`description` varchar(255) ,
|
||||
`type` varchar(255) NOT NULL ,
|
||||
`item_id` INT NOT NULL ,
|
||||
`config` text ,
|
||||
`status` varchar(255) NOT NULL ,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_dictionary_conf IS 'dictionary conf information table';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_dictionary_task` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`description` varchar(255) ,
|
||||
`type` varchar(255) NOT NULL ,
|
||||
`item_id` INT NOT NULL ,
|
||||
`config` text ,
|
||||
`status` varchar(255) NOT NULL ,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`elapsed_ms` bigINT DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_dictionary_task IS 'dictionary task information table';
|
||||
|
||||
@@ -205,29 +205,28 @@ CREATE TABLE IF NOT EXISTS `s2_dictionary_conf` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`description` varchar(255) ,
|
||||
`type` varchar(255) NOT NULL ,
|
||||
`item_id` INT NOT NULL , -- task Request Parameters md5
|
||||
`config` mediumtext , -- remark related information
|
||||
`status` varchar(255) NOT NULL , -- the final status of the task
|
||||
`item_id` INT NOT NULL ,
|
||||
`config` mediumtext ,
|
||||
`status` varchar(255) NOT NULL ,
|
||||
`created_at` datetime NOT NULL COMMENT '创建时间' ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_dictionary_conf IS '字典配置信息表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='字典配置信息表';
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_dictionary_task` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL , -- task name
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`description` varchar(255) ,
|
||||
`type` varchar(255) NOT NULL ,
|
||||
`item_id` INT NOT NULL , -- task Request Parameters md5
|
||||
`config` mediumtext , -- remark related information
|
||||
`status` varchar(255) NOT NULL , -- the final status of the task
|
||||
`item_id` INT NOT NULL ,
|
||||
`config` mediumtext ,
|
||||
`status` varchar(255) NOT NULL ,
|
||||
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`elapsed_ms` int(10) DEFAULT NULL , -- the task takes time in milliseconds
|
||||
`elapsed_ms` int(10) DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_dictionary_task IS 'dictionary task information table';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='字典运行任务表';
|
||||
|
||||
|
||||
CREATE TABLE `s2_dimension` (
|
||||
|
||||
Reference in New Issue
Block a user