youjianchi
1 year ago
9 changed files with 555 additions and 7 deletions
@ -0,0 +1,24 @@ |
|||||
|
package com.ruoyi.framework.web.service; |
||||
|
|
||||
|
import com.ruoyi.system.domain.SysCategory; |
||||
|
import com.ruoyi.system.service.ISysCategoryService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description thymeleaf调用得到分类字典 |
||||
|
* @Author youjianchi |
||||
|
* @Date 2023/11/17 15:00 |
||||
|
*/ |
||||
|
@Service("category") |
||||
|
public class CategoryService { |
||||
|
|
||||
|
@Autowired |
||||
|
private ISysCategoryService categoryService; |
||||
|
|
||||
|
public List<SysCategory> getChildByCode(String code){ |
||||
|
return categoryService.getChildByCode(code); |
||||
|
} |
||||
|
} |
@ -0,0 +1,123 @@ |
|||||
|
package com.ruoyi.system.domain; |
||||
|
|
||||
|
import com.ruoyi.common.annotation.Excel; |
||||
|
import com.ruoyi.common.core.domain.BaseEntity; |
||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 分类字典对象 sys_category |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
* @date 2023-11-17 |
||||
|
*/ |
||||
|
public class SysCategory extends BaseEntity |
||||
|
{ |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** 主键ID */ |
||||
|
private Long id; |
||||
|
|
||||
|
/** 删除标志(0代表存在 1代表删除) */ |
||||
|
private String delFlag; |
||||
|
|
||||
|
/** 父级id */ |
||||
|
@Excel(name = "父级id") |
||||
|
private Long parentId; |
||||
|
|
||||
|
/** 类型编码 */ |
||||
|
@Excel(name = "类型编码") |
||||
|
private String code; |
||||
|
|
||||
|
/** 类型名称 */ |
||||
|
@Excel(name = "类型名称") |
||||
|
private String name; |
||||
|
|
||||
|
/** 类型排序 */ |
||||
|
@Excel(name = "类型排序") |
||||
|
private Long sortOrder; |
||||
|
|
||||
|
private List<SysCategory> children; |
||||
|
|
||||
|
public void setId(Long id) |
||||
|
{ |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
public Long getId() |
||||
|
{ |
||||
|
return id; |
||||
|
} |
||||
|
public void setDelFlag(String delFlag) |
||||
|
{ |
||||
|
this.delFlag = delFlag; |
||||
|
} |
||||
|
|
||||
|
public String getDelFlag() |
||||
|
{ |
||||
|
return delFlag; |
||||
|
} |
||||
|
public void setParentId(Long parentId) |
||||
|
{ |
||||
|
this.parentId = parentId; |
||||
|
} |
||||
|
|
||||
|
public Long getParentId() |
||||
|
{ |
||||
|
return parentId; |
||||
|
} |
||||
|
public void setCode(String code) |
||||
|
{ |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public String getCode() |
||||
|
{ |
||||
|
return code; |
||||
|
} |
||||
|
public void setName(String name) |
||||
|
{ |
||||
|
this.name = name; |
||||
|
} |
||||
|
|
||||
|
public String getName() |
||||
|
{ |
||||
|
return name; |
||||
|
} |
||||
|
public void setSortOrder(Long sortOrder) |
||||
|
{ |
||||
|
this.sortOrder = sortOrder; |
||||
|
} |
||||
|
|
||||
|
public Long getSortOrder() |
||||
|
{ |
||||
|
return sortOrder; |
||||
|
} |
||||
|
|
||||
|
public List<SysCategory> getChildren() { |
||||
|
return children; |
||||
|
} |
||||
|
|
||||
|
public void setChildren(List<SysCategory> children) { |
||||
|
this.children = children; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() { |
||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
||||
|
.append("id", getId()) |
||||
|
.append("delFlag", getDelFlag()) |
||||
|
.append("createBy", getCreateBy()) |
||||
|
.append("createTime", getCreateTime()) |
||||
|
.append("updateBy", getUpdateBy()) |
||||
|
.append("updateTime", getUpdateTime()) |
||||
|
.append("remark", getRemark()) |
||||
|
.append("parentId", getParentId()) |
||||
|
.append("code", getCode()) |
||||
|
.append("name", getName()) |
||||
|
.append("sortOrder", getSortOrder()) |
||||
|
.toString(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
package com.ruoyi.system.mapper; |
||||
|
|
||||
|
import com.ruoyi.system.domain.SysCategory; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 分类字典Mapper接口 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
* @date 2023-11-17 |
||||
|
*/ |
||||
|
public interface SysCategoryMapper |
||||
|
{ |
||||
|
/** |
||||
|
* 查询分类字典 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 分类字典 |
||||
|
*/ |
||||
|
public SysCategory selectSysCategoryById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 查询分类字典列表 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 分类字典集合 |
||||
|
*/ |
||||
|
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 新增分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int insertSysCategory(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 修改分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int updateSysCategory(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 删除分类字典 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteSysCategoryById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除分类字典 |
||||
|
* |
||||
|
* @param ids 需要删除的数据ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteSysCategoryByIds(String[] ids); |
||||
|
|
||||
|
List<SysCategory> getChildByCode(String code); |
||||
|
|
||||
|
List<SysCategory> getChildByParentIdList(List<String> parentIdList); |
||||
|
|
||||
|
List<SysCategory> getChildByParentId(Long parentId); |
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
package com.ruoyi.system.service; |
||||
|
|
||||
|
import com.ruoyi.system.domain.SysCategory; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 分类字典Service接口 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
* @date 2023-11-17 |
||||
|
*/ |
||||
|
public interface ISysCategoryService |
||||
|
{ |
||||
|
/** |
||||
|
* 查询分类字典 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 分类字典 |
||||
|
*/ |
||||
|
public SysCategory selectSysCategoryById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 查询分类字典列表 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 分类字典集合 |
||||
|
*/ |
||||
|
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 新增分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int insertSysCategory(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 修改分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int updateSysCategory(SysCategory sysCategory); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除分类字典 |
||||
|
* |
||||
|
* @param ids 需要删除的数据ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteSysCategoryByIds(String ids); |
||||
|
|
||||
|
/** |
||||
|
* 删除分类字典信息 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
public int deleteSysCategoryById(Long id); |
||||
|
|
||||
|
|
||||
|
List<SysCategory> getChildByCode(String code); |
||||
|
} |
@ -0,0 +1,112 @@ |
|||||
|
package com.ruoyi.system.service.impl; |
||||
|
|
||||
|
import com.ruoyi.common.core.text.Convert; |
||||
|
import com.ruoyi.common.utils.DateUtils; |
||||
|
import com.ruoyi.system.domain.SysCategory; |
||||
|
import com.ruoyi.system.mapper.SysCategoryMapper; |
||||
|
import com.ruoyi.system.service.ISysCategoryService; |
||||
|
import org.apache.commons.collections.CollectionUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 分类字典Service业务层处理 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
* @date 2023-11-17 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class SysCategoryServiceImpl implements ISysCategoryService |
||||
|
{ |
||||
|
@Autowired |
||||
|
private SysCategoryMapper sysCategoryMapper; |
||||
|
|
||||
|
/** |
||||
|
* 查询分类字典 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 分类字典 |
||||
|
*/ |
||||
|
@Override |
||||
|
public SysCategory selectSysCategoryById(Long id) |
||||
|
{ |
||||
|
return sysCategoryMapper.selectSysCategoryById(id); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询分类字典列表 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 分类字典 |
||||
|
*/ |
||||
|
@Override |
||||
|
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory) |
||||
|
{ |
||||
|
return sysCategoryMapper.selectSysCategoryList(sysCategory); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 新增分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int insertSysCategory(SysCategory sysCategory) |
||||
|
{ |
||||
|
sysCategory.setCreateTime(DateUtils.getNowDate()); |
||||
|
return sysCategoryMapper.insertSysCategory(sysCategory); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改分类字典 |
||||
|
* |
||||
|
* @param sysCategory 分类字典 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int updateSysCategory(SysCategory sysCategory) |
||||
|
{ |
||||
|
sysCategory.setUpdateTime(DateUtils.getNowDate()); |
||||
|
return sysCategoryMapper.updateSysCategory(sysCategory); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除分类字典对象 |
||||
|
* |
||||
|
* @param ids 需要删除的数据ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int deleteSysCategoryByIds(String ids) |
||||
|
{ |
||||
|
return sysCategoryMapper.deleteSysCategoryByIds(Convert.toStrArray(ids)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除分类字典信息 |
||||
|
* |
||||
|
* @param id 分类字典ID |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int deleteSysCategoryById(Long id) |
||||
|
{ |
||||
|
return sysCategoryMapper.deleteSysCategoryById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<SysCategory> getChildByCode(String code) { |
||||
|
List<SysCategory> childCgList = sysCategoryMapper.getChildByCode(code); |
||||
|
if(CollectionUtils.isNotEmpty(childCgList)){ |
||||
|
childCgList.forEach(child->{ |
||||
|
Long childId = child.getId(); |
||||
|
List<SysCategory> childSonList = sysCategoryMapper.getChildByParentId(childId); |
||||
|
child.setChildren(childSonList); |
||||
|
}); |
||||
|
} |
||||
|
return childCgList; |
||||
|
} |
||||
|
} |
@ -0,0 +1,114 @@ |
|||||
|
<?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.system.mapper.SysCategoryMapper"> |
||||
|
|
||||
|
<resultMap type="SysCategory" id="SysCategoryResult"> |
||||
|
<result property="id" column="id" /> |
||||
|
<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" /> |
||||
|
<result property="parentId" column="parent_id" /> |
||||
|
<result property="code" column="code" /> |
||||
|
<result property="name" column="name" /> |
||||
|
<result property="sortOrder" column="sort_order" /> |
||||
|
</resultMap> |
||||
|
|
||||
|
<sql id="selectSysCategoryVo"> |
||||
|
select id, del_flag, create_by, create_time, update_by, update_time, remark, parent_id, code, name, sort_order from sys_category |
||||
|
</sql> |
||||
|
|
||||
|
<select id="selectSysCategoryList" parameterType="SysCategory" resultMap="SysCategoryResult"> |
||||
|
<include refid="selectSysCategoryVo"/> |
||||
|
<where> |
||||
|
<if test="parentId != null "> and parent_id = #{parentId}</if> |
||||
|
<if test="code != null and code != ''"> and code = #{code}</if> |
||||
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> |
||||
|
<if test="sortOrder != null "> and sort_order = #{sortOrder}</if> |
||||
|
</where> |
||||
|
</select> |
||||
|
|
||||
|
<select id="selectSysCategoryById" parameterType="Long" resultMap="SysCategoryResult"> |
||||
|
<include refid="selectSysCategoryVo"/> |
||||
|
where id = #{id} |
||||
|
</select> |
||||
|
<select id="getChildByCode" resultMap="SysCategoryResult"> |
||||
|
<include refid="selectSysCategoryVo"/> |
||||
|
where parent_id = (select id from sys_category where code = #{code}) |
||||
|
order by sort_order |
||||
|
</select> |
||||
|
<select id="getChildByParentIdList" resultMap="SysCategoryResult"> |
||||
|
<include refid="selectSysCategoryVo"/> |
||||
|
where parent_id in |
||||
|
<foreach item="parentId" collection="parentIdList" open="(" separator="," close=")"> |
||||
|
#{parentId} |
||||
|
</foreach> |
||||
|
order by sort_order |
||||
|
</select> |
||||
|
<select id="getChildByParentId" resultMap="SysCategoryResult"> |
||||
|
<include refid="selectSysCategoryVo"/> |
||||
|
where parent_id = #{parentId} |
||||
|
order by sort_order |
||||
|
</select> |
||||
|
|
||||
|
<insert id="insertSysCategory" parameterType="SysCategory" useGeneratedKeys="true" keyProperty="id"> |
||||
|
insert into sys_category |
||||
|
<trim prefix="(" suffix=")" suffixOverrides=","> |
||||
|
<if test="delFlag != null and delFlag != ''">del_flag,</if> |
||||
|
<if test="createBy != null and createBy != ''">create_by,</if> |
||||
|
<if test="createTime != null ">create_time,</if> |
||||
|
<if test="updateBy != null and updateBy != ''">update_by,</if> |
||||
|
<if test="updateTime != null ">update_time,</if> |
||||
|
<if test="remark != null and remark != ''">remark,</if> |
||||
|
<if test="parentId != null ">parent_id,</if> |
||||
|
<if test="code != null and code != ''">code,</if> |
||||
|
<if test="name != null and name != ''">name,</if> |
||||
|
<if test="sortOrder != null ">sort_order,</if> |
||||
|
</trim> |
||||
|
<trim prefix="values (" suffix=")" suffixOverrides=","> |
||||
|
<if test="delFlag != null and delFlag != ''">#{delFlag},</if> |
||||
|
<if test="createBy != null and createBy != ''">#{createBy},</if> |
||||
|
<if test="createTime != null ">#{createTime},</if> |
||||
|
<if test="updateBy != null and updateBy != ''">#{updateBy},</if> |
||||
|
<if test="updateTime != null ">#{updateTime},</if> |
||||
|
<if test="remark != null and remark != ''">#{remark},</if> |
||||
|
<if test="parentId != null ">#{parentId},</if> |
||||
|
<if test="code != null and code != ''">#{code},</if> |
||||
|
<if test="name != null and name != ''">#{name},</if> |
||||
|
<if test="sortOrder != null ">#{sortOrder},</if> |
||||
|
</trim> |
||||
|
</insert> |
||||
|
|
||||
|
<update id="updateSysCategory" parameterType="SysCategory"> |
||||
|
update sys_category |
||||
|
<trim prefix="SET" suffixOverrides=","> |
||||
|
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if> |
||||
|
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if> |
||||
|
<if test="createTime != null ">create_time = #{createTime},</if> |
||||
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
||||
|
<if test="updateTime != null ">update_time = #{updateTime},</if> |
||||
|
<if test="remark != null and remark != ''">remark = #{remark},</if> |
||||
|
<if test="parentId != null ">parent_id = #{parentId},</if> |
||||
|
<if test="code != null and code != ''">code = #{code},</if> |
||||
|
<if test="name != null and name != ''">name = #{name},</if> |
||||
|
<if test="sortOrder != null ">sort_order = #{sortOrder},</if> |
||||
|
</trim> |
||||
|
where id = #{id} |
||||
|
</update> |
||||
|
|
||||
|
<delete id="deleteSysCategoryById" parameterType="Long"> |
||||
|
delete from sys_category where id = #{id} |
||||
|
</delete> |
||||
|
|
||||
|
<delete id="deleteSysCategoryByIds" parameterType="String"> |
||||
|
delete from sys_category where id in |
||||
|
<foreach item="id" collection="array" open="(" separator="," close=")"> |
||||
|
#{id} |
||||
|
</foreach> |
||||
|
</delete> |
||||
|
|
||||
|
</mapper> |
Loading…
Reference in new issue