XMTT vor 8 Jahren
Ursprung
Commit
f7c9f8554e

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

@ -10,7 +10,11 @@ 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;
13 15
import java.sql.SQLException;
16
import java.util.ArrayList;
17
import java.util.List;
14 18
15 19
@DAO
16 20
public abstract class ViewCustomerDao {
@ -22,4 +26,37 @@ public abstract class ViewCustomerDao {
22 26
	@OrderBy(" ORDER BY create_time")
23 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;
24 28
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
	}
25 62
}

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

@ -11,11 +11,8 @@ 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.ResultSetExtractor;
16 14
17 15
import java.sql.Connection;
18
import java.sql.ResultSet;
19 16
import java.sql.SQLException;
20 17
import java.util.ArrayList;
21 18
import java.util.List;
@ -62,15 +59,13 @@ public class ViewCustomerService {
62 59
	@Get
63 60
	@Path("/orgName")
64 61
	public List<TestService.TypeaheadItem> get(@JdbcConn Connection con, String q, @DefaultValue("11") int s) throws SQLException{
62
		String key=null;
63
		if(q!=null)
64
		{
65
			key="%"+q+"%";
66
		}
65 67
		List<TestService.TypeaheadItem> ret = new ArrayList<>(s);
66
		List<ViewCustomer> typeahead = JdbcUtil.queryList(con, "SELECT ORGNAME FROM view_customer WHERE ORGNAME LIKE '%" + q + "%' group by orgname", new ResultSetExtractor<ViewCustomer>() {
67
			@Override
68
			public ViewCustomer extractData(ResultSet resultSet) throws SQLException {
69
				ViewCustomer viewCustomer = new ViewCustomer();
70
				viewCustomer.setOrgname(resultSet.getString("ORGNAME"));
71
				return viewCustomer;
72
			}
73
		});
68
		List<ViewCustomer> typeahead = this.viewCustomerDao.orgName(con, key);
74 69
		for (ViewCustomer viewCustomer : typeahead) {
75 70
			TestService.TypeaheadItem thi = new TestService.TypeaheadItem();
76 71
			thi.setCode(viewCustomer.getOrgname());