Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
shop-Mall
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
licc
shop-Mall
Commits
cebb9105
Commit
cebb9105
authored
Mar 11, 2021
by
m1991
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
资讯模块数据——点赞功能
parent
c72445ea
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
14 deletions
+80
-14
BaseException.java
...ain/java/cn/wisenergy/common/expection/BaseException.java
+2
-0
ShopZxMapper.java
...apper/src/main/java/cn/wisenergy/mapper/ShopZxMapper.java
+7
-0
ShopZxMapper.xml
wisenergy-mapper/src/main/resources/mapper/ShopZxMapper.xml
+21
-1
UsersMapper.xml
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
+0
-3
shopZx.java
...gy-model/src/main/java/cn/wisenergy/model/app/shopZx.java
+10
-2
UploadService.java
...src/main/java/cn/wisenergy/service/app/UploadService.java
+7
-0
UploadServiceImpl.java
...java/cn/wisenergy/service/app/impl/UploadServiceImpl.java
+24
-8
UploadController.java
.../wisenergy/web/admin/controller/app/UploadController.java
+9
-0
No files found.
wisenergy-common/src/main/java/cn/wisenergy/common/expection/BaseException.java
View file @
cebb9105
...
...
@@ -35,4 +35,6 @@ public class BaseException extends RuntimeException {
this
.
msg
=
msg
;
this
.
code
=
code
;
}
}
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/ShopZxMapper.java
View file @
cebb9105
...
...
@@ -27,4 +27,11 @@ public interface ShopZxMapper extends BaseMapper<shopZx> {
* 查询资讯数据
*/
List
<
zxUserDto
>
selectPage
(
@Param
(
"pageNum"
)
Integer
pageNum
,
@Param
(
"pageSize"
)
Integer
pageSize
);
/**
* 点赞接口专用
*/
shopZx
selectByzxid
(
@Param
(
"zxid"
)
Integer
zxid
);
int
updateByzxid
(
@Param
(
"zxid"
)
Integer
zxid
,
@Param
(
"zxLikes"
)
Integer
zxLikes
);
}
wisenergy-mapper/src/main/resources/mapper/ShopZxMapper.xml
View file @
cebb9105
...
...
@@ -27,6 +27,11 @@
<sql
id=
"vals"
>
#{zxUrl},#{zxField},#{zxAddress},#{inviteCode},#{zxDate}
</sql>
<sql
id=
"updateCondition"
>
<if
test=
"zxLikes != null"
>
zx_likes = #{zxLikes},
</if>
</sql>
<!--资讯内容插入-->
<insert
id=
"zxadd"
parameterType=
"cn.wisenergy.model.app.shopZx"
>
insert into
...
...
@@ -53,9 +58,24 @@
WHERE zx_to_examine != 0
order by zxid desc limit #{pageNum},#{pageSize}
</select>
<!--资讯总记录数查询-->
<select
id=
"selectAllNum"
parameterType=
"cn.wisenergy.model.app.shopZx"
>
select count (*) from shop_zx
</select>
<!--资讯点赞专用sql-->
<select
id=
"selectByzxid"
parameterType=
"java.lang.Integer"
resultType=
"cn.wisenergy.model.app.shopZx"
>
select * from shop_zx where zx_id=#{zxid}
</select>
<update
id=
"updateByzxid"
>
UPDATE
<include
refid=
"table"
/>
<set>
zx_likes = #{zxLikes}
</set>
<where>
zx_id = #{zxid}
</where>
</update>
</mapper>
\ No newline at end of file
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
View file @
cebb9105
...
...
@@ -83,9 +83,6 @@
<set>
<include
refid=
"updateCondition"
/>
</set>
<where>
id = #{id}
</where>
</update>
<delete
id=
"delById"
parameterType=
"java.lang.Integer"
>
...
...
wisenergy-model/src/main/java/cn/wisenergy/model/app/shopZx.java
View file @
cebb9105
...
...
@@ -9,8 +9,6 @@ import io.swagger.annotations.ApiModelProperty;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigInteger
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -56,6 +54,16 @@ public class shopZx extends Model<shopZx> implements Serializable {
*/
@ApiModelProperty
(
name
=
"zx_field"
,
value
=
"资讯文字输入字段"
)
private
String
zxField
;
public
Integer
getZxLikes
()
{
return
zxLikes
;
}
public
Integer
setZxLikes
(
Integer
zxLikes
)
{
this
.
zxLikes
=
zxLikes
;
return
zxLikes
;
}
/**
* 用户发布地址
*/
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/app/UploadService.java
View file @
cebb9105
...
...
@@ -53,5 +53,12 @@ public interface UploadService {
*/
Map
selectPage
(
Integer
pageNum
,
Integer
pageSize
);
/**
* TODO 资讯点赞
* @param zxid
* @return
*/
Map
Ilike
(
Integer
zxid
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UploadServiceImpl.java
View file @
cebb9105
package
cn
.
wisenergy
.
service
.
app
.
impl
;
import
cn.wisenergy.common.expection.BaseException
;
import
cn.wisenergy.common.utils.*
;
import
cn.wisenergy.mapper.UsersMapper
;
import
cn.wisenergy.model.app.shopZx
;
import
cn.wisenergy.model.app.zxUserDto
;
import
com.alibaba.fastjson.JSON
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.UrlResource
;
import
org.springframework.stereotype.Service
;
...
...
@@ -167,11 +168,9 @@ public class UploadServiceImpl implements UploadService {
if
(
file
.
isEmpty
())
{
System
.
out
.
println
(
"上传图片为空,请重新上传"
);
}
//判断上传文件格式
String
fileType
=
file
.
getContentType
();
if
(
fileType
.
equals
(
"image/jpeg"
)
||
fileType
.
equals
(
"image/png"
))
{
//上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名
fileName1
=
file
.
getOriginalFilename
();
...
...
@@ -182,21 +181,18 @@ public class UploadServiceImpl implements UploadService {
//设置文件存储路径,可以存放在你想要指定的路径里面
String
Path
=
"/opt/upload/video/"
;
//上传图片存放位置
zxUrl
+=
localPath
+
fileName
+
","
;
if
(
FileUtils
.
upload
(
file
,
Path
,
fileName
))
{
//文件存放的相对路径(一般存放在数据库用于img标签的src)
String
relativePath
=
"用于判断是否图片上传成功,返回值有:"
+
fileName
;
result
.
put
(
"relativePath"
,
relativePath
);
//前端根据是否存在该字段来判断上传是否成功
result_msg
=
"图片上传成功"
;
result
.
put
(
"zxUrl"
,
zxUrl
);
}
else
{
result_msg
=
"图片上传失败"
;
}
}
else
{
result_msg
=
"图片格式不正确"
;
}
}
result
.
put
(
"result_msg"
,
result_msg
);
root
.
add
(
result
);
...
...
@@ -242,11 +238,9 @@ public class UploadServiceImpl implements UploadService {
if
(
fileName
.
contains
(
".."
))
{
throw
new
FileException
(
"Sorry! Filename contains invalid path sequence "
+
fileName
);
}
// Copy file to the target location (Replacing existing file with the same name)
Path
targetLocation
=
this
.
fileStorageLocation
.
resolve
(
fileName
);
Files
.
copy
(
file
.
getInputStream
(),
targetLocation
,
StandardCopyOption
.
REPLACE_EXISTING
);
return
fileName
;
}
catch
(
IOException
ex
)
{
throw
new
FileException
(
"Could not store file "
+
fileName
+
". Please try again!"
,
ex
);
...
...
@@ -290,4 +284,26 @@ public class UploadServiceImpl implements UploadService {
return
map
;
}
/**
* 资讯点赞实现
* @param zxid
* @return
*/
@Override
public
Map
Ilike
(
Integer
zxid
)
{
Map
map
=
new
HashMap
();
try
{
shopZx
shopZx
=
shopZxMapper
.
selectByzxid
(
zxid
);
int
a
=
shopZx
.
getZxLikes
();
Integer
zxLikes
=
shopZx
.
setZxLikes
(
a
+
1
);
shopZxMapper
.
updateByzxid
(
zxid
,
zxLikes
);
map
.
put
(
"code"
,
0
);
map
.
put
(
"msg"
,
"点赞成功!"
);
}
catch
(
BaseException
e
){
map
.
put
(
"code"
,
1
);
map
.
put
(
"msg"
,
"点赞失败!"
);
};
return
map
;
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UploadController.java
View file @
cebb9105
...
...
@@ -110,4 +110,13 @@ public class UploadController {
return
uploadService
.
selectPage
(
pageNum
,
pageSize
);
}
/**
* 点赞接口
*/
@ApiImplicitParam
(
name
=
"zxid"
,
value
=
"资讯ID"
,
required
=
true
,
dataType
=
"integer"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/thumbUp"
)
public
Map
like
(
int
zxid
){
return
uploadService
.
Ilike
(
zxid
);
}
}
\ No newline at end of file
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