Authored by Lixiaodi

消息盒子

... ... @@ -13,13 +13,13 @@ import java.util.Map;
*/
public interface IInBoxDao {
int selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel, @Param("type")Integer type);
int selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel, @Param("type")Integer type, @Param("time")int time);
List<InBox> selectInboxs(@Param("tableName")String tableName, @Param("type") Integer type, @Param("uid") int uid, @Param("rowNo") int rowNo, @Param("limit") int limit);
int selectTotalInboxs(@Param("tableName")String tableName, @Param("type") Integer type, @Param("uid") int uid);
void updateReadedByUidAndType(@Param("tableName")String tableName,@Param("uid") int uid, @Param("type")Integer type, @Param("readTime")int readTime);
void updateReadedByUidAndType(@Param("tableName")String tableName,@Param("uid") int uid, @Param("type")Integer type, @Param("readTime")int readTime, @Param("time")int time);
void insertInbox(@Param("tableName")String tableName, @Param("inBox")InBox inBox);
... ...
... ... @@ -31,11 +31,17 @@
<update id="updateReadedByUidAndType">
update ${tableName} set is_read='Y', read_time=#{readTime} where uid = ${uid} and is_read='N'
and is_del = 'N' and type = #{type}
<if test="time != 0">
and create_time &gt;= #{time}
</if>
</update>
<select id="selectTypeCount" resultType="java.lang.Integer">
SELECT count(1) count FROM ${tableName} force index (`read`) WHERE uid = #{uid}
and is_read = #{isRead} and is_del = #{isDel} AND type = #{type}
<if test="time != 0 and isRead ='N'">
and create_time &gt;= #{time}
</if>
</select>
<select id="selectInboxs" resultMap="BaseResultMap">
SELECT
... ...
... ... @@ -8,6 +8,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yoho.core.config.ConfigReader;
import com.yohoufo.common.helper.NoticeMessageFormatter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -95,7 +96,7 @@ public class InBoxServiceImpl implements IInBoxService {
Map<Integer, TypeCountInbox> result = new HashMap<>();
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
TypeCountInbox inbox = new TypeCountInbox();
int count = inBoxDao.selectTypeCount(tableName, uid, isRead, isDel, typeEnum.getId());
int count = inBoxDao.selectTypeCount(tableName, uid, isRead, isDel, typeEnum.getId(),getUnreadBeginTime());
inbox.setCount(count);
inbox.setType(typeEnum.getId());
result.put(typeEnum.getId(), inbox);
... ... @@ -271,7 +272,7 @@ public class InBoxServiceImpl implements IInBoxService {
private void updateReaded(ListInboxReqVO reqVO){
if(null != reqVO.getType()){
log.info("listInboxByTypes updateReadedByUidAndType param is {}", reqVO);
inBoxDao.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
inBoxDao.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond(),getUnreadBeginTime());
RedisKeyBuilder key = CacheEnum.USERS_INBOX_TYPE_UNREADCOUNT.generateKey(reqVO.getUid(),reqVO.getType());
redisTemplate.delete(key);
}
... ... @@ -437,4 +438,18 @@ public class InBoxServiceImpl implements IInBoxService {
return "inbox_" + uid % 10;
}
@Autowired
private ConfigReader configReader;
// 未读记录的开始时间
private int getUnreadBeginTime() {
String daysStr = configReader.getString("ufo.users.messageUnreadDays", "7");
try {
int days = Integer.parseInt(daysStr.trim());
return (int) (System.currentTimeMillis() / 1000) - days * 24 * 3600;
} catch (NumberFormatException e) {
return 0;
}
}
}
... ...