wanghui лет назад: 8
Родитель
Сommit
4108588b96

+ 11 - 12
src/main/java/com/goafanti/admin/controller/AdminMessageController.java

@@ -1,7 +1,6 @@
 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;
@@ -16,6 +15,7 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.utils.DateUtils;
 import com.goafanti.message.enums.ConsumerType;
 import com.goafanti.message.enums.RecommendType;
 import com.goafanti.message.enums.SubjectType;
@@ -39,9 +39,8 @@ public class AdminMessageController extends CertifyApiController{
 	@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()));
+		jsonObject.addProperty("createTime", DateUtils.formatDate(new Date(), AFTConstants.YYYYMMDDHHMMSS));
 		res.setData(jsonObject);
 		return res;
 	}
@@ -97,8 +96,8 @@ public class AdminMessageController extends CertifyApiController{
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须选定目标群体"));
 			return res;
 		}
-		SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
-		messageServiceImpl.insertSystemMessage(targetMap,targetType, title, body, subject,format.parse(createTime),isDraft);
+		messageServiceImpl.insertSystemMessage(targetMap,targetType, title, body, subject,
+				DateUtils.parseDate(createTime,AFTConstants.YYYYMMDDHHMMSS),isDraft);
 		return res;
 	}
 	
@@ -139,13 +138,13 @@ public class AdminMessageController extends CertifyApiController{
 			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(sourceType == RecommendType.TECH_SERVICE.getTypeCode()) sourceMap.put(sourceType, projectIds);
+		if(sourceType == RecommendType.PERSON_ACHIEVEMENT.getTypeCode()) sourceMap.put(sourceType, personalAchievementIds);
+		if(sourceType == RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode()) sourceMap.put(sourceType, organizationAchievementIds);
+		if(sourceType == RecommendType.PERSONAL_DEMAND.getTypeCode()) sourceMap.put(sourceType, personalDemandIds);
+		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))){
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须选定推荐内容"));
 			return res;

+ 16 - 0
src/main/java/com/goafanti/app/bo/IndexBo.java

@@ -3,10 +3,14 @@ package com.goafanti.app.bo;
 public class IndexBo {
 	/** 最新系统消息标题 **/
 	private String sysMessageTitle;
+	/** 最新系统消息日期 **/
+	private String sysMessageDate;
 	/** 未读系统消息数量 **/
 	private String sysMessageUnRead;
 	/** 最新推荐消息标题 **/
 	private String recMessageTitle;
+	/** 最新推荐消息日期 **/
+	private String recMessageDate;
 	/** 未读推荐消息数量 **/
 	private String recMessageUnRead;
 	public String getSysMessageTitle() {
@@ -15,6 +19,12 @@ public class IndexBo {
 	public void setSysMessageTitle(String sysMessageTitle) {
 		this.sysMessageTitle = sysMessageTitle;
 	}
+	public String getSysMessageDate() {
+		return sysMessageDate;
+	}
+	public void setSysMessageDate(String sysMessageDate) {
+		this.sysMessageDate = sysMessageDate;
+	}
 	public String getSysMessageUnRead() {
 		return sysMessageUnRead;
 	}
@@ -24,6 +34,12 @@ public class IndexBo {
 	public String getRecMessageTitle() {
 		return recMessageTitle;
 	}
+	public String getRecMessageDate() {
+		return recMessageDate;
+	}
+	public void setRecMessageDate(String recMessageDate) {
+		this.recMessageDate = recMessageDate;
+	}
 	public void setRecMessageTitle(String recMessageTitle) {
 		this.recMessageTitle = recMessageTitle;
 	}

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

@@ -1,5 +1,7 @@
 package com.goafanti.app.controller;
 
+import java.lang.reflect.InvocationTargetException;
+
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.StringUtils;
@@ -9,10 +11,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.model.MessageFromSystem;
 import com.goafanti.common.model.User;
+import com.goafanti.common.utils.BeanUtilsExt;
+import com.goafanti.common.utils.DateUtils;
 import com.goafanti.core.shiro.token.TokenManager;
+import com.goafanti.message.bo.MessageListBo;
 import com.goafanti.message.service.MessageService;
 import com.goafanti.user.service.UserService;
 
@@ -70,7 +77,7 @@ public class AppApiController extends BaseApiController {
 		return res;
 	}
 	
-	@RequestMapping(value = "/listMessage", method = RequestMethod.GET)
+	@RequestMapping(value = "/listMessage", method = RequestMethod.POST)
 	public Result listMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize){
 		Result res = new Result();
 		if(null == subject){
@@ -98,6 +105,8 @@ public class AppApiController extends BaseApiController {
 	/**
 	 * 读取消息
 	 * @param messageId
+	 * @throws IllegalAccessException 
+	 * @throws InvocationTargetException 
 	 */
 	@RequestMapping(value = "/readMessage",method = RequestMethod.GET)
 	private Result readMessage(String messageId){
@@ -107,7 +116,15 @@ public class AppApiController extends BaseApiController {
 			return res;
 		}
 		//读取消息详情
-		res.setData(messageServiceImpl.selectSystemMessageDetail(messageId));
+		MessageFromSystem mfs = messageServiceImpl.selectSystemMessageDetail(messageId);
+		MessageListBo bo = new MessageListBo();
+		bo.setCreateTime(bo.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
+		bo.setResourceType(String.valueOf(mfs.getResourceType()));
+		bo.setSubject(String.valueOf(mfs.getSubject()));
+		bo.setMessageId(mfs.getId());
+		bo.setTitle(mfs.getTitle());
+		bo.setBody(mfs.getBody());
+		res.setData(bo);
 		//更新 message_consumer
 		messageServiceImpl.updateMessageConsumer(messageId);
 		return res;

+ 6 - 2
src/main/java/com/goafanti/common/mapper/MessageFromSystemMapper.xml

@@ -507,11 +507,13 @@
 		(
 			select
 				t1.sysMessageTitle,
+				t1.sysMessageDate,
 				t2.sysMessageUnRead
 			from
 				(
 					select
 						title as sysMessageTitle,
+						date_format(b.create_time,'%Y-%m-%d %H:%I:%S') as sysMessageDate,
 						1 as nouse
 					from
 						message_consumer a left join message_from_system b on
@@ -541,11 +543,13 @@
 		(
 			select
 				t3.recMessageTitle,
+				t3.recMessageDate,
 				t4.recMessageUnRead
 			from
 				(
 					select
 						title as recMessageTitle,
+						date_format(b.create_time,'%Y-%m-%d %H:%I:%S') as recMessageDate,
 						1 as nouse
 					from
 						message_consumer a left join message_from_system b on
@@ -574,9 +578,9 @@
 		) y
    </select>
    
-   <select id="listPersonalMessageByPage" resultMap="BaseResultMap">
+   <select id="listPersonalMessageByPage" resultType="com.goafanti.message.bo.MessageListBo">
 		select
-			b.title,b.create_time,b.subject
+			b.title,date_format(b.create_time,'%Y-%m-%d %H:%I:%S') as createTime,b.subject, b.resource_type as resourceType
 		from
 			message_consumer a left join message_from_system b on
 			a.message_id = b.id

+ 25 - 0
src/main/java/com/goafanti/common/utils/DateUtils.java

@@ -1,5 +1,7 @@
 package com.goafanti.common.utils;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -407,4 +409,27 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
 		calendar.roll(Calendar.DAY_OF_YEAR, -1);
 		return calendar.getTime();
 	}
+	
+	/**
+	 * 格式化时间
+	 * @param date
+	 * @param pattern
+	 * @return
+	 */
+	public static String formatDate(Date date,String pattern){
+		SimpleDateFormat format = new SimpleDateFormat(pattern);
+		return format.format(date);
+	}
+	
+	/**
+	 * 解析日期
+	 * @param source
+	 * @param pattern
+	 * @return
+	 * @throws ParseException 
+	 */
+	public static Date parseDate(String source,String pattern) throws ParseException{
+		SimpleDateFormat format = new SimpleDateFormat(pattern);
+		return format.parse(source);
+	}
 }

+ 46 - 0
src/main/java/com/goafanti/message/bo/MessageListBo.java

@@ -0,0 +1,46 @@
+package com.goafanti.message.bo;
+
+public class MessageListBo {
+	private String messageId;
+	private String title;
+	private String body;
+	private String createTime;
+	private String subject;
+	private String resourceType;
+	public String getMessageId() {
+		return messageId;
+	}
+	public void setMessageId(String messageId) {
+		this.messageId = messageId;
+	}
+	public String getTitle() {
+		return title;
+	}
+	public void setTitle(String title) {
+		this.title = title;
+	}
+	public String getBody() {
+		return body;
+	}
+	public void setBody(String body) {
+		this.body = body;
+	}
+	public String getCreateTime() {
+		return createTime;
+	}
+	public void setCreateTime(String createTime) {
+		this.createTime = createTime;
+	}
+	public String getSubject() {
+		return subject;
+	}
+	public void setSubject(String subject) {
+		this.subject = subject;
+	}
+	public String getResourceType() {
+		return resourceType;
+	}
+	public void setResourceType(String resourceType) {
+		this.resourceType = resourceType;
+	}
+}

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

@@ -16,11 +16,11 @@ public enum ConsumerType {
 	/** 公司 **/
 	COMPANY(3,"COMPANY"),
 	/** 角色 **/
-	ROLE(6,"ROLE"),
+	ROLE(4,"ROLE"),
 	/** 用户散户 **/
-	USER_RETAIL(7,"USER_RETAIL"),
+	USER_RETAIL(5,"USER_RETAIL"),
 	/** 行业 **/
-	INDUSTRY(8,"INDUSTRY"),
+	INDUSTRY(6,"INDUSTRY"),
 	/** 没有定义 **/
 	NO_DEFINITION(null,"NO_DEFINITION");
 	private ConsumerType(Integer typeCode, String typeName) {

+ 10 - 6
src/main/java/com/goafanti/message/enums/RecommendType.java

@@ -6,18 +6,22 @@ import java.util.Map;
 public enum RecommendType {
 	/** 科技服务 **/
 	TECH_SERVICE(0,"TECH_SERVICE"),
+	/** 成果 **/
+	ACHIEVEMENT(1,"ACHIEVEMENT"),
 	/** 个人成果 **/
-	PERSON_ACHIEVEMENT(1,"PERSON_ACHIEVEMENT"),
+	PERSON_ACHIEVEMENT(11,"PERSON_ACHIEVEMENT"),
 	/** 组织成果 **/
-	ORGANIZATION_ACHIEVEMENT(2,"ORGANIZATION_ACHIEVEMENT"),
+	ORGANIZATION_ACHIEVEMENT(12,"ORGANIZATION_ACHIEVEMENT"),
+	/** 需求 **/
+	DEMAND(2,"DEMAND"),
 	/** 个人需求 **/
-	PERSONAL_DEMAND(3,"PERSONAL_DEMAND"),
+	PERSONAL_DEMAND(21,"PERSONAL_DEMAND"),
 	/** 个人需求 **/
-	ORGANIZATION_DEMAND(4,"ORGANIZATION_DEMAND"),
+	ORGANIZATION_DEMAND(22,"ORGANIZATION_DEMAND"),
 	/** 专家 **/
-	EXPERT(5,"EXPERT"),
+	EXPERT(3,"EXPERT"),
 	/** 政策 **/
-	NEWS(6,"NEWS"),
+	NEWS(4,"NEWS"),
 	/** 未定义 **/
 	NO_DEFINITION(null,"NO_DEFINITION");
 	private Integer	typeCode;

+ 2 - 1
src/main/java/com/goafanti/message/service/MessageService.java

@@ -10,6 +10,7 @@ import com.goafanti.common.model.MessageFromSystem;
 import com.goafanti.common.model.MessageProducer;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.message.bo.MessageBo;
+import com.goafanti.message.bo.MessageListBo;
 
 public interface MessageService {
 	/**
@@ -133,7 +134,7 @@ public interface MessageService {
 	 * @param sourceType 推荐类型
 	 * @return
 	 */
-	Pagination<MessageFromSystem> listPersonalMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize);
+	Pagination<MessageListBo> listPersonalMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize);
 	
 	/**
 	 * 查看消息详情

+ 20 - 5
src/main/java/com/goafanti/message/service/impl/MessageServiceImpl.java

@@ -25,6 +25,7 @@ import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.message.bo.MessageBo;
+import com.goafanti.message.bo.MessageListBo;
 import com.goafanti.message.enums.ConsumerType;
 import com.goafanti.message.enums.RecommendType;
 import com.goafanti.message.enums.SubjectType;
@@ -183,7 +184,7 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 			message.setId(messageId);
 			message.setSubject(subject);
 			message.setConsumerType(targetType);
-			message.setResourceType(sourceType);
+			message.setResourceType(getSourceType(sourceType)); //需要适配
 			message.setIsDraft(isDraft);
 			if(SecurityUtils.getSubject().getPrincipal() instanceof Admin){
 				Admin admin = (Admin)SecurityUtils.getSubject().getPrincipal();
@@ -209,7 +210,6 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 						producerTarget.add(mp);
 					}
 				}
-				
 			}
 			//批量插入
 			if(messageTarget.size()>0) messageFromSystemMapper.insertBatchMessage(messageTarget);
@@ -287,13 +287,13 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 
 	@SuppressWarnings("unchecked")
 	@Override
-	public Pagination<MessageFromSystem> listPersonalMessage(Integer subject, Integer sourceType,Integer pageNo,Integer pageSize) {
+	public Pagination<MessageListBo> listPersonalMessage(Integer subject, Integer sourceType,Integer pageNo,Integer pageSize) {
 		if(subject == SubjectType.KE_HU.getTypeCode() || subject == SubjectType.TUI_JIAN.getTypeCode()){
 			Map<String,Object> params = new HashMap<String, Object>();
 			if(null != subject) params.put("subject", subject);
 			if(null != sourceType) params.put("sourceType", sourceType);
 			params.put("uid", TokenManager.getUserId());
-			return (Pagination<MessageFromSystem>)findPage("listPersonalMessageByPage", "listPersonalMessageCount", params, pageNo, pageSize);
+			return (Pagination<MessageListBo>)findPage("listPersonalMessageByPage", "listPersonalMessageCount", params, pageNo, pageSize);
 		}
 		return null;
 	}
@@ -302,5 +302,20 @@ public class MessageServiceImpl  extends BaseMybatisDao<MessageFromSystemMapper>
 	public MessageFromSystem selectSystemMessageDetail(String messageId) {
 		return messageFromSystemMapper.selectByPrimaryKey(messageId);
 	}
-
+	
+	/**
+	 * 为个人和组织做转换
+	 * @param sourceType
+	 * @return
+	 */
+	private Integer getSourceType(Integer sourceType){
+		if(RecommendType.PERSON_ACHIEVEMENT.getTypeCode() == sourceType 
+				|| RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode() == sourceType){
+			sourceType = RecommendType.ACHIEVEMENT.getTypeCode();
+		}else if(RecommendType.PERSONAL_DEMAND.getTypeCode() == sourceType
+				|| RecommendType.ORGANIZATION_DEMAND.getTypeCode() == sourceType){
+			sourceType = RecommendType.DEMAND.getTypeCode();
+		}
+		return sourceType;
+	}
 }