mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
add TagTest and correctDateConf logic (#797)
This commit is contained in:
@@ -35,6 +35,14 @@ public class TagController {
|
||||
this.tagQueryService = tagQueryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建标签
|
||||
* @param tagReq
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public TagResp create(@RequestBody TagReq tagReq,
|
||||
HttpServletRequest request,
|
||||
@@ -43,6 +51,14 @@ public class TagController {
|
||||
return tagMetaService.create(tagReq, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑标签信息
|
||||
* @param tagReq
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
public TagResp update(@RequestBody TagReq tagReq,
|
||||
HttpServletRequest request,
|
||||
@@ -51,6 +67,13 @@ public class TagController {
|
||||
return tagMetaService.update(tagReq, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新标签状态
|
||||
* @param metaBatchReq
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/batchUpdateStatus")
|
||||
public Boolean batchUpdateStatus(@RequestBody MetaBatchReq metaBatchReq,
|
||||
HttpServletRequest request,
|
||||
@@ -59,6 +82,14 @@ public class TagController {
|
||||
return tagMetaService.batchUpdateStatus(metaBatchReq, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签删除
|
||||
* @param id
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@DeleteMapping("delete/{id}")
|
||||
public Boolean delete(@PathVariable("id") Long id,
|
||||
HttpServletRequest request,
|
||||
@@ -68,6 +99,13 @@ public class TagController {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签详情获取
|
||||
* @param id
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getTag/{id}")
|
||||
public TagResp getTag(@PathVariable("id") Long id,
|
||||
HttpServletRequest request,
|
||||
@@ -76,6 +114,14 @@ public class TagController {
|
||||
return tagMetaService.getTag(id, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签市场-分页查询
|
||||
* @param tagFilterPage
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/queryTag")
|
||||
public PageInfo<TagResp> queryPage(@RequestBody TagFilterPage tagFilterPage,
|
||||
HttpServletRequest request,
|
||||
|
||||
@@ -6,19 +6,25 @@ import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
import com.tencent.supersonic.common.pojo.Order;
|
||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||
import com.tencent.supersonic.headless.api.pojo.Dim;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||
import com.tencent.supersonic.headless.api.pojo.ValueDistribution;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ItemValueReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryTagReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ItemValueResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||
import com.tencent.supersonic.headless.server.service.QueryService;
|
||||
import com.tencent.supersonic.headless.server.service.TagMetaService;
|
||||
import com.tencent.supersonic.headless.server.service.TagQueryService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -30,13 +36,19 @@ import static com.tencent.supersonic.common.pojo.Constants.DESC_UPPER;
|
||||
@Service
|
||||
public class TagQueryServiceImpl implements TagQueryService {
|
||||
|
||||
@Value("${item.value.date.before:1}")
|
||||
private Integer dayBefore;
|
||||
|
||||
private final String tagValueAlias = "internalTagCount";
|
||||
private final TagMetaService tagMetaService;
|
||||
private final QueryService queryService;
|
||||
private final ModelService modelService;
|
||||
|
||||
public TagQueryServiceImpl(TagMetaService tagMetaService, QueryService queryService) {
|
||||
public TagQueryServiceImpl(TagMetaService tagMetaService, QueryService queryService,
|
||||
ModelService modelService) {
|
||||
this.tagMetaService = tagMetaService;
|
||||
this.queryService = queryService;
|
||||
this.modelService = modelService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +59,7 @@ public class TagQueryServiceImpl implements TagQueryService {
|
||||
TagResp tag = tagMetaService.getTag(itemValueReq.getItemId(), user);
|
||||
itemValueResp.setName(tag.getName());
|
||||
itemValueResp.setBizName(tag.getBizName());
|
||||
correctDateConf(itemValueReq, tag);
|
||||
// tag total count
|
||||
Long totalCount = queryTagTotalCount(tag, itemValueReq, user);
|
||||
// tag value
|
||||
@@ -56,6 +69,26 @@ public class TagQueryServiceImpl implements TagQueryService {
|
||||
return itemValueResp;
|
||||
}
|
||||
|
||||
private void correctDateConf(ItemValueReq itemValueReq, TagResp tag) {
|
||||
if (Objects.nonNull(itemValueReq.getDateConf())) {
|
||||
return;
|
||||
}
|
||||
ModelResp model = modelService.getModel(tag.getModelId());
|
||||
List<Dim> timeDimension = model.getTimeDimension();
|
||||
if (CollectionUtils.isEmpty(timeDimension)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Dim dim = timeDimension.get(0);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dim.getDateFormat());
|
||||
String endDate = LocalDate.now().plusDays(-dayBefore).format(formatter);
|
||||
DateConf dateConf = new DateConf();
|
||||
dateConf.setDateMode(DateConf.DateMode.BETWEEN);
|
||||
dateConf.setStartDate(endDate);
|
||||
dateConf.setEndDate(endDate);
|
||||
itemValueReq.setDateConf(dateConf);
|
||||
}
|
||||
|
||||
private Long queryTagTotalCount(TagResp tag, ItemValueReq itemValueReq, User user) throws Exception {
|
||||
|
||||
QueryTagReq queryTagReq = new QueryTagReq();
|
||||
@@ -74,8 +107,7 @@ public class TagQueryServiceImpl implements TagQueryService {
|
||||
return Long.parseLong(total.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return Long.MAX_VALUE;
|
||||
throw new RuntimeException("queryTagTotalCount error");
|
||||
}
|
||||
|
||||
private void fillTagValueInfo(ItemValueResp itemValueResp, SemanticQueryResp semanticQueryResp, Long totalCount) {
|
||||
|
||||
Reference in New Issue
Block a user