提交 affc4772 authored 作者: zgy's avatar zgy

Merge remote-tracking branch 'origin/master'

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