|
@@ -1,16 +1,16 @@
|
|
|
package com.goafanti.admin.service.impl;
|
|
package com.goafanti.admin.service.impl;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
-import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
-import java.util.Map.Entry;
|
|
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import com.goafanti.admin.service.MessageService;
|
|
import com.goafanti.admin.service.MessageService;
|
|
|
import com.goafanti.common.dao.MessageFromSystemMapper;
|
|
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.common.model.MessageProducer;
|
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
|
import com.goafanti.message.bo.MessageBo;
|
|
import com.goafanti.message.bo.MessageBo;
|
|
|
|
|
+import com.goafanti.message.enums.ConsumerType;
|
|
|
|
|
+import com.goafanti.message.enums.RecommendType;
|
|
|
import com.goafanti.message.enums.SubjectType;
|
|
import com.goafanti.message.enums.SubjectType;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -30,70 +32,94 @@ public class MessageServiceImpl implements MessageService{
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MessageProducerMapper messageProducerMapper;
|
|
private MessageProducerMapper messageProducerMapper;
|
|
|
@Override
|
|
@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 = "";
|
|
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 "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@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 "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@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) {
|
|
public int insertSystemMessage(Map<Integer, String> selectMap, String title, String body, Integer subject,Integer type,Date createTime) {
|
|
|
MessageFromSystem mfs = new MessageFromSystem();
|
|
MessageFromSystem mfs = new MessageFromSystem();
|
|
|
mfs.setId(UUID.randomUUID().toString());
|
|
mfs.setId(UUID.randomUUID().toString());
|
|
@@ -105,13 +131,13 @@ public class MessageServiceImpl implements MessageService{
|
|
|
if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
|
|
if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
|
|
|
Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
|
|
Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
|
|
|
mfs.setCreater(admin.getName());
|
|
mfs.setCreater(admin.getName());
|
|
|
- mfs.setCreater(admin.getId());
|
|
|
|
|
|
|
+ mfs.setProducerId(admin.getId());
|
|
|
}
|
|
}
|
|
|
messageFromSystemMapper.insert(mfs);
|
|
messageFromSystemMapper.insert(mfs);
|
|
|
List<MessageProducer> target = new ArrayList<MessageProducer>();
|
|
List<MessageProducer> target = new ArrayList<MessageProducer>();
|
|
|
String[] cids;
|
|
String[] cids;
|
|
|
if(subject == SubjectType.KE_HU.getTypeCode()){
|
|
if(subject == SubjectType.KE_HU.getTypeCode()){
|
|
|
- cids = selectSendUser(selectMap).split(",");
|
|
|
|
|
|
|
+ cids = selectSendUser(selectMap,type).split(",");
|
|
|
MessageProducer mp;
|
|
MessageProducer mp;
|
|
|
for(String cid : cids){
|
|
for(String cid : cids){
|
|
|
mp = new MessageProducer();
|
|
mp = new MessageProducer();
|
|
@@ -121,7 +147,7 @@ public class MessageServiceImpl implements MessageService{
|
|
|
}
|
|
}
|
|
|
insertBatchProducer(target);
|
|
insertBatchProducer(target);
|
|
|
}else if(subject == SubjectType.YUN_YING.getTypeCode()){
|
|
}else if(subject == SubjectType.YUN_YING.getTypeCode()){
|
|
|
- cids = selectSendAdmin(selectMap).split(",");
|
|
|
|
|
|
|
+ cids = selectSendAdmin(selectMap,type).split(",");
|
|
|
MessageProducer mp;
|
|
MessageProducer mp;
|
|
|
for(String cid : cids){
|
|
for(String cid : cids){
|
|
|
mp = new MessageProducer();
|
|
mp = new MessageProducer();
|
|
@@ -133,7 +159,56 @@ public class MessageServiceImpl implements MessageService{
|
|
|
}
|
|
}
|
|
|
return 1;
|
|
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
|
|
@Override
|
|
|
public List<MessageBo> selectSendMessage(String uid) {
|
|
public List<MessageBo> selectSendMessage(String uid) {
|
|
|
return messageFromSystemMapper.selectSendMessage(uid);
|
|
return messageFromSystemMapper.selectSendMessage(uid);
|
|
@@ -166,4 +241,5 @@ public class MessageServiceImpl implements MessageService{
|
|
|
public int updateMessageConsumer(String messageId) {
|
|
public int updateMessageConsumer(String messageId) {
|
|
|
return messageFromSystemMapper.updateMessageConsumer(messageId, TokenManager.getUserId() , new Date());
|
|
return messageFromSystemMapper.updateMessageConsumer(messageId, TokenManager.getUserId() , new Date());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|