浏览代码

PC端商品分类

zjy 3 月之前
父节点
当前提交
20eea86a97

+ 9 - 3
alien-entity/src/main/java/shop/alien/entity/second/SecondGoodsCategory.java

@@ -41,9 +41,16 @@ public class SecondGoodsCategory implements Serializable {
     @TableLogic
     private Integer deleteFlag;
 
-    @TableField(value = "created_time", fill = FieldFill.INSERT)
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField("category_sort")
+    @ApiModelProperty(value = "排序")
+    private Integer categorySort;
+
+    @TableField("category_state")
+    @ApiModelProperty(value = "状态 0:显示 1:隐藏")
+    private String categoryState;
+
     @ApiModelProperty(value = "创建时间")
+    @TableField(value = "created_time", fill = FieldFill.INSERT)
     private Date createdTime;
 
     @TableField("created_user_id")
@@ -51,7 +58,6 @@ public class SecondGoodsCategory implements Serializable {
     private Integer createdUserId;
 
     @TableField(value = "updated_time", fill = FieldFill.UPDATE)
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @ApiModelProperty(value = "修改时间")
     private Date updatedTime;
 

+ 2 - 1
alien-entity/src/main/java/shop/alien/mapper/second/SecondGoodsCategoryMapper.java

@@ -1,6 +1,7 @@
 package shop.alien.mapper.second;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import shop.alien.entity.second.SecondGoodsCategory;
 
 import java.util.List;
@@ -12,5 +13,5 @@ public interface SecondGoodsCategoryMapper extends BaseMapper<SecondGoodsCategor
     /**
      * 自定义分页查询
      */
-    List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId);
+    List<SecondGoodsCategory> querySecondGoodsByParentId(@Param("parentId") Integer parentId, @Param("categoryState") Integer categoryState);
 }

+ 17 - 2
alien-entity/src/main/resources/mapper/second/SecondGoodsCategoryMapper.xml

@@ -12,6 +12,8 @@
         <result column="created_user_id" property="createdUserId" jdbcType="INTEGER"/>
         <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
         <result column="updated_user_id" property="updatedUserId" jdbcType="INTEGER"/>
+        <result column="category_sort" property="categorySort" jdbcType="INTEGER"/>
+        <result column="category_state" property="categoryState" jdbcType="VARCHAR"/>
     </resultMap>
 
     <!-- 根据上级ID查询二手商品类别表 -->
@@ -20,7 +22,17 @@
             id,
             category_name,
             category_url,
-            parent_id
+            parent_id,
+            delete_flag,
+            created_time,
+            created_user_id,
+            updated_time,
+            updated_user_id,
+            category_sort,
+            case when category_state = 0 then '显示'
+                when category_state = 1 then '隐藏'
+                else '未知'
+            end as category_state
         FROM
             second_goods_category
         WHERE
@@ -31,6 +43,9 @@
             <if test="parentId == null or parentId == '' ">
                 AND parent_id = -1
             </if>
+            <if test="categoryState != null and categoryState != ''">
+                AND category_state = #{categoryState}
+            </if>
+        ORDER BY category_sort, created_time
     </select>
-
 </mapper>

+ 3 - 3
alien-second/src/main/java/shop/alien/second/controller/SecondGoodsCategoryController.java

@@ -26,8 +26,8 @@ public class SecondGoodsCategoryController {
     @ApiOperation("搜索商品类型")
     @PostMapping("/querySecondGoodsByParentId")
     public R<List<SecondGoodsCategory>> querySecondGoodsByParentId(
-            @RequestParam(value = "parentId", required = false) Integer parentId) throws Exception {
-        return R.data(service.querySecondGoodsByParentId(parentId), "查询成功");
+            @RequestParam(value = "parentId", required = false) Integer parentId,
+            @RequestParam(value = "categoryState", required = false) Integer categoryState) throws Exception {
+        return R.data(service.querySecondGoodsByParentId(parentId, categoryState), "查询成功");
     }
-
 }

+ 49 - 0
alien-second/src/main/java/shop/alien/second/platform/SecondCategoryController.java

@@ -0,0 +1,49 @@
+package shop.alien.second.platform;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiSort;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.second.SecondGoodsCategory;
+import shop.alien.second.service.SecondGoodsCategoryService;
+
+import java.util.List;
+
+@Slf4j
+@Api(tags = {"二手平台-商品类型"})
+@ApiSort(9)
+@CrossOrigin
+@RestController
+@RequestMapping("/second/goodsCategory")
+@RequiredArgsConstructor
+public class SecondCategoryController {
+
+    private final SecondGoodsCategoryService service;
+
+    @ApiOperation("新增商品类型")
+    @PostMapping("/insertSecondGoodsCategory")
+    public R<String> insertSecondGoodsCategory(@RequestBody SecondGoodsCategory category) throws Exception {
+        log.info("SecondGoodsCategoryController.insertSecondGoodsCategory?category={}", category.toString());
+        Integer reporting = service.insertSecondGoodsCategory(category);
+        if (0 == reporting) {
+            return R.fail("新增商品类型失败");
+        } else {
+            return R.data("新增商品类型成功");
+        }
+    }
+
+    @ApiOperation("修改商品类型")
+    @PostMapping("/updateSecondGoodsCategory")
+    public R<String> updateSecondGoodsCategory(@RequestBody SecondGoodsCategory category) throws Exception  {
+        log.info("SecondGoodsCategoryController.updateSecondGoodsCategory?category={}", category.toString());
+        Integer reporting = service.updateSecondGoodsCategory(category);
+        if (0 == reporting) {
+            return R.fail("修改商品类型失败");
+        } else {
+            return R.data("修改商品类型成功");
+        }
+    }
+}

+ 5 - 1
alien-second/src/main/java/shop/alien/second/service/SecondGoodsCategoryService.java

@@ -15,6 +15,10 @@ public interface SecondGoodsCategoryService extends IService<SecondGoodsCategory
      * @param parentId 父ID
      * @return 分页后的屏蔽商品列
      */
-    List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId) throws Exception;
+    List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId, Integer categoryState) throws Exception;
+
+    Integer insertSecondGoodsCategory(SecondGoodsCategory category) throws Exception;
+
+    Integer updateSecondGoodsCategory(SecondGoodsCategory category) throws Exception;
 
 }

+ 57 - 2
alien-second/src/main/java/shop/alien/second/service/impl/SecondGoodsCategoryServiceImpl.java

@@ -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);
+        }
+    }
 }