Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/codeCollection/WsMaInfoMapper.xml

209 lines
7.2 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.bonus.material.codeCollection.mapper.WsMaInfoMapper">
<resultMap id="BaseResultMap" type="com.bonus.material.codeCollection.domain.WsMaInfo">
<id column="id" property="id"/>
<result column="ma_name" property="maName"/>
<result column="ma_model" property="maModel"/>
<result column="ma_code" property="maCode"/>
<result column="supplier" property="supplier"/>
<result column="this_check_time" property="thisCheckTime"/>
<result column="next_check_time" property="nextCheckTime"/>
<result column="repair_man" property="repairMan"/>
<result column="check_man" property="checkMan"/>
<result column="phone" property="phone"/>
<result column="result" property="result"/>
<result column="type" property="type"/>
<result column="model_id" property="modelId"/>
<result column="is_active" property="isActive"/>
<result column="opt_user" property="optUser"/>
<result column="opt_time" property="optTime"/>
</resultMap>
<select id="selectById" resultMap="BaseResultMap">
SELECT id,
ma_name,
ma_model,
ma_code,
supplier,
DATE(now()) as this_check_time,
DATE(DATE_SUB(DATE_ADD(NOW(), INTERVAL 1 YEAR), INTERVAL 1 DAY)) as next_check_time,
repair_man,
check_man,
phone,
result,
type,
model_id,
is_active,
opt_user,
opt_time
FROM ws_ma_info
WHERE id = #{id}
</select>
<select id="getMaTypeData" resultType="java.util.Map">
SELECT type_id AS id,
type_name AS `name`
FROM ma_type
WHERE `level` = '3'
AND del_flag = '0'
and is_enter = '1'
</select>
<select id="getMaModeData" resultType="java.util.Map">
SELECT type_id AS id,
type_name AS `name`
FROM ma_type
WHERE parent_id = #{parentId}
AND del_flag = '0'
</select>
<select id="getSupplier" resultType="java.util.Map">
SELECT supplier_id AS id,
supplier AS `name`
FROM ma_supplier_info
WHERE del_flag = '0'
</select>
<select id="existsByModelAndCode" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM ws_ma_info
WHERE
ma_code = #{maCode}
</select>
<select id="selectAll" resultType="com.bonus.material.codeCollection.domain.WsMaInfo">
SELECT * FROM (
SELECT
id AS id,
ma_code AS maCode,
ma_name AS maName,
LEFT(next_check_time, 10) AS nextCheckTime,
LEFT(this_check_time, 10) AS thisCheckTime,
ma_model AS maModel,
repair_man AS repairMan
FROM
ws_ma_info
<where>
<if test="maCode != null and maCode != ''">
and (ma_code like concat('%', #{maCode}, '%')
or qr_code = #{maCode})
</if>
</where>
LIMIT 10
) AS t1
UNION ALL
SELECT * FROM (
SELECT
mm.ma_id AS id,
mm.ma_code AS maCode,
mt1.type_name AS maName,
LEFT(mm.next_check_time, 10) AS nextCheckTime,
LEFT(mm.this_check_time, 10) AS thisCheckTime,
mt.type_name AS maModel,
mm.check_man AS repairMan
FROM
ma_machine mm
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt1.type_id = mt.parent_id
<where>
<if test="maCode != null and maCode != ''">
and (mm.ma_code like concat('%', #{maCode}, '%')
or mm.qr_code = #{maCode})
</if>
</where>
LIMIT 10
) AS t2
</select>
<select id="getGadgetList" resultType="com.bonus.material.codeCollection.domain.WsMaInfo">
SELECT id,
ma_name AS maName,
ma_model AS maModel,
ma_code AS maCode,
this_check_time AS thisCheckTime,
next_check_time AS nextCheckTime,
repair_man AS repairMan,
check_man AS checkMan,
phone,
result
FROM ws_ma_info wmi
WHERE is_active = '1'
<if test="keyWord != null and keyWord != ''">
and ( ma_name like concat('%', #{keyWord}, '%') or
ma_model like concat('%', #{keyWord}, '%') or
ma_code like concat('%', #{keyWord}, '%') or
repair_man like concat('%', #{keyWord}, '%') or
check_man like concat('%', #{keyWord}, '%')
)
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[
and (
DATE_FORMAT( this_check_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} or
DATE_FORMAT( next_check_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
)
]]>
</if>
</select>
<insert id="insert" parameterType="com.bonus.material.codeCollection.domain.WsMaInfo" useGeneratedKeys="true"
keyProperty="id">
INSERT INTO ws_ma_info (ma_name, ma_model, ma_code, supplier, this_check_time, next_check_time,
repair_man, check_man, phone, result, type, model_id, is_active, opt_user, opt_time, qr_code)
VALUES (#{maName}, #{maModel}, #{maCode}, #{supplier}, DATE(now()),
DATE(DATE_SUB(DATE_ADD(NOW(), INTERVAL 1 YEAR), INTERVAL 1 DAY)),
#{repairMan}, #{checkMan}, #{phone}, #{result}, #{type}, #{modelId}, #{isActive}, #{optUser}, now(), #{qrCode})
</insert>
<update id="update" parameterType="com.bonus.material.codeCollection.domain.WsMaInfo">
UPDATE ws_ma_info
SET ma_name = #{maName},
ma_model = #{maModel},
ma_code = #{maCode},
supplier = #{supplier},
this_check_time = #{thisCheckTime},
next_check_time = #{nextCheckTime},
repair_man = #{repairMan},
check_man = #{checkMan},
phone = #{phone},
result = #{result},
type = #{type},
model_id = #{modelId},
is_active = #{isActive},
opt_user = #{optUser},
opt_time = #{optTime}
WHERE id = #{id}
</update>
<update id="updateCheckTime">
<!-- 更新 ws_ma_info 表 -->
UPDATE ws_ma_info
SET this_check_time = #{thisCheckTime},
next_check_time = #{nextCheckTime},
opt_time = NOW()
WHERE ma_code = #{maCode};
<!-- 更新 ma_machine 表 -->
UPDATE ma_machine
SET this_check_time = #{thisCheckTime},
next_check_time = #{nextCheckTime},
update_time = NOW()
WHERE ma_code = #{maCode}
</update>
<delete id="deleteById" parameterType="int">
DELETE
FROM ws_ma_info
WHERE id = #{id}
</delete>
</mapper>