提交 3b6df9b1 编写于 作者: Z Zhou Rui

增加dll命令

上级 089a966f
因为 它太大了无法显示 source diff 。你可以改为 查看blob
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<global.version>4.3.5</global.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8
</project.reporting.outputEncoding>
</properties>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
<packaging>pom</packaging>
<modules>
<module>x_base_core_project</module>
......@@ -61,13 +69,6 @@
<module>x_program_center</module>
<module>x_console</module>
</modules>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8
</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
......@@ -365,13 +366,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<excludes>
<exclude>META-INF</exclude>
<exclude>META-INF/**</exclude>
</excludes>
</configuration>
</plugin>
......@@ -734,142 +735,142 @@
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_base_core_project</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_attendance_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_bbs_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_calendar_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_cms_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_cms_core_express</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_component_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_file_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_general_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_hotpic_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_meeting_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_message_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_mind_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_okr_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_organization_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_organization_core_express</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_portal_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_processplatform_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_processplatform_core_express</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_query_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_query_core_express</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_report_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_strategydeploy_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_strategydeploy_assemble_control</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_program_center</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_program_center_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_teamwork_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_workschedu_core_entity</artifactId>
<version>${project.version}</version>
<version>${global.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_attendance_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_attendance_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -6,7 +6,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_base_core_project</artifactId>
<packaging>jar</packaging>
......
......@@ -6,7 +6,15 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import com.x.base.core.container.FactorDistributionPolicy;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Node;
import com.x.base.core.project.tools.ListTools;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.persistence.PersistenceProviderImpl;
import org.dom4j.Document;
......@@ -16,33 +24,41 @@ import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import com.x.base.core.container.FactorDistributionPolicy;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.tools.ListTools;
public class PersistenceXmlHelper {
public static List<String> directWrite(String path, List<String> classNames) throws Exception {
private PersistenceXmlHelper() {
}
public static void writeForDdl(String path) throws Exception {
try {
Document document = DocumentHelper.createDocument();
Element persistence = document.addElement("persistence", "http://java.sun.com/xml/ns/persistence");
persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
persistence.addAttribute("version", "2.0");
for (String className : classNames) {
Element unit = persistence.addElement("persistence-unit");
unit.addAttribute("name", className);
unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
Element provider = unit.addElement("provider");
provider.addText(PersistenceProviderImpl.class.getName());
Element mapped_element = unit.addElement("class");
mapped_element.addText(className);
Element sliceJpaObject_element = unit.addElement("class");
sliceJpaObject_element.addText("com.x.base.core.entity.SliceJpaObject");
Element jpaObject_element = unit.addElement("class");
jpaObject_element.addText("com.x.base.core.entity.JpaObject");
Element unit = persistence.addElement("persistence-unit");
unit.addAttribute("name", "enhance");
unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
Element provider = unit.addElement("provider");
provider.addText(PersistenceProviderImpl.class.getName());
List<String> entities = new ArrayList<>();
for (String className : (List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES)) {
Class<? extends JpaObject> clazz = (Class<JpaObject>) Class.forName(className);
for (Class<?> o : JpaObjectTools.scanMappedSuperclass(clazz)) {
entities.add(o.getName());
}
}
entities = ListTools.trim(entities, true, true);
for (String className : entities) {
Element class_element = unit.addElement("class");
class_element.addText(className);
}
Element properties = unit.addElement("properties");
if (BooleanUtils.isTrue(Config.externalDataSources().enable())) {
writeForDdlExternalProperty(properties);
} else {
writeForDdlInternalProperty(properties);
}
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
......@@ -51,12 +67,51 @@ public class PersistenceXmlHelper {
XMLWriter writer = new XMLWriter(new FileWriter(file), format);
writer.write(document);
writer.close();
return classNames;
} catch (Exception e) {
throw new Exception("registContainerEntity error.className:" + ListTools.toStringJoin(classNames), e);
throw new Exception("writeForDdl error.", e);
}
}
private static void writeForDdlExternalProperty(Element properties) throws Exception {
Element property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.driver");
property.addAttribute("value", Config.externalDataSources().get(0).getDriverClassName());
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.url");
property.addAttribute("value", Config.externalDataSources().get(0).getUrl());
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.user");
property.addAttribute("value", Config.externalDataSources().get(0).getUsername());
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.password");
property.addAttribute("value", Config.externalDataSources().get(0).getPassword());
property = properties.addElement("property");
property.addAttribute("name", "openjpa.DynamicEnhancementAgent");
property.addAttribute("value", "false");
}
private static void writeForDdlInternalProperty(Element properties) throws Exception {
Element property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.driver");
property.addAttribute("value", SlicePropertiesBuilder.driver_h2);
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.url");
Node node = Config.currentNode();
String url = "jdbc:h2:tcp://" + Config.node() + ":" + node.getData().getTcpPort() + "/X;JMX="
+ (node.getData().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE="
+ (node.getData().getCacheSize() * 1024);
property.addAttribute("value", url);
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.user");
property.addAttribute("value", "sa");
property = properties.addElement("property");
property.addAttribute("name", "javax.persistence.jdbc.password");
property.addAttribute("value", Config.token().getPassword());
property = properties.addElement("property");
property.addAttribute("name", "openjpa.DynamicEnhancementAgent");
property.addAttribute("value", "false");
}
public static List<String> write(String path, List<String> entities) throws Exception {
List<String> names = new ArrayList<>();
String name = "";
......@@ -90,7 +145,7 @@ public class PersistenceXmlHelper {
writer.close();
return names;
} catch (Exception e) {
throw new Exception("registContainerEntity error.className:" + name, e);
throw new Exception("write error.className:" + name, e);
}
}
......@@ -108,7 +163,6 @@ public class PersistenceXmlHelper {
return properties_internal_single(className);
}
}
}
private static Properties properties_base_slice(String className) throws Exception {
......
......@@ -88,12 +88,6 @@ public class MetaModelBuilder {
for (URL url : urls) {
cp.add(new File(url.getFile()));
}
// filter = new WildcardFileFilter("*.jar");
// File dir = new File(o2oadir, "o2server/commons/ext");
// for (File o : FileUtils.listFiles(dir, filter, null)) {
// cp.add(o);
// }
return cp;
}
......
......@@ -96,6 +96,7 @@ public class Config {
public static final String DIR_LOCAL_UPDATE = "local/update";
public static final String DIR_LOCAL_TEMP = "local/temp";
public static final String DIR_LOCAL_TEMP_CLASSES = "local/temp/classes";
public static final String DIR_LOCAL_TEMP_SQL = "local/temp/sql";
public static final String DIR_LOCAL_TEMP_DYNAMIC = "local/temp/dynamic";
public static final String DIR_LOCAL_TEMP_DYNAMIC_SRC = "local/temp/dynamic/src";
public static final String DIR_LOCAL_TEMP_DYNAMIC_TARGET = "local/temp/dynamic/target";
......@@ -329,6 +330,20 @@ public class Config {
return dir;
}
public static File dir_local_temp_sql() throws Exception {
return new File(base(), DIR_LOCAL_TEMP_SQL);
}
public static File dir_local_temp_sql(Boolean force) throws Exception {
File dir = new File(base(), DIR_LOCAL_TEMP_SQL);
if (force) {
if ((!dir.exists()) || dir.isFile()) {
FileUtils.forceMkdir(dir);
}
}
return dir;
}
public static File dir_logs() throws Exception {
return new File(base(), DIR_LOGS);
}
......@@ -790,9 +805,12 @@ public class Config {
/* 添加默认格式 */
mimeTypes.addMimeMapping("", "application/octet-stream");
/* 添加新版office格式 */
mimeTypes.addMimeMapping("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
mimeTypes.addMimeMapping("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
mimeTypes.addMimeMapping("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
mimeTypes.addMimeMapping("docx",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
mimeTypes.addMimeMapping("xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
mimeTypes.addMimeMapping("pptx",
"application/vnd.openxmlformats-officedocument.presentationml.presentation");
/* 名片 */
mimeTypes.addMimeMapping("vcf", "text/x-vcard");
instance().mimeTypes = mimeTypes;
......
package com.x.base.core.project.tools;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
public class URLClassLoaderTools {
private URLClassLoaderTools() {
}
public static void add(URLClassLoader classLoader, File file) throws Exception {
Class<?> urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(classLoader, new Object[] { file.toURI().toURL() });
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_bbs_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_bbs_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_calendar_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_calendar_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_cms_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_cms_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_cms_core_express</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_component_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_component_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_console</artifactId>
<packaging>jar</packaging>
......
......@@ -37,6 +37,7 @@ public class ActionControl extends ActionBase {
private static final String CMD_RS = "rs";
private static final String CMD_CLH2 = "clh2";
private static final String CMD_UF = "uf";
private static final String CMD_DDL = "ddl";
private static final int REPEAT_MAX = 100;
private static final int REPEAT_MIN = 1;
......@@ -69,6 +70,8 @@ public class ActionControl extends ActionBase {
clh2(cmd);
} else if (cmd.hasOption(CMD_UF)) {
uf(cmd);
} else if (cmd.hasOption(CMD_DDL)) {
ddl(cmd);
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("control command", options);
......@@ -91,6 +94,7 @@ public class ActionControl extends ActionBase {
options.addOption(rsOption());
options.addOption(clh2Option());
options.addOption(ufOption());
options.addOption(ddlOption());
return options;
}
......@@ -152,6 +156,11 @@ public class ActionControl extends ActionBase {
.desc("升级服务器,升级前请注意备份.").build();
}
private static Option ddlOption() {
return Option.builder("ddl").longOpt("DataDefinitionLanguage").argName("type").hasArg()
.desc("导出数据定义语句:建表语句:build,数据库创建:createDB,数据库删除dropDB.").build();
}
private void ec(CommandLine cmd) throws Exception {
if (BooleanUtils.isNotTrue(Config.currentNode().getEraseContentEnable())) {
logger.print("erase content is disabled.");
......@@ -238,6 +247,12 @@ public class ActionControl extends ActionBase {
updateFile.execute(path);
}
private void ddl(CommandLine cmd) throws Exception {
String type = Objects.toString(cmd.getOptionValue(CMD_DDL), "");
Ddl ddl= new Ddl();
ddl.execute(type);
}
private Integer getArgInteger(CommandLine cmd, String opt, Integer defaultValue) {
Integer repeat = defaultValue;
String r = cmd.getOptionValue(opt);
......
package com.x.server.console.action;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.x.base.core.container.factory.PersistenceXmlHelper;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.meta.MappingTool;
import org.apache.openjpa.lib.util.Options;
import org.apache.openjpa.persistence.EntityManagerImpl;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
import org.apache.openjpa.persistence.OpenJPAPersistence;
public class Ddl {
private static Logger logger = LoggerFactory.getLogger(Ddl.class);
/* 初始化完成 */
public boolean execute(String type) throws Exception {
// List<String> containerEntityNames = new ArrayList<>();
// containerEntityNames.addAll((List<String>)
// Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
// List<String> classNames =
// ListTools.includesExcludesWildcard(containerEntityNames,
// Config.dumpRestoreData().getIncludes(),
// Config.dumpRestoreData().getExcludes());
// File persistence = new File(Config.dir_local_temp_classes(),
// "META-INF/persistence.xml");
// PersistenceXmlHelper.writeForDdl(persistence.getAbsolutePath());
// String[] arguments = new String[4];
// arguments[0] = "-schemaAction";
// arguments[1] = StringUtils.equals(type ,"create")? "build":"add";
// arguments[2] = "-sql";
// arguments[3] = Config.dir_local_temp_sql(true) + "/" + type + ".sql";
// MappingTool.main(arguments);
// return true;
String flag = "build";
if (StringUtils.equalsIgnoreCase(type, "createDB")) {
flag = "createDB";
}
if (StringUtils.equalsIgnoreCase(type, "dropDB")) {
flag = "dropDB";
}
if (StringUtils.equalsIgnoreCase(type, "retain")) {
flag = "retain";
}
List<String> containerEntityNames = new ArrayList<>();
containerEntityNames.addAll((List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
List<String> classNames = ListTools.includesExcludesWildcard(containerEntityNames,
Config.dumpRestoreData().getIncludes(), Config.dumpRestoreData().getExcludes());
File persistence = new File(Config.dir_local_temp_classes(), "persistence_sql.xml");
PersistenceXmlHelper.writeForDdl(persistence.getAbsolutePath());
OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory("enhance",
persistence.getName());
EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
String[] arguments = new String[4];
arguments[0] = "-schemaAction";
arguments[1] = flag;
arguments[2] = "-sql";
arguments[3] = Config.dir_local_temp_sql(true) + "/" + flag + ".sql";
Options opts = new Options();
final String[] args = opts.setFromCmdLine(arguments);
MappingTool.run((JDBCConfiguration) em.getConfiguration(), args, opts, null);
return true;
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_file_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_file_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_general_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_general_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_hotpic_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_hotpic_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_jpush_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_jpush_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_meeting_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_meeting_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_message_assemble_communicate</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_message_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_mind_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_mind_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_okr_assemble_control</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_okr_core_entity</artifactId>
<packaging>jar</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_organization_assemble_authentication</artifactId>
<packaging>war</packaging>
......
......@@ -7,7 +7,7 @@
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
<version>${global.version}</version>
</parent>
<artifactId>x_organization_assemble_control</artifactId>
<packaging>war</packaging>
......
package com.x.organization.assemble.control;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.cache.ApplicationCache;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
public abstract class AbstractFactory {
protected Business business;
protected Ehcache cache;
public AbstractFactory(Business business) throws Exception {
try {
if (null == business) {
throw new Exception("business can not be null.");
}
this.business = business;
} catch (Exception e) {
throw new Exception("can not instantiating factory.");
}
}
public EntityManagerContainer entityManagerContainer() throws Exception {
return this.business.entityManagerContainer();
}
@SuppressWarnings("unchecked")
protected <T extends JpaObject> T pick(String flag, Class<T> clz, String... attributes) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Ehcache cache = ApplicationCache.instance().getCache(clz);
T t = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
t = (T) element.getObjectValue();
}
} else {
t = this.entityManagerContainer().flag(flag, clz);
if (t != null) {
this.entityManagerContainer().get(clz).detach(t);
}
cache.put(new Element(flag, t));
}
return t;
}
@SuppressWarnings("unchecked")
protected <T extends JpaObject> List<T> pick(List<String> flags, Class<T> clz) throws Exception {
List<T> list = new ArrayList<>();
if (null == flags || flags.isEmpty()) {
return list;
}
Ehcache cache = ApplicationCache.instance().getCache(clz);
Map<Object, Element> map = cache.getAll(flags);
if (map.size() == flags.size()) {
map.values().stream().forEach(o -> {
list.add((T) o.getObjectValue());
});
} else {
List<T> os = this.entityManagerContainer().flag(flags, clz);
EntityManager em = this.entityManagerContainer().get(clz);
os.stream().forEach(o -> {
em.detach(o);
list.add(o);
cache.put(new Element(o.getId(), o));
});
}
return list;
}
}
\ No newline at end of file
package com.x.organization.assemble.control;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
ThisApplication.destroy();
ThisApplication.context.destrory(servletContextEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.collections4.CollectionUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.instrument.Instrument;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.factory.GroupFactory;
import com.x.organization.assemble.control.factory.IdentityFactory;
import com.x.organization.assemble.control.factory.PermissionSettingFactory;
import com.x.organization.assemble.control.factory.PersonAttributeFactory;
import com.x.organization.assemble.control.factory.PersonCardFactory;
import com.x.organization.assemble.control.factory.PersonFactory;
import com.x.organization.assemble.control.factory.RoleFactory;
import com.x.organization.assemble.control.factory.UnitAttributeFactory;
import com.x.organization.assemble.control.factory.UnitDutyFactory;
import com.x.organization.assemble.control.factory.UnitFactory;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Group_;
import com.x.organization.core.entity.Identity;
import com.x.organization.core.entity.Identity_;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.PersonAttribute;
import com.x.organization.core.entity.Person_;
import com.x.organization.core.entity.Role;
import com.x.organization.core.entity.Role_;
import com.x.organization.core.entity.Unit;
import com.x.organization.core.entity.UnitAttribute;
import com.x.organization.core.entity.UnitDuty;
import net.sf.ehcache.Ehcache;
public class Business {
private EntityManagerContainer emc;
private Ehcache cache;
public Business(EntityManagerContainer emc) throws Exception {
this.emc = emc;
this.cache = ApplicationCache.instance().getCache(Group.class, Role.class, Person.class, PersonAttribute.class,
Unit.class, UnitDuty.class, UnitAttribute.class, Identity.class);
}
public EntityManagerContainer entityManagerContainer() {
return this.emc;
}
private Instrument instrument;
public Instrument instrument() throws Exception {
if (null == this.instrument) {
this.instrument = new Instrument();
}
return instrument;
}
private PersonFactory person;
public PersonFactory person() throws Exception {
if (null == this.person) {
this.person = new PersonFactory(this);
}
return person;
}
private PersonCardFactory personCard;
public PersonCardFactory personCard() throws Exception {
if (null == this.personCard) {
this.personCard = new PersonCardFactory(this);
}
return personCard;
}
private PermissionSettingFactory permissionSetting;
public PermissionSettingFactory permissionSetting() throws Exception {
if (null == this.permissionSetting) {
this.permissionSetting = new PermissionSettingFactory(this);
}
return permissionSetting;
}
private PersonAttributeFactory personAttribute;
public PersonAttributeFactory personAttribute() throws Exception {
if (null == this.personAttribute) {
this.personAttribute = new PersonAttributeFactory(this);
}
return personAttribute;
}
private IdentityFactory identity;
public IdentityFactory identity() throws Exception {
if (null == this.identity) {
this.identity = new IdentityFactory(this);
}
return identity;
}
private GroupFactory group;
public GroupFactory group() throws Exception {
if (null == this.group) {
this.group = new GroupFactory(this);
}
return group;
}
private RoleFactory role;
public RoleFactory role() throws Exception {
if (null == this.role) {
this.role = new RoleFactory(this);
}
return role;
}
private UnitFactory unit;
public UnitFactory unit() throws Exception {
if (null == this.unit) {
this.unit = new UnitFactory(this);
}
return unit;
}
private UnitAttributeFactory unitAttribute;
public UnitAttributeFactory unitAttribute() throws Exception {
if (null == this.unitAttribute) {
this.unitAttribute = new UnitAttributeFactory(this);
}
return unitAttribute;
}
private UnitDutyFactory unitDuty;
public UnitDutyFactory unitDuty() throws Exception {
if (null == this.unitDuty) {
this.unitDuty = new UnitDutyFactory(this);
}
return unitDuty;
}
public boolean hasAnyRole(EffectivePerson effectivePerson, String... roleFlags) throws Exception {
/** 如果不加这个xadmin会报错 */
if (effectivePerson.isManager()) {
return true;
}
Person person = this.person().pick(effectivePerson.getDistinguishedName());
if (null != person) {
List<String> groupIds = this.group().listSupNestedWithPerson(person.getId());
if (null != person) {
List<Role> roles = this.role().pick(Arrays.asList(roleFlags));
for (Role o : roles) {
if (o.getPersonList().contains(person.getId())) {
return true;
}
if (CollectionUtils.containsAny(o.getGroupList(), groupIds)) {
return true;
}
}
}
}
return false;
}
public boolean editable(EffectivePerson effectivePerson, Group group) throws Exception {
if (effectivePerson.isManager()) {
return true;
}
if (this.hasAnyRole(effectivePerson, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.GroupManager)) {
return true;
}
return false;
}
public boolean editable(EffectivePerson effectivePerson, Unit unit) throws Exception {
if (effectivePerson.isManager()) {
return true;
}
if (this.hasAnyRole(effectivePerson, OrganizationDefinition.Manager, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.UnitManager)) {
return true;
}
if (ListTools.isNotEmpty(unit.getControllerList())) {
List<Person> os = this.person().pick(unit.getControllerList());
List<String> list = ListTools.extractProperty(os, JpaObject.DISTINGUISHEDNAME, String.class, true, true);
if (ListTools.contains(list, effectivePerson.getDistinguishedName())) {
return true;
}
}
if (ListTools.isNotEmpty(unit.getInheritedControllerList())) {
List<Person> os = this.person().pick(unit.getInheritedControllerList());
List<String> list = ListTools.extractProperty(os, JpaObject.DISTINGUISHEDNAME, String.class, true, true);
if (ListTools.contains(list, effectivePerson.getDistinguishedName())) {
return true;
}
}
return false;
}
public boolean editable(EffectivePerson effectivePerson, Person person) throws Exception {
if (effectivePerson.isManager()) {
return true;
}
if (this.hasAnyRole(effectivePerson, OrganizationDefinition.Manager, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.PersonManager)) {
return true;
}
return false;
}
public boolean editable(EffectivePerson effectivePerson, Role role) throws Exception {
if (effectivePerson.isManager()) {
return true;
}
if (this.hasAnyRole(effectivePerson, OrganizationDefinition.Manager, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.RoleManager)) {
return true;
}
return false;
}
public List<String> expendGroupRoleToPerson(List<String> values) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> roleIds = new ArrayList<>();
List<String> personIds = new ArrayList<>();
for (String str : values) {
Group g = this.group().pick(str);
if (null != g) {
groupIds.add(g.getId());
} else {
Role r = this.role().pick(str);
if (null != r) {
roleIds.add(r.getId());
} else {
Person p = this.person().pick(str);
if (null != p) {
personIds.add(p.getId());
}
}
}
}
personIds.addAll(this.expendGroupRoleToPerson(groupIds, roleIds));
personIds = ListTools.trim(personIds, true, true);
return personIds;
}
public List<String> expendGroupRoleToPerson(List<String> groupList, List<String> roleList) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> expendGroupIds = new ArrayList<>();
List<String> personIds = new ArrayList<>();
if (ListTools.isNotEmpty(groupList)) {
for (String s : groupList) {
Group g = this.group().pick(s);
if (null != g) {
groupIds.add(g.getId());
}
}
}
if (ListTools.isNotEmpty(roleList)) {
for (String s : roleList) {
Role r = this.role().pick(s);
if (null != r) {
groupIds.addAll(r.getGroupList());
personIds.addAll(r.getPersonList());
}
}
}
if (ListTools.isNotEmpty(groupIds)) {
groupIds = ListTools.trim(groupIds, true, true);
for (String s : groupIds) {
expendGroupIds.add(s);
expendGroupIds.addAll(this.group().listSubNested(s));
}
expendGroupIds = ListTools.trim(expendGroupIds, true, true);
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = root.get(Group_.id).in(expendGroupIds);
List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList();
for (Group o : os) {
personIds.addAll(o.getPersonList());
}
personIds = ListTools.trim(personIds, true, true);
}
return personIds;
}
public List<String> expendGroupRoleToGroup(List<String> values) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> roleIds = new ArrayList<>();
List<String> expendGroupIds = new ArrayList<>();
for (String str : values) {
Group g = this.group().pick(str);
if (null != g) {
groupIds.add(g.getId());
} else {
Role r = this.role().pick(str);
if (null != r) {
roleIds.add(r.getId());
}
}
}
expendGroupIds.addAll(this.expendGroupRoleToGroup(groupIds, roleIds));
return expendGroupIds;
}
public List<String> expendGroupRoleToGroup(List<String> groupList, List<String> roleList) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> expendGroupIds = new ArrayList<>();
if (ListTools.isNotEmpty(groupList)) {
for (String s : groupList) {
Group g = this.group().pick(s);
if (null != g) {
groupIds.add(g.getId());
}
}
}
if (ListTools.isNotEmpty(roleList)) {
for (String s : roleList) {
Role r = this.role().pick(s);
if (null != r) {
groupIds.addAll(r.getGroupList());
}
}
}
if (ListTools.isNotEmpty(groupIds)) {
groupIds = ListTools.trim(groupIds, true, true);
for (String s : groupIds) {
expendGroupIds.add(s);
expendGroupIds.addAll(this.group().listSubNested(s));
}
expendGroupIds = ListTools.trim(expendGroupIds, true, true);
}
return expendGroupIds;
}
public List<String> expendGroupRoleToRole(List<String> values) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> roleIds = new ArrayList<>();
List<String> expendRoleIds = new ArrayList<>();
for (String str : values) {
Group g = this.group().pick(str);
if (null != g) {
groupIds.add(g.getId());
} else {
Role r = this.role().pick(str);
if (null != r) {
roleIds.add(r.getId());
}
}
}
expendRoleIds.addAll(this.expendGroupRoleToRole(groupIds, roleIds));
return expendRoleIds;
}
public List<String> expendGroupRoleToRole(List<String> groupList, List<String> roleList) throws Exception {
List<String> groupIds = new ArrayList<>();
List<String> expendGroupIds = new ArrayList<>();
List<String> roleIds = new ArrayList<>();
if (ListTools.isNotEmpty(groupList)) {
for (String s : groupList) {
Group g = this.group().pick(s);
if (null != g) {
groupIds.add(g.getId());
}
}
}
if (ListTools.isNotEmpty(roleList)) {
for (String s : roleList) {
Role r = this.role().pick(s);
if (null != r) {
roleIds.add(r.getId());
groupIds.addAll(r.getGroupList());
}
}
}
if (ListTools.isNotEmpty(groupIds)) {
groupIds = ListTools.trim(groupIds, true, true);
for (String s : groupIds) {
expendGroupIds.add(s);
expendGroupIds.addAll(this.group().listSubNested(s));
}
expendGroupIds = ListTools.trim(expendGroupIds, true, true);
EntityManager em = this.entityManagerContainer().get(Role.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Role> cq = cb.createQuery(Role.class);
Root<Role> root = cq.from(Role.class);
Predicate p = root.get(Role_.groupList).in(expendGroupIds);
List<Role> os = em.createQuery(cq.select(root).where(p)).getResultList();
for (Role o : os) {
roleIds.add(o.getId());
}
}
roleIds = ListTools.trim(roleIds, true, true);
return roleIds;
}
public List<String> expendUnitToUnit(List<String> unitList) throws Exception {
List<String> unitIds = new ArrayList<>();
List<String> expendUnitIds = new ArrayList<>();
if (ListTools.isNotEmpty(unitList)) {
for (String s : unitList) {
Unit u = this.unit().pick(s);
if (null != u) {
unitIds.add(u.getId());
}
}
}
if (ListTools.isNotEmpty(unitIds)) {
unitIds = ListTools.trim(unitIds, true, true);
for (String s : unitIds) {
expendUnitIds.add(s);
expendUnitIds.addAll(this.unit().listSubNested(s));
}
}
expendUnitIds = ListTools.trim(expendUnitIds, true, true);
return expendUnitIds;
}
public List<String> expendUnitToIdentity(List<String> unitList) throws Exception {
List<String> unitIds = new ArrayList<>();
List<String> expendUnitIds = new ArrayList<>();
if (ListTools.isNotEmpty(unitList)) {
for (String s : unitList) {
Unit u = this.unit().pick(s);
if (null != u) {
unitIds.add(u.getId());
}
}
}
if (ListTools.isNotEmpty(unitIds)) {
unitIds = ListTools.trim(unitIds, true, true);
for (String s : unitIds) {
expendUnitIds.add(s);
expendUnitIds.addAll(this.unit().listSubNested(s));
}
}
expendUnitIds = ListTools.trim(expendUnitIds, true, true);
EntityManager em = this.entityManagerContainer().get(Identity.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Identity> root = cq.from(Identity.class);
Predicate p = root.get(Identity_.unit).in(expendUnitIds);
List<String> os = em.createQuery(cq.select(root.get(Identity_.id)).where(p)).getResultList();
os = ListTools.trim(os, true, true);
return os;
}
public Ehcache cache() {
return cache;
}
public List<Person> listPersonWithUnit(String unitFlag) throws Exception {
Unit unit = this.unit().pick(unitFlag);
EntityManager em = this.entityManagerContainer().get(Identity.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Identity> root = cq.from(Identity.class);
Predicate p = cb.equal(root.get(Identity_.unit), unit.getId());
List<String> os = em.createQuery(cq.select(root.get(Identity_.person)).where(p)).getResultList();
return this.person().pick(os);
}
public List<Unit> listTopUnitWithPerson(String personFlag) throws Exception {
List<Unit> os = new ArrayList<>();
Person person = this.person().pick(personFlag);
List<Identity> identities = emc.listEqual(Identity.class, Identity.person_FIELDNAME, person.getId());
List<String> unitIds = new ArrayList<>();
for (String id : ListTools.extractField(identities, Identity.unit_FIELDNAME, String.class, true, true)) {
unitIds.add(id);
unitIds.addAll(unit().listSupNested(id));
}
unitIds = ListTools.trim(unitIds, true, true);
for (Unit unit : this.unit().pick(unitIds)) {
if (Objects.deepEquals(Unit.TOP_LEVEL, unit.getLevel())) {
os.add(unit);
}
}
return os;
}
public boolean sameTopUnit(EffectivePerson effectivePerson, String person) throws Exception {
List<Unit> o = this.listTopUnitWithPerson(effectivePerson.getDistinguishedName());
List<Unit> t = this.listTopUnitWithPerson(person);
return ListTools.containsAny(o, t);
}
public Predicate personPredicateWithTopUnit(EffectivePerson effectivePerson) throws Exception {
EntityManager em = emc.get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
if (effectivePerson.isManager() || this.hasAnyRole(effectivePerson, OrganizationDefinition.Manager,
OrganizationDefinition.OrganizationManager)) {
return cb.conjunction();
} else {
CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
Root<Person> root = cq.from(Person.class);
List<Unit> units = listTopUnitWithPerson(effectivePerson.getDistinguishedName());
List<String> ids = ListTools.extractField(units, Unit.id_FIELDNAME, String.class, true, true);
return cb.or(root.get(Person_.topUnitList).in(ids), cb.isEmpty(root.get(Person_.topUnitList)));
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.type.GenderType;
import com.x.base.core.project.gson.GsonPropertyObject;
public class MappingItem extends GsonPropertyObject {
public static void setValue(Row row, JpaObject jpaObject, MappingItem item) throws Exception {
Cell cell = row.getCell(item.getColumn());
if (null != cell) {
switch (item.getType()) {
case string:
cell.setCellType(CellType.STRING);
String stringValue = cell.getStringCellValue();
if (null != stringValue) {
PropertyUtils.setProperty(jpaObject, item.getField(), stringValue);
}
break;
case integer:
cell.setCellType(CellType.NUMERIC);
Double doubeValue = cell.getNumericCellValue();
if (null != doubeValue) {
PropertyUtils.setProperty(jpaObject, item.getField(), doubeValue.intValue());
}
break;
case date:
Date dateValue = cell.getDateCellValue();
if (null != dateValue) {
PropertyUtils.setProperty(jpaObject, item.getField(), dateValue);
}
break;
case genderType:
String genderTypeStringValue = cell.getStringCellValue();
if (StringUtils.isNotEmpty(genderTypeStringValue)) {
if (StringUtils.equalsIgnoreCase(GenderType.f.toString(), genderTypeStringValue)) {
PropertyUtils.setProperty(jpaObject, item.getField(), GenderType.f);
} else if (StringUtils.equalsIgnoreCase(GenderType.m.toString(), genderTypeStringValue)) {
PropertyUtils.setProperty(jpaObject, item.getField(), GenderType.m);
} else {
PropertyUtils.setProperty(jpaObject, item.getField(), GenderType.d);
}
}
break;
case stringList:
String stringListValue = cell.getStringCellValue();
if (null != stringListValue) {
List<String> list = new ArrayList<>(Arrays.asList(StringUtils.split(stringListValue, ",")));
PropertyUtils.setProperty(jpaObject, item.getField(), list);
}
break;
default:
break;
}
}
}
public static List<MappingItem> personMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("姓名", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("工号", "employee", MappingItemValueType.string));
list.add(new MappingItem("性别", "genderType", MappingItemValueType.genderType));
list.add(new MappingItem("密码", "password", MappingItemValueType.string));
list.add(new MappingItem("密码到期时间", "passwordExpiredTime", MappingItemValueType.date));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
// list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("邮件", "mail", MappingItemValueType.string));
list.add(new MappingItem("手机", "mobile", MappingItemValueType.string));
list.add(new MappingItem("固定电话", "officePhone", MappingItemValueType.string));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
list.add(new MappingItem("入职时间", "boardDate", MappingItemValueType.date));
list.add(new MappingItem("出生日期", "birthday", MappingItemValueType.date));
list.add(new MappingItem("头像", "icon", MappingItemValueType.string));
list.add(new MappingItem("签名", "signature", MappingItemValueType.string));
list.add(new MappingItem("微信", "weixin", MappingItemValueType.string));
list.add(new MappingItem("QQ", "qq", MappingItemValueType.string));
list.add(new MappingItem("管理者", "controllerList", MappingItemValueType.stringList));
return list;
}
public static List<MappingItem> personMappings(Sheet sheet) throws Exception {
List<MappingItem> list = personMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> groupMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
list.add(new MappingItem("人员成员", "personList", MappingItemValueType.stringList));
list.add(new MappingItem("群组成员", "groupList", MappingItemValueType.stringList));
return list;
}
public static List<MappingItem> groupMappings(Sheet sheet) throws Exception {
List<MappingItem> list = groupMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> roleMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
list.add(new MappingItem("人员成员", "personList", MappingItemValueType.stringList));
list.add(new MappingItem("群组成员", "groupList", MappingItemValueType.stringList));
return list;
}
public static List<MappingItem> roleMappings(Sheet sheet) throws Exception {
List<MappingItem> list = roleMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> companyMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("简称", "shortName", MappingItemValueType.string));
list.add(new MappingItem("上级公司", "superior", MappingItemValueType.string));
list.add(new MappingItem("级别", "level", MappingItemValueType.integer));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
list.add(new MappingItem("管理者", "controllerList", MappingItemValueType.stringList));
return list;
}
public static List<MappingItem> companyMappings(Sheet sheet) throws Exception {
List<MappingItem> list = companyMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> departmentMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("简称", "shortName", MappingItemValueType.string));
list.add(new MappingItem("上级部门", "superior", MappingItemValueType.string));
list.add(new MappingItem("所属公司", "company", MappingItemValueType.string));
list.add(new MappingItem("级别", "level", MappingItemValueType.integer));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> departmentMappings(Sheet sheet) throws Exception {
List<MappingItem> list = departmentMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> identityMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("显示名", "display", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("所属人员", "person", MappingItemValueType.string));
list.add(new MappingItem("所属部门", "department", MappingItemValueType.string));
list.add(new MappingItem("排序号", "orderNumber", MappingItemValueType.integer));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("下属身份", "juniorList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> identityMappings(Sheet sheet) throws Exception {
List<MappingItem> list = identityMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> personAttributeMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("人员", "person", MappingItemValueType.string));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("属性值", "attributeList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> personAttributeMappings(Sheet sheet) throws Exception {
List<MappingItem> list = personAttributeMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> companyAttributeMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("公司", "company", MappingItemValueType.string));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("属性值", "attributeList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> companyAttributeMappings(Sheet sheet) throws Exception {
List<MappingItem> list = companyAttributeMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> companyDutyMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("公司", "company", MappingItemValueType.string));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("成员", "identityList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> companyDutyMappings(Sheet sheet) throws Exception {
List<MappingItem> list = companyDutyMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> departmentAttributeMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("部门", "department", MappingItemValueType.string));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("属性值", "attributeList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> departmentAttributeMappings(Sheet sheet) throws Exception {
List<MappingItem> list = departmentAttributeMappings();
mappingColumns(list, sheet);
return list;
}
public static List<MappingItem> departmentDutyMappings() {
List<MappingItem> list = new ArrayList<>();
list.add(new MappingItem("名称", "name", MappingItemValueType.string));
list.add(new MappingItem("唯一编码", "unique", MappingItemValueType.string));
list.add(new MappingItem("部门", "department", MappingItemValueType.string));
list.add(new MappingItem("标识", "id", MappingItemValueType.string));
list.add(new MappingItem("成员", "identityList", MappingItemValueType.stringList));
list.add(new MappingItem("创建时间", "createTime", MappingItemValueType.date));
return list;
}
public static List<MappingItem> departmentDutyMappings(Sheet sheet) throws Exception {
List<MappingItem> list = departmentDutyMappings();
mappingColumns(list, sheet);
return list;
}
private static void mappingColumns(List<MappingItem> list, Sheet sheet) {
Row row = sheet.getRow(sheet.getFirstRowNum());
if (null != row) {
Cell cell = null;
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
cell = row.getCell(i);
if (null != cell) {
String str = cell.getStringCellValue();
for (MappingItem o : list) {
if (StringUtils.equalsIgnoreCase(o.getName(), str)) {
o.setColumn(i);
}
}
}
}
}
}
public static Integer getResultColumnNum(Sheet sheet) {
Row row = sheet.getRow(sheet.getFirstRowNum());
if (null != row) {
Cell cell = null;
for (int i = row.getFirstCellNum() + 1; i < row.getLastCellNum(); i++) {
cell = row.getCell(i);
if (null != cell) {
String str = cell.getStringCellValue();
if (StringUtils.isEmpty(str) || StringUtils.equals(str, "结果")
|| StringUtils.equals(str, "result")) {
return i;
}
}
}
return (int) row.getLastCellNum();
}
return null;
}
private String name;
private String field;
private MappingItemValueType type;
private Integer column;
public MappingItem(String name, String field, MappingItemValueType type) {
this.name = name;
this.field = field;
this.type = type;
this.column = -1;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public MappingItemValueType getType() {
return type;
}
public void setType(MappingItemValueType type) {
this.type = type;
}
public Integer getColumn() {
return column;
}
public void setColumn(Integer column) {
this.column = column;
}
}
\ No newline at end of file
package com.x.organization.assemble.control;
public enum MappingItemValueType {
string, stringList, date, integer, genderType
}
package com.x.organization.assemble.control;
import com.x.base.core.project.Context;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.LoggerFactory;
public class ThisApplication {
protected static Context context;
public static Context context() {
return context;
}
public static void init() {
try {
LoggerFactory.setLevel(Config.logLevel().x_organization_assemble_control());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroy() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.collections4.set.ListOrderedSet;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Group_;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.Person;
import net.sf.ehcache.Element;
public class GroupFactory extends AbstractFactory {
public GroupFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(Group.class);
}
public Group pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Group o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (Group) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
public List<Group> pick(List<String> flags) throws Exception {
List<Group> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((Group) element.getObjectValue());
}
} else {
Group o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
private Group pickObject(String flag) throws Exception {
Group o = this.entityManagerContainer().flag(flag, Group.class);
if (o != null) {
this.entityManagerContainer().get(Group.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.Group.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, Group.class);
if (null != o) {
this.entityManagerContainer().get(Group.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.equal(root.get(Group_.name), name);
List<Group> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public <T extends Group> List<T> sort(List<T> list) {
list = list.stream().sorted(
Comparator.comparing(Group::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(
Comparator.comparing(Group::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return list;
}
public List<Group> listSupDirectObject(Group group) throws Exception {
List<String> ids = this.listSupDirect(group.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
// @MethodDescribe("获取指定指定群组所在的群组.")
public List<String> listSupDirect(String id) throws Exception {
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.isMember(id, root.get(Group_.groupList));
cq.select(root.get(Group_.id)).where(p);
return em.createQuery(cq).getResultList();
}
// @MethodDescribe("获取指定指定群组所在的群组,并递归其上级群组.")
public List<String> listSupNested(String id) throws Exception {
ListOrderedSet<String> set = new ListOrderedSet<>();
this.supNested(id, set);
return set.asList();
}
public List<Group> listSupNestedObject(Group group) throws Exception {
List<String> ids = this.listSupNested(group.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
// @MethodDescribe("上级群组循环递归.")
private void supNested(String id, ListOrderedSet<String> set) throws Exception {
List<String> list = new ArrayList<String>();
for (String str : this.listSupDirect(id)) {
if (!set.contains(str)) {
list.add(str);
}
}
if (!list.isEmpty()) {
set.addAll(list);
for (String str : list) {
this.supNested(str, set);
}
}
}
public List<Group> listSupDirectWithPersonObject(Person person) throws Exception {
List<String> ids = this.listSupDirectWithPerson(person.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
// @MethodDescribe("获取指定个人直接所在的群组.")
public List<String> listSupDirectWithPerson(String id) throws Exception {
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.isMember(id, root.get(Group_.personList));
cq.select(root.get(Group_.id)).where(p);
return em.createQuery(cq).getResultList();
}
public List<Group> listSupNestedWithPersonObject(Person person) throws Exception {
List<String> ids = this.listSupNestedWithPerson(person.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
// @MethodDescribe("获取指定个人所在的群组,并递归其上级群组.")
public List<String> listSupNestedWithPerson(String id) throws Exception {
ListOrderedSet<String> set = new ListOrderedSet<>();
List<String> list = new ArrayList<>();
for (String o : this.listSupDirectWithPerson(id)) {
if (!set.contains(o)) {
list.add(o);
}
}
if (!list.isEmpty()) {
set.addAll(list);
for (String str : list) {
this.supNested(str, set);
}
}
return set.asList();
}
public List<Group> listSubDirectObject(Group group) throws Exception {
List<String> ids = this.listSubDirect(group.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
public List<Group> listSubNestedObject(Group group) throws Exception {
List<String> ids = this.listSubNested(group.getId());
return this.entityManagerContainer().list(Group.class, ids);
}
// @MethodDescribe("查找群组的直接群组成员.")
public List<String> listSubDirect(String id) throws Exception {
Group group = this.entityManagerContainer().find(id, Group.class, ExceptionWhen.none);
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Group> root = cq.from(Group.class);
Predicate p = root.get(Group_.id).in(group.getGroupList());
cq.select(root.get(Group_.id)).where(p);
return em.createQuery(cq).getResultList();
}
// @MethodDescribe("查找群组的全部群组成员,包括嵌套的群组成员.")
public List<String> listSubNested(String id) throws Exception {
ListOrderedSet<String> set = new ListOrderedSet<String>();
this.subNested(id, set);
return set.asList();
}
// @MethodDescribe("递归循环调用群组查找。.")
private void subNested(String id, ListOrderedSet<String> set) throws Exception {
List<String> list = new ArrayList<String>();
for (String str : this.listSubDirect(id)) {
if (!set.contains(str)) {
list.add(str);
}
}
if (!list.isEmpty()) {
set.addAll(list);
for (String str : list) {
this.subNested(str, set);
}
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Identity;
import com.x.organization.core.entity.Identity_;
import com.x.organization.core.entity.PersistenceProperties;
import net.sf.ehcache.Element;
public class IdentityFactory extends AbstractFactory {
public IdentityFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(Identity.class);
}
public Identity pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Identity o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (Identity) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private Identity pickObject(String flag) throws Exception {
Identity o = this.entityManagerContainer().flag(flag, Identity.class);
if (o != null) {
this.entityManagerContainer().get(Identity.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.Identity.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, Identity.class);
if (null != o) {
this.entityManagerContainer().get(Identity.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(Identity.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
Root<Identity> root = cq.from(Identity.class);
Predicate p = cb.equal(root.get(Identity_.name), name);
List<Identity> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<Identity> pick(List<String> flags) throws Exception {
List<Identity> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((Identity) element.getObjectValue());
}
} else {
Identity o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends Identity> List<T> sort(List<T> list) {
list = list.stream().sorted(
Comparator.comparing(Identity::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(
Comparator.comparing(Identity::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return list;
}
}
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.PersonAttribute;
import com.x.organization.core.entity.PersonAttribute_;
import net.sf.ehcache.Element;
public class PersonAttributeFactory extends AbstractFactory {
public PersonAttributeFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(PersonAttribute.class);
}
public PersonAttribute pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
PersonAttribute o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (PersonAttribute) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private PersonAttribute pickObject(String flag) throws Exception {
PersonAttribute o = this.entityManagerContainer().flag(flag, PersonAttribute.class);
if (o != null) {
this.entityManagerContainer().get(PersonAttribute.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.PersonAttribute.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, PersonAttribute.class);
if (null != o) {
this.entityManagerContainer().get(PersonAttribute.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(PersonAttribute.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PersonAttribute> cq = cb.createQuery(PersonAttribute.class);
Root<PersonAttribute> root = cq.from(PersonAttribute.class);
Predicate p = cb.equal(root.get(PersonAttribute_.name), name);
List<PersonAttribute> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<PersonAttribute> pick(List<String> flags) throws Exception {
List<PersonAttribute> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((PersonAttribute) element.getObjectValue());
}
} else {
PersonAttribute o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends PersonAttribute> List<T> sort(List<T> list) {
list = list.stream()
.sorted(Comparator.comparing(PersonAttribute::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(
Comparator.comparing(PersonAttribute::getName, Comparator.nullsFirst(String::compareTo))
.reversed()))
.collect(Collectors.toList());
return list;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.tools.Crypto;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Person_;
import net.sf.ehcache.Element;
public class PersonFactory extends AbstractFactory {
public PersonFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(Person.class);
}
public Person pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Person o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (Person) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private Person pickObject(String flag) throws Exception {
Person o = this.entityManagerContainer().flag(flag, Person.class);
if (o != null) {
this.entityManagerContainer().get(Person.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.Person.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, Person.class);
if (null != o) {
this.entityManagerContainer().get(Person.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class);
Root<Person> root = cq.from(Person.class);
Predicate p = cb.equal(root.get(Person_.name), name);
List<Person> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<Person> pick(List<String> flags) throws Exception {
List<Person> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((Person) element.getObjectValue());
}
} else {
Person o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends Person> List<T> sort(List<T> list) {
list = list.stream().sorted(
Comparator.comparing(Person::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(
Comparator.comparing(Person::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return list;
}
public String getWithName(String name, String excludeId) throws Exception {
if (StringUtils.isEmpty(name)
|| (!JpaObjectTools.withinDefinedLength(name, Person.class, Person.name_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.name_FIELDNAME, name,
Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithMobile(String mobile, String excludeId) throws Exception {
if (StringUtils.isEmpty(mobile)
|| (!JpaObjectTools.withinDefinedLength(mobile, Person.class, Person.mobile_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.mobile_FIELDNAME,
mobile, Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithEmployee(String employee, String excludeId) throws Exception {
if (StringUtils.isEmpty(employee)
|| (!JpaObjectTools.withinDefinedLength(employee, Person.class, Person.employee_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.employee_FIELDNAME,
employee, Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithUnique(String unique, String excludeId) throws Exception {
if (StringUtils.isEmpty(unique)
|| (!JpaObjectTools.withinDefinedLength(unique, Person.class, Person.unique_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.unique_FIELDNAME,
unique, Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithQq(String qq, String excludeId) throws Exception {
if (StringUtils.isEmpty(qq) || (!JpaObjectTools.withinDefinedLength(qq, Person.class, Person.qq_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.qq_FIELDNAME, qq,
Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithMail(String mail, String excludeId) throws Exception {
if (StringUtils.isEmpty(mail)
|| (!JpaObjectTools.withinDefinedLength(mail, Person.class, Person.mail_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.mail_FIELDNAME, mail,
Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
public String getWithWeixin(String weixin, String excludeId) throws Exception {
if (StringUtils.isEmpty(weixin)
|| (!JpaObjectTools.withinDefinedLength(weixin, Person.class, Person.weixin_FIELDNAME))) {
return null;
}
List<String> list = this.entityManagerContainer().idsEqualAndNotEqual(Person.class, Person.mail_FIELDNAME,
weixin, Person.id_FIELDNAME, excludeId);
return this.returnNotDuplicateId(list);
}
private String returnNotDuplicateId(List<String> list) throws Exception {
if (list.isEmpty()) {
return null;
} else if (list.size() == 1) {
return list.get(0);
}
throw new Exception("find duplicate value{" + StringUtils.join(list, ",") + "}");
}
public void setPassword(Person person, String password) throws Exception {
Calendar cal = Calendar.getInstance();
person.setChangePasswordTime(cal.getTime());
person.setPassword(Crypto.encrypt(password, Config.token().getKey()));
Integer passwordPeriod = Config.person().getPasswordPeriod();
if (passwordPeriod == null || passwordPeriod <= 0) {
person.setPasswordExpiredTime(null);
} else {
cal.add(Calendar.DATE, passwordPeriod);
person.setPasswordExpiredTime(cal.getTime());
}
}
// public Person getWi1thDingdingIdObject(String dingdingId) throws Exception {
// EntityManager em = this.entityManagerContainer().get(Person.class);
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery<Person> cq = cb.createQuery(Person.class);
// Root<Person> root = cq.from(Person.class);
// Predicate p = cb.equal(root.get(Person_.dingdingId), dingdingId);
// List<Person> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
// if (os.isEmpty()) {
// return null;
// } else {
// return os.get(0);
// }
// }
//
// public Person getWithQiyeweixinIdObject(String dingdingId) throws Exception {
// EntityManager em = this.entityManagerContainer().get(Person.class);
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery<Person> cq = cb.createQuery(Person.class);
// Root<Person> root = cq.from(Person.class);
// Predicate p = cb.equal(root.get(Person_.qiyeweixinId), dingdingId);
// List<Person> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
// if (os.isEmpty()) {
// return null;
// } else {
// return os.get(0);
// }
// }
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.Role;
import com.x.organization.core.entity.Role_;
import net.sf.ehcache.Element;
public class RoleFactory extends AbstractFactory {
public RoleFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(Role.class);
}
public Role pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Role o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (Role) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private Role pickObject(String flag) throws Exception {
Role o = this.entityManagerContainer().flag(flag, Role.class);
if (o != null) {
this.entityManagerContainer().get(Role.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.Role.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, Role.class);
if (null != o) {
this.entityManagerContainer().get(Role.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(Role.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Role> cq = cb.createQuery(Role.class);
Root<Role> root = cq.from(Role.class);
Predicate p = cb.equal(root.get(Role_.name), name);
List<Role> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<Role> pick(List<String> flags) throws Exception {
List<Role> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((Role) element.getObjectValue());
}
} else {
Role o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends Role> List<T> sort(List<T> list) {
list = list
.stream().sorted(
Comparator.comparing(Role::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Comparator
.comparing(Role::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return list;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.UnitAttribute;
import com.x.organization.core.entity.UnitAttribute_;
import net.sf.ehcache.Element;
public class UnitAttributeFactory extends AbstractFactory {
public UnitAttributeFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(UnitAttribute.class);
}
public UnitAttribute pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
UnitAttribute o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (UnitAttribute) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private UnitAttribute pickObject(String flag) throws Exception {
UnitAttribute o = this.entityManagerContainer().flag(flag, UnitAttribute.class);
if (o != null) {
this.entityManagerContainer().get(UnitAttribute.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.UnitAttribute.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, UnitAttribute.class);
if (null != o) {
this.entityManagerContainer().get(UnitAttribute.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(UnitAttribute.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UnitAttribute> cq = cb.createQuery(UnitAttribute.class);
Root<UnitAttribute> root = cq.from(UnitAttribute.class);
Predicate p = cb.equal(root.get(UnitAttribute_.name), name);
List<UnitAttribute> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<UnitAttribute> pick(List<String> flags) throws Exception {
List<UnitAttribute> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((UnitAttribute) element.getObjectValue());
}
} else {
UnitAttribute o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends UnitAttribute> List<T> sort(List<T> list) {
list = list.stream()
.sorted(Comparator.comparing(UnitAttribute::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(
Comparator.comparing(UnitAttribute::getName, Comparator.nullsFirst(String::compareTo))
.reversed()))
.collect(Collectors.toList());
return list;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.UnitDuty;
import com.x.organization.core.entity.UnitDuty_;
import net.sf.ehcache.Element;
public class UnitDutyFactory extends AbstractFactory {
public UnitDutyFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(UnitDuty.class);
}
public UnitDuty pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
UnitDuty o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (UnitDuty) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private UnitDuty pickObject(String flag) throws Exception {
UnitDuty o = this.entityManagerContainer().flag(flag, UnitDuty.class);
if (o != null) {
this.entityManagerContainer().get(UnitDuty.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.UnitDuty.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, UnitDuty.class);
if (null != o) {
this.entityManagerContainer().get(UnitDuty.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(UnitDuty.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
Root<UnitDuty> root = cq.from(UnitDuty.class);
Predicate p = cb.equal(root.get(UnitDuty_.name), name);
List<UnitDuty> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
}
return o;
}
public List<UnitDuty> pick(List<String> flags) throws Exception {
List<UnitDuty> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((UnitDuty) element.getObjectValue());
}
} else {
UnitDuty o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends UnitDuty> List<T> sort(List<T> list) {
list = list.stream().sorted(
Comparator.comparing(UnitDuty::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(
Comparator.comparing(UnitDuty::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return list;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.factory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.AbstractFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.Unit;
import com.x.organization.core.entity.Unit_;
import net.sf.ehcache.Element;
public class UnitFactory extends AbstractFactory {
public UnitFactory(Business business) throws Exception {
super(business);
cache = ApplicationCache.instance().getCache(Unit.class);
}
public Unit pick(String flag) throws Exception {
if (StringUtils.isEmpty(flag)) {
return null;
}
Unit o = null;
Element element = cache.get(flag);
if (null != element) {
if (null != element.getObjectValue()) {
o = (Unit) element.getObjectValue();
}
} else {
o = this.pickObject(flag);
cache.put(new Element(flag, o));
}
return o;
}
private Unit pickObject(String flag) throws Exception {
Unit o = this.entityManagerContainer().flag(flag, Unit.class);
if (o != null) {
this.entityManagerContainer().get(Unit.class).detach(o);
} else {
String name = flag;
Matcher matcher = PersistenceProperties.Unit.distinguishedName_pattern.matcher(flag);
if (matcher.find()) {
name = matcher.group(1);
String unique = matcher.group(2);
o = this.entityManagerContainer().flag(unique, Unit.class);
if (null != o) {
this.entityManagerContainer().get(Unit.class).detach(o);
}
}
if (null == o) {
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.name), name);
List<Unit> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
if (os.size() == 1) {
o = os.get(0);
em.detach(o);
}
}
if (null == o && StringUtils.contains(flag, PersistenceProperties.Unit.levelNameSplit)) {
List<String> list = Arrays.asList(StringUtils.split(flag, PersistenceProperties.Unit.levelNameSplit));
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.and(cb.equal(root.get(Unit_.name), Objects.toString(ListTools.last(list), "")),
cb.equal(root.get(Unit_.level), list.size()));
List<Unit> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
for (Unit unit : os) {
if (StringUtils.equalsIgnoreCase(unit.getLevelName(), flag)) {
o = unit;
em.detach(o);
break;
}
}
}
}
return o;
}
public List<Unit> pick(List<String> flags) throws Exception {
List<Unit> list = new ArrayList<>();
for (String str : flags) {
Element element = cache.get(str);
if (null != element) {
if (null != element.getObjectValue()) {
list.add((Unit) element.getObjectValue());
}
} else {
Unit o = this.pickObject(str);
cache.put(new Element(str, o));
if (null != o) {
list.add(o);
}
}
}
return list;
}
public <T extends Unit> List<T> sort(List<T> list) {
List<T> os = list.stream().sorted(Comparator.comparing(Unit::getLevel, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Comparator.comparing(Unit::getOrderNumber, Comparator.nullsLast(Integer::compareTo)))
.thenComparing(
Comparator.comparing(Unit::getName, Comparator.nullsFirst(String::compareTo)).reversed()))
.collect(Collectors.toList());
return os;
}
public String getSupDirect(String id) throws Exception {
if (StringUtils.isEmpty(id)) {
return null;
}
Unit unit = this.pick(id);
if (null == unit) {
return null;
}
if (StringUtils.isEmpty(unit.getSuperior())) {
return null;
}
Unit superior = this.pick(unit.getSuperior());
if (null == superior) {
return null;
}
return superior.getId();
}
/** 递归的上级组织,从底层到顶层 */
public List<String> listSupNested(String id) throws Exception {
List<String> list = new ArrayList<>();
this.supNested(id, list);
return list;
}
private void supNested(String id, List<String> list) throws Exception {
String superiorId = this.getSupDirect(id);
if (StringUtils.isNotEmpty(superiorId) && (!list.contains(superiorId))) {
list.add(superiorId);
this.supNested(superiorId, list);
}
}
public Unit getSupDirectObject(Unit unit) throws Exception {
if (null == unit) {
return null;
}
if (StringUtils.isEmpty(unit.getSuperior())) {
return null;
}
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.id), unit.getSuperior());
List<Unit> list = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
if (!list.isEmpty()) {
return list.get(0);
} else {
return null;
}
}
/** 递归的上级组织,从底层到顶层 */
public List<Unit> listSupNestedObject(Unit unit) throws Exception {
List<Unit> list = new ArrayList<>();
if (unit == null) {
return list;
}
if (StringUtils.isEmpty(unit.getSuperior())) {
return list;
}
this.supNestedObject(unit, list);
list = list.stream().sorted(Comparator.comparing(Unit::getLevel, Comparator.nullsLast(Integer::compareTo)))
.collect(Collectors.toList());
return list;
}
private void supNestedObject(Unit unit, List<Unit> list) throws Exception {
Unit superior = this.getSupDirectObject(unit);
if ((null != superior) && (!list.contains(superior))) {
list.add(superior);
this.supNestedObject(superior, list);
}
}
public void adjustInherit(Unit unit) throws Exception {
List<Unit> os = new ArrayList<>();
os.add(unit);
os.addAll(this.listSubNestedObject(unit));
for (Unit o : os) {
List<Unit> list = this.listSupNestedObject(o);
/** 级别从1开始 */
o.setLevel(list.size() + 1);
List<String> names = ListTools.extractProperty(list, "name", String.class, false, false);
// Collections.reverse(names);
names.add(o.getName());
o.setLevelName(StringUtils.join(names, PersistenceProperties.Unit.levelNameSplit));
List<String> inheritControllerList = new ArrayList<>();
for (Unit u : list) {
if (ListTools.isNotEmpty(u.getControllerList())) {
inheritControllerList.addAll(u.getControllerList());
}
}
o.setInheritedControllerList(ListTools.trim(inheritControllerList, true, true));
}
}
public List<String> listSubNested(String id) throws Exception {
List<String> list = new ArrayList<>();
this.subNested(id, list);
return list;
}
private void subNested(String id, List<String> list) throws Exception {
List<String> os = new ArrayList<>();
for (String o : this.listSubDirect(id)) {
if (!list.contains(o)) {
os.add(o);
}
}
if (!os.isEmpty()) {
list.addAll(os);
for (String o : os) {
this.subNested(o, list);
}
}
}
public List<String> listSubDirect(String id) throws Exception {
if (StringUtils.isEmpty(id)) {
return new ArrayList<String>();
}
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.superior), id);
return em.createQuery(cq.select(root.get(Unit_.id)).where(p)).getResultList();
}
public List<Unit> listSubNestedObject(Unit unit) throws Exception {
List<Unit> list = new ArrayList<>();
this.subNestedObject(unit, list);
return list;
}
private void subNestedObject(Unit unit, List<Unit> list) throws Exception {
List<Unit> os = new ArrayList<>();
for (Unit o : this.listSubDirectObject(unit)) {
if (!list.contains(o)) {
os.add(o);
}
}
if (!os.isEmpty()) {
list.addAll(os);
for (Unit o : os) {
this.subNestedObject(o, list);
}
}
}
public List<Unit> listSubDirectObject(Unit unit) throws Exception {
if (null == unit) {
return new ArrayList<Unit>();
}
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.superior), unit.getId());
return em.createQuery(cq.select(root).where(p)).getResultList();
}
public List<Unit> listTopObject() throws Exception {
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.level), 0);
List<Unit> os = em.createQuery(cq.select(root).where(p)).getResultList();
os = os.stream().sorted(Comparator.comparing(Unit::getOrderNumber, Comparator.nullsLast(Integer::compareTo)))
.collect(Collectors.toList());
return os;
}
public Unit getWithDingdingIdObject(String dingdingId) throws Exception {
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.dingdingId), dingdingId);
List<Unit> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
if (os.isEmpty()) {
return null;
} else {
return os.get(0);
}
}
public Unit getWithQiyeweixinIdObject(String dingdingId) throws Exception {
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.equal(root.get(Unit_.qiyeweixinId), dingdingId);
List<Unit> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
if (os.isEmpty()) {
return null;
} else {
return os.get(0);
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.organization.assemble.control.jaxrs.export.ExportAction;
import com.x.organization.assemble.control.jaxrs.function.FunctionAction;
import com.x.organization.assemble.control.jaxrs.group.GroupAction;
import com.x.organization.assemble.control.jaxrs.identity.IdentityAction;
import com.x.organization.assemble.control.jaxrs.inputperson.InputPersonAction;
import com.x.organization.assemble.control.jaxrs.loginrecord.LoginRecordAction;
import com.x.organization.assemble.control.jaxrs.permissionsetting.PermissionSettingAction;
import com.x.organization.assemble.control.jaxrs.person.PersonAction;
import com.x.organization.assemble.control.jaxrs.personattribute.PersonAttributeAction;
import com.x.organization.assemble.control.jaxrs.personcard.PersonCardAction;
import com.x.organization.assemble.control.jaxrs.role.RoleAction;
import com.x.organization.assemble.control.jaxrs.unit.UnitAction;
import com.x.organization.assemble.control.jaxrs.unitattribute.UnitAttributeAction;
import com.x.organization.assemble.control.jaxrs.unitduty.UnitDutyAction;
@ApplicationPath("jaxrs")
public class ActionApplication extends AbstractActionApplication {
public Set<Class<?>> getClasses() {
classes.add(PersonAction.class);
classes.add(PersonAttributeAction.class);
classes.add(IdentityAction.class);
classes.add(GroupAction.class);
classes.add(RoleAction.class);
classes.add(FunctionAction.class);
classes.add(LoginRecordAction.class);
classes.add(InputPersonAction.class);
classes.add(UnitAction.class);
classes.add(UnitAttributeAction.class);
classes.add(UnitDutyAction.class);
classes.add(ExportAction.class);
classes.add(PersonCardAction.class);
classes.add(PermissionSettingAction.class);
return classes;
}
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/export/*", asyncSupported = true)
public class ExportJaxrsFilter extends CipherManagerJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/function/*", asyncSupported = true)
public class FunctionJaxrsFilter extends CipherManagerJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/group/*", asyncSupported = true)
public class GroupJaxrsFilter extends ManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/identity/*", asyncSupported = true)
public class IdentityJaxrsFilter extends ManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/inputperson/*", asyncSupported = true)
public class InputPersonFilter extends CipherManagerJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/loginrecord/*", asyncSupported = true)
public class LoginRecordFilter extends CipherManagerJaxrsFilter {
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/personattribute/*", asyncSupported = true)
public class PersonAttributeJaxrsFilter extends ManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/person/*", asyncSupported = true)
public class PersonJaxrsFilter extends ManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.ManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/role/*", asyncSupported = true)
public class RoleFilter extends ManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/test/*", asyncSupported = true)
public class TestFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/unitattribute/*", asyncSupported = true)
public class UnitAttributeFilter extends CipherManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/unitduty/*", asyncSupported = true)
public class UnitDutyFilter extends CipherManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/unit/*", asyncSupported = true)
public class UnitFilter extends CipherManagerUserJaxrsFilter {
}
package com.x.organization.assemble.control.jaxrs.export;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import net.sf.ehcache.Element;
class ActionGetResult extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionGetResult.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
logger.debug(effectivePerson, "flag:{}.", flag);
ActionResult<Wo> result = new ActionResult<>();
Element element = cache.get(flag);
if (null == element || (null == element.getObjectValue())) {
throw new ExceptionResultNotFound(flag);
}
CacheFileResult o = (CacheFileResult) element.getObjectValue();
Wo wo = new Wo(o.getBytes(), this.contentType(true, o.getName()), this.contentDisposition(true, o.getName()));
result.setData(wo);
return result;
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.export;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Identity;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Unit;
import net.sf.ehcache.Element;
class ActionZhengwuDingdingPerson extends BaseAction {
private List<Unit> allUnit;
private List<Person> allPerson;
private List<Identity> allIdentity;
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Workbook workBook = new XSSFWorkbook()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
allUnit = this.listUnit(business);
allPerson = this.listPerson(business);
allIdentity = emc.listAll(Identity.class);
List<Person> sortedPerson = new ArrayList<>();
for (Unit u : this.allUnit) {
List<Person> os = this.listPersonWithUnit(u);
for (Person p : os) {
if (!sortedPerson.contains(p)) {
sortedPerson.add(p);
}
}
}
List<User> users = new ArrayList<>();
for (Person person : sortedPerson) {
List<Unit> units = this.listUnitWithPerson(person);
User user = new User();
user.setName(person.getName());
user.setZhengwuDingdingId(person.getZhengwuDingdingId());
user.setMobile(person.getMobile());
user.setUnitList(ListTools.extractProperty(units, Unit.name_FIELDNAME, String.class, true, false));
users.add(user);
}
Sheet sheet = workBook.createSheet("政务钉钉人员");
Row row = sheet.createRow(0);
row.createCell(0).setCellValue("姓名");
row.createCell(1).setCellValue("手机");
row.createCell(2).setCellValue("政务钉钉ID");
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(user.getName());
row.createCell(1).setCellValue(user.getMobile());
row.createCell(2).setCellValue(user.getZhengwuDingdingId());
for (int j = 0; j < user.getUnitList().size(); j++) {
row.createCell(j + 3).setCellValue(user.getUnitList().get(j));
}
}
workBook.write(baos);
CacheFileResult cacheFileResult = new CacheFileResult();
cacheFileResult.setBytes(baos.toByteArray());
cacheFileResult.setName("政务钉钉人员.xlsx");
Wo wo = new Wo();
wo.setFlag(StringTools.uniqueToken());
this.cache.put(new Element(wo.getFlag(), cacheFileResult));
result.setData(wo);
return result;
}
}
private List<Person> listPerson(Business business) throws Exception {
EntityManager em = business.entityManagerContainer().get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class);
Root<Person> root = cq.from(Person.class);
Predicate p = cb.isNotEmpty(root.get(Person.zhengwuDingdingId_FIELDNAME));
List<Person> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
return os;
}
private List<Unit> listUnit(Business business) throws Exception {
EntityManager em = business.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p = cb.isNotEmpty(root.get(Unit.zhengwuDingdingId_FIELDNAME));
List<Unit> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
os = os.stream().sorted(Comparator.comparing(Unit::getOrderNumber, Comparator.nullsLast(Integer::compareTo)))
.collect(Collectors.toList());
return os;
}
private List<Person> listPersonWithUnit(Unit unit) throws Exception {
List<Identity> identities = this.listIdentityWithUnit(unit);
return this.listWithIdentity(identities);
}
private List<Identity> listIdentityWithUnit(Unit unit) throws Exception {
List<Identity> os = allIdentity.stream().filter(o -> {
return StringUtils.equals(unit.getId(), o.getUnit());
}).collect(Collectors.toList());
return os;
}
private List<Person> listWithIdentity(List<Identity> identities) throws Exception {
final List<String> ids = ListTools.extractProperty(identities, Identity.person_FIELDNAME, String.class, true,
true);
List<Person> os = allPerson.stream().filter(o -> {
return ListTools.contains(ids, o.getId());
}).collect(Collectors.toList());
return os;
}
private List<Unit> listUnitWithPerson(Person person) throws Exception {
List<Identity> identities = this.listIdentityWithPerson(person);
final List<String> ids = ListTools.extractProperty(identities, Identity.unit_FIELDNAME, String.class, true,
true);
List<Unit> os = allUnit.stream().filter(o -> {
return ListTools.contains(ids, o.getId());
}).collect(Collectors.toList());
return os;
}
private List<Identity> listIdentityWithPerson(Person person) {
List<Identity> os = allIdentity.stream().filter(o -> {
return StringUtils.equals(o.getPerson(), person.getId());
}).collect(Collectors.toList());
return os;
}
public static class Wo extends GsonPropertyObject {
@FieldDescribe("返回的结果标识")
private String flag;
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
}
public static class User extends GsonPropertyObject {
private String name;
private String mobile;
private String zhengwuDingdingId;
private String zhengwuDingdingTitle;
private List<String> unitList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getZhengwuDingdingId() {
return zhengwuDingdingId;
}
public void setZhengwuDingdingId(String zhengwuDingdingId) {
this.zhengwuDingdingId = zhengwuDingdingId;
}
public String getZhengwuDingdingTitle() {
return zhengwuDingdingTitle;
}
public void setZhengwuDingdingTitle(String zhengwuDingdingTitle) {
this.zhengwuDingdingTitle = zhengwuDingdingTitle;
}
public List<String> getUnitList() {
return unitList;
}
public void setUnitList(List<String> unitList) {
this.unitList = unitList;
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.export;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import net.sf.ehcache.Ehcache;
abstract class BaseAction extends StandardJaxrsAction {
protected Ehcache cache = ApplicationCache.instance().getCache(CacheFileResult.class);
public static class CacheFileResult {
private String name;
private byte[] bytes;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
}
}
package com.x.organization.assemble.control.jaxrs.export;
import com.x.base.core.project.exception.PromptException;
class ExceptionResultNotFound extends PromptException {
private static final long serialVersionUID = -2139584911736169462L;
ExceptionResultNotFound(String flag) {
super("找不到导入结果:{}.", flag);
}
}
package com.x.organization.assemble.control.jaxrs.export;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("export")
@JaxrsDescribe("导出")
public class ExportAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(ExportAction.class);
@JaxrsMethodDescribe(value = "获取政务钉钉人员.", action = ActionZhengwuDingdingPerson.class)
@GET
@Path("zhengwudingding/person")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void zhengwuDingdingPerson(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request) {
ActionResult<ActionZhengwuDingdingPerson.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionZhengwuDingdingPerson().execute(effectivePerson);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取导出结果.", action = ActionGetResult.class)
@GET
@Path("result/flag/{flag}")
@Consumes(MediaType.APPLICATION_JSON)
public void getResult(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("导入文件返回的结果标记") @PathParam("flag") String flag) {
ActionResult<ActionGetResult.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetResult().execute(effectivePerson, flag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.function;
import java.util.List;
import java.util.Objects;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.WrapOutCount;
import com.x.base.core.project.tools.Crypto;
import com.x.organization.core.entity.Person;
public class ActionCreatePassword {
protected ActionResult<WrapOutCount> execute(String attribute) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<WrapOutCount> result = new ActionResult<>();
if (!StringUtils.equals(attribute, "password")) {
EntityManager em = emc.beginTransaction(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class);
Root<Person> root = cq.from(Person.class);
cq.select(root);
List<Person> list = em.createQuery(cq).getResultList();
for (Person o : list) {
Object obj = PropertyUtils.getProperty(o, attribute);
if (null == obj) {
throw new Exception("person{name:" + o.getName() + "} can not create password.");
}
String str = Objects.toString(obj);
if (StringUtils.isEmpty(str)) {
throw new Exception("person{name:" + o.getName() + "} can not create empty password.");
}
String value = Crypto.encrypt(str, Config.token().getKey());
PropertyUtils.setProperty(o, "password", value);
}
emc.commit();
WrapOutCount wrap = new WrapOutCount();
wrap.setCount(list.size());
result.setData(wrap);
}
return result;
}
}
}
package com.x.organization.assemble.control.jaxrs.function;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.project.http.WrapInStringList;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Person;
public class ActionListAllPersonName {
protected List<Tuple> execute(Business business, WrapInStringList wrapIn) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
EntityManager em = emc.get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createQuery(Tuple.class);
Root<Person> root = cq.from(Person.class);
List<Selection<?>> selections = new ArrayList<>();
for (String str : wrapIn.getValueList()) {
selections.add(root.get(str));
}
cq.multiselect(selections);
List<Tuple> wraps = em.createQuery(cq).getResultList();
return wraps;
}
}
package com.x.organization.assemble.control.jaxrs.function;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.http.WrapInString;
import com.x.base.core.project.http.WrapOutId;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Person;
public class ActionSetPassword {
protected WrapOutId execute(Business business, String name, WrapInString wrapIn) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
String personId = business.person().getWithName(name, null);
if (StringUtils.isEmpty(personId)) {
personId = business.person().getWithUnique(name, null);
}
if (StringUtils.isEmpty(personId)) {
throw new Exception("can not find person:" + name);
} else {
if (StringUtils.isEmpty(wrapIn.getValue())) {
throw new Exception("new password is empty");
}
Person person = emc.find(personId, Person.class, ExceptionWhen.not_found);
emc.beginTransaction(Person.class);
business.person().setPassword(person, wrapIn.getValue());
emc.check(person, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Person.class);
WrapOutId wrap = new WrapOutId(person.getId());
return wrap;
}
}
}
package com.x.organization.assemble.control.jaxrs.function;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.WrapOutCount;
import com.x.base.core.project.tools.Crypto;
import com.x.organization.core.entity.Person;
public class ActionSetText {
protected ActionResult<WrapOutCount> execute(String attribute, String key) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<WrapOutCount> result = new ActionResult<>();
if (!StringUtils.equals(attribute, "password")) {
EntityManager em = emc.beginTransaction(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class);
Root<Person> root = cq.from(Person.class);
cq.select(root);
List<Person> list = em.createQuery(cq).getResultList();
for (Person o : list) {
String value = Crypto.decrypt(o.getPassword(), key);
PropertyUtils.setProperty(o, attribute, value);
}
emc.commit();
WrapOutCount wrap = new WrapOutCount();
wrap.setCount(list.size());
result.setData(wrap);
}
return result;
}
}
}
package com.x.organization.assemble.control.jaxrs.function;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Tuple;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.http.WrapInString;
import com.x.base.core.project.http.WrapInStringList;
import com.x.base.core.project.http.WrapOutCount;
import com.x.base.core.project.http.WrapOutId;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.organization.assemble.control.Business;
@Path("function")
public class FunctionAction extends StandardJaxrsAction {
// @HttpMethodDescribe(value = "获取人员指定信息.", response = WrapOutStringList.class)
@POST
@Path("list/person")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listAllPersonName(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
WrapInStringList wrapIn) {
ActionResult<List<Tuple>> result = new ActionResult<>();
List<Tuple> wraps = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
wraps = new ActionListAllPersonName().execute(business, wrapIn);
result.setData(wraps);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
// @HttpMethodDescribe(value = "更新指定Person的Password.", request =
// WrapInString.class, response = WrapOutId.class)
@PUT
@Path("person/{name}/set/password")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void setPassword(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@PathParam("name") String name, WrapInString wrapIn) {
ActionResult<WrapOutId> result = new ActionResult<>();
WrapOutId wrap = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
wrap = new ActionSetPassword().execute(business, name, wrapIn);
result.setData(wrap);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
// @HttpMethodDescribe(response = WrapOutCount.class, value = "set text")
@GET
@Path("person/set/text/{attribute}/{key}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void setText(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@PathParam("attribute") String attribute, @PathParam("key") String key) {
ActionResult<WrapOutCount> result = new ActionResult<>();
try {
result = new ActionSetText().execute(attribute, key);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
// @HttpMethodDescribe(response = WrapOutCount.class, value = "create password")
@GET
@Path("person/create/password/{attribute}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void createPassword(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@PathParam("attribute") String attribute) {
ActionResult<WrapOutCount> result = new ActionResult<>();
try {
result = new ActionCreatePassword().execute(attribute);
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import java.util.List;
import org.apache.commons.collections4.ListUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
class ActionAddMember extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Group group = business.group().pick(flag);
if (null == group) {
throw new ExceptionGroupNotExist(flag);
}
if (!business.editable(effectivePerson, group)) {
throw new ExceptionDenyEditGroup(effectivePerson, flag);
}
emc.beginTransaction(Group.class);
group = emc.find(group.getId(), Group.class);
if (ListTools.isNotEmpty(wi.getPersonList())) {
List<String> person_add_ids = ListTools.extractProperty(
business.person().pick(ListTools.trim(wi.getPersonList(), true, true)), JpaObject.id_FIELDNAME,
String.class, true, true);
if (ListTools.isNotEmpty(person_add_ids)) {
group.setPersonList(
ListTools.trim(ListUtils.sum(group.getPersonList(), person_add_ids), true, true));
}
}
if (ListTools.isNotEmpty(wi.getGroupList())) {
List<String> group_add_ids = ListTools.extractProperty(
business.group().pick(ListTools.trim(wi.getGroupList(), true, true)), JpaObject.id_FIELDNAME,
String.class, true, true);
if (ListTools.isNotEmpty(group_add_ids)) {
group.setGroupList(ListTools.trim(ListUtils.sum(group.getGroupList(), group_add_ids), true, true));
}
}
emc.check(group, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Group.class);
Wo wo = new Wo();
wo.setId(group.getId());
result.setData(wo);
return result;
}
}
public static class Wi extends Group {
private static final long serialVersionUID = -6314932919066148113L;
static WrapCopier<Wi, Group> copier = WrapCopierFactory.wi(Wi.class, Group.class,
ListTools.toList(JpaObject.FieldsUnmodify, Group.personList_FIELDNAME, Group.groupList_FIELDNAME),
null);
}
public static class Wo extends WoId {
}
}
package com.x.organization.assemble.control.jaxrs.group;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.x_message_assemble_communicate;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.assemble.control.ThisApplication;
import com.x.organization.assemble.control.message.OrgBodyMessage;
import com.x.organization.assemble.control.message.OrgMessage;
import com.x.organization.assemble.control.message.OrgMessageFactory;
import com.x.organization.core.entity.Group;
class ActionCreate extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionCreate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Group group = Wi.copier.copy(wi);
/** 如果唯一标识不为空,要检查唯一标识是否唯一 */
if (this.uniqueDuplicateWhenNotEmpty(business, group)) {
throw new ExceptionDuplicateUnique(group.getName(), group.getUnique());
}
if (!business.editable(effectivePerson, group)) {
throw new ExceptionDenyCreateGroup(effectivePerson, group.getName());
}
if (StringUtils.isEmpty(wi.getName())) {
throw new ExceptionNameEmpty();
}
group.setPersonList(
ListTools.extractProperty(business.person().pick(ListTools.trim(group.getPersonList(), true, true)),
JpaObject.id_FIELDNAME, String.class, true, true));
group.setGroupList(
ListTools.extractProperty(business.group().pick(ListTools.trim(group.getGroupList(), true, true)),
JpaObject.id_FIELDNAME, String.class, true, true));
emc.beginTransaction(Group.class);
emc.persist(group, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Group.class);
/**创建 组织变更org消息通信 */
OrgMessageFactory orgMessageFactory = new OrgMessageFactory();
orgMessageFactory.createMessageCommunicate("add", "group", group, effectivePerson);
Wo wo = new Wo();
wo.setId(group.getId());
result.setData(wo);
return result;
}
}
public static class Wi extends Group {
private static final long serialVersionUID = -6314932919066148113L;
static WrapCopier<Wi, Group> copier = WrapCopierFactory.wi(Wi.class, Group.class, null,
ListTools.toList(JpaObject.FieldsUnmodify, "pinyin", "pinyinInitial"));
}
public static class Wo extends WoId {
}
}
package com.x.organization.assemble.control.jaxrs.group;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.google.gson.Gson;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.x_message_assemble_communicate;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.organization.assemble.control.Business;
import com.x.organization.assemble.control.ThisApplication;
import com.x.organization.assemble.control.message.OrgBodyMessage;
import com.x.organization.assemble.control.message.OrgMessage;
import com.x.organization.assemble.control.message.OrgMessageFactory;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Group_;
import com.x.organization.core.entity.Role;
import com.x.organization.core.entity.Role_;
class ActionDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionDelete.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String groupFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Group group = business.group().pick(groupFlag);
if (null == group) {
throw new ExceptionGroupNotExist(groupFlag);
}
if (!business.editable(effectivePerson, group)) {
throw new ExceptionDenyDeleteGroup(effectivePerson, groupFlag);
}
// if (emc.listIsMember(Group.class,Group., value))
emc.beginTransaction(Group.class);
group = emc.find(group.getId(), Group.class);
emc.beginTransaction(Role.class);
/** 删除有群组成员的群组和角色成员 */
this.removeGroupMember(business, group);
this.removeRoleMember(business, group);
emc.remove(group, CheckRemoveType.all);
emc.commit();
ApplicationCache.notify(Group.class);
/**创建 组织变更org消息通信 */
OrgMessageFactory orgMessageFactory = new OrgMessageFactory();
orgMessageFactory.createMessageCommunicate("delete", "group", group, effectivePerson);
Wo wo = new Wo();
wo.setId(group.getId());
result.setData(wo);
return result;
}
}
private void removeGroupMember(Business business, Group group) throws Exception {
EntityManager em = business.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.isMember(group.getId(), root.get(Group_.groupList));
List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList();
for (Group o : os) {
o.getGroupList().remove(group.getId());
}
}
private void removeRoleMember(Business business, Group group) throws Exception {
EntityManager em = business.entityManagerContainer().get(Role.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Role> cq = cb.createQuery(Role.class);
Root<Role> root = cq.from(Role.class);
Predicate p = cb.isMember(group.getId(), root.get(Role_.groupList));
List<Role> os = em.createQuery(cq.select(root).where(p)).getResultList();
for (Role o : os) {
o.getGroupList().remove(group.getId());
}
}
public static class Wo extends WoId {
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import java.util.List;
import org.apache.commons.collections4.ListUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
class ActionDeleteMember extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Group group = business.group().pick(flag);
if (null == group) {
throw new ExceptionGroupNotExist(flag);
}
if (!business.editable(effectivePerson, group)) {
throw new ExceptionDenyEditGroup(effectivePerson, flag);
}
emc.beginTransaction(Group.class);
group = emc.find(group.getId(), Group.class);
if (ListTools.isNotEmpty(wi.getPersonList())) {
List<String> person_remove_ids = ListTools.extractProperty(
business.person().pick(ListTools.trim(wi.getPersonList(), true, true)), JpaObject.id_FIELDNAME,
String.class, true, true);
if (ListTools.isNotEmpty(person_remove_ids)) {
group.setPersonList(ListUtils.subtract(group.getPersonList(), person_remove_ids));
}
}
if (ListTools.isNotEmpty(wi.getGroupList())) {
List<String> group_remove_ids = ListTools.extractProperty(
business.group().pick(ListTools.trim(wi.getGroupList(), true, true)), JpaObject.id_FIELDNAME,
String.class, true, true);
if (ListTools.isNotEmpty(group_remove_ids)) {
group.setGroupList(ListUtils.union(group.getGroupList(), group_remove_ids));
}
}
emc.check(group, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Group.class);
Wo wo = new Wo();
wo.setId(group.getId());
result.setData(wo);
return result;
}
}
public static class Wi extends Group {
private static final long serialVersionUID = -6314932919066148113L;
static WrapCopier<Wi, Group> copier = WrapCopierFactory.wi(Wi.class, Group.class,
ListTools.toList(JpaObject.FieldsUnmodify, Group.personList_FIELDNAME, Group.groupList_FIELDNAME),
null);
}
public static class Wo extends WoId {
}
}
package com.x.organization.assemble.control.jaxrs.group;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.x_message_assemble_communicate;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.assemble.control.ThisApplication;
import com.x.organization.assemble.control.message.OrgBodyMessage;
import com.x.organization.assemble.control.message.OrgMessage;
import com.x.organization.assemble.control.message.OrgMessageFactory;
import com.x.organization.core.entity.Group;
class ActionEdit extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionEdit.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Group group = business.group().pick(flag);
if (null == group) {
throw new ExceptionGroupNotExist(flag);
}
if (!business.editable(effectivePerson, group)) {
throw new ExceptionDenyEditGroup(effectivePerson, flag);
}
if (StringUtils.isEmpty(wi.getName())) {
throw new ExceptionNameEmpty();
}
emc.beginTransaction(Group.class);
group = emc.find(group.getId(), Group.class);
Gson gsontool = new Gson();
String strGroup = gsontool.toJson(group);
Wi.copier.copy(wi, group);
/** 如果唯一标识不为空,要检查唯一标识是否唯一 */
if (this.uniqueDuplicateWhenNotEmpty(business, group)) {
throw new ExceptionDuplicateUnique(group.getName(), group.getUnique());
}
group.setPersonList(
ListTools.extractProperty(business.person().pick(ListTools.trim(group.getPersonList(), true, true)),
JpaObject.id_FIELDNAME, String.class, true, true));
group.setGroupList(
ListTools.extractProperty(business.group().pick(ListTools.trim(group.getGroupList(), true, true)),
JpaObject.id_FIELDNAME, String.class, true, true));
emc.check(group, CheckPersistType.all);
emc.commit();
ApplicationCache.notify(Group.class);
/**创建 组织变更org消息通信 */
OrgMessageFactory orgMessageFactory = new OrgMessageFactory();
orgMessageFactory.createMessageCommunicate("modfiy", "group",strGroup, group, effectivePerson);
Wo wo = new Wo();
wo.setId(group.getId());
result.setData(wo);
return result;
}
}
public static class Wi extends Group {
private static final long serialVersionUID = -6314932919066148113L;
static WrapCopier<Wi, Group> copier = WrapCopierFactory.wi(Wi.class, Group.class, null,
ListTools.toList(JpaObject.FieldsUnmodify, "pinyin", "pinyinInitial"));
}
public static class Wo extends WoId {
}
}
package com.x.organization.assemble.control.jaxrs.group;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Unit;
import net.sf.ehcache.Element;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), flag);
Element element = business.cache().get(cacheKey);
if (null != element && (null != element.getObjectValue())) {
result.setData((Wo) element.getObjectValue());
} else {
Wo wo = this.get(business, flag);
business.cache().put(new Element(cacheKey, wo));
result.setData(wo);
}
this.updateControl(effectivePerson, business, result.getData());
return result;
}
}
private Wo get(Business business, String flag) throws Exception {
Group group = business.group().pick(flag);
if (null == group) {
throw new ExceptionGroupNotExist(flag);
}
Wo wo = Wo.copier.copy(group);
this.referenceGroup(business, wo);
this.referencePerson(business, wo);
this.referenceUnit(business, wo);
return wo;
}
private void referenceGroup(Business business, Wo wo) throws Exception {
List<Wo> wos = new ArrayList<>();
if (ListTools.isNotEmpty(wo.getGroupList())) {
List<Group> os = business.group().pick(wo.getGroupList());
wos = Wo.copier.copy(os);
}
/*wos = wos.stream()
.sorted(Comparator.comparing(Wo::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Comparator.comparing(Wo::getName, Comparator.nullsLast(String::compareTo))))
.collect(Collectors.toList());*/
wo.setWoGroupList(wos);
}
private void referencePerson(Business business, Wo wo) throws Exception {
List<WoPerson> wos = new ArrayList<>();
if (ListTools.isNotEmpty(wo.getPersonList())) {
List<Person> os = business.person().pick(wo.getPersonList());
wos = WoPerson.copier.copy(os);
}
/*wos = wos.stream()
.sorted(Comparator.comparing(WoPerson::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(
Comparator.comparing(WoPerson::getName, Comparator.nullsLast(String::compareTo))))
.collect(Collectors.toList());*/
wo.setWoPersonList(wos);
}
private void referenceUnit(Business business, Wo wo) throws Exception {
List<WoUnit> wos = new ArrayList<>();
if (ListTools.isNotEmpty(wo.getUnitList())) {
List<Unit> os = business.unit().pick(wo.getUnitList());
wos = WoUnit.copier.copy(os);
}
/*wos = wos.stream()
.sorted(Comparator.comparing(WoUnit::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Comparator.comparing(WoUnit::getName, Comparator.nullsLast(String::compareTo))))
.collect(Collectors.toList());*/
wo.setWoUnitList(wos);
}
public static class Wo extends WoGroupAbstract {
private static final long serialVersionUID = -125007357898871894L;
@FieldDescribe("成员群组对象")
private List<Wo> woGroupList = new ArrayList<>();
@FieldDescribe("成员个人对象")
private List<WoPerson> woPersonList = new ArrayList<>();
@FieldDescribe("成员组织对象")
private List<WoUnit> woUnitList = new ArrayList<>();
static WrapCopier<Group, Wo> copier = WrapCopierFactory.wo(Group.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
public List<Wo> getWoGroupList() {
return woGroupList;
}
public void setWoGroupList(List<Wo> woGroupList) {
this.woGroupList = woGroupList;
}
public List<WoPerson> getWoPersonList() {
return woPersonList;
}
public void setWoPersonList(List<WoPerson> woPersonList) {
this.woPersonList = woPersonList;
}
public List<WoUnit> getWoUnitList() {
return woUnitList;
}
public void setWoUnitList(List<WoUnit> woUnitList) {
this.woUnitList = woUnitList;
}
}
public static class WoPerson extends Person {
private static final long serialVersionUID = -125007357898871894L;
static WrapCopier<Person, WoPerson> copier = WrapCopierFactory.wo(Person.class, WoPerson.class, null,
ListTools.toList(JpaObject.FieldsInvisible, "password", "icon"));
}
public static class WoUnit extends Unit {
private static final long serialVersionUID = -125007357898871894L;
static WrapCopier<Unit, WoUnit> copier = WrapCopierFactory.wo(Unit.class, WoUnit.class, null,
JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Group_;
import net.sf.ehcache.Element;
class ActionListLike extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
StringUtils.join(wi.getGroupList(), ","), StringUtils.join(wi.getRoleList(), ","));
Element element = business.cache().get(cacheKey);
if (null != element && (null != element.getObjectValue())) {
result.setData((List<Wo>) element.getObjectValue());
} else {
List<Wo> wos = this.list(business, wi);
business.cache().put(new Element(cacheKey, wos));
result.setData(wos);
}
this.updateControl(effectivePerson, business, result.getData());
return result;
}
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("搜索关键字")
private String key;
@FieldDescribe("搜索群组范围,为空则不限定")
private List<String> groupList = new ArrayList<>();
@FieldDescribe("搜索角色范围,为空则不限定")
private List<String> roleList = new ArrayList<>();
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public List<String> getGroupList() {
return groupList;
}
public void setGroupList(List<String> groupList) {
this.groupList = groupList;
}
public List<String> getRoleList() {
return roleList;
}
public void setRoleList(List<String> roleList) {
this.roleList = roleList;
}
}
public static class Wo extends WoGroupAbstract {
private static final long serialVersionUID = -125007357898871894L;
static WrapCopier<Group, Wo> copier = WrapCopierFactory.wo(Group.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
private List<Wo> list(Business business, Wi wi) throws Exception {
List<Wo> wos = new ArrayList<>();
if (StringUtils.isEmpty(wi.getKey())) {
return wos;
}
List<String> groupIds = business.expendGroupRoleToGroup(wi.getGroupList(), wi.getRoleList());
String str = StringUtils.lowerCase(StringTools.escapeSqlLikeKey(wi.getKey()));
EntityManager em = business.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.like(cb.lower(root.get(Group_.name)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR);
p = cb.or(p, cb.like(cb.lower(root.get(Group_.unique)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR));
p = cb.or(p, cb.like(cb.lower(root.get(Group_.pinyin)), str + "%", StringTools.SQL_ESCAPE_CHAR));
p = cb.or(p, cb.like(cb.lower(root.get(Group_.pinyinInitial)), str + "%", StringTools.SQL_ESCAPE_CHAR));
p = cb.or(p, cb.like(cb.lower(root.get(Group_.distinguishedName)), str + "%", StringTools.SQL_ESCAPE_CHAR));
if (ListTools.isNotEmpty(groupIds)) {
p = cb.and(p, root.get(Group_.id).in(groupIds));
}
List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList();
wos = Wo.copier.copy(os);
wos = business.group().sort(wos);
return wos;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
import com.x.organization.core.entity.Group_;
import net.sf.ehcache.Element;
class ActionListLikePinyin extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
StringUtils.join(wi.getGroupList(), ","), StringUtils.join(wi.getRoleList(), ","));
Element element = business.cache().get(cacheKey);
if (null != element && (null != element.getObjectValue())) {
result.setData((List<Wo>) element.getObjectValue());
} else {
List<Wo> wos = this.list(business, wi);
business.cache().put(new Element(cacheKey, wos));
result.setData(wos);
}
this.updateControl(effectivePerson, business, result.getData());
return result;
}
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("搜索关键字")
private String key;
@FieldDescribe("搜索群组范围,为空则不限定")
private List<String> groupList = new ArrayList<>();
@FieldDescribe("搜索角色范围,为空则不限定")
private List<String> roleList = new ArrayList<>();
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public List<String> getGroupList() {
return groupList;
}
public void setGroupList(List<String> groupList) {
this.groupList = groupList;
}
public List<String> getRoleList() {
return roleList;
}
public void setRoleList(List<String> roleList) {
this.roleList = roleList;
}
}
public static class Wo extends WoGroupAbstract {
private static final long serialVersionUID = -125007357898871894L;
static WrapCopier<Group, Wo> copier = WrapCopierFactory.wo(Group.class, Wo.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
private List<Wo> list(Business business, Wi wi) throws Exception {
List<Wo> wos = new ArrayList<>();
if (StringUtils.isEmpty(wi.getKey())) {
return wos;
}
List<String> groupIds = business.expendGroupRoleToGroup(wi.getGroupList(), wi.getRoleList());
String str = StringUtils.lowerCase(StringTools.escapeSqlLikeKey(wi.getKey()));
EntityManager em = business.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.like(root.get(Group_.pinyin), str + "%");
p = cb.or(p, cb.like(root.get(Group_.pinyinInitial), str + "%"));
if (ListTools.isNotEmpty(groupIds)) {
p = cb.and(p, root.get(Group_.id).in(groupIds));
}
List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList();
wos = Wo.copier.copy(os);
wos = business.group().sort(wos);
return wos;
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.organization.assemble.control.Business;
import com.x.organization.core.entity.Group;
import net.sf.ehcache.Element;
class ActionListNext extends BaseAction {
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String flag, Integer count) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<List<Wo>> result = new ActionResult<>();
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), flag, count);
Element element = business.cache().get(cacheKey);
if (null != element && null != element.getObjectValue()) {
Co co = (Co) element.getObjectValue();
result.setData(co.getWos());
result.setCount(co.getCount());
} else {
String id = EMPTY_SYMBOL;
/** 如果不是空位标志位 */
if (!StringUtils.equals(EMPTY_SYMBOL, flag)) {
Group o = business.group().pick(flag);
if (null == o) {
throw new ExceptionGroupNotExist(flag);
}
id = o.getId();
}
result = this.standardListNext(Wo.copier, id, count, JpaObject.sequence_FIELDNAME, null, null, null, null, null, null,
null, null, true, DESC);
Co co = new Co(result.getData(), result.getCount());
business.cache().put(new Element(cacheKey, co));
}
this.updateControl(effectivePerson, business, result.getData());
return result;
}
}
public static class Co extends GsonPropertyObject {
public Co(List<Wo> wos, Long count) {
this.wos = wos;
this.count = count;
}
List<Wo> wos;
Long count;
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public List<Wo> getWos() {
return wos;
}
public void setWos(List<Wo> wos) {
this.wos = wos;
}
}
public static class Wo extends WoGroupAbstract {
private static final long serialVersionUID = -125007357898871894L;
@FieldDescribe("排序号")
private Long rank;
static WrapCopier<Group, Wo> copier = WrapCopierFactory.wo(Group.class, Wo.class,
JpaObject.singularAttributeField(Group.class, true, true), null);
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
}
}
\ No newline at end of file
package com.x.organization.assemble.control.jaxrs.group;
import com.x.base.core.project.exception.PromptException;
import com.x.base.core.project.http.EffectivePerson;
class ExceptionDenyCreateGroup extends PromptException {
private static final long serialVersionUID = -3439770681867963457L;
ExceptionDenyCreateGroup(EffectivePerson effectivePerson, String name) {
super("{} 不能创建群组:{}, 权限不足.", effectivePerson.getDistinguishedName(), name);
}
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册