| | |
| | | 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.constant.YamlProperties; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Page; |
| | | 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(Page page) { |
| | | PageHelper.startPage(page.getPageCurr(),page.getPageSize()); |
| | | List<DocUser> list=mapper.getAllUser(); |
| | | public Response getAllUser(DocUser docUser, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<DocUser> list=mapper.getAllUser(docUser); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null?true:false,pageInfo,"数据返回"); |
| | | } |
| | | //编辑所有用户信息 |
| | | public Response updateAllUser(MultipartFile file,DocUser docUser) { |
| | | public Response updateUser(MultipartFile file,DocUser docUser) { |
| | | int faceId=(docUser.getFaceId()==null||docUser.getFaceId().isEmpty())?0:Integer.valueOf(docUser.getFaceId()); |
| | | //检测是否存在重新上传的人脸 |
| | | faceId=checkFaceData(file,faceId); |
| | |
| | | } |
| | | //新添加用户信息 |
| | | public Response addUser(MultipartFile file,DocUser docUser) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | String[] dataArr = RSAUtil.decryptFront("123456", RSAUtil.fontSeparator); |
| | | String pwd = RSAUtil.encrypt(dataArr[0],RSAUtil.getPublicKey()); |
| | | docUser.setSnId(pwd); |
| | | 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); |
| | | } |
| | | |
| | | //检测是否存在重新上传的人脸 |
| | | public int checkFaceData(MultipartFile file,int faceId){ |
| | | String fileDirName = ""; |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | File jarFile = applicationHome.getDir(); |
| | | if( 1 == YamlProperties.runModel){ |
| | | fileDirName = jarFile.getParentFile().toString(); |
| | | }else{ |
| | | //打包版 |
| | | fileDirName = jarFile.toString(); |
| | | } |
| | | String root=fileDirName+"/face/"+File.separator; |
| | | if(file.isEmpty()){ |
| | | faceId=0; |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String root=fileDirName+File.separator+"face"+File.separator; |
| | | if(file==null){ |
| | | return faceId; |
| | | }else{ |
| | | String fileFileName = file.getOriginalFilename(); |
| | | String filePath = root + fileFileName; |
| | |
| | | } |
| | | return faceId; |
| | | } |
| | | //删除用户信息 |
| | | public Response delUser(int id) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("id",id); |
| | | 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,"登录成功"); |
| | | } |
| | | } |