Authored by csgyoho

no message

package com.yoho.ufo.user.dal.inbox;
import com.yoho.ufo.user.dal.inbox.model.InBox;
import com.yoho.ufo.user.dal.inbox.model.TypeCountInbox;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
... ... @@ -13,4 +15,12 @@ public interface InBoxMapper {
@MapKey("type")
Map<Integer,TypeCountInbox> selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel);
List<InBox> selectNewInboxs(@Param("tableName")String tableName, @Param("type") int type, @Param("uid") int uid, @Param("rowNo") int rowNo, @Param("limit") int limit);
int selectTotalNewInboxs(@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 insertInbox(@Param("tableName")String tableName, @Param("inBox")InBox inBox);
}
... ...
package com.yoho.ufo.user.dal.inbox.enums;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public enum InboxBusinessTypeEnum {
USER_WILL_DOWN_GRADE(Integer.valueOf(100), "userWillDownGrade", "您的会员级别即将降级", "您的{0}会员有效期即将到期!还需获得{1}成长值可继续保持!快来选购吧!", "http://img10.static.yhbimg.com/couponImg/2017/01/06/18/01bcf2f47b1f18d34293af4b2a71d9b953.png"),
USER_DOWN_GRADE(Integer.valueOf(101), "userDownGrade", "您的会员级别降级", "您的{0}等级会员有效期已到期,现会员等级为{1},购物享受{2}折优惠,更多会员权益请点击了解!", "http://img10.static.yhbimg.com/couponImg/2017/01/06/18/01bcf2f47b1f18d34293af4b2a71d9b953.png");
private Integer businessType;
private String beanName;
private String title;
private String content;
private String imgUrl;
InboxBusinessTypeEnum(Integer businessType, String beanName, String title, String content, String imgUrl) {
this.businessType = businessType;
this.beanName = beanName;
this.title = title;
this.content = content;
this.imgUrl = imgUrl;
}
public Integer getBusinessType() {
return businessType;
}
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
public String getBeanName() {
return beanName;
}
public void setBeanName(String beanName) {
this.beanName = beanName;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public static String getBeanNameByBusinessType(int businessType) {
if(businessType == 0) {
return "";
}
InboxBusinessTypeEnum[] var1 = values();
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
InboxBusinessTypeEnum b = var1[var3];
if(b.getBusinessType().intValue() == businessType) {
return b.getBeanName();
}
}
return "";
}
}
... ...
... ... @@ -24,9 +24,35 @@
<sql id="Base_Column_List">
id, uid, send_uid, title, type, is_read, create_time, read_time, verify_key, is_del,content,business_type
</sql>
<insert id="insertInbox">
INSERT INTO ${tableName} (uid,title,content,type,is_read,create_time,verify_key,is_del, business_type)
values
(#{inBox.uid},#{inBox.title},#{inBox.content},#{inBox.type},#{inBox.isRead},
#{inBox.createTime},#{inBox.verifyKey},#{inBox.isDel},#{inBox.businessType})
</insert>
<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}
</update>
<select id="selectTypeCount" resultMap="TypeCountInboxMap">
SELECT type, count(1) count FROM #{tableName} WHERE uid = #{uid}
and is_read = #{isRead} and is_del = #{isDel} GROUP BY type
</select>
<select id="selectNewInboxs" resultType="com.yoho.ufo.user.dal.inbox.model.InBox">
SELECT
<include refid="Base_Column_List"/>
FROM #{tableName} where uid = #{uid} and is_read='N' and is_del='N'
<if test="type != null">
and type=#{type}
</if>
order by id desc
limit #{rowNo},#{limit}
</select>
<select id="selectTotalNewInboxs" resultType="java.lang.Integer">
select count(1) from #{tableName} where uid = #{uid} and is_read='N' and is_del='N'
<if test="type != null">
and type=#{type}
</if>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,7 +4,11 @@ import com.alibaba.fastjson.JSONArray;
import com.yoho.core.common.restbean.ResponseBean;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqBO;
import com.yoho.ufo.user.requestVO.InboxReqVO;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yoho.ufo.user.requestVO.ListNewInboxReqVO;
import com.yoho.ufo.user.responseVO.InboxDetailRespVO;
import com.yoho.ufo.user.responseVO.PageResponseVO;
import com.yoho.ufo.user.service.IInBoxService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -31,7 +35,7 @@ public class InBoxController {
* @param reqBO
*/
@RequestMapping("/listInboxTypeInfo")
public ResponseBean listInboxTypeInfo(@RequestBody ListInboxTypeInfoReqBO reqBO){
public ResponseBean listInboxTypeInfo(@RequestBody ListInboxTypeInfoReqVO reqBO){
logger.info("enter listInboxTypeInfo param is {}", reqBO);
// (1)判断用户id是否存在
if (null == reqBO || reqBO.getUid() < 1) {
... ... @@ -42,39 +46,39 @@ public class InBoxController {
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setData(allTabs);
responseBean.setMessage("success");
responseBean.setMessage("listInboxTypeInfo success");
return responseBean;
}
/**
* 查看某个消息类型下的未读消息列表(设置为已读)
*/
@RequestMapping("/listNewInboxByType")
public void listNewInboxByType(){
}
/**
* 查看具体某个未读消息(设置已读)
*/
@RequestMapping("/getInboxDetail")
public void getInboxDetail(){
}
/**
* 分页查找最新的未读消息(按时间排序)
* 查看某个消息类型下的未读消息列表
* @param reqVO
* reqVO.type 为 null,查询最新未读消息;
* reqVO.type 不为null,根据type查询未读消息
* @return
*/
@RequestMapping("/listNewInboxByPage")
public void listNewInboxByPage(){
@RequestMapping("/listNewInboxs")
public ResponseBean listNewInboxs(@RequestBody ListNewInboxReqVO reqVO){
logger.info("enter listNewInboxByTypes param is {}", reqVO);
ResponseBean responseBean = new ResponseBean();
PageResponseVO<InboxDetailRespVO> pageList = inBoxService.listNewInboxByTypes(reqVO);
responseBean.setCode("200");
responseBean.setMessage("success");
responseBean.setData(pageList);
logger.info("listNewInboxByTypes success with param is {}, count is {}", reqVO, pageList.getTotal());
return responseBean;
}
/**
* 新增消息
*/
@RequestMapping("/addInbox")
public void addInbox(){
public ResponseBean addInbox(@RequestBody InboxReqVO reqVO){
logger.info("addInbox with param is {}", reqVO);
inBoxService.addInbox(reqVO);
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setMessage("保存成功");
return responseBean;
}
}
... ...
package com.yoho.ufo.user.requestVO;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public class InboxReqVO {
private int uid;
private String couponName;
private String client_type;
private String app_version;
private String isRead;
private String title;
private String content;
private String type;
private Integer verifyKey;
private Integer sendUid;
private Integer businessType=400;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getCouponName() {
return couponName;
}
public void setCouponName(String couponName) {
this.couponName = couponName;
}
public String getClient_type() {
return client_type;
}
public void setClient_type(String client_type) {
this.client_type = client_type;
}
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this.app_version = app_version;
}
public String getIsRead() {
return isRead;
}
public void setIsRead(String isRead) {
this.isRead = isRead;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getVerifyKey() {
return verifyKey;
}
public void setVerifyKey(Integer verifyKey) {
this.verifyKey = verifyKey;
}
public Integer getSendUid() {
return sendUid;
}
public void setSendUid(Integer sendUid) {
this.sendUid = sendUid;
}
public Integer getBusinessType() {
return businessType;
}
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
}
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.ufo.user.requestVO;
/**
* Created by shengguo.cai on 2018/9/11.
*/
public class ListInboxTypeInfoReqBO {
public class ListInboxTypeInfoReqVO {
private int uid;
private int size;
private String gender;
... ...
package com.yoho.ufo.user.requestVO;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public class ListNewInboxReqVO extends PageReqVO {
private int uid;
private Integer type;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}
... ...
package com.yoho.ufo.user.requestVO;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public class PageReqVO {
private int limit = 10;
private int page = 1;
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit<1 ? 1 : limit;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page<1 ? 1 : page;
}
public int getRowNo(){
return (page-1)*limit;
}
}
... ...
package com.yoho.ufo.user.responseVO;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public class InboxDetailRespVO {
private int id;
private int uid;
private String from = "有货";
private String title;
private Object body;
private String type;
private String is_read;
private long create_time;
private String create_date;
private String content;
private Integer businessType;
private String pcLink;
private String appLink;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Object getBody() {
return body;
}
public void setBody(Object body) {
this.body = body;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getIs_read() {
return is_read;
}
public void setIs_read(String is_read) {
this.is_read = is_read;
}
public long getCreate_time() {
return create_time;
}
public void setCreate_time(long create_time) {
this.create_time = create_time;
}
public String getCreate_date() {
return create_date;
}
public void setCreate_date(String create_date) {
this.create_date = create_date;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getBusinessType() {
return businessType;
}
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
public String getPcLink() {
return pcLink;
}
public void setPcLink(String pcLink) {
this.pcLink = pcLink;
}
public String getAppLink() {
return appLink;
}
public void setAppLink(String appLink) {
this.appLink = appLink;
}
}
... ...
package com.yoho.ufo.user.responseVO;
import java.util.List;
/**
* Created by shengguo.cai on 2018/9/12.
*/
public class PageResponseVO<T> {
/**
* 总记录数
*/
private int total;
/**
* 当前页
*/
private int page;
/**
* 每页记录数
*/
private int size;
/**
* 总页数
*/
private int totalPage;
/**
* 数据
*/
private List<T> list;
public PageResponseVO() {
}
public int getTotal() {
return this.total;
}
public void setTotal(int total) {
this.total = total;
this.dealTotalPage();
}
private void dealTotalPage() {
if (this.total > 0 && this.size > 0) {
int totalPage = this.total % this.size == 0 ? this.total / this.size : this.total / this.size + 1;
this.setTotalPage(totalPage);
}
}
public int getPage() {
return this.page;
}
public void setPage(int page) {
this.page = page;
}
public List<T> getList() {
return this.list;
}
public void setList(List<T> list) {
this.list = list;
}
public int getSize() {
return this.size;
}
public void setSize(int size) {
this.size = size;
this.dealTotalPage();
}
public int getTotalPage() {
return this.totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
}
... ...
package com.yoho.ufo.user.service;
import com.alibaba.fastjson.JSONArray;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqBO;
import com.yoho.ufo.user.requestVO.InboxReqVO;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yoho.ufo.user.requestVO.ListNewInboxReqVO;
import com.yoho.ufo.user.responseVO.InboxDetailRespVO;
import com.yoho.ufo.user.responseVO.PageResponseVO;
/**
* Created by shengguo.cai on 2018/9/11.
... ... @@ -12,5 +16,9 @@ public interface IInBoxService {
* @param reqBO
* @return
*/
public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqBO reqBO);
JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO);
PageResponseVO<InboxDetailRespVO> listNewInboxByTypes(ListNewInboxReqVO reqVO);
void addInbox(InboxReqVO reqVO);
}
... ...
... ... @@ -2,16 +2,27 @@ package com.yoho.ufo.user.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.ufo.user.dal.inbox.InBoxMapper;
import com.yoho.ufo.user.dal.inbox.enums.InboxTypeEnum;
import com.yoho.ufo.user.dal.inbox.model.InBox;
import com.yoho.ufo.user.dal.inbox.model.TypeCountInbox;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqBO;
import com.yoho.ufo.user.requestVO.InboxReqVO;
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yoho.ufo.user.requestVO.ListNewInboxReqVO;
import com.yoho.ufo.user.responseVO.InboxDetailRespVO;
import com.yoho.ufo.user.responseVO.PageResponseVO;
import com.yoho.ufo.user.service.IInBoxService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
... ... @@ -24,7 +35,7 @@ public class InBoxServiceImpl implements IInBoxService {
private InBoxMapper inBoxMapper;
@Override
public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqBO reqBO) {
public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO) {
log.info("listInboxTypeInfo begin.param is {}",reqBO);
Integer uid = reqBO.getUid();
Map<Integer,TypeCountInbox> typeCountMap = inBoxMapper.selectTypeCount(getTableName(uid), uid, "N", "N");
... ... @@ -40,7 +51,103 @@ public class InBoxServiceImpl implements IInBoxService {
return result;
}
@Override
public PageResponseVO<InboxDetailRespVO> listNewInboxByTypes(ListNewInboxReqVO reqVO) {
log.info("entre listNewInboxByTypes with param is {}", reqVO);
//判断为空
if (reqVO.getUid() <= 0) {
log.warn("listNewInboxByTypes error because uid is null with param is {}", reqVO);
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
}
PageResponseVO<InboxDetailRespVO> response = new PageResponseVO<>();
int total = inBoxMapper.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid());
if(total == 0){
log.info("listNewInboxByTypes query inbox is empty with param is {}", reqVO);
response.setPage(reqVO.getPage());
response.setTotal(0);
return response;
}
List<InBox> list = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid(),reqVO.getRowNo(),reqVO.getLimit());
List<InboxDetailRespVO> inboxDetailRespVOList = initInboxDetails(list);
// 将当前分类下用户所有的未读消息置为已读
if(null!=reqVO.getType()){
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
}
response.setList(inboxDetailRespVOList);
response.setPage(reqVO.getPage());
response.setSize(reqVO.getLimit());
response.setTotal(total);
return response;
}
@Override
public void addInbox(InboxReqVO reqVO) {
InBox inBox = new InBox();
inBox.setUid(reqVO.getUid());
inBox.setSendUid(reqVO.getSendUid());
inBox.setType(reqVO.getBusinessType() / 100);
inBox.setIsRead("N");
inBox.setIsDel("N");
inBox.setTitle(reqVO.getTitle());
inBox.setCreateTime(DateUtil.getCurrentTimeSecond());
inBox.setContent(reqVO.getContent());
inBox.setVerifyKey(reqVO.getVerifyKey());
inBox.setBusinessType(reqVO.getBusinessType());
inBoxMapper.insertInbox(getTableName(inBox.getUid()),inBox);
}
private List<InboxDetailRespVO> initInboxDetails(List<InBox> inBoxList){
List<InboxDetailRespVO> inboxDetailRespVOList = new ArrayList<>();
InboxDetailRespVO resp = null;
String date = "";
//取当天的年月日的时间毫秒数
long now = DateUtil.stringToDate(DateUtil.long2DateStr(new Date().getTime(), DateUtil.DATE_FORMAT), DateUtil.DATE_FORMAT).getTime();
String lastDate = DateUtil.dateAdd(DateUtil.getcurrentDate(), "d", -1, DateUtil.DATE_FORMAT);
for (InBox box : inBoxList) {
// 校验消息业务类型
if (box.getBusinessType() == null) {
log.warn("initInboxDetails inbox BusinessType is null. with box={}", box);
continue;
}
date = DateUtil.long2DateStr((long) box.getCreateTime() * 1000, DateUtil.DATE_TIME_FORMAT);
if (box.getCreateTime() * 1000 >= now) {
date = "今天" + DateUtil.dateToString(DateUtil.long2Date(box.getCreateTime() * 1000), "HH:mm");
} else if (box.getCreateTime() * 1000 > DateUtil.stringToDate(lastDate, DateUtil.DATE_FORMAT).getTime()) {
date = "昨天" + DateUtil.dateToString(DateUtil.long2Date(box.getCreateTime() * 1000), "HH:mm");
}
resp = new InboxDetailRespVO();
resp.setContent(box.getContent());
resp.setId(box.getId());
resp.setUid(box.getUid());
resp.setTitle(box.getTitle());
resp.setBusinessType(box.getBusinessType());
if (box.getBusinessType() != null && box.getBusinessType() > 0) {
// final String beanName = InboxBusinessTypeEnum.getBeanNameByBusinessType(box.getBusinessType());
// IInBoxBusinessService service = SpringContextUtil.getBean(beanName, IInBoxBusinessService.class);
// Map<String, Object> map = service.getMessage(box);
// String imgUrl = BusinessTypeEnum.getImgUrlByBusinessType(box.getBusinessType());
// resp.setBody(map);
} else {
continue;
}
// Map<String, String> urlMap = InboxJumpUrlHelper.getJumpUrl(box, resp.getBody());
// resp.setPcLink(StringUtils.isNotEmpty(urlMap.get("pc_link")) ? urlMap.get("pc_link") : "");
// resp.setAppLink(StringUtils.isNotEmpty(urlMap.get("app_link")) ? urlMap.get("app_link") : "");
resp.setIs_read(box.getIsRead());
resp.setCreate_time(box.getCreateTime());
resp.setCreate_date(date);
resp.setType(String.valueOf(box.getType()));
inboxDetailRespVOList.add(resp);
}
return inboxDetailRespVOList;
}
private String getTableName(Integer uid) {
return "inbox_" + uid % 10;
}
}
... ...