9 changed files with 777 additions and 0 deletions
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
package com.ruoyi.web.controller.gss; |
||||
|
||||
import java.util.List; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.PutMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import com.ruoyi.common.annotation.Log; |
||||
import com.ruoyi.common.constant.UserConstants; |
||||
import com.ruoyi.common.core.controller.BaseController; |
||||
import com.ruoyi.common.core.domain.AjaxResult; |
||||
import com.ruoyi.common.core.domain.entity.SysDept; |
||||
import com.ruoyi.common.enums.BusinessType; |
||||
import com.ruoyi.common.utils.StringUtils; |
||||
import com.ruoyi.gss.domain.ProductCategory; |
||||
import com.ruoyi.gss.service.IProductCategoryService; |
||||
|
||||
@RestController |
||||
@RequestMapping("/gss/category") |
||||
public class ProductCategoryController extends BaseController |
||||
{ |
||||
@Autowired |
||||
private IProductCategoryService productCategoryService; |
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:list')") |
||||
@GetMapping("/list") |
||||
public AjaxResult list(ProductCategory productCategory) |
||||
{ |
||||
List<ProductCategory> list = productCategoryService.selectProductCategoryList(productCategory); |
||||
return success(productCategoryService.buildProductCategoryTree(list)); |
||||
} |
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:query')") |
||||
@GetMapping(value = "/{categoryId}") |
||||
public AjaxResult getInfo(@PathVariable Long categoryId) |
||||
{ |
||||
return success(productCategoryService.selectProductCategoryById(categoryId)); |
||||
} |
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:query')") |
||||
@GetMapping(value = "/children/{categoryId}") |
||||
public AjaxResult getChildren(@PathVariable Long categoryId) |
||||
{ |
||||
List<ProductCategory> list = productCategoryService.selectChildrenProductCategoryById(categoryId); |
||||
return success(productCategoryService.buildProductCategoryTree(list)); |
||||
} |
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:query')") |
||||
@GetMapping(value = "/parent/{categoryId}") |
||||
public AjaxResult getParent(@PathVariable Long categoryId) |
||||
{ |
||||
return success(productCategoryService.selectParentProductCategoryById(categoryId)); |
||||
} |
||||
|
||||
// @PreAuthorize("@ss.hasPermi('gss:category:add')")
|
||||
// @Log(title = "产品分类管理", businessType = BusinessType.INSERT)
|
||||
// @PostMapping
|
||||
// public AjaxResult add(@Validated @RequestBody ProductCategory productCategory)
|
||||
// {
|
||||
// if (StringUtils.isNotEmpty(productCategory.getCategoryCode())
|
||||
// && UserConstants.NOT_UNIQUE.equals(productCategoryService.checkProductCategoryCodeUnique(productCategory)))
|
||||
// {
|
||||
// return error("新增产品分类'" + productCategory.getCategoryName() + "'失败,分类编码已存在");
|
||||
// }
|
||||
// return toAjax(productCategoryService.insertProductCategory(productCategory));
|
||||
// }
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:edit')") |
||||
@Log(title = "产品分类管理", businessType = BusinessType.UPDATE) |
||||
@PutMapping |
||||
public AjaxResult edit(@Validated @RequestBody ProductCategory productCategory) |
||||
{ |
||||
// todo相关类型验证 目前没有新新增方法
|
||||
// if (StringUtils.isNotEmpty(productCategory.getCategoryCode())
|
||||
// && UserConstants.NOT_UNIQUE.equals(productCategoryService.checkProductCategoryCodeUnique(productCategory)))
|
||||
// {
|
||||
// return error("修改产品分类'" + productCategory.getCategoryName() + "'失败,分类编码已存在");
|
||||
// }
|
||||
// else if (productCategory.getParentId().equals(productCategory.getCategoryId()))
|
||||
// {
|
||||
// return error("修改产品分类'" + productCategory.getCategoryName() + "'失败,上级分类不能是自己");
|
||||
// }
|
||||
return toAjax(productCategoryService.updateProductCategory(productCategory)); |
||||
} |
||||
|
||||
@PreAuthorize("@ss.hasPermi('gss:category:remove')") |
||||
@Log(title = "产品分类管理", businessType = BusinessType.DELETE) |
||||
@DeleteMapping("/{categoryIds}") |
||||
public AjaxResult remove(@PathVariable Long[] categoryIds) |
||||
{ |
||||
return toAjax(productCategoryService.deleteProductCategoryByIds(categoryIds)); |
||||
} |
||||
} |
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
package com.ruoyi.gss.domain; |
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
import org.apache.commons.lang3.builder.ToStringStyle; |
||||
import com.ruoyi.common.annotation.Excel; |
||||
import com.ruoyi.common.core.domain.TreeEntity; |
||||
|
||||
public class ProductCategory extends TreeEntity |
||||
{ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** 分类ID */ |
||||
private Long categoryId; |
||||
|
||||
/** 分类编码 */ |
||||
@Excel(name = "分类编码") |
||||
private String categoryCode; |
||||
|
||||
/** 分类名称 */ |
||||
@Excel(name = "分类名称") |
||||
private String categoryName; |
||||
|
||||
/** 分类英文名称 */ |
||||
@Excel(name = "分类英文名称") |
||||
private String categoryNameEn; |
||||
|
||||
/** 分类级别(1大类 2中类 3小类) */ |
||||
@Excel(name = "分类级别", readConverterExp = "1=大类,2=中类,3=小类") |
||||
private String categoryLevel; |
||||
|
||||
/** 状态(0正常 1停用) */ |
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用") |
||||
private String status; |
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */ |
||||
private String delFlag; |
||||
|
||||
public Long getCategoryId() { |
||||
return categoryId; |
||||
} |
||||
|
||||
public void setCategoryId(Long categoryId) { |
||||
this.categoryId = categoryId; |
||||
} |
||||
|
||||
public String getCategoryCode() { |
||||
return categoryCode; |
||||
} |
||||
|
||||
public void setCategoryCode(String categoryCode) { |
||||
this.categoryCode = categoryCode; |
||||
} |
||||
|
||||
public String getCategoryName() { |
||||
return categoryName; |
||||
} |
||||
|
||||
public void setCategoryName(String categoryName) { |
||||
this.categoryName = categoryName; |
||||
} |
||||
|
||||
public String getCategoryNameEn() { |
||||
return categoryNameEn; |
||||
} |
||||
|
||||
public void setCategoryNameEn(String categoryNameEn) { |
||||
this.categoryNameEn = categoryNameEn; |
||||
} |
||||
|
||||
public String getCategoryLevel() { |
||||
return categoryLevel; |
||||
} |
||||
|
||||
public void setCategoryLevel(String categoryLevel) { |
||||
this.categoryLevel = categoryLevel; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getDelFlag() { |
||||
return delFlag; |
||||
} |
||||
|
||||
public void setDelFlag(String delFlag) { |
||||
this.delFlag = delFlag; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
||||
.append("categoryId", getCategoryId()) |
||||
.append("categoryCode", getCategoryCode()) |
||||
.append("categoryName", getCategoryName()) |
||||
.append("categoryNameEn", getCategoryNameEn()) |
||||
.append("parentId", getParentId()) |
||||
.append("ancestors", getAncestors()) |
||||
.append("categoryLevel", getCategoryLevel()) |
||||
.append("orderNum", getOrderNum()) |
||||
.append("status", getStatus()) |
||||
.append("delFlag", getDelFlag()) |
||||
.append("createBy", getCreateBy()) |
||||
.append("createTime", getCreateTime()) |
||||
.append("updateBy", getUpdateBy()) |
||||
.append("updateTime", getUpdateTime()) |
||||
.append("remark", getRemark()) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
package com.ruoyi.gss.mapper; |
||||
|
||||
import java.util.List; |
||||
import com.ruoyi.gss.domain.ProductCategory; |
||||
|
||||
public interface ProductCategoryMapper |
||||
{ |
||||
/** |
||||
* 查询产品分类 |
||||
*/ |
||||
public ProductCategory selectProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 查询产品分类列表 |
||||
*/ |
||||
public List<ProductCategory> selectProductCategoryList(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 查询产品分类树列表 |
||||
*/ |
||||
public List<ProductCategory> selectProductCategoryTreeList(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 根据ID查询所有子产品分类 |
||||
*/ |
||||
public List<ProductCategory> selectChildrenProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 根据ID查询所有父产品分类 |
||||
*/ |
||||
public List<ProductCategory> selectParentProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 是否存在子节点 |
||||
*/ |
||||
public int hasChildByProductCategoryId(Long categoryId); |
||||
|
||||
/** |
||||
* 新增产品分类 |
||||
*/ |
||||
public int insertProductCategory(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 修改产品分类 |
||||
*/ |
||||
public int updateProductCategory(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 修改子元素关系 |
||||
*/ |
||||
public int updateProductCategoryChildren(List<ProductCategory> children); |
||||
|
||||
/** |
||||
* 删除产品分类 |
||||
*/ |
||||
public int deleteProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 批量删除产品分类 |
||||
*/ |
||||
public int deleteProductCategoryByIds(Long[] categoryIds); |
||||
|
||||
/** |
||||
* 校验分类编码是否唯一 |
||||
* |
||||
* @param categoryCode 分类编码 |
||||
* @return 结果 |
||||
*/ |
||||
public ProductCategory checkProductCategoryCodeUnique(String categoryCode); |
||||
} |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
package com.ruoyi.gss.service; |
||||
|
||||
import java.util.List; |
||||
import com.ruoyi.gss.domain.ProductCategory; |
||||
|
||||
public interface IProductCategoryService |
||||
{ |
||||
/** |
||||
* 查询产品分类 |
||||
*/ |
||||
public ProductCategory selectProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 查询产品分类列表 |
||||
*/ |
||||
public List<ProductCategory> selectProductCategoryList(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 构建前端所需要树结构 |
||||
*/ |
||||
public List<ProductCategory> buildProductCategoryTree(List<ProductCategory> categories); |
||||
|
||||
/** |
||||
* 根据ID查询所有子产品分类 |
||||
*/ |
||||
public List<ProductCategory> selectChildrenProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 根据ID查询所有父产品分类 |
||||
*/ |
||||
public List<ProductCategory> selectParentProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 新增产品分类 |
||||
*/ |
||||
public int insertProductCategory(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 修改产品分类 |
||||
*/ |
||||
public int updateProductCategory(ProductCategory productCategory); |
||||
|
||||
/** |
||||
* 删除产品分类信息 |
||||
*/ |
||||
public int deleteProductCategoryById(Long categoryId); |
||||
|
||||
/** |
||||
* 批量删除产品分类信息 |
||||
*/ |
||||
public int deleteProductCategoryByIds(Long[] categoryIds); |
||||
|
||||
/** |
||||
* 校验分类编码是否唯一 |
||||
* |
||||
* @param productCategory 产品分类信息 |
||||
* @return 结果 |
||||
*/ |
||||
public String checkProductCategoryCodeUnique(ProductCategory productCategory); |
||||
} |
@ -0,0 +1,215 @@
@@ -0,0 +1,215 @@
|
||||
package com.ruoyi.gss.service.impl; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import com.ruoyi.common.core.domain.TreeSelect; |
||||
import com.ruoyi.common.core.text.Convert; |
||||
import com.ruoyi.common.utils.StringUtils; |
||||
import com.ruoyi.gss.mapper.ProductCategoryMapper; |
||||
import com.ruoyi.gss.domain.ProductCategory; |
||||
import com.ruoyi.gss.service.IProductCategoryService; |
||||
import com.ruoyi.common.constant.UserConstants; |
||||
|
||||
@Service |
||||
public class ProductCategoryServiceImpl implements IProductCategoryService |
||||
{ |
||||
@Autowired |
||||
private ProductCategoryMapper productCategoryMapper; |
||||
|
||||
@Override |
||||
public ProductCategory selectProductCategoryById(Long categoryId) |
||||
{ |
||||
return productCategoryMapper.selectProductCategoryById(categoryId); |
||||
} |
||||
|
||||
@Override |
||||
public List<ProductCategory> selectProductCategoryList(ProductCategory productCategory) |
||||
{ |
||||
return productCategoryMapper.selectProductCategoryList(productCategory); |
||||
} |
||||
|
||||
@Override |
||||
public List<ProductCategory> buildProductCategoryTree(List<ProductCategory> categories) |
||||
{ |
||||
List<ProductCategory> returnList = new ArrayList<ProductCategory>(); |
||||
List<Long> tempList = new ArrayList<Long>(); |
||||
for (ProductCategory category : categories) |
||||
{ |
||||
tempList.add(category.getCategoryId()); |
||||
} |
||||
for (Iterator<ProductCategory> iterator = categories.iterator(); iterator.hasNext();) |
||||
{ |
||||
ProductCategory category = (ProductCategory) iterator.next(); |
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.contains(category.getParentId())) |
||||
{ |
||||
recursionFn(categories, category); |
||||
returnList.add(category); |
||||
} |
||||
} |
||||
if (returnList.isEmpty()) |
||||
{ |
||||
returnList = categories; |
||||
} |
||||
return returnList; |
||||
} |
||||
|
||||
@Override |
||||
public List<ProductCategory> selectChildrenProductCategoryById(Long categoryId) |
||||
{ |
||||
return productCategoryMapper.selectChildrenProductCategoryById(categoryId); |
||||
} |
||||
|
||||
@Override |
||||
public List<ProductCategory> selectParentProductCategoryById(Long categoryId) |
||||
{ |
||||
return productCategoryMapper.selectParentProductCategoryById(categoryId); |
||||
} |
||||
|
||||
@Override |
||||
public int insertProductCategory(ProductCategory productCategory) |
||||
{ |
||||
ProductCategory info = productCategoryMapper.selectProductCategoryById(productCategory.getParentId()); |
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
if (StringUtils.isNotNull(info) && !info.getStatus().equals("0")) |
||||
{ |
||||
throw new RuntimeException("父分类停用,不允许新增"); |
||||
} |
||||
productCategory.setAncestors(info.getAncestors() + "," + productCategory.getParentId()); |
||||
return productCategoryMapper.insertProductCategory(productCategory); |
||||
} |
||||
|
||||
@Override |
||||
public int updateProductCategory(ProductCategory productCategory) |
||||
{ |
||||
ProductCategory newParentCategory = productCategoryMapper.selectProductCategoryById(productCategory.getParentId()); |
||||
ProductCategory oldCategory = productCategoryMapper.selectProductCategoryById(productCategory.getCategoryId()); |
||||
if (StringUtils.isNotNull(newParentCategory) && StringUtils.isNotNull(oldCategory)) |
||||
{ |
||||
String newAncestors = newParentCategory.getAncestors() + "," + newParentCategory.getCategoryId(); |
||||
String oldAncestors = oldCategory.getAncestors(); |
||||
productCategory.setAncestors(newAncestors); |
||||
updateProductCategoryChildren(productCategory.getCategoryId(), newAncestors, oldAncestors); |
||||
} |
||||
int result = productCategoryMapper.updateProductCategory(productCategory); |
||||
if (StringUtils.isNotNull(oldCategory) && "1".equals(productCategory.getStatus()) |
||||
&& StringUtils.equals(oldCategory.getStatus(), "0")) |
||||
{ |
||||
// 如果当前节点被停用,则将所有子节点停用
|
||||
updateProductCategoryStatus(productCategory); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public int deleteProductCategoryById(Long categoryId) |
||||
{ |
||||
return productCategoryMapper.deleteProductCategoryById(categoryId); |
||||
} |
||||
|
||||
@Override |
||||
public int deleteProductCategoryByIds(Long[] categoryIds) |
||||
{ |
||||
return productCategoryMapper.deleteProductCategoryByIds(categoryIds); |
||||
} |
||||
|
||||
/** |
||||
* 递归列表 |
||||
*/ |
||||
private void recursionFn(List<ProductCategory> list, ProductCategory t) |
||||
{ |
||||
// 得到子节点列表
|
||||
List<ProductCategory> childList = getChildList(list, t); |
||||
t.setChildren(childList); |
||||
for (ProductCategory tChild : childList) |
||||
{ |
||||
if (hasChild(list, tChild)) |
||||
{ |
||||
recursionFn(list, tChild); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 得到子节点列表 |
||||
*/ |
||||
private List<ProductCategory> getChildList(List<ProductCategory> list, ProductCategory t) |
||||
{ |
||||
List<ProductCategory> tlist = new ArrayList<ProductCategory>(); |
||||
Iterator<ProductCategory> it = list.iterator(); |
||||
while (it.hasNext()) |
||||
{ |
||||
ProductCategory n = (ProductCategory) it.next(); |
||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getCategoryId().longValue()) |
||||
{ |
||||
tlist.add(n); |
||||
} |
||||
} |
||||
return tlist; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否有子节点 |
||||
*/ |
||||
private boolean hasChild(List<ProductCategory> list, ProductCategory t) |
||||
{ |
||||
return getChildList(list, t).size() > 0; |
||||
} |
||||
|
||||
/** |
||||
* 修改子元素关系 |
||||
*/ |
||||
private void updateProductCategoryChildren(Long categoryId, String newAncestors, String oldAncestors) |
||||
{ |
||||
List<ProductCategory> children = productCategoryMapper.selectChildrenProductCategoryById(categoryId); |
||||
for (ProductCategory child : children) |
||||
{ |
||||
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); |
||||
} |
||||
if (children.size() > 0) |
||||
{ |
||||
productCategoryMapper.updateProductCategoryChildren(children); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 修改子元素状态 |
||||
*/ |
||||
private void updateProductCategoryStatus(ProductCategory category) |
||||
{ |
||||
List<ProductCategory> children = productCategoryMapper.selectChildrenProductCategoryById(category.getCategoryId()); |
||||
for (ProductCategory child : children) |
||||
{ |
||||
child.setStatus(category.getStatus()); |
||||
productCategoryMapper.updateProductCategory(child); |
||||
} |
||||
} |
||||
|
||||
// todo相关类型验证 目前没有新新增方法
|
||||
// /**
|
||||
// * 校验产品分类编码是否唯一
|
||||
// *
|
||||
// * @param productCategory 产品分类信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// @Override
|
||||
public String checkProductCategoryCodeUnique(ProductCategory productCategory) |
||||
{ |
||||
// 如果分类ID为空则设置为-1
|
||||
Long categoryId = StringUtils.isNull(productCategory.getCategoryId()) ? -1L : productCategory.getCategoryId(); |
||||
// 根据分类编码查询数据库中是否存在相同编码的分类
|
||||
ProductCategory info = productCategoryMapper.checkProductCategoryCodeUnique(productCategory.getCategoryCode()); |
||||
// 如果存在相同编码且不是当前编辑的分类,则返回不唯一标识
|
||||
// if (StringUtils.isNotNull(info) && info.getCategoryId().longValue() != categoryId.longValue())
|
||||
// {
|
||||
// return UserConstants.NOT_UNIQUE;
|
||||
// }
|
||||
// // 返回唯一标识
|
||||
// return UserConstants.UNIQUE;
|
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,154 @@
@@ -0,0 +1,154 @@
|
||||
<?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.gss.mapper.ProductCategoryMapper"> |
||||
|
||||
<resultMap type="ProductCategory" id="ProductCategoryResult"> |
||||
<id property="categoryId" column="category_id" /> |
||||
<result property="categoryCode" column="category_code" /> |
||||
<result property="categoryName" column="category_name" /> |
||||
<result property="categoryNameEn" column="category_name_en" /> |
||||
<result property="parentId" column="parent_id" /> |
||||
<result property="ancestors" column="ancestors" /> |
||||
<result property="categoryLevel" column="category_level" /> |
||||
<result property="orderNum" column="order_num" /> |
||||
<result property="status" column="status" /> |
||||
<result property="delFlag" column="del_flag" /> |
||||
<result property="createBy" column="create_by" /> |
||||
<result property="createTime" column="create_time" /> |
||||
<result property="updateBy" column="update_by" /> |
||||
<result property="updateTime" column="update_time" /> |
||||
<result property="remark" column="remark" /> |
||||
</resultMap> |
||||
|
||||
<!-- 修改基础查询SQL --> |
||||
<sql id="selectProductCategoryVo"> |
||||
select category_id, category_name, category_code, parent_id, ancestors, |
||||
category_level, order_num, status, del_flag, create_by, create_time, update_by, update_time, remark |
||||
from dhc_product_category |
||||
</sql> |
||||
|
||||
<select id="selectProductCategoryList" parameterType="ProductCategory" resultMap="ProductCategoryResult"> |
||||
<include refid="selectProductCategoryVo"/> |
||||
where del_flag = '0' |
||||
<if test="categoryCode != null and categoryCode != ''"> |
||||
AND category_code like concat('%', #{categoryCode}, '%') |
||||
</if> |
||||
<if test="categoryName != null and categoryName != ''"> |
||||
AND category_name like concat('%', #{categoryName}, '%') |
||||
</if> |
||||
<if test="categoryLevel != null and categoryLevel != ''"> |
||||
AND category_level = #{categoryLevel} |
||||
</if> |
||||
<if test="status != null and status != ''"> |
||||
AND status = #{status} |
||||
</if> |
||||
order by parent_id, order_num |
||||
</select> |
||||
|
||||
<select id="selectProductCategoryById" parameterType="Long" resultMap="ProductCategoryResult"> |
||||
<include refid="selectProductCategoryVo"/> |
||||
where category_id = #{categoryId} |
||||
</select> |
||||
|
||||
<select id="selectChildrenProductCategoryById" parameterType="Long" resultMap="ProductCategoryResult"> |
||||
<include refid="selectProductCategoryVo"/> |
||||
where find_in_set(#{categoryId}, ancestors) |
||||
</select> |
||||
|
||||
<select id="selectParentProductCategoryById" parameterType="Long" resultMap="ProductCategoryResult"> |
||||
<include refid="selectProductCategoryVo"/> |
||||
where category_id in ( |
||||
select regexp_substr(ancestors, '[^,]+', 1, level) |
||||
from ( |
||||
select ancestors |
||||
from dhc_product_category |
||||
where category_id = #{categoryId} |
||||
) t, |
||||
(select @rownum:=0) r |
||||
where level <= (length(ancestors) - length(replace(ancestors, ',', '')) + 1) |
||||
) |
||||
</select> |
||||
|
||||
<select id="hasChildByProductCategoryId" parameterType="Long" resultType="Integer"> |
||||
select count(1) from dhc_product_category |
||||
where parent_id = #{categoryId} limit 1 |
||||
</select> |
||||
|
||||
<insert id="insertProductCategory" parameterType="ProductCategory"> |
||||
insert into dhc_product_category( |
||||
<if test="categoryId != null">category_id,</if> |
||||
<if test="categoryCode != null">category_code,</if> |
||||
<if test="categoryName != null">category_name,</if> |
||||
<if test="categoryNameEn != null">category_name_en,</if> |
||||
<if test="parentId != null">parent_id,</if> |
||||
<if test="ancestors != null">ancestors,</if> |
||||
<if test="categoryLevel != null">category_level,</if> |
||||
<if test="orderNum != null">order_num,</if> |
||||
<if test="status != null">status,</if> |
||||
<if test="createBy != null">create_by,</if> |
||||
create_time |
||||
)values( |
||||
<if test="categoryId != null">#{categoryId},</if> |
||||
<if test="categoryCode != null">#{categoryCode},</if> |
||||
<if test="categoryName != null">#{categoryName},</if> |
||||
<if test="categoryNameEn != null">#{categoryNameEn},</if> |
||||
<if test="parentId != null">#{parentId},</if> |
||||
<if test="ancestors != null">#{ancestors},</if> |
||||
<if test="categoryLevel != null">#{categoryLevel},</if> |
||||
<if test="orderNum != null">#{orderNum},</if> |
||||
<if test="status != null">#{status},</if> |
||||
<if test="createBy != null">#{createBy},</if> |
||||
sysdate() |
||||
) |
||||
</insert> |
||||
|
||||
<update id="updateProductCategory" parameterType="ProductCategory"> |
||||
update dhc_product_category |
||||
<set> |
||||
<if test="categoryCode != null">category_code = #{categoryCode},</if> |
||||
<if test="categoryName != null">category_name = #{categoryName},</if> |
||||
<if test="categoryNameEn != null">category_name_en = #{categoryNameEn},</if> |
||||
<if test="parentId != null">parent_id = #{parentId},</if> |
||||
<if test="ancestors != null">ancestors = #{ancestors},</if> |
||||
<if test="categoryLevel != null">category_level = #{categoryLevel},</if> |
||||
<if test="orderNum != null">order_num = #{orderNum},</if> |
||||
<if test="status != null">status = #{status},</if> |
||||
<if test="updateBy != null">update_by = #{updateBy},</if> |
||||
update_time = sysdate() |
||||
</set> |
||||
where category_id = #{categoryId} |
||||
</update> |
||||
|
||||
<update id="updateProductCategoryChildren" parameterType="java.util.List"> |
||||
update dhc_product_category set ancestors = |
||||
<foreach collection="list" item="item" index="index" |
||||
separator=" " open="case category_id" close="end"> |
||||
when #{item.categoryId} then #{item.ancestors} |
||||
</foreach> |
||||
where category_id in |
||||
<foreach collection="list" item="item" index="index" |
||||
separator="," open="(" close=")"> |
||||
#{item.categoryId} |
||||
</foreach> |
||||
</update> |
||||
|
||||
<delete id="deleteProductCategoryById" parameterType="Long"> |
||||
update dhc_product_category set del_flag = '2' where category_id = #{categoryId} |
||||
</delete> |
||||
|
||||
<delete id="deleteProductCategoryByIds" parameterType="Long"> |
||||
update dhc_product_category set del_flag = '2' where category_id in |
||||
<foreach item="categoryId" collection="array" open="(" separator="," close=")"> |
||||
#{categoryId} |
||||
</foreach> |
||||
</delete> |
||||
|
||||
<!-- 修改校验分类编码唯一性查询 --> |
||||
<select id="checkProductCategoryCodeUnique" parameterType="String" resultMap="ProductCategoryResult"> |
||||
select category_id, category_name, category_code, parent_id, ancestors, status |
||||
from dhc_product_category |
||||
where category_code = #{categoryCode} limit 1 |
||||
</select> |
||||
</mapper> |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
CREATE TABLE `dhc_product_category` ( |
||||
`category_id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类ID', |
||||
`category_code` varchar(10) COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类编码', |
||||
`category_name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类名称', |
||||
`category_name_en` varchar(200) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '分类英文名称', |
||||
`parent_id` bigint DEFAULT '0' COMMENT '父分类ID', |
||||
`ancestors` varchar(500) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '祖级列表', |
||||
`category_level` char(1) COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类级别(1大类 2中类 3小类)', |
||||
`order_num` int DEFAULT '0' COMMENT '显示顺序', |
||||
`status` char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '状态(0正常 1停用)', |
||||
`del_flag` char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)', |
||||
`create_by` varchar(64) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者', |
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间', |
||||
`update_by` varchar(64) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者', |
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间', |
||||
`remark` varchar(500) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', |
||||
PRIMARY KEY (`category_id`) |
||||
) ENGINE=InnoDB AUTO_INCREMENT=211 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='产品分类表'; |
||||
|
||||
|
||||
--------------------------------------------------------------------------------------------------------- |
||||
-- 菜单与权限 |
||||
-- 菜单 SQL |
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) |
||||
values('产品分类管理', '3', '1', 'category', 'gss/category/index', 1, 0, 'C', '0', '0', 'gss:category:list', 'tree', 'admin', sysdate(), '', null, '产品分类管理菜单'); |
||||
|
||||
-- 按钮父菜单ID |
||||
SELECT @parentId := LAST_INSERT_ID(); |
||||
|
||||
-- 按钮 SQL |
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) |
||||
values('产品分类查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', 'gss:category:query', '#', 'admin', sysdate(), '', null, ''); |
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) |
||||
values('产品分类新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', 'gss:category:add', '#', 'admin', sysdate(), '', null, ''); |
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) |
||||
values('产品分类修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', 'gss:category:edit', '#', 'admin', sysdate(), '', null, ''); |
||||
|
||||
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) |
||||
values('产品分类删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', 'gss:category:remove', '#', 'admin', sysdate(), '', null, ''); |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
-- ---------------------------- |
||||
-- by AI |
||||
-- ---------------------------- |
||||
|
||||
-- 创建销售区域表 |
||||
CREATE TABLE `sales_region` ( |
||||
`region_id` bigint NOT NULL AUTO_INCREMENT COMMENT '销售区域ID', |
||||
`region_name` varchar(100) NOT NULL COMMENT '销售区域名称', |
||||
`country_id` int NOT NULL COMMENT '国家ID', |
||||
`user_id` bigint NOT NULL COMMENT '负责用户ID', |
||||
`status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', |
||||
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)', |
||||
`create_by` varchar(64) DEFAULT '' COMMENT '创建者', |
||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间', |
||||
`update_by` varchar(64) DEFAULT '' COMMENT '更新者', |
||||
`update_time` datetime DEFAULT NULL COMMENT '更新时间', |
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注', |
||||
PRIMARY KEY (`region_id`), |
||||
KEY `idx_country_id` (`country_id`), |
||||
KEY `idx_user_id` (`user_id`), |
||||
CONSTRAINT `fk_sales_region_country` FOREIGN KEY (`country_id`) REFERENCES `iso3166_country` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, |
||||
CONSTRAINT `fk_sales_region_user` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`user_id`) ON DELETE RESTRICT ON UPDATE RESTRICT |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='销售区域表'; |
Loading…
Reference in new issue