jiapeng 8 years ago
parent
commit
5447a379c1

+ 4 - 0
src/main/java/com/ekexiu/console/system/dao/DictDao.java

@ -9,6 +9,7 @@ import org.jfw.apt.orm.annotation.dao.Column;
9 9
import org.jfw.apt.orm.annotation.dao.DAO;
10 10
import org.jfw.apt.orm.annotation.dao.method.From;
11 11
import org.jfw.apt.orm.annotation.dao.method.operator.DeleteWith;
12
import org.jfw.apt.orm.annotation.dao.method.operator.Insert;
12 13
import org.jfw.apt.orm.annotation.dao.method.operator.QueryVal;
13 14
import org.jfw.apt.orm.annotation.dao.method.operator.SelectList;
14 15
import org.jfw.apt.orm.annotation.dao.method.operator.Update;
@ -26,6 +27,9 @@ public interface DictDao {
26 27
	@Update
27 28
	int update(Connection con ,Dict dict)throws SQLException;
28 29
	
30
	@Insert
31
	int insert(Connection con,Dict dict)throws SQLException;
32
	
29 33
	@Nullable
30 34
	@QueryVal
31 35
	@Column(value="ITEM",handlerClass=StringHandler.class)

+ 2 - 1
src/main/java/com/ekexiu/console/system/po/Dict.java

@ -3,6 +3,7 @@ package com.ekexiu.console.system.po;
3 3
import org.jfw.apt.orm.annotation.entry.Column;
4 4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5 5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
6 7
import org.jfw.apt.orm.core.enums.DE;
7 8

8 9
@PrimaryKey("code")
@ -44,7 +45,7 @@ public class Dict {
44 45
	public void setReadonly(boolean readonly) {
45 46
		this.readonly = readonly;
46 47
	}
47
	@Column(value=DE.Text_de,renewable=false)
48
	@Column(dbType="TEXT",fixSqlValueWithInsert="'[]'",handlerClass=StringHandler.class,nullable=false,renewable=false)
48 49
	public String getItem() {
49 50
		return item;
50 51
	}

+ 53 - 5
src/main/java/com/ekexiu/console/system/service/DictService.java

@ -6,6 +6,7 @@ import java.sql.SQLException;
6 6
import java.util.ArrayList;
7 7
import java.util.Collection;
8 8
import java.util.Collections;
9
import java.util.Comparator;
9 10
import java.util.HashMap;
10 11
import java.util.LinkedList;
11 12
import java.util.List;
@ -17,12 +18,17 @@ import java.util.concurrent.atomic.AtomicReference;
17 18
import javax.sql.DataSource;
18 19

19 20
import org.jfw.apt.annotation.Autowrie;
21
import org.jfw.apt.annotation.DefaultValue;
22
import org.jfw.apt.annotation.Nullable;
20 23
import org.jfw.apt.web.annotation.Path;
21 24
import org.jfw.apt.web.annotation.operate.Get;
25
import org.jfw.apt.web.annotation.operate.Post;
22 26
import org.jfw.apt.web.annotation.operate.Put;
23 27
import org.jfw.apt.web.annotation.param.JdbcConn;
24 28
import org.jfw.apt.web.annotation.param.PathVar;
25 29
import org.jfw.apt.web.annotation.param.RequestBody;
30
import org.jfw.apt.web.annotation.param.RequestParam;
31
import org.jfw.util.PageQueryResult;
26 32
import org.jfw.util.exception.JfwBaseException;
27 33
import org.jfw.util.jdbc.JdbcTask;
28 34
import org.jfw.util.jdbc.JdbcUtil;
@ -64,6 +70,34 @@ public class DictService {
64 70
		return ret;
65 71
	}
66 72

73
	private ArrayList<DictInfo> filterAndSort(String key) {
74
		ArrayList<DictInfo> ret = new ArrayList<DictInfo>();
75
		Collection<DictInfo> its = this.dicts.get().values();
76
		if (key == null || key.length() == 0) {
77
			ret.addAll(its);
78
		} else {
79
			for (DictInfo di : its) {
80
				if (di.getCode().indexOf(key) >= 0 || di.getCaption().indexOf(key) >= 0) {
81
					ret.add(di);
82
				}
83
			}
84
		}
85
		Collections.sort(ret, new Comparator<DictInfo>(){
86
			@Override
87
			public int compare(DictInfo o1, DictInfo o2) {
88
				return o1.getCode().compareTo(o2.getCode());
89
			}
90
		});
91
		return ret;
92
	}
93
	
94
	@Get
95
	@Path("/pq")
96
	public PageQueryResult<DictInfo> pageQuery( @Nullable String key,@DefaultValue("1") int pageNo,@DefaultValue("10") int pageSize){
97
		 ArrayList<DictInfo> list = filterAndSort(key);
98
		return PageQueryResult.build(list, pageSize, pageNo);
99
	}
100

67 101
	@Get
68 102
	@Path("/info/{code}")
69 103
	public DictInfo get(@PathVar String code) {
@ -105,6 +139,19 @@ public class DictService {
105 139
		if (ab.get())
106 140
			this.update(dict);
107 141
	}
142
	@Post
143
	@Path("/info")
144
	public void insert(@JdbcConn final Connection con, @RequestParam(excludeFields="item") final Dict dict)throws SQLException{
145
		final AtomicBoolean ab = new AtomicBoolean(false);
146
		JdbcUtil.executeAutoCommit(con, new JdbcTask() {
147
			@Override
148
			public void exec() throws SQLException {
149
				ab.set(dictDao.insert(con, dict) > 0);
150
			}
151
		});
152
		if (ab.get())
153
			this.update(dict);
154
	}
108 155

109 156
	@Put
110 157
	@Path("/item/{code}")
@ -119,11 +166,12 @@ public class DictService {
119 166
		}
120 167
		// TODO : check dictItem.system == true can't modify
121 168
		LinkedList<DictItem> ret = new LinkedList<DictItem>();
122
		if(di.isTree()){
123
		if (transfer(items, ret) == null) {
124
			throw new JfwBaseException(50003, "not exists parentCode or loop parentCode");
125
		}}else{
126
			for(ListIterator<EditDictItem> it = items.listIterator();it.hasNext();){
169
		if (di.isTree()) {
170
			if (transfer(items, ret) == null) {
171
				throw new JfwBaseException(50003, "not exists parentCode or loop parentCode");
172
			}
173
		} else {
174
			for (ListIterator<EditDictItem> it = items.listIterator(); it.hasNext();) {
127 175
				ret.add(transfer(it.next()));
128 176
			}
129 177
		}

+ 7 - 0
src/main/java/com/ekexiu/console/system/service/UserService.java

@ -6,7 +6,9 @@ import java.util.ArrayList;
6 6

7 7
import org.jfw.apt.annotation.Autowrie;
8 8
import org.jfw.apt.web.annotation.Path;
9
import org.jfw.apt.web.annotation.method.InvalidSession;
9 10
import org.jfw.apt.web.annotation.method.SetSession;
11
import org.jfw.apt.web.annotation.operate.Get;
10 12
import org.jfw.apt.web.annotation.operate.Post;
11 13
import org.jfw.apt.web.annotation.param.JdbcConn;
12 14
import org.jfw.util.StringUtil;
@ -62,6 +64,11 @@ public class UserService {
62 64
		}
63 65
		return null;
64 66
	}
67
	@Get
68
	@Path("/logout")
69
	@InvalidSession
70
	public void logout(){		
71
	}
65 72
	public static void main(String[] args)throws Exception{
66 73
		System.out.println(AuthUtil.serialAuth(new int[]{0}));
67 74
	}