fs-danaus
2021-09-29 03b162821b77a3d9686b0bc2104388f10a31cf66
提交 | 用户 | age
a6a76f 1 package com.yc.service.user;
F 2
3 import com.yc.action.grid.GridUtils;
4 import com.yc.entity.Page;
5 import com.yc.entity.UserAccountEntity;
6 import com.yc.factory.FactoryBean;
7 import com.yc.sdk.password.action.ChangePassword;
8 import com.yc.service.BaseService;
9 import com.yc.utils.IPUtil;
10 import org.springframework.dao.DataAccessException;
11 import org.springframework.dao.EmptyResultDataAccessException;
12 import org.springframework.jdbc.core.CallableStatementCallback;
13 import org.springframework.jdbc.core.CallableStatementCreator;
14 import org.springframework.jdbc.support.rowset.SqlRowSet;
15 import org.springframework.stereotype.Service;
16
17 import java.sql.*;
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20 import java.util.*;
21
22 /**
23  * 用户账号有关业务处理
24  * 
25  * @author 邓文峰 2010-2-24
26  * */
27 @Service("UserAccountServiceImpl")
28 public class UserAccountServiceImpl extends BaseService implements UserAccountServiceIfc {
29     // 登录日志
30     private final String LOGIN_LOG = "set nocount on ; \n"
31             + " declare @UserCode varchar(50),@UserName varchar(50), @Useripaddress varchar(50) , @SessionId varchar(80)  ; \n"
32             + " select  @UserCode = ? \n select @UserName  =? \n select @Useripaddress  =? \n select @SessionId =?  \n"
33             + " if not exists(select 1 from _sysLoginLog a where a.sessionid = @SessionId ) \n"
34             + " begin  \n"
35             + "     insert into _sysLoginLog(UserGUID,userCode,userName,inTime,useripaddress,sessionid ) \n" 
36             + "     values('.',@UserCode,@UserName" + ",getDate(),@useripaddress,@sessionid)  \n"
37             + " end else  \n"
38             + " begin  \n"
39             + "     update a set inTime = getDate() from  _sysLoginLog a where a.sessionid = @SessionId \n"
40             + " end \n";
41     // 用户权限
42     private final String GET_USER_PROFILE ="set nocount on; declare @formid int,@optype int,@hideFields varchar(800),@ReadOnlyFields varchar(800),@datelimit int                  \n"+
03b162 43         " declare @gridop varchar(20),@gridopVal varchar(20),@gridreadonlyyn int,@formtype int,@lastoptype int \n" +
F 44         " declare @lastStatisIds varchar(4000),@StatisIds varchar(4000)  \n"+
45         " declare @table table( formid int,optype int,hideFields varchar(800),ReadOnlyFields varchar(800),datelimit int,        \n"+
46         " gridop varchar(20),gridopVal varchar(20),gridreadonlyyn int,formtype int,StatisIds varchar(4000) )                                           \n"+
a6a76f 47
03b162 48         " insert into @table (formid, optype,formtype,StatisIds )     \n"+
a6a76f 49
03b162 50 //        " select  a.formid, a.optype,a.hidefields,a.readonlyfields,a.datelimit,a.gridop,a.gridopVal,a.gridreadonlyyn,b.formtype \n"+
F 51 //        " from gprofileformop a left join _sysmenu b on  a.formid=b.formid where a.profileid in(select profileid from gprofile  \n"+
52 //        " where profileid in(select profileid from gUserProfile where userCode=?))  order by a.formid,optype               \n"+
a6a76f 53             //by by danaus 2020/4/20 17:25,修正增加读取子职责权限
03b162 54         " select a.formid,a.optype,a.formtype,a.StatisIds \n" +
a6a76f 55             "from (\n" +
03b162 56             "\tselect  a.formid , a.optype,b.formtype,a.StatisIds \n" +
a6a76f 57             "\tfrom gprofileformop a \n" +
F 58             "\tleft join _sysmenu b on  a.formid=b.formid \n" +
59             "\tinner join gprofile c on a.ProfileID = c.ProfileID\n" +
60             "\tinner join gUserProfile d on a.ProfileID = d.ProfileID\n" +
61             "\twhere  d.userCode=?\n" +
62             "\n" +
63             "\t union \n" +
03b162 64             "\t select c.formid, c.optype,d.formtype, c.StatisIds \n" +
a6a76f 65             "\t FROM   gprofile_subprofile  a   \n" +
F 66             "\t INNER JOIN  gUserProfile b ON  a.profileid = b.ProfileID \n" +
67             "\t INNER JOIN  gProfileFormOP c ON  a.subprofileid = c.ProfileID\n" +
68             "\t  left join _sysmenu d on  c.formid=d.formid \n" +
69             "\t  where b.UserCode = ?\n" +
70             " ) a \n" +
71
72         " declare mycurFormId cursor for                                                                                        \n"+
73         "select formid from @table group by formid  having count(1) > 1                                                        \n"+
74         "open mycurFormId                                                                                                      \n"+
75         "fetch next from mycurFormId into @formid                                                                              \n"+
76         "while @@fetch_status = 0                                                                                              \n"+
77         "begin                                                                                                                 \n"+
78         "    set @lastoptype = 0                                                                                               \n"+
79         "    declare mycurOp cursor for                                                                                        \n"+
80         "    select isnull(optype,0) as optype from @table where formid = @formid                                                                     \n"+
81         "    open mycurOp                                                                                                         \n"+
82         "    fetch next from mycurOp into @optype                                                                                 \n"+
83         "    while @@fetch_status = 0                                                                                             \n"+
84         "    begin                                                                                                                \n"+
85         "       select @lastoptype = @lastoptype | @optype                                                                        \n"+
86         "       fetch next from mycurOp into @optype                                                                              \n"+
87         "    end                                                                                                                  \n"+
88         "    close mycurOp                                                                                                        \n"+
89         "    deallocate mycurOp                                                                                                   \n"+
03b162 90         "   set @lastStatisIds = '' \n" +
F 91         "   declare mycurStatisIds cursor for \n" +
92         "   select isnull(StatisIds,'') as StatisIds from @table where formid = @formid and isnull(StatisIds,'') <> '' \n" +
93         "   open mycurStatisIds \n" +
94         "   fetch next from mycurStatisIds into @StatisIds \n" +
95         "   while @@fetch_status = 0 \n" +
96         "   begin \n" +
97         "      if not exists(select 1 from getinstr(@lastStatisIds) a where a.list = isnull(@StatisIds,'') ) \n" +
98         "      begin \n" +
99         "          set @lastStatisIds = case when isnull(@lastStatisIds,'') = '' then '' else isnull(@lastStatisIds,'') + ';' end + isnull(@StatisIds,'') \n" +
100         "      end \n" +
101         "      fetch next from mycurStatisIds into @StatisIds" +
102         "   end \n" +
103         "   close mycurStatisIds \n" +
104         "   deallocate mycurStatisIds \n"+
105         "    update a set optype = @lastoptype,StatisIds = @StatisIds from @table a where formid = @formid                                               \n"+
a6a76f 106         "    fetch next from mycurFormId into @formid                                                                             \n"+
F 107         "end                                                                                                                   \n"+
108         "close mycurFormId                                                                                                     \n"+
109         "deallocate mycurFormId                                                                                                \n"+
110         "                                                                                                                      \n"+
111         "                                                                                                                      \n"+
03b162 112         "select distinct formid, optype,hidefields,readonlyfields,datelimit,gridop,gridopVal,gridreadonlyyn,formtype,StatisIds from @table        \n";
a6a76f 113
98c7bf 114     private final String GET_DEFAULT_SET = "set nocount on ; select * from _sysloaddefaultvalue where defaultset=?";
a6a76f 115
F 116     @Override
117     public void loginLog(String userCode, String userName, String userIpAddress,String sessionId) {
118     this.jdbcTemplate.update(LOGIN_LOG, userCode, userName, userIpAddress,sessionId);
119     }
120
121     @Override
122     public Map<String, Map<String, Object>> getUserProfiles(String userCode) {
123     SqlRowSet rs = this.jdbcTemplate.queryForRowSet(GET_USER_PROFILE, userCode,userCode);
124     Map<String, Map<String, Object>> map = new HashMap<String, Map<String, Object>>();
125     Map<String, Object> temp = null;
126     while (rs.next()) {
127         temp = new HashMap<String, Object>();
128         temp.put("optype", rs.getObject("optype"));
03b162 129         temp.put("statisIds", rs.getObject("StatisIds"));
a6a76f 130         //------by by danaus 2020/4/20 17:26 这些已不使用
F 131         //temp.put("hidefields", rs.getObject("hidefields"));
132         //temp.put("readonlyfields", rs.getObject("readonlyfields"));
133         //temp.put("datelimit", rs.getObject("datelimit"));
134         //temp.put("gridop", rs.getObject("gridop"));
135         //temp.put("gridopval", rs.getObject("gridopVal"));
136         //temp.put("gridreadonlyyn", rs.getObject("gridreadonlyyn"));
137
138         //------
139         temp.put("formtype", rs.getObject("formtype"));
140         map.put(rs.getString("formid"), temp);
141     }
142     return map;
143     }
144
145     @Override
146     public List<Map<String, Object>> getDefaultSet(String defaultSetName) {
147     return this.jdbcTemplate.queryForList(GET_DEFAULT_SET, defaultSetName);
148     }
149
150     @Override
151     public SqlRowSet getRowSet(String sql, Object... objects) {
152     return this.jdbcTemplate.queryForRowSet(sql, objects);
153     }
154
155     @Override
156     public List<Map<String, String>> StatisticUserLoginByDay(final Date start, final Date end) {
157     return this.jdbcTemplate.execute(new CallableStatementCreator() {
158         @Override
159         public CallableStatement createCallableStatement(Connection conn) throws SQLException {
160         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
161         CallableStatement cs = conn.prepareCall("{call onLineUser_statistic_by_day(?,?)}");
162         cs.setString(1, df.format(start));
163         cs.setString(2, df.format(end));
164         return cs;
165         }
166     }, new CallableStatementCallback<List<Map<String, String>>>() {
167         @Override
168         public List<Map<String, String>> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
169         ResultSet rs = cs.executeQuery();
170         if (rs != null) {
171             List<Map<String, String>> list = new ArrayList<Map<String, String>>();
172             Map<String, String> temp = null;
173             while (rs.next()) {
174             temp = new HashMap<String, String>();
175             temp.put("id", rs.getString("id"));
176             temp.put("dt", rs.getString("dt"));
177             temp.put("counts", rs.getString("counts"));
178             list.add(temp);
179             }
180             temp = null;
181             return list;
182         }
183         return null;
184         }
185
186     });
187     }
188
189     @Override
190     public List<Map<String, String>> StatisticUserLoginByHours(final Date start) {
191     return this.jdbcTemplate.execute(new CallableStatementCreator() {
192         @Override
193         public CallableStatement createCallableStatement(Connection conn) throws SQLException {
194         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
195         CallableStatement cs = conn.prepareCall("{call onLineUser_statistic_by_Hours(?)}");
196         cs.setString(1, df.format(start));
197         return cs;
198         }
199     }, new CallableStatementCallback<List<Map<String, String>>>() {
200         @Override
201         public List<Map<String, String>> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
202         ResultSet rs = cs.executeQuery();
203         if (rs != null) {
204             List<Map<String, String>> list = new ArrayList<Map<String, String>>();
205             Map<String, String> temp = null;
206             while (rs.next()) {
207             temp = new HashMap<String, String>();
208             temp.put("id", rs.getString("id"));
209             temp.put("dt", rs.getString("dt"));
210             temp.put("counts", rs.getString("counts"));
211             list.add(temp);
212             }
213             temp = null;
214             return list;
215         }
216         return null;
217         }
218     });
219     }
220
221     public Page<Map<String, Object>> findPages(final Page<Map<String, Object>> page) {
222     return this.jdbcTemplate.execute(new CallableStatementCreator() {
223         @Override
224         public CallableStatement createCallableStatement(Connection conn) throws SQLException {
225         String preStr = "{call " + PROC_NAME + "(?,?,?,?,?,?,?,?,?,?,?)}";
226         CallableStatement cs = null;
227         cs = conn.prepareCall(preStr);
228         cs.setString(1, page.getTableName());
229         cs.setString(2, page.getFieldList());
230         cs.setString(3, page.getPrimaryKey());
231         cs.setString(4, page.getWhere());
232         cs.setString(5, page.getOrder());
233         cs.setInt(6, page.getSortType());
234         cs.setInt(7, page.getRecorderCount());
235         cs.setInt(8, page.getPageSize());
236         cs.setInt(9, page.getPageIndex());
237
238         cs.registerOutParameter(10, Types.INTEGER);
239         cs.registerOutParameter(11, Types.INTEGER);
240         return cs;
241         }
242     }, new CallableStatementCallback<Page<Map<String, Object>>>() {
243
244         @Override
245         public Page<Map<String, Object>> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
246         cs.execute();
247         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
248         ResultSet rs = cs.getResultSet();
249         Map<String, Object> map = null;
250         String[] temp = page.getFieldList().split(",");
251         if (rs != null) while (rs.next()) {
252             map = new HashMap<String, Object>();
253             for (int i = 0; i < temp.length; i++)
254             map.put(temp[i], rs.getObject(temp[i]));
255             list.add(map);
256         }
257         cs.getMoreResults();
258         page.setTotalCount(cs.getInt(10));
259         page.setTotalPageCount(cs.getInt(11));
260         page.setResult(list);
261         return page;
262         }
263     });
264     }
265
266     private static final String QUIT_LOG = "set nocount on\n"
267             + " update _sysloginlog set outtime=getdate() where sessionid = ? ";
268
269     @Override
270     public void doQuitLog(String sessionId) {
271     this.jdbcTemplate.update(QUIT_LOG, sessionId);
272     }
273
274     // 查找用户信息
275     private final String fieldid = " UserCode,UserName,CompanyId,CompanyName, \n"
276             + " CcCode,CcName,AreaId,AreaName,EnterCode,EnterName, \n"
277             + " [Password] as Password,[Description] as Description,Memo, \n"
278             + " Memo1, Memo2, Memo3,HrCode,HrName,[Role] as Role,FlowchartYN, \n"
279             + " AgentActive,AgentUser,InDomain,DefaultStcode,DefaultSet, \n"
280             + " CompanyPermission,UserType,InActive,PwdLastModified, \n"
281             + " PwdExpired,PromptExpired,CalPwdExpired,PwdLength,PwdComplexLevel, \n"
282             + " DefaultAcctCode,LogonType,IsEnableLoadCollection,WxDeptID,Tel, \n"
283             + " Gender,EMail, \n"
284             + " LangId,Currency,WxCcCode,ProfileIds, \n"
285             + " AccessIds,OpenId,IsStopSystem , activeApp,DefaultBrand,cccodepermission,isModifyPriceWhenScanQrCode,UserCodePermission,\n"
286             + " case when ISNULL(inActive,0) = 1 then '当前用户【'+ISNULL(UserName,'') + '】已停用,请与管理员联系!' "
287                 +"    else case when isnull(CalPwdExpired,0) > 0 then '您的密码已过期【' "
288                 +"    + CAST(ISNULL(CalPwdExpired,0) as varchar)+'】天' "
289                 +"    else '您的密码还剩【'+CAST(0 - ISNULL(CalPwdExpired,0) as varchar)+'】天过期' end  " 
290                 +"    +',请在【' + convert(varchar(10),dateadd(day,PwdExpired, PwdLastModified ), 120) +'】前修改' " 
291                 +"    end as PasswordExpiredHint,WeiXinCorpUserId,Oauth2OpenIdForWeiXin,Oauth2OpenIdForQQ, \n"
292                 + " ShopCcCode,CompanyMemo,AvatarUnid \n";
293
294     @Override
295     public UserAccountEntity getUserInfoByUserCode(String userCode) {
296         String sql = "set nocount on\n"
297                 + " select top 1 " + fieldid 
298                 + " from _sys_LoginUser  \n"
299                 + " where UserCode collate Chinese_PRC_CS_AI = ?  and inActive<>1 \n";
300         try {
301             Map<String, Object> map  = this.jdbcTemplate.queryForMap(sql, userCode);
302             return getUserAccountEntity(map);
303         }catch(DataAccessException e ) {
304             if (e instanceof EmptyResultDataAccessException){
305                 return null ;
306             }else {
307                 e.printStackTrace();
308                  throw e;
309             }
310         }catch(Exception e){
311             e.printStackTrace();
312             throw e;
313         }
314         
315     }
316     
317     @Override
318     public UserAccountEntity getUserInfoByWeiXinCorpUserId(String userid) {
319         String sql = " set nocount on\n"
320                 + " select top 1 " + fieldid 
321                 + " from _sys_LoginUser  \n"
322                 + " where isnull(WeiXinCorpUserId,'') <> '' and WeiXinCorpUserId  = ?  and inActive<>1 \n";
323         try {
324             Map<String, Object> map  = this.jdbcTemplate.queryForMap(sql, userid);
325             return getUserAccountEntity(map);
326         }catch(DataAccessException e ) {
327             if (e instanceof EmptyResultDataAccessException){
328                 return null ;
329             }else {
330                 e.printStackTrace();
331                  throw e;
332             }
333         }catch(Exception e){
334             e.printStackTrace();
335             throw e;
336         }
337     }
338     
339     @Override
340     public UserAccountEntity getUserInfoByOauth2OpenIdForWeiXin(String openid) {
341         String sql = " set nocount on\n"
342                 + " select top 1 " + fieldid 
343                 + " from _sys_LoginUser  \n"
344                 + " where isnull(Oauth2OpenIdForWeiXin,'') <> '' and Oauth2OpenIdForWeiXin  = ?  and inActive<>1 \n";
345         try {
346             Map<String, Object> map  = this.jdbcTemplate.queryForMap(sql, openid);
347             return getUserAccountEntity(map);
348             
349         }catch(DataAccessException e ) {
350             if (e instanceof EmptyResultDataAccessException){
351                 return null ;
352             }else {
353                 e.printStackTrace();
354                  throw e;
355             }
356         }catch(Exception e){
357             e.printStackTrace();
358             throw e;
359         }
360     }
361
362     @Override
363     public UserAccountEntity getUserInfoByOauth2OpenIdForQQ(String openid) {
364         String sql = "set nocount on \n"
365                 + " select top 1 " + fieldid 
366                 + " from _sys_LoginUser  \n"
367                 + " where isnull(Oauth2OpenIdForQQ,'') <> '' and Oauth2OpenIdForQQ  = ?  and inActive<>1 \n";
368         try {
369             Map<String, Object> map  = this.jdbcTemplate.queryForMap(sql, openid);
370             return getUserAccountEntity(map);
371         }catch(DataAccessException e ) {
372             if (e instanceof EmptyResultDataAccessException){
373                 return null ;
374             }else {
375                 e.printStackTrace();
376                  throw e;
377             }
378         }catch(Exception e){
379             e.printStackTrace();
380             throw e;
381         }
382     }
383     
384     @Override
385     public UserAccountEntity getUserInfoByEmail(String email) {
386         String sql = "set nocount on \n"
387                 + " select top 1 " + fieldid 
388                 + " from _sys_LoginUser  \n"
389                 + " where isnull(email,'') <> '' and email  = ?  and inActive<>1 \n";
390         try {
391             Map<String, Object> map  = this.jdbcTemplate.queryForMap(sql, email);
392             return getUserAccountEntity(map);
393         }catch(DataAccessException e ) {
394             if (e instanceof EmptyResultDataAccessException){
395                 return null ;
396             }else {
397                 e.printStackTrace();
398                  throw e;
399             }
400         }catch(Exception e){
401             e.printStackTrace();
402             throw e;
403         }
404     }
405
406     @Override
407     public UserAccountEntity getUserInfoByTelephone(String telephone) {
408         try {
409             String sql = " set nocount on\n"
410                     + " select top 1 " + fieldid
411                     + " from _sys_LoginUser  \n"
412                     + " where isnull(tel,'') <> '' and tel  = ?  and inActive<>1 \n";
413             Map<String, Object> map = this.jdbcTemplate.queryForMap(sql, telephone);
414             return getUserAccountEntity(map);
415         }catch(DataAccessException e ) {
416             if (e instanceof EmptyResultDataAccessException){
417                 return null ;
418             }else {
419                 e.printStackTrace();
420                  throw e;
421             }
422         }catch(Exception e){
423             e.printStackTrace();
424             throw e;
425         }
426
427     }
428     
429     @Override
430     public List<UserAccountEntity> getUserInfos(String userCodes) {
431         String sql = " set nocount on \n "
432                 + " declare @UserCodes varchar(2000) = ? \n"
433                 + " select " + fieldid 
434                 + " from _sys_LoginUser  \n"
435                 + " where  (isnull(@UserCodes,'') = '' or UserCode in (select list from getinstr(@UserCodes))) \n" ;
436                 //+ " where inActive<>1 \n";
437         try {
438             List<UserAccountEntity> retList = new ArrayList<UserAccountEntity>() ;
439             List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql,userCodes);
440             for (int i = 0 ; list != null && i < list.size();i++) {
441                 retList.add(getUserAccountEntity(list.get(i)))  ;
442             }
443             return retList ;
444         }catch(DataAccessException e ) {
445             if (e instanceof EmptyResultDataAccessException){
446                 return null ;
447             }else {
448                 e.printStackTrace();
449                  throw e;
450             }
451         }catch(Exception e){
452             e.printStackTrace();
453             throw e;
454         }
455     }
456     
457     @Override
458     public List<UserAccountEntity> getUserInfos() {
459         String sql = " set nocount on \n"
460                 + " select " + fieldid 
461                 + " from _sys_LoginUser  \n" ;
462                 //+ " where inActive<>1 \n";
463         try {
464             List<UserAccountEntity> retList = new ArrayList<UserAccountEntity>() ;
465             List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql);
466             for (int i = 0 ; list != null && i < list.size();i++) {
467                 retList.add(getUserAccountEntity(list.get(i)))  ;
468             }
469             return retList ;
470         }catch(DataAccessException e ) {
471             if (e instanceof EmptyResultDataAccessException){
472                 return null ;
473             }else {
474                 e.printStackTrace();
475                  throw e;
476             }
477         }catch(Exception e){
478             e.printStackTrace();
479             throw e;
480         }
481     }
482     
483     private UserAccountEntity getUserAccountEntity(Map<String, Object> map) {
484         if (map == null) return null ;
485         UserAccountEntity userAccountEntity = new UserAccountEntity() ;
486         userAccountEntity.setUserCode(map.get("UserCode") == null?"":(String)map.get("UserCode"));
487         userAccountEntity.setUserName(map.get("UserName") == null?"":(String)map.get("UserName"));
488         userAccountEntity.setCompanyId(map.get("CompanyId") == null?"":(String)map.get("CompanyId"));
489         userAccountEntity.setCompanyName(map.get("CompanyName") == null?"":(String)map.get("CompanyName"));
490         userAccountEntity.setCompanyMemo(map.get("CompanyMemo") == null?"":(String)map.get("CompanyMemo"));
491         userAccountEntity.setCcCode(map.get("CcCode") == null?"":(String)map.get("CcCode"));
492         userAccountEntity.setCcName(map.get("CcName") == null?"":(String)map.get("CcName"));
493         userAccountEntity.setAreaId(map.get("AreaId") == null?"":(String)map.get("AreaId"));
494         userAccountEntity.setAreaName(map.get("AreaName") == null?"":(String)map.get("AreaName"));
495         userAccountEntity.setEnterCode(map.get("EnterCode") == null?"":(String)map.get("EnterCode"));
496         userAccountEntity.setEnterName(map.get("EnterName") == null?"":(String)map.get("EnterName"));
497         userAccountEntity.setPassword(map.get("Password") == null?"":(String)map.get("Password"));
498         userAccountEntity.setDescription(map.get("Description") == null?"":(String)map.get("Description"));
499         userAccountEntity.setMemo(map.get("Memo") == null?"":(String)map.get("Memo"));
500         userAccountEntity.setMemo1(map.get("Memo1") == null?"":(String)map.get("Memo1"));
501         userAccountEntity.setMemo2(map.get("Memo2") == null?"":(String)map.get("Memo2"));
502         userAccountEntity.setMemo3(map.get("Memo3") == null?"":(String)map.get("Memo3"));
503         userAccountEntity.setHrCode(map.get("HrCode") == null?"":(String)map.get("HrCode"));
504         userAccountEntity.setHrName(map.get("HrName") == null?"":(String)map.get("HrName"));
505         userAccountEntity.setRole(map.get("Role") == null?"":(String)map.get("Role"));
506         userAccountEntity.setFlowchartYN(map.get("FlowchartYN") != null&& map.get("FlowchartYN").equals(1)?true:false);
507         userAccountEntity.setAgentActive(map.get("AgentActive") != null&& map.get("AgentActive").equals(1)?true:false);
508         userAccountEntity.setAgentUser(map.get("AgentUser") == null?"":(String)map.get("AgentUser"));
509         userAccountEntity.setInDomain(map.get("InDomain") == null?"":(String)map.get("InDomain"));
510         userAccountEntity.setDefaultStcode(map.get("DefaultStcode") == null?"":(String)map.get("DefaultStcode"));
511         userAccountEntity.setCompanyPermission(map.get("CompanyPermission") == null?"":(String)map.get("CompanyPermission"));
512         userAccountEntity.setUserType(map.get("UserType") == null?"":(String)map.get("UserType"));
513         userAccountEntity.setInActive(map.get("InActive") != null&&map.get("InActive").equals(1)?true:false);
514         userAccountEntity.setPwdLastModified(map.get("PwdLastModified") == null?null:(Date)map.get("PwdLastModified"));
515         
516         userAccountEntity.setPwdExpired(map.get("PwdExpired") == null?0:(Integer)map.get("PwdExpired"));
517         userAccountEntity.setPromptExpired(map.get("PromptExpired") == null?0:(Integer)map.get("PromptExpired"));
518         userAccountEntity.setCalPwdExpired(map.get("CalPwdExpired") == null?0:(Integer)map.get("CalPwdExpired"));
519         userAccountEntity.setPwdLength(map.get("PwdLength") == null?0:(Integer)map.get("PwdLength"));
520         userAccountEntity.setPwdComplexLevel(map.get("PwdComplexLevel") == null?1:(Integer)map.get("PwdComplexLevel"));
521         userAccountEntity.setDefaultAcctCode(map.get("DefaultAcctCode") == null?"":(String)map.get("DefaultAcctCode"));
522         userAccountEntity.setDefaultBrand(map.get("Defaultbrand") == null?"":(String)map.get("Defaultbrand"));
523         userAccountEntity.setCcCodePermission(map.get("cccodepermission") == null?"":(String)map.get("cccodepermission"));
524         userAccountEntity.setUserCodePermission(map.get("UserCodePermission") == null?"":(String)map.get("UserCodePermission"));
525         userAccountEntity.setIsModifyPriceWhenScanQrCode(map.get("isModifyPriceWhenScanQrCode") == null?0:(Integer)map.get("isModifyPriceWhenScanQrCode"));
526         userAccountEntity.setLogonType(map.get("LogonType") == null?0:(Integer)map.get("LogonType"));
527         userAccountEntity.setEnableLoadCollection(map.get("IsEnableLoadCollection") != null&&map.get("IsEnableLoadCollection").equals(1)?true:false);
528         userAccountEntity.setWxDeptID(map.get("WxDeptID") == null?0:(Integer)map.get("WxDeptID"));
529         userAccountEntity.setTel(map.get("Tel") == null?"":(String)map.get("Tel"));
530         userAccountEntity.setGender(map.get("Gender") == null?0:(Integer)map.get("Gender"));
531         userAccountEntity.setEMail(map.get("EMail") == null?"":(String)map.get("EMail"));
532         userAccountEntity.setLangId(map.get("LangId") == null?null:(Integer)map.get("LangId"));
533         userAccountEntity.setCurrency(map.get("Currency") == null?"":(String)map.get("Currency"));
534         userAccountEntity.setWxCcCode(map.get("WxCcCode") == null?"":(String)map.get("WxCcCode"));
535         userAccountEntity.setProfileIds(map.get("ProfileIds") == null?"":(String)map.get("ProfileIds"));
536         userAccountEntity.setAccessIds(map.get("AccessIds") == null?"":(String)map.get("AccessIds"));
537         userAccountEntity.setOpenId(map.get("OpenId") == null?"":(String)map.get("OpenId"));
538         userAccountEntity.setStopSystem(map.get("IsStopSystem") != null&&map.get("IsStopSystem").equals(1)?true:false);
539         userAccountEntity.setDefaultSet(map.get("DefaultSet") == null?"":(String)map.get("DefaultSet"));
540         userAccountEntity.setPasswordExpiredHint(map.get("PasswordExpiredHint") == null?"":(String)map.get("PasswordExpiredHint"));
541         userAccountEntity.setWeiXinCorpUserId(map.get("WeiXinCorpUserId") == null?"":(String)map.get("WeiXinCorpUserId"));
542         userAccountEntity.setOauth2OpenIdForWeiXin(map.get("Oauth2OpenIdForWeiXin") == null?"":(String)map.get("Oauth2OpenIdForWeiXin"));
543         userAccountEntity.setOauth2OpenIdForQQ(map.get("Oauth2OpenIdForQQ") == null?"":(String)map.get("Oauth2OpenIdForQQ"));
544         userAccountEntity.setShopCcCode(map.get("ShopCcCode") == null?"":(String)map.get("ShopCcCode"));
545         userAccountEntity.setActiveApp(GridUtils.prossRowSetDataType_Int(map,"activeApp"));
546         userAccountEntity.setAvatarUnid(GridUtils.prossRowSetDataType_String(map,"AvatarUnid"));
547         return userAccountEntity ;
548     }
549     
550     //获取所有用户信息
551     public List<Map<String, Object>> getLoginUser(int curPage,int pageSize) {
552         try {
553             String sql = "set nocount on \n"
554                     + " select top "+pageSize+" * from _sys_LoginUser where UserCode not in (select top "+((curPage-1)*pageSize)+" UserCode from _sys_LoginUser)";
555             return this.jdbcTemplate.queryForList(sql);
556         }catch(DataAccessException e ) {
557             if (e instanceof EmptyResultDataAccessException){
558                 return null ;
559             }else {
560                 e.printStackTrace();
561                  throw e;
562             }
563         }catch(Exception e){
564             e.printStackTrace();
565             throw e;
566         }
567     }
568
569     //获得所有用户信息的总数
570     public int getUserTotal() {
571         try {
572             String sql = "set nocount on \n"
573                     + " select count(1) from _sys_LoginUser";
574             SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
575             if(rs.next()){
576                 return rs.getInt(1);
577             }
578             return 0;
579         }catch(DataAccessException e ) {
580             if (e instanceof EmptyResultDataAccessException){
581                 return 0 ;
582             }else {
583                 e.printStackTrace();
584                  throw e;
585             }
586         }catch(Exception e){
587             e.printStackTrace();
588             throw e;
589         }
590     }
591
592     /**
593      * 获取用户信息(带查询条件)
594      */
595     public List<Map<String, Object>> getLoginUser(int curPage, int pageSize,
596             String companyname, String usercocde, String username) {
597         try {
598             String filter = filterSql(companyname,usercocde,username);
599             String sql = "set nocount on \n"
600                     + " select top "+pageSize+" * from _sys_LoginUser where UserCode not in (select top "+((curPage-1)*pageSize)+" UserCode from _sys_LoginUser where "+filter+") and "+filter;
601             return this.jdbcTemplate.queryForList(sql);
602         }catch(DataAccessException e ) {
603             if (e instanceof EmptyResultDataAccessException){
604                 return null ;
605             }else {
606                 e.printStackTrace();
607                  throw e;
608             }
609         }catch(Exception e){
610             e.printStackTrace();
611             throw e;
612         }
613     }
614     
615
616     //获得用户信息的总数(带查询条件)
617     public int getUserTotal(String companyname, String usercocde, String username) {
618         try {
619             String filter=filterSql(companyname, usercocde, username);
620             String sql = "set nocount on\n"
621                     + " select count(Companyid) from _sys_LoginUser where "+filter;
622             SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
623             if(rs.next()){
624                 return rs.getInt(1);
625             }
626             return 0;
627         }catch(DataAccessException e ) {
628             if (e instanceof EmptyResultDataAccessException){
629                 return 0 ;
630             }else {
631                 e.printStackTrace();
632                  throw e;
633             }
634         }catch(Exception e){
635             e.printStackTrace();
636             throw e;
637         }
638     }
639     
640     public String filterSql(String companyname, String usercocde, String username){
641         String filter="";
642         if(!companyname.equals("") && !usercocde.equals("") && !username.equals("")){
643             filter=" companyname like '%"+companyname+"%' and UserCode like '%"+usercocde+"%' and UserName like '%"+username+"%'";
644         }else if(!companyname.equals("") &&  !usercocde.equals("")){
645             filter=" companyname like '%"+companyname+"%' and UserCode like '%"+usercocde+"%'";
646         }else if(!usercocde.equals("") && !username.equals("")){
647             filter=" UserCode like '%"+usercocde+"%' and UserName like '%"+username+"%'";
648         }else if(!companyname.equals("") && !username.equals("")){
649             filter=" companyname like '%"+companyname+"%' and UserName like '%"+username+"%'";
650         }else if(!companyname.equals("") && usercocde.equals("") && username.equals("")){
651             filter=" companyname like '%"+companyname+"%'";
652         }else if(companyname.equals("") && !usercocde.equals("") && username.equals("")){
653             filter=" UserCode like '%"+usercocde+"%'";
654         }else if(companyname.equals("") && usercocde.equals("") && !username.equals("")){
655             filter=" UserName like '%"+username+"%'";
656         }else{
657             filter="0=0";
658         }
659         return filter;
660     }
661     
662     
663     @Override
664     public void doCheckHasExpired() {
665             
666             try {
667                 this.simpleJdbcCallShopping
668                     .withProcedureName("oa_ChangeUserCodePasswordExpired") 
669                                 .execute();
670                 
671             }catch(DataAccessException e ) {
672                 if (e instanceof EmptyResultDataAccessException){
673                     return  ;
674                 }else {
675                     e.printStackTrace();
676                      throw e;
677                 }
678             }catch(Exception e){
679                 e.printStackTrace();
680                 throw e;
681             }
682             return ;
683     }
684
685     @Override
686     public boolean savePassword(String userCode, String password,String enterCode) {
687         String sql = "set nocount on \n"
688                 + " declare @UserCode varchar(50), @UserName varchar(50),@Password varchar(max) ;\n"
689                 + " declare @EnterCode varchar(50),@EnterName varchar(50),@LogonType int\n"
690                 + " declare @EnterDate datetime = getdate() ,@Result varchar(500) \n"
691                 + " declare @MyRowCount int,@MyError int,@Formid int ; \n"
692                 + " select @UserCode = ?,@Password = ? ,@EnterCode = ? ;  \n"
693                 + " select @Formid = 301114 ; \n"
694                 + " select @UserName = UserName,@LogonType = LogonType from _sys_LoginUser where usercode = @UserCode ;\n"
695                 + " select @MyRowCount = @@rowcount,@MyError = @@error ; \n"
696                 + " if isnull(@MyRowCount,0) = 0 \n"
697                 + " begin \n"
698                 + "    raiserror('用户不存在或已被禁用',16,1) ;\n"
699                 + "    return \n"
700                 + " end \n"
701                 + " select @EnterName = UserName from _sys_LoginUser where usercode = @EnterCode ;\n"
702                 + " select @MyRowCount = 0,@MyError = 0 ; \n"
703                 + " if isnull(@LogonType,0) = 0  \n"
704                 + " begin  \n"
705                 + "    update a set [password] = @Password , PwdLastModified = getdate() \n"
706                 + "    from _sysuser a where usercode = @UserCode ; \n"
707                 + "    select @MyRowCount = @@rowcount,@MyError = @@error ; \n"
708                 + " end \n"
709                 + " if isnull(@LogonType,0) = 1  \n"
710                 + " begin  \n"
711                 + "    update a set [password] = @Password , PwdLastModified = getdate() \n"
712                 + "    from t110203 a where cltcode = @UserCode ; \n"
713                 + "    select @MyRowCount = @@rowcount,@MyError = @@error ; \n"
714                 + " end \n"
715                 + " if isnull(@LogonType,0) = 2  \n"
716                 + " begin  \n"
717                 + "    update a set [password] = @Password , PwdLastModified = getdate() \n"
718                 + "    from t180201 a where hrcode = @UserCode ; \n"
719                 + "    select @MyRowCount = @@rowcount,@MyError = @@error ; \n"
720                 + " end \n"
721                 + " if isnull(@LogonType,0) = 3  \n"
722                 + " begin  \n"
723                 + "    update a set [password] = @Password , PwdLastModified = getdate() \n"
724                 + "    from t110302 a where vndcode = @UserCode ; \n"
725                 + "    select @MyRowCount = @@rowcount,@MyError = @@error ; \n"
726                 + " end \n"
727                 + " if isnull(@MyRowCount,0) > 0  \n"
728                 + " begin  \n"
729                 + "    insert into _sysUserPwdHistory(UserCode,UserName,PwdLastModified,[Password],EnterCode,EnterName) \n"
730                 + "    values(@UserCode,@UserName,getdate(),@Password,@EnterCode,@EnterName) ; \n"
731                 + " end \n"
732                 + " if isnull(@MyRowCount,0) > 0 \n"
733                 + " begin \n"
734                 + "     exec p219001  @UserCodes = @UserCode  , @UserNames = @UserName  ,@Formid = @Formid , \n"
735                 + "        @FormType = 22,@Doccode = @UserCode ,@CurFormid = @Formid  ,@SenderCode=@UserCode,@SenderName=@UserName, \n"
736                 + "        @ActiveType = 6 ,@isSendWxCorpMsgs = 0,@CorpAgentId = 0,@MsgFrom = 1,@EnterCode=@EnterCode,\n" + 
737                 "           @EnterName=@EnterName,@EnterDate=@EnterDate,@PostCode=@EnterCode,@PostName=@EnterName,\n" + 
738                 "           @PostDate=@EnterDate,@ButtonType='提交',@ActionType='通知',@Result=@Result output\n"
739                 + " end \n"
740                 + " select @MyRowCount ; \n";
741         Integer ret = null ;
742         try {
98c7bf 743             ret = this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {
J 744                     userCode,password,enterCode}) ;
a6a76f 745         }catch(DataAccessException e ) {
F 746             if (e instanceof EmptyResultDataAccessException){
747                 return false ;
748             }else {
749                 e.printStackTrace();
750                  throw e;
751             }
752         }catch(Exception e){
753             e.printStackTrace();
754             throw e;
755         }
756         return (ret != null && ret.equals(1)?true:false );
757     }
758     
759
760
761     @Override 
762     public String getTranslateVariable(String templateMsg,int formId,String docCode,
763             String userCode,String userName,String whereFieldId,String whereOthers) {
764         String sql = " set nocount on \n"
765                 + " declare @TemplateMsg nvarchar(max) = ?,@FormId int = ?,@DocCode nvarchar(50) = ? \n"
766                 + " declare @UserCode nvarchar(50) = ? ,@UserName nvarchar(100) = ? \n"
767                 + " declare @WhereFieldId nvarchar(100) = ?,@WhereOthers nvarchar(2000) = ? \n"
768                 + " exec p111637 @TemplateMsg = @TemplateMsg output ,@FormId = @FormId, \n"
769                 + "    @DocCode = @DocCode,@UserCode = @UserCode, \n" + 
770                 "       @UserName = @UserName ,@WhereFieldId = @WhereFieldId,@WhereOthers = @WhereOthers \n"
771                 + " select isnull(@TemplateMsg,'') as TemplateMsg \n" ;
772         String ret = null ;
773         try {
98c7bf 774             ret = this.jdbcTemplate.queryForObject(sql, String.class,new Object[] {
J 775                     templateMsg, formId, docCode,userCode, userName, whereFieldId, whereOthers}) ;
a6a76f 776         }catch(DataAccessException e ) {
F 777             if (e instanceof EmptyResultDataAccessException){
778                 return null  ;
779             }else {
780                 e.printStackTrace();
781                  throw e;
782             }
783         }catch(Exception e){
784             e.printStackTrace();
785             throw e;
786         }
787         return ret ; 
788     }
789     
790     
791     @Override
792     public boolean checkPasswordComplexity(String passwordPlainText) {
793         String sql = " set nocount on \n"
794                 + " select top 1 1 from _sysuserPwdEx where defaultpwd = ? \n" ;
795         Integer ret = null ;
796         try {
98c7bf 797             ret = this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {
J 798                     passwordPlainText}) ;
a6a76f 799         }catch(DataAccessException e ) {
F 800             if (e instanceof EmptyResultDataAccessException){
801                 return false ;
802             }else {
803                 e.printStackTrace();
804                  throw e;
805             }
806         }catch(Exception e){
807             e.printStackTrace();
808             throw e;
809         }
810         return (ret != null && ret.equals(1)?true:false );
811     }
812
813     @Override
814     public boolean checkPasswordHistory(String userCode,String passwordPlainText) throws Exception {
815         String sql = "set nocount on \n"
816                 + " select [password] as password from _sysUserPwdHistory  \n"
817                 + " where UserCode = ?  \n"
818                 + " and PwdLastModified between DATEADD(year,-1,getdate() ) \n"
819                 + " and getdate() and isnull(password,'') <> '' \n" ;
820         try {
821             List<Map<String,Object>> list =  this.jdbcTemplate.queryForList(sql,new Object[] {
822                     userCode}) ;
823             for (int i = 0 ;list != null && i < list.size();i ++) {
824                 String orgPassword = (String)list.get(i).get("password");
825                 if (orgPassword != null) {
826                     if ( orgPassword.length()<30 ) {   //该用户原密码未加密
827                         if (passwordPlainText.equals(orgPassword)) {
828                             return true ;
829                         }else {
830                             continue ;   
831                         }
832                     }
833                     
834                     String passwordHis =  ChangePassword.getDecryptPassword( orgPassword);
835                     if (passwordPlainText.equals(passwordHis)) {
836                         return true ;
837                     }
838                 }
839             }
840         }catch(DataAccessException e ) {
841             if (e instanceof EmptyResultDataAccessException){
842                 return false ;
843             }else {
844                 //e.printStackTrace();
845                  throw e;
846             }
847         }catch(Exception e){
848             //e.printStackTrace();
849             throw e;
850         }
851         return false;
852     }
853     
854     
855     /**
856      * 检查限制时间和IP,决定 是否可以登录
857      * 
858      */
859     @Override
860     public int checkUserLoginTimeAndIp(String usercode, String ip) throws  DataAccessException {
861     BaseService base = (BaseService) FactoryBean.getBean("BaseService");
862     String sql="set nocount on; \n" +
863             " declare @UserCode varchar(50) =?,@Now datetime = getdate(),@IP varchar(50) =?\n" +
864             " declare @Today datetime = convert(datetime,convert(varchar(10),@Now,120))\n" +
865             " declare @WeekDay int = datepart(weekday,@Today) \n" +
866             " if not exists(select top 1 1 from _sys_LimitLogin where usercode = @UserCode and isnull(isActived,0) = 1 ) \n" +
867             " begin select 1 ; return ; end \n" +
868             " if exists(\n" +
869             " select top 1 1 \n" +
870             " from _sys_LimitLogin a \n" +
871             " where a.usercode=@UserCode  \n" +
872             "    and (a.EnterDate is null or a.EnterDate = @Today)\n" +
873             "    and (a.WeekDay is null or a.WeekDay = isnull(@WeekDay,0) - 1 )\n" +
874             "   and (isnull(a.isExStatutoryHolidays,0) = 0 \n" +
875             "   or (isnull(a.isExStatutoryHolidays,0) = 1 \n" +
876             "      and not exists(select 1 from _sys_HolidaysDate where HolidaysDate = @Today)))\n" +
877             " and (isnull(a.StartTime,'') = '' and isnull(a.EndTime,'') = '' \n" +
878             "   or @Now between convert(datetime,@Today+' ' + replace(isnull(a.StartTime,''),' ','')) \n" +
879             "      and convert(datetime,@Today + ' ' + replace(isnull( a.EndTime,''),' ','')))\n" +
880             " and (isnull(a.StartIP,'') = '' and isnull(a.EndIP,'') = '' \n" +
881             "   or  isnull(@IP,'') between replace(replace(isnull(a.StartIP,''),' ',''),'.00','.') \n" +
882             "      and replace(replace(isnull(a.EndIP,''),' ',''),'.00','.'))\n" +
883             " and isnull(a.isActived,0) =1 )" +
884             " begin \n" +
885             "    select 1 ; return ; \n" +
886             " end \n" +
887             "  else \n" +
888             " begin \n" +
889             "    select 0 ; return ; \n" +
890             "  end ";
891
892         return base.getSimpleJdbcTemplate().queryForObject(sql,Integer.class,usercode,ip);
893
894 //    Calendar ca = Calendar.getInstance();
895 //    ca.setTime(new Date());
896 //    int week = ca.get(Calendar.DAY_OF_WEEK) - 1;// 当前星期几
897 //    //int year = ca.get(Calendar.YEAR);// 当前年份
898 //    String today = DateUtil.toDayDate();// 当前日期
899 //    // 第一步先查找自定义日期
900 //
901 //    List<Map<String, Object>> lm = base.getSimpleJdbcTemplate().queryForList("set nocount on; select * from _sys_LimitLogin where usercode=? and EnterDate is not null and isActived=1", usercode);
902 //    if (lm.size() > 0) {// 比较自定义日期
903 //        boolean dateFlag = false;
904 //        for (Map<String, Object> m : lm) {
905 //        // 比较那一个是当前时间
906 //        // String d1=(Date)m.get("EnterDate");
907 //        // SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd");
908 //        Date da1 = (Date) m.get("EnterDate");
909 //
910 //        if (DateUtil.daysBetween(da1, new Date()) == 0) { return prossIPAndTime(ip, base, today, m); }
911 //        }
912 //        if (!dateFlag) return 3;
913 //        // 其他的都不能通过登录
914 //    } else {// 比较星期,取出用户的星期设置
915 //        List<Map<String, Object>> list = base.getSimpleJdbcTemplate().queryForList("set nocount on; select * from _sys_LimitLogin where usercode=? and (EnterDate   is null or EnterDate='') and isActived=1", usercode);
916 //        if (list.size() > 0) {// 存在设置,否则就是还没对用户进行设置,应该是全都可以访问
917 //        boolean flg = false;
918 //        for (Map<String, Object> m : list) {
919 //            if (m.get("WeekDay")!=null&&!"".equalsIgnoreCase(m.get("WeekDay")+"")&&((Integer) m.get("WeekDay")) == week) {// 是当前设置的星期
920 //            flg = true;
921 //            return prossIPAndTime(ip, base, today, m);
922 //            }else {//没设置星期,则检查ip
923 //            return prossIPAndTime(ip, base, today, m);
924 //            }
925 //        }
926 //        if (!flg) {// 表示不在当前设置内,限制登录
927 //            return 3;
928 //        }
929 //        }
930 //
931 //    }
932
933     //return 0;
934     }
935
936     @Override
937     public int prossIPAndTime(String ip, BaseService base, String today, Map<String, Object> m) {
938     // 读取节假日表是否存在当前日期记录,再判断是不是当前的星期
939     if (m.get("isExStatutoryHolidays") != null && ((Integer) m.get("isExStatutoryHolidays")) == 1) {// 排除节假日时间
98c7bf 940         int holid = base.getSimpleJdbcTemplate().queryForObject("set nocount on; select count(*) from _sys_HolidaysDate where HolidaysDate=?", Integer.class, new Object[] { today });
a6a76f 941         if (holid != 0) {// 表示当前是节假日
F 942         return 3;// 与节假日和星期相同,所有不能登录
943         }
944     }
945     // 不是同一个星期,则继续处理时间和ip//取时间和ip与当前时间和ip相对比
946     boolean ipFlag = false;
947     boolean timeFlag = false;
948     // IP
949     String sIP = (String) m.get("StartIP");
950     String eIP = (String) m.get("EndIP");
951     if (sIP == null || "*".equalsIgnoreCase(sIP)) {
952         return 0;
953     } else {// 有IP段设置
954         if (IPUtil.ipCheck(sIP) && IPUtil.ipCheck(eIP)) {
955         int start = Integer.parseInt(sIP.split("\\.")[3]);
956         int end = Integer.parseInt(eIP.split("\\.")[3]);
957         int cur = Integer.parseInt(ip.split("\\.")[3]);
958         if (cur >= start && cur <= end) {// 在这个范围之内
959             ipFlag = true;
960
961         } else {
962             return 1;
963         }
964         }
965     }
966     // 时间
967     String sTime = (String) m.get("StartTime");
968     String eTime = (String) m.get("EndTime");
969     if (sTime == null || "".equalsIgnoreCase(sTime)) {// 没设置时间
970         return 0;
971     } else {
972         Calendar ca2 = Calendar.getInstance();// start
973         Calendar ca3 = Calendar.getInstance();// end
974         Calendar ca4 = Calendar.getInstance();// cur
975         ca2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(sTime.split(":")[0]));
976         ca2.set(Calendar.MINUTE, Integer.parseInt(sTime.split(":")[1]));
977         ca3.set(Calendar.HOUR_OF_DAY, Integer.parseInt(eTime.split(":")[0]));
978         ca3.set(Calendar.MINUTE, Integer.parseInt(eTime.split(":")[1]));
979         if (ca4.compareTo(ca2) >= 0 && ca4.compareTo(ca3) <= 0) {// 在充许时间内
980         timeFlag = true;
981         } else {
982         return 2;
983         }
984
985     }
986     if (ipFlag && timeFlag) return 0;
987     return 0;
988     }
989 }