187 lines
7.0 KiB
XML
187 lines
7.0 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.psbc.cpsp.eden.mapper.asset.AssetLocationMapper">
|
|
<resultMap id="BaseResultMap" type="com.psbc.cpsp.eden.common.entity.AssetLocation">
|
|
<id column="id" property="id"/>
|
|
<result column="location_code" property="locationCode"/>
|
|
<result column="location_name" property="locationName"/>
|
|
<result column="parent_id" property="parentId"/>
|
|
<result column="status" property="status"/>
|
|
<result column="remark" property="remark"/>
|
|
<result column="create_user_id" property="createUserId"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="del_flag" property="delFlag"/>
|
|
<result column="last_mod_user_id" property="lastModUserId"/>
|
|
<result column="last_mod_time" property="lastModTime"/>
|
|
<result column="tenant_id" property="tenantId"/>
|
|
</resultMap>
|
|
|
|
<resultMap id="TreeResultMap" type="com.psbc.cpsp.eden.common.vo.TreeNode">
|
|
<id column="id" property="id"/>
|
|
<result column="location_name" property="label"/>
|
|
<result column="parent_id" property="parentId"/>
|
|
<result column="has_children" property="hasChildren"/>
|
|
<result column="location_code" property="code"/>
|
|
</resultMap>
|
|
|
|
<sql id="Base_Column_List">
|
|
"id", "location_code", "location_name", "parent_id", "status", "remark",
|
|
"create_user_id", "create_time", "del_flag", "last_mod_user_id", "last_mod_time", "tenant_id"
|
|
</sql>
|
|
|
|
<!-- 新增资产位置 -->
|
|
<insert id="insert" parameterType="com.psbc.cpsp.eden.common.entity.AssetLocation" useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO "tb_asset_location" (
|
|
"location_code", "location_name", "parent_id", "status", "remark",
|
|
"create_user_id", "create_time", "del_flag", "last_mod_user_id", "last_mod_time"
|
|
) VALUES (
|
|
#{locationCode}, #{locationName}, #{parentId}, #{status}, #{remark},
|
|
#{createUserId}, #{createTime}, #{delFlag}, #{lastModUserId}, #{lastModTime}
|
|
)
|
|
</insert>
|
|
|
|
<!-- 修改资产位置 -->
|
|
<update id="update" parameterType="com.psbc.cpsp.eden.common.entity.AssetLocation">
|
|
UPDATE "tb_asset_location"
|
|
<set>
|
|
"location_code" = #{locationCode},
|
|
"location_name" = #{locationName},
|
|
"parent_id" = #{parentId},
|
|
"status" = #{status},
|
|
"remark" = #{remark},
|
|
"last_mod_user_id" = #{lastModUserId},
|
|
"last_mod_time" = #{lastModTime}
|
|
</set>
|
|
WHERE "id" = #{id} AND "del_flag" = '0'
|
|
</update>
|
|
|
|
<!-- 更新资产位置状态 -->
|
|
<update id="updateStatus">
|
|
UPDATE "tb_asset_location"
|
|
SET "status" = #{status},
|
|
"last_mod_user_id" = #{lastModUserId},
|
|
"last_mod_time" = #{lastModTime}
|
|
WHERE "id" = #{id} AND "del_flag" = '0'
|
|
</update>
|
|
|
|
<!-- 根据ID查询资产位置详情 -->
|
|
<select id="selectById" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List" />
|
|
FROM "tb_asset_location"
|
|
WHERE "id" = #{id} AND "del_flag" = '0'
|
|
</select>
|
|
|
|
<!-- 查询资产位置列表 -->
|
|
<select id="selectList" parameterType="com.psbc.cpsp.eden.common.entity.AssetLocation" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List" />
|
|
FROM "tb_asset_location"
|
|
WHERE "del_flag" = '0'
|
|
<if test="locationCode != null and locationCode != ''">
|
|
AND "location_code" LIKE CONCAT('%', #{locationCode}, '%')
|
|
</if>
|
|
<if test="locationName != null and locationName != ''">
|
|
AND "location_name" LIKE CONCAT('%', #{locationName}, '%')
|
|
</if>
|
|
<if test="parentId != null">
|
|
AND "parent_id" = #{parentId}
|
|
</if>
|
|
<if test="status != null and status != ''">
|
|
AND "status" = #{status}
|
|
</if>
|
|
ORDER BY "location_code"
|
|
</select>
|
|
|
|
<!-- 逻辑删除资产位置 -->
|
|
<update id="deleteById">
|
|
UPDATE "tb_asset_location"
|
|
SET "del_flag" = '1',
|
|
"last_mod_user_id" = #{lastModUserId},
|
|
"last_mod_time" = NOW()
|
|
WHERE "id" = #{id} AND "del_flag" = '0'
|
|
</update>
|
|
|
|
<!-- 批量逻辑删除资产位置 -->
|
|
<update id="deleteBatchIds">
|
|
UPDATE "tb_asset_location"
|
|
SET "del_flag" = '1',
|
|
"last_mod_user_id" = #{lastModUserId},
|
|
"last_mod_time" = NOW()
|
|
WHERE "id" IN
|
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
AND "del_flag" = '0'
|
|
</update>
|
|
|
|
<!-- 检查位置编码是否唯一 -->
|
|
<select id="checkCodeUnique" resultType="int">
|
|
SELECT COUNT(1)
|
|
FROM "tb_asset_location"
|
|
WHERE "location_code" = #{locationCode}
|
|
AND "del_flag" = '0'
|
|
<if test="id != null">
|
|
AND "id" != #{id}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="checkNameUnique" resultType="int">
|
|
SELECT COUNT(1)
|
|
FROM "tb_asset_location"
|
|
WHERE "location_name" = #{locationName}
|
|
AND "del_flag" = '0'
|
|
<if test="id != null">
|
|
AND "id" != #{id}
|
|
</if>
|
|
</select>
|
|
|
|
|
|
<!-- 查询资产位置树结构 -->
|
|
<select id="selectTree" resultMap="TreeResultMap">
|
|
SELECT
|
|
a."id",
|
|
a."location_name",
|
|
a."parent_id",
|
|
a."location_code",
|
|
CASE WHEN EXISTS (
|
|
SELECT 1 FROM "tb_asset_location" b
|
|
WHERE b."parent_id" =a."id"
|
|
AND b."del_flag" = '0'
|
|
) THEN TRUE ELSE FALSE END AS "has_children"
|
|
FROM "tb_asset_location" a
|
|
WHERE a."del_flag" = '0'
|
|
<if test="locationName != null and locationName != ''">
|
|
AND a."location_name" LIKE CONCAT('%', #{locationName}, '%')
|
|
</if>
|
|
<if test="status != null and status != ''">
|
|
AND a."status" = #{status}
|
|
</if>
|
|
ORDER BY a."parent_id" NULLS FIRST, a."location_code"
|
|
</select>
|
|
|
|
<!-- 根据父ID查询所有子节点 -->
|
|
<select id="selectChildrenByParentId" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List" />
|
|
FROM "tb_asset_location"
|
|
WHERE "del_flag" = '0'
|
|
<if test="parentId != null">
|
|
AND "parent_id" = #{parentId}
|
|
</if>
|
|
ORDER BY "location_code"
|
|
</select>
|
|
|
|
<!-- 根据位置名称查询位置ID -->
|
|
<select id="selectIdByName" resultType="java.lang.Long">
|
|
SELECT "id"
|
|
FROM "tb_asset_location"
|
|
WHERE "location_name" = #{locationName}
|
|
AND "del_flag" = '0'
|
|
</select>
|
|
|
|
<!-- 检查位置名称是否存在 -->
|
|
<select id="checkLocationNameExists" resultType="boolean">
|
|
SELECT COUNT(1) > 0
|
|
FROM "tb_asset_location"
|
|
WHERE "location_name" = #{locationName}
|
|
AND "del_flag" = '0'
|
|
</select>
|
|
</mapper> |