153 lines
3.4 KiB
XML
153 lines
3.4 KiB
XML
<?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.jeeplus.modules.test.dao.grid.GoodsDao">
|
|
|
|
<sql id="goodsColumns">
|
|
a.id AS "id",
|
|
a.name AS "name",
|
|
a.category_id AS "category.id",
|
|
a.price AS "price",
|
|
a.create_by AS "createBy.id",
|
|
a.create_date AS "createDate",
|
|
a.update_by AS "updateBy.id",
|
|
a.update_date AS "updateDate",
|
|
a.remarks AS "remarks",
|
|
a.del_flag AS "delFlag",
|
|
category.name AS "category.name"
|
|
</sql>
|
|
|
|
<sql id="goodsJoins">
|
|
LEFT JOIN category category ON category.id = a.category_id
|
|
</sql>
|
|
|
|
|
|
<select id="get" resultType="Goods" >
|
|
SELECT
|
|
<include refid="goodsColumns"/>
|
|
FROM goods a
|
|
<include refid="goodsJoins"/>
|
|
WHERE a.id = #{id}
|
|
</select>
|
|
|
|
<select id="findList" resultType="Goods" >
|
|
SELECT
|
|
<include refid="goodsColumns"/>
|
|
FROM goods a
|
|
<include refid="goodsJoins"/>
|
|
<where>
|
|
a.del_flag = #{DEL_FLAG_NORMAL}
|
|
<if test="name != null and name != ''">
|
|
AND a.name = #{name}
|
|
</if>
|
|
<if test="category != null and category.id != null and category.id != ''">
|
|
AND a.category_id = #{category.id}
|
|
</if>
|
|
</where>
|
|
<choose>
|
|
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
|
|
ORDER BY ${page.orderBy}
|
|
</when>
|
|
<otherwise>
|
|
ORDER BY a.update_date DESC
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<select id="findAllList" resultType="Goods" >
|
|
SELECT
|
|
<include refid="goodsColumns"/>
|
|
FROM goods a
|
|
<include refid="goodsJoins"/>
|
|
<where>
|
|
a.del_flag = #{DEL_FLAG_NORMAL}
|
|
</where>
|
|
<choose>
|
|
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
|
|
ORDER BY ${page.orderBy}
|
|
</when>
|
|
<otherwise>
|
|
ORDER BY a.update_date DESC
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<insert id="insert">
|
|
INSERT INTO goods(
|
|
id,
|
|
name,
|
|
category_id,
|
|
price,
|
|
create_by,
|
|
create_date,
|
|
update_by,
|
|
update_date,
|
|
remarks,
|
|
del_flag
|
|
) VALUES (
|
|
#{id},
|
|
#{name},
|
|
#{category.id},
|
|
#{price},
|
|
#{createBy.id},
|
|
#{createDate},
|
|
#{updateBy.id},
|
|
#{updateDate},
|
|
#{remarks},
|
|
#{delFlag}
|
|
)
|
|
</insert>
|
|
|
|
<update id="update">
|
|
UPDATE goods SET
|
|
name = #{name},
|
|
category_id = #{category.id},
|
|
price = #{price},
|
|
update_by = #{updateBy.id},
|
|
update_date = #{updateDate},
|
|
remarks = #{remarks}
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
|
|
<!--物理删除-->
|
|
<update id="delete">
|
|
DELETE FROM goods
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<!--逻辑删除-->
|
|
<update id="deleteByLogic">
|
|
UPDATE goods SET
|
|
del_flag = #{DEL_FLAG_DELETE}
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
|
|
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
|
|
<select id="findUniqueByProperty" resultType="Goods" statementType="STATEMENT">
|
|
select * FROM goods where ${propertyName} = '${value}'
|
|
</select>
|
|
|
|
<select id="findListBycategory" resultType="Category">
|
|
SELECT
|
|
*
|
|
FROM category a
|
|
<where>
|
|
a.del_flag = #{DEL_FLAG_NORMAL}
|
|
<if test="name != null and name != ''">
|
|
AND a.name LIKE
|
|
<if test="dbName == 'oracle'">#{name}||'%'</if>
|
|
<if test="dbName == 'mssql'">#{name}+'%'</if>
|
|
<if test="dbName == 'mysql'">concat(#{name},'%')</if>
|
|
</if>
|
|
</where>
|
|
<choose>
|
|
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
|
|
ORDER BY ${page.orderBy}
|
|
</when>
|
|
<otherwise>
|
|
ORDER BY a.update_date DESC
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
</mapper> |