dev798
wxy 2024-04-03 08:33:09 +08:00
parent 8afb95bbfc
commit bfee419d3c
10 changed files with 138 additions and 6 deletions

View File

@ -1,10 +1,12 @@
package com.muyu.product.controller;
import com.muyu.common.core.domain.AjaxResult;
import com.muyu.product.domain.DTO.Brand;
import com.muyu.product.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @Author: wangxinyuan
@ -17,4 +19,27 @@ public class BrandController {
@Autowired
private BrandService brandService;
@PostMapping
@ApiOperation("品牌添加")
public AjaxResult insertBrand(@RequestBody Brand brand){
Integer res=brandService.insertBrand(brand);
return AjaxResult.success(res==1?"添加成功":"添加失败");
}
@DeleteMapping("/{brandId}")
@ApiOperation("品牌删除")
public AjaxResult deleteBrand(@PathVariable Integer brandId){
Integer res = brandService.deleteBrand(brandId);
return AjaxResult.success(res==1?"删除成功":"删除失败");
}
@PutMapping
@ApiOperation("品牌修改")
public AjaxResult updateBrand(@RequestBody Brand brand){
Integer res = brandService.updateBrand(brand);
return AjaxResult.success(res==1?"修改成功":"修改失败");
}
}

View File

@ -3,10 +3,9 @@ package com.muyu.product.controller;
import com.muyu.common.core.domain.AjaxResult;
import com.muyu.product.domain.DTO.Category;
import com.muyu.product.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -27,4 +26,11 @@ public class CategoryController {
List<Category>list=categoryService.queryCategory();
return AjaxResult.success(list);
}
@DeleteMapping("{categoryId}")
@ApiOperation("分类删除")
public AjaxResult deleteCategory(@PathVariable Integer categoryId){
Integer res = categoryService.deleteCategory(categoryId);
return AjaxResult.success(res==1?"删除成功":"删除失败");
}
}

View File

@ -1,11 +1,22 @@
package com.muyu.product.mapper;
import com.muyu.product.domain.DTO.Brand;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author: wangxinyuan
* @Date: 2024/4/2 19:51
*/
@Mapper
public interface BrandMapper {
Integer deleteBrand(Integer brandId);
Integer insertBrand(Brand brand);
Integer updateBrand(Brand brand);
}

View File

@ -13,4 +13,5 @@ import java.util.List;
public interface CategoryMapper {
List<Category> queryCategory();
Integer deleteCategory(Integer categoryId);
}

View File

@ -1,8 +1,18 @@
package com.muyu.product.service;
import com.muyu.product.domain.DTO.Brand;
/**
* @Author: wangxinyuan
* @Date: 2024/4/2 19:51
*/
public interface BrandService {
Integer insertBrand(Brand brand);
Integer deleteBrand(Integer brandId);
Integer updateBrand(Brand brand);
}

View File

@ -10,4 +10,6 @@ import java.util.List;
*/
public interface CategoryService {
List<Category> queryCategory();
Integer deleteCategory(Integer categoryId);
}

View File

@ -1,6 +1,10 @@
package com.muyu.product.service.impl;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.DTO.Brand;
import com.muyu.product.mapper.BrandMapper;
import com.muyu.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@ -9,4 +13,27 @@ import org.springframework.stereotype.Service;
*/
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandMapper brandMapper;
@Override
public Integer insertBrand(Brand brand) {
brand.setCreateBy(SecurityUtils.getUsername());
return brandMapper.insertBrand(brand);
}
@Override
public Integer deleteBrand(Integer brandId) {
return brandMapper.deleteBrand(brandId);
}
@Override
public Integer updateBrand(Brand brand) {
brand.setCreateBy(SecurityUtils.getUsername());
return brandMapper.updateBrand(brand);
}
}

View File

@ -21,4 +21,9 @@ public class CategoryServiceImpl implements CategoryService {
public List<Category> queryCategory() {
return categoryMapper.queryCategory();
}
@Override
public Integer deleteCategory(Integer categoryId) {
return categoryMapper.deleteCategory(categoryId);
}
}

View File

@ -3,9 +3,49 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.product.mapper.BrandMapper">
<insert id="insertBrand">
INSERT INTO `product`.`t_product_brand` (
`brand_name`,
`first_letter`,
`sort`,
`factory_status`,
`show_status`,
`product_count`,
`product_comment_count`,
`logo`,
`big_pic`,
`brand_story`,
`create_by`,
`create_time`
)
VALUES
(
#{brandName},
#{firstLetter},
#{sort},
#{factoryStatus},
#{showStatus},
#{productCount},
#{productCommentCount},
#{logo},
#{bigPic},
#{brandStory},
#{createBy},
now()
);
</insert>
<update id="updateBrand">
update t_product_brand set brand_name= #{brandName},first_letter=#{firstLetter},sort=#{sort},factory_status=#{factoryStatus}
,show_status=#{showStatus},product_count=#{productCount},product_comment_count=#{productCommentCount},logo=#{logo},
big_pic=#{bigPic},brand_story=#{brandStory},create_by=#{createBy},update_time=now() where id = #{id}
</update>
<!-- 添加其他操作方法如插入、更新、删除等 -->
<delete id="deleteBrand">
update t_product_brand set id_delete = 0 where id = #{id} <!--逻辑删除id_delete=0为删除-->
</delete>
</mapper>

View File

@ -9,6 +9,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
,product_unit,nav_status,show_status,sort,icon,keywords,description
</sql>
<update id="deleteCategory">
update t_product_category set id_delete = 0 where id = #{id}
</update>
<select id="queryCategory" resultType="com.muyu.product.domain.DTO.Category">
select <include refid="sqlCategory"></include> from t_product_category
</select>