浏览代码

Merge remote-tracking branch 'origin/test' into patch

anderx 7 年之前
父节点
当前提交
96f2d06e82

+ 7 - 1
src/main/java/com/goafanti/comment/bo/CommentDetailResult.java

@@ -8,6 +8,7 @@ import com.goafanti.common.utils.LimitLengthUtil;
 public class CommentDetailResult {
 private String content;
 private String commenter;
+private String uname;
 private Integer star;
 private Date createTime;
 private String createTimeFormat;
@@ -41,5 +42,10 @@ public String getCreateTimeFormat() {
 public void setCreateTimeFormat(String createTimeFormat) {
 	this.createTimeFormat = createTimeFormat;
 }
-
+public String getUname() {
+	return uname;
+}
+public void setUname(String uname) {
+	this.uname = uname;
+}
 }

+ 2 - 0
src/main/java/com/goafanti/comment/service/CommentService.java

@@ -12,5 +12,7 @@ public interface CommentService {
 	Pagination<CommentDetailResult> searchComment(String commodityId,Integer pageNo,Integer pageSize);
 
 	Pagination<CommentDetailResult> selectExpertsComment(String id,Integer pageNo,Integer pageSize);
+	
+	Pagination<CommentDetailResult> searchUnlandedCommentList(String commodityId,Integer pageNo,Integer pageSize);
 
 }

+ 23 - 4
src/main/java/com/goafanti/comment/service/impl/CommentServiceImpl.java

@@ -16,6 +16,7 @@ import com.goafanti.common.dao.JtCommodityCommentMapper;
 import com.goafanti.common.dao.JtConsultOrderMapper;
 import com.goafanti.common.dao.JtOrderMapper;
 import com.goafanti.common.model.JtCommodityComment;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
@@ -57,10 +58,19 @@ public class CommentServiceImpl extends BaseMybatisDao<JtCommodityCommentMapper>
 		jtCommodityComment.setIp(ip);
 		jtCommodityComment.setStar(commentInput.getStar());
 		
-		//用户id和订单id如果不存在(匿名评论)
-		uid = null == uid ? "" : uid;
-		commentInput.setOrderNo( null == commentInput.getOrderNo()? "" : commentInput.getOrderNo());
-		
+		//用户id或者订单id如果不存在(匿名评论)
+		if(StringUtils.isBlank(commentInput.getOrderNo())){
+			commentInput.setOrderNo("");
+		}
+		if(StringUtils.isBlank(uid)){
+			commentInput.setOrderNo("");
+			//查看当前ip的游客名称和游客最大名称
+			uid = jtCommodityCommentMapper.getUidByIp(ip);
+			if(StringUtils.isBlank(uid)){
+				int c = Integer.parseInt(jtCommodityCommentMapper.getMaxNameUid()) + 1;
+				uid = "游客" + String.format("%03d", c);
+			}
+		}
 		jtCommodityComment.setUid(uid);
 		jtCommodityComment.setOrderNo(commentInput.getOrderNo());
 		jtCommodityCommentMapper.insert(jtCommodityComment);
@@ -95,6 +105,15 @@ public class CommentServiceImpl extends BaseMybatisDao<JtCommodityCommentMapper>
 		params.put("id", id);
 		return (Pagination<CommentDetailResult>) findPage("selectExpertsCommentList", "selectExpertsCommentCount", params, pageNo, pageSize);
 	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<CommentDetailResult> searchUnlandedCommentList(
+			String commodityId, Integer pageNo, Integer pageSize) {
+		Map<String, Object>params=new HashMap<>();
+		params.put("commodityId", commodityId);
+		return (Pagination<CommentDetailResult>) findPage("searchUnlandedCommentByCommodityId", "searchCommentCountByCommodityId", params, pageNo, pageSize);
+	}
 	
 	
 	

+ 24 - 0
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -715,4 +715,28 @@ public class PublicController extends BaseController {
 		return result;
 	}
 	
+	/**
+	 * 
+	 * @param commodityId
+	 * @param pageNo
+	 * @param pageSize
+	 * @return
+	 */
+	@RequestMapping(value = "unlanded/comment/list", method = RequestMethod.GET)
+	@ResponseBody
+	public Result unlandedCommentList(String commodityId,Integer pageNo,Integer pageSize) {
+		Result result=new Result();
+		if(StringUtils.isBlank(commodityId)) {
+			result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
+		}
+		CommentResult commentResult=new CommentResult();
+		commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
+		commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
+		commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
+		commentResult.setComments(commentService.searchUnlandedCommentList(commodityId, pageNo, pageSize));
+		result.setData(commentResult);
+		return result;
+		
+	}
+	
 }

+ 3 - 0
src/main/java/com/goafanti/common/dao/JtCommodityCommentMapper.java

@@ -80,4 +80,7 @@ public interface JtCommodityCommentMapper {
 	Integer getCommentCount(Integer type,String commodityId);
 
 	CommentDetailResult selectByProjectId(String id);
+	
+	String getUidByIp(String ip);
+	String getMaxNameUid();
 }

+ 23 - 0
src/main/java/com/goafanti/common/mapper/JtCommodityCommentMapper.xml

@@ -386,4 +386,27 @@
   where 1=1
   and b.seller_id= #{id,jdbcType=VARCHAR}
   </select>
+  
+  <!-- 查看某ip的uid -->
+  <select id="getUidByIp" resultType="java.lang.String">
+   select distinct uid from jt_commodity_comment where  ip = #{0} and uid like '游客%' limit 1
+  </select>
+  <!-- 获得以游客开头的最大uid -->
+  <select id="getMaxNameUid" resultType="java.lang.String">
+   select max(substring(uid,3)) from jt_commodity_comment where uid like '游客%'
+  </select>
+  
+  <!-- 未登录用户获得评价 -->
+  <select id="searchUnlandedCommentByCommodityId" resultType="com.goafanti.comment.bo.CommentDetailResult">
+  select jcc.create_time as createTime,
+  date_format(jcc.create_time,'%Y-%m-%d') as createTimeFormat,
+  jcc.content,jcc.star,IFNULL(LPAD(right(u.identify_name,1),(CHAR_LENGTH(u.identify_name)),'*'), jcc.uid) as uname
+  from jt_commodity_comment jcc
+  left join user u on jcc.uid=u.id
+  where jcc.commodity_id=#{commodityId,jdbcType=VARCHAR}
+  order by jcc.create_time desc
+  <if test="page_sql!=null">
+	${page_sql}
+  </if>
+  </select>
 </mapper>