Commit cebb9105 authored by m1991's avatar m1991

资讯模块数据——点赞功能

parent c72445ea
...@@ -35,4 +35,6 @@ public class BaseException extends RuntimeException { ...@@ -35,4 +35,6 @@ public class BaseException extends RuntimeException {
this.msg = msg; this.msg = msg;
this.code = code; this.code = code;
} }
} }
...@@ -27,4 +27,11 @@ public interface ShopZxMapper extends BaseMapper<shopZx> { ...@@ -27,4 +27,11 @@ public interface ShopZxMapper extends BaseMapper<shopZx> {
* 查询资讯数据 * 查询资讯数据
*/ */
List<zxUserDto> selectPage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize); 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);
} }
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
<sql id="vals"> <sql id="vals">
#{zxUrl},#{zxField},#{zxAddress},#{inviteCode},#{zxDate} #{zxUrl},#{zxField},#{zxAddress},#{inviteCode},#{zxDate}
</sql> </sql>
<sql id="updateCondition">
<if test="zxLikes != null">zx_likes = #{zxLikes},</if>
</sql>
<!--资讯内容插入--> <!--资讯内容插入-->
<insert id="zxadd" parameterType="cn.wisenergy.model.app.shopZx"> <insert id="zxadd" parameterType="cn.wisenergy.model.app.shopZx">
insert into insert into
...@@ -53,9 +58,24 @@ ...@@ -53,9 +58,24 @@
WHERE zx_to_examine != 0 WHERE zx_to_examine != 0
order by zxid desc limit #{pageNum},#{pageSize} order by zxid desc limit #{pageNum},#{pageSize}
</select> </select>
<!--资讯总记录数查询--> <!--资讯总记录数查询-->
<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>
<!--资讯点赞专用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> </mapper>
\ No newline at end of file
...@@ -83,9 +83,6 @@ ...@@ -83,9 +83,6 @@
<set> <set>
<include refid="updateCondition"/> <include refid="updateCondition"/>
</set> </set>
<where>
id = #{id}
</where>
</update> </update>
<delete id="delById" parameterType="java.lang.Integer"> <delete id="delById" parameterType="java.lang.Integer">
......
...@@ -9,8 +9,6 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -9,8 +9,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.List; import java.util.List;
...@@ -56,6 +54,16 @@ public class shopZx extends Model<shopZx> implements Serializable { ...@@ -56,6 +54,16 @@ public class shopZx extends Model<shopZx> implements Serializable {
*/ */
@ApiModelProperty(name = "zx_field", value = "资讯文字输入字段") @ApiModelProperty(name = "zx_field", value = "资讯文字输入字段")
private String zxField; private String zxField;
public Integer getZxLikes() {
return zxLikes;
}
public Integer setZxLikes(Integer zxLikes) {
this.zxLikes = zxLikes;
return zxLikes;
}
/** /**
* 用户发布地址 * 用户发布地址
*/ */
......
...@@ -53,5 +53,12 @@ public interface UploadService { ...@@ -53,5 +53,12 @@ public interface UploadService {
*/ */
Map selectPage(Integer pageNum, Integer pageSize); Map selectPage(Integer pageNum, Integer pageSize);
/**
* TODO 资讯点赞
* @param zxid
* @return
*/
Map Ilike(Integer zxid);
} }
package cn.wisenergy.service.app.impl; package cn.wisenergy.service.app.impl;
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.model.app.shopZx;
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.beans.factory.annotation.Value;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -167,11 +168,9 @@ public class UploadServiceImpl implements UploadService { ...@@ -167,11 +168,9 @@ public class UploadServiceImpl implements UploadService {
if (file.isEmpty()) { if (file.isEmpty()) {
System.out.println("上传图片为空,请重新上传"); System.out.println("上传图片为空,请重新上传");
} }
//判断上传文件格式 //判断上传文件格式
String fileType = file.getContentType(); String fileType = file.getContentType();
if (fileType.equals("image/jpeg") || fileType.equals("image/png")) { if (fileType.equals("image/jpeg") || fileType.equals("image/png")) {
//上传后保存的文件名(需要防止图片重名导致的文件覆盖) //上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名 //获取文件名
fileName1 = file.getOriginalFilename(); fileName1 = file.getOriginalFilename();
...@@ -182,21 +181,18 @@ public class UploadServiceImpl implements UploadService { ...@@ -182,21 +181,18 @@ public class UploadServiceImpl implements UploadService {
//设置文件存储路径,可以存放在你想要指定的路径里面 //设置文件存储路径,可以存放在你想要指定的路径里面
String Path="/opt/upload/video/"; //上传图片存放位置 String Path="/opt/upload/video/"; //上传图片存放位置
zxUrl+=localPath+fileName+","; zxUrl+=localPath+fileName+",";
if (FileUtils.upload(file,Path, fileName)) { if (FileUtils.upload(file,Path, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src) //文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath ="用于判断是否图片上传成功,返回值有:"+fileName; String relativePath ="用于判断是否图片上传成功,返回值有:"+fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功 result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
result_msg = "图片上传成功"; result_msg = "图片上传成功";
result.put("zxUrl", zxUrl); result.put("zxUrl", zxUrl);
} else { } else {
result_msg = "图片上传失败"; result_msg = "图片上传失败";
} }
} else { } else {
result_msg = "图片格式不正确"; result_msg = "图片格式不正确";
} }
} }
result.put("result_msg", result_msg); result.put("result_msg", result_msg);
root.add(result); root.add(result);
...@@ -242,11 +238,9 @@ public class UploadServiceImpl implements UploadService { ...@@ -242,11 +238,9 @@ public class UploadServiceImpl implements UploadService {
if(fileName.contains("..")) { if(fileName.contains("..")) {
throw new FileException("Sorry! Filename contains invalid path sequence " + fileName); throw new FileException("Sorry! Filename contains invalid path sequence " + fileName);
} }
// Copy file to the target location (Replacing existing file with the same name) // Copy file to the target location (Replacing existing file with the same name)
Path targetLocation = this.fileStorageLocation.resolve(fileName); Path targetLocation = this.fileStorageLocation.resolve(fileName);
Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING); Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
return fileName; return fileName;
} catch (IOException ex) { } catch (IOException ex) {
throw new FileException("Could not store file " + fileName + ". Please try again!", ex); throw new FileException("Could not store file " + fileName + ". Please try again!", ex);
...@@ -290,4 +284,26 @@ public class UploadServiceImpl implements UploadService { ...@@ -290,4 +284,26 @@ public class UploadServiceImpl implements UploadService {
return map; 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;
}
} }
...@@ -110,4 +110,13 @@ public class UploadController { ...@@ -110,4 +110,13 @@ public class UploadController {
return uploadService.selectPage(pageNum,pageSize); 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
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