| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.RSAUtil; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.UnknownAccountException; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.whyc.util.ActionUtil.createFilefolderIFNotExist; |
| | |
| | | private DocFaceService faceService; |
| | | |
| | | //查询所有用户信息 |
| | | public Response getAllUser(int pageCurr,int pageSize) { |
| | | public Response getAllUser(DocUser docUser, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<DocUser> list=mapper.getAllUser(); |
| | | List<DocUser> list=mapper.getAllUser(docUser); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null?true:false,pageInfo,"数据返回"); |
| | | } |
| | |
| | | } |
| | | //新添加用户信息 |
| | | public Response addUser(MultipartFile file,DocUser docUser) { |
| | | if(docUser.getName()!=null){ |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("name",docUser.getName()); |
| | | List list=mapper.selectList(wrapper); |
| | | if(list!=null&&list.size()>0){ |
| | | return new Response().setII(1,false,list,"用户名已存在"); |
| | | } |
| | | } |
| | | int faceId=(docUser.getFaceId()==null||docUser.getFaceId().isEmpty())?0:Integer.valueOf(docUser.getFaceId()); |
| | | //检测是否存在重新上传的人脸 |
| | | faceId=checkFaceData(file,faceId); |
| | | docUser.setFaceId(String.valueOf(faceId)); |
| | | docUser.setCreTime(new Date()); |
| | | int bl=mapper.insert(docUser); |
| | | return new Response().set(1,bl>0?true:false); |
| | | } |
| | |
| | | int bl=mapper.delete(wrapper); |
| | | return new Response().setII(1,bl>0?true:false,bl,"删除返回"); |
| | | } |
| | | |
| | | public Response login(String name, String snId, HttpServletRequest request) { |
| | | Response response = new Response(); |
| | | String[] dataArr = RSAUtil.decryptFrontP(snId, RSAUtil.fontSeparator); |
| | | //验签md5 |
| | | if (!dataArr[1].equals(ActionUtil.EncryptionMD5(org.apache.commons.lang3.StringUtils.trim(dataArr[0])).toString())) { |
| | | return response.set(1, false, "密码验签失败"); |
| | | } |
| | | UsernamePasswordToken userToken = new UsernamePasswordToken(name, dataArr[0]); |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | try { |
| | | subject.login(userToken); |
| | | } catch (Exception e) { |
| | | if(e instanceof UnknownAccountException){ |
| | | return response.set(1,false,"账号不存在"); |
| | | } |
| | | return response.set(1,false,"密码错误"); |
| | | } |
| | | //登录成功 |
| | | //Session存储当前用户及权限组列表 |
| | | DocUser userDB = (DocUser) subject.getPrincipal(); |
| | | userDB.setSnId(null); |
| | | request.getSession().setAttribute("user", userDB); |
| | | return response.setII(1,true, userDB,"登录成功"); |
| | | } |
| | | } |