XMTT 5 years ago
parent
commit
0e293961b0

+ 1 - 1
src/main/java/com/ekexiu/project/msconsole/doctor/DoctorDao.java

@ -46,7 +46,7 @@ public interface DoctorDao {
46 46
47 47
    @PageSelect
48 48
    @OrderBy("ORDER BY CREATE_TIME DESC")
49
    PageQueryResult<Doctor> pageQuery(Connection con, String hospital, @Nullable boolean active, @Nullable @Like String name, @Nullable @SqlColumn(handlerClass = StringHandler.class, value = "ID IN (SELECT ID FROM DEPARTMENT WHERE NAME LIKE ?)") String department, int pageSize, int pageNo) throws SQLException;
49
    PageQueryResult<Doctor> pageQuery(Connection con, String hospital, @Nullable Boolean active, @Nullable @Like String name, @Nullable @SqlColumn(handlerClass = StringHandler.class, value = "DEPARTMENT IN (SELECT ID FROM DEPARTMENT WHERE NAME LIKE ?)") String department, int pageSize, int pageNo) throws SQLException;
50 50
51 51
    @Nullable
52 52
    @SelectOne

+ 4 - 0
src/main/java/com/ekexiu/project/msconsole/system/dao/HospitalDao.java

@ -34,6 +34,10 @@ public interface HospitalDao {
34 34
    @SelectOne
35 35
    Hospital query(Connection con, String id) throws SQLException;
36 36
37
    @Nullable
38
    @SelectOne
39
    Hospital queryByAccount(Connection con,String account,Boolean active) throws SQLException;
40
37 41
    @Update
38 42
    @Exclude({"passwd", "active", "account"})
39 43
    int update(Connection con, Hospital hospital) throws SQLException;

+ 163 - 0
src/main/java/com/ekexiu/project/msconsole/system/service/DictService.java

@ -0,0 +1,163 @@
1
package com.ekexiu.project.msconsole.system.service;
2
3
import com.ekexiu.project.msconsole.system.dao.DictDao;
4
import com.ekexiu.project.msconsole.system.po.DictItem;
5
import org.jfw.apt.annotation.Autowrie;
6
import org.jfw.apt.annotation.Nullable;
7
import org.jfw.apt.web.annotation.Path;
8
import org.jfw.apt.web.annotation.operate.Get;
9
import org.jfw.apt.web.annotation.operate.Post;
10
import org.jfw.apt.web.annotation.param.AfterCommit;
11
import org.jfw.apt.web.annotation.param.JdbcConn;
12
13
import java.sql.Connection;
14
import java.sql.SQLException;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
@Path("/dict")
21
public class DictService {
22
	private static final HashMap<String, List<DictItem>> dictCache = new HashMap<String, List<DictItem>>();
23
	private static final List<DictItem> Empty_DICT = Collections.emptyList();
24
25
	@Autowrie
26
	private DictDao dictDao;
27
28
	public DictDao getDictDao() {
29
		return dictDao;
30
	}
31
32
	public void setDictDao(DictDao dictDao) {
33
		this.dictDao = dictDao;
34
	}
35
36
	@Path("/load")
37
	@Get
38
	public void load(@JdbcConn Connection con) throws SQLException {
39
		HashMap<String, List<DictItem>> map = new HashMap<String, List<DictItem>>();
40
		List<DictItem> items = this.dictDao.query(con);
41
		for (DictItem item : items) {
42
			List<DictItem> list = map.get(item.getDictCode());
43
			if (list == null) {
44
				list = new LinkedList<DictItem>();
45
				map.put(item.getDictCode(), list);
46
			}
47
			list.add(item);
48
		}
49
		synchronized(dictCache){
50
			dictCache.clear();
51
			dictCache.putAll(map);
52
		}
53
	}
54
55
	@Path("/items")
56
	@Get
57
	public List<DictItem> query(String dict) {
58
		List<DictItem> ret = null;
59
		synchronized (dictCache) {
60
			ret = dictCache.get(dict);
61
		}
62
		return ret == null ? Empty_DICT : ret;
63
	}
64
65
	@Path("/delete")
66
	@Post
67
	public int delete(@JdbcConn(true) Connection con, final String dict, final String code, @AfterCommit List<Runnable> runs) throws SQLException {
68
		int num = this.dictDao.disable(con, dict, code);
69
		if (num > 0) {
70
			runs.add(new Runnable() {
71
				@Override
72
				public void run() {
73
					synchronized (dictCache) {
74
						List<DictItem> list = dictCache.get(dict);
75
						if (list != null) {
76
							List<DictItem> newlist = new LinkedList<DictItem>();
77
							for (DictItem item : list) {
78
								if (!item.getCode().equals(code)) {
79
									newlist.add(item);
80
								}
81
							}
82
							dictCache.put(dict, newlist);
83
						}
84
					}
85
				}
86
			});
87
		}
88
		return num;
89
	}
90
91
	@Post
92
	@Path("/add")
93
	public void insert(@JdbcConn(true) Connection con, String code, String dict, @Nullable String bcode, String caption, @Nullable String fullCaption,
94
			@Nullable String shortCut, @Nullable String remark, boolean readonly, @AfterCommit List<Runnable> runs) throws SQLException {
95
		final DictItem item = new DictItem();
96
		item.setActive(true);
97
		item.setBcode(bcode);
98
		item.setCaption(caption);
99
		item.setCode(code);
100
		item.setDictCode(dict);
101
		item.setFullCaption(fullCaption);
102
		item.setReadonly(readonly);
103
		item.setRemark(remark);
104
		item.setShortCut(shortCut);
105
		this.dictDao.insert(con, item);
106
		runs.add(new Runnable() {
107
			@Override
108
			public void run() {
109
				synchronized (dictCache) {
110
					List<DictItem> newlist = new LinkedList<DictItem>();
111
					List<DictItem> list = dictCache.get(item.getDictCode());
112
					if (list != null) {
113
						newlist.addAll(list);
114
					}
115
					newlist.add(item);
116
					dictCache.put(item.getDictCode(), newlist);
117
				}
118
			}
119
		});
120
	}
121
122
	@Post
123
	@Path("/modify")
124
	public int update(@JdbcConn(true) Connection con, String code, String dict, @Nullable String bcode, String caption, @Nullable String fullCaption,
125
			@Nullable String shortCut, @Nullable String remark, @AfterCommit List<Runnable> runs) throws SQLException {
126
		int num = this.dictDao.update(con, bcode, caption, fullCaption, shortCut, remark, code, dict);
127
		if (num > 0) {
128
			final DictItem item = new DictItem();
129
			item.setActive(true);
130
			item.setBcode(bcode);
131
			item.setCaption(caption);
132
			item.setCode(code);
133
			item.setDictCode(dict);
134
			item.setFullCaption(fullCaption);
135
			item.setReadonly(false);
136
			item.setRemark(remark);
137
			item.setShortCut(shortCut);
138
139
			runs.add(new Runnable() {
140
				@Override
141
				public void run() {
142
					synchronized (dictCache) {
143
						List<DictItem> newlist = new LinkedList<DictItem>();
144
						List<DictItem> list = dictCache.get(item.getDictCode());
145
						if (list != null) {
146
							for (DictItem nitem : list) {
147
								if (!nitem.getCode().equals(item.getCode())) {
148
									newlist.add(nitem);
149
								}
150
							}
151
						}
152
						newlist.add(item);
153
						dictCache.put(item.getDictCode(), newlist);
154
					}
155
				}
156
			});
157
158
		}
159
		return num;
160
161
	}
162
163
}

+ 18 - 10
src/main/java/com/ekexiu/project/msconsole/system/service/SysService.java

@ -64,6 +64,12 @@ public class SysService {
64 64
    public void logout() {
65 65
    }
66 66
67
    @Get
68
    @Path("/user/exists")
69
    public boolean existsUser(@JdbcConn Connection con, String account, @Nullable Boolean active) throws SQLException {
70
        return null != hospitalDao.queryByAccount(con, account, active);
71
    }
72
67 73
    @Path("/user")
68 74
    @Get
69 75
    public SessionUser get(@LoginUser SessionUser user) {
@ -123,18 +129,20 @@ public class SysService {
123 129
    @Get
124 130
    public PageQueryResult<SessionUser> pageQuery(@JdbcConn Connection con, @Nullable Boolean active,@Nullable String level,@Nullable String subLevel,@Nullable String type,@Nullable String name,int pageSize,int pageNo)throws SQLException {
125 131
        PageQueryResult<Hospital> pageQueryResult = hospitalDao.pageQuery(con, active, level, subLevel, type, name == null ? null : "%" + name + "%", pageSize, pageNo);
132
        if(pageQueryResult!=null) {
126 133
        List<Hospital> hospitals = pageQueryResult.getData();
127
        List<SessionUser> sessionUsers = new ArrayList<>();
128
        if (!hospitals.isEmpty()) {
129
            for (Hospital hospital : hospitals) {
130
                sessionUsers.add(makeSessionUser(hospital));
134
            List<SessionUser> sessionUsers = new ArrayList<>();
135
            if (!hospitals.isEmpty()) {
136
                for (Hospital hospital : hospitals) {
137
                    sessionUsers.add(makeSessionUser(hospital));
138
                }
139
                PageQueryResult<SessionUser> ret = new PageQueryResult<>();
140
                ret.setPageNo(pageQueryResult.getPageNo());
141
                ret.setPageSize(pageQueryResult.getPageSize());
142
                ret.setTotal(pageQueryResult.getTotal());
143
                ret.setData(sessionUsers);
144
                return ret;
131 145
            }
132
            PageQueryResult<SessionUser> ret = new PageQueryResult<>();
133
            ret.setPageNo(pageQueryResult.getPageNo());
134
            ret.setPageSize(pageQueryResult.getPageSize());
135
            ret.setTotal(pageQueryResult.getTotal());
136
            ret.setData(sessionUsers);
137
            return ret;
138 146
        }
139 147
        return null;
140 148
    }