Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmQrBoxMapper.xml

193 lines
8.4 KiB
XML
Raw Normal View History

2024-12-11 13:26:02 +08:00
<?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.bonus.material.basic.mapper.BmQrBoxMapper">
2024-12-20 13:18:35 +08:00
<select id="findBoxInfoByKey" resultType="com.bonus.material.basic.domain.BmQrBoxInfo">
select * from bm_qrcode_box
<where>
<if test="boxId != null">and bqb.box_id = #{boxId}</if>
<if test="boxCode != null and boxCode != ''">and bqb.box_code = #{boxCode}</if>
<if test="boxType != null">and bqb.box_type = #{boxType}</if>
</where>
</select>
2024-12-11 13:26:02 +08:00
<select id="find" resultType="com.bonus.material.basic.domain.BmQrBoxInfo">
select
2024-12-20 10:52:01 +08:00
bqb.box_id as boxId,
bqb.box_name as boxName,
bqb.box_code as boxCode,
bqb.box_type as boxType,
bqb.box_status as status,
bqb.create_by as createBy,
bqb.create_time as createTime,
bqb.update_by as updateBy,
bqb.update_time as updateTime,
bqb.transfer_user,bqb.input_user,
mm.type_id as maTypeId,
COUNT(qbb.box_id) as devNum
2024-12-12 11:10:03 +08:00
from bm_qrcode_box bqb
2024-12-20 10:52:01 +08:00
left join bm_qrcode_box_bind qbb on bqb.box_id = qbb.box_id
left join ma_machine mm on qbb.ma_id = mm.ma_id
2024-12-11 13:26:02 +08:00
<where>
2024-12-12 11:10:03 +08:00
<if test="boxId != null">and bqb.box_id = #{boxId}</if>
<if test="boxName != null and boxName != ''">and bqb.box_name like concat('%',#{boxName},'%')</if>
<if test="boxCode != null and boxCode != ''">and bqb.box_code like concat('%',#{boxCode},'%')</if>
<if test="boxType != null">and bqb.box_type = #{boxType}</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[ AND DATE_FORMAT( bqb.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
<if test="keyWord != null and keyWord != ''">
2024-12-20 10:52:01 +08:00
AND (
bqb.box_name like concat('%',#{keyWord},'%')
OR bqb.box_code like concat('%',#{keyWord},'%')
)
</if>
<if test="statusList != null and statusList != ''">
AND bqb.box_status in
<foreach item="key" collection="statusList" open="(" separator="," close=")">
#{key}
</foreach>
2024-12-12 11:10:03 +08:00
</if>
2024-12-11 13:26:02 +08:00
</where>
2024-12-12 11:10:03 +08:00
GROUP BY bqb.box_id
order by bqb.create_time desc
</select>
<select id="countBmQrcodeInfoByBoxId" resultType="java.lang.Integer">
2024-12-20 10:52:01 +08:00
select count(1) from bm_qrcode_box_bind where box_id = #{boxId}
2024-12-12 11:10:03 +08:00
</select>
<select id="getList" resultType="com.bonus.material.basic.domain.BmQrBoxInfo">
SELECT
2024-12-20 10:52:01 +08:00
qb.id as id,qb.box_id as boxId,qb.create_by as createBy,
2024-12-12 11:10:03 +08:00
mt1.type_name as typeName,
mt.type_name as typeModelName,
2024-12-20 10:52:01 +08:00
mm.ma_id as maId,mm.ma_code as maCode,mm.type_id as maTypeId
2024-12-12 11:10:03 +08:00
FROM
2024-12-20 10:52:01 +08:00
bm_qrcode_box_bind qb
LEFT JOIN ma_machine mm ON qb.ma_id = mm.ma_id
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0'
<where>
<if test="boxId != null">and qb.box_id = #{boxId}</if>
2024-12-12 11:10:03 +08:00
<if test="keyWord != null and keyWord != ''">
2024-12-20 10:52:01 +08:00
AND (
mt1.type_name like concat('%',#{keyWord},'%')
OR mt.type_name like concat('%',#{keyWord},'%')
OR mm.ma_code like concat('%',#{keyWord},'%')
)
2024-12-12 11:10:03 +08:00
</if>
2024-12-20 10:52:01 +08:00
</where>
2024-12-11 13:26:02 +08:00
</select>
2024-12-12 11:10:03 +08:00
<insert id="insertBmQrcodeInfo" parameterType="com.bonus.material.basic.domain.BmQrBoxInfo" useGeneratedKeys="true" keyProperty="boxId">
2024-12-11 13:26:02 +08:00
insert into bm_qrcode_box
<trim prefix="(" suffix=")" suffixOverrides=",">
2024-12-12 11:10:03 +08:00
<if test="boxCode != null">box_code,</if>
<if test="boxName != null and boxName != ''">box_name,</if>
<if test="boxType != null">box_type,</if>
2024-12-11 13:26:02 +08:00
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
2024-12-12 11:10:03 +08:00
<if test="boxCode != null">#{boxCode},</if>
<if test="boxName != null and boxName != ''">#{boxName},</if>
<if test="boxType != null">#{boxType},</if>
2024-12-11 13:26:02 +08:00
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
2024-12-20 10:52:01 +08:00
<update id="updateBmQrcodeInfoById" parameterType="com.bonus.material.basic.domain.BmQrBoxInfo">
2024-12-11 13:26:02 +08:00
update bm_qrcode_box
<trim prefix="SET" suffixOverrides=",">
2024-12-12 11:10:03 +08:00
<if test="boxCode != null">box_code = #{boxCode},</if>
<if test="boxType != null">box_type = #{boxType},</if>
<if test="boxName != null and boxName != ''">box_name = #{boxName},</if>
2024-12-20 10:52:01 +08:00
<if test="status != null and status != ''">box_status = #{status} ,</if>
2024-12-11 13:26:02 +08:00
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
2024-12-20 10:52:01 +08:00
<if test="transferUser != null">transfer_user = #{transferUser},</if>
<if test="inputUser != null">input_user = #{inputUser},</if>
2024-12-11 13:26:02 +08:00
</trim>
2024-12-12 11:10:03 +08:00
where box_id = #{boxId}
2024-12-11 13:26:02 +08:00
</update>
2024-12-20 10:52:01 +08:00
<update id="updateBmQrcodeInfoByCode" parameterType="com.bonus.material.basic.domain.BmQrBoxInfo">
update bm_qrcode_box
<trim prefix="SET" suffixOverrides=",">
<if test="boxType != null">box_type = #{boxType},</if>
<if test="boxName != null and boxName != ''">box_name = #{boxName},</if>
<if test="status != null">box_status = #{status},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where box_code = #{boxCode}
</update>
2024-12-11 13:26:02 +08:00
<delete id="deleteById">
delete
from bm_qrcode_box
2024-12-12 11:10:03 +08:00
where box_id = #{boxId}
2024-12-11 13:26:02 +08:00
</delete>
2024-12-20 10:52:01 +08:00
<delete id="unBindQrcodeBox">
delete
from bm_qrcode_box_bind
where id = #{id}
</delete>
<insert id="addQrcodeBoxBind">
insert into bm_qrcode_box_bind
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="maId != null">ma_id,</if>
<if test="boxId != null">box_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="maId != null">#{maId},</if>
<if test="boxId != null">#{boxId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateBmQrcodeStatus">
update bm_qrcode_box
<trim prefix="SET" suffixOverrides=",">
<if test="status != null and status != ''">box_status = IF(box_status = 1,#{status},box_status) ,</if>
</trim>
where box_id = #{boxId}
</update>
<select id="getBoxMaTypeList" resultType="java.lang.Long">
SELECT DISTINCT(mm.type_id) from bm_qrcode_box_bind qbb
LEFT JOIN ma_machine mm on mm.ma_id = qbb.ma_id
WHERE qbb.box_id = #{boxId}
</select>
<select id="existsMaId" resultType="int">
select count(1) from bm_qrcode_box_bind where ma_id = #{maId}
</select>
<select id="getBoxBindList" resultType="com.bonus.material.basic.domain.BmQrBoxInfo">
SELECT
qb.id as id, qb.box_id as boxId, qb.create_by as createBy, qb.create_time,
mt1.type_name as typeName,
mt.type_name as typeModelName,
mm.ma_id as maId,mm.ma_code as maCode,mm.type_id as maTypeId,
sdd.dict_label as maStatus
FROM
bm_qrcode_box_bind qb
LEFT JOIN ma_machine mm ON qb.ma_id = mm.ma_id
LEFT JOIN sys_dict_data sdd ON sdd.dict_type = 'ma_machine_status' and sdd.dict_value = mm.ma_status
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0'
<where>
qb.box_id = #{boxId}
</where>
</select>
2024-12-11 13:26:02 +08:00
</mapper>