|
@@ -0,0 +1,159 @@
|
|
|
|
+package com.caimei365.commodity.service.impl;
|
|
|
|
+
|
|
|
|
+import com.caimei365.commodity.mapper.SecondHandMapper;
|
|
|
|
+import com.caimei365.commodity.model.ResponseJson;
|
|
|
|
+import com.caimei365.commodity.model.vo.PaginationVo;
|
|
|
|
+import com.caimei365.commodity.model.vo.SecondDetailVo;
|
|
|
|
+import com.caimei365.commodity.model.vo.SecondListVo;
|
|
|
|
+import com.caimei365.commodity.service.SecondHandService;
|
|
|
|
+import com.caimei365.commodity.utils.ImageUtils;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Description
|
|
|
|
+ *
|
|
|
|
+ * @author : Charles
|
|
|
|
+ * @date : 2021/4/14
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class SecondHandServiceImpl implements SecondHandService {
|
|
|
|
+ @Value("${caimei.wwwDomain}")
|
|
|
|
+ private String domain;
|
|
|
|
+ @Resource
|
|
|
|
+ private SecondHandMapper secondHandMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 二手商品列表
|
|
|
|
+ *
|
|
|
|
+ * @param secondHandType 二手商品分类,1二手仪器,2临期产品,3其他
|
|
|
|
+ * @param instrumentType 二手仪器分类的类型,1轻光电、2重光电、3耗材配件
|
|
|
|
+ * @param name 二手商品名称搜索关键词
|
|
|
|
+ * @param pageNum 页码
|
|
|
|
+ * @param pageSize 每页数量
|
|
|
|
+ * @return List<SecondHandVo>
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<PaginationVo<SecondListVo>> getSecondHandList(Integer secondHandType, Integer instrumentType, String name, int pageNum, int pageSize) {
|
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
|
+ List<SecondListVo> secondList = secondHandMapper.getSeconHandList(secondHandType, instrumentType, name);
|
|
|
|
+ if (!CollectionUtils.isEmpty(secondList)) {
|
|
|
|
+ // 初始化商品产品标签
|
|
|
|
+ int initNewNum = 0;
|
|
|
|
+ for (SecondListVo second : secondList) {
|
|
|
|
+ initNewNum++;
|
|
|
|
+ if (initNewNum > 10) {
|
|
|
|
+ second.setNewAdded(0);
|
|
|
|
+ } else {
|
|
|
|
+ second.setNewAdded(1);
|
|
|
|
+ }
|
|
|
|
+ // 优化地址信息
|
|
|
|
+ String provinceCityDistrict = second.getProvinceCityDistrict();
|
|
|
|
+ provinceCityDistrict = provinceCityDistrict.replace("/", "").replace("市辖区", "");
|
|
|
|
+ second.setProvinceCityDistrict(provinceCityDistrict);
|
|
|
|
+ //价格千分位处理
|
|
|
|
+ second.setPriceStr(priceFormatStr(second.getPrice()));
|
|
|
|
+ // 处理时间格式化
|
|
|
|
+ second.setOnLineDateStr(dateFormatStr(second.getOnLineDate()));
|
|
|
|
+ // 获取二手商品图片
|
|
|
|
+ List<String> images = secondHandMapper.getImageByProductId(second.getProductId());
|
|
|
|
+ images.forEach(img -> {
|
|
|
|
+ img = ImageUtils.getImageURL("product", img, 0, domain);
|
|
|
|
+ });
|
|
|
|
+ second.setImageList(images);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ PaginationVo<SecondListVo> pageData = new PaginationVo<SecondListVo>(secondList);
|
|
|
|
+ return ResponseJson.success(pageData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取二手商品详情
|
|
|
|
+ *
|
|
|
|
+ * @param productId 商品表的商品Id
|
|
|
|
+ * @return SecondDetailVo
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<SecondDetailVo> getSecondHandDetail(Integer productId) {
|
|
|
|
+ SecondDetailVo second = secondHandMapper.getSecondHandDetail(productId);
|
|
|
|
+ // 优化地址信息
|
|
|
|
+ String provinceCityDistrict = second.getProvinceCityDistrict();
|
|
|
|
+ provinceCityDistrict = provinceCityDistrict.replace("/", "").replace("市辖区", "");
|
|
|
|
+ second.setProvinceCityDistrict(provinceCityDistrict);
|
|
|
|
+ //价格千分位处理
|
|
|
|
+ second.setPriceStr(priceFormatStr(second.getPrice()));
|
|
|
|
+ second.setNormalPriceStr(priceFormatStr(second.getNormalPrice()));
|
|
|
|
+ second.setOriginalPriceStr(priceFormatStr(second.getOriginalPrice()));
|
|
|
|
+ // 处理时间格式化
|
|
|
|
+ second.setOnLineDateStr(dateFormatStr(second.getOnLineDate()));
|
|
|
|
+ // 获取二手商品图片
|
|
|
|
+ List<String> images = secondHandMapper.getImageByProductId(second.getProductId());
|
|
|
|
+ // 获取二手商品图片(处理老的非全路径图片)
|
|
|
|
+ images.forEach(img -> {
|
|
|
|
+ img = ImageUtils.getImageURL("product", img, 0, domain);
|
|
|
|
+ });
|
|
|
|
+ second.setImageList(images);
|
|
|
|
+ // 初始商品分类
|
|
|
|
+ String typeStr = "";
|
|
|
|
+ String secondHandType = second.getSecondHandType();
|
|
|
|
+ if ("1".equals(secondHandType)) {
|
|
|
|
+ typeStr += "二手仪器";
|
|
|
|
+ } else if ("2".equals(secondHandType)) {
|
|
|
|
+ typeStr += "临期产品";
|
|
|
|
+ } else {
|
|
|
|
+ typeStr += "其他";
|
|
|
|
+ }
|
|
|
|
+ // 二手仪器分类
|
|
|
|
+ String instrumentType = second.getInstrumentType();
|
|
|
|
+ if ("1".equals(instrumentType)) {
|
|
|
|
+ typeStr += "-轻光电";
|
|
|
|
+ } else if ("2".equals(instrumentType)) {
|
|
|
|
+ typeStr += "-重光电";
|
|
|
|
+ } else if ("3".equals(instrumentType)) {
|
|
|
|
+ typeStr += "-耗材配件";
|
|
|
|
+ }
|
|
|
|
+ second.setTypeStr(typeStr);
|
|
|
|
+ return ResponseJson.success(second);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 金额格式化,千分位
|
|
|
|
+ *
|
|
|
|
+ * @param number 金额
|
|
|
|
+ * @return str
|
|
|
|
+ */
|
|
|
|
+ private String priceFormatStr(Double number) {
|
|
|
|
+ number = (number == null && number > 0d) ? number : 0d;
|
|
|
|
+ DecimalFormat df = new DecimalFormat("##,##0.00");
|
|
|
|
+ return df.format(number);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 时间格式化
|
|
|
|
+ *
|
|
|
|
+ * @param date 时间
|
|
|
|
+ * @return str
|
|
|
|
+ */
|
|
|
|
+ private String dateFormatStr(Date date) {
|
|
|
|
+ if (null != date) {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
|
|
|
|
+ return sdf.format(date);
|
|
|
|
+ } else {
|
|
|
|
+ return "时间未知";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|