Browse Source

APP消息推送接口联调12.22

Michael 8 years ago
parent
commit
9d1fff2eca

+ 3 - 2
src/main/java/com/goafanti/admin/controller/AdminMessageController.java

@@ -152,7 +152,7 @@ public class AdminMessageController extends CertifyApiController{
 		if(sourceType == RecommendType.ORGANIZATION_DEMAND.getTypeCode()) sourceMap.put(sourceType, organizationDemandIds);
 		if(sourceType == RecommendType.EXPERT.getTypeCode()) sourceMap.put(sourceType, expertIds);
 		if(sourceType == RecommendType.NEWS.getTypeCode()) sourceMap.put(sourceType, newsIds);
-		if(StringUtils.isBlank(sourceMap.get(targetType))){
+		if(StringUtils.isBlank(sourceMap.get(sourceType))){
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须选定推荐内容"));
 			return res;
 		}
@@ -253,7 +253,7 @@ public class AdminMessageController extends CertifyApiController{
 		// 读取消息详情
 		MessageFromSystem mfs = messageServiceImpl.selectSystemMessageDetail(messageId);
 		MessageListBo bo = new MessageListBo();
-		bo.setCreateTime(bo.getCreateTime() == null ? ""
+		bo.setCreateTime(mfs.getCreateTime() == null ? ""
 				: DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
 		bo.setResourceType(String.valueOf(mfs.getResourceType()));
 		bo.setSubject(String.valueOf(mfs.getSubject()));
@@ -261,6 +261,7 @@ public class AdminMessageController extends CertifyApiController{
 		bo.setTitle(mfs.getTitle());
 		bo.setBody(mfs.getBody());
 		bo.setResourceId(mfs.getResourceId());
+		bo.setConsumerType(""+mfs.getConsumerType());
 		res.setData(bo);
 		return res;
 	}

+ 2 - 2
src/main/java/com/goafanti/app/controller/AppApiController.java

@@ -143,13 +143,13 @@ public class AppApiController extends BaseApiController {
 	private Result readMessage(String messageId){
 		Result res = new Result();
 		if(StringUtils.isBlank(messageId)){
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "消息编号为空"));
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号为空"));
 			return res;
 		}
 		//读取消息详情
 		MessageFromSystem mfs = messageServiceImpl.selectSystemMessageDetail(messageId);
 		MessageListBo bo = new MessageListBo();
-		bo.setCreateTime(bo.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
+		bo.setCreateTime(mfs.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
 		bo.setResourceType(String.valueOf(mfs.getResourceType()));
 		bo.setSubject(String.valueOf(mfs.getSubject()));
 		bo.setMessageId(mfs.getId());

+ 9 - 8
src/main/java/com/goafanti/common/mapper/MessageFromSystemMapper.xml

@@ -475,16 +475,16 @@
    <update id="updateMessageConsumer">
    	update message_consumer
    	<set>
-   		read_time = #{readTime,jdbcType=TIMESTAMP} where uid = #{uid,jdbcType=VARCHAR} and message_id = #{messageId,jdbcType=VARCHAR}
+   		read_time = #{readTime,jdbcType=TIMESTAMP} where consumer_id = #{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}
+   		${sql}
    </select>
    
    <select id="selectRecommendTarget" parameterType="java.lang.String" resultType="com.goafanti.common.model.MessageFromSystem">
-   	 	#{sql,jdbcType=VARCHAR}
+   	 	${sql}
    </select>
    
    <select id="listSystemMessageByPage"  resultType="com.goafanti.message.bo.MessageListBo">
@@ -496,17 +496,18 @@
 			a.resource_type as resourceType,
 			a.title,
 			a.body,
-			a.is_draft as isDraft
+			a.is_draft as isDraft,
+			a.subject
 		from
 			message_from_system a
 		where 1= 1
 		<choose>
-			<when test="subject = 01">
-				and a.subject != 2
-			</when>
 			<when test="subject = 2">
 				and a.subject = 2
 			</when>
+			<otherwise>
+				and a.subject != 2
+			</otherwise>
 		</choose>
 		<if test="isDraft != null">
 			and a.is_draft = #{isDraft,jdbcType=INTEGER}
@@ -618,7 +619,7 @@
    <select id="listPersonalMessageByPage" resultType="com.goafanti.message.bo.MessageListBo">
 		select
 			b.id as messageId,b.title,date_format(b.create_time,'%Y-%m-%d %H:%I:%S') as createTime,b.subject,
-			b.resource_type as resourceType,b.resource_id as resourceId,if(a.read_time is null,0,1) as isRead
+			b.resource_type as resourceType,b.resource_id as resourceId,if(a.read_time is null,0,1) as isRead,b.body as body
 		from
 			message_consumer a left join message_from_system b on
 			a.message_id = b.id

+ 48 - 25
src/main/java/com/goafanti/message/service/impl/MessageServiceImpl.java

@@ -8,6 +8,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -55,17 +56,20 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 			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);
+				String tmp=messageFromSystemMapper.selectSendTarget(sql);
+				result +="," + tmp==null?"":tmp;
 			}
 			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);
+				String tmp=messageFromSystemMapper.selectSendTarget(sql);
+				result +="," + tmp==null?"":tmp;
 			}
 			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);
+				String tmp=messageFromSystemMapper.selectSendTarget(sql);
+				result +="," + tmp==null?"":tmp;
 			}
-			if(!result.equals("")){
+			if(!result.equals("")&&result!=null){
 				String data[] = result.substring(1).split(",");
 				List<String> list = new ArrayList<String>();
 				boolean flag;
@@ -84,6 +88,9 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 			}
 		}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";
+			if(messageFromSystemMapper.selectSendTarget(sql)==null){
+				return "";
+			}
 			return messageFromSystemMapper.selectSendTarget(sql);
 		}
 		return "";
@@ -93,9 +100,11 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 	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()) + ")";
+			// 123,123
+			
+			sql = "select group_concat(id) from admin where department_id in ("+ changeSql(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()) + ")";
+			sql = "select group_concat(id) from admin a left join user_role b on a.id = b.uid where b.rid in (" + changeSql(selectMap.get(ConsumerType.ROLE.getTypeCode())) + ")";
 		}
 		if(!sql.equals("")) return messageFromSystemMapper.selectSendTarget(sql);
 		return "";
@@ -105,7 +114,7 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 	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()) + ")";
+			sql = "select project_name as title,project_des as body,id as resourceId from tech_project where id in (" + changeSql(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())){ //组织成果
@@ -135,6 +144,7 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 		mfs.setSubject(subject);
 		mfs.setConsumerType(targetType);
 		mfs.setIsDraft(isDraft);
+		mfs.setDeleteSign(Boolean.FALSE);
 		if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
 			Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
 			mfs.setCreater(admin.getName());
@@ -144,26 +154,30 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 		List<MessageProducer> target = new ArrayList<MessageProducer>();
 		String[] cids;
 		if(subject == SubjectType.KE_HU.getTypeCode()){
-			cids = selectSendUser(targetMap,targetType).split(",");
-			MessageProducer mp;
-			for(String cid : cids){
-				mp = new MessageProducer();
-				mp.setId(UUID.randomUUID().toString());
-				mp.setMessageId(mfs.getId());
-				mp.setConsumerId(cid);
-				target.add(mp);
+			if(selectSendUser(targetMap,targetType).split(",")!=null){
+				cids = selectSendUser(targetMap,targetType).split(",");
+				MessageProducer mp;
+				for(String cid : cids){
+					mp = new MessageProducer();
+					mp.setId(UUID.randomUUID().toString());
+					mp.setMessageId(mfs.getId());
+					mp.setConsumerId(cid);
+					target.add(mp);
+				}
 			}
-			if(target.size()>0) insertBatchProducer(target);
+				if(target.size()>0) insertBatchProducer(target);					
 		}else if(subject == SubjectType.YUN_YING.getTypeCode()){
-			cids = selectSendAdmin(targetMap,targetType).split(",");
-			MessageProducer mp;
-			for(String cid : cids){
-				mp = new MessageProducer();
-				mp.setId(UUID.randomUUID().toString());
-				mp.setMessageId(mfs.getId());
-				mp.setConsumerId(cid);
-				target.add(mp);
-			}
+			if(selectSendUser(targetMap,targetType).split(",")!=null){
+				cids = selectSendAdmin(targetMap,targetType).split(",");
+				MessageProducer mp;
+				for(String cid : cids){
+					mp = new MessageProducer();
+					mp.setId(UUID.randomUUID().toString());
+					mp.setMessageId(mfs.getId());
+					mp.setConsumerId(cid);
+					target.add(mp);
+				}
+			}			
 			if(target.size()>0) insertBatchProducer(target);
 		}
 		return 1;
@@ -327,4 +341,13 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 	public JpushEasemobAccount selectSynAccByUid(String uid) {
 		return jpushEasemobAccountMapper.selectSynAccByUid(uid);
 	}
+	
+	private String changeSql(String source){
+		String result = "";
+		if(StringUtils.isNotBlank(source)){
+			source = "'" + source + "'";
+			result = source.replace(",", "','");
+		}
+		return result;
+	}
 }