Merge branch 'feature/qt' into develop
This commit is contained in:
commit
fbfb5f5005
|
|
@ -2,6 +2,7 @@ package com.engine.salary.biz;
|
|||
|
||||
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
||||
import com.engine.salary.mapper.salarysob.SalarySobMapper;
|
||||
import com.engine.salary.util.db.SalarySqlProxyHandle;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import weaver.conn.mybatis.MyBatisFactory;
|
||||
|
||||
|
|
@ -10,13 +11,8 @@ import java.util.List;
|
|||
|
||||
public class SalarySobBiz {
|
||||
public SalarySobPO getById(Long id) {
|
||||
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
|
||||
try {
|
||||
SalarySobMapper mapper = sqlSession.getMapper(SalarySobMapper.class);
|
||||
return mapper.getById(id);
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
SalarySobMapper mapper = SalarySqlProxyHandle.getProxy(SalarySobMapper.class);
|
||||
return mapper.getById(id);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package com.engine.salary.util.db;
|
||||
|
||||
import com.api.formmode.mybatis.util.SqlProxyHandle;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import weaver.conn.mybatis.MyBatisFactory;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
public class SalarySqlProxyHandle implements InvocationHandler {
|
||||
private Class clazz;
|
||||
private boolean isAutoCommit = true;
|
||||
private SqlSession session;
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
|
||||
if (this.session == null) {
|
||||
this.session = MyBatisFactory.sqlSessionFactory.openSession();
|
||||
}
|
||||
try {
|
||||
Object target = session.getMapper(clazz);
|
||||
Object invoke = method.invoke(target, args);
|
||||
if (isAutoCommit) {
|
||||
session.commit();
|
||||
}
|
||||
return invoke;
|
||||
} finally {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Object getProxy() {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
Class<?>[] interfaces = new Class<?>[1];
|
||||
interfaces[0] = this.clazz;
|
||||
return Proxy.newProxyInstance(loader, interfaces, this);
|
||||
}
|
||||
|
||||
public Object getProxy(boolean isAutoCommit) {
|
||||
this.isAutoCommit = isAutoCommit;
|
||||
return this.getProxy();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
if (this.session != null) {
|
||||
this.session.commit();
|
||||
this.session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
if (this.session != null) {
|
||||
this.session.rollback();
|
||||
this.session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getProxy(Class<T> clazz) {
|
||||
SqlProxyHandle handle = new SqlProxyHandle(clazz);
|
||||
return (T) handle.getProxy();
|
||||
}
|
||||
|
||||
public static <T> T getProxy(Class<T> clazz, boolean isAutoSubmit) {
|
||||
SqlProxyHandle handle = new SqlProxyHandle(clazz);
|
||||
return (T) handle.getProxy(isAutoSubmit);
|
||||
}
|
||||
}
|
||||
|
|
@ -92,9 +92,9 @@ public class SalarySobController {
|
|||
public String getSalarySobBasicForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalarySobBasicSaveParam saveParam) {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
if (saveParam.getId() == null || saveParam.getId() <= 0) {
|
||||
return new ResponseResult<SalarySobBasicSaveParam, Map<String, Object>>().run(getSalarySobWrapper(user)::save, saveParam);
|
||||
return new ResponseResult<SalarySobBasicSaveParam, Long>().run(getSalarySobWrapper(user)::save, saveParam);
|
||||
} else {
|
||||
return new ResponseResult<SalarySobBasicSaveParam, Map<String, Object>>().run(getSalarySobWrapper(user)::update, saveParam);
|
||||
return new ResponseResult<SalarySobBasicSaveParam, Long>().run(getSalarySobWrapper(user)::update, saveParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class SalarySobWrapper extends Service {
|
|||
|
||||
table.setBackfields(fields);
|
||||
table.setSqlform(from);
|
||||
// table.setSqlwhere(makeSqlWhere(queryParam));
|
||||
table.setSqlwhere(makeSqlWhere(queryParam));
|
||||
table.setSqlorderby("t.id DESC");
|
||||
table.setSqlprimarykey("t.id");
|
||||
table.setSqlisdistinct("false");
|
||||
|
|
|
|||
Loading…
Reference in New Issue