抢晒镜修改
This commit is contained in:
parent
a3050ad0b5
commit
1e781e9bdf
1
pom.xml
1
pom.xml
@ -91,6 +91,7 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
||||
@ -8,8 +8,11 @@
|
||||
|
||||
package com.lz;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
@ -20,9 +20,6 @@ public class SampleLineConverter extends ClassicConverter {
|
||||
} else {
|
||||
return CallerData.NA;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -144,4 +144,15 @@ public class Constant {
|
||||
|
||||
public static final int FAIL_CODE_VALUE = 400; // 失败 插入 、删除 更新 修改
|
||||
|
||||
|
||||
|
||||
public static final String INVELOMENT_TYPE_DEV = "dev";
|
||||
public static final String INVELOMENT_TYPE_TEST1 = "test1";
|
||||
public static final String INVELOMENT_TYPE_TEST2 = "test2";
|
||||
public static final String INVELOMENT_TYPE_TEST3 = "test3";
|
||||
public static final String INVELOMENT_TYPE_ONLINE = "online";
|
||||
public static final String INVELOMENT_TYPE_PRE_ENV = "preissue";
|
||||
public static final String FORMAL_APP_IDENTIFY = "www";
|
||||
|
||||
|
||||
}
|
||||
|
||||
47
src/main/java/com/lz/common/utils/ISelect.java
Normal file
47
src/main/java/com/lz/common/utils/ISelect.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2017 abel533@gmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.lz.common.utils;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页查询接口
|
||||
*
|
||||
* @author liuzh_3nofxnp
|
||||
* @since 2015-12-18 18:51
|
||||
*/
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ISelect {
|
||||
|
||||
/**
|
||||
* 在接口中调用自己的查询方法,不要在该方法内写过多代码,只要一行查询方法最好
|
||||
*/
|
||||
List doSelect(IPage page);
|
||||
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
package com.lz.common.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@ -18,7 +19,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
public class PageUtils implements Serializable {
|
||||
public class PageUtils<E> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 总记录数
|
||||
@ -56,6 +57,26 @@ public class PageUtils implements Serializable {
|
||||
this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
|
||||
}
|
||||
|
||||
|
||||
public <E> PageUtils<E> doSelect(ISelect select) {
|
||||
IPage page = new Page(this.currPage,this.pageSize);
|
||||
list = select.doSelect(page);
|
||||
page.setRecords(list);
|
||||
return new PageUtils<E>(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始分页
|
||||
*
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页显示数量
|
||||
* @param count 是否进行count查询
|
||||
*/
|
||||
public static <E> PageUtils<E> startPage(int pageNum, int pageSize) {
|
||||
IPage<E> page = new Page<E>(pageNum, pageSize);
|
||||
return new PageUtils<E>(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
|
||||
199
src/main/java/com/lz/common/utils/ReflectionUtils.java
Normal file
199
src/main/java/com/lz/common/utils/ReflectionUtils.java
Normal file
@ -0,0 +1,199 @@
|
||||
package com.lz.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.aop.framework.AdvisedSupport;
|
||||
import org.springframework.aop.framework.AopProxy;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 方法类
|
||||
*
|
||||
* @author syh
|
||||
*/
|
||||
|
||||
public class ReflectionUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReflectionUtils.class);
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的 DeclaredMethod
|
||||
*
|
||||
* @param object : 子类对象
|
||||
* @param methodName : 父类中的方法名
|
||||
* @param parameterTypes : 父类中的方法参数类型
|
||||
* @return 父类中的方法对象
|
||||
*/
|
||||
|
||||
public static Method getDeclaredMethod(Object object, String methodName, Class<?>... parameterTypes) {
|
||||
Method method = null;
|
||||
|
||||
for (Class<?> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
|
||||
try {
|
||||
method = clazz.getDeclaredMethod(methodName, parameterTypes);
|
||||
return method;
|
||||
} catch (Exception e) {
|
||||
//这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
|
||||
//如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用对象方法, 而忽略修饰符(private, protected, default)
|
||||
*
|
||||
* @param object : 子类对象
|
||||
* @param methodName : 父类中的方法名
|
||||
* @param parameterTypes : 父类中的方法参数类型
|
||||
* @param parameters : 父类中的方法参数
|
||||
* @return 父类中方法的执行结果
|
||||
*/
|
||||
|
||||
public static Object invokeMethod(Object object, String methodName, Class<?>[] parameterTypes,
|
||||
Object[] parameters) {
|
||||
//根据 对象、方法名和对应的方法参数 通过反射 调用上面的方法获取 Method 对象
|
||||
Method method = getDeclaredMethod(object, methodName, parameterTypes);
|
||||
|
||||
//抑制Java对方法进行检查,主要是针对私有方法而言
|
||||
method.setAccessible(true);
|
||||
try {
|
||||
if (null != method) {
|
||||
|
||||
//调用object 的 method 所代表的方法,其方法的参数是 parameters
|
||||
return method.invoke(object, parameters);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的 DeclaredField
|
||||
*
|
||||
* @param object : 子类对象
|
||||
* @param fieldName : 父类中的属性名
|
||||
* @return 父类中的属性对象
|
||||
*/
|
||||
|
||||
public static Field getDeclaredField(Object object, String fieldName) {
|
||||
Field field = null;
|
||||
|
||||
Class<?> clazz = object.getClass();
|
||||
|
||||
for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
|
||||
try {
|
||||
field = clazz.getDeclaredField(fieldName);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
//这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
|
||||
//如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接设置对象属性值, 忽略 private/protected 修饰符, 也不经过 setter
|
||||
*
|
||||
* @param object : 子类对象
|
||||
* @param fieldName : 父类中的属性名
|
||||
* @param value : 将要设置的值
|
||||
*/
|
||||
|
||||
public static void setFieldValue(Object object, String fieldName, Object value) {
|
||||
|
||||
//根据 对象和属性名通过反射 调用上面的方法获取 Field对象
|
||||
Field field = getDeclaredField(object, fieldName);
|
||||
|
||||
//抑制Java对其的检查
|
||||
field.setAccessible(true);
|
||||
|
||||
try {
|
||||
//将 object 中 field 所代表的值 设置为 value
|
||||
field.set(object, value);
|
||||
} catch (Exception e) {
|
||||
logger.info(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接读取对象的属性值, 忽略 private/protected 修饰符, 也不经过 getter
|
||||
*
|
||||
* @param object : 子类对象
|
||||
* @param fieldName : 父类中的属性名
|
||||
* @return : 父类中的属性值
|
||||
*/
|
||||
|
||||
public static Object getFieldValue(Object object, String fieldName) {
|
||||
|
||||
//根据 对象和属性名通过反射 调用上面的方法获取 Field对象
|
||||
Field field = getDeclaredField(object, fieldName);
|
||||
|
||||
//抑制Java对其的检查
|
||||
field.setAccessible(true);
|
||||
|
||||
try {
|
||||
//获取 object 中 field 所代表的属性值
|
||||
return field.get(object);
|
||||
} catch (Exception e) {
|
||||
logger.info(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 目标对象
|
||||
*
|
||||
* @param proxy 代理对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Object getTarget(Object proxy) throws Exception {
|
||||
if (!AopUtils.isAopProxy(proxy)) {
|
||||
return proxy;//不是代理对象
|
||||
}
|
||||
|
||||
if (AopUtils.isJdkDynamicProxy(proxy)) {
|
||||
return getJdkDynamicProxyTargetObject(proxy);
|
||||
} else { //cglib
|
||||
return getCglibProxyTargetObject(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
|
||||
h.setAccessible(true);
|
||||
Object dynamicAdvisedInterceptor = h.get(proxy);
|
||||
Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
Object target = ((AdvisedSupport) advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
|
||||
h.setAccessible(true);
|
||||
AopProxy aopProxy = (AopProxy) h.get(proxy);
|
||||
Field advised = aopProxy.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
Object target = ((AdvisedSupport) advised.get(aopProxy)).getTargetSource().getTarget();
|
||||
return target;
|
||||
}
|
||||
|
||||
public static Object getObjectFieldValue(Object parameter, String column) {
|
||||
return getFieldValue(parameter,column);
|
||||
}
|
||||
}
|
||||
@ -48,4 +48,52 @@ public class SpringContextUtils implements ApplicationContextAware {
|
||||
return applicationContext.getType(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// 获取当前环境
|
||||
public static boolean isSQLLogDebug() {
|
||||
if (Constant.INVELOMENT_TYPE_TEST.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_DEV.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST1.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST2.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST3.equals(getActiveProfile())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// 获取当前环境
|
||||
public static boolean isDataLogDebug() {
|
||||
if (Constant.INVELOMENT_TYPE_TEST.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_DEV.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST2.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST3.equals(getActiveProfile())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// 获取当前环境
|
||||
public static String getActiveProfile() {
|
||||
if (applicationContext != null) {
|
||||
return applicationContext.getEnvironment().getActiveProfiles()[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// 获取当前环境
|
||||
public static boolean isTestDev() {
|
||||
if (Constant.INVELOMENT_TYPE_TEST.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_DEV.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST2.equals(getActiveProfile())
|
||||
|| Constant.INVELOMENT_TYPE_TEST3.equals(getActiveProfile())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
47
src/main/java/com/lz/config/DataScope.java
Normal file
47
src/main/java/com/lz/config/DataScope.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, songfayuan All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the 霖梓控股 developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: songfayuan (1414798079@qq.com)
|
||||
*/
|
||||
|
||||
package com.lz.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author songfayuan
|
||||
* @date 2018/1/19
|
||||
* 数据权限、参考guns实现
|
||||
* 2018年02月12日 增强查询参数
|
||||
*/
|
||||
@Data
|
||||
public class DataScope extends HashMap {
|
||||
/**
|
||||
* 限制范围的字段名称
|
||||
*/
|
||||
private String scopeName = "dept_id";
|
||||
|
||||
/**
|
||||
* 具体的数据范围
|
||||
*/
|
||||
private List<Integer> deptIds;
|
||||
|
||||
/**
|
||||
* 是否只查询本部门
|
||||
*/
|
||||
private Boolean isOnly = false;
|
||||
}
|
||||
252
src/main/java/com/lz/config/DataScopeInterceptor.java
Normal file
252
src/main/java/com/lz/config/DataScopeInterceptor.java
Normal file
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, songfayuan All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the 霖梓控股 developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: songfayuan (1414798079@qq.com)
|
||||
*/
|
||||
|
||||
package com.lz.config;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
||||
import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
|
||||
import com.lz.common.utils.OrderUtil;
|
||||
import com.lz.common.utils.ReflectionUtils;
|
||||
import com.lz.common.utils.SpringContextUtils;
|
||||
import com.lz.common.utils.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.binding.BindingException;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.ParameterMapping;
|
||||
import org.apache.ibatis.mapping.SqlCommandType;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.apache.ibatis.reflection.SystemMetaObject;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author songfayuan
|
||||
* @date 2018/1/19
|
||||
* 数据权限插件,guns
|
||||
*/
|
||||
@Slf4j
|
||||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
|
||||
public class DataScopeInterceptor extends AbstractSqlParserHandler implements Interceptor {
|
||||
|
||||
public static final org.slf4j.Logger logger = LoggerFactory.getLogger(DataScopeInterceptor.class);
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
|
||||
MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
|
||||
this.sqlParser(metaObject);
|
||||
// 先判断是不是SELECT操作
|
||||
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
|
||||
String originalSql = boundSql.getSql();
|
||||
Object parameterObject = boundSql.getParameterObject();
|
||||
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
|
||||
String sqlCommandTypePre = "SELECT SQL = ";
|
||||
if(SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType())){
|
||||
sqlCommandTypePre = "INSERT SQL = ";
|
||||
}else if (SqlCommandType.UPDATE.equals(mappedStatement.getSqlCommandType())){
|
||||
sqlCommandTypePre = "UPDATE SQL = ";
|
||||
}
|
||||
|
||||
Configuration configuration = mappedStatement.getConfiguration();
|
||||
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { //非select语句
|
||||
if(SpringContextUtils.isSQLLogDebug()){
|
||||
logger.info(sqlCommandTypePre + showSql(configuration, boundSql));
|
||||
}
|
||||
Object result = invocation.proceed();
|
||||
return result ;
|
||||
}
|
||||
//查找参数中包含DataScope类型的参数
|
||||
DataScope dataScope = findDataScopeObject(parameterObject);
|
||||
if (dataScope == null) {
|
||||
String sql = getContainsIsDeleteOriginalSql(originalSql);
|
||||
if(SpringContextUtils.isSQLLogDebug()){
|
||||
logger.info(sqlCommandTypePre + showSql(configuration, boundSql));
|
||||
}
|
||||
metaObject.setValue("delegate.boundSql.sql", sql);
|
||||
Object result = invocation.proceed();
|
||||
return result ;
|
||||
} else {
|
||||
String scopeName = dataScope.getScopeName();
|
||||
List<Integer> deptIds = dataScope.getDeptIds();
|
||||
if (StringUtil.isNotBlank(scopeName) && CollectionUtil.isNotEmpty(deptIds)) {
|
||||
String join = CollectionUtil.join(deptIds, ",");
|
||||
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
|
||||
metaObject.setValue("delegate.boundSql.sql", originalSql);
|
||||
}
|
||||
|
||||
if(SpringContextUtils.isSQLLogDebug()){
|
||||
logger.info(sqlCommandTypePre + showSql(configuration, boundSql));
|
||||
}
|
||||
Object result=invocation.proceed();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// todo quyixiao 所有的sql查询加上is_delete=0,目前没有想到解决办法
|
||||
public static String getContainsIsDeleteOriginalSql(String originalSql){
|
||||
|
||||
return originalSql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static String getParameterValue(Object obj) {
|
||||
String value = null;
|
||||
if (obj instanceof String) {
|
||||
value = "'" + obj.toString() + "'";
|
||||
} else if (obj instanceof Date) {
|
||||
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
|
||||
value = "'" + formatter.format(obj) + "'";
|
||||
} else {
|
||||
if (obj != null) {
|
||||
value = obj.toString();
|
||||
} else {
|
||||
value = "''";
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Object getParameterValue(String propertyName, Object obj) {
|
||||
|
||||
Object value = null;
|
||||
|
||||
try {
|
||||
value = ReflectionUtils.getObjectFieldValue(obj, propertyName);
|
||||
} catch (BindingException e2) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成拦截对象的代理
|
||||
*
|
||||
* @param target 目标对象
|
||||
* @return 代理对象
|
||||
*/
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
if (target instanceof StatementHandler) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis配置的属性
|
||||
*
|
||||
* @param properties mybatis配置的属性
|
||||
*/
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找参数是否包括DataScope对象
|
||||
*
|
||||
* @param parameterObj 参数列表
|
||||
* @return DataScope
|
||||
*/
|
||||
private DataScope findDataScopeObject(Object parameterObj) {
|
||||
if (parameterObj instanceof DataScope) {
|
||||
return (DataScope) parameterObj;
|
||||
} else if (parameterObj instanceof Map) {
|
||||
for (Object val : ((Map<?, ?>) parameterObj).values()) {
|
||||
if (val instanceof DataScope) {
|
||||
return (DataScope) val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String showSql(Configuration configuration, BoundSql boundSql) {
|
||||
try {
|
||||
Map<String,String> listMap = new HashMap<>();
|
||||
Object parameterObject = boundSql.getParameterObject();
|
||||
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
|
||||
String sql = boundSql.getSql().replaceAll("[\\s]+", " ");
|
||||
if (parameterMappings.size() > 0 && parameterObject != null) {
|
||||
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
|
||||
if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
|
||||
String value = getParameterValue(parameterObject);
|
||||
if (value.contains("?")) {
|
||||
String key = OrderUtil.getUserPoolOrder("rn");
|
||||
listMap.put(key,value);
|
||||
value = key;
|
||||
}
|
||||
sql = sql.replaceFirst("\\?", value);
|
||||
} else {
|
||||
MetaObject metaObject = configuration.newMetaObject(parameterObject);
|
||||
for (ParameterMapping parameterMapping : parameterMappings) {
|
||||
String propertyName = parameterMapping.getProperty();
|
||||
if (metaObject.hasGetter(propertyName)) {
|
||||
Object obj = metaObject.getValue(propertyName);
|
||||
String value = getParameterValue(obj);
|
||||
if (value.contains("?")) {
|
||||
String key = OrderUtil.getUserPoolOrder("rn");
|
||||
listMap.put(key,value);
|
||||
value = key;
|
||||
}
|
||||
sql = sql.replaceFirst("\\?", value);
|
||||
} else if (boundSql.hasAdditionalParameter(propertyName)) {
|
||||
Object obj = boundSql.getAdditionalParameter(propertyName);
|
||||
|
||||
String value = getParameterValue(obj);
|
||||
if (value.contains("?")) {
|
||||
String key = OrderUtil.getUserPoolOrder("rn");
|
||||
listMap.put(key,value);
|
||||
value = key;
|
||||
}
|
||||
sql = sql.replaceFirst("\\?", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!listMap.isEmpty()){
|
||||
for (Map.Entry<String, String> m : listMap.entrySet()) {
|
||||
sql = sql.replaceAll(m.getKey(),m.getValue());
|
||||
}
|
||||
}
|
||||
return sql;
|
||||
} catch (Exception e) {
|
||||
log.error("showSql exception ", e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -28,4 +28,12 @@ public class MybatisPlusConfig {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public DataScopeInterceptor dataScopeInterceptor() {
|
||||
return new DataScopeInterceptor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
@ -36,9 +37,8 @@ public class ResultRecordController {
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
@RequiresPermissions("user:lzresultrecord:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = lzResultRecordService.queryPage(params);
|
||||
|
||||
public R list(ResultRecordReq req){
|
||||
PageUtils page = lzResultRecordService.queryPage(req);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
12
src/main/java/com/lz/modules/app/req/ResultRecordReq.java
Normal file
12
src/main/java/com/lz/modules/app/req/ResultRecordReq.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.lz.modules.app.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ResultRecordReq {
|
||||
private Integer page;
|
||||
private Integer limit;
|
||||
private String monthBeginDate;
|
||||
private String monthEndDate;
|
||||
|
||||
}
|
||||
43
src/main/java/com/lz/modules/app/resp/ResultRecordResp.java
Normal file
43
src/main/java/com/lz/modules/app/resp/ResultRecordResp.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.lz.modules.app.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ResultRecordResp {
|
||||
|
||||
private Long id;
|
||||
//是否删除状态,1:删除,0:有效
|
||||
private Integer isDelete;
|
||||
//创建时间
|
||||
private Date gmtCreate;
|
||||
//最后修改时间
|
||||
private Date gmtModified;
|
||||
//月份
|
||||
private Date monthTime;
|
||||
//0.新建,1 提交审批中,2 拒绝,3 审批完成
|
||||
private Integer status;
|
||||
//最后得分
|
||||
private BigDecimal lastScore;
|
||||
//总分
|
||||
private BigDecimal allScore;
|
||||
//备注
|
||||
private String remark;
|
||||
|
||||
private String statusStr;
|
||||
|
||||
public String getStatusStr() {
|
||||
if (this.status == 0) {
|
||||
return "新建";
|
||||
} else if (this.status == 1) {
|
||||
return "审批中";
|
||||
} else if (this.status == 2) {
|
||||
return "拒绝";
|
||||
} else if (this.status == 3) {
|
||||
return "审批通过";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -8,9 +8,15 @@ package com.lz.modules.sys.dao.app;
|
||||
* @since 2020-08-10
|
||||
*/
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
|
||||
|
||||
@ -30,4 +36,5 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
|
||||
int deleteResultRecordById(@Param("id") Long id);
|
||||
|
||||
|
||||
List<ResultRecord> selectByCondition(@Param("page") IPage page, @Param("req") ResultRecordReq req);
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.lz.modules.sys.service.app;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
|
||||
import java.util.List;
|
||||
@ -33,7 +34,7 @@ public interface ResultRecordService extends IService<ResultRecord> {
|
||||
|
||||
int deleteResultRecordById(Long id);
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
PageUtils queryPage(ResultRecordReq params);
|
||||
|
||||
|
||||
void deleteBatchIds(List<Long> asList);
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
package com.lz.modules.sys.service.app.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.common.utils.ISelect;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.Query;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.app.resp.ResultRecordResp;
|
||||
import com.lz.modules.sys.dao.app.ResultRecordMapper;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -62,18 +64,27 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<ResultRecord> page = this.page(
|
||||
new Query<ResultRecord>().getPage(params),
|
||||
new QueryWrapper<ResultRecord>()
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
public PageUtils queryPage(ResultRecordReq params) {
|
||||
PageUtils pageUtils = PageUtils.startPage(params.getPage(), params.getLimit() ).doSelect(new ISelect() {
|
||||
@Override
|
||||
public List doSelect(IPage page) {
|
||||
return resultRecordMapper.selectByCondition(page, params);
|
||||
}
|
||||
});
|
||||
List<ResultRecord> resultRecords = pageUtils.getList();
|
||||
List<ResultRecordResp> list = new ArrayList<>();
|
||||
for (ResultRecord resultRecord : resultRecords) {
|
||||
ResultRecordResp resp = new ResultRecordResp();
|
||||
BeanUtils.copyProperties(resultRecord, resp);
|
||||
list.add(resp);
|
||||
}
|
||||
pageUtils.setList(list);
|
||||
return pageUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatchIds(List<Long> asList) {
|
||||
@Override
|
||||
public void deleteBatchIds(List<Long> asList) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -89,5 +89,20 @@
|
||||
update lz_result_record set is_delete = 1 where id=#{id} limit 1
|
||||
</update>
|
||||
|
||||
<select id="selectByCondition" resultType="com.lz.modules.sys.entity.app.ResultRecord">
|
||||
select * from lz_result_record where is_delete = 0
|
||||
<if test="req.monthBeginDate != null and req.monthBeginDate != '' ">
|
||||
AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S') <![CDATA[ >= ]]> DATE_FORMAT(#{req.monthBeginDate}, '%Y-%m-%d %H:%i:%S')
|
||||
</if>
|
||||
|
||||
<if test="req.monthEndDate != null and req.monthEndDate != '' ">
|
||||
AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S') <![CDATA[ >= ]]> DATE_FORMAT(#{req.monthEndDate}, '%Y-%m-%d %H:%i:%S')
|
||||
</if>
|
||||
|
||||
order by id desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
18
src/test/java/com/lz/MyTest2.java
Normal file
18
src/test/java/com/lz/MyTest2.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.lz;
|
||||
|
||||
import com.lz.common.utils.DateUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class MyTest2 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
Date initDate = sdf2.parse("2020-07-01 00:00:00");
|
||||
for(int i = 0 ;i < 1000;i++){
|
||||
Date date1 = DateUtils.addDateDays(initDate,i);
|
||||
System.out.println("('"+sdf2.format(date1)+"'),");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user