|  |  | @ -1,5 +1,6 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | package com.dsic.gj_erp.service; |  |  |  | package com.dsic.gj_erp.service; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import cn.hutool.core.util.StrUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.bean.request.LoginBean; |  |  |  | import com.dsic.gj_erp.bean.request.LoginBean; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.bean.sy.QSyfunp; |  |  |  | import com.dsic.gj_erp.bean.sy.QSyfunp; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.bean.sy.QSyifrp; |  |  |  | import com.dsic.gj_erp.bean.sy.QSyifrp; | 
			
		
	
	
		
		
			
				
					|  |  | @ -8,6 +9,7 @@ import com.dsic.gj_erp.bean.sy.Syuserp; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.dao.sy.SyuserpRepository; |  |  |  | import com.dsic.gj_erp.dao.sy.SyuserpRepository; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.exception.CustomException; |  |  |  | import com.dsic.gj_erp.exception.CustomException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.mapper.SyuserMapper; |  |  |  | import com.dsic.gj_erp.mapper.SyuserMapper; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.dsic.gj_erp.util.IPUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.util.JwtUtil; |  |  |  | import com.dsic.gj_erp.util.JwtUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.dsic.gj_erp.util.MD5Util; |  |  |  | import com.dsic.gj_erp.util.MD5Util; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.querydsl.jpa.impl.JPAQueryFactory; |  |  |  | import com.querydsl.jpa.impl.JPAQueryFactory; | 
			
		
	
	
		
		
			
				
					|  |  | @ -17,6 +19,7 @@ import org.springframework.util.StringUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.annotation.PostConstruct; |  |  |  | import javax.annotation.PostConstruct; | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.persistence.EntityManager; |  |  |  | import javax.persistence.EntityManager; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import javax.servlet.http.HttpServletRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.HashMap; |  |  |  | import java.util.HashMap; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Map; |  |  |  | import java.util.Map; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -49,8 +52,11 @@ public class ApiService { | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @return |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @throws CustomException |  |  |  |      * @throws CustomException | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public Map<String, Object> userLogin(LoginBean loginBean) throws CustomException { |  |  |  |     public Map<String, Object> userLogin(LoginBean loginBean, HttpServletRequest request) throws CustomException { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        String pwd=""; |  |  |  |        String pwd=""; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         String ip= IPUtils.getIpAddr(request); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         String macAddress=IPUtils.getMACAddress(ip); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!StringUtils.isEmpty(loginBean.getPwd())){ |  |  |  |         if (!StringUtils.isEmpty(loginBean.getPwd())){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             pwd= MD5Util.encrypt(loginBean.getPwd()); |  |  |  |             pwd= MD5Util.encrypt(loginBean.getPwd()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | @ -59,6 +65,18 @@ public class ApiService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (syuserp == null) { |  |  |  |         if (syuserp == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new CustomException(10201, "登陆失败,账号密码错误!"); |  |  |  |             throw new CustomException(10201, "登陆失败,账号密码错误!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (!syuserp.getIpAddress().equals(ip) ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             throw new CustomException(10201, "登陆失败,IP地址未授权!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (StrUtil.isNotEmpty(syuserp.getMacAddress())&& !syuserp.getMacAddress().equals(macAddress)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             throw new CustomException(10201, "登陆失败,mac地址错误!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (StrUtil.isEmpty(syuserp.getMacAddress())){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             syuserp.setMacAddress(macAddress); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             syuserMapper.updateUserMac(syuserp); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         syuserp.setPWD(null); |  |  |  |         syuserp.setPWD(null); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         String token = jwtUtil.generateToken(loginBean.getYhdm(), loginBean.getZxtbm(),syuserp.getYHMS()); |  |  |  |         String token = jwtUtil.generateToken(loginBean.getYhdm(), loginBean.getZxtbm(),syuserp.getYHMS()); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |