调用存储过程msql
/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.desk.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springblade.desk.entity.OaSerial; import java.util.HashMap; /** * Mapper 接口 * * @author Chill */ public interface OaSerialMapper extends BaseMapper<OaSerial> { public HashMap<String,Object> getSerial(@Param("tenantId") String tenantId,@Param("module") String module, @Param("dateStr") String dateStr, @Param("prefix") String prefix, @Param("serialLength") int serialLength); }
mapper.xml文件
<mapper namespace="org.springblade.desk.mapper.OaSerialMapper"> <select id="getSerial" resultType="java.util.HashMap" statementType="CALLABLE"> { call get_module_serial_code(#{tenantId},#{module},#{dateStr},#{prefix},#{serialLength}) } </select> </mapper>
CREATE DEFINER=`root`@`%` PROCEDURE `get_module_serial_code`(IN `p_tenant_id` varchar(20),IN `p_module` varchar(100),IN `p_date` varchar(20),IN `p_prefix` varchar(20),IN `p_serial_length` int) BEGIN declare p_is_success varchar(10) default 0 ; declare l_serial varchar(100); DECLARE t_error INTEGER DEFAULT 0; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; start transaction; begin begin IF EXISTS( select 1 from oa_serial where module=p_module and tenant_id = p_tenant_id lock in share mode) then IF EXISTS( select 1 from oa_serial where module=p_module and date_str=p_date and tenant_id = p_tenant_id lock in share mode) then UPDATE oa_serial SET serial=right(concat('00000000', cast((cast(COALESCE(serial,'0') as signed) +1) as char)),p_serial_length) WHERE module=p_module and date_str=p_date and tenant_id = p_tenant_id ; ELSE UPDATE oa_serial SET serial = right('00000001',p_serial_length) , date_str=p_date WHERE module=p_module and tenant_id = p_tenant_id ; end if; ELSE INSERT INTO oa_serial ( tenant_id,module, date_str, serial) VALUES ( p_tenant_id,p_module,p_date,right('00000001',p_serial_length) ) ; end if; SELECT serial into l_serial FROM oa_serial WHERE module = p_module and date_str = p_date and tenant_id = p_tenant_id ; end; end; IF t_error = 1 THEN ROLLBACK; set p_is_success='-1'; ELSE COMMIT; set p_is_success='1'; END IF; if p_is_success = '1' then select concat(p_prefix,l_serial) l_serial,p_is_success ; else select null l_serial ,p_is_success; end if; END