TASK:搭配
This commit is contained in:
@@ -21,7 +21,7 @@ public class ReCollocationSchedule {
|
||||
* @author yl
|
||||
* @since 2023-04-13
|
||||
*/
|
||||
// @Scheduled(cron = "0 0 1 * * ?")
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
// @Scheduled(cron = "0 0/2 * * * ?")
|
||||
public void websocketHeartBeatTask() {
|
||||
log.info("定时任务-商品重新搭配开始---------");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PythonService {
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public JSONObject attributeRecognition(List<String> pictureUrls,List<String> ids) {
|
||||
public JSONObject attributeRecognition(List<String> pictureUrls,List<String> ids, List<String> category) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("attributeRecognition", 20);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
@@ -58,6 +58,7 @@ public class PythonService {
|
||||
content.put("upload_img_path", pictureUrls);
|
||||
//识别图片id数组
|
||||
content.put("upload_img_id", ids);
|
||||
content.put("upload_img_category", category);
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":9993/api/attribute")
|
||||
|
||||
@@ -1071,7 +1071,8 @@ public class TProductService extends ServiceImpl<TProductMapper, TProduct> {
|
||||
//计算python商品属性,性能慢 一次一件
|
||||
JSONObject productIdInnerToMap = pythonService.attributeRecognition(
|
||||
Collections.singletonList(tProduct.getPictureUrl()),
|
||||
Collections.singletonList(tProduct.getId().toString()));
|
||||
Collections.singletonList(tProduct.getId().toString()),
|
||||
Collections.singletonList(tProduct.getPictureUrl().split("/")[2] + "/" + tProduct.getPictureUrl().split("/")[3]));
|
||||
//保存商品属性
|
||||
tProductAttributeService.saveBatch(resolveProductAttributeNew(productIdInnerToMap, product.getTimeZone()));
|
||||
// resolveProductIdToMap(productIdToMap, productIdInnerToMap);
|
||||
@@ -1860,29 +1861,44 @@ public class TProductService extends ServiceImpl<TProductMapper, TProduct> {
|
||||
List<List<TProduct>> questList = Lists.partition(page.getRecords(), 10);
|
||||
questList.forEach(list -> {
|
||||
//校验规则
|
||||
List<TProduct> validateList = validateGenerateProductAssortment(list, null, dataBase, tProductIdToAttributeItemNewMap);
|
||||
if (CollectionUtils.isEmpty(validateList)) {
|
||||
return;
|
||||
}
|
||||
// List<TProduct> validateList = validateGenerateProductAssortment(list, null, dataBase, tProductIdToAttributeItemNewMap);
|
||||
// if (CollectionUtils.isEmpty(validateList)) {
|
||||
// return;
|
||||
// }
|
||||
List<TProduct> validateList = list;
|
||||
try {
|
||||
Map<String, GenerateCollocationDataBaseDTO> dataBaseMap = dataBase.stream().collect(Collectors.toMap(p -> p.getId().toString(),
|
||||
p2 -> GenerateCollocationDataBaseDTO.builder()
|
||||
.category(tProductIdToAttributeItemNewMap.get(p2.getId()))
|
||||
.path(p2.getPictureUrl()).build(), (v1, v2) -> v2));
|
||||
//推荐搭配
|
||||
List<GenerateCollocationOutVO> collocationOutResult = pythonService.generateCollocation(
|
||||
validateList.stream()
|
||||
.map(product1 ->
|
||||
GenerateCollocationQueryDTO.builder()
|
||||
.item_category(tProductIdToAttributeItemNewMap.get(product1.getId()))
|
||||
.path(product1.getPictureUrl())
|
||||
.item_id(product1.getId().toString()).build())
|
||||
.collect(Collectors.toList()), dataBaseMap
|
||||
);
|
||||
QueryWrapper<TProduct> qw = new QueryWrapper<>();
|
||||
List<TProduct> db = tProductMapper.selectList(qw);
|
||||
List<GenerateCollocationQueryNewDTO> query = new ArrayList<>();
|
||||
List<GenerateCollocationQueryNewDTO> database = new ArrayList<>();
|
||||
for (TProduct tProduct : validateList) {
|
||||
GenerateCollocationQueryNewDTO vo = new GenerateCollocationQueryNewDTO();
|
||||
// vo.setItem_name(tProduct.getPictureName().split("_")[0]);
|
||||
vo.setItem_name(tProduct.getPictureName());
|
||||
vo.setImage_path(tProduct.getPictureUrl());
|
||||
String[] split = tProduct.getPictureUrl().split("/");
|
||||
vo.setSemantic_category(split[2] + "/" + split[3]);
|
||||
query.add(vo);
|
||||
}
|
||||
for (TProduct tProduct : db) {
|
||||
GenerateCollocationQueryNewDTO vo = new GenerateCollocationQueryNewDTO();
|
||||
// vo.setItem_name(tProduct.getPictureName().split("_")[0]);
|
||||
vo.setItem_name(tProduct.getPictureName());
|
||||
vo.setImage_path(tProduct.getPictureUrl());
|
||||
String[] split = tProduct.getPictureUrl().split("/");
|
||||
vo.setSemantic_category(split[2] + "/" + split[3]);
|
||||
database.add(vo);
|
||||
}
|
||||
List<GenerateCollocationOutVO> collocationOutResult = pythonService.generateCollocationNew(query, database);
|
||||
//保存搭配数据
|
||||
List<Long> collect = validateList.stream().map(TProduct::getId).collect(Collectors.toList());
|
||||
for (Long l : collect) {
|
||||
tProductAssortmentService.deleteByProductId(String.valueOf(l));
|
||||
}
|
||||
tProductAssortmentService.saveBatch(
|
||||
resolveProductAssortment(collocationOutResult, dataBaseMap, "Asia/Shanghai"));
|
||||
resolveProductAssortmentNew(collocationOutResult, "Asia/Shanghai"));
|
||||
//更新商品的搭配状态为已搭配
|
||||
System.out.println(collocationOutResult);
|
||||
validateList.stream().forEach(pro -> pro.setCollocationState(1));
|
||||
this.updateBatchById(validateList);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user