|
@@ -0,0 +1,153 @@
|
|
|
+package com.txz.mall.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.txz.mall.core.Result;
|
|
|
+import com.txz.mall.core.ResultCode;
|
|
|
+import com.txz.mall.model.Category;
|
|
|
+import com.txz.mall.service.CategoryService;
|
|
|
+import com.txz.mall.vo.CategoryTreeVo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by CodeGenerator on 2025/07/11.
|
|
|
+ */
|
|
|
+@Api(tags = "[后台]类目管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/category")
|
|
|
+public class CategoryController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(CategoryController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CategoryService categoryService;
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "类目新增", httpMethod = "POST")
|
|
|
+ public Result add(@RequestBody Category category, Long userId) {
|
|
|
+ if (category == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ category.setCreateTime(new Date());
|
|
|
+ category.setCreateUserId(userId);
|
|
|
+ categoryService.save(category);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ @ApiOperation(value = "类目删除", httpMethod = "POST")
|
|
|
+ public Result delete(@RequestParam Long id, Long userId) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Category category = new Category();
|
|
|
+ category.setIsDelete(1);
|
|
|
+ categoryService.update(category);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperation(value = "类目更新", httpMethod = "POST")
|
|
|
+ public Result update(@RequestBody Category category, Long userId) {
|
|
|
+ if (category == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (category.getId() == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ category.setUpdateTime(new Date());
|
|
|
+ category.setUpdateUserId(userId);
|
|
|
+ categoryService.update(category);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/detail")
|
|
|
+ @ApiOperation(value = "类目获取详情", httpMethod = "POST")
|
|
|
+ public Result<Category> detail(@RequestParam Long id, Long userId) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ Category category = null;
|
|
|
+ try {
|
|
|
+ category = categoryService.findById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(category);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ @ApiOperation(value = "类目获取列表", httpMethod = "POST")
|
|
|
+ public Result<List<Category>> list(@RequestBody Category category, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, Long userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+
|
|
|
+ Condition condition = new Condition(category.getClass());
|
|
|
+// Criteria criteria = condition.createCriteria();
|
|
|
+// criteria.andEqualTo("name", city.getName());
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<Category> list = categoryService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取tree结构的列表")
|
|
|
+ @GetMapping(value = "/list/tree")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "type", value = "类型ID | 类型,1 产品分类,2 附件分类,3 文章分类, 4 设置分类, 5 菜单分类, 6 配置分类, 7 秒杀配置", example = "1"),
|
|
|
+ @ApiImplicitParam(name = "status", value = "-1=全部,0=未生效,1=已生效", example = "1"),
|
|
|
+ @ApiImplicitParam(name = "name", value = "模糊搜索", example = "电视")
|
|
|
+ })
|
|
|
+ public Result<List<CategoryTreeVo>> getListTree(@RequestParam(name = "type") Integer type,
|
|
|
+ @RequestParam(name = "status") Integer status,
|
|
|
+ @RequestParam(name = "name", required = false) String name) {
|
|
|
+ List<CategoryTreeVo> listTree = categoryService.getListTree(type, status, name);
|
|
|
+ return Result.success(listTree);
|
|
|
+ }
|
|
|
+}
|