XMTT 5 anni fa
parent
commit
ad3bcbbef6

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

4
import org.jfw.apt.orm.annotation.dao.DAO;
4
import org.jfw.apt.orm.annotation.dao.DAO;
5
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
5
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
6
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
6
import org.jfw.apt.orm.annotation.dao.method.operator.PageSelect;
7
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
7
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
8
import org.jfw.apt.orm.annotation.dao.method.operator.SelectOne;
8
import org.jfw.apt.orm.annotation.dao.param.Like;
9
import org.jfw.apt.orm.annotation.dao.param.Like;
9
import org.jfw.util.PageQueryResult;
10
import org.jfw.util.PageQueryResult;
10
11
11
import java.sql.Connection;
12
import java.sql.Connection;
12
import java.sql.SQLException;
13
import java.sql.SQLException;
14
import java.util.List;
13
15
14
/**
16
/**
15
 * Created by TT on 2019/5/30.
17
 * Created by TT on 2019/5/30.
25
    @OrderBy("ORDER BY CREATE_TIME DESC")
27
    @OrderBy("ORDER BY CREATE_TIME DESC")
26
    PageQueryResult<Department> pageQuery(Connection con, @Nullable Boolean active, @Nullable @Like String name, int pageSize, int pageNo) throws SQLException;
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
    @OrderBy("ORDER BY CREATE_TIME DESC")
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
import org.jfw.util.PageQueryResult;
8
import org.jfw.util.PageQueryResult;
9
import org.jfw.util.jdbc.JdbcUtil;
9
import org.jfw.util.jdbc.JdbcUtil;
10
import org.jfw.util.jdbc.PreparedStatementConfig;
10
import org.jfw.util.jdbc.PreparedStatementConfig;
11
import org.jfw.util.jdbc.ResultSetExtractor;
11
12
12
import java.sql.Connection;
13
import java.sql.Connection;
13
import java.sql.PreparedStatement;
14
import java.sql.PreparedStatement;
15
import java.sql.ResultSet;
14
import java.sql.SQLException;
16
import java.sql.SQLException;
15
import java.util.ArrayList;
17
import java.util.ArrayList;
18
import java.util.HashMap;
16
import java.util.List;
19
import java.util.List;
17
import java.util.Map;
20
import java.util.Map;
18
21
47
50
48
    @Path("/hospital")
51
    @Path("/hospital")
49
    @Get
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
    @Path("/name")
92
    @Path("/name")