商品品牌,商品分类

master
miaoqingshuai 2026-01-22 14:28:30 +08:00
parent 4dfa2301df
commit b78ad98b8c
23 changed files with 609 additions and 80 deletions

View File

@ -8,10 +8,14 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Brand; import com.ruoyi.web.domain.Brand;
import com.ruoyi.web.service.BrandService; import com.ruoyi.web.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
/**
*
*/
@RestController @RestController
@RequestMapping("/mall/brand") @RequestMapping("/mall/brand")
public class BrandController extends BaseController { public class BrandController extends BaseController {
@ -25,9 +29,9 @@ public class BrandController extends BaseController {
* @return * @return
*/ */
@Anonymous @Anonymous
@GetMapping("/tree") @GetMapping(value = "/getTree/{storeId}")
public AjaxResult getBrandTree() { public AjaxResult getBrandTree(@PathVariable String storeId) {
return AjaxResult.success(brandService.getBrandTree()); return AjaxResult.success(brandService.getBrandTree(storeId));
} }
/** /**
@ -40,6 +44,10 @@ public class BrandController extends BaseController {
@Log(title = "商品品牌管理", businessType = BusinessType.INSERT) @Log(title = "商品品牌管理", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
public AjaxResult addBrand(@RequestBody Brand brand) { public AjaxResult addBrand(@RequestBody Brand brand) {
if (!brandService.checkBrandUnique(brand)) {
return error("新增商品品牌'" + brand.getBrandName() + "'失败,商品品牌名称已存在");
}
brand.setCreateBy(getUsername()); brand.setCreateBy(getUsername());
return toAjax(brandService.addBrand(brand)); return toAjax(brandService.addBrand(brand));
} }
@ -54,13 +62,21 @@ public class BrandController extends BaseController {
@Log(title = "商品品牌管理", businessType = BusinessType.UPDATE) @Log(title = "商品品牌管理", businessType = BusinessType.UPDATE)
@PostMapping("/update") @PostMapping("/update")
public AjaxResult updateBrand(@RequestBody Brand brand) { public AjaxResult updateBrand(@RequestBody Brand brand) {
if (!brandService.checkBrandUnique(brand)) {
return error("修改商品品牌'" + brand.getBrandName() + "'失败,商品品牌名称已存在");
}
return toAjax(brandService.updateBrand(brand)); return toAjax(brandService.updateBrand(brand));
} }
// 删除品牌 /**
*
*
* @param id
* @return
*/
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public String deleteBrand(@PathVariable Long id) { @Log(title = "商品品牌管理", businessType = BusinessType.DELETE)
brandService.deleteBrand(id); public AjaxResult deleteBrand(@PathVariable Long id) {
return "success"; return toAjax(brandService.deleteBrand(id));
} }
} }

View File

@ -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));
}
}

View File

@ -67,7 +67,6 @@ public class ProductStoreController extends BaseController {
} }
/** /**
* *
*/ */
@ -75,14 +74,17 @@ public class ProductStoreController extends BaseController {
@Log(title = "商品管理", businessType = BusinessType.INSERT) @Log(title = "商品管理", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
public AjaxResult add(@Validated Product product, 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)) { if (!productService.checkProductCodeUnique(product)) {
return error("新增商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在"); return error("新增商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在");
} }
//todo 这里可以国码有的时候使用国码的图片路径
// TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的 // TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的
//国码后续添加 //国码后续添加
if (!file.isEmpty()) { if (file != null) {
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true); String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true);
if (StringUtils.isNotEmpty(avatar)) { if (StringUtils.isNotEmpty(avatar)) {
product.setMainImage(avatar); product.setMainImage(avatar);
@ -101,22 +103,22 @@ public class ProductStoreController extends BaseController {
@Log(title = "商品管理", businessType = BusinessType.UPDATE) @Log(title = "商品管理", businessType = BusinessType.UPDATE)
@PostMapping("/update") @PostMapping("/update")
public AjaxResult edit(@Validated Product product, 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)) { if (!productService.checkProductCodeUnique(product)) {
return error("修改商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在"); return error("修改商品条码'" + product.getProductBarCode() + "'失败,商品条码已存在");
} }
//todo 这里可以国码有的时候使用国码的图片路径
// TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的 // TODO: 2026/1/14 这个file 为空的时候 就使用国码里面的图片,不为空代表用户自己选择了图片上传 用自己服务器上的
//然后修改的时候 这个file不为空代表用户又修改了图片需要更新为空的话之前图片保持不变 //然后修改的时候 这个file不为空代表用户又修改了图片需要更新为空的话之前图片保持不变
if (!file.isEmpty()) { if (file != null) {
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true); String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION, true);
if (StringUtils.isNotEmpty(avatar)) { if (StringUtils.isNotEmpty(avatar)) {
product.setMainImage(avatar); product.setMainImage(avatar);
} }
} }
//todo 这里可以国码有的时候使用国码的图片路径
product.setUpdateBy(getUsername()); product.setUpdateBy(getUsername());
return toAjax(productService.updateProduct(product)); return toAjax(productService.updateProduct(product));
} }
@ -143,6 +145,6 @@ public class ProductStoreController extends BaseController {
@RequestParam("storeId") Integer storeId) throws Exception { @RequestParam("storeId") Integer storeId) throws Exception {
ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class); ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
List<Product> productList = util.importExcel(file.getInputStream()); List<Product> productList = util.importExcel(file.getInputStream());
return AjaxResult.success(productService.importProduct(productList,storeId)); return AjaxResult.success(productService.importProduct(productList, storeId));
} }
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.web.controller; package com.ruoyi.web.controller;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
@ -35,6 +36,15 @@ public class StoreController extends BaseController {
return getDataTable(list); 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)); 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 * id
*/ */
@Anonymous
// @PreAuthorize("@ss.hasPermi('product:query')") // @PreAuthorize("@ss.hasPermi('product:query')")
@GetMapping(value = "/getUserStore/{userId}") @GetMapping(value = "/getUserStore/{userId}")
public AjaxResult getUserStore(@PathVariable String userId) { public AjaxResult getUserStore(@PathVariable String userId) {

View File

@ -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<Classification> children;
}

View File

@ -55,6 +55,18 @@ public class Product extends BaseEntity {
@Excel(name = "商品条码") @Excel(name = "商品条码")
private String productBarCode; private String productBarCode;
/**
*
*/
private String productBrand;
/**
*
*/
private String classifcation;
/** /**
* *
*/ */

View File

@ -3,6 +3,8 @@ package com.ruoyi.web.domain;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Size;
/** /**
* mall_store * mall_store
@ -49,6 +51,7 @@ public class Store extends BaseEntity {
/** /**
* *
*/ */
@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
private String contactPhone; private String contactPhone;
/** /**
@ -56,4 +59,6 @@ public class Store extends BaseEntity {
*/ */
private String storeManager; private String storeManager;
private Integer status;
} }

View File

@ -1,56 +1,34 @@
package com.ruoyi.web.mapper; package com.ruoyi.web.mapper;
import com.ruoyi.web.domain.Brand; import com.ruoyi.web.domain.Brand;
import com.ruoyi.web.domain.Store;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@Mapper @Mapper
public interface BrandMapper { public interface BrandMapper {
/**
*
*/
List<Brand> selectAll(); List<Brand> selectAll();
/** List<Brand> selectRootBrands(String storeId);
* parentId=0
*/
List<Brand> selectRootBrands();
/**
* ID
*/
List<Brand> selectByParentId(@Param("parentId") Long parentId); List<Brand> selectByParentId(@Param("parentId") Long parentId);
/**
* ID
*/
Brand selectById(@Param("id") Long id); Brand selectById(@Param("id") Long id);
/**
*
*/
int insert(Brand brand); int insert(Brand brand);
/**
*
*/
int update(Brand brand); int update(Brand brand);
/**
*
*/
int delete(@Param("id") Long id); 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);
} }

View File

@ -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<Classification> selectRootBrands(String storeId);
List<Classification> 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);
}

View File

@ -2,6 +2,8 @@ package com.ruoyi.web.mapper;
import com.ruoyi.web.domain.Store; 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 org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -29,4 +31,9 @@ public interface StoreMapper
void deleteStoreUser(Long storeId); void deleteStoreUser(Long storeId);
Store selectStore(Long storeId);
int updateStatus(Store store);
} }

View File

@ -1,12 +1,17 @@
package com.ruoyi.web.mapper; package com.ruoyi.web.mapper;
import com.ruoyi.web.vo.StoreVo;
import com.ruoyi.web.vo.UserStoreVo; import com.ruoyi.web.vo.UserStoreVo;
import java.util.List;
/** /**
* *
*/ */
public interface UserStoreMapper { public interface UserStoreMapper {
UserStoreVo getUserStoreWithStores(String userId); UserStoreVo getUserStoreWithStores(String userId);
List<StoreVo> queryStore();
} }

View File

@ -7,7 +7,7 @@ import java.util.List;
public interface BrandService { public interface BrandService {
// 获取品牌树(一级品牌包含子品牌) // 获取品牌树(一级品牌包含子品牌)
List<Brand> getBrandTree(); List<Brand> getBrandTree(String storeId);
// 添加品牌 // 添加品牌
int addBrand(Brand brand); int addBrand(Brand brand);
@ -15,6 +15,7 @@ public interface BrandService {
int updateBrand(Brand brand); int updateBrand(Brand brand);
// 删除品牌 // 删除品牌
void deleteBrand(Long id); int deleteBrand(Long id);
boolean checkBrandUnique(Brand brand);
} }

View File

@ -0,0 +1,18 @@
package com.ruoyi.web.service;
import com.ruoyi.web.domain.Classification;
import java.util.List;
public interface ClassIficationService {
List<Classification> getIficationTree(String storeId);
int addClassification(Classification classification);
int updateClassification(Classification classification);
int deleteClassIfication(Long id);
boolean checkBrandUnique(Classification classification);
}

View File

@ -56,4 +56,8 @@ public interface StoreService {
int insertUserStores(Long userId, Long[] storeIds); int insertUserStores(Long userId, Long[] storeIds);
UserStoreVo getUserStore(String userId); UserStoreVo getUserStore(String userId);
Store selectStore(Long storeId);
int updateStatus(Store store);
} }

View File

@ -1,13 +1,20 @@
package com.ruoyi.web.service.impl; 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.Brand;
import com.ruoyi.web.domain.Classification;
import com.ruoyi.web.domain.Store;
import com.ruoyi.web.mapper.BrandMapper; import com.ruoyi.web.mapper.BrandMapper;
import com.ruoyi.web.service.BrandService; import com.ruoyi.web.service.BrandService;
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 org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class BrandServiceImpl implements BrandService { public class BrandServiceImpl implements BrandService {
@ -16,20 +23,43 @@ public class BrandServiceImpl implements BrandService {
private BrandMapper brandMapper; private BrandMapper brandMapper;
@Override @Override
public List<Brand> getBrandTree() { public List<Brand> getBrandTree(String storeId) {
// 1. 获取所有一级品牌 List<Brand> rootBrands = brandMapper.selectRootBrands(storeId);
List<Brand> rootBrands = brandMapper.selectRootBrands();
// 2. 为每个一级品牌设置子品牌 return buildTree(rootBrands);
for (Brand rootBrand : rootBrands) {
List<Brand> children = brandMapper.selectByParentId(rootBrand.getId()); }
rootBrand.setChildren(children);
private List<Brand> buildTree(List<Brand> allList) {
List<Brand> rootList = new ArrayList<>();
Map<Long, Brand> 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 @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public int addBrand(Brand brand) { public int addBrand(Brand brand) {
// 如果是二级品牌,检查父品牌是否存在 // 如果是二级品牌,检查父品牌是否存在
if (brand.getParentId() != null && brand.getParentId() != 0) { if (brand.getParentId() != null && brand.getParentId() != 0) {
@ -44,14 +74,30 @@ public class BrandServiceImpl implements BrandService {
} }
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public int updateBrand(Brand brand) { public int updateBrand(Brand brand) {
return brandMapper.update(brand); return brandMapper.update(brand);
} }
@Override @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;
}
} }

View File

@ -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<Classification> getIficationTree(String storeId) {
List<Classification> rootBrands = classIficationMapper.selectRootBrands(storeId);
// 构建树形结构
return buildTree(rootBrands);
}
/**
*
*/
private List<Classification> buildTree(List<Classification> allList) {
List<Classification> rootList = new ArrayList<>();
Map<Long, Classification> 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<Long> allDeleteIds = getAllChildIds(id);
allDeleteIds.add(id); // 包括自身
for (Long allDeleteId : allDeleteIds) {
classIficationMapper.delete(allDeleteId);
}
return 1;
}
/**
* ID
*/
private List<Long> getAllChildIds(Long parentId) {
List<Long> allChildIds = new ArrayList<>();
// 查询直接子节点
List<Classification> 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;
}
}

View File

@ -7,6 +7,7 @@ import com.ruoyi.web.domain.Store;
import com.ruoyi.web.mapper.StoreMapper; import com.ruoyi.web.mapper.StoreMapper;
import com.ruoyi.web.mapper.UserStoreMapper; import com.ruoyi.web.mapper.UserStoreMapper;
import com.ruoyi.web.service.StoreService; import com.ruoyi.web.service.StoreService;
import com.ruoyi.web.vo.StoreVo;
import com.ruoyi.web.vo.UserStoreVo; import com.ruoyi.web.vo.UserStoreVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -84,6 +85,27 @@ public class StoreServiceImpl implements StoreService {
@Override @Override
public UserStoreVo getUserStore(String userId) { public UserStoreVo getUserStore(String userId) {
return userStoreMapper.getUserStoreWithStores(userId);
UserStoreVo userStoreWithStores = userStoreMapper.getUserStoreWithStores(userId);
List<StoreVo> 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);
} }
} }

View File

@ -2,11 +2,12 @@ package com.ruoyi.web.vo;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Data @Data
public class UserStoreVo { public class UserStoreVo {
private List<StoreVo> allStores = new ArrayList<>(); //所有的门店
private Long userId; //用户id private Long userId; //用户id
private List<StoreVo> stores; // 门店对象列表 private List<StoreVo> stores; // 门店对象列表
} }

View File

@ -4,13 +4,13 @@
<mapper namespace="com.ruoyi.web.mapper.BrandMapper"> <mapper namespace="com.ruoyi.web.mapper.BrandMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.web.domain.Brand"> <resultMap id="BaseResultMap" type="com.ruoyi.web.domain.Brand">
<id property="id" column="id"/> <id property="id" column="id"/>
<result column="parent_id" property="parentId" /> <result column="parent_id" property="parentId"/>
<result column="brand_name" property="brandName" /> <result column="brand_name" property="brandName"/>
<result column="create_time" property="createTime" /> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime" /> <result column="update_time" property="updateTime"/>
<result column="create_by" property="createBy" /> <result column="create_by" property="createBy"/>
<result column="update_by" property="updateBy" /> <result column="update_by" property="updateBy"/>
<result column="store_id" property="storeId" /> <result column="store_id" property="storeId"/>
</resultMap> </resultMap>
@ -24,7 +24,7 @@
<select id="selectRootBrands" resultMap="BaseResultMap"> <select id="selectRootBrands" resultMap="BaseResultMap">
SELECT * SELECT *
FROM mall_brand FROM mall_brand
WHERE parent_id = 0 and del_flag = '0' WHERE del_flag = '0' and store_id = #{storeId}
</select> </select>
<!-- 根据父ID查询子品牌 --> <!-- 根据父ID查询子品牌 -->
@ -32,6 +32,7 @@
SELECT * SELECT *
FROM mall_brand FROM mall_brand
WHERE parent_id = #{parentId} WHERE parent_id = #{parentId}
and del_flag = '0'
</select> </select>
<!-- 根据ID查询品牌 --> <!-- 根据ID查询品牌 -->
@ -41,6 +42,15 @@
WHERE id = #{id} WHERE id = #{id}
</select> </select>
<select id="checkBrandUnique" resultType="com.ruoyi.web.domain.Store">
select * from mall_brand
where brand_name=#{brandName} and del_flag = '0' and store_id = #{storeId}
<if test="id != null">
AND id != #{id}
</if>
limit 1
</select>
<insert id="insert" parameterType="Brand"> <insert id="insert" parameterType="Brand">
insert into mall_brand ( insert into mall_brand (
@ -67,11 +77,16 @@
<!-- 删除品牌 --> <!-- 删除品牌 -->
<delete id="delete"> <delete id="delete">
DELETE update mall_brand
FROM brand set del_flag = '2'
WHERE id = #{id} where id = #{id}
</delete>
<delete id="batchBrand">
update mall_brand
set del_flag = '2'
where parent_id = #{id}
</delete> </delete>
</mapper> </mapper>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.mapper.ClassIficationMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.web.domain.Classification">
<id property="id" column="id"/>
<result column="parent_id" property="parentId"/>
<result column="classification_name" property="classificationName"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="create_by" property="createBy"/>
<result column="update_by" property="updateBy"/>
<result column="store_id" property="storeId"/>
</resultMap>
<select id="selectRootBrands" resultMap="BaseResultMap">
SELECT *
FROM mall_classification
where del_flag = '0' and store_id = #{storeId}
</select>
<select id="selectByParentId" resultMap="BaseResultMap">
SELECT *
FROM mall_classification
WHERE parent_id = #{parentId}
and del_flag = '0'
</select>
<select id="selectById" resultMap="BaseResultMap" parameterType="long">
SELECT id, parent_id, classification_name
FROM mall_classification
WHERE id = #{id}
</select>
<select id="checkBrandUnique" resultType="com.ruoyi.web.domain.Classification">
select * from mall_classification
where classification_name=#{classificationName} and del_flag = '0' and store_id = #{storeId}
<if test="id != null">
AND id != #{id}
</if>
limit 1
</select>
<insert id="insert" parameterType="Brand">
insert into mall_classification (
<if test="parentId != null">parent_id,</if>
<if test="classificationName != null and classificationName != ''">classification_name,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="storeId != null">store_id,</if>
create_time
)values(
<if test="parentId != null">#{parentId},</if>
<if test="classificationName != null and classificationName != ''">#{classificationName},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="storeId != null">#{storeId},</if>
sysdate()
)
</insert>
<update id="update">
UPDATE mall_classification
SET classification_name = #{classificationName}
WHERE id = #{id}
</update>
<delete id="delete">
update mall_classification
set del_flag = '2'
where id = #{id}
</delete>
<delete id="batchBrand">
update mall_classification
set del_flag = '2'
where parent_id = #{id}
</delete>
</mapper>

View File

@ -25,6 +25,8 @@
<result property="shelfLife" column="shelf_life"/> <result property="shelfLife" column="shelf_life"/>
<result property="approaching" column="approaching"/> <result property="approaching" column="approaching"/>
<result property="productionDate" column="production_date"/> <result property="productionDate" column="production_date"/>
<result property="productBrand" column="product_brand"/>
<result property="classifcation" column="classifcation"/>
</resultMap> </resultMap>
<sql id="selectCommodityVo"> <sql id="selectCommodityVo">
@ -48,7 +50,9 @@
shelf_code, shelf_code,
shelf_life, shelf_life,
production_date, production_date,
approaching approaching,
product_brand,
classifcation
from mall_product_store from mall_product_store
</sql> </sql>
@ -155,6 +159,8 @@
<if test="shelfLife != null">shelf_life = #{shelfLife},</if> <if test="shelfLife != null">shelf_life = #{shelfLife},</if>
<if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if> <if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if>
<if test="approaching != null">approaching = #{approaching},</if> <if test="approaching != null">approaching = #{approaching},</if>
<if test="productBrand != null and productBrand != ''">product_brand = #{productBrand},</if>
<if test="classifcation != null and classifcation != ''">classifcation = #{classifcation},</if>
update_time = sysdate() update_time = sysdate()
</set> </set>
where id = #{id} where id = #{id}
@ -179,6 +185,8 @@
<if test="shelfLife != null">shelf_life = #{shelfLife},</if> <if test="shelfLife != null">shelf_life = #{shelfLife},</if>
<if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if> <if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if>
<if test="approaching != null">approaching = #{approaching},</if> <if test="approaching != null">approaching = #{approaching},</if>
<if test="productBrand != null and productBrand != ''">product_brand = #{productBrand},</if>
<if test="classifcation != null and classifcation != ''">classifcation = #{classifcation},</if>
update_time = sysdate() update_time = sysdate()
</set> </set>
where product_bar_code = #{productBarCode} where product_bar_code = #{productBarCode}

View File

@ -18,11 +18,10 @@
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
<result property="status" column="status"/>
</resultMap> </resultMap>
<sql id="selectStoreVo"> <sql id="selectStoreVo">
select store_id, select store_id,
store_name, store_name,
@ -37,7 +36,8 @@
create_time, create_time,
update_by, update_by,
update_time, update_time,
remark remark,
status
from mall_store from mall_store
</sql> </sql>
@ -61,6 +61,13 @@
limit 1 limit 1
</select> </select>
<select id="selectStore" resultType="com.ruoyi.web.domain.Store">
<include refid="selectStoreVo"/>
where store_id=#{storeId} and del_flag = '0'
</select>
<insert id="insertStore" parameterType="Store"> <insert id="insertStore" parameterType="Store">
insert into mall_store ( insert into mall_store (
@ -74,6 +81,7 @@
<if test="storeManager != null and storeManager != '' ">store_manager,</if> <if test="storeManager != null and storeManager != '' ">store_manager,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if> <if test="remark != null and remark != ''">remark,</if>
<if test="status != null ">status,</if>
create_time create_time
)values( )values(
<if test="storeName != null and storeName != ''">#{storeName},</if> <if test="storeName != null and storeName != ''">#{storeName},</if>
@ -86,6 +94,7 @@
<if test="storeManager != null and storeManager != ''">#{storeManager},</if> <if test="storeManager != null and storeManager != ''">#{storeManager},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="remark != null and remark != ''">#{remark},</if>
<if test="status != null">#{status},</if>
sysdate() sysdate()
) )
</insert> </insert>
@ -112,11 +121,18 @@
<if test="storeManager != null and storeManager != ''">store_manager = #{storeManager},</if> <if test="storeManager != null and storeManager != ''">store_manager = #{storeManager},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="status != null">status = #{status},</if>
update_time = sysdate() update_time = sysdate()
</set> </set>
where store_id = #{storeId} where store_id = #{storeId}
</update> </update>
<update id="updateStatus">
update mall_store
set status = #{status}
where store_id = #{storeId}
</update>
<delete id="deleteStoreById"> <delete id="deleteStoreById">
update mall_store update mall_store
set del_flag = '2' set del_flag = '2'

View File

@ -13,6 +13,12 @@
</collection> </collection>
</resultMap> </resultMap>
<resultMap id="userStoresMap" type="com.ruoyi.web.vo.StoreVo">
<result property="storeName" column="store_name"/>
<result property="storeId" column="store_id"/>
<result property="storeCode" column="store_code"/>
</resultMap>
<select id="getUserStoreWithStores" resultMap="userStoreWithStoresMap"> <select id="getUserStoreWithStores" resultMap="userStoreWithStoresMap">
SELECT mus.user_id, SELECT mus.user_id,
s.store_id, s.store_id,
@ -23,5 +29,11 @@
WHERE mus.user_id = #{userId} WHERE mus.user_id = #{userId}
</select> </select>
<select id="queryStore" resultMap="userStoresMap">
select *
from mall_store
where del_flag = '0'
</select>
</mapper> </mapper>