Files
sake/build/resources/main/mybatis/xml/mapper/gcone/puri/BOPuriMapper.xml

448 lines
16 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.wb.domainserver.domain.gcone.puri.mapper.BOPuriMapper">
<!-- 정수기 판매 및 설치 내역 조회 WHERE 절 -->
<sql id="selectBOPuriOrderListFormWhere">
<![CDATA[
WHERE 1=1
AND gpo.status != 'delete'
]]>
<choose>
<when test="srchOrderDateType == 'purchsDe'">
<if test="sndngOrderReqstSDate != null and sndngOrderReqstEDate != null">
<![CDATA[
AND gpo.purchs_de between #{sndngOrderReqstSDate} AND #{sndngOrderReqstEDate}
]]>
</if>
</when>
<when test="srchOrderDateType == 'dlivyDe'">
<if test="sndngOrderReqstSDate != null and sndngOrderReqstEDate != null">
<![CDATA[
AND gpo.dlivy_de between #{sndngOrderReqstSDate} AND #{sndngOrderReqstEDate}
]]>
</if>
</when>
<when test="srchOrderDateType == 'visitDe'">
<if test="sndngOrderReqstSDate != null and sndngOrderReqstEDate != null">
<![CDATA[
AND gpo.visit_de between #{sndngOrderReqstSDate} AND #{sndngOrderReqstEDate}
]]>
</if>
</when>
</choose>
<choose>
<when test="srchOrderInfoType == 'purchsrNm'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.purchsr_nm = #{srchOrdrText}
]]>
</if>
</when>
<when test="srchOrderInfoType == 'cttpc'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.cttpc = HEX(AES_ENCRYPT(#{srchOrdrText}, #{secretKey}))
]]>
</if>
</when>
<when test="srchOrderInfoType == 'dlivyNm'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.dlivy_nm = #{srchOrdrText}
]]>
</if>
</when>
<when test="srchOrderInfoType == 'dlivyCttpc'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.dlivy_cttpc = HEX(AES_ENCRYPT(#{srchOrdrText}, #{secretKey}))
]]>
</if>
</when>
<when test="srchOrderInfoType == 'goodsCd'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.goods_cd = #{srchOrdrText}
]]>
</if>
</when>
<when test="srchOrderInfoType == 'erpCode'">
<if test="srchOrdrText != null and srchOrdrText != ''">
<![CDATA[
AND gpo.erp_code = #{srchOrdrText}
]]>
</if>
</when>
</choose>
<choose>
<when test="srchMallCdType != ''">
<![CDATA[
AND gpo.purchs_cd = #{srchMallCdType}
]]>
</when>
</choose>
<choose>
<when test="srchGoodsType != ''">
<![CDATA[
AND gpo.goods_cd = #{srchGoodsType}
]]>
</when>
</choose>
<choose>
<when test="srchVisitType != ''">
<![CDATA[
AND gpo.visit_trgter_at = #{srchVisitType}
]]>
</when>
</choose>
<choose>
<when test="srchAlimType != ''">
<![CDATA[
AND gpa.status = #{srchAlimType}
]]>
</when>
</choose>
<choose>
<when test="srchSndngType == 'installDe'">
<if test="sndngAllimReqstSDate != null and sndngAllimReqstEDate != null">
<![CDATA[
AND gpa.install_de between #{sndngAllimReqstSDate} AND #{sndngAllimReqstEDate}
]]>
</if>
</when>
<when test="srchSndngType == 'frstSndngDe'">
<if test="sndngAllimReqstSDate != null and sndngAllimReqstEDate != null">
<![CDATA[
AND gpa.frst_sndng_de between #{sndngAllimReqstSDate} AND #{sndngAllimReqstEDate}
]]>
</if>
</when>
<when test="srchSndngType == 'prevSndngDe'">
<if test="sndngAllimReqstSDate != null and sndngAllimReqstEDate != null">
<![CDATA[
AND gpa.prev_sndng_de between #{sndngAllimReqstSDate} AND #{sndngAllimReqstEDate}
]]>
</if>
</when>
<when test="srchSndngType == 'nextSndngResveDe'">
<if test="sndngAllimReqstSDate != null and sndngAllimReqstEDate != null">
<![CDATA[
AND gpa.next_sndng_resve_de between #{sndngAllimReqstSDate} AND #{sndngAllimReqstEDate}
]]>
</if>
</when>
</choose>
<choose>
<when test="srchAlimInfoType == 'cstmrNm'">
<if test="srchAllimText != null and srchAllimText != ''">
<![CDATA[
AND gpa.cstmr_nm = #{srchAllimText}
]]>
</if>
</when>
<when test="srchAlimInfoType == 'telnb'">
<if test="srchAllimText != null and srchAllimText != ''">
<![CDATA[
AND gpa.telnb = HEX(AES_ENCRYPT(#{srchAllimText}, #{secretKey}))
]]>
</if>
</when>
</choose>
</sql>
<select id="selectBOPuriOrderList"
parameterType="com.wb.domainserver.domain.gcone.puri.vo.BOPuriSrchVO"
resultType="dataMap">
<![CDATA[
SELECT
ROW_NUMBER() OVER (ORDER BY gpo.puri_order_seq DESC) AS rnum,
gpo.puri_order_seq,
gpo.status,
gpo.regist_dt,
gpo.erp_code,
gpo.purchs_dv,
gpo.purchs_cd,
gpo.purchs_nm,
gpo.ordr_cd,
gpo.purchs_de,
gpo.purchs_dtls,
gpo.ordr_rm,
CONCAT(LEFT(gpo.purchsr_nm, 1), '*', RIGHT(gpo.purchsr_nm, 1)) AS purchsr_nm,
gpo.purchsr_nm AS no_mask_purchsr_nm,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}), 3),
'-****-',
RIGHT(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}), 4)
) AS CHAR(50)
) AS cttpc,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}), 3),
'-',
SUBSTR(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}), 4, 4),
'-',
RIGHT(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}), 4)
) AS CHAR(50)
) AS no_mask_cttpc,
gpo.goods_cd,
gpo.goods_nm,
gpo.dlivy_de,
CONCAT(LEFT(gpo.dlivy_nm, 1), '*', RIGHT(gpo.dlivy_nm, 1)) AS dlivyNm,
gpo.dlivy_nm AS no_mask_dlivy_nm,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}), 3),
'-****-',
RIGHT(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}), 4)
) AS CHAR(50)
) AS dlivy_cttpc,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}), 3),
'-',
SUBSTR(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}), 4, 4),
'-',
RIGHT(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}), 4)
) AS CHAR(50)
) AS no_mask_dlivy_cttpc,
gpo.visit_trgter_at,
IF(gpo.visit_de > '2020-01-01', gpo.visit_de, NULL) AS visitDe,
gpa.puri_allim_seq,
CASE gpa.status
WHEN 'wait' THEN '대기'
WHEN 'send' THEN '발송'
WHEN 'stop' THEN '중지'
ELSE ''
END AS allimStatus,
gpa.cstmr_nm,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpa.telnb), #{secretKey}), 3),
'-',
SUBSTR(AES_DECRYPT(UNHEX(gpa.telnb), #{secretKey}), 4, 4),
'-',
RIGHT(AES_DECRYPT(UNHEX(gpa.telnb), #{secretKey}), 4)
) AS CHAR(50)
) AS noMasktelnb,
gpa.regist_dt AS allimRegistDt,
gpa.install_de,
IF(gpa.frst_sndng_de > '2020-01-01', gpa.frst_sndng_de, NULL) AS frstSndngDe,
IF(gpa.prev_sndng_de > '2020-01-01', gpa.prev_sndng_de, NULL) AS prevSndngDe,
IF(gpa.next_sndng_resve_de > '2020-01-01', gpa.next_sndng_resve_de, NULL) AS nextSndngResveDe
FROM
GC_PURI_ORDER gpo
LEFT JOIN
GC_PURI_ALLIM gpa ON (gpo.puri_order_seq = gpa.puri_order_seq)
LEFT JOIN
(SELECT puri_allim_seq, MAX(reg_date) AS latest_log_dt
FROM GC_PURI_ALLIM_LOG
GROUP BY puri_allim_seq) gpal ON (gpa.puri_allim_seq = gpal.puri_allim_seq)
]]>
<include refid = "selectBOPuriOrderListFormWhere"/>
<![CDATA[
ORDER BY gpo.puri_order_seq DESC
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
]]>
</select>
<select id="selectBOPuriOrderListCnt"
parameterType="com.wb.domainserver.domain.gcone.puri.vo.BOPuriSrchVO">
<![CDATA[
SELECT
COUNT(1)
FROM GC_PURI_ORDER gpo
LEFT JOIN GC_PURI_ALLIM gpa
ON (gpo.puri_order_seq = gpa.puri_order_seq)
]]>
<include refid = "selectBOPuriOrderListFormWhere"/>
</select>
<select id="selectPuriAllimList"
parameterType="com.wb.domainserver.domain.gcone.puri.vo.BOPuriSrchVO"
resultType="dataMap">
SELECT
@rownum := @rownum + 1 AS rnum,
gpal.sndng_de,
CAST(
CONCAT(
LEFT(AES_DECRYPT(UNHEX(gpal.telnb), #{secretKey}), 3),
'-',
SUBSTR(AES_DECRYPT(UNHEX(gpal.telnb), #{secretKey}), 4,4),
'-',
RIGHT(AES_DECRYPT(UNHEX(gpal.telnb), #{secretKey}), 4)
) AS CHAR(50)
) AS telnb,
gpal.sndng_cn
FROM (SELECT @rownum := 0) r,
GC_PURI_ALLIM_LOG gpal
WHERE puri_allim_seq = #{puriAllimSeq}
AND act = 'send'
</select>
<update id="updatePuriOrder">
UPDATE GC_PURI_ORDER set
status = #{status},
visit_trgter_at = #{visitTrgterAt},
ordr_rm = #{ordrRm}
WHERE puri_order_seq = #{puriOrderSeq}
</update>
<update id="updatePuriAllim">
UPDATE GC_PURI_ALLIM set
status = #{alimStatus},
cstmr_nm = #{cstmrNm},
telnb = HEX(AES_ENCRYPT(#{telnb}, #{secretKey})),
install_de = #{installDe}
WHERE puri_allim_seq = #{puriAllimSeq}
</update>
<insert id="insertPuriAllim">
INSERT INTO GC_PURI_ALLIM (status,regist_dt,puri_order_seq,cstmr_nm,telnb)
VALUES('wait',NOW(),#{puriOrderSeq},#{cstmrNm},HEX(AES_ENCRYPT(#{telnb}, #{secretKey})))
</insert>
<select id="selectPuriVisitUpdate">
SELECT
gpo.puri_order_seq AS puriOrderSeq,
gpo.purchsr_nm AS purchsrNm,
CAST(AES_DECRYPT(UNHEX(gpo.cttpc), #{secretKey}) AS CHAR(50)) AS cttpc,
gpo.visit_de as visitDe,
gpa.puri_allim_seq as puriAllimSeq,
gpa.install_de as installDe,
CAST(AES_DECRYPT(UNHEX(gpo.dlivy_cttpc), #{secretKey}) AS CHAR(50)) AS dlivyCttpc
FROM GC_PURI_ORDER gpo
LEFT JOIN GC_PURI_ALLIM gpa ON (gpo.puri_order_seq=gpa.puri_order_seq)
where gpo.ordr_cd = #{ordrCd}
</select>
<update id="updatePuriVisitDate" parameterType="map">
<foreach collection="puriOrderSeqArr" item="orderSeq" index="index" separator=";">
UPDATE GC_PURI_ORDER SET
visit_trgter_at = 'Y',
visit_de = #{realUpdateVisitDateArr[${index}]}
WHERE puri_order_seq = #{orderSeq}
</foreach>
</update>
<update id="updatePuriVisitCancelDate" parameterType="map">
<![CDATA[
UPDATE GC_PURI_ORDER SET
visit_trgter_at = 'N',
visit_de = ''
WHERE puri_order_seq in
]]>
<foreach collection="item.puriOrderSeqArr" item="seq" open="(" separator="," close=")">
#{seq}
</foreach>
</update>
<select id="selectDupPuriOrderAllimList">
<![CDATA[
select puri_order_seq, puri_allim_seq from GC_PURI_ALLIM
where puri_order_seq = #{puriOrderSeq}
]]>
</select>
<insert id="insertPuriAllimList">
<foreach collection="list" item="item" separator=";">
<![CDATA[
INSERT INTO gcone.GC_PURI_ALLIM (
STATUS,
REGIST_DT,
PURI_ORDER_SEQ,
CSTMR_NM,
TELNB,
INSTALL_DE,
NEXT_SNDNG_RESVE_DE,
CHNG_LOG
) VALUES (
#{item.status},
SYSDATE(),
#{item.puriOrderSeq},
#{item.cstmrNm},
HEX(AES_ENCRYPT(#{item.telnb}, #{item.secretKey})),
#{item.installDe},
#{item.nextSndngResveDe},
#{item.chngLog}
)
]]>
</foreach>
</insert>
<delete id="deletePuriAllim">
<foreach collection="list" item="item" separator=";">
<![CDATA[
delete from GC_PURI_ALLIM
where puri_allim_seq = #{item.puriAllimSeq}
]]>
</foreach>
</delete>
<update id="updatePuriAllimSeq" parameterType="java.util.List">
<foreach collection="list" item="item" separator=";">
<![CDATA[
UPDATE GC_PURI_ORDER SET PURI_ALLIM_SEQ = #{item.puriAllimSeq}
WHERE PURI_ORDER_SEQ = #{item.puriOrderSeq}
]]>
</foreach>
</update>
<select id="selectSameNumber">
<foreach collection="list" item="item" separator=";">
<![CDATA[
select puri_allim_seq from GC_PURI_ALLIM
where telnb = HEX(AES_ENCRYPT(#{item.telnb}, #{item.secretkey}))
and puri_allim_seq != #{item.puriOrderSeq}
and status in ('wait','send')
]]>
</foreach>
</select>
<insert id="insertPuriAllimLogFirst">
<foreach collection="list" item="item" separator=";">
<![CDATA[
insert into GC_PURI_ALLIM_LOG (reg_date,puri_allim_seq,act,telnb,sndng_de,sndng_ty,sndng_cn)
values (now(),#{item.puriAllimSeq},#{item.act},HEX(AES_ENCRYPT(#{item.telnb}, #{item.secretkey}),'','',#{item.sndngCn}))
]]>
</foreach>
</insert>
<update id="updateStopAllim">
<![CDATA[
UPDATE GC_PURI_ALLIM
SET status = 'stop',
chng_log = #{item.chngLog}
WHERE puri_allim_seq IN ]]>
<foreach collection="item.puriAllimSeq" item="seq" open="(" separator="," close=")">
#{seq}
</foreach>
</update>
</mapper>