81 lines
2.9 KiB
XML
81 lines
2.9 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.zioinfo.hrm.admin.AdminMapper">
|
|
|
|
<resultMap id="UserRM" type="com.zioinfo.hrm.auth.HrmUser">
|
|
<id property="id" column="id"/>
|
|
<result property="username" column="username"/>
|
|
<result property="displayName" column="display_name"/>
|
|
<result property="email" column="email"/>
|
|
<result property="role" column="role"/>
|
|
<result property="active" column="active"/>
|
|
<result property="createdAt" column="created_at"/>
|
|
</resultMap>
|
|
|
|
<select id="findAllUsers" resultMap="UserRM">
|
|
SELECT id, username, display_name, email, role, active, created_at
|
|
FROM hrm_users ORDER BY id
|
|
</select>
|
|
|
|
<select id="findUserById" resultMap="UserRM">
|
|
SELECT id, username, display_name, email, role, active, created_at
|
|
FROM hrm_users WHERE id=#{id}
|
|
</select>
|
|
|
|
<insert id="insertUser">
|
|
INSERT INTO hrm_users (username, password_hash, display_name, email, role, active)
|
|
VALUES (#{username}, #{passwordHash}, #{displayName}, #{email}, #{role}, #{active})
|
|
</insert>
|
|
|
|
<update id="updateUser">
|
|
UPDATE hrm_users SET
|
|
display_name=#{displayName}, email=#{email}, role=#{role}
|
|
<if test="passwordHash != null and passwordHash != ''">, password_hash=#{passwordHash}</if>
|
|
WHERE id=#{id}
|
|
</update>
|
|
|
|
<update id="updateUserActive">
|
|
UPDATE hrm_users SET active=#{active} WHERE id=#{id}
|
|
</update>
|
|
|
|
<select id="findAuditLogs" resultType="map">
|
|
SELECT id, actor, action, target_type, target_id, detail, ip_addr, created_at
|
|
FROM hrm_audit_log
|
|
<where>
|
|
<if test="actor != null and actor != ''">AND actor ILIKE '%'||#{actor}||'%'</if>
|
|
<if test="action != null and action != ''">AND action=#{action}</if>
|
|
</where>
|
|
ORDER BY created_at DESC
|
|
LIMIT #{limit} OFFSET #{offset}
|
|
</select>
|
|
|
|
<select id="countAuditLogs" resultType="long">
|
|
SELECT COUNT(*) FROM hrm_audit_log
|
|
<where>
|
|
<if test="actor != null and actor != ''">AND actor ILIKE '%'||#{actor}||'%'</if>
|
|
<if test="action != null and action != ''">AND action=#{action}</if>
|
|
</where>
|
|
</select>
|
|
|
|
<insert id="insertAuditLog">
|
|
INSERT INTO hrm_audit_log (actor, action, target_type, target_id, detail, ip_addr)
|
|
VALUES (#{actor}, #{action}, #{targetType}, #{targetId}, #{detail}, #{ipAddr})
|
|
</insert>
|
|
|
|
<select id="findSettings" resultType="map">
|
|
SELECT key, value, description, updated_by, updated_at FROM hrm_settings ORDER BY key
|
|
</select>
|
|
|
|
<select id="findSetting" resultType="map">
|
|
SELECT key, value, description FROM hrm_settings WHERE key=#{key}
|
|
</select>
|
|
|
|
<insert id="upsertSetting">
|
|
INSERT INTO hrm_settings (key, value, updated_by)
|
|
VALUES (#{key}, #{value}, #{updatedBy})
|
|
ON CONFLICT (key) DO UPDATE SET value=#{value}, updated_by=#{updatedBy}, updated_at=NOW()
|
|
</insert>
|
|
|
|
</mapper>
|