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