团队项目——技术规格说明书


一、引言

1.开发:开发一款类似于“知乎”的网上教学问答系统。

2.功能:实现用户管理、搜索、分类、上传下载、用户贡献与交互等功能。

二、技术支持

1.开发环境:eclipse+ADT+androidSDK

2.服务器:由老师提供的服务器,搭载win server 2012系统。

3.数据库:SQLserver

4.通讯机制:java servlet机制

三、数据库表单

说明:

1.属性名为“字母+‘id’”表示某个实体的id号,如aid表示answer的id。

2.由于Document和Tag,Question和Tag都是m:n的对应关系,所以添加了DocumentTagAssociation、QuestionTagAssociation两个表。

3.views:访问量; replies:回复量;

Answer aid(PK,int,not null) qid(int,not null) uid(int,not null) content(nvarchar(max),not null) created(datetime,not null) lastmodified(datetime,not null) vote(int,null) best(int ,null)      
Comment comment_id(PK,int,not null) uid(int,not null) qid(int,not null) aid(int,not null) content(nvarchar(max),not null) created(datetime,not null) lastmodified(datetime,not null)        
Credit uid(PK,int,notnull) cid(int,not null) value(int,not null)                
Document did(PK,int,not null) uid(int,not null) title(nvarchar(max),not null) author(nvarchar(max),not null) credit(int,not null) views(int,not null) downloads(int,not null) filename(nvarchar(max),not null) postdatetime(datetime,not null)    
DocumentTagAssociation did(int,not null) tid(int,not,null) qtid(PK,int,not null)                
Question qid(PK,int,not null) uid(int,not null) title(nvarchar(max),not null) content(nvarchar(max),not null) created(datetime,not null) lastmodified(datetime,not null) views(int,not null) replies(int,not null) solved(bit,not null)    
QuestionTagAssociation qaid(PK,int,not null) qid(int,not null) tid(int,not null)                
Tag tid(PK,int,not null) qid(int, not null) name(nvarchar(max),not null)                
User uid(PK,int,not null) nick(nvarchar(max),not null) password(nvarchar(max),not null) created(datetime,not null) Realname(nvarchar(max),null) Description(nvarchar(max),null) Downloadcredit(int,null) rank(int,null) title(nchar(10),null)    
UserRegister uid(PK,int,not null) email(nvarchar(max),not null) nick(nvarchar(max),not null) password(nvarchar(max),not null) created(datetime,not null) realname(nvarchar(max),null) description(nvarchar(null),null) credit(int,null) activated(int,null) forgot_time(datetime,null) download(int,null)
Vote aid(PK,int,not null) uid(int, not null) up(int, not null)                

四、整体框架

五、代码规范

1.实体类,一共有6个类,类及其函数如下:

       1.1回答Answer类

com.hks.entity
class answer
public Answer() //所提问题的有关内容
public int Id; //问题ID
public int FieldId; //与问题有关的文件ID
public int TopicId; //与问题有关的关键词ID
public int Layer; //?
public User Poster; //回答发布者
public String Title; //题目?
public String Content; //内容
public Timestamp PostDateTime; //发布时间
public int Views; //浏览量
public boolean IsBestAns; //是否是最好的答案
public int Votes; //贡献值?

 

1.2文档Documentr类

class document //与文件有关的内容
public int Id;
public int FieldId;
public User Poster; //文件发布者
public String Title; //标题
public DocumentType Type; //文件类型
public String Author; //?
public String Institution;
public Timestamp PostDateTime; //时间戳,发布时间
public int Views; //查看量
public int DownLoads; //下载量
public String Abstract; //摘要?
public String Content; //内容?
public int Votes; //投票
public List<Tag> Tags; //文件标签
public String FilePath; //文件路径
public int Credit;

public String TagStr;

enum documenttype //文件类型
PDF,PPT,DOC,Html,Video

1.3问题question
class question
public Question() //建立问题的动态数组,建立标签的动态数组 与该问题相关的答案与标签
public getabstract() //问题摘要 问题为空,返回空;摘要最大为60个字符

public int Id;
public int FieldId;
public User Poster; //问题发布者
public String Title;
public String Content;
public Timestamp PostDateTime;
public Timestamp LastPostDateTime;
public int Views;
public int Replies;
private String Abstract;
public int Credit;

public List<Answer> Answers;
public List<Tag> Tags; //与问题有关的标签
public String TagStr;

class Tag //标签类
int ID; //标签ID
string Name; //标签名字

calss TagInfo //标签信息
String Name; //
int Id; //标签ID
int DocumentCount; //与标签有关的文件
int QuestionCount; //与文件有关的问题

1.4用户user类
class user //用户信息
public int Uid; //用户ID
public String Email; //用户email
public String Nick; //昵称
public String Realname; //真实姓名
public String Description; //个性签名
public int DownloadCredit; //下载积分
public Timestamp ForgotTime;
public Timestamp CreatedAt;
public int Activated;
public static int qacredit; //提问回答积分
public static int rank; //等级
public static String title; //等级所对应的名称

public int Rank() //根据积分确定等级

public String Title() //等级的名称

 

1.5页面WebPage类
class WebPage
public WebPage() //网页?

public int Id;
public String Title;
public String author;
public Timestamp PostDateTime;

public String link;
public int referred;

public int Views;
public int Rate;

public List<Tag> Tags;
public String TagStr;

       1.6评论Comment

 

com.xujunhong.CodingCook.Model
class Comment //评论类
private int CommentId ; //评论ID
private int Qid ; //问题ID
private int Aid ; //回答ID
private int Uid ; //用户ID
private Date Created ; //评论创建时间
private Date LastModified ;//最终修改时间
private String Content ; //内容
private String UserNick ; //用户昵称

public Comment();
public int getQid();
public int getAid();
public int getUid();
public Date getCreated();
public Date getLastModified();
public String getContent();
public String getUserNick();

 

2.搜索类,名为QuestionSearchActivity,其具体属性及函数如下: 

private List<Question> queList; //问题列表

private HashMap<String,Object> doc;  //用哈希形式存储单个问题的问题名和问题对象

private ArrayList<HashMap <String,Object> > docs; //存储问题信息列表

private SimpleAdapter sa;

private static LayoutInflater factory;

Handler nextHandler;

Runnable nextRun;  //运行nextHandler的线程

Handler initHandler;  //发送初始化信息

Runnable initRun;  //运行initHandler的线程

String[] quesuchoices; //一些文件信息

 

private void QuestionSearchSetting();  //设置需要显示的问题信息

private void ClickSearch(); //获取要搜索的内容

private void HandleNextPage(); //调用nextRun

public void onClick(View view); 设置点击时的动作:调用clickSearch()开始查询;或者调用handleNextPage()换页;

private void initial();初始化界面并运行initRun;

private void update(String xml); 获取quesList

private void response(String xml); 得到问题内容并布局到当前界面

private void jumpToDocDetail(String did); 跳转到QuestionDetails界面

private void onCreate(Bundle saveInstanceState);创建界面

public static String String getTagString(List<Tag> tlist);//将列表中存储的数据转换成String形式

3.下载类,名为DownloadPage,其属性函数如下:

private final String URL_HOST:服务器地址

private final String DocSel_URL:?

private final String DocUp_URL:文件更新的服务器地址

private final String DTASELBydid_URL:?

private final String TagSel_URL:文件标签的服务器地址?

private final String TagIn_URL:?

private final String DTAIn_URL:?

private final String Download_Home下载到本地的主路径

private String Savepath:下载文件的储存路径

private String tagString:文件标签

 

private String uid:文件上传者id

private String title:文件名称

private String postdatetime:文件上传的时间

private String credit:点赞数

private String views:浏览量

private String downloads:下载次数

private String filename:文件名称

private String[] tags:文件标签

private int FLAG:数据下载完毕标志

private TextView text_title:文件名称布局

private TextView text_uid:上传者id布局

private TextView text_filepath:文件下载路径布局

private TextView text_postdatetime:上传时间布局

private TextView text_views:浏览量布局

private TextView text_downloads:下载次数布局

private TextView text_credit:点赞数布局

private TextView text_tags:文件标签布局

 

protected void onCreate(Bundle savedInstanceState){}:

得到要显示信息的文件对应的did。若不成功,则返回-1000

    缺省:从数据库中获得document表中did对应元组的各个属性

    从DocumentTagAssociation表中得此文件did对应的tid

    从Tag表中得到这些tid对应的具体tag名称

    再将得到的数据布置显示于页面中

    还需要将document表中did对应元组的浏览量属性+1,代表多了一次访问

    在这里也要拼接好从服务器下载文件的url(服务器路径是tomcat映射的,在这里将服务器路径,文件名,格式三者拼接完整)

    暂时就将这个存url的string变量命名为urlDownload吧,方便下面描述

    为按钮设置监听事件,点击则下载,保存路径由对应管理下载保存路径的sharedpreference决定

    ,这个sharedpreference存储的下载保存路径在设置里面被改变,在软件启动时要检测是否有赋值,没有则要赋初值

    下载后将document表中did对应元组的下载次数属性+1,代表多了一次下载

    还需要提供增加tag和点赞的按钮,点击增加tag按钮以后,跳转到一个新页面,获得输入的新tag,将这个tag登记在tag表中

    同时在DocumentTagasAociation中添加这个联系。点击点赞按钮后,将document表中did对应元组的点赞属性+1,代表多了一次点赞

4.上传类,其名为Upload,属性及函数如下:

private final String URL_HOST = "http://124.207.188.97:8081/yyyy" ;

private final String DocIn_URL = URL_HOST + "/DocIn?";

        

private TextView tips:提示

private EditText editpath:文件路径布局

private Button CButton:上传按钮

private Button Browse_Button:文件浏览按钮

private int FLAG:线程结束标志

private int i:计数器

 

protected void onCreate(Bundle savedInstanceState){}:

填充布局数据。

private void showFileChooser(){}:

从本地文件中选择文件。

protected void onActivityResult(int requestCode, int resultCode,Intent intent){}:

此方法未被调用,功能未知。

 a

HttpAssist:

public int uploadFile(File file){}:

和服务器通讯并上传文件

5.Servlet机制,程序说明如下:

                5.1事件处理

CodingCook.Affairs

Class AnswerAffairs     //回答相关

public static int GiveAnswer(int qid, int uid, String content)  

//用户uid给qid的问题添加答案content

public static boolean DeleteAnswer(int aid, int uid) //删除用户uid给的答案aid

public static int UpdateAnswer(int uid, int aid, String content)//更新答案

                 

class CommentAffairs     //评论相关

public static int AddComment(int qid, int aid, int uid, String content)  //添加评论

public static List<Comment> CommentList(int qid, int aid)           //从数据库中得到评论

 

class QuestionAffairs       //问题相关

public static int Ask(int uid, String title, String content , String[] s)//提问,成功则返回问题的qid,否则返回

public static boolean Mofify(int qid, int cid, String title, String content)//修改问题,若成功修改返回true,否则false

public static int MofifyByuidqid(int uid, int qid, String content)

        

class UserAffairs

public static int Register(String email, String nick, String password)//用户注册

public static int Login(String email, String password) //用户登录

public static int ModifyInformation(int uid,String email,String nick,String realname,

String description)//用户修改信息

public static int MofifyPassword(int uid, String oldPass, String newPass) //用户修改密码

public static int ResetPassword(int uid, String password)//重置密码

public static int UpdateCredit(int uid, int value) //更新积分

public static  User GetUserById(int uid)//得到用户ID

public static User GetUserByEmail(String email) //得到用户email

public static int Activate(int uid)  //  ?

 

class VoteAffairs   //贡献相关 ?

public static boolean GiveVote(int aid, int uid, int up)

       5.2 工具类,包括加密、格式匹配以及生成随机数

CodingCook.Helper

Class Encryption      //加密

private static String encrypt(String input, String salt)

public static String Encrypt(String input)

public static boolean Validate(String input, String correct)

public static String hexDigest(byte[] src)

 

class FormatValidator    //格式匹配 :邮箱,密码(>=6位),昵称

public static boolean ValidateEmail(String email)   //检查邮箱的格式是否正确

public static boolean ValidatePassword(String password)  //检查密码的格式是否正确

public static boolean ValidateNick(String nick)           //检查昵称的格式是否正确

        

class RandomString       //生成随机数  ?

private static char getRandomChar()

public static String GetRandomString(int length)

 

 

 

        5.3后端数据库操作

CodingCook SQL

class AnswerSQL      //问题的数据库操作

public static int Insert(int uid, int qid, String content)    //插入答案

public static int Update(int aid, String content)         //更新答案

public static List<Answer> Select(int qid)              //选择

public static int delete(int aid , int uid)                //删除

public static int UpdateByuidaid(int uid , int aid, String content)

 

class CommentSQL

public static int Insert(int uid, int qid, int aid, String content)  //插入

public static List<Comment> GetComments(int qid, int aid)

 

class ConnetionPool

private String name=null;  //名称

private LinkedList notUsedConnection = new LinkedList();   //未使用连接

private HashSet usedConnection = new HashSet();    //正在使用的连接

private String url = "";    //数据库URL

private String user = "";    //数据库用户名

private String password = "";    //数据库密码

private long lastClearClosedConnection = System.currentTimeMillis();  //上次关闭连接时间

private static final boolean DEBUG = true;

private static long CHECK_CLOSED_CONNECTION_TIME = 4 * 60 * 60 * 1000;//关闭时间间隔4 hours

public ConnetionPool(String name1, String url1, String user1, String password1)//构造对象

public synchronized Connection getConnection()//从连接池中获取一个连接(外部使用)

private ConnectionWrapper getNewConnection()//从驱动程序管理器中获取一个连接(包装后的,内部使用)

synchronized void pushConnectionBackToPool(ConnectionWrapper con)//归还连接

public int close()//关闭连接池

private void clearClosedConnection()//在达到指定的时间间隔后清理连接池 

private int getIncreasingConnectionCount()//获取一次要新增连接的数量(当前总数的1/4,最少为1)

private int getDecreasingConnectionCount()//获取一次要减少连接的数量(当前总数的1/3,但总数不能小于10)

public synchronized void printDebugMsg() //

public synchronized void printDebugMsg(PrintStream out)

public synchronized int getConnectionCount()

public synchronized int getNotUsedConnectionCount()

public synchronized int getUsedConnectionCount()

 

class CreditSQL    //积分

public static int Insert(int uid, int cid)

public static int Update(int uid, int cid, int value)

public static int Sum(int uid)

                 

class DataBase://系统公共数据类:将整个系统共享的基本数据、参数以public static的形式定义在此类中,显然能够提供很多方便

private static ConnetionPool defaultDBPool=null; //数据库连接池

private static boolean ready=false;

private static String user = "sa";

private static String pwd = "XueBa@ASE";

public static int getCount(String sql)  //查询记录条数

 

class DocumentSQL    //文件

public static Document Select(int did)

public static int UpViews(int did , int views )

public static int UpDownloads(int did , int downloads )

public static int UpCredit(int did , int credit )

public static int Insert(int uid , String title ,  String author ,  int credit , int views , int downloads , String filename)

  

class DTASQL        //?  

public static Vector SelectBydid(int did)

public static Vector SelectBytid(int tid)

public static int Insert( int did , int tid)

public static List<Tidcount> Select(  )

 

class QTASQL         //?

public static List<Tidcount> Select()

public static Vector SelectBytid(int tid)

 

class QuestionSQL     //问题

public static int Insert(int uid, String title, String content , String[] s)

public static int Update(int qid, int cid, String title, String content)

public static TitleReplies Select( int qid )

public static List SelectByUid( int uid )

public static List SelectAnsweredByUid( int uid )

public static int UpdateByuidqid(int uid, int qid,  String content)

 

class TagSQL          //标签

public static String Select( int tid)

public static int Insert( String name )

 

class UserSQL          //用户

private final static  int DB_LEN_EMAIL = 50;

private final int DB_LEN_NICK = 20;

private final int DB_LEN_REAL = 20;

private final int DB_LEN_DES = 128;

private final int DB_LEN_PASS = 40;

public static int Insert(String email,String nick,String password)

public static int Update(int uid,String email,String nick,String realname,String description)

public static int Update(int uid, String password)

public static int Update(int uid)

public static int Update(int uid, int value)

public static int UpdateForgot(int uid, Boolean forgot)

public static User GetUser(String key, String value)

public static int UpdateCredit( int uid , int score)

 

class VoteSQL       //贡献

public static int Insert(int aid, int uid )

public static int delete(int aid, int uid )

public static int select(int aid, int uid )

       5.4 用Servlet机制实现数据的接受和发送

class QuestionAsk

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题的用户id,题目,内容,标签,调用函数将问题插入数据库

 

class QuestionModify

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题的id,cid(这是什么一直搞不懂 ==,可能是content的id或者comment的id,前者可能性更高),题目,内容,调用函数通过问题id查找问题,并用其它属性修改问题。

 

class QuestionModifyByuidqid

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题的用户Id,问题的id,以及问题的新内容,调用函数通过用户id和题目id查找问题,并用新内容替换旧内容。

 

class QuestionYS

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题的id,调用函数,获取问题的标题和reply(这个是什么我也不太确定)

 

class AnswerGiveAnswer

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题id、用户id和答案的内容,调用函数将其插入数据库中。

 

class AnswerDeleteAnswer

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取答案id和用户id,调用函数通过这两个参数,删除问题。

 

class AnswerUpdateAnswer

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题id,用户Id,新答案内容,调用函数,通过前两个参数获取旧答案并用新答案替换旧答案。

 

class AnswerYS

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取问题id,调用函数,回复该问题的所有回复。

 

class UserAddCredit

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取用户id和分数,调用函数为用户修改分数。

 

class UserGetUserById

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取用户id,回复用户各类信息

 

class UserLogin

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取用户的邮箱地址和密码,回复用户登录结果。

 

class UserModifyInformation

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取用户要修改的信息及用户id,调用函数,用新id覆盖旧id。

 

class UserModifyPassword

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException();//获取用户id和新旧密码,调用函数修改密码。

                 

                  

posted @ 2015-11-02 18:47  1306SEers  阅读(351)  评论(2编辑  收藏  举报