|
@@ -0,0 +1,87 @@
|
|
|
+package com.bjlt.spider.table.dao.impl;
|
|
|
+
|
|
|
+import com.bjlt.spider.entity.OaPriceInExcel;
|
|
|
+import com.bjlt.spider.table.dao.OaPriceInExcelDao;
|
|
|
+import groovy.util.logging.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.RowMapper;
|
|
|
+import org.springframework.stereotype.Repository;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Repository
|
|
|
+public class OaPriceInExcelDaoImpl implements OaPriceInExcelDao {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OaPriceInExcel> listPageOaPriceInExcel(OaPriceInExcel oaPriceInExcel) {
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
+ String select = "select id,price_table_uuid as priceTableUuid, from_city as fromCity,ret_cicy as retCicy,from_date as fromDate,adult_tax as adultTax,adult_score as adultScore,dep_airport as depAirport,arr_airport as arrAirport,arr_time as arrTime,dep_time as depTime,flight_number as flightNumber from oa_price_in_excel ";
|
|
|
+ stringBuffer.append(select);
|
|
|
+ Map<String,Object> map= map(oaPriceInExcel);
|
|
|
+ String where = " where 1 = 1 " + map.keySet().stream().map(t -> " and " + t + "=?").collect(Collectors.joining(" "));
|
|
|
+ oaPriceInExcel.setTotal(count(where,map.values().toArray()));
|
|
|
+ stringBuffer.append(where);
|
|
|
+ String limit = " limit " + oaPriceInExcel.getStart() + "," + oaPriceInExcel.getSize();
|
|
|
+ stringBuffer.append(limit);
|
|
|
+ RowMapper<OaPriceInExcel> rowMapper = new BeanPropertyRowMapper<OaPriceInExcel>(OaPriceInExcel.class);
|
|
|
+ List<OaPriceInExcel> list = jdbcTemplate.query(stringBuffer.toString(),rowMapper,map.values().toArray());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer count(String where, Object[] objects) {
|
|
|
+ String sql = "select count(*) from oa_price_in_excel " + where;
|
|
|
+ return jdbcTemplate.queryForObject(sql,Integer.class,objects);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> map(OaPriceInExcel oaPriceInExcel) {
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ if (oaPriceInExcel.getId() != null){
|
|
|
+ map.put("id",oaPriceInExcel.getId());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getPriceTableUuid() != null){
|
|
|
+ map.put("price_table_uuid",oaPriceInExcel.getPriceTableUuid());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getFromCity() != null && !"".equals(oaPriceInExcel.getFromCity())){
|
|
|
+ map.put("from_city",oaPriceInExcel.getFromCity());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getRetCicy() != null && !"".equals(oaPriceInExcel.getRetCicy())){
|
|
|
+ map.put("ret_cicy",oaPriceInExcel.getRetCicy());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getFromDate() != null && !"".equals(oaPriceInExcel.getFromDate())){
|
|
|
+ map.put("from_date",oaPriceInExcel.getFromDate());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getAdultTax() != null && !"".equals(oaPriceInExcel.getAdultTax())){
|
|
|
+ map.put("adult_tax",oaPriceInExcel.getAdultTax());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getAdultScore() != null && !"".equals(oaPriceInExcel.getAdultScore())){
|
|
|
+ map.put("adult_score",oaPriceInExcel.getAdultScore());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getDepAirport() != null && !"".equals(oaPriceInExcel.getDepAirport())){
|
|
|
+ map.put("dep_airport",oaPriceInExcel.getDepAirport());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getArrAirport() != null && !"".equals(oaPriceInExcel.getArrAirport())){
|
|
|
+ map.put("arr_airport",oaPriceInExcel.getArrAirport());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getArrTime() != null && !"".equals(oaPriceInExcel.getArrTime())){
|
|
|
+ map.put("arr_time",oaPriceInExcel.getArrTime());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getDepTime() != null && !"".equals(oaPriceInExcel.getDepTime())){
|
|
|
+ map.put("dep_time",oaPriceInExcel.getDepTime());
|
|
|
+ }
|
|
|
+ if (oaPriceInExcel.getFlightNumber() != null && !"".equals(oaPriceInExcel.getFlightNumber())){
|
|
|
+ map.put("flight_number",oaPriceInExcel.getFlightNumber());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|