Commit 9fe13f32 by wutong

自动周转修改分片分页,计算时不漏SKU.

parent e89eca99
......@@ -43,51 +43,20 @@ public class AutoTurnoverJob extends PointJob {
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
long count = 0;
try {
DcBaseStockMapper baseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
count = baseStockMapper.countByExample(DcBaseStockExample.newAndCreateCriteria().example());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB查询总页数失败", e);
} finally {
SessionUtil.closeSession();
}
long count = getTotalCount();
int totalPage = getTotalPage(count, jobPointLog.getPageSize());
switch (shardingContext.getShardingItem()) {
case 0:
if (shardingContext.getShardingItem() + 1 < shardingContext.getShardingTotalCount()) {
totalPage = totalPage / shardingContext.getShardingTotalCount() * (shardingContext.getShardingItem() + 1);
}
break;
case 1:
if (shardingContext.getShardingItem() + 1 < shardingContext.getShardingTotalCount()) {
totalPage = (totalPage / shardingContext.getShardingTotalCount()) * (shardingContext.getShardingItem() + 1);
}
break;
case 2:
/*
* 根据不同分片
* 再分页去处理数据
*/
int shardingSize = totalPage % shardingContext.getShardingTotalCount() == 0? totalPage / shardingContext.getShardingTotalCount() : totalPage / shardingContext.getShardingTotalCount() + 1;
if (shardingContext.getShardingItem() + 1 < shardingContext.getShardingTotalCount()) {
totalPage = (totalPage / shardingContext.getShardingTotalCount()) * (shardingContext.getShardingItem() + 1);
}
break;
case 3:
break;
totalPage = shardingSize * (shardingContext.getShardingItem() + 1);
}
if (totalPage > 0) {
int page = 0;
switch (shardingContext.getShardingItem()) {
case 0:
break;
case 1:
page = totalPage / shardingContext.getShardingTotalCount() * shardingContext.getShardingItem();
break;
case 2:
page = (totalPage / shardingContext.getShardingTotalCount()) * shardingContext.getShardingItem();
break;
case 3:
page = (totalPage / shardingContext.getShardingTotalCount()) * shardingContext.getShardingItem();
break;
if (shardingContext.getShardingItem() > 0) {
page = shardingSize * shardingContext.getShardingItem();
}
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
do {
......@@ -125,6 +94,17 @@ public class AutoTurnoverJob extends PointJob {
}
private long getTotalCount() {
try {
DcBaseStockMapper baseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
return baseStockMapper.countByExample(DcBaseStockExample.newAndCreateCriteria().example());
} catch (Exception e) {
throw new RuntimeException("Mybatis操作DB查询总页数失败", e);
} finally {
SessionUtil.closeSession();
}
}
/**
* 基于库存
* 计算自动周转
......
......@@ -12,12 +12,14 @@ import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Slf4j
public class AutoTurnoverJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
......@@ -57,7 +59,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
try {
autoTurnoverJob.autoTurnoverFromStock(queryTime, dcBaseStock);
} catch (Exception e) {
throw new RuntimeException("Mybatis操作自动周转异常数据再次计算失败SKU=" + dcAutoException.getBailunSku() + ",仓库编码=" + dcAutoException.getWarehouseCode(), e);
log.error("Mybatis操作自动周转异常数据再次计算失败SKU=" + dcAutoException.getBailunSku() + ",仓库编码=" + dcAutoException.getWarehouseCode());
}
mapper.deleteByPrimaryKey(dcAutoException.getId());
}
......@@ -65,7 +67,7 @@ public class AutoTurnoverJobListener implements ElasticJobListener {
pageIndex++;
} while (dcAutoExceptions != null && dcAutoExceptions.size() == pageSize);
} catch (RuntimeException e) {
throw new RuntimeException("Mybatis操作自动周转异常数据再次计算失败", e);
throw new RuntimeException("Mybatis操作自动周转异常数据再次计算失败");
} finally {
if (sqlSession != null) {
sqlSession.close();
......
......@@ -125,4 +125,7 @@ public interface DcBaseStockMapper {
List<DcBaseStock> listNoChinaWarehouse(@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listOrderByFba(@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listInStockNotInAutoTurnover();
}
\ No newline at end of file
......@@ -1092,4 +1092,8 @@
<select id="listOrderByFba" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT * FROM dc_base_stock order by id asc limit #{v1}, #{v2}
</select>
<select id="listInStockNotInAutoTurnover" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT tb1.* FROM dc_base_stock tb1 LEFT JOIN dc_auto_turnover tb2 ON tb1.bailun_sku = tb2.bailun_sku and tb1.warehouse_code = tb2.warehouse_code WHERE tb2.bailun_sku is null;
</select>
</mapper>
\ No newline at end of file
SKUMS_PARENT_CATEGORIES_URL=http://10.0.6.13:8001/api/BailunCateData/GetMyParentCategories
#SKUMS_PARENT_CATEGORIES_URL=http://api.sku.bailuntec.com/api/BailunCateData/GetMyParentCategories
#SKUMS_PARENT_CATEGORIES_URL=http://10.0.6.13:8001/api/BailunCateData/GetMyParentCategories
SKUMS_PARENT_CATEGORIES_URL=http://api.sku.bailuntec.com/api/BailunCateData/GetMyParentCategories
TJ_OUT_STOCK_URL=http://tj.bailuntec.com/ApiService/GetNoStockForDataCenter
\ No newline at end of file
......@@ -50,7 +50,7 @@ public class AutoTurnoverTest {
try {
DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
// dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("322572421").andWarehouseCodeEqualTo("QYBLZZ").example());
dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("273129601").andWarehouseCodeEqualTo("GZBLWH").example());
dcBaseStock = mapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo("278308409").andWarehouseCodeEqualTo("GZBLYS").example());
} catch (Exception e) {
e.printStackTrace();
} finally {
......@@ -58,6 +58,24 @@ public class AutoTurnoverTest {
}
autoTurnoverJob.autoTurnoverFromStock(queryTime, dcBaseStock);
}
@Test
public void test22() throws Exception {
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
List<DcBaseStock> dcBaseStockList = null;
try {
DcBaseStockMapper mapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
dcBaseStockList = mapper.listInStockNotInAutoTurnover();
} catch (Exception e) {
e.printStackTrace();
} finally {
SessionUtil.closeSession();
}
for (DcBaseStock dcBaseStock : dcBaseStockList) {
autoTurnoverJob.autoTurnoverFromStock(queryTime, dcBaseStock);
}
}
@Test
public void test3() throws Exception {
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
......@@ -80,8 +98,8 @@ public class AutoTurnoverTest {
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
HashMap<Integer, String> map = new HashMap<>();
map.put(1,"");
ShardingContext shardingContext = new ShardingContext(new ShardingContexts("","",1,"", map), 0);
JobPointLog jobPointLog = new JobPointLog("", 1, 1, 1, 1, LocalDateTime.now().minusSeconds(1), LocalDateTime.now());
ShardingContext shardingContext = new ShardingContext(new ShardingContexts("","",4,"", map), 3);
JobPointLog jobPointLog = new JobPointLog("", 1, 2000, 1, 1, LocalDateTime.now().minusSeconds(1), LocalDateTime.now());
autoTurnoverJob.executeJob(shardingContext, jobPointLog);
}
......
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