XMTT лет назад: 8
Родитель
Сommit
ae6200fc80

+ 0 - 37
src/main/java/com/ekexiu/console/system/dao/ViewCustomerDao.java

@ -10,11 +10,7 @@ import org.jfw.apt.orm.annotation.dao.param.Like;
10 10
import org.jfw.util.PageQueryResult;
11 11
12 12
import java.sql.Connection;
13
import java.sql.PreparedStatement;
14
import java.sql.ResultSet;
15 13
import java.sql.SQLException;
16
import java.util.ArrayList;
17
import java.util.List;
18 14
19 15
@DAO
20 16
public abstract class ViewCustomerDao {
@ -26,37 +22,4 @@ public abstract class ViewCustomerDao {
26 22
	@OrderBy(" ORDER BY create_time")
27 23
	public abstract PageQueryResult<ViewCustomer> query(Connection con, @Like String name, @Like String address, @Like String orgname, @Nullable Integer sendMailStatus, int pageSize, int pageNo) throws SQLException;
28 24
29
	public List<ViewCustomer> orgName(Connection con,String orgname) throws SQLException{
30
		int index = 1;
31
		boolean oname = null == orgname;
32
		StringBuilder sql = new StringBuilder();
33
		sql.append("SELECT ORGNAME FROM view_customer");
34
		if(!oname){
35
			sql.append(" WHERE ORGNAME LIKE ? group by orgname");
36
		}
37
		PreparedStatement ps = con.prepareStatement(sql.toString());
38
		try{
39
			if(!oname){
40
				ps.setString(index++,orgname);
41
			}
42
			ResultSet rs = ps.executeQuery();
43
			try{
44
				List<ViewCustomer> viewCustomers = new ArrayList<ViewCustomer>();
45
				while(rs.next()){
46
					ViewCustomer viewCustomer =  new ViewCustomer();
47
					String orgName = rs.getString(1);
48
					if(rs.wasNull()){
49
						orgName = null;
50
					}
51
					viewCustomer.setOrgname(orgName);
52
					viewCustomers.add(viewCustomer);
53
				}
54
				return viewCustomers;
55
			}finally{
56
				try{rs.close();}catch(Exception e){}
57
			}
58
		}finally{
59
			try{ps.close();}catch(Exception e){}
60
		}
61
	}
62 25
}

+ 23 - 6
src/main/java/com/ekexiu/console/system/service/ViewCustomerService.java

@ -11,8 +11,13 @@ import org.jfw.apt.web.annotation.operate.Get;
11 11
import org.jfw.apt.web.annotation.param.JdbcConn;
12 12
import org.jfw.apt.web.annotation.param.PathVar;
13 13
import org.jfw.util.PageQueryResult;
14
import org.jfw.util.jdbc.JdbcUtil;
15
import org.jfw.util.jdbc.PreparedStatementConfig;
16
import org.jfw.util.jdbc.ResultSetExtractor;
14 17
15 18
import java.sql.Connection;
19
import java.sql.PreparedStatement;
20
import java.sql.ResultSet;
16 21
import java.sql.SQLException;
17 22
import java.util.ArrayList;
18 23
import java.util.List;
@ -59,17 +64,29 @@ public class ViewCustomerService {
59 64
	@Get
60 65
	@Path("/orgName")
61 66
	public List<TestService.TypeaheadItem> get(@JdbcConn Connection con, String q, @DefaultValue("11") int s) throws SQLException{
62
		String key=null;
67
		String key = "%";
63 68
		if(q!=null)
64 69
		{
65
			key="%"+q+"%";
70
			key= "%"+q+"%";
66 71
		}
67 72
		List<TestService.TypeaheadItem> ret = new ArrayList<>(s);
68
		List<ViewCustomer> typeahead = this.viewCustomerDao.orgName(con, key);
69
		for (ViewCustomer viewCustomer : typeahead) {
73
		final String finalKey = key;
74
		List<String> typeahead = JdbcUtil.queryList(con, "SELECT ORGNAME FROM view_customer WHERE ORGNAME LIKE ? group by orgname", new ResultSetExtractor<String>() {
75
			@Override
76
			public String extractData(ResultSet resultSet) throws SQLException {
77
				String s1 = resultSet.getString("ORGNAME");
78
				return s1;
79
			}
80
		}, new PreparedStatementConfig() {
81
			@Override
82
			public void config(PreparedStatement preparedStatement) throws SQLException {
83
				preparedStatement.setString(1, finalKey);
84
			}
85
		});
86
		for (String s1 : typeahead) {
70 87
			TestService.TypeaheadItem thi = new TestService.TypeaheadItem();
71
			thi.setCode(viewCustomer.getOrgname());
72
			thi.setCaption(viewCustomer.getOrgname());
88
			thi.setCode(s1);
89
			thi.setCaption(s1);
73 90
			ret.add(thi);
74 91
		}
75 92
		return ret;