|
@@ -6,17 +6,19 @@ import com.kmall.admin.dao.GoodsDao;
|
|
|
import com.kmall.admin.dao.ProductStoreRelaDao;
|
|
|
import com.kmall.admin.dao.StoreDao;
|
|
|
import com.kmall.admin.dto.CateStoreDto;
|
|
|
+import com.kmall.admin.dto.CategoryDto;
|
|
|
import com.kmall.admin.dto.CopyCategoryDto;
|
|
|
import com.kmall.admin.entity.*;
|
|
|
import com.kmall.admin.service.CategoryService;
|
|
|
+import com.kmall.admin.utils.ValidateUtils;
|
|
|
import com.kmall.common.constant.Dict;
|
|
|
-import com.kmall.common.utils.MapBeanUtil;
|
|
|
-import com.kmall.common.utils.R;
|
|
|
-import com.kmall.common.utils.RRException;
|
|
|
-import com.kmall.common.utils.ValidatorUtil;
|
|
|
+import com.kmall.common.utils.*;
|
|
|
+import com.kmall.manager.manager.express.sf.ServiceException;
|
|
|
import com.kmall.manager.manager.redis.JedisUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -305,5 +307,99 @@ public class CategoryServiceImpl implements CategoryService {
|
|
|
return categoryDao.queryListByParentId(parentId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void uploadExcel(List<CategoryDto> categoryDtoList) {
|
|
|
+ int parentId = 0;
|
|
|
+
|
|
|
+ for (CategoryDto categoryDto : categoryDtoList) {
|
|
|
+ // 分类名称
|
|
|
+ String name = categoryDto.getName();
|
|
|
+ // 关键字
|
|
|
+ String keywords = categoryDto.getKeywords();
|
|
|
+ // 描述
|
|
|
+ String frontDesc = categoryDto.getFrontDesc();
|
|
|
+ // 排序
|
|
|
+ Integer sortOrder = categoryDto.getSortOrder();
|
|
|
+ // 是否显示
|
|
|
+ Integer isShow = categoryDto.getIsShow();
|
|
|
+ // 级别
|
|
|
+ String level = categoryDto.getLevel();
|
|
|
+ // 父节点
|
|
|
+ String parentName = categoryDto.getParentName();
|
|
|
+ // 类型
|
|
|
+ Integer type = categoryDto.getType();
|
|
|
+
|
|
|
+ // 校验
|
|
|
+ if (!ValidateUtils.validateSpecialAllowChinese(name)) {
|
|
|
+ throw new ServiceException("请输入正确的分类名称,有问题的分类名称:" + name);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(keywords)) {
|
|
|
+ if (!ValidateUtils.validateSpecialAllowChinese(keywords)) {
|
|
|
+ throw new ServiceException("请输入正确的关键字,有问题的关键字:" + keywords);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!ValidateUtils.validateSpecialAllowChinese(frontDesc)) {
|
|
|
+ throw new ServiceException("请输入正确的描述,有问题的描述:" + frontDesc);
|
|
|
+ }
|
|
|
+ if (sortOrder == null || sortOrder < 0) {
|
|
|
+ throw new ServiceException("请输入正确的排序,有问题的排序:" + sortOrder);
|
|
|
+ }
|
|
|
+ if (isShow < 0 || isShow > 1) {
|
|
|
+ throw new ServiceException("请填写正确的是否显示,有问题的是否显示:" + isShow);
|
|
|
+ }
|
|
|
+ if (!(Dict.Level.item_L1.getItem()).equals(level) && !(Dict.Level.item_L2.getItem()).equals(level)) {
|
|
|
+ throw new ServiceException("请填写正确的级别,有问题的级别:" + level);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(parentName)) {
|
|
|
+ if (!ValidateUtils.validateSpecialAllowChinese(parentName)) {
|
|
|
+ throw new ServiceException("请输入正确的上级分类名称,有问题的上级分类名称:" + parentName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断分类是否已存在
|
|
|
+ CategoryDto isExist = categoryDao.queryExistByNameAndLevel(name, level);
|
|
|
+ if (isExist != null) {
|
|
|
+ throw new RRException("该级别下的分类名称已存在,已存在的分类名称:" + name);
|
|
|
+ }
|
|
|
+ // 判断上级分类是否已存在
|
|
|
+ if (StringUtils.isNotBlank(parentName)) {
|
|
|
+ // 查询数据库判断有没有
|
|
|
+ CategoryDto isParentExist = categoryDao.queryExistByNameAndLevel(parentName, Dict.Level.item_L1.getItem());
|
|
|
+ if (isParentExist == null) {
|
|
|
+ // 再去判断excel表是否有对应的上级分类
|
|
|
+ boolean flag = true;
|
|
|
+ for (CategoryDto temp : categoryDtoList) {
|
|
|
+ if (temp.getName().equals(parentName) && Dict.Level.item_L1.getItem().equals(temp.getLevel())) {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ throw new RRException("不存在的父分类名称:" + parentName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果excel表分类的父分类在数据库中,则获取父分类
|
|
|
+ parentId = isParentExist.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ CategoryEntity categoryEntity = new CategoryEntity();
|
|
|
+ BeanUtils.copyProperties(categoryDto, categoryEntity);
|
|
|
+ // 父分类的添加
|
|
|
+ if (Dict.Level.item_L1.getItem().equals(level)) {
|
|
|
+ categoryEntity.setParentId(0);
|
|
|
+
|
|
|
+ parentId = categoryDao.save(categoryEntity);
|
|
|
+ } else if (Dict.Level.item_L2.getItem().equals(level)) {
|
|
|
+ // 子分类的添加
|
|
|
+ categoryEntity.setParentId(parentId);
|
|
|
+
|
|
|
+ categoryDao.save(categoryEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|