jiapeng 8 vuotta sitten
vanhempi
commit
5447a379c1

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

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

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

3
import org.jfw.apt.orm.annotation.entry.Column;
3
import org.jfw.apt.orm.annotation.entry.Column;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
4
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
5
import org.jfw.apt.orm.annotation.entry.Table;
5
import org.jfw.apt.orm.annotation.entry.Table;
6
import org.jfw.apt.orm.core.defaultImpl.StringHandler;
6
import org.jfw.apt.orm.core.enums.DE;
7
import org.jfw.apt.orm.core.enums.DE;
7

8

8
@PrimaryKey("code")
9
@PrimaryKey("code")
44
	public void setReadonly(boolean readonly) {
45
	public void setReadonly(boolean readonly) {
45
		this.readonly = readonly;
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
	public String getItem() {
49
	public String getItem() {
49
		return item;
50
		return item;
50
	}
51
	}

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

6
import java.util.ArrayList;
6
import java.util.ArrayList;
7
import java.util.Collection;
7
import java.util.Collection;
8
import java.util.Collections;
8
import java.util.Collections;
9
import java.util.Comparator;
9
import java.util.HashMap;
10
import java.util.HashMap;
10
import java.util.LinkedList;
11
import java.util.LinkedList;
11
import java.util.List;
12
import java.util.List;
17
import javax.sql.DataSource;
18
import javax.sql.DataSource;
18

19

19
import org.jfw.apt.annotation.Autowrie;
20
import org.jfw.apt.annotation.Autowrie;
21
import org.jfw.apt.annotation.DefaultValue;
22
import org.jfw.apt.annotation.Nullable;
20
import org.jfw.apt.web.annotation.Path;
23
import org.jfw.apt.web.annotation.Path;
21
import org.jfw.apt.web.annotation.operate.Get;
24
import org.jfw.apt.web.annotation.operate.Get;
25
import org.jfw.apt.web.annotation.operate.Post;
22
import org.jfw.apt.web.annotation.operate.Put;
26
import org.jfw.apt.web.annotation.operate.Put;
23
import org.jfw.apt.web.annotation.param.JdbcConn;
27
import org.jfw.apt.web.annotation.param.JdbcConn;
24
import org.jfw.apt.web.annotation.param.PathVar;
28
import org.jfw.apt.web.annotation.param.PathVar;
25
import org.jfw.apt.web.annotation.param.RequestBody;
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
import org.jfw.util.exception.JfwBaseException;
32
import org.jfw.util.exception.JfwBaseException;
27
import org.jfw.util.jdbc.JdbcTask;
33
import org.jfw.util.jdbc.JdbcTask;
28
import org.jfw.util.jdbc.JdbcUtil;
34
import org.jfw.util.jdbc.JdbcUtil;
64
		return ret;
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
	@Get
101
	@Get
68
	@Path("/info/{code}")
102
	@Path("/info/{code}")
69
	public DictInfo get(@PathVar String code) {
103
	public DictInfo get(@PathVar String code) {
105
		if (ab.get())
139
		if (ab.get())
106
			this.update(dict);
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
	@Put
156
	@Put
110
	@Path("/item/{code}")
157
	@Path("/item/{code}")
119
		}
166
		}
120
		// TODO : check dictItem.system == true can't modify
167
		// TODO : check dictItem.system == true can't modify
121
		LinkedList<DictItem> ret = new LinkedList<DictItem>();
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
				ret.add(transfer(it.next()));
175
				ret.add(transfer(it.next()));
128
			}
176
			}
129
		}
177
		}

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

6

6

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