|
@@ -13,7 +13,6 @@ import com.caimei365.commodity.model.vo.*;
|
|
|
import com.caimei365.commodity.service.SecondHandService;
|
|
|
import com.caimei365.commodity.utils.ImageUtils;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
-import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -24,6 +23,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -472,6 +472,82 @@ public class SecondHandServiceImpl implements SecondHandService {
|
|
|
return "时间未知";
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取是否在固定天数以内
|
|
|
+ *
|
|
|
+ * @param addtime 需要判断的时间
|
|
|
+ * @param now 当前时间
|
|
|
+ * @param day 多少天内
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isLatestWeek(Date addtime, Date now, int day) {
|
|
|
+ Calendar calendar = Calendar.getInstance(); //得到日历
|
|
|
+ calendar.setTime(now);//把当前时间赋给日历
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -day); //设置为day天前
|
|
|
+ Date before7days = calendar.getTime(); //得到day天前的时间
|
|
|
+ if (before7days.getTime() < addtime.getTime()) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算二手商品浏览量
|
|
|
+ *
|
|
|
+ * @param productId 商品Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Integer> updateSecondHandViews(Integer productId) {
|
|
|
+ SecondDetailVo second = secondHandMapper.getSecondHandDetail(productId);
|
|
|
+ Integer viewingNum = 0;
|
|
|
+ if (null != second) {
|
|
|
+ viewingNum = second.getViewingNum();
|
|
|
+ /* 更新新浏览量规则
|
|
|
+ * 7天内,每被浏览一次,浏览数添加一个20以内的随机数
|
|
|
+ * 14天内,每被浏览一次,浏览数添加一个10以内的随机数
|
|
|
+ * 30天内,每被浏览一次,浏览数添加一个5以内的随机数
|
|
|
+ * 30天以外,每被浏览一次,浏览数添加1
|
|
|
+ */
|
|
|
+ Date onLine = second.getOnLineDate();
|
|
|
+ int random = 1;
|
|
|
+ if (null != onLine) {
|
|
|
+ boolean latestWeek = isLatestWeek(onLine, new Date(), 7);
|
|
|
+ boolean latestHalfMonth = isLatestWeek(onLine, new Date(), 14);
|
|
|
+ boolean latestMonth = isLatestWeek(onLine, new Date(), 30);
|
|
|
+ if (latestWeek) {
|
|
|
+ random = (int) (Math.random() * 20 + 1);
|
|
|
+ } else if (latestHalfMonth) {
|
|
|
+ random = (int) (Math.random() * 10 + 1);
|
|
|
+ } else if (latestMonth) {
|
|
|
+ random = (int) (Math.random() * 5 + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != viewingNum) {
|
|
|
+ viewingNum = viewingNum + random;
|
|
|
+ second.setViewingNum(viewingNum);
|
|
|
+ } else {
|
|
|
+ viewingNum = random;
|
|
|
+ second.setViewingNum(random);
|
|
|
+ }
|
|
|
+ secondHandMapper.updateSecondHandViews(second);
|
|
|
+ return ResponseJson.success(viewingNum);
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("二手商品异常!", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 二手商品-相关推荐
|
|
|
+ *
|
|
|
+ * @param productId 商品Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<SecondListVo>> getSecondRecommends(Integer productId) {
|
|
|
+ List<SecondListVo> recommendList = secondHandMapper.getSecondRecommends(productId);
|
|
|
+ for (SecondListVo product : recommendList) {
|
|
|
+ product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
|
|
|
+ }
|
|
|
+ return ResponseJson.success(recommendList);
|
|
|
+ }
|
|
|
}
|