Explorar el Código

消息推送后台

wanghui hace 8 años
padre
commit
b71eb7d433

+ 96 - 14
src/main/java/com/goafanti/admin/controller/AdminMessageController.java

@@ -2,6 +2,7 @@ package com.goafanti.admin.controller;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -17,6 +18,9 @@ import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.message.enums.ConsumerType;
+import com.goafanti.message.enums.RecommendType;
+import com.goafanti.message.enums.SubjectType;
+import com.google.gson.JsonObject;
 
 /**
  *  消息推送
@@ -28,6 +32,19 @@ import com.goafanti.message.enums.ConsumerType;
 public class AdminMessageController extends CertifyApiController{
 	@Autowired
 	private MessageService messageServiceImpl;
+	
+	/**
+	 * 进入创建系统消息
+	 */
+	@RequestMapping(value = "/toCreateSystemMessage", method = RequestMethod.GET)
+	public Result toCreateSystemMessage(){
+		Result res = new Result();
+		SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
+		JsonObject jsonObject = new JsonObject();
+		jsonObject.addProperty("createTime", format.format(new Date()));
+		res.setData(jsonObject);
+		return res;
+	}
 	/**
 	 * 
 	 * @param companyIds 公司集
@@ -41,10 +58,10 @@ public class AdminMessageController extends CertifyApiController{
 	 * @throws ParseException 
 	 */
 	@RequestMapping(value = "/createSystemMessage", method = RequestMethod.POST)
-	public Result createSystemMessage(String userIds,String companyIds,String societyTags,String provinceIds,String cityIds,String areaIds,String roles,
-			String title,String body,Integer subject,Integer type,String createTime) throws ParseException{
+	public Result createSystemMessage(String userIds,String adminIds,String companyIds,String societyTags,String provinceIds,String cityIds,String areaIds,
+			String roles,String industryIds,String title,String body,Integer subject,Integer targetType,String createTime) throws ParseException{
 		Result res = new Result();
-		if(null == type){
+		if(null == targetType){
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定人员类型"));
 			return res;
 		}
@@ -56,24 +73,89 @@ public class AdminMessageController extends CertifyApiController{
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "消息是的标题和内容不能为空"));
 			return res;
 		}
-		Map<Integer,String> selectMap = new HashMap<Integer, String>();
-		if(type == ConsumerType.SAN_HU.getTypeCode()) selectMap.put(type, userIds);
-		if(type == ConsumerType.SOCIETY_TAG.getTypeCode()) selectMap.put(type, societyTags);
-		if(type == ConsumerType.PROVINCE.getTypeCode()) selectMap.put(type, provinceIds);
-		if(type == ConsumerType.CITY.getTypeCode()) selectMap.put(type, cityIds);
-		if(type == ConsumerType.AREA.getTypeCode()) selectMap.put(type, areaIds);
-		if(type == ConsumerType.COMPANY.getTypeCode()) selectMap.put(type, companyIds);
-		if(type == ConsumerType.ROLE.getTypeCode()) selectMap.put(type, roles);
-		if(StringUtils.isBlank(selectMap.get(type))){
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "指定人员不能为空"));
+		Map<Integer,String> targetMap = new HashMap<Integer, String>();
+		if(targetType == ConsumerType.CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, userIds);
+		if(targetType == ConsumerType.USER_RETAIL.getTypeCode()) targetMap.put(targetType, userIds);
+		if(targetType == ConsumerType.SOCIETY_TAG.getTypeCode()) targetMap.put(targetType, societyTags);
+		if(targetType == ConsumerType.LOCATION.getTypeCode()){
+			 targetMap.put(targetType, ConsumerType.LOCATION.getTypeName());
+			 targetMap.put(ConsumerType.LOCATION_PROVINCE.getTypeCode(), provinceIds);
+			 targetMap.put(ConsumerType.LOCATION_CITY.getTypeCode(), cityIds);
+			 targetMap.put(ConsumerType.LOCATION_AREA.getTypeCode(), areaIds);
+		}
+		if(targetType == ConsumerType.COMPANY.getTypeCode()) targetMap.put(targetType, companyIds);
+		if(targetType == ConsumerType.ROLE.getTypeCode()) targetMap.put(targetType, roles);
+		if(targetType == ConsumerType.INDUSTRY.getTypeCode()) targetMap.put(targetType, industryIds);
+		if(StringUtils.isBlank(targetMap.get(targetType))){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须选定目标群体"));
 			return res;
 		}
 		SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
-		messageServiceImpl.insertSystemMessage(selectMap, title, body, subject,type,format.parse(createTime));
+		messageServiceImpl.insertSystemMessage(targetMap, title, body, subject,targetType,format.parse(createTime));
 		return res;
 	}
 	
 	/**
+	 * 
+	 * @param projectIds 项目
+	 * @param personalAchievementIds 个人成果
+	 * @param organizationAchievementIds 组织成果
+	 * @param personalDemandIds 个人需求
+	 * @param organizationDemandIds 组织需求
+	 * @param userIds 专家
+	 * @param newsIds 政策
+	 * @param sourceType 资源类型
+	 * @param userIds 用户类型
+	 * @param societyTags 社会属性
+	 * @param provinceIds 省
+	 * @param cityIds 市
+	 * @param areaIds 区
+	 * @param targetType 目标类型
+	 * @return
+	 */
+	public Result createRecommendMessage(String projectIds,String personalAchievementIds,String organizationAchievementIds,
+			String personalDemandIds,String organizationDemandIds, String expertIds, String newsIds,Integer sourceType,
+			String userIds,String societyTags,String provinceIds,String cityIds,String areaIds,String industryIds,Integer targetType){
+		Result res = new Result();
+		if(null == sourceType){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定推荐类型"));
+			return res;
+		}
+		if(null == targetType){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"必须制定目标群体"));
+			return res;
+		}
+		Map<Integer,String> sourceMap = new HashMap<Integer, String>();
+		if(sourceType == RecommendType.TECH_SERVICE.getTypeCode()) sourceMap.put(targetType, projectIds);
+		if(sourceType == RecommendType.PERSON_ACHIEVEMENT.getTypeCode()) sourceMap.put(targetType, personalAchievementIds);
+		if(sourceType == RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode()) sourceMap.put(targetType, organizationAchievementIds);
+		if(sourceType == RecommendType.PERSONAL_DEMAND.getTypeCode()) sourceMap.put(targetType, personalDemandIds);
+		if(sourceType == RecommendType.ORGANIZATION_DEMAND.getTypeCode()) sourceMap.put(targetType, organizationDemandIds);
+		if(sourceType == RecommendType.EXPERT.getTypeCode()) sourceMap.put(targetType, expertIds);
+		if(sourceType == RecommendType.NEWS.getTypeCode()) sourceMap.put(targetType, newsIds);
+		if(StringUtils.isBlank(sourceMap.get(targetType))){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须选定推荐内容"));
+			return res;
+		}
+		Map<Integer,String> targetMap = new HashMap<Integer, String>();
+		if(targetType == ConsumerType.CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, userIds);
+		if(targetType == ConsumerType.SOCIETY_TAG.getTypeCode()) targetMap.put(targetType, societyTags);
+		if(targetType == ConsumerType.LOCATION.getTypeCode()){
+			 targetMap.put(targetType, ConsumerType.LOCATION.getTypeName());
+			 targetMap.put(ConsumerType.LOCATION_PROVINCE.getTypeCode(), provinceIds);
+			 targetMap.put(ConsumerType.LOCATION_CITY.getTypeCode(), cityIds);
+			 targetMap.put(ConsumerType.LOCATION_AREA.getTypeCode(), areaIds);
+		}
+		if(targetType == ConsumerType.INDUSTRY.getTypeCode()) targetMap.put(targetType, industryIds);
+		if(StringUtils.isBlank(targetMap.get(targetType))){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须制定目标群体"));
+			return res;
+		}
+		messageServiceImpl.insertRecommendMessage(sourceMap,sourceType,targetMap,targetType,SubjectType.TUI_JIAN.getTypeCode());
+		return res;
+		
+	}
+	/**
 	 * 同步绑定账号
 	 * @param uuid
 	 * @param registrationId

+ 25 - 6
src/main/java/com/goafanti/admin/service/MessageService.java

@@ -5,6 +5,7 @@ import java.util.List;
 import java.util.Map;
 
 import com.goafanti.common.model.MessageConsumer;
+import com.goafanti.common.model.MessageFromSystem;
 import com.goafanti.common.model.MessageProducer;
 import com.goafanti.message.bo.MessageBo;
 
@@ -15,14 +16,23 @@ public interface MessageService {
 	 * @param subject
 	 * @return
 	 */
-	String selectSendUser(Map<Integer,String> selectMap);
+	String selectSendUser(Map<Integer,String> selectMap,Integer type);
 	/**
 	 * 查询推送运营人员
 	 * @param selectMap
 	 * @param subject
 	 * @return
 	 */
-	String selectSendAdmin(Map<Integer,String> selectMap);
+	String selectSendAdmin(Map<Integer,String> selectMap,Integer type);
+	
+	/**
+	 * 查询推荐内容
+	 * @param selectMap
+	 * @param type
+	 * @return
+	 */
+	List<MessageFromSystem> selectRecommend(Map<Integer, String> selectMap,Integer type);
+	
 	/**
 	 * 
 	 * @param selectMap 
@@ -31,7 +41,7 @@ public interface MessageService {
 	 * @param subject
 	 * @return
 	 */
-	int insertSystemMessage(Map<Integer, String> selectMap, String title, String body, Integer subject,Integer type,Date createTime);
+	int insertSystemMessage(Map<Integer, String> targetMap, String title, String body, Integer subject,Integer targetType,Date createTime);
 	
 	/**
 	 * 查询用户的未发消息
@@ -41,21 +51,21 @@ public interface MessageService {
 	List<MessageBo> selectSendMessage(String uid);
 	
 	/**
-	 * 更新消息生产
+	 * 更新消息表
 	 * @param producerList
 	 * @return
 	 */
 	public int updateMessageProducer(List<MessageProducer> producerList);
 	
 	/**
-	 * 批量插入生产者 
+	 * 批量插生产表
 	 * @param target
 	 * @return
 	 */
 	public int insertBatchProducer(List<MessageProducer> target);
 	
 	/**
-	 * 批量插入
+	 * 批量插入消费表
 	 * @param target
 	 * @return
 	 */
@@ -76,4 +86,13 @@ public interface MessageService {
 	 * @return
 	 */
 	public int updateMessageConsumer(String messageId);
+	
+	/**
+	 * 生成推荐消息
+	 * @param selectMap
+	 * @param type
+	 * @param subject
+	 * @return
+	 */
+	public int insertRecommendMessage(Map<Integer, String> sourceMap, Integer sourceType, Map<Integer, String> targetMap,Integer targetType,Integer subject);
 }

+ 133 - 57
src/main/java/com/goafanti/admin/service/impl/MessageServiceImpl.java

@@ -1,16 +1,16 @@
 package com.goafanti.admin.service.impl;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.UUID;
 
 import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.goafanti.admin.service.MessageService;
 import com.goafanti.common.dao.MessageFromSystemMapper;
@@ -21,6 +21,8 @@ import com.goafanti.common.model.MessageFromSystem;
 import com.goafanti.common.model.MessageProducer;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.message.bo.MessageBo;
+import com.goafanti.message.enums.ConsumerType;
+import com.goafanti.message.enums.RecommendType;
 import com.goafanti.message.enums.SubjectType;
 
 @Service
@@ -30,70 +32,94 @@ public class MessageServiceImpl implements MessageService{
 	@Autowired
 	private MessageProducerMapper messageProducerMapper;
 	@Override
-	public String selectSendUser(Map<Integer, String> selectMap) {
-		Iterator<Entry<Integer, String>> iterator= selectMap.entrySet().iterator();
-		if(iterator.hasNext()){
-			Entry<Integer, String> entry = iterator.next();
-			Integer key = entry.getKey();
-			String value = entry.getValue();
-			if(0 == key) return value;
+	public String selectSendUser(Map<Integer, String> selectMap,Integer type) {
+		if(selectMap.containsKey(ConsumerType.CUSTOMER_RETAIL.getTypeCode())){ //客户散户
+			return selectMap.get(ConsumerType.CUSTOMER_RETAIL.getTypeCode());
+		}else if(selectMap.containsKey(ConsumerType.USER_RETAIL.getTypeCode())){
+			return selectMap.get(ConsumerType.USER_RETAIL.getTypeCode()); //用户散户
+		}else if(selectMap.containsKey(ConsumerType.SOCIETY_TAG.getTypeCode())){ // 社会标签
+			String sql  = "select group_concat(id) from user where";
+			StringBuffer tmp = new StringBuffer();
+			String[] societys = selectMap.get(ConsumerType.SOCIETY_TAG.getTypeCode()).split(",");
+			for(String s:societys){
+				tmp.append(" or society_tag like "+s);
+			}
+			if(tmp.length()>0) sql = sql + "(" +tmp.substring(3) + ")" +" and a.source=0 and status != 2";
+			return messageFromSystemMapper.selectSendTarget(sql);
+		}else if(selectMap.containsKey(ConsumerType.LOCATION.getTypeCode())){ //用户地区
 			String sql = "";
-			switch (key) {
-			case 0:
-				break;
-			case 1: //社会属性
-				sql = "select group_concat(id) from user where";
-				StringBuffer tmp = new StringBuffer();
-				String[] societys = value.split(",");
-				for(String s:societys){
-					tmp.append("or society_tag like "+s);
+			String result = "";
+			if(selectMap.containsKey(ConsumerType.LOCATION_PROVINCE.getTypeCode())){ //省
+				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where a.source=0 and b.province in (" + selectMap.get(ConsumerType.LOCATION_PROVINCE.getTypeCode()) + ")";
+				result += ","+messageFromSystemMapper.selectSendTarget(sql);
+			}
+			if(selectMap.containsKey(ConsumerType.LOCATION_CITY.getTypeCode())){ //市
+				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where a.source=0 and b.city in (" + selectMap.get(ConsumerType.LOCATION_CITY.getTypeCode()) + ") and a.status != 2";
+				result += ","+messageFromSystemMapper.selectSendTarget(sql);
+			}
+			if(selectMap.containsKey(ConsumerType.LOCATION_AREA.getTypeCode())){ //区
+				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where a.source=0 and b.area in (" + selectMap.get(ConsumerType.LOCATION_AREA.getTypeCode()) + ") and a.status != 2";
+				result += ","+messageFromSystemMapper.selectSendTarget(sql);
+			}
+			if(!result.equals("")){
+				String data[] = result.substring(1).split(",");
+				List<String> list = new ArrayList<String>();
+				boolean flag;
+				for(int i=0; i< data.length;i++){
+					flag = false;
+					for(int j=0; j<list.size(); j++){
+						if(data[i].equals(list.get(j))){
+							flag = true;
+							break;
+						}
+					}
+					if(!flag) list.add(data[i]);
 				}
-				if(tmp.length()>0) sql = sql + "(" +tmp.substring(3) + ")" +"  and status != 2";
-				break;
-			case 2: //省份
-				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where b.province in (" + value + ") and a.status != 2";
-				break;
-			case 3: //城市
-				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where b.city in (" + value + ") and a.status != 2";
-				break;
-			case 4: //区域
-				sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where b.area in (" + value + ") and a.status != 2";
-				break;
-			default:
-				break;
+				String[] tmp = (String[])list.toArray(new String[list.size()]);
+				return Arrays.toString(tmp);
 			}
-			if(!sql.equals("")) return messageFromSystemMapper.selectSendTarget(sql);
+		}else if(selectMap.containsKey(ConsumerType.INDUSTRY.getTypeCode())){ //行业
+			String sql = "select group_concat(a.id) from user a left join user_identity b on a.id = b.uid where a.source=0 and b.industry in (" + selectMap.get(ConsumerType.INDUSTRY.getTypeCode()) + ") and a.status != 2";
+			return messageFromSystemMapper.selectSendTarget(sql);
 		}
 		return "";
 	}
 
 	@Override
-	public String selectSendAdmin(Map<Integer, String> selectMap) {
-		Iterator<Entry<Integer, String>> iterator= selectMap.entrySet().iterator();
-		if(iterator.hasNext()){
-			Entry<Integer, String> entry = iterator.next();
-			Integer key = entry.getKey();
-			String value = entry.getValue();
-			if(0 == key) return value;
-			String sql = "";
-			switch (key) {
-			case 0:
-				break;
-			case 5: //分公司
-				sql = "select group_concat(id) from admin where department_id in ("+ value + ")";
-				break;
-			case 6: // 角色
-				sql = "select group_concat(id) from admin a left join user_role b on a.id = b.uid where b.id in (" + value + ")";
-				break;
-			default:
-				break;
-			}
-			if(!sql.equals("")) return messageFromSystemMapper.selectSendTarget(sql);
+	public String selectSendAdmin(Map<Integer, String> selectMap,Integer type) {
+		String sql = "";
+		if(selectMap.containsKey(ConsumerType.COMPANY.getTypeCode())){
+			sql = "select group_concat(id) from admin where department_id in ("+ selectMap.get(ConsumerType.COMPANY.getTypeCode()) + ")";
+		}else if(selectMap.containsKey(ConsumerType.ROLE.getTypeCode())){
+			sql = "select group_concat(id) from admin a left join user_role b on a.id = b.uid where b.id in (" + selectMap.get(ConsumerType.ROLE.getTypeCode()) + ")";
 		}
+		if(!sql.equals("")) return messageFromSystemMapper.selectSendTarget(sql);
 		return "";
 	}
 
 	@Override
+	public List<MessageFromSystem> selectRecommend(Map<Integer, String> selectMap,Integer type){
+		String sql = "";
+		if(selectMap.containsKey(RecommendType.TECH_SERVICE.getTypeCode())){
+			sql = "select project_name as title,project_des as body,id as resourceId from tech_project where id in (" + selectMap.get(RecommendType.TECH_SERVICE.getTypeCode()) + ")";
+		}else if(selectMap.containsKey(RecommendType.PERSON_ACHIEVEMENT.getTypeCode())){
+			sql = "select name as title,summary as body,id as resourceIdfrom achievement  where id in (" + selectMap.get(RecommendType.PERSON_ACHIEVEMENT.getTypeCode())  +")";
+		}else if(selectMap.containsKey(RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode())){
+			sql = "select name as title,summary as body,id as resourceId from achievement  where id in (" + selectMap.get(RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode())  +")";
+		}else if(selectMap.containsKey(RecommendType.PERSONAL_DEMAND.getTypeCode())){
+			sql = "select name as title,problem_des as body,id as resourceId from demand where id in (" + selectMap.get(RecommendType.PERSONAL_DEMAND.getTypeCode()) +")";
+		}else if(selectMap.containsKey(RecommendType.ORGANIZATION_DEMAND.getTypeCode())){
+			sql = "select name as title,problem_des as body,id as resourceId from demand where id in (" + selectMap.get(RecommendType.ORGANIZATION_DEMAND.getTypeCode()) +")";
+		}else if(selectMap.containsKey(RecommendType.EXPERT.getTypeCode())){
+			sql = "select nickname as title ,introduction as body,id as resourceId from user where id in("+ selectMap.get(RecommendType.EXPERT.getTypeCode()) +")";
+		}else if(selectMap.containsKey(RecommendType.NEWS.getTypeCode())){
+			sql = "select title,summary as body,id as resourceId from news where id in("+ selectMap.get(RecommendType.NEWS.getTypeCode()) +")";
+		}
+		if(!sql.equals("")) return messageFromSystemMapper.selectRecommendTarget(sql);
+		return null;
+	}
+	
+	@Override
 	public int insertSystemMessage(Map<Integer, String> selectMap, String title, String body, Integer subject,Integer type,Date createTime) {
 		MessageFromSystem mfs = new MessageFromSystem();
 		mfs.setId(UUID.randomUUID().toString());
@@ -105,13 +131,13 @@ public class MessageServiceImpl implements MessageService{
 		if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
 			Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
 			mfs.setCreater(admin.getName());
-			mfs.setCreater(admin.getId());
+			mfs.setProducerId(admin.getId());
 		}
 		messageFromSystemMapper.insert(mfs);
 		List<MessageProducer> target = new ArrayList<MessageProducer>();
 		String[] cids;
 		if(subject == SubjectType.KE_HU.getTypeCode()){
-			cids = selectSendUser(selectMap).split(",");
+			cids = selectSendUser(selectMap,type).split(",");
 			MessageProducer mp;
 			for(String cid : cids){
 				mp = new MessageProducer();
@@ -121,7 +147,7 @@ public class MessageServiceImpl implements MessageService{
 			}
 			insertBatchProducer(target);
 		}else if(subject == SubjectType.YUN_YING.getTypeCode()){
-			cids = selectSendAdmin(selectMap).split(",");
+			cids = selectSendAdmin(selectMap,type).split(",");
 			MessageProducer mp;
 			for(String cid : cids){
 				mp = new MessageProducer();
@@ -133,7 +159,56 @@ public class MessageServiceImpl implements MessageService{
 		}
 		return 1;
 	}
-
+	
+	@Override
+	@Transactional
+	public int insertRecommendMessage(Map<Integer, String> sourceMap, Integer sourceType, Map<Integer, String> targetMap,Integer targetType,Integer subject) {
+		List<MessageFromSystem> mfsList = selectRecommend(sourceMap, sourceType);
+		List<MessageProducer> producerTarget = new ArrayList<MessageProducer>();
+		List<MessageFromSystem> messageTarget = new ArrayList<MessageFromSystem>();
+		if(mfsList != null && mfsList.size()>0){
+			MessageFromSystem message = new MessageFromSystem();
+			String messageId = "";
+			Date createTime = new Date();
+			message.setCreateTime(createTime);
+			message.setId(messageId);
+			message.setSubject(subject);
+			message.setConsumerType(targetType);
+			message.setResourceType(sourceType);
+			if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
+				Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
+				message.setCreater(admin.getName());
+				message.setProducerId(admin.getId());
+			}
+			for(MessageFromSystem mfs : mfsList){
+				messageId = UUID.randomUUID().toString();
+				message.setTitle(mfs.getTitle());
+				message.setBody(mfs.getBody());
+				message.setResourceId(mfs.getResourceId());
+				messageTarget.add(mfs);
+				//插入消息推送表
+				if(subject == SubjectType.KE_HU.getTypeCode()){ //只推客户
+					MessageProducer mp = null;
+					String[] cids = selectSendUser(targetMap,targetType).split(",");
+					for(String cid : cids){
+						mp = new MessageProducer();
+						mp.setId(UUID.randomUUID().toString());
+						mp.setConsumerId(cid);
+						mp.setCreateTime(createTime);
+						mp.setMessageId(messageId);
+						producerTarget.add(mp);
+					}
+				}
+				
+			}
+			//批量插入
+			if(messageTarget.size()>0) messageFromSystemMapper.insertBatchMessage(messageTarget);
+			if(producerTarget.size()>0) messageFromSystemMapper.insertBatchProducer(producerTarget);
+			return 1;
+		}
+		return 0;
+	}
+	
 	@Override
 	public List<MessageBo> selectSendMessage(String uid) {
 		return messageFromSystemMapper.selectSendMessage(uid);
@@ -166,4 +241,5 @@ public class MessageServiceImpl implements MessageService{
 	public int updateMessageConsumer(String messageId) {
 		return messageFromSystemMapper.updateMessageConsumer(messageId, TokenManager.getUserId() , new Date());
 	}
+
 }

+ 14 - 0
src/main/java/com/goafanti/common/dao/MessageFromSystemMapper.java

@@ -109,6 +109,13 @@ public interface MessageFromSystemMapper {
     /**
      * 
      * @param target
+     * @return
+     */
+    int insertBatchMessage(List<MessageFromSystem> target);
+    
+    /**
+     * 
+     * @param target
      */
 	int insertBatchProducer(List<MessageProducer> target);
 	
@@ -145,5 +152,12 @@ public interface MessageFromSystemMapper {
 	 * @return
 	 */
 	int updateMessageConsumer(@Param("messageId")String messageId, @Param("uid")String uid,@Param("readTime")Date readTime);
+
+	/**
+	 * 查询推荐目标
+	 * @param sql
+	 * @return
+	 */
+	List<MessageFromSystem> selectRecommendTarget(@Param("sql")String sql);
 	
 }

+ 10 - 0
src/main/java/com/goafanti/common/mapper/MessageFromSystemMapper.xml

@@ -426,6 +426,7 @@
 			and a.send_time is null
 			and a.consumer_id = #{uid,jdbcType=VARCHAR};
    </select>
+   
    <update id="updateJpushEasemobAccount" parameterType="java.lang.String">
    		update jpush_easemob_account
    		<set>
@@ -441,10 +442,19 @@
    			where uid = #{uid,jdbcType=VARCHAR}
    		</set>
    </update>
+   
    <update id="updateMessageConsumer">
    	update message_consumer
    	<set>
    		read_time = #{readTime,jdbcType=TIMESTAMP} where uid = #{uid,jdbcType=VARCHAR} and message_id = #{messageId,jdbcType=VARCHAR}
    	</set>
    </update>
+   
+   <select id="selectSendTarget" parameterType="java.lang.String" resultType="java.lang.String">
+   		#{sql,jdbcType=VARCHAR}
+   </select>
+   
+   <select id="selectRecommendTarget" parameterType="java.lang.String" resultType="com.goafanti.common.model.MessageFromSystem">
+   	 	#{sql,jdbcType=VARCHAR}
+   </select>
 </mapper>

+ 12 - 9
src/main/java/com/goafanti/message/enums/ConsumerType.java

@@ -4,20 +4,23 @@ import java.util.HashMap;
 import java.util.Map;
 
 public enum ConsumerType {
-	/** 散户 **/
-	SAN_HU(0,"SAN_HU"),
+	/** 客户散户 **/
+	CUSTOMER_RETAIL(0,"CUSTOMER_RETAIL"),
 	/** 社会标签 **/
 	SOCIETY_TAG(1,"SOCIETY_TAG"),
-	/** 省份 **/
-	PROVINCE(2,"PROVINCE"),
-	/** 城市 **/
-	CITY(3,"CITY"),
-	/** 区域 **/
-	AREA(4,"AREA"),
+	/** 省市区 **/
+	LOCATION(2,"LOCATION"),
+	LOCATION_PROVINCE(21,"PROVINCE"),
+	LOCATION_CITY(22,"CITY"),
+	LOCATION_AREA(23,"AREA"),
 	/** 公司 **/
-	COMPANY(5,"COMPANY"),
+	COMPANY(3,"COMPANY"),
 	/** 角色 **/
 	ROLE(6,"ROLE"),
+	/** 用户散户 **/
+	USER_RETAIL(7,"USER_RETAIL"),
+	/** 行业 **/
+	INDUSTRY(8,"INDUSTRY"),
 	/** 没有定义 **/
 	NO_DEFINITION(null,"NO_DEFINITION");
 	private ConsumerType(Integer typeCode, String typeName) {

+ 63 - 0
src/main/java/com/goafanti/message/enums/RecommendType.java

@@ -0,0 +1,63 @@
+package com.goafanti.message.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum RecommendType {
+	/** 科技服务 **/
+	TECH_SERVICE(0,"TECH_SERVICE"),
+	/** 个人成果 **/
+	PERSON_ACHIEVEMENT(1,"PERSON_ACHIEVEMENT"),
+	/** 组织成果 **/
+	ORGANIZATION_ACHIEVEMENT(2,"ORGANIZATION_ACHIEVEMENT"),
+	/** 个人需求 **/
+	PERSONAL_DEMAND(3,"PERSONAL_DEMAND"),
+	/** 个人需求 **/
+	ORGANIZATION_DEMAND(4,"ORGANIZATION_DEMAND"),
+	/** 专家 **/
+	EXPERT(5,"EXPERT"),
+	/** 政策 **/
+	NEWS(6,"NEWS"),
+	/** 未定义 **/
+	NO_DEFINITION(null,"NO_DEFINITION");
+	private Integer	typeCode;
+
+	private String	typeName;
+
+	private RecommendType(Integer typeCode,String typeName){
+		this.typeCode = typeCode;
+		this.typeName = typeName;
+	}
+	public Integer getTypeCode() {
+		return typeCode;
+	}
+
+	public void setTypeCode(Integer typeCode) {
+		this.typeCode = typeCode;
+	}
+
+	public String getTypeName() {
+		return typeName;
+	}
+
+	public void setTypeName(String typeName) {
+		this.typeName = typeName;
+	}
+
+	public RecommendType getField(Integer code){
+		if(recommends.containsKey(code)) return recommends.get(code);
+		return NO_DEFINITION;
+	}
+	
+	public static Map<Integer,RecommendType> recommends = new HashMap<Integer, RecommendType>();
+	
+	static {
+		for(RecommendType value : RecommendType.values()){
+			recommends.put(value.getTypeCode(), value);
+		}
+	}
+	
+	public static boolean containsType(int code){
+		return recommends.containsKey(code);
+	}
+}

+ 1 - 1
src/main/java/com/goafanti/message/enums/SubjectType.java

@@ -39,7 +39,7 @@ public enum  SubjectType {
 
 	public SubjectType getField(Integer code){
 		if(subjects.containsKey(code)) return subjects.get(code);
-		return YUN_YING;
+		return NO_DEFINITION;
 	}
 	
 	public static Map<Integer,SubjectType> subjects = new HashMap<Integer, SubjectType>();