模块化拆分

This commit is contained in:
禾几海
2021-09-29 23:09:54 +08:00
parent c8e93c45c7
commit 6d3739517a
157 changed files with 9528 additions and 9014 deletions

91
blog-common/pom.xml Normal file
View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>blog</artifactId>
<groupId>cn.celess</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blog-common</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<!-- pageHelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!--Email-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- TODO: remove this -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>[7.2.0, 7.2.99]</version>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.45.0</version>
</dependency>
<!-- protostuff序列化依赖 -->
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,9 @@
package cn.celess.common.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan("cn.celess.common.mapper")
public class MybatisConfig {
}

View File

@@ -0,0 +1,23 @@
package cn.celess.common.enmu;
import lombok.Getter;
/**
* @Author: 小海
* @Date: 2020-05-25 08:58
* @Desc:
*/
@Getter
public enum CommentStatusEnum {
// 正常
NORMAL(0, "正常"),
DELETED(3, "已删除");
private final int code;
private final String msg;
CommentStatusEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
}

View File

@@ -0,0 +1,96 @@
package cn.celess.common.enmu;
/**
* @author : xiaohai
* @date : 2019/03/28 15:37
*/
public enum ResponseEnum {
// Response enum
SUCCESS(0, "成功"),
FAILURE(-1, "失败"),
ERROR(-2, "错误"),
DATA_IS_DELETED(1000, "数据已被删除"),
//文章类
ARTICLE_NOT_EXIST(2010, "文章不存在"),
ARTICLE_HAS_EXIST(2020, "文章已存在"),
ARTICLE_NOT_PUBLIC(2030, "文章暂未公开"),
ARTICLE_NOT_BELONG_YOU(2040, "无权限操作别人的文章"),
//用户类
HAVE_NOT_LOG_IN(3010, "还未登录"),
PERMISSION_ERROR(3020, "没有此权限"),
USER_NOT_EXIST(3030, "用户不存在"),
USERNAME_HAS_EXIST(3040, "用户名已存在"),
USERNAME_TOO_SHORT(3050, "用户名太短"),
PASSWORD_TOO_SHORT_OR_LONG(3060, "密码长度过长或者过短"),
LOGIN_FAILURE(3100, "登录失败,用户名/密码不正确"),
USEREMAIL_NULL(3310, "未设置邮箱"),
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
LOGIN_LATER(3500, "错误次数已达5次请稍后再试"),
PWD_SAME(3601, "新密码与原密码相同"),
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
LOGIN_EXPIRED(3700, "登陆过期"),
LOGOUT(3710, "账户已注销"),
CAN_NOT_USE(3711, "账户不可用"),
PWD_WRONG(3800, "密码不正确"),
JWT_EXPIRED(3810, "Token过期"),
JWT_MALFORMED(3820, "Token格式不对"),
JWT_SIGNATURE(3830, "Token签名错误"),
JWT_NOT_SUPPORT(3840, "不支持的Token"),
//标签
TAG_NOT_EXIST(4010, "标签不存在"),
TAG_HAS_EXIST(4020, "标签已存在"),
//分类
CATEGORY_NOT_EXIST(5010, "分类不存在"),
CATEGORY_HAS_EXIST(5020, "分类已存在"),
//评论/留言
COMMENT_NOT_EXIST(6010, "评论/留言不存在"),
COMMENT_HAS_EXIST(6020, "评论/留言已存在,请不要重复提交"),
//webUdpateInfo amd PartnerSite
DATA_NOT_EXIST(7010, "数据不存在"),
DATA_HAS_EXIST(7020, "数据已存在"),
//其他
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
DATA_EXPIRED(7300, "数据过期"),
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
NO_FILE(7500, "未选择文件,请重新选择"),
//提交更新之前,没有获取数据/,
DID_NOT_GET_THE_DATA(8020, "非法访问"),
IMG_CODE_TIMEOUT(8100, "验证码已失效"),
IMG_CODE_DIDNOTVERIFY(8200, "请先验证验证码"),
VERIFY_ERROR(8300, "验证失败"),
PARAMETERS_ERROR(8500, "参数错误"),
PARAMETERS_URL_ERROR(8510, "链接格式错误"),
PARAMETERS_EMAIL_ERROR(8520, "邮箱格式错误"),
PARAMETERS_PHONE_ERROR(8530, "手机格式错误"),
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
VERIFY_OUT(8400, "已经验证过了");
private final int code;
private final String msg;
ResponseEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
}

View File

@@ -0,0 +1,23 @@
package cn.celess.common.enmu;
import lombok.Getter;
/**
* @Author: 小海
* @Date: 2020-05-24 16:31
* @Desc:
*/
@Getter
public enum RoleEnum {
// admin 权限
ADMIN_ROLE("admin"),
// user 权限
USER_ROLE("user");
private final String roleName;
RoleEnum(String roleName) {
this.roleName = roleName;
}
}

View File

@@ -0,0 +1,72 @@
package cn.celess.common.enmu;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: 小海
* @Date: 2020-05-22 21:32
* @Desc:
*/
public enum UserAccountStatusEnum {
/**
* 账户正常
*/
NORMAL(0, "正常"),
/**
* 账户被锁定
*/
LOCKED(1, "锁定"),
/**
* 账户被删除
*/
DELETED(2, "已删除");
private final int code;
private final String desc;
UserAccountStatusEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
public static UserAccountStatusEnum get(int code) {
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
if (value.code == code) {
return value;
}
}
return null;
}
@JsonCreator
public static UserAccountStatusEnum get(Map<String, Object> map) {
for (UserAccountStatusEnum value : UserAccountStatusEnum.values()) {
if (value.code == (int) map.get("code") && value.desc.equals(map.get("desc"))) {
return value;
}
}
return null;
}
@JsonValue
public Map<String, Object> toJson() {
Map<String, Object> map = new HashMap<>(2);
map.put("code", code);
map.put("desc", desc);
return map;
}
}

View File

@@ -0,0 +1,64 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/03/28 14:51
*/
@Data
public class Article implements Serializable {
private Long id;
/**
* 标题
*/
private String title;
/**
* 摘要
*/
private String summary;
/**
* Markdown正文
*/
private String mdContent;
/**
* 文章类型 true(1)为原创 false(0)为转载
*/
private Boolean type;
/**
* 若为转载 则为转载文章的url
*/
private String url = null;
private Date publishDate;
private Date updateDate = null;
private Long readingNumber;
/**
* 文章的状态 true公开 false:不公开
*/
private Boolean open;
private Category category;
private List<Tag> tags;
private Integer likeCount;
private Integer dislikeCount;
private User user;
private boolean deleted = false;
}

View File

@@ -0,0 +1,28 @@
package cn.celess.common.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @Author: 小海
* @Date: 2020-05-24 14:52
* @Desc:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ArticleTag implements Serializable {
private Long id;
private Article article;
private TagCategory tag;
public ArticleTag(Article article, TagCategory tag) {
this.article = article;
this.tag = tag;
}
}

View File

@@ -0,0 +1,16 @@
package cn.celess.common.entity;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/03/28 22:18
*/
@NoArgsConstructor
public class Category extends TagCategory implements Serializable {
public Category(String name) {
super.setName(name);
}
}

View File

@@ -0,0 +1,35 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author : xiaohai
* @date : 2019/03/29 16:47
*/
@Data
public class Comment implements Serializable {
private Long id;
private int status;
private String pagePath;
private String content;
private Date date;
private User fromUser;
private User toUser;
/**
* 评论的父ID
*/
private Long pid;
// private boolean delete;
}

View File

@@ -0,0 +1,42 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
/**
* 友链
*
* @author : xiaohai
* @date : 2019/05/12 11:33
*/
@Data
public class PartnerSite implements Serializable {
private Long id;
private String name;
private String url;
private Boolean open;
private String iconPath;
private String desc;
private Boolean delete = false;
private String email;
private Boolean notification = true;
public PartnerSite() {
}
public PartnerSite(String name, String url, Boolean open) {
this.name = name;
this.url = url;
this.open = open;
}
}

View File

@@ -0,0 +1,65 @@
package cn.celess.common.entity;
import cn.celess.common.enmu.ResponseEnum;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.SneakyThrows;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/03/28 15:24
*/
@Data
public class Response<T> implements Serializable {
private int code;
private String msg;
private T result;
public Response() {
}
public Response(int code, String msg, T result) {
this.code = code;
this.msg = msg;
this.result = result;
}
/**
* 成功相应
*
* @param result 结果
* @return Response
*/
public static <T> Response<T> success(T result) {
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
}
/**
* 失败的响应
*
* @param result 结果
* @return Response
*/
public static Response<String> failure(String result) {
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
}
/**
* 其他的响应
*
* @param r 枚举常量
* @param result 结果
* @return Response
*/
public static <T> Response<T> response(ResponseEnum r, T result) {
return new Response<T>(r.getCode(), r.getMsg(), result);
}
@SneakyThrows
@Override
public String toString() {
return new ObjectMapper().writeValueAsString(this);
}
}

View File

@@ -0,0 +1,17 @@
package cn.celess.common.entity;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/03/28 22:19
*/
@NoArgsConstructor
public class Tag extends TagCategory implements Serializable {
public Tag(String name) {
super.setName(name);
}
}

View File

@@ -0,0 +1,21 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: 小海
* @Date: 2020-05-24 14:03
* @Desc:
*/
@Data
public class TagCategory implements Serializable {
private Long id;
private String name;
private Boolean category = true;
private Boolean deleted = false;
}

View File

@@ -0,0 +1,54 @@
package cn.celess.common.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* @author : xiaohai
* @date : 2019/03/28 14:52
*/
@Data
@NoArgsConstructor
public class User implements Serializable {
private Long id;
/**
* 邮箱
*/
private String email;
/**
* 密码
*/
@JsonIgnore
private String pwd;
/**
* 昵称
*/
private String displayName;
private Boolean emailStatus = false;
/**
* 头像地址
*/
private String avatarImgUrl;
private String desc;
private Date recentlyLandedDate;
private String role = "user";
private int status;
public User(String email, String pwd) {
this.email = email;
this.pwd = pwd;
}
}

View File

@@ -0,0 +1,29 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author : xiaohai
* @date : 2019/04/02 22:14
*/
@Data
public class Visitor implements Serializable {
private long id;
private String ip;
private Date date;
private String ua;
private boolean delete;
public Visitor(String ip, Date date, String ua) {
this.ip = ip;
this.date = date;
this.ua = ua;
}
public Visitor() {
}
}

View File

@@ -0,0 +1,29 @@
package cn.celess.common.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author : xiaohai
* @date : 2019/05/12 11:29
*/
@Data
public class WebUpdate implements Serializable {
private long id;
private String updateInfo;
private Date updateTime;
private boolean delete;
public WebUpdate() {
}
public WebUpdate(String updateInfo) {
this.updateInfo = updateInfo;
}
}

View File

@@ -0,0 +1,21 @@
package cn.celess.common.entity.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/06/01 22:46
*/
@Data
public class ArticleReq implements Serializable {
private Long id;
private String title;
private String mdContent;
private String[] tags;
private Boolean type;
private String url;
private String category;
private Boolean open = true;
}

View File

@@ -0,0 +1,18 @@
package cn.celess.common.entity.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/06/02 10:35
*/
@Data
public class CommentReq implements Serializable {
private Long id;
private String content;
private long pid = -1;
private String pagePath;
private long toUserId = -1;
}

View File

@@ -0,0 +1,19 @@
package cn.celess.common.entity.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2020/07/31 20:50
*/
@Data
public class LinkApplyReq implements Serializable {
private String name;
private String email;
private String url;
private String linkUrl;
private String desc;
private String iconPath;
}

View File

@@ -0,0 +1,19 @@
package cn.celess.common.entity.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/06/02 11:40
*/
@Data
public class LinkReq implements Serializable {
private long id;
private String name;
private String url;
private String iconPath;
private String desc;
private boolean open;
}

View File

@@ -0,0 +1,25 @@
package cn.celess.common.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/06/01 22:47
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginReq implements Serializable {
private String email;
private String password;
/**
* isRememberMe默认为false
*/
private Boolean isRememberMe = false;
}

View File

@@ -0,0 +1,28 @@
package cn.celess.common.entity.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: 小海
* @Date 2019/09/06 13:33
* @Description
*/
@Data
public class UserReq implements Serializable {
private Long id;
private String email;
private String pwd;
private String displayName;
private Boolean emailStatus;
private String desc;
private String role;
}

View File

@@ -0,0 +1,88 @@
package cn.celess.common.entity.vo;
import cn.celess.common.entity.Tag;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/04/23 12:02
*/
@Getter
@Setter
public class ArticleModel implements Serializable {
private Long id;
/**
* 标题
*/
private String title;
/**
* 摘要
*/
private String summary;
/**
* Markdown正文
*/
private String mdContent;
/**
* 文章类型 true(1)为原创 false(0)为转载
*/
private Boolean original;
/**
* 若为转载 则为转载文章的url
*/
private String url;
/**
* 发布时间
*/
private String publishDateFormat;
/**
* 更新时间
*/
private String updateDateFormat;
/**
* 分类
*/
private String category;
/**
* 标签
*/
private List<Tag> tags;
/**
* 作者
*/
private UserModel author;
private ArticleModel preArticle;
private ArticleModel nextArticle;
/**
* 阅读数
*/
private Long readingNumber;
private Integer likeCount;
private Integer dislikeCount;
/**
* 文章的状态 true公开 false:不公开
*/
private Boolean open;
private boolean deleted;
}

View File

@@ -0,0 +1,25 @@
package cn.celess.common.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @Author: 小海
* @Date: 2020-03-29 12:18
* @Desc:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CategoryModel implements Serializable {
private Long id;
private String name;
private List<ArticleModel> articles;
private boolean deleted;
}

View File

@@ -0,0 +1,45 @@
package cn.celess.common.entity.vo;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/04/22 21:50
*/
@Setter
@Getter
public class CommentModel implements Serializable {
private long id;
private UserModel fromUser;
private UserModel toUser;
/**
* 内容
*/
private String content;
/**
* 文章标题
*/
private String pagePath;
/**
* 发布日期
*/
private String date;
/**
* 评论的父ID
*/
private Long pid;
private List<CommentModel> respComment;
private int status;
}

View File

@@ -0,0 +1,39 @@
package cn.celess.common.entity.vo;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @Author: 小海
* @Date: 2020-05-25 17:13
* @Desc:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageData<T> implements Serializable {
private List<T> list;
private long total;
private int pageSize;
private int pageNum;
public PageData(PageInfo pageInfo) {
this.pageNum = pageInfo.getPageNum();
this.pageSize = pageInfo.getPageSize();
this.total = pageInfo.getTotal();
}
public PageData(PageInfo pageInfo, List<T> data) {
this(pageInfo);
this.list = data;
}
}

View File

@@ -0,0 +1,15 @@
package cn.celess.common.entity.vo;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/04/21 22:43
*/
public class QiniuResponse implements Serializable {
public String key;
public String hash;
public String bucket;
public long fsize;
}

View File

@@ -0,0 +1,26 @@
package cn.celess.common.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @Author: 小海
* @Date: 2020-03-29 13:56
* @Desc:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TagModel implements Serializable {
private Long id;
private String name;
private List<ArticleModel> articles;
private boolean deleted;
}

View File

@@ -0,0 +1,45 @@
package cn.celess.common.entity.vo;
import cn.celess.common.enmu.UserAccountStatusEnum;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/04/22 23:13
*/
@Getter
@Setter
public class UserModel implements Serializable {
private Long id;
/**
* 邮箱
*/
private String email;
/**
* 昵称
*/
private String displayName;
private Boolean emailStatus = false;
/**
* 头像地址
*/
private String avatarImgUrl;
private String desc;
private String recentlyLandedDate;
private String role = "user";
private String token;
private UserAccountStatusEnum status;
}

View File

@@ -0,0 +1,26 @@
package cn.celess.common.entity.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/05/05 16:05
*/
@Data
public class VisitorModel implements Serializable {
private long id;
private String ip;
private String date;
private String browserName;
private String browserVersion;
private String OSName;
private String location;
}

View File

@@ -0,0 +1,28 @@
package cn.celess.common.entity.vo;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author : xiaohai
* @date : 2019/05/12 11:32
*/
@Data
@NoArgsConstructor
public class WebUpdateModel implements Serializable {
private long id;
private String info;
private String time;
public WebUpdateModel(long id, String info, String time) {
this.id = id;
this.info = info;
this.time = time;
}
private boolean deleted;
}

View File

@@ -0,0 +1,101 @@
package cn.celess.common.exception;
import cn.celess.common.enmu.ResponseEnum;
import cn.celess.common.entity.Response;
import cn.celess.common.service.MailService;
import cn.celess.common.util.DateFormatUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @author : xiaohai
* @date : 2019/03/28 17:02
*/
@ControllerAdvice
public class ExceptionHandle {
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
@Resource
MailService mailService;
@Autowired
HttpServletRequest request;
@Value("${spring.profiles.active}")
private String activeModel;
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Response handle(Exception e) {
//自定义错误
if (e instanceof MyException) {
MyException exception = (MyException) e;
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
}
//请求路径不支持该方法
if (e instanceof HttpRequestMethodNotSupportedException) {
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={}path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null);
}
//数据输入类型不匹配
if (e instanceof MethodArgumentTypeMismatchException) {
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null);
}
//数据验证失败
if (e instanceof BindException) {
logger.debug("数据验证失败,[msg={}]", e.getMessage());
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null);
}
//数据输入不完整
if (e instanceof MissingServletRequestParameterException) {
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null);
}
// 发送错误信息到邮箱
if ("prod".equals(activeModel)) {
logger.debug("有一个未捕获的bug已发送到邮箱");
sendMessage(e);
}
e.printStackTrace();
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null);
}
/**
* 发送错误信息
*
* @param e 错误
*/
private void sendMessage(Exception e) {
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo("a@celess.cn");
simpleMailMessage.setSubject("服务器出现了错误");
StringBuilder msg = new StringBuilder();
String queryString = request.getQueryString();
msg.append("requirePath:\n").append(request.getRequestURL().toString());
if (queryString != null) {
msg.append("?").append(queryString);
}
msg.append("\n\n\n");
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
msg.append("ip:\n").append(request.getRemoteAddr()).append("\n\n\n");
simpleMailMessage.setText(msg.toString());
mailService.AsyncSend(simpleMailMessage);
}
}

View File

@@ -0,0 +1,41 @@
package cn.celess.common.exception;
import cn.celess.common.enmu.ResponseEnum;
import lombok.Data;
/**
* @author : xiaohai
* @date : 2019/03/28 16:56
*/
@Data
public class MyException extends RuntimeException {
private int code;
private Object result;
public MyException(int code, String msg) {
super(msg);
this.code = code;
}
public MyException(ResponseEnum e) {
super(e.getMsg());
this.code = e.getCode();
}
public MyException(ResponseEnum e, Object result) {
super(e.getMsg());
this.code = e.getCode();
this.result = result;
}
public MyException(ResponseEnum e, String msg) {
super(msg + e.getMsg());
this.code = e.getCode();
}
public MyException(ResponseEnum e, String msg, Object result) {
super(e.getMsg());
this.code = e.getCode();
this.result = result;
}
}

View File

@@ -0,0 +1,55 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/06/27 20:43
* @Description
*/
@Mapper
@Repository
public interface ArticleMapper {
int insert(Article a);
int delete(long id);
int update(Article a);
Article getLastestArticle();
Article findArticleById(long id);
boolean existsByTitle(String title);
boolean isDeletedById(long id);
List<Article> findAllByAuthorId(long authorId);
List<Article> findAllByOpen(boolean isOpen);
String getTitleById(long id);
List<Article> findAllByCategoryId(long id);
List<Article> findAllByCategoryIdAndOpen(long id);
List<Article> findAll();
@Cacheable(value = {"articleDao"}, key = "'getPreArticle:'+#id")
Article getPreArticle(Long id);
@Cacheable(value = {"articleDao"}, key = "'getNextArticle:'+#id")
Article getNextArticle(Long id);
int updateReadingNumber(long id);
long count();
}

View File

@@ -0,0 +1,38 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.ArticleTag;
import cn.celess.common.entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date: 2020-05-24 14:21
* @Desc:
*/
@Mapper
@Repository
public interface ArticleTagMapper {
int insert(ArticleTag articleTag);
int update(ArticleTag articleTag);
ArticleTag findOneById(Long id);
int deleteById(Long id);
int deleteByArticleId(Long articleId);
List<ArticleTag> findAllByArticleId(Long articleId);
List<Tag> findTagByArticleId(Long articleId);
int deleteMultiById(List<ArticleTag> articleTags);
List<ArticleTag> findArticleByTag(Long tagId);
List<ArticleTag> findArticleByTagAndOpen(Long tagId);
}

View File

@@ -0,0 +1,42 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/06/30 12:56
* @Description
*/
@Mapper
@Repository
public interface CategoryMapper {
int insert(Category c);
int delete(long id);
int update(Category c);
boolean existsByName(String name);
boolean existsById(long id);
Category findCategoryByName(String name);
Category findCategoryById(long id);
List<Category> findAll();
List<String> getAllName();
String getNameById(long id);
Long getIdByName(String name);
Category getLastestCategory();
long count();
}

View File

@@ -0,0 +1,44 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date: 2019/06/30 16:19
* @Description:
*/
@Mapper
@Repository
public interface CommentMapper {
int insert(Comment c);
int updateContent(String content, long id);
int delete(long id);
int deleteByPagePath(String pagePath);
boolean existsById(long id);
Comment findCommentById(long id);
Comment getLastestComment();
List<Comment> findAllByFromUser(long id);
List<Comment> findAllByPid(long pid);
List<Comment> findAllByPagePath(String pagePath);
List<Comment> findAllByPagePathAndFromUser(String pagePath, long userId);
List<Comment> findAllByPagePathAndPidAndNormal(String pagePath, long pid);
long countByPagePath(String pagePath);
long count();
}

View File

@@ -0,0 +1,41 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.PartnerSite;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/07/03 00:22
* @Description
*/
@Mapper
@Repository
public interface PartnerMapper {
int insert(PartnerSite site);
int delete(long id);
int update(PartnerSite site);
boolean existsById(long id);
boolean existsByName(String name);
boolean existsByUrl(String url);
PartnerSite findById(long id);
PartnerSite findByName(String name);
PartnerSite findByUrl(String url);
PartnerSite getLastest();
List<PartnerSite> findAll();
List<PartnerSite> findAll(Boolean deleted);
}

View File

@@ -0,0 +1,34 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/06/29 22:00
* @Description
*/
@Mapper
@Repository
public interface TagMapper {
int insert(Tag tag);
int update(Tag tag);
int delete(long id);
Tag findTagById(long id);
Tag findTagByName(String name);
Boolean existsByName(String name);
Tag getLastestTag();
List<Tag> findAll();
long count();
}

View File

@@ -0,0 +1,61 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/07/03 00:23
* @Description
*/
@Mapper
@Repository
public interface UserMapper {
int addUser(User user);
int updateInfo(String desc, String displayName, long id);
int updateAvatarImgUrl(String avatarImgUrl, long id);
int updateLoginTime(String email);
int updateEmailStatus(String email, boolean status);
int updatePwd(String email, String pwd);
String getPwd(String email);
boolean existsByEmail(String email);
User findByEmail(String email);
User findById(long id);
String getAvatarImgUrlById(long id);
String getEmail(long id);
String getDisPlayName(long id);
String getRoleByEmail(String email);
String getRoleById(long id);
long count();
int delete(long id);
int lock(long id);
int setUserRole(Long id, String role);
List<User> findAll(Integer status);
List<User> findAll();
int update(User user);
}

View File

@@ -0,0 +1,26 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.Visitor;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/07/03 00:23
* @Description
*/
@Repository
@Mapper
public interface VisitorMapper {
int insert(Visitor visitor);
int delete(long id);
List<Visitor> findAll();
List<Visitor> findAllNotDeleted();
long count();
}

View File

@@ -0,0 +1,32 @@
package cn.celess.common.mapper;
import cn.celess.common.entity.WebUpdate;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author: 小海
* @Date 2019/07/03 00:24
* @Description
*/
@Mapper
@Repository
public interface WebUpdateInfoMapper {
int insert(WebUpdate webUpdate);
int delete(long id);
int update(long id, String info);
boolean existsById(long id);
WebUpdate findById(long id);
List<WebUpdate> findAll();
List<WebUpdate> findAllNotDeleted();
WebUpdate getLastestOne();
}

View File

@@ -0,0 +1,85 @@
package cn.celess.common.service;
import cn.celess.common.entity.dto.ArticleReq;
import cn.celess.common.entity.vo.ArticleModel;
import cn.celess.common.entity.vo.PageData;
import org.springframework.stereotype.Service;
/**
* @author : xiaohai
* @date : 2019/03/28 15:20
*/
@Service
public interface ArticleService {
/**
* 新增一篇文章
*
* @param reqBody 请求文章的数据
* @return 文章数据
*/
ArticleModel create(ArticleReq reqBody);
/**
* 删除一篇文章
*
* @param articleID 文章id
* @return 删除状态 true删除成功 false失败
*/
boolean delete(long articleID);
/**
* 更新一篇文章
*
* @param reqBody 请求数据
* @return 文章数据
*/
ArticleModel update(ArticleReq reqBody);
/**
* 获取一篇文章的数据
*
* @param articleId 文章id
* @param is4update 是否是因文章更新而请求数据
* @return 文章数据
*/
ArticleModel retrieveOneById(long articleId, boolean is4update);
/**
* 管理员 获取分页数据
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted);
/**
* 获取文章状态为开放的文章
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<ArticleModel> retrievePageForOpen(int count, int page);
/**
* 根据分类名获取文章数据
*
* @param name 分类名
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<ArticleModel> findByCategory(String name, int page, int count);
/**
* 根据标签名获取文章数据
*
* @param name 标签名
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<ArticleModel> findByTag(String name, int page, int count);
}

View File

@@ -0,0 +1,45 @@
package cn.celess.common.service;
import cn.celess.common.entity.vo.CategoryModel;
import cn.celess.common.entity.vo.PageData;
import org.springframework.stereotype.Service;
/**
* @author : xiaohai
* @date : 2019/03/28 22:42
*/
@Service
public interface CategoryService {
/**
* 增加一个分类
*
* @param name 分类名
* @return 所增加的分类数据
*/
CategoryModel create(String name);
/**
* 通过id删除分类
*
* @param id 分类id
* @return 删除状态
*/
boolean delete(long id);
/**
* 编辑分类的名字
*
* @param id 分类id
* @param name 分类名字
* @return 更新后的分类的数据
*/
CategoryModel update(Long id, String name);
/**
* 获取全部的分类数据
*
* @return 全部的分类数据
*/
PageData<CategoryModel> retrievePage(int page, int count);
}

View File

@@ -0,0 +1,92 @@
package cn.celess.common.service;
import cn.celess.common.entity.dto.CommentReq;
import cn.celess.common.entity.vo.CommentModel;
import cn.celess.common.entity.vo.PageData;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/03/29 16:58
*/
@Service
public interface CommentService {
/**
* 新增数据
*
* @param reqBody 请求数据体
* @return 增加的comment数据
*/
CommentModel create(CommentReq reqBody);
/**
* 删除数据
*
* @param id comment的id
* @return 删除状态
*/
boolean delete(long id);
/**
* 更新数据
*
* @param reqBody comment请求体
* @return 更新后的数据
*/
CommentModel update(CommentReq reqBody);
/**
* 分页获取数据
*
* @param pagePath pagePath
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<CommentModel> retrievePage(String pagePath, int page, int count);
/**
* 通过pid获取数据
*
* @param pid 父id
* @return 分页数据
*/
List<CommentModel> retrievePageByPid(long pid);
/**
* 根据评论者获取数据
*
* @param pagePath pagePath
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count);
/**
* 根据数据的type和pid获取数据
*
* @param pagePath pagePath
* @param pid 父id
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count);
/**
* 根据type获取数据
*
* @param pagePath pagePath
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count);
}

View File

@@ -0,0 +1,59 @@
package cn.celess.common.service;
import org.springframework.stereotype.Service;
/**
* @author : xiaohai
* @date : 2019/04/02 22:04
*/
@Service
public interface CountService {
/**
* 获取评论的数据量
*
* @return 评论的数据量
*/
long getCommentCount();
/**
* 获取文章的篇数
*
* @return 文章的篇数
*/
long getArticleCount();
/**
* 获取分类数量
*
* @return 分类数量
*/
long getCategoriesCount();
/**
* 获取标签数量
*
* @return 标签数量
*/
long getTagsCount();
/**
* 获取用户量
*
* @return 用户量
*/
long getUserCount();
/**
* 获取总访问量
*
* @return 总访问量
*/
long getVisitorCount();
/**
* 获取日访问量
*
* @return 日访问量
*/
long getDayVisitCount();
}

View File

@@ -0,0 +1,27 @@
package cn.celess.common.service;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;
/**
* @author : xiaohai
* @date : 2019/04/22 14:25
*/
@Service
public interface MailService {
/**
* 异步发生邮件
*
* @param message SimpleMailMessage对象
* @return //
*/
Boolean AsyncSend(SimpleMailMessage message);
/**
* 同步发送邮件
*
* @param message SimpleMailMessage对象
* @return 发送状态
*/
Boolean send(SimpleMailMessage message);
}

View File

@@ -0,0 +1,72 @@
package cn.celess.common.service;
import cn.celess.common.entity.PartnerSite;
import cn.celess.common.entity.dto.LinkApplyReq;
import cn.celess.common.entity.dto.LinkReq;
import cn.celess.common.entity.vo.PageData;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/05/12 11:42
*/
@Service
public interface PartnerSiteService {
/**
* 新增数据
*
* @param reqBody 数据请求体
* @return 新增数据
*/
PartnerSite create(LinkReq reqBody);
/**
* 删除数据
*
* @param id 数据id
* @return 删除状态
*/
Boolean del(long id);
/**
* 更新数据
*
* @param reqBody 数据请求体
* @return 更新后的数据
*/
PartnerSite update(LinkReq reqBody);
/**
* 分页获取数据
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted);
/**
* 获取全部数据
*
* @return 全部友链数据
*/
List<PartnerSite> findAll();
/**
* 申请友链
*
* @param linkApplyReq linkApplyReq
* @return linkApplyReq
*/
PartnerSite apply(LinkApplyReq linkApplyReq);
/**
* 重写申请友链
*
* @param key key
* @return msg
*/
String reapply(String key);
}

View File

@@ -0,0 +1,31 @@
package cn.celess.common.service;
import cn.celess.common.entity.vo.QiniuResponse;
import com.qiniu.storage.model.FileInfo;
import org.springframework.stereotype.Service;
import java.io.InputStream;
/**
* @author : xiaohai
* @date : 2019/04/25 18:15
*/
@Service
public interface QiniuService {
/**
* 上传文件
*
* @param is InputStream流
* @param fileName 文件名
* @return 响应数据
*/
QiniuResponse uploadFile(InputStream is, String fileName);
/**
* 获取文件列表
*
* @return 文件列表
*/
FileInfo[] getFileList();
}

View File

@@ -0,0 +1,56 @@
package cn.celess.common.service;
import cn.celess.common.entity.vo.PageData;
import cn.celess.common.entity.vo.TagModel;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : xiaohai
* @date : 2019/03/28 22:23
*/
@Service
public interface TagService {
/**
* 新增数据
*
* @param name 标签名
* @return 新增后的数据
*/
TagModel create(String name);
/**
* 删除数据
*
* @param tagId 标签id
* @return 删除状态
*/
boolean delete(long tagId);
/**
* 更新数据
*
* @param id 标签id
* @param name 改名的name值
* @return 更新后的数据
*/
TagModel update(Long id, String name);
/**
* 分页获取标签数据
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<TagModel> retrievePage(int page, int count);
/**
* 获取全部标签数据
*
* @return 标签数据列表
*/
List<TagModel> findAll();
}

View File

@@ -0,0 +1,159 @@
package cn.celess.common.service;
import cn.celess.common.entity.dto.LoginReq;
import cn.celess.common.entity.dto.UserReq;
import cn.celess.common.entity.vo.PageData;
import cn.celess.common.entity.vo.UserModel;
import org.springframework.stereotype.Service;
import java.io.InputStream;
/**
* @author : xiaohai
* @date : 2019/03/30 18:40
*/
@Service
public interface UserService {
/**
* 注册
*
* @param email 邮箱
* @param password 密码
* @return 注册状态
*/
Boolean registration(String email, String password);
/**
* 登录
*
* @param loginReq 请求数据
* @return 用户数据
*/
UserModel login(LoginReq loginReq);
/**
* 注销登录
*
* @return **
*/
Object logout();
/**
* 更新用户数据
*
* @param desc 用户描述
* @param displayName 显示昵称
* @return 用户数据
*/
UserModel update(String desc, String displayName);
/**
* 更新头像
*
* @param is 头像文件的输入流
* @param mime 文件的mime
* @return 响应数据
*/
Object updateUserAavatarImg(InputStream is, String mime);
/**
* 获取session中存储的用户资料
*
* @return 用户资料
*/
UserModel getUserInfoBySession();
/**
* 获取用户的角色
*
* @param email 用户的邮箱
* @return role
*/
String getUserRoleByEmail(String email);
/**
* 获取邮箱是否注册过
*
* @param email 用户邮箱
* @return 注册状态
*/
boolean isExistOfEmail(String email);
/**
* 发送重置密码邮件
*
* @param email 用户邮箱
* @return 发送状态
*/
Object sendResetPwdEmail(String email);
/**
* 发送验证邮箱邮件
*
* @param email 用户邮箱
* @return 发送状态
*/
Object sendVerifyEmail(String email);
/**
* 验证邮箱
*
* @param verifyId 验证码
* @param email 邮箱
* @return 验证状态
*/
Object verifyEmail(String verifyId, String email);
/**
* 重置密码
*
* @param verifyId 验证码
* @param email 邮箱
* @param pwd 新密码
* @return 修改状态
*/
Object reSetPwd(String verifyId, String email, String pwd);
/**
* 删除用户
*
* @param id 用户id的数组
* @return 对应id 的删除状态
*/
Object deleteUser(Integer[] id);
/**
* 获取用户列表
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<UserModel> getUserList(Integer page, Integer count, Integer status);
/**
* 更改用户信息
*
* @param user 用户数据
* @return 用户信息
*/
UserModel adminUpdate(UserReq user);
/**
* 获取电子邮件的存在状态
*
* @param email email
* @return true:存在 false不存在
*/
boolean getStatusOfEmail(String email);
/**
* 设置密码
*
* @param pwd pwd
* @param newPwd newPwd
* @param confirmPwd confirmPwd
* @return UserModel
*/
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
}

View File

@@ -0,0 +1,40 @@
package cn.celess.common.service;
import cn.celess.common.entity.vo.PageData;
import cn.celess.common.entity.vo.VisitorModel;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
/**
* @author : xiaohai
* @date : 2019/04/02 23:03
*/
@Service
public interface VisitorService {
/**
* 分页获取访客数据
*
* @param count 单页数据量
* @param page 数据页
* @param showLocation 是否显示位置信息 开启改选项数据响应超慢
* @return 分页数据
*/
PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation);
/**
* 新增访客
*
* @param request HttpServletRequest
* @return 返回状态 null: 访客信息已记录、爬虫
*/
VisitorModel addVisitor(HttpServletRequest request);
/**
* 获取位置信息
*
* @param ip ip地址
* @return 位置信息
*/
String location(String ip);
}

View File

@@ -0,0 +1,64 @@
package cn.celess.common.service;
import cn.celess.common.entity.vo.PageData;
import cn.celess.common.entity.vo.WebUpdateModel;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* @author : xiaohai
* @date : 2019/05/12 11:42
*/
@Service
public interface WebUpdateInfoService {
/**
* 新增记录
*
* @param info 更新内容
* @return 创建状态
*/
WebUpdateModel create(String info);
/**
* 删除数据
*
* @param id 数据id
* @return 删除状态
*/
Boolean del(long id);
/**
* 更新数据
*
* @param id 数据id
* @param info 新内容
* @return 数据
*/
WebUpdateModel update(long id, String info);
/**
* 分页获取更新记录
*
* @param count 单页数据量
* @param page 数据页
* @return 分页数据
*/
PageData<WebUpdateModel> pages(int count, int page);
/**
* 获取全部的更新记录
*
* @return 更新记录
*/
List<WebUpdateModel> findAll();
/**
* 获取最后更新时间
*
* @return
*/
Map<String, Object> getLastestUpdateTime();
}

View File

@@ -0,0 +1,42 @@
package cn.celess.common.util;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* @author : xiaohai
* @date : 2019/03/28 17:22
*/
public class DateFormatUtil {
public static String get(Date date) {
if (date == null) {
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
public static String getForXmlDate(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
GregorianCalendar gc = new GregorianCalendar();
String dateString = sdf.format(date);
try {
gc.setTime(sdf.parse(dateString));
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
return date2.toString();
} catch (DatatypeConfigurationException | ParseException e) {
e.printStackTrace();
return null;
}
}
public static String getNow() {
return get(new Date());
}
}

View File

@@ -0,0 +1,53 @@
package cn.celess.common.util;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;
/**
* @Author: 小海
* @Date: 2020-04-23 15:51
* @Desc:
*/
public class HttpUtil {
public static String get(String urlStr) {
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setDownloadImages(false);
webClient.getOptions().setActiveXNative(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
Page clientPage = webClient.getPage(urlStr);
if (clientPage.isHtmlPage()) {
return clientPage.toString();
}
return null;
} catch (IOException e) {
return null;
}
}
public static String getAfterRendering(String url) {
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setDownloadImages(false);
webClient.getOptions().setActiveXNative(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
final HtmlPage page = webClient.getPage(url);
return page.asXml();
} catch (IOException e) {
return null;
}
}
}

View File

@@ -0,0 +1,14 @@
package cn.celess.common.util;
import org.springframework.util.DigestUtils;
/**
* @author : xiaohai
* @date : 2019/03/30 18:56
*/
public class MD5Util {
public static String getMD5(String str) {
String md5 = DigestUtils.md5DigestAsHex(str.getBytes());
return md5;
}
}

View File

@@ -0,0 +1,112 @@
package cn.celess.common.util;
import cn.celess.common.enmu.UserAccountStatusEnum;
import cn.celess.common.entity.*;
import cn.celess.common.entity.vo.*;
import org.springframework.beans.BeanUtils;
/**
* @Author: 小海
* @Date: 2020-05-24 18:04
* @Desc:
*/
public class ModalTrans {
public static ArticleModel article(Article article) {
if (article == null) {
return null;
}
ArticleModel articleModel = new ArticleModel();
BeanUtils.copyProperties(article, articleModel);
articleModel.setPublishDateFormat(DateFormatUtil.get(article.getPublishDate()));
articleModel.setUpdateDateFormat(DateFormatUtil.get(article.getUpdateDate()));
articleModel.setOriginal(article.getType());
articleModel.setCategory(article.getCategory().getName());
articleModel.setAuthor(user(article.getUser()));
articleModel.getTags().forEach(tag -> {
tag.setCategory(null);
tag.setDeleted(null);
});
return articleModel;
}
public static ArticleModel article(Article article, boolean noMdContent) {
ArticleModel article1 = article(article);
if (!noMdContent || article1 == null) {
return article1;
}
article1.setMdContent(null);
article1.setOpen(null);
return article1;
}
public static UserModel userFullInfo(User user) {
if (user == null || user.getId() == -1) {
return null;
}
UserModel userModel = new UserModel();
BeanUtils.copyProperties(user, userModel);
userModel.setStatus(UserAccountStatusEnum.get(user.getStatus()));
userModel.setAvatarImgUrl(user.getAvatarImgUrl() == null || user.getAvatarImgUrl().length() == 0 ?
null :
"http://cdn.celess.cn/" + user.getAvatarImgUrl());
userModel.setDisplayName(user.getDisplayName() == null ? user.getEmail() : user.getDisplayName());
userModel.setRecentlyLandedDate(DateFormatUtil.get(user.getRecentlyLandedDate()));
return userModel;
}
public static UserModel user(User user) {
UserModel model = userFullInfo(user);
if (model == null) {
return null;
}
model.setRole(null);
model.setEmailStatus(null);
return model;
}
public static CategoryModel category(Category category) {
if (category == null) {
return null;
}
CategoryModel model = new CategoryModel();
BeanUtils.copyProperties(category, model);
return model;
}
public static TagModel tag(Tag tag) {
if (tag == null) {
return null;
}
TagModel model = new TagModel();
BeanUtils.copyProperties(tag, model);
return model;
}
public static WebUpdateModel webUpdate(WebUpdate update) {
if (update == null) {
return null;
}
WebUpdateModel model = new WebUpdateModel();
model.setId(update.getId());
model.setInfo(update.getUpdateInfo());
model.setTime(DateFormatUtil.get(update.getUpdateTime()));
return model;
}
public static CommentModel comment(Comment comment) {
if (comment == null) {
return null;
}
CommentModel model = new CommentModel();
BeanUtils.copyProperties(comment, model);
model.setFromUser(user(comment.getFromUser()));
model.setToUser(user(comment.getToUser()));
model.setDate(DateFormatUtil.get(comment.getDate()));
return model;
}
}

View File

@@ -0,0 +1,126 @@
package cn.celess.common.util;
import com.dyuproject.protostuff.LinkedBuffer;
import com.dyuproject.protostuff.ProtostuffIOUtil;
import com.dyuproject.protostuff.Schema;
import com.dyuproject.protostuff.runtime.RuntimeSchema;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
/**
* ProtoStuffSerializerUtil
*
* @author Sirius
* @date 2019-1-8
*/
public class ProtoStuffSerializerUtil {
/**
* 序列化对象
*
* @param obj
* @return
*/
public static <T> byte[] serialize(T obj) {
if (obj == null) {
throw new RuntimeException("序列化对象(" + obj + ")!");
}
@SuppressWarnings("unchecked")
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(obj.getClass());
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
byte[] protostuff = null;
try {
protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Exception e) {
throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
} finally {
buffer.clear();
}
return protostuff;
}
/**
* 反序列化对象
*
* @param paramArrayOfByte
* @param targetClass
* @return
*/
public static <T> T deserialize(byte[] paramArrayOfByte, Class<T> targetClass) {
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
}
T instance = null;
try {
instance = targetClass.newInstance();
} catch (InstantiationException e1) {
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e1);
} catch (IllegalAccessException e2) {
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e2);
}
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
ProtostuffIOUtil.mergeFrom(paramArrayOfByte, instance, schema);
return instance;
}
/**
* 序列化列表
*
* @param objList
* @return
*/
public static <T> byte[] serializeList(List<T> objList) {
if (objList == null || objList.isEmpty()) {
throw new RuntimeException("序列化对象列表(" + objList + ")参数异常!");
}
@SuppressWarnings("unchecked")
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(objList.get(0).getClass());
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
byte[] protostuff = null;
ByteArrayOutputStream bos = null;
try {
bos = new ByteArrayOutputStream();
ProtostuffIOUtil.writeListTo(bos, objList, schema, buffer);
protostuff = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException("序列化对象列表(" + objList + ")发生异常!", e);
} finally {
buffer.clear();
try {
if (bos != null) {
bos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return protostuff;
}
/**
* 反序列化列表
*
* @param paramArrayOfByte
* @param targetClass
* @return
*/
public static <T> List<T> deserializeList(byte[] paramArrayOfByte, Class<T> targetClass) {
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
}
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
List<T> result = null;
try {
result = ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(paramArrayOfByte), schema);
} catch (IOException e) {
throw new RuntimeException("反序列化对象列表发生异常!", e);
}
return result;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
package cn.celess.common.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author : xiaohai
* @date : 2019/05/12 11:04
*/
public class RegexUtil {
/**
* 网址匹配
*
* @param url
* @return
*/
public static boolean urlMatch(String url) {
if (url == null || url.replaceAll(" ", "").isEmpty()) {
return false;
}
//正则 http(s)://www.celess/xxxx,www.celess.cn/xxx
String pattern = "^(http://|https://|)([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
return match(url, pattern);
}
/**
* 邮箱验证
*
* @param email
* @return
*/
public static boolean emailMatch(String email) {
if (email == null || email.replaceAll(" ", "").isEmpty()) {
return false;
}
//正则
String pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
return match(email, pattern);
}
/**
* 手机号匹配
*
* @param phone
* @return
*/
public static boolean phoneMatch(String phone) {
if (phone == null || phone.replaceAll(" ", "").isEmpty()) {
return false;
}
//正则
String pattern = "^([1][3,4,5,6,7,8,9])\\d{9}$";
return match(phone, pattern);
}
/**
* 密码正则
* 最短6位最长16位 {6,16}
* 可以包含小写大母 [a-z] 和大写字母 [A-Z]
* 可以包含数字 [0-9]
* 可以包含下划线 [ _ ] 和减号 [ - ]
*
* @param pwd
* @return
*/
public static boolean pwdMatch(String pwd) {
if (pwd == null || pwd.replaceAll(" ", "").isEmpty()) {
return false;
}
//正则
String pattern = "^[\\w_-]{6,16}$";
return match(pwd, pattern);
}
private static boolean match(String str, String pattern) {
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(str);
return m.matches();
}
}

View File

@@ -0,0 +1,17 @@
package cn.celess.common.util;
import javax.servlet.http.HttpServletRequest;
/**
* @Author: 小海
* @Date: 2019/10/18 15:44
* @Description:
*/
public class RequestUtil {
public static String getCompleteUrlAndMethod(HttpServletRequest request) {
// like this : /articles?page=1&count=5:GET
return request.getRequestURI() +
(request.getQueryString() == null ? "" : "?" + request.getQueryString()) +
":" + request.getMethod();
}
}

View File

@@ -0,0 +1,17 @@
package cn.celess.common.util;
/**
* @author : xiaohai
* @date : 2019/03/28 17:21
*/
public class StringFromHtmlUtil {
public static String getString(String html) {
//从html中提取纯文本
//剔出<html>的标签
String txtcontent = html.replaceAll("</?[^>]+>", "");
//去除字符串中的空格,回车,换行符,制表符
txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
return txtcontent;
}
}

View File

@@ -0,0 +1,90 @@
package cn.celess.common.util;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
/**
* @author : xiaohai
* @date : 2019/04/11 15:42
*/
public class VeriCodeUtil {
// 验证码字符集
private static final char[] chars = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
// 字符数量
private static final int SIZE = 4;
// 干扰线数量
private static final int LINES = 5;
// 宽度
private static final int WIDTH = 80;
// 高度
private static final int HEIGHT = 40;
// 字体大小
private static final int FONT_SIZE = 30;
/**
* 生成随机验证码及图片
* Object[0]:验证码字符串;
* Object[1]:验证码图片。
*/
public static Object[] createImage() {
StringBuffer sb = new StringBuffer();
// 1.创建空白图片
BufferedImage image = new BufferedImage(
WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// 2.获取图片画笔
Graphics graphic = image.getGraphics();
// 3.设置画笔颜色
graphic.setColor(Color.LIGHT_GRAY);
// 4.绘制矩形背景
graphic.fillRect(0, 0, WIDTH, HEIGHT);
// 5.画随机字符
Random ran = new Random();
for (int i = 0; i < SIZE; i++) {
// 取随机字符索引
int n = ran.nextInt(chars.length);
// 设置随机颜色
graphic.setColor(getRandomColor());
// 设置字体大小
graphic.setFont(new Font(
null, Font.BOLD + Font.ITALIC, FONT_SIZE));
// 画字符
graphic.drawString(
chars[n] + "", i * WIDTH / SIZE, HEIGHT * 2 / 3);
// 记录字符
sb.append(chars[n]);
}
// 6.画干扰线
for (int i = 0; i < LINES; i++) {
// 设置随机颜色
graphic.setColor(getRandomColor());
// 随机画线
graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT),
ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
}
// 7.返回验证码和图片
return new Object[]{sb.toString(), image};
}
/**
* 随机取色
*/
public static Color getRandomColor() {
Random ran = new Random();
Color color = new Color(ran.nextInt(256),
ran.nextInt(256), ran.nextInt(256));
return color;
}
}

View File

@@ -0,0 +1,109 @@
<?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.celess.common.mapper.ArticleTagMapper">
<resultMap id="articleTagResultMap" type="cn.celess.common.entity.ArticleTag">
<id column="at_id" property="id"/>
<result column="a_id" property="article.id"/>
<result column="t_id" property="tag.id"/>
<association property="article" column="a_id" resultMap="cn.celess.common.mapper.ArticleMapper.articleResultMap"
javaType="cn.celess.common.entity.Article">
</association>
<association property="tag" column="t_id" resultMap="cn.celess.common.mapper.CategoryMapper.categoryResultMap"
javaType="cn.celess.common.entity.TagCategory">
</association>
</resultMap>
<!--新增-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into article_tag(a_id, t_id)
values (#{article.id}, #{tag.id})
</insert>
<!--通过主键修改数据-->
<update id="update">
update article_tag
<set>
<if test="article!=null and article.id != null">
a_id = #{article.id},
</if>
<if test="tag!=null and tag.id != null">
t_id = #{tag.id},
</if>
</set>
where at_id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from article_tag
where at_id = #{id};
</delete>
<delete id="deleteMultiById">
delete from article_tag where at_id in
<foreach item="item" collection="list" open="(" close=")" separator=",">
#{item.id}
</foreach>
</delete>
<!--通过主键删除-->
<update id="deleteByArticleId">
delete
from article_tag
where a_id = #{id}
</update>
<select id="findAllByArticleId" resultMap="articleTagResultMap">
select *
from article_tag,
tag_category
where a_id = #{articleId}
and article_tag.t_id = tag_category.t_id
</select>
<select id="findTagByArticleId" resultMap="cn.celess.common.mapper.TagMapper.tagResultMap">
select tag_category.*
from article_tag,
tag_category
where a_id = #{articleId}
and article_tag.t_id = tag_category.t_id
</select>
<select id="findOneById" resultMap="articleTagResultMap">
select *
from article_tag,
article,
tag_category
where article_tag.at_id = #{id}
and article_tag.a_id = article.a_id
and tag_category.t_id = article_tag.t_id
</select>
<select id="findArticleByTag" resultMap="articleTagResultMap">
select *
from tag_category,
article,
article_tag
where tag_category.t_id = #{tagId}
and is_category = false
and tag_category.t_id = article_tag.t_id
and article_tag.a_id = article.a_id
</select>
<select id="findArticleByTagAndOpen" resultMap="articleTagResultMap">
select *
from tag_category,
article,
article_tag
where tag_category.t_id = #{tagId}
and is_category = false
and tag_category.t_id = article_tag.t_id
and article.a_is_open = true
and article_tag.a_id = article.a_id
</select>
</mapper>

View File

@@ -0,0 +1,93 @@
<?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.celess.common.mapper.CategoryMapper">
<resultMap id="categoryResultMap" type="cn.celess.common.entity.Category">
<id column="t_id" property="id"/>
<result column="t_name" property="name"/>
<result column="is_category" property="category"/>
<result column="is_delete" property="deleted"/>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into tag_category (t_name, is_category)
values (#{name}, true);
</insert>
<update id="update">
update tag_category
set t_name=#{name}
where t_id = #{id}
and is_category = true
</update>
<update id="delete">
update tag_category
set is_delete= true
where t_id = #{id}
and is_category = true
</update>
<select id="findCategoryByName" resultMap="categoryResultMap">
select *
from tag_category
where t_name = #{name}
and is_category = true
</select>
<select id="findCategoryById" resultMap="categoryResultMap">
select *
from tag_category
where t_id = #{id}
and is_category = true
</select>
<select id="findAll" resultMap="categoryResultMap">
select *
from tag_category
where is_category = true
</select>
<select id="getAllName" resultType="java.lang.String">
select t_name
from tag_category
where is_category = true
</select>
<select id="getNameById" resultType="java.lang.String">
select t_name
from tag_category
where is_category = true
and t_id = #{id}
</select>
<select id="getIdByName" resultType="java.lang.Long">
select t_id
from tag_category
where is_category = true
and t_name = #{name}
</select>
<select id="existsByName" resultType="java.lang.Boolean">
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = true)
</select>
<select id="existsById" resultType="java.lang.Boolean">
SELECT EXISTS(SELECT * FROM tag_category WHERE t_id = #{id})
</select>
<select id="getLastestCategory" resultMap="categoryResultMap">
select *
from tag_category
where is_category = true
order by t_id desc
limit 1;
</select>
<select id="count" resultType="java.lang.Long">
select count(*)
from tag_category
where is_category = true
and is_delete = false;
</select>
</mapper>

View File

@@ -0,0 +1,131 @@
<?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.celess.common.mapper.CommentMapper">
<resultMap id="commentResultMap" type="cn.celess.common.entity.Comment">
<id column="co_id" property="id"/>
<result column="co_page_path" property="pagePath"/>
<result column="co_status" property="status"/>
<result column="co_content" property="content"/>
<result column="co_date" property="date"/>
<result column="co_pid" property="pid"/>
<result column="co_from_author_id" property="fromUser.id"/>
<result column="co_to_author_id" property="toUser.id"/>
</resultMap>
<resultMap id="commentViewResultMap" type="cn.celess.common.entity.Comment">
<id column="commentId" property="id"/>
<result column="pagePath" property="pagePath"/>
<result column="status" property="status"/>
<result column="content" property="content"/>
<result column="date" property="date"/>
<result column="pid" property="pid"/>
<result column="fromAuthorId" property="fromUser.id"/>
<result column="toAuthorId" property="toUser.id"/>
<association property="fromUser" column="fromAuthorId" javaType="cn.celess.common.entity.User">
<id column="fromAuthorId" property="id"/>
<result column="fromAuthorEmail" property="email"/>
<result column="fromAuthorDisplayName" property="displayName"/>
<result column="fromAuthorAvatar" property="avatarImgUrl"/>
</association>
<association property="toUser" column="toAuthorId" javaType="cn.celess.common.entity.User">
<id column="toAuthorId" property="id"/>
<result column="toAuthorEmail" property="email"/>
<result column="toAuthorDisplayName" property="displayName"/>
<result column="toAuthorAvatar" property="avatarImgUrl"/>
</association>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into comment (co_page_path, co_content, co_date, co_pid, co_from_author_id, co_to_author_id, co_status)
VALUES (#{pagePath}, #{content}, now(), #{pid}, #{fromUser.id}, #{toUser.id}, 0)
</insert>
<update id="updateContent">
update comment
set co_content=#{content}
where co_id = #{id}
</update>
<update id="delete">
update comment
set co_status = 3
where co_id = #{id}
</update>
<update id="deleteByPagePath">
update comment
set co_status = 3
where co_page_path = #{path}
</update>
<select id="existsById" resultType="java.lang.Boolean">
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
</select>
<select id="findCommentById" resultMap="commentViewResultMap">
select *
from commentView
where commentId = #{sqid}
</select>
<select id="findAllByFromUser" resultMap="commentViewResultMap">
select *
from commentView
where fromAuthorId = #{id}
</select>
<select id="findAllByPid" resultMap="commentViewResultMap">
select *
from commentView
where pid = #{pid}
</select>
<select id="findAllByPagePath" resultMap="commentViewResultMap" parameterType="string">
select *
from commentView
<if test="toString() != null ">
where pagePath = #{pagePath}
</if>
</select>
<select id="findAllByPagePathAndFromUser" resultMap="commentViewResultMap">
select *
from commentView
where
<if test="pagePath != null ">
pagePath = #{pagePath} and
</if>
fromAuthorId = #{userId}
</select>
<select id="findAllByPagePathAndPidAndNormal" resultMap="commentViewResultMap">
select *
from commentView
where
<if test="pagePath != null ">
pagePath = #{pagePath} and
</if>
pid = #{pid} and status = 0
</select>
<select id="countByPagePath" resultType="java.lang.Long">
select count(*)
from commentView
where pagePath = #{pagePath}
</select>
<select id="getLastestComment" resultMap="commentViewResultMap">
select *
from commentView
order by commentId desc
limit 1
</select>
<select id="count" resultType="long">
select count(*)
from comment
where co_status = 0;
</select>
</mapper>

View File

@@ -0,0 +1,87 @@
<?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.celess.common.mapper.PartnerMapper">
<resultMap id="partnerSiteResultMap" type="cn.celess.common.entity.PartnerSite">
<id column="l_id" property="id"/>
<result column="l_name" property="name"/>
<result column="l_url" property="url"/>
<result column="l_is_open" property="open"/>
<result column="l_icon_path" property="iconPath"/>
<result column="l_desc" property="desc"/>
<result column="is_delete" property="delete"/>
<result column="l_email" property="email"/>
<result column="l_notification" property="notification"/>
</resultMap>
<insert id="insert" parameterType="cn.celess.common.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
</insert>
<update id="update" parameterType="cn.celess.common.entity.PartnerSite">
update links
<trim prefix="set" suffixOverrides=",">
<if test="open!=null">l_is_open=#{open},</if>
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
<if test="desc!=null">l_desc=#{desc},</if>
<if test="url!=null">l_url=#{url},</if>
<if test="name!=null">l_name=#{name},</if>
<if test="notification!=null">l_notification=#{notification},</if>
<if test="email!=null">l_email=#{email}</if>
</trim>
where l_id=#{id}
</update>
<update id="delete">
update links
set is_delete = true
where l_id = #{id}
</update>
<select id="existsById" resultType="boolean">
SELECT EXISTS(SELECT * FROM links WHERE l_id = #{id})
</select>
<select id="existsByName" resultType="boolean">
SELECT EXISTS(SELECT * FROM links WHERE l_name = #{name})
</select>
<select id="existsByUrl" resultType="boolean">
SELECT EXISTS(SELECT * FROM links WHERE l_url = #{url})
</select>
<select id="findById" resultMap="partnerSiteResultMap">
select *
from links
where l_id = #{id}
</select>
<select id="findByName" resultMap="partnerSiteResultMap">
select *
from links
where l_name = #{name}
</select>
<select id="findByUrl" resultMap="partnerSiteResultMap">
select *
from links
where l_url = #{url}
</select>
<select id="getLastest" resultMap="partnerSiteResultMap">
select *
from links
order by l_id desc
limit 1
</select>
<select id="findAll" resultMap="partnerSiteResultMap">
select *
from links
<if test="_parameter != null">
where is_delete=#{deleted}
</if>
</select>
</mapper>

View File

@@ -0,0 +1,137 @@
<?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.celess.common.mapper.UserMapper">
<resultMap id="userResultMap" type="cn.celess.common.entity.User">
<id column="u_id" property="id"/>
<result column="u_email" property="email"/>
<result column="u_pwd" property="pwd"/>
<result column="u_email_status" property="emailStatus"/>
<result column="u_avatar" property="avatarImgUrl"/>
<result column="u_desc" property="desc"/>
<result column="u_recently_landed_time" property="recentlyLandedDate"/>
<result column="u_display_name" property="displayName"/>
<result column="u_role" property="role"/>
<result column="status" property="status"/>
</resultMap>
<insert id="addUser" useGeneratedKeys="true" keyProperty="id">
insert into user(u_email, u_pwd)
values (#{email}, #{pwd})
</insert>
<update id="updateInfo">
update user set
<if test="desc!=null">u_desc=#{desc},</if>
<if test="displayName!=null">u_display_name=#{displayName}</if>
where u_id=#{id}
</update>
<update id="updateLoginTime">
update user
set u_recently_landed_time=now()
where u_email = #{email}
</update>
<update id="updateAvatarImgUrl">
update user
set u_avatar=#{avatarImgUrl}
where u_id = #{id}
</update>
<update id="updateEmailStatus">
update user
set u_email_status=#{status}
where u_email = #{email}
</update>
<update id="updatePwd">
update user
set u_pwd=#{pwd}
where u_email = #{email}
</update>
<update id="setUserRole">
update user
set u_role=#{role}
where u_id = #{id}
</update>
<update id="update">
update user
set u_email = #{email},
u_pwd = #{pwd},
u_email_status = #{emailStatus},
u_desc = #{desc},
u_display_name = #{displayName},
u_avatar = #{avatarImgUrl},
u_role = #{role}
where u_id = #{id}
</update>
<update id="delete">
update user
set status= 2
where u_id = #{id}
</update>
<update id="lock">
update user
set status= 1
where u_id = #{id}
</update>
<select id="existsByEmail" resultType="java.lang.Boolean">
select exists(select * from user where u_email = #{email})
</select>
<select id="findByEmail" resultMap="userResultMap">
select *
from user
where u_email = #{email}
</select>
<select id="findById" resultMap="userResultMap">
select *
from user
where u_id = #{id}
</select>
<select id="getAvatarImgUrlById" resultType="string">
select u_avatar
from user
where u_id = #{id};
</select>
<select id="getEmail" resultType="java.lang.String">
select u_email
from user
where u_id = #{id}
</select>
<select id="getDisPlayName" resultType="java.lang.String">
select u_display_name
from user
where u_id = #{id}
</select>
<select id="getPwd" resultType="java.lang.String">
select u_pwd
from user
where u_email = #{email}
</select>
<select id="getRoleByEmail" resultType="java.lang.String">
select u_role
from user
where u_email = #{emai}
</select>
<select id="count" resultType="java.lang.Long">
select count(*)
from user
where status =0;
</select>
<select id="getRoleById" resultType="java.lang.String">
select u_role
from user
where u_id = #{id}
</select>
<select id="findAll" resultMap="userResultMap">
select *
from user
<if test="_parameter != null">
where status=#{status}
</if>
</select>
</mapper>

View File

@@ -0,0 +1,39 @@
<?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.celess.common.mapper.VisitorMapper">
<resultMap id="partnerSiteResultMap" type="cn.celess.common.entity.Visitor">
<id column="v_id" property="id"/>
<result column="v_date" property="date"/>
<result column="v_user_agent" property="ua"/>
<result column="v_ip" property="ip"/>
<result column="is_delete" property="delete"/>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into visitor (v_date, v_ip, v_user_agent)
values (#{date}, #{ip}, #{ua})
</insert>
<update id="delete">
update visitor
set is_delete = true
where v_id = #{id}
</update>
<select id="findAll" resultMap="partnerSiteResultMap">
select *
from visitor
order by v_id desc
</select>
<select id="findAllNotDeleted" resultMap="partnerSiteResultMap">
select *
from visitor
where is_delete = false
order by v_id desc
</select>
<select id="count" resultType="java.lang.Long">
select count(*)
from visitor
</select>
</mapper>

View File

@@ -0,0 +1,57 @@
<?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.celess.common.mapper.WebUpdateInfoMapper">
<resultMap id="webUpdateResultMap" type="cn.celess.common.entity.WebUpdate">
<id column="wu_id" property="id"/>
<result column="wu_info" property="updateInfo"/>
<result column="wu_time" property="updateTime"/>
<result column="is_delete" property="delete"/>
</resultMap>
<insert id="insert" parameterType="cn.celess.common.entity.WebUpdate" useGeneratedKeys="true" keyProperty="id">
insert into web_update(wu_info, wu_time, is_delete)
values (#{updateInfo}, now(), false)
</insert>
<update id="update">
update web_update
set wu_info=#{info}
where wu_id = #{id};
</update>
<update id="delete">
update web_update
set is_delete = true
where wu_id = #{id}
</update>
<select id="existsById" resultType="java.lang.Boolean">
select EXISTS(select * from web_update where wu_id = #{id})
</select>
<select id="findById" resultMap="webUpdateResultMap">
select *
from web_update
where wu_id = #{id}
</select>
<select id="findAll" resultMap="webUpdateResultMap">
select *
from web_update
order by wu_id desc
</select>
<select id="findAllNotDeleted" resultMap="webUpdateResultMap">
select *
from web_update
where is_delete = false
</select>
<select id="getLastestOne" resultMap="webUpdateResultMap">
select *
from web_update
order by wu_id desc
limit 1
</select>
</mapper>

View File

@@ -0,0 +1,242 @@
<?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.celess.common.mapper.ArticleMapper">
<resultMap id="articleResultMap" type="cn.celess.common.entity.Article">
<id column="a_id" property="id"/>
<result column="a_title" property="title"/>
<result column="a_summary" property="summary"/>
<result column="a_md_content" property="mdContent"/>
<result column="a_url" property="url"/>
<result column="a_author_id" property="user.id"/>
<result column="a_is_open" property="open"/>
<result column="a_is_original" property="type"/>
<!-- <result column="next_a_id" property="nextArticleId"/>-->
<!-- <result column="pre_a_id" property="preArticleId"/>-->
<result column="a_reading_number" property="readingNumber"/>
<result column="a_publish_date" property="publishDate"/>
<result column="a_update_date" property="updateDate"/>
<result column="is_delete" property="deleted"/>
<association property="category" column="a_category_id" javaType="cn.celess.common.entity.TagCategory"
resultMap="cn.celess.common.mapper.CategoryMapper.categoryResultMap">
</association>
<collection property="tags" ofType="cn.celess.common.entity.Tag"
select="cn.celess.common.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
<id column="tagId" property="id"/>
<result column="tagName" property="name"/>
</collection>
</resultMap>
<resultMap id="articleViewResultMap" type="cn.celess.common.entity.Article">
<id column="articleId" property="id"/>
<result column="title" property="title"/>
<result column="summary" property="summary"/>
<result column="mdContent" property="mdContent"/>
<result column="url" property="url"/>
<result column="isOpen" property="open"/>
<result column="isOriginal" property="type"/>
<result column="likeCount" property="likeCount"/>
<result column="dislikeCount" property="dislikeCount"/>
<result column="readingCount" property="readingNumber"/>
<result column="publishDate" property="publishDate"/>
<result column="updateDate" property="updateDate"/>
<result column="isDelete" property="deleted"/>
<association property="category" column="categoryId" javaType="cn.celess.common.entity.Category">
<id column="categoryId" property="id"/>
<result column="categoryName" property="name"/>
</association>
<association property="user" column="authorId" javaType="cn.celess.common.entity.User">
<id column="authorId" property="id"/>
<result column="userEmail" property="email"/>
<result column="userAvatar" property="avatarImgUrl"/>
<result column="userDisplayName" property="displayName"/>
</association>
<collection property="tags" ofType="cn.celess.common.entity.Tag"
select="cn.celess.common.mapper.ArticleTagMapper.findTagByArticleId" column="{articleId=articleId}">
<id column="tagId" property="id"/>
<result column="tagName" property="name"/>
</collection>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.common.entity.Article">
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
a_summary, a_title, a_url)
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
</insert>
<update id="delete">
update article
set is_delete = true
where a_id = #{id}
</update>
<update id="update">
update article
set a_update_date=now(),
<if test="title!=null">a_title=#{title},</if>
<if test="mdContent!=null">a_md_content=#{mdContent},</if>
<if test="summary!=null">a_summary=#{summary},</if>
<if test="type!=null">a_is_original=#{type},</if>
<if test="url!=null">a_url=#{url},</if>
<if test="category!=null">a_category_id=#{category.id},</if>
<if test="open!=null">a_is_open=#{open}</if>
where a_id = #{id}
</update>
<update id="updateReadingNumber">
update article
set a_reading_number=a_reading_number + 1
where a_id = #{id}
</update>
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.common.entity.Article">
select *
from articleView
order by articleId desc
limit 1
</select>
<select id="findArticleById" resultMap="articleViewResultMap">
select *
from articleView
where articleId = #{id}
</select>
<select id="existsByTitle" resultType="boolean">
SELECT EXISTS(SELECT * FROM article WHERE a_title = #{title})
</select>
<select id="isDeletedById" resultType="boolean">
select is_delete
from article
WHERE a_id = #{id}
</select>
<select id="findAllByAuthorId" resultMap="articleViewResultMap">
select *
from articleView
where authorId = #{authorId}
and isDelete = false
order by articleId desc
</select>
<select id="findAllByOpen" resultMap="articleViewResultMap">
select article.a_id as articleId,
article.a_title as title,
article.a_summary as summary,
article.a_md_content as mdContent,
article.a_url as url,
article.a_is_original as isOriginal,
article.a_reading_number as readingCount,
article.a_like as likeCount,
article.a_dislike as dislikeCount,
article.a_publish_date as publishDate,
article.a_update_date as updateDate,
article.a_is_open as isOpen,
category.t_id as categoryId,
category.t_name as categoryName,
user.u_id as authorId,
user.u_email as userEmail,
user.u_avatar as userAvatar,
user.u_display_name as userDisplayName,
article.is_delete as isDelete
from article,
tag_category as category,
article_tag,
user
where article.a_is_open = #{isOpen}
and article.is_delete = false
and article.a_id = article_tag.a_id
and article.a_category_id = category.t_id
and category.is_category = true
and article.a_author_id = user.u_id
group by article.a_id
order by article.a_id desc
</select>
<select id="getTitleById" resultType="string">
SELECT title
from articleView
where articleId = #{id}
</select>
<select id="findAllByCategoryId" resultMap="articleViewResultMap">
select *
from articleView
where categoryId = #{id}
and isDelete = false
order by articleId desc
</select>
<select id="findAllByCategoryIdAndOpen" resultMap="articleViewResultMap">
select *
from articleView
where categoryId = #{id}
and isDelete = false
and isOpen = true
order by articleId desc
</select>
<select id="findAll" resultMap="articleViewResultMap">
select article.a_id as articleId,
article.a_title as title,
article.a_summary as summary,
article.a_md_content as mdContent,
article.a_url as url,
article.a_is_original as isOriginal,
article.a_reading_number as readingCount,
article.a_like as likeCount,
article.a_dislike as dislikeCount,
article.a_publish_date as publishDate,
article.a_update_date as updateDate,
article.a_is_open as isOpen,
category.t_id as categoryId,
category.t_name as categoryName,
user.u_id as authorId,
user.u_email as userEmail,
user.u_avatar as userAvatar,
user.u_display_name as userDisplayName,
article.is_delete as isDelete
from article,
tag_category as category,
article_tag,
user
where article.a_id = article_tag.a_id
and article.a_category_id = category.t_id
and category.is_category = true
and article.a_author_id = user.u_id
group by article.a_id
order by article.a_id desc
</select>
<select id="count" resultType="long">
select count(*)
from article
where is_delete = false;
</select>
<select id="getPreArticle" resultMap="articleViewResultMap">
select *
from articleView
where articleId = (select max(articleId)
from articleView
where isOpen = true
and articleId &lt; #{id}
)
</select>
<select id="getNextArticle" resultMap="articleViewResultMap">
select *
from articleView
where articleId = (select min(articleId)
from articleView
where isOpen = true
and articleId &gt; #{id}
)
</select>
</mapper>

View File

@@ -0,0 +1,66 @@
<?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.celess.common.mapper.TagMapper">
<resultMap id="tagResultMap" type="cn.celess.common.entity.Tag"
extends="cn.celess.common.mapper.CategoryMapper.categoryResultMap">
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into tag_category (t_name, is_category)
VALUES (#{name}, false);
</insert>
<update id="update">
update tag_category
set t_name=#{name}
where t_id = #{id}
and is_category = false;
</update>
<update id="delete">
update tag_category
set is_delete = true
where t_id = #{id}
and is_category = false;
</update>
<select id="findTagById" resultMap="tagResultMap">
select *
from tag_category
where t_id = #{id}
and is_category = false;
</select>
<select id="findTagByName" resultMap="tagResultMap">
select *
from tag_category
where t_name = #{name}
and is_category = false;
</select>
<select id="existsByName" resultType="boolean">
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = false)
</select>
<select id="getLastestTag" resultMap="tagResultMap">
select *
from tag_category
where is_category = false
order by t_id desc
limit 1
</select>
<select id="findAll" resultMap="tagResultMap">
select *
from tag_category
where is_category = false
</select>
<select id="count" resultType="long">
select count(*)
from tag_category
where is_category = false
and is_delete = false;
</select>
</mapper>