Commit 3aea3da7 by wutong

将FBA库存的平台SKU及Asin存入db

parent 99ecfc94
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package com.bailuntec.domain.pojo; package com.bailuntec.domain.pojo;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
/** /**
* Auto-generated: 2019-01-07 16:3:56 * Auto-generated: 2019-01-07 16:3:56
...@@ -11,46 +12,20 @@ import com.alibaba.fastjson.annotation.JSONField; ...@@ -11,46 +12,20 @@ import com.alibaba.fastjson.annotation.JSONField;
* @author bejson.com (i@bejson.com) * @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/ * @website http://www.bejson.com/java2pojo/
*/ */
@Data
public class FbaStockInfo { public class FbaStockInfo {
@JSONField(name = "sellerSku")
private String platformSku;
@JSONField(name = "sku") @JSONField(name = "sku")
private String bailunSku; private String bailunSku;
@JSONField(name = "wareCode") @JSONField(name = "wareCode")
private String warehouseCode; private String warehouseCode;
@JSONField(name = "asin")
private String asin;
@JSONField(name = "stockQuantity") @JSONField(name = "stockQuantity")
private Integer usableStock; private Integer usableStock;
@JSONField(name = "totalQuantity") @JSONField(name = "totalQuantity")
private Integer inWarehouse; private Integer inWarehouse;
public String getBailunSku() {
return bailunSku;
}
public void setBailunSku(String bailunSku) {
this.bailunSku = bailunSku;
}
public String getWarehouseCode() {
return warehouseCode;
}
public void setWarehouseCode(String warehouseCode) {
this.warehouseCode = warehouseCode;
}
public Integer getUsableStock() {
return usableStock;
}
public void setUsableStock(Integer usableStock) {
this.usableStock = usableStock;
}
public Integer getInWarehouse() {
return inWarehouse;
}
public void setInWarehouse(Integer inWarehouse) {
this.inWarehouse = inWarehouse;
}
} }
\ No newline at end of file
...@@ -3,9 +3,13 @@ package com.bailuntec.job; ...@@ -3,9 +3,13 @@ package com.bailuntec.job;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.bailuntec.domain.entity.DcBaseStock; import com.bailuntec.domain.entity.DcBaseStock;
import com.bailuntec.domain.entity.DcBaseStockFba;
import com.bailuntec.domain.entity.JobPointLog; import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseStockExample;
import com.bailuntec.domain.example.DcBaseStockFbaExample;
import com.bailuntec.domain.pojo.FbaStockData; import com.bailuntec.domain.pojo.FbaStockData;
import com.bailuntec.domain.pojo.FbaStockInfo; import com.bailuntec.domain.pojo.FbaStockInfo;
import com.bailuntec.mapper.DcBaseStockFbaMapper;
import com.bailuntec.mapper.DcBaseStockMapper; import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.support.PointJob; import com.bailuntec.support.PointJob;
import com.bailuntec.utils.OkHttpUtil; import com.bailuntec.utils.OkHttpUtil;
...@@ -13,9 +17,12 @@ import com.bailuntec.utils.PropertiesUtil; ...@@ -13,9 +17,12 @@ import com.bailuntec.utils.PropertiesUtil;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import okhttp3.*; import okhttp3.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -70,6 +77,26 @@ public class FbaStockJob extends PointJob { ...@@ -70,6 +77,26 @@ public class FbaStockJob extends PointJob {
dcBaseStock.setUsableStock(dcBaseStockInMap.getUsableStock() + fbaStockInfo.getUsableStock()); dcBaseStock.setUsableStock(dcBaseStockInMap.getUsableStock() + fbaStockInfo.getUsableStock());
} }
hashmap.put(dcBaseStock.getBailunSku() + dcBaseStock.getWarehouseCode(), dcBaseStock); hashmap.put(dcBaseStock.getBailunSku() + dcBaseStock.getWarehouseCode(), dcBaseStock);
DcBaseStockFba dcBaseStockFba = new DcBaseStockFba();
try {
BeanUtils.copyProperties(dcBaseStockFba, fbaStockInfo);
} catch (Exception e) {
throw new RuntimeException("BeanUtils.copyPropertiesFBA库存数据失败");
}
dcBaseStockFba.setGmtModified(LocalDateTime.now());
try {
DcBaseStockFbaMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockFbaMapper.class);
int i = mapper.updateByExampleSelective(dcBaseStockFba, DcBaseStockFbaExample.newAndCreateCriteria().andBailunSkuEqualTo(dcBaseStockFba.getBailunSku()).andWarehouseCodeEqualTo(dcBaseStockFba.getWarehouseCode()).example());
if (i == 0) {
mapper.insertSelective(dcBaseStockFba);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("MYBATIS操作DB存DcBaseStockFba失败", e);
} finally {
SessionUtil.closeSession();
}
} }
} }
} }
...@@ -85,8 +112,12 @@ public class FbaStockJob extends PointJob { ...@@ -85,8 +112,12 @@ public class FbaStockJob extends PointJob {
try { try {
DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class); DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
hashmap.forEach(((skuWarehouse, dcBaseStock) -> { hashmap.forEach(((skuWarehouse, dcBaseStock) -> {
mapper.upsertSelective(dcBaseStock); dcBaseStock.setGmtModified(LocalDateTime.now());
SessionUtil.getSession().commit(); int i = mapper.updateByExampleSelective(dcBaseStock, DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo(dcBaseStock.getBailunSku()).andWarehouseCodeEqualTo(dcBaseStock.getWarehouseCode()).example());
if (i == 0) {
mapper.insertSelective(dcBaseStock);
}
})); }));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseStockFba;
import com.bailuntec.domain.example.DcBaseStockFbaExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DcBaseStockFbaMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
long countByExample(DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int deleteByExample(DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int insert(DcBaseStockFba record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int insertSelective(DcBaseStockFba record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
DcBaseStockFba selectOneByExample(DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
List<DcBaseStockFba> selectByExample(DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
DcBaseStockFba selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") DcBaseStockFba record, @Param("example") DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int updateByExample(@Param("record") DcBaseStockFba record, @Param("example") DcBaseStockFbaExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(DcBaseStockFba record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
int updateByPrimaryKey(DcBaseStockFba record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsert(DcBaseStockFba record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcBaseStockFba record);
}
\ No newline at end of file
...@@ -22,7 +22,7 @@ public class DailyStockTest { ...@@ -22,7 +22,7 @@ public class DailyStockTest {
FbaStockJob fbaStockJob = new FbaStockJob(); FbaStockJob fbaStockJob = new FbaStockJob();
JobPointLog jobPointLog = new JobPointLog(); JobPointLog jobPointLog = new JobPointLog();
jobPointLog.setPageIndex(1); jobPointLog.setPageIndex(1);
jobPointLog.setPageSize(100); jobPointLog.setPageSize(10000);
fbaStockJob.executeJob(null,jobPointLog); fbaStockJob.executeJob(null,jobPointLog);
} }
......
package com.bailuntec.domain.entity;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class DcBaseStockFba {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.gmt_create
*
* @mbg.generated
*/
private LocalDateTime gmtCreate;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.gmt_modified
*
* @mbg.generated
*/
private LocalDateTime gmtModified;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.bailun_sku
*
* @mbg.generated
*/
private String bailunSku;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.platform_sku
*
* @mbg.generated
*/
private String platformSku;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.warehouse_code
*
* @mbg.generated
*/
private String warehouseCode;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.usable_stock
*
* @mbg.generated
*/
private Integer usableStock;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.in_warehouse
*
* @mbg.generated
*/
private Integer inWarehouse;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_base_stock_fba.asin
*
* @mbg.generated
*/
private String asin;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", gmtCreate=").append(gmtCreate);
sb.append(", gmtModified=").append(gmtModified);
sb.append(", bailunSku=").append(bailunSku);
sb.append(", platformSku=").append(platformSku);
sb.append(", warehouseCode=").append(warehouseCode);
sb.append(", usableStock=").append(usableStock);
sb.append(", inWarehouse=").append(inWarehouse);
sb.append(", asin=").append(asin);
sb.append("]");
return sb.toString();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
DcBaseStockFba other = (DcBaseStockFba) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getGmtCreate() == null ? other.getGmtCreate() == null : this.getGmtCreate().equals(other.getGmtCreate()))
&& (this.getGmtModified() == null ? other.getGmtModified() == null : this.getGmtModified().equals(other.getGmtModified()))
&& (this.getBailunSku() == null ? other.getBailunSku() == null : this.getBailunSku().equals(other.getBailunSku()))
&& (this.getPlatformSku() == null ? other.getPlatformSku() == null : this.getPlatformSku().equals(other.getPlatformSku()))
&& (this.getWarehouseCode() == null ? other.getWarehouseCode() == null : this.getWarehouseCode().equals(other.getWarehouseCode()))
&& (this.getUsableStock() == null ? other.getUsableStock() == null : this.getUsableStock().equals(other.getUsableStock()))
&& (this.getInWarehouse() == null ? other.getInWarehouse() == null : this.getInWarehouse().equals(other.getInWarehouse()))
&& (this.getAsin() == null ? other.getAsin() == null : this.getAsin().equals(other.getAsin()));
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table dc_base_stock_fba
*
* @mbg.generated
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getGmtCreate() == null) ? 0 : getGmtCreate().hashCode());
result = prime * result + ((getGmtModified() == null) ? 0 : getGmtModified().hashCode());
result = prime * result + ((getBailunSku() == null) ? 0 : getBailunSku().hashCode());
result = prime * result + ((getPlatformSku() == null) ? 0 : getPlatformSku().hashCode());
result = prime * result + ((getWarehouseCode() == null) ? 0 : getWarehouseCode().hashCode());
result = prime * result + ((getUsableStock() == null) ? 0 : getUsableStock().hashCode());
result = prime * result + ((getInWarehouse() == null) ? 0 : getInWarehouse().hashCode());
result = prime * result + ((getAsin() == null) ? 0 : getAsin().hashCode());
return result;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment