|
package com.ekexiu.console.system.service;
import com.ekexiu.console.system.dao.ViewCustomerDao;
import com.ekexiu.console.system.po.ViewCustomer;
import org.jfw.apt.annotation.Autowrie;
import org.jfw.apt.annotation.DefaultValue;
import org.jfw.apt.annotation.Nullable;
import org.jfw.apt.orm.annotation.dao.param.Like;
import org.jfw.apt.web.annotation.Path;
import org.jfw.apt.web.annotation.operate.Get;
import org.jfw.apt.web.annotation.param.JdbcConn;
import org.jfw.apt.web.annotation.param.PathVar;
import org.jfw.util.PageQueryResult;
import org.jfw.util.jdbc.JdbcUtil;
import org.jfw.util.jdbc.ResultSetExtractor;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Path("/sys/viewcustomer")
public class ViewCustomerService {
@Autowrie
private ViewCustomerDao viewCustomerDao;
public ViewCustomerDao getViewCustomerDao() {
return viewCustomerDao;
}
public void setViewCustomerDao(ViewCustomerDao viewCustomerDao) {
this.viewCustomerDao = viewCustomerDao;
}
@Get
@Path("/pq")
public PageQueryResult<ViewCustomer> pageQuery(@JdbcConn Connection con, @Nullable @Like String name, @Nullable @Like String address, @Nullable @Like String orgname, @Nullable Integer sendMailStatus, @DefaultValue("1") int pageNo, @DefaultValue("10") int pageSize)throws SQLException{
String Cname ="%";
if(name!=null)
{
Cname="%"+name+"%";
}
String Caddress ="%";
if(address!=null)
{
Caddress="%"+address+"%";
}
String Corgname ="%";
if(orgname!=null)
{
Corgname="%"+orgname+"%";
}
return this.viewCustomerDao.query(con, Cname, Caddress, Corgname, sendMailStatus, pageSize, pageNo);
}
@Get
@Path("/id/{id}")
public ViewCustomer query(@JdbcConn Connection con, @PathVar String id)throws SQLException{
return this.viewCustomerDao.query(con, id);
}
@Get
@Path("/orgName")
public List<TestService.TypeaheadItem> get(@JdbcConn Connection con, String q, @DefaultValue("11") int s) throws SQLException{
List<TestService.TypeaheadItem> ret = new ArrayList<>(s);
List<ViewCustomer> typeahead = JdbcUtil.queryList(con, "SELECT ORGNAME FROM view_customer WHERE ORGNAME LIKE '%" + q + "%' group by orgname", new ResultSetExtractor<ViewCustomer>() {
@Override
public ViewCustomer extractData(ResultSet resultSet) throws SQLException {
ViewCustomer viewCustomer = new ViewCustomer();
viewCustomer.setOrgname(resultSet.getString("ORGNAME"));
return viewCustomer;
}
});
for (ViewCustomer viewCustomer : typeahead) {
TestService.TypeaheadItem thi = new TestService.TypeaheadItem();
thi.setCode(viewCustomer.getOrgname());
thi.setCaption(viewCustomer.getOrgname());
ret.add(thi);
}
return ret;
}
}
|