修改分类
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.sky.controller.category;
|
package com.sky.controller.category;
|
||||||
|
|
||||||
|
import com.sky.dto.CategoryDTO;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
@@ -7,12 +8,10 @@ import com.sky.service.CategoryService;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@Api(tags = "分类相关接口")
|
@Api(tags = "分类相关接口")
|
||||||
@@ -25,6 +24,7 @@ public class CategoryController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类分页查询
|
* 分类分页查询
|
||||||
|
*
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -36,5 +36,57 @@ public class CategoryController {
|
|||||||
return Result.success(pageResult);
|
return Result.success(pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增分类
|
||||||
|
*
|
||||||
|
* @param categoryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增分类")
|
||||||
|
public Result save(@RequestBody CategoryDTO categoryDTO) {
|
||||||
|
log.info("新增分类: {}", categoryDTO);
|
||||||
|
categoryService.save(categoryDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除分类
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("根据id删除分类")
|
||||||
|
public Result deleteById(long id) {
|
||||||
|
log.info("根据id删除分类: {}",id);
|
||||||
|
categoryService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用分类
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("启用、禁用分类")
|
||||||
|
public Result startOrStop(@PathVariable Integer status,long id){
|
||||||
|
log.info("启用、禁用分类: 启用/禁用:{},分类:{}",status,id);
|
||||||
|
categoryService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改分类
|
||||||
|
* @param categoryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改分类")
|
||||||
|
public Result update(@RequestBody CategoryDTO categoryDTO){
|
||||||
|
log.info("修改分类: {}",categoryDTO);
|
||||||
|
categoryService.update(categoryDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,21 @@ package com.sky.mapper;
|
|||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.entity.Category;
|
import com.sky.entity.Category;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CategoryMapper {
|
public interface CategoryMapper {
|
||||||
|
|
||||||
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||||
|
|
||||||
|
@Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user) " +
|
||||||
|
"values (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||||
|
void insert(Category category);
|
||||||
|
|
||||||
|
@Delete("delete from category where id = #{id}")
|
||||||
|
void deleteById(long id);
|
||||||
|
|
||||||
|
void update(Category category);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.CategoryDTO;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -12,4 +13,29 @@ public interface CategoryService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增分类
|
||||||
|
* @param categoryDTO
|
||||||
|
*/
|
||||||
|
void save(CategoryDTO categoryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除分类
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void deleteById(long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用分类
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改分类
|
||||||
|
* @param categoryDTO
|
||||||
|
*/
|
||||||
|
void update(CategoryDTO categoryDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,19 @@ package com.sky.service.impl;
|
|||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.sky.constant.StatusConstant;
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.dto.CategoryDTO;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.entity.Category;
|
import com.sky.entity.Category;
|
||||||
import com.sky.mapper.CategoryMapper;
|
import com.sky.mapper.CategoryMapper;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.service.CategoryService;
|
import com.sky.service.CategoryService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -20,6 +25,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类分页查询
|
* 分类分页查询
|
||||||
|
*
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -35,4 +41,67 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
|
|
||||||
return new PageResult(total, result);
|
return new PageResult(total, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增分类
|
||||||
|
*
|
||||||
|
* @param categoryDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void save(CategoryDTO categoryDTO) {
|
||||||
|
//复制属性
|
||||||
|
Category category = new Category();
|
||||||
|
BeanUtils.copyProperties(categoryDTO, category);
|
||||||
|
//补充属性
|
||||||
|
category.setStatus(StatusConstant.DISABLE);
|
||||||
|
category.setCreateTime(LocalDateTime.now());
|
||||||
|
category.setUpdateTime(LocalDateTime.now());
|
||||||
|
category.setCreateUser(BaseContext.getCurrentId());
|
||||||
|
category.setUpdateUser(BaseContext.getCurrentId());
|
||||||
|
|
||||||
|
categoryMapper.insert(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除分类
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteById(long id) {
|
||||||
|
categoryMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用分类
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void startOrStop(Integer status, long id) {
|
||||||
|
Category category = Category.builder()
|
||||||
|
.id(id)
|
||||||
|
.status(status)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
categoryMapper.update(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改分类
|
||||||
|
* @param categoryDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void update(CategoryDTO categoryDTO) {
|
||||||
|
//复制属性
|
||||||
|
Category category = new Category();
|
||||||
|
BeanUtils.copyProperties(categoryDTO, category);
|
||||||
|
//设置属性
|
||||||
|
category.setUpdateTime(LocalDateTime.now());
|
||||||
|
category.setUpdateUser(BaseContext.getCurrentId());
|
||||||
|
|
||||||
|
BaseContext.removeCurrentId();
|
||||||
|
categoryMapper.update(category);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,18 @@
|
|||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.sky.mapper.CategoryMapper">
|
<mapper namespace="com.sky.mapper.CategoryMapper">
|
||||||
|
<update id="update">
|
||||||
|
update category
|
||||||
|
<set>
|
||||||
|
<if test="type != null">type = #{type},</if>
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="sort != null">sort = #{sort},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="updateUser != null"> update_user = #{updateUser},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="pageQuery" resultType="com.sky.entity.Category">
|
<select id="pageQuery" resultType="com.sky.entity.Category">
|
||||||
select * from category
|
select * from category
|
||||||
|
|||||||
Reference in New Issue
Block a user