Authored by caoyan

自助尺码

... ... @@ -25,4 +25,6 @@ public interface IInBoxDao {
void insertInbox(@Param("tableName")String tableName, @Param("inBox")InBox inBox);
InBox selectNewUserGuideInBox(@Param("tableName")String tableName, @Param("businessType") Integer businessType, @Param("uid") Integer uid);
int insertBatch(@Param("tableName") String tableName, @Param("list") List<InBox> list);
}
... ...
... ... @@ -59,4 +59,15 @@
FROM ${tableName} where uid = #{uid} and business_type = #{businessType}
limit 1
</select>
<insert id="insertBatch">
insert into ${tableName}
(uid,title,content,type,is_read,create_time,is_del, business_type,action)
values
<foreach collection="list" separator="," item="inBox">
(#{inBox.uid},#{inBox.title},#{inBox.content},#{inBox.type},#{inBox.isRead},
#{inBox.createTime},#{inBox.isDel},#{inBox.businessType},#{inBox.action})
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -14,4 +14,8 @@ public class UrlConstant {
public String getInboxAddUrl(){
return baseUrl+"&method=ufo.users.addInbox";
}
private String getInboxAddBatchUrl() {
return baseUrl+"&method=ufo.users.addBatchInbox";
}
}
... ...
... ... @@ -39,7 +39,16 @@ public class InboxController {
logger.info("InboxController.addInbox call result is {}",result);
return "SUCCESS";
}
@RequestMapping(value = "/addBatchInboxForPlatform")
@IgnoreSession
@IgnoreSignature
public String addBatchInboxForPlatform(@RequestBody InboxReqVO reqVO){
logger.info("InboxController.addInbox with param is {}", reqVO);
InBoxResponse result = inBoxSDK.addBatchInbox(reqVO);
logger.info("InboxController.addBatchInbox call result is {}",result);
return "SUCCESS";
}
@RequestMapping(value = "/sendSmsForPlatform")
@IgnoreSession
... ...
... ... @@ -10,6 +10,7 @@ public class InboxReqVO extends BaseVO{
private Integer type;
private Integer businessType;
private String params;
private String uids;
public String getParams() {
return params;
... ... @@ -42,4 +43,13 @@ public class InboxReqVO extends BaseVO{
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
public String getUids() {
return uids;
}
public void setUids(String uids) {
this.uids = uids;
}
}
... ...
... ... @@ -37,4 +37,12 @@ public class InBoxSDK {
log.info("addInbox call result is {}",result);
return result;
}
public InBoxResponse addBatchInbox(InboxReqVO reqVO){
log.info("addBatchInbox with param is {}", reqVO);
InBoxResponse result = restTemplate.getForObject(urlConstant.getInboxAddBatchUrl()+"&uids={1}&type={2}&businessType={3}&params={4}",InBoxResponse.class,
reqVO.getUids(),reqVO.getType(),reqVO.getBusinessType(),reqVO.getParams());
log.info("addBatchInbox call result is {}",result);
return result;
}
}
... ...
... ... @@ -91,4 +91,18 @@ public class InBoxController {
Integer id = inBoxService.addInbox(uid,type,businessType,params);
return new ApiResponse(200,"保存成功",id);
}
/**
* 批量新增消息
*/
@RequestMapping(params = "method=ufo.users.addBatchInbox")
@IgnoreSession
public ApiResponse addBatchInbox(@RequestParam(name = "uids") String uids,
@RequestParam(name = "type") Integer type,
@RequestParam(name = "businessType") Integer businessType,
@RequestParam(name = "params",required = false) String params){
logger.info("addBatchInbox with param :uids is {},type is {},businessType is {},params is {}", uids,type,businessType,params);
inBoxService.addBatchInboxByUids(uids,type,businessType,params);
return new ApiResponse(200,"保存成功", "");
}
}
... ...
... ... @@ -23,4 +23,6 @@ public interface IInBoxService {
Integer addInbox(int uid, Integer type, Integer businessType, String params);
JSONObject getTotalUnread(int uid);
void addBatchInboxByUids(String uids, Integer type, Integer businessType, String params);
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.user.service.impl;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.annotation.Resource;
... ... @@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.ServiceError;
... ... @@ -287,6 +289,55 @@ public class InBoxServiceImpl implements IInBoxService {
deleteIboxsByRedis(uid,type);
return inBox.getId();
}
@Override
public void addBatchInboxByUids(String uids, Integer type, Integer businessType, String params) {
log.info("entre addBatchInboxByUids with param .uids is {},type is {},businessType is {},params is {}", uids,type,businessType,params);
InboxBusinessTypeEnum businessTypeEnum = InboxBusinessTypeEnum.getByTypeAndBusinessType(type,businessType);
if(businessTypeEnum == null){
log.warn("addInbox businessTypeEnum is null.type is {},businessType is {}",type,businessType);
throw new ServiceException(ServiceError.SMS_TEMPLATE_NOT_EXIST);
}
String[] uidArr = uids.split(",");
Map<String, List<InBox>> tableNameInboxMap = Maps.newHashMap();
for(int i=0; i<uidArr.length; i++) {
Integer uid = Integer.parseInt(uidArr[i]);
InBox inBox = createInBox(type, businessType, params, businessTypeEnum);
String tableName = getTableName(uid);
if(CollectionUtils.isEmpty(tableNameInboxMap.get(tableName))) {
List<InBox> inBoxList = Lists.newArrayList(inBox);
tableNameInboxMap.put(tableName, inBoxList);
}else {
tableNameInboxMap.get(tableName).add(inBox);
}
//清空redis缓存
deleteIboxsByRedis(uid,type);
}
//分表批量插入
for(Entry<String, List<InBox>> entry : tableNameInboxMap.entrySet()) {
List<InBox> inBoxList = entry.getValue();
inBoxDao.insertBatch(entry.getKey(), inBoxList);
}
}
private InBox createInBox(Integer type, Integer businessType, String params, InboxBusinessTypeEnum businessTypeEnum) {
InBox inBox = new InBox();
inBox.setType(type);
inBox.setIsRead(InBox.N);
inBox.setIsDel(InBox.N);
inBox.setTitle(businessTypeEnum.getTitle());
inBox.setCreateTime(DateUtil.getCurrentTimeSecond());
inBox.setContent(createContent(businessTypeEnum.getContent(),params));
inBox.setBusinessType(businessType);
//处理附加业务
dealAddition(inBox,params);
return inBox;
}
private void dealAddition(InBox inBox,String params) {
if(InboxBusinessTypeEnum.NOTICE_PROBLEM_ORDER.getBusinessType().equals(inBox.getBusinessType())){
... ...