66import info .xiaomo .core .service .AdminUserService ;
77import info .xiaomo .core .untils .MD5Util ;
88import org .springframework .beans .factory .annotation .Autowired ;
9- import org .springframework .beans .factory .annotation .Value ;
109import org .springframework .data .domain .Page ;
1110import org .springframework .data .domain .PageRequest ;
1211import org .springframework .web .bind .annotation .RequestMapping ;
@@ -69,12 +68,32 @@ public Map<String, Object> login(@RequestParam String userName, @RequestParam St
6968 return result ;
7069 }
7170
71+ /**
72+ * 添加用户
73+ *
74+ * @param operator
75+ * @param userName
76+ * @param password
77+ * @param authLevel
78+ * @return
79+ */
7280 @ RequestMapping (value = "add" , method = RequestMethod .POST )
73- public HashMap <String , Object > register (
81+ public HashMap <String , Object > add (
82+ @ RequestParam String operator ,
7483 @ RequestParam String userName ,
7584 @ RequestParam String password ,
7685 @ RequestParam int authLevel
7786 ) {
87+ AdminModel operatorModel = service .findAdminUserByUserName (operator );
88+ if (operator == null ) {
89+ result .put (code , notFound );
90+ return result ;
91+ }
92+ if (operatorModel .getAuthLevel () <= 0 ) {
93+ result .put (code , authError );
94+ return result ;
95+ }
96+
7897 AdminModel adminModel = service .findAdminUserByUserName (userName );
7998 if (adminModel != null ) {
8099 result .put (code , error );
@@ -108,15 +127,24 @@ public HashMap<String, Object> findUserById(@RequestParam("id") Long id) {
108127
109128
110129 @ RequestMapping (value = "findAll" , method = RequestMethod .GET )
111- public HashMap <String , Object > getAll (@ RequestParam (value = "start" ,defaultValue = "1" ) int start , @ RequestParam (value = "pageSize" , defaultValue ="10" ) int page ) {
130+ public HashMap <String , Object > getAll (@ RequestParam (value = "start" , defaultValue = "1" ) int start , @ RequestParam (value = "pageSize" , defaultValue = "10" ) int page ) {
112131 Page <AdminModel > pages = service .getAdminUsers (new PageRequest (start - 1 , page ));
113132 result .put (code , success );
114133 result .put (adminUsers , pages );
115134 return result ;
116135 }
117136
118137 @ RequestMapping (value = "deleteById" , method = RequestMethod .GET )
119- public HashMap <String , Object > deleteUserById (@ RequestParam ("id" ) Long id ) throws UserNotFoundException {
138+ public HashMap <String , Object > deleteUserById (@ RequestParam ("id" ) Long id , @ RequestParam String operator ) throws UserNotFoundException {
139+ AdminModel operatorModel = service .findAdminUserByUserName (operator );
140+ if (operator == null ) {
141+ result .put (code , notFound );
142+ return result ;
143+ }
144+ if (operatorModel .getAuthLevel () <= 0 ) {
145+ result .put (code , authError );
146+ return result ;
147+ }
120148 AdminModel adminModel = service .deleteAdminUserById (id );
121149 if (adminModel == null ) {
122150 result .put (code , notFound );
@@ -129,10 +157,20 @@ public HashMap<String, Object> deleteUserById(@RequestParam("id") Long id) throw
129157
130158 @ RequestMapping (value = "update" , method = RequestMethod .POST )
131159 public HashMap <String , Object > update (
160+ @ RequestParam ("operator" ) String operator ,
132161 @ RequestParam ("userName" ) String userName ,
133162 @ RequestParam ("password" ) String password ,
134163 @ RequestParam ("authLevel" ) int authLevel
135164 ) throws UserNotFoundException {
165+ AdminModel operatorModel = service .findAdminUserByUserName (operator );
166+ if (operator == null ) {
167+ result .put (code , notFound );
168+ return result ;
169+ }
170+ if (operatorModel .getAuthLevel () <= 0 ) {
171+ result .put (code , authError );
172+ return result ;
173+ }
136174 AdminModel adminModel = service .findAdminUserByUserName (userName );
137175 if (adminModel == null ) {
138176 result .put (code , notFound );
@@ -148,7 +186,16 @@ public HashMap<String, Object> update(
148186 }
149187
150188 @ RequestMapping (value = "forbid" , method = RequestMethod .GET )
151- public HashMap <String , Object > forbid (@ RequestParam ("id" ) Long id ) throws UserNotFoundException {
189+ public HashMap <String , Object > forbid (@ RequestParam ("id" ) Long id , @ RequestParam ("operator" ) String operator ) throws UserNotFoundException {
190+ AdminModel operatorModel = service .findAdminUserByUserName (operator );
191+ if (operator == null ) {
192+ result .put (code , notFound );
193+ return result ;
194+ }
195+ if (operatorModel .getAuthLevel () <= 0 ) {
196+ result .put (code , authError );
197+ return result ;
198+ }
152199 AdminModel model = service .findAdminUserById (id );
153200 if (model == null ) {
154201 result .put (code , notFound );
0 commit comments