融合代码

更新:辅助字典移动到basics目录下,
              修订数据类型条件查询无效bug,
              优化无条件分页查询代码,
              配置编码自增,用户不需手动输入(app强特征作用域选着配置功能待添加)
             无上级,改为根节点,
This commit is contained in:
zhangshilin
2018-03-06 10:06:42 +08:00
parent bb27ba16db
commit fc2af8ba04
25 changed files with 193 additions and 366 deletions

View File

@@ -0,0 +1,98 @@
package com.nis.web.dao.basics;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.SysMenu;
import com.nis.domain.basics.ServiceDictInfo;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface ServiceDictInfoDao extends CrudDao<ServiceDictInfo> {
/**
* 查询顶层字典列表(无条件查询(==)
* @param serviceDictInfo
* @return
*/
List<ServiceDictInfo> findTopDictList(ServiceDictInfo serviceDictInfo);
/**
* 查询顶层字典列表(无条件查询(!=)
* @param serviceDictInfo
* @return
*/
List<ServiceDictInfo> findTopDictListN(ServiceDictInfo serviceDictInfo);
/**
* 查出所有有效数据
*/
List<ServiceDictInfo> findAllDictList(ServiceDictInfo serviceDictInfo);
/**
* 查询所有的非叶子配置
*/
List<ServiceDictInfo> findAllNoLeafDictList(@Param("itemType")Integer itemType);
/**
* 根据上级id选出所有下级
* @param parentId
* @return
*/
List<ServiceDictInfo> getDictByParentId(Integer parentId);
/**
* 查询字典列表(含条件查询(==)
* @param serviceDictInfo
* @return
*/
List<ServiceDictInfo> findDictSearchList(ServiceDictInfo serviceDictInfo);
/**
* 查询字典列表(含条件查询(!=)
* @param serviceDictInfo
* @return
*/
List<ServiceDictInfo> findDictSearchListN(ServiceDictInfo serviceDictInfo);
/**
* 添加字典信息
* @param serviceDictInfo
*/
void insertDict(ServiceDictInfo serviceDictInfo);
/**
* 根据主键查询字典详细信息
* @param serviceDictId
* @return
*/
ServiceDictInfo getDictById(Integer serviceDictId);
/**
* 根据itemCode查询字典对象列表
* @param itemCode
* @return
*/
List<ServiceDictInfo> findByItemCode(Integer itemCode);
/**
* 查询itemCode最大值
* @return
*/
Integer findMaxItemCode();
List<ServiceDictInfo> findItemDict(@Param("itemType")int itemType,@Param("isValid")int isValid);
List<ServiceDictInfo> findAllItemDict(@Param("itemType")int itemType);
}

View File

@@ -0,0 +1,284 @@
<?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.nis.web.dao.basics.ServiceDictInfoDao" >
<resultMap id="dictResultMap" type="com.nis.domain.basics.ServiceDictInfo" >
<id column="service_dict_id" property="serviceDictId" jdbcType="INTEGER" />
<result column="item_type" property="itemType" jdbcType="INTEGER" />
<result column="item_code" property="itemCode" jdbcType="INTEGER" />
<result column="item_value" property="itemValue" jdbcType="VARCHAR" />
<result column="item_desc" property="itemDesc" jdbcType="VARCHAR" />
<result column="is_leaf" property="isLeaf" jdbcType="INTEGER" />
<result column="is_valid" property="isValid" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
<!-- 父id -->
<association property="parent" javaType="com.nis.domain.basics.ServiceDictInfo">
<id column="parent_id" property="serviceDictId" jdbcType="INTEGER" />
</association>
<!-- 创建人员 -->
<association property="serviceDictCreator" javaType="com.nis.domain.SysUser">
<id property="id" column="creator_id"/>
<result property="loginId" column="login_id"/>
<result property="name" column="name"/>
</association>
<!-- 修改人员 -->
<association property="serviceDictEditor" javaType="com.nis.domain.SysUser">
<id property="id" column="editor_id"/>
<result property="loginId" column="login_id"/>
<result property="name" column="name"/>
</association>
</resultMap>
<sql id="serviceDictInfoColumns">
s.service_dict_id AS serviceDictId,
s.item_type AS itemType,
s.item_code AS itemCode,
s.item_value AS itemValue,
s.item_desc AS itemDesc,
s.parent_id AS "parent.serviceDictId",
s.is_leaf AS isLeaf,
s.is_valid AS isValid,
s.creator_id AS "serviceDictCreator.id",
s.create_time AS createTime,
s.editor_id AS "serviceDictEditor.id",
s.edit_time AS editTime
</sql>
<!-- 查询顶层分页列表 (==)-->
<select id="findTopDictList" resultMap="dictResultMap" parameterType="com.nis.domain.basics.ServiceDictInfo">
SELECT * FROM service_dict_info WHERE is_valid=1 AND parent_id = 0
<if test="itemValue != null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemType != null and itemType != '' " >
AND item_type = #{itemType}
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 查询顶层分页列表 (!=)-->
<select id="findTopDictListN" resultMap="dictResultMap" parameterType="com.nis.domain.basics.ServiceDictInfo">
SELECT * FROM service_dict_info WHERE is_valid=1 AND parent_id = 0
<if test="itemValue != null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemType != null and itemType != '' " >
AND item_type != #{itemType}
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 查出所有 -->
<select id="findAllDictList" resultType="serviceDictInfo">
SELECT
<include refid="serviceDictInfoColumns"/>
FROM service_dict_info s
<include refid="menuJoins"/>
WHERE s.is_valid =1
</select>
<!-- 查询所有非叶子配置 -->
<select id="findAllNoLeafDictList" resultType="com.nis.domain.basics.ServiceDictInfo" parameterType="java.lang.Integer">
SELECT
<include refid="serviceDictInfoColumns"/>
FROM service_dict_info s
WHERE s.is_valid = 1 AND s.is_leaf = 0 AND item_type = #{itemType}
</select>
<!-- 条件查询分页(==) -->
<select id="findDictSearchList" resultMap="dictResultMap" parameterType="com.nis.domain.basics.ServiceDictInfo">
SELECT * FROM service_dict_info WHERE is_valid=1
<if test="itemType != null and itemType != '' " >
AND item_type like '%${itemType}%'
</if>
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemValue!= null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 条件查询分页(!=) -->
<select id="findDictSearchListN" resultMap="dictResultMap" parameterType="com.nis.domain.basics.ServiceDictInfo">
SELECT * FROM service_dict_info WHERE is_valid=1
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemValue!= null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="itemType != null and itemType != '' " >
AND item_type != ${itemType}
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 根据主键查询字典详细信息 -->
<select id="getDictById" resultType="com.nis.domain.basics.ServiceDictInfo">
select
<include refid="serviceDictInfoColumns"/>
from service_dict_info s where s.service_dict_id = #{serviceDictId}
</select>
<!-- 根据上级id选出所有下级 -->
<select id="getDictByParentId" resultMap="dictResultMap">
select *
from service_dict_info s where parent_id = #{parentId}
</select>
<!-- 根据itemCode查询字典对象列表 -->
<select id="findByItemCode" resultType="com.nis.domain.basics.ServiceDictInfo">
select
<include refid="serviceDictInfoColumns"/>
from service_dict_info s where s.item_code = #{itemCode}
</select>
<!-- 查出最大的itemCode值 -->
<select id="findMaxItemCode" resultType="java.lang.Integer">
select max(s.item_code) from service_dict_info s
</select>
<!-- 新增字典信息 -->
<insert id="insertDict" parameterType="com.nis.domain.basics.ServiceDictInfo" useGeneratedKeys="true" keyProperty="id" >
insert into service_dict_info (item_type, item_code, item_value, item_desc, parent_id, is_leaf, is_valid, creator_id, create_time, editor_id, edit_time)
values ( #{itemType,jdbcType=INTEGER}, #{itemCode,jdbcType=INTEGER},
#{itemValue,jdbcType=VARCHAR}, #{itemDesc,jdbcType=VARCHAR},
#{parent.serviceDictId,jdbcType=INTEGER}, #{isLeaf,jdbcType=INTEGER}, #{isValid,jdbcType=INTEGER},
#{serviceDictCreator.id,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{serviceDictEditor.id,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP})
</insert>
<!-- 修改 -->
<update id="update">
UPDATE service_dict_info s SET
s.service_dict_id = #{serviceDictId},
s.item_type = #{itemType},
s.item_code = #{itemCode},
s.item_value = #{itemValue},
s.item_desc = #{itemDesc},
s.parent_id = #{parent.serviceDictId},
s.is_leaf = #{isLeaf},
s.creator_id = #{serviceDictCreator.id},
s.editor_id = #{serviceDictEditor.id},
s.edit_time = #{editTime}
WHERE s.service_dict_id = #{serviceDictId}
</update>
<!-- 删除 -->
<update id="delete">
UPDATE service_dict_info s set s.is_valid = #{isValid} where s.service_dict_id = #{serviceDictId}
</update>
<select id="findItemDict" resultMap="dictResultMap">
select
<include refid="serviceDictInfoColumns" />
from service_dict_info s where s.is_leaf = 0 and s.item_type=#{itemType} and s.is_valid=#{isValid};
</select>
<select id="findAllItemDict" resultMap="dictResultMap">
select
<include refid="serviceDictInfoColumns" />
from service_dict_info s where s.is_leaf = 0 and s.item_type=#{itemType};
</select>
<sql id="menuJoins">
LEFT JOIN service_dict_info p ON p.service_dict_id = s.parent_id
</sql>
</mapper>

View File

@@ -0,0 +1,90 @@
package com.nis.web.dao.basics;
import java.util.List;
import com.nis.domain.basics.SysDictInfo;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface SysDictInfoDao extends CrudDao<SysDictInfo> {
/**
* 查询顶层字典列表(无条件查询(==)
* @param sysDictInfo
* @return
*/
List<SysDictInfo> findTopDictList(SysDictInfo sysDictInfo);
/**
* 查出所有有效数据
* @param sysDictInfo
* @return
*/
List<SysDictInfo> findAllDictList(SysDictInfo sysDictInfo);
/**
* 查询字典列表(含条件查询(==)
* @param sysDictInfo
* @return
*/
List<SysDictInfo> findDictSearchList(SysDictInfo sysDictInfo);
/**
* 添加字典信息
* @param sysDictInfo
*/
void insertDict(SysDictInfo sysDictInfo);
/**
* 根据主键查询字典详细信息
* @param sysDictId
* @return
*/
SysDictInfo getDictById(Integer sysDictId);
/**
* 查询所有的非叶子配置
* @param itemType
* @return
*/
List<SysDictInfo> findAllNoLeafDictList(Integer itemType);
/**
* 根据itemCode查询字典对象列表
* @param itemCode
* @return
*/
List<SysDictInfo> findByItemCode(Integer itemCode);
/**
* 根据上级id选出所有下级
* @param parentId
* @return
*/
List<SysDictInfo> getDictByParentId(Integer parentId);
/**
* 查询最大itemCode值
* @return
*/
Integer findMaxItemCode();
}

View File

@@ -0,0 +1,195 @@
<?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.nis.web.dao.basics.SysDictInfoDao" >
<resultMap id="dictResultMap" type="com.nis.domain.basics.SysDictInfo" >
<id column="sys_dict_id" property="sysDictId" jdbcType="INTEGER" />
<result column="item_type" property="itemType" jdbcType="INTEGER" />
<result column="item_code" property="itemCode" jdbcType="INTEGER" />
<result column="item_value" property="itemValue" jdbcType="VARCHAR" />
<result column="item_desc" property="itemDesc" jdbcType="VARCHAR" />
<result column="is_leaf" property="isLeaf" jdbcType="INTEGER" />
<result column="is_valid" property="isValid" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
<!-- 父id -->
<association property="parent" javaType="com.nis.domain.basics.SysDictInfo">
<id column="parent_id" property="sysDictId" jdbcType="INTEGER" />
</association>
<!-- 创建人员 -->
<association property="sysDictCreator" javaType="com.nis.domain.SysUser">
<id property="id" column="creator_id"/>
<result property="loginId" column="login_id"/>
<result property="name" column="name"/>
</association>
<!-- 修改人员 -->
<association property="sysDictEditor" javaType="com.nis.domain.SysUser">
<id property="id" column="editor_id"/>
<result property="loginId" column="login_id"/>
<result property="name" column="name"/>
</association>
</resultMap>
<sql id="sysDictInfoColumns">
s.sys_dict_id AS sysDictId,
s.item_type AS itemType,
s.item_code AS itemCode,
s.item_value AS itemValue,
s.item_desc AS itemDesc,
s.parent_id AS "parent.sysDictId",
s.is_leaf AS isLeaf,
s.is_valid AS isValid,
s.creator_id AS "sysDictCreator.id",
s.create_time AS createTime,
s.editor_id AS "sysDictEditor.id",
s.edit_time AS editTime
</sql>
<sql id="menuJoins">
LEFT JOIN sys_dict_info p ON p.sys_dict_id = s.parent_id
</sql>
<!-- 查询顶层分页列表 (==)-->
<select id="findTopDictList" resultMap="dictResultMap" parameterType="com.nis.domain.basics.SysDictInfo">
SELECT * FROM sys_dict_info WHERE is_valid=1 AND parent_id = 0
<if test="itemValue != null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemType != null and itemType != '' " >
AND item_type = #{itemType}
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 查出所有 -->
<select id="findAllDictList" resultType="sysDictInfo">
SELECT
<include refid="sysDictInfoColumns"/>
FROM sys_dict_info s
<include refid="menuJoins"/>
WHERE s.is_valid =1
</select>
<!-- 条件查询分页(==) -->
<select id="findDictSearchList" resultMap="dictResultMap" parameterType="com.nis.domain.basics.SysDictInfo">
SELECT * FROM sys_dict_info WHERE is_valid=1
<if test="itemType != null and itemType != '' " >
AND item_type like '%${itemType}%'
</if>
<if test="itemCode != null and itemCode != '' " >
AND item_code like '%${itemCode}%'
</if>
<if test="itemValue!= null and itemValue != '' " >
AND item_value like '%${itemValue}%'
</if>
<if test="beginDate !=null" >
AND create_time &gt;= #{beginDate,jdbcType=TIMESTAMP}
</if>
<if test="endDate !=null" >
AND create_time &lt;= DATE_ADD(#{endDate,jdbcType=TIMESTAMP},INTERVAL 1 DAY)
</if>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY create_time desc
</otherwise>
</choose>
</select>
<!-- 根据主键查询字典详细信息 -->
<select id="getDictById" resultType="com.nis.domain.basics.SysDictInfo">
select
<include refid="sysDictInfoColumns"/>
from sys_dict_info s where s.sys_dict_id = #{sysDictId}
</select>
<!-- 新增字典信息 -->
<insert id="insertDict" parameterType="com.nis.domain.basics.SysDictInfo" useGeneratedKeys="true" keyProperty="id" >
insert into sys_dict_info (item_type, item_code, item_value, item_desc, parent_id, is_leaf, is_valid, creator_id, create_time, editor_id, edit_time)
values ( #{itemType,jdbcType=INTEGER}, #{itemCode,jdbcType=INTEGER},
#{itemValue,jdbcType=VARCHAR}, #{itemDesc,jdbcType=VARCHAR},
#{parent.sysDictId,jdbcType=INTEGER}, #{isLeaf,jdbcType=INTEGER}, #{isValid,jdbcType=INTEGER},
#{sysDictCreator.id,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{sysDictEditor.id,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP})
</insert>
<!-- 查询所有非叶子配置 -->
<select id="findAllNoLeafDictList" resultType="com.nis.domain.basics.SysDictInfo" parameterType="java.lang.Integer">
SELECT
<include refid="sysDictInfoColumns"/>
FROM sys_dict_info s
WHERE s.is_valid = 1 AND s.is_leaf = 0 AND item_type = #{itemType}
</select>
<!-- 修改 -->
<update id="update">
UPDATE sys_dict_info s SET
s.sys_dict_id = #{sysDictId},
s.item_type = #{itemType},
s.item_code = #{itemCode},
s.item_value = #{itemValue},
s.item_desc = #{itemDesc},
s.parent_id = #{parent.sysDictId},
s.is_leaf = #{isLeaf},
s.creator_id = #{sysDictCreator.id},
s.editor_id = #{sysDictEditor.id},
s.edit_time = #{editTime}
WHERE s.sys_dict_id = #{sysDictId}
</update>
<!-- 删除 -->
<update id="delete">
UPDATE sys_dict_info s set s.is_valid = #{isValid} where s.sys_dict_id = #{sysDictId}
</update>
<!-- 根据itemCode查询字典对象列表 -->
<select id="findByItemCode" resultType="com.nis.domain.basics.SysDictInfo">
select
<include refid="sysDictInfoColumns"/>
from sys_dict_info s where s.item_code = #{itemCode}
</select>
<!-- 根据上级id选出所有下级 -->
<select id="getDictByParentId" resultMap="dictResultMap">
select *
from sys_dict_info s where parent_id = #{parentId}
</select>
<!-- 查询最大itemCode值 -->
<select id="findMaxItemCode" resultType="java.lang.Integer">
select max(s.item_code) from sys_dict_info s
</select>
</mapper>