提交 67591291 authored 作者: wudepeng's avatar wudepeng

商品导入

上级 deb656b2
package com.example.afrishop_v3.config; //package com.example.afrishop_v3.config;
//
import com.example.afrishop_v3.models.Token; //import com.example.afrishop_v3.models.Token;
import com.example.afrishop_v3.repository.TokenRepository; //import com.example.afrishop_v3.repository.TokenRepository;
import com.example.afrishop_v3.util.PayPalUtil; //import com.example.afrishop_v3.util.PayPalUtil;
import com.paypal.base.codec.binary.Base64; //import com.paypal.base.codec.binary.Base64;
import com.paypal.base.rest.APIContext; //import com.paypal.base.rest.APIContext;
import com.paypal.base.rest.OAuthTokenCredential; //import com.paypal.base.rest.OAuthTokenCredential;
import com.paypal.base.rest.PayPalRESTException; //import com.paypal.base.rest.PayPalRESTException;
//
import net.sf.json.JSONObject; //import net.sf.json.JSONObject;
import org.apache.commons.lang3.builder.ToStringExclude; //import org.apache.commons.lang3.builder.ToStringExclude;
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*; //import org.springframework.context.annotation.*;
//
//
import java.io.IOException; //import java.io.IOException;
import java.io.UnsupportedEncodingException; //import java.io.UnsupportedEncodingException;
import java.util.*; //import java.util.*;
import java.util.concurrent.*; //import java.util.concurrent.*;
//
//
@Configuration //@Configuration
public class PaypalConfig { //public class PaypalConfig {
//
@Value("${paypal.client_app}") // @Value("${paypal.client_app}")
private String clientId; // private String clientId;
//
@Value("${paypal.client_secret}") // @Value("${paypal.client_secret}")
private String clientSecret; // private String clientSecret;
//
@Value("${paypal.mode}") // @Value("${paypal.mode}")
private String mode; // private String mode;
//
//
@Bean // @Bean
public Map<String, String> paypalSdkConfig() { // public Map<String, String> paypalSdkConfig() {
Map<String, String> sdkConfig = new HashMap<>(); // Map<String, String> sdkConfig = new HashMap<>();
sdkConfig.put("mode", mode); // sdkConfig.put("mode", mode);
return sdkConfig; // return sdkConfig;
} // }
//
//
@Bean // @Bean
public OAuthTokenCredential authTokenCredential() { // public OAuthTokenCredential authTokenCredential() {
return new OAuthTokenCredential(clientId, clientSecret, paypalSdkConfig()); // return new OAuthTokenCredential(clientId, clientSecret, paypalSdkConfig());
} // }
//
@Bean // @Bean
public APIContext apiContext() throws PayPalRESTException { // public APIContext apiContext() throws PayPalRESTException {
APIContext apiContext = new APIContext(authTokenCredential().getAccessToken()); // APIContext apiContext = new APIContext(authTokenCredential().getAccessToken());
apiContext.setConfigurationMap(paypalSdkConfig()); // apiContext.setConfigurationMap(paypalSdkConfig());
return apiContext; // return apiContext;
} // }
//
//
} //}
package com.example.afrishop_v3.enums;
public enum CategoryEnum {
WOMEN(1,"Women"),
CURVE(3,"Curve+Plus"),
MEN(5,"Men"),
KIDS(4,"Kids");
private Integer categoryId;
private String categoryName;
CategoryEnum(Integer categoryId, String categoryName){
this.categoryId= categoryId;
this.categoryName= categoryName;
}
public Integer getCategoryId() {
return categoryId;
}
public String getCategoryName() {
return categoryName;
}
}
...@@ -63,6 +63,8 @@ public class TbCfDescripiton{ ...@@ -63,6 +63,8 @@ public class TbCfDescripiton{
*/ */
private String twoType; private String twoType;
private String tempId;
private Integer sort; private Integer sort;
public Integer getSort() { public Integer getSort() {
......
...@@ -19,6 +19,9 @@ import java.util.Date; ...@@ -19,6 +19,9 @@ import java.util.Date;
@Data @Data
public class TbCfExpressTemplate{ public class TbCfExpressTemplate{
/** /**
* 模板id * 模板id
*/ */
...@@ -89,6 +92,13 @@ public class TbCfExpressTemplate{ ...@@ -89,6 +92,13 @@ public class TbCfExpressTemplate{
*/ */
private Date updateTime; private Date updateTime;
public TbCfExpressTemplate() {
}
public TbCfExpressTemplate(String templateId) {
this.templateId = templateId;
}
/** /**
* 设置:模板id * 设置:模板id
*/ */
......
...@@ -41,6 +41,8 @@ public class TbCfGoodstwotype{ ...@@ -41,6 +41,8 @@ public class TbCfGoodstwotype{
*/ */
private String goodstwotypeUrl; private String goodstwotypeUrl;
private String tempId;
@Transient @Transient
private boolean autoLoad = false; private boolean autoLoad = false;
......
...@@ -2,6 +2,7 @@ package com.example.afrishop_v3.models; ...@@ -2,6 +2,7 @@ package com.example.afrishop_v3.models;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.data.relational.core.sql.In;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
...@@ -41,6 +42,11 @@ public class TbCfGoodstype{ ...@@ -41,6 +42,11 @@ public class TbCfGoodstype{
*/ */
private String goodstypeImage; private String goodstypeImage;
/**
* 临时ID
*/
private Integer tempId;
/** /**
* 设置:商品分类Id * 设置:商品分类Id
*/ */
......
...@@ -93,7 +93,7 @@ public class TbCfStationItem { ...@@ -93,7 +93,7 @@ public class TbCfStationItem {
/** /**
* 是否置顶 Y:是 N:否 * 是否置顶 Y:是 N:否
*/ */
private String itemTop; private Integer itemTop;
/** /**
* 供应商 * 供应商
*/ */
...@@ -127,6 +127,16 @@ public class TbCfStationItem { ...@@ -127,6 +127,16 @@ public class TbCfStationItem {
private String handled; private String handled;
private String tempId;
public String getTempId() {
return tempId;
}
public void setTempId(String tempId) {
this.tempId = tempId;
}
@JsonIgnore @JsonIgnore
@ManyToOne @ManyToOne
@JoinColumn(columnDefinition = "template", name = "template") @JoinColumn(columnDefinition = "template", name = "template")
...@@ -394,19 +404,7 @@ public class TbCfStationItem { ...@@ -394,19 +404,7 @@ public class TbCfStationItem {
return itemSku; return itemSku;
} }
/**
* 设置:是否置顶 Y:是 N:否
*/
public void setItemTop(String itemTop) {
this.itemTop = itemTop;
}
/**
* 获取:是否置顶 Y:是 N:否
*/
public String getItemTop() {
return itemTop;
}
/** /**
* 设置:供应商 * 设置:供应商
......
package com.example.afrishop_v3.repository; package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.TbCfDescripiton; import com.example.afrishop_v3.models.TbCfDescripiton;
import com.example.afrishop_v3.models.TbCfGoodstwotype;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List; import java.util.List;
...@@ -10,4 +12,9 @@ public interface TbCfDescripitonRepository extends PagingAndSortingRepository<Tb ...@@ -10,4 +12,9 @@ public interface TbCfDescripitonRepository extends PagingAndSortingRepository<Tb
List<TbCfDescripiton> findAllByGoodstwotypeIdOrderBySort(String categoryTwo); List<TbCfDescripiton> findAllByGoodstwotypeIdOrderBySort(String categoryTwo);
int countByGoodstwotypeId(String id); int countByGoodstwotypeId(String id);
boolean existsByDescripitionNameAndTempId(String name,String tempId);
TbCfDescripiton findFirstByDescripitionNameAndTempId(String name,String tempId);
} }
package com.example.afrishop_v3.repository; package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.TbCfGoodstwotype; import com.example.afrishop_v3.models.TbCfGoodstwotype;
import com.example.afrishop_v3.models.TbCfGoodstype;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List; import java.util.List;
...@@ -10,4 +12,11 @@ public interface TbCfGoodstwotypeRepository extends PagingAndSortingRepository<T ...@@ -10,4 +12,11 @@ public interface TbCfGoodstwotypeRepository extends PagingAndSortingRepository<T
int countByGoodstypeId(String id); int countByGoodstypeId(String id);
@Query(value = "select max(sort) from TbCfGoodstwotype where goodstypeId=:goodstypeId")
int findMaxSort(String goodstypeId);
boolean existsByGoodstwotypeTitleAndTempId(String name,String tempId);
TbCfGoodstwotype findFirstByGoodstwotypeTitleAndTempId(String name,String tempId);
} }
package com.example.afrishop_v3.repository; package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.TbCfGoodstype; import com.example.afrishop_v3.models.TbCfGoodstype;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
public interface TbCfGoodstypeRepository extends PagingAndSortingRepository<TbCfGoodstype,String> { public interface TbCfGoodstypeRepository extends PagingAndSortingRepository<TbCfGoodstype,String> {
@Query(value = "select max(goodstypeSort) from TbCfGoodstype")
int findMaxSort();
boolean existsByGoodstypeTitle(String name);
TbCfGoodstype findByGoodstypeTitle(String name);
} }
...@@ -62,4 +62,7 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb ...@@ -62,4 +62,7 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
@Transactional @Transactional
int updateItmeImg(@Param("itemImg") String itemImg, @Param("itemId") String itemId); int updateItmeImg(@Param("itemImg") String itemImg, @Param("itemId") String itemId);
// @Query("select i from #{#entityName} i where tempId is not null")
List<TbCfStationItem> findAllByTempIdIsNotNull();
} }
...@@ -34,6 +34,7 @@ public class PayPalUtil { ...@@ -34,6 +34,7 @@ public class PayPalUtil {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
String string = response.body().string(); String string = response.body().string();
System.out.println("================"+string);
net.sf.json.JSONObject jsonObject = JSONObject.fromObject(string); net.sf.json.JSONObject jsonObject = JSONObject.fromObject(string);
String token_type = jsonObject.getString("token_type"); String token_type = jsonObject.getString("token_type");
String access_token = jsonObject.getString("access_token"); String access_token = jsonObject.getString("access_token");
......
server: server:
servlet: servlet:
context-path: /afrishop context-path: /afrishop
port: 8099 port: 8012
spring: spring:
datasource: datasource:
......
...@@ -2,7 +2,7 @@ server.servlet.context-path=/zion ...@@ -2,7 +2,7 @@ server.servlet.context-path=/zion
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
server.port=8083 server.port=8083
spring.profiles.active=test spring.profiles.active=test
#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC #spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliant\TimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root #spring.datasource.username=root
#spring.datasource.password=Diaoyunnuli.8 #spring.datasource.password=Diaoyunnuli.8
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect #spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
...@@ -25,5 +25,5 @@ spring.servlet.multipart.max-request-size=456128KB ...@@ -25,5 +25,5 @@ spring.servlet.multipart.max-request-size=456128KB
bezkoder.app.jwtSecret=bezKoderSecretKey bezkoder.app.jwtSecret=bezKoderSecretKey
bezkoder.app.jwtExpirationMs=86400000 bezkoder.app.jwtExpirationMs=86400000
#spring.jpa.show-sql=true spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.format_sql=true
\ No newline at end of file \ No newline at end of file
...@@ -214,6 +214,12 @@ ...@@ -214,6 +214,12 @@
// return output.toByteArray(); // return output.toByteArray();
// } // }
// //
// @Test
// public void test001(){
// Date now = DateUtil.getNow();
// System.out.println(now);
// }
// //
// //
//} //}
//package com.example.afrishop_v3;
//
//import com.example.afrishop_v3.enums.CategoryEnum;
//import com.example.afrishop_v3.models.Country;
//import com.example.afrishop_v3.util.HttpClientUtil;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//import org.junit.Test;
//
//import java.io.IOException;
//import java.util.*;
//import java.util.stream.Collectors;
//
//public class MainTest {
//// usd_shop_price(现价) usd_market_price(原价)
// //https://apiv2.lovelywholesale.com/lw-api/product/item/296341?Origin=https:%2F%2Fm.lovelywholesale.com%2F&v=1619262060361
// private final String ITEM_URL="https://goapi.lovelywholesale.com/search/category/products";
// private volatile Integer page=1;
// private final Integer limit=48;
// private int total_page=0;
//// @Test
// public void importItems(Integer category_id) throws IOException {
// JSONArray items=null;
// do {
// page++ ;
// Map<String,Object> params=new LinkedHashMap<>();
// params.put("offset",page);
// params.put("limit",limit);
// params.put("category_id",category_id);
// params.put("original_category_id",category_id);
// params.put("is_virtual",1);
// String response = HttpClientUtil.sendPostWithBodyParameter(ITEM_URL, params);
// JSONObject jsonObject = JSONObject.fromObject(response);
// JSONObject data = jsonObject.getJSONObject("data");
// total_page = data.getInt("total_page");
// items = data.getJSONArray("search_list");
// for (int i = 0; i < items.size(); i++) {
// JSONObject item = items.getJSONObject(i);
// String itemId = item.getString("goods_id");
// String itemName = item.getString("goods_name");
// String categoryName = item.getString("category_name");
// }
//
// }while (page<total_page);
//
//
// }
//
// private final String CATEGORY_URL="https://apiv2.lovelywholesale.com/lw-api/head/switch-top-category";
//
// @Test
// public void importCategory() throws IOException {
// String topCategory = null;
// List<Integer> ids= Arrays.asList(1,3,5,4);
// for (int i = 0; i < ids.size(); i++) {
// Integer catId = ids.get(i);
// if (CategoryEnum.WOMEN.getCategoryId()==catId){
// topCategory=CategoryEnum.WOMEN.getCategoryName();
// }else if (CategoryEnum.CURVE.getCategoryId()==catId){
// topCategory=CategoryEnum.CURVE.getCategoryName();
// }else if (CategoryEnum.MEN.getCategoryId()==catId){
// topCategory=CategoryEnum.MEN.getCategoryName();
// }else if (CategoryEnum.KIDS.getCategoryId()==catId){
// topCategory=CategoryEnum.KIDS.getCategoryName();
// }
// Map<String,Object> params=new LinkedHashMap<>();
// params.put("top_cat_id",catId);
// String response=HttpClientUtil.sendPostWithBodyParameter(CATEGORY_URL,params);
// JSONObject jsonObject = JSONObject.fromObject(response);
// JSONObject data = jsonObject.getJSONObject("data");
// JSONArray categorys = data.getJSONArray("categorys");
// for (int j = 0; j < categorys.size(); j++) {
// JSONObject category = categorys.getJSONObject(j);
// String categoryId = category.getString("nav_id");
// String navName = category.getString("nav_name");
// Map<String, String> children = getCategoryChildren(categoryId);
// System.err.println("一级分类:"+topCategory+"---"+"二级分类-:"+categoryId+"---"+navName);
// //二级分类入库
//// children.entrySet().stream().forEach(System.err::println);
// //三级分类入库
// //通过三级分类查询商品、入库
// children.forEach((k, v) ->{
// try {
// importItems(Integer.parseInt(k));
// } catch (IOException e) {
// e.printStackTrace();
// }
// });
// }
//
//
// }
//
// }
//
// private final String url="https://apiv2.lovelywholesale.com/lw-api/list/get_child_cat";
//
//// @Test
// public Map<String,String> getCategoryChildren(String categoryId) throws IOException {
// Map<String,String> results=new LinkedHashMap<>();
// Map<String,Object> params=new LinkedHashMap<>();
// params.put("nav_id",categoryId);
// String response=HttpClientUtil.sendPostWithBodyParameter(url,params);
// JSONObject jsonObject = JSONObject.fromObject(response);
// JSONObject data = jsonObject.getJSONObject("data");
// JSONArray categorys = data.getJSONArray("category");
// for (int j = 0; j < categorys.size(); j++) {
// JSONObject category = categorys.getJSONObject(j);
// JSONArray childs = category.getJSONArray("child");
// for (int i = 0; i < childs.size(); i++) {
// JSONObject child = childs.getJSONObject(i);
// String name = child.getString("nav_name");
// String cat_id = child.getJSONObject("cat_info").getString("cat_id");
// System.err.println(cat_id+"---"+name);
// results.put(cat_id,name);
// }
// }
// return results;
// }
//
//}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论