Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
</parent>

<dependencies>
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.9.0</version> <scope>test</scope>
</dependency>
<!-- spring boot dependency start -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -471,4 +476,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
36 changes: 15 additions & 21 deletions src/main/java/egovframework/com/cmm/service/impl/FileManageDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* 수정일 수정자 수정내용
* ------- ------- -------------------
* 2009. 3. 25. 이삼섭 최초생성
* 2025. 9. 26. 박준규 쿼리 n+1 개선
*
* @author 공통 서비스 개발팀 이삼섭
* @since 2009. 3. 25.
Expand All @@ -34,17 +35,17 @@ public class FileManageDAO extends EgovAbstractMapper {
* @throws Exception
*/
public String insertFileInfs(List<?> fileList) throws Exception {
FileVO vo = (FileVO) fileList.get(0);
String atchFileId = vo.getAtchFileId();

insert("FileManageDAO.insertFileMaster", vo);
if (fileList == null || fileList.isEmpty()) {
return null;
}

Iterator<?> iter = fileList.iterator();
while (iter.hasNext()) {
vo = (FileVO) iter.next();
// 1. 마스터 정보는 첫 번째 파일 기준으로 한 번만 등록
FileVO masterVO = (FileVO) fileList.get(0);
String atchFileId = masterVO.getAtchFileId();
insert("FileManageDAO.insertFileMaster", masterVO);

insert("FileManageDAO.insertFileDetail", vo);
}
// 2. 상세 정보는 리스트 전체를 Bulk Insert
insert("FileManageDAO.insertFileDetail_bulk", fileList);

return atchFileId;
}
Expand All @@ -67,12 +68,9 @@ public void insertFileInf(FileVO vo) throws Exception {
* @throws Exception
*/
public void updateFileInfs(List<?> fileList) throws Exception {
FileVO vo;
Iterator<?> iter = fileList.iterator();
while (iter.hasNext()) {
vo = (FileVO) iter.next();

insert("FileManageDAO.insertFileDetail", vo);
if (fileList != null && !fileList.isEmpty()) {
// MySQL의 ON DUPLICATE KEY UPDATE를 활용하여 Bulk Upsert(Update or Insert) 처리
insert("FileManageDAO.updateFileDetail_bulk", fileList);
}
}

Expand All @@ -83,12 +81,8 @@ public void updateFileInfs(List<?> fileList) throws Exception {
* @throws Exception
*/
public void deleteFileInfs(List<?> fileList) throws Exception {
Iterator<?> iter = fileList.iterator();
FileVO vo;
while (iter.hasNext()) {
vo = (FileVO) iter.next();

delete("FileManageDAO.deleteFileDetail", vo);
if (fileList != null && !fileList.isEmpty()) {
delete("FileManageDAO.deleteFileDetail_bulk", fileList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>
</select>

<delete id="FileManageDAO.deleteFileDetail_bulk" parameterType="java.util.List">
DELETE FROM LETTNFILEDETAIL
WHERE (ATCH_FILE_ID, FILE_SN) IN
<foreach item="file" collection="list" open="(" separator="," close=")">
(#{file.atchFileId}, #{file.fileSn})
</foreach>
</delete>

</mapper>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>
</select>

<delete id="FileManageDAO.deleteFileDetail_bulk" parameterType="java.util.List">
DELETE FROM LETTNFILEDETAIL
WHERE (ATCH_FILE_ID, FILE_SN) IN
<foreach item="file" collection="list" open="(" separator="," close=")">
(#{file.atchFileId}, #{file.fileSn})
</foreach>
</delete>

</mapper>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>

</mapper>
</select>

<delete id="FileManageDAO.deleteFileDetail_bulk" parameterType="java.util.List">
DELETE FROM LETTNFILEDETAIL
WHERE (ATCH_FILE_ID, FILE_SN) IN
<foreach item="file" collection="list" open="(" separator="," close=")">
(#{file.atchFileId}, #{file.fileSn})
</foreach>
</delete>

</mapper>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="FileManageDAO">

Expand All @@ -13,7 +13,7 @@
<result property="fileStreCours" column="FILE_STRE_COURS"/>
<result property="orignlFileNm" column="ORIGNL_FILE_NM"/>
<result property="streFileNm" column="STRE_FILE_NM"/>
<result property="creatDt" column="CREAT_DT"/>
<result property="creatDt" column="CREAT_DT"/>
</resultMap>

<resultMap id="fileDetail" type="egovframework.com.cmm.service.FileVO">
Expand All @@ -25,146 +25,178 @@
<result property="fileStreCours" column="FILE_STRE_COURS"/>
<result property="orignlFileNm" column="ORIGNL_FILE_NM"/>
<result property="streFileNm" column="STRE_FILE_NM"/>
</resultMap>
</resultMap>


<select id="FileManageDAO.selectFileList" parameterType="FileVO" resultMap="fileList">
SELECT

SELECT
a.ATCH_FILE_ID, b.FILE_CN, b.FILE_SN, b.FILE_STRE_COURS, b.STRE_FILE_NM,
b.FILE_EXTSN, b.ORIGNL_FILE_NM, b.FILE_SIZE, a.CREAT_DT
FROM
LETTNFILE a, LETTNFILEDETAIL b
WHERE
a.ATCH_FILE_ID = #{atchFileId}
AND
AND
a.ATCH_FILE_ID = b.ATCH_FILE_ID
AND
a.USE_AT = 'Y'
ORDER BY b.FILE_SN
AND
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>

<insert id="FileManageDAO.insertFileMaster" parameterType="FileVO">

INSERT INTO LETTNFILE
(ATCH_FILE_ID, CREAT_DT, USE_AT)
VALUES
( #{atchFileId}, SYSDATE(), 'Y')
( #{atchFileId}, SYSDATE(), 'Y')

</insert>

<insert id="FileManageDAO.insertFileDetail" parameterType="FileVO">

INSERT INTO LETTNFILEDETAIL
( ATCH_FILE_ID, FILE_SN, FILE_STRE_COURS, STRE_FILE_NM,
( ATCH_FILE_ID, FILE_SN, FILE_STRE_COURS, STRE_FILE_NM,
ORIGNL_FILE_NM, FILE_EXTSN, FILE_SIZE, FILE_CN )
VALUES
( #{atchFileId}, #{fileSn}, #{fileStreCours}, #{streFileNm},
#{orignlFileNm}, #{fileExtsn}, #{fileMg}, #{fileCn} )
</insert>
( #{atchFileId}, #{fileSn}, #{fileStreCours}, #{streFileNm},
#{orignlFileNm}, #{fileExtsn}, #{fileMg}, #{fileCn} )

</insert>

<delete id="FileManageDAO.deleteFileDetail" parameterType="FileVO">

DELETE FROM LETTNFILEDETAIL
WHERE
ATCH_FILE_ID = #{atchFileId}
AND
FILE_SN = #{fileSn}
AND
FILE_SN = #{fileSn}

</delete>

<select id="FileManageDAO.getMaxFileSN" parameterType="FileVO" resultType="java.lang.Integer">

SELECT IFNULL(MAX(FILE_SN),0)+1 AS FILE_SN
FROM LETTNFILEDETAIL
WHERE ATCH_FILE_ID = #{atchFileId}
WHERE ATCH_FILE_ID = #{atchFileId}

</select>

<select id="FileManageDAO.selectFileInf" parameterType="FileVO" resultMap="fileDetail">
SELECT

SELECT
ATCH_FILE_ID, FILE_CN, FILE_SN, FILE_STRE_COURS, STRE_FILE_NM,
FILE_EXTSN, ORIGNL_FILE_NM, FILE_SIZE
FROM
LETTNFILEDETAIL
WHERE
ATCH_FILE_ID = #{atchFileId}
AND
FILE_SN = #{fileSn}
AND
FILE_SN = #{fileSn}

</select>

<update id="FileManageDAO.deleteCOMTNFILE" parameterType="FileVO">

UPDATE LETTNFILE
SET USE_AT = 'N'
WHERE ATCH_FILE_ID = #{atchFileId}

</update>

<select id="FileManageDAO.selectFileListByFileNm" parameterType="FileVO" resultMap="fileList">
SELECT

SELECT
a.ATCH_FILE_ID, b.FILE_CN, b.FILE_SN, b.FILE_STRE_COURS, b.STRE_FILE_NM,
b.FILE_EXTSN, b.ORIGNL_FILE_NM, b.FILE_SIZE, a.CREAT_DT
FROM
LETTNFILE a, LETTNFILEDETAIL b
WHERE
a.ATCH_FILE_ID = b.ATCH_FILE_ID
AND
AND
a.USE_AT = 'Y'

<if test="searchCnd == &quot;streFileNm&quot;">AND
b.STRE_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
b.STRE_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>
<if test="searchCnd == &quot;orignlFileNm&quot;">AND
b.ORIGNL_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>
ORDER BY a.ATCH_FILE_ID, b.FILE_SN
b.ORIGNL_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>

ORDER BY a.ATCH_FILE_ID, b.FILE_SN
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}

</select>

<select id="FileManageDAO.selectFileListCntByFileNm" parameterType="FileVO" resultType="java.lang.Integer">
SELECT

SELECT
COUNT(a.ATCH_FILE_ID)
FROM
LETTNFILE a, LETTNFILEDETAIL b
WHERE
a.ATCH_FILE_ID = b.ATCH_FILE_ID
AND
a.USE_AT = 'Y'
AND
a.USE_AT = 'Y'

<if test="searchCnd == &quot;streFileNm&quot;">AND
b.STRE_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
b.STRE_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>
<if test="searchCnd == &quot;orignlFileNm&quot;">AND
b.ORIGNL_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>
b.ORIGNL_FILE_NM LIKE CONCAT ('%', #{searchWrd},'%')
</if>
</select>

<select id="FileManageDAO.selectImageFileList" parameterType="FileVO" resultMap="fileList">

SELECT
SELECT
a.ATCH_FILE_ID, b.FILE_CN, b.FILE_SN, b.FILE_STRE_COURS, b.STRE_FILE_NM,
b.FILE_EXTSN, b.ORIGNL_FILE_NM, b.FILE_SIZE, a.CREAT_DT
FROM
LETTNFILE a, LETTNFILEDETAIL b
WHERE
a.ATCH_FILE_ID = #{atchFileId}
AND
AND
a.ATCH_FILE_ID = b.ATCH_FILE_ID
AND
UPPER(b.FILE_EXTSN) IN ('GIF','JPG','BMP','PNG')
AND
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>

</mapper>
AND
a.USE_AT = 'Y'
ORDER BY b.FILE_SN

</select>

<insert id="FileManageDAO.insertFileDetail_bulk" parameterType="java.util.List">
INSERT INTO LETTNFILEDETAIL
(ATCH_FILE_ID, FILE_SN, FILE_STRE_COURS, STRE_FILE_NM, ORIGNL_FILE_NM, FILE_EXTSN, FILE_SIZE, FILE_CN)
VALUES
<foreach collection="list" item="file" separator=",">
(#{file.atchFileId}, #{file.fileSn}, #{file.fileStreCours}, #{file.streFileNm}, #{file.orignlFileNm}, #{file.fileExtsn}, #{file.fileMg}, #{file.fileCn})
</foreach>
</insert>

<insert id="FileManageDAO.updateFileDetail_bulk" parameterType="java.util.List">
INSERT INTO LETTNFILEDETAIL
(ATCH_FILE_ID, FILE_SN, FILE_STRE_COURS, STRE_FILE_NM, ORIGNL_FILE_NM, FILE_EXTSN, FILE_SIZE, FILE_CN)
VALUES
<foreach collection="list" item="file" separator=",">
(#{file.atchFileId}, #{file.fileSn}, #{file.fileStreCours}, #{file.streFileNm}, #{file.orignlFileNm}, #{file.fileExtsn}, #{file.fileMg}, #{file.fileCn})
</foreach>
ON DUPLICATE KEY UPDATE
FILE_STRE_COURS = VALUES(FILE_STRE_COURS),
STRE_FILE_NM = VALUES(STRE_FILE_NM),
ORIGNL_FILE_NM = VALUES(ORIGNL_FILE_NM),
FILE_EXTSN = VALUES(FILE_EXTSN),
FILE_SIZE = VALUES(FILE_SIZE),
FILE_CN = VALUES(FILE_CN)
</insert>

<delete id="deleteFileDetail_bulk" parameterType="java.util.List">
DELETE FROM LETTNFILEDETAIL
WHERE (ATCH_FILE_ID, FILE_SN) IN
<foreach collection="list" item="file" open="(" separator="," close=")">
(#{file.atchFileId}, #{file.fileSn})
</foreach>
</delete>

</mapper>
Loading