1.@SpringBootTest注解是SpringBoot自1.4.0版本开始引入的一个用于测试的注解
2.@RunWith 翻译成中文就是 测试运行器,JUnit所有的测试方法都是由测试运行器负责执行。
3.@EnableAutoConfiguration自动配置
三者缺一不可
这样就不用来回的启动项目了,减少时间,提高开发效率
@SpringBootTest(classes= JobReportRun.class)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class UpdateDemo {
@Autowired
private BasicOrdersMapper basicOrdersMapper;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private static Logger logger= LoggerFactory.getLogger(WaimaiOrdersReportService.class);
@Test
public void test1(){
String createDate= DateUtils.convert2YestadayString(-1,"yyyy-MM-dd");
//查询外卖订单数据
int orderCount=0,orderItemsCount=0;
try{
List<ReportOrders> reportOrdersList=basicOrdersMapper.selectReportAllOrdersList(createDate);
//合并所有的订单明细
List<ReportOrderItems> reportOrderItemsList=new ArrayList<>();
for(int j=0;j<reportOrdersList.size();j++){
reportOrderItemsList.addAll(reportOrdersList.get(j).getReportItemsList());
}
if(reportOrdersList.size()>0){
//插入订单数据
orderCount=insertOrders(namedParameterJdbcTemplate,reportOrdersList,"etoneO2o");
//插入订单明细数据
orderItemsCount=insertOrderItems(namedParameterJdbcTemplate,reportOrderItemsList,"etoneO2o");
//1.查询除平台以外的所有商圈中外卖授权的商户
List<String> waimaiTradingMerchantBn = basicOrdersMapper.selectWaiMaiTradingMerchantBn();
int count = 0;
//根据这些商户号查询对应的易客来商户号和对应的商圈
if(waimaiTradingMerchantBn.size()>0){
List<Map<Object,Object>> waimaiMT = basicOrdersMapper.selectWaiMaiMerchantBnAndDb(waimaiTradingMerchantBn);
//如果不为空就直接更新之前错误的数据所有的外卖source_name=etoneO2o
if(waimaiMT.size()>0){
for (Map<Object, Object> map : waimaiMT) {
count = basicOrdersMapper.updateWaiMaiSourceName(map);
}
logger.info("-------------总计更新数据:【"+count+"】条数据--------------");
}
}
}
}catch (CannotGetJdbcConnectionException e){
}catch (Exception e) {
}
);
}
public int insertOrders(NamedParameterJdbcTemplate jdbcTemplateManal,List<ReportOrders> ordersList,String sourceName) {
int[] aa={};
if(ordersList.size()>0) {
Object[] obj = new Object[ordersList.size()];
for (int i = 0; i < ordersList.size(); i++) {
obj[i] = ordersList.get(i);
}
//批量提交
SqlParameterSource[] params = SqlParameterSourceUtils.createBatch(obj);
String insertSql = "insert into sdb_b2c_orders(order_id,seller_order_id,total_amount,final_amount,pay_status,ship_status,createtime,merchant_bn,source,source_name)" +
"VALUES(:orderId,:sellerOrderId,:totalAmount,:finalAmount,:payStatus,:shipStatus,:createTime,:merchantBn,:source,'"+sourceName+"')";
aa= jdbcTemplateManal.batchUpdate(insertSql, params);
}
return aa.length;
}
public int insertOrderItems(NamedParameterJdbcTemplate jdbcTemplateManal,List<ReportOrderItems> itemsList,String sourceName) {
int[] bb={};
if(itemsList.size()>0) {
Object[] obj = new Object[itemsList.size()];
for (int i = 0; i < itemsList.size(); i++) {
obj[i] = itemsList.get(i);
}
//批量提交
SqlParameterSource[] params = SqlParameterSourceUtils.createBatch(obj);
String insertSql = "insert into sdb_b2c_order_items(order_id,`name`,price,amount,nums,merchant_bn,source_name)" +
"VALUES(:orderId,:name,:price,:amount,:nums,:merchantBn,'"+sourceName+"')";
bb= jdbcTemplateManal.batchUpdate(insertSql, params);
}
return bb.length;
}
}