TASK:模块化;
This commit is contained in:
@@ -4,5 +4,5 @@ import com.ai.da.model.dto.ProgressDTO;
|
||||
|
||||
public interface ProductImageService {
|
||||
void asyncInitialize(Long brandId);
|
||||
double getInitializeProgress(Long brandId);
|
||||
// double getInitializeProgress(Long brandId);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
|
||||
Boolean productImageInitialize(ProductImageInitializeDTO productImageInitializeDTO);
|
||||
|
||||
double getInitializeProgress(ProductImageInitializeDTO productImageInitializeDTO);
|
||||
InitializeProgressVO getInitializeProgress(ProductImageInitializeDTO productImageInitializeDTO);
|
||||
|
||||
IPage<ProjectVO> getPage(ProjectQueryDTO projectQueryDTO);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -45,6 +46,8 @@ public class ProductImageServiceImpl implements ProductImageService {
|
||||
@Async
|
||||
@Override
|
||||
public void asyncInitialize(Long brandId) {
|
||||
System.out.println(">>> [asyncInitialize] 当前线程:" + Thread.currentThread().getName());
|
||||
|
||||
String progressKey = String.valueOf(brandId);
|
||||
ProgressDTO progressDTO = new ProgressDTO(0, 0, false);
|
||||
redisUtil.setTaskProgressDTO(progressKey, progressDTO);
|
||||
@@ -62,15 +65,20 @@ public class ProductImageServiceImpl implements ProductImageService {
|
||||
Library library = libraryMapper.selectById(libraryId);
|
||||
String url = library.getUrl();
|
||||
|
||||
JSONObject result = pythonService.segProduct(url);
|
||||
JSONArray data = result.getJSONArray("data");
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject obj = data.getJSONObject(i);
|
||||
JSONObject attribute = obj.getJSONObject("attribute");
|
||||
AttributeRecognitionJSON attrJSON = attribute.toJavaObject(AttributeRecognitionJSON.class);
|
||||
ProductImageAttribute attr = toAttrDict(attrJSON);
|
||||
attr.setLibraryId(libraryId);
|
||||
productImageAttributeMapper.insert(attr);
|
||||
QueryWrapper<ProductImageAttribute> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(ProductImageAttribute::getLibraryId, libraryId);
|
||||
List<ProductImageAttribute> productImageAttributes = productImageAttributeMapper.selectList(qw);
|
||||
if (!CollectionUtil.isNotEmpty(productImageAttributes)) {
|
||||
JSONObject result = pythonService.segProduct(url);
|
||||
JSONArray data = result.getJSONArray("data");
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject obj = data.getJSONObject(i);
|
||||
JSONObject attribute = obj.getJSONObject("attribute");
|
||||
AttributeRecognitionJSON attrJSON = attribute.toJavaObject(AttributeRecognitionJSON.class);
|
||||
ProductImageAttribute attr = toAttrDict(attrJSON);
|
||||
attr.setLibraryId(libraryId);
|
||||
productImageAttributeMapper.insert(attr);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新当前进度
|
||||
@@ -80,26 +88,26 @@ public class ProductImageServiceImpl implements ProductImageService {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
// log.error("初始化失败", e);
|
||||
redisUtil.setTaskProgressDTO(progressKey, new ProgressDTO(0, 0, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getInitializeProgress(Long brandId) {
|
||||
ProgressDTO dto = redisUtil.getTaskProgressDTO(String.valueOf(brandId));
|
||||
if (dto.getTotal() == 0 || dto.isError()) return 0.0;
|
||||
return (dto.getCurrent() * 1.0 / dto.getTotal());
|
||||
}
|
||||
// public double getInitializeProgress(Long brandId) {
|
||||
// ProgressDTO dto = redisUtil.getTaskProgressDTO(String.valueOf(brandId));
|
||||
// if (dto.getTotal() == 0 || dto.isError()) return 0.0;
|
||||
// return (dto.getCurrent() * 1.0 / dto.getTotal());
|
||||
// }
|
||||
|
||||
private ProductImageAttribute toAttrDict(AttributeRecognitionJSON attrDictJSON) {
|
||||
ProductImageAttribute attributeRetrieval = new ProductImageAttribute();
|
||||
|
||||
// 处理 imgName
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getImgName()) && attrDictJSON.getImgName().get(0) != null) {
|
||||
attributeRetrieval.setImgName(attrDictJSON.getImgName().get(0));
|
||||
}
|
||||
// if (CollectionUtil.isNotEmpty(attrDictJSON.getImgName()) && attrDictJSON.getImgName().get(0) != null) {
|
||||
// attributeRetrieval.setImgName(attrDictJSON.getImgName().get(0));
|
||||
// }
|
||||
// 处理 length
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getLength()) && attrDictJSON.getLength().get(0) != null) {
|
||||
attributeRetrieval.setLength(attrDictJSON.getLength().get(0));
|
||||
|
||||
@@ -1163,18 +1163,33 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInitializeProgress(ProductImageInitializeDTO productImageInitializeDTO) {
|
||||
public InitializeProgressVO getInitializeProgress(ProductImageInitializeDTO productImageInitializeDTO) {
|
||||
InitializeProgressVO vo = new InitializeProgressVO();
|
||||
|
||||
return productImageService.getInitializeProgress(productImageInitializeDTO.getBrandId());
|
||||
// QueryWrapper<>
|
||||
|
||||
ProgressDTO dto = redisUtil.getTaskProgressDTO(String.valueOf(productImageInitializeDTO.getBrandId()));
|
||||
|
||||
if (Objects.isNull(dto)) {
|
||||
vo.setAnalyzed(false);
|
||||
return vo;
|
||||
}
|
||||
vo.setAnalyzed(true);
|
||||
if (dto.getTotal() == 0 || dto.isError()) {
|
||||
vo.setPercent(0.0);
|
||||
return vo;
|
||||
}
|
||||
vo.setPercent(dto.getCurrent() * 1.0 / dto.getTotal());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private ProductImageAttribute toAttrDict(AttributeRecognitionJSON attrDictJSON) {
|
||||
ProductImageAttribute attributeRetrieval = new ProductImageAttribute();
|
||||
|
||||
// 处理 imgName
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getImgName()) && attrDictJSON.getImgName().get(0) != null) {
|
||||
attributeRetrieval.setImgName(attrDictJSON.getImgName().get(0));
|
||||
}
|
||||
// if (CollectionUtil.isNotEmpty(attrDictJSON.getImgName()) && attrDictJSON.getImgName().get(0) != null) {
|
||||
// attributeRetrieval.setImgName(attrDictJSON.getImgName().get(0));
|
||||
// }
|
||||
// 处理 length
|
||||
if (CollectionUtil.isNotEmpty(attrDictJSON.getLength()) && attrDictJSON.getLength().get(0) != null) {
|
||||
attributeRetrieval.setLength(attrDictJSON.getLength().get(0));
|
||||
|
||||
Reference in New Issue
Block a user