<?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.chinaweal.aiccs.aiccs.inspect.mapper.TSWorkNoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.inspect.entity.TSWorkNo">
        <id column="WORKNOID" property="worknoid" />
        <result column="AICID" property="aicid" />
        <result column="ORGID" property="orgid" />
        <result column="DEPTID" property="deptid" />
        <result column="SHORTNAME" property="shortname" />
        <result column="CURRENTNO" property="currentNo" />
        <result column="YEARS" property="years" />
        <result column="WORKNOTYPE" property="workNoType" />
        <result column="TYPECOMMENT" property="typecomment" />
        <result column="GENRULE" property="genrule" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="AREA_CODE" property="areaCode" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        WORKNOID, AICID, ORGID, DEPTID, SHORTNAME, CURRENTNO, YEARS, WORKNOTYPE, TYPECOMMENT, GENRULE, LAUPTIME, AREA_CODE
    </sql>

    <update id="updateTSWorkNoByTypeComment" parameterType="com.chinaweal.aiccs.aiccs.inspect.entity.TSWorkNo">
        update TSWorkNo
        <set>
            <if test="currentNo != null">
                currentNo = #{currentNo}
            </if>
        </set>
        where workNoType = #{workNoType}
        <if test="aicid != null">
            and aicID = #{aicid}
        </if>
    </update>

    <select id="selectTSWorkNoListByTypeComment" resultMap="BaseResultMap" parameterType="com.chinaweal.aiccs.aiccs.inspect.entity.TSWorkNo">
        select <include refid="Base_Column_List"/> from TSWorkNo where workNoType = #{workNoType}
        <if test="aicid != null">
            and AICID = #{aicid}
        </if>
        order by "YEARS" desc
        limit 1
    </select>
</mapper>
