|
|
@@ -1,13 +1,18 @@
|
|
|
package shop.alien.second.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import shop.alien.entity.second.SecondGoodsCategory;
|
|
|
import shop.alien.mapper.second.SecondGoodsCategoryMapper;
|
|
|
import shop.alien.second.service.SecondGoodsCategoryService;
|
|
|
+import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -27,12 +32,62 @@ public class SecondGoodsCategoryServiceImpl extends ServiceImpl<SecondGoodsCateg
|
|
|
* @return 是否成功保存
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId) throws Exception {
|
|
|
+ public List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId, Integer categoryState) throws Exception {
|
|
|
try {
|
|
|
- return mapper.querySecondGoodsByParentId(parentId);
|
|
|
+ return mapper.querySecondGoodsByParentId(parentId, categoryState);
|
|
|
} catch (Exception e) {
|
|
|
log.error("SecondGoodsCategoryServiceImpl.querySecondGoodsByParentId Error Mgs={}", e.getMessage());
|
|
|
throw new Exception("查询二级商品分类失败", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer insertSecondGoodsCategory(SecondGoodsCategory category) throws Exception {
|
|
|
+ try {
|
|
|
+ return mapper.insert(category);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondGoodsCategoryServiceImpl.insertSecondGoodsCategory Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception("查询二级商品分类失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer updateSecondGoodsCategory(SecondGoodsCategory category) throws Exception {
|
|
|
+ try {
|
|
|
+ JSONObject data = JwtUtil.getCurrentUserInfo();
|
|
|
+ String userId = null;
|
|
|
+ if (data != null) {
|
|
|
+ userId = data.getString("userId");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(userId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<SecondGoodsCategory> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(SecondGoodsCategory::getId, category.getId());
|
|
|
+ if (StringUtils.isNotBlank(category.getCategoryName())) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getCategoryName, category.getCategoryName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(category.getCategoryUrl())) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getCategoryUrl, category.getCategoryUrl());
|
|
|
+ }
|
|
|
+ if (category.getParentId() != null) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getParentId, category.getParentId());
|
|
|
+ }
|
|
|
+ if (category.getCategorySort() != null) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getCategorySort, category.getCategorySort());
|
|
|
+ }
|
|
|
+ if (category.getCategoryState() != null) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getCategoryState, category.getCategoryState());
|
|
|
+ }
|
|
|
+ wrapper.set(SecondGoodsCategory::getUpdatedUserId, userId);
|
|
|
+ if (category.getDeleteFlag() != null) {
|
|
|
+ wrapper.set(SecondGoodsCategory::getDeleteFlag, category.getDeleteFlag());
|
|
|
+ } else {
|
|
|
+ wrapper.set(SecondGoodsCategory::getDeleteFlag, 0);
|
|
|
+ }
|
|
|
+ return mapper.update(null, wrapper);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("SecondGoodsCategoryServiceImpl.insertSecondGoodsCategory Error Mgs={}", e.getMessage());
|
|
|
+ throw new Exception("更新二级商品分类失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|