<?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.jeeplus.test.mould.mapper.SerialnumTplMapper">

	<select id="pageList" resultType="com.jeeplus.test.mould.domain.SysSerialnumTpl">
		SELECT
			a.id,
			a.tpl_name,
			(SELECT b.`name` FROM sys_office b WHERE b.del_flag = 0 AND b.id = a.company_id ) AS company_name,
			a.biz_code,
			a.serial_num_len,
			a.serial_tpl_ex
		FROM
			sys_serialnum_tpl a
		${ew.customSqlSegment}
		ORDER BY create_date DESC
	</select>

	<select id="queryByComAndBizCode" resultType="com.jeeplus.test.mould.domain.SysSerialnumTpl">
		select	a.*
		 from sys_serialnum_tpl a
		where a.company_id = #{id} and a.biz_code = #{bizCode} and a.del_flag = 0
		order by update_date desc
		limit 1
	</select>

	<update id="resetSerialNum">
		UPDATE sys_serialnum_tpl
		SET serial_num = 0 , year_built = #{newYear}
		WHERE id = #{id} AND  year_built = #{yearBuilt}
	</update>

	<update id="updateSerialNum">
		UPDATE sys_serialnum_tpl
		SET serial_num = serial_num +1
		WHERE id = #{id}
	</update>
</mapper>
