[Spring][쇼핑몰 프로젝트][30] (이미지 존재) 상품 정보 삭제 코드 보완

https://kimvampa.tistory.com/243
This commit is contained in:
SeoJin Kim
2021-08-11 11:35:45 +09:00
parent 47e2d4ba3b
commit 89fdadbdad
16 changed files with 158 additions and 3 deletions

View File

@@ -5,6 +5,8 @@ import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -139,6 +141,30 @@ public class AdminController {
logger.info("goodsDeletePOST..........");
List<AttachImageVO> fileList = adminService.getAttachInfo(bookId);
if(fileList != null) {
List<Path> pathList = new ArrayList();
fileList.forEach(vo ->{
// 원본 이미지
Path path = Paths.get("C:\\upload", vo.getUploadPath(), vo.getUuid() + "_" + vo.getFileName());
pathList.add(path);
// 섬네일 이미지
path = Paths.get("C:\\upload", vo.getUploadPath(), "s_" + vo.getUuid()+"_" + vo.getFileName());
pathList.add(path);
});
pathList.forEach(path ->{
path.toFile().delete();
});
}
int result = adminService.goodsDelete(bookId);
rttr.addFlashAttribute("delete_result", result);

View File

@@ -39,4 +39,7 @@ public interface AdminMapper {
/* 어제자 날짜 이미지 리스트 */
public List<AttachImageVO> checkFileList();
/* 지정 상품 이미지 정보 얻기 */
public List<AttachImageVO> getAttachInfo(int bookId);
}

View File

@@ -2,6 +2,7 @@ package com.vam.service;
import java.util.List;
import com.vam.model.AttachImageVO;
import com.vam.model.BookVO;
import com.vam.model.CateVO;
import com.vam.model.Criteria;
@@ -29,4 +30,7 @@ public interface AdminService {
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
/* 지정 상품 이미지 정보 얻기 */
public List<AttachImageVO> getAttachInfo(int bookId);
}

View File

@@ -102,13 +102,28 @@ public class AdminServiceImpl implements AdminService {
return result;
}
/* 상품 정보 삭제 */
@Override
@Transactional
public int goodsDelete(int bookId) {
log.info("goodsDelete..........");
adminMapper.deleteImageAll(bookId);
return adminMapper.goodsDelete(bookId);
}
/* 지정 상품 이미지 정보 얻기 */
@Override
public List<AttachImageVO> getAttachInfo(int bookId) {
log.info("getAttachInfo........");
return adminMapper.getAttachInfo(bookId);
}
}

View File

@@ -108,5 +108,12 @@
select * from vam_image where uploadpath = to_char(sysdate -1, 'yyyy\mm\dd')
</select>
<!-- 지정 상품 이미지 정보 얻기 -->
<select id="getAttachInfo" resultType="com.vam.model.AttachImageVO">
select * from vam_image where bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,6 +1,8 @@
package com.vam.mapper;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,7 +10,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.vam.model.AttachImageVO;
import com.vam.model.BookVO;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -164,12 +165,26 @@ public class AdminMapperTests {
*/
/* 어제자 날짜 이미지 리스트 */
/*
@Test
public void checkImageListTest() {
mapper.checkFileList();
}
*/
/* 지정 상품 이미지 정보 얻기 */
@Test
public void getAttachInfoTest() {
int bookId = 3141;
List<AttachImageVO> list = mapper.getAttachInfo(bookId);
System.out.println("list : " + list);
}

View File

@@ -108,5 +108,12 @@
select * from vam_image where uploadpath = to_char(sysdate -1, 'yyyy\mm\dd')
</select>
<!-- 지정 상품 이미지 정보 얻기 -->
<select id="getAttachInfo" resultType="com.vam.model.AttachImageVO">
select * from vam_image where bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Sun Jul 25 23:04:40 KST 2021
#Wed Aug 11 10:43:19 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
m2e.projectName=VamPa
groupId=com.vam

View File

@@ -5,6 +5,8 @@ import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -139,6 +141,31 @@ public class AdminController {
logger.info("goodsDeletePOST..........");
List<AttachImageVO> fileList = adminService.getAttachInfo(bookId);
if(fileList != null) {
List<Path> pathList = new ArrayList();
fileList.forEach(vo ->{
// 원본 이미지
Path path = Paths.get("C:\\upload", vo.getUploadPath(), vo.getUuid() + "_" + vo.getFileName());
pathList.add(path);
// 섬네일 이미지
path = Paths.get("C:\\upload", vo.getUploadPath(), "s_" + vo.getUuid()+"_" + vo.getFileName());
pathList.add(path);
});
pathList.forEach(path ->{
path.toFile().delete();
});
}
int result = adminService.goodsDelete(bookId);
rttr.addFlashAttribute("delete_result", result);

View File

@@ -39,4 +39,7 @@ public interface AdminMapper {
/* 어제자 날짜 이미지 리스트 */
public List<AttachImageVO> checkFileList();
/* 지정 상품 이미지 정보 얻기 */
public List<AttachImageVO> getAttachInfo(int bookId);
}

View File

@@ -2,6 +2,7 @@ package com.vam.service;
import java.util.List;
import com.vam.model.AttachImageVO;
import com.vam.model.BookVO;
import com.vam.model.CateVO;
import com.vam.model.Criteria;
@@ -29,4 +30,7 @@ public interface AdminService {
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
/* 지정 상품 이미지 정보 얻기 */
public List<AttachImageVO> getAttachInfo(int bookId);
}

View File

@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.vam.mapper.AdminMapper;
import com.vam.model.AttachImageVO;
import com.vam.model.BookVO;
import com.vam.model.CateVO;
import com.vam.model.Criteria;
@@ -99,11 +100,23 @@ public class AdminServiceImpl implements AdminService {
/* 상품 정보 삭제 */
@Override
@Transactional
public int goodsDelete(int bookId) {
log.info("goodsDelete..........");
adminMapper.deleteImageAll(bookId);
return adminMapper.goodsDelete(bookId);
}
/* 지정 상품 이미지 정보 얻기 */
@Override
public List<AttachImageVO> getAttachInfo(int bookId) {
log.info("getAttachInfo........");
return adminMapper.getAttachInfo(bookId);
}
}

View File

@@ -97,6 +97,13 @@
select * from vam_image where uploadpath = DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y\%m\%d')
</select>
<!-- 지정 상품 이미지 정보 얻기 -->
<select id="getAttachInfo" resultType="com.vam.model.AttachImageVO">
select * from vam_image where bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,11 +1,14 @@
package com.vam.mapper;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.vam.model.AttachImageVO;
import com.vam.model.BookVO;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -164,12 +167,26 @@ public class AdminMapperTests {
*/
/* 어제자 날짜 이미지 리스트 */
/*
@Test
public void checkImageListTest() {
mapper.checkFileList();
}
*/
/* 지정 상품 이미지 정보 얻기 */
@Test
public void getAttachInfoTest() {
int bookId = 3076;
List<AttachImageVO> list = mapper.getAttachInfo(bookId);
System.out.println("list : " + list);
}

View File

@@ -97,6 +97,13 @@
select * from vam_image where uploadpath = DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y\%m\%d')
</select>
<!-- 지정 상품 이미지 정보 얻기 -->
<select id="getAttachInfo" resultType="com.vam.model.AttachImageVO">
select * from vam_image where bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Sun Jul 25 23:15:48 KST 2021
#Wed Aug 11 10:43:21 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
m2e.projectName=VamPa_MySQL
groupId=com.vam