diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/BrandController.java b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/BrandController.java index b7e0c093..478ccb05 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/BrandController.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/BrandController.java @@ -8,10 +8,14 @@ import com.ruoyi.common.enums.BusinessType; import com.ruoyi.web.domain.Brand; import com.ruoyi.web.service.BrandService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.List; +/** + * 商品品牌管理 + */ @RestController @RequestMapping("/mall/brand") public class BrandController extends BaseController { @@ -25,9 +29,9 @@ public class BrandController extends BaseController { * @return */ @Anonymous - @GetMapping("/tree") - public AjaxResult getBrandTree() { - return AjaxResult.success(brandService.getBrandTree()); + @GetMapping(value = "/getTree/{storeId}") + public AjaxResult getBrandTree(@PathVariable String storeId) { + return AjaxResult.success(brandService.getBrandTree(storeId)); } /** @@ -40,6 +44,10 @@ public class BrandController extends BaseController { @Log(title = "商品品牌管理", businessType = BusinessType.INSERT) @PostMapping("/add") public AjaxResult addBrand(@RequestBody Brand brand) { + if (!brandService.checkBrandUnique(brand)) { + return error("新增商品品牌'" + brand.getBrandName() + "'失败,商品品牌名称已存在"); + } + brand.setCreateBy(getUsername()); return toAjax(brandService.addBrand(brand)); } @@ -54,13 +62,21 @@ public class BrandController extends BaseController { @Log(title = "商品品牌管理", businessType = BusinessType.UPDATE) @PostMapping("/update") public AjaxResult updateBrand(@RequestBody Brand brand) { + if (!brandService.checkBrandUnique(brand)) { + return error("修改商品品牌'" + brand.getBrandName() + "'失败,商品品牌名称已存在"); + } return toAjax(brandService.updateBrand(brand)); } - // 删除品牌 + /** + * 删除品牌 + * + * @param id + * @return + */ @DeleteMapping("/delete/{id}") - public String deleteBrand(@PathVariable Long id) { - brandService.deleteBrand(id); - return "success"; + @Log(title = "商品品牌管理", businessType = BusinessType.DELETE) + public AjaxResult deleteBrand(@PathVariable Long id) { + return toAjax(brandService.deleteBrand(id)); } } \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ClassificationController.java b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ClassificationController.java new file mode 100644 index 00000000..f3784e95 --- /dev/null +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ClassificationController.java @@ -0,0 +1,80 @@ +package com.ruoyi.web.controller; + +import com.ruoyi.common.annotation.Anonymous; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.web.domain.Classification; +import com.ruoyi.web.service.ClassIficationService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * 商品分类管理 + */ +@RestController +@RequestMapping("/mall/classification") +public class ClassificationController extends BaseController { + + @Resource + private ClassIficationService classIficationService; + + /** + * 获取商品分类树 + * + * @return + */ + @Anonymous + @GetMapping(value = "/getTree/{storeId}") + public AjaxResult getClassIficationTree(@PathVariable String storeId) { + return AjaxResult.success(classIficationService.getIficationTree(storeId)); + } + + /** + * 添加商品分类 + * + * @param classification + * @return + */ + @Anonymous + @Log(title = "商品分类管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public AjaxResult addClassIfication(@RequestBody Classification classification) { + if (!classIficationService.checkBrandUnique(classification)) { + return error("新增商品分类'" + classification.getClassificationName() + "'失败,商品分类名称已存在"); + } + + classification.setCreateBy(getUsername()); + return toAjax(classIficationService.addClassification(classification)); + } + + /** + * 修改商品分类 + * + * @param classification + * @return + */ + @Anonymous + @Log(title = "商品分类管理", businessType = BusinessType.UPDATE) + @PostMapping("/update") + public AjaxResult updateClassIfication(@RequestBody Classification classification) { + if (!classIficationService.checkBrandUnique(classification)) { + return error("修改商品分类'" + classification.getClassificationName()+ "'失败,商品分类名称已存在"); + } + return toAjax(classIficationService.updateClassification(classification)); + } + + /** + * 删除分类 + * + * @param id + * @return + */ + @DeleteMapping("/delete/{id}") + @Log(title = "商品分类管理", businessType = BusinessType.DELETE) + public AjaxResult deleteClassIfication(@PathVariable Long id) { + return toAjax(classIficationService.deleteClassIfication(id)); + } +} \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ProductStoreController.java b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ProductStoreController.java index f302bb76..2d703441 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ProductStoreController.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/ProductStoreController.java @@ -67,7 +67,6 @@ public class ProductStoreController extends BaseController { } - /** * 新增商品 */ @@ -75,14 +74,17 @@ public class ProductStoreController extends BaseController { @Log(title = "商品管理", businessType = BusinessType.INSERT) @PostMapping("/add") public AjaxResult add(@Validated Product product, - @RequestParam("file") MultipartFile file) throws IOException, InvalidExtensionException { + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, InvalidExtensionException { if (!productService.checkProductCodeUnique(product)) { return error("新增商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在"); } + //todo 这里可以国码有的时候使用国码的图片路径 + + // TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的 //国码后续添加 - if (!file.isEmpty()) { + if (file != null) { String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true); if (StringUtils.isNotEmpty(avatar)) { product.setMainImage(avatar); @@ -101,22 +103,22 @@ public class ProductStoreController extends BaseController { @Log(title = "商品管理", businessType = BusinessType.UPDATE) @PostMapping("/update") public AjaxResult edit(@Validated Product product, - @RequestParam("file") MultipartFile file) throws IOException, InvalidExtensionException { + @RequestParam(value = "file", required = false) MultipartFile file) throws IOException, InvalidExtensionException { if (!productService.checkProductCodeUnique(product)) { return error("修改商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在"); } + //todo 这里可以国码有的时候使用国码的图片路径 + + // TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的 //然后修改的时候 这个file不为空代表用户又修改了图片需要更新,为空的话之前图片保持不变 - if (!file.isEmpty()) { + if (file != null) { String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true); if (StringUtils.isNotEmpty(avatar)) { product.setMainImage(avatar); } } - //todo 这里可以国码有的时候使用国码的图片路径 - - product.setUpdateBy(getUsername()); return toAjax(productService.updateProduct(product)); } @@ -143,6 +145,6 @@ public class ProductStoreController extends BaseController { @RequestParam("storeId") Integer storeId) throws Exception { ExcelUtil util = new ExcelUtil(Product.class); List productList = util.importExcel(file.getInputStream()); - return AjaxResult.success(productService.importProduct(productList,storeId)); + return AjaxResult.success(productService.importProduct(productList, storeId)); } } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/StoreController.java b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/StoreController.java index f5276bb5..cd32fcb0 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/controller/StoreController.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/controller/StoreController.java @@ -1,5 +1,6 @@ package com.ruoyi.web.controller; +import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -35,6 +36,15 @@ public class StoreController extends BaseController { return getDataTable(list); } + /** + * 根据门店id 获取商品详情 + */ + @Anonymous +// @PreAuthorize("@ss.hasPermi('store:query')") + @GetMapping(value = "/{storeId}") + public AjaxResult getInfo(@PathVariable Long storeId) { + return success(storeService.selectStore(storeId)); + } /** * 新增门店 @@ -74,6 +84,16 @@ public class StoreController extends BaseController { return toAjax(storeService.updateStore(store)); } + /** + * 修改门店状态 + */ + @Anonymous + @Log(title = "门店管理", businessType = BusinessType.UPDATE) + @PutMapping("updateStatus") + public AjaxResult updateStatus(@Validated @RequestBody Store store) { + store.setUpdateBy(getUsername()); + return toAjax(storeService.updateStatus(store)); + } /** * 用户关联门店 包含 修改 删除 @@ -88,6 +108,7 @@ public class StoreController extends BaseController { /** * 根据用户id 获取关联的门店 */ + @Anonymous // @PreAuthorize("@ss.hasPermi('product:query')") @GetMapping(value = "/getUserStore/{userId}") public AjaxResult getUserStore(@PathVariable String userId) { diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Classification.java b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Classification.java new file mode 100644 index 00000000..e5f91399 --- /dev/null +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Classification.java @@ -0,0 +1,18 @@ +package com.ruoyi.web.domain; + +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; + +import java.util.List; + +@Data +public class Classification extends BaseEntity { + private static final long serialVersionUID = 1L; + + private Long id; + private Long parentId = 0L; // 0表示一级分类 + private String classificationName; // 分类名称 + private Integer storeId; //门店id + // 非数据库字段:子商品分类列表 + private List children; +} diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Product.java b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Product.java index 05946a85..bed02ce2 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Product.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Product.java @@ -55,6 +55,18 @@ public class Product extends BaseEntity { @Excel(name = "商品条码") private String productBarCode; + /** + * 商品品牌 + */ + private String productBrand; + + + /** + * 商品分类 + */ + private String classifcation; + + /** * 商品名称 */ diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Store.java b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Store.java index 43cf7636..ce60ca58 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Store.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/domain/Store.java @@ -3,6 +3,8 @@ package com.ruoyi.web.domain; import com.ruoyi.common.core.domain.BaseEntity; import lombok.Data; +import javax.validation.constraints.Size; + /** * 门店表 mall_store @@ -49,6 +51,7 @@ public class Store extends BaseEntity { /** * 联系电话 */ + @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") private String contactPhone; /** @@ -56,4 +59,6 @@ public class Store extends BaseEntity { */ private String storeManager; + private Integer status; + } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/BrandMapper.java b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/BrandMapper.java index 7e4d2bcd..0e79333a 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/BrandMapper.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/BrandMapper.java @@ -1,56 +1,34 @@ package com.ruoyi.web.mapper; import com.ruoyi.web.domain.Brand; +import com.ruoyi.web.domain.Store; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; + import java.util.List; @Mapper public interface BrandMapper { - /** - * 查询所有品牌 - */ List selectAll(); - /** - * 查询一级品牌(parentId=0) - */ - List selectRootBrands(); + List selectRootBrands(String storeId); + - /** - * 根据父品牌ID查询子品牌 - */ List selectByParentId(@Param("parentId") Long parentId); - /** - * 根据ID查询品牌 - */ + Brand selectById(@Param("id") Long id); - /** - * 新增品牌 - */ + int insert(Brand brand); - /** - * 更新品牌 - */ int update(Brand brand); - /** - * 删除品牌 - */ int delete(@Param("id") Long id); + int batchBrand(Long id); + + Store checkBrandUnique(Brand brand); -// /** -// * 检查是否有子品牌 -// */ -// int countChildren(@Param("parentId") Long parentId); -// -// /** -// * 根据品牌名称查询 -// */ -// Brand selectByName(@Param("brandName") String brandName); } \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/ClassIficationMapper.java b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/ClassIficationMapper.java new file mode 100644 index 00000000..8491832a --- /dev/null +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/ClassIficationMapper.java @@ -0,0 +1,37 @@ +package com.ruoyi.web.mapper; + +import com.ruoyi.web.domain.Brand; +import com.ruoyi.web.domain.Classification; +import com.ruoyi.web.domain.Store; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ClassIficationMapper { + + + List selectRootBrands(String storeId); + + + List selectByParentId(@Param("parentId") Long parentId); + + Classification selectById(@Param("id") Long id); + + + int insert(Classification classification); + + + int update(Classification classification); + + + int delete(@Param("id") Long id); + + int batchBrand(Long id); + + Classification checkBrandUnique(Classification classification); + + + +} \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/StoreMapper.java b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/StoreMapper.java index e2cb1dae..7e9720f9 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/StoreMapper.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/StoreMapper.java @@ -2,6 +2,8 @@ package com.ruoyi.web.mapper; import com.ruoyi.web.domain.Store; +import com.ruoyi.web.vo.StoreVo; +import com.ruoyi.web.vo.UserStoreVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -29,4 +31,9 @@ public interface StoreMapper void deleteStoreUser(Long storeId); + Store selectStore(Long storeId); + + int updateStatus(Store store); + + } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/UserStoreMapper.java b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/UserStoreMapper.java index f382801e..38a56f24 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/UserStoreMapper.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/mapper/UserStoreMapper.java @@ -1,12 +1,17 @@ package com.ruoyi.web.mapper; +import com.ruoyi.web.vo.StoreVo; import com.ruoyi.web.vo.UserStoreVo; +import java.util.List; + /** * 用户关联门店 */ public interface UserStoreMapper { UserStoreVo getUserStoreWithStores(String userId); + + List queryStore(); } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/BrandService.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/BrandService.java index 920d3018..aee2a897 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/service/BrandService.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/BrandService.java @@ -7,7 +7,7 @@ import java.util.List; public interface BrandService { // 获取品牌树(一级品牌包含子品牌) - List getBrandTree(); + List getBrandTree(String storeId); // 添加品牌 int addBrand(Brand brand); @@ -15,6 +15,7 @@ public interface BrandService { int updateBrand(Brand brand); // 删除品牌 - void deleteBrand(Long id); + int deleteBrand(Long id); + boolean checkBrandUnique(Brand brand); } \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/ClassIficationService.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/ClassIficationService.java new file mode 100644 index 00000000..4083fe89 --- /dev/null +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/ClassIficationService.java @@ -0,0 +1,18 @@ +package com.ruoyi.web.service; + +import com.ruoyi.web.domain.Classification; + +import java.util.List; + +public interface ClassIficationService { + + List getIficationTree(String storeId); + + int addClassification(Classification classification); + + int updateClassification(Classification classification); + + int deleteClassIfication(Long id); + + boolean checkBrandUnique(Classification classification); +} \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/StoreService.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/StoreService.java index 40e2064e..36a1434a 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/service/StoreService.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/StoreService.java @@ -56,4 +56,8 @@ public interface StoreService { int insertUserStores(Long userId, Long[] storeIds); UserStoreVo getUserStore(String userId); + + Store selectStore(Long storeId); + + int updateStatus(Store store); } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/BrandServiceImpl.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/BrandServiceImpl.java index ae6058fa..e008c3dc 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/BrandServiceImpl.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/BrandServiceImpl.java @@ -1,13 +1,20 @@ package com.ruoyi.web.service.impl; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.web.domain.Brand; +import com.ruoyi.web.domain.Classification; +import com.ruoyi.web.domain.Store; import com.ruoyi.web.mapper.BrandMapper; import com.ruoyi.web.service.BrandService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class BrandServiceImpl implements BrandService { @@ -16,20 +23,43 @@ public class BrandServiceImpl implements BrandService { private BrandMapper brandMapper; @Override - public List getBrandTree() { - // 1. 获取所有一级品牌 - List rootBrands = brandMapper.selectRootBrands(); + public List getBrandTree(String storeId) { + List rootBrands = brandMapper.selectRootBrands(storeId); - // 2. 为每个一级品牌设置子品牌 - for (Brand rootBrand : rootBrands) { - List children = brandMapper.selectByParentId(rootBrand.getId()); - rootBrand.setChildren(children); + return buildTree(rootBrands); + + } + + private List buildTree(List allList) { + List rootList = new ArrayList<>(); + + Map nodeMap = new HashMap<>(); + + for (Brand node : allList) { + node.setChildren(new ArrayList<>()); + nodeMap.put(node.getId(), node); } - return rootBrands; + + for (Brand node : allList) { + Long parentId = node.getParentId(); + + if (parentId == null || parentId == 0) { + rootList.add(node); + } else { + Brand parent = nodeMap.get(parentId); + if (parent != null) { + parent.getChildren().add(node); + } else { + rootList.add(node); + } + } + } + + return rootList; } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public int addBrand(Brand brand) { // 如果是二级品牌,检查父品牌是否存在 if (brand.getParentId() != null && brand.getParentId() != 0) { @@ -44,14 +74,30 @@ public class BrandServiceImpl implements BrandService { } @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public int updateBrand(Brand brand) { - return brandMapper.update(brand); + return brandMapper.update(brand); } @Override - public void deleteBrand(Long id) { - + @Transactional(rollbackFor = Exception.class) + public int deleteBrand(Long id) { + brandMapper.delete(id); + //如果该品牌是一级品牌,那删除的时候也要把下面的二级品牌一起删掉 + brandMapper.batchBrand(id); + return 1; } + @Override + public boolean checkBrandUnique(Brand brand) { + if (brand == null || StringUtils.isBlank(brand.getBrandName())) { + return UserConstants.UNIQUE; + } + + Long id = brand.getId() == null ? -1L : brand.getId(); + brand.setId(id); + Store existStore = brandMapper.checkBrandUnique(brand); + + return existStore != null ? UserConstants.NOT_UNIQUE : UserConstants.UNIQUE; + } } \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/ClassIficationServiceImpl.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/ClassIficationServiceImpl.java new file mode 100644 index 00000000..588d77e9 --- /dev/null +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/ClassIficationServiceImpl.java @@ -0,0 +1,124 @@ +package com.ruoyi.web.service.impl; + +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.web.domain.Classification; +import com.ruoyi.web.domain.Store; +import com.ruoyi.web.mapper.ClassIficationMapper; +import com.ruoyi.web.service.ClassIficationService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class ClassIficationServiceImpl implements ClassIficationService { + + @Resource + private ClassIficationMapper classIficationMapper; + + @Override + public List getIficationTree(String storeId) { + List rootBrands = classIficationMapper.selectRootBrands(storeId); + + // 构建树形结构 + return buildTree(rootBrands); + } + + /** + * 从平铺列表构建树形结构 + */ + private List buildTree(List allList) { + List rootList = new ArrayList<>(); + + Map nodeMap = new HashMap<>(); + + for (Classification node : allList) { + node.setChildren(new ArrayList<>()); + nodeMap.put(node.getId(), node); + } + + for (Classification node : allList) { + Long parentId = node.getParentId(); + + if (parentId == null || parentId == 0) { + rootList.add(node); + } else { + Classification parent = nodeMap.get(parentId); + if (parent != null) { + parent.getChildren().add(node); + } else { + rootList.add(node); + } + } + } + + return rootList; + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public int addClassification(Classification classification) { + // 如果是二级品牌,检查父品牌是否存在 + if (classification.getParentId() != null && classification.getParentId() != 0) { + Classification classification1 = classIficationMapper.selectById(classification.getParentId()); + if (classification1 == null) { + throw new RuntimeException("父分类不存在"); + } + } + return classIficationMapper.insert(classification); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int updateClassification(Classification classification) { + return classIficationMapper.update(classification); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int deleteClassIfication(Long id) { + List allDeleteIds = getAllChildIds(id); + allDeleteIds.add(id); // 包括自身 + for (Long allDeleteId : allDeleteIds) { + classIficationMapper.delete(allDeleteId); + } + return 1; + } + + /** + * 递归获取所有子分类ID + */ + private List getAllChildIds(Long parentId) { + List allChildIds = new ArrayList<>(); + + // 查询直接子节点 + List children = classIficationMapper.selectByParentId(parentId); + + for (Classification child : children) { + allChildIds.add(child.getId()); + + allChildIds.addAll(getAllChildIds(child.getId())); + } + + return allChildIds; + } + + @Override + public boolean checkBrandUnique(Classification classification) { + if (classification == null || StringUtils.isBlank(classification.getClassificationName())) { + return UserConstants.UNIQUE; + } + + Long id = classification.getId() == null ? -1L : classification.getId(); + classification.setId(id); + Classification existStore = classIficationMapper.checkBrandUnique(classification); + + return existStore != null ? UserConstants.NOT_UNIQUE : UserConstants.UNIQUE; + } +} \ No newline at end of file diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/StoreServiceImpl.java b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/StoreServiceImpl.java index 795c0f5f..2c49cbe6 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/StoreServiceImpl.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/service/impl/StoreServiceImpl.java @@ -7,6 +7,7 @@ import com.ruoyi.web.domain.Store; import com.ruoyi.web.mapper.StoreMapper; import com.ruoyi.web.mapper.UserStoreMapper; import com.ruoyi.web.service.StoreService; +import com.ruoyi.web.vo.StoreVo; import com.ruoyi.web.vo.UserStoreVo; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -84,6 +85,27 @@ public class StoreServiceImpl implements StoreService { @Override public UserStoreVo getUserStore(String userId) { - return userStoreMapper.getUserStoreWithStores(userId); + + UserStoreVo userStoreWithStores = userStoreMapper.getUserStoreWithStores(userId); + List storeVos = userStoreMapper.queryStore(); + if (userStoreWithStores != null) { + userStoreWithStores.setAllStores(storeVos); + return userStoreWithStores; + } else { + UserStoreVo userStoreVo = new UserStoreVo(); + userStoreVo.setAllStores(storeVos); + userStoreVo.setUserId(Long.valueOf(userId)); + return userStoreVo; + } + } + + @Override + public Store selectStore(Long storeId) { + return storeMapper.selectStore(storeId); + } + + @Override + public int updateStatus(Store store) { + return storeMapper.updateStatus(store); } } diff --git a/ruoyi-mall/src/main/java/com/ruoyi/web/vo/UserStoreVo.java b/ruoyi-mall/src/main/java/com/ruoyi/web/vo/UserStoreVo.java index 54dcba77..db2d1e35 100644 --- a/ruoyi-mall/src/main/java/com/ruoyi/web/vo/UserStoreVo.java +++ b/ruoyi-mall/src/main/java/com/ruoyi/web/vo/UserStoreVo.java @@ -2,11 +2,12 @@ package com.ruoyi.web.vo; import lombok.Data; +import java.util.ArrayList; import java.util.List; @Data public class UserStoreVo { - + private List allStores = new ArrayList<>(); //所有的门店 private Long userId; //用户id private List stores; // 门店对象列表 } diff --git a/ruoyi-mall/src/main/resources/mapper/commodity/BrandMapper.xml b/ruoyi-mall/src/main/resources/mapper/commodity/BrandMapper.xml index 160324f0..a91c099f 100644 --- a/ruoyi-mall/src/main/resources/mapper/commodity/BrandMapper.xml +++ b/ruoyi-mall/src/main/resources/mapper/commodity/BrandMapper.xml @@ -4,13 +4,13 @@ - - - - - - - + + + + + + + @@ -24,7 +24,7 @@ @@ -32,6 +32,7 @@ SELECT * FROM mall_brand WHERE parent_id = #{parentId} + and del_flag = '0' @@ -41,6 +42,15 @@ WHERE id = #{id} + + insert into mall_brand ( @@ -67,11 +77,16 @@ - DELETE - FROM brand - WHERE id = #{id} + update mall_brand + set del_flag = '2' + where id = #{id} + + + + update mall_brand + set del_flag = '2' + where parent_id = #{id} - \ No newline at end of file diff --git a/ruoyi-mall/src/main/resources/mapper/commodity/ClassIficationMapper.xml b/ruoyi-mall/src/main/resources/mapper/commodity/ClassIficationMapper.xml new file mode 100644 index 00000000..c9574419 --- /dev/null +++ b/ruoyi-mall/src/main/resources/mapper/commodity/ClassIficationMapper.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + insert into mall_classification ( + parent_id, + classification_name, + create_by, + store_id, + create_time + )values( + #{parentId}, + #{classificationName}, + #{createBy}, + #{storeId}, + sysdate() + ) + + + + + UPDATE mall_classification + SET classification_name = #{classificationName} + WHERE id = #{id} + + + + update mall_classification + set del_flag = '2' + where id = #{id} + + + + update mall_classification + set del_flag = '2' + where parent_id = #{id} + + + + \ No newline at end of file diff --git a/ruoyi-mall/src/main/resources/mapper/commodity/ProductMapper.xml b/ruoyi-mall/src/main/resources/mapper/commodity/ProductMapper.xml index 8a85ff88..3be50d4d 100644 --- a/ruoyi-mall/src/main/resources/mapper/commodity/ProductMapper.xml +++ b/ruoyi-mall/src/main/resources/mapper/commodity/ProductMapper.xml @@ -25,6 +25,8 @@ + + @@ -48,7 +50,9 @@ shelf_code, shelf_life, production_date, - approaching + approaching, + product_brand, + classifcation from mall_product_store @@ -155,6 +159,8 @@ shelf_life = #{shelfLife}, production_date = #{productionDate}, approaching = #{approaching}, + product_brand = #{productBrand}, + classifcation = #{classifcation}, update_time = sysdate() where id = #{id} @@ -179,6 +185,8 @@ shelf_life = #{shelfLife}, production_date = #{productionDate}, approaching = #{approaching}, + product_brand = #{productBrand}, + classifcation = #{classifcation}, update_time = sysdate() where product_bar_code = #{productBarCode} diff --git a/ruoyi-mall/src/main/resources/mapper/commodity/StoreMapper.xml b/ruoyi-mall/src/main/resources/mapper/commodity/StoreMapper.xml index d26a70e6..3ab480fb 100644 --- a/ruoyi-mall/src/main/resources/mapper/commodity/StoreMapper.xml +++ b/ruoyi-mall/src/main/resources/mapper/commodity/StoreMapper.xml @@ -18,11 +18,10 @@ + - - select store_id, store_name, @@ -37,7 +36,8 @@ create_time, update_by, update_time, - remark + remark, + status from mall_store @@ -61,6 +61,13 @@ limit 1 + + + + insert into mall_store ( @@ -74,6 +81,7 @@ store_manager, create_by, remark, + status, create_time )values( #{storeName}, @@ -86,6 +94,7 @@ #{storeManager}, #{createBy}, #{remark}, + #{status}, sysdate() ) @@ -112,11 +121,18 @@ store_manager = #{storeManager}, update_by = #{updateBy}, remark = #{remark}, + status = #{status}, update_time = sysdate() where store_id = #{storeId} + + update mall_store + set status = #{status} + where store_id = #{storeId} + + update mall_store set del_flag = '2' diff --git a/ruoyi-mall/src/main/resources/mapper/commodity/UserStoreMapper.xml b/ruoyi-mall/src/main/resources/mapper/commodity/UserStoreMapper.xml index e339f680..f4458d66 100644 --- a/ruoyi-mall/src/main/resources/mapper/commodity/UserStoreMapper.xml +++ b/ruoyi-mall/src/main/resources/mapper/commodity/UserStoreMapper.xml @@ -13,6 +13,12 @@ + + + + + + + + \ No newline at end of file