Authored by chaogeng

Merge branch 'dev-inbox-20180911'

package com.yohoufo.user.dal.enums;
package com.yohoufo.common.enums;
/**
* Created by shengguo.cai on 2018/9/12.
... ... @@ -43,16 +43,15 @@ public enum InboxBusinessTypeEnum {
this.type = type;
}
public static InboxBusinessTypeEnum getByTypeAndBusinessType(Integer type,Integer businessType){
InboxBusinessTypeEnum[] var1 = values();
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
InboxBusinessTypeEnum b = var1[var3];
if(b.getBusinessType().intValue() == businessType && b.getType().equals(type)) {
return b;
InboxBusinessTypeEnum[] emums = values();
for(InboxBusinessTypeEnum cell : emums){
if(cell.getBusinessType().equals(businessType) && cell.getType().equals(type)) {
return cell;
}
}
return null;
}
public Integer getBusinessType() {
return businessType;
}
... ...
package com.yohoufo.user.dal.enums;
package com.yohoufo.common.enums;
/**
* Created by shengguo.cai on 2018/9/12.
... ... @@ -11,7 +11,7 @@ public enum InboxTypeEnum {
private Integer id;
private String description;
private String imgUrl;
private InboxTypeEnum(Integer id,String description,String imgUrl){
private InboxTypeEnum(Integer id, String description, String imgUrl){
this.id = id;
this.description = description;
this.imgUrl = imgUrl;
... ...
... ... @@ -11,7 +11,7 @@ import java.util.Map;
/**
* Created by shengguo.cai on 2018/9/11.
*/
public interface InBoxMapper {
public interface IInBoxDao {
@MapKey("type")
Map<Integer,TypeCountInbox> selectTypeCount(@Param("tableName") String tableName, @Param("uid") Integer uid, @Param("isRead") String isRead, @Param("isDel") String isDel);
... ...
... ... @@ -12,29 +12,29 @@ public class InBox {
private Integer uid;
private Integer sendUid;
private String title;
private Integer type;
private String isRead;
private String isDel;
private Integer createTime;
private Integer readTime;
private Integer verifyKey;
private String isDel;
private String content;
private String tableName;
private Integer businessType;
private Integer groupType;
public String getIsDel() {
return isDel;
}
public void setIsDel(String isDel) {
this.isDel = isDel;
}
public Integer getId() {
return id;
... ... @@ -52,14 +52,6 @@ public class InBox {
this.uid = uid;
}
public Integer getSendUid() {
return sendUid;
}
public void setSendUid(Integer sendUid) {
this.sendUid = sendUid;
}
public String getTitle() {
return title;
}
... ... @@ -100,22 +92,6 @@ public class InBox {
this.readTime = readTime;
}
public Integer getVerifyKey() {
return verifyKey;
}
public void setVerifyKey(Integer verifyKey) {
this.verifyKey = verifyKey;
}
public String getIsDel() {
return isDel;
}
public void setIsDel(String isDel) {
this.isDel = isDel;
}
public String getContent() {
return content;
}
... ... @@ -124,14 +100,6 @@ public class InBox {
this.content = content;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public Integer getBusinessType() {
return businessType;
}
... ... @@ -139,12 +107,4 @@ public class InBox {
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
public Integer getGroupType() {
return groupType;
}
public void setGroupType(Integer groupType) {
this.groupType = groupType;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yohoufo.user.dal.InBoxMapper">
<mapper namespace="com.yohoufo.user.dal.IInBoxDao">
<resultMap id="BaseResultMap" type="com.yohoufo.user.dal.model.InBox">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="uid" property="uid" jdbcType="INTEGER"/>
<result column="send_uid" property="sendUid" jdbcType="INTEGER"/>
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="type" property="type" jdbcType="INTEGER"/>
<result column="is_read" property="isRead" jdbcType="CHAR"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
<result column="read_time" property="readTime" jdbcType="INTEGER"/>
<result column="verify_key" property="verifyKey" jdbcType="INTEGER"/>
<result column="is_del" property="isDel" jdbcType="CHAR"/>
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
<result column="business_type" property="businessType" jdbcType="INTEGER" />
<result column="group_type" property="groupType" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="TypeCountInboxMap" type="com.yohoufo.user.dal.model.TypeCountInbox">
<result column="type" property="type" jdbcType="INTEGER"/>
... ... @@ -22,13 +19,13 @@
</resultMap>
<sql id="Base_Column_List">
id, uid, send_uid, title, type, is_read, create_time, read_time, verify_key, is_del,content,business_type
id, uid, title, type, is_read, create_time, read_time, 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)
INSERT INTO ${tableName} (uid,title,content,type,is_read,create_time,is_del, business_type)
values
(#{inBox.uid},#{inBox.title},#{inBox.content},#{inBox.type},#{inBox.isRead},
#{inBox.createTime},#{inBox.verifyKey},#{inBox.isDel},#{inBox.businessType})
#{inBox.createTime},#{inBox.isDel},#{inBox.businessType})
</insert>
<update id="updateReadedByUidAndType">
update #{tableName} set is_read='Y', read_time=#{readTime} where uid = ${uid} and is_read='N'
... ...
... ... @@ -8,7 +8,6 @@ import com.yohoufo.user.dal.model.InBox;
import com.yohoufo.user.requestVO.InboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.requestVO.ListNewInboxReqVO;
import com.yohoufo.user.requestVO.UpdateReadedReqVO;
import com.yohoufo.user.responseVO.PageResponseVO;
import com.yohoufo.user.service.IInBoxService;
import org.slf4j.Logger;
... ... @@ -82,19 +81,4 @@ public class InBoxController {
responseBean.setMessage("保存成功");
return responseBean;
}
/**
* 将某类型下的未读消息更新为已读
* @param reqVO
* @return
*/
@RequestMapping("/updateReadedByType")
public ResponseBean updateReadedByType(@RequestBody UpdateReadedReqVO reqVO){
logger.info("updateReadedByType with param is {}", reqVO);
inBoxService.updateReadedByType(reqVO);
ResponseBean responseBean = new ResponseBean();
responseBean.setCode("200");
responseBean.setMessage("更新成功");
return responseBean;
}
}
... ...
... ... @@ -7,7 +7,7 @@ import java.util.List;
*/
public class InboxReqVO {
private int uid;
private String type;
private Integer type;
private Integer businessType;
private List<String> params;
... ... @@ -19,20 +19,20 @@ public class InboxReqVO {
this.params = params;
}
public int getUid() {
return uid;
public Integer getType() {
return type;
}
public void setUid(int uid) {
this.uid = uid;
public void setType(Integer type) {
this.type = type;
}
public String getType() {
return type;
public int getUid() {
return uid;
}
public void setType(String type) {
this.type = type;
public void setUid(int uid) {
this.uid = uid;
}
public Integer getBusinessType() {
... ...
... ... @@ -5,7 +5,6 @@ import com.yohoufo.user.dal.model.InBox;
import com.yohoufo.user.requestVO.InboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.requestVO.ListNewInboxReqVO;
import com.yohoufo.user.requestVO.UpdateReadedReqVO;
import com.yohoufo.user.responseVO.PageResponseVO;
/**
... ... @@ -23,5 +22,4 @@ public interface IInBoxService {
void addInbox(InboxReqVO reqVO);
void updateReadedByType(UpdateReadedReqVO reqVO);
}
... ...
... ... @@ -5,15 +5,14 @@ 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.yohoufo.user.dal.InBoxMapper;
import com.yohoufo.user.dal.enums.InboxBusinessTypeEnum;
import com.yohoufo.user.dal.enums.InboxTypeEnum;
import com.yohoufo.common.enums.InboxBusinessTypeEnum;
import com.yohoufo.common.enums.InboxTypeEnum;
import com.yohoufo.user.dal.IInBoxDao;
import com.yohoufo.user.dal.model.InBox;
import com.yohoufo.user.dal.model.TypeCountInbox;
import com.yohoufo.user.requestVO.InboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.requestVO.ListNewInboxReqVO;
import com.yohoufo.user.requestVO.UpdateReadedReqVO;
import com.yohoufo.user.responseVO.PageResponseVO;
import com.yohoufo.user.service.IInBoxService;
import org.slf4j.Logger;
... ... @@ -31,13 +30,13 @@ import java.util.Map;
public class InBoxServiceImpl implements IInBoxService {
private static Logger log = LoggerFactory.getLogger(InBoxServiceImpl.class);
@Autowired
private InBoxMapper inBoxMapper;
private IInBoxDao inBoxDao;
@Override
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");
Map<Integer,TypeCountInbox> typeCountMap = inBoxDao.selectTypeCount(getTableName(uid), uid, "N", "N");
JSONArray result = new JSONArray();
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
JSONObject obj = new JSONObject();
... ... @@ -60,7 +59,7 @@ public class InBoxServiceImpl implements IInBoxService {
}
PageResponseVO<InBox> response = new PageResponseVO<>();
int total = inBoxMapper.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
int total = inBoxDao.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid());
if(total == 0){
log.info("listNewInboxByTypes query inbox is empty with param is {}", reqVO);
... ... @@ -68,10 +67,13 @@ public class InBoxServiceImpl implements IInBoxService {
response.setTotal(0);
return response;
}
List<InBox> inBoxes = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
List<InBox> inBoxes = inBoxDao.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid(),reqVO.getRowNo(),reqVO.getLimit());
//如果根据类型查看,设置未读为已读
if(null != reqVO.getType()){
inBoxDao.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
response.setList(inBoxes);
}
response.setPage(reqVO.getPage());
response.setSize(reqVO.getLimit());
response.setTotal(total);
... ... @@ -80,27 +82,30 @@ public class InBoxServiceImpl implements IInBoxService {
@Override
public void addInbox(InboxReqVO reqVO) {
InboxBusinessTypeEnum businessTypeEnum = InboxBusinessTypeEnum
InboxBusinessTypeEnum businessTypeEnum = InboxBusinessTypeEnum.getByTypeAndBusinessType(reqVO.getType(),reqVO.getBusinessType());
if(businessTypeEnum == null){
throw new ServiceException(ServiceError.ERROR);//TODO 自定义
}
InBox inBox = new InBox();
inBox.setUid(reqVO.getUid());
inBox.setType(reqVO.getBusinessType());
inBox.setIsRead("N");
inBox.setIsDel("N");
inBox.setTitle(reqVO.getTitle());
inBox.setIsRead(InBox.N);
inBox.setIsDel(InBox.N);
inBox.setTitle(businessTypeEnum.getTitle());
inBox.setCreateTime(DateUtil.getCurrentTimeSecond());
inBox.setContent(reqVO.getContent());
inBox.setVerifyKey(reqVO.getVerifyKey());
inBox.setContent(createContent(businessTypeEnum.getContent(),reqVO.getParams()));
inBox.setBusinessType(reqVO.getBusinessType());
inBoxMapper.insertInbox(getTableName(inBox.getUid()),inBox);
inBoxDao.insertInbox(getTableName(inBox.getUid()),inBox);
}
@Override
public void updateReadedByType(UpdateReadedReqVO reqVO) {
if (reqVO.getUid() < 1) {
log.warn("updateReadedByType error because uid is null with param is {}", reqVO);
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
private String createContent(String template, List<String> params){
if(params==null){
return template;
}
for(String param : params){
template=template.replaceFirst("\\{\\}",param);
}
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
return template;
}
private String getTableName(Integer uid) {
... ...