Commit 4f720f0f authored by shiyu's avatar shiyu

Merge remote-tracking branch 'origin/master'

parents 69ec71c4 4dcbe68a
package com.wwdz.ch.core.util;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.entity.ImageInfo;
import com.xxdxxs.utils.CommonUtils;
import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -113,9 +111,9 @@ public class MediaUtil {
}
}
if (org.apache.commons.lang3.StringUtils.isNotBlank(videos)) {
String[] vedioImage = videos.split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
String[] videoImage = videos.split(";");
if (videoImage[0].contains(",")) {
String[] video = videoImage[0].split(",");
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
......
package com.wwdz.ch.wx.impl;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.MediaUtil;
import com.wwdz.ch.db.dao.FavoritesDao;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao;
import com.wwdz.ch.db.dao.ItemDao;
......@@ -21,7 +21,6 @@ import com.wwdz.ch.wx.entity.vo.ItemResponseVo;
import com.wwdz.ch.wx.service.FavoritesService;
import com.wwdz.ch.wx.util.StringUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -251,10 +250,11 @@ public class FavoritesServiceImpl implements FavoritesService {
vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
}
// 设置收藏数
vo.setCollectCount(getCollectCount(item.getId(), item.getSourceType()));
long count = favoritesItemsRelationDao.countByItemId(item.getId());
vo.setCollectCount(StringUtil.formatCount(count));
// 设置图片或视频
vo.setHomePageImage(getImage(item));
vo.setHomePageImage(MediaUtil.getHomePageImage(item.getImages(), item.getVideos()));
agentTranceResponseVo.setDetail(vo);
list.add(agentTranceResponseVo);
}
......@@ -396,78 +396,6 @@ public class FavoritesServiceImpl implements FavoritesService {
}
}
/**
* 获取展示图片
*
* @param item
* @return
*/
private Map<String, Object> getImage(Item item) {
Map<String, Object> homePageMap = new HashMap<>();
homePageMap.put("url", "");
homePageMap.put("type", 2);
homePageMap.put("width", "0");
homePageMap.put("height", "0");
if (StringUtils.isNotBlank(item.getImages())) {
String[] image = item.getImages().split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
}
if (StringUtils.isNotBlank(item.getVideos())) {
String[] vedioImage = item.getVideos().split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
}
return homePageMap;
}
/**
* 获取图片的长宽
*
* @param image
* @return
*/
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
String[] result = infoImage[0].split("x");
map.put("width", result[0]);
map.put("height", result[1]);
return map;
}
/**
* 获取藏品的收藏数
*
* @param itemId
* @param sourceType
* @return
*/
private String getCollectCount(Long itemId, Integer sourceType) {
String countString = "";
// 设置收藏数
long count = favoritesItemsRelationDao.countByItemId(itemId);
if (sourceType.equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
if (count < 1000) {
countString = String.valueOf(count);
} else {
countString = String.format("%.1f", (double) count / 1000) + "k";
}
return countString;
}
/**
* 获取格式化后的金额
*
......
package com.wwdz.ch.wx.impl;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.MediaUtil;
import com.wwdz.ch.db.dao.FavoritesItemsRelationDao;
import com.wwdz.ch.db.dao.FootPrintDao;
import com.wwdz.ch.db.dao.ItemDao;
......@@ -17,7 +17,6 @@ import com.wwdz.ch.wx.service.FootPrintService;
import com.wwdz.ch.wx.util.StringUtil;
import com.xxdxxs.utils.DateUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -104,9 +103,10 @@ public class FootPrintServiceImpl implements FootPrintService {
itemResponseVo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), footprint.getItemId(), null) ? 1 : 0);
itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
// 设置收藏数
itemResponseVo.setCollectCount(getCollectCount(item.getId(), item.getSourceType()));
long count = favoritesItemsRelationDao.countByItemId(item.getId());
itemResponseVo.setCollectCount(StringUtil.formatCount(count));
// 设置图片或视频
itemResponseVo.setHomePageImage(getImage(item));
itemResponseVo.setHomePageImage(MediaUtil.getHomePageImage(item.getImages(), item.getVideos()));
// 设置日期类型
if (footprint.getUpdateTime().compareTo(today) >= 0) {
......@@ -150,80 +150,6 @@ public class FootPrintServiceImpl implements FootPrintService {
}
}
/**
* 获取展示图片
*
* @param item
* @return
*/
private Map<String, Object> getImage(Item item) {
Map<String, Object> homePageMap = new HashMap<>();
homePageMap.put("url", "");
homePageMap.put("type", 2);
homePageMap.put("width", "0");
homePageMap.put("height", "0");
if (StringUtils.isNotBlank(item.getImages())) {
String[] image = item.getImages().split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
}
if (StringUtils.isNotBlank(item.getVideos())) {
String[] vedioImage = item.getVideos().split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
}
return homePageMap;
}
/**
* 获取图片的长宽
*
* @param image
* @return
*/
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
String[] result = infoImage[0].split("x");
map.put("width", result[0]);
map.put("height", result[1]);
return map;
}
/**
* 获取藏品的收藏数
*
* @param itemId
* @param sourceType
* @return
*/
private String getCollectCount(Long itemId, Integer sourceType) {
String countString = "";
// 设置收藏数
long count = favoritesItemsRelationDao.countByItemId(itemId);
if (count <= 0) {
return "0";
}
if (sourceType.equals(CommonEnum.SourceTypeEnum.USER_UPLOAD.getCode())) {
count --;
}
if (count < 1000) {
countString = String.valueOf(count);
} else {
countString = String.format("%.1f", (double) count / 1000) + "k";
}
return countString;
}
/**
* 获取格式化后的金额
*
......
......@@ -142,7 +142,7 @@ public class ItemServiceImpl implements ItemService {
// 设置价格
vo.setPrice(getPrice(es.getPrice()));
// 设置图片或视频
vo.setHomePageImage(getImage(es.getImages(), es.getVideos()));
vo.setHomePageImage(MediaUtil.getHomePageImage(es.getImages(), es.getVideos()));
// 设置是否收藏和是否是自己发布的
vo.setIsCollected(0);
vo.setIsMine(0);
......@@ -151,7 +151,8 @@ public class ItemServiceImpl implements ItemService {
vo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), es.getId()) ? 1 : 0);
}
// 设置收藏数
vo.setCollectCount(getCollectCount(es.getId()));
long count = favoritesItemsRelationDao.countByItemId(es.getId());
vo.setCollectCount(StringUtil.formatCount(count));
AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo();
agentTranceResponseVo.setAgentTraceInfo_("");
......@@ -208,7 +209,7 @@ public class ItemServiceImpl implements ItemService {
// 设置价格
vo.setPrice(getPrice(item.getPrice()));
// 设置图片或视频
vo.setHomePageImage(getImage(item.getImages(), item.getVideos()));
vo.setHomePageImage(MediaUtil.getHomePageImage(item.getImages(), item.getVideos()));
// 设置是否收藏和是否是自己发布的
vo.setIsCollected(0);
vo.setIsMine(1);
......@@ -216,7 +217,8 @@ public class ItemServiceImpl implements ItemService {
vo.setIsCollected(favoritesItemsRelationDao.isCollected(dto.getUserId(), item.getId(), null) ? 1 : 0);
}
// 设置收藏数
vo.setCollectCount(getCollectCount(item.getId()));
long count = favoritesItemsRelationDao.countByItemId(item.getId());
vo.setCollectCount(StringUtil.formatCount(count));
AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo();
agentTranceResponseVo.setAgentTraceInfo_("");
......@@ -276,9 +278,10 @@ public class ItemServiceImpl implements ItemService {
itemResponseVo.setIsCollected(1);
itemResponseVo.setIsMine(userItemsRelationDao.isExisted(dto.getUserId(), item.getId()) ? 1 : 0);
// 设置收藏数
itemResponseVo.setCollectCount(getCollectCount(item.getId()));
long count = favoritesItemsRelationDao.countByItemId(item.getId());
itemResponseVo.setCollectCount(StringUtil.formatCount(count));
// 设置图片或视频
itemResponseVo.setHomePageImage(getImage(item.getImages(), item.getVideos()));
itemResponseVo.setHomePageImage(MediaUtil.getHomePageImage(item.getImages(), item.getVideos()));
AgentTranceResponseVo agentTranceResponseVo = new AgentTranceResponseVo();
agentTranceResponseVo.setAgentTraceInfo_("");
......@@ -511,7 +514,8 @@ public class ItemServiceImpl implements ItemService {
}
// 查询收藏数
String collectCount = getCollectCount(item.getId());
long count = favoritesItemsRelationDao.countByItemId(item.getId());
String collectCount = StringUtil.formatCount(count);
Map<String, Object> map = new HashMap<>();
map.put("collectCount", collectCount);
......@@ -541,7 +545,8 @@ public class ItemServiceImpl implements ItemService {
favoritesItemsRelationDao.deleteByUserIdItemId(dto.getUserId(), dto.getId());
// 查询收藏数
String collectCount = getCollectCount(item.getId());
long count = favoritesItemsRelationDao.countByItemId(item.getId());
String collectCount = StringUtil.formatCount(count);
Map<String, Object> map = new HashMap<>();
map.put("collectCount", collectCount);
......@@ -791,40 +796,6 @@ public class ItemServiceImpl implements ItemService {
return null;
}
/**
* 获取展示图片
*
* @param images
* @param videos
* @return
*/
private Map<String, Object> getImage(String images, String videos) {
Map<String, Object> homePageMap = new HashMap<>();
homePageMap.put("url", "");
homePageMap.put("type", 2);
homePageMap.put("width", "0");
homePageMap.put("height", "0");
if (StringUtils.isNotBlank(images)) {
String[] image = images.split(";");
homePageMap.put("url", image[0]);
if (image[0].contains("_")) {
homePageMap = getAspect(image[0]);
homePageMap.put("url", image[0]);
homePageMap.put("type", 2);
}
}
if (StringUtils.isNotBlank(videos)) {
String[] vedioImage = videos.split(";");
if (vedioImage[0].contains(",")) {
String[] video = vedioImage[0].split(",");
homePageMap = getAspect(video[1]);
homePageMap.put("url", video[1]);
homePageMap.put("type", 1);
}
}
return homePageMap;
}
/**
* 获取图片对象列表
*
......@@ -837,7 +808,7 @@ public class ItemServiceImpl implements ItemService {
for (int i = 0; i < image.length; i++) {
Map<String, Object> map = new HashMap<>();
if (image[i].contains("_")) {
map = getAspect(image[i]);
map = MediaUtil.getAspect(image[i]);
} else {
map.put("width", "0");
map.put("type", "0");
......@@ -862,7 +833,7 @@ public class ItemServiceImpl implements ItemService {
Map<String, Object> map = new HashMap<>();
if (video[i].contains(",")) {
String[] image = video[i].split(",");
map = getAspect(image[1]);
map = MediaUtil.getAspect(image[1]);
map.put("url", image[0]);
} else {
map.put("width", "0");
......@@ -875,40 +846,6 @@ public class ItemServiceImpl implements ItemService {
return list;
}
/**
* 获取图片的长宽
*
* @param image
* @return
*/
private Map<String, Object> getAspect(String image) {
Map<String, Object> map = new HashMap<>();
String[] _image = image.split("_");
String[] infoImage = _image[1].split("\\.");
String[] result = infoImage[0].split("x");
map.put("width", result[0]);
map.put("height", result[1]);
return map;
}
/**
* 获取藏品的收藏数
*
* @param itemId
* @return
*/
private String getCollectCount(Long itemId) {
String countString = "";
// 设置收藏数
long count = favoritesItemsRelationDao.countByItemId(itemId);
if (count < 1000) {
countString = String.valueOf(count);
} else {
countString = String.format("%.1f", (double) count / 1000) + "k";
}
return countString;
}
/**
* 获取格式化后的金额
*
......
......@@ -49,4 +49,20 @@ public class StringUtil {
}
return sb.toString();
}
/**
* 格式化数量(1000转换成k)
*
* @param count
* @return
*/
public static String formatCount(long count) {
String countString = "";
if (count < 1000) {
countString = String.valueOf(count);
} else {
countString = String.format("%.1f", (double) count / 1000) + "k";
}
return countString;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment