infoboxoperimp.java
来自「jaguey,网上的一个朋友给我的」· Java 代码 · 共 134 行
JAVA
134 行
package net.javapassion.jaguey.service.imp;
import java.util.List;
import java.util.Date;
import java.util.Iterator;
import net.javapassion.jaguey.core.Log;
import net.javapassion.jaguey.util.DateUtil;
import net.javapassion.jaguey.domain.InfoBox;
import net.javapassion.jaguey.dao.InfoBoxDao;
import net.javapassion.jaguey.service.InfoBoxOper;
//版本: JagueyBBS 1.1
//功能: 论坛短信息业务逻辑实现
//作者: 赵程佳
//时间: 2006-02-10 15:49:36
public class InfoBoxOperImp implements InfoBoxOper {
private InfoBoxDao infoBoxDao;
//保存短信息
public String saveInfoBox(InfoBox infoBox) {
try {
this.infoBoxDao.saveInfoBox(infoBox);
return "success";
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "failed";
}
}
//删除短信息
public String deleteInfoBox(String infoId) {
try {
InfoBox infoBox = this.infoBoxDao.getInfoBoxById(infoId);
if (infoBox != null) {
this.infoBoxDao.deleteInfoBox(infoBox);
return "success";
} else {
return "can't find data";
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "failed";
}
}
//获取特定用户的短信息
public List getInfoBoxByUser(Long userId) {
try {
return this.infoBoxDao.getInfoBoxByUserId(userId);
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return null;
}
}
//通过短信息号获取短信息
public InfoBox getInfoBoxById(String infoId) {
try {
InfoBox infoBox = this.infoBoxDao.getInfoBoxById(infoId);
if (infoBox != null) {
return infoBox;
} else {
Log.warn("Use infoId can't find InfoBox!");
return null;
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return null;
}
}
//获取阅读与否的短信息
public List getInfoBoxByUserRead(Long userId, Integer readFlag) {
try {
return this.infoBoxDao.getInfoBoxByUserRead(userId, readFlag);
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return null;
}
}
//判断特定用户的短信息中是否存在未阅读短信息
public boolean getReadFlagByUser(Long userId) {
try {
return this.getReadFlagByUser(userId);
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return false;
}
}
//创建短信息编号
public String makeInfoBoxId() {
String infoId = "";
try {
List list = this.infoBoxDao.getInfoBoxByLikeId(DateUtil.formatDate7(new Date()));
if (list.size() == 0) {
return DateUtil.formatDate7(new Date()) + "0001";
} else {
Iterator it = list.iterator();
int i = 1;
while (it.hasNext()) {
if (i == list.size()) {
InfoBox infoBox = (InfoBox) it.next();
infoId = String.valueOf(Integer.parseInt(infoBox.getInfoId().substring(6)) + 1);
if (Integer.parseInt(infoId) != 10000) {
switch (infoId.length()) {
case 1 : infoId = "000" + infoId; break;
case 2 : infoId = "00" + infoId; break;
case 3 : infoId = "0" + infoId; break;
}
} else {
Log.info("The infoId have already exceed to allow max quantity!");
infoId = "0000";
}
} else {
i++;
continue;
}
}
return DateUtil.formatDate7(new Date()) + infoId;
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "";
}
}
public void setInfoBoxDao(InfoBoxDao infoBoxDao) {
this.infoBoxDao = infoBoxDao;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?