Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
0eac338a
Commit
0eac338a
authored
Oct 23, 2020
by
shoei.kanno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
商品管理画面、重複商品は個数を変更
parent
9eeaf4ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
62 deletions
+96
-62
ShoesRepository.java
src/main/java/com/example/repository/ShoesRepository.java
+7
-1
ShoesService.java
src/main/java/com/example/service/ShoesService.java
+5
-0
ManagementController.java
src/main/java/com/example/web/ManagementController.java
+84
-61
スニーカー3.jpg
src/main/resources/static/upload/スニーカー3.jpg
+0
-0
No files found.
src/main/java/com/example/repository/ShoesRepository.java
View file @
0eac338a
...
...
@@ -12,4 +12,9 @@ import com.example.domain.Shoes;
public
interface
ShoesRepository
extends
JpaRepository
<
Shoes
,
Integer
>{
@Query
(
value
=
"SELECT * FROM shoes WHERE product_status = ?1 ORDER BY id DESC"
,
nativeQuery
=
true
)
public
List
<
Shoes
>
findAllByStatus
(
Integer
status
);
}
//管理画面で使用
@Query
(
value
=
"SELECT * FROM shoes WHERE name = ?1 && size = ?2"
,
nativeQuery
=
true
)
public
Shoes
findOneAddStock
(
String
name
,
Integer
size
);
}
\ No newline at end of file
src/main/java/com/example/service/ShoesService.java
View file @
0eac338a
...
...
@@ -49,4 +49,9 @@ public class ShoesService {
public
List
<
Shoes
>
findAllLimitedShoes
()
{
return
shoesRepository
.
findAllByStatus
(
1
);
}
//管理画面、重複商品のバリデーション
public
Shoes
findOneAddStock
(
String
name
,
Integer
size
)
{
return
shoesRepository
.
findOneAddStock
(
name
,
size
);
};
}
src/main/java/com/example/web/ManagementController.java
View file @
0eac338a
...
...
@@ -57,67 +57,90 @@ public class ManagementController {
}
//靴の登録処理
@PostMapping
(
"addShoes"
)
public
String
CreateShoes
(
@Validated
ShoesForm
form
,
BindingResult
result
,
MultipartFile
multipartFile
)
throws
Exception
{
if
(
result
.
hasErrors
())
{
return
"management"
;
}
multipartFile
=
form
.
getMultipartFile
();
Shoes
shoes
=
new
Shoes
();
if
(!
multipartFile
.
isEmpty
())
{
try
{
// ファイル名をリネイム
File
oldFileName
=
new
File
(
multipartFile
.
getOriginalFilename
());
//File newFileName = new File(oldFileName + ".jpg");
//oldFileName.renameTo(newFileName);
// 保存先を定義
String
uploadPath
=
"src/main/resources/static/upload/"
;
byte
[]
bytes
=
multipartFile
.
getBytes
();
// 指定ファイルへ読み込みファイルを書き込み
BufferedOutputStream
stream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
new
File
(
uploadPath
+
oldFileName
)));
// BufferedOutputStream stream = new BufferedOutputStream(
// new FileOutputStream(new File(uploadPath + newFileName)));
stream
.
write
(
bytes
);
stream
.
close
();
// 圧縮
//File input = new File(uploadPath + newFileName);
File
input
=
new
File
(
uploadPath
+
oldFileName
);
BufferedImage
image
=
ImageIO
.
read
(
input
);
OutputStream
os
=
new
FileOutputStream
(
input
);
Iterator
<
ImageWriter
>
writers
=
ImageIO
.
getImageWritersByFormatName
(
"jpg"
);
ImageWriter
writer
=
(
ImageWriter
)
writers
.
next
();
ImageOutputStream
ios
=
ImageIO
.
createImageOutputStream
(
os
);
writer
.
setOutput
(
ios
);
ImageWriteParam
param
=
new
JPEGImageWriteParam
(
null
);
param
.
setCompressionMode
(
ImageWriteParam
.
MODE_EXPLICIT
);
param
.
setCompressionQuality
(
0.30f
);
writer
.
write
(
null
,
new
IIOImage
(
image
,
null
,
null
),
param
);
os
.
close
();
ios
.
close
();
writer
.
dispose
();
// shoes entity に写真の名前を格納する
//shoes.setPhoto(newFileName.toString());
shoes
.
setPhoto
(
oldFileName
.
toString
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
else
{
shoes
.
setPhoto
(
"noimage.jpg"
);
}
shoes
.
setName
(
form
.
getName
());
shoes
.
setPrice
(
form
.
getPrice
());
shoes
.
setStock
(
form
.
getStock
());
shoes
.
setSize
(
form
.
getSize
());
shoes
.
setProductStatus
(
form
.
getProductStatus
());
shoesService
.
update
(
shoes
);
@PostMapping
(
"addShoes"
)
public
String
CreateShoes
(
@Validated
ShoesForm
form
,
BindingResult
result
,
MultipartFile
multipartFile
)
throws
Exception
{
if
(
result
.
hasErrors
())
{
return
"management"
;
}
multipartFile
=
form
.
getMultipartFile
();
System
.
out
.
println
(
multipartFile
);
//以前に登録されている商品の場合に登録できないバリデーション
Shoes
sameShoes
=
shoesService
.
findOneAddStock
(
form
.
getName
(),
form
.
getSize
());
System
.
out
.
println
(
sameShoes
);
if
(!(
sameShoes
==
null
))
{
Integer
sumStock
=
form
.
getStock
()
+
sameShoes
.
getStock
();
if
(
sumStock
>=
10
)
{
sameShoes
.
setStock
(
10
);
shoesService
.
update
(
sameShoes
);
}
else
{
sameShoes
.
setStock
(
sumStock
);
shoesService
.
update
(
sameShoes
);
}
}
else
{
Shoes
shoes
=
new
Shoes
();
if
(!
multipartFile
.
isEmpty
())
{
try
{
// ファイル名をリネイム
File
oldFileName
=
new
File
(
multipartFile
.
getOriginalFilename
());
//File newFileName = new File(oldFileName + ".jpg");
//oldFileName.renameTo(newFileName);
// 保存先を定義
String
uploadPath
=
"src/main/resources/static/upload/"
;
byte
[]
bytes
=
multipartFile
.
getBytes
();
// 指定ファイルへ読み込みファイルを書き込み
BufferedOutputStream
stream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
new
File
(
uploadPath
+
oldFileName
)));
// BufferedOutputStream stream = new BufferedOutputStream(
// new FileOutputStream(new File(uploadPath + newFileName)));
stream
.
write
(
bytes
);
stream
.
close
();
// 圧縮
//File input = new File(uploadPath + newFileName);
File
input
=
new
File
(
uploadPath
+
oldFileName
);
BufferedImage
image
=
ImageIO
.
read
(
input
);
OutputStream
os
=
new
FileOutputStream
(
input
);
Iterator
<
ImageWriter
>
writers
=
ImageIO
.
getImageWritersByFormatName
(
"jpg"
);
ImageWriter
writer
=
(
ImageWriter
)
writers
.
next
();
ImageOutputStream
ios
=
ImageIO
.
createImageOutputStream
(
os
);
writer
.
setOutput
(
ios
);
ImageWriteParam
param
=
new
JPEGImageWriteParam
(
null
);
param
.
setCompressionMode
(
ImageWriteParam
.
MODE_EXPLICIT
);
param
.
setCompressionQuality
(
0.30f
);
writer
.
write
(
null
,
new
IIOImage
(
image
,
null
,
null
),
param
);
os
.
close
();
ios
.
close
();
writer
.
dispose
();
// shoes entity に写真の名前を格納する
//shoes.setPhoto(newFileName.toString());
shoes
.
setPhoto
(
oldFileName
.
toString
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
else
{
shoes
.
setPhoto
(
"noimage.jpg"
);
}
shoes
.
setName
(
form
.
getName
());
shoes
.
setPrice
(
form
.
getPrice
());
shoes
.
setStock
(
form
.
getStock
());
shoes
.
setSize
(
form
.
getSize
());
shoes
.
setProductStatus
(
form
.
getProductStatus
());
shoesService
.
update
(
shoes
);
}
//遷移先
return
"redirect:/limited/admin/management"
;
}
...
...
src/main/resources/static/upload/スニーカー3.jpg
View replaced file @
9eeaf4ab
View file @
0eac338a
4.93 KB
|
W:
|
H:
4.92 KB
|
W:
|
H:
2-up
Swipe
Onion skin
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment