xinyb
2022-07-06 a4a24e74cc85db75990874e3e12459c454cb137f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package com.yc.userCenter.service;
 
import com.yc.service.BaseService;
import com.yc.userCenter.entity.JurisdictionEntiy;
import com.yc.userCenter.entity.UserEntity;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
 
@Service("UserCenterImpl")
public class UserCenterImpl extends BaseService implements UserCenterIfc  {
 
    @Override
    public List<Map<String, Object>> getUserCenter(String value,int page,int limit,String allow,String appAllow,String appList) throws Exception {
        try {
            String sql = "set nocount on\n" +
                    " declare @tel varchar(max) = '" + appList + "' \n"
                    + "select top " + limit + " COUNT(1) OVER() as total,a.avatarunid,a.usercode,a.username,"
                    + "(case a.gender when '1' then '男' when '2' then '女' else '' end) gender,b.ccname,"
                    + "(case a.usertype when 'NormalUser' then '普通用户' when 'SuperUser' then '超级用户' else '' end) usertype,"
                    + "a.tel,a.pwdexpired,a.inactive,a.logontype from _sys_LoginUser a left join t110601 b on a.cccode = b.ccCode"
                    + " where ( a.usercode like '%" + value + "%' or a.username like '%" + value + "%' or b.ccname like '%" + value + "%' "
                    + "or a.tel like '%" + value + "%') and a.UserCode not in "
                    + "(select top ((" + page + "-1)*" + limit + ") aa.UserCode from _sys_LoginUser aa order by aa.UserCode desc) "
                    + "and (a.LogonType in (" + allow + ")) \n";
            if (!"1".equals(appAllow)) {//查询是否注册app
                if ("2".equals(appAllow)) {//已注册
                    sql += " and a.tel in (select list from GetInStr(@tel))";
                } else if ("3".equals(appAllow)) {//未注册
                    sql += " and a.tel not in (select list from GetInStr(@tel))";
                } else {
                    throw new Exception("为找到符合条件的信息");
                }
            }
            sql += " order by a.UserCode desc";
            return this.jdbcTemplate.queryForList(sql);
        } catch (Exception e) {
            throw e;
        }        
    }
 
    @Override
    public Map<String, Object> getSysUser(String usercode) throws Exception {
        try {
            String sql="select a.avatarunid,a.usercode,a.username,(case a.gender when '1' then '男' when '2' then '女' else '' end) gender,"
                    + "b.ccname,(case a.usertype when 'NormalUser' then '普通用户' when 'SuperUser' then '超级用户' else '' end) usertype,"
                    + "a.tel,a.email,a.pwdexpired,a.cccode,a.memo3,a.PwdLength,"
                    + "(case a.PwdComplexLevel when '1' then '随便' when '2' then '数字[0..9]' when '3' then '数字+字母混合' else '' end) PwdComplexLevel,"
                    + "a.PromptExpired,(case a.LangId when '1' then '中文' when '2' then 'English' else '' end) LangId,"
                    + "(case a.Currency when '1' then '[RMB]人民币' when '2' then '[USD]美元' else '' end) Currency,a.OpenId,a.inactive,a.userName as NickName,"
                    + "a.WeiXinCorpUserId,a.WeiXinCorpUserName,a.oauth2openidforweixin,a.oauth2openidforqq,"
                    + "a.openid,d.nickname as qqname,d.AvatarUnid as qqunid,c.nickname as wxname,c.AvatarUnid as wxunid,"
                    + "a.accessids,a.profileids,a.defaultacctcode,a.defaultbrand,a.defaultstcode,a.isstopsystem,a.cccodepermission,a.ismodifypricewhenscanqrcode,"
                    + "a.isreceivemaintenancefeenotification,a.ismodifypricewhensalesorder,a.ismodifypricewhenpurchaseorder,a.switchToPageWhenLogonApp "
                    + "from _sys_LoginUser a left join t110601 b on a.cccode = b.ccCode "
                    + "left join t9666 d on a.oauth2openidforqq = d.OpenId " 
                    + "left join t9665 c on a.oauth2openidforweixin = c.OpenId "
                    + "where a.usercode='"+usercode+"'";
            return this.jdbcTemplate.queryForMap(sql);
        } catch (Exception e) {
            throw e;
        }        
    }
 
    @Override
    public Map<String, Object> getUpdateUserPwd(String newpwd, String usercode,Integer logontype) throws Exception {
        try {
            String sql="declare @UserCode varchar(20)=?,@newPwd varchar(max)=?, @row int \n"
                     + "select @UserCode = usercode from _sysUser where UserCode = @UserCode \n"
                     + "select @row=@@ROWCOUNT \n if @row > 0 begin \n"
                     + "update _sysUser set PassWord = @newPwd where UserCode = @UserCode\n"
                     + "select @row=@@ROWCOUNT \n if @row >0 \n"
                     + " select '密码修改成功' as msg \n else \n select '密码修改失败' as msg \n"
                     + "end \n else \n begin \n select '未能找到对应账户信息' as msg \n end";
            
            String sql1="declare @UserCode varchar(20)=?,@newPwd varchar(max)=?, @row int \n"
                     + "select @UserCode = cltcode from t110203 where cltcode = @UserCode \n"
                     + "select @row=@@ROWCOUNT \n if @row > 0 begin \n"
                     + "update t110203 set PassWord = @newPwd where cltcode = @UserCode\n"
                     + "select @row=@@ROWCOUNT \n if @row >0 \n"
                     + " select '密码修改成功' as msg \n else \n select '密码修改失败' as msg \n"
                     + "end \n else \n begin \n select '未能找到对应账户信息' as msg \n end";
            
            String sql2="declare @UserCode varchar(20)=?,@newPwd varchar(max)=?, @row int \n"
                     + "select @UserCode = EnterCode from t180201 where EnterCode = @UserCode \n"
                     + "select @row=@@ROWCOUNT \n if @row > 0 begin \n"
                     + "update t180201 set PassWord = @newPwd where EnterCode = @UserCode\n"
                     + "select @row=@@ROWCOUNT \n if @row >0 \n"
                     + " select '密码修改成功' as msg \n else \n select '密码修改失败' as msg \n"
                     + "end \n else \n begin \n select '未能找到对应账户信息' as msg \n end";
            
            String sql3="declare @UserCode varchar(20)=?,@newPwd varchar(max)=?, @row int \n"
                     + "select @UserCode = vndCode from t110302 where vndCode = @UserCode \n"
                     + "select @row=@@ROWCOUNT \n if @row > 0 begin \n"
                     + "update t110302 set PassWord = @newPwd where vndCode = @UserCode\n"
                     + "select @row=@@ROWCOUNT \n if @row >0 \n"
                     + " select '密码修改成功' as msg \n else \n select '密码修改失败' as msg \n"
                     + "end \n else \n begin \n select '未能找到对应账户信息' as msg \n end";
            if (logontype == 0) {
                return this.jdbcTemplate.queryForMap(sql,new Object[] {usercode,newpwd});
            } else if (logontype == 1) {
                return this.jdbcTemplate.queryForMap(sql1,new Object[] {usercode,newpwd});
            } else if (logontype == 2) {
                return this.jdbcTemplate.queryForMap(sql2,new Object[] {usercode,newpwd});
            } else if (logontype == 3) {
                return this.jdbcTemplate.queryForMap(sql3,new Object[] {usercode,newpwd});
            } else {
                return null;
            }
//            return this.jdbcTemplate.queryForMap(sql,new Object[] {usercode,newpwd});
        } catch (Exception e) {
            throw e;// TODO: handle exception
        }        
    }
    
    @Override
    public int getUserCenterInfo(String value, String usercode,Integer logontype) throws Exception {
        try {
            String sql = "set nocount on;\n update _sysUser set " + value + " where usercode='" + usercode
                    + "' \n select @@rowcount \n";
            String sql1 = "set nocount on;\n update t110203 set " + value + " where CltCode='" + usercode
                    + "' \n select @@rowcount \n";
            String sql2 = "set nocount on;\n update t180201 set " + value + " where EnterCode='" + usercode
                    + "' \n select @@rowcount \n";
            String sql3 = "set nocount on;\n update t110302 set " + value + " where vndCode='" + usercode
                    + "' \n select @@rowcount \n";
            if (logontype == 0) {
                return this.jdbcTemplate.queryForObject(sql, Integer.class);
            } else if (logontype == 1) {
                return this.jdbcTemplate.queryForObject(sql1, Integer.class);
            } else if (logontype == 2) {
                return this.jdbcTemplate.queryForObject(sql2, Integer.class);
            } else if (logontype == 3) {
                return this.jdbcTemplate.queryForObject(sql3, Integer.class);
            } else {
                return 0;
            }
        } catch (Exception e) {
            throw e;
        }
        
    }
 
    @Override
    public Map<String, Object> getselect2SQL(String codeId,String userCode) throws Exception {
        try {
//            String sql=    "select sqlscript from gField where fieldid in('defaultStcode','defaultAcctcode','ProfileIds','AccessIds','defaultBrand','cccode','CcCodePermission') and formid=9901";
            String sql=    "select g.sqlscript,(select a."+codeId+" from _sysUser a where a.UserCode='"+userCode+"') as val from gField g where g.fieldid ='"+codeId+"' and g.formid=9901";
            return this.jdbcTemplate.queryForMap(sql);
        } catch (Exception e) {
            throw e;
        }
        
    }
 
    @Override
    public List<Map<String, Object>> getMessage(String key,String search) throws Exception {
        try {
            String type="'notice','success','warning','error'";
            if("".equals(search) || !"0".equals(key)) {
                switch (key) {
                case "1":
                    type="'notice'";
                    break;
                case "2":
                    type="'success'";
                    break;
                case "3":
                    type="'warning'";
                    break;
                case "4":
                    type="'error'";
                    break;
                }
            }
            String sql =" set nocount on \n"
                    + " select a.messid,a.messagetxt,a.unvaliddate,a.createuser,a.createtime,\n"
                    + "a.topic ,(case a.messagetype when 'notice' then '通知消息' when 'success' then "
                    + "'成功消息' when 'warning' then '警告消息' when 'error' then '错误消息' else '通知消息' end) as type "
                    + "from _sysmessage a  where a.messagetype in ("+type+") and a.topic like '%"+search+"%'\n"
                    + " order by a.createtime desc \n";
            return this.jdbcTemplate.queryForList(sql);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public int delMessage(String id) throws Exception {
        try {
            String sql=" set nocount on; \n"
                    + "delete _sysMessage where messid in ("+id+") \n"
                    + "select @@rowcount \n";
            return this.jdbcTemplate.queryForObject(sql,Integer.class);
        } catch (Exception e) {
            throw e;
        }        
    }
 
    /**
     * 删除维护登录用户
     */
    @Override
    public int delUser(String usercode,Integer logontype) throws Exception {
        try {
            String sql="set nocount on;\n delete _sysUser  where usercode='"+usercode+"' \n select @@rowcount \n";
            String sql1="set nocount on;\n delete t110203  where CltCode='"+usercode+"' \n select @@rowcount \n";
            String sql2="set nocount on;\n delete t180201  where EnterCode='"+usercode+"' \n select @@rowcount \n";
            String sql3="set nocount on;\n delete t110302  where vndCode='"+usercode+"' \n select @@rowcount \n";
            if (logontype == 0) {
                return this.jdbcTemplate.queryForObject(sql, Integer.class);
            } else if (logontype == 1) {
                return this.jdbcTemplate.queryForObject(sql1, Integer.class);
            } else if (logontype == 2) {
                return this.jdbcTemplate.queryForObject(sql2, Integer.class);
            } else if (logontype == 3) {
                return this.jdbcTemplate.queryForObject(sql3, Integer.class);
            } else {
                return 0;
            }
        } catch (Exception e) {
            throw e;
        }
    }
 
    //sql查询
    @Override
    public SqlRowSet getSelect(String sql) throws Exception {
        try {
            return this.jdbcTemplate.queryForRowSet(sql);
        } catch (Exception e) {
            throw e;
        }    
    }
 
    //添加用户
    @Override
    public int addUser(UserEntity user) throws Exception {
        try {
            String sql="insert into _sysUser(UserCode,UserName,passWord,cccode,ccname,Companyid,companyname,UserType) values(?,?,?,?,?,?,?,?)\n select @@rowcount \n";
            return jdbcTemplate.queryForObject(sql, new Object[] {user.getUrserCode(),user.getUserName(),user.getPassWord(),
                    user.getCcCode(),user.getCcName(),user.getCompanyId(),user.getCompanyName(),user.getUserType()},Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public Map<String, Object> selectApp(String phone, String dbId) throws Exception {
        try {
            String sql="select userid,username,invitationcode,organizationname,departmentname,"
                    + "status,isdebug from gProfileInvitationCode "
                    + "where UserId in (select UserId from gProfile where Telephone='"+phone+"') and "
                    + "invitationcode in (select invitationcode from gsystem where id = "+dbId+")";
            return super.jdbcTemplate.queryForMap(sql);
        } catch (Exception e) {
            return null;
        }
    }
 
    @Override
    public List<String> selectApps(String dbId) {
        try {
            String sql = " select a.Telephone from gProfile a join gProfileInvitationCode b on a.UserId=b.UserId \n" +
                    " where b.invitationcode in (select invitationcode from gsystem where id = "+dbId+")";
            return super.jdbcTemplate.query(sql, new RowMapper<String>() {
                @Override
                public String mapRow(ResultSet resultSet, int i) throws SQLException {
                    return resultSet.getString(1);
                }
            },null);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public int updateApp(String value,String userId, String dbId) throws Exception {
        try {
            String sql="set nocount on \n declare @UserId int = ?, @id int = ? \n"
                    + " update gProfileInvitationCode set "+value
                    + " where UserId=@UserId and invitationcode in (select invitationcode from gsystem where id = @id) \n select @@rowcount";
            return super.jdbcTemplate.queryForObject(sql, new Object[] {userId,dbId},Integer.class);
        } catch (Exception e) {
            return 0;
        }        
    }
 
    @Override
    public int deleteApp(String userId, String dbId) throws Exception {
        try {
            String sql="set nocount on\n delete gProfileInvitationCode where UserId=? and invitationcode in (select invitationcode from gsystem where id = ?)\n select @@rowcount";
            return super.jdbcTemplate.queryForObject(sql, new Object[] {userId,dbId},Integer.class);
        } catch (Exception e) {
            return 0;
        }
    }
 
    @Override
    public int updateSetTing(JurisdictionEntiy j) throws Exception {
        try {
            String sql="set nocount on;\n update _sysUser set companyId=?,Cccode=?,DefaultBrand=?,ProfileIds=?,AccessIds=?"
                    + ",DefaultAcctcode=?,DefaultStcode=?,CompanyPermission=?,CcCodePermission=?,UserCodePermission=?,isModifyPriceWhenScanQrCode=?,IsStopSystem=?," +
                    "isModifyPriceWhenSalesOrder=?,isModifyPriceWhenPurchaseOrder=?,isReceiveMaintenanceFeeNotification=?" +
                    " where usercode=? \n select @@rowcount \n";
            return super.jdbcTemplate.queryForObject(sql, new Object[] {j.getCompanyId(),j.getCccode(),j.getDefaultBrand(),j.getProfileIds(),j.getAccessIds(),
                    j.getDefaultAcctcode(),j.getDefaultStcode(),j.getCompanyPermission(),j.getCcCodePermission(),j.getUserCodePermission(),
                    j.getIsModifyPriceWhenScanQrCode(),j.getIsStopSystem(),j.getIsModifyPriceWhenSalesOrder(),j.getIsModifyPriceWhenPurchaseOrder(),
            j.getIsReceiveMaintenanceFeeNotification(),j.getUserCode()},Integer.class);
        } catch (Exception e) {
            throw e;
        }
    }
 
    @Override
    public int updateTelephone(String value, String userCode, String userId) throws Exception {
        try {
            String sql = "declare @tel nvarchar\r\n";
            if (!userCode.equals("") && userId.equals("")) {
                sql += "select @tel=Telephone from t9668h where UserCode='" + userCode + "'\r\n"
                        + "if ISNULL(@tel,'') !='' and @tel !=''\r\n" + "begin\r\n" + "update t9668h set Telephone='"
                        + value + "' where UserCode='" + userCode + "'\r\n" + "end\r\n";
            } else if (userCode.equals("") && !userId.equals("")) {
                sql += "select @tel=Telephone from gProfile where UserId=" + userId + "\r\n"
                        + "if ISNULL(@tel,'') !='' and @tel !=''\r\n" + "begin\r\n" + "update gProfile set Telephone='"
                        + value + "' where UserId=" + userId + "\r\n" + "end\r\n";
            }
            sql += "select @@ROWCOUNT";
            return super.jdbcTemplate.queryForObject(sql, Integer.class);
        } catch (Exception e) {
            return 0;
        }
    }
 
    @Override
    public Map<String, Object> getIsAllowLogin() throws Exception {
        try {
            String sql="select top 1 isAllowCustomerLogin,isAllowStaffLogin,isAllowVendorLogin from v111613";
            return  super.jdbcTemplate.queryForMap(sql);
        } catch (Exception e) {
            return null;
        }
    }
 
}