迁移时间:2017年6月1日16:09:02

Author:Marydon

(四)IBATIS + ORACLE

    UpdateTime--2017年5月31日10:49:34

    第二部分:提升篇

新增&修改共用一个SQL

<!-- 新增和修改使用一个SQL语句搞定 -->
<insert id="saveTDICTICDCLASS" parameterClass="map">
DECLARE
n_count number(1);
BEGIN
SELECT count(1) INTO n_count FROM TDICTICDCLASS
WHERE FCLASSID=#FCLASSID#;
IF n_count=0 THEN
INSERT INTO TDICTICDCLASS(FCLASSID,FCLASSNAME,FICDFM,FPLVCODE)
VALUES(#FCLASSID:VARCHAR#,#FCLASSNAME:VARCHAR#,#FICDFM:VARCHAR#,#FPLVCODE:VARCHAR#);
ELSE
UPDATE TDICTICDCLASS
<dynamic prepend="SET">
<isNotEmpty prepend="," property="FCLASSID">FCLASSID=#FCLASSID#</isNotEmpty>
<isNotEmpty prepend="," property="FCLASSNAME">FCLASSNAME=#FCLASSNAME#</isNotEmpty>
<isNotNull prepend="," property="FICDFM">FICDFM=#FICDFM#</isNotNull>
<isNotEmpty prepend="," property="FPLVCODE">FPLVCODE=#FPLVCODE#</isNotEmpty>
</dynamic>
WHERE FCLASSID=#FCLASSID#;
END IF;
END;
</insert>

2022年2月7日10:59:01

说明:begin end块中只能添加insert、update、delete之类的,不能添加纯粹的select语句(可以使用select...into...)。

批量操作以排班表为例

    1.4.2.2 批量新增

    1.4.2.4 批量删除

     js取值方式,注意事项 同上

<delete id="delCONSULT_SCHEDULE" parameterClass="map">
DELETE FROM CONSULT_SCHEDULE WHERE CONSULT_SCHEDULE_ID IN ($CONSULT_SCHEDULE_ID$)
</delete>

    1.4.2.5 调用存储过程

     CreateTime--2017年1月10日10:42:49

      sqlmap文件配置

      第四步:Dao层获取返回数据        

/**
* 三目录对照错误信 息汇总查询
* @param mapParam
* @return
* @throws DaoException
*/
public List<Map<String, Object>> getSHEHE_ERROR_DATA(Map mapParam) throws DaoException {
List list = null;
try {
//用这两步实现接收返回数据
sqlMap.queryForList("xnh.config.orgitem.getSHEHE_ERROR_DATA", mapParam != null ? mapParam : new HashMap());
list = (List) mapParam.get("out_cur");
} catch (Exception e) {
String err = "查询出错->出错原因:" + e.getMessage();
log.error(err, e);
throw new DaoException(err, e);
}
return list;
}

2021年11月16日10:35:07

ibatis使用动态值使用$$包住参数值即可,如:

ZJM like '$ZJM$%'

IBATIS + ORACLE(二)_用户信息

2022年1月5日10:31:21

也可以

<isNotEmpty prepend="and" property="CHINESENAME">
T.CHINESENAME like CONCAT(#CHINESENAME#,'%')
</isNotEmpty>

2021年11月24日18:31:02

Oracle还可以使用管道符

<isNotEmpty prepend="and" property="AccessType">
T.ACCESSID like #AccessType# || '%'
</isNotEmpty>

2022年4月26日10:40:48

复杂SQL

查看代码

<!-- 根据医生表数据添加用户和绑定关系 -->
<insert id="saveBASE_AC_USER_BY_DOCTOR" parameterClass="map">
DECLARE
V_CNT INT;
T_FID NUMBER;
T_ORGID NUMBER;
T_USERID NUMBER;
T_USERCODE VARCHAR2(64);
T_THEME VARCHAR2(32) DEFAULT 'xixian';
T_HOME VARCHAR2(32) DEFAULT 'index3';
BEGIN
SELECT COUNT(1) INTO V_CNT FROM TDOCTORORG T WHERE T.FID = #FID#;
IF V_CNT = 0 THEN
RAISE_APPLICATION_ERROR(-20000, '医师信息查询不到!');
END IF;
SELECT FID, FORGID, nvl(T.FDOCTORPHONE,'') INTO T_FID, T_ORGID, T_USERCODE
FROM TDOCTORORG T
WHERE FID = #FID#;

IF LENGTH(T_USERCODE) != 11 THEN
RAISE_APPLICATION_ERROR(-20000, '医师的手机号不符合创建系统用户要求!');
END IF;
<!-- 查询用户账号-唯一 2022.04.25 -->
SELECT COUNT(1) INTO V_CNT FROM BASE_AC_USER T WHERE T.USERCODE = T_USERCODE;
IF V_CNT > 0 THEN
RAISE_APPLICATION_ERROR(-20000, '医师手机号[' || T_USERCODE || ']已创建系统用户信息,请联系售后核对!');
END IF;

<!-- 查询是否专家成员 -->
SELECT COUNT(1) INTO V_CNT FROM BASE_EXPERT_TEAM T WHERE T.FPERSONID = T_FID ;
IF V_CNT > 0 THEN
t_HOME := 'index2';
END IF;

SELECT SEQ_BASE_AC_USER.NEXTVAL INTO T_USERID FROM DUAL;
<!-- 新增用户信息 -->
INSERT INTO BASE_AC_USER
(USERID, USERCODE, USERNAME, USERPASSWORD, STATUS,
CREATEDATE, ORGID, USERTEL, THEME, HOME,
AREACODE, ORGCODE, USERMOBILE, USERIDCARD)
SELECT T_USERID AS USERID, T.FDOCTORPHONE AS USERCODE,
T.FDOCTORNAME AS USERNAME, #USERPASSWORD# USERPASSWORD, NVL(#STATUS#,3) STATUS,
SYSDATE AS CREATEDATE, T.FORGID AS ORGID,
T.FDOCTORPHONE AS USERTEL, T_THEME AS THEME, T_HOME AS HOME,
T.FRCODE AS AREACODE, T.FRCODE AS ORGCODE,
T.FDOCTORPHONE AS USERMOBILE, T.FCARDID AS USERIDCARD
FROM TDOCTORORG T
WHERE T.FID = T_FID;
<!-- 添加绑定信息 -->
INSERT INTO BASE_USER_DOCTOR
SELECT T_USERID, T_ORGID, T_FID FROM DUAL;
END;
</insert>
<!-- 根据医生表的联系电话,更新用户账号 -->
<update id="updateBASE_AC_USER_BY_DOCTOR" parameterClass="map">
DECLARE
V_CNT INT;
T_FID NUMBER;
T_NEW_PHONE VARCHAR2(64);
T_USERID NUMBER;
T_FDOCTORPHONE VARCHAR2(11);
T_USERCODE VARCHAR2(64);
BEGIN
T_FID := #FID# ;
T_NEW_PHONE := #NEW_PHONE#;

SELECT COUNT(1) INTO V_CNT FROM TDOCTORORG T WHERE T.FID = T_FID;
IF V_CNT = 0 THEN
RAISE_APPLICATION_ERROR(-20000, '医师信息查询不到!');
END IF;
SELECT T.FDOCTORPHONE INTO T_FDOCTORPHONE FROM TDOCTORORG T WHERE T.FID = T_FID;

SELECT COUNT(1) INTO V_CNT FROM BASE_USER_DOCTOR T WHERE T.FDOCTORID = T_FID;
IF V_CNT = 0 THEN
RETURN;
END IF;

IF V_CNT > 1 THEN
RAISE_APPLICATION_ERROR(-20000, '当前医生绑定了多条用户信息,请联系管理员重新维护!');
END IF;

SELECT COUNT(1) INTO V_CNT
FROM BASE_AC_USER T, BASE_USER_DOCTOR T1
WHERE T.USERID = T1.FUSERID AND T1.FDOCTORID = T_FID;
IF V_CNT = 0 THEN
RETURN;
END IF;

SELECT USERCODE,USERID INTO T_USERCODE,T_USERID
FROM BASE_AC_USER T, BASE_USER_DOCTOR T1
WHERE T.USERID = T1.FUSERID AND T1.FDOCTORID = T_FID;
<!--要更新的用户账号和当前医生手机号不相同,停止更新-->
IF T_FDOCTORPHONE != T_USERCODE THEN
RETURN;
END IF;
<!--新的手机号是否有用户注册,已经被注册停止更新 -->
SELECT COUNT(1) INTO v_cnt FROM BASE_AC_USER T WHERE USERCODE = T_NEW_PHONE;
IF v_cnt =0 THEN
UPDATE BASE_AC_USER
SET USERCODE = T_NEW_PHONE
WHERE USERID = T_USERID;
END IF;
END;
</update>

 

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

作者:​​Marydon​​