Skip to content

Commit

Permalink
[improvement](headless) add batchUpdateStatus and opt deleteCollectio…
Browse files Browse the repository at this point in the history
…nIndicators (#779)
  • Loading branch information
daikon12 authored Mar 1, 2024
1 parent 2052352 commit 93534af
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
@Mapper
public interface TagCustomMapper {
List<TagDO> query(TagFilter tagFilter);

Boolean batchUpdateStatus(List<TagDO> tagDOList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface TagRepository {
TagDO getTagById(Long id);

List<TagDO> query(TagFilter tagFilter);

Boolean batchUpdateStatus(List<TagDO> tagDOList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public TagDO getTagById(Long id) {
public List<TagDO> query(TagFilter tagFilter) {
return tagCustomMapper.query(tagFilter);
}

@Override
public Boolean batchUpdateStatus(List<TagDO> tagDOList) {
return tagCustomMapper.batchUpdateStatus(tagDOList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public boolean createCollectionIndicators(@RequestBody CollectDO collectDO,
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,
Expand All @@ -44,4 +45,12 @@ public boolean deleteCollectionIndicators(@PathVariable Long id,
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -42,6 +43,14 @@ public TagResp update(@RequestBody TagReq tagReq,
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,
Expand All @@ -55,7 +64,8 @@ public Boolean delete(@PathVariable("id") Long id,
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -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;
}

Expand All @@ -41,6 +42,16 @@ public Boolean deleteCollectionIndicators(User user, Long id) {
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand All @@ -24,6 +25,7 @@
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;
Expand All @@ -32,6 +34,7 @@
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;
Expand Down Expand Up @@ -102,8 +105,21 @@ public void delete(Long id, User user) throws Exception {
}

@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
Expand Down Expand Up @@ -148,6 +164,30 @@ public PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user) {
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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';
23 changes: 11 additions & 12 deletions launchers/standalone/src/main/resources/db/schema-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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` (
Expand Down

0 comments on commit 93534af

Please sign in to comment.