|
@@ -9,12 +9,15 @@ import com.yami.shop.bean.dto.ShopCategoryExcelDTO;
|
|
|
import com.yami.shop.bean.model.FrontCategory;
|
|
|
import com.yami.shop.bean.model.ShopCategory;
|
|
|
import com.yami.shop.bean.model.ShopCategory;
|
|
|
+import com.yami.shop.bean.model.ShopDetail;
|
|
|
import com.yami.shop.bean.vo.FrontCategoryVO;
|
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.dao.FrontCategoryMapper;
|
|
|
import com.yami.shop.dao.ShopCategoryMapper;
|
|
|
+import com.yami.shop.dao.ShopDetailMapper;
|
|
|
import com.yami.shop.service.IShopCategoryService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -38,6 +41,8 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
|
|
|
private final FrontCategoryMapper frontCategoryMapper;
|
|
|
|
|
|
+ private final ShopDetailMapper shopDetailMapper;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -107,15 +112,19 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
|
|
|
// 批量保存数据
|
|
|
if (!shopCategories.isEmpty()) {
|
|
|
- // 检查数据有效性
|
|
|
- validateShopCategories(shopCategories);
|
|
|
- for (ShopCategory shopCategory : shopCategories) {
|
|
|
- this.save(shopCategory);
|
|
|
+
|
|
|
+ for (int i = 0; i < shopCategories.size(); i++) {
|
|
|
+ ShopCategory category = shopCategories.get(i);
|
|
|
+ // 检查数据有效性
|
|
|
+ Long shopId = validateShopCategories(category, i);
|
|
|
+ category.setShopId(shopId);
|
|
|
+ category.setPid(0L);
|
|
|
+ this.save(category);
|
|
|
//添加对应的二级和三级类目
|
|
|
- FrontCategory frontCategoryByName = frontCategoryMapper.selectListName(shopCategory.getSubName());
|
|
|
- frontCategoryByName.setParentCode(shopCategory.getCode());
|
|
|
- frontCategoryByName.setParentName(shopCategory.getName());
|
|
|
- addShopCategory(frontCategoryByName,shopCategory.getShopId());
|
|
|
+ FrontCategory frontCategoryByName = frontCategoryMapper.selectListName(category.getSubName());
|
|
|
+ frontCategoryByName.setParentCode(category.getCode());
|
|
|
+ frontCategoryByName.setParentName(category.getName());
|
|
|
+ addShopCategory(frontCategoryByName,category.getHbShopId(),shopId,category.getId());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -127,13 +136,14 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
/**
|
|
|
* 添加对应的二级和三级类目
|
|
|
* @param frontCategory 前台类目模板
|
|
|
+ * @param hbShopId 海报
|
|
|
* @param shopId 门店ID
|
|
|
*/
|
|
|
- private void addShopCategory(FrontCategory frontCategory, Long shopId) {
|
|
|
+ private void addShopCategory(FrontCategory frontCategory, String hbShopId, Long shopId,Long id) {
|
|
|
ShopCategory shopCategory = new ShopCategory();
|
|
|
+ shopCategory.setPid(id);
|
|
|
shopCategory.setName(frontCategory.getName());
|
|
|
shopCategory.setCode(frontCategory.getCode());
|
|
|
- shopCategory.setShopId(shopId);
|
|
|
shopCategory.setParentCode(frontCategory.getParentCode());
|
|
|
shopCategory.setParentName(frontCategory.getName());
|
|
|
shopCategory.setLevel(frontCategory.getLevel());
|
|
@@ -141,11 +151,15 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
shopCategory.setIsDelete(0);
|
|
|
shopCategory.setOperateUser("admin");
|
|
|
shopCategory.setIsLeaves(1);
|
|
|
+
|
|
|
+ shopCategory.setHbShopId(hbShopId);
|
|
|
+ shopCategory.setShopId(shopId);
|
|
|
+
|
|
|
this.save(shopCategory);
|
|
|
List<FrontCategory> frontCategoryList = frontCategoryMapper.selectList(new LambdaQueryWrapper<FrontCategory>()
|
|
|
.eq(FrontCategory::getParentCode, frontCategory.getCode()));
|
|
|
for (FrontCategory frontCategory1 : frontCategoryList) {
|
|
|
- addShopCategory(frontCategory1,shopId);
|
|
|
+ addShopCategory(frontCategory1,hbShopId,shopId,shopCategory.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -193,7 +207,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
shopCategory.setName(excelDTO.getName());
|
|
|
shopCategory.setSubName(excelDTO.getSubName());
|
|
|
shopCategory.setCode(generateUniqueCode());
|
|
|
- shopCategory.setShopId(excelDTO.getShopId());
|
|
|
+ shopCategory.setHbShopId(excelDTO.getShopId());
|
|
|
shopCategory.setIsDelete(0); // 默认未删除
|
|
|
shopCategory.setParentCode("0"); // 默认未删除
|
|
|
|
|
@@ -214,24 +228,20 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
/**
|
|
|
* 验证门店前台类目数据有效性
|
|
|
*
|
|
|
- * @param shopCategories 门店前台类目列表
|
|
|
+ * @param category 门店前台类目
|
|
|
*/
|
|
|
- private void validateShopCategories(List<ShopCategory> shopCategories) {
|
|
|
- if (shopCategories == null || shopCategories.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < shopCategories.size(); i++) {
|
|
|
- ShopCategory category = shopCategories.get(i);
|
|
|
-
|
|
|
+ private Long validateShopCategories(ShopCategory category,int i) {
|
|
|
// 检查必填字段
|
|
|
- if (category.getName() == null || category.getName().trim().isEmpty()) {
|
|
|
+ if (ObjectUtils.isEmpty(category.getName())) {
|
|
|
throw new GlobalException("第" + (i + 1) + "行:类目名称不能为空");
|
|
|
}
|
|
|
-
|
|
|
- if (category.getShopId() == null) {
|
|
|
+ if (ObjectUtils.isEmpty(category.getHbShopId())) {
|
|
|
throw new GlobalException("第" + (i + 1) + "行:门店ID不能为空");
|
|
|
}
|
|
|
+ ShopDetail shopDetail = shopDetailMapper.selectByHbStationId(category.getHbShopId());
|
|
|
+ if (ObjectUtils.isEmpty(shopDetail)) {
|
|
|
+ throw new GlobalException("第" + (i + 1) + "行:门店不存在");
|
|
|
+ }
|
|
|
|
|
|
// 检查类目名称长度
|
|
|
if (category.getName().length() > 255) {
|
|
@@ -261,9 +271,7 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
if (integer > 1) {
|
|
|
throw new GlobalException("第" + (i + 1) + "行:二级类目"+category.getSubName()+"存在多个");
|
|
|
}
|
|
|
-
|
|
|
-// .eq(FrontCategory::getLevel, 1));
|
|
|
- }
|
|
|
+ return shopDetail.getShopId();
|
|
|
}
|
|
|
|
|
|
|