初始化引入工具类
parent
b6c920dc64
commit
e7742fdfe0
@ -1,24 +0,0 @@
|
||||
package com.engine.organization.entity.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DemoUser {
|
||||
|
||||
private String username;
|
||||
|
||||
private Integer age;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.engine.organization.mapper;
|
||||
|
||||
|
||||
import com.engine.organization.entity.po.Demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/3/9
|
||||
* @Version V1.0
|
||||
**/
|
||||
public interface DemoMapper {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
* @return
|
||||
*/
|
||||
List<Demo> listAll();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.engine.organization.mapper.DemoMapper">
|
||||
<resultMap id="BaseResultMap" type="com.engine.organization.entity.po.Demo">
|
||||
<result column="fid" property="fid"/>
|
||||
<result column="flevel" property="flevel"/>
|
||||
<result column="fwd" property="fwd"/>
|
||||
<result column="fnumber" property="fnumber"/>
|
||||
<result column="fname" property="fname"/>
|
||||
<result column="fleader" property="fleader"/>
|
||||
<result column="fplan" property="fplan"/>
|
||||
<result column="fonjob" property="fonjob"/>
|
||||
<result column="fisvitual" property="fisvitual"/>
|
||||
<result column="ftimebegin" property="ftimebegin"/>
|
||||
<result column="ftimeend" property="ftimeend"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 表字段 -->
|
||||
<sql id="baseColumns">
|
||||
t.fid
|
||||
, t.flevel
|
||||
, t.fwd
|
||||
, t.fnumber
|
||||
, t.fname
|
||||
, t.fleader
|
||||
, t.fplan
|
||||
, t.fonjob
|
||||
, t.fisvitual
|
||||
, t.ftimebegin
|
||||
, t.ftimeend
|
||||
</sql>
|
||||
|
||||
<select id="listAll" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="baseColumns"/>
|
||||
FROM hr_company t
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -0,0 +1,22 @@
|
||||
package com.engine.organization.service;
|
||||
|
||||
import com.engine.organization.entity.po.Demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/27
|
||||
* @Version V1.0
|
||||
**/
|
||||
public interface DemoService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
List<Demo> list(String name);
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.engine.organization.service.impl;
|
||||
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.po.Demo;
|
||||
import com.engine.organization.mapper.DemoMapper;
|
||||
import com.engine.organization.service.DemoService;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import com.engine.organization.wrapper.DemoWrapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/27
|
||||
* @Version V1.0
|
||||
**/
|
||||
public class DemoServiceImpl extends Service implements DemoService {
|
||||
|
||||
@Override
|
||||
public List<Demo> list(String name) {
|
||||
OrganizationAssert.notNull(name,"参数不能为空");
|
||||
return MapperProxyFactory.getProxy(DemoMapper.class).listAll();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.engine.organization.util;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO 多语言工具类
|
||||
* @Date 2022/3/9
|
||||
* @Version V1.0
|
||||
**/
|
||||
public class HrmI18nUtil {
|
||||
|
||||
/**
|
||||
* 获取多语言信息
|
||||
*
|
||||
* @param labelId 多语言对应的labelId
|
||||
* @param defaultLabel 默认中文
|
||||
* @return
|
||||
*/
|
||||
public static String getI18nLabel(int labelId, String defaultLabel) {
|
||||
return defaultLabel;
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * 获取多语言信息
|
||||
// *
|
||||
// * @param tenantKey 租户key
|
||||
// * @param employeeId 人员id
|
||||
// * @param labelId 多语言对应的labelId
|
||||
// * @param defaultLabel 默认中文
|
||||
// * @return
|
||||
// */
|
||||
// public static String getI18nLabel(String tenantKey, Long employeeId, int labelId, String defaultLabel) {
|
||||
// int languageId = I18nLanguageUtil.getLangId(employeeId);
|
||||
// return SystemEnv.getHtmlLabelName(labelId, languageId, tenantKey, defaultLabel);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取多语言信息
|
||||
// *
|
||||
// * @param simpleEmployee 租户信息
|
||||
// * @param labelId 多语言对应的labelId
|
||||
// * @param defaultLabel 默认中文
|
||||
// * @return
|
||||
// */
|
||||
// public static String getI18nLabel(SimpleEmployee simpleEmployee, int labelId, String defaultLabel) {
|
||||
// int languageId = I18nLanguageUtil.getLangId(simpleEmployee.getEmployeeId());
|
||||
// return SystemEnv.getHtmlLabelName(labelId, languageId, simpleEmployee.getTenantKey(), defaultLabel);
|
||||
// }
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.engine.organization.util.db;
|
||||
|
||||
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 MapperProxyFactory implements InvocationHandler {
|
||||
private Class clazz;
|
||||
private boolean enableTransactions = false;
|
||||
private SqlSession session;
|
||||
|
||||
public MapperProxyFactory(Class clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@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);
|
||||
return method.invoke(target, args);
|
||||
} finally {
|
||||
if (!enableTransactions) {
|
||||
session.commit();
|
||||
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 enableTransactions) {
|
||||
this.enableTransactions = enableTransactions;
|
||||
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) {
|
||||
MapperProxyFactory handle = new MapperProxyFactory(clazz);
|
||||
return (T) handle.getProxy();
|
||||
}
|
||||
|
||||
public static <T> T getProxy(Class<T> clazz, boolean enableTransactions) {
|
||||
MapperProxyFactory handle = new MapperProxyFactory(clazz);
|
||||
return (T) handle.getProxy(enableTransactions);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue