|
|
@@ -102,7 +102,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void importCategory(MultipartFile file, Long userId, String username) {
|
|
|
+ public void importCategory(MultipartFile file, Long userId) {
|
|
|
try {
|
|
|
// 检查文件是否为空
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
@@ -118,6 +118,8 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
|
|
|
// 批量保存数据
|
|
|
if (!shopCategories.isEmpty()) {
|
|
|
+ Date date = new Date();
|
|
|
+ String code = generateUniqueCode();
|
|
|
for (int i = 0; i < shopCategories.size(); i++) {
|
|
|
ShopCategoryExcelDTO category = shopCategories.get(i);
|
|
|
|
|
|
@@ -127,15 +129,16 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
shopCategoryLog.setSubSubName(category.getSubSubName());
|
|
|
shopCategoryLog.setHbShopId(category.getHbShopId());
|
|
|
shopCategoryLog.setIsFail(true);
|
|
|
+ shopCategoryLog.setTaskCode(code);
|
|
|
+ shopCategoryLog.setTaskName("导入前台类目");
|
|
|
// 设置操作人 获取当前操作人信息
|
|
|
- shopCategoryLog.setSysUserId(userId);
|
|
|
- shopCategoryLog.setSysUserName(username);
|
|
|
- shopCategoryLog.setCreateTime(new Date());
|
|
|
- shopCategoryLog.setUpdateTime(new Date());
|
|
|
+ shopCategoryLog.setCreateBy(userId);
|
|
|
+ shopCategoryLog.setCreateTime(date);
|
|
|
+ shopCategoryLog.setUpdateTime(date);
|
|
|
|
|
|
try {
|
|
|
// 检查数据有效性 及 添加
|
|
|
- validateShopCategories(category, i);
|
|
|
+ validateShopCategories(category, i, code);
|
|
|
} catch (Exception e) {
|
|
|
shopCategoryLog.setReason(e.getMessage());
|
|
|
shopCategoryLog.setIsFail(false);
|
|
|
@@ -269,28 +272,6 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
return excelDataList;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 将Excel数据转换为ShopCategory对象
|
|
|
- *
|
|
|
- * @param excelDTO Excel数据传输对象
|
|
|
- * @return ShopCategory对象
|
|
|
- */
|
|
|
- private ShopCategory convertToShopCategory(ShopCategoryExcelDTO excelDTO) {
|
|
|
- if (excelDTO == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- ShopCategory shopCategory = new ShopCategory();
|
|
|
- shopCategory.setName(excelDTO.getName());
|
|
|
- shopCategory.setSubName(excelDTO.getSubName());
|
|
|
- shopCategory.setSubSubName(excelDTO.getSubSubName());
|
|
|
- shopCategory.setCode(generateUniqueCode());
|
|
|
- shopCategory.setHbShopId(excelDTO.getHbShopId());
|
|
|
- shopCategory.setIsDelete(0); // 默认未删除
|
|
|
- shopCategory.setParentCode("0"); // 默认未删除
|
|
|
-
|
|
|
- return shopCategory;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 生成唯一编码
|
|
|
@@ -310,7 +291,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
*
|
|
|
* @param category 门店前台类目
|
|
|
*/
|
|
|
- private void validateShopCategories(ShopCategoryExcelDTO category, int i) {
|
|
|
+ private void validateShopCategories(ShopCategoryExcelDTO category, int i, String code) {
|
|
|
|
|
|
// 检查必填字段
|
|
|
if (ObjectUtils.isEmpty(category.getHbShopId())) {
|
|
|
@@ -348,10 +329,19 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
shopCategoryByCode1 = addShopCategory(frontCategory, shopDetail.getHbStationId(), shopDetail.getShopId(), shopCategoryByCode1.getId());
|
|
|
}
|
|
|
|
|
|
- ShopCategory shopCategory = new ShopCategory();
|
|
|
+ ShopCategory shopCategory1 = shopCategoryMapper.selectOne(new LambdaQueryWrapper<ShopCategory>()
|
|
|
+ .eq(ShopCategory::getParentCode, frontCategory.getCode())
|
|
|
+ .eq(ShopCategory::getIsDelete, 0)
|
|
|
+ .eq(ShopCategory::getShopId, shopDetail.getShopId())
|
|
|
+ .eq(ShopCategory::getName, category.getSubSubName()));
|
|
|
+ if (shopCategory1 != null){
|
|
|
+ throw new GlobalException("第" + (i + 1) + "行:三级类目已经存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ ShopCategory shopCategory = new ShopCategory();
|
|
|
shopCategory.setPid(shopCategoryByCode1.getId());
|
|
|
shopCategory.setName(category.getSubSubName());
|
|
|
- shopCategory.setCode(generateUniqueCode());
|
|
|
+ shopCategory.setCode(code);
|
|
|
shopCategory.setParentCode(shopCategoryByCode1.getCode());
|
|
|
shopCategory.setParentName(shopCategoryByCode1.getName());
|
|
|
shopCategory.setLevel(3);
|