提交 676c7994 authored 作者: 梁业锦's avatar 梁业锦 💬 提交者: 何春颖

- 方法改为返回集合

上级 8378c7f1
......@@ -69,7 +69,7 @@ public class ShopifyController {
*
* @return 保存商品数据
*/
@PostMapping("/save")
/*@PostMapping("/save")
public R save() {
// 记录页数的
int pageSize = 0;
......@@ -213,8 +213,8 @@ public class ShopifyController {
tbCfGoodstypeDao.save(tbCfGoodstypeEntity);
} else {
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();
*//*TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);*//*
*//*oods_type_id = tbCfGoodstypeEntity.getGoodstypeId();*//*
}
String goodsTwoId = IdUtil.simpleUUID(); // 商品二级分类id
......@@ -303,7 +303,7 @@ public class ShopifyController {
// 记录页数
pageSize++;
}
}
}*/
/**
* 补录失败的商品
......
......@@ -2,6 +2,8 @@ package com.platform.dao;
import com.platform.entity.TbCategoryTemplateEntity;
import java.util.List;
/**
* Dao
*
......@@ -10,6 +12,6 @@ import com.platform.entity.TbCategoryTemplateEntity;
*/
public interface TbCategoryTemplateDao extends BaseDao<TbCategoryTemplateEntity> {
TbCategoryTemplateEntity queryByDesc(String category_desc);
List<TbCategoryTemplateEntity> queryByDesc(String category_desc);
}
......@@ -14,5 +14,5 @@ public interface TbCfDescripitonDao extends BaseDao<TbCfDescripitonEntity> {
List<TbCfDescripitonEntity> queryByItemTypeTwo(String id);
TbCfDescripitonEntity queryByDescriptionName(String descripition_name);
List<TbCfDescripitonEntity> queryByDescriptionName(String descripition_name);
}
......@@ -17,5 +17,5 @@ public interface TbCfGoodstwotypeDao extends BaseDao<TbCfGoodstwotypeEntity> {
List<TbCfGoodstwotypeEntity> queryByTypeId(String typeId);
TbCfGoodstwotypeEntity queryTitle(String title);
List<TbCfGoodstwotypeEntity> queryTitle(String title);
}
......@@ -2,6 +2,8 @@ package com.platform.dao;
import com.platform.entity.TbCfGoodstypeEntity;
import java.util.List;
/**
* Dao
*
......@@ -16,6 +18,6 @@ public interface TbCfGoodstypeDao extends BaseDao<TbCfGoodstypeEntity> {
* @param title 分类名称
* @return TbCfGoodstypeEntity
*/
TbCfGoodstypeEntity queryByTitle(String title);
List<TbCfGoodstypeEntity> queryByTitle(String title);
}
......@@ -33,10 +33,9 @@
`create_time`,
`update_time`
from tb_category_template
where category_desc = #{category_desc}
where category_name = #{category_name}
</select>
<select id="queryList" resultType="com.platform.entity.TbCategoryTemplateEntity">
select
`id`,
......
......@@ -116,7 +116,6 @@ public class ImpartCode {
}
}
}
}
/**
......@@ -161,37 +160,6 @@ public class ImpartCode {
// 商品详情
int optionNum = 0;
StringBuilder optionBuilder = new StringBuilder();
StringBuilder imageBuilder = new StringBuilder();
JSONArray imagesArr = productsObj.getJSONArray("images");
for (int j = 0; j < imagesArr.size(); j++) {
JSONObject imageObj = imagesArr.getJSONObject(j);
// 上传图片
String skuSrc = imageObj.getString("src");
InputStream skuInputStream = getImageStream(skuSrc);
byte[] skuBytes = toByteArray(skuInputStream);
String url = OssUtil.upload(skuBytes, id + "_sku_" + j + ".jpg", "image");
// 拼接富文本的 HTML
imageBuilder.append("<p><img src=\"")
.append(url).append("\" title=\"")
.append(IdUtil.randomUUID()).append("_350x350")
.append(IdUtil.simpleUUID()).append(".jpg\"/></p>");
System.err.println("富文本图片内容:" + imageBuilder.toString());
}
TbCfItemDescEntity itemDescEntity = tbCfItemDescDao.queryObject(itemId);
if (itemDescEntity == null) {
itemDescEntity = new TbCfItemDescEntity();
itemDescEntity.setItemId(itemId);
itemDescEntity.setItemDesc(imageBuilder.toString());
itemDescEntity.setCreateTime(date);
tbCfItemDescDao.save(itemDescEntity);
}
// 上传图片获取主图
String src = productsObj.getJSONObject("image").getString("src");
InputStream inputStream = getImageStream(src);
byte[] bytes = toByteArray(inputStream);
String url = OssUtil.upload(bytes, id + "_station.jpg", "image");
System.err.println("主图的链接为: " + url);
// 商品的属性
JSONArray optionsArr = productsObj.getJSONArray("options");
......@@ -216,7 +184,7 @@ public class ImpartCode {
categoryEntity.setOption("option" + optionNum);
// 保存属性名
String categoryId = IdUtil.simpleUUID();
if (tbCategoryTemplateDao.queryByDesc(optionName) == null) {
if (tbCategoryTemplateDao.queryByDesc(optionName).size() == 0) {
TbCategoryTemplateEntity tbCategoryTemplateEntity = new TbCategoryTemplateEntity();
tbCategoryTemplateEntity.setId(categoryId);
tbCategoryTemplateEntity.setCategoryDesc(optionName);
......@@ -224,8 +192,10 @@ public class ImpartCode {
tbCategoryTemplateEntity.setCategoryName(optionName);
tbCategoryTemplateEntity.setUpdateTime(date);
tbCategoryTemplateEntity.setUpdateTime(date);
if (tbCategoryTemplateDao.queryByDesc(optionName).size() == 0) {
tbCategoryTemplateDao.save(tbCategoryTemplateEntity);
}
}
StringBuilder categoryBuilder = new StringBuilder();
JSONArray valuesArr = optionObj.getJSONArray("values");
......@@ -297,18 +267,24 @@ public class ImpartCode {
// 保存一级分类名
String goods_type_id = IdUtil.simpleUUID();
if (tbCfGoodstypeDao.queryByTitle(product_type) == null) { // 如果分类名已存在则不保存
if (tbCfGoodstypeDao.queryByTitle(product_type).size() == 0) { // 如果分类名已存在则不保存
TbCfGoodstypeEntity tbCfGoodstypeEntity = new TbCfGoodstypeEntity();
tbCfGoodstypeEntity.setGoodstypeId(goods_type_id);
tbCfGoodstypeEntity.setGoodstypeTitle(product_type);
tbCfGoodstypeEntity.setGoodstypeSort(tbCfGoodstypeDao.queryTotal() + 1);
product_type = product_type.replaceAll(" ", "-");
tbCfGoodstypeEntity.setGoodstypeUrl("https://www.afrieshop.com/collections/" + product_type);
if (tbCfGoodstypeDao.queryByTitle(product_type).size() == 0) { // 如果分类名已存在则不保存
tbCfGoodstypeDao.save(tbCfGoodstypeEntity);
} else {
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();
List<TbCfGoodstypeEntity> tbCfGoodstypeEntity1 = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity1.get(0).getGoodstypeId();
}
} else {
// 如果已存在一级分类名,则使用已存在的 id
List<TbCfGoodstypeEntity> tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.get(0).getGoodstypeId();
}
// 解析二三级分类名
......@@ -325,29 +301,39 @@ public class ImpartCode {
// 保存二级分类名
String goodsTwoId = IdUtil.simpleUUID();
if (tbCfGoodstwotypeDao.queryTitle(tags) == null) {
if (tbCfGoodstwotypeDao.queryTitle(tags).size() == 0) {
TbCfGoodstwotypeEntity tbCfGoodstwotypeEntity = new TbCfGoodstwotypeEntity();
tbCfGoodstwotypeEntity.setGoodstwotypeId(goodsTwoId);
tbCfGoodstwotypeEntity.setGoodstwotypeTitle(tags);
tbCfGoodstwotypeEntity.setGoodstypeId(goods_type_id);
if (tbCfGoodstwotypeDao.queryTitle(tags).size() == 0) {
tbCfGoodstwotypeDao.save(tbCfGoodstwotypeEntity);
} else {
TbCfGoodstwotypeEntity tbCfGoodstwotypeEntity = tbCfGoodstwotypeDao.queryTitle(tags);
goodsTwoId = tbCfGoodstwotypeEntity.getGoodstwotypeId();
List<TbCfGoodstwotypeEntity> tbCfGoodstwotypeEntity1 = tbCfGoodstwotypeDao.queryTitle(tags);
goodsTwoId = tbCfGoodstwotypeEntity1.get(0).getGoodstwotypeId();
}
} else {
List<TbCfGoodstwotypeEntity> tbCfGoodstwotypeEntity = tbCfGoodstwotypeDao.queryTitle(tags);
goodsTwoId = tbCfGoodstwotypeEntity.get(0).getGoodstwotypeId();
}
// 保存三级分类名(品名)
String goodsThreeId = IdUtil.simpleUUID();
if (tbCfDescripitonDao.queryByDescriptionName(three) == null) {
if (tbCfDescripitonDao.queryByDescriptionName(three).size() == 0) {
TbCfDescripitonEntity tbCfDescripitonEntity = new TbCfDescripitonEntity();
tbCfDescripitonEntity.setDescripitionId(goodsThreeId);
tbCfDescripitonEntity.setDescripitionName(three);
tbCfDescripitonEntity.setGoodstypeId(goods_type_id);
tbCfDescripitonEntity.setGoodstwotypeId(goodsTwoId);
if (tbCfDescripitonDao.queryByDescriptionName(three).size() == 0) {
tbCfDescripitonDao.save(tbCfDescripitonEntity);
} else {
TbCfDescripitonEntity tbCfDescripitonEntity = tbCfDescripitonDao.queryByDescriptionName(three);
goodsThreeId = tbCfDescripitonEntity.getDescripitionId();
List<TbCfDescripitonEntity> tbCfDescripitonEntity1 = tbCfDescripitonDao.queryByDescriptionName(three);
goodsThreeId = tbCfDescripitonEntity1.get(0).getDescripitionId();
}
} else {
List<TbCfDescripitonEntity> tbCfDescripitonEntity = tbCfDescripitonDao.queryByDescriptionName(three);
goodsThreeId = tbCfDescripitonEntity.get(0).getDescripitionId();
}
// 保存商品的主体信息
......@@ -364,10 +350,42 @@ public class ImpartCode {
tbCfStationItem.setItemDescritionId(goodsThreeId);
tbCfStationItem.setItemTags(product_type + "," + tags + "," + three);
tbCfStationItem.setItemTop("N");
// 上传图片获取主图
String src = productsObj.getJSONObject("image").getString("src");
InputStream inputStream = getImageStream(src);
byte[] bytes = toByteArray(inputStream);
String url = OssUtil.upload(bytes, id + "_station.jpg", "image");
System.err.println("主图的链接为: " + url);
tbCfStationItem.setItemImg(url);
tbCfStationItem.setEnableFlag(2);
tbCfStationItemDao.save(tbCfStationItem);
StringBuilder imageBuilder = new StringBuilder();
JSONArray imagesArr = productsObj.getJSONArray("images");
for (int j = 0; j < imagesArr.size(); j++) {
JSONObject imageObj = imagesArr.getJSONObject(j);
// 上传图片
String skuSrc = imageObj.getString("src");
InputStream skuInputStream = getImageStream(skuSrc);
byte[] skuBytes = toByteArray(skuInputStream);
String skuUrl = OssUtil.upload(skuBytes, id + "_sku_" + j + ".jpg", "image");
// 拼接富文本的 HTML
imageBuilder.append("<p><img src=\"")
.append(skuUrl).append("\" title=\"")
.append(IdUtil.randomUUID()).append("_350x350")
.append(IdUtil.simpleUUID()).append(".jpg\"/></p>");
System.err.println("富文本图片内容:" + imageBuilder.toString());
}
TbCfItemDescEntity itemDescEntity = tbCfItemDescDao.queryObject(itemId);
if (itemDescEntity == null) {
itemDescEntity = new TbCfItemDescEntity();
itemDescEntity.setItemId(itemId);
itemDescEntity.setItemDesc(imageBuilder.toString());
itemDescEntity.setCreateTime(date);
tbCfItemDescDao.save(itemDescEntity);
}
} catch (Exception e) {
e.printStackTrace();
// 记录失败的产品记录
......
......@@ -158,20 +158,20 @@ public class TestApi {
.execute().body();
JSONObject jsonObject = JSONObject.fromObject(result);
// 第一次导入
once(result);
// once(result);
// 解析请求头,获取到下一页的 url
String headerLink = HttpRequest.get(link)
.header("Authorization", "Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA=")
.execute().header("link");
headerLink = headerLink.split(";")[0].replaceAll("<", "").replaceAll(">", "");
// 无限导入
unlimited(headerLink);
// unlimited(headerLink);
}
/**
* 第一遍循环导入
*/
private void once(String data) {
/* private void once(String data) {
// 记录页数的
int productCount = 0;
// json 化返回数据
......@@ -305,8 +305,8 @@ public class TestApi {
tbCfGoodstypeDao.save(tbCfGoodstypeEntity);
} else {
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();
*//*TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);*//*
*//*goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();*//*
}
// 二级分类名
......@@ -423,12 +423,12 @@ public class TestApi {
tbProductMissDao.save(tbProductMissEntity);
}
}
}
}*/
/**
* 无限循环导入
*/
private void unlimited(String link) {
/*private void unlimited(String link) {
// 记录页数的
int pageSize = 0;
int productCount = 1;
......@@ -570,8 +570,8 @@ public class TestApi {
tbCfGoodstypeDao.save(tbCfGoodstypeEntity);
} else {
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();
*//* TbCfGoodstypeEntity tbCfGoodstypeEntity = tbCfGoodstypeDao.queryByTitle(product_type);
goods_type_id = tbCfGoodstypeEntity.getGoodstypeId();*//*
}
// 二级分类名
......@@ -678,7 +678,7 @@ public class TestApi {
pageSize++;
}
}
*/
/**
* 通过URL获取网络图片
* 获取网络图片流
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论