SysUserService.java
12.2 KB
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
package cn.csbr.app.service;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.exception.AuthException;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.springboot.dao.mapper.SysOrgMapper;
import cn.csbr.springboot.dao.mapper.SysUserFingerMapper;
import cn.csbr.springboot.dao.mapper.SysUserMapper;
import cn.csbr.springboot.dao.model.SysOrg;
import cn.csbr.springboot.dao.model.SysUser;
import cn.csbr.springboot.dao.model.SysUserFinger;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.csbr.mybatis.CommonMapper;
import com.csbr.util.IdUtils;
import com.sun.xml.internal.xsom.impl.ListSimpleTypeImpl;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 用户信息查询
* @author liwuji
* @since 2018-12-10
*/
@Service
public class SysUserService {
@Autowired
private CommonMapper commonMapper;
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private SysUserFingerMapper sysUserFingerMapper;
@Autowired
private GUIContext guiContext;
@Value("${app.cabinet.group.code}")
private String cabinetGroupCode;
private static Logger logger = LoggerFactory.getLogger(SysUserService.class);
@Autowired
private SysOrgMapper sysOrgMapper;
public synchronized void updateUserPassword(SysUser user) {
logger.info("SysUserService.updateUserPassword修改密码方法入参为" + JSON.toJSONString(user));
String sql = "update sys_user set PWD = '" + user.getPwd() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getGuid() + "';";
commonMapper.update(sql);
}
public synchronized void updateUserPassword2(SysUser user) {
logger.info("SysUserService.updateUserPassword修改密码方法入参为" + JSON.toJSONString(user));
String sql2 = "update sys_user set PWD = '" + user.getPwd() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getGuid() + "';";
// userMapper.updatePwd(sql2);
}
public synchronized boolean updateUserCarid(SysUser user) {
logger.info("SysUserService.updateUserPassword修改carid方法入参为" + user.getCardId()+"|"+user.getLoginuser());
String sql = "update sys_user set cardid = '" + user.getCardId() + "',UPDATETIME = '" + new Timestamp(new Date().getTime()) + "',UPDATENAME = '" + user.getUpdatename() + "'where GUID = '" + user.getLoginuser() + "';";
System.out.println("准备上传");
commonMapper.update(sql);
System.out.println("上传完成");
Map m= commonMapper.queryOne("SELECT cardid FROM sys_user WHERE GUID='"+user.getLoginuser()+"'");
System.out.println("SELECT cardid FROM sys_user WHERE GUID='"+user.getLoginuser()+"'");
logger.info("1111"+ user.getLoginuser().toString() );
if(m!=null&&m.size()<=0)
return false;
System.out.println(m.get("cardid"));
return m.get("cardid")==null?false:m.get("cardid").equals(user.getCardId());
}
public synchronized void updateUserstate(SysUser user) {
logger.info("SysUserService.updateUserstate修改状态方法入参为" + JSON.toJSONString(user));
int res = sysUserMapper.updateByPrimaryKeySelective(user);
if (res <= 0) {
throw new AuthException("修改失败,请稍后重试");
}
}
public synchronized SysUser findUser(SysUser user) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
Example example = new Example(SysUser.class);
example.createCriteria().andEqualTo("fingerprint", user.getFingerprint());
List<SysUser> userList = sysUserMapper.selectByExample(example);
logger.info("查询到的对象为1"+userList);
if(CollectionUtils.isEmpty(userList)) {
return null;
}
return userList.get(0);
}
@Autowired
private FxConfigure fxConfigure;
public synchronized List<SysUserFinger> findUserFingerByUserid(SysUser user) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
Example example = new Example(SysUserFinger.class);
example.createCriteria().andEqualTo("userguid", user.getGuid()).andEqualTo("orgguid",user.getOrgguid())
.andEqualTo("groupcode",fxConfigure.getCabinetGroupCode());
List<SysUserFinger> userList = sysUserFingerMapper.selectByExample(example);
//logger.info("查询到的对象为1"+userList);
if(CollectionUtils.isEmpty(userList)) {
return null;
}
return userList;
// return userList.get(0);
}
public synchronized SysUser findUserByCardId(SysUser user) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
//String sql = " select ta.* from sys_user ta where bizstate='Y' and cardid="+"'"+user.getCardId()+"'"+" exists (select 'x' from sys_store_org tb where ta.orgguid=tb.deptguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
String sql="select u.* from sys_user u,sys_store_org s where bizstate = 'Y' AND cardid = "+"'"+user.getCardId()+"'"+" and u.orgguid = s.deptguid AND s.storeguid = '"+guiContext.getStoreguid()+"'";
System.out.println("card:"+sql);
List<Map> maps = commonMapper.queryList(sql);
List<SysUser> userList = new ArrayList<SysUser>();
for (Map map : maps) {
SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
userList.add(sysUser);
}
logger.info("查询到的对象为2"+userList);
if(CollectionUtils.isEmpty(userList)) {
guiContext.setDooropenUser(null);
return null;
}
guiContext.setDooropenUser(userList.get(0));
return userList.get(0);
}
//增加科室与柜子对应关系处理 YYQ 2021/09/09
public synchronized SysUser findUserByCardId(SysUser user,String CabinetGuid) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
//String sql = " select ta.* from sys_user ta where bizstate='Y' and cardid="+"'"+user.getCardId()+"'"+" exists (select 'x' from sys_store_org tb where ta.orgguid=tb.deptguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
String sql="select u.* from sys_user u,sys_store_org s where bizstate = 'Y' AND cardid = "+"'"+user.getCardId()+"'"+" and u.orgguid = s.deptguid AND s.storeguid = '"+guiContext.getStoreguid()+"'"
+" and exists (select 'x' from sys_sotre_org_cabinet tb where u.ORGGUID=tb.DEPTGUID AND TB.CABINETGUID="+"'"+CabinetGuid+"'"+" and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
System.out.println("card:"+sql);
List<Map> maps = commonMapper.queryList(sql);
List<SysUser> userList = new ArrayList<SysUser>();
for (Map map : maps) {
SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
userList.add(sysUser);
}
logger.info("查询到的对象为2"+userList);
if(CollectionUtils.isEmpty(userList)) {
guiContext.setDooropenUser(null);
return null;
}
guiContext.setDooropenUser(userList.get(0));
return userList.get(0);
}
public synchronized SysUser findUserByFinger(SysUser user) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
String sql = " select ta.* from sys_user ta where exists (select 'x' from sys_user_finger tb where ta.GUID=tb.userguid and tb.fingercd="+"'"+user.getFingerprint()+"'"+" and tb.groupcode='"+cabinetGroupCode+"'"
+" and ta.bizstate='Y' and ta.ORGGUID=tb.orgguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
logger.info(sql);
List<Map> maps = commonMapper.queryList(sql);
//logger.info("sql"+sql);
List<SysUser> sysUserList = new ArrayList<SysUser>();
for (Map map : maps) {
SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
sysUserList.add(sysUser);
}
logger.info("usercou"+sysUserList.size());
if(sysUserList.size()>0)
{return sysUserList.get(0);}
else
{return null;}
}
//增加科室与柜子对应关系处理 YYQ 202/09/09
public synchronized SysUser findUserByFinger(SysUser user,String CabinetGuid) {
logger.info("SysUserService.findUser查询用户信息入参为:" + JSON.toJSONString(user));
logger.info("sysMapper对象为"+sysUserMapper);
//构建SysUser类型的通用查询对象
String sql = " select ta.* from sys_user ta where exists (select 'x' from sys_user_finger tb where ta.GUID=tb.userguid and tb.fingercd="+"'"+user.getFingerprint()+"'"+" and tb.groupcode='"+cabinetGroupCode+"'"
+" and ta.bizstate='Y' and ta.ORGGUID=tb.orgguid and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") "
+" and exists (select 'x' from sys_sotre_org_cabinet tb where ta.ORGGUID=tb.DEPTGUID AND TB.CABINETGUID="+"'"+CabinetGuid+"'"+" and tb.storeguid="+"'"+guiContext.getStoreguid()+"'"+") ";
List<Map> maps = commonMapper.queryList(sql);
logger.info("sql:"+sql);
List<SysUser> sysUserList = new ArrayList<SysUser>();
for (Map map : maps) {
SysUser sysUser = JSON.parseObject(JSON.toJSONString(map), SysUser.class);
sysUserList.add(sysUser);
}
logger.info("usercou"+sysUserList.size());
if(sysUserList.size()>0)
{return sysUserList.get(0);}
else
{return null;}
}
public synchronized int updateFingerTextByGuid(SysUser user){
logger.info("SysUserService.updateFingerTextByGuid更新指纹信息入参为:" + JSON.toJSONString(user));
SysUserFinger userFinger=new SysUserFinger();
SysUser sysUser=sysUserMapper.selectByPrimaryKey(user.getGuid());
userFinger.setGuid(IdUtils.getUUID());
userFinger.setStoreguid(guiContext.getStoreguid());
userFinger.setStorename(guiContext.getStorename());
userFinger.setOrgguid(sysUser.getOrgguid());
SysOrg sysOrg=sysOrgMapper.selectByPrimaryKey(sysUser.getOrgguid());
userFinger.setOrgname(sysOrg.getOrgname());
userFinger.setFingercd(user.getFingerprint().trim());
userFinger.setGroupcode(cabinetGroupCode);
userFinger.setUserguid(user.getGuid());
userFinger.setUsername(sysUser.getRealname());
userFinger.setCreatetime(DateTime.now());
int count=sysUserFingerMapper.insert(userFinger);
count = sysUserMapper.updateByPrimaryKeySelective(user);
return count;
}
public synchronized SysUser findUserByCheck(String cardid) {
logger.info("返回用户卡号信息:" + cardid);
//构建SysUser类型的通用查询对象
Example example = new Example(SysUser.class);
example.createCriteria().andEqualTo("cardId", cardid);
List<SysUser> userList = sysUserMapper.selectByExample(example);
logger.info("查询到的对象为3"+userList);
if(CollectionUtils.isEmpty(userList)) {
return null;
}
return userList.get(0);
}
}