Commit b71264da authored by m1991's avatar m1991

资讯模块数据——图片展示功能修复

parent 7cfbaa09
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.userLikes;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 用户点赞记录表
* Created by m1991 on 2021/3/15 12:54
*/
@Mapper
public interface userLikesMapper extends BaseMapper<userLikes> {
/**
* userId查询用户点赞记录
* @param userLikeId
* @return
*/
userLikes selectlikes(@Param("userLikeId") String userLikeId, @Param("likedId") int likedId);
/**
* 添加点赞记录
* @return
*/
int addlikes(@Param("userLikeId") String userLikeId,@Param("likedId")int likedId,@Param("likedStaus")int likedStaus,@Param("likedType")int likedType);
}
...@@ -73,6 +73,10 @@ ...@@ -73,6 +73,10 @@
<select id="selectAllNum" parameterType="cn.wisenergy.model.app.shopZx" > <select id="selectAllNum" parameterType="cn.wisenergy.model.app.shopZx" >
select count (*) from shop_zx select count (*) from shop_zx
</select> </select>
<!--查询点赞记录-->
<select id="selectlikes" parameterType="cn.wisenergy.model.app.userLikes" >
select * from user_likes
</select>
<!--资讯点赞专用sql--> <!--资讯点赞专用sql-->
<select id="selectByzxid" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx"> <select id="selectByzxid" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx">
select * from shop_zx where zx_id=#{zxid} select * from shop_zx where zx_id=#{zxid}
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.mapper.userLikesMapper">
<resultMap id="zxMap" type="cn.wisenergy.model.app.userLikes">
<id column="like_id" property="likeId"/>
<result column="user_like_id" property="userLikeId"/>
<result column="liked_id" property="likedId"/>
<result column="liked_status" property="likedStatus"/>
<result column="liked_type" property="likedType"/>
<result column="liked_time" property="likedTime"/>
</resultMap>
<sql id="table">
user_likes
</sql>
<sql id="cols_all">
like_id as likeId,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_like_id as userLikeId,
liked_id as likedId,
liked_status as likedStaus,
liked_type as likedType
</sql>
<sql id="vals">
#{userLikeId},#{likedId},#{likedStaus},#{likedType}
</sql>
<!--查询点赞记录-->
<select id="selectlikes" parameterType="cn.wisenergy.model.app.userLikes" resultType="cn.wisenergy.model.app.userLikes" >
select * from user_likes WHERE user_like_id=#{userLikeId} and liked_id=#{likedId}
</select>
<!--点赞内容插入-->
<insert id="addlikes" parameterType="cn.wisenergy.model.app.userLikes">
insert into user_likes
(user_like_id,
liked_id ,
liked_status,
liked_type)
value(
#{userLikeId},#{likedId},#{likedStaus},#{likedType}
)
</insert>
</mapper>
\ No newline at end of file
...@@ -12,7 +12,7 @@ import java.sql.Timestamp; ...@@ -12,7 +12,7 @@ import java.sql.Timestamp;
* Created by m1991 on 2021/3/12 15:57 * Created by m1991 on 2021/3/12 15:57
*/ */
@Data @Data
@ApiModel(value = "userLikes") @ApiModel(value = "userl_ikes")
public class userLikes implements Serializable { public class userLikes implements Serializable {
private static final long serialVersionUID = 3050641578536493424L; private static final long serialVersionUID = 3050641578536493424L;
......
...@@ -4,8 +4,10 @@ import cn.wisenergy.common.expection.BaseException; ...@@ -4,8 +4,10 @@ import cn.wisenergy.common.expection.BaseException;
import cn.wisenergy.common.utils.*; import cn.wisenergy.common.utils.*;
import cn.wisenergy.mapper.UsersMapper; import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.mapper.userLikesMapper;
import cn.wisenergy.model.app.User; import cn.wisenergy.model.app.User;
import cn.wisenergy.model.app.shopZx; import cn.wisenergy.model.app.shopZx;
import cn.wisenergy.model.app.userLikes;
import cn.wisenergy.model.app.zxUserDto; import cn.wisenergy.model.app.zxUserDto;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
...@@ -44,6 +46,9 @@ public class UploadServiceImpl implements UploadService { ...@@ -44,6 +46,9 @@ public class UploadServiceImpl implements UploadService {
@Autowired @Autowired
private UsersMapper usersMapper; private UsersMapper usersMapper;
@Autowired
private userLikesMapper LikesMapper;
// @Value("${file.upload.path:#{null}}") // @Value("${file.upload.path:#{null}}")
private String path; private String path;
...@@ -305,28 +310,40 @@ public class UploadServiceImpl implements UploadService { ...@@ -305,28 +310,40 @@ public class UploadServiceImpl implements UploadService {
User user=usersMapper.InvitedCode2(inviteCode); User user=usersMapper.InvitedCode2(inviteCode);
//用户等于null //用户等于null
if(null == inviteCode || "".equals(inviteCode)){ if(null == user || "".equals(user)){
map.put("code",1); map.put("code",1);
map.put("msg","用户信息不存在,请先注册!"); map.put("msg","用户信息不存在,请先注册!");
return map; return map;
//用户存在 //用户存在
}else { }else {
//判断该用户是否点过赞,如果点过赞,就返回信息告知前端, //判断该用户是否点过赞,如果点过赞,就返回信息告知前端,
user.getUserId(); String userLikeId=user.getUserId();
// usersMapper. int likedId= zxid;
// 没有点过的话,就进行插入点赞记录表,更新点赞数 userLikes b= LikesMapper.selectlikes(userLikeId, likedId);
if(b==null){
// 没有点过的话,就进行插入点赞记录表,更新点赞数
Integer likedType=0;//点赞类型为扩展类型,暂时默认0
Integer likedStaus=1; //更新点赞状态
LikesMapper.addlikes(userLikeId,likedId,likedStaus,likedType);
shopZx shopZx = shopZxMapper.selectByzxid(zxid);
int a = shopZx.getZxLikes();
Integer zxLikes=shopZx.setZxLikes(a + 1);
shopZxMapper.updateByzxid(zxid,zxLikes);
map.put("LikedStatus",likedStaus);
map.put("code",0);
map.put("msg","点赞成功!");
}else {
map.put("code",1);
map.put("msg","点赞失败!");
};
} }
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; return map;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment