Authored by LiQZ

Merge branch 'channel' of http://git.yoho.cn/yoho30/yohobuy-union into channel

package com.yoho.unions.channel.restapi;
import com.alibaba.fastjson.JSONObject;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yoho.message.sdk.service.crm.ISendCrmMessage;
import com.yoho.message.sdk.service.crm.impl.SendCrmMessageImpl;
... ... @@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
/**
* Created by yoho on 2017/2/15.
*/
... ... @@ -54,4 +57,18 @@ public class ChannelGroupRest {
}
@RequestMapping("/test")
@ResponseBody
public String test(){
return "success";
}
@RequestMapping("/getCondition")
@ResponseBody
public ApiResponse getCondition(String ids){
logger.info("enter getCondition. param ids={}", ids);
Map<Integer,String> result = channelGroupService.getCondition(ids);
return new ApiResponse.ApiResponseBuilder().code(200).message("成功").data(result).build();
}
}
... ...
package com.yoho.unions.channel.service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.service.model.union.request.ChannelGroupRequestBO;
import com.yoho.service.model.union.request.ChannelMessageRequestBO;
import com.yoho.service.model.union.response.PageChannelGroupRspBO;
import com.yoho.unions.dal.model.ChannelGroup;
import java.util.List;
import java.util.Map;
/**
* Created by yoho on 2017/2/15.
... ... @@ -15,4 +17,6 @@ public interface ChannelGroupService {
PageChannelGroupRspBO queryChannelGroupList(ChannelGroupRequestBO channelGroupRequestBO);
void sendMessage(ChannelMessageRequestBO channelGroupRequestBO);
Map<Integer,String> getCondition(String ids);
}
... ...
package com.yoho.unions.channel.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
... ... @@ -22,9 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
... ... @@ -61,6 +61,26 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
public static final short SMS_STATUS_FAIL = 0;
public final static Map paramMap = new HashMap() {{
put("channelSource", "泛渠道来源");
put("channelOrderCode", "泛渠道订单号");
put("uid", "有货uid");
put("hasUid", "是否有货会员");
put("hasYHOrder", "是否存在有货订单");
put("yhOrderCode", "有货订单号");
put("unionCode", "渠道号");
put("userChannel", "渠道注册终端");
put("beginChannelOrderTime", "泛渠道订单时间");
put("endChannelOrderTime", "泛渠道订单时间");
put("beginYHOrderTime", "有货订单时间");
put("endYHOrderTime", "有货订单时间");
put("beginRegisterTime", "注册时间");
put("endRegisterTime", "注册时间");
put("beginSmsTime", "短信发送时间");
put("endSmsTime", "短信发送时间");
}};
@Override
public PageChannelGroupRspBO queryChannelGroupList(ChannelGroupRequestBO channelGroupRequestBO) {
logger.info("enter queryChannelGroupList. param channelGroupRequestBO={}", channelGroupRequestBO);
... ... @@ -95,26 +115,36 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
//1.根据groupId查询条件
List<ChannelGroupCondition> conditions = channelGroupConditionDAO.selectByGroupId(groupId);
logger.info("sendMessage:conditions is {}",conditions);
Map<String, Object> params = Maps.newHashMap();
if (!CollectionUtils.isEmpty(conditions)) {
for (ChannelGroupCondition channelGroupCondition : conditions) {
params.put(channelGroupCondition.getKey(), channelGroupCondition.getValue());
}
}
Map<String, Object> params = conditions.stream().collect(Collectors.toMap(ChannelGroupCondition::getKey,ChannelGroupCondition::getValue));
// Map<String, Object> params = Maps.newHashMap();
// if (!CollectionUtils.isEmpty(conditions)) {
// for (ChannelGroupCondition channelGroupCondition : conditions) {
// params.put(channelGroupCondition.getKey(), channelGroupCondition.getValue());
// }
// }
//2.根据条件分批查询手机号发送短信
int total = channelUserDAO.selectCount(params);
//3.记录分组批次表
//2.记录分组批次表
int sendTime = DateUtils.getCurrentTimeSecond();
ChannelGroupBatch channelGroupBatch = new ChannelGroupBatch(groupId, content, sendTime, sendUserId);
channelGroupBatchDAO.insertSelective(channelGroupBatch);
logger.info("sendMessage:insert channelGroupBatch,channelGroupBatch ={}",channelGroupBatch);
int groupBatchId = channelGroupBatch.getId();
//3.根据条件分批查询手机号
int total = channelUserDAO.selectCount(params);
Set<String> mobileSet = Sets.newHashSet();
//分批从数据库中查询,每次1000,使用mobileSet去重
for (int i = 0; i < total; i += BATCH_MESSAGE_NUMBER) {
List<ChannelUser> channelUsers = channelUserDAO.selectPage(params, i, i + BATCH_MESSAGE_NUMBER);
List<String> mobiles = channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toList());
Set<String> channelMobiles= channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toSet());
mobileSet.addAll(channelMobiles);
}
List<String> mobileList = Lists.newArrayList(mobileSet);
List<ChannelSmsDetail> smsDetails = Lists.newArrayList();
//4.用户去重、黑名单后,分批发送短信
for (int i = 0; i < mobileList.size(); i += BATCH_MESSAGE_NUMBER) {
List<String> mobiles = mobileList.subList(i, i + BATCH_MESSAGE_NUMBER);
String mobile = StringUtils.join(mobiles.toArray(), ",");
//调用SDK发送短信接口
SendMessageRspBo sendMessageRspBo = null;
... ... @@ -127,7 +157,6 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
}
List<ChannelSmsDetail> smsDetails = Lists.newArrayList();
//4.1短信发送成功,记录短信日志表(状态为1)
if (sendMessageRspBo!=null&&sendMessageRspBo.getCode() == 200 && sendMessageRspBo.getMessage().equals("SUCCESS")) {
for (String sms : mobiles) {
... ... @@ -141,9 +170,11 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
smsDetails.add(channelSmsDetail);
}
}
channelSmsDetailDAO.batchInsert(smsDetails);
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}",smsDetails);
}
channelSmsDetailDAO.batchInsert(smsDetails);
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}",smsDetails);
//5.修改分组表的分组人数、发送时间、修改时间、内容、发送人
ChannelGroup channelGroup = new ChannelGroup();
channelGroup.setId(groupId);
... ... @@ -157,6 +188,64 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
}
@Override
public Map<Integer,String> getCondition(String ids) {
logger.info("enter getCondition. param ids={}", ids);
List groupIds = Arrays.asList(ids.split(","));
List<ChannelGroupCondition> channelGroupConditions = channelGroupConditionDAO.selectByGroupIds(groupIds);
Map<Integer,Map<String,String>> conditionMap = Maps.newHashMap();
if(!CollectionUtils.isEmpty(channelGroupConditions)){
for(int i=0;i<channelGroupConditions.size();i++){
ChannelGroupCondition channelGroupCondition = channelGroupConditions.get(i);
if(conditionMap.get(channelGroupCondition.getGroupId())!=null){
Map<String,String> condition = conditionMap.get(channelGroupCondition.getGroupId());
condition.put(channelGroupCondition.getKey(),channelGroupCondition.getValue());
conditionMap.put(channelGroupCondition.getGroupId(),condition);
}else{
Map<String,String> condition = Maps.newHashMap();
condition.put(channelGroupCondition.getKey(),channelGroupCondition.getValue());
conditionMap.put(channelGroupCondition.getGroupId(),condition);
}
}
}
Map<Integer,String> result = Maps.newHashMap();
for (Map.Entry<Integer,Map<String,String>> entry : conditionMap .entrySet()) {
Map<String,String> map = entry.getValue();
StringBuffer sb = new StringBuffer();
convertTime(map,"beginChannelOrderTime","endChannelOrderTime",sb);
convertTime(map,"beginYHOrderTime","endYHOrderTime",sb);
convertTime(map,"beginRegisterTime","endRegisterTime",sb);
convertTime(map,"beginSmsTime","endSmsTime",sb);
for(Map.Entry<String,String> entry1:map.entrySet()){
String key = entry1.getKey();
sb.append("<div>").append(paramMap.get(key)).append(":").append(entry1.getValue()).append("</div>");
}
result.put(entry.getKey(),sb.toString());
}
return result;
}
private void convertTime(Map<String, String> map, String beginTimeKey, String endTimeKey, StringBuffer sb) {
if(map.get(beginTimeKey)!=null || map.get(endTimeKey)!=null){
String beginTime = map.get(beginTimeKey);
String endTime = map.get(endTimeKey);
if(beginTime!=null){
beginTime = DateUtils.int2DateStr(Integer.parseInt(beginTime),"yyyy-MM-dd HH:mm:ss");
}else{
beginTime = "未设置";
}
if(endTime!=null){
endTime = DateUtils.int2DateStr(Integer.parseInt(endTime),"yyyy-MM-dd HH:mm:ss");
}else{
endTime = "未设置";
}
sb.append("<div>").append(paramMap.get("beginChannelOrderTime")).append(":").append( beginTime).append("-").append(endTime).append("</div>");
map.remove(beginTimeKey);
map.remove(endTimeKey);
}
}
private List<ChannelGroupRspBO> toRspBOList(List<ChannelGroup> channelGroupList) {
logger.info("enter toRspBOList. param channelGroupList={}", channelGroupList);
List<ChannelGroupRspBO> list = Lists.newArrayList();
... ... @@ -164,7 +253,6 @@ public class ChannelGroupServiceImpl implements ChannelGroupService {
return list;
}
for (int i = 0; i < channelGroupList.size(); i++) {
ChannelGroup channelGroup = channelGroupList.get(i);
ChannelGroupRspBO channelGroupRspBO = new ChannelGroupRspBO();
... ...
... ... @@ -35,6 +35,8 @@
<value>/tencentMkt/TencentMktController/validRegCodeAndSendCode</value>
<value>/channel/queryChannelGroupList</value>
<value>/channel/sendMessage</value>
<value>/channel/test</value>
<value>/channel/getCondition</value>
</list>
</property>
<property name="excludeMethods">
... ...
... ... @@ -18,4 +18,6 @@ public interface IChannelGroupConditionDAO {
int updateByPrimaryKey(ChannelGroupCondition record);
List<ChannelGroupCondition> selectByGroupId(Integer groupId);
List<ChannelGroupCondition> selectByGroupIds(List<Integer> list);
}
\ No newline at end of file
... ...
... ... @@ -8,7 +8,7 @@
<result column="value" property="value" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, group_id, 'key', value
id, group_id, key, value
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -22,6 +22,14 @@
from channel_group_condition
where group_id = #{groupId,jdbcType=INTEGER}
</select>
<select id="selectByGroupIds" resultMap="BaseResultMap">
select *
from channel_group_condition
where group_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from channel_group_condition
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -108,7 +108,9 @@
width: 170,
align: "center",
formatter: function (value, rowData, rowIndex) {
return "条件筛选";
// return "<a href='#' class='easyui-tooltip' title='泛渠道来源:淘宝B店\r\nuid:171717171'>条件筛选</a>";
// return "<span class='dd' >条件筛选</span>";
return '<span id="condition-'+rowIndex+'" >条件筛选</span>';
}
},{
title: "创建时间",
... ... @@ -163,12 +165,15 @@
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function (data) {
getCondition(data);
$(this).myDatagrid("getPanel").find("a[role='send']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
sendMessage($(this).attr("dataId"));
}
});
}
});
... ... @@ -229,7 +234,6 @@
});
//新增或修改视频
function sendMessage(id) {
var div = $("<div>").appendTo($(document.body));
var title = "发送短信";
... ... @@ -285,6 +289,37 @@
}
function addTooltip(content,tootipId){
//添加相应的tooltip
$('#'+tootipId).tooltip({
position: 'right',
content: content,
onShow: function(){
$(this).tooltip('tip').css({
backgroundColor: '#666',
borderColor: '#666'
});
}
});
}
function getCondition(data1){
var ids = [];
for ( var i = 0; i < data1.rows.length; i++) {
ids.push(data1.rows[i].id);
}
$.post(contextPath + "/channel/getCondition", {ids:"2,3"},function (data) {
var content = data.data;
for ( var i = 0; i < data1.rows.length; i++) {
var id = data1.rows[i].id;
console.info(content[id]);
addTooltip(content[id],'condition-' + i);
}
});
}
</script>
</body>
... ...