XMTT 5 years ago
parent
commit
ad3bcbbef6

+ 4 - 2
src/main/java/com/ekexiu/project/department/DepartmentDao.java

@ -4,12 +4,14 @@ import org.jfw.apt.annotation.Nullable;
4 4
import org.jfw.apt.orm.annotation.dao.DAO;
5 5
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
6 6
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
7
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
7 8
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
8 9
import org.jfw.apt.orm.annotation.dao.param.Like;
9 10
import org.jfw.util.PageQueryResult;
10 11
11 12
import java.sql.Connection;
12 13
import java.sql.SQLException;
14
import java.util.List;
13 15
14 16
/**
15 17
 * Created by TT on 2019/5/30.
@ -25,7 +27,7 @@ public interface DepartmentDao {
25 27
    @OrderBy("ORDER BY CREATE_TIME DESC")
26 28
    PageQueryResult<Department> pageQuery(Connection con, @Nullable Boolean active, @Nullable @Like String name, int pageSize, int pageNo) throws SQLException;
27 29
28
    @PageSelect
30
    @SelectList
29 31
    @OrderBy("ORDER BY CREATE_TIME DESC")
30
    PageQueryResult<Department> pageQuery(Connection con,String hospital, @Nullable Boolean active, int pageSize, int pageNo) throws SQLException;
32
    List<Department> listQuery(Connection con, String hospital, @Nullable Boolean active) throws SQLException;
31 33
}

+ 40 - 2
src/main/java/com/ekexiu/project/department/DepartmentService.java

@ -8,11 +8,14 @@ import org.jfw.apt.web.annotation.param.JdbcConn;
8 8
import org.jfw.util.PageQueryResult;
9 9
import org.jfw.util.jdbc.JdbcUtil;
10 10
import org.jfw.util.jdbc.PreparedStatementConfig;
11
import org.jfw.util.jdbc.ResultSetExtractor;
11 12
12 13
import java.sql.Connection;
13 14
import java.sql.PreparedStatement;
15
import java.sql.ResultSet;
14 16
import java.sql.SQLException;
15 17
import java.util.ArrayList;
18
import java.util.HashMap;
16 19
import java.util.List;
17 20
import java.util.Map;
18 21
@ -47,8 +50,43 @@ public class DepartmentService {
47 50
48 51
    @Path("/hospital")
49 52
    @Get
50
    public PageQueryResult<Department> pqgeQuery(@JdbcConn Connection con,@Nullable Boolean active,String hospital,int pageSize,int pageNo)throws SQLException {
51
        return departmentDao.pageQuery(con, hospital, active, pageSize, pageNo);
53
    public List<Department> listQuery(@JdbcConn Connection con, @Nullable Boolean active, String hospital) throws SQLException {
54
        return departmentDao.listQuery(con, hospital, active);
55
    }
56
57
    @Path("/classify")
58
    @Get
59
    public List<Map<String, Object>> classify(@JdbcConn Connection con, final Boolean active, String hospital) throws SQLException {
60
        final String finalkey = hospital;
61
        List<Map<String, Object>> result = JdbcUtil.queryList(con, "select id,name,type from department where hospital = ? and active = ?", new ResultSetExtractor<Map<String, Object>>() {
62
            @Override
63
            public Map<String, Object> extractData(ResultSet resultSet) throws SQLException {
64
                Map<String, Object> map = new HashMap<>();
65
                map.put("id", resultSet.getInt(1));
66
                map.put("name", resultSet.getInt(2));
67
                map.put("type", resultSet.getInt(3));
68
                return map;
69
            }
70
        }, new PreparedStatementConfig() {
71
            @Override
72
            public void config(PreparedStatement preparedStatement) throws SQLException {
73
                preparedStatement.setString(1, finalkey);
74
                preparedStatement.setBoolean(2, active);
75
            }
76
        });
77
78
        for (Map<String, Object> map : result) {
79
            final String id = (String) map.get("id");
80
            map.put("num", JdbcUtil.queryInt(con, "select count(*) from doctor where hospital = ? and department = ? and active = ?", new PreparedStatementConfig() {
81
                @Override
82
                public void config(PreparedStatement preparedStatement) throws SQLException {
83
                    preparedStatement.setString(1, finalkey);
84
                    preparedStatement.setString(2, id);
85
                    preparedStatement.setBoolean(3, active);
86
                }
87
            }, 0));
88
        }
89
        return result;
52 90
    }
53 91
54 92
    @Path("/name")