|
@@ -1,16 +1,23 @@
|
|
|
package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
+import com.caimei365.commodity.components.RedisService;
|
|
|
import com.caimei365.commodity.mapper.SecondHandMapper;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
|
+import com.caimei365.commodity.model.dto.SecondDto;
|
|
|
+import com.caimei365.commodity.model.po.ProductImagePo;
|
|
|
+import com.caimei365.commodity.model.po.ProductPo;
|
|
|
+import com.caimei365.commodity.model.po.ProductSecondPo;
|
|
|
+import com.caimei365.commodity.model.vo.AddressVo;
|
|
|
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.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -19,7 +26,6 @@ import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.regex.Matcher;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -34,6 +40,9 @@ public class SecondHandServiceImpl implements SecondHandService {
|
|
|
private String domain;
|
|
|
@Resource
|
|
|
private SecondHandMapper secondHandMapper;
|
|
|
+ @Resource
|
|
|
+ private RedisService redisService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 二手商品列表
|
|
@@ -128,6 +137,239 @@ public class SecondHandServiceImpl implements SecondHandService {
|
|
|
return ResponseJson.success(second);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发布二手商品
|
|
|
+ *
|
|
|
+ * @param secondDto 对象内容描述{
|
|
|
+ * "secondHandType" : 二手商品分类,1二手仪器,2临期产品,3其他
|
|
|
+ * ,"instrumentType" : 二手仪器分类的类型,1轻光电、2重光电、3耗材配件(仅适用于二手仪器分类多个用英文逗号分分隔)
|
|
|
+ * ,"brandId" : 品牌Id
|
|
|
+ * ,"name" : 商品名称
|
|
|
+ * ,"fixedYears" : 出厂日期格式:2020年6月
|
|
|
+ * ,"maturityYears" : 产品到期日格式:2020年6月(仅适用于临期产品)
|
|
|
+ * ,"companyName" : 公司名称
|
|
|
+ * ,"price" : 交易价格
|
|
|
+ * ,"detailTalkFlag" : 是否启用详聊,1不开启,2开启(开启详聊不展示交易价)
|
|
|
+ * ,"normalPrice" : 市场价
|
|
|
+ * ,"originalPrice" : 采购价/原价(该二手原始购买价格)
|
|
|
+ * ,"stock" : 数量(等同库存)
|
|
|
+ * ,"productQuality" : 商品成色
|
|
|
+ * ,"contactName" : 联系人名字
|
|
|
+ * ,"contactMobile" : 联系方式
|
|
|
+ * ,"secondProductType" : 设备类型:1医美、2非医美
|
|
|
+ * ,"townId" : 县区ID
|
|
|
+ * ,"address" : 详细地址
|
|
|
+ * ,"image" : 图片信息
|
|
|
+ * ,"productDetails" : 商品详细信息
|
|
|
+ * ,"source" : 信息来源 1网站 2CRM 3后台
|
|
|
+ * }
|
|
|
+ * @param headers HttpHeaders
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson releaseSecondHand(SecondDto secondDto, HttpHeaders headers) {
|
|
|
+ // 打印IP
|
|
|
+ String ip = headers.getFirst("X-CLIENT-IP");
|
|
|
+ log.info("发布二手商品 X-CLIENT-IP : " + ip);
|
|
|
+ String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
+ if (StringUtils.isNotEmpty(ip)) {
|
|
|
+ Integer accessNumCount = 0;
|
|
|
+ boolean exists = redisService.exists(dateStr + ":releaseSecondHand-" + ip);
|
|
|
+ if (exists) {
|
|
|
+ accessNumCount = (Integer) redisService.get(dateStr + ":releaseSecondHand-" + ip);
|
|
|
+ if (accessNumCount >= 20) {
|
|
|
+ return ResponseJson.error("操作太频繁,今日已不能发布");
|
|
|
+ }
|
|
|
+ accessNumCount += 1;
|
|
|
+ } else {
|
|
|
+ accessNumCount = 1;
|
|
|
+ }
|
|
|
+ //以时间串+接口名称+ip和当前时间为key,设置有效期为24小时,限制每天操作次数20次
|
|
|
+ redisService.set(dateStr + ":releaseSecondHand-" + ip, accessNumCount, 86400L);
|
|
|
+ }
|
|
|
+ // 验证传入参数
|
|
|
+ String secondHandType = secondDto.getSecondHandType();
|
|
|
+ String instrumentType = secondDto.getInstrumentType();
|
|
|
+ Integer brandId = secondDto.getBrandId();
|
|
|
+ String name = secondDto.getName();
|
|
|
+ Double price = secondDto.getPrice();
|
|
|
+ Double normalPrice = secondDto.getNormalPrice();
|
|
|
+ Double originalPrice = secondDto.getOriginalPrice();
|
|
|
+ Integer stock = secondDto.getStock();
|
|
|
+ String productQuality = secondDto.getProductQuality();
|
|
|
+ String contactName = secondDto.getContactName();
|
|
|
+ String contactMobile = secondDto.getContactMobile();
|
|
|
+ String source = secondDto.getSource();
|
|
|
+ Integer townId = secondDto.getTownId();
|
|
|
+ String address = secondDto.getAddress();
|
|
|
+ // 此图片为逗号隔开的多张数据
|
|
|
+ String image = secondDto.getImage();
|
|
|
+ String maturityYears = secondDto.getMaturityYears();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(secondHandType)) {
|
|
|
+ return ResponseJson.error("参数异常:请选择分类");
|
|
|
+ } else if (StringUtils.equals("1", secondHandType)) {
|
|
|
+ if (StringUtils.isEmpty(instrumentType)) {
|
|
|
+ return ResponseJson.error("参数异常:请完善仪器分类");
|
|
|
+ }
|
|
|
+ } else if (StringUtils.equals("2", secondHandType)) {
|
|
|
+ // 选择临期产品的时候才需要设置
|
|
|
+ if (null == normalPrice || normalPrice <= 0) {
|
|
|
+ return ResponseJson.error("参数异常:请输入市场价");
|
|
|
+ }
|
|
|
+ if (null == originalPrice) {
|
|
|
+ return ResponseJson.error("参数异常:请输入采购价/原价");
|
|
|
+ }
|
|
|
+ if (null == stock) {
|
|
|
+ return ResponseJson.error("参数异常:请输入数量");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(maturityYears)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入产品到期日");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null == brandId) {
|
|
|
+ return ResponseJson.error("参数异常:请选择商品品牌");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入商品名称");
|
|
|
+ }
|
|
|
+ if (null == price || price <= 0) {
|
|
|
+ return ResponseJson.error("参数异常:请输入交易价");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(contactName)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入联系人姓名");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(contactMobile)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入联系方式");
|
|
|
+ }
|
|
|
+ if (null == townId) {
|
|
|
+ return ResponseJson.error("参数异常:请完善联系地址");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(address)) {
|
|
|
+ return ResponseJson.error("参数异常:请填写详细地址");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(image)) {
|
|
|
+ return ResponseJson.error("参数异常:请上传图片");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(productQuality)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入商品成色");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(source)) {
|
|
|
+ return ResponseJson.error("参数异常:请输入发布来源");
|
|
|
+ }
|
|
|
+ // 保存二手商品
|
|
|
+ return saveSecondHandProduct(secondDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseJson saveSecondHandProduct(SecondDto secondDto) {
|
|
|
+ // 设置日期时间格式
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String current = dateFormat.format(date);
|
|
|
+ // 图片
|
|
|
+ String[] images = secondDto.getImage().split(",");
|
|
|
+ // 组装数据
|
|
|
+ ProductPo product = new ProductPo();
|
|
|
+ product.setBrandId(secondDto.getBrandId());
|
|
|
+ product.setName(secondDto.getName());
|
|
|
+ product.setPrice(secondDto.getPrice());
|
|
|
+ product.setStock(secondDto.getStock());
|
|
|
+ product.setAliasName(secondDto.getName());
|
|
|
+ product.setNormalPrice(secondDto.getNormalPrice());
|
|
|
+ product.setMainImage(images[0]);
|
|
|
+ // 二手商品类型
|
|
|
+ product.setProductCategory(2);
|
|
|
+ product.setPreferredFlag(0);
|
|
|
+ // 默认发布到二手供应商
|
|
|
+ product.setShopId(1252);
|
|
|
+ product.setSellNumber(secondDto.getStock());
|
|
|
+ product.setCostPrice(0d);
|
|
|
+ product.setCostCheckFlag(1);
|
|
|
+ product.setHasSkuFlag(1);
|
|
|
+ // 商品状态默认待审核
|
|
|
+ product.setValidFlag(1);
|
|
|
+ product.setLadderPriceFlag(0);
|
|
|
+ product.setSortIndex(1);
|
|
|
+ product.setFeaturedFlag(0);
|
|
|
+ product.setByFlag(0);
|
|
|
+ product.setStep(1);
|
|
|
+ product.setActFlag(0);
|
|
|
+ product.setActStatus(0);
|
|
|
+ product.setFreePostFlag(1);
|
|
|
+ product.setProductType(0);
|
|
|
+ product.setMachineType(0);
|
|
|
+ product.setIncludedTax(0);
|
|
|
+ product.setRecommendType(0);
|
|
|
+ product.setInvoiceType(0);
|
|
|
+ product.setVisibility(3);
|
|
|
+ product.setAddTime(current);
|
|
|
+ product.setUpdateTime(current);
|
|
|
+ product.setOnlineTime(date);
|
|
|
+ product.setOfflineTime(date);
|
|
|
+ /* 保存商品表 */
|
|
|
+ secondHandMapper.insertProduct22222222222(product);
|
|
|
+ /* 保存商品图片信息*/
|
|
|
+ for (int i = 0; i < images.length; i++) {
|
|
|
+ ProductImagePo imagePo = new ProductImagePo();
|
|
|
+ imagePo.setProductId(product.getProductId());
|
|
|
+ imagePo.setShopId(1252);
|
|
|
+ imagePo.setAddTime(current);
|
|
|
+ imagePo.setImage(images[i]);
|
|
|
+ if (i == 0) {
|
|
|
+ imagePo.setMainFlag(1);
|
|
|
+ } else {
|
|
|
+ imagePo.setMainFlag(0);
|
|
|
+ }
|
|
|
+ secondHandMapper.insertProductImage(imagePo);
|
|
|
+ }
|
|
|
+ ProductSecondPo secondPo = new ProductSecondPo();
|
|
|
+ // 保存附赠详细信息关系
|
|
|
+ secondPo.setProductId(product.getProductId());
|
|
|
+ // 通过地址查询省市区
|
|
|
+ String provinceCityDistrict = "";
|
|
|
+ Integer townId = secondDto.getTownId();
|
|
|
+ secondPo.setTownId(townId);
|
|
|
+ if (null != townId) {
|
|
|
+ AddressVo address = secondHandMapper.getAddressInfo(townId);
|
|
|
+ if (null != address) {
|
|
|
+ provinceCityDistrict = address.getProvince() + "/" + address.getCity() + "/" + address.getTown();
|
|
|
+ secondPo.setProvinceCityDistrict(provinceCityDistrict);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 默认设置未出售
|
|
|
+ secondPo.setSold(0);
|
|
|
+ // 付款状态1:待支付、2已付款
|
|
|
+ secondPo.setPayStatus(1);
|
|
|
+ secondPo.setPayAmount(0d);
|
|
|
+ secondPo.setPayType("");
|
|
|
+ secondPo.setSubmitDate(date);
|
|
|
+ secondPo.setViewingNum(0);
|
|
|
+ secondPo.setDockingPeopleName(secondDto.getDockingPeopleName());
|
|
|
+ if (StringUtils.isNotBlank(secondDto.getDockingPeopleName())) {
|
|
|
+ secondPo.setPublisher(secondDto.getDockingPeopleName());
|
|
|
+ } else {
|
|
|
+ secondPo.setPublisher(secondDto.getContactName());
|
|
|
+ }
|
|
|
+ secondPo.setSecondHandType(secondDto.getSecondHandType());
|
|
|
+ secondPo.setInstrumentType(secondDto.getInstrumentType());
|
|
|
+ secondPo.setFixedYears(secondDto.getFixedYears());
|
|
|
+ secondPo.setMaturityYears(secondDto.getMaturityYears());
|
|
|
+ secondPo.setCompanyName(secondDto.getCompanyName());
|
|
|
+ secondPo.setDetailTalkFlag(secondDto.getDetailTalkFlag());
|
|
|
+ secondPo.setOriginalPrice(secondDto.getOriginalPrice());
|
|
|
+ secondPo.setContactName(secondDto.getContactName());
|
|
|
+ secondPo.setContactMobile(secondDto.getContactMobile());
|
|
|
+ secondPo.setDockingPeopleMobile(secondDto.getDockingPeopleName());
|
|
|
+ secondPo.setSecondProductType(secondDto.getSecondProductType());
|
|
|
+ secondPo.setAddress(secondDto.getAddress());
|
|
|
+ secondPo.setProductQuality(secondDto.getProductQuality());
|
|
|
+ secondPo.setProductDetails(secondDto.getProductDetails());
|
|
|
+ secondPo.setSource(secondDto.getSource());
|
|
|
+ /* 保存商品二手附加详细信息 */
|
|
|
+ secondHandMapper.saveSencondHandProduct(secondPo);
|
|
|
+ return ResponseJson.success(secondPo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 金额格式化,千分位
|
|
|
*
|