|
@@ -4,15 +4,20 @@ import cn.hutool.core.util.IdUtil;
|
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
import com.example.xiaoshiweixinback.business.utils.FileUtils;
|
|
|
import com.example.xiaoshiweixinback.business.utils.ReadExcelUtils;
|
|
|
+import com.example.xiaoshiweixinback.domain.ImportTask;
|
|
|
import com.example.xiaoshiweixinback.domain.Product;
|
|
|
+import com.example.xiaoshiweixinback.domain.ProductCategory;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.productCategory.EditCategoryDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.product.HotProductAddDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.product.UploadCategoryParamsVO;
|
|
|
import com.example.xiaoshiweixinback.entity.product.UploadProductParamsVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
+import com.example.xiaoshiweixinback.entity.websocket.WebSocketMessageVO;
|
|
|
import com.example.xiaoshiweixinback.service.AssoProductFileService;
|
|
|
import com.example.xiaoshiweixinback.service.ProductCategoryService;
|
|
|
import com.example.xiaoshiweixinback.service.ProductService;
|
|
|
import com.example.xiaoshiweixinback.service.common.FileManagerService;
|
|
|
+import com.example.xiaoshiweixinback.service.common.MessageService;
|
|
|
import org.apache.poi.ss.usermodel.PictureData;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -28,22 +33,20 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class ImportProductCategoryService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ProductService productService;
|
|
|
|
|
|
@Autowired
|
|
|
private FileManagerService fileManagerService;
|
|
|
- @Autowired
|
|
|
- private AssoProductFileService assoProductFileService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExcuteUploadSettingService excuteUploadSettingService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductCategoryService productCategoryService;
|
|
|
-
|
|
|
- public void importProductCategory(File tempFile) {
|
|
|
+ @Autowired
|
|
|
+ private MessageService messageService;
|
|
|
+ public void importProductCategory(File tempFile, ImportTask importTask) {
|
|
|
try {
|
|
|
- PersonnelVO personnelVO =new PersonnelVO();
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
personnelVO.setUuid("123");
|
|
|
Sheet sheet = ReadExcelUtils.readExcel(tempFile);
|
|
|
Integer total = ReadExcelUtils.getExcelTotal(sheet);
|
|
@@ -54,17 +57,29 @@ public class ImportProductCategoryService {
|
|
|
PatentData patentData = ReadExcelUtils.readExcelOneRow2(tempFile, sheet, i);
|
|
|
Map<Object, Object> map = patentData.getMap();
|
|
|
UploadCategoryParamsVO uploadParamsVO = UploadPatentBatchUtil.processCategoryData(map, jsonData);
|
|
|
- if (uploadParamsVO.getCategoryList() == null||uploadParamsVO.getCategoryList().size()==0) {
|
|
|
+ if (uploadParamsVO.getCategoryList() == null || uploadParamsVO.getCategoryList().size() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
List<PictureData> pictureDataList = patentData.getPictureDataList();
|
|
|
+ List<String> names = uploadParamsVO.getCategoryList();
|
|
|
+ if (names == null || names.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- HotProductAddDTO hotProductAddDTO = this.loadCategoryAddVO(uploadParamsVO, pictureDataList);
|
|
|
+
|
|
|
+
|
|
|
+ EditCategoryDTO editCategoryDTO = this.loadCategoryAddVO(uploadParamsVO, pictureDataList);
|
|
|
try {
|
|
|
- productService.addOrUpdateHotProduct(hotProductAddDTO,personnelVO.getUuid());
|
|
|
+ productCategoryService.editCategory(editCategoryDTO);
|
|
|
} catch (Exception e) {
|
|
|
continue;
|
|
|
}
|
|
|
+ WebSocketMessageVO webSocketMessageVO =new WebSocketMessageVO();
|
|
|
+ webSocketMessageVO.setTaskId(importTask.getId());
|
|
|
+ webSocketMessageVO.setAllNum(total);
|
|
|
+ webSocketMessageVO.setState(2);
|
|
|
+ webSocketMessageVO.setCreateId(importTask.getCreateId());
|
|
|
+ messageService.sendImportTaskDone(webSocketMessageVO);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
@@ -72,13 +87,12 @@ public class ImportProductCategoryService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private HotProductAddDTO loadCategoryAddVO(UploadCategoryParamsVO uploadParamsVO, List<PictureData> pictureDataList) throws Exception {
|
|
|
- Integer categoryId = productCategoryService.addCategorysByStr(uploadParamsVO.getCategoryList());
|
|
|
+ private EditCategoryDTO loadCategoryAddVO(UploadCategoryParamsVO uploadParamsVO, List<PictureData> pictureDataList) throws Exception {
|
|
|
+ ProductCategory productCategory = productCategoryService.addCategorysByStr(uploadParamsVO.getCategoryList());
|
|
|
+
|
|
|
+ EditCategoryDTO editCategoryDTO = new EditCategoryDTO();
|
|
|
+ BeanUtils.copyProperties(uploadParamsVO, editCategoryDTO);
|
|
|
|
|
|
- HotProductAddDTO hotProductAddDTO = new HotProductAddDTO();
|
|
|
- BeanUtils.copyProperties(uploadParamsVO, hotProductAddDTO);
|
|
|
- hotProductAddDTO.setIfHot(true);
|
|
|
- hotProductAddDTO.getFileGuids();
|
|
|
List<String> fileIds = new ArrayList<>();
|
|
|
for (PictureData pictureData : pictureDataList) {
|
|
|
String ext = pictureData.suggestFileExtension();
|
|
@@ -93,8 +107,12 @@ public class ImportProductCategoryService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- hotProductAddDTO.setFileGuids(fileIds);
|
|
|
- hotProductAddDTO.setProductCategoryId(categoryId);
|
|
|
- return hotProductAddDTO;
|
|
|
+ editCategoryDTO.setFileGuids(fileIds);
|
|
|
+ editCategoryDTO.setName(productCategory.getName());
|
|
|
+ if(productCategory!=null) {
|
|
|
+ editCategoryDTO.setId(productCategory.getId());
|
|
|
+ editCategoryDTO.setParentId(productCategory.getParentId());
|
|
|
+ }
|
|
|
+ return editCategoryDTO;
|
|
|
}
|
|
|
}
|