提交代码

dev
胡锐 7 months ago
parent 7c6d7cfe6f
commit b6914bdf1f
  1. 8
      bweb/src/main/java/com/bweb/controller/SecMenuController.java
  2. 26
      bweb/src/main/java/com/bweb/controller/SecUserController.java
  3. 56
      service/src/main/java/com/hfkj/common/utils/AliyunService.java
  4. 430
      service/src/main/java/com/hfkj/common/utils/HttpsUtils.java
  5. 39
      service/src/main/java/com/hfkj/common/utils/RequestUtils.java
  6. 139
      service/src/main/java/com/hfkj/dao/SecUserLoginLogMapper.java
  7. 7
      service/src/main/java/com/hfkj/dao/SecUserLoginLogMapperExt.java
  8. 388
      service/src/main/java/com/hfkj/dao/SecUserLoginLogSqlProvider.java
  9. 296
      service/src/main/java/com/hfkj/entity/SecUserLoginLog.java
  10. 1303
      service/src/main/java/com/hfkj/entity/SecUserLoginLogExample.java
  11. 37
      service/src/main/java/com/hfkj/service/SecUserLoginLogService.java
  12. 98
      service/src/main/java/com/hfkj/service/impl/SecUserLoginLogServiceImpl.java
  13. 23
      service/src/main/java/com/hfkj/service/impl/SecUserServiceImpl.java
  14. 46
      service/src/main/java/com/hfkj/sysenum/SecUserLoginLogStatusEnum.java

@ -6,6 +6,8 @@ import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpUtils;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.SecMenu;
import com.hfkj.entity.SecRoleMenuRel;
@ -17,6 +19,8 @@ import com.hfkj.sysenum.SecMenuTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@ -216,8 +220,4 @@ public class SecMenuController {
}
return treeModelList;
}
}

@ -10,6 +10,7 @@ import com.hfkj.common.utils.MD5Util;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.SecUser;
import com.hfkj.model.ResponseData;
import com.hfkj.service.SecUserLoginLogService;
import com.hfkj.service.SecUserService;
import com.hfkj.sysenum.SecUserStatusEnum;
import io.swagger.annotations.Api;
@ -33,6 +34,8 @@ public class SecUserController {
@Resource
private SecUserService secUserService;
@Resource
private SecUserLoginLogService secUserLoginLogService;
@RequestMapping(value="/create",method = RequestMethod.POST)
@ResponseBody
@ -218,4 +221,27 @@ public class SecUserController {
}
@RequestMapping(value="/queryList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询登录日志列表")
public ResponseData queryLoginLogList(@RequestParam(value = "userId", required = true) String userId,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "pageNum", required = true) Integer pageNum,
@RequestParam(value = "pageSize", required = true) Integer pageSize) {
try {
Map<String,Object> param = new HashMap<>();
param.put("userId", userId);
param.put("status", status);
PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(secUserLoginLogService.getLogList(param));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,56 @@
package com.hfkj.common.utils;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
/**
* 阿里云业务服务
* @className: AliyunService
* @author: HuRui
* @date: 2024/4/3
**/
public class AliyunService {
/**
* 查询ip地址
* @param ip ip地址
* @return
*/
public static JSONObject queryAddress(String ip) {
try {
String host = "https://ipaddquery.market.alicloudapi.com";
String path = "/ip/address-query";
String method = "POST";
String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "APPCODE " + appcode);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> bodys = new HashMap<>();
bodys.put("ip", ip);
HttpResponse response = HttpUtils.doPost(host, path, method, headers, new HashMap<>(), bodys);
JSONObject resObj = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
if (resObj.getString("code").equals("200")) {
return resObj.getJSONObject("data");
}
return null;
} catch (Exception e) {
return null;
}
}
public static void main(String[] args) {
try {
System.out.println(queryAddress("123.147.76.209"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -203,44 +203,6 @@ public class HttpsUtils {
return null;
}
public static JSONObject doWxGet(String url, Map<String, Object> params) {
String apiUrl = url;
StringBuffer param = new StringBuffer();
int i = 0;
for (String key : params.keySet()) {
if (i == 0)
param.append("?");
else
param.append("&");
param.append(key).append("=").append(params.get(key));
i++;
}
apiUrl += param + "#wechat_redirect";
String result = null;
HttpClient httpClient = null;
try {
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
HttpGet httpGet = new HttpGet(apiUrl);
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = IOUtils.toString(instream, "UTF-8");
}
return JSON.parseObject(result);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
return null;
}
/**
* 发送 POST 请求HTTP不带输入数据
*
@ -297,54 +259,6 @@ public class HttpsUtils {
return null;
}
/**
* 发送 POST 请求K-V形式
*
* @param apiUrl
* API接口URL
* @param params
* 参数map
* @return
*/
public static JSONObject doPostSendSms(String apiUrl, Map<String, Object> params) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
List<NameValuePair> pairList = new ArrayList<>(params.size());
for (Map.Entry<String, Object> entry : params.entrySet()) {
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
pairList.add(pair);
}
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
/**
* 发送 POST 请求JSON形式
*
@ -389,80 +303,6 @@ public class HttpsUtils {
return null;
}
public static JSONObject doHuiLianTongPost(String apiUrl) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity("", "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static JSONObject doWxPost(String apiUrl, Map<String,String> body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(JSON.toJSONString(body), "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static JSONObject doPost(String apiUrl, Map<String,Object> body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
@ -502,123 +342,6 @@ public class HttpsUtils {
return null;
}
public static JSONObject doPostForm(String apiUrl, String body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(body,"UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static JSONObject doSmsPost(String apiUrl, Map<String,Object> body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(body.get("from").toString());// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static JSONObject doWxH5PayPost(String apiUrl, Map<String,Object> body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(body.get("from").toString());// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
/**
* 发送 POST 请求JSON形式
*
@ -661,167 +384,22 @@ public class HttpsUtils {
return null;
}
public static JSONObject doPost(String apiUrl, String str, String token, String sign, Long ts) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
httpPost.setHeader("token", token);
httpPost.setHeader("sign", sign);
httpPost.setHeader("ts", ts.toString());
StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
/**
* @Author Sum1Dream
* @Description // 不带证书请求xml
* @Date 11:42 2021/6/8
* @Param [url, str]
* @return com.alibaba.fastjson.JSONObject
**/
public static JSONObject postData(String url, String str) {
CloseableHttpClient httpClient = null;
if (url.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
httpPost.addHeader("Content-Type", "text/xml");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
/**
* @Author Sum1Dream
* @Description // 带证书请求 xml
* @Date 11:45 2021/6/8
* @Param [url, mchId, str]
* @return com.alibaba.fastjson.JSONObject
**/
public static JSONObject postData(String url, String mchId , String str) {
CloseableHttpClient httpClient = null;
if (url.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(readCertificate(mchId))
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
httpPost.addHeader("Content-Type", "text/xml");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
public static SSLConnectionSocketFactory readCertificate(String mchId) {
try {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream stream = new FileInputStream( "F:/mine/hai-server/hai-service/src/main/java/privatekey/apiclient_cert.p12");
keyStore.load(stream , mchId.toCharArray());
stream.close();
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mchId.toCharArray()).build();
return new SSLConnectionSocketFactory(
sslcontext,
new String[]{"TLSv1"},
null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
} catch (Exception e) {
System.out.println("证书双向认证出现异常" + e);
}
return null;
}
/**
* 创建SSL安全连接
*
*
* @return
*/
private static SSLConnectionSocketFactory createSSLConnSocketFactory() {
SSLConnectionSocketFactory sslsf = null;
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
@ -832,5 +410,5 @@ public class HttpsUtils {
}
return sslsf;
}
}

@ -1,10 +1,12 @@
package com.hfkj.common.utils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import javax.servlet.http.HttpServletRequest;
public class RequestUtils {
public static String getIpAddress(HttpServletRequest request) {
// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
@ -35,4 +37,39 @@ public class RequestUtils {
return ip;
}
/**
* 获取请求的ip
*/
public static String getRequestIp() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return null;
}
// 从获取RequestAttributes中获取HttpServletRequest的信息
HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}

@ -0,0 +1,139 @@
package com.hfkj.dao;
import com.hfkj.entity.SecUserLoginLog;
import com.hfkj.entity.SecUserLoginLogExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;
/**
*
* 代码由工具生成,请勿修改!!!
* 如果需要扩展请在其父类进行扩展
*
**/
@Repository
public interface SecUserLoginLogMapper extends SecUserLoginLogMapperExt {
@SelectProvider(type=SecUserLoginLogSqlProvider.class, method="countByExample")
long countByExample(SecUserLoginLogExample example);
@DeleteProvider(type=SecUserLoginLogSqlProvider.class, method="deleteByExample")
int deleteByExample(SecUserLoginLogExample example);
@Delete({
"delete from sec_user_login_log",
"where id = #{id,jdbcType=BIGINT}"
})
int deleteByPrimaryKey(Long id);
@Insert({
"insert into sec_user_login_log (user_id, user_login_name, ",
"ip, country, region_id, ",
"region_name, city_id, ",
"city_name, isp, `status`, ",
"remark, create_time, ",
"ext_1, ext_2, ext_3)",
"values (#{userId,jdbcType=BIGINT}, #{userLoginName,jdbcType=VARCHAR}, ",
"#{ip,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{regionId,jdbcType=VARCHAR}, ",
"#{regionName,jdbcType=VARCHAR}, #{cityId,jdbcType=VARCHAR}, ",
"#{cityName,jdbcType=VARCHAR}, #{isp,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
"#{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
})
@Options(useGeneratedKeys=true,keyProperty="id")
int insert(SecUserLoginLog record);
@InsertProvider(type=SecUserLoginLogSqlProvider.class, method="insertSelective")
@Options(useGeneratedKeys=true,keyProperty="id")
int insertSelective(SecUserLoginLog record);
@SelectProvider(type=SecUserLoginLogSqlProvider.class, method="selectByExample")
@Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="user_login_name", property="userLoginName", jdbcType=JdbcType.VARCHAR),
@Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
@Result(column="country", property="country", jdbcType=JdbcType.VARCHAR),
@Result(column="region_id", property="regionId", jdbcType=JdbcType.VARCHAR),
@Result(column="region_name", property="regionName", jdbcType=JdbcType.VARCHAR),
@Result(column="city_id", property="cityId", jdbcType=JdbcType.VARCHAR),
@Result(column="city_name", property="cityName", jdbcType=JdbcType.VARCHAR),
@Result(column="isp", property="isp", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
})
List<SecUserLoginLog> selectByExample(SecUserLoginLogExample example);
@Select({
"select",
"id, user_id, user_login_name, ip, country, region_id, region_name, city_id, ",
"city_name, isp, `status`, remark, create_time, ext_1, ext_2, ext_3",
"from sec_user_login_log",
"where id = #{id,jdbcType=BIGINT}"
})
@Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="user_login_name", property="userLoginName", jdbcType=JdbcType.VARCHAR),
@Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
@Result(column="country", property="country", jdbcType=JdbcType.VARCHAR),
@Result(column="region_id", property="regionId", jdbcType=JdbcType.VARCHAR),
@Result(column="region_name", property="regionName", jdbcType=JdbcType.VARCHAR),
@Result(column="city_id", property="cityId", jdbcType=JdbcType.VARCHAR),
@Result(column="city_name", property="cityName", jdbcType=JdbcType.VARCHAR),
@Result(column="isp", property="isp", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
})
SecUserLoginLog selectByPrimaryKey(Long id);
@UpdateProvider(type=SecUserLoginLogSqlProvider.class, method="updateByExampleSelective")
int updateByExampleSelective(@Param("record") SecUserLoginLog record, @Param("example") SecUserLoginLogExample example);
@UpdateProvider(type=SecUserLoginLogSqlProvider.class, method="updateByExample")
int updateByExample(@Param("record") SecUserLoginLog record, @Param("example") SecUserLoginLogExample example);
@UpdateProvider(type=SecUserLoginLogSqlProvider.class, method="updateByPrimaryKeySelective")
int updateByPrimaryKeySelective(SecUserLoginLog record);
@Update({
"update sec_user_login_log",
"set user_id = #{userId,jdbcType=BIGINT},",
"user_login_name = #{userLoginName,jdbcType=VARCHAR},",
"ip = #{ip,jdbcType=VARCHAR},",
"country = #{country,jdbcType=VARCHAR},",
"region_id = #{regionId,jdbcType=VARCHAR},",
"region_name = #{regionName,jdbcType=VARCHAR},",
"city_id = #{cityId,jdbcType=VARCHAR},",
"city_name = #{cityName,jdbcType=VARCHAR},",
"isp = #{isp,jdbcType=VARCHAR},",
"`status` = #{status,jdbcType=INTEGER},",
"remark = #{remark,jdbcType=VARCHAR},",
"create_time = #{createTime,jdbcType=TIMESTAMP},",
"ext_1 = #{ext1,jdbcType=VARCHAR},",
"ext_2 = #{ext2,jdbcType=VARCHAR},",
"ext_3 = #{ext3,jdbcType=VARCHAR}",
"where id = #{id,jdbcType=BIGINT}"
})
int updateByPrimaryKey(SecUserLoginLog record);
}

@ -0,0 +1,7 @@
package com.hfkj.dao;
/**
* mapper扩展类
*/
public interface SecUserLoginLogMapperExt {
}

@ -0,0 +1,388 @@
package com.hfkj.dao;
import com.hfkj.entity.SecUserLoginLog;
import com.hfkj.entity.SecUserLoginLogExample.Criteria;
import com.hfkj.entity.SecUserLoginLogExample.Criterion;
import com.hfkj.entity.SecUserLoginLogExample;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;
public class SecUserLoginLogSqlProvider {
public String countByExample(SecUserLoginLogExample example) {
SQL sql = new SQL();
sql.SELECT("count(*)").FROM("sec_user_login_log");
applyWhere(sql, example, false);
return sql.toString();
}
public String deleteByExample(SecUserLoginLogExample example) {
SQL sql = new SQL();
sql.DELETE_FROM("sec_user_login_log");
applyWhere(sql, example, false);
return sql.toString();
}
public String insertSelective(SecUserLoginLog record) {
SQL sql = new SQL();
sql.INSERT_INTO("sec_user_login_log");
if (record.getUserId() != null) {
sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}");
}
if (record.getUserLoginName() != null) {
sql.VALUES("user_login_name", "#{userLoginName,jdbcType=VARCHAR}");
}
if (record.getIp() != null) {
sql.VALUES("ip", "#{ip,jdbcType=VARCHAR}");
}
if (record.getCountry() != null) {
sql.VALUES("country", "#{country,jdbcType=VARCHAR}");
}
if (record.getRegionId() != null) {
sql.VALUES("region_id", "#{regionId,jdbcType=VARCHAR}");
}
if (record.getRegionName() != null) {
sql.VALUES("region_name", "#{regionName,jdbcType=VARCHAR}");
}
if (record.getCityId() != null) {
sql.VALUES("city_id", "#{cityId,jdbcType=VARCHAR}");
}
if (record.getCityName() != null) {
sql.VALUES("city_name", "#{cityName,jdbcType=VARCHAR}");
}
if (record.getIsp() != null) {
sql.VALUES("isp", "#{isp,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}");
}
if (record.getRemark() != null) {
sql.VALUES("remark", "#{remark,jdbcType=VARCHAR}");
}
if (record.getCreateTime() != null) {
sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
}
if (record.getExt1() != null) {
sql.VALUES("ext_1", "#{ext1,jdbcType=VARCHAR}");
}
if (record.getExt2() != null) {
sql.VALUES("ext_2", "#{ext2,jdbcType=VARCHAR}");
}
if (record.getExt3() != null) {
sql.VALUES("ext_3", "#{ext3,jdbcType=VARCHAR}");
}
return sql.toString();
}
public String selectByExample(SecUserLoginLogExample example) {
SQL sql = new SQL();
if (example != null && example.isDistinct()) {
sql.SELECT_DISTINCT("id");
} else {
sql.SELECT("id");
}
sql.SELECT("user_id");
sql.SELECT("user_login_name");
sql.SELECT("ip");
sql.SELECT("country");
sql.SELECT("region_id");
sql.SELECT("region_name");
sql.SELECT("city_id");
sql.SELECT("city_name");
sql.SELECT("isp");
sql.SELECT("`status`");
sql.SELECT("remark");
sql.SELECT("create_time");
sql.SELECT("ext_1");
sql.SELECT("ext_2");
sql.SELECT("ext_3");
sql.FROM("sec_user_login_log");
applyWhere(sql, example, false);
if (example != null && example.getOrderByClause() != null) {
sql.ORDER_BY(example.getOrderByClause());
}
return sql.toString();
}
public String updateByExampleSelective(Map<String, Object> parameter) {
SecUserLoginLog record = (SecUserLoginLog) parameter.get("record");
SecUserLoginLogExample example = (SecUserLoginLogExample) parameter.get("example");
SQL sql = new SQL();
sql.UPDATE("sec_user_login_log");
if (record.getId() != null) {
sql.SET("id = #{record.id,jdbcType=BIGINT}");
}
if (record.getUserId() != null) {
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}");
}
if (record.getUserLoginName() != null) {
sql.SET("user_login_name = #{record.userLoginName,jdbcType=VARCHAR}");
}
if (record.getIp() != null) {
sql.SET("ip = #{record.ip,jdbcType=VARCHAR}");
}
if (record.getCountry() != null) {
sql.SET("country = #{record.country,jdbcType=VARCHAR}");
}
if (record.getRegionId() != null) {
sql.SET("region_id = #{record.regionId,jdbcType=VARCHAR}");
}
if (record.getRegionName() != null) {
sql.SET("region_name = #{record.regionName,jdbcType=VARCHAR}");
}
if (record.getCityId() != null) {
sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}");
}
if (record.getCityName() != null) {
sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}");
}
if (record.getIsp() != null) {
sql.SET("isp = #{record.isp,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
}
if (record.getRemark() != null) {
sql.SET("remark = #{record.remark,jdbcType=VARCHAR}");
}
if (record.getCreateTime() != null) {
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
}
if (record.getExt1() != null) {
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
}
if (record.getExt2() != null) {
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
}
if (record.getExt3() != null) {
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}");
}
applyWhere(sql, example, true);
return sql.toString();
}
public String updateByExample(Map<String, Object> parameter) {
SQL sql = new SQL();
sql.UPDATE("sec_user_login_log");
sql.SET("id = #{record.id,jdbcType=BIGINT}");
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}");
sql.SET("user_login_name = #{record.userLoginName,jdbcType=VARCHAR}");
sql.SET("ip = #{record.ip,jdbcType=VARCHAR}");
sql.SET("country = #{record.country,jdbcType=VARCHAR}");
sql.SET("region_id = #{record.regionId,jdbcType=VARCHAR}");
sql.SET("region_name = #{record.regionName,jdbcType=VARCHAR}");
sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}");
sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}");
sql.SET("isp = #{record.isp,jdbcType=VARCHAR}");
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
sql.SET("remark = #{record.remark,jdbcType=VARCHAR}");
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}");
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}");
SecUserLoginLogExample example = (SecUserLoginLogExample) parameter.get("example");
applyWhere(sql, example, true);
return sql.toString();
}
public String updateByPrimaryKeySelective(SecUserLoginLog record) {
SQL sql = new SQL();
sql.UPDATE("sec_user_login_log");
if (record.getUserId() != null) {
sql.SET("user_id = #{userId,jdbcType=BIGINT}");
}
if (record.getUserLoginName() != null) {
sql.SET("user_login_name = #{userLoginName,jdbcType=VARCHAR}");
}
if (record.getIp() != null) {
sql.SET("ip = #{ip,jdbcType=VARCHAR}");
}
if (record.getCountry() != null) {
sql.SET("country = #{country,jdbcType=VARCHAR}");
}
if (record.getRegionId() != null) {
sql.SET("region_id = #{regionId,jdbcType=VARCHAR}");
}
if (record.getRegionName() != null) {
sql.SET("region_name = #{regionName,jdbcType=VARCHAR}");
}
if (record.getCityId() != null) {
sql.SET("city_id = #{cityId,jdbcType=VARCHAR}");
}
if (record.getCityName() != null) {
sql.SET("city_name = #{cityName,jdbcType=VARCHAR}");
}
if (record.getIsp() != null) {
sql.SET("isp = #{isp,jdbcType=VARCHAR}");
}
if (record.getStatus() != null) {
sql.SET("`status` = #{status,jdbcType=INTEGER}");
}
if (record.getRemark() != null) {
sql.SET("remark = #{remark,jdbcType=VARCHAR}");
}
if (record.getCreateTime() != null) {
sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
}
if (record.getExt1() != null) {
sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}");
}
if (record.getExt2() != null) {
sql.SET("ext_2 = #{ext2,jdbcType=VARCHAR}");
}
if (record.getExt3() != null) {
sql.SET("ext_3 = #{ext3,jdbcType=VARCHAR}");
}
sql.WHERE("id = #{id,jdbcType=BIGINT}");
return sql.toString();
}
protected void applyWhere(SQL sql, SecUserLoginLogExample example, boolean includeExamplePhrase) {
if (example == null) {
return;
}
String parmPhrase1;
String parmPhrase1_th;
String parmPhrase2;
String parmPhrase2_th;
String parmPhrase3;
String parmPhrase3_th;
if (includeExamplePhrase) {
parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}";
parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}";
parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}";
parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
} else {
parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}";
parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}";
parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}";
parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
}
StringBuilder sb = new StringBuilder();
List<Criteria> oredCriteria = example.getOredCriteria();
boolean firstCriteria = true;
for (int i = 0; i < oredCriteria.size(); i++) {
Criteria criteria = oredCriteria.get(i);
if (criteria.isValid()) {
if (firstCriteria) {
firstCriteria = false;
} else {
sb.append(" or ");
}
sb.append('(');
List<Criterion> criterions = criteria.getAllCriteria();
boolean firstCriterion = true;
for (int j = 0; j < criterions.size(); j++) {
Criterion criterion = criterions.get(j);
if (firstCriterion) {
firstCriterion = false;
} else {
sb.append(" and ");
}
if (criterion.isNoValue()) {
sb.append(criterion.getCondition());
} else if (criterion.isSingleValue()) {
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j));
} else {
sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler()));
}
} else if (criterion.isBetweenValue()) {
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j));
} else {
sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler()));
}
} else if (criterion.isListValue()) {
sb.append(criterion.getCondition());
sb.append(" (");
List<?> listItems = (List<?>) criterion.getValue();
boolean comma = false;
for (int k = 0; k < listItems.size(); k++) {
if (comma) {
sb.append(", ");
} else {
comma = true;
}
if (criterion.getTypeHandler() == null) {
sb.append(String.format(parmPhrase3, i, j, k));
} else {
sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler()));
}
}
sb.append(')');
}
}
sb.append(')');
}
}
if (sb.length() > 0) {
sql.WHERE(sb.toString());
}
}
}

@ -0,0 +1,296 @@
package com.hfkj.entity;
import java.io.Serializable;
import java.util.Date;
/**
* sec_user_login_log
* @author
*/
/**
*
* 代码由工具生成
*
**/
public class SecUserLoginLog implements Serializable {
/**
* 主键
*/
private Long id;
/**
* 登录账户id
*/
private Long userId;
/**
* 登录账户
*/
private String userLoginName;
/**
* ip
*/
private String ip;
/**
* 国家
*/
private String country;
/**
* 省份编号
*/
private String regionId;
/**
* 省份名称
*/
private String regionName;
/**
* 城市编号
*/
private String cityId;
/**
* 城市名称
*/
private String cityName;
/**
* 运营商
*/
private String isp;
/**
* 状态 1正常 2风险
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private Date createTime;
private String ext1;
private String ext2;
private String ext3;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUserLoginName() {
return userLoginName;
}
public void setUserLoginName(String userLoginName) {
this.userLoginName = userLoginName;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getRegionName() {
return regionName;
}
public void setRegionName(String regionName) {
this.regionName = regionName;
}
public String getCityId() {
return cityId;
}
public void setCityId(String cityId) {
this.cityId = cityId;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getIsp() {
return isp;
}
public void setIsp(String isp) {
this.isp = isp;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getExt1() {
return ext1;
}
public void setExt1(String ext1) {
this.ext1 = ext1;
}
public String getExt2() {
return ext2;
}
public void setExt2(String ext2) {
this.ext2 = ext2;
}
public String getExt3() {
return ext3;
}
public void setExt3(String ext3) {
this.ext3 = ext3;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
SecUserLoginLog other = (SecUserLoginLog) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getUserLoginName() == null ? other.getUserLoginName() == null : this.getUserLoginName().equals(other.getUserLoginName()))
&& (this.getIp() == null ? other.getIp() == null : this.getIp().equals(other.getIp()))
&& (this.getCountry() == null ? other.getCountry() == null : this.getCountry().equals(other.getCountry()))
&& (this.getRegionId() == null ? other.getRegionId() == null : this.getRegionId().equals(other.getRegionId()))
&& (this.getRegionName() == null ? other.getRegionName() == null : this.getRegionName().equals(other.getRegionName()))
&& (this.getCityId() == null ? other.getCityId() == null : this.getCityId().equals(other.getCityId()))
&& (this.getCityName() == null ? other.getCityName() == null : this.getCityName().equals(other.getCityName()))
&& (this.getIsp() == null ? other.getIsp() == null : this.getIsp().equals(other.getIsp()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1()))
&& (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2()))
&& (this.getExt3() == null ? other.getExt3() == null : this.getExt3().equals(other.getExt3()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getUserLoginName() == null) ? 0 : getUserLoginName().hashCode());
result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode());
result = prime * result + ((getCountry() == null) ? 0 : getCountry().hashCode());
result = prime * result + ((getRegionId() == null) ? 0 : getRegionId().hashCode());
result = prime * result + ((getRegionName() == null) ? 0 : getRegionName().hashCode());
result = prime * result + ((getCityId() == null) ? 0 : getCityId().hashCode());
result = prime * result + ((getCityName() == null) ? 0 : getCityName().hashCode());
result = prime * result + ((getIsp() == null) ? 0 : getIsp().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode());
result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode());
result = prime * result + ((getExt3() == null) ? 0 : getExt3().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", userId=").append(userId);
sb.append(", userLoginName=").append(userLoginName);
sb.append(", ip=").append(ip);
sb.append(", country=").append(country);
sb.append(", regionId=").append(regionId);
sb.append(", regionName=").append(regionName);
sb.append(", cityId=").append(cityId);
sb.append(", cityName=").append(cityName);
sb.append(", isp=").append(isp);
sb.append(", status=").append(status);
sb.append(", remark=").append(remark);
sb.append(", createTime=").append(createTime);
sb.append(", ext1=").append(ext1);
sb.append(", ext2=").append(ext2);
sb.append(", ext3=").append(ext3);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

@ -0,0 +1,37 @@
package com.hfkj.service;
import com.hfkj.entity.SecUser;
import com.hfkj.entity.SecUserLoginLog;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* 登录账户
* @className: SecUserLoginLogService
* @author: HuRui
* @date: 2024/4/3
**/
public interface SecUserLoginLogService {
/**
* 创建
* @param userLoginLog
*/
void create(SecUserLoginLog userLoginLog);
/**
* 异步创建登录日志
* @param user
*/
void asyncCreateLog(SecUser user, HttpServletRequest request);
/**
* 查询日志列表
* @param param
* @return
*/
List<SecUserLoginLog> getLogList(Map<String, Object> param);
}

@ -0,0 +1,98 @@
package com.hfkj.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.utils.AliyunService;
import com.hfkj.common.utils.RequestUtils;
import com.hfkj.dao.SecUserLoginLogMapper;
import com.hfkj.entity.SecUser;
import com.hfkj.entity.SecUserLoginLog;
import com.hfkj.entity.SecUserLoginLogExample;
import com.hfkj.service.SecUserLoginLogService;
import com.hfkj.sysenum.SecUserLoginLogStatusEnum;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @className: SecUserLoginLogServiceImpl
* @author: HuRui
* @date: 2024/4/3
**/
@Service("secUserLoginLogService")
public class SecUserLoginLogServiceImpl implements SecUserLoginLogService {
@Resource
private SecUserLoginLogMapper secUserLoginLogMapper;
@Override
public void create(SecUserLoginLog userLoginLog) {
userLoginLog.setCreateTime(new Date());
secUserLoginLogMapper.insert(userLoginLog);
}
@Override
public void asyncCreateLog(SecUser user, HttpServletRequest request) {
// 创建一个单线程的线程池
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
// 异步记录登录信息
singleThreadExecutor.submit(new Runnable() {
@Override
public void run() {
SecUserLoginLog loginLog = new SecUserLoginLog();
loginLog.setUserId(user.getId());
loginLog.setUserLoginName(user.getLoginName());
loginLog.setIp(RequestUtils.getIpAddress(request));
// 查询ip归属地
JSONObject ipAddress = AliyunService.queryAddress(loginLog.getIp());
if (ipAddress != null) {
loginLog.setCountry(StringUtils.isNotBlank(ipAddress.getString("country"))?ipAddress.getString("country"):"未知");
loginLog.setRegionId(StringUtils.isNotBlank(ipAddress.getString("region_id"))?ipAddress.getString("region_id"):null);
loginLog.setRegionName(StringUtils.isNotBlank(ipAddress.getString("region"))?ipAddress.getString("region"):"未知");
loginLog.setCityId(StringUtils.isNotBlank(ipAddress.getString("city_id"))?ipAddress.getString("city_id"):null);
loginLog.setCityName(StringUtils.isNotBlank(ipAddress.getString("city"))?ipAddress.getString("city"):"未知");
loginLog.setIsp(StringUtils.isNotBlank(ipAddress.getString("isp"))?ipAddress.getString("isp"):"未知");
loginLog.setStatus(SecUserLoginLogStatusEnum.status1.getCode());
} else {
loginLog.setCountry("未知");
loginLog.setRegionName("未知");
loginLog.setCityName("未知");
loginLog.setIsp("未知");
loginLog.setStatus(SecUserLoginLogStatusEnum.status2.getCode());
}
create(loginLog);
}
});
singleThreadExecutor.shutdown();
}
@Override
public List<SecUserLoginLog> getLogList(Map<String, Object> param) {
SecUserLoginLogExample example = new SecUserLoginLogExample();
SecUserLoginLogExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(param, "userId") != null) {
criteria.andUserIdEqualTo(MapUtils.getLong(param, "userId"));
}
if (StringUtils.isNotBlank(MapUtils.getString(param, "userLoginName"))) {
criteria.andUserLoginNameEqualTo(MapUtils.getString(param, "userLoginName"));
}
if (MapUtils.getInteger(param, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(param, "status"));
}
example.setOrderByClause("create_time desc");
return secUserLoginLogMapper.selectByExample(example);
}
}

@ -1,32 +1,39 @@
package com.hfkj.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.AESEncodeUtil;
import com.hfkj.common.security.SessionObject;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.AliyunService;
import com.hfkj.common.utils.MD5Util;
import com.hfkj.common.utils.RequestUtils;
import com.hfkj.dao.SecUserMapper;
import com.hfkj.entity.SecMenu;
import com.hfkj.entity.SecRole;
import com.hfkj.entity.SecUser;
import com.hfkj.entity.SecUserExample;
import com.hfkj.entity.*;
import com.hfkj.model.MenuTreeModel;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.SecMenuService;
import com.hfkj.service.SecRoleService;
import com.hfkj.service.SecUserLoginLogService;
import com.hfkj.service.SecUserService;
import com.hfkj.sysenum.SecMenuTypeEnum;
import com.hfkj.sysenum.SecUserLoginLogStatusEnum;
import com.hfkj.sysenum.SecUserStatusEnum;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
/**
@ -42,6 +49,8 @@ public class SecUserServiceImpl implements SecUserService {
@Resource
private UserCenter userCenter;
@Resource
private SecUserLoginLogService secUserLoginLogService;
@Resource
private SecRoleService secRoleService;
@Resource
private SecMenuService secMenuService;
@ -135,10 +144,14 @@ public class SecUserServiceImpl implements SecUserService {
List<SecMenu> button = secMenuService.queryRoleMenu(role.getId(), SecMenuTypeEnum.type2);
// token 生成格式:账户id + 时间戳
String token = AESEncodeUtil.aesEncrypt(user.getId()+"", "O8gTZ6wIovDPjhsaz0zAoqZmm3jtjIcO");
String token = AESEncodeUtil.aesEncrypt(user.getId()+"_"+System.currentTimeMillis(), "O8gTZ6wIovDPjhsaz0zAoqZmm3jtjIcO");
SessionObject sessionObject = new SessionObject(token, new SecUserSessionObject(user, role, menuTree, button));
userCenter.save(sessionObject);
// 异步记录登录信息
secUserLoginLogService.asyncCreateLog(user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST));
return sessionObject;
}

@ -0,0 +1,46 @@
package com.hfkj.sysenum;
/**
* 登录日志状态
* @className: SecUserLoginLogStatusEnum
* @author: HuRui
* @date: 2024/4/3
**/
public enum SecUserLoginLogStatusEnum {
/**
* 正常
*/
status1(1, "正常"),
/**
* 风险
*/
status2(2, "风险"),
;
private int code;
private String name;
SecUserLoginLogStatusEnum(int code, String name) {
this.code = code;
this.name = name;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Loading…
Cancel
Save