XMTT 8 vuotta sitten
vanhempi
commit
ae6200fc80

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

10
import org.jfw.util.PageQueryResult;
10
import org.jfw.util.PageQueryResult;
11
11
12
import java.sql.Connection;
12
import java.sql.Connection;
13
import java.sql.PreparedStatement;
14
import java.sql.ResultSet;
15
import java.sql.SQLException;
13
import java.sql.SQLException;
16
import java.util.ArrayList;
17
import java.util.List;
18
14
19
@DAO
15
@DAO
20
public abstract class ViewCustomerDao {
16
public abstract class ViewCustomerDao {
26
	@OrderBy(" ORDER BY create_time")
22
	@OrderBy(" ORDER BY create_time")
27
	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;
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
import org.jfw.apt.web.annotation.param.JdbcConn;
11
import org.jfw.apt.web.annotation.param.JdbcConn;
12
import org.jfw.apt.web.annotation.param.PathVar;
12
import org.jfw.apt.web.annotation.param.PathVar;
13
import org.jfw.util.PageQueryResult;
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
import java.sql.Connection;
18
import java.sql.Connection;
19
import java.sql.PreparedStatement;
20
import java.sql.ResultSet;
16
import java.sql.SQLException;
21
import java.sql.SQLException;
17
import java.util.ArrayList;
22
import java.util.ArrayList;
18
import java.util.List;
23
import java.util.List;
59
	@Get
64
	@Get
60
	@Path("/orgName")
65
	@Path("/orgName")
61
	public List<TestService.TypeaheadItem> get(@JdbcConn Connection con, String q, @DefaultValue("11") int s) throws SQLException{
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
		if(q!=null)
68
		if(q!=null)
64
		{
69
		{
65
			key="%"+q+"%";
70
			key= "%"+q+"%";
66
		}
71
		}
67
		List<TestService.TypeaheadItem> ret = new ArrayList<>(s);
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
			TestService.TypeaheadItem thi = new TestService.TypeaheadItem();
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
			ret.add(thi);
90
			ret.add(thi);
74
		}
91
		}
75
		return ret;
92
		return ret;