|
@@ -0,0 +1,87 @@
|
|
|
+package com.bjlt.spider.table.dao.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.bjlt.spider.entity.PriceInExcelEntity;
|
|
|
+import com.bjlt.spider.table.dao.OaLineInExcelDao;
|
|
|
+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 OaLineInExcelDaoImpl implements OaLineInExcelDao {
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询oa_line_in_excel表的所有数据
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PriceInExcelEntity> listPageOaLineInExcel(PriceInExcelEntity priceInExcelEntity){
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
+ String select = "select id,price_table_uuid as priceTableUuid,from_city as fromCity,to_city as toCity,start_date as startDate,end_date as endDate,is_request as isRequest,edit_user as editUser,update_time as updateTime from oa_line_in_excel ";
|
|
|
+ stringBuffer.append(select);
|
|
|
+ Map<String,Object> map= map(priceInExcelEntity);
|
|
|
+ String where = "where 1 = 1" + map.keySet().stream().map(t -> " and " + t + "=?").collect(Collectors.joining(" "));
|
|
|
+ priceInExcelEntity.setTotal(count(where,map.values().toArray()));
|
|
|
+ stringBuffer.append(where);
|
|
|
+ String limit = " limit " + priceInExcelEntity.getStart() + "," + priceInExcelEntity.getSize();
|
|
|
+ stringBuffer.append(limit);
|
|
|
+ RowMapper<PriceInExcelEntity> rowMapper = new BeanPropertyRowMapper<PriceInExcelEntity>(PriceInExcelEntity.class);
|
|
|
+ System.out.println(stringBuffer.toString());
|
|
|
+ System.out.println(JSON.toJSONString(map));
|
|
|
+ List<PriceInExcelEntity> list = jdbcTemplate.query(stringBuffer.toString(),rowMapper,map.values().toArray());
|
|
|
+ System.out.println(JSON.toJSONString(list));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer count(String where, Object[] objects) {
|
|
|
+ String sql = "select count(*) from oa_line_in_excel " + where;
|
|
|
+ return jdbcTemplate.queryForObject(sql, Integer.class,objects);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String,Object> map(PriceInExcelEntity priceInExcelEntity) {
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ if (priceInExcelEntity.getId() != null) {
|
|
|
+ map.put("id", priceInExcelEntity.getId());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getPriceTableUuid() != null) {
|
|
|
+ map.put("price_table_uuid", priceInExcelEntity.getPriceTableUuid());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getFromCity() != null && !"".equals(priceInExcelEntity.getFromCity())) {
|
|
|
+ map.put("from_city", priceInExcelEntity.getFromCity());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getToCity() != null && !"".equals(priceInExcelEntity.getToCity())) {
|
|
|
+ map.put("to_city", priceInExcelEntity.getToCity());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getStartDate() != null && !"".equals(priceInExcelEntity.getStartDate())) {
|
|
|
+ map.put("start_date", priceInExcelEntity.getStartDate());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getEndDate() != null && !"".equals(priceInExcelEntity.getEndDate())) {
|
|
|
+ map.put("end_date", priceInExcelEntity.getEndDate());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getIsRequest() != null && !"".equals(priceInExcelEntity.getIsRequest())) {
|
|
|
+ map.put("is_request", priceInExcelEntity.getIsRequest());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getEditUser() != null && !"".equals(priceInExcelEntity.getEditUser())) {
|
|
|
+ map.put("edit_user", priceInExcelEntity.getEditUser());
|
|
|
+ }
|
|
|
+ if (priceInExcelEntity.getUpdateTime() != null && !"".equals(priceInExcelEntity.getUpdateTime())) {
|
|
|
+ map.put("update_time", priceInExcelEntity.getUpdateTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|