diff --git a/src/main/resources/sql/mapper/file-mapper.xml b/src/main/resources/sql/mapper/file-mapper.xml new file mode 100644 index 0000000..55f5dc6 --- /dev/null +++ b/src/main/resources/sql/mapper/file-mapper.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + +SELECT INF_TYPE + , CONCAT('files/', DIR, DATE_FORMAT(CURRENT_DATE, '/%Y/%m/%d/')) DIR + FROM ( + SELECT '010' INF_TYPE, 'interface/attachment/smg' DIR UNION + SELECT '020' INF_TYPE, 'interface/attachment/saeol' DIR UNION + SELECT '030' INF_TYPE, 'interface/attachment/epost' DIR UNION + + SELECT '100' INF_TYPE, 'attachment/violation' DIR UNION + SELECT '110' INF_TYPE, 'attachment/opinion' DIR UNION + SELECT '190' INF_TYPE, 'attachment/capture' DIR + ) FILE_DIRS + + + +SELECT A.*, FILE_PATH URL + FROM TB_FILE A + WHERE FILE_ID IN (#{fileID}) + ORDER BY FILE_ID + +SELECT A.*, FILE_PATH URL + FROM TB_FILE A + + AND A.INF_TYPE = #{infoType} + AND INF_KEY IN (#{infoKey}) + AND USE_YN = 'Y' + + + + + + + + + + +/* 파일 등록(fileMapper.insertFile) */ + +SELECT NEW_ID, CONCAT(DIR, NEW_ID, '.', #{file.extension}) PATH + FROM ( + SELECT IFNULL(MAX(FILE_ID) + 1, CONCAT(THIS_DAY, '00001')) NEW_ID + FROM TB_FILE A, () B + WHERE FILE_ID LIKE CONCAT(THIS_DAY, '%') + ) T1, ( + + WHERE INF_TYPE = #{file.infoType} + ) T2 +INSERT INTO TB_FILE ( + FILE_ID + , INF_TYPE + , INF_KEY + , SUB_TYPE + , FILE_NM + , FILE_PATH + , MIME_TYPE + , FILE_SIZE + , DNLD_CNT + , SRT_ORD + , RGTR + , REG_DT + , USE_YN +) VALUES ( + #{file.id} + , #{file.infoType} + , #{file.infoKey} + , #{file.subType} + , #{file.name} + , #{file.path} + , #{file.mimeType} + , #{file.size} + , #{file.downloadCount} + , #{file.sortOrder} + , #{currentUser.id} + , + , 'Y' +) + + +/* 파일 순서 변경(fileMapper.reorder) */ +UPDATE TB_FILE SET + SRT_ORD = CASE FILE_ID + WHEN #{fileID} THEN #{index} + + ELSE SRT_ORD END +WHERE FILE_ID IN (#{fileID}) + +/* 다운로드 횟수 증가(fileMapper.updateDownloadCount) */ +UPDATE TB_FILE SET + DNLD_CNT = DNLD_CNT + 1 + WHERE USE_YN = 'Y' + AND FILE_ID IN (#{fileID}) + +/* 파일 제거(fileMapper.removeFiles) */ +UPDATE TB_FILE SET + USE_YN = 'N' + WHERE USE_YN = 'Y' + AND FILE_ID IN (#{fileID}) + + AND INF_TYPE = #{infoType} + AND INF_KEY IN (#{infoKey}) + +/* 파일 삭제(fileMapper.deleteFiles) */ +DELETE FROM TB_FILE +WHERE FILE_ID IN (#{fileID}) + + + \ No newline at end of file