✨ 1.文章点赞功能2.文章赞赏功能
This commit is contained in:
parent
1ef5f5c898
commit
39ba372cac
@ -55,4 +55,8 @@ public class ArticleDTO {
|
||||
private Integer sortNo;
|
||||
/** 0:非优选1:优选;0 */
|
||||
private String articlePerfect;
|
||||
/** 点赞总数 */
|
||||
private Integer articleThumbsUpCount;
|
||||
/** 赞赏总数 */
|
||||
private Integer articleSponsorCount;
|
||||
}
|
||||
|
@ -48,4 +48,8 @@ public class Article implements Serializable,Cloneable {
|
||||
private Date updatedTime;
|
||||
/** 文章状态 */
|
||||
private String articleStatus;
|
||||
/** 点赞总数 */
|
||||
private Integer articleThumbsUpCount;
|
||||
/** 赞赏总数 */
|
||||
private Integer articleSponsorCount;
|
||||
}
|
||||
|
37
src/main/java/com/rymcu/forest/entity/ArticleThumbsUp.java
Normal file
37
src/main/java/com/rymcu/forest/entity/ArticleThumbsUp.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.rymcu.forest.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Data
|
||||
@Table(name="vertical_article_thumbs_up")
|
||||
public class ArticleThumbsUp implements Serializable, Cloneable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "JDBC")
|
||||
private Integer idArticleThumbsUp;
|
||||
/**
|
||||
* 文章表主键
|
||||
*/
|
||||
private Integer idArticle;
|
||||
/**
|
||||
* 用户表主键
|
||||
*/
|
||||
private Integer idUser;
|
||||
/**
|
||||
* 点赞时间
|
||||
*/
|
||||
private Date thumbsUpTime;
|
||||
}
|
44
src/main/java/com/rymcu/forest/entity/Sponsor.java
Normal file
44
src/main/java/com/rymcu/forest/entity/Sponsor.java
Normal file
@ -0,0 +1,44 @@
|
||||
package com.rymcu.forest.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Data
|
||||
@Table(name="vertical_sponsor")
|
||||
public class Sponsor implements Serializable, Cloneable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(generator = "JDBC")
|
||||
private Integer id;
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
/**
|
||||
* 数据主键
|
||||
*/
|
||||
private Integer dataId;
|
||||
/**
|
||||
* 赞赏人
|
||||
*/
|
||||
private Integer sponsor;
|
||||
/**
|
||||
* 赞赏日期
|
||||
*/
|
||||
private Date sponsorshipTime;
|
||||
/**
|
||||
* 赞赏金额
|
||||
*/
|
||||
private BigDecimal sponsorshipMoney;
|
||||
}
|
30
src/main/java/com/rymcu/forest/enumerate/SponsorEnum.java
Normal file
30
src/main/java/com/rymcu/forest/enumerate/SponsorEnum.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.rymcu.forest.enumerate;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
|
||||
public enum SponsorEnum {
|
||||
Article("0", 20);
|
||||
|
||||
private String dataType;
|
||||
|
||||
private Integer money;
|
||||
|
||||
SponsorEnum(String dataType, Integer money) {
|
||||
this.dataType = dataType;
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return this.dataType;
|
||||
}
|
||||
|
||||
public Integer getMoney() {
|
||||
return this.money;
|
||||
}
|
||||
|
||||
public boolean isArticle() {
|
||||
return Article.equals(this);
|
||||
}
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
package com.rymcu.forest.jwt.aop;
|
||||
|
||||
|
||||
|
||||
import com.rymcu.forest.jwt.def.JwtConstants;
|
||||
import com.rymcu.forest.jwt.model.TokenModel;
|
||||
import com.rymcu.forest.jwt.service.TokenManager;
|
||||
import com.rymcu.forest.jwt.util.oConvertUtils;
|
||||
import com.rymcu.forest.web.api.exception.ErrorCode;
|
||||
import com.rymcu.forest.web.api.exception.BaseApiException;
|
||||
import com.rymcu.forest.web.api.exception.ErrorCode;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureException;
|
||||
@ -18,6 +16,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Restful请求, Token校验规则拦截器(JWT)
|
||||
@ -55,7 +54,7 @@ public class RestAuthTokenInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
Object username = claims.getId();
|
||||
if (oConvertUtils.isEmpty(username)) {
|
||||
if (Objects.isNull(username)) {
|
||||
throw new BaseApiException(ErrorCode.INVALID_TOKEN);
|
||||
}
|
||||
TokenModel model = manager.getToken(authHeader,username.toString());
|
||||
|
@ -1,499 +0,0 @@
|
||||
package com.rymcu.forest.jwt.util;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.sql.Date;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 张代浩
|
||||
*
|
||||
*/
|
||||
public class oConvertUtils {
|
||||
public static boolean isEmpty(Object object) {
|
||||
if (object == null) {
|
||||
return (true);
|
||||
}
|
||||
if (object.equals("")) {
|
||||
return (true);
|
||||
}
|
||||
if (object.equals("null")) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(Object object) {
|
||||
if (object != null && !object.equals("") && !object.equals("null")) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
public static String decode(String strIn, String sourceCode, String targetCode) {
|
||||
String temp = code2code(strIn, sourceCode, targetCode);
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static String StrToUTF(String strIn, String sourceCode, String targetCode) {
|
||||
strIn = "";
|
||||
try {
|
||||
strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return strIn;
|
||||
|
||||
}
|
||||
|
||||
private static String code2code(String strIn, String sourceCode, String targetCode) {
|
||||
String strOut = null;
|
||||
if (strIn == null || (strIn.trim()).equals("")) {
|
||||
return strIn;
|
||||
}
|
||||
try {
|
||||
byte[] b = strIn.getBytes(sourceCode);
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
System.out.print(b[i] + " ");
|
||||
}
|
||||
strOut = new String(b, targetCode);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return strOut;
|
||||
}
|
||||
|
||||
public static int getInt(String s, int defval) {
|
||||
if (s == null || s == "") {
|
||||
return (defval);
|
||||
}
|
||||
try {
|
||||
return (Integer.parseInt(s));
|
||||
} catch (NumberFormatException e) {
|
||||
return (defval);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(String s) {
|
||||
if (s == null || s == "") {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return (Integer.parseInt(s));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(String s, Integer df) {
|
||||
if (s == null || s == "") {
|
||||
return df;
|
||||
}
|
||||
try {
|
||||
return (Integer.parseInt(s));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer[] getInts(String[] s) {
|
||||
Integer[] integer = new Integer[s.length];
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
integer[i] = Integer.parseInt(s[i]);
|
||||
}
|
||||
return integer;
|
||||
|
||||
}
|
||||
|
||||
public static double getDouble(String s, double defval) {
|
||||
if (s == null || s == "") {
|
||||
return (defval);
|
||||
}
|
||||
try {
|
||||
return (Double.parseDouble(s));
|
||||
} catch (NumberFormatException e) {
|
||||
return (defval);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDou(Double s, double defval) {
|
||||
if (s == null) {
|
||||
return (defval);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Short getShort(String s) {
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
return (Short.parseShort(s));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(Object object, int defval) {
|
||||
if (isEmpty(object)) {
|
||||
return (defval);
|
||||
}
|
||||
try {
|
||||
return (Integer.parseInt(object.toString()));
|
||||
} catch (NumberFormatException e) {
|
||||
return (defval);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(BigDecimal s, int defval) {
|
||||
if (s == null) {
|
||||
return (defval);
|
||||
}
|
||||
return s.intValue();
|
||||
}
|
||||
|
||||
public static Integer[] getIntegerArry(String[] object) {
|
||||
int len = object.length;
|
||||
Integer[] result = new Integer[len];
|
||||
try {
|
||||
for (int i = 0; i < len; i++) {
|
||||
result[i] = new Integer(object[i].trim());
|
||||
}
|
||||
return result;
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getString(String s) {
|
||||
return (getString(s, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转义成Unicode编码
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String escapeJava(Object s) {
|
||||
return StringEscapeUtils.escapeJava(getString(s));
|
||||
}
|
||||
|
||||
public static String getString(Object object) {
|
||||
if (isEmpty(object)) {
|
||||
return "";
|
||||
}
|
||||
return (object.toString().trim());
|
||||
}
|
||||
|
||||
public static String getString(int i) {
|
||||
return (String.valueOf(i));
|
||||
}
|
||||
|
||||
public static String getString(float i) {
|
||||
return (String.valueOf(i));
|
||||
}
|
||||
|
||||
public static String getString(String s, String defval) {
|
||||
if (isEmpty(s)) {
|
||||
return (defval);
|
||||
}
|
||||
return (s.trim());
|
||||
}
|
||||
|
||||
public static String getString(Object s, String defval) {
|
||||
if (isEmpty(s)) {
|
||||
return (defval);
|
||||
}
|
||||
return (s.toString().trim());
|
||||
}
|
||||
|
||||
public static long stringToLong(String str) {
|
||||
Long test = new Long(0);
|
||||
try {
|
||||
test = Long.valueOf(str);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return test.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本机IP
|
||||
*/
|
||||
public static String getIp() {
|
||||
String ip = null;
|
||||
try {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
ip = address.getHostAddress();
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个类是否为基本数据类型。
|
||||
*
|
||||
* @param clazz
|
||||
* 要判断的类。
|
||||
* @return true 表示为基本数据类型。
|
||||
*/
|
||||
private static boolean isBaseDataType(Class clazz) throws Exception {
|
||||
return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* IP
|
||||
* @return IP Address
|
||||
*/
|
||||
public static String getIpAddrByRequest(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 本机IP
|
||||
* @throws SocketException
|
||||
*/
|
||||
public static String getRealIp() throws SocketException {
|
||||
String localip = null;// 本地IP,如果没有配置外网IP则返回它
|
||||
String netip = null;// 外网IP
|
||||
|
||||
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
InetAddress ip = null;
|
||||
boolean finded = false;// 是否找到外网IP
|
||||
while (netInterfaces.hasMoreElements() && !finded) {
|
||||
NetworkInterface ni = netInterfaces.nextElement();
|
||||
Enumeration<InetAddress> address = ni.getInetAddresses();
|
||||
while (address.hasMoreElements()) {
|
||||
ip = address.nextElement();
|
||||
if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 外网IP
|
||||
netip = ip.getHostAddress();
|
||||
finded = true;
|
||||
break;
|
||||
} else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 内网IP
|
||||
localip = ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (netip != null && !"".equals(netip)) {
|
||||
return netip;
|
||||
} else {
|
||||
return localip;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* java去除字符串中的空格、回车、换行符、制表符
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String replaceBlank(String str) {
|
||||
String dest = "";
|
||||
if (str != null) {
|
||||
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
||||
Matcher m = p.matcher(str);
|
||||
dest = m.replaceAll("");
|
||||
}
|
||||
return dest;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断元素是否在数组内
|
||||
*
|
||||
* @param substring
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIn(String substring, String[] source) {
|
||||
if (source == null || source.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < source.length; i++) {
|
||||
String aSource = source[i];
|
||||
if (aSource.equals(substring)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Map对象
|
||||
*/
|
||||
public static Map<Object, Object> getHashMap() {
|
||||
return new HashMap<Object, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* SET转换MAP
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static Map<Object, Object> SetToMap(Set<Object> setobj) {
|
||||
Map<Object, Object> map = getHashMap();
|
||||
for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
|
||||
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
|
||||
map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isInnerIP(String ipAddress) {
|
||||
boolean isInnerIp = false;
|
||||
long ipNum = getIpNum(ipAddress);
|
||||
/**
|
||||
* 私有IP:A类 10.0.0.0-10.255.255.255 B类 172.16.0.0-172.31.255.255 C类 192.168.0.0-192.168.255.255 当然,还有127这个网段是环回地址
|
||||
**/
|
||||
long aBegin = getIpNum("10.0.0.0");
|
||||
long aEnd = getIpNum("10.255.255.255");
|
||||
long bBegin = getIpNum("172.16.0.0");
|
||||
long bEnd = getIpNum("172.31.255.255");
|
||||
long cBegin = getIpNum("192.168.0.0");
|
||||
long cEnd = getIpNum("192.168.255.255");
|
||||
isInnerIp = isInner(ipNum, aBegin, aEnd) || isInner(ipNum, bBegin, bEnd) || isInner(ipNum, cBegin, cEnd) || ipAddress.equals("127.0.0.1");
|
||||
return isInnerIp;
|
||||
}
|
||||
|
||||
private static long getIpNum(String ipAddress) {
|
||||
String[] ip = ipAddress.split("\\.");
|
||||
long a = Integer.parseInt(ip[0]);
|
||||
long b = Integer.parseInt(ip[1]);
|
||||
long c = Integer.parseInt(ip[2]);
|
||||
long d = Integer.parseInt(ip[3]);
|
||||
|
||||
long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
|
||||
return ipNum;
|
||||
}
|
||||
|
||||
private static boolean isInner(long userIp, long begin, long end) {
|
||||
return (userIp >= begin) && (userIp <= end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。
|
||||
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
||||
* 例如:hello_world->helloWorld
|
||||
*
|
||||
* @param name
|
||||
* 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String camelName(String name) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
// 快速检查
|
||||
if (name == null || name.isEmpty()) {
|
||||
// 没必要转换
|
||||
return "";
|
||||
} else if (!name.contains("_")) {
|
||||
// 不含下划线,仅将首字母小写
|
||||
|
||||
return name.substring(0, 1).toLowerCase() + name.substring(1).toLowerCase();
|
||||
|
||||
}
|
||||
// 用下划线将原始字符串分割
|
||||
String camels[] = name.split("_");
|
||||
for (String camel : camels) {
|
||||
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
||||
if (camel.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 处理真正的驼峰片段
|
||||
if (result.length() == 0) {
|
||||
// 第一个驼峰片段,全部字母都小写
|
||||
result.append(camel.toLowerCase());
|
||||
} else {
|
||||
// 其他的驼峰片段,首字母大写
|
||||
result.append(camel.substring(0, 1).toUpperCase());
|
||||
result.append(camel.substring(1).toLowerCase());
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。
|
||||
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
||||
* 例如:hello_world,test_id->helloWorld,testId
|
||||
*
|
||||
* @param name
|
||||
* 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String camelNames(String names) {
|
||||
if(names==null||names.equals("")){
|
||||
return null;
|
||||
}
|
||||
StringBuffer sf = new StringBuffer();
|
||||
String[] fs = names.split(",");
|
||||
for (String field : fs) {
|
||||
field = camelName(field);
|
||||
sf.append(field + ",");
|
||||
}
|
||||
String result = sf.toString();
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。(首字母写)
|
||||
* 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
|
||||
* 例如:hello_world->HelloWorld
|
||||
*
|
||||
* @param name
|
||||
* 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String camelNameCapFirst(String name) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
// 快速检查
|
||||
if (name == null || name.isEmpty()) {
|
||||
// 没必要转换
|
||||
return "";
|
||||
} else if (!name.contains("_")) {
|
||||
// 不含下划线,仅将首字母小写
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
|
||||
}
|
||||
// 用下划线将原始字符串分割
|
||||
String camels[] = name.split("_");
|
||||
for (String camel : camels) {
|
||||
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
||||
if (camel.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 其他的驼峰片段,首字母大写
|
||||
result.append(camel.substring(0, 1).toUpperCase());
|
||||
result.append(camel.substring(1).toLowerCase());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.rymcu.forest.mapper;
|
||||
|
||||
import com.rymcu.forest.core.mapper.Mapper;
|
||||
import com.rymcu.forest.entity.ArticleThumbsUp;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
public interface ArticleThumbsUpMapper extends Mapper<ArticleThumbsUp> {
|
||||
/**
|
||||
* 更新文章点赞数
|
||||
* @param idArticle
|
||||
* @param thumbsUpNumber
|
||||
* @return
|
||||
*/
|
||||
Integer updateArticleThumbsUpNumber(@Param("idArticle") Integer idArticle, @Param("thumbsUpNumber") Integer thumbsUpNumber);
|
||||
}
|
17
src/main/java/com/rymcu/forest/mapper/SponsorMapper.java
Normal file
17
src/main/java/com/rymcu/forest/mapper/SponsorMapper.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.rymcu.forest.mapper;
|
||||
|
||||
import com.rymcu.forest.core.mapper.Mapper;
|
||||
import com.rymcu.forest.entity.Sponsor;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
public interface SponsorMapper extends Mapper<Sponsor> {
|
||||
/**
|
||||
* 更新文章赞赏数
|
||||
* @param idArticle
|
||||
* @return
|
||||
*/
|
||||
Integer updateArticleSponsorCount(@Param("idArticle") Integer idArticle);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.rymcu.forest.service;
|
||||
|
||||
import com.rymcu.forest.core.service.Service;
|
||||
import com.rymcu.forest.entity.ArticleThumbsUp;
|
||||
import com.rymcu.forest.web.api.exception.BaseApiException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
public interface ArticleThumbsUpService extends Service<ArticleThumbsUp> {
|
||||
/**
|
||||
* 点赞
|
||||
* @param articleThumbsUp
|
||||
* @throws BaseApiException
|
||||
* @return
|
||||
*/
|
||||
Map thumbsUp(ArticleThumbsUp articleThumbsUp) throws BaseApiException;
|
||||
}
|
19
src/main/java/com/rymcu/forest/service/SponsorService.java
Normal file
19
src/main/java/com/rymcu/forest/service/SponsorService.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.rymcu.forest.service;
|
||||
|
||||
import com.rymcu.forest.core.service.Service;
|
||||
import com.rymcu.forest.entity.Sponsor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
public interface SponsorService extends Service<Sponsor> {
|
||||
/**
|
||||
* 赞赏
|
||||
* @param sponsor
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
Map sponsorship(Sponsor sponsor) throws Exception;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.rymcu.forest.service;
|
||||
|
||||
import com.rymcu.forest.core.exception.ServiceException;
|
||||
import com.rymcu.forest.core.service.Service;
|
||||
import com.rymcu.forest.dto.TransactionRecordDTO;
|
||||
import com.rymcu.forest.entity.TransactionRecord;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -15,8 +15,9 @@ public interface TransactionRecordService extends Service<TransactionRecord> {
|
||||
* 交易
|
||||
* @param transactionRecord
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
TransactionRecord transfer(TransactionRecord transactionRecord);
|
||||
TransactionRecord transfer(TransactionRecord transactionRecord) throws Exception;
|
||||
|
||||
/**
|
||||
* 查询指定账户的交易记录
|
||||
@ -24,4 +25,14 @@ public interface TransactionRecordService extends Service<TransactionRecord> {
|
||||
* @return
|
||||
*/
|
||||
List<TransactionRecordDTO> findTransactionRecords(String bankAccount);
|
||||
|
||||
/**
|
||||
* 根据用户主键进行交易
|
||||
* @param toUserId
|
||||
* @param formUserId
|
||||
* @param money
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
TransactionRecord transferByUserId(Integer toUserId, Integer formUserId, BigDecimal money) throws Exception;
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package com.rymcu.forest.service.impl;
|
||||
|
||||
import com.rymcu.forest.core.service.AbstractService;
|
||||
import com.rymcu.forest.entity.Article;
|
||||
import com.rymcu.forest.entity.ArticleThumbsUp;
|
||||
import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.mapper.ArticleThumbsUpMapper;
|
||||
import com.rymcu.forest.service.ArticleService;
|
||||
import com.rymcu.forest.service.ArticleThumbsUpService;
|
||||
import com.rymcu.forest.util.UserUtils;
|
||||
import com.rymcu.forest.web.api.exception.BaseApiException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Service
|
||||
public class ArticleThumbsUpServiceImpl extends AbstractService<ArticleThumbsUp> implements ArticleThumbsUpService {
|
||||
|
||||
@Resource
|
||||
private ArticleThumbsUpMapper articleThumbsUpMapper;
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map thumbsUp(ArticleThumbsUp articleThumbsUp) throws BaseApiException {
|
||||
Map map = new HashMap(3);
|
||||
if (Objects.isNull(articleThumbsUp) || Objects.isNull(articleThumbsUp.getIdArticle())) {
|
||||
map.put("message", "数据异常,文章不存在!");
|
||||
map.put("success", false);
|
||||
} else {
|
||||
Integer thumbsUpNumber = 1;
|
||||
Article article = articleService.findById(String.valueOf(articleThumbsUp.getIdArticle()));
|
||||
if (Objects.isNull(article)) {
|
||||
map.put("message", "数据异常,文章不存在!");
|
||||
map.put("success", false);
|
||||
} else {
|
||||
User user = UserUtils.getCurrentUserByToken();
|
||||
articleThumbsUp.setIdUser(user.getIdUser());
|
||||
ArticleThumbsUp thumbsUp = articleThumbsUpMapper.selectOne(articleThumbsUp);
|
||||
if (Objects.isNull(thumbsUp)) {
|
||||
articleThumbsUp.setThumbsUpTime(new Date());
|
||||
articleThumbsUpMapper.insertSelective(articleThumbsUp);
|
||||
// 更新文章点赞数
|
||||
} else {
|
||||
articleThumbsUpMapper.deleteByPrimaryKey(thumbsUp.getIdArticleThumbsUp());
|
||||
// 更新文章点赞数
|
||||
thumbsUpNumber = -1;
|
||||
}
|
||||
articleThumbsUpMapper.updateArticleThumbsUpNumber(articleThumbsUp.getIdArticle(), thumbsUpNumber);
|
||||
map.put("success", true);
|
||||
map.put("thumbsUpNumber", thumbsUpNumber);
|
||||
if (thumbsUpNumber > 0) {
|
||||
map.put("message", "点赞成功");
|
||||
} else {
|
||||
map.put("message", "已取消点赞");
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.rymcu.forest.service.impl;
|
||||
|
||||
import com.rymcu.forest.core.service.AbstractService;
|
||||
import com.rymcu.forest.dto.ArticleDTO;
|
||||
import com.rymcu.forest.entity.Sponsor;
|
||||
import com.rymcu.forest.entity.TransactionRecord;
|
||||
import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.enumerate.SponsorEnum;
|
||||
import com.rymcu.forest.mapper.SponsorMapper;
|
||||
import com.rymcu.forest.service.ArticleService;
|
||||
import com.rymcu.forest.service.SponsorService;
|
||||
import com.rymcu.forest.service.TransactionRecordService;
|
||||
import com.rymcu.forest.util.UserUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Service
|
||||
public class SponsorServiceImpl extends AbstractService<Sponsor> implements SponsorService {
|
||||
|
||||
@Resource
|
||||
private SponsorMapper sponsorMapper;
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
@Resource
|
||||
private TransactionRecordService transactionRecordService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map sponsorship(Sponsor sponsor) throws Exception {
|
||||
Map map = new HashMap(2);
|
||||
if (Objects.isNull(sponsor) || Objects.isNull(sponsor.getDataId()) || Objects.isNull(sponsor.getDataType())) {
|
||||
map.put("success", false);
|
||||
map.put("message", "数据异常");
|
||||
} else {
|
||||
SponsorEnum result = Arrays.stream(SponsorEnum.values()).filter(sponsorEnum -> sponsorEnum.getDataType().equals(sponsor.getDataType())).findFirst().orElse(SponsorEnum.Article);
|
||||
BigDecimal money = BigDecimal.valueOf(result.getMoney());
|
||||
sponsor.setSponsorshipMoney(money);
|
||||
User user = UserUtils.getCurrentUserByToken();
|
||||
sponsor.setSponsor(user.getIdUser());
|
||||
sponsor.setSponsorshipTime(new Date());
|
||||
sponsorMapper.insertSelective(sponsor);
|
||||
// 赞赏金额划转
|
||||
if (result.isArticle()) {
|
||||
ArticleDTO articleDTO = articleService.findArticleDTOById(sponsor.getDataId(), 1);
|
||||
TransactionRecord transactionRecord = transactionRecordService.transferByUserId(articleDTO.getArticleAuthorId(), user.getIdUser(), money);
|
||||
if (Objects.isNull(transactionRecord.getIdTransactionRecord())) {
|
||||
throw new Exception("余额不足");
|
||||
}
|
||||
// 更新文章赞赏数
|
||||
sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle());
|
||||
}
|
||||
map.put("success", true);
|
||||
map.put("message", "赞赏成功");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.rymcu.forest.service.impl;
|
||||
import com.rymcu.forest.core.exception.ServiceException;
|
||||
import com.rymcu.forest.core.service.AbstractService;
|
||||
import com.rymcu.forest.core.service.redis.RedisService;
|
||||
import com.rymcu.forest.dto.BankAccountDTO;
|
||||
import com.rymcu.forest.dto.TransactionRecordDTO;
|
||||
import com.rymcu.forest.entity.BankAccount;
|
||||
import com.rymcu.forest.entity.TransactionRecord;
|
||||
@ -35,7 +36,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TransactionRecord transfer(TransactionRecord transactionRecord) {
|
||||
public TransactionRecord transfer(TransactionRecord transactionRecord) throws Exception {
|
||||
// 判断发起者账户状态
|
||||
boolean formAccountStatus = checkFormAccountStatus(transactionRecord.getFormBankAccount(), transactionRecord.getMoney());
|
||||
if (formAccountStatus) {
|
||||
@ -45,6 +46,8 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
transactionRecord.setTransactionTime(new Date());
|
||||
transactionRecordMapper.insertSelective(transactionRecord);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("余额不足");
|
||||
}
|
||||
return transactionRecord;
|
||||
}
|
||||
@ -54,6 +57,18 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
return transactionRecordMapper.selectTransactionRecords(bankAccount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionRecord transferByUserId(Integer toUserId, Integer formUserId, BigDecimal money) throws Exception {
|
||||
BankAccountDTO toBankAccount = bankAccountService.findBankAccountByIdUser(toUserId);
|
||||
BankAccountDTO formBankAccount = bankAccountService.findBankAccountByIdUser(formUserId);
|
||||
TransactionRecord transactionRecord = new TransactionRecord();
|
||||
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||
transactionRecord.setMoney(money);
|
||||
transactionRecord.setFunds("赞赏");
|
||||
return transfer(transactionRecord);
|
||||
}
|
||||
|
||||
private String nextTransactionNo() {
|
||||
String orderNo = "E";
|
||||
String key = "orderId";
|
||||
|
@ -7,8 +7,12 @@ import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.dto.ArticleDTO;
|
||||
import com.rymcu.forest.dto.CommentDTO;
|
||||
import com.rymcu.forest.entity.Article;
|
||||
import com.rymcu.forest.entity.ArticleThumbsUp;
|
||||
import com.rymcu.forest.entity.Sponsor;
|
||||
import com.rymcu.forest.service.ArticleService;
|
||||
import com.rymcu.forest.service.ArticleThumbsUpService;
|
||||
import com.rymcu.forest.service.CommentService;
|
||||
import com.rymcu.forest.service.SponsorService;
|
||||
import com.rymcu.forest.util.Utils;
|
||||
import com.rymcu.forest.web.api.exception.BaseApiException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -31,6 +35,10 @@ public class ArticleController {
|
||||
private ArticleService articleService;
|
||||
@Resource
|
||||
private CommentService commentService;
|
||||
@Resource
|
||||
private ArticleThumbsUpService articleThumbsUpService;
|
||||
@Resource
|
||||
private SponsorService sponsorService;
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
public GlobalResult<Map<String, Object>> detail(@PathVariable Integer id, @RequestParam(defaultValue = "2") Integer type) {
|
||||
@ -93,4 +101,16 @@ public class ArticleController {
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
@PostMapping("/thumbs-up")
|
||||
public GlobalResult thumbsUp(@RequestBody ArticleThumbsUp articleThumbsUp) throws BaseApiException {
|
||||
Map map = articleThumbsUpService.thumbsUp(articleThumbsUp);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
@PostMapping("/sponsor")
|
||||
public GlobalResult sponsor(@RequestBody Sponsor sponsor) throws Exception {
|
||||
Map map = sponsorService.sponsorship(sponsor);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.rymcu.forest.web.api.bank;
|
||||
|
||||
import com.rymcu.forest.core.exception.ServiceException;
|
||||
import com.rymcu.forest.core.result.GlobalResult;
|
||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.entity.TransactionRecord;
|
||||
@ -23,7 +22,7 @@ public class TransactionRecordController {
|
||||
private TransactionRecordService transactionRecordService;
|
||||
|
||||
@PostMapping("/transfer")
|
||||
public GlobalResult transfer(@RequestBody TransactionRecord transactionRecord) {
|
||||
public GlobalResult transfer(@RequestBody TransactionRecord transactionRecord) throws Exception {
|
||||
transactionRecord = transactionRecordService.transfer(transactionRecord);
|
||||
return GlobalResultGenerator.genSuccessResult(transactionRecord);
|
||||
}
|
||||
|
@ -13,11 +13,15 @@
|
||||
<result column="article_tags" property="articleTags"></result>
|
||||
<result column="article_view_count" property="articleViewCount"></result>
|
||||
<result column="article_preview_content" property="articlePreviewContent"></result>
|
||||
<result column="comment_count" property="articleCommentCount"></result>
|
||||
<result column="article_comment_count" property="articleCommentCount"></result>
|
||||
<result column="article_permalink" property="articlePermalink"></result>
|
||||
<result column="article_link" property="articleLink"></result>
|
||||
<result column="created_time" property="createdTime"></result>
|
||||
<result column="updated_time" property="updatedTime"></result>
|
||||
<result column="article_thumbs_up_count" property="articleThumbsUpCount"></result>
|
||||
<result column="article_status" property="articleStatus"></result>
|
||||
<result column="article_perfect" property="articlePerfect"></result>
|
||||
<result column="article_sponsor_count" property="articleSponsorCount"></result>
|
||||
</resultMap>
|
||||
<resultMap id="DTOResultMap" type="com.rymcu.forest.dto.ArticleDTO">
|
||||
<result column="id" property="idArticle"></result>
|
||||
@ -39,6 +43,8 @@
|
||||
<result column="updated_time" property="updatedTime"></result>
|
||||
<result column="sort_no" property="sortNo"></result>
|
||||
<result column="article_perfect" property="articlePerfect"></result>
|
||||
<result column="article_thumbs_up_count" property="articleThumbsUpCount"></result>
|
||||
<result column="article_sponsor_count" property="articleSponsorCount"></result>
|
||||
</resultMap>
|
||||
<resultMap id="ArticleContentResultMap" type="com.rymcu.forest.entity.ArticleContent">
|
||||
<result column="id_article" property="idArticle"/>
|
||||
|
7
src/main/java/mapper/ArticleThumbsUpMapper.xml
Normal file
7
src/main/java/mapper/ArticleThumbsUpMapper.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?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="com.rymcu.forest.mapper.ArticleThumbsUpMapper">
|
||||
<update id="updateArticleThumbsUpNumber">
|
||||
update vertical_article set article_thumbs_up_count = article_thumbs_up_count + #{thumbsUpNumber} where id = #{idArticle}
|
||||
</update>
|
||||
</mapper>
|
7
src/main/java/mapper/SponsorMapper.xml
Normal file
7
src/main/java/mapper/SponsorMapper.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?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="com.rymcu.forest.mapper.SponsorMapper">
|
||||
<update id="updateArticleSponsorCount">
|
||||
update vertical_article set article_sponsor_count = article_sponsor_count + 1 where id = #{idArticle}
|
||||
</update>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user