package com.nowcoder.model;
import java.util.Date;
/**
* @Author liguo
* @Description
* @Data 2018-09-06 7:50
*/
public class Comment {
private int id;
private int userId;
private int entityId;
private int entityType;
private String content;
private Date createdDate;
private int status;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getEntityId() {
return entityId;
}
public void setEntityId(int entityId) {
this.entityId = entityId;
}
public int getEntityType() {
return entityType;
}
public void setEntityType(int entityType) {
this.entityType = entityType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
//数据库接口的crud
@Mapper
public interface CommentDAO {
String TABLE_NAME = " comment ";
String INSERT_FIELDS = " user_id, content, created_date, entity_id, entity_type, status ";
String SELECT_FIELDS = " id, " + INSERT_FIELDS;
@Insert({"insert into ", TABLE_NAME, "(", INSERT_FIELDS,
") values (#{userId},#{content},#{createdDate},#{entityId},#{entityType},#{status})"})
int addComment(Comment comment);
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id=#{id}"})
Comment getCommentById(int id);
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME,
" where entity_id=#{entityId} and entity_type=#{entityType} order by created_date desc"})
List<Comment> selectCommentByEntity(@Param("entityId") int entityId, @Param("entityType") int entityType);
@Select({"select count(id) from ", TABLE_NAME, " where entity_id=#{entityId} and entity_type=#{entityType}"})
int getCommentCount(@Param("entityId") int entityId, @Param("entityType") int entityType);
@Update({"update comment set status=#{status} where id=#{id}"})
int updateStatus(@Param("id") int id, @Param("status") int status);
@Select({"select count(id) from ", TABLE_NAME, " where user_id=#{userId}"})
int getUserCommentCount(int userId);