ScheduleRuleServiceImpl.java
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.bsth.service.schedule.rules;
import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
/**
* Created by xu on 17/4/19.
*/
@Service
public class ScheduleRuleServiceImpl implements ScheduleRuleService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<SchedulePlanRuleResult> findLastByXl(String xlid, Date from) {
String sql = "select * from bsth_c_s_sp_rule_rst a " +
"where exists (select 1 from " +
"(select t.rule_id as rid, max(t.schedule_date) as sd from bsth_c_s_sp_rule_rst t " +
"where t.xl_id = ? and t.schedule_date < ? " +
"group by t.rule_id) a2 " +
"where a.rule_id = rid and a.schedule_date = sd) ";
return jdbcTemplate.query(sql, new Object[]{xlid, from}, new RowMapper<SchedulePlanRuleResult>() {
@Override
public SchedulePlanRuleResult mapRow(ResultSet rs, int i) throws SQLException {
SchedulePlanRuleResult obj = new SchedulePlanRuleResult();
obj.setRuleId(rs.getString("rule_id"));
obj.setScheduleDate(rs.getDate("schedule_date"));
obj.setGidindex(rs.getString("gidindex"));
obj.setEcindex(rs.getString("ecindex"));
// 其他字段没用
return obj;
}
});
}
}