• 站内信的实现


    • 站内信的实现

     
    • 站内信
    “站内信”主要实现站内用户的沟通,有两个基本功能。
    一:点到点的消息传送。用户给用户发送站内信,管理员给用户发送站内信。
    二:点到面的消息传送。管理员给用户(指定满足某一条件的用户群)群发消息
    站内信的开发流程
    1. Database Column
    2. Model:模型定义,和数据库相匹配
    3. DAO:数据读取
    4. Service:服务包装
    5. Controller:业务入口
    6. Test
     
    1. Database Column
    private int id;
    private int from_Id;
    private int to_Id;
    private String content;
    private Date createdDate;
    private int hasRead;
    2. Model:模型定义,和数据库相匹配
    package com.LG.model;
    import java.util.Date;
     
    /**
    * @Author liguo
    * @Description
    * @Data 2018-09-06 14:21
    */
     
    public class Message {
    private int id;
    private int fromId;
    private int toId;
    private String content;
    private Date createdDate;
    private int hasRead;
     
    public int getId() {
    return id;
    }
     
    public void setId(int id) {
    this.id = id;
    }
     
    public int getFromId() {
    return fromId;
    }
     
    public void setFromId(int fromId) {
    this.fromId = fromId;
    }
     
    public int getToId() {
    return toId;
    }
     
    public void setToId(int toId) {
    this.toId = toId;
    }
     
    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 getHasRead() {
    return hasRead;
    }
     
    public void setHasRead(int hasRead) {
    this.hasRead = hasRead;
    }
     
    public String getConversationId() {
    if (fromId < toId) {
    return String.format("%d_%d", fromId, toId);
    } else {
    return String.format("%d_%d", toId, fromId);
    }
    }
     
    public void setConversationId(String conversationId) {
    String conversationId1 = conversationId;
    }
    }
    3. DAO:数据读取
    package com.LG.dao;
     
    import com.LG.model.Message;
    import org.apache.ibatis.annotations.Insert;
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    import org.apache.ibatis.annotations.Select;
     
    import java.util.List;
     
    /**
    * @Author liguo
    * @Description
    * @Data 2018-09-06 14:38
    */
     
     
    @Mapper
    public interface MessageDAO {
    String TABLE_NAME = " message ";
    String INSERT_FIELDS = " from_id, to_id, content, has_read, conversation_id, created_date ";
    String SELECT_FIELDS = " id, " + INSERT_FIELDS;
     
    @Insert({"insert into ", TABLE_NAME, "(", INSERT_FIELDS,
    ") values (#{fromId},#{toId},#{content},#{hasRead},#{conversationId},#{createdDate})"})
    int addMessage(Message message);
     
    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME,
    " where conversation_id=#{conversationId} order by created_date desc limit #{offset}, #{limit}"})
    List<Message> getConversationDetail(@Param("conversationId") String conversationId,
    @Param("offset") int offset,
    @Param("limit") int limit);
     
    @Select({"select ", INSERT_FIELDS, " , count(id) as id from ( select * from ", TABLE_NAME,
    " where from_id=#{userId} or to_id=#{userId} order by created_date desc) tt group by conversation_id order by created_date desc limit #{offset}, #{limit}"})
    //实现分页功能;offset是分的页数目 ,limit为每页显示的内容;
    List <Message> getConversationList(@Param("userId") int userId,
    @Param("offset") int offset,
    @Param("limit") int limit);
     
    @Select({"select count(id) from ", TABLE_NAME, " where has_read=0 and to_id=#{userId} and conversation_id=#{conversationId}"})
    int getConversationUnreadCount(@Param("userId") int userId, @Param("conversationId") String conversationId);
    }
    4. Service:服务包装
     
    5. Controller:业务入口
    6. Test
     

  • 相关阅读:
    【Linux】kali 安装 python3 和 pip3(亲测有效)
    Xcode10:library not found for -lstdc++.6.0.9 临时解决
    React-Native入门
    CodeSign error: no provisioning profile at path '/Users/zhht-2015/Library/MobileDevice/Provisioning Profiles/79693141-f98b-4ac4-8bb4-476c9475f265.mobileprovision'
    Please verify that your device’s clock is properly set, and that your signing certificate is not expired.
    “Your build settings specify a provisioning profile with the UUID “”, however, no such provisioning profile was found”
    出现An App ID with Identifier 'com.XXX.XXX’ is not available. Please enter a different string.
    iOS的项目目录结构
    cocoa pods最新安装说明和使用方法
    真机调试报The executable was signed with invalid entitlements.错误
  • 原文地址:https://www.cnblogs.com/liguo-wang/p/9600277.html
Copyright © 2020-2023  润新知