Skip to content

Commit

Permalink
根据类型查询分类
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 21, 2022
1 parent 65c7982 commit 682956f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.reggie.dto.CategoryDTO;
import com.reggie.dto.CategoryPageQueryDTO;
import com.reggie.entity.Category;
import com.reggie.result.PageResult;
import com.reggie.result.R;
import com.reggie.service.CategoryService;
Expand All @@ -12,6 +13,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
Expand Down Expand Up @@ -89,10 +92,24 @@ public R<String> update(@RequestBody CategoryDTO categoryDTO) {
@PostMapping("/status/{status}")
@ApiOperation("分类 启用/禁用")
public R<String> startOrStop(@PathVariable Integer status, Long id) {
log.info("分类 启用/禁用:{},{}", status,id);
categoryService.startOrStop(status,id);
log.info("分类 启用/禁用:{},{}", status, id);
categoryService.startOrStop(status, id);
return R.success("状态更新成功");
}

/**
* 根据类型查询分类
*
* @param type 分类类型
* @return 所有 菜品/套餐
*/
@GetMapping("/list")
@ApiOperation("根据类型查询分类")
public R<List<Category>> list(Integer type) {
log.info("根据类型查询分类:{}", type);
List<Category> list = categoryService.list(type);
return R.success(list);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.reggie.entity.Category;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface CategoryMapper {

Expand All @@ -24,4 +26,7 @@ public interface CategoryMapper {
@AutoFill(type = AutoFillConstant.UPDATE)
//修改分类
void update(Category category);

//根据类型查询分类
List<Category> list(Integer type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

import com.reggie.dto.CategoryDTO;
import com.reggie.dto.CategoryPageQueryDTO;
import com.reggie.entity.Category;
import com.reggie.result.PageResult;

import java.util.List;

public interface CategoryService {
//新增分类
void save(CategoryDTO categoryDTO);
Expand All @@ -20,4 +23,7 @@ public interface CategoryService {

//启用/禁用 分类
void startOrStop(Integer status, Long id);

//根据类型查询分类
List<Category> list(Integer type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
Expand Down Expand Up @@ -118,4 +120,14 @@ public void startOrStop(Integer status, Long id) {

categoryMapper.update(category);
}

/**
* 根据类型查询分类
*
* @param type 分类类型
* @return 所有 菜品/套餐
*/
public List<Category> list(Integer type) {
return categoryMapper.list(type);
}
}
12 changes: 12 additions & 0 deletions reggie_server/src/main/resources/mapper/CategoryMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@
</set>
where id = #{id}
</update>


<!--根据类型查询分类-->
<select id="list" resultType="com.reggie.entity.Category">
select *
from category
where status = 1
<if test="type != null">
and type = #{type}
</if>
order by sort,create_time desc
</select>
</mapper>

0 comments on commit 682956f

Please sign in to comment.