| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.UserConstant; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.UserClient; |
| | | import com.whyc.mapper.BaojigroupUsrMapper; |
| | | import com.whyc.mapper.PageParamMapper; |
| | | import com.whyc.mapper.PermitGroupUserMapper; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.pojo.db_app_sys.PageParam; |
| | | import com.whyc.pojo.db_user.User; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.MD5Util; |
| | | import com.whyc.util.RSAUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.security.InvalidParameterException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Autowired(required = false) |
| | | private PermitGroupUserMapper pergroupUserMapper; |
| | | |
| | | @Resource |
| | | private PageParamMapper pageParamMapper; |
| | | |
| | | |
| | | //查询所有用户信息 |
| | | public Response getAllUser(String uname, String realName, int pageCurr, int pageSize) { |
| | | public Response getAllUser(String uname, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<User> list=mapper.getAllUser(uname,realName); |
| | | List<User> list=mapper.getAllUser(uname); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询所有用户信息"); |
| | | } |
| | |
| | | } |
| | | String pwd= RSAUtil.encrypt("123456", RSAUtil.getPublicKey()); |
| | | uinf.setPwd(pwd); |
| | | wrapper.select("uid","uname"); |
| | | wrapper.eq("uname",uinf.getName()); |
| | | wrapper.select("id","name"); |
| | | wrapper.eq("name",uinf.getName()); |
| | | User user=mapper.selectOne(wrapper); |
| | | if(user!=null){ |
| | | return new Response().setII(1,false,user,"用户名已存在"); |
| | | } |
| | | uinf.setCreateTime(new Date()); |
| | | int bl=mapper.insert(uinf); |
| | | return new Response().set(1,bl>0); |
| | | return new Response().set(1,bl>0,bl>0?"用户添加成功":"用户添加失败"); |
| | | } |
| | | //修改密码 |
| | | public Response changeSnId(String uname,String oldSnId, String newSnId) { |
| | |
| | | String newId=newOld[0]; |
| | | if(oldId.equals(snId)){ |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("usnid",RSAUtil.encrypt(newId,RSAUtil.getPublicKey())); |
| | | wrapper.eq("uname",uname); |
| | | wrapper.set("pwd",RSAUtil.encrypt(newId,RSAUtil.getPublicKey())); |
| | | wrapper.eq("name",uname); |
| | | int flag=mapper.update(null,wrapper); |
| | | return new Response().set(1,flag>0,flag>0?"修改成功":"修改失败"); |
| | | }else { |
| | |
| | | //重置密码 |
| | | public Response resetSnId(int uid ) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("usnid",RSAUtil.encrypt("123456",RSAUtil.getPublicKey())); |
| | | wrapper.eq("uid",uid); |
| | | wrapper.set("pwd",RSAUtil.encrypt("123456",RSAUtil.getPublicKey())); |
| | | wrapper.eq("id",uid); |
| | | int flag=mapper.update(null,wrapper); |
| | | return new Response().set(1,flag>0,flag>0?"修改成功":"修改失败"); |
| | | |
| | |
| | | }else { |
| | | int uid=User.getId(); |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("uname",uname); |
| | | wrapper.eq("name",uname); |
| | | int bl=mapper.delete(wrapper); |
| | | if(bl>0){ |
| | | //删除权限组下的用户 |
| | |
| | | return new Response().setII(1,bl>0,bl,"删除成功"); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | public Response login(String uname, String usnId, Integer platFrom, HttpServletRequest request) { |
| | | Response response = new Response(); |
| | | String[] dataArr = RSAUtil.decryptFrontP(usnId, RSAUtil.fontSeparator); |
| | |
| | | request.getSession().setAttribute("user", userDB); |
| | | |
| | | return response.setII(1,true, userDB,"登录成功"); |
| | | } |
| | | }*/ |
| | | |
| | | public void logout() { |
| | | Subject subject = SecurityUtils.getSubject(); |
| | |
| | | return new Response().set(1,false,"管理员个数超过上限"); |
| | | } |
| | | UpdateWrapper wrapper =new UpdateWrapper(); |
| | | wrapper.set("uid",minUid); |
| | | wrapper.eq("uid",uid); |
| | | wrapper.set("id",minUid); |
| | | wrapper.eq("id",uid); |
| | | int flag= mapper.update(null,wrapper); |
| | | return new Response().set(1,flag>0,flag>0?"身份变更成功":"身份变更失败"); |
| | | } |
| | |
| | | } |
| | | //根据用户id查询用户信息 |
| | | QueryWrapper qWrapper=new QueryWrapper(); |
| | | qWrapper.eq("uid",uid); |
| | | qWrapper.eq("id",uid); |
| | | qWrapper.last("limit 1"); |
| | | User uinf=mapper.selectOne(qWrapper); |
| | | //编辑 |
| | | UpdateWrapper wrapper =new UpdateWrapper(); |
| | | wrapper.set("uid",Integer.valueOf(maxUid)+1); |
| | | wrapper.eq("uid",uid); |
| | | wrapper.set("id",Integer.valueOf(maxUid)+1); |
| | | wrapper.eq("id",uid); |
| | | int flag= mapper.update(null,wrapper); |
| | | //如果是普通用户自己强退,将用户名对应的sessionId变更 |
| | | ServletContext servletContext = request.getServletContext(); |
| | |
| | | |
| | | public Response getUserNameList() { |
| | | QueryWrapper<User> query = Wrappers.query(); |
| | | query.select("uname"); |
| | | query.select("name"); |
| | | List<String> userNameList = mapper.selectList(query).stream().map(User::getName).collect(Collectors.toList()); |
| | | return new Response().set(1,userNameList); |
| | | } |
| | |
| | | //查询所有用户信息(不分页用于下拉) |
| | | public Response getUinf() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("uid","uname","urole"); |
| | | wrapper.gt("uid",100); |
| | | //wrapper.eq("urole",0);//普通用户 |
| | | wrapper.orderByAsc("uid"); |
| | | wrapper.select("id","name"); |
| | | wrapper.gt("id",100); |
| | | wrapper.orderByAsc("id"); |
| | | List<User> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"查询所有用户信息(不分页用于下拉)"); |
| | | } |
| | |
| | | if(uinf.getPhoneNumber()!=null){ |
| | | wrapper.set("phone_number",uinf.getPhoneNumber()); |
| | | } |
| | | if(uinf.getSex()!=null){ |
| | | wrapper.set("sex",uinf.getSex()); |
| | | } |
| | | if(uinf.getEmail()!=null){ |
| | | wrapper.set("email",uinf.getEmail()); |
| | | } |
| | | if(uinf.getRole()!=null){ |
| | | wrapper.set("role",uinf.getRole()); |
| | | } |
| | | wrapper.eq("id",uinf.getId()); |
| | | mapper.update(null,wrapper); |
| | | mapper.update((User) ActionUtil.objeNull,wrapper); |
| | | |
| | | return new Response().set(1,true,"编辑用户信息成功"); |
| | | } |
| | | //根据Ukey查询用户 |
| | | public User getUserByUKeyId(String ukeyId){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.select("uid","uname","real_name","urole","create_time","phone_number","address","face_id","ukey_id"); |
| | | queryWrapper.eq("ukey_id",ukeyId); |
| | | queryWrapper.last("limit 1"); |
| | | User User = mapper.selectOne(queryWrapper); |
| | | return User; |
| | | } |
| | | |
| | | //根据uname查询用户 |
| | | public User getUserByUserName(String uname){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.select("uid","uname","real_name","urole","create_time","phone_number","address","face_id","ukey_id"); |
| | | queryWrapper.eq("uname",uname); |
| | | queryWrapper.select("id","name","create_time","phone_number"); |
| | | queryWrapper.eq("name",uname); |
| | | queryWrapper.last("limit 1"); |
| | | User User = mapper.selectOne(queryWrapper); |
| | | return User; |
| | | } |
| | | /**锁定账号*/ |
| | | public void lock(Integer uId) { |
| | | UpdateWrapper<User> wrapper = Wrappers.update(); |
| | | wrapper.set("status", UserConstant.ACCOUNT_STATUS_LOCK_FAIL.getValue()).set("lock_time",new Date()).eq("uId",uId); |
| | | mapper.update((User) ActionUtil.objeNull,wrapper); |
| | | } |
| | | |
| | | /**更新登录时间*/ |
| | | public void updateLoginTime(Integer uId) { |
| | | UpdateWrapper<User> wrapper = Wrappers.update(); |
| | | wrapper.set("last_login_time", new Date()).eq("id",uId); |
| | | mapper.update((User) ActionUtil.objeNull,wrapper); |
| | | } |
| | | // 将所有登陆的用户的信息存到application中 |
| | | public void setApplication(User user) { |
| | | ServletContext application = ActionUtil.getApplication(); |
| | |
| | | application.setAttribute("users", map); |
| | | } |
| | | |
| | | //验证密码的时效性 |
| | | public int checkPasswordValidity(User uinf) { |
| | | int flag=1; |
| | | //获取系统设置的密码时效(57,15) |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("categoryId",15); |
| | | wrapper.eq("id",57); |
| | | wrapper.last("limit 1"); |
| | | PageParam pageParam=pageParamMapper.selectOne(wrapper); |
| | | if(pageParam!=null){ |
| | | int dayDifference=ActionUtil.daysBetween(uinf.getPasswordUpdateTime(),new Date()); |
| | | if((pageParam.getStatus()>0)&&(dayDifference>pageParam.getStatus())){ |
| | | flag= -1; |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | public List<User> searchCS_All2() { |
| | | return mapper.searchCS_All2(); |